@libp2p/floodsub 11.0.29-87dca02b0 → 11.0.29-cef4d32cf
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 +3 -3
- package/package.json +8 -8
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PFloodsub = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PFloodsub=(()=>{var qa=Object.create;var Br=Object.defineProperty;var Ha=Object.getOwnPropertyDescriptor;var za=Object.getOwnPropertyNames;var Va=Object.getPrototypeOf,$a=Object.prototype.hasOwnProperty;var ja=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(r){throw t=0,r}},yt=(e,t)=>{for(var r in t)Br(e,r,{get:t[r],enumerable:!0})},gi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of za(t))!$a.call(e,s)&&s!==r&&Br(e,s,{get:()=>t[s],enumerable:!(n=Ha(t,s))||n.enumerable});return e};var Ya=(e,t,r)=>(r=e!=null?qa(Va(e)):{},gi(t||!e||!e.__esModule?Br(r,"default",{value:e,enumerable:!0}):r,e)),Za=e=>gi(Br({},"__esModule",{value:!0}),e);var La=ja((wb,di)=>{"use strict";var tl=Object.prototype.hasOwnProperty,bt="~";function Sr(){}Object.create&&(Sr.prototype=Object.create(null),new Sr().__proto__||(bt=!1));function el(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function Ta(e,t,r,n,s){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new el(r,n||e,s),o=bt?bt+t:t;return e._events[o]?e._events[o].fn?e._events[o]=[e._events[o],i]:e._events[o].push(i):(e._events[o]=i,e._eventsCount++),e}function mn(e,t){--e._eventsCount===0?e._events=new Sr:delete e._events[t]}function mt(){this._events=new Sr,this._eventsCount=0}mt.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)tl.call(r,n)&&t.push(bt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};mt.prototype.listeners=function(t){var r=bt?bt+t:t,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var s=0,i=n.length,o=new Array(i);s<i;s++)o[s]=n[s].fn;return o};mt.prototype.listenerCount=function(t){var r=bt?bt+t:t,n=this._events[r];return n?n.fn?1:n.length:0};mt.prototype.emit=function(t,r,n,s,i,o){var a=bt?bt+t:t;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,f,h;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,s),!0;case 5:return c.fn.call(c.context,r,n,s,i),!0;case 6:return c.fn.call(c.context,r,n,s,i,o),!0}for(h=1,f=new Array(u-1);h<u;h++)f[h-1]=arguments[h];c.fn.apply(c.context,f)}else{var l=c.length,d;for(h=0;h<l;h++)switch(c[h].once&&this.removeListener(t,c[h].fn,void 0,!0),u){case 1:c[h].fn.call(c[h].context);break;case 2:c[h].fn.call(c[h].context,r);break;case 3:c[h].fn.call(c[h].context,r,n);break;case 4:c[h].fn.call(c[h].context,r,n,s);break;default:if(!f)for(d=1,f=new Array(u-1);d<u;d++)f[d-1]=arguments[d];c[h].fn.apply(c[h].context,f)}}return!0};mt.prototype.on=function(t,r,n){return Ta(this,t,r,n,!1)};mt.prototype.once=function(t,r,n){return Ta(this,t,r,n,!0)};mt.prototype.removeListener=function(t,r,n,s){var i=bt?bt+t:t;if(!this._events[i])return this;if(!r)return mn(this,i),this;var o=this._events[i];if(o.fn)o.fn===r&&(!s||o.once)&&(!n||o.context===n)&&mn(this,i);else{for(var a=0,c=[],u=o.length;a<u;a++)(o[a].fn!==r||s&&!o[a].once||n&&o[a].context!==n)&&c.push(o[a]);c.length?this._events[i]=c.length===1?c[0]:c:mn(this,i)}return this};mt.prototype.removeAllListeners=function(t){var r;return t?(r=bt?bt+t:t,this._events[r]&&mn(this,r)):(this._events=new Sr,this._eventsCount=0),this};mt.prototype.off=mt.prototype.removeListener;mt.prototype.addListener=mt.prototype.on;mt.prefixed=bt;mt.EventEmitter=mt;typeof di<"u"&&(di.exports=mt)});var ll={};yt(ll,{StrictNoSign:()=>cl,StrictSign:()=>al,TopicValidatorResult:()=>Ve,floodsub:()=>fl,isPubSub:()=>ul,protocol:()=>bi,pubSubSymbol:()=>je});var je=Symbol.for("@libp2p/pubsub");var et=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Be=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Ir=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var ct=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Tr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var ce=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var xn=Symbol.for("@libp2p/peer-id");function Ga(e){return typeof e?.handleEvent=="function"}function Wa(e){return e===!0||e===!1}function Xa(e){return Wa(e)?e:e?.capture??!1}function En(e){let t={capture:Xa(e),once:!!e?.once};return e?.passive!=null&&(t.passive=e?.passive),e?.signal!=null&&(t.signal=e?.signal),t}function wi(e,t){return En(e).capture===En(t).capture}var Ie=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){let s=En(n);if(s?.signal?.aborted===!0)return;let i=u=>{s.once&&this.removeEventListener(t,r,s),Ga(r)?r.handleEvent(u):r(u)},o=this.#t.get(t);if(o==null&&(o=[],this.#t.set(t,o)),o.some(u=>u.callback!==r?!1:wi(u.options,s)))return;super.addEventListener(t,i,s);let c=()=>{this.removeEventListener(t,r,s)};s.signal?.addEventListener("abort",c),o.push({callback:r,wrapper:i,options:s,onAbort:c})}removeEventListener(t,r,n){let s=this.#t.get(t);if(s==null){super.removeEventListener(t,r??null,n);return}this.#t.set(t,s.filter(i=>i.callback===r&&wi(i.options,n)?(super.removeEventListener(t,i.wrapper,n),i.options?.signal?.removeEventListener("abort",i.onAbort),!1):!0))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var xi=Symbol.for("@libp2p/service-capabilities"),Ei=Symbol.for("@libp2p/service-dependencies");var In={};yt(In,{base58btc:()=>rt,base58flickr:()=>ic});var Hl=new Uint8Array(0);function vi(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 Bt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return ue(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return ue(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function Ai(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var Si=4096;function Bi(e){let t=e.length;if(t<=Si)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=Si));return r}function Ja(e){return e?.buffer instanceof ArrayBuffer}function ue(e){return Ja(e)?e:e.slice()}function Qa(e,t,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var i=0;i<e.length;i++){var o=e.charAt(i),a=o.charCodeAt(0);if(n[a]!==255)throw new TypeError(o+" is ambiguous");if(n[a]=i,r){var c=o.toLowerCase().charCodeAt(0),u=o.toUpperCase().charCodeAt(0);c!==a&&(n[c]=i),u!==a&&(n[u]=i)}}var f=e.length,h=e.charAt(0),l=Math.log(f)/Math.log(256),d=Math.log(256)/Math.log(f);function y(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var B=0,b=0,v=0,A=w.length;v!==A&&w[v]===0;)v++,B++;for(var O=(A-v)*d+1>>>0,K=new Uint8Array(O);v!==A;){for(var k=w[v],R=0,C=O-1;(k!==0||R<b)&&C!==-1;C--,R++)k+=256*K[C]>>>0,K[C]=k%f>>>0,k=k/f>>>0;if(k!==0)throw new Error("Non-zero carry");b=R,v++}for(var q=O-b;q!==O&&K[q]===0;)q++;for(var U=h.repeat(B);q<O;++q)U+=e.charAt(K[q]);return U}function g(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var B=0;if(w[B]!==" "){for(var b=0,v=0;w[B]===h;)b++,B++;for(var A=(w.length-B)*l+1>>>0,O=new Uint8Array(A);w[B];){var K=n[w.charCodeAt(B)];if(K===255)return;for(var k=0,R=A-1;(K!==0||k<v)&&R!==-1;R--,k++)K+=f*O[R]>>>0,O[R]=K%256>>>0,K=K/256>>>0;if(K!==0)throw new Error("Non-zero carry");v=k,B++}if(w[B]!==" "){for(var C=A-v;C!==A&&O[C]===0;)C++;for(var q=new Uint8Array(b+(A-C)),U=b;C!==A;)q[U++]=O[C++];return q}}}function S(w){var B=g(w);if(B)return B;throw new Error(`Non-${t} character`)}return{encode:y,decodeUnsafe:g,decode:S}}var tc=Qa,ec=tc,Ti=ec;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 s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 Li(this,t)}},An=class{decoders;constructor(t){this.decoders=t}or(t){return Li(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 Li(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,s){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new Sn(t,r,n),this.decoder=new vn(t,r,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Te({name:e,prefix:t,encode:r,decode:n}){return new Bn(e,t,r,n)}function $t({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:s,decode:i}=Ti(r,e,n);return Te({prefix:t,name:e,encode:s,decode:o=>Bt(i(o))})}function rc(e,t,r,n){let s=e.length;for(;e[s-1]==="=";)--s;let i=new Uint8Array(s*r/8|0),o=0,a=0,c=0;for(let u=0;u<s;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,o+=r,o>=8&&(o-=8,i[c++]=255&a>>o)}if(o>=r||(255&a<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return i}function nc(e,t,r){let n=t[t.length-1]==="=",s=(1<<r)-1,i="",o=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],o+=8;o>r;)o-=r,i+=t[s&a>>o];if(o!==0&&(i+=t[s&a<<r-o]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function sc(e,t){let r={};for(let n=0;n<e.length;++n)if(r[e[n]]=n,t){let s=e[n].toLowerCase(),i=e[n].toUpperCase();s!==e[n]&&(r[s]=n),i!==e[n]&&(r[i]=n)}return r}function it({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:s=!1}){let i=sc(n,s);return Te({prefix:t,name:e,encode(o){return nc(o,n,r)},decode(o){return rc(o,i,r,e)}})}var rt=$t({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ic=$t({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Tn={};yt(Tn,{base32:()=>Le,base32hex:()=>uc,base32hexpad:()=>lc,base32hexpadupper:()=>hc,base32hexupper:()=>fc,base32pad:()=>ac,base32padupper:()=>cc,base32upper:()=>oc,base32z:()=>dc});var Le=it({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),oc=it({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),ac=it({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),cc=it({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),uc=it({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),fc=it({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),lc=it({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),hc=it({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),dc=it({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ln={};yt(Ln,{base36:()=>Ye,base36upper:()=>pc});var Ye=$t({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),pc=$t({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var mc=Di,_i=128,bc=127,yc=~bc,gc=Math.pow(2,31);function Di(e,t,r){t=t||[],r=r||0;for(var n=r;e>=gc;)t[r++]=e&255|_i,e/=128;for(;e&yc;)t[r++]=e&255|_i,e>>>=7;return t[r]=e|0,Di.bytes=r-n+1,t}var wc=_n,xc=128,Ri=127;function _n(e,n){var r=0,n=n||0,s=0,i=n,o,a=e.length;do{if(i>=a)throw _n.bytes=0,new RangeError("Could not decode varint");o=e[i++],r+=s<28?(o&Ri)<<s:(o&Ri)*Math.pow(2,s),s+=7}while(o>=xc);return _n.bytes=i-n,r}var Ec=Math.pow(2,7),Sc=Math.pow(2,14),vc=Math.pow(2,21),Ac=Math.pow(2,28),Bc=Math.pow(2,35),Ic=Math.pow(2,42),Tc=Math.pow(2,49),Lc=Math.pow(2,56),_c=Math.pow(2,63),Rc=function(e){return e<Ec?1:e<Sc?2:e<vc?3:e<Ac?4:e<Bc?5:e<Ic?6:e<Tc?7:e<Lc?8:e<_c?9:10},Dc={encode:mc,decode:wc,encodingLength:Rc},Cc=Dc,Ze=Cc;function Ge(e,t=0){let r=Ze.decode(e,t),n=Ze.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&e[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function _e(e,t,r=0){return Ze.encode(e,t,r),t}function Re(e){return Ze.encodingLength(e)}function Pt(e,t){let r=t.byteLength,n=Re(e),s=n+Re(r),i=new Uint8Array(s+r);return _e(e,i,0),_e(r,i,n),i.set(t,s),new De(e,r,t,i)}function jt(e){let t=Bt(e),[r,n]=Ge(t),[s,i]=Ge(t.subarray(n)),o=t.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new De(r,s,o,t)}function Ci(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&vi(e.bytes,r.bytes)}}var De=class{code;size;digest;bytes;constructor(t,r,n,s){this.code=t,this.size=r,this.digest=ue(n),this.bytes=ue(s)}};function Pi(e,t){let{bytes:r,version:n}=e;return n===0?Oc(r,Rn(e),t??rt.encoder):kc(r,Rn(e),t??Le.encoder)}var Oi=new WeakMap;function Rn(e){let t=Oi.get(e);if(t==null){let r=new Map;return Oi.set(e,r),r}return t}var ht=class e{code;version;multihash;bytes;"/";constructor(t,r,n,s){this.code=r,this.version=t,this.multihash=n,this.bytes=ue(s),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==We)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Nc)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=Pt(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&&Ci(t.multihash,n.multihash)}toString(t){return Pi(this,t)}toJSON(){return{"/":Pi(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:s,multihash:i,bytes:o}=r;return new e(n,s,i,o??ki(n,s,i.bytes))}else if(r[Kc]===!0){let{version:n,multihash:s,code:i}=r,o=jt(s);return e.create(n,i,o)}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!==We)throw new Error(`Version 0 CID must use dag-pb (code: ${We}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let s=ki(t,r,n.bytes);return new e(t,r,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,We,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,s=Bt(t.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=s.subarray(r.multihashSize-r.digestSize),o=new De(r.multihashCode,r.digestSize,i,s);return[r.version===0?e.createV0(o):e.createV1(r.codec,o),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[h,l]=Ge(t.subarray(r));return r+=l,h},s=n(),i=We;if(s===18?(s=0,r=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=r,a=n(),c=n(),u=r+c,f=u-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,s]=Pc(t,r),i=e.decode(s);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Rn(i).set(n,t),i}};function Pc(e,t){switch(e[0]){case"Q":{let r=t??rt;return[rt.prefix,r.decode(`${rt.prefix}${e}`)]}case rt.prefix:{let r=t??rt;return[rt.prefix,r.decode(e)]}case Le.prefix:{let r=t??Le;return[Le.prefix,r.decode(e)]}case Ye.prefix:{let r=t??Ye;return[Ye.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 Oc(e,t,r){let{prefix:n}=r;if(n!==rt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=t.get(n);if(s==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return s}function kc(e,t,r){let{prefix:n}=r,s=t.get(n);if(s==null){let i=r.encode(e);return t.set(n,i),i}else return s}var We=112,Nc=18;function ki(e,t,r){let n=Re(e),s=n+Re(t),i=new Uint8Array(s+r.byteLength);return _e(e,i,0),_e(t,i,n),i.set(r,s),i}var Kc=Symbol.for("@ipld/js-cid/CID");var Dn={};yt(Dn,{identity:()=>Rt});var Ni=0,Fc="identity",Ki=Bt;function Mc(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 Pt(Ni,Ki(e))}var Rt={code:Ni,name:Fc,encode:Ki,digest:Mc};function gt(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 Uc(e){return e.buffer instanceof ArrayBuffer}function It(e){return Uc(e)?e:e.slice()}async function Fi(e,t,r,n){let s=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,It(t),It(r.subarray()));return n?.signal?.throwIfAborted(),i}function Kt(e=0){return new Uint8Array(e)}function wt(e=0){return new Uint8Array(e)}function qc(e){return e?.buffer instanceof ArrayBuffer}function Mi(e){if(qc(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function fe(e,t){t==null&&(t=e.reduce((s,i)=>s+i.length,0));let r=wt(t),n=0;for(let s of e)r.set(s,n),n+=s.length;return Mi(r)}var qi=Symbol.for("@achingbrain/uint8arraylist");function Ui(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let s=r+n.byteLength;if(t<s)return{buf:n,index:t-r};r=s}throw new RangeError("index is out of bounds")}function _r(e){return!!e?.[qi]}var lt=class e{bufs;length;[qi]=!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(_r(n)){r+=n.byteLength;for(let s of n.bufs)this.bufs.push(s)}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(_r(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=Ui(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Ui(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(_r(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:s}=this._subList(t,r);return fe(n,s)}subarray(t,r){let{bufs:n,length:s}=this._subList(t,r);return n.length===1?n[0]:fe(n,s)}sublist(t,r){let{bufs:n,length:s}=this._subList(t,r),i=new e;return i.length=s,i.bufs=n,i}_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=[],s=0;for(let i=0;i<this.bufs.length;i++){let o=this.bufs[i],a=s,c=a+o.byteLength;if(s=c,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(o);break}let h=t-a;n.push(o.subarray(h,h+(r-t)));break}if(u){if(t===0){n.push(o);continue}n.push(o.subarray(t-a));continue}if(f){if(r===c){n.push(o);break}n.push(o.subarray(0,r-a));break}n.push(o)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!_r(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 s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let h=0;h<i;h++)o[h]=-1;for(let h=0;h<s;h++)o[n[h]]=h;let a=o,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let h=r;h<=c;h+=f){f=0;for(let l=u;l>=0;l--){let d=this.get(h+l);if(n[l]!==d){f=Math.max(1,l-a[d]);break}}if(f===0)return h}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=wt(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 s=Kt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,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 s=Kt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,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 s=Kt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,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=wt(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 s=Kt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,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 s=Kt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,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 s=Kt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,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 s=Kt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,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 s=Kt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,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(!gt(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((s,i)=>s+i.byteLength,0)),n.length=r,n}};var Cn={};yt(Cn,{base10:()=>Hc});var Hc=$t({prefix:"9",name:"base10",alphabet:"0123456789"});var Pn={};yt(Pn,{base16:()=>zc,base16upper:()=>Vc});var zc=it({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Vc=it({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var On={};yt(On,{base2:()=>$c});var $c=it({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var kn={};yt(kn,{base256emoji:()=>Wc});var Hi=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}"),jc=Hi.reduce((e,t,r)=>(e[r]=t,e),[]),Yc=Hi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Zc(e){return e.reduce((t,r)=>(t+=jc[r],t),"")}function Gc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=Yc[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(s)}return new Uint8Array(t)}var Wc=Te({prefix:"\u{1F680}",name:"base256emoji",encode:Zc,decode:Gc});var Nn={};yt(Nn,{base64:()=>Xc,base64pad:()=>Jc,base64url:()=>Qc,base64urlpad:()=>tu});var Xc=it({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Jc=it({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Qc=it({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),tu=it({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Kn={};yt(Kn,{base8:()=>eu});var eu=it({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Fn={};yt(Fn,{identity:()=>ru});var ru=Te({prefix:"\0",name:"identity",encode:e=>Bi(Bt(e)),decode:e=>Bt(Ai(e))});var Th=new TextEncoder,Lh=new TextDecoder;var qn={};yt(qn,{sha256:()=>le,sha512:()=>ou});var iu=20;function Un({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:s}){return new Mn(e,t,r,n,s)}var Mn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,s,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=s??iu,this.maxDigestLength=i}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?zi(n,this.code,r?.truncate):n.then(s=>zi(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function zi(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 Pt(t,e)}function $i(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var le=Un({name:"sha2-256",code:18,encode:$i("SHA-256")}),ou=Un({name:"sha2-512",code:19,encode:$i("SHA-512")});var Hn={...Fn,...On,...Kn,...Cn,...Pn,...Tn,...Ln,...In,...Nn,...kn},Uh={...qn,...Dn};function Yi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ji=Yi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),zn=Yi("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=wt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),au={utf8:ji,"utf-8":ji,hex:Hn.base16,latin1:zn,ascii:zn,binary:zn,...Hn},Rr=au;function Z(e,t="utf8"){let r=Rr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function Y(e,t="utf8"){let r=Rr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var cu=parseInt("11111",2),Vn=parseInt("10000000",2),uu=parseInt("01111111",2),Zi={0:Xe,1:Xe,2:fu,3:du,4:pu,5:hu,6:lu,16:Xe,22:Xe,48:Xe};function Ft(e,t={offset:0}){let r=e[t.offset]&cu;if(t.offset++,Zi[r]!=null)return Zi[r](e,t);throw new Error("No decoder for tag "+r)}function Je(e,t){let r=0;if((e[t.offset]&Vn)===Vn){let n=e[t.offset]&uu,s="0x";t.offset++;for(let i=0;i<n;i++,t.offset++){if(t.offset>=e.byteLength)throw new Error("invalid DER element length");s+=e[t.offset].toString(16).padStart(2,"0")}r=parseInt(s,16)}else r=e[t.offset],t.offset++;if(!Number.isInteger(r)||r<0||r>e.byteLength-t.offset)throw new Error("invalid DER element length");return r}function Xe(e,t){Je(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Ft(e,t);if(n===null)break;r.push(n)}return r}function fu(e,t){let r=Je(e,t),n=t.offset,s=t.offset+r,i=[];for(let o=n;o<s;o++)o===n&&e[o]===0||i.push(e[o]);return t.offset+=r,Uint8Array.from(i)}function lu(e,t){let r=Je(e,t),n=t.offset+r,s=e[t.offset];t.offset++;let i=0,o=0;s<40?(i=0,o=s):s<80?(i=1,o=s-40):(i=2,o=s-80);let a=`${i}.${o}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let h=0;h<c.length;h++)f+=c[h]<<h*7;a+=`.${f}`,c=[]}}return a}function hu(e,t){return t.offset++,null}function du(e,t){let r=Je(e,t),n=e[t.offset];t.offset++;let s=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 s}function pu(e,t){let r=Je(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function mu(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new lt;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=mu(e.byteLength);return new lt(Uint8Array.from([t.byteLength|Vn]),t)}function xt(e){let t=new lt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new lt(Uint8Array.from([2]),$n(t),t)}function Dr(e){let t=Uint8Array.from([0]),r=new lt(t,e);return new lt(Uint8Array.from([3]),$n(r),r)}function Zt(e,t=48){let r=new lt;for(let n of e)r.append(n);return new lt(Uint8Array.from([t]),$n(r),r)}var bu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),yu=Uint8Array.from([6,5,43,129,4,0,34]),gu=Uint8Array.from([6,5,43,129,4,0,35]),wu={ext:!0,kty:"EC",crv:"P-256"},xu={ext:!0,kty:"EC",crv:"P-384"},Eu={ext:!0,kty:"EC",crv:"P-521"},jn=32,Yn=48,Zn=66;function Gn(e){let t=Ft(e);return Gi(t)}function Gi(e){let t=e[1][1][0],r=1,n,s;if(t.byteLength===jn*2+1)return n=Y(t.subarray(r,r+jn),"base64url"),s=Y(t.subarray(r+jn),"base64url"),new Ce({...wu,key_ops:["verify"],x:n,y:s});if(t.byteLength===Yn*2+1)return n=Y(t.subarray(r,r+Yn),"base64url"),s=Y(t.subarray(r+Yn),"base64url"),new Ce({...xu,key_ops:["verify"],x:n,y:s});if(t.byteLength===Zn*2+1)return n=Y(t.subarray(r,r+Zn),"base64url"),s=Y(t.subarray(r+Zn),"base64url"),new Ce({...Eu,key_ops:["verify"],x:n,y:s});throw new et(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Wi(e){return Zt([xt(Uint8Array.from([1])),Zt([Su(e.crv)],160),Zt([Dr(new lt(Uint8Array.from([4]),Z(e.x??"","base64url"),Z(e.y??"","base64url")))],161)]).subarray()}function Su(e){if(e==="P-256")return bu;if(e==="P-384")return yu;if(e==="P-521")return gu;throw new et(`Invalid curve ${e}`)}var Ce=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Wi(this.jwk)),this._raw}toMultihash(){return Rt.digest(Mt(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}async verify(t,r,n){return Fi(this.jwk,r,t,n)}};var Cr=BigInt(4294967295),Xi=BigInt(32);function vu(e,t=!1){return t?{h:Number(e&Cr),l:Number(e>>Xi&Cr)}:{h:Number(e>>Xi&Cr)|0,l:Number(e&Cr)|0}}function Ji(e,t=!1){let r=e.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let i=0;i<r;i++){let{h:o,l:a}=vu(e[i],t);[n[i],s[i]]=[o,a]}return[n,s]}var Au=e=>e/2**32|0,Bu=e=>e>>>0;function Qi(e,t,r,n){let s=Au(r),i=Bu(r);e.setUint32(t,n?i:s,n),e.setUint32(t+4,n?s:i,n)}var Wn=(e,t,r)=>e>>>r,Xn=(e,t,r)=>e<<32-r|t>>>r,he=(e,t,r)=>e>>>r|t<<32-r,de=(e,t,r)=>e<<32-r|t>>>r,Qe=(e,t,r)=>e<<64-r|t>>>r-32,tr=(e,t,r)=>e>>>r-32|t<<64-r;function Ot(e,t,r,n){let s=(t>>>0)+(n>>>0);return{h:e+r+(s/2**32|0)|0,l:s|0}}var to=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),eo=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ro=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),no=(e,t,r,n,s)=>t+r+n+s+(e/2**32|0)|0,so=(e,t,r,n,s)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(s>>>0),io=(e,t,r,n,s,i)=>t+r+n+s+i+(e/2**32|0)|0;function Pr(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}var Jn=e=>e?`"${e}" `:"";function Ut(e,t=""){if(typeof e!="number")throw new TypeError(Jn(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(Jn(t)+"expected integer >= 0, got "+e);return e}function Tt(e,t,r=""){if(Pr(e)&&(t===void 0||e.length===t))return e;t!==void 0&&Ut(t,"length");let n=Pr(e),s=t!==void 0?` of length ${t}`:"",i=n?`length=${e.length}`:`type=${typeof e}`,o=Jn(r)+"expected Uint8Array"+s+", got "+i;throw n?new RangeError(o):new TypeError(o)}function Or(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Ut(e.outputLen),Ut(e.blockLen),e.outputLen<1||e.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Tu=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)},oo=(e,t)=>{Tu(e,t);let r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${t}" expected plain object`);if(Object.hasOwn(e,"__proto__"))throw new TypeError(`"${t}.__proto__" is not allowed`)};function Pe(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function kr(e,t){Tt(e,void 0,"output");let r=t.outputLen;if(!(e.length>=r))throw new RangeError('"output" expected length >= '+r)}function pe(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Nr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Dt(e,t){return e<<32-t|e>>>t}var co=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Lu=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Kr(e){if(Tt(e),co)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Lu[e[r]];return t}function ao(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function Fr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(co)try{return Uint8Array.fromHex(e)}catch(s){throw s instanceof SyntaxError?new RangeError(s.message):s}let t=e.length,r=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let s=0,i=0;s<r;s++,i+=2){let o=ao(e.charCodeAt(i)),a=ao(e.charCodeAt(i+1));if(o===void 0||a===void 0){let c=e[i]+e[i+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+i)}n[s]=o*16+a}return n}function Qn(...e){let t=0;for(let n=0;n<e.length;n++){let s=e[n];Tt(s),t+=s.length}let r=new Uint8Array(t);for(let n=0,s=0;n<e.length;n++){let i=e[n];r.set(i,s),s+=i.length}return r}function _u(e,t,r="opts"){return oo(e,"defaults"),t!==void 0&&oo(t,r),Object.assign(Object.create(null),e,t)}function ts(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=_u({},t,"info");let r=(s,i)=>e(i).update(s).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=s=>e(s),Object.assign(r,t),Object.freeze(r)}function uo(e=32){Ut(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var es=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function fo(e,t,r){return e&t^~e&r}function lo(e,t,r){return e&t^e&r^t&r}var er=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,s){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Nr(this.buffer)}update(t){Pe(this),Tt(t);let{view:r,buffer:n,blockLen:s}=this,i=t.length,o=!1;for(let a=0;a<i;){let c=Math.min(s-this.pos,i-a);if(c===s){let u=Nr(t);for(;s<=i-a;a+=s)this.process(u,a);o=!0;continue}n.set(a===0&&c===i?t:t.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===s&&(this.process(r,0),this.pos=0,o=!0)}return this.length+=t.length,o&&this.roundClean(),this}digestInto(t){Pe(this),kr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;r[o++]=128,r.fill(0,o),this.padOffset>s-o&&(this.process(n,0),r.fill(0)),Qi(n,s-8,this.length*8,i),this.process(n,0),this.roundClean();let a=t===r?n:Nr(t),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let h=0;h<u;h++)a.setUint32(4*h,f[h],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneIntoMeta(t){let{buffer:r,length:n,finished:s,destroyed:i,pos:o}=this;return t.destroyed=i,t.finished=s,t.length=n,t.pos=o,o&&t.buffer.set(r),t}clone(){return this._cloneInto()}},ho=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var po=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Ru=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]),Gt=new Uint32Array(64),rs=class extends er{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(t,r){super(64,t,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:t,B:r,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[t,r,n,s,i,o,a,c]}set(t,r,n,s,i,o,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let h=0;h<16;h++,r+=4)Gt[h]=t.getUint32(r,!1);for(let h=16;h<64;h++){let l=Gt[h-15],d=Gt[h-2],y=Dt(l,7)^Dt(l,18)^l>>>3,g=Dt(d,17)^Dt(d,19)^d>>>10;Gt[h]=g+Gt[h-7]+y+Gt[h-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:u,H:f}=this;for(let h=0;h<64;h++){let l=Dt(a,6)^Dt(a,11)^Dt(a,25),d=f+l+fo(a,c,u)+Ru[h]+Gt[h]|0,g=(Dt(n,2)^Dt(n,13)^Dt(n,22))+lo(n,s,i)|0;f=u,u=c,c=a,a=o+d|0,o=i,i=s,s=n,n=d+g|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,i,o,a,c,u,f)}roundClean(){pe(Gt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),pe(this.buffer)}},ns=class extends rs{constructor(){super(32,ho)}};var mo=Ji(["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))),Du=mo[0],Cu=mo[1],Wt=new Uint32Array(80),Xt=new Uint32Array(80),ss=class extends er{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(t,r){super(128,t,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:u,El:f,Fh:h,Fl:l,Gh:d,Gl:y,Hh:g,Hl:S}=this;return[t,r,n,s,i,o,a,c,u,f,h,l,d,y,g,S]}set(t,r,n,s,i,o,a,c,u,f,h,l,d,y,g,S){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=h|0,this.Fl=l|0,this.Gh=d|0,this.Gl=y|0,this.Hh=g|0,this.Hl=S|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let b=0;b<16;b++,r+=4)Wt[b]=t.getUint32(r),Xt[b]=t.getUint32(r+=4);for(let b=16;b<80;b++){let v=Wt[b-15]|0,A=Xt[b-15]|0,O=he(v,A,1)^he(v,A,8)^Wn(v,A,7),K=de(v,A,1)^de(v,A,8)^Xn(v,A,7),k=Wt[b-2]|0,R=Xt[b-2]|0,C=he(k,R,19)^Qe(k,R,61)^Wn(k,R,6),q=de(k,R,19)^tr(k,R,61)^Xn(k,R,6),U=ro(K,q,Xt[b-7],Xt[b-16]),G=no(U,O,C,Wt[b-7],Wt[b-16]);Wt[b]=G|0,Xt[b]=U|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:u,Dl:f,Eh:h,El:l,Fh:d,Fl:y,Gh:g,Gl:S,Hh:w,Hl:B}=this;for(let b=0;b<80;b++){let v=he(h,l,14)^he(h,l,18)^Qe(h,l,41),A=de(h,l,14)^de(h,l,18)^tr(h,l,41),O=h&d^~h&g,K=l&y^~l&S,k=so(B,A,K,Cu[b],Xt[b]),R=io(k,w,v,O,Du[b],Wt[b]),C=k|0,q=he(n,s,28)^Qe(n,s,34)^Qe(n,s,39),U=de(n,s,28)^tr(n,s,34)^tr(n,s,39),G=n&i^n&a^i&a,T=s&o^s&c^o&c;w=g|0,B=S|0,g=d|0,S=y|0,d=h|0,y=l|0,{h,l}=Ot(u|0,f|0,R|0,C|0),u=a|0,f=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let F=to(C,U,T);n=eo(F,R,q,G),s=F|0}({h:n,l:s}=Ot(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=Ot(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=Ot(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Ot(this.Dh|0,this.Dl|0,u|0,f|0),{h,l}=Ot(this.Eh|0,this.El|0,h|0,l|0),{h:d,l:y}=Ot(this.Fh|0,this.Fl|0,d|0,y|0),{h:g,l:S}=Ot(this.Gh|0,this.Gl|0,g|0,S|0),{h:w,l:B}=Ot(this.Hh|0,this.Hl|0,w|0,B|0),this.set(n,s,i,o,a,c,u,f,h,l,d,y,g,S,w,B)}roundClean(){pe(Wt,Xt)}destroy(){this.destroyed=!0,pe(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},is=class extends ss{constructor(){super(64,po)}};var Oe=ts(()=>new ns,es(1));var os=ts(()=>new is,es(3));function Ur(e,t,r=()=>{}){if(!Array.isArray(e))throw new TypeError(`"${t}" expected array, got type=${typeof e}`);for(let n=0;n<e.length;n++)r(e[n],`${t}[${n}]`);return e}var V=(e,t,r)=>Tt(e,t,r),as=Ut;function yo(e,t=""){if(typeof e!="string"){let r=t&&`"${t}" `;throw new TypeError(r+"expected string, got type="+typeof e)}return e}function Jt(e,t="object"){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(t==="object"?"expected valid options object":`"${t}" expected object, got type=${typeof e}`);return e}function me(e,t){if(typeof e!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}var rr=Kr,Lt=(...e)=>Qn(...e),ke=e=>Fr(e),te=Pr,be=e=>uo(e),Mr=BigInt(0),bo=BigInt(1),Pu=e=>e?`"${e}" `:"";function Et(e,t=""){if(typeof e!="boolean")throw new TypeError(Pu(t)+"expected boolean, got type="+typeof e);return e}function qr(e){if(typeof e=="bigint"){if(!Qt(e))throw new RangeError("positive bigint expected, got "+e)}else as(e);return e}function qt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function nr(e){let t=qr(e).toString(16);return t.length&1?"0"+t:t}function go(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?Mr:BigInt("0x"+e)}function kt(e){return go(Kr(e))}function ye(e){return go(Kr(sr(Tt(e)).reverse()))}function Hr(e,t){if(Ut(t),t===0)throw new Error("zero output length is invalid");e=qr(e);let r=t*2,n=e.toString(16);if(n.length>r)throw new RangeError("number is too large");return Fr(n.padStart(r,"0"))}function cs(e,t){return Hr(e,t).reverse()}function sr(e){return Uint8Array.from(V(e))}function Qt(e){return typeof e=="bigint"&&Mr<=e}function us(e,t,r){return Qt(e)&&Qt(t)&&Qt(r)&&t<=e&&e<r}function Ne(e,t,r,n){if(!us(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ke(e){if(e<Mr)throw new Error("expected non-negative bigint, got "+e);return e===Mr?0:e.toString(2).length}var ir=e=>(qt(e,"n"),(bo<<BigInt(e))-bo);function wo(e,t,r){if(Ut(e,"hashLen"),Ut(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=S=>new Uint8Array(S),s=Uint8Array.of(),i=Uint8Array.of(0),o=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,h=()=>{c.fill(1),u.fill(0),f=0},l=(...S)=>r(u,Lt(c,...S)),d=(S=s)=>{u=l(i,S),c=l(),S.length!==0&&(u=l(o,S),c=l())},y=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let S=0,w=[];for(;S<t;){c=l();let B=c.slice();w.push(B),S+=c.length}return Lt(...w)};return(S,w)=>{h(),d(S);let B;for(;(B=w(y()))===void 0;)d();return h(),B}}function St(e,t={},r={},n="object"){Jt(e,n),Jt(t,"fields"),Jt(r,"optFields");function s(o,a,c){let u=n==="object"?`param "${String(o)}"`:`"${n}.${String(o)}"`,f=e[o];if(!Object.hasOwn(e,o)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let h=typeof f;if(h!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${h}`)}let i=(o,a)=>Object.entries(o).forEach(([c,u])=>s(c,u,a));i(t,!1),i(r,!0)}var ut=BigInt(0),$=BigInt(1),ee=BigInt(2),So=BigInt(3),fs=BigInt(4),vo=BigInt(5),Ou=BigInt(7),Ao=BigInt(8),ku=BigInt(9),Nu=BigInt(15),Bo=BigInt(16),Ku=BigInt("0x10000000000000000");function nt(e,t){if(t<=ut)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=ut?r:t+r}function Io(e,t,r){if(r<=$)throw new Error("pow: expected modulus > 1, got "+r);if(typeof t!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof t);if(t<ut)throw new Error("invalid exponent, negatives unsupported");if(t===ut)return $;if(t===$)return e;let n=e%r;if(n<ut&&(n+=r),t<Ku){let a=$;for(;t>ut;)t&$&&(a=a*n%r),n=n*n%r,t>>=$;return a}let s=[];for(;t>ut;)s.push(Number(t&Nu)),t>>=fs;let i=new Array(16);i[0]=$,i[1]=n;for(let a=2;a<16;a++)i[a]=i[a-1]*n%r;let o=i[s[s.length-1]];for(let a=s.length-2;a>=0;a--){o=o*o%r,o=o*o%r,o=o*o%r,o=o*o%r;let c=s[a];c!==0&&(o=o*i[c]%r)}return o}function Q(e,t,r){if(r<=$)throw new Error("pow2: expected modulus > 1, got "+r);if(t<ut)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >ut;)n*=n,n%=r;return n}function xo(e,t){if(e===ut)throw new Error("invert: expected non-zero number");if(t<=$)throw new Error("invert: expected modulus > 1, got "+t);let r=nt(e,t),n=t,s=ut,i=$;for(;r!==ut;){let a=n/r,c=n-r*a,u=s-i*a;n=r,r=c,s=i,i=u}if(n!==$)throw new Error("invert: does not exist");return nt(s,t)}function To(e,t){if(t<=$)throw new Error("invertCt: expected prime modulus > 1, got "+t);let r=nt(e,t);if(r===ut)throw new Error("invertCt: expected non-zero number");let n=Io(r,t-ee,t);if(nt(r*n,t)!==$)throw new Error("invertCt: does not exist");return n}function ls(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function hs(e,t){if((e&$)===ut)throw new Error(t+": expected odd modulus, got "+e)}function Lo(e,t){let r=e,n=(r.ORDER+$)/fs,s=r.pow(t,n);return ls(r,s,t),s}function Fu(e,t){let r=e,n=(r.ORDER-vo)/Ao,s=r.mul(t,ee),i=r.pow(s,n),o=r.mul(t,i),a=r.mul(r.mul(o,ee),i),c=r.mul(o,r.sub(a,r.ONE));return ls(r,c,t),c}function Mu(e){let t=Me(e),r=_o(e),n=r(t,t.neg(t.ONE)),s=r(t,n),i=r(t,t.neg(n)),o=(e+Ou)/Bo;return((a,c)=>{let u=a,f=u.pow(c,o),h=u.mul(f,n),l=u.mul(f,s),d=u.mul(f,i),y=u.eql(u.sqr(h),c),g=u.eql(u.sqr(l),c);f=u.cmov(f,h,y),h=u.cmov(d,l,g);let S=u.eql(u.sqr(h),c),w=u.cmov(f,h,S);return ls(u,w,c),w})}function _o(e){if(e<So)throw new Error("sqrt is not defined for small field");hs(e,"tonelliShanks");let t=e-$,r=0;for(;t%ee===ut;)t/=ee,r++;let n=ee,s=Me(e);for(;or(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Lo;let i=s.pow(n,t),o=(t+$)/ee;return function(c,u){let f=c;if(f.is0(u))return u;if(or(f,u)!==1)throw new Error("Cannot find square root");let h=r,l=f.mul(f.ONE,i),d=f.pow(u,t),y=f.pow(u,o);for(;!f.eql(d,f.ONE);){if(f.is0(d))throw new Error("Cannot find square root: probably non-prime P");let g=1,S=f.sqr(d);for(;!f.eql(S,f.ONE);)if(g++,S=f.sqr(S),g===h)throw new Error("Cannot find square root");let w=$<<BigInt(h-g-1),B=f.pow(l,w);h=g,l=f.sqr(B),d=f.mul(d,l),y=f.mul(y,B)}return y}}function Uu(e){return hs(e,"Fp.sqrt"),e%fs===So?Lo:e%Ao===vo?Fu:e%Bo===ku?Mu(e):_o(e)}var Ro=(e,t)=>(nt(e,t)&$)===$,qu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Fe(e){if(Jt(e,"field"),typeof e.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof e.ORDER);qt(e.BYTES,"BYTES"),qt(e.BITS,"BITS");for(let t of qu)me(e[t],"field."+t);if(e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=$)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function Vr(e,t,r=!1){Fe(e),Ur(t,"nums"),Et(r,"passZero");let n=e,s=new Array(t.length).fill(r?n.ZERO:void 0),i=t.reduce((a,c,u)=>n.is0(c)?a:(s[u]=a,n.mul(a,c)),n.ONE),o=n.inv(i);return t.reduceRight((a,c,u)=>n.is0(c)?a:(s[u]=n.mul(a,s[u]),n.mul(a,c)),o),s}function or(e,t){Fe(e);let r=e;hs(r.ORDER,"FpLegendre");let n=(r.ORDER-$)/ee,s=r.pow(t,n),i=r.eql(s,r.ONE),o=r.eql(s,r.ZERO),a=r.eql(s,r.neg(r.ONE));if(!i&&!o&&!a)throw new Error("invalid Legendre symbol result");return i?1:o?0:-1}function Hu(e,t){if(t!==void 0&&as(t),e<=ut)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=Ke(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${r})`);let n=t!==void 0?t:r,s=Math.ceil(n/8);return{nBitLength:n,nByteLength:s}}var Eo=new WeakMap,zr=class{ORDER;BITS;BYTES;isLE;ZERO=ut;ONE=$;_lengths;_mod;constructor(t,r={}){if(t<=$)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:s,nByteLength:i}=Hu(t,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=s,this.BYTES=i,Object.freeze(this)}create(t){return nt(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return ut<=t&&t<this.ORDER}is0(t){return t===ut}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&$)===$}neg(t){return nt(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return nt(t*t,this.ORDER)}add(t,r){return nt(t+r,this.ORDER)}sub(t,r){return nt(t-r,this.ORDER)}mul(t,r){return nt(t*r,this.ORDER)}pow(t,r){return Io(t,r,this.ORDER)}div(t,r){return nt(t*xo(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return xo(t,this.ORDER)}sqrt(t){let r=Eo.get(this);return r||Eo.set(this,r=Uu(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?cs(t,this.BYTES):Hr(t,this.BYTES)}fromBytes(t,r=!1){V(t);let{_lengths:n,BYTES:s,isLE:i,ORDER:o,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(s);u.set(t,i?0:u.length-t.length),t=u}if(t.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);let c=i?ye(t):kt(t);if(a&&(c=nt(c,o)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Vr(this,t,!0)}cmov(t,r,n){return Et(n,"condition"),n?r:t}};function Me(e,t={}){return Object.freeze(zr.prototype),new zr(e,t)}function Do(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=$)throw new Error("field order must be greater than 1");let t=Ke(e-$);return Math.ceil(t/8)}function $r(e){let t=Do(e);return t+Math.ceil(t/2)}function jr(e,t,r=!1){V(e);let n=e.length,s=Do(t),i=Math.max($r(t),16);if(n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let o=r?ye(e):kt(e),a=nt(o,t-$)+$;return r?cs(a,s):Hr(a,s)}var ms=BigInt(0),ar=BigInt(1),zu=BigInt(4),ds=16,Co=128,Vu=5,Po=2**31;function re(e){let t=e;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof e);me(t.fromAffine,"Point.fromAffine"),me(t.fromBytes,"Point.fromBytes"),me(t.fromHex,"Point.fromHex"),Jt(t.BASE,"Point.BASE"),Jt(t.ZERO,"Point.ZERO"),Fe(t.Fp),Fe(t.Fn)}function Yr(e,t){re(e),ko(t,e);let r=Vr(e.Fp,t.map(n=>n.Z));return t.map((n,s)=>e.fromAffine(n.toAffine(r[s])))}function $u(e,t,r=1){if(!Number.isSafeInteger(e)||e<r||e>t)throw new Error("invalid window size, expected ["+r+".."+t+"], got W="+e)}function ju(e,t){let r=e*(4*t+128);if(r>Po)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+Po/2**20+" MiB")}function bs(e,t){if(e!==void 0){me(e,"randomBytes");try{let r=e(t);if(!te(r)||r.length!==t)return}catch{return}return e}}function ko(e,t){Ur(e,"points"),e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Yu(e,t,r){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((n,s)=>{if(!(r===void 0?t.isValid(n):Qt(n)&&n<r))throw new Error("invalid scalar at index "+s)})}var No=new WeakMap;function ps(e){return No.get(e)||1}function Zu(e,t){let r=e.double(),n=[e];for(let s=1;s<t;s++)n.push(n[s-1].add(r));return n}function Gu(e,t){let r=2**t,n=r/2,s=BigInt(r-1),i=[];for(;e>ms;){let o=0;e&ar&&(o=Number(e&s),o>=n&&(o-=r),e-=BigInt(o)),i.push(o),e>>=ar}return i}function Wu(e,t,r){let n=2**t,s=n/2,i=BigInt(n-1),o=BigInt(t),a=[];for(let c=0;c<r;c++){let u=Number(e&i);e>>=o,u>s&&(u-=n,e+=ar),a.push(u)}if(e!==ms)throw new Error("invalid wnaf");return a}function Xu(e,t,r){let n=0;for(let i of r)n=Math.max(n,i.length);let s=e;for(let i=n-1;i>=0;i--){i!==n-1&&(s=s.double());for(let o=0;o<r.length;o++){let a=r[o][i];if(a){let c=t[o][Math.abs(a)-1>>1];s=s.add(a<0?c.negate():c)}}}return s}var Ue=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,r){re(t),this.randomBytes=bs(r,ds),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,r,n){let s=Math.ceil(n/r)+1,i=2**(r-1),o=[],a=t;for(let c=0;c<s;c++){let u=a;for(let f=0;f<i;f++)o.push(u),u=u.add(a);a=o[o.length-1].double()}return{W:r,bits:n,windows:s,comp:o}}wnafCachedCT(t,r){let{W:n,windows:s,comp:i}=t,o=2**(n-1),a=Wu(r,n,s),c=this.ZERO,u=this.BASE;for(let f=0;f<s;f++){let h=a[f],l=f*o,d=Math.abs(h)-1,y=i[l];for(let S=1;S<o;S++)y=S===d?i[l+S]:y;let g=y.negate();h===0?u=u.add(i[l]):c=c.add(h<0?g:y)}return{p:c,f:u}}getWnafPrecomputes(t,r,n,s){let i=this.wnafPrecomputes.get(r),o=i?.find(a=>a.W===t&&a.bits===n);return o||(o=this.buildWnafTable(r,t,n),typeof s=="function"&&(o={...o,comp:s(o.comp)}),i||(i=[],this.wnafPrecomputes.set(r,i)),i.push(o)),o}assertPoint(t){if(!(t instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof t)}validateMulInput(t,r){if(this.assertPoint(t),!us(r,ar,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,r,n,s){let i=ps(t);return i===1?this.fixedWindowCT(t,r,n):this.wnafCachedCT(this.getWnafPrecomputes(i,t,n,s),r)}mulCT(t,r,n){return this.validateMulInput(t,r),this.runCT(t,r,this.bits,n)}mulCTBlinded(t,r,n){if(this.validateMulInput(t,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let s=this.Point.Fn.BITS+Co,i=this.randomBytes(ds);if(!te(i)||i.length!==ds)throw new Error("randomBytes returned invalid byte array");i[0]=i[0]&63|128;let o=r+kt(i)*this.Point.Fn.ORDER;return this.runCT(t,o,s,n)}fixedWindowCT(t,r,n){let s=Vu,i=1<<s,o=ir(s),a=new Array(i);a[0]=this.ZERO;for(let f=1;f<i;f++)a[f]=a[f-1].add(t);let c=Math.ceil(n/s),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let d=0;d<s;d++)u=u.double();let h=Number(r>>BigInt(f*s)&o),l=a[0];for(let d=1;d<i;d++)l=d===h?a[d]:l;u=u.add(l)}return{p:u,f:u}}shouldBlind(t,r){return this.randomBytes===void 0?!1:r===ar?!0:t!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(t,r,n,s){return this.shouldBlind(t,n)?this.mulCTBlinded(t,r,s):this.mulCT(t,r,s)}mulUnsafe(t,r,n){if(this.assertPoint(t),!Qt(r))throw new Error("invalid scalar");let s=ps(t);if(s===1||r>=this.Point.Fn.ORDER)return Zr(this.Point,[t],[r],!0);let i=this.getWnafPrecomputes(s,t,this.bits,n);return this.wnafCachedCT(i,r).p}setWindowSize(t,r){this.assertPoint(t),$u(r,this.bits);let n=Math.ceil((this.bits+Co)/r)+1;ju(n*2**(r-1),this.Point.Fp.BYTES),No.set(t,r),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return ps(t)!==1}};function Zr(e,t,r,n=!1){if(re(e),ko(t,e),Et(n,"allowOversized"),Yu(r,e.Fn,n?e.Fn.ORDER**zu:void 0),t.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let s=t.map(o=>Zu(o,4)),i=r.map(o=>Gu(o,4));return Xu(e.ZERO,s,i)}function Oo(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Fe(t),t}else return Me(e,{isLE:r})}function Gr(e,t,r={},n){if(e!=="weierstrass"&&e!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);St(r);for(let c of["p","n","h"]){let u=t[c];if(!(Qt(u)&&u!==ms))throw new Error(`CURVE.${c} must be positive bigint`)}let s=Oo(t.p,r.Fp,n),i=Oo(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:s,Fn:i}}function Wr(e,t){return function(n){let s=e(n);return{secretKey:s,publicKey:t(s)}}}var Xr=BigInt(0),Jr=BigInt(1),Qr=BigInt(2),Ju=BigInt(4),Ko=BigInt(8);function Qu(e,t,r,n){let s=e.sqr(r),i=e.sqr(n),o=e.add(e.mul(t.a,s),i),a=e.add(e.ONE,e.mul(t.d,e.mul(s,i)));return e.eql(o,a)}function Fo(e,t={}){St(t,{},{},"extraOpts");let r=t,n=Gr("edwards",e,r,r.FpFnLE),{Fp:s,Fn:i}=n,o=n.CURVE,{h:a}=o;if(or(s,o.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(or(s,o.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");St(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?be:r.randomBytes,u=Qr<<BigInt(s.BYTES*8)-Jr;function f(B){if(!s.isOdd)throw new Error("Field does not have .isOdd()");return s.isOdd(B)}let h=r.uvRatio===void 0?(B,b)=>{try{return{isValid:!0,value:s.sqrt(s.div(B,b))}}catch{return{isValid:!1,value:Xr}}}:r.uvRatio;if(!Qu(s,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");let l=s.eql(o.a,s.neg(s.ONE))?B=>s.neg(B):s.eql(o.a,s.ONE)?B=>B:B=>s.mul(o.a,B);function d(B,b,v=!1){let A=v?Jr:Xr;return Ne("coordinate "+B,b,A,u),b}function y(B){if(!(B instanceof g))throw new Error("EdwardsPoint expected")}class g{static BASE=new g(o.Gx,o.Gy,s.ONE,s.mul(o.Gx,o.Gy));static ZERO=new g(s.ZERO,s.ONE,s.ONE,s.ZERO);static Fp=s;static Fn=i;X;Y;Z;T;constructor(b,v,A,O){this.X=d("x",b),this.Y=d("y",v),this.Z=d("z",A,!0),this.T=d("t",O),Object.freeze(this)}static CURVE(){return o}static fromAffine(b){if(b instanceof g)throw new Error("extended point not allowed");let{x:v,y:A}=b||{};return d("x",v),d("y",A),new g(v,A,s.ONE,s.mul(v,A))}static fromBytes(b,v=!1){let A=s.BYTES,{a:O,d:K}=o;b=sr(V(b,A,"point")),Et(v,"zip215");let k=sr(b),R=b[A-1];k[A-1]=R&-129;let C=ye(k),q=v?u:s.ORDER;Ne("point.y",C,Xr,q);let U=s.sqr(C),G=s.sub(U,s.ONE),T=s.sub(s.mulN(K,U),O),{isValid:F,value:M}=h(G,T);if(!F)throw new Error("bad point: invalid y coordinate");let D=f(M),W=(R&128)!==0;if(!v&&s.is0(M)&&W)throw new Error("bad point: x=0 and x_0=1");return W!==D&&(M=s.neg(M)),g.fromAffine({x:M,y:C})}static fromHex(b,v=!1){return g.fromBytes(ke(b),v)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=6,v=!0){return w.setWindowSize(this,b),v||this.multiply(Qr),this}assertValidity(){let b=this,{a:v,d:A}=o;if(b.is0())throw new Error("bad point: ZERO");let{X:O,Y:K,Z:k,T:R}=b,C=s.sqr(O),q=s.sqr(K),U=s.sqr(k),G=s.sqr(U),T=s.mul(C,v),F=s.mul(s.add(T,q),U),M=s.add(G,s.mul(A,s.mul(C,q)));if(!s.eql(F,M))throw new Error("bad point: equation left != right (1)");let D=s.mul(O,K),W=s.mul(k,R);if(!s.eql(D,W))throw new Error("bad point: equation left != right (2)")}equals(b){y(b);let{X:v,Y:A,Z:O}=this,{X:K,Y:k,Z:R}=b,C=s.mul(v,R),q=s.mul(K,O),U=s.mul(A,R),G=s.mul(k,O);return s.eql(C,q)&&s.eql(U,G)}is0(){return this.equals(g.ZERO)}negate(){return new g(s.neg(this.X),this.Y,this.Z,s.neg(this.T))}double(){let{X:b,Y:v,Z:A}=this,O=s.sqr(b),K=s.sqr(v),k=s.mul(s.sqr(A),Qr),R=l(O),C=s.addN(b,v),q=s.sub(s.subN(s.sqr(C),O),K),U=s.addN(R,K),G=s.subN(U,k),T=s.subN(R,K),F=s.mul(q,G),M=s.mul(U,T),D=s.mul(q,T),W=s.mul(G,U);return new g(F,M,W,D)}add(b){y(b);let{d:v}=o,{X:A,Y:O,Z:K,T:k}=this,{X:R,Y:C,Z:q,T:U}=b,G=s.mul(A,R),T=s.mul(O,C),F=s.mul(s.mulN(k,v),U),M=s.mul(K,q),D=s.sub(s.subN(s.mulN(s.addN(A,O),s.addN(R,C)),G),T),W=s.subN(M,F),tt=s.addN(M,F),E=s.sub(T,l(G)),p=s.mul(D,W),m=s.mul(tt,E),x=s.mul(D,E),I=s.mul(W,tt);return new g(p,m,I,x)}subtract(b){return y(b),this.add(b.negate())}multiply(b){if(!i.isValidNot0(b))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:v,f:A}=w.mulSecret(this,b,a,S);return S([v,A])[0]}multiplyUnsafe(b){if(!i.isValid(b))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return b===Xr?g.ZERO:this.is0()||b===Jr?this:w.mulUnsafe(this,b,S)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return w.mulUnsafe(this,o.n).is0()}toAffine(b){let v=this,A=b;if(A!=null&&typeof A!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof A);let{X:O,Y:K,Z:k}=v,R=v.is0();A==null&&(A=R?s.create(Ko):s.inv(k));let C=s.mul(O,A),q=s.mul(K,A),U=s.mul(k,A);if(R)return{x:s.ZERO,y:s.ONE};if(!s.eql(U,s.ONE))throw new Error("invZ was invalid");return{x:C,y:q}}clearCofactor(){return a===Jr?this:a===Qr?this.double():a===Ju?this.double().double():a===Ko?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:b,y:v}=this.toAffine(),A=s.toBytes(v);return A[A.length-1]|=f(b)?128:0,A}toHex(){return rr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let S=B=>Yr(g,B),w=new Ue(g,c);return w.bits>=6&&g.BASE.precompute(6),Object.freeze(g.prototype),Object.freeze(g),g}function Mo(e,t,r={}){if(re(e),typeof t!="function")throw new Error('"hash" function param is required');let n=t,s=r;St(s,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:i}=s,{BASE:o,Fp:a,Fn:c}=e,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(qt(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let h=s.randomBytes===void 0?be:s.randomBytes,l=s.toMontgomery,d=s.toMontgomerySecret,y=s.adjustScalarBytes===void 0?T=>T:s.adjustScalarBytes,g=s.domain===void 0?(T,F,M)=>{if(Et(M,"phflag"),F.length||M)throw new Error("Contexts/pre-hash are not supported");return T}:s.domain;function S(T){return c.create(ye(T))}function w(T){let F=R.secretKey;V(T,R.secretKey,"secretKey");let M=V(n(T),2*F,"hashedSecretKey"),D=y(M.slice(0,F)),W=M.slice(F,2*F),tt=S(D);return{head:D,prefix:W,scalar:tt}}function B(T){let{head:F,prefix:M,scalar:D}=w(T),W=o.multiply(D),tt=W.toBytes();return{head:F,prefix:M,scalar:D,point:W,pointBytes:tt}}function b(T){return B(T).pointBytes}function v(T=Uint8Array.of(),...F){let M=Lt(...F);return S(n(g(M,V(T,void 0,"context"),!!i)))}function A(T,F,M={}){St(M,{},{},"options"),T=sr(V(T,void 0,"message")),i&&(T=i(T));let{prefix:D,scalar:W,pointBytes:tt}=B(F),E=v(M.context,D,T),p=o.multiply(E).toBytes(),m=v(M.context,p,tt,T),x=c.create(E+m*W);if(!c.isValid(x))throw new Error("sign failed: invalid s");let I=Lt(p,c.toBytes(x));return V(I,R.signature,"result")}let O={zip215:s.zip215};function K(T,F,M,D=O){St(D);let{context:W}=D,tt=D.zip215===void 0?!!O.zip215:D.zip215,E=R.signature;T=V(T,E,"signature"),F=V(F,void 0,"message"),M=V(M,R.publicKey,"publicKey"),tt!==void 0&&Et(tt,"zip215"),i&&(F=i(F));let p=E/2,m=T.subarray(0,p),x=ye(T.subarray(p,E)),I,L,_;try{I=e.fromBytes(M,tt),L=e.fromBytes(m,tt),_=o.multiplyUnsafe(x)}catch{return!1}if(!tt&&I.isSmallOrder())return!1;let P=v(W,m,M,F);return L.add(I.multiplyUnsafe(P)).subtract(_).clearCofactor().is0()}let k=a.BYTES,R={secretKey:k,publicKey:k,signature:2*k,seed:k};function C(T){return T=T===void 0?h(R.seed):T,V(T,R.seed,"seed")}function q(T){return te(T)&&T.length===R.secretKey}function U(T,F){try{return!!e.fromBytes(T,F===void 0?O.zip215:F)}catch{return!1}}let G={getExtendedPublicKey:B,randomSecretKey:C,isValidSecretKey:q,isValidPublicKey:U,toMontgomery(T){if(l===void 0)throw new Error("Montgomery conversion is not supported for this curve");return l(e.fromBytes(T))},toMontgomerySecret(T){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(T)}};return Object.freeze(R),Object.freeze(G),Object.freeze({keygen:Wr(C,b),getPublicKey:b,sign:A,verify:K,utils:G,Point:e,lengths:R})}var ys=BigInt(1),Uo=BigInt(2);var tf=BigInt(5),ef=BigInt(8),gs=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),rf={p:gs,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:ef,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function nf(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),i=gs,a=e*e%i*e%i,c=Q(a,Uo,i)*a%i,u=Q(c,ys,i)*e%i,f=Q(u,tf,i)*u%i,h=Q(f,t,i)*f%i,l=Q(h,r,i)*h%i,d=Q(l,n,i)*l%i,y=Q(d,s,i)*d%i,g=Q(y,s,i)*d%i,S=Q(g,t,i)*f%i;return{pow_p_5_8:Q(S,Uo,i)*e%i,b2:a}}function zo(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var qo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function sf(e,t){let r=gs,n=nt(t*t*t,r),s=nt(n*n*t,r),i=nf(e*s).pow_p_5_8,o=nt(e*n*i,r),a=nt(t*o*o,r),c=o,u=nt(o*qo,r),f=a===e,h=a===nt(-e,r),l=a===nt(-e*qo,r);return f&&(o=c),(h||l)&&(o=u),Ro(o,r)&&(o=nt(-o,r)),{isValid:f||h,value:o}}var ws=Fo(rf,{uvRatio:sf}),Ho=ws.Fp;function of(e){let{y:t}=e;return Ho.toBytes(Ho.div(ys+t,ys-t))}function af(e){let t=ws.Fp.BYTES;return Tt(e,t),zo(os(e.subarray(0,t))).subarray(0,t)}function cf(e){return Mo(ws,os,Object.assign({adjustScalarBytes:zo,toMontgomery:of,toMontgomerySecret:af,zip215:!0},e))}var Vo=cf({});var cr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},tn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var _t={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new tn("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 en=32;var xs,uf=(async()=>{try{return await _t.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function ff(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await _t.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await _t.get().subtle.verify({name:"Ed25519"},n,It(t),It(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function lf(e,t,r){return Vo.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function $o(e,t,r){return xs==null&&(xs=await uf),xs?ff(e,t,r):lf(e,t,r)}function rn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var nn=class{type="Ed25519";raw;constructor(t){this.raw=Es(t,en)}toMultihash(){return Rt.digest(Mt(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let s=$o(this.raw,r,t);return rn(s)?s.then(i=>(n?.signal?.throwIfAborted(),i)):s}};function Ss(e){return e=Es(e,en),new nn(e)}function Es(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new et(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var df=Math.pow(2,7),pf=Math.pow(2,14),mf=Math.pow(2,21),vs=Math.pow(2,28),As=Math.pow(2,35),Bs=Math.pow(2,42),Is=Math.pow(2,49),j=128,dt=127;function Ht(e){if(e<df)return 1;if(e<pf)return 2;if(e<mf)return 3;if(e<vs)return 4;if(e<As)return 5;if(e<Bs)return 6;if(e<Is)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ts(e,t,r=0){switch(Ht(e)){case 8:t[r++]=e&255|j,e/=128;case 7:t[r++]=e&255|j,e/=128;case 6:t[r++]=e&255|j,e/=128;case 5:t[r++]=e&255|j,e/=128;case 4:t[r++]=e&255|j,e>>>=7;case 3:t[r++]=e&255|j,e>>>=7;case 2:t[r++]=e&255|j,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function bf(e,t,r=0){switch(Ht(e)){case 8:t.set(r++,e&255|j),e/=128;case 7:t.set(r++,e&255|j),e/=128;case 6:t.set(r++,e&255|j),e/=128;case 5:t.set(r++,e&255|j),e/=128;case 4:t.set(r++,e&255|j),e>>>=7;case 3:t.set(r++,e&255|j),e>>>=7;case 2:t.set(r++,e&255|j),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function Ls(e,t){let r=e[t],n=0;if(n+=r&dt,r<j||(r=e[t+1],n+=(r&dt)<<7,r<j)||(r=e[t+2],n+=(r&dt)<<14,r<j)||(r=e[t+3],n+=(r&dt)<<21,r<j)||(r=e[t+4],n+=(r&dt)*vs,r<j)||(r=e[t+5],n+=(r&dt)*As,r<j)||(r=e[t+6],n+=(r&dt)*Bs,r<j)||(r=e[t+7],n+=(r&dt)*Is,r<j))return n;throw new RangeError("Could not decode varint")}function yf(e,t){let r=e.get(t),n=0;if(n+=r&dt,r<j||(r=e.get(t+1),n+=(r&dt)<<7,r<j)||(r=e.get(t+2),n+=(r&dt)<<14,r<j)||(r=e.get(t+3),n+=(r&dt)<<21,r<j)||(r=e.get(t+4),n+=(r&dt)*vs,r<j)||(r=e.get(t+5),n+=(r&dt)*As,r<j)||(r=e.get(t+6),n+=(r&dt)*Bs,r<j)||(r=e.get(t+7),n+=(r&dt)*Is,r<j))return n;throw new RangeError("Could not decode varint")}function Yo(e,t,r=0){return t==null&&(t=wt(Ht(e))),t instanceof Uint8Array?Ts(e,t,r):bf(e,t,r)}function Zo(e,t=0){return e instanceof Uint8Array?Ls(e,t):yf(e,t)}var _s=new Float32Array([-0]),ne=new Uint8Array(_s.buffer);function Go(e,t,r){_s[0]=e,t[r]=ne[0],t[r+1]=ne[1],t[r+2]=ne[2],t[r+3]=ne[3]}function Wo(e,t){return ne[0]=e[t],ne[1]=e[t+1],ne[2]=e[t+2],ne[3]=e[t+3],_s[0]}var Rs=new Float64Array([-0]),pt=new Uint8Array(Rs.buffer);function Xo(e,t,r){Rs[0]=e,t[r]=pt[0],t[r+1]=pt[1],t[r+2]=pt[2],t[r+3]=pt[3],t[r+4]=pt[4],t[r+5]=pt[5],t[r+6]=pt[6],t[r+7]=pt[7]}function Jo(e,t){return pt[0]=e[t],pt[1]=e[t+1],pt[2]=e[t+2],pt[3]=e[t+3],pt[4]=e[t+4],pt[5]=e[t+5],pt[6]=e[t+6],pt[7]=e[t+7],Rs[0]}var wf=BigInt(Number.MAX_SAFE_INTEGER),xf=BigInt(Number.MIN_SAFE_INTEGER),vt=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<wf&&t>xf)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,s=t-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>Qo&&(s=0n,++n>Qo&&(n=0n))),new e(Number(s),Number(n))}static fromNumber(t){if(t===0)return ge;let r=t<0;r&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new e(n,s)}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 vt(0,0);ge.toBigInt=function(){return 0n};ge.zzEncode=ge.zzDecode=function(){return this};ge.length=function(){return 1};var Qo=4294967296n;function ta(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 ea(e,t,r){if(r-t<1)return"";let s,i=[],o=0,a;for(;t<r;)a=e[t++],a<128?i[o++]=a:a>191&&a<224?i[o++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,i[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,o>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,i)),o=0);return s!=null?(o>0&&s.push(String.fromCharCode.apply(String,i.slice(0,o))),s.join("")):String.fromCharCode.apply(String,i.slice(0,o))}function Ds(e,t,r){let n=r,s,i;for(let o=0;o<e.length;++o)s=e.charCodeAt(o),s<128?t[r++]=s:s<2048?(t[r++]=s>>6|192,t[r++]=s&63|128):(s&64512)===55296&&((i=e.charCodeAt(o+1))&64512)===56320?(s=65536+((s&1023)<<10)+(i&1023),++o,t[r++]=s>>18|240,t[r++]=s>>12&63|128,t[r++]=s>>6&63|128,t[r++]=s&63|128):(t[r++]=s>>12|224,t[r++]=s>>6&63|128,t[r++]=s&63|128);return r-n}function Ct(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function sn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Cs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=It(t),this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Ct(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ct(this,4);return sn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ct(this,4);return sn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ct(this,4);let t=Wo(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ct(this,4);let t=Jo(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 Ct(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return ea(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ct(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ct(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new vt(0,0),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 Ct(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 Ct(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 Ct(this,8);let t=sn(this.buf,this.pos+=4),r=sn(this.buf,this.pos+=4);return new vt(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=Ls(this.buf,this.pos);return this.pos+=Ht(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 ur(e){return new Cs(e instanceof Uint8Array?e:e.subarray())}function se(e,t,r){let n=ur(e);return t.decode(n,void 0,r)}function Ps(e){let t=e??8192,r=t>>>1,n,s=t;return function(o){if(o<1||o>r)return wt(o);s+o>t&&(n=wt(t),s=0);let a=n.subarray(s,s+=o);return(s&7)!==0&&(s=(s|7)+1),a}}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 Os(){}var Ns=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Ef=Ps();function Sf(e){return globalThis.Buffer!=null?wt(e):Ef(e)}var lr=class{len;head;tail;states;constructor(){this.len=0,this.head=new we(Os,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 Ks((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(on,10,vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=vt.fromBigInt(t);return this._push(on,r.length(),r)}uint64Number(t){return this._push(Ts,Ht(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=vt.fromBigInt(t).zzEncode();return this._push(on,r.length(),r)}sint64Number(t){let r=vt.fromNumber(t).zzEncode();return this._push(on,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(ks,1,t?1:0)}fixed32(t){return this._push(fr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=vt.fromBigInt(t);return this._push(fr,4,r.lo)._push(fr,4,r.hi)}fixed64Number(t){let r=vt.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(Go,4,t)}double(t){return this._push(Xo,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(ks,1,0):this.uint32(r)._push(Af,r,t)}string(t){let r=ta(t);return r!==0?this.uint32(r)._push(Ds,r,t):this._push(ks,1,0)}fork(){return this.states=new Ns(this),this.head=this.tail=new we(Os,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(Os,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=Sf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function ks(e,t,r){t[r]=e&255}function vf(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Ks=class extends we{next;constructor(t,r){super(vf,t,r),this.next=void 0}};function on(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 Af(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(Bf,t,e),this},lr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(If,t,e),this});function Bf(e,t,r){t.set(e,r)}function If(e,t,r){e.length<40?Ds(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Z(e),r)}function Fs(){return new lr}function ie(e,t){let r=Fs();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*oe(e,t,r){let n=ur(e);yield*t.stream(n,void 0,"$",r)}var an={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function cn(e,t,r,n,s){return{name:e,type:t,encode:r,decode:n,stream:s}}function Ms(e){function t(i){if(e[i.toString()]==null)throw new Error("Invalid enum value");return e[i]}let r=function(o,a){let c=t(o);a.int32(c)},n=function(o){let a=o.int32();return t(a)},s=function*(o){let a=o.int32();yield t(a)};return cn("enum",an.VARINT,r,n,s)}function ae(e,t,r){return cn("message",an.LENGTH_DELIMITED,e,t,r)}var xe=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var st;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(st||(st={}));var Us;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Us||(Us={}));(function(e){e.codec=()=>Ms(Us)})(st||(st={}));var Nt;(function(e){let t;e.codec=()=>(t==null&&(t=ae((i,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),i.Type!=null&&(o.uint32(8),st.codec().encode(i.Type,o)),i.Data!=null&&(o.uint32(18),o.bytes(i.Data)),a.lengthDelimited!==!1&&o.ldelim()},(i,o,a={})=>{let c={},u=o==null?i.len:i.pos+o;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=st.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,o,a,c={}){let u=o==null?i.len:i.pos+o;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:st.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),t);function r(i){return ie(i,e.codec())}e.encode=r;function n(i,o){return se(i,e.codec(),o)}e.decode=n;function s(i,o){return oe(i,e.codec(),o)}e.stream=s})(Nt||(Nt={}));var qs;(function(e){let t;e.codec=()=>(t==null&&(t=ae((i,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),i.Type!=null&&(o.uint32(8),st.codec().encode(i.Type,o)),i.Data!=null&&(o.uint32(18),o.bytes(i.Data)),a.lengthDelimited!==!1&&o.ldelim()},(i,o,a={})=>{let c={},u=o==null?i.len:i.pos+o;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=st.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,o,a,c={}){let u=o==null?i.len:i.pos+o;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:st.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),t);function r(i){return ie(i,e.codec())}e.encode=r;function n(i,o){return se(i,e.codec(),o)}e.decode=n;function s(i,o){return oe(i,e.codec(),o)}e.stream=s})(qs||(qs={}));var dr={};yt(dr,{MAX_RSA_KEY_SIZE:()=>Hs,generateRSAKeyPair:()=>aa,jwkToJWKKeyPair:()=>ca,jwkToPkcs1:()=>Rf,jwkToPkix:()=>js,jwkToRSAPrivateKey:()=>Ws,pkcs1MessageToJwk:()=>Vs,pkcs1MessageToRSAPrivateKey:()=>Ys,pkcs1ToJwk:()=>_f,pkcs1ToRSAPrivateKey:()=>oa,pkixMessageToJwk:()=>$s,pkixMessageToRSAPublicKey:()=>Gs,pkixToJwk:()=>Df,pkixToRSAPublicKey:()=>Zs});var qe=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 ht.createV1(114,this._multihash)}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}verify(t,r,n){return ia(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:gt(this.raw,t.raw)}sign(t,r){return sa(this.jwk,t,r)}};var Hs=8192,zs=18,Tf=1062,Lf=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function _f(e){let t=Ft(e);return Vs(t)}function Vs(e){return{n:Y(e[1],"base64url"),e:Y(e[2],"base64url"),d:Y(e[3],"base64url"),p:Y(e[4],"base64url"),q:Y(e[5],"base64url"),dp:Y(e[6],"base64url"),dq:Y(e[7],"base64url"),qi:Y(e[8],"base64url"),kty:"RSA"}}function Rf(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 et("JWK was missing components");return Zt([xt(Uint8Array.from([0])),xt(Z(e.n,"base64url")),xt(Z(e.e,"base64url")),xt(Z(e.d,"base64url")),xt(Z(e.p,"base64url")),xt(Z(e.q,"base64url")),xt(Z(e.dp,"base64url")),xt(Z(e.dq,"base64url")),xt(Z(e.qi,"base64url"))]).subarray()}function Df(e){let t=Ft(e,{offset:0});return $s(t)}function $s(e){let t=Ft(e[1],{offset:0});return{kty:"RSA",n:Y(t[0],"base64url"),e:Y(t[1],"base64url")}}function js(e){if(e.n==null||e.e==null)throw new et("JWK was missing components");return Zt([Lf,Dr(Zt([xt(Z(e.n,"base64url")),xt(Z(e.e,"base64url"))]))]).subarray()}function oa(e){let t=Ft(e);return Ys(t)}function Ys(e){let t=Vs(e);return Ws(t)}function Zs(e,t){if(e.byteLength>=Tf)throw new Be("Key size is too large");let r=Ft(e,{offset:0});return Gs(r,e,t)}function Gs(e,t,r){let n=$s(e);if(r==null){let s=Oe(Nt.encode({Type:st.RSA,Data:t}));r=Pt(zs,s)}return new qe(n,r)}function Ws(e){if(fa(e)>Hs)throw new et("Key size is too large");let t=ca(e),r=Oe(Nt.encode({Type:st.RSA,Data:js(t.publicKey)})),n=Pt(zs,r);return new hr(t.privateKey,new qe(t.publicKey,n))}async function aa(e){if(e>Hs)throw new et("Key size is too large");let t=await ua(e),r=Oe(Nt.encode({Type:st.RSA,Data:js(t.publicKey)})),n=Pt(zs,r);return new hr(t.privateKey,new qe(t.publicKey,n))}function ca(e){if(e==null)throw new et("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function ua(e,t){let r=await _t.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 Cf(r,t);return{privateKey:n[0],publicKey:n[1]}}async function sa(e,t,r){let n=await _t.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await _t.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,It(t instanceof Uint8Array?t:t.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function ia(e,t,r,n){let s=await _t.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await _t.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,It(t),It(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),i}async function Cf(e,t){if(e.privateKey==null||e.publicKey==null)throw new et("Private and public key are required");let r=await Promise.all([_t.get().subtle.exportKey("jwk",e.privateKey),_t.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function fa(e){if(e.kty!=="RSA")throw new et("invalid key type");if(e.n==null)throw new et("invalid key modulus");return Z(e.n,"base64url").length*8}var un=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(Or(t),Tt(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,s=new Uint8Array(n);s.set(r.length>n?t.create().update(r).digest():r);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),pe(s)}update(t){return Pe(this),this.iHash.update(t),this}digestInto(t){Pe(this),kr(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:s,destroyed:i,blockLen:o,outputLen:a,canXOF:c}=this;return t=t,t.finished=s,t.destroyed=i,t.blockLen=o,t.outputLen=a,t.canXOF=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()}},la=(()=>{let e=((t,r,n)=>new un(t,r).update(n).digest());return e.create=(t,r)=>new un(t,r),e})();var Pf=BigInt(0),Xs=class extends Error{constructor(t=""){super(t)}},zt={Err:Xs,_tlv:{encode:(e,t)=>{let{Err:r}=zt;if(qt(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(yo(t,"data"),t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,s=nr(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?nr(s.length/2|128):"";return nr(e)+i+s+t},decode(e,t){let{Err:r}=zt;t=V(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.decode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let s=t[n++],i=!!(s&128),o=0;if(!i)o=s;else{let c=s&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)o=o<<8|f;if(n+=c,o<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+o);if(a.length!==o)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+o)}}},_int:{encode(e){let{Err:t}=zt;if(qr(e),e<Pf)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}=zt;if(e.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return kt(e)}},toSig(e,t){let{Err:r,_int:n,_tlv:s}=zt;if(t!==void 0&&(qt(t,"maxScalarBytes"),t<1))throw new r("invalid signature: maxScalarBytes must be positive");let i=V(e,void 0,"signature"),{v:o,l:a}=s.decode(48,i);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:u}=s.decode(2,o),{v:f,l:h}=s.decode(2,u);if(h.length)throw new r("invalid signature: left bytes after parsing");if(t!==void 0&&(c.length>t||f.length>t))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=zt;St(e,{r:"bigint",s:"bigint"},{},"sig");let n=t.encode(2,r.encode(e.r)),s=t.encode(2,r.encode(e.s)),i=n+s;return t.encode(48,i)}},fn=(Object.freeze(zt._tlv),Object.freeze(zt._int),Object.freeze(zt));var ha=(e,t)=>(e+(e>=0?t:-t)/da)/t;function Of(e,t,r){Ne("scalar",e,Vt,r);let[[n,s],[i,o]]=t,a=ha(o*e,r),c=ha(-s*e,r),u=e-a*n-c*i,f=-a*s-c*o,h=u<Vt,l=f<Vt;h&&(u=-u),l&&(f=-f);let d=ir(Math.ceil(Ke(r)/2))+Ee;if(u<Vt||u>=d||f<Vt||f>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:u,k2neg:l,k2:f}}function ti(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Js(e,t){St(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Et(r.lowS,"lowS"),Et(r.prehash,"prehash"),r.format!==void 0&&ti(r.format),r}var Vt=BigInt(0),Ee=BigInt(1),da=BigInt(2),Qs=BigInt(3),kf=BigInt(4);function pa(e,t={}){let r=Gr("weierstrass",e,t),n=r.Fp,s=r.Fn,i=r.CURVE,{h:o,n:a}=i;St(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:h,fromBytes:l,toBytes:d}=t,y=t.randomBytes===void 0?be:t.randomBytes;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let g=c?{beta:c.beta,basises:c.basises.map(E=>[...E])}:void 0,S=ba(n,s);function w(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function B(E,p,m){if(p.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x,y:I}=p.toAffine(),L=n.toBytes(x);if(Et(m,"isCompressed"),m){w();let _=!n.isOdd(I);return Lt(ma(_),L)}else return Lt(Uint8Array.of(4),L,n.toBytes(I))}function b(E){V(E,void 0,"Point");let{publicKey:p,publicKeyUncompressed:m}=S,x=E.length,I=E[0],L=E.subarray(1);if(u&&x===1&&I===0)return{x:n.ZERO,y:n.ZERO};if(x===p&&(I===2||I===3)){let _=n.fromBytes(L);if(!n.isValid(_))throw new Error("bad point: is not on curve, wrong x");let P=k(_),N;try{N=n.sqrt(P)}catch(ot){let X=ot instanceof Error?": "+ot.message:"";throw new Error("bad point: is not on curve, sqrt error"+X)}w();let z=n.isOdd(N);return(I&1)===1!==z&&(N=n.neg(N)),{x:_,y:N}}else if(x===m&&I===4){let _=n.BYTES,P=n.fromBytes(L.subarray(0,_)),N=n.fromBytes(L.subarray(_,_*2));if(!R(P,N))throw new Error("bad point: is not on curve");return{x:P,y:N}}else throw new Error(`bad point: got length ${x}, expected compressed=${p} or uncompressed=${m}`)}let v=d===void 0?B:d,A=l===void 0?b:l,O=n.mul(i.b,Qs),K=n.is0(i.a)?E=>n.ZERO:E=>n.mul(i.a,E);function k(E){let p=n.sqr(E),m=n.mul(p,E);return n.add(n.add(m,n.mul(E,i.a)),i.b)}function R(E,p){let m=n.sqr(p),x=k(E);return n.eql(m,x)}if(!R(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let C=n.mul(n.pow(i.a,Qs),kf),q=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(C,q)))throw new Error("bad curve params: a or b");function U(E,p,m=!1){if(!n.isValid(p)||m&&n.is0(p))throw new Error(`bad point coordinate ${E}`);return typeof p=="object"&&p!==null?n.create(p):p}function G(E){if(!(E instanceof D))throw new Error("Weierstrass Point expected")}function T(E){if(!g||!g.basises)throw new Error("no endo");return Of(E,g.basises,s.ORDER)}function F(E,p,m,x){if(!s.isValid(x))throw new RangeError("invalid scalar: out of range");if(g){let{k1neg:I,k1:L,k2neg:_,k2:P}=T(x),N=new D(n.mul(m.X,g.beta),m.Y,m.Z);E.push(I?m.negate():m,_?N.negate():N),p.push(L,P)}else E.push(m),p.push(x)}let M=new WeakSet;class D{static BASE=new D(i.Gx,i.Gy,n.ONE);static ZERO=new D(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(p,m,x){this.X=U("x",p),this.Y=U("y",m,!0),this.Z=U("z",x),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){let{x:m,y:x}=p||{};if(!p||!n.isValid(m)||!n.isValid(x))throw new Error("invalid affine point");if(p instanceof D)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(x)?D.ZERO:new D(m,x,n.ONE)}static fromBytes(p){let m=D.fromAffine(A(V(p,void 0,"point")));return m.assertValidity(),m}static fromHex(p){return D.fromBytes(ke(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=6,m=!0){return tt.setWindowSize(this,p),m||this.multiply(Qs),this}assertValidity(){let p=this;if(p.is0()){if(u&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}if(M.has(p))return;let{x:m,y:x}=p.toAffine();if(!n.isValid(m)||!n.isValid(x))throw new Error("bad point: x or y not field elements");if(!R(m,x))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");M.add(p)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){G(p);let{X:m,Y:x,Z:I}=this,{X:L,Y:_,Z:P}=p,N=n.eql(n.mul(m,P),n.mul(L,I)),z=n.eql(n.mul(x,P),n.mul(_,I));return N&&z}negate(){return new D(this.X,n.neg(this.Y),this.Z)}double(){let{X:p,Y:m,Z:x}=this,I=n.ZERO,L=n.ZERO,_=n.ZERO,P=n.mul(p,p),N=n.mul(m,m),z=n.mul(x,x),H=n.mul(p,m);return H=n.add(H,H),_=n.mul(p,x),_=n.add(_,_),I=K(_),L=n.mul(O,z),L=n.add(I,L),I=n.sub(N,L),L=n.add(N,L),L=n.mul(I,L),I=n.mul(H,I),_=n.mul(O,_),z=K(z),H=n.sub(P,z),H=K(H),H=n.add(H,_),_=n.add(P,P),P=n.add(_,P),P=n.add(P,z),P=n.mul(P,H),L=n.add(L,P),z=n.mul(m,x),z=n.add(z,z),P=n.mul(z,H),I=n.sub(I,P),_=n.mul(z,N),_=n.add(_,_),_=n.add(_,_),new D(I,L,_)}add(p){G(p);let{X:m,Y:x,Z:I}=this,{X:L,Y:_,Z:P}=p,N=n.ZERO,z=n.ZERO,H=n.ZERO,ot=n.mul(m,L),X=n.mul(x,_),ft=n.mul(I,P),At=n.add(m,x),J=n.add(L,_);At=n.mul(At,J),J=n.add(ot,X),At=n.sub(At,J),J=n.add(m,I);let at=n.add(L,P);return J=n.mul(J,at),at=n.add(ot,ft),J=n.sub(J,at),at=n.add(x,I),N=n.add(_,P),at=n.mul(at,N),N=n.add(X,ft),at=n.sub(at,N),H=K(J),N=n.mul(O,ft),H=n.add(N,H),N=n.sub(X,H),H=n.add(X,H),z=n.mul(N,H),X=n.add(ot,ot),X=n.add(X,ot),ft=K(ft),J=n.mul(O,J),X=n.add(X,ft),ft=n.sub(ot,ft),ft=K(ft),J=n.add(J,ft),ot=n.mul(X,J),z=n.add(z,ot),ot=n.mul(at,J),N=n.mul(At,N),N=n.sub(N,ot),ot=n.mul(At,X),H=n.mul(at,H),H=n.add(H,ot),new D(N,z,H)}subtract(p){return G(p),this.add(p.negate())}is0(){return this.equals(D.ZERO)}multiply(p){if(!s.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let{p:m,f:x}=tt.mulSecret(this,p,o,W);return W([m,x])[0]}multiplyUnsafe(p){let m=this,x=p;if(!s.isValid(x))throw new RangeError("invalid scalar: out of range");if(x===Vt||m.is0())return D.ZERO;if(x===Ee)return m;if(tt.hasWindowSize(this))return tt.mulUnsafe(m,x,W);let I=[],L=[];return F(I,L,m,x),Zr(D,I,L)}mulAddUnsafe(p,m,x){G(m);let I=[],L=[];return F(I,L,this,p),F(I,L,m,x),Zr(D,I,L)}toAffine(p){let m=this,x=p;if(x!=null&&!n.isValid(x))throw new RangeError('"invertedZ" expected valid field element');let{X:I,Y:L,Z:_}=m;if(n.eql(_,n.ONE))return{x:I,y:L};let P=m.is0();x==null&&(x=P?n.ONE:n.inv(_));let N=n.mul(I,x),z=n.mul(L,x),H=n.mul(_,x);if(P)return{x:n.ZERO,y:n.ZERO};if(!n.eql(H,n.ONE))throw new Error("invZ was invalid");return{x:N,y:z}}isTorsionFree(){return o===Ee?!0:h?h(D,this):tt.mulUnsafe(this,a).is0()}clearCofactor(){return o===Ee?this:f?f(D,this):this.multiplyUnsafe(o)}isSmallOrder(){return o===Ee?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return Et(p,"isCompressed"),this.assertValidity(),v(D,this,p)}toHex(p=!0){return rr(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let W=E=>Yr(D,E),tt=new Ue(D,y);return tt.bits>=6&&D.BASE.precompute(6),Object.freeze(D.prototype),Object.freeze(D),D}function ma(e){return Uint8Array.of(e?2:3)}function ba(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Nf(e,t={}){re(e);let{Fn:r}=e,n=t.randomBytes===void 0?be:t.randomBytes,s=Object.assign(ba(e.Fp,r),{seed:Math.max($r(r.ORDER),16)});function i(d){try{let y=r.fromBytes(d);return r.isValidNot0(y)}catch{return!1}}function o(d,y){let{publicKey:g,publicKeyUncompressed:S}=s;try{let w=d.length;return y===!0&&w!==g||y===!1&&w!==S?!1:!e.fromBytes(d).is0()}catch{return!1}}function a(d){return d=d===void 0?n(s.seed):d,jr(V(d,s.seed,"seed"),r.ORDER)}function c(d,y=!0){return e.BASE.multiply(r.fromBytes(d)).toBytes(y)}function u(d){let{secretKey:y,publicKey:g,publicKeyUncompressed:S}=s,w=r._lengths;if(!te(d))return;let B=V(d,void 0,"key").length,b=B===g||B===S,v=B===y||!!w?.includes(B);if(!(b&&v))return b}function f(d,y,g=!0){if(u(d)===!0)throw new Error("first arg must be private key");if(u(y)===!1)throw new Error("second arg must be public key");let S=r.fromBytes(d),w=e.fromBytes(y);if(w.is0())throw new Error("invalid public key: point at infinity");return w.multiply(S).toBytes(g)}let h={isValidSecretKey:i,isValidPublicKey:o,randomSecretKey:a},l=Wr(a,c);return Object.freeze(h),Object.freeze(s),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:l,Point:e,utils:h,lengths:s})}function ya(e,t,r={}){re(e);let n=t;Or(n),St(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let s=Object.assign({},r),i=s.randomBytes===void 0?be:s.randomBytes,o=s.hmac===void 0?(E,p)=>la(n,E,p):s.hmac,{Fp:a,Fn:c}=e,{ORDER:u,BITS:f}=c,h=$r(u),l=bs(i,h),{keygen:d,getPublicKey:y,getSharedSecret:g,utils:S,lengths:w}=Nf(e,s),B={prehash:!0,lowS:typeof s.lowS=="boolean"?s.lowS:!0,format:"compact",extraEntropy:!1},b=u*da+Ee<a.ORDER;function v(E){let p=u>>Ee;return E>p}function A(E,p){if(!c.isValidNot0(p))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return p}function O(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function K(E,p,m){return O(),(E===m?0:2)|Number(a.isOdd(p))}function k(){if(b)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function R(E,p){ti(p);let m=w.signature,x=p==="compact"?m:p==="recovered"?m+1:void 0;return V(E,x)}class C{r;s;recovery;constructor(p,m,x){if(this.r=A("r",p),this.s=A("s",m),x!=null){if(k(),![0,1,2,3].includes(x))throw new Error("invalid recovery id");this.recovery=x}Object.freeze(this)}static fromBytes(p,m=B.format){R(p,m);let x;if(m==="der"){if(p.length>2*c.BYTES+16)throw new fn.Err("invalid signature: DER signature too long");let{r:P,s:N}=fn.toSig(V(p),c.BYTES+1);return new C(P,N)}m==="recovered"&&(x=p[0],m="compact",p=p.subarray(1));let I=w.signature/2,L=p.subarray(0,I),_=p.subarray(I,I*2);return new C(c.fromBytes(L),c.fromBytes(_),x)}static fromHex(p,m){return this.fromBytes(ke(p),m)}assertRecovery(){let{recovery:p}=this;if(p==null)throw new Error("invalid recovery id: must be present");return p}addRecoveryBit(p){return new C(this.r,this.s,p)}recoverPublicKey(p){let{r:m,s:x}=this,I=this.assertRecovery(),L=I===2||I===3?m+u:m;if(!a.isValid(L))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let _=a.toBytes(L),P=e.fromBytes(Lt(ma((I&1)===0),_)),N=c.inv(L),z=U(V(p,void 0,"msgHash")),H=c.create(-z*N),ot=c.create(x*N),X=e.BASE.mulAddUnsafe(H,P,ot);if(X.is0())throw new Error("invalid recovery: point at infinify");return X.assertValidity(),X}hasHighS(){return v(this.s)}toBytes(p=B.format){if(ti(p),p==="der")return ke(fn.hexFromSig(this));let{r:m,s:x}=this,I=c.toBytes(m),L=c.toBytes(x);return p==="recovered"?(k(),Lt(Uint8Array.of(this.assertRecovery()),I,L)):Lt(I,L)}toHex(p){return rr(this.toBytes(p))}}Object.freeze(C.prototype),Object.freeze(C);let q=s.bits2int===void 0?function(p){if(p.length>8192)throw new Error("input is too large");let m=kt(p),x=p.length*8-f;return x>0?m>>BigInt(x):m}:s.bits2int,U=s.bits2int_modN===void 0?function(p){return c.create(q(p))}:s.bits2int_modN,G=ir(f);function T(E){return Ne("num < 2^"+f,E,Vt,G),c.toBytes(E)}function F(E,p){return V(E,void 0,"message"),p?V(n(E),void 0,"prehashed message"):E}function M(E,p,m){let{lowS:x,prehash:I,extraEntropy:L}=Js(m,B);E=F(E,I);let _=U(E),P=c.fromBytes(p);if(!c.isValidNot0(P))throw new Error("invalid private key");let N=[T(P),T(_)];if(L!=null&&L!==!1){let X=L===!0?i(w.secretKey):L;N.push(V(X,void 0,"extraEntropy"))}let z=Lt(...N),H=_;function ot(X){let ft=q(X);if(!c.isValidNot0(ft))return;let At=e.BASE.multiply(ft).toAffine(),J=c.create(At.x);if(J===Vt)return;let at;if(l!==void 0){let $e=kt(jr(l(h),u)),Fa=c.inv(c.mul($e,ft)),Ma=c.mul($e,H),Ua=c.mul($e,P);at=c.create(Fa*c.create(Ma+Ua*J))}else{let $e=To(ft,u);at=c.create($e*c.create(H+J*P))}if(at===Vt)return;let wn=K(At.x,At.y,J),yi=at;return x&&v(at)&&(yi=c.neg(at),wn^=1),new C(J,yi,b?void 0:wn)}return{seed:z,k2sig:ot}}function D(E,p,m={}){let{seed:x,k2sig:I}=M(E,p,m);return wo(n.outputLen,c.BYTES,o)(x,I).toBytes(m.format)}function W(E,p,m,x={}){let{lowS:I,prehash:L,format:_}=Js(x,B);if(m=V(m,void 0,"publicKey"),p=F(p,L),!te(E)){let P=E instanceof C?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+P)}R(E,_);try{let P=C.fromBytes(E,_),N=e.fromBytes(m);if(N.is0()||I&&P.hasHighS())return!1;let{r:z,s:H}=P,ot=U(p),X=c.inv(H),ft=c.create(ot*X),At=c.create(z*X),J=e.BASE.mulAddUnsafe(ft,N,At);if(J.is0())return!1;let at=J.toAffine();return!(c.create(at.x)!==z||_==="recovered"&&P.recovery!==K(at.x,at.y,z))}catch{return!1}}function tt(E,p,m={}){let{prehash:x}=Js(m,B);return p=F(p,x),C.fromBytes(E,"recovered").recoverPublicKey(p).toBytes()}return Object.freeze({keygen:d,getPublicKey:y,getSharedSecret:g,utils:S,lengths:w,Point:e,sign:D,verify:W,recoverPublicKey:tt,Signature:C,hash:n})}var ri={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Kf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var ga=BigInt(2);function Ff(e){let t=ri.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,h=Q(f,r,t)*f%t,l=Q(h,r,t)*f%t,d=Q(l,ga,t)*u%t,y=Q(d,s,t)*d%t,g=Q(y,i,t)*y%t,S=Q(g,a,t)*g%t,w=Q(S,c,t)*S%t,B=Q(w,a,t)*g%t,b=Q(B,r,t)*f%t,v=Q(b,o,t)*y%t,A=Q(v,n,t)*u%t,O=Q(A,ga,t);if(!ei.eql(ei.sqr(O),e))throw new Error("Cannot find square root");return O}var ei=Me(ri.p,{sqrt:Ff}),Mf=pa(ri,{Fp:ei,endo:Kf}),He=ya(Mf,Oe);function wa(e,t,r,n){let s=le.digest(r instanceof Uint8Array?r:r.subarray());if(rn(s))return s.then(({digest:i})=>(n?.signal?.throwIfAborted(),He.verify(t,i,e,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new cr(String(i))});try{return n?.signal?.throwIfAborted(),He.verify(t,s.digest,e,{prehash:!1,format:"der"})}catch(i){throw new cr(String(i))}}var ln=class{type="secp256k1";raw;_key;constructor(t){this._key=Ea(t),this.raw=xa(this._key)}toMultihash(){return Rt.digest(Mt(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}verify(t,r,n){return wa(this._key,r,t,n)}};function ni(e){return new ln(e)}function xa(e){return He.Point.fromBytes(e).toBytes()}function Ea(e){try{return He.Point.fromBytes(e),e}catch(t){throw new Be(String(t))}}function si(e,t){let{Type:r,Data:n}=Nt.decode(e),s=n??new Uint8Array;switch(r){case st.RSA:return Zs(s,t);case st.Ed25519:return Ss(s);case st.secp256k1:return ni(s);case st.ECDSA:return Gn(s);default:throw new ce}}function Sa(e){let{Type:t,Data:r}=Nt.decode(e.digest),n=r??new Uint8Array;switch(t){case st.Ed25519:return Ss(n);case st.secp256k1:return ni(n);case st.ECDSA:return Gn(n);default:throw new ce}}function Mt(e){return Nt.encode({Type:st[e.type],Data:e.raw})}var va=Symbol.for("nodejs.util.inspect.custom"),Uf=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()})`}[xn]=!0;toString(){return this.string==null&&(this.string=rt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ht.createV1(Uf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return gt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return gt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[va](){return`PeerId(${this.toString()})`}},mr=class extends pr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},br=class extends pr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},yr=class extends pr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},qf=2336,hn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Rt.digest(Z(this.url))}[va](){return`PeerId(${this.url})`}[xn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ht.createV1(qf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=Y(t)),t.toString()===this.toString())}};function ii(e){if(e.type==="Ed25519")return new br({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 mr({multihash:e.toCID().multihash,publicKey:e});throw new ce}function Aa(e){return ii(e.publicKey)}function gr(e){if(zf(e))return new mr({multihash:e});if(Hf(e))try{let t=Sa(e);if(t.type==="Ed25519")return new br({multihash:e,publicKey:t});if(t.type==="secp256k1")return new yr({multihash:e,publicKey:t})}catch{let r=Y(e.digest);return new hn(new URL(r))}throw new Ir("Supplied PeerID Multihash is invalid")}function Hf(e){return e.code===Rt.code}function zf(e){return e.code===le.code}function Se(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:t(s)}}};return r}function dn(e){let t=jt(rt.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 Se(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 Se(this.map.values(),t=>t.key)}values(){return Se(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 Se(this.set.entries(),t=>{let r=dn(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=dn(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Se(this.set.values(),t=>dn(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}};var oi=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},Ba=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function Er(e,t){let{milliseconds:r,fallback:n,message:s,customTimers:i={setTimeout,clearTimeout},signal:o}=t,a,c,f=new Promise((h,l)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(o?.aborted){l(Ba(o));return}if(o&&(c=()=>{l(Ba(o))},o.addEventListener("abort",c,{once:!0})),e.then(h,l),r===Number.POSITIVE_INFINITY)return;let d=new oi;a=i.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(y){l(y)}return}typeof e.cancel=="function"&&e.cancel(),s===!1?h():s instanceof Error?l(s):(d.message=s??`Promise timed out after ${r} milliseconds`,l(d))},r)}).finally(()=>{f.clear(),c&&o&&o.removeEventListener("abort",c)});return f.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},f}var Vf=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 $f(e,t,r){let n,s=new Promise((i,o)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!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 a=[t].flat(),c=[],{addListener:u,removeListener:f}=Vf(e),h=async(...d)=>{let y=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(y))return}catch(g){n(),o(g);return}c.push(y),r.count===c.length&&(n(),i(c))},l=(...d)=>{n(),o(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)f(d,h);for(let d of r.rejectionEvents)a.includes(d)||f(d,l)};for(let d of a)u(d,h);for(let d of r.rejectionEvents)a.includes(d)||u(d,l);r.signal&&r.signal.addEventListener("abort",()=>{l(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(s.cancel=n,typeof r.timeout=="number"){let i=Er(s,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return s}function Ia(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=$f(e,t,r),s=n.then(i=>i[0]);return s.cancel=n.cancel,s}var ve=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function jf(e){return e.reason}function ai(e,t,r){if(t==null||e==null)return e;let n=r?.translateError??jf;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let s;return Promise.race([e,new Promise((i,o)=>{s=()=>{o(n(t))},t.addEventListener("abort",s)})]).finally(()=>{s!=null&&t.removeEventListener("abort",s)})}var Zf=4194304,pn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},ui=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},fi=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},li=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Gf(e){return typeof e?.closeRead=="function"}function Wf(e){return typeof e?.close=="function"}function ci(e){return Gf(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:Wf(e)?e.status!=="open":!1}function Xf(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function Jf(e,t){let r=t?.maxBufferSize??Zf,n=new lt,s,i=!1;if(!Xf(e))throw new et("Argument should be a Stream or a Multiaddr");let o=f=>{if(n.append(f.data),n.byteLength>r){let h=n.byteLength;n.consume(n.byteLength),s?.reject(new Error(`Read buffer overflow - ${h} > ${r}`))}s?.resolve()};e.addEventListener("message",o);let a=f=>{f.error!=null?s?.reject(f.error):s?.resolve()};e.addEventListener("close",a);let c=()=>{s?.resolve()};e.addEventListener("remoteCloseWrite",c);let u={readBuffer:n,async read(f){if(i===!0)throw new pn("Stream was unwrapped");if(ci(e)){if(n.byteLength===0&&f?.bytes==null)return null;if(f?.bytes!=null&&n.byteLength<f.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,f.bytes),new ve(`Unexpected EOF - stream closed after reading ${n.byteLength}/${f.bytes} bytes`)}let h=f?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=h){s.resolve();break}if(await ai(s.promise,f?.signal),ci(e)){if(n.byteLength===0&&f?.bytes==null)return null;break}s=Promise.withResolvers()}let l=f?.bytes??n.byteLength;if(n.byteLength<l){if(ci(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,l),new ve(`Unexpected EOF - stream closed while reading ${n.byteLength}/${l} bytes`);return u.read(f)}let d=n.sublist(0,l);return n.consume(l),d},async write(f,h){if(i===!0)throw new pn("Stream was unwrapped");e.send(f)||await Ia(e,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,e.removeEventListener("message",o),e.removeEventListener("close",a),e.removeEventListener("remoteCloseWrite",c),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.unshift(n))),e}};return u}function Qf(e,t={}){let r=Jf(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Ht(t.maxDataLength));let n=t?.lengthDecoder??Zo,s=t?.lengthEncoder??Yo;return{async read(o){let a=-1,c=new lt;for(;;){let f=await r.read({...o,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(h){if(h instanceof RangeError)continue;throw h}if(a<0)throw new ui("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new li(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new fi(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await r.read({...o,bytes:a});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",a),new ve(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new ve(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(o,a){await r.write(new lt(s(o.byteLength),o),a)},async writeV(o,a){let c=new lt(...o.flatMap(u=>[s(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function hi(e,t){let r=Qf(e,t),n={read:async(s,i)=>{let o=await r.read(i);return s.decode(o,i)},write:async(s,i,o)=>{await r.write(i.encode(s),o)},writeV:async(s,i,o)=>{await r.writeV(s.map(a=>i.encode(a)),o)},pb:s=>({read:async i=>n.read(s,i),write:async(i,o)=>n.write(i,s,o),writeV:async(i,o)=>n.writeV(i,s,o),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var pi=Ya(La(),1);function mi(e,t,r){let n=0,s=e.length;for(;s>0;){let i=Math.trunc(s/2),o=n+i;r(e[o],t)<=0?(n=++o,s-=i+1):s=i}return n}var rl=100,ze=class{#t=[];#e=0;enqueue(t,r){let{priority:n=0,id:s}=r??{},{size:i}=this,o={priority:n,id:s,run:t};if(i===0){this.#t.length=0,this.#e=0,this.#t.push(o);return}if(this.#t.at(-1).priority>=n){this.#t.push(o);return}this.#i();let a=mi(this.#t,o,(c,u)=>u.priority-c.priority);this.#t.splice(a,0,o)}setPriority(t,r){let n=this.#t.findIndex((i,o)=>o>=this.#e&&i.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[s]=this.#t.splice(n,1);this.enqueue(s.run,{priority:r,id:t})}remove(t){let r=this.#t.findIndex((n,s)=>s<this.#e?!1:typeof t=="string"?n.id===t:n.run===t);r!==-1&&this.#t.splice(r,1)}dequeue(){if(this.#e===this.#t.length)return;let t=this.#t[this.#e];return this.#e++,this.#e===this.#t.length?(this.#t.length=0,this.#e=0):this.#e>rl&&this.#e>this.#t.length/2&&this.#i(),t?.run}filter(t){let r=[];for(let n=this.#e;n<this.#t.length;n++){let s=this.#t[n];s.priority===t.priority&&r.push(s.run)}return r}get size(){return this.#t.length-this.#e}#i(){this.#e!==0&&(this.#t.splice(0,this.#e),this.#e=0)}};var vr=class extends pi.default{#t;#e;#i=0;#d;#m=!1;#w=!1;#u;#x=0;#c;#f;#a;#o=[];#s=0;#r;#I;#n=0;#b;#l;#C=1n;#y=new Map;#E=new Set;timeout;constructor(t){if(super(),t={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:ze,strict:!1,...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})`);if(t.strict&&t.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(t.strict&&t.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#t=t.carryoverIntervalCount??t.carryoverConcurrencyCount??!1,this.#e=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#u=t.interval,this.#a=t.strict,this.#r=new t.queueClass,this.#I=t.queueClass,this.concurrency=t.concurrency,t.timeout!==void 0&&!(Number.isFinite(t.timeout)&&t.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${t.timeout}\` (${typeof t.timeout})`);this.timeout=t.timeout,this.#l=t.autoStart===!1,this.#U()}#S(t){for(;this.#s<this.#o.length;){let n=this.#o[this.#s];if(n!==void 0&&t-n>=this.#u)this.#s++;else break}(this.#s>100&&this.#s>this.#o.length/2||this.#s===this.#o.length)&&(this.#o=this.#o.slice(this.#s),this.#s=0)}#P(t){this.#a?this.#o.push(t):this.#i++}#O(){this.#a?this.#o.length>this.#s&&this.#o.pop():this.#i>0&&this.#i--}#v(){return this.#o.length-this.#s}get#k(){return this.#e?!0:this.#a?this.#v()<this.#d:this.#i<this.#d}get#N(){return this.#n<this.#b}#K(){this.#n--,this.#n===0&&this.emit("pendingZero"),this.#g(),this.emit("next")}#F(){this.#f=void 0,this.#R(),this.#_()}#M(t){if(this.#a){if(this.#S(t),this.#v()>=this.#d){let n=this.#o[this.#s],s=this.#u-(t-n);return this.#T(s),!0}return!1}if(this.#c===void 0){let r=this.#x-t;if(r<0)this.#i=this.#t?this.#n:0;else return this.#T(r),!0}return!1}#T(t){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#F()},t))}#A(){this.#c&&(clearInterval(this.#c),this.#c=void 0)}#L(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#g(){if(this.#r.size===0){if(this.#A(),this.emit("empty"),this.#n===0){if(this.#L(),this.#a&&this.#s>0){let r=Date.now();this.#S(r)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let r=Date.now(),n=!this.#M(r);if(this.#k&&this.#N){let s=this.#r.dequeue();this.#e||(this.#P(r),this.#p()),n&&this.#_(),this.emit("active"),s(),t=!0}}return t}#_(){this.#e||this.#c!==void 0||this.#a||(this.#c=setInterval(()=>{this.#R()},this.#u),this.#x=Date.now()+this.#u)}#R(){this.#a||(this.#c!==void 0&&(this.#i===0&&this.#n===0?this.#A():this.#x=Date.now()+this.#u),this.#i=this.#t?this.#n:0),this.#B(),this.#p()}#B(){for(;this.#g(););}get concurrency(){return this.#b}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.#b=t,this.#B()}setPriority(t,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#r.setPriority(t,r)}async add(t,r={}){if(r={timeout:this.timeout,...r,id:r.id??(this.#C++).toString()},r.timeout!==void 0&&!(Number.isFinite(r.timeout)&&r.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${r.timeout}\` (${typeof r.timeout})`);return new Promise((n,s)=>{let i=Symbol(`task-${r.id}`),o=()=>{},a=async()=>{o(),this.#n++,this.#y.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let u;try{try{r.signal?.throwIfAborted()}catch(l){throw this.#q(),this.#y.delete(i),l}let f=t({signal:r.signal});if(r.timeout!==void 0&&(f=Er(Promise.resolve(f),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#n} running, ${this.#r.size} waiting)`})),r.signal){let{signal:l}=r;f=Promise.race([f,new Promise((d,y)=>{u=()=>{y(l.reason)},l.addEventListener("abort",u,{once:!0})})])}let h=await f;n(h),this.emit("completed",h)}catch(f){s(f),this.emit("error",f)}finally{u&&r.signal?.removeEventListener("abort",u),this.#y.delete(i),queueMicrotask(()=>{this.#K()})}};this.#r.enqueue(a,r);let c=()=>{if(this.#r instanceof ze){this.#r.remove(a);return}this.#r.remove?.(r.id)};if(r.signal){let{signal:u}=r,f=()=>{o(),c(),s(u.reason),this.#g(),this.emit("next")};if(o=()=>{u.removeEventListener("abort",f),this.#E.delete(o)},u.aborted){f();return}u.addEventListener("abort",f,{once:!0}),this.#E.add(o)}this.emit("add"),this.#g()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#B(),this):this}pause(){this.#l=!0}clear(){for(let t of this.#E)t();this.#r=new this.#I,this.#A(),this.#D(),this.emit("empty"),this.#n===0&&(this.#L(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#r.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#r.size<t||await this.#h(["next","active"],()=>this.#r.size<t)}async onIdle(){this.#n===0&&this.#r.size===0||await this.#h("idle")}async onPendingZero(){this.#n!==0&&await this.#h("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#h("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#h("rateLimitCleared")}onError(){return new Promise((t,r)=>{let n=s=>{this.off("error",n),r(s)};this.on("error",n)})}async#h(t,r){let n=Array.isArray(t)?t:[t];return new Promise(s=>{let i=()=>{if(!(r&&!r())){for(let o of n)this.off(o,i);s()}};for(let o of n)this.on(o,i)})}get size(){return this.#r.size}sizeBy(t){return this.#r.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#l}#U(){this.#e||(this.on("add",()=>{this.#r.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#e||this.#w||(this.#w=!0,queueMicrotask(()=>{this.#w=!1,this.#D()}))}#q(){this.#e||(this.#O(),this.#p())}#D(){let t=this.#m;if(this.#e||this.#r.size===0){t&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let s=Date.now();this.#S(s),r=this.#v()}else r=this.#i;let n=r>=this.#d;n!==t&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#n===this.#b&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#y.values()].map(t=>({...t,timeoutRemaining:t.timeout?Math.max(0,t.startTime+t.timeout-Date.now()):void 0}))}};var bn=class{entries;validityMs;lastPruneTime=0;constructor(t){this.entries=new Map,this.validityMs=t.validityMs}put(t,r){this.entries.set(t,{value:r,validUntilMs:Date.now()+this.validityMs}),this.prune()}prune(){let t=Date.now();if(!(t-this.lastPruneTime<200)){this.lastPruneTime=t;for(let[r,n]of this.entries.entries())if(n.validUntilMs<t)this.entries.delete(r);else break}}has(t){return this.entries.has(t)}get(t){let r=this.entries.get(t);return r!=null&&r.validUntilMs>=Date.now()?r.value:void 0}clear(){this.entries=new Map,this.lastPruneTime=0}};var _a={maxSubscriptions:5e3,maxMessages:5e3};function Ra(e){return{subscriptions:e.maxSubscriptions,messages:e.maxMessages}}var Ae;(function(e){let t;(function(a){let c;a.codec=()=>(c==null&&(c=ae((l,d,y={})=>{y.lengthDelimited!==!1&&d.fork(),l.subscribe!=null&&(d.uint32(8),d.bool(l.subscribe)),l.topic!=null&&(d.uint32(18),d.string(l.topic)),y.lengthDelimited!==!1&&d.ldelim()},(l,d,y={})=>{let g={},S=d==null?l.len:l.pos+d;for(;l.pos<S;){let w=l.uint32();switch(w>>>3){case 1:{g.subscribe=l.bool();break}case 2:{g.topic=l.string();break}default:{l.skipType(w&7);break}}}return g},function*(l,d,y,g={}){let S=d==null?l.len:l.pos+d;for(;l.pos<S;){let w=l.uint32();switch(w>>>3){case 1:{yield{field:`${y}.subscribe`,value:l.bool()};break}case 2:{yield{field:`${y}.topic`,value:l.string()};break}default:{l.skipType(w&7);break}}}})),c);function u(l){return ie(l,a.codec())}a.encode=u;function f(l,d){return se(l,a.codec(),d)}a.decode=f;function h(l,d){return oe(l,a.codec(),d)}a.stream=h})(t=e.SubOpts||(e.SubOpts={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=ae((l,d,y={})=>{y.lengthDelimited!==!1&&d.fork(),l.from!=null&&(d.uint32(10),d.bytes(l.from)),l.data!=null&&(d.uint32(18),d.bytes(l.data)),l.sequenceNumber!=null&&(d.uint32(26),d.bytes(l.sequenceNumber)),l.topic!=null&&(d.uint32(34),d.string(l.topic)),l.signature!=null&&(d.uint32(42),d.bytes(l.signature)),l.key!=null&&(d.uint32(50),d.bytes(l.key)),y.lengthDelimited!==!1&&d.ldelim()},(l,d,y={})=>{let g={},S=d==null?l.len:l.pos+d;for(;l.pos<S;){let w=l.uint32();switch(w>>>3){case 1:{g.from=l.bytes();break}case 2:{g.data=l.bytes();break}case 3:{g.sequenceNumber=l.bytes();break}case 4:{g.topic=l.string();break}case 5:{g.signature=l.bytes();break}case 6:{g.key=l.bytes();break}default:{l.skipType(w&7);break}}}return g},function*(l,d,y,g={}){let S=d==null?l.len:l.pos+d;for(;l.pos<S;){let w=l.uint32();switch(w>>>3){case 1:{yield{field:`${y}.from`,value:l.bytes()};break}case 2:{yield{field:`${y}.data`,value:l.bytes()};break}case 3:{yield{field:`${y}.sequenceNumber`,value:l.bytes()};break}case 4:{yield{field:`${y}.topic`,value:l.string()};break}case 5:{yield{field:`${y}.signature`,value:l.bytes()};break}case 6:{yield{field:`${y}.key`,value:l.bytes()};break}default:{l.skipType(w&7);break}}}})),c);function u(l){return ie(l,a.codec())}a.encode=u;function f(l,d){return se(l,a.codec(),d)}a.decode=f;function h(l,d){return oe(l,a.codec(),d)}a.stream=h})(r=e.Message||(e.Message={}));let n;e.codec=()=>(n==null&&(n=ae((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.subscriptions!=null&&a.subscriptions.length>0)for(let f of a.subscriptions)c.uint32(10),e.SubOpts.codec().encode(f,c);if(a.messages!=null&&a.messages.length>0)for(let f of a.messages)c.uint32(18),e.Message.codec().encode(f,c);u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={subscriptions:[],messages:[]},h=c==null?a.len:a.pos+c;for(;a.pos<h;){let l=a.uint32();switch(l>>>3){case 1:{if(u.limits?.subscriptions!=null&&f.subscriptions.length===u.limits.subscriptions)throw new xe('Decode error - repeated field "subscriptions" had too many elements');f.subscriptions.push(e.SubOpts.codec().decode(a,a.uint32(),{limits:u.limits?.subscriptions$}));break}case 2:{if(u.limits?.messages!=null&&f.messages.length===u.limits.messages)throw new xe('Decode error - repeated field "messages" had too many elements');f.messages.push(e.Message.codec().decode(a,a.uint32(),{limits:u.limits?.messages$}));break}default:{a.skipType(l&7);break}}}return f},function*(a,c,u,f={}){let h={subscriptions:0,messages:0},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let d=a.uint32();switch(d>>>3){case 1:{if(f.limits?.subscriptions!=null&&h.subscriptions===f.limits.subscriptions)throw new xe('Streaming decode error - repeated field "subscriptions" had too many elements');for(let y of e.SubOpts.codec().stream(a,a.uint32(),`${u}.subscriptions[]`,{limits:f.limits?.subscriptions$}))yield{...y,index:h.subscriptions};h.subscriptions++;break}case 2:{if(f.limits?.messages!=null&&h.messages===f.limits.messages)throw new xe('Streaming decode error - repeated field "messages" had too many elements');for(let y of e.Message.codec().stream(a,a.uint32(),`${u}.messages[]`,{limits:f.limits?.messages$}))yield{...y,index:h.messages};h.messages++;break}default:{a.skipType(d&7);break}}}})),n);function s(a){return ie(a,e.codec())}e.encode=s;function i(a,c){return se(a,e.codec(),c)}e.decode=i;function o(a,c){return oe(a,e.codec(),c)}e.stream=o})(Ae||(Ae={}));var yn=class extends Ie{peerId;shutDownController;inboundPb;outboundPb;constructor(t){super(),this.peerId=t,this.shutDownController=new AbortController}attachInboundStream(t,r,n){this.inboundPb=hi(t,r).pb(Ae),Promise.resolve().then(async()=>{for(;;){if(this.inboundPb==null)return;let s=await this.inboundPb.read({signal:this.shutDownController.signal,limits:n});this.safeDispatchEvent("message",{detail:s})}}).catch(s=>{this.inboundPb?.unwrap().unwrap().abort(s),this.close()})}attachOutboundStream(t,r){this.outboundPb=hi(t,r).pb(Ae)}write(t){this.outboundPb!=null&&this.outboundPb.write(t,{signal:this.shutDownController.signal}).catch(r=>{this.outboundPb?.unwrap().unwrap().abort(r)})}close(){this.shutDownController.abort(),Promise.all([this.inboundPb?.unwrap().unwrap().close().catch(t=>{this.inboundPb?.unwrap().unwrap().abort(t)}),this.outboundPb?.unwrap().unwrap().close().catch(t=>{this.inboundPb?.unwrap().unwrap().abort(t)})]).finally(()=>{this.safeDispatchEvent("close")})}};function Da(){return BigInt(`0x${Y(crypto.getRandomValues(new Uint8Array(8)),"base16")}`)}var Ca=(e,t)=>{let r=Z(t.toString(16).padStart(16,"0"),"base16"),n=Mt(e),s=new Uint8Array(n.byteLength+r.length);return s.set(n,0),s.set(r,n.byteLength),s},Pa=e=>le.encode(e);var nl=async e=>{if(e.sequenceNumber==null||e.from==null||e.signature==null)return!1;let t=gr(jt(e.from));if(t.publicKey!=null)return!0;if(e.key!=null){let r=e.key;return ii(si(r)).equals(t)}return!1},Oa=async e=>{if(e.from==null)throw new ct("RPC message was missing from");if(!await nl(e))return{type:"unsigned",topic:e.topic??"",data:e.data??new Uint8Array(0)};let t=gr(jt(e.from)),r=e.key??t.publicKey;if(r==null)throw new ct("RPC message was missing public key");return{type:"signed",from:t,topic:e.topic??"",sequenceNumber:il(e.sequenceNumber??new Uint8Array(0)),data:e.data??new Uint8Array(0),signature:e.signature??new Uint8Array(0),key:r instanceof Uint8Array?si(r):r}},Ar=e=>e.type==="signed"?{from:e.from.toMultihash().bytes,data:e.data,sequenceNumber:sl(e.sequenceNumber),topic:e.topic,signature:e.signature,key:e.key?Mt(e.key):void 0}:{data:e.data,topic:e.topic},sl=e=>{let t=e.toString(16);return t.length%2!==0&&(t=`0${t}`),Z(t,"base16")},il=e=>BigInt(`0x${Y(e,"base16")}`);var ka=Z("libp2p-pubsub:");async function Na(e,t,r){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Aa(e)},s=fe([ka,r(Ar(n)).subarray()]);return n.signature=await e.sign(s),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([ka,t({...Ar(e),signature:void 0,key:void 0}).subarray()]);return ol(e).verify(r,e.signature)}function ol(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.from.publicKey!=null)return e.from.publicKey;if(e.key!=null&&e.from.equals(e.key.toMultihash().bytes))return e.key;throw new Error("Could not get the public key from the originator id")}var gn=class extends Ie{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;protocol;components;_registrarTopologyId;maxInboundStreams;maxOutboundStreams;seenCache;decodeRpcLimits;constructor(t,r){super(),this.log=t.logger.forComponent("libp2p:floodsub"),this.components=t,this.protocol=r.protocol??bi,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new wr,this.globalSignaturePolicy=r.globalSignaturePolicy==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=r.canRelayMessage??!0,this.emitSelf=r.emitSelf??!1,this.topicValidators=new Map,this.queue=new vr({concurrency:r.messageProcessingConcurrency??10}),this.maxInboundStreams=r.maxInboundStreams??1,this.maxOutboundStreams=r.maxOutboundStreams??1,this.seenCache=new bn({validityMs:r?.seenTTL??3e4}),this.decodeRpcLimits=Ra(r.decodeRpcLimits??_a),this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}[je]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[xi]=["@libp2p/pubsub"];[Ei]=["@libp2p/identify"];async start(){this.started||(this.log("starting"),await this.components.registrar.handle(this.protocol,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this._registrarTopologyId=await this.components.registrar.register(this.protocol,{onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected}),this.log("started"),this.started=!0)}async stop(){if(!this.started)return;let t=this.components.registrar;this._registrarTopologyId!=null&&t.unregister(this._registrarTopologyId),await t.unhandle(this.protocol),this.log("stopping");for(let r of this.peers.values())r.close();this.peers.clear(),this.topics.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t,r){this.addPeer(r.remotePeer,t).attachInboundStream(t,void 0,this.decodeRpcLimits)}async _onPeerConnected(t,r){if(this.log("connected %p",t),r.streams.find(i=>i.direction==="outbound"&&i.protocol===this.protocol)){this.log("outbound pubsub stream already present on connection from %p",t);return}let n=await r.newStream(this.protocol);this.addPeer(t,n).attachOutboundStream(n),this.send(t,{subscriptions:Array.from(this.subscriptions).map(i=>i.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 s=new yn(t);return this.peers.set(t,s),s.addEventListener("message",i=>{let o=i.detail,a=[];for(let c of o.messages??[]){if(c.from==null||c.data==null||c.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}a.push({from:c.from,data:c.data,topic:c.topic,sequenceNumber:c.sequenceNumber??void 0,signature:c.signature??void 0,key:c.key??void 0})}this.processRpc(s,{subscriptions:(o.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}),s.addEventListener("close",()=>this._removePeer(t),{once:!0}),s}_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,s]of this.topics)s.delete(t),s.size===0&&this.topics.delete(n)}}async processRpc(t,r){this.log("rpc from %p",t.peerId);let{subscriptions:n,messages:s}=r;return n!=null&&n.length>0&&(this.log("subscription update from %p",t.peerId),n.forEach(i=>{this.processRpcSubOpt(t.peerId,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:t.peerId,subscriptions:n.map(({topic:i,subscribe:o})=>({topic:`${i??""}`,subscribe:!!o}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t.peerId),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 o=await Oa(i);await this.processMessage(t.peerId,o)}catch(o){this.log.error("failed to queue messages from %p - %e",t.peerId,o)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,r){let n=r.topic;if(n==null)return;let s=this.topics.get(n);r.subscribe===!0?(s==null&&(s=new xr,this.topics.set(n,s)),s.add(t)):s!=null&&(s.delete(t),s.size===0&&this.topics.delete(n))}async processMessage(t,r){if(this.components.peerId.equals(t)&&!this.emitSelf)return;let n=await this.getMsgId(r),s=Y(n,"base64");if(!this.seenCache.has(s)){this.seenCache.put(s,!0);try{await this.validate(t,r)}catch(i){this.log("Message is invalid, dropping it. %O",i);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 ct('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new ct("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new ct("Need key when signature policy is StrictSign but it was missing");return Ca(t.key,t.sequenceNumber);case"StrictNoSign":return Pa(t.data);default:throw new ct("Cannot get message id: unhandled signature policy")}}encodeMessage(t){return Ae.Message.encode(t)}send(t,r){let{messages:n,subscriptions:s,subscribe:i}=r;this.sendRpc(t,{subscriptions:(s??[]).map(o=>({topic:o,subscribe:!!i})),messages:(n??[]).map(Ar)})}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}n.write(r)}async validate(t,r){switch(this.globalSignaturePolicy){case"StrictNoSign":if(r.type!=="unsigned")throw new ct('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(r.signature!=null)throw new ct("StrictNoSigning: signature should not be present");if(r.key!=null)throw new ct("StrictNoSigning: key should not be present");if(r.sequenceNumber!=null)throw new ct("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(r.type!=="signed")throw new ct('Message type should be "signed" when signature policy is StrictSign but it was not');if(r.signature==null)throw new ct("StrictSigning: Signing required and no signature was present");if(r.sequenceNumber==null)throw new ct("StrictSigning: Signing required and no sequenceNumber was present");if(!await Ka(r,this.encodeMessage.bind(this)))throw new ct("StrictSigning: Invalid message signature");break;default:throw new ct("Cannot validate message: unhandled signature policy")}let s=this.topicValidators.get(r.topic);if(s!=null){let i=await s(t,r);if(i===Ve.Reject||i===Ve.Ignore)throw new ct("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return Na(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new ct("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new Tr("not started yet");if(t==null)throw new et("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:Da()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let s=await this.buildMessage(n),i=!1;this.emitSelf&&this.subscriptions.has(t)&&(i=!0,super.dispatchEvent(new CustomEvent("message",{detail:s})));let o=await this.publishMessage(this.components.peerId,s);return i&&(o.recipients=[...o.recipients,this.components.peerId]),o}async publishMessage(t,r){let n=this.getSubscribers(r.topic),s=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",r.topic),{recipients:s}):(n.forEach(i=>{if(this.components.peerId.equals(i)){this.log("not sending message on topic %s to myself",r.topic);return}if(i.equals(t)){this.log("not sending message on topic %s to sender %p",r.topic,i);return}this.log("publish msgs on topics %s %p",r.topic,i),s.push(i),this.send(i,{messages:[r]})}),{recipients:s})}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(!this.subscriptions.has(t)){this.log("subscribe to topic: %s",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");if(this.subscriptions.has(t)){this.log("unsubscribe from %s",t),this.subscriptions.delete(t);for(let r of this.peers.keys())this.send(r,{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())}};var bi="/floodsub/1.0.0",al="StrictSign",cl="StrictNoSign",Ve;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(Ve||(Ve={}));function ul(e){return!!e?.[je]}function fl(e={}){return t=>new gn(t,e)}return Za(ll);})();
|
|
2
|
+
"use strict";var Libp2PFloodsub=(()=>{var Ha=Object.create;var Br=Object.defineProperty;var za=Object.getOwnPropertyDescriptor;var Va=Object.getOwnPropertyNames;var $a=Object.getPrototypeOf,ja=Object.prototype.hasOwnProperty;var Ya=(e,t)=>()=>{try{return t||e((t={exports:{}}).exports,t),t.exports}catch(r){throw t=0,r}},yt=(e,t)=>{for(var r in t)Br(e,r,{get:t[r],enumerable:!0})},wi=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of Va(t))!ja.call(e,s)&&s!==r&&Br(e,s,{get:()=>t[s],enumerable:!(n=za(t,s))||n.enumerable});return e};var Za=(e,t,r)=>(r=e!=null?Ha($a(e)):{},wi(t||!e||!e.__esModule?Br(r,"default",{value:e,enumerable:!0}):r,e)),Ga=e=>wi(Br({},"__esModule",{value:!0}),e);var _a=Ya((xb,pi)=>{"use strict";var el=Object.prototype.hasOwnProperty,bt="~";function Sr(){}Object.create&&(Sr.prototype=Object.create(null),new Sr().__proto__||(bt=!1));function rl(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function La(e,t,r,n,s){if(typeof r!="function")throw new TypeError("The listener must be a function");var i=new rl(r,n||e,s),o=bt?bt+t:t;return e._events[o]?e._events[o].fn?e._events[o]=[e._events[o],i]:e._events[o].push(i):(e._events[o]=i,e._eventsCount++),e}function bn(e,t){--e._eventsCount===0?e._events=new Sr:delete e._events[t]}function mt(){this._events=new Sr,this._eventsCount=0}mt.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)el.call(r,n)&&t.push(bt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};mt.prototype.listeners=function(t){var r=bt?bt+t:t,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var s=0,i=n.length,o=new Array(i);s<i;s++)o[s]=n[s].fn;return o};mt.prototype.listenerCount=function(t){var r=bt?bt+t:t,n=this._events[r];return n?n.fn?1:n.length:0};mt.prototype.emit=function(t,r,n,s,i,o){var a=bt?bt+t:t;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,f,l;if(c.fn){switch(c.once&&this.removeListener(t,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,s),!0;case 5:return c.fn.call(c.context,r,n,s,i),!0;case 6:return c.fn.call(c.context,r,n,s,i,o),!0}for(l=1,f=new Array(u-1);l<u;l++)f[l-1]=arguments[l];c.fn.apply(c.context,f)}else{var h=c.length,d;for(l=0;l<h;l++)switch(c[l].once&&this.removeListener(t,c[l].fn,void 0,!0),u){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,r);break;case 3:c[l].fn.call(c[l].context,r,n);break;case 4:c[l].fn.call(c[l].context,r,n,s);break;default:if(!f)for(d=1,f=new Array(u-1);d<u;d++)f[d-1]=arguments[d];c[l].fn.apply(c[l].context,f)}}return!0};mt.prototype.on=function(t,r,n){return La(this,t,r,n,!1)};mt.prototype.once=function(t,r,n){return La(this,t,r,n,!0)};mt.prototype.removeListener=function(t,r,n,s){var i=bt?bt+t:t;if(!this._events[i])return this;if(!r)return bn(this,i),this;var o=this._events[i];if(o.fn)o.fn===r&&(!s||o.once)&&(!n||o.context===n)&&bn(this,i);else{for(var a=0,c=[],u=o.length;a<u;a++)(o[a].fn!==r||s&&!o[a].once||n&&o[a].context!==n)&&c.push(o[a]);c.length?this._events[i]=c.length===1?c[0]:c:bn(this,i)}return this};mt.prototype.removeAllListeners=function(t){var r;return t?(r=bt?bt+t:t,this._events[r]&&bn(this,r)):(this._events=new Sr,this._eventsCount=0),this};mt.prototype.off=mt.prototype.removeListener;mt.prototype.addListener=mt.prototype.on;mt.prefixed=bt;mt.EventEmitter=mt;typeof pi<"u"&&(pi.exports=mt)});var hl={};yt(hl,{StrictNoSign:()=>ul,StrictSign:()=>cl,TopicValidatorResult:()=>Ve,floodsub:()=>ll,isPubSub:()=>fl,protocol:()=>yi,pubSubSymbol:()=>je});var je=Symbol.for("@libp2p/pubsub");var et=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Be=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Ir=class extends Error{static name="StreamBufferError";constructor(t="The stream buffer was full"){super(t),this.name="StreamBufferError"}};var Tr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var ct=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Lr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var ce=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var En=Symbol.for("@libp2p/peer-id");function Wa(e){return typeof e?.handleEvent=="function"}function Xa(e){return e===!0||e===!1}function Ja(e){return Xa(e)?e:e?.capture??!1}function Sn(e){let t={capture:Ja(e),once:!!e?.once};return e?.passive!=null&&(t.passive=e?.passive),e?.signal!=null&&(t.signal=e?.signal),t}function xi(e,t){return Sn(e).capture===Sn(t).capture}var Ie=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){let s=Sn(n);if(s?.signal?.aborted===!0)return;let i=u=>{s.once&&this.removeEventListener(t,r,s),Wa(r)?r.handleEvent(u):r(u)},o=this.#t.get(t);if(o==null&&(o=[],this.#t.set(t,o)),o.some(u=>u.callback!==r?!1:xi(u.options,s)))return;super.addEventListener(t,i,s);let c=()=>{this.removeEventListener(t,r,s)};s.signal?.addEventListener("abort",c),o.push({callback:r,wrapper:i,options:s,onAbort:c})}removeEventListener(t,r,n){let s=this.#t.get(t);if(s==null){super.removeEventListener(t,r??null,n);return}this.#t.set(t,s.filter(i=>i.callback===r&&xi(i.options,n)?(super.removeEventListener(t,i.wrapper,n),i.options?.signal?.removeEventListener("abort",i.onAbort),!1):!0))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var Ei=Symbol.for("@libp2p/service-capabilities"),Si=Symbol.for("@libp2p/service-dependencies");var Tn={};yt(Tn,{base58btc:()=>rt,base58flickr:()=>oc});var zl=new Uint8Array(0);function Ai(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 Bt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return ue(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return ue(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function Bi(e){let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}var vi=4096;function Ii(e){let t=e.length;if(t<=vi)return String.fromCharCode.apply(String,e);let r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.subarray(n,n+=vi));return r}function Qa(e){return e?.buffer instanceof ArrayBuffer}function ue(e){return Qa(e)?e:e.slice()}function tc(e,t,r){if(e.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var i=0;i<e.length;i++){var o=e.charAt(i),a=o.charCodeAt(0);if(n[a]!==255)throw new TypeError(o+" is ambiguous");if(n[a]=i,r){var c=o.toLowerCase().charCodeAt(0),u=o.toUpperCase().charCodeAt(0);c!==a&&(n[c]=i),u!==a&&(n[u]=i)}}var f=e.length,l=e.charAt(0),h=Math.log(f)/Math.log(256),d=Math.log(256)/Math.log(f);function y(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var B=0,b=0,v=0,A=w.length;v!==A&&w[v]===0;)v++,B++;for(var O=(A-v)*d+1>>>0,K=new Uint8Array(O);v!==A;){for(var k=w[v],R=0,C=O-1;(k!==0||R<b)&&C!==-1;C--,R++)k+=256*K[C]>>>0,K[C]=k%f>>>0,k=k/f>>>0;if(k!==0)throw new Error("Non-zero carry");b=R,v++}for(var q=O-b;q!==O&&K[q]===0;)q++;for(var U=l.repeat(B);q<O;++q)U+=e.charAt(K[q]);return U}function g(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var B=0;if(w[B]!==" "){for(var b=0,v=0;w[B]===l;)b++,B++;for(var A=(w.length-B)*h+1>>>0,O=new Uint8Array(A);w[B];){var K=n[w.charCodeAt(B)];if(K===255)return;for(var k=0,R=A-1;(K!==0||k<v)&&R!==-1;R--,k++)K+=f*O[R]>>>0,O[R]=K%256>>>0,K=K/256>>>0;if(K!==0)throw new Error("Non-zero carry");v=k,B++}if(w[B]!==" "){for(var C=A-v;C!==A&&O[C]===0;)C++;for(var q=new Uint8Array(b+(A-C)),U=b;C!==A;)q[U++]=O[C++];return q}}}function S(w){var B=g(w);if(B)return B;throw new Error(`Non-${t} character`)}return{encode:y,decodeUnsafe:g,decode:S}}var ec=tc,rc=ec,Li=rc;var vn=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")}},An=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 _i(this,t)}},Bn=class{decoders;constructor(t){this.decoders=t}or(t){return _i(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 _i(e,t){return new Bn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var In=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,s){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new vn(t,r,n),this.decoder=new An(t,r,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Te({name:e,prefix:t,encode:r,decode:n}){return new In(e,t,r,n)}function $t({name:e,prefix:t,alphabet:r,caseInsensitive:n=!1}){let{encode:s,decode:i}=Li(r,e,n);return Te({prefix:t,name:e,encode:s,decode:o=>Bt(i(o))})}function nc(e,t,r,n){let s=e.length;for(;e[s-1]==="=";)--s;let i=new Uint8Array(s*r/8|0),o=0,a=0,c=0;for(let u=0;u<s;++u){let f=t[e[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,o+=r,o>=8&&(o-=8,i[c++]=255&a>>o)}if(o>=r||(255&a<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return i}function sc(e,t,r){let n=t[t.length-1]==="=",s=(1<<r)-1,i="",o=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],o+=8;o>r;)o-=r,i+=t[s&a>>o];if(o!==0&&(i+=t[s&a<<r-o]),n)for(;(i.length*r&7)!==0;)i+="=";return i}function ic(e,t){let r={};for(let n=0;n<e.length;++n)if(r[e[n]]=n,t){let s=e[n].toLowerCase(),i=e[n].toUpperCase();s!==e[n]&&(r[s]=n),i!==e[n]&&(r[i]=n)}return r}function it({name:e,prefix:t,bitsPerChar:r,alphabet:n,caseInsensitive:s=!1}){let i=ic(n,s);return Te({prefix:t,name:e,encode(o){return sc(o,n,r)},decode(o){return nc(o,i,r,e)}})}var rt=$t({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),oc=$t({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ln={};yt(Ln,{base32:()=>Le,base32hex:()=>fc,base32hexpad:()=>hc,base32hexpadupper:()=>dc,base32hexupper:()=>lc,base32pad:()=>cc,base32padupper:()=>uc,base32upper:()=>ac,base32z:()=>pc});var Le=it({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),ac=it({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),cc=it({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),uc=it({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),fc=it({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),lc=it({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),hc=it({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),dc=it({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),pc=it({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var _n={};yt(_n,{base36:()=>Ye,base36upper:()=>mc});var Ye=$t({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),mc=$t({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var bc=Ci,Ri=128,yc=127,gc=~yc,wc=Math.pow(2,31);function Ci(e,t,r){t=t||[],r=r||0;for(var n=r;e>=wc;)t[r++]=e&255|Ri,e/=128;for(;e&gc;)t[r++]=e&255|Ri,e>>>=7;return t[r]=e|0,Ci.bytes=r-n+1,t}var xc=Rn,Ec=128,Di=127;function Rn(e,n){var r=0,n=n||0,s=0,i=n,o,a=e.length;do{if(i>=a)throw Rn.bytes=0,new RangeError("Could not decode varint");o=e[i++],r+=s<28?(o&Di)<<s:(o&Di)*Math.pow(2,s),s+=7}while(o>=Ec);return Rn.bytes=i-n,r}var Sc=Math.pow(2,7),vc=Math.pow(2,14),Ac=Math.pow(2,21),Bc=Math.pow(2,28),Ic=Math.pow(2,35),Tc=Math.pow(2,42),Lc=Math.pow(2,49),_c=Math.pow(2,56),Rc=Math.pow(2,63),Dc=function(e){return e<Sc?1:e<vc?2:e<Ac?3:e<Bc?4:e<Ic?5:e<Tc?6:e<Lc?7:e<_c?8:e<Rc?9:10},Cc={encode:bc,decode:xc,encodingLength:Dc},Pc=Cc,Ze=Pc;function Ge(e,t=0){let r=Ze.decode(e,t),n=Ze.decode.bytes;if(n>9)throw new RangeError("Invalid varint: too long");if(n>1&&e[t+n-1]===0)throw new RangeError("Invalid varint: not minimally encoded");return[r,n]}function _e(e,t,r=0){return Ze.encode(e,t,r),t}function Re(e){return Ze.encodingLength(e)}function Pt(e,t){let r=t.byteLength,n=Re(e),s=n+Re(r),i=new Uint8Array(s+r);return _e(e,i,0),_e(r,i,n),i.set(t,s),new De(e,r,t,i)}function jt(e){let t=Bt(e),[r,n]=Ge(t),[s,i]=Ge(t.subarray(n)),o=t.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new De(r,s,o,t)}function Pi(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ai(e.bytes,r.bytes)}}var De=class{code;size;digest;bytes;constructor(t,r,n,s){this.code=t,this.size=r,this.digest=ue(n),this.bytes=ue(s)}};function Oi(e,t){let{bytes:r,version:n}=e;return n===0?kc(r,Dn(e),t??rt.encoder):Nc(r,Dn(e),t??Le.encoder)}var ki=new WeakMap;function Dn(e){let t=ki.get(e);if(t==null){let r=new Map;return ki.set(e,r),r}return t}var ht=class e{code;version;multihash;bytes;"/";constructor(t,r,n,s){this.code=r,this.version=t,this.multihash=n,this.bytes=ue(s),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==We)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Kc)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=Pt(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&&Pi(t.multihash,n.multihash)}toString(t){return Oi(this,t)}toJSON(){return{"/":Oi(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:s,multihash:i,bytes:o}=r;return new e(n,s,i,o??Ni(n,s,i.bytes))}else if(r[Fc]===!0){let{version:n,multihash:s,code:i}=r,o=jt(s);return e.create(n,i,o)}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!==We)throw new Error(`Version 0 CID must use dag-pb (code: ${We}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let s=Ni(t,r,n.bytes);return new e(t,r,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,We,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,s=Bt(t.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let i=s.subarray(r.multihashSize-r.digestSize),o=new De(r.multihashCode,r.digestSize,i,s);return[r.version===0?e.createV0(o):e.createV1(r.codec,o),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,h]=Ge(t.subarray(r));return r+=h,l},s=n(),i=We;if(s===18?(s=0,r=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=r,a=n(),c=n(),u=r+c,f=u-o;return{version:s,codec:i,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(t,r){let[n,s]=Oc(t,r),i=e.decode(s);if(i.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Dn(i).set(n,t),i}};function Oc(e,t){switch(e[0]){case"Q":{let r=t??rt;return[rt.prefix,r.decode(`${rt.prefix}${e}`)]}case rt.prefix:{let r=t??rt;return[rt.prefix,r.decode(e)]}case Le.prefix:{let r=t??Le;return[Le.prefix,r.decode(e)]}case Ye.prefix:{let r=t??Ye;return[Ye.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 kc(e,t,r){let{prefix:n}=r;if(n!==rt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=t.get(n);if(s==null){let i=r.encode(e).slice(1);return t.set(n,i),i}else return s}function Nc(e,t,r){let{prefix:n}=r,s=t.get(n);if(s==null){let i=r.encode(e);return t.set(n,i),i}else return s}var We=112,Kc=18;function Ni(e,t,r){let n=Re(e),s=n+Re(t),i=new Uint8Array(s+r.byteLength);return _e(e,i,0),_e(t,i,n),i.set(r,s),i}var Fc=Symbol.for("@ipld/js-cid/CID");var Cn={};yt(Cn,{identity:()=>Rt});var Ki=0,Mc="identity",Fi=Bt;function Uc(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 Pt(Ki,Fi(e))}var Rt={code:Ki,name:Mc,encode:Fi,digest:Uc};function gt(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 qc(e){return e.buffer instanceof ArrayBuffer}function It(e){return qc(e)?e:e.slice()}async function Mi(e,t,r,n){let s=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let i=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,It(t),It(r.subarray()));return n?.signal?.throwIfAborted(),i}function Kt(e=0){return new Uint8Array(e)}function wt(e=0){return new Uint8Array(e)}function Hc(e){return e?.buffer instanceof ArrayBuffer}function Ui(e){if(Hc(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function fe(e,t){t==null&&(t=e.reduce((s,i)=>s+i.length,0));let r=wt(t),n=0;for(let s of e)r.set(s,n),n+=s.length;return Ui(r)}var Hi=Symbol.for("@achingbrain/uint8arraylist");function qi(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let s=r+n.byteLength;if(t<s)return{buf:n,index:t-r};r=s}throw new RangeError("index is out of bounds")}function Rr(e){return!!e?.[Hi]}var lt=class e{bufs;length;[Hi]=!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(Rr(n)){r+=n.byteLength;for(let s of n.bufs)this.bufs.push(s)}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(Rr(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=qi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=qi(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(Rr(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:s}=this._subList(t,r);return fe(n,s)}subarray(t,r){let{bufs:n,length:s}=this._subList(t,r);return n.length===1?n[0]:fe(n,s)}sublist(t,r){let{bufs:n,length:s}=this._subList(t,r),i=new e;return i.length=s,i.bufs=n,i}_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=[],s=0;for(let i=0;i<this.bufs.length;i++){let o=this.bufs[i],a=s,c=a+o.byteLength;if(s=c,t>=c)continue;let u=t>=a&&t<c,f=r>a&&r<=c;if(u&&f){if(t===a&&r===c){n.push(o);break}let l=t-a;n.push(o.subarray(l,l+(r-t)));break}if(u){if(t===0){n.push(o);continue}n.push(o.subarray(t-a));continue}if(f){if(r===c){n.push(o);break}n.push(o.subarray(0,r-a));break}n.push(o)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Rr(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 s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let i=256,o=new Int32Array(i);for(let l=0;l<i;l++)o[l]=-1;for(let l=0;l<s;l++)o[n[l]]=l;let a=o,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let h=u;h>=0;h--){let d=this.get(l+h);if(n[h]!==d){f=Math.max(1,h-a[d]);break}}if(f===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=wt(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 s=Kt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,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 s=Kt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,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 s=Kt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,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=wt(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 s=Kt(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,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 s=Kt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,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 s=Kt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,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 s=Kt(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,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 s=Kt(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,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(!gt(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((s,i)=>s+i.byteLength,0)),n.length=r,n}};var Pn={};yt(Pn,{base10:()=>zc});var zc=$t({prefix:"9",name:"base10",alphabet:"0123456789"});var On={};yt(On,{base16:()=>Vc,base16upper:()=>$c});var Vc=it({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),$c=it({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var kn={};yt(kn,{base2:()=>jc});var jc=it({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Nn={};yt(Nn,{base256emoji:()=>Xc});var zi=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}"),Yc=zi.reduce((e,t,r)=>(e[r]=t,e),[]),Zc=zi.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Gc(e){return e.reduce((t,r)=>(t+=Yc[r],t),"")}function Wc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=Zc[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(s)}return new Uint8Array(t)}var Xc=Te({prefix:"\u{1F680}",name:"base256emoji",encode:Gc,decode:Wc});var Kn={};yt(Kn,{base64:()=>Jc,base64pad:()=>Qc,base64url:()=>tu,base64urlpad:()=>eu});var Jc=it({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Qc=it({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),tu=it({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),eu=it({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Fn={};yt(Fn,{base8:()=>ru});var ru=it({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Mn={};yt(Mn,{identity:()=>nu});var nu=Te({prefix:"\0",name:"identity",encode:e=>Ii(Bt(e)),decode:e=>Bt(Bi(e))});var Lh=new TextEncoder,_h=new TextDecoder;var Hn={};yt(Hn,{sha256:()=>le,sha512:()=>au});var ou=20;function qn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:s}){return new Un(e,t,r,n,s)}var Un=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,s,i){this.name=t,this.code=r,this.encode=n,this.minDigestLength=s??ou,this.maxDigestLength=i}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?Vi(n,this.code,r?.truncate):n.then(s=>Vi(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Vi(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 Pt(t,e)}function ji(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var le=qn({name:"sha2-256",code:18,encode:ji("SHA-256")}),au=qn({name:"sha2-512",code:19,encode:ji("SHA-512")});var zn={...Mn,...kn,...Fn,...Pn,...On,...Ln,..._n,...Tn,...Kn,...Nn},qh={...Hn,...Cn};function Zi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Yi=Zi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Vn=Zi("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=wt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),cu={utf8:Yi,"utf-8":Yi,hex:zn.base16,latin1:Vn,ascii:Vn,binary:Vn,...zn},Dr=cu;function Z(e,t="utf8"){let r=Dr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function Y(e,t="utf8"){let r=Dr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var uu=parseInt("11111",2),$n=parseInt("10000000",2),fu=parseInt("01111111",2),Gi={0:Xe,1:Xe,2:lu,3:pu,4:mu,5:du,6:hu,16:Xe,22:Xe,48:Xe};function Ft(e,t={offset:0}){let r=e[t.offset]&uu;if(t.offset++,Gi[r]!=null)return Gi[r](e,t);throw new Error("No decoder for tag "+r)}function Je(e,t){let r=0;if((e[t.offset]&$n)===$n){let n=e[t.offset]&fu,s="0x";t.offset++;for(let i=0;i<n;i++,t.offset++){if(t.offset>=e.byteLength)throw new Error("invalid DER element length");s+=e[t.offset].toString(16).padStart(2,"0")}r=parseInt(s,16)}else r=e[t.offset],t.offset++;if(!Number.isInteger(r)||r<0||r>e.byteLength-t.offset)throw new Error("invalid DER element length");return r}function Xe(e,t){Je(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Ft(e,t);if(n===null)break;r.push(n)}return r}function lu(e,t){let r=Je(e,t),n=t.offset,s=t.offset+r,i=[];for(let o=n;o<s;o++)o===n&&e[o]===0||i.push(e[o]);return t.offset+=r,Uint8Array.from(i)}function hu(e,t){let r=Je(e,t),n=t.offset+r,s=e[t.offset];t.offset++;let i=0,o=0;s<40?(i=0,o=s):s<80?(i=1,o=s-40):(i=2,o=s-80);let a=`${i}.${o}`,c=[];for(;t.offset<n;){let u=e[t.offset];if(t.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function du(e,t){return t.offset++,null}function pu(e,t){let r=Je(e,t),n=e[t.offset];t.offset++;let s=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 s}function mu(e,t){let r=Je(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function bu(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new lt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function jn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=bu(e.byteLength);return new lt(Uint8Array.from([t.byteLength|$n]),t)}function xt(e){let t=new lt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new lt(Uint8Array.from([2]),jn(t),t)}function Cr(e){let t=Uint8Array.from([0]),r=new lt(t,e);return new lt(Uint8Array.from([3]),jn(r),r)}function Zt(e,t=48){let r=new lt;for(let n of e)r.append(n);return new lt(Uint8Array.from([t]),jn(r),r)}var yu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),gu=Uint8Array.from([6,5,43,129,4,0,34]),wu=Uint8Array.from([6,5,43,129,4,0,35]),xu={ext:!0,kty:"EC",crv:"P-256"},Eu={ext:!0,kty:"EC",crv:"P-384"},Su={ext:!0,kty:"EC",crv:"P-521"},Yn=32,Zn=48,Gn=66;function Wn(e){let t=Ft(e);return Wi(t)}function Wi(e){let t=e[1][1][0],r=1,n,s;if(t.byteLength===Yn*2+1)return n=Y(t.subarray(r,r+Yn),"base64url"),s=Y(t.subarray(r+Yn),"base64url"),new Ce({...xu,key_ops:["verify"],x:n,y:s});if(t.byteLength===Zn*2+1)return n=Y(t.subarray(r,r+Zn),"base64url"),s=Y(t.subarray(r+Zn),"base64url"),new Ce({...Eu,key_ops:["verify"],x:n,y:s});if(t.byteLength===Gn*2+1)return n=Y(t.subarray(r,r+Gn),"base64url"),s=Y(t.subarray(r+Gn),"base64url"),new Ce({...Su,key_ops:["verify"],x:n,y:s});throw new et(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Xi(e){return Zt([xt(Uint8Array.from([1])),Zt([vu(e.crv)],160),Zt([Cr(new lt(Uint8Array.from([4]),Z(e.x??"","base64url"),Z(e.y??"","base64url")))],161)]).subarray()}function vu(e){if(e==="P-256")return yu;if(e==="P-384")return gu;if(e==="P-521")return wu;throw new et(`Invalid curve ${e}`)}var Ce=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Xi(this.jwk)),this._raw}toMultihash(){return Rt.digest(Mt(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}async verify(t,r,n){return Mi(this.jwk,r,t,n)}};var Pr=BigInt(4294967295),Ji=BigInt(32);function Au(e,t=!1){return t?{h:Number(e&Pr),l:Number(e>>Ji&Pr)}:{h:Number(e>>Ji&Pr)|0,l:Number(e&Pr)|0}}function Qi(e,t=!1){let r=e.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let i=0;i<r;i++){let{h:o,l:a}=Au(e[i],t);[n[i],s[i]]=[o,a]}return[n,s]}var Bu=e=>e/2**32|0,Iu=e=>e>>>0;function to(e,t,r,n){let s=Bu(r),i=Iu(r);e.setUint32(t,n?i:s,n),e.setUint32(t+4,n?s:i,n)}var Xn=(e,t,r)=>e>>>r,Jn=(e,t,r)=>e<<32-r|t>>>r,he=(e,t,r)=>e>>>r|t<<32-r,de=(e,t,r)=>e<<32-r|t>>>r,Qe=(e,t,r)=>e<<64-r|t>>>r-32,tr=(e,t,r)=>e>>>r-32|t<<64-r;function Ot(e,t,r,n){let s=(t>>>0)+(n>>>0);return{h:e+r+(s/2**32|0)|0,l:s|0}}var eo=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),ro=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,no=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),so=(e,t,r,n,s)=>t+r+n+s+(e/2**32|0)|0,io=(e,t,r,n,s)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(s>>>0),oo=(e,t,r,n,s,i)=>t+r+n+s+i+(e/2**32|0)|0;function Or(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}var Qn=e=>e?`"${e}" `:"";function Ut(e,t=""){if(typeof e!="number")throw new TypeError(Qn(t)+"expected number, got "+typeof e);if(!Number.isSafeInteger(e)||e<0)throw new RangeError(Qn(t)+"expected integer >= 0, got "+e);return e}function Tt(e,t,r=""){if(Or(e)&&(t===void 0||e.length===t))return e;t!==void 0&&Ut(t,"length");let n=Or(e),s=t!==void 0?` of length ${t}`:"",i=n?`length=${e.length}`:`type=${typeof e}`,o=Qn(r)+"expected Uint8Array"+s+", got "+i;throw n?new RangeError(o):new TypeError(o)}function kr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("expected hash wrapped by utils.createHasher");if(Ut(e.outputLen),Ut(e.blockLen),e.outputLen<1||e.blockLen<1)throw new Error("hash blockLen / outputLen must be >= 1")}var Lu=(e,t)=>{if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError((t==="object"?"":`"${t}" `)+"expected object, got type="+typeof e)},ao=(e,t)=>{Lu(e,t);let r=Object.getPrototypeOf(e);if(r!==Object.prototype&&r!==null)throw new TypeError(`"${t}" expected plain object`);if(Object.hasOwn(e,"__proto__"))throw new TypeError(`"${t}.__proto__" is not allowed`)};function Pe(e,t=!0){if(e.destroyed)throw new Error("hash was destroyed");if(t&&e.finished)throw new Error("digest() was already called")}function Nr(e,t){Tt(e,void 0,"output");let r=t.outputLen;if(!(e.length>=r))throw new RangeError('"output" expected length >= '+r)}function pe(...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 Dt(e,t){return e<<32-t|e>>>t}var uo=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",_u=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Fr(e){if(Tt(e),uo)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=_u[e[r]];return t}function co(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function Mr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(uo)try{return Uint8Array.fromHex(e)}catch(s){throw s instanceof SyntaxError?new RangeError(s.message):s}let t=e.length,r=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let s=0,i=0;s<r;s++,i+=2){let o=co(e.charCodeAt(i)),a=co(e.charCodeAt(i+1));if(o===void 0||a===void 0){let c=e[i]+e[i+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+i)}n[s]=o*16+a}return n}function ts(...e){let t=0;for(let n=0;n<e.length;n++){let s=e[n];Tt(s),t+=s.length}let r=new Uint8Array(t);for(let n=0,s=0;n<e.length;n++){let i=e[n];r.set(i,s),s+=i.length}return r}function Ru(e,t,r="opts"){return ao(e,"defaults"),t!==void 0&&ao(t,r),Object.assign(Object.create(null),e,t)}function es(e,t={}){if(typeof e!="function")throw new TypeError('"hashCons" expected function, got type='+typeof e);t=Ru({},t,"info");let r=(s,i)=>e(i).update(s).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=s=>e(s),Object.assign(r,t),Object.freeze(r)}function fo(e=32){Ut(e,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(e>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var rs=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function lo(e,t,r){return e&t^~e&r}function ho(e,t,r){return e&t^e&r^t&r}var er=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,s){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Kr(this.buffer)}update(t){Pe(this),Tt(t);let{view:r,buffer:n,blockLen:s}=this,i=t.length,o=!1;for(let a=0;a<i;){let c=Math.min(s-this.pos,i-a);if(c===s){let u=Kr(t);for(;s<=i-a;a+=s)this.process(u,a);o=!0;continue}n.set(a===0&&c===i?t:t.subarray(a,a+c),this.pos),this.pos+=c,a+=c,this.pos===s&&(this.process(r,0),this.pos=0,o=!0)}return this.length+=t.length,o&&this.roundClean(),this}digestInto(t){Pe(this),Nr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:i}=this,{pos:o}=this;r[o++]=128,r.fill(0,o),this.padOffset>s-o&&(this.process(n,0),r.fill(0)),to(n,s-8,this.length*8,i),this.process(n,0),this.roundClean();let a=t===r?n:Kr(t),c=this.outputLen,u=c/4,f=this.get();if(c%4||u>f.length)throw new Error("invalid outputLen");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],i)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneIntoMeta(t){let{buffer:r,length:n,finished:s,destroyed:i,pos:o}=this;return t.destroyed=i,t.finished=s,t.length=n,t.pos=o,o&&t.buffer.set(r),t}clone(){return this._cloneInto()}},po=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var mo=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Du=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]),Gt=new Uint32Array(64),ns=class extends er{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(t,r){super(64,t,8,!1),this.A=r[0]|0,this.B=r[1]|0,this.C=r[2]|0,this.D=r[3]|0,this.E=r[4]|0,this.F=r[5]|0,this.G=r[6]|0,this.H=r[7]|0}get(){let{A:t,B:r,C:n,D:s,E:i,F:o,G:a,H:c}=this;return[t,r,n,s,i,o,a,c]}set(t,r,n,s,i,o,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=i|0,this.F=o|0,this.G=a|0,this.H=c|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let l=0;l<16;l++,r+=4)Gt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let h=Gt[l-15],d=Gt[l-2],y=Dt(h,7)^Dt(h,18)^h>>>3,g=Dt(d,17)^Dt(d,19)^d>>>10;Gt[l]=g+Gt[l-7]+y+Gt[l-16]|0}let{A:n,B:s,C:i,D:o,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let h=Dt(a,6)^Dt(a,11)^Dt(a,25),d=f+h+lo(a,c,u)+Du[l]+Gt[l]|0,g=(Dt(n,2)^Dt(n,13)^Dt(n,22))+ho(n,s,i)|0;f=u,u=c,c=a,a=o+d|0,o=i,i=s,s=n,n=d+g|0}n=n+this.A|0,s=s+this.B|0,i=i+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,s,i,o,a,c,u,f)}roundClean(){pe(Gt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),pe(this.buffer)}},ss=class extends ns{constructor(){super(32,po)}};var bo=Qi(["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))),Cu=bo[0],Pu=bo[1],Wt=new Uint32Array(80),Xt=new Uint32Array(80),is=class extends er{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(t,r){super(128,t,16,!1),this.Ah=r[0]|0,this.Al=r[1]|0,this.Bh=r[2]|0,this.Bl=r[3]|0,this.Ch=r[4]|0,this.Cl=r[5]|0,this.Dh=r[6]|0,this.Dl=r[7]|0,this.Eh=r[8]|0,this.El=r[9]|0,this.Fh=r[10]|0,this.Fl=r[11]|0,this.Gh=r[12]|0,this.Gl=r[13]|0,this.Hh=r[14]|0,this.Hl=r[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:s,Ch:i,Cl:o,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:h,Gh:d,Gl:y,Hh:g,Hl:S}=this;return[t,r,n,s,i,o,a,c,u,f,l,h,d,y,g,S]}set(t,r,n,s,i,o,a,c,u,f,l,h,d,y,g,S){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=i|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=d|0,this.Gl=y|0,this.Hh=g|0,this.Hl=S|0}_cloneInto(t){return(t||=new this.constructor).set(...this.get()),this._cloneIntoMeta(t)}process(t,r){for(let b=0;b<16;b++,r+=4)Wt[b]=t.getUint32(r),Xt[b]=t.getUint32(r+=4);for(let b=16;b<80;b++){let v=Wt[b-15]|0,A=Xt[b-15]|0,O=he(v,A,1)^he(v,A,8)^Xn(v,A,7),K=de(v,A,1)^de(v,A,8)^Jn(v,A,7),k=Wt[b-2]|0,R=Xt[b-2]|0,C=he(k,R,19)^Qe(k,R,61)^Xn(k,R,6),q=de(k,R,19)^tr(k,R,61)^Jn(k,R,6),U=no(K,q,Xt[b-7],Xt[b-16]),G=so(U,O,C,Wt[b-7],Wt[b-16]);Wt[b]=G|0,Xt[b]=U|0}let{Ah:n,Al:s,Bh:i,Bl:o,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:h,Fh:d,Fl:y,Gh:g,Gl:S,Hh:w,Hl:B}=this;for(let b=0;b<80;b++){let v=he(l,h,14)^he(l,h,18)^Qe(l,h,41),A=de(l,h,14)^de(l,h,18)^tr(l,h,41),O=l&d^~l&g,K=h&y^~h&S,k=io(B,A,K,Pu[b],Xt[b]),R=oo(k,w,v,O,Cu[b],Wt[b]),C=k|0,q=he(n,s,28)^Qe(n,s,34)^Qe(n,s,39),U=de(n,s,28)^tr(n,s,34)^tr(n,s,39),G=n&i^n&a^i&a,T=s&o^s&c^o&c;w=g|0,B=S|0,g=d|0,S=y|0,d=l|0,y=h|0,{h:l,l:h}=Ot(u|0,f|0,R|0,C|0),u=a|0,f=c|0,a=i|0,c=o|0,i=n|0,o=s|0;let F=eo(C,U,T);n=ro(F,R,q,G),s=F|0}({h:n,l:s}=Ot(this.Ah|0,this.Al|0,n|0,s|0)),{h:i,l:o}=Ot(this.Bh|0,this.Bl|0,i|0,o|0),{h:a,l:c}=Ot(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Ot(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:h}=Ot(this.Eh|0,this.El|0,l|0,h|0),{h:d,l:y}=Ot(this.Fh|0,this.Fl|0,d|0,y|0),{h:g,l:S}=Ot(this.Gh|0,this.Gl|0,g|0,S|0),{h:w,l:B}=Ot(this.Hh|0,this.Hl|0,w|0,B|0),this.set(n,s,i,o,a,c,u,f,l,h,d,y,g,S,w,B)}roundClean(){pe(Wt,Xt)}destroy(){this.destroyed=!0,pe(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},os=class extends is{constructor(){super(64,mo)}};var Oe=es(()=>new ss,rs(1));var as=es(()=>new os,rs(3));function qr(e,t,r=()=>{}){if(!Array.isArray(e))throw new TypeError(`"${t}" expected array, got type=${typeof e}`);for(let n=0;n<e.length;n++)r(e[n],`${t}[${n}]`);return e}var V=(e,t,r)=>Tt(e,t,r),cs=Ut;function go(e,t=""){if(typeof e!="string"){let r=t&&`"${t}" `;throw new TypeError(r+"expected string, got type="+typeof e)}return e}function Jt(e,t="object"){if(e===null||typeof e!="object"||Array.isArray(e))throw new TypeError(t==="object"?"expected valid options object":`"${t}" expected object, got type=${typeof e}`);return e}function me(e,t){if(typeof e!="function")throw new TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}var rr=Fr,Lt=(...e)=>ts(...e),ke=e=>Mr(e),te=Or,be=e=>fo(e),Ur=BigInt(0),yo=BigInt(1),Ou=e=>e?`"${e}" `:"";function Et(e,t=""){if(typeof e!="boolean")throw new TypeError(Ou(t)+"expected boolean, got type="+typeof e);return e}function Hr(e){if(typeof e=="bigint"){if(!Qt(e))throw new RangeError("positive bigint expected, got "+e)}else cs(e);return e}function qt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(r+"expected number, got type="+typeof e)}if(!Number.isSafeInteger(e)){let r=t&&`"${t}" `;throw new RangeError(r+"expected safe integer, got "+e)}}function nr(e){let t=Hr(e).toString(16);return t.length&1?"0"+t:t}function wo(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?Ur:BigInt("0x"+e)}function kt(e){return wo(Fr(e))}function ye(e){return wo(Fr(sr(Tt(e)).reverse()))}function zr(e,t){if(Ut(t),t===0)throw new Error("zero output length is invalid");e=Hr(e);let r=t*2,n=e.toString(16);if(n.length>r)throw new RangeError("number is too large");return Mr(n.padStart(r,"0"))}function us(e,t){return zr(e,t).reverse()}function sr(e){return Uint8Array.from(V(e))}function Qt(e){return typeof e=="bigint"&&Ur<=e}function fs(e,t,r){return Qt(e)&&Qt(t)&&Qt(r)&&t<=e&&e<r}function Ne(e,t,r,n){if(!fs(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ke(e){if(e<Ur)throw new Error("expected non-negative bigint, got "+e);return e===Ur?0:e.toString(2).length}var ir=e=>(qt(e,"n"),(yo<<BigInt(e))-yo);function xo(e,t,r){if(Ut(e,"hashLen"),Ut(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=S=>new Uint8Array(S),s=Uint8Array.of(),i=Uint8Array.of(0),o=Uint8Array.of(1),a=1e3,c=n(e),u=n(e),f=0,l=()=>{c.fill(1),u.fill(0),f=0},h=(...S)=>r(u,Lt(c,...S)),d=(S=s)=>{u=h(i,S),c=h(),S.length!==0&&(u=h(o,S),c=h())},y=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let S=0,w=[];for(;S<t;){c=h();let B=c.slice();w.push(B),S+=c.length}return Lt(...w)};return(S,w)=>{l(),d(S);let B;for(;(B=w(y()))===void 0;)d();return l(),B}}function St(e,t={},r={},n="object"){Jt(e,n),Jt(t,"fields"),Jt(r,"optFields");function s(o,a,c){let u=n==="object"?`param "${String(o)}"`:`"${n}.${String(o)}"`,f=e[o];if(!Object.hasOwn(e,o)&&(c?f!==void 0:a!=="function"))throw new TypeError(`${u} is invalid: expected own property`);if(c&&f===void 0)return;let l=typeof f;if(l!==a||f===null)throw new TypeError(`${u} is invalid: expected ${a}, got ${l}`)}let i=(o,a)=>Object.entries(o).forEach(([c,u])=>s(c,u,a));i(t,!1),i(r,!0)}var ut=BigInt(0),$=BigInt(1),ee=BigInt(2),vo=BigInt(3),ls=BigInt(4),Ao=BigInt(5),ku=BigInt(7),Bo=BigInt(8),Nu=BigInt(9),Ku=BigInt(15),Io=BigInt(16),Fu=BigInt("0x10000000000000000");function nt(e,t){if(t<=ut)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=ut?r:t+r}function To(e,t,r){if(r<=$)throw new Error("pow: expected modulus > 1, got "+r);if(typeof t!="bigint")throw new TypeError("invalid exponent: expected bigint, got "+typeof t);if(t<ut)throw new Error("invalid exponent, negatives unsupported");if(t===ut)return $;if(t===$)return e;let n=e%r;if(n<ut&&(n+=r),t<Fu){let a=$;for(;t>ut;)t&$&&(a=a*n%r),n=n*n%r,t>>=$;return a}let s=[];for(;t>ut;)s.push(Number(t&Ku)),t>>=ls;let i=new Array(16);i[0]=$,i[1]=n;for(let a=2;a<16;a++)i[a]=i[a-1]*n%r;let o=i[s[s.length-1]];for(let a=s.length-2;a>=0;a--){o=o*o%r,o=o*o%r,o=o*o%r,o=o*o%r;let c=s[a];c!==0&&(o=o*i[c]%r)}return o}function Q(e,t,r){if(r<=$)throw new Error("pow2: expected modulus > 1, got "+r);if(t<ut)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >ut;)n*=n,n%=r;return n}function Eo(e,t){if(e===ut)throw new Error("invert: expected non-zero number");if(t<=$)throw new Error("invert: expected modulus > 1, got "+t);let r=nt(e,t),n=t,s=ut,i=$;for(;r!==ut;){let a=n/r,c=n-r*a,u=s-i*a;n=r,r=c,s=i,i=u}if(n!==$)throw new Error("invert: does not exist");return nt(s,t)}function Lo(e,t){if(t<=$)throw new Error("invertCt: expected prime modulus > 1, got "+t);let r=nt(e,t);if(r===ut)throw new Error("invertCt: expected non-zero number");let n=To(r,t-ee,t);if(nt(r*n,t)!==$)throw new Error("invertCt: does not exist");return n}function hs(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function ds(e,t){if((e&$)===ut)throw new Error(t+": expected odd modulus, got "+e)}function _o(e,t){let r=e,n=(r.ORDER+$)/ls,s=r.pow(t,n);return hs(r,s,t),s}function Mu(e,t){let r=e,n=(r.ORDER-Ao)/Bo,s=r.mul(t,ee),i=r.pow(s,n),o=r.mul(t,i),a=r.mul(r.mul(o,ee),i),c=r.mul(o,r.sub(a,r.ONE));return hs(r,c,t),c}function Uu(e){let t=Me(e),r=Ro(e),n=r(t,t.neg(t.ONE)),s=r(t,n),i=r(t,t.neg(n)),o=(e+ku)/Io;return((a,c)=>{let u=a,f=u.pow(c,o),l=u.mul(f,n),h=u.mul(f,s),d=u.mul(f,i),y=u.eql(u.sqr(l),c),g=u.eql(u.sqr(h),c);f=u.cmov(f,l,y),l=u.cmov(d,h,g);let S=u.eql(u.sqr(l),c),w=u.cmov(f,l,S);return hs(u,w,c),w})}function Ro(e){if(e<vo)throw new Error("sqrt is not defined for small field");ds(e,"tonelliShanks");let t=e-$,r=0;for(;t%ee===ut;)t/=ee,r++;let n=ee,s=Me(e);for(;or(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return _o;let i=s.pow(n,t),o=(t+$)/ee;return function(c,u){let f=c;if(f.is0(u))return u;if(or(f,u)!==1)throw new Error("Cannot find square root");let l=r,h=f.mul(f.ONE,i),d=f.pow(u,t),y=f.pow(u,o);for(;!f.eql(d,f.ONE);){if(f.is0(d))throw new Error("Cannot find square root: probably non-prime P");let g=1,S=f.sqr(d);for(;!f.eql(S,f.ONE);)if(g++,S=f.sqr(S),g===l)throw new Error("Cannot find square root");let w=$<<BigInt(l-g-1),B=f.pow(h,w);l=g,h=f.sqr(B),d=f.mul(d,h),y=f.mul(y,B)}return y}}function qu(e){return ds(e,"Fp.sqrt"),e%ls===vo?_o:e%Bo===Ao?Mu:e%Io===Nu?Uu(e):Ro(e)}var Do=(e,t)=>(nt(e,t)&$)===$,Hu=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Fe(e){if(Jt(e,"field"),typeof e.ORDER!="bigint")throw new TypeError('param "ORDER" is invalid: expected bigint, got '+typeof e.ORDER);qt(e.BYTES,"BYTES"),qt(e.BITS,"BITS");for(let t of Hu)me(e[t],"field."+t);if(e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=$)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function $r(e,t,r=!1){Fe(e),qr(t,"nums"),Et(r,"passZero");let n=e,s=new Array(t.length).fill(r?n.ZERO:void 0),i=t.reduce((a,c,u)=>n.is0(c)?a:(s[u]=a,n.mul(a,c)),n.ONE),o=n.inv(i);return t.reduceRight((a,c,u)=>n.is0(c)?a:(s[u]=n.mul(a,s[u]),n.mul(a,c)),o),s}function or(e,t){Fe(e);let r=e;ds(r.ORDER,"FpLegendre");let n=(r.ORDER-$)/ee,s=r.pow(t,n),i=r.eql(s,r.ONE),o=r.eql(s,r.ZERO),a=r.eql(s,r.neg(r.ONE));if(!i&&!o&&!a)throw new Error("invalid Legendre symbol result");return i?1:o?0:-1}function zu(e,t){if(t!==void 0&&cs(t),e<=ut)throw new Error("invalid n length: expected positive n, got "+e);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let r=Ke(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${r})`);let n=t!==void 0?t:r,s=Math.ceil(n/8);return{nBitLength:n,nByteLength:s}}var So=new WeakMap,Vr=class{ORDER;BITS;BYTES;isLE;ZERO=ut;ONE=$;_lengths;_mod;constructor(t,r={}){if(t<=$)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:r.sqrt,enumerable:!0}),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=Object.freeze(r.allowedLengths.slice())),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:s,nByteLength:i}=zu(t,n);if(i>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=s,this.BYTES=i,Object.freeze(this)}create(t){return nt(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return ut<=t&&t<this.ORDER}is0(t){return t===ut}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&$)===$}neg(t){return nt(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return nt(t*t,this.ORDER)}add(t,r){return nt(t+r,this.ORDER)}sub(t,r){return nt(t-r,this.ORDER)}mul(t,r){return nt(t*r,this.ORDER)}pow(t,r){return To(t,r,this.ORDER)}div(t,r){return nt(t*Eo(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return Eo(t,this.ORDER)}sqrt(t){let r=So.get(this);return r||So.set(this,r=qu(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?us(t,this.BYTES):zr(t,this.BYTES)}fromBytes(t,r=!1){V(t);let{_lengths:n,BYTES:s,isLE:i,ORDER:o,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let u=new Uint8Array(s);u.set(t,i?0:u.length-t.length),t=u}if(t.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);let c=i?ye(t):kt(t);if(a&&(c=nt(c,o)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return $r(this,t,!0)}cmov(t,r,n){return Et(n,"condition"),n?r:t}};function Me(e,t={}){return Object.freeze(Vr.prototype),new Vr(e,t)}function Co(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=$)throw new Error("field order must be greater than 1");let t=Ke(e-$);return Math.ceil(t/8)}function jr(e){let t=Co(e);return t+Math.ceil(t/2)}function Yr(e,t,r=!1){V(e);let n=e.length,s=Co(t),i=Math.max(jr(t),16);if(n<i||n>1024)throw new Error("expected "+i+"-1024 bytes of input, got "+n);let o=r?ye(e):kt(e),a=nt(o,t-$)+$;return r?us(a,s):zr(a,s)}var bs=BigInt(0),ar=BigInt(1),Vu=BigInt(4),ps=16,Po=128,$u=5,Oo=2**31;function re(e){let t=e;if(typeof t!="function")throw new TypeError('"Point" expected constructor, got type='+typeof e);me(t.fromAffine,"Point.fromAffine"),me(t.fromBytes,"Point.fromBytes"),me(t.fromHex,"Point.fromHex"),Jt(t.BASE,"Point.BASE"),Jt(t.ZERO,"Point.ZERO"),Fe(t.Fp),Fe(t.Fn)}function Zr(e,t){re(e),No(t,e);let r=$r(e.Fp,t.map(n=>n.Z));return t.map((n,s)=>e.fromAffine(n.toAffine(r[s])))}function ju(e,t,r=1){if(!Number.isSafeInteger(e)||e<r||e>t)throw new Error("invalid window size, expected ["+r+".."+t+"], got W="+e)}function Yu(e,t){let r=e*(4*t+128);if(r>Oo)throw new Error("invalid window size: table would need ~"+Math.ceil(r/2**20)+" MiB, max "+Oo/2**20+" MiB")}function ys(e,t){if(e!==void 0){me(e,"randomBytes");try{let r=e(t);if(!te(r)||r.length!==t)return}catch{return}return e}}function No(e,t){qr(e,"points"),e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Zu(e,t,r){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((n,s)=>{if(!(r===void 0?t.isValid(n):Qt(n)&&n<r))throw new Error("invalid scalar at index "+s)})}var Ko=new WeakMap;function ms(e){return Ko.get(e)||1}function Gu(e,t){let r=e.double(),n=[e];for(let s=1;s<t;s++)n.push(n[s-1].add(r));return n}function Wu(e,t){let r=2**t,n=r/2,s=BigInt(r-1),i=[];for(;e>bs;){let o=0;e&ar&&(o=Number(e&s),o>=n&&(o-=r),e-=BigInt(o)),i.push(o),e>>=ar}return i}function Xu(e,t,r){let n=2**t,s=n/2,i=BigInt(n-1),o=BigInt(t),a=[];for(let c=0;c<r;c++){let u=Number(e&i);e>>=o,u>s&&(u-=n,e+=ar),a.push(u)}if(e!==bs)throw new Error("invalid wnaf");return a}function Ju(e,t,r){let n=0;for(let i of r)n=Math.max(n,i.length);let s=e;for(let i=n-1;i>=0;i--){i!==n-1&&(s=s.double());for(let o=0;o<r.length;o++){let a=r[o][i];if(a){let c=t[o][Math.abs(a)-1>>1];s=s.add(a<0?c.negate():c)}}}return s}var Ue=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(t,r){re(t),this.randomBytes=ys(r,ps),this.Point=t,this.BASE=t.BASE,this.ZERO=t.ZERO,this.bits=t.Fn.BITS}buildWnafTable(t,r,n){let s=Math.ceil(n/r)+1,i=2**(r-1),o=[],a=t;for(let c=0;c<s;c++){let u=a;for(let f=0;f<i;f++)o.push(u),u=u.add(a);a=o[o.length-1].double()}return{W:r,bits:n,windows:s,comp:o}}wnafCachedCT(t,r){let{W:n,windows:s,comp:i}=t,o=2**(n-1),a=Xu(r,n,s),c=this.ZERO,u=this.BASE;for(let f=0;f<s;f++){let l=a[f],h=f*o,d=Math.abs(l)-1,y=i[h];for(let S=1;S<o;S++)y=S===d?i[h+S]:y;let g=y.negate();l===0?u=u.add(i[h]):c=c.add(l<0?g:y)}return{p:c,f:u}}getWnafPrecomputes(t,r,n,s){let i=this.wnafPrecomputes.get(r),o=i?.find(a=>a.W===t&&a.bits===n);return o||(o=this.buildWnafTable(r,t,n),typeof s=="function"&&(o={...o,comp:s(o.comp)}),i||(i=[],this.wnafPrecomputes.set(r,i)),i.push(o)),o}assertPoint(t){if(!(t instanceof this.Point))throw new TypeError('"point" expected Point instance, got type='+typeof t)}validateMulInput(t,r){if(this.assertPoint(t),!fs(r,ar,this.Point.Fn.ORDER))throw new Error("invalid scalar")}runCT(t,r,n,s){let i=ms(t);return i===1?this.fixedWindowCT(t,r,n):this.wnafCachedCT(this.getWnafPrecomputes(i,t,n,s),r)}mulCT(t,r,n){return this.validateMulInput(t,r),this.runCT(t,r,this.bits,n)}mulCTBlinded(t,r,n){if(this.validateMulInput(t,r),this.randomBytes===void 0)throw new Error("randomBytes is required for scalar blinding");let s=this.Point.Fn.BITS+Po,i=this.randomBytes(ps);if(!te(i)||i.length!==ps)throw new Error("randomBytes returned invalid byte array");i[0]=i[0]&63|128;let o=r+kt(i)*this.Point.Fn.ORDER;return this.runCT(t,o,s,n)}fixedWindowCT(t,r,n){let s=$u,i=1<<s,o=ir(s),a=new Array(i);a[0]=this.ZERO;for(let f=1;f<i;f++)a[f]=a[f-1].add(t);let c=Math.ceil(n/s),u=this.ZERO;for(let f=c-1;f>=0;f--){if(f!==c-1)for(let d=0;d<s;d++)u=u.double();let l=Number(r>>BigInt(f*s)&o),h=a[0];for(let d=1;d<i;d++)h=d===l?a[d]:h;u=u.add(h)}return{p:u,f:u}}shouldBlind(t,r){return this.randomBytes===void 0?!1:r===ar?!0:t!==this.BASE?!1:(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(t,r,n,s){return this.shouldBlind(t,n)?this.mulCTBlinded(t,r,s):this.mulCT(t,r,s)}mulUnsafe(t,r,n){if(this.assertPoint(t),!Qt(r))throw new Error("invalid scalar");let s=ms(t);if(s===1||r>=this.Point.Fn.ORDER)return Gr(this.Point,[t],[r],!0);let i=this.getWnafPrecomputes(s,t,this.bits,n);return this.wnafCachedCT(i,r).p}setWindowSize(t,r){this.assertPoint(t),ju(r,this.bits);let n=Math.ceil((this.bits+Po)/r)+1;Yu(n*2**(r-1),this.Point.Fp.BYTES),Ko.set(t,r),this.wnafPrecomputes.delete(t)}hasWindowSize(t){return ms(t)!==1}};function Gr(e,t,r,n=!1){if(re(e),No(t,e),Et(n,"allowOversized"),Zu(r,e.Fn,n?e.Fn.ORDER**Vu:void 0),t.length!==r.length)throw new Error("arrays of points and scalars must have equal length");let s=t.map(o=>Gu(o,4)),i=r.map(o=>Wu(o,4));return Ju(e.ZERO,s,i)}function ko(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Fe(t),t}else return Me(e,{isLE:r})}function Wr(e,t,r={},n){if(e!=="weierstrass"&&e!=="edwards")throw new Error('expected curve type "weierstrass" or "edwards"');if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);St(r);for(let c of["p","n","h"]){let u=t[c];if(!(Qt(u)&&u!==bs))throw new Error(`CURVE.${c} must be positive bigint`)}let s=ko(t.p,r.Fp,n),i=ko(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let c of a)if(!s.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:s,Fn:i}}function Xr(e,t){return function(n){let s=e(n);return{secretKey:s,publicKey:t(s)}}}var Jr=BigInt(0),Qr=BigInt(1),tn=BigInt(2),Qu=BigInt(4),Fo=BigInt(8);function tf(e,t,r,n){let s=e.sqr(r),i=e.sqr(n),o=e.add(e.mul(t.a,s),i),a=e.add(e.ONE,e.mul(t.d,e.mul(s,i)));return e.eql(o,a)}function Mo(e,t={}){St(t,{},{},"extraOpts");let r=t,n=Wr("edwards",e,r,r.FpFnLE),{Fp:s,Fn:i}=n,o=n.CURVE,{h:a}=o;if(or(s,o.a)!==1)throw new Error("edwards: CURVE.a must be a square in Fp for complete addition formulas");if(or(s,o.d)!==-1)throw new Error("edwards: CURVE.d must be a non-square in Fp for complete addition formulas");St(r,{},{uvRatio:"function",randomBytes:"function"});let c=r.randomBytes===void 0?be:r.randomBytes,u=tn<<BigInt(s.BYTES*8)-Qr;function f(B){if(!s.isOdd)throw new Error("Field does not have .isOdd()");return s.isOdd(B)}let l=r.uvRatio===void 0?(B,b)=>{try{return{isValid:!0,value:s.sqrt(s.div(B,b))}}catch{return{isValid:!1,value:Jr}}}:r.uvRatio;if(!tf(s,o,o.Gx,o.Gy))throw new Error("bad curve params: generator point");let h=s.eql(o.a,s.neg(s.ONE))?B=>s.neg(B):s.eql(o.a,s.ONE)?B=>B:B=>s.mul(o.a,B);function d(B,b,v=!1){let A=v?Qr:Jr;return Ne("coordinate "+B,b,A,u),b}function y(B){if(!(B instanceof g))throw new Error("EdwardsPoint expected")}class g{static BASE=new g(o.Gx,o.Gy,s.ONE,s.mul(o.Gx,o.Gy));static ZERO=new g(s.ZERO,s.ONE,s.ONE,s.ZERO);static Fp=s;static Fn=i;X;Y;Z;T;constructor(b,v,A,O){this.X=d("x",b),this.Y=d("y",v),this.Z=d("z",A,!0),this.T=d("t",O),Object.freeze(this)}static CURVE(){return o}static fromAffine(b){if(b instanceof g)throw new Error("extended point not allowed");let{x:v,y:A}=b||{};return d("x",v),d("y",A),new g(v,A,s.ONE,s.mul(v,A))}static fromBytes(b,v=!1){let A=s.BYTES,{a:O,d:K}=o;b=sr(V(b,A,"point")),Et(v,"zip215");let k=sr(b),R=b[A-1];k[A-1]=R&-129;let C=ye(k),q=v?u:s.ORDER;Ne("point.y",C,Jr,q);let U=s.sqr(C),G=s.sub(U,s.ONE),T=s.sub(s.mulN(K,U),O),{isValid:F,value:M}=l(G,T);if(!F)throw new Error("bad point: invalid y coordinate");let D=f(M),W=(R&128)!==0;if(!v&&s.is0(M)&&W)throw new Error("bad point: x=0 and x_0=1");return W!==D&&(M=s.neg(M)),g.fromAffine({x:M,y:C})}static fromHex(b,v=!1){return g.fromBytes(ke(b),v)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=6,v=!0){return w.setWindowSize(this,b),v||this.multiply(tn),this}assertValidity(){let b=this,{a:v,d:A}=o;if(b.is0())throw new Error("bad point: ZERO");let{X:O,Y:K,Z:k,T:R}=b,C=s.sqr(O),q=s.sqr(K),U=s.sqr(k),G=s.sqr(U),T=s.mul(C,v),F=s.mul(s.add(T,q),U),M=s.add(G,s.mul(A,s.mul(C,q)));if(!s.eql(F,M))throw new Error("bad point: equation left != right (1)");let D=s.mul(O,K),W=s.mul(k,R);if(!s.eql(D,W))throw new Error("bad point: equation left != right (2)")}equals(b){y(b);let{X:v,Y:A,Z:O}=this,{X:K,Y:k,Z:R}=b,C=s.mul(v,R),q=s.mul(K,O),U=s.mul(A,R),G=s.mul(k,O);return s.eql(C,q)&&s.eql(U,G)}is0(){return this.equals(g.ZERO)}negate(){return new g(s.neg(this.X),this.Y,this.Z,s.neg(this.T))}double(){let{X:b,Y:v,Z:A}=this,O=s.sqr(b),K=s.sqr(v),k=s.mul(s.sqr(A),tn),R=h(O),C=s.addN(b,v),q=s.sub(s.subN(s.sqr(C),O),K),U=s.addN(R,K),G=s.subN(U,k),T=s.subN(R,K),F=s.mul(q,G),M=s.mul(U,T),D=s.mul(q,T),W=s.mul(G,U);return new g(F,M,W,D)}add(b){y(b);let{d:v}=o,{X:A,Y:O,Z:K,T:k}=this,{X:R,Y:C,Z:q,T:U}=b,G=s.mul(A,R),T=s.mul(O,C),F=s.mul(s.mulN(k,v),U),M=s.mul(K,q),D=s.sub(s.subN(s.mulN(s.addN(A,O),s.addN(R,C)),G),T),W=s.subN(M,F),tt=s.addN(M,F),E=s.sub(T,h(G)),p=s.mul(D,W),m=s.mul(tt,E),x=s.mul(D,E),I=s.mul(W,tt);return new g(p,m,I,x)}subtract(b){return y(b),this.add(b.negate())}multiply(b){if(!i.isValidNot0(b))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:v,f:A}=w.mulSecret(this,b,a,S);return S([v,A])[0]}multiplyUnsafe(b){if(!i.isValid(b))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return b===Jr?g.ZERO:this.is0()||b===Qr?this:w.mulUnsafe(this,b,S)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return w.mulUnsafe(this,o.n).is0()}toAffine(b){let v=this,A=b;if(A!=null&&typeof A!="bigint")throw new TypeError('"invertedZ" expected bigint, got type='+typeof A);let{X:O,Y:K,Z:k}=v,R=v.is0();A==null&&(A=R?s.create(Fo):s.inv(k));let C=s.mul(O,A),q=s.mul(K,A),U=s.mul(k,A);if(R)return{x:s.ZERO,y:s.ONE};if(!s.eql(U,s.ONE))throw new Error("invZ was invalid");return{x:C,y:q}}clearCofactor(){return a===Qr?this:a===tn?this.double():a===Qu?this.double().double():a===Fo?this.double().double().double():this.multiplyUnsafe(a)}toBytes(){let{x:b,y:v}=this.toAffine(),A=s.toBytes(v);return A[A.length-1]|=f(b)?128:0,A}toHex(){return rr(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let S=B=>Zr(g,B),w=new Ue(g,c);return w.bits>=6&&g.BASE.precompute(6),Object.freeze(g.prototype),Object.freeze(g),g}function Uo(e,t,r={}){if(re(e),typeof t!="function")throw new Error('"hash" function param is required');let n=t,s=r;St(s,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function",toMontgomery:"function",toMontgomerySecret:"function"});let{prehash:i}=s,{BASE:o,Fp:a,Fn:c}=e,u=n.outputLen,f=2*a.BYTES;if(u!==void 0&&(qt(u,"hash.outputLen"),u!==f))throw new Error(`hash.outputLen must be ${f}, got ${u}`);let l=s.randomBytes===void 0?be:s.randomBytes,h=s.toMontgomery,d=s.toMontgomerySecret,y=s.adjustScalarBytes===void 0?T=>T:s.adjustScalarBytes,g=s.domain===void 0?(T,F,M)=>{if(Et(M,"phflag"),F.length||M)throw new Error("Contexts/pre-hash are not supported");return T}:s.domain;function S(T){return c.create(ye(T))}function w(T){let F=R.secretKey;V(T,R.secretKey,"secretKey");let M=V(n(T),2*F,"hashedSecretKey"),D=y(M.slice(0,F)),W=M.slice(F,2*F),tt=S(D);return{head:D,prefix:W,scalar:tt}}function B(T){let{head:F,prefix:M,scalar:D}=w(T),W=o.multiply(D),tt=W.toBytes();return{head:F,prefix:M,scalar:D,point:W,pointBytes:tt}}function b(T){return B(T).pointBytes}function v(T=Uint8Array.of(),...F){let M=Lt(...F);return S(n(g(M,V(T,void 0,"context"),!!i)))}function A(T,F,M={}){St(M,{},{},"options"),T=sr(V(T,void 0,"message")),i&&(T=i(T));let{prefix:D,scalar:W,pointBytes:tt}=B(F),E=v(M.context,D,T),p=o.multiply(E).toBytes(),m=v(M.context,p,tt,T),x=c.create(E+m*W);if(!c.isValid(x))throw new Error("sign failed: invalid s");let I=Lt(p,c.toBytes(x));return V(I,R.signature,"result")}let O={zip215:s.zip215};function K(T,F,M,D=O){St(D);let{context:W}=D,tt=D.zip215===void 0?!!O.zip215:D.zip215,E=R.signature;T=V(T,E,"signature"),F=V(F,void 0,"message"),M=V(M,R.publicKey,"publicKey"),tt!==void 0&&Et(tt,"zip215"),i&&(F=i(F));let p=E/2,m=T.subarray(0,p),x=ye(T.subarray(p,E)),I,L,_;try{I=e.fromBytes(M,tt),L=e.fromBytes(m,tt),_=o.multiplyUnsafe(x)}catch{return!1}if(!tt&&I.isSmallOrder())return!1;let P=v(W,m,M,F);return L.add(I.multiplyUnsafe(P)).subtract(_).clearCofactor().is0()}let k=a.BYTES,R={secretKey:k,publicKey:k,signature:2*k,seed:k};function C(T){return T=T===void 0?l(R.seed):T,V(T,R.seed,"seed")}function q(T){return te(T)&&T.length===R.secretKey}function U(T,F){try{return!!e.fromBytes(T,F===void 0?O.zip215:F)}catch{return!1}}let G={getExtendedPublicKey:B,randomSecretKey:C,isValidSecretKey:q,isValidPublicKey:U,toMontgomery(T){if(h===void 0)throw new Error("Montgomery conversion is not supported for this curve");return h(e.fromBytes(T))},toMontgomerySecret(T){if(d===void 0)throw new Error("Montgomery conversion is not supported for this curve");return d(T)}};return Object.freeze(R),Object.freeze(G),Object.freeze({keygen:Xr(C,b),getPublicKey:b,sign:A,verify:K,utils:G,Point:e,lengths:R})}var gs=BigInt(1),qo=BigInt(2);var ef=BigInt(5),rf=BigInt(8),ws=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),nf={p:ws,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:rf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function sf(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),s=BigInt(80),i=ws,a=e*e%i*e%i,c=Q(a,qo,i)*a%i,u=Q(c,gs,i)*e%i,f=Q(u,ef,i)*u%i,l=Q(f,t,i)*f%i,h=Q(l,r,i)*l%i,d=Q(h,n,i)*h%i,y=Q(d,s,i)*d%i,g=Q(y,s,i)*d%i,S=Q(g,t,i)*f%i;return{pow_p_5_8:Q(S,qo,i)*e%i,b2:a}}function Vo(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ho=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function of(e,t){let r=ws,n=nt(t*t*t,r),s=nt(n*n*t,r),i=sf(e*s).pow_p_5_8,o=nt(e*n*i,r),a=nt(t*o*o,r),c=o,u=nt(o*Ho,r),f=a===e,l=a===nt(-e,r),h=a===nt(-e*Ho,r);return f&&(o=c),(l||h)&&(o=u),Do(o,r)&&(o=nt(-o,r)),{isValid:f||l,value:o}}var xs=Mo(nf,{uvRatio:of}),zo=xs.Fp;function af(e){let{y:t}=e;return zo.toBytes(zo.div(gs+t,gs-t))}function cf(e){let t=xs.Fp.BYTES;return Tt(e,t),Vo(as(e.subarray(0,t))).subarray(0,t)}function uf(e){return Uo(xs,as,Object.assign({adjustScalarBytes:Vo,toMontgomery:af,toMontgomerySecret:cf,zip215:!0},e))}var $o=uf({});var cr=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},en=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var _t={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new en("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 rn=32;var Es,ff=(async()=>{try{return await _t.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function lf(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await _t.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await _t.get().subtle.verify({name:"Ed25519"},n,It(t),It(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function hf(e,t,r){return $o.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function jo(e,t,r){return Es==null&&(Es=await ff),Es?lf(e,t,r):hf(e,t,r)}function nn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var sn=class{type="Ed25519";raw;constructor(t){this.raw=Ss(t,rn)}toMultihash(){return Rt.digest(Mt(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let s=jo(this.raw,r,t);return nn(s)?s.then(i=>(n?.signal?.throwIfAborted(),i)):s}};function vs(e){return e=Ss(e,rn),new sn(e)}function Ss(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new et(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var pf=Math.pow(2,7),mf=Math.pow(2,14),bf=Math.pow(2,21),As=Math.pow(2,28),Bs=Math.pow(2,35),Is=Math.pow(2,42),Ts=Math.pow(2,49),j=128,dt=127;function Ht(e){if(e<pf)return 1;if(e<mf)return 2;if(e<bf)return 3;if(e<As)return 4;if(e<Bs)return 5;if(e<Is)return 6;if(e<Ts)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Ls(e,t,r=0){switch(Ht(e)){case 8:t[r++]=e&255|j,e/=128;case 7:t[r++]=e&255|j,e/=128;case 6:t[r++]=e&255|j,e/=128;case 5:t[r++]=e&255|j,e/=128;case 4:t[r++]=e&255|j,e>>>=7;case 3:t[r++]=e&255|j,e>>>=7;case 2:t[r++]=e&255|j,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function yf(e,t,r=0){switch(Ht(e)){case 8:t.set(r++,e&255|j),e/=128;case 7:t.set(r++,e&255|j),e/=128;case 6:t.set(r++,e&255|j),e/=128;case 5:t.set(r++,e&255|j),e/=128;case 4:t.set(r++,e&255|j),e>>>=7;case 3:t.set(r++,e&255|j),e>>>=7;case 2:t.set(r++,e&255|j),e>>>=7;case 1:{t.set(r++,e&255),e>>>=7;break}default:throw new Error("unreachable")}return t}function _s(e,t){let r=e[t],n=0;if(n+=r&dt,r<j||(r=e[t+1],n+=(r&dt)<<7,r<j)||(r=e[t+2],n+=(r&dt)<<14,r<j)||(r=e[t+3],n+=(r&dt)<<21,r<j)||(r=e[t+4],n+=(r&dt)*As,r<j)||(r=e[t+5],n+=(r&dt)*Bs,r<j)||(r=e[t+6],n+=(r&dt)*Is,r<j)||(r=e[t+7],n+=(r&dt)*Ts,r<j))return n;throw new RangeError("Could not decode varint")}function gf(e,t){let r=e.get(t),n=0;if(n+=r&dt,r<j||(r=e.get(t+1),n+=(r&dt)<<7,r<j)||(r=e.get(t+2),n+=(r&dt)<<14,r<j)||(r=e.get(t+3),n+=(r&dt)<<21,r<j)||(r=e.get(t+4),n+=(r&dt)*As,r<j)||(r=e.get(t+5),n+=(r&dt)*Bs,r<j)||(r=e.get(t+6),n+=(r&dt)*Is,r<j)||(r=e.get(t+7),n+=(r&dt)*Ts,r<j))return n;throw new RangeError("Could not decode varint")}function Zo(e,t,r=0){return t==null&&(t=wt(Ht(e))),t instanceof Uint8Array?Ls(e,t,r):yf(e,t,r)}function Go(e,t=0){return e instanceof Uint8Array?_s(e,t):gf(e,t)}var Rs=new Float32Array([-0]),ne=new Uint8Array(Rs.buffer);function Wo(e,t,r){Rs[0]=e,t[r]=ne[0],t[r+1]=ne[1],t[r+2]=ne[2],t[r+3]=ne[3]}function Xo(e,t){return ne[0]=e[t],ne[1]=e[t+1],ne[2]=e[t+2],ne[3]=e[t+3],Rs[0]}var Ds=new Float64Array([-0]),pt=new Uint8Array(Ds.buffer);function Jo(e,t,r){Ds[0]=e,t[r]=pt[0],t[r+1]=pt[1],t[r+2]=pt[2],t[r+3]=pt[3],t[r+4]=pt[4],t[r+5]=pt[5],t[r+6]=pt[6],t[r+7]=pt[7]}function Qo(e,t){return pt[0]=e[t],pt[1]=e[t+1],pt[2]=e[t+2],pt[3]=e[t+3],pt[4]=e[t+4],pt[5]=e[t+5],pt[6]=e[t+6],pt[7]=e[t+7],Ds[0]}var xf=BigInt(Number.MAX_SAFE_INTEGER),Ef=BigInt(Number.MIN_SAFE_INTEGER),vt=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<xf&&t>Ef)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,s=t-(n<<32n);return r&&(n=~n|0n,s=~s|0n,++s>ta&&(s=0n,++n>ta&&(n=0n))),new e(Number(s),Number(n))}static fromNumber(t){if(t===0)return ge;let r=t<0;r&&(t=-t);let n=t>>>0,s=(t-n)/4294967296>>>0;return r&&(s=~s>>>0,n=~n>>>0,++n>4294967295&&(n=0,++s>4294967295&&(s=0))),new e(n,s)}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 vt(0,0);ge.toBigInt=function(){return 0n};ge.zzEncode=ge.zzDecode=function(){return this};ge.length=function(){return 1};var ta=4294967296n;function ea(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 ra(e,t,r){if(r-t<1)return"";let s,i=[],o=0,a;for(;t<r;)a=e[t++],a<128?i[o++]=a:a>191&&a<224?i[o++]=(a&31)<<6|e[t++]&63:a>239&&a<365?(a=((a&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,i[o++]=55296+(a>>10),i[o++]=56320+(a&1023)):i[o++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,o>8191&&((s??(s=[])).push(String.fromCharCode.apply(String,i)),o=0);return s!=null?(o>0&&s.push(String.fromCharCode.apply(String,i.slice(0,o))),s.join("")):String.fromCharCode.apply(String,i.slice(0,o))}function Cs(e,t,r){let n=r,s,i;for(let o=0;o<e.length;++o)s=e.charCodeAt(o),s<128?t[r++]=s:s<2048?(t[r++]=s>>6|192,t[r++]=s&63|128):(s&64512)===55296&&((i=e.charCodeAt(o+1))&64512)===56320?(s=65536+((s&1023)<<10)+(i&1023),++o,t[r++]=s>>18|240,t[r++]=s>>12&63|128,t[r++]=s>>6&63|128,t[r++]=s&63|128):(t[r++]=s>>12|224,t[r++]=s>>6&63|128,t[r++]=s&63|128);return r-n}function Ct(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function on(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Ps=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=It(t),this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,Ct(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ct(this,4);return on(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ct(this,4);return on(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ct(this,4);let t=Xo(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ct(this,4);let t=Qo(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 Ct(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return ra(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Ct(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Ct(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new vt(0,0),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 Ct(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 Ct(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 Ct(this,8);let t=on(this.buf,this.pos+=4),r=on(this.buf,this.pos+=4);return new vt(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=_s(this.buf,this.pos);return this.pos+=Ht(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 ur(e){return new Ps(e instanceof Uint8Array?e:e.subarray())}function se(e,t,r){let n=ur(e);return t.decode(n,void 0,r)}function Os(e){let t=e??8192,r=t>>>1,n,s=t;return function(o){if(o<1||o>r)return wt(o);s+o>t&&(n=wt(t),s=0);let a=n.subarray(s,s+=o);return(s&7)!==0&&(s=(s|7)+1),a}}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 ks(){}var Ks=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Sf=Os();function vf(e){return globalThis.Buffer!=null?wt(e):Sf(e)}var lr=class{len;head;tail;states;constructor(){this.len=0,this.head=new we(ks,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 Fs((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(an,10,vt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=vt.fromBigInt(t);return this._push(an,r.length(),r)}uint64Number(t){return this._push(Ls,Ht(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=vt.fromBigInt(t).zzEncode();return this._push(an,r.length(),r)}sint64Number(t){let r=vt.fromNumber(t).zzEncode();return this._push(an,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ns,1,t?1:0)}fixed32(t){return this._push(fr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=vt.fromBigInt(t);return this._push(fr,4,r.lo)._push(fr,4,r.hi)}fixed64Number(t){let r=vt.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(Wo,4,t)}double(t){return this._push(Jo,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Ns,1,0):this.uint32(r)._push(Bf,r,t)}string(t){let r=ea(t);return r!==0?this.uint32(r)._push(Cs,r,t):this._push(Ns,1,0)}fork(){return this.states=new Ks(this),this.head=this.tail=new we(ks,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(ks,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=vf(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Ns(e,t,r){t[r]=e&255}function Af(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Fs=class extends we{next;constructor(t,r){super(Af,t,r),this.next=void 0}};function an(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 Bf(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(If,t,e),this},lr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Tf,t,e),this});function If(e,t,r){t.set(e,r)}function Tf(e,t,r){e.length<40?Cs(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Z(e),r)}function Ms(){return new lr}function ie(e,t){let r=Ms();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*oe(e,t,r){let n=ur(e);yield*t.stream(n,void 0,"$",r)}var cn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function un(e,t,r,n,s){return{name:e,type:t,encode:r,decode:n,stream:s}}function Us(e){function t(i){if(e[i.toString()]==null)throw new Error("Invalid enum value");return e[i]}let r=function(o,a){let c=t(o);a.int32(c)},n=function(o){let a=o.int32();return t(a)},s=function*(o){let a=o.int32();yield t(a)};return un("enum",cn.VARINT,r,n,s)}function ae(e,t,r){return un("message",cn.LENGTH_DELIMITED,e,t,r)}var xe=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var st;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(st||(st={}));var qs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(qs||(qs={}));(function(e){e.codec=()=>Us(qs)})(st||(st={}));var Nt;(function(e){let t;e.codec=()=>(t==null&&(t=ae((i,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),i.Type!=null&&(o.uint32(8),st.codec().encode(i.Type,o)),i.Data!=null&&(o.uint32(18),o.bytes(i.Data)),a.lengthDelimited!==!1&&o.ldelim()},(i,o,a={})=>{let c={},u=o==null?i.len:i.pos+o;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=st.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,o,a,c={}){let u=o==null?i.len:i.pos+o;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:st.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),t);function r(i){return ie(i,e.codec())}e.encode=r;function n(i,o){return se(i,e.codec(),o)}e.decode=n;function s(i,o){return oe(i,e.codec(),o)}e.stream=s})(Nt||(Nt={}));var Hs;(function(e){let t;e.codec=()=>(t==null&&(t=ae((i,o,a={})=>{a.lengthDelimited!==!1&&o.fork(),i.Type!=null&&(o.uint32(8),st.codec().encode(i.Type,o)),i.Data!=null&&(o.uint32(18),o.bytes(i.Data)),a.lengthDelimited!==!1&&o.ldelim()},(i,o,a={})=>{let c={},u=o==null?i.len:i.pos+o;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{c.Type=st.codec().decode(i);break}case 2:{c.Data=i.bytes();break}default:{i.skipType(f&7);break}}}return c},function*(i,o,a,c={}){let u=o==null?i.len:i.pos+o;for(;i.pos<u;){let f=i.uint32();switch(f>>>3){case 1:{yield{field:`${a}.Type`,value:st.codec().decode(i)};break}case 2:{yield{field:`${a}.Data`,value:i.bytes()};break}default:{i.skipType(f&7);break}}}})),t);function r(i){return ie(i,e.codec())}e.encode=r;function n(i,o){return se(i,e.codec(),o)}e.decode=n;function s(i,o){return oe(i,e.codec(),o)}e.stream=s})(Hs||(Hs={}));var dr={};yt(dr,{MAX_RSA_KEY_SIZE:()=>zs,generateRSAKeyPair:()=>ca,jwkToJWKKeyPair:()=>ua,jwkToPkcs1:()=>Df,jwkToPkix:()=>Ys,jwkToRSAPrivateKey:()=>Xs,pkcs1MessageToJwk:()=>$s,pkcs1MessageToRSAPrivateKey:()=>Zs,pkcs1ToJwk:()=>Rf,pkcs1ToRSAPrivateKey:()=>aa,pkixMessageToJwk:()=>js,pkixMessageToRSAPublicKey:()=>Ws,pkixToJwk:()=>Cf,pkixToRSAPublicKey:()=>Gs});var qe=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 ht.createV1(114,this._multihash)}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}verify(t,r,n){return oa(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:gt(this.raw,t.raw)}sign(t,r){return ia(this.jwk,t,r)}};var zs=8192,Vs=18,Lf=1062,_f=Uint8Array.from([48,13,6,9,42,134,72,134,247,13,1,1,1,5,0]);function Rf(e){let t=Ft(e);return $s(t)}function $s(e){return{n:Y(e[1],"base64url"),e:Y(e[2],"base64url"),d:Y(e[3],"base64url"),p:Y(e[4],"base64url"),q:Y(e[5],"base64url"),dp:Y(e[6],"base64url"),dq:Y(e[7],"base64url"),qi:Y(e[8],"base64url"),kty:"RSA"}}function Df(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 et("JWK was missing components");return Zt([xt(Uint8Array.from([0])),xt(Z(e.n,"base64url")),xt(Z(e.e,"base64url")),xt(Z(e.d,"base64url")),xt(Z(e.p,"base64url")),xt(Z(e.q,"base64url")),xt(Z(e.dp,"base64url")),xt(Z(e.dq,"base64url")),xt(Z(e.qi,"base64url"))]).subarray()}function Cf(e){let t=Ft(e,{offset:0});return js(t)}function js(e){let t=Ft(e[1],{offset:0});return{kty:"RSA",n:Y(t[0],"base64url"),e:Y(t[1],"base64url")}}function Ys(e){if(e.n==null||e.e==null)throw new et("JWK was missing components");return Zt([_f,Cr(Zt([xt(Z(e.n,"base64url")),xt(Z(e.e,"base64url"))]))]).subarray()}function aa(e){let t=Ft(e);return Zs(t)}function Zs(e){let t=$s(e);return Xs(t)}function Gs(e,t){if(e.byteLength>=Lf)throw new Be("Key size is too large");let r=Ft(e,{offset:0});return Ws(r,e,t)}function Ws(e,t,r){let n=js(e);if(r==null){let s=Oe(Nt.encode({Type:st.RSA,Data:t}));r=Pt(Vs,s)}return new qe(n,r)}function Xs(e){if(la(e)>zs)throw new et("Key size is too large");let t=ua(e),r=Oe(Nt.encode({Type:st.RSA,Data:Ys(t.publicKey)})),n=Pt(Vs,r);return new hr(t.privateKey,new qe(t.publicKey,n))}async function ca(e){if(e>zs)throw new et("Key size is too large");let t=await fa(e),r=Oe(Nt.encode({Type:st.RSA,Data:Ys(t.publicKey)})),n=Pt(Vs,r);return new hr(t.privateKey,new qe(t.publicKey,n))}function ua(e){if(e==null)throw new et("Missing key parameter");return{privateKey:e,publicKey:{kty:e.kty,n:e.n,e:e.e}}}async function fa(e,t){let r=await _t.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 ia(e,t,r){let n=await _t.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["sign"]);r?.signal?.throwIfAborted();let s=await _t.get().subtle.sign({name:"RSASSA-PKCS1-v1_5"},n,It(t instanceof Uint8Array?t:t.subarray()));return r?.signal?.throwIfAborted(),new Uint8Array(s,0,s.byteLength)}async function oa(e,t,r,n){let s=await _t.get().subtle.importKey("jwk",e,{name:"RSASSA-PKCS1-v1_5",hash:{name:"SHA-256"}},!1,["verify"]);n?.signal?.throwIfAborted();let i=await _t.get().subtle.verify({name:"RSASSA-PKCS1-v1_5"},s,It(t),It(r instanceof Uint8Array?r:r.subarray()));return n?.signal?.throwIfAborted(),i}async function Pf(e,t){if(e.privateKey==null||e.publicKey==null)throw new et("Private and public key are required");let r=await Promise.all([_t.get().subtle.exportKey("jwk",e.privateKey),_t.get().subtle.exportKey("jwk",e.publicKey)]);return t?.signal?.throwIfAborted(),r}function la(e){if(e.kty!=="RSA")throw new et("invalid key type");if(e.n==null)throw new et("invalid key modulus");return Z(e.n,"base64url").length*8}var fn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(kr(t),Tt(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("expected Hash instance");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,s=new Uint8Array(n);s.set(r.length>n?t.create().update(r).digest():r);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),pe(s)}update(t){return Pe(this),this.iHash.update(t),this}digestInto(t){Pe(this),Nr(t,this),this.finished=!0;let r=t.subarray(0,this.outputLen);this.iHash.digestInto(r),this.oHash.update(r),this.oHash.digestInto(r),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:r,iHash:n,finished:s,destroyed:i,blockLen:o,outputLen:a,canXOF:c}=this;return t=t,t.finished=s,t.destroyed=i,t.blockLen=o,t.outputLen=a,t.canXOF=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()}},ha=(()=>{let e=((t,r,n)=>new fn(t,r).update(n).digest());return e.create=(t,r)=>new fn(t,r),e})();var Of=BigInt(0),Js=class extends Error{constructor(t=""){super(t)}},zt={Err:Js,_tlv:{encode:(e,t)=>{let{Err:r}=zt;if(qt(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(go(t,"data"),t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,s=nr(n);if(s.length/2&128)throw new r("tlv.encode: long form length too big");let i=n>127?nr(s.length/2|128):"";return nr(e)+i+s+t},decode(e,t){let{Err:r}=zt;t=V(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.decode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let s=t[n++],i=!!(s&128),o=0;if(!i)o=s;else{let c=s&127;if(!c)throw new r("tlv.decode(long): indefinite length not supported");if(c>4)throw new r("tlv.decode(long): byte length is too big");let u=t.subarray(n,n+c);if(u.length!==c)throw new r("tlv.decode: length bytes not complete");if(u[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let f of u)o=o<<8|f;if(n+=c,o<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+o);if(a.length!==o)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+o)}}},_int:{encode(e){let{Err:t}=zt;if(Hr(e),e<Of)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}=zt;if(e.length<1)throw new t("invalid signature integer: empty");if(e[0]&128)throw new t("invalid signature integer: negative");if(e.length>1&&e[0]===0&&!(e[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return kt(e)}},toSig(e,t){let{Err:r,_int:n,_tlv:s}=zt;if(t!==void 0&&(qt(t,"maxScalarBytes"),t<1))throw new r("invalid signature: maxScalarBytes must be positive");let i=V(e,void 0,"signature"),{v:o,l:a}=s.decode(48,i);if(a.length)throw new r("invalid signature: left bytes after parsing");let{v:c,l:u}=s.decode(2,o),{v:f,l}=s.decode(2,u);if(l.length)throw new r("invalid signature: left bytes after parsing");if(t!==void 0&&(c.length>t||f.length>t))throw new r("invalid signature: integer too large");return{r:n.decode(c),s:n.decode(f)}},hexFromSig(e){let{_tlv:t,_int:r}=zt;St(e,{r:"bigint",s:"bigint"},{},"sig");let n=t.encode(2,r.encode(e.r)),s=t.encode(2,r.encode(e.s)),i=n+s;return t.encode(48,i)}},ln=(Object.freeze(zt._tlv),Object.freeze(zt._int),Object.freeze(zt));var da=(e,t)=>(e+(e>=0?t:-t)/pa)/t;function kf(e,t,r){Ne("scalar",e,Vt,r);let[[n,s],[i,o]]=t,a=da(o*e,r),c=da(-s*e,r),u=e-a*n-c*i,f=-a*s-c*o,l=u<Vt,h=f<Vt;l&&(u=-u),h&&(f=-f);let d=ir(Math.ceil(Ke(r)/2))+Ee;if(u<Vt||u>=d||f<Vt||f>=d)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:u,k2neg:h,k2:f}}function ei(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Qs(e,t){St(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Et(r.lowS,"lowS"),Et(r.prehash,"prehash"),r.format!==void 0&&ei(r.format),r}var Vt=BigInt(0),Ee=BigInt(1),pa=BigInt(2),ti=BigInt(3),Nf=BigInt(4);function ma(e,t={}){let r=Wr("weierstrass",e,t),n=r.Fp,s=r.Fn,i=r.CURVE,{h:o,n:a}=i;St(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object",randomBytes:"function"});let{endo:c,allowInfinityPoint:u,clearCofactor:f,isTorsionFree:l,fromBytes:h,toBytes:d}=t,y=t.randomBytes===void 0?be:t.randomBytes;if(c&&(!n.is0(i.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let g=c?{beta:c.beta,basises:c.basises.map(E=>[...E])}:void 0,S=ya(n,s);function w(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function B(E,p,m){if(p.is0()){if(!u)throw new Error("bad point: ZERO");return Uint8Array.of(0)}let{x,y:I}=p.toAffine(),L=n.toBytes(x);if(Et(m,"isCompressed"),m){w();let _=!n.isOdd(I);return Lt(ba(_),L)}else return Lt(Uint8Array.of(4),L,n.toBytes(I))}function b(E){V(E,void 0,"Point");let{publicKey:p,publicKeyUncompressed:m}=S,x=E.length,I=E[0],L=E.subarray(1);if(u&&x===1&&I===0)return{x:n.ZERO,y:n.ZERO};if(x===p&&(I===2||I===3)){let _=n.fromBytes(L);if(!n.isValid(_))throw new Error("bad point: is not on curve, wrong x");let P=k(_),N;try{N=n.sqrt(P)}catch(ot){let X=ot instanceof Error?": "+ot.message:"";throw new Error("bad point: is not on curve, sqrt error"+X)}w();let z=n.isOdd(N);return(I&1)===1!==z&&(N=n.neg(N)),{x:_,y:N}}else if(x===m&&I===4){let _=n.BYTES,P=n.fromBytes(L.subarray(0,_)),N=n.fromBytes(L.subarray(_,_*2));if(!R(P,N))throw new Error("bad point: is not on curve");return{x:P,y:N}}else throw new Error(`bad point: got length ${x}, expected compressed=${p} or uncompressed=${m}`)}let v=d===void 0?B:d,A=h===void 0?b:h,O=n.mul(i.b,ti),K=n.is0(i.a)?E=>n.ZERO:E=>n.mul(i.a,E);function k(E){let p=n.sqr(E),m=n.mul(p,E);return n.add(n.add(m,n.mul(E,i.a)),i.b)}function R(E,p){let m=n.sqr(p),x=k(E);return n.eql(m,x)}if(!R(i.Gx,i.Gy))throw new Error("bad curve params: generator point");let C=n.mul(n.pow(i.a,ti),Nf),q=n.mul(n.sqr(i.b),BigInt(27));if(n.is0(n.add(C,q)))throw new Error("bad curve params: a or b");function U(E,p,m=!1){if(!n.isValid(p)||m&&n.is0(p))throw new Error(`bad point coordinate ${E}`);return typeof p=="object"&&p!==null?n.create(p):p}function G(E){if(!(E instanceof D))throw new Error("Weierstrass Point expected")}function T(E){if(!g||!g.basises)throw new Error("no endo");return kf(E,g.basises,s.ORDER)}function F(E,p,m,x){if(!s.isValid(x))throw new RangeError("invalid scalar: out of range");if(g){let{k1neg:I,k1:L,k2neg:_,k2:P}=T(x),N=new D(n.mul(m.X,g.beta),m.Y,m.Z);E.push(I?m.negate():m,_?N.negate():N),p.push(L,P)}else E.push(m),p.push(x)}let M=new WeakSet;class D{static BASE=new D(i.Gx,i.Gy,n.ONE);static ZERO=new D(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=s;X;Y;Z;constructor(p,m,x){this.X=U("x",p),this.Y=U("y",m,!0),this.Z=U("z",x),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){let{x:m,y:x}=p||{};if(!p||!n.isValid(m)||!n.isValid(x))throw new Error("invalid affine point");if(p instanceof D)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(x)?D.ZERO:new D(m,x,n.ONE)}static fromBytes(p){let m=D.fromAffine(A(V(p,void 0,"point")));return m.assertValidity(),m}static fromHex(p){return D.fromBytes(ke(p))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=6,m=!0){return tt.setWindowSize(this,p),m||this.multiply(ti),this}assertValidity(){let p=this;if(p.is0()){if(u&&n.is0(p.X)&&n.eql(p.Y,n.ONE)&&n.is0(p.Z))return;throw new Error("bad point: ZERO")}if(M.has(p))return;let{x:m,y:x}=p.toAffine();if(!n.isValid(m)||!n.isValid(x))throw new Error("bad point: x or y not field elements");if(!R(m,x))throw new Error("bad point: equation left != right");if(!p.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");M.add(p)}hasEvenY(){let{y:p}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(p)}equals(p){G(p);let{X:m,Y:x,Z:I}=this,{X:L,Y:_,Z:P}=p,N=n.eql(n.mul(m,P),n.mul(L,I)),z=n.eql(n.mul(x,P),n.mul(_,I));return N&&z}negate(){return new D(this.X,n.neg(this.Y),this.Z)}double(){let{X:p,Y:m,Z:x}=this,I=n.ZERO,L=n.ZERO,_=n.ZERO,P=n.mul(p,p),N=n.mul(m,m),z=n.mul(x,x),H=n.mul(p,m);return H=n.add(H,H),_=n.mul(p,x),_=n.add(_,_),I=K(_),L=n.mul(O,z),L=n.add(I,L),I=n.sub(N,L),L=n.add(N,L),L=n.mul(I,L),I=n.mul(H,I),_=n.mul(O,_),z=K(z),H=n.sub(P,z),H=K(H),H=n.add(H,_),_=n.add(P,P),P=n.add(_,P),P=n.add(P,z),P=n.mul(P,H),L=n.add(L,P),z=n.mul(m,x),z=n.add(z,z),P=n.mul(z,H),I=n.sub(I,P),_=n.mul(z,N),_=n.add(_,_),_=n.add(_,_),new D(I,L,_)}add(p){G(p);let{X:m,Y:x,Z:I}=this,{X:L,Y:_,Z:P}=p,N=n.ZERO,z=n.ZERO,H=n.ZERO,ot=n.mul(m,L),X=n.mul(x,_),ft=n.mul(I,P),At=n.add(m,x),J=n.add(L,_);At=n.mul(At,J),J=n.add(ot,X),At=n.sub(At,J),J=n.add(m,I);let at=n.add(L,P);return J=n.mul(J,at),at=n.add(ot,ft),J=n.sub(J,at),at=n.add(x,I),N=n.add(_,P),at=n.mul(at,N),N=n.add(X,ft),at=n.sub(at,N),H=K(J),N=n.mul(O,ft),H=n.add(N,H),N=n.sub(X,H),H=n.add(X,H),z=n.mul(N,H),X=n.add(ot,ot),X=n.add(X,ot),ft=K(ft),J=n.mul(O,J),X=n.add(X,ft),ft=n.sub(ot,ft),ft=K(ft),J=n.add(J,ft),ot=n.mul(X,J),z=n.add(z,ot),ot=n.mul(at,J),N=n.mul(At,N),N=n.sub(N,ot),ot=n.mul(At,X),H=n.mul(at,H),H=n.add(H,ot),new D(N,z,H)}subtract(p){return G(p),this.add(p.negate())}is0(){return this.equals(D.ZERO)}multiply(p){if(!s.isValidNot0(p))throw new RangeError("invalid scalar: out of range");let{p:m,f:x}=tt.mulSecret(this,p,o,W);return W([m,x])[0]}multiplyUnsafe(p){let m=this,x=p;if(!s.isValid(x))throw new RangeError("invalid scalar: out of range");if(x===Vt||m.is0())return D.ZERO;if(x===Ee)return m;if(tt.hasWindowSize(this))return tt.mulUnsafe(m,x,W);let I=[],L=[];return F(I,L,m,x),Gr(D,I,L)}mulAddUnsafe(p,m,x){G(m);let I=[],L=[];return F(I,L,this,p),F(I,L,m,x),Gr(D,I,L)}toAffine(p){let m=this,x=p;if(x!=null&&!n.isValid(x))throw new RangeError('"invertedZ" expected valid field element');let{X:I,Y:L,Z:_}=m;if(n.eql(_,n.ONE))return{x:I,y:L};let P=m.is0();x==null&&(x=P?n.ONE:n.inv(_));let N=n.mul(I,x),z=n.mul(L,x),H=n.mul(_,x);if(P)return{x:n.ZERO,y:n.ZERO};if(!n.eql(H,n.ONE))throw new Error("invZ was invalid");return{x:N,y:z}}isTorsionFree(){return o===Ee?!0:l?l(D,this):tt.mulUnsafe(this,a).is0()}clearCofactor(){return o===Ee?this:f?f(D,this):this.multiplyUnsafe(o)}isSmallOrder(){return o===Ee?this.is0():this.clearCofactor().is0()}toBytes(p=!0){return Et(p,"isCompressed"),this.assertValidity(),v(D,this,p)}toHex(p=!0){return rr(this.toBytes(p))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let W=E=>Zr(D,E),tt=new Ue(D,y);return tt.bits>=6&&D.BASE.precompute(6),Object.freeze(D.prototype),Object.freeze(D),D}function ba(e){return Uint8Array.of(e?2:3)}function ya(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Kf(e,t={}){re(e);let{Fn:r}=e,n=t.randomBytes===void 0?be:t.randomBytes,s=Object.assign(ya(e.Fp,r),{seed:Math.max(jr(r.ORDER),16)});function i(d){try{let y=r.fromBytes(d);return r.isValidNot0(y)}catch{return!1}}function o(d,y){let{publicKey:g,publicKeyUncompressed:S}=s;try{let w=d.length;return y===!0&&w!==g||y===!1&&w!==S?!1:!e.fromBytes(d).is0()}catch{return!1}}function a(d){return d=d===void 0?n(s.seed):d,Yr(V(d,s.seed,"seed"),r.ORDER)}function c(d,y=!0){return e.BASE.multiply(r.fromBytes(d)).toBytes(y)}function u(d){let{secretKey:y,publicKey:g,publicKeyUncompressed:S}=s,w=r._lengths;if(!te(d))return;let B=V(d,void 0,"key").length,b=B===g||B===S,v=B===y||!!w?.includes(B);if(!(b&&v))return b}function f(d,y,g=!0){if(u(d)===!0)throw new Error("first arg must be private key");if(u(y)===!1)throw new Error("second arg must be public key");let S=r.fromBytes(d),w=e.fromBytes(y);if(w.is0())throw new Error("invalid public key: point at infinity");return w.multiply(S).toBytes(g)}let l={isValidSecretKey:i,isValidPublicKey:o,randomSecretKey:a},h=Xr(a,c);return Object.freeze(l),Object.freeze(s),Object.freeze({getPublicKey:c,getSharedSecret:f,keygen:h,Point:e,utils:l,lengths:s})}function ga(e,t,r={}){re(e);let n=t;kr(n),St(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"});let s=Object.assign({},r),i=s.randomBytes===void 0?be:s.randomBytes,o=s.hmac===void 0?(E,p)=>ha(n,E,p):s.hmac,{Fp:a,Fn:c}=e,{ORDER:u,BITS:f}=c,l=jr(u),h=ys(i,l),{keygen:d,getPublicKey:y,getSharedSecret:g,utils:S,lengths:w}=Kf(e,s),B={prehash:!0,lowS:typeof s.lowS=="boolean"?s.lowS:!0,format:"compact",extraEntropy:!1},b=u*pa+Ee<a.ORDER;function v(E){let p=u>>Ee;return E>p}function A(E,p){if(!c.isValidNot0(p))throw new Error(`invalid signature ${E}: out of range 1..Point.Fn.ORDER`);return p}function O(){if(!a.isOdd)throw new Error("Field doesn't support isOdd")}function K(E,p,m){return O(),(E===m?0:2)|Number(a.isOdd(p))}function k(){if(b)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function R(E,p){ei(p);let m=w.signature,x=p==="compact"?m:p==="recovered"?m+1:void 0;return V(E,x)}class C{r;s;recovery;constructor(p,m,x){if(this.r=A("r",p),this.s=A("s",m),x!=null){if(k(),![0,1,2,3].includes(x))throw new Error("invalid recovery id");this.recovery=x}Object.freeze(this)}static fromBytes(p,m=B.format){R(p,m);let x;if(m==="der"){if(p.length>2*c.BYTES+16)throw new ln.Err("invalid signature: DER signature too long");let{r:P,s:N}=ln.toSig(V(p),c.BYTES+1);return new C(P,N)}m==="recovered"&&(x=p[0],m="compact",p=p.subarray(1));let I=w.signature/2,L=p.subarray(0,I),_=p.subarray(I,I*2);return new C(c.fromBytes(L),c.fromBytes(_),x)}static fromHex(p,m){return this.fromBytes(ke(p),m)}assertRecovery(){let{recovery:p}=this;if(p==null)throw new Error("invalid recovery id: must be present");return p}addRecoveryBit(p){return new C(this.r,this.s,p)}recoverPublicKey(p){let{r:m,s:x}=this,I=this.assertRecovery(),L=I===2||I===3?m+u:m;if(!a.isValid(L))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let _=a.toBytes(L),P=e.fromBytes(Lt(ba((I&1)===0),_)),N=c.inv(L),z=U(V(p,void 0,"msgHash")),H=c.create(-z*N),ot=c.create(x*N),X=e.BASE.mulAddUnsafe(H,P,ot);if(X.is0())throw new Error("invalid recovery: point at infinify");return X.assertValidity(),X}hasHighS(){return v(this.s)}toBytes(p=B.format){if(ei(p),p==="der")return ke(ln.hexFromSig(this));let{r:m,s:x}=this,I=c.toBytes(m),L=c.toBytes(x);return p==="recovered"?(k(),Lt(Uint8Array.of(this.assertRecovery()),I,L)):Lt(I,L)}toHex(p){return rr(this.toBytes(p))}}Object.freeze(C.prototype),Object.freeze(C);let q=s.bits2int===void 0?function(p){if(p.length>8192)throw new Error("input is too large");let m=kt(p),x=p.length*8-f;return x>0?m>>BigInt(x):m}:s.bits2int,U=s.bits2int_modN===void 0?function(p){return c.create(q(p))}:s.bits2int_modN,G=ir(f);function T(E){return Ne("num < 2^"+f,E,Vt,G),c.toBytes(E)}function F(E,p){return V(E,void 0,"message"),p?V(n(E),void 0,"prehashed message"):E}function M(E,p,m){let{lowS:x,prehash:I,extraEntropy:L}=Qs(m,B);E=F(E,I);let _=U(E),P=c.fromBytes(p);if(!c.isValidNot0(P))throw new Error("invalid private key");let N=[T(P),T(_)];if(L!=null&&L!==!1){let X=L===!0?i(w.secretKey):L;N.push(V(X,void 0,"extraEntropy"))}let z=Lt(...N),H=_;function ot(X){let ft=q(X);if(!c.isValidNot0(ft))return;let At=e.BASE.multiply(ft).toAffine(),J=c.create(At.x);if(J===Vt)return;let at;if(h!==void 0){let $e=kt(Yr(h(l),u)),Ma=c.inv(c.mul($e,ft)),Ua=c.mul($e,H),qa=c.mul($e,P);at=c.create(Ma*c.create(Ua+qa*J))}else{let $e=Lo(ft,u);at=c.create($e*c.create(H+J*P))}if(at===Vt)return;let xn=K(At.x,At.y,J),gi=at;return x&&v(at)&&(gi=c.neg(at),xn^=1),new C(J,gi,b?void 0:xn)}return{seed:z,k2sig:ot}}function D(E,p,m={}){let{seed:x,k2sig:I}=M(E,p,m);return xo(n.outputLen,c.BYTES,o)(x,I).toBytes(m.format)}function W(E,p,m,x={}){let{lowS:I,prehash:L,format:_}=Qs(x,B);if(m=V(m,void 0,"publicKey"),p=F(p,L),!te(E)){let P=E instanceof C?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+P)}R(E,_);try{let P=C.fromBytes(E,_),N=e.fromBytes(m);if(N.is0()||I&&P.hasHighS())return!1;let{r:z,s:H}=P,ot=U(p),X=c.inv(H),ft=c.create(ot*X),At=c.create(z*X),J=e.BASE.mulAddUnsafe(ft,N,At);if(J.is0())return!1;let at=J.toAffine();return!(c.create(at.x)!==z||_==="recovered"&&P.recovery!==K(at.x,at.y,z))}catch{return!1}}function tt(E,p,m={}){let{prehash:x}=Qs(m,B);return p=F(p,x),C.fromBytes(E,"recovered").recoverPublicKey(p).toBytes()}return Object.freeze({keygen:d,getPublicKey:y,getSharedSecret:g,utils:S,lengths:w,Point:e,sign:D,verify:W,recoverPublicKey:tt,Signature:C,hash:n})}var ni={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ff={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var wa=BigInt(2);function Mf(e){let t=ni.p,r=BigInt(3),n=BigInt(6),s=BigInt(11),i=BigInt(22),o=BigInt(23),a=BigInt(44),c=BigInt(88),u=e*e*e%t,f=u*u*e%t,l=Q(f,r,t)*f%t,h=Q(l,r,t)*f%t,d=Q(h,wa,t)*u%t,y=Q(d,s,t)*d%t,g=Q(y,i,t)*y%t,S=Q(g,a,t)*g%t,w=Q(S,c,t)*S%t,B=Q(w,a,t)*g%t,b=Q(B,r,t)*f%t,v=Q(b,o,t)*y%t,A=Q(v,n,t)*u%t,O=Q(A,wa,t);if(!ri.eql(ri.sqr(O),e))throw new Error("Cannot find square root");return O}var ri=Me(ni.p,{sqrt:Mf}),Uf=ma(ni,{Fp:ri,endo:Ff}),He=ga(Uf,Oe);function xa(e,t,r,n){let s=le.digest(r instanceof Uint8Array?r:r.subarray());if(nn(s))return s.then(({digest:i})=>(n?.signal?.throwIfAborted(),He.verify(t,i,e,{prehash:!1,format:"der"}))).catch(i=>{throw i.name==="AbortError"?i:new cr(String(i))});try{return n?.signal?.throwIfAborted(),He.verify(t,s.digest,e,{prehash:!1,format:"der"})}catch(i){throw new cr(String(i))}}var hn=class{type="secp256k1";raw;_key;constructor(t){this._key=Sa(t),this.raw=Ea(this._key)}toMultihash(){return Rt.digest(Mt(this))}toCID(){return ht.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}verify(t,r,n){return xa(this._key,r,t,n)}};function si(e){return new hn(e)}function Ea(e){return He.Point.fromBytes(e).toBytes()}function Sa(e){try{return He.Point.fromBytes(e),e}catch(t){throw new Be(String(t))}}function ii(e,t){let{Type:r,Data:n}=Nt.decode(e),s=n??new Uint8Array;switch(r){case st.RSA:return Gs(s,t);case st.Ed25519:return vs(s);case st.secp256k1:return si(s);case st.ECDSA:return Wn(s);default:throw new ce}}function va(e){let{Type:t,Data:r}=Nt.decode(e.digest),n=r??new Uint8Array;switch(t){case st.Ed25519:return vs(n);case st.secp256k1:return si(n);case st.ECDSA:return Wn(n);default:throw new ce}}function Mt(e){return Nt.encode({Type:st[e.type],Data:e.raw})}var Aa=Symbol.for("nodejs.util.inspect.custom"),qf=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()})`}[En]=!0;toString(){return this.string==null&&(this.string=rt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ht.createV1(qf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return gt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return gt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Aa](){return`PeerId(${this.toString()})`}},mr=class extends pr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},br=class extends pr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},yr=class extends pr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Hf=2336,dn=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Rt.digest(Z(this.url))}[Aa](){return`PeerId(${this.url})`}[En]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ht.createV1(Hf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=Y(t)),t.toString()===this.toString())}};function oi(e){if(e.type==="Ed25519")return new br({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 mr({multihash:e.toCID().multihash,publicKey:e});throw new ce}function Ba(e){return oi(e.publicKey)}function gr(e){if(Vf(e))return new mr({multihash:e});if(zf(e))try{let t=va(e);if(t.type==="Ed25519")return new br({multihash:e,publicKey:t});if(t.type==="secp256k1")return new yr({multihash:e,publicKey:t})}catch{let r=Y(e.digest);return new dn(new URL(r))}throw new Tr("Supplied PeerID Multihash is invalid")}function zf(e){return e.code===Rt.code}function Vf(e){return e.code===le.code}function Se(e,t){let r={[Symbol.iterator]:()=>r,next:()=>{let n=e.next(),s=n.value;return n.done===!0||s==null?{done:!0,value:void 0}:{done:!1,value:t(s)}}};return r}function pn(e){let t=jt(rt.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 Se(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 Se(this.map.values(),t=>t.key)}values(){return Se(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 Se(this.set.entries(),t=>{let r=pn(t[0]);return[r,r]})}forEach(t){this.set.forEach(r=>{let n=pn(r);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Se(this.set.values(),t=>pn(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}};var ai=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},Ia=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function Er(e,t){let{milliseconds:r,fallback:n,message:s,customTimers:i={setTimeout,clearTimeout},signal:o}=t,a,c,f=new Promise((l,h)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(o?.aborted){h(Ia(o));return}if(o&&(c=()=>{h(Ia(o))},o.addEventListener("abort",c,{once:!0})),e.then(l,h),r===Number.POSITIVE_INFINITY)return;let d=new ai;a=i.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(y){h(y)}return}typeof e.cancel=="function"&&e.cancel(),s===!1?l():s instanceof Error?h(s):(d.message=s??`Promise timed out after ${r} milliseconds`,h(d))},r)}).finally(()=>{f.clear(),c&&o&&o.removeEventListener("abort",c)});return f.clear=()=>{i.clearTimeout.call(void 0,a),a=void 0},f}var $f=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 jf(e,t,r){let n,s=new Promise((i,o)=>{if(r={rejectionEvents:["error"],multiArgs:!1,rejectionMultiArgs:!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 a=[t].flat(),c=[],{addListener:u,removeListener:f}=$f(e),l=async(...d)=>{let y=r.multiArgs?d:d[0];if(r.filter)try{if(!await r.filter(y))return}catch(g){n(),o(g);return}c.push(y),r.count===c.length&&(n(),i(c))},h=(...d)=>{n(),o(r.rejectionMultiArgs?d:d[0])};n=()=>{for(let d of a)f(d,l);for(let d of r.rejectionEvents)a.includes(d)||f(d,h)};for(let d of a)u(d,l);for(let d of r.rejectionEvents)a.includes(d)||u(d,h);r.signal&&r.signal.addEventListener("abort",()=>{h(r.signal.reason)},{once:!0}),r.resolveImmediately&&i(c)});if(s.cancel=n,typeof r.timeout=="number"){let i=Er(s,{milliseconds:r.timeout});return i.cancel=()=>{n(),i.clear()},i}return s}function Ta(e,t,r){typeof r=="function"&&(r={filter:r}),r={...r,count:1,resolveImmediately:!1};let n=jf(e,t,r),s=n.then(i=>i[0]);return s.cancel=n.cancel,s}var ve=class extends Error{static name="UnexpectedEOFError";name="UnexpectedEOFError"};function Yf(e){return e.reason}function ci(e,t,r){if(t==null||e==null)return e;let n=r?.translateError??Yf;if(t.aborted)return e.catch(()=>{}),Promise.reject(n(t));let s;return Promise.race([e,new Promise((i,o)=>{s=()=>{o(n(t))},t.addEventListener("abort",s)})]).finally(()=>{s!=null&&t.removeEventListener("abort",s)})}var Gf=4194304,mn=class extends Error{static name="UnwrappedError";name="UnwrappedError"},fi=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MSG_LENGTH"},li=class extends Error{name="InvalidDataLengthError";code="ERR_MSG_DATA_TOO_LONG"},hi=class extends Error{name="InvalidDataLengthLengthError";code="ERR_MSG_LENGTH_TOO_LONG"};function Wf(e){return typeof e?.closeRead=="function"}function Xf(e){return typeof e?.close=="function"}function ui(e){return Wf(e)?e.remoteWriteStatus!=="writable"&&e.readBufferLength===0:Xf(e)?e.status!=="open":!1}function Jf(e){return e?.addEventListener!=null&&e?.removeEventListener!=null&&e?.send!=null&&e?.push!=null&&e?.log!=null}function Qf(e,t){let r=t?.maxBufferSize??Gf,n=new lt,s,i=!1,o;if(!Jf(e))throw new et("Argument should be a Stream or a Multiaddr");let a=l=>{if(o==null){if(n.append(l.data),n.byteLength>r){let h=n.byteLength;n.consume(h);let d=new Ir(`Read buffer overflow - ${h} > ${r}`);o=d,s?.reject(d),queueMicrotask(()=>{e.abort(d)});return}s?.resolve()}};e.addEventListener("message",a);let c=l=>{l.error!=null?s?.reject(l.error):s?.resolve()};e.addEventListener("close",c);let u=()=>{s?.resolve()};e.addEventListener("remoteCloseWrite",u);let f={readBuffer:n,async read(l){if(i===!0)throw new mn("Stream was unwrapped");if(o!=null)throw o;if(ui(e)){if(n.byteLength===0&&l?.bytes==null)return null;if(l?.bytes!=null&&n.byteLength<l.bytes)throw e.log.error("closed after reading %d/%d bytes",n.byteLength,l.bytes),new ve(`Unexpected EOF - stream closed after reading ${n.byteLength}/${l.bytes} bytes`)}let h=l?.bytes??1;for(s=Promise.withResolvers();;){if(n.byteLength>=h){s.resolve();break}if(await ci(s.promise,l?.signal),ui(e)){if(n.byteLength===0&&l?.bytes==null)return null;break}s=Promise.withResolvers()}let d=l?.bytes??n.byteLength;if(n.byteLength<d){if(ui(e))throw e.log.error("closed while reading %d/%d bytes",n.byteLength,d),new ve(`Unexpected EOF - stream closed while reading ${n.byteLength}/${d} bytes`);return f.read(l)}let y=n.sublist(0,d);return n.consume(d),y},async write(l,h){if(i===!0)throw new mn("Stream was unwrapped");e.send(l)||await Ta(e,"drain",{signal:h?.signal,rejectionEvents:["close"]})},unwrap(){return i||(i=!0,e.removeEventListener("message",a),e.removeEventListener("close",c),e.removeEventListener("remoteCloseWrite",u),n.byteLength>0&&(e.log("stream unwrapped with %d unread bytes",n.byteLength),e.unshift(n))),e}};return f}function tl(e,t={}){let r=Qf(e,t);t.maxDataLength!=null&&t.maxLengthLength==null&&(t.maxLengthLength=Ht(t.maxDataLength));let n=t?.lengthDecoder??Go,s=t?.lengthEncoder??Zo;return{async read(o){let a=-1,c=new lt;for(;;){let f=await r.read({...o,bytes:1});if(f==null)break;c.append(f);try{a=n(c)}catch(l){if(l instanceof RangeError)continue;throw l}if(a<0)throw new fi("Invalid message length");if(t?.maxLengthLength!=null&&c.byteLength>t.maxLengthLength)throw new hi(`Message length length too long - ${c.byteLength} > ${t.maxLengthLength}`);if(a>-1)break}if(t?.maxDataLength!=null&&a>t.maxDataLength)throw new li(`Message length too long - ${a} > ${t.maxDataLength}`);let u=await r.read({...o,bytes:a});if(u==null)throw e.log.error("tried to read %d bytes but the stream closed",a),new ve(`Unexpected EOF - tried to read ${a} bytes but the stream closed`);if(u.byteLength!==a)throw e.log.error("read %d/%d bytes before the stream closed",u.byteLength,a),new ve(`Unexpected EOF - read ${u.byteLength}/${a} bytes before the stream closed`);return u},async write(o,a){await r.write(new lt(s(o.byteLength),o),a)},async writeV(o,a){let c=new lt(...o.flatMap(u=>[s(u.byteLength),u]));await r.write(c,a)},unwrap(){return r.unwrap()}}}function di(e,t){let r=tl(e,t),n={read:async(s,i)=>{let o=await r.read(i);return s.decode(o,i)},write:async(s,i,o)=>{await r.write(i.encode(s),o)},writeV:async(s,i,o)=>{await r.writeV(s.map(a=>i.encode(a)),o)},pb:s=>({read:async i=>n.read(s,i),write:async(i,o)=>n.write(i,s,o),writeV:async(i,o)=>n.writeV(i,s,o),unwrap:()=>n}),unwrap:()=>r.unwrap()};return n}var mi=Za(_a(),1);function bi(e,t,r){let n=0,s=e.length;for(;s>0;){let i=Math.trunc(s/2),o=n+i;r(e[o],t)<=0?(n=++o,s-=i+1):s=i}return n}var nl=100,ze=class{#t=[];#e=0;enqueue(t,r){let{priority:n=0,id:s}=r??{},{size:i}=this,o={priority:n,id:s,run:t};if(i===0){this.#t.length=0,this.#e=0,this.#t.push(o);return}if(this.#t.at(-1).priority>=n){this.#t.push(o);return}this.#i();let a=bi(this.#t,o,(c,u)=>u.priority-c.priority);this.#t.splice(a,0,o)}setPriority(t,r){let n=this.#t.findIndex((i,o)=>o>=this.#e&&i.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[s]=this.#t.splice(n,1);this.enqueue(s.run,{priority:r,id:t})}remove(t){let r=this.#t.findIndex((n,s)=>s<this.#e?!1:typeof t=="string"?n.id===t:n.run===t);r!==-1&&this.#t.splice(r,1)}dequeue(){if(this.#e===this.#t.length)return;let t=this.#t[this.#e];return this.#e++,this.#e===this.#t.length?(this.#t.length=0,this.#e=0):this.#e>nl&&this.#e>this.#t.length/2&&this.#i(),t?.run}filter(t){let r=[];for(let n=this.#e;n<this.#t.length;n++){let s=this.#t[n];s.priority===t.priority&&r.push(s.run)}return r}get size(){return this.#t.length-this.#e}#i(){this.#e!==0&&(this.#t.splice(0,this.#e),this.#e=0)}};var vr=class extends mi.default{#t;#e;#i=0;#d;#m=!1;#w=!1;#u;#x=0;#c;#f;#a;#o=[];#s=0;#r;#I;#n=0;#b;#l;#C=1n;#y=new Map;#E=new Set;timeout;constructor(t){if(super(),t={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:ze,strict:!1,...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})`);if(t.strict&&t.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(t.strict&&t.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#t=t.carryoverIntervalCount??t.carryoverConcurrencyCount??!1,this.#e=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#d=t.intervalCap,this.#u=t.interval,this.#a=t.strict,this.#r=new t.queueClass,this.#I=t.queueClass,this.concurrency=t.concurrency,t.timeout!==void 0&&!(Number.isFinite(t.timeout)&&t.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${t.timeout}\` (${typeof t.timeout})`);this.timeout=t.timeout,this.#l=t.autoStart===!1,this.#U()}#S(t){for(;this.#s<this.#o.length;){let n=this.#o[this.#s];if(n!==void 0&&t-n>=this.#u)this.#s++;else break}(this.#s>100&&this.#s>this.#o.length/2||this.#s===this.#o.length)&&(this.#o=this.#o.slice(this.#s),this.#s=0)}#P(t){this.#a?this.#o.push(t):this.#i++}#O(){this.#a?this.#o.length>this.#s&&this.#o.pop():this.#i>0&&this.#i--}#v(){return this.#o.length-this.#s}get#k(){return this.#e?!0:this.#a?this.#v()<this.#d:this.#i<this.#d}get#N(){return this.#n<this.#b}#K(){this.#n--,this.#n===0&&this.emit("pendingZero"),this.#g(),this.emit("next")}#F(){this.#f=void 0,this.#R(),this.#_()}#M(t){if(this.#a){if(this.#S(t),this.#v()>=this.#d){let n=this.#o[this.#s],s=this.#u-(t-n);return this.#T(s),!0}return!1}if(this.#c===void 0){let r=this.#x-t;if(r<0)this.#i=this.#t?this.#n:0;else return this.#T(r),!0}return!1}#T(t){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#F()},t))}#A(){this.#c&&(clearInterval(this.#c),this.#c=void 0)}#L(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#g(){if(this.#r.size===0){if(this.#A(),this.emit("empty"),this.#n===0){if(this.#L(),this.#a&&this.#s>0){let r=Date.now();this.#S(r)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let r=Date.now(),n=!this.#M(r);if(this.#k&&this.#N){let s=this.#r.dequeue();this.#e||(this.#P(r),this.#p()),n&&this.#_(),this.emit("active"),s(),t=!0}}return t}#_(){this.#e||this.#c!==void 0||this.#a||(this.#c=setInterval(()=>{this.#R()},this.#u),this.#x=Date.now()+this.#u)}#R(){this.#a||(this.#c!==void 0&&(this.#i===0&&this.#n===0?this.#A():this.#x=Date.now()+this.#u),this.#i=this.#t?this.#n:0),this.#B(),this.#p()}#B(){for(;this.#g(););}get concurrency(){return this.#b}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.#b=t,this.#B()}setPriority(t,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#r.setPriority(t,r)}async add(t,r={}){if(r={timeout:this.timeout,...r,id:r.id??(this.#C++).toString()},r.timeout!==void 0&&!(Number.isFinite(r.timeout)&&r.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${r.timeout}\` (${typeof r.timeout})`);return new Promise((n,s)=>{let i=Symbol(`task-${r.id}`),o=()=>{},a=async()=>{o(),this.#n++,this.#y.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let u;try{try{r.signal?.throwIfAborted()}catch(h){throw this.#q(),this.#y.delete(i),h}let f=t({signal:r.signal});if(r.timeout!==void 0&&(f=Er(Promise.resolve(f),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#n} running, ${this.#r.size} waiting)`})),r.signal){let{signal:h}=r;f=Promise.race([f,new Promise((d,y)=>{u=()=>{y(h.reason)},h.addEventListener("abort",u,{once:!0})})])}let l=await f;n(l),this.emit("completed",l)}catch(f){s(f),this.emit("error",f)}finally{u&&r.signal?.removeEventListener("abort",u),this.#y.delete(i),queueMicrotask(()=>{this.#K()})}};this.#r.enqueue(a,r);let c=()=>{if(this.#r instanceof ze){this.#r.remove(a);return}this.#r.remove?.(r.id)};if(r.signal){let{signal:u}=r,f=()=>{o(),c(),s(u.reason),this.#g(),this.emit("next")};if(o=()=>{u.removeEventListener("abort",f),this.#E.delete(o)},u.aborted){f();return}u.addEventListener("abort",f,{once:!0}),this.#E.add(o)}this.emit("add"),this.#g()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#B(),this):this}pause(){this.#l=!0}clear(){for(let t of this.#E)t();this.#r=new this.#I,this.#A(),this.#D(),this.emit("empty"),this.#n===0&&(this.#L(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#r.size!==0&&await this.#h("empty")}async onSizeLessThan(t){this.#r.size<t||await this.#h(["next","active"],()=>this.#r.size<t)}async onIdle(){this.#n===0&&this.#r.size===0||await this.#h("idle")}async onPendingZero(){this.#n!==0&&await this.#h("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#h("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#h("rateLimitCleared")}onError(){return new Promise((t,r)=>{let n=s=>{this.off("error",n),r(s)};this.on("error",n)})}async#h(t,r){let n=Array.isArray(t)?t:[t];return new Promise(s=>{let i=()=>{if(!(r&&!r())){for(let o of n)this.off(o,i);s()}};for(let o of n)this.on(o,i)})}get size(){return this.#r.size}sizeBy(t){return this.#r.filter(t).length}get pending(){return this.#n}get isPaused(){return this.#l}#U(){this.#e||(this.on("add",()=>{this.#r.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#e||this.#w||(this.#w=!0,queueMicrotask(()=>{this.#w=!1,this.#D()}))}#q(){this.#e||(this.#O(),this.#p())}#D(){let t=this.#m;if(this.#e||this.#r.size===0){t&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let s=Date.now();this.#S(s),r=this.#v()}else r=this.#i;let n=r>=this.#d;n!==t&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#n===this.#b&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#y.values()].map(t=>({...t,timeoutRemaining:t.timeout?Math.max(0,t.startTime+t.timeout-Date.now()):void 0}))}};var yn=class{entries;validityMs;lastPruneTime=0;constructor(t){this.entries=new Map,this.validityMs=t.validityMs}put(t,r){this.entries.set(t,{value:r,validUntilMs:Date.now()+this.validityMs}),this.prune()}prune(){let t=Date.now();if(!(t-this.lastPruneTime<200)){this.lastPruneTime=t;for(let[r,n]of this.entries.entries())if(n.validUntilMs<t)this.entries.delete(r);else break}}has(t){return this.entries.has(t)}get(t){let r=this.entries.get(t);return r!=null&&r.validUntilMs>=Date.now()?r.value:void 0}clear(){this.entries=new Map,this.lastPruneTime=0}};var Ra={maxSubscriptions:5e3,maxMessages:5e3};function Da(e){return{subscriptions:e.maxSubscriptions,messages:e.maxMessages}}var Ae;(function(e){let t;(function(a){let c;a.codec=()=>(c==null&&(c=ae((h,d,y={})=>{y.lengthDelimited!==!1&&d.fork(),h.subscribe!=null&&(d.uint32(8),d.bool(h.subscribe)),h.topic!=null&&(d.uint32(18),d.string(h.topic)),y.lengthDelimited!==!1&&d.ldelim()},(h,d,y={})=>{let g={},S=d==null?h.len:h.pos+d;for(;h.pos<S;){let w=h.uint32();switch(w>>>3){case 1:{g.subscribe=h.bool();break}case 2:{g.topic=h.string();break}default:{h.skipType(w&7);break}}}return g},function*(h,d,y,g={}){let S=d==null?h.len:h.pos+d;for(;h.pos<S;){let w=h.uint32();switch(w>>>3){case 1:{yield{field:`${y}.subscribe`,value:h.bool()};break}case 2:{yield{field:`${y}.topic`,value:h.string()};break}default:{h.skipType(w&7);break}}}})),c);function u(h){return ie(h,a.codec())}a.encode=u;function f(h,d){return se(h,a.codec(),d)}a.decode=f;function l(h,d){return oe(h,a.codec(),d)}a.stream=l})(t=e.SubOpts||(e.SubOpts={}));let r;(function(a){let c;a.codec=()=>(c==null&&(c=ae((h,d,y={})=>{y.lengthDelimited!==!1&&d.fork(),h.from!=null&&(d.uint32(10),d.bytes(h.from)),h.data!=null&&(d.uint32(18),d.bytes(h.data)),h.sequenceNumber!=null&&(d.uint32(26),d.bytes(h.sequenceNumber)),h.topic!=null&&(d.uint32(34),d.string(h.topic)),h.signature!=null&&(d.uint32(42),d.bytes(h.signature)),h.key!=null&&(d.uint32(50),d.bytes(h.key)),y.lengthDelimited!==!1&&d.ldelim()},(h,d,y={})=>{let g={},S=d==null?h.len:h.pos+d;for(;h.pos<S;){let w=h.uint32();switch(w>>>3){case 1:{g.from=h.bytes();break}case 2:{g.data=h.bytes();break}case 3:{g.sequenceNumber=h.bytes();break}case 4:{g.topic=h.string();break}case 5:{g.signature=h.bytes();break}case 6:{g.key=h.bytes();break}default:{h.skipType(w&7);break}}}return g},function*(h,d,y,g={}){let S=d==null?h.len:h.pos+d;for(;h.pos<S;){let w=h.uint32();switch(w>>>3){case 1:{yield{field:`${y}.from`,value:h.bytes()};break}case 2:{yield{field:`${y}.data`,value:h.bytes()};break}case 3:{yield{field:`${y}.sequenceNumber`,value:h.bytes()};break}case 4:{yield{field:`${y}.topic`,value:h.string()};break}case 5:{yield{field:`${y}.signature`,value:h.bytes()};break}case 6:{yield{field:`${y}.key`,value:h.bytes()};break}default:{h.skipType(w&7);break}}}})),c);function u(h){return ie(h,a.codec())}a.encode=u;function f(h,d){return se(h,a.codec(),d)}a.decode=f;function l(h,d){return oe(h,a.codec(),d)}a.stream=l})(r=e.Message||(e.Message={}));let n;e.codec=()=>(n==null&&(n=ae((a,c,u={})=>{if(u.lengthDelimited!==!1&&c.fork(),a.subscriptions!=null&&a.subscriptions.length>0)for(let f of a.subscriptions)c.uint32(10),e.SubOpts.codec().encode(f,c);if(a.messages!=null&&a.messages.length>0)for(let f of a.messages)c.uint32(18),e.Message.codec().encode(f,c);u.lengthDelimited!==!1&&c.ldelim()},(a,c,u={})=>{let f={subscriptions:[],messages:[]},l=c==null?a.len:a.pos+c;for(;a.pos<l;){let h=a.uint32();switch(h>>>3){case 1:{if(u.limits?.subscriptions!=null&&f.subscriptions.length===u.limits.subscriptions)throw new xe('Decode error - repeated field "subscriptions" had too many elements');f.subscriptions.push(e.SubOpts.codec().decode(a,a.uint32(),{limits:u.limits?.subscriptions$}));break}case 2:{if(u.limits?.messages!=null&&f.messages.length===u.limits.messages)throw new xe('Decode error - repeated field "messages" had too many elements');f.messages.push(e.Message.codec().decode(a,a.uint32(),{limits:u.limits?.messages$}));break}default:{a.skipType(h&7);break}}}return f},function*(a,c,u,f={}){let l={subscriptions:0,messages:0},h=c==null?a.len:a.pos+c;for(;a.pos<h;){let d=a.uint32();switch(d>>>3){case 1:{if(f.limits?.subscriptions!=null&&l.subscriptions===f.limits.subscriptions)throw new xe('Streaming decode error - repeated field "subscriptions" had too many elements');for(let y of e.SubOpts.codec().stream(a,a.uint32(),`${u}.subscriptions[]`,{limits:f.limits?.subscriptions$}))yield{...y,index:l.subscriptions};l.subscriptions++;break}case 2:{if(f.limits?.messages!=null&&l.messages===f.limits.messages)throw new xe('Streaming decode error - repeated field "messages" had too many elements');for(let y of e.Message.codec().stream(a,a.uint32(),`${u}.messages[]`,{limits:f.limits?.messages$}))yield{...y,index:l.messages};l.messages++;break}default:{a.skipType(d&7);break}}}})),n);function s(a){return ie(a,e.codec())}e.encode=s;function i(a,c){return se(a,e.codec(),c)}e.decode=i;function o(a,c){return oe(a,e.codec(),c)}e.stream=o})(Ae||(Ae={}));var gn=class extends Ie{peerId;shutDownController;inboundPb;outboundPb;constructor(t){super(),this.peerId=t,this.shutDownController=new AbortController}attachInboundStream(t,r,n){this.inboundPb=di(t,r).pb(Ae),Promise.resolve().then(async()=>{for(;;){if(this.inboundPb==null)return;let s=await this.inboundPb.read({signal:this.shutDownController.signal,limits:n});this.safeDispatchEvent("message",{detail:s})}}).catch(s=>{this.inboundPb?.unwrap().unwrap().abort(s),this.close()})}attachOutboundStream(t,r){this.outboundPb=di(t,r).pb(Ae)}write(t){this.outboundPb!=null&&this.outboundPb.write(t,{signal:this.shutDownController.signal}).catch(r=>{this.outboundPb?.unwrap().unwrap().abort(r)})}close(){this.shutDownController.abort(),Promise.all([this.inboundPb?.unwrap().unwrap().close().catch(t=>{this.inboundPb?.unwrap().unwrap().abort(t)}),this.outboundPb?.unwrap().unwrap().close().catch(t=>{this.inboundPb?.unwrap().unwrap().abort(t)})]).finally(()=>{this.safeDispatchEvent("close")})}};function Ca(){return BigInt(`0x${Y(crypto.getRandomValues(new Uint8Array(8)),"base16")}`)}var Pa=(e,t)=>{let r=Z(t.toString(16).padStart(16,"0"),"base16"),n=Mt(e),s=new Uint8Array(n.byteLength+r.length);return s.set(n,0),s.set(r,n.byteLength),s},Oa=e=>le.encode(e);var sl=async e=>{if(e.sequenceNumber==null||e.from==null||e.signature==null)return!1;let t=gr(jt(e.from));if(t.publicKey!=null)return!0;if(e.key!=null){let r=e.key;return oi(ii(r)).equals(t)}return!1},ka=async e=>{if(e.from==null)throw new ct("RPC message was missing from");if(!await sl(e))return{type:"unsigned",topic:e.topic??"",data:e.data??new Uint8Array(0)};let t=gr(jt(e.from)),r=e.key??t.publicKey;if(r==null)throw new ct("RPC message was missing public key");return{type:"signed",from:t,topic:e.topic??"",sequenceNumber:ol(e.sequenceNumber??new Uint8Array(0)),data:e.data??new Uint8Array(0),signature:e.signature??new Uint8Array(0),key:r instanceof Uint8Array?ii(r):r}},Ar=e=>e.type==="signed"?{from:e.from.toMultihash().bytes,data:e.data,sequenceNumber:il(e.sequenceNumber),topic:e.topic,signature:e.signature,key:e.key?Mt(e.key):void 0}:{data:e.data,topic:e.topic},il=e=>{let t=e.toString(16);return t.length%2!==0&&(t=`0${t}`),Z(t,"base16")},ol=e=>BigInt(`0x${Y(e,"base16")}`);var Na=Z("libp2p-pubsub:");async function Ka(e,t,r){let n={type:"signed",topic:t.topic,data:t.data,sequenceNumber:t.sequenceNumber,from:Ba(e)},s=fe([Na,r(Ar(n)).subarray()]);return n.signature=await e.sign(s),n.key=e.publicKey,n}async function Fa(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([Na,t({...Ar(e),signature:void 0,key:void 0}).subarray()]);return al(e).verify(r,e.signature)}function al(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.from.publicKey!=null)return e.from.publicKey;if(e.key!=null&&e.from.equals(e.key.toMultihash().bytes))return e.key;throw new Error("Could not get the public key from the originator id")}var wn=class extends Ie{log;started;topics;subscriptions;peers;globalSignaturePolicy;canRelayMessage;emitSelf;topicValidators;queue;protocol;components;_registrarTopologyId;maxInboundStreams;maxOutboundStreams;seenCache;decodeRpcLimits;constructor(t,r){super(),this.log=t.logger.forComponent("libp2p:floodsub"),this.components=t,this.protocol=r.protocol??yi,this.started=!1,this.topics=new Map,this.subscriptions=new Set,this.peers=new wr,this.globalSignaturePolicy=r.globalSignaturePolicy==="StrictNoSign"?"StrictNoSign":"StrictSign",this.canRelayMessage=r.canRelayMessage??!0,this.emitSelf=r.emitSelf??!1,this.topicValidators=new Map,this.queue=new vr({concurrency:r.messageProcessingConcurrency??10}),this.maxInboundStreams=r.maxInboundStreams??1,this.maxOutboundStreams=r.maxOutboundStreams??1,this.seenCache=new yn({validityMs:r?.seenTTL??3e4}),this.decodeRpcLimits=Da(r.decodeRpcLimits??Ra),this._onIncomingStream=this._onIncomingStream.bind(this),this._onPeerConnected=this._onPeerConnected.bind(this),this._onPeerDisconnected=this._onPeerDisconnected.bind(this)}[je]=!0;[Symbol.toStringTag]="@libp2p/floodsub";[Ei]=["@libp2p/pubsub"];[Si]=["@libp2p/identify"];async start(){this.started||(this.log("starting"),await this.components.registrar.handle(this.protocol,this._onIncomingStream,{maxInboundStreams:this.maxInboundStreams,maxOutboundStreams:this.maxOutboundStreams}),this._registrarTopologyId=await this.components.registrar.register(this.protocol,{onConnect:this._onPeerConnected,onDisconnect:this._onPeerDisconnected}),this.log("started"),this.started=!0)}async stop(){if(!this.started)return;let t=this.components.registrar;this._registrarTopologyId!=null&&t.unregister(this._registrarTopologyId),await t.unhandle(this.protocol),this.log("stopping");for(let r of this.peers.values())r.close();this.peers.clear(),this.topics.clear(),this.subscriptions=new Set,this.started=!1,this.log("stopped")}isStarted(){return this.started}_onIncomingStream(t,r){this.addPeer(r.remotePeer,t).attachInboundStream(t,void 0,this.decodeRpcLimits)}async _onPeerConnected(t,r){if(this.log("connected %p",t),r.streams.find(i=>i.direction==="outbound"&&i.protocol===this.protocol)){this.log("outbound pubsub stream already present on connection from %p",t);return}let n=await r.newStream(this.protocol);this.addPeer(t,n).attachOutboundStream(n),this.send(t,{subscriptions:Array.from(this.subscriptions).map(i=>i.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 s=new gn(t);return this.peers.set(t,s),s.addEventListener("message",i=>{let o=i.detail,a=[];for(let c of o.messages??[]){if(c.from==null||c.data==null||c.topic==null){this.log("message from %p was missing from, data or topic fields, dropping",t);continue}a.push({from:c.from,data:c.data,topic:c.topic,sequenceNumber:c.sequenceNumber??void 0,signature:c.signature??void 0,key:c.key??void 0})}this.processRpc(s,{subscriptions:(o.subscriptions??[]).map(c=>({subscribe:!!c.subscribe,topic:c.topic??""})),messages:a}).catch(c=>{this.log(c)})}),s.addEventListener("close",()=>this._removePeer(t),{once:!0}),s}_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,s]of this.topics)s.delete(t),s.size===0&&this.topics.delete(n)}}async processRpc(t,r){this.log("rpc from %p",t.peerId);let{subscriptions:n,messages:s}=r;return n!=null&&n.length>0&&(this.log("subscription update from %p",t.peerId),n.forEach(i=>{this.processRpcSubOpt(t.peerId,i)}),super.dispatchEvent(new CustomEvent("subscription-change",{detail:{peerId:t.peerId,subscriptions:n.map(({topic:i,subscribe:o})=>({topic:`${i??""}`,subscribe:!!o}))}}))),s!=null&&s.length>0&&(this.log("messages from %p",t.peerId),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 o=await ka(i);await this.processMessage(t.peerId,o)}catch(o){this.log.error("failed to queue messages from %p - %e",t.peerId,o)}})).catch(i=>{this.log(i)})),!0}processRpcSubOpt(t,r){let n=r.topic;if(n==null)return;let s=this.topics.get(n);r.subscribe===!0?(s==null&&(s=new xr,this.topics.set(n,s)),s.add(t)):s!=null&&(s.delete(t),s.size===0&&this.topics.delete(n))}async processMessage(t,r){if(this.components.peerId.equals(t)&&!this.emitSelf)return;let n=await this.getMsgId(r),s=Y(n,"base64");if(!this.seenCache.has(s)){this.seenCache.put(s,!0);try{await this.validate(t,r)}catch(i){this.log("Message is invalid, dropping it. %O",i);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 ct('Message type should be "signed" when signature policy is StrictSign but it was not');if(t.sequenceNumber==null)throw new ct("Need sequence number when signature policy is StrictSign but it was missing");if(t.key==null)throw new ct("Need key when signature policy is StrictSign but it was missing");return Pa(t.key,t.sequenceNumber);case"StrictNoSign":return Oa(t.data);default:throw new ct("Cannot get message id: unhandled signature policy")}}encodeMessage(t){return Ae.Message.encode(t)}send(t,r){let{messages:n,subscriptions:s,subscribe:i}=r;this.sendRpc(t,{subscriptions:(s??[]).map(o=>({topic:o,subscribe:!!i})),messages:(n??[]).map(Ar)})}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}n.write(r)}async validate(t,r){switch(this.globalSignaturePolicy){case"StrictNoSign":if(r.type!=="unsigned")throw new ct('Message type should be "unsigned" when signature policy is StrictNoSign but it was not');if(r.signature!=null)throw new ct("StrictNoSigning: signature should not be present");if(r.key!=null)throw new ct("StrictNoSigning: key should not be present");if(r.sequenceNumber!=null)throw new ct("StrictNoSigning: seqno should not be present");break;case"StrictSign":if(r.type!=="signed")throw new ct('Message type should be "signed" when signature policy is StrictSign but it was not');if(r.signature==null)throw new ct("StrictSigning: Signing required and no signature was present");if(r.sequenceNumber==null)throw new ct("StrictSigning: Signing required and no sequenceNumber was present");if(!await Fa(r,this.encodeMessage.bind(this)))throw new ct("StrictSigning: Invalid message signature");break;default:throw new ct("Cannot validate message: unhandled signature policy")}let s=this.topicValidators.get(r.topic);if(s!=null){let i=await s(t,r);if(i===Ve.Reject||i===Ve.Ignore)throw new ct("Message validation failed")}}async buildMessage(t){switch(this.globalSignaturePolicy){case"StrictSign":return Ka(this.components.privateKey,t,this.encodeMessage.bind(this));case"StrictNoSign":return Promise.resolve({type:"unsigned",...t});default:throw new ct("Cannot build message: unhandled signature policy")}}getSubscribers(t){if(!this.started)throw new Lr("not started yet");if(t==null)throw new et("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:Ca()};this.log("publish topic: %s from: %p data: %m",t,n.from,n.data);let s=await this.buildMessage(n),i=!1;this.emitSelf&&this.subscriptions.has(t)&&(i=!0,super.dispatchEvent(new CustomEvent("message",{detail:s})));let o=await this.publishMessage(this.components.peerId,s);return i&&(o.recipients=[...o.recipients,this.components.peerId]),o}async publishMessage(t,r){let n=this.getSubscribers(r.topic),s=[];return n==null||n.length===0?(this.log("no peers are subscribed to topic %s",r.topic),{recipients:s}):(n.forEach(i=>{if(this.components.peerId.equals(i)){this.log("not sending message on topic %s to myself",r.topic);return}if(i.equals(t)){this.log("not sending message on topic %s to sender %p",r.topic,i);return}this.log("publish msgs on topics %s %p",r.topic,i),s.push(i),this.send(i,{messages:[r]})}),{recipients:s})}subscribe(t){if(!this.started)throw new Error("Pubsub has not started");if(!this.subscriptions.has(t)){this.log("subscribe to topic: %s",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");if(this.subscriptions.has(t)){this.log("unsubscribe from %s",t),this.subscriptions.delete(t);for(let r of this.peers.keys())this.send(r,{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())}};var yi="/floodsub/1.0.0",cl="StrictSign",ul="StrictNoSign",Ve;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(Ve||(Ve={}));function fl(e){return!!e?.[je]}function ll(e={}){return t=>new wn(t,e)}return Ga(hl);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|