@libp2p/bootstrap 12.0.22-ed1ad1f26 → 12.0.23-29797a5bb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/package.json +7 -7
package/dist/index.min.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PBootstrap = factory()}(typeof self !== 'undefined' ? self : this, function () {
|
|
2
|
-
"use strict";var Libp2PBootstrap=(()=>{var An=Object.defineProperty;var Jc=Object.getOwnPropertyDescriptor;var ta=Object.getOwnPropertyNames;var ea=Object.prototype.hasOwnProperty;var bt=(e,t)=>{for(var r in t)An(e,r,{get:t[r],enumerable:!0})},ra=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ta(t))!ea.call(e,o)&&o!==r&&An(e,o,{get:()=>t[o],enumerable:!(n=Jc(t,o))||n.enumerable});return e};var na=e=>ra(An({},"__esModule",{value:!0}),e);var xl={};bt(xl,{bootstrap:()=>bl});var Ot=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},gr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var wr=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Er=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Ve=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Rs=Symbol.for("@libp2p/peer-discovery");var Bn=Symbol.for("@libp2p/peer-id");function oa(e){return typeof e?.handleEvent=="function"}function sa(e){return(e!==!0&&e!==!1&&e?.once)??!1}var Sr=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 o=sa(n);super.addEventListener(t,i=>{if(o){let c=this.#t.get(i.type);c!=null&&(c=c.filter(({callback:f})=>f!==r),this.#t.set(i.type,c))}oa(r)?r.handleEvent(i):r(i)},n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:r,once:o})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#t.set(t,o))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var Ls=Symbol.for("@libp2p/service-capabilities");var Dn={};bt(Dn,{base58btc:()=>tt,base58flickr:()=>da});var Gl=new Uint8Array(0);function Ps(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 Nt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Us(e){return new TextEncoder().encode(e)}function Ns(e){return new TextDecoder().decode(e)}function ia(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=e.length,f=e.charAt(0),a=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);function l(b){if(b instanceof Uint8Array||(ArrayBuffer.isView(b)?b=new Uint8Array(b.buffer,b.byteOffset,b.byteLength):Array.isArray(b)&&(b=Uint8Array.from(b))),!(b instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(b.length===0)return"";for(var S=0,h=0,g=0,v=b.length;g!==v&&b[g]===0;)g++,S++;for(var B=(v-g)*u+1>>>0,O=new Uint8Array(B);g!==v;){for(var C=b[g],U=0,R=B-1;(C!==0||U<h)&&R!==-1;R--,U++)C+=256*O[R]>>>0,O[R]=C%c>>>0,C=C/c>>>0;if(C!==0)throw new Error("Non-zero carry");h=U,g++}for(var T=B-h;T!==B&&O[T]===0;)T++;for(var N=f.repeat(S);T<B;++T)N+=e.charAt(O[T]);return N}function w(b){if(typeof b!="string")throw new TypeError("Expected String");if(b.length===0)return new Uint8Array;var S=0;if(b[S]!==" "){for(var h=0,g=0;b[S]===f;)h++,S++;for(var v=(b.length-S)*a+1>>>0,B=new Uint8Array(v);b[S];){var O=r[b.charCodeAt(S)];if(O===255)return;for(var C=0,U=v-1;(O!==0||C<g)&&U!==-1;U--,C++)O+=c*B[U]>>>0,B[U]=O%256>>>0,O=O/256>>>0;if(O!==0)throw new Error("Non-zero carry");g=C,S++}if(b[S]!==" "){for(var R=v-g;R!==v&&B[R]===0;)R++;for(var T=new Uint8Array(h+(v-R)),N=h;R!==v;)T[N++]=B[R++];return T}}}function p(b){var S=w(b);if(S)return S;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:w,decode:p}}var ca=ia,aa=ca,Ks=aa;var _n=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")}},Tn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return ks(this,t)}},In=class{decoders;constructor(t){this.decoders=t}or(t){return ks(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 ks(e,t){return new In({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Cn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new _n(t,r,n),this.decoder=new Tn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function be({name:e,prefix:t,encode:r,decode:n}){return new Cn(e,t,r,n)}function $t({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ks(r,e);return be({prefix:t,name:e,encode:n,decode:s=>Nt(o(s))})}function fa(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,f=0;for(let a=0;a<o;++a){let u=t[e[a]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|u,i+=r,i>=8&&(i-=8,s[f++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ua(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let f=0;f<e.length;++f)for(c=c<<8|e[f],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function la(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function W({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=la(n);return be({prefix:t,name:e,encode(s){return ua(s,n,r)},decode(s){return fa(s,o,r,e)}})}var tt=$t({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),da=$t({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var On={};bt(On,{base32:()=>Yt,base32hex:()=>ya,base32hexpad:()=>xa,base32hexpadupper:()=>ga,base32hexupper:()=>ba,base32pad:()=>pa,base32padupper:()=>ma,base32upper:()=>ha,base32z:()=>wa});var Yt=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ha=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),pa=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ma=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ya=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),ba=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),xa=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ga=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),wa=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Rn={};bt(Rn,{base36:()=>He,base36upper:()=>Ea});var He=$t({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ea=$t({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Sa=Hs,Ms=128,va=127,Aa=~va,Ba=Math.pow(2,31);function Hs(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Ba;)t[r++]=e&255|Ms,e/=128;for(;e&Aa;)t[r++]=e&255|Ms,e>>>=7;return t[r]=e|0,Hs.bytes=r-n+1,t}var _a=Ln,Ta=128,Vs=127;function Ln(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw Ln.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Vs)<<o:(i&Vs)*Math.pow(2,o),o+=7}while(i>=Ta);return Ln.bytes=s-n,r}var Ia=Math.pow(2,7),Ca=Math.pow(2,14),Da=Math.pow(2,21),Oa=Math.pow(2,28),Ra=Math.pow(2,35),La=Math.pow(2,42),Pa=Math.pow(2,49),Ua=Math.pow(2,56),Na=Math.pow(2,63),Fa=function(e){return e<Ia?1:e<Ca?2:e<Da?3:e<Oa?4:e<Ra?5:e<La?6:e<Pa?7:e<Ua?8:e<Na?9:10},Ka={encode:Sa,decode:_a,encodingLength:Fa},ka=Ka,qe=ka;function ze(e,t=0){return[qe.decode(e,t),qe.decode.bytes]}function xe(e,t,r=0){return qe.encode(e,t,r),t}function ge(e){return qe.encodingLength(e)}function Ee(e,t){let r=t.byteLength,n=ge(e),o=n+ge(r),s=new Uint8Array(o+r);return xe(e,s,0),xe(r,s,n),s.set(t,o),new we(e,r,t,s)}function je(e){let t=Nt(e),[r,n]=ze(t),[o,s]=ze(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new we(r,o,i,t)}function qs(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ps(e.bytes,r.bytes)}}var we=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function zs(e,t){let{bytes:r,version:n}=e;return n===0?Va(r,Pn(e),t??tt.encoder):Ha(r,Pn(e),t??Yt.encoder)}var js=new WeakMap;function Pn(e){let t=js.get(e);if(t==null){let r=new Map;return js.set(e,r),r}return t}var at=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Ze)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==qa)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=Ee(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&&qs(t.multihash,n.multihash)}toString(t){return zs(this,t)}toJSON(){return{"/":zs(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??Zs(n,o,s.bytes))}else if(r[za]===!0){let{version:n,multihash:o,code:s}=r,i=je(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Ze)throw new Error(`Version 0 CID must use dag-pb (code: ${Ze}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Zs(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ze,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Nt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new we(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,w]=ze(t.subarray(r));return r+=w,l},o=n(),s=Ze;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),f=n(),a=r+f,u=a-i;return{version:o,codec:s,multihashCode:c,digestSize:f,multihashSize:u,size:a}}static parse(t,r){let[n,o]=Ma(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Pn(s).set(n,t),s}};function Ma(e,t){switch(e[0]){case"Q":{let r=t??tt;return[tt.prefix,r.decode(`${tt.prefix}${e}`)]}case tt.prefix:{let r=t??tt;return[tt.prefix,r.decode(e)]}case Yt.prefix:{let r=t??Yt;return[Yt.prefix,r.decode(e)]}case He.prefix:{let r=t??He;return[He.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 Va(e,t,r){let{prefix:n}=r;if(n!==tt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function Ha(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var Ze=112,qa=18;function Zs(e,t,r){let n=ge(e),o=n+ge(t),s=new Uint8Array(o+r.byteLength);return xe(e,s,0),xe(t,s,n),s.set(r,o),s}var za=Symbol.for("@ipld/js-cid/CID");var Un={};bt(Un,{identity:()=>At});var $s=0,ja="identity",Ys=Nt;function Za(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 Ee($s,Ys(e))}var At={code:$s,name:ja,encode:Ys,digest:Za};function xt(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}async function Gs(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}function Ft(e=0){return new Uint8Array(e)}function gt(e=0){return new Uint8Array(e)}function Kt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=gt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Xs=Symbol.for("@achingbrain/uint8arraylist");function Ws(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Ar(e){return!!e?.[Xs]}var wt=class e{bufs;length;[Xs]=!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(Ar(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=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(Ar(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=Ws(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Ws(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(Ar(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Kt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Kt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=n,s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,f=c+i.byteLength;if(o=f,t>=f)continue;let a=t>=c&&t<f,u=r>c&&r<=f;if(a&&u){if(t===c&&r===f){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(r-t)));break}if(a){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(u){if(r===f){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Ar(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let c=i,f=this.byteLength-n.byteLength,a=n.byteLength-1,u;for(let l=r;l<=f;l+=u){u=0;for(let w=a;w>=0;w--){let p=this.get(l+w);if(n[w]!==p){u=Math.max(1,w-c[p]);break}}if(u===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=gt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Ft(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Ft(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Ft(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=gt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Ft(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Ft(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Ft(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Ft(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Ft(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!xt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Nn={};bt(Nn,{base10:()=>$a});var $a=$t({prefix:"9",name:"base10",alphabet:"0123456789"});var Fn={};bt(Fn,{base16:()=>Ya,base16upper:()=>Ga});var Ya=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ga=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Kn={};bt(Kn,{base2:()=>Wa});var Wa=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var kn={};bt(kn,{base256emoji:()=>ef});var Qs=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}"),Xa=Qs.reduce((e,t,r)=>(e[r]=t,e),[]),Qa=Qs.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Ja(e){return e.reduce((t,r)=>(t+=Xa[r],t),"")}function tf(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Qa[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var ef=be({prefix:"\u{1F680}",name:"base256emoji",encode:Ja,decode:tf});var Vn={};bt(Vn,{base64:()=>rf,base64pad:()=>nf,base64url:()=>Mn,base64urlpad:()=>of});var rf=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),nf=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Mn=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),of=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Hn={};bt(Hn,{base8:()=>sf});var sf=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var qn={};bt(qn,{identity:()=>cf});var cf=be({prefix:"\0",name:"identity",encode:e=>Ns(e),decode:e=>Us(e)});var Ld=new TextEncoder,Pd=new TextDecoder;var Zn={};bt(Zn,{sha256:()=>$e,sha512:()=>lf});var uf=20;function jn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new zn(e,t,r,n,o)}var zn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??uf,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Js(n,this.code,r?.truncate):n.then(o=>Js(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Js(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 Ee(t,e)}function ei(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var $e=jn({name:"sha2-256",code:18,encode:ei("SHA-256")}),lf=jn({name:"sha2-512",code:19,encode:ei("SHA-512")});var Ye={...qn,...Kn,...Hn,...Nn,...Fn,...On,...Rn,...Dn,...Vn,...kn},Zd={...Zn,...Un};function ni(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var ri=ni("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),$n=ni("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=gt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),df={utf8:ri,"utf-8":ri,hex:Ye.base16,latin1:$n,ascii:$n,binary:$n,...Ye},Br=df;function Et(e,t="utf8"){let r=Br[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function et(e,t="utf8"){let r=Br[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var hf=parseInt("11111",2),Yn=parseInt("10000000",2),pf=parseInt("01111111",2),oi={0:Ge,1:Ge,2:mf,3:xf,4:gf,5:bf,6:yf,16:Ge,22:Ge,48:Ge};function Gn(e,t={offset:0}){let r=e[t.offset]&hf;if(t.offset++,oi[r]!=null)return oi[r](e,t);throw new Error("No decoder for tag "+r)}function We(e,t){let r=0;if((e[t.offset]&Yn)===Yn){let n=e[t.offset]&pf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Ge(e,t){We(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Gn(e,t);if(n===null)break;r.push(n)}return r}function mf(e,t){let r=We(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function yf(e,t){let r=We(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,f=[];for(;t.offset<n;){let a=e[t.offset];if(t.offset++,f.push(a&127),a<128){f.reverse();let u=0;for(let l=0;l<f.length;l++)u+=f[l]<<l*7;c+=`.${u}`,f=[]}}return c}function bf(e,t){return t.offset++,null}function xf(e,t){let r=We(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function gf(e,t){let r=We(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function wf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new wt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Wn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=wf(e.byteLength);return new wt(Uint8Array.from([t.byteLength|Yn]),t)}function si(e){let t=new wt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new wt(Uint8Array.from([2]),Wn(t),t)}function ii(e){let t=Uint8Array.from([0]),r=new wt(t,e);return new wt(Uint8Array.from([3]),Wn(r),r)}function _r(e,t=48){let r=new wt;for(let n of e)r.append(n);return new wt(Uint8Array.from([t]),Wn(r),r)}var Ef=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Sf=Uint8Array.from([6,5,43,129,4,0,34]),vf=Uint8Array.from([6,5,43,129,4,0,35]),Af={ext:!0,kty:"EC",crv:"P-256"},Bf={ext:!0,kty:"EC",crv:"P-384"},_f={ext:!0,kty:"EC",crv:"P-521"},Xn=32,Qn=48,Jn=66;function ci(e){let t=Gn(e);return ai(t)}function ai(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Xn*2+1)return n=et(t.subarray(r,r+Xn),"base64url"),o=et(t.subarray(r+Xn),"base64url"),new ve({...Af,key_ops:["verify"],x:n,y:o});if(t.byteLength===Qn*2+1)return n=et(t.subarray(r,r+Qn),"base64url"),o=et(t.subarray(r+Qn),"base64url"),new ve({...Bf,key_ops:["verify"],x:n,y:o});if(t.byteLength===Jn*2+1)return n=et(t.subarray(r,r+Jn),"base64url"),o=et(t.subarray(r+Jn),"base64url"),new ve({..._f,key_ops:["verify"],x:n,y:o});throw new Ot(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function fi(e){return _r([si(Uint8Array.from([1])),_r([Tf(e.crv)],160),_r([ii(new wt(Uint8Array.from([4]),Et(e.x??"","base64url"),Et(e.y??"","base64url")))],161)]).subarray()}function Tf(e){if(e==="P-256")return Ef;if(e==="P-384")return Sf;if(e==="P-521")return vf;throw new Ot(`Invalid curve ${e}`)}var ve=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=fi(this.jwk)),this._raw}toMultihash(){return At.digest(Ae(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}async verify(t,r,n){return Gs(this.jwk,r,t,n)}};function to(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function Gt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(`${r}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new RangeError(`${r}expected integer >= 0, got ${e}`)}}function St(e,t,r=""){let n=to(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",f=n?`length=${o}`:`type=${typeof e}`,a=i+"expected Uint8Array"+c+", got "+f;throw n?new RangeError(a):new TypeError(a)}return e}function Tr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Gt(e.outputLen),Gt(e.blockLen),e.outputLen<1)throw new Error('"outputLen" must be >= 1');if(e.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Be(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Ir(e,t){St(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function Mt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Cr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Bt(e,t){return e<<32-t|e>>>t}var li=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",If=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Dr(e){if(St(e),li)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=If[e[r]];return t}var kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function ui(e){if(e>=kt._0&&e<=kt._9)return e-kt._0;if(e>=kt.A&&e<=kt.F)return e-(kt.A-10);if(e>=kt.a&&e<=kt.f)return e-(kt.a-10)}function Xe(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(li)try{return Uint8Array.fromHex(e)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}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 o=0,s=0;o<r;o++,s+=2){let i=ui(e.charCodeAt(s)),c=ui(e.charCodeAt(s+1));if(i===void 0||c===void 0){let f=e[s]+e[s+1];throw new RangeError('hex string expected, got non-hex character "'+f+'" at index '+s)}n[o]=i*16+c}return n}function eo(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];St(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function ro(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function di(e=32){Gt(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 no=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function hi(e,t,r){return e&t^~e&r}function pi(e,t,r){return e&t^e&r^t&r}var Qe=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Cr(this.buffer)}update(t){Be(this),St(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let f=Cr(t);for(;o<=s-i;i+=o)this.process(f,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Be(this),Ir(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Mt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let c=Cr(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let a=f/4,u=this.get();if(a>u.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<a;l++)c.setUint32(4*l,u[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Vt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ft=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Or=BigInt(4294967295),mi=BigInt(32);function Cf(e,t=!1){return t?{h:Number(e&Or),l:Number(e>>mi&Or)}:{h:Number(e>>mi&Or)|0,l:Number(e&Or)|0}}function yi(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=Cf(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var oo=(e,t,r)=>e>>>r,so=(e,t,r)=>e<<32-r|t>>>r,se=(e,t,r)=>e>>>r|t<<32-r,ie=(e,t,r)=>e<<32-r|t>>>r,Je=(e,t,r)=>e<<64-r|t>>>r-32,tr=(e,t,r)=>e>>>r-32|t<<64-r;function Rt(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var bi=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),xi=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,gi=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),wi=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Ei=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Si=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Of=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]),Wt=new Uint32Array(64),io=class extends Qe{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:c,H:f}=this;return[t,r,n,o,s,i,c,f]}set(t,r,n,o,s,i,c,f){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=f|0}process(t,r){for(let l=0;l<16;l++,r+=4)Wt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let w=Wt[l-15],p=Wt[l-2],b=Bt(w,7)^Bt(w,18)^w>>>3,S=Bt(p,17)^Bt(p,19)^p>>>10;Wt[l]=S+Wt[l-7]+b+Wt[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:f,G:a,H:u}=this;for(let l=0;l<64;l++){let w=Bt(c,6)^Bt(c,11)^Bt(c,25),p=u+w+hi(c,f,a)+Of[l]+Wt[l]|0,S=(Bt(n,2)^Bt(n,13)^Bt(n,22))+pi(n,o,s)|0;u=a,a=f,f=c,c=i+p|0,i=s,s=o,o=n,n=p+S|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,f=f+this.F|0,a=a+this.G|0,u=u+this.H|0,this.set(n,o,s,i,c,f,a,u)}roundClean(){Mt(Wt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Mt(this.buffer)}},co=class extends io{A=Vt[0]|0;B=Vt[1]|0;C=Vt[2]|0;D=Vt[3]|0;E=Vt[4]|0;F=Vt[5]|0;G=Vt[6]|0;H=Vt[7]|0;constructor(){super(32)}};var vi=yi(["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))),Rf=vi[0],Lf=vi[1],Xt=new Uint32Array(80),Qt=new Uint32Array(80),ao=class extends Qe{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:f,Eh:a,El:u,Fh:l,Fl:w,Gh:p,Gl:b,Hh:S,Hl:h}=this;return[t,r,n,o,s,i,c,f,a,u,l,w,p,b,S,h]}set(t,r,n,o,s,i,c,f,a,u,l,w,p,b,S,h){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=f|0,this.Eh=a|0,this.El=u|0,this.Fh=l|0,this.Fl=w|0,this.Gh=p|0,this.Gl=b|0,this.Hh=S|0,this.Hl=h|0}process(t,r){for(let B=0;B<16;B++,r+=4)Xt[B]=t.getUint32(r),Qt[B]=t.getUint32(r+=4);for(let B=16;B<80;B++){let O=Xt[B-15]|0,C=Qt[B-15]|0,U=se(O,C,1)^se(O,C,8)^oo(O,C,7),R=ie(O,C,1)^ie(O,C,8)^so(O,C,7),T=Xt[B-2]|0,N=Qt[B-2]|0,j=se(T,N,19)^Je(T,N,61)^oo(T,N,6),F=ie(T,N,19)^tr(T,N,61)^so(T,N,6),d=gi(R,F,Qt[B-7],Qt[B-16]),m=wi(d,U,j,Xt[B-7],Xt[B-16]);Xt[B]=m|0,Qt[B]=d|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:f,Dh:a,Dl:u,Eh:l,El:w,Fh:p,Fl:b,Gh:S,Gl:h,Hh:g,Hl:v}=this;for(let B=0;B<80;B++){let O=se(l,w,14)^se(l,w,18)^Je(l,w,41),C=ie(l,w,14)^ie(l,w,18)^tr(l,w,41),U=l&p^~l&S,R=w&b^~w&h,T=Ei(v,C,R,Lf[B],Qt[B]),N=Si(T,g,O,U,Rf[B],Xt[B]),j=T|0,F=se(n,o,28)^Je(n,o,34)^Je(n,o,39),d=ie(n,o,28)^tr(n,o,34)^tr(n,o,39),m=n&s^n&c^s&c,E=o&i^o&f^i&f;g=S|0,v=h|0,S=p|0,h=b|0,p=l|0,b=w|0,{h:l,l:w}=Rt(a|0,u|0,N|0,j|0),a=c|0,u=f|0,c=s|0,f=i|0,s=n|0,i=o|0;let x=bi(j,d,E);n=xi(x,N,F,m),o=x|0}({h:n,l:o}=Rt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Rt(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:f}=Rt(this.Ch|0,this.Cl|0,c|0,f|0),{h:a,l:u}=Rt(this.Dh|0,this.Dl|0,a|0,u|0),{h:l,l:w}=Rt(this.Eh|0,this.El|0,l|0,w|0),{h:p,l:b}=Rt(this.Fh|0,this.Fl|0,p|0,b|0),{h:S,l:h}=Rt(this.Gh|0,this.Gl|0,S|0,h|0),{h:g,l:v}=Rt(this.Hh|0,this.Hl|0,g|0,v|0),this.set(n,o,s,i,c,f,a,u,l,w,p,b,S,h,g,v)}roundClean(){Mt(Xt,Qt)}destroy(){this.destroyed=!0,Mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},fo=class extends ao{Ah=ft[0]|0;Al=ft[1]|0;Bh=ft[2]|0;Bl=ft[3]|0;Ch=ft[4]|0;Cl=ft[5]|0;Dh=ft[6]|0;Dl=ft[7]|0;Eh=ft[8]|0;El=ft[9]|0;Fh=ft[10]|0;Fl=ft[11]|0;Gh=ft[12]|0;Gl=ft[13]|0;Hh=ft[14]|0;Hl=ft[15]|0;constructor(){super(64)}};var Ai=ro(()=>new co,no(1));var Rr=ro(()=>new fo,no(3));var V=(e,t,r)=>St(e,t,r),lo=Gt,_e=Dr,nt=(...e)=>eo(...e),Te=e=>Xe(e),ce=to,er=e=>di(e),Pr=BigInt(0),uo=BigInt(1);function _t(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function Ur(e){if(typeof e=="bigint"){if(!Lr(e))throw new RangeError("positive bigint expected, got "+e)}else lo(e);return e}function Tt(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 rr(e){let t=Ur(e).toString(16);return t.length&1?"0"+t:t}function Bi(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?Pr:BigInt("0x"+e)}function ae(e){return Bi(Dr(e))}function Lt(e){return Bi(Dr(nr(St(e)).reverse()))}function Nr(e,t){if(Gt(t),t===0)throw new RangeError("zero length");e=Ur(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return Xe(r.padStart(t*2,"0"))}function ho(e,t){return Nr(e,t).reverse()}function _i(e,t){if(e=V(e),t=V(t),e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function nr(e){return Uint8Array.from(V(e))}function Fr(e){if(typeof e!="string")throw new TypeError("ascii string expected, got "+typeof e);return Uint8Array.from(e,(t,r)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${e[r]}" with code ${n} at position ${r}`);return n})}var Lr=e=>typeof e=="bigint"&&Pr<=e;function Pf(e,t,r){return Lr(e)&&Lr(t)&&Lr(r)&&t<=e&&e<r}function Ie(e,t,r,n){if(!Pf(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ce(e){if(e<Pr)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>Pr;e>>=uo,t+=1);return t}var or=e=>(uo<<BigInt(e))-uo;function Ti(e,t,r){if(Gt(e,"hashLen"),Gt(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=h=>new Uint8Array(h),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),c=1e3,f=n(e),a=n(e),u=0,l=()=>{f.fill(1),a.fill(0),u=0},w=(...h)=>r(a,nt(f,...h)),p=(h=o)=>{a=w(s,h),f=w(),h.length!==0&&(a=w(i,h),f=w())},b=()=>{if(u++>=c)throw new Error("drbg: tried max amount of iterations");let h=0,g=[];for(;h<t;){f=w();let v=f.slice();g.push(v),h+=f.length}return nt(...g)};return(h,g)=>{l(),p(h);let v;for(;(v=g(b()))===void 0;)p();return l(),v}}function It(e,t={},r={}){if(Object.prototype.toString.call(e)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,c){if(!c&&i!=="function"&&!Object.hasOwn(e,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let f=e[s];if(c&&f===void 0)return;let a=typeof f;if(a!==i||f===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${a}`)}let o=(s,i)=>Object.entries(s).forEach(([c,f])=>n(c,f,i));o(t,!1),o(r,!0)}var po=()=>{throw new Error("not implemented")};var ut=BigInt(0),X=BigInt(1),fe=BigInt(2),Oi=BigInt(3),Ri=BigInt(4),Li=BigInt(5),Uf=BigInt(7),Pi=BigInt(8),Nf=BigInt(9),Ui=BigInt(16);function J(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 Y(e,t,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 Ii(e,t){if(e===ut)throw new Error("invert: expected non-zero number");if(t<=ut)throw new Error("invert: expected positive modulus, got "+t);let r=J(e,t),n=t,o=ut,s=X,i=X,c=ut;for(;r!==ut;){let a=n/r,u=n-r*a,l=o-i*a,w=s-c*a;n=r,r=u,o=i,s=c,i=l,c=w}if(n!==X)throw new Error("invert: does not exist");return J(o,t)}function mo(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function Ni(e,t){let r=e,n=(r.ORDER+X)/Ri,o=r.pow(t,n);return mo(r,o,t),o}function Ff(e,t){let r=e,n=(r.ORDER-Li)/Pi,o=r.mul(t,fe),s=r.pow(o,n),i=r.mul(t,s),c=r.mul(r.mul(i,fe),s),f=r.mul(i,r.sub(c,r.ONE));return mo(r,f,t),f}function Kf(e){let t=De(e),r=Fi(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Uf)/Ui;return((c,f)=>{let a=c,u=a.pow(f,i),l=a.mul(u,n),w=a.mul(u,o),p=a.mul(u,s),b=a.eql(a.sqr(l),f),S=a.eql(a.sqr(w),f);u=a.cmov(u,l,b),l=a.cmov(p,w,S);let h=a.eql(a.sqr(l),f),g=a.cmov(u,l,h);return mo(a,g,f),g})}function Fi(e){if(e<Oi)throw new Error("sqrt is not defined for small field");let t=e-X,r=0;for(;t%fe===ut;)t/=fe,r++;let n=fe,o=De(e);for(;Ci(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ni;let s=o.pow(n,t),i=(t+X)/fe;return function(f,a){let u=f;if(u.is0(a))return a;if(Ci(u,a)!==1)throw new Error("Cannot find square root");let l=r,w=u.mul(u.ONE,s),p=u.pow(a,t),b=u.pow(a,i);for(;!u.eql(p,u.ONE);){if(u.is0(p))return u.ZERO;let S=1,h=u.sqr(p);for(;!u.eql(h,u.ONE);)if(S++,h=u.sqr(h),S===l)throw new Error("Cannot find square root");let g=X<<BigInt(l-S-1),v=u.pow(w,g);l=S,w=u.sqr(v),p=u.mul(p,w),b=u.mul(b,v)}return b}}function kf(e){return e%Ri===Oi?Ni:e%Pi===Li?Ff:e%Ui===Nf?Kf(e):Fi(e)}var Ht=(e,t)=>(J(e,t)&X)===X,Mf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function yo(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Mf.reduce((n,o)=>(n[o]="function",n),t);if(It(e,r),Tt(e.BYTES,"BYTES"),Tt(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=X)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function Vf(e,t,r){let n=e;if(r<ut)throw new Error("invalid exponent, negatives unsupported");if(r===ut)return n.ONE;if(r===X)return t;let o=n.ONE,s=t;for(;r>ut;)r&X&&(o=n.mul(o,s)),s=n.sqr(s),r>>=X;return o}function sr(e,t,r=!1){let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((c,f,a)=>n.is0(f)?c:(o[a]=c,n.mul(c,f)),n.ONE),i=n.inv(s);return t.reduceRight((c,f,a)=>n.is0(f)?c:(o[a]=n.mul(c,o[a]),n.mul(c,f)),i),o}function Ci(e,t){let r=e,n=(r.ORDER-X)/fe,o=r.pow(t,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),c=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!c)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function Hf(e,t){if(t!==void 0&&lo(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=Ce(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${t})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var Di=new WeakMap,Kr=class{ORDER;BITS;BYTES;isLE;ZERO=ut;ONE=X;_lengths;_mod;constructor(t,r={}){if(t<=X)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:o,nByteLength:s}=Hf(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return J(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&X)===X}neg(t){return J(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return J(t*t,this.ORDER)}add(t,r){return J(t+r,this.ORDER)}sub(t,r){return J(t-r,this.ORDER)}mul(t,r){return J(t*r,this.ORDER)}pow(t,r){return Vf(this,t,r)}div(t,r){return J(t*Ii(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 Ii(t,this.ORDER)}sqrt(t){let r=Di.get(this);return r||Di.set(this,r=kf(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?ho(t,this.BYTES):Nr(t,this.BYTES)}fromBytes(t,r=!1){V(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:c}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let a=new Uint8Array(o);a.set(t,s?0:a.length-t.length),t=a}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let f=s?Lt(t):ae(t);if(c&&(f=J(f,i)),!r&&!this.isValid(f))throw new Error("invalid field element: outside of range 0..ORDER");return f}invertBatch(t){return sr(this,t)}cmov(t,r,n){return _t(n,"condition"),n?r:t}};Object.freeze(Kr.prototype);function De(e,t={}){return new Kr(e,t)}function Ki(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=X)throw new Error("field order must be greater than 1");let t=Ce(e-X);return Math.ceil(t/8)}function bo(e){let t=Ki(e);return t+Math.ceil(t/2)}function xo(e,t,r=!1){V(e);let n=e.length,o=Ki(t),s=Math.max(bo(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Lt(e):ae(e),c=J(i,t-X)+X;return r?ho(c,o):Nr(c,o)}var Oe=BigInt(0),ue=BigInt(1);function ir(e,t){let r=t.negate();return e?r:t}function le(e,t){let r=sr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Hi(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function go(e,t){Hi(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=or(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function ki(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,c=Number(e&o),f=e>>i;c>n&&(c-=s,f+=ue);let a=t*n,u=a+Math.abs(c)-1,l=c===0,w=c<0,p=t%2!==0;return{nextN:f,offset:u,isZero:l,isNeg:w,isNegF:p,offsetF:a}}var wo=new WeakMap,qi=new WeakMap;function Eo(e){return qi.get(e)||1}function Mi(e){if(e!==Oe)throw new Error("invalid wNAF")}var Re=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>Oe;)r&ue&&(n=n.add(o)),o=o.double(),r>>=ue;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=go(r,this.bits),s=[],i=t,c=i;for(let f=0;f<n;f++){c=i,s.push(c);for(let a=1;a<o;a++)c=c.add(i),s.push(c);i=c.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=go(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:f,offset:a,isZero:u,isNeg:l,isNegF:w,offsetF:p}=ki(n,c,i);n=f,u?s=s.add(ir(w,r[p])):o=o.add(ir(l,r[a]))}return Mi(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=go(t,this.bits);for(let i=0;i<s.windows&&n!==Oe;i++){let{nextN:c,offset:f,isZero:a,isNeg:u}=ki(n,i,s);if(n=c,!a){let l=r[f];o=o.add(u?l.negate():l)}}return Mi(n),o}getPrecomputes(t,r,n){let o=wo.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),wo.set(r,o))),o}cached(t,r,n){let o=Eo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Eo(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Hi(r,this.bits),qi.set(t,r),wo.delete(t)}hasCache(t){return Eo(t)!==1}};function zi(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Oe||n>Oe;)r&ue&&(s=s.add(o)),n&ue&&(i=i.add(o)),o=o.double(),r>>=ue,n>>=ue;return{p1:s,p2:i}}function Vi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return yo(t),t}else return De(e,{isLE:r})}function kr(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let f of["p","n","h"]){let a=t[f];if(!(typeof a=="bigint"&&a>Oe))throw new Error(`CURVE.${f} must be positive bigint`)}let o=Vi(t.p,r.Fp,n),s=Vi(t.n,r.Fn,n),c=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let f of c)if(!o.isValid(t[f]))throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function Mr(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var Jt=BigInt(0),it=BigInt(1),So=BigInt(2),qf=BigInt(8);function zf(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),c=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,c)}function ji(e,t={}){let r=t,n=kr("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:c}=i;It(r,{},{uvRatio:"function"});let f=So<<BigInt(s.BYTES*8)-it,a=S=>o.create(S),u=r.uvRatio===void 0?(S,h)=>{try{return{isValid:!0,value:o.sqrt(o.div(S,h))}}catch{return{isValid:!1,value:Jt}}}:r.uvRatio;if(!zf(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(S,h,g=!1){let v=g?it:Jt;return Ie("coordinate "+S,h,v,f),h}function w(S){if(!(S instanceof p))throw new Error("EdwardsPoint expected")}class p{static BASE=new p(i.Gx,i.Gy,it,a(i.Gx*i.Gy));static ZERO=new p(Jt,it,it,Jt);static Fp=o;static Fn=s;X;Y;Z;T;constructor(h,g,v,B){this.X=l("x",h),this.Y=l("y",g),this.Z=l("z",v,!0),this.T=l("t",B),Object.freeze(this)}static CURVE(){return i}static fromAffine(h){if(h instanceof p)throw new Error("extended point not allowed");let{x:g,y:v}=h||{};return l("x",g),l("y",v),new p(g,v,it,a(g*v))}static fromBytes(h,g=!1){let v=o.BYTES,{a:B,d:O}=i;h=nr(V(h,v,"point")),_t(g,"zip215");let C=nr(h),U=h[v-1];C[v-1]=U&-129;let R=Lt(C),T=g?f:o.ORDER;Ie("point.y",R,Jt,T);let N=a(R*R),j=a(N-it),F=a(O*N-B),{isValid:d,value:m}=u(j,F);if(!d)throw new Error("bad point: invalid y coordinate");let E=(m&it)===it,x=(U&128)!==0;if(!g&&m===Jt&&x)throw new Error("bad point: x=0 and x_0=1");return x!==E&&(m=a(-m)),p.fromAffine({x:m,y:R})}static fromHex(h,g=!1){return p.fromBytes(Te(h),g)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,g=!0){return b.createCache(this,h),g||this.multiply(So),this}assertValidity(){let h=this,{a:g,d:v}=i;if(h.is0())throw new Error("bad point: ZERO");let{X:B,Y:O,Z:C,T:U}=h,R=a(B*B),T=a(O*O),N=a(C*C),j=a(N*N),F=a(R*g),d=a(N*a(F+T)),m=a(j+a(v*a(R*T)));if(d!==m)throw new Error("bad point: equation left != right (1)");let E=a(B*O),x=a(C*U);if(E!==x)throw new Error("bad point: equation left != right (2)")}equals(h){w(h);let{X:g,Y:v,Z:B}=this,{X:O,Y:C,Z:U}=h,R=a(g*U),T=a(O*B),N=a(v*U),j=a(C*B);return R===T&&N===j}is0(){return this.equals(p.ZERO)}negate(){return new p(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:h}=i,{X:g,Y:v,Z:B}=this,O=a(g*g),C=a(v*v),U=a(So*a(B*B)),R=a(h*O),T=g+v,N=a(a(T*T)-O-C),j=R+C,F=j-U,d=R-C,m=a(N*F),E=a(j*d),x=a(N*d),y=a(F*j);return new p(m,E,y,x)}add(h){w(h);let{a:g,d:v}=i,{X:B,Y:O,Z:C,T:U}=this,{X:R,Y:T,Z:N,T:j}=h,F=a(B*R),d=a(O*T),m=a(U*v*j),E=a(C*N),x=a((B+O)*(R+T)-F-d),y=E-m,A=E+m,I=a(d-g*F),_=a(x*y),D=a(A*I),P=a(x*I),M=a(y*A);return new p(_,D,M,P)}subtract(h){return w(h),this.add(h.negate())}multiply(h){if(!s.isValidNot0(h))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:g,f:v}=b.cached(this,h,B=>le(p,B));return le(p,[g,v])[0]}multiplyUnsafe(h){if(!s.isValid(h))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return h===Jt?p.ZERO:this.is0()||h===it?this:b.unsafe(this,h,g=>le(p,g))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return b.unsafe(this,i.n).is0()}toAffine(h){let g=this,v=h,{X:B,Y:O,Z:C}=g,U=g.is0();v==null&&(v=U?qf:o.inv(C));let R=a(B*v),T=a(O*v),N=o.mul(C,v);if(U)return{x:Jt,y:it};if(N!==it)throw new Error("invZ was invalid");return{x:R,y:T}}clearCofactor(){return c===it?this:this.multiplyUnsafe(c)}toBytes(){let{x:h,y:g}=this.toAffine(),v=o.toBytes(g);return v[v.length-1]|=h&it?128:0,v}toHex(){return _e(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let b=new Re(p,s.BITS);return s.BITS>=8&&p.BASE.precompute(8),Object.freeze(p.prototype),Object.freeze(p),p}var Vr=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){po()}static fromHex(t){po()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return _e(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.ep.precompute(t,r),this}};function Zi(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;It(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:c,Fn:f}=e,a=n.outputLen,u=2*c.BYTES;if(a!==void 0&&(Tt(a,"hash.outputLen"),a!==u))throw new Error(`hash.outputLen must be ${u}, got ${a}`);let l=o.randomBytes===void 0?er:o.randomBytes,w=o.adjustScalarBytes===void 0?d=>d:o.adjustScalarBytes,p=o.domain===void 0?(d,m,E)=>{if(_t(E,"phflag"),m.length||E)throw new Error("Contexts/pre-hash are not supported");return d}:o.domain;function b(d){return f.create(Lt(d))}function S(d){let m=R.secretKey;V(d,R.secretKey,"secretKey");let E=V(n(d),2*m,"hashedSecretKey"),x=w(E.slice(0,m)),y=E.slice(m,2*m),A=b(x);return{head:x,prefix:y,scalar:A}}function h(d){let{head:m,prefix:E,scalar:x}=S(d),y=i.multiply(x),A=y.toBytes();return{head:m,prefix:E,scalar:x,point:y,pointBytes:A}}function g(d){return h(d).pointBytes}function v(d=Uint8Array.of(),...m){let E=nt(...m);return b(n(p(E,V(d,void 0,"context"),!!s)))}function B(d,m,E={}){d=V(d,void 0,"message"),s&&(d=s(d));let{prefix:x,scalar:y,pointBytes:A}=h(m),I=v(E.context,x,d),_=i.multiply(I).toBytes(),D=v(E.context,_,A,d),P=f.create(I+D*y);if(!f.isValid(P))throw new Error("sign failed: invalid s");let M=nt(_,f.toBytes(P));return V(M,R.signature,"result")}let O={zip215:o.zip215};function C(d,m,E,x=O){let{context:y}=x,A=x.zip215===void 0?!!O.zip215:x.zip215,I=R.signature;d=V(d,I,"signature"),m=V(m,void 0,"message"),E=V(E,R.publicKey,"publicKey"),A!==void 0&&_t(A,"zip215"),s&&(m=s(m));let _=I/2,D=d.subarray(0,_),P=Lt(d.subarray(_,I)),M,q,K;try{M=e.fromBytes(E,A),q=e.fromBytes(D,A),K=i.multiplyUnsafe(P)}catch{return!1}if(!A&&M.isSmallOrder())return!1;let rt=v(y,D,E,m);return q.add(M.multiplyUnsafe(rt)).subtract(K).clearCofactor().is0()}let U=c.BYTES,R={secretKey:U,publicKey:U,signature:2*U,seed:U};function T(d){return d=d===void 0?l(R.seed):d,V(d,R.seed,"seed")}function N(d){return ce(d)&&d.length===R.secretKey}function j(d,m){try{return!!e.fromBytes(d,m===void 0?O.zip215:m)}catch{return!1}}let F={getExtendedPublicKey:h,randomSecretKey:T,isValidSecretKey:N,isValidPublicKey:j,toMontgomery(d){let{y:m}=e.fromBytes(d),E=R.publicKey,x=E===32;if(!x&&E!==57)throw new Error("only defined for 25519 and 448");let y=x?c.div(it+m,it-m):c.div(m-it,m+it);return c.toBytes(y)},toMontgomerySecret(d){let m=R.secretKey;V(d,m);let E=n(d.subarray(0,m));return w(E).subarray(0,m)}};return Object.freeze(R),Object.freeze(F),Object.freeze({keygen:Mr(T,g),getPublicKey:g,sign:B,verify:C,utils:F,Point:e,lengths:R})}function cr(e,t){if(Tt(e),Tt(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(e<0||e>2**(8*t)-1)throw new Error("invalid I2OSP input: "+e);let r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function jf(e,t){let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}function Zf(e){if(!ce(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?Fr(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function vo(e,t,r,n){V(e),Tt(r),t=Zf(t),t.length>255&&(t=n(nt(Fr("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let c=nt(t,cr(t.length,1)),f=new Uint8Array(s),a=cr(r,2),u=new Array(i),l=n(nt(f,e,a,cr(0,1),c));u[0]=n(nt(l,cr(1,1),c));for(let p=1;p<i;p++){let b=[jf(l,u[p-1]),cr(p+1,1),c];u[p]=n(nt(...b))}return nt(...u).slice(0,r)}var $i="HashToScalar-";var $f=BigInt(0),qt=BigInt(1),Yi=BigInt(2);var Yf=BigInt(5),Gf=BigInt(8),Le=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),To={p:Le,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Gf,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Wf(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Le,c=e*e%s*e%s,f=Y(c,Yi,s)*c%s,a=Y(f,qt,s)*e%s,u=Y(a,Yf,s)*a%s,l=Y(u,t,s)*u%s,w=Y(l,r,s)*l%s,p=Y(w,n,s)*w%s,b=Y(p,o,s)*p%s,S=Y(b,o,s)*p%s,h=Y(S,t,s)*u%s;return{pow_p_5_8:Y(h,Yi,s)*e%s,b2:c}}function Xf(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Ao=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Io(e,t){let r=Le,n=J(t*t*t,r),o=J(n*n*t,r),s=Wf(e*o).pow_p_5_8,i=J(e*n*s,r),c=J(t*i*i,r),f=i,a=J(i*Ao,r),u=c===e,l=c===J(-e,r),w=c===J(-e*Ao,r);return u&&(i=f),(l||w)&&(i=a),Ht(i,r)&&(i=J(-i,r)),{isValid:u||l,value:i}}var ee=ji(To,{uvRatio:Io}),te=ee.Fp,Xi=ee.Fn;function Qf(e){return Zi(ee,Rr,Object.assign({adjustScalarBytes:Xf,zip215:!0},e))}var Qi=Qf({});var Bo=Ao,Jf=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),tu=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),eu=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),ru=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Gi=e=>Io(qt,e),nu=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),_o=e=>te.create(Lt(e)&nu);function Wi(e){let{d:t}=To,r=Le,n=g=>te.create(g),o=n(Bo*e*e),s=n((o+qt)*eu),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:f,value:a}=Io(s,c),u=n(a*e);Ht(u,r)||(u=n(-u)),f||(a=u),f||(i=o);let l=n(i*(o-qt)*ru-c),w=a*a,p=n((a+a)*c),b=n(l*Jf),S=n(qt-w),h=n(qt+w);return new ee(n(p*h),n(S*b),n(b*h),n(p*S))}var re=class e extends Vr{static BASE=new e(ee.BASE);static ZERO=new e(ee.ZERO);static Fp=te;static Fn=Xi;constructor(t){super(t)}static fromAffine(t){return new e(ee.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static fromBytes(t){St(t,32);let{a:r,d:n}=To,o=Le,s=O=>te.create(O),i=_o(t);if(!_i(te.toBytes(i),t)||Ht(i,o))throw new Error("invalid ristretto255 encoding 1");let c=s(i*i),f=s(qt+r*c),a=s(qt-r*c),u=s(f*f),l=s(a*a),w=s(r*n*u-l),{isValid:p,value:b}=Gi(s(w*l)),S=s(b*a),h=s(b*S*w),g=s((i+i)*S);Ht(g,o)&&(g=s(-g));let v=s(f*h),B=s(g*v);if(!p||Ht(B,o)||v===$f)throw new Error("invalid ristretto255 encoding 2");return new e(new ee(g,v,qt,B))}static fromHex(t){return e.fromBytes(Xe(t))}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Le,i=h=>te.create(h),c=i(i(n+r)*i(n-r)),f=i(t*r),a=i(f*f),{value:u}=Gi(i(c*a)),l=i(u*c),w=i(u*f),p=i(l*w*o),b;if(Ht(o*p,s)){let h=i(r*Bo),g=i(t*Bo);t=h,r=g,b=i(l*tu)}else b=w;Ht(t*p,s)&&(r=i(-r));let S=i((n-r)*b);return Ht(S,s)&&(S=i(-S)),te.toBytes(S)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=a=>te.create(a),c=i(r*s)===i(n*o),f=i(n*s)===i(r*o);return c||f}is0(){return this.equals(e.ZERO)}};Object.freeze(re.BASE);Object.freeze(re.ZERO);Object.freeze(re.prototype);Object.freeze(re);var ou=Object.freeze({Point:re,hashToCurve(e,t){let r=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=vo(e,r,64,Rr);return ou.deriveToCurve(n)},hashToScalar(e,t={DST:$i}){let r=vo(e,t.DST,64,Rr);return Xi.create(Lt(r))},deriveToCurve(e){St(e,64);let t=_o(e.subarray(0,32)),r=Wi(t),n=_o(e.subarray(32,64)),o=Wi(n);return new re(r.add(o))}});var ar=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Hr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var Ji={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new Hr("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 qr=Ji;var zr=32;var Co,su=(async()=>{try{return await qr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function iu(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await qr.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await qr.get().subtle.verify({name:"Ed25519"},n,t,r instanceof Uint8Array?r:r.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function cu(e,t,r){return Qi.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function tc(e,t,r){return Co==null&&(Co=await su),Co?iu(e,t,r):cu(e,t,r)}function jr(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Zr=class{type="Ed25519";raw;constructor(t){this.raw=Do(t,zr)}toMultihash(){return At.digest(Ae(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=tc(this.raw,r,t);return jr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function rc(e){return e=Do(e,zr),new Zr(e)}function Do(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new Ot(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var fu=Math.pow(2,7),uu=Math.pow(2,14),lu=Math.pow(2,21),Oo=Math.pow(2,28),Ro=Math.pow(2,35),Lo=Math.pow(2,42),Po=Math.pow(2,49),G=128,dt=127;function Pt(e){if(e<fu)return 1;if(e<uu)return 2;if(e<lu)return 3;if(e<Oo)return 4;if(e<Ro)return 5;if(e<Lo)return 6;if(e<Po)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function fr(e,t,r=0){switch(Pt(e)){case 8:t[r++]=e&255|G,e/=128;case 7:t[r++]=e&255|G,e/=128;case 6:t[r++]=e&255|G,e/=128;case 5:t[r++]=e&255|G,e/=128;case 4:t[r++]=e&255|G,e>>>=7;case 3:t[r++]=e&255|G,e>>>=7;case 2:t[r++]=e&255|G,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function Uo(e,t){let r=e[t],n=0;if(n+=r&dt,r<G||(r=e[t+1],n+=(r&dt)<<7,r<G)||(r=e[t+2],n+=(r&dt)<<14,r<G)||(r=e[t+3],n+=(r&dt)<<21,r<G)||(r=e[t+4],n+=(r&dt)*Oo,r<G)||(r=e[t+5],n+=(r&dt)*Ro,r<G)||(r=e[t+6],n+=(r&dt)*Lo,r<G)||(r=e[t+7],n+=(r&dt)*Po,r<G))return n;throw new RangeError("Could not decode varint")}function du(e,t){let r=e.get(t),n=0;if(n+=r&dt,r<G||(r=e.get(t+1),n+=(r&dt)<<7,r<G)||(r=e.get(t+2),n+=(r&dt)<<14,r<G)||(r=e.get(t+3),n+=(r&dt)<<21,r<G)||(r=e.get(t+4),n+=(r&dt)*Oo,r<G)||(r=e.get(t+5),n+=(r&dt)*Ro,r<G)||(r=e.get(t+6),n+=(r&dt)*Lo,r<G)||(r=e.get(t+7),n+=(r&dt)*Po,r<G))return n;throw new RangeError("Could not decode varint")}function No(e,t=0){return e instanceof Uint8Array?Uo(e,t):du(e,t)}var Fo=new Float32Array([-0]),ne=new Uint8Array(Fo.buffer);function nc(e,t,r){Fo[0]=e,t[r]=ne[0],t[r+1]=ne[1],t[r+2]=ne[2],t[r+3]=ne[3]}function oc(e,t){return ne[0]=e[t],ne[1]=e[t+1],ne[2]=e[t+2],ne[3]=e[t+3],Fo[0]}var Ko=new Float64Array([-0]),ht=new Uint8Array(Ko.buffer);function sc(e,t,r){Ko[0]=e,t[r]=ht[0],t[r+1]=ht[1],t[r+2]=ht[2],t[r+3]=ht[3],t[r+4]=ht[4],t[r+5]=ht[5],t[r+6]=ht[6],t[r+7]=ht[7]}function ic(e,t){return ht[0]=e[t],ht[1]=e[t+1],ht[2]=e[t+2],ht[3]=e[t+3],ht[4]=e[t+4],ht[5]=e[t+5],ht[6]=e[t+6],ht[7]=e[t+7],Ko[0]}var pu=BigInt(Number.MAX_SAFE_INTEGER),mu=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 de;if(t<pu&&t>mu)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>cc&&(o=0n,++n>cc&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return de;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):de}},de=new vt(0,0);de.toBigInt=function(){return 0n};de.zzEncode=de.zzDecode=function(){return this};de.length=function(){return 1};var cc=4294967296n;function ac(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 fc(e,t,r){if(r-t<1)return"";let o,s=[],i=0,c;for(;t<r;)c=e[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|e[t++]&63:c>239&&c<365?(c=((c&7)<<18|(e[t++]&63)<<12|(e[t++]&63)<<6|e[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function ko(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function Ct(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function $r(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Mo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,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 $r(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ct(this,4);return $r(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ct(this,4);let t=oc(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Ct(this,4);let t=ic(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 fc(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=$r(this.buf,this.pos+=4),r=$r(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=Uo(this.buf,this.pos);return this.pos+=Pt(t),t}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function ur(e){return new Mo(e instanceof Uint8Array?e:e.subarray())}function Yr(e,t,r){let n=ur(e);return t.decode(n,void 0,r)}function Vo(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return gt(i);o+i>t&&(n=gt(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var he=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Ho(){}var zo=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},yu=Vo();function bu(e){return globalThis.Buffer!=null?gt(e):yu(e)}var dr=class{len;head;tail;states;constructor(){this.len=0,this.head=new he(Ho,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new he(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new jo((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(Gr,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(Gr,r.length(),r)}uint64Number(t){return this._push(fr,Pt(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=vt.fromBigInt(t).zzEncode();return this._push(Gr,r.length(),r)}sint64Number(t){let r=vt.fromNumber(t).zzEncode();return this._push(Gr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(qo,1,t?1:0)}fixed32(t){return this._push(lr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=vt.fromBigInt(t);return this._push(lr,4,r.lo)._push(lr,4,r.hi)}fixed64Number(t){let r=vt.fromNumber(t);return this._push(lr,4,r.lo)._push(lr,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(nc,4,t)}double(t){return this._push(sc,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(qo,1,0):this.uint32(r)._push(gu,r,t)}string(t){let r=ac(t);return r!==0?this.uint32(r)._push(ko,r,t):this._push(qo,1,0)}fork(){return this.states=new zo(this),this.head=this.tail=new he(Ho,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new he(Ho,0,0),this.len=0),this}ldelim(){let t=this.head,r=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=r,this.len+=n),this}finish(){let t=this.head.next,r=bu(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function qo(e,t,r){t[r]=e&255}function xu(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var jo=class extends he{next;constructor(t,r){super(xu,t,r),this.next=void 0}};function Gr(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 lr(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 gu(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(dr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(wu,t,e),this},dr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(Eu,t,e),this});function wu(e,t,r){t.set(e,r)}function Eu(e,t,r){e.length<40?ko(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Et(e),r)}function Zo(){return new dr}function Wr(e,t){let r=Zo();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Xr(e,t,r){let n=ur(e);yield*t.stream(n,void 0,"$",r)}var Qr={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Jr(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function $o(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,c){let f=t(i);c.int32(f)},n=function(i){let c=i.int32();return t(c)},o=function*(i){let c=i.int32();yield t(c)};return Jr("enum",Qr.VARINT,r,n,o)}function tn(e,t,r){return Jr("message",Qr.LENGTH_DELIMITED,e,t,r)}var mt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(mt||(mt={}));var Yo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Yo||(Yo={}));(function(e){e.codec=()=>$o(Yo)})(mt||(mt={}));var hr;(function(e){let t;e.codec=()=>(t==null&&(t=tn((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),mt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let f={},a=i==null?s.len:s.pos+i;for(;s.pos<a;){let u=s.uint32();switch(u>>>3){case 1:{f.Type=mt.codec().decode(s);break}case 2:{f.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return f},function*(s,i,c,f={}){let a=i==null?s.len:s.pos+i;for(;s.pos<a;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${c}.Type`,value:mt.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return Wr(s,e.codec())}e.encode=r;function n(s,i){return Yr(s,e.codec(),i)}e.decode=n;function o(s,i){return Xr(s,e.codec(),i)}e.stream=o})(hr||(hr={}));var Go;(function(e){let t;e.codec=()=>(t==null&&(t=tn((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),mt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),c.lengthDelimited!==!1&&i.ldelim()},(s,i,c={})=>{let f={},a=i==null?s.len:s.pos+i;for(;s.pos<a;){let u=s.uint32();switch(u>>>3){case 1:{f.Type=mt.codec().decode(s);break}case 2:{f.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return f},function*(s,i,c,f={}){let a=i==null?s.len:s.pos+i;for(;s.pos<a;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${c}.Type`,value:mt.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return Wr(s,e.codec())}e.encode=r;function n(s,i){return Yr(s,e.codec(),i)}e.decode=n;function o(s,i){return Xr(s,e.codec(),i)}e.stream=o})(Go||(Go={}));var en=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(Tr(t),St(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Mt(o)}update(t){return Be(this),this.iHash.update(t),this}digestInto(t){Be(this),Ir(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:o,destroyed:s,blockLen:i,outputLen:c}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=c,t.oHash=r._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},lc=(()=>{let e=((t,r,n)=>new en(t,r).update(n).digest());return e.create=(t,r)=>new en(t,r),e})();var dc=(e,t)=>(e+(e>=0?t:-t)/hc)/t;function vu(e,t,r){Ie("scalar",e,Ut,r);let[[n,o],[s,i]]=t,c=dc(i*e,r),f=dc(-o*e,r),a=e-c*n-f*s,u=-c*o-f*i,l=a<Ut,w=u<Ut;l&&(a=-a),w&&(u=-u);let p=or(Math.ceil(Ce(r)/2))+oe;if(a<Ut||a>=p||u<Ut||u>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:a,k2neg:w,k2:u}}function Xo(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Wo(e,t){It(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return _t(r.lowS,"lowS"),_t(r.prehash,"prehash"),r.format!==void 0&&Xo(r.format),r}var Qo=class extends Error{constructor(t=""){super(t)}},Dt={Err:Qo,_tlv:{encode:(e,t)=>{let{Err:r}=Dt;if(Tt(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=rr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?rr(o.length/2|128):"";return rr(e)+s+o+t},decode(e,t){let{Err:r}=Dt;t=V(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let f=o&127;if(!f)throw new r("tlv.decode(long): indefinite length not supported");if(f>4)throw new r("tlv.decode(long): byte length is too big");let a=t.subarray(n,n+f);if(a.length!==f)throw new r("tlv.decode: length bytes not complete");if(a[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of a)i=i<<8|u;if(n+=f,i<128)throw new r("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new r("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Dt;if(Ur(e),e<Ut)throw new t("integer: negative integers are not allowed");let r=rr(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}=Dt;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 ae(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Dt,o=V(e,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:c,l:f}=n.decode(2,s),{v:a,l:u}=n.decode(2,f);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(c),s:r.decode(a)}},hexFromSig(e){let{_tlv:t,_int:r}=Dt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}};Object.freeze(Dt._tlv);Object.freeze(Dt._int);Object.freeze(Dt);var Ut=BigInt(0),oe=BigInt(1),hc=BigInt(2),rn=BigInt(3),Au=BigInt(4);function pc(e,t={}){let r=kr("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:c}=s;It(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:f,allowInfinityPoint:a}=t;if(f&&(!n.is0(s.a)||typeof f.beta!="bigint"||!Array.isArray(f.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=yc(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function w(F,d,m){if(a&&d.is0())return Uint8Array.of(0);let{x:E,y:x}=d.toAffine(),y=n.toBytes(E);if(_t(m,"isCompressed"),m){l();let A=!n.isOdd(x);return nt(mc(A),y)}else return nt(Uint8Array.of(4),y,n.toBytes(x))}function p(F){V(F,void 0,"Point");let{publicKey:d,publicKeyUncompressed:m}=u,E=F.length,x=F[0],y=F.subarray(1);if(a&&E===1&&x===0)return{x:n.ZERO,y:n.ZERO};if(E===d&&(x===2||x===3)){let A=n.fromBytes(y);if(!n.isValid(A))throw new Error("bad point: is not on curve, wrong x");let I=h(A),_;try{_=n.sqrt(I)}catch(M){let q=M instanceof Error?": "+M.message:"";throw new Error("bad point: is not on curve, sqrt error"+q)}l();let D=n.isOdd(_);return(x&1)===1!==D&&(_=n.neg(_)),{x:A,y:_}}else if(E===m&&x===4){let A=n.BYTES,I=n.fromBytes(y.subarray(0,A)),_=n.fromBytes(y.subarray(A,A*2));if(!g(I,_))throw new Error("bad point: is not on curve");return{x:I,y:_}}else throw new Error(`bad point: got length ${E}, expected compressed=${d} or uncompressed=${m}`)}let b=t.toBytes===void 0?w:t.toBytes,S=t.fromBytes===void 0?p:t.fromBytes;function h(F){let d=n.sqr(F),m=n.mul(d,F);return n.add(n.add(m,n.mul(F,s.a)),s.b)}function g(F,d){let m=n.sqr(d),E=h(F);return n.eql(m,E)}if(!g(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(s.a,rn),Au),B=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(v,B)))throw new Error("bad curve params: a or b");function O(F,d,m=!1){if(!n.isValid(d)||m&&n.is0(d))throw new Error(`bad point coordinate ${F}`);return d}function C(F){if(!(F instanceof T))throw new Error("Weierstrass Point expected")}function U(F){if(!f||!f.basises)throw new Error("no endo");return vu(F,f.basises,o.ORDER)}function R(F,d,m,E,x){return m=new T(n.mul(m.X,F),m.Y,m.Z),d=ir(E,d),m=ir(x,m),d.add(m)}class T{static BASE=new T(s.Gx,s.Gy,n.ONE);static ZERO=new T(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(d,m,E){this.X=O("x",d),this.Y=O("y",m,!0),this.Z=O("z",E),Object.freeze(this)}static CURVE(){return s}static fromAffine(d){let{x:m,y:E}=d||{};if(!d||!n.isValid(m)||!n.isValid(E))throw new Error("invalid affine point");if(d instanceof T)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(E)?T.ZERO:new T(m,E,n.ONE)}static fromBytes(d){let m=T.fromAffine(S(V(d,void 0,"point")));return m.assertValidity(),m}static fromHex(d){return T.fromBytes(Te(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,m=!0){return j.createCache(this,d),m||this.multiply(rn),this}assertValidity(){let d=this;if(d.is0()){if(t.allowInfinityPoint&&n.is0(d.X)&&n.eql(d.Y,n.ONE)&&n.is0(d.Z))return;throw new Error("bad point: ZERO")}let{x:m,y:E}=d.toAffine();if(!n.isValid(m)||!n.isValid(E))throw new Error("bad point: x or y not field elements");if(!g(m,E))throw new Error("bad point: equation left != right");if(!d.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:d}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(d)}equals(d){C(d);let{X:m,Y:E,Z:x}=this,{X:y,Y:A,Z:I}=d,_=n.eql(n.mul(m,I),n.mul(y,x)),D=n.eql(n.mul(E,I),n.mul(A,x));return _&&D}negate(){return new T(this.X,n.neg(this.Y),this.Z)}double(){let{a:d,b:m}=s,E=n.mul(m,rn),{X:x,Y:y,Z:A}=this,I=n.ZERO,_=n.ZERO,D=n.ZERO,P=n.mul(x,x),M=n.mul(y,y),q=n.mul(A,A),K=n.mul(x,y);return K=n.add(K,K),D=n.mul(x,A),D=n.add(D,D),I=n.mul(d,D),_=n.mul(E,q),_=n.add(I,_),I=n.sub(M,_),_=n.add(M,_),_=n.mul(I,_),I=n.mul(K,I),D=n.mul(E,D),q=n.mul(d,q),K=n.sub(P,q),K=n.mul(d,K),K=n.add(K,D),D=n.add(P,P),P=n.add(D,P),P=n.add(P,q),P=n.mul(P,K),_=n.add(_,P),q=n.mul(y,A),q=n.add(q,q),P=n.mul(q,K),I=n.sub(I,P),D=n.mul(q,M),D=n.add(D,D),D=n.add(D,D),new T(I,_,D)}add(d){C(d);let{X:m,Y:E,Z:x}=this,{X:y,Y:A,Z:I}=d,_=n.ZERO,D=n.ZERO,P=n.ZERO,M=s.a,q=n.mul(s.b,rn),K=n.mul(m,y),rt=n.mul(E,A),ot=n.mul(x,I),st=n.add(m,E),Q=n.add(y,A);st=n.mul(st,Q),Q=n.add(K,rt),st=n.sub(st,Q),Q=n.add(m,x);let yt=n.add(y,I);return Q=n.mul(Q,yt),yt=n.add(K,ot),Q=n.sub(Q,yt),yt=n.add(E,x),_=n.add(A,I),yt=n.mul(yt,_),_=n.add(rt,ot),yt=n.sub(yt,_),P=n.mul(M,Q),_=n.mul(q,ot),P=n.add(_,P),_=n.sub(rt,P),P=n.add(rt,P),D=n.mul(_,P),rt=n.add(K,K),rt=n.add(rt,K),ot=n.mul(M,ot),Q=n.mul(q,Q),rt=n.add(rt,ot),ot=n.sub(K,ot),ot=n.mul(M,ot),Q=n.add(Q,ot),K=n.mul(rt,Q),D=n.add(D,K),K=n.mul(yt,Q),_=n.mul(st,_),_=n.sub(_,K),K=n.mul(st,rt),P=n.mul(yt,P),P=n.add(P,K),new T(_,D,P)}subtract(d){return C(d),this.add(d.negate())}is0(){return this.equals(T.ZERO)}multiply(d){let{endo:m}=t;if(!o.isValidNot0(d))throw new RangeError("invalid scalar: out of range");let E,x,y=A=>j.cached(this,A,I=>le(T,I));if(m){let{k1neg:A,k1:I,k2neg:_,k2:D}=U(d),{p:P,f:M}=y(I),{p:q,f:K}=y(D);x=M.add(K),E=R(m.beta,P,q,A,_)}else{let{p:A,f:I}=y(d);E=A,x=I}return le(T,[E,x])[0]}multiplyUnsafe(d){let{endo:m}=t,E=this,x=d;if(!o.isValid(x))throw new RangeError("invalid scalar: out of range");if(x===Ut||E.is0())return T.ZERO;if(x===oe)return E;if(j.hasCache(this))return this.multiply(x);if(m){let{k1neg:y,k1:A,k2neg:I,k2:_}=U(x),{p1:D,p2:P}=zi(T,E,A,_);return R(m.beta,D,P,y,I)}else return j.unsafe(E,x)}toAffine(d){let m=this,E=d,{X:x,Y:y,Z:A}=m;if(n.eql(A,n.ONE))return{x,y};let I=m.is0();E==null&&(E=I?n.ONE:n.inv(A));let _=n.mul(x,E),D=n.mul(y,E),P=n.mul(A,E);if(I)return{x:n.ZERO,y:n.ZERO};if(!n.eql(P,n.ONE))throw new Error("invZ was invalid");return{x:_,y:D}}isTorsionFree(){let{isTorsionFree:d}=t;return i===oe?!0:d?d(T,this):j.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:d}=t;return i===oe?this:d?d(T,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===oe?this.is0():this.clearCofactor().is0()}toBytes(d=!0){return _t(d,"isCompressed"),this.assertValidity(),b(T,this,d)}toHex(d=!0){return _e(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=o.BITS,j=new Re(T,t.endo?Math.ceil(N/2):N);return N>=8&&T.BASE.precompute(8),Object.freeze(T.prototype),Object.freeze(T),T}function mc(e){return Uint8Array.of(e?2:3)}function yc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Bu(e,t={}){let{Fn:r}=e,n=t.randomBytes===void 0?er:t.randomBytes,o=Object.assign(yc(e.Fp,r),{seed:Math.max(bo(r.ORDER),16)});function s(p){try{let b=r.fromBytes(p);return r.isValidNot0(b)}catch{return!1}}function i(p,b){let{publicKey:S,publicKeyUncompressed:h}=o;try{let g=p.length;return b===!0&&g!==S||b===!1&&g!==h?!1:!!e.fromBytes(p)}catch{return!1}}function c(p){return p=p===void 0?n(o.seed):p,xo(V(p,o.seed,"seed"),r.ORDER)}function f(p,b=!0){return e.BASE.multiply(r.fromBytes(p)).toBytes(b)}function a(p){let{secretKey:b,publicKey:S,publicKeyUncompressed:h}=o,g=r._lengths;if(!ce(p))return;let v=V(p,void 0,"key").length,B=v===S||v===h,O=v===b||!!g?.includes(v);if(!(B&&O))return B}function u(p,b,S=!0){if(a(p)===!0)throw new Error("first arg must be private key");if(a(b)===!1)throw new Error("second arg must be public key");let h=r.fromBytes(p);return e.fromBytes(b).multiply(h).toBytes(S)}let l={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c},w=Mr(c,f);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:f,getSharedSecret:u,keygen:w,Point:e,utils:l,lengths:o})}function bc(e,t,r={}){let n=t;Tr(n),It(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?er:r.randomBytes,s=r.hmac===void 0?(x,y)=>lc(n,x,y):r.hmac,{Fp:i,Fn:c}=e,{ORDER:f,BITS:a}=c,{keygen:u,getPublicKey:l,getSharedSecret:w,utils:p,lengths:b}=Bu(e,r),S={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},h=f*hc+oe<i.ORDER;function g(x){let y=f>>oe;return x>y}function v(x,y){if(!c.isValidNot0(y))throw new Error(`invalid signature ${x}: out of range 1..Point.Fn.ORDER`);return y}function B(){if(h)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function O(x,y){Xo(y);let A=b.signature,I=y==="compact"?A:y==="recovered"?A+1:void 0;return V(x,I)}class C{r;s;recovery;constructor(y,A,I){if(this.r=v("r",y),this.s=v("s",A),I!=null){if(B(),![0,1,2,3].includes(I))throw new Error("invalid recovery id");this.recovery=I}Object.freeze(this)}static fromBytes(y,A=S.format){O(y,A);let I;if(A==="der"){let{r:M,s:q}=Dt.toSig(V(y));return new C(M,q)}A==="recovered"&&(I=y[0],A="compact",y=y.subarray(1));let _=b.signature/2,D=y.subarray(0,_),P=y.subarray(_,_*2);return new C(c.fromBytes(D),c.fromBytes(P),I)}static fromHex(y,A){return this.fromBytes(Te(y),A)}assertRecovery(){let{recovery:y}=this;if(y==null)throw new Error("invalid recovery id: must be present");return y}addRecoveryBit(y){return new C(this.r,this.s,y)}recoverPublicKey(y){let{r:A,s:I}=this,_=this.assertRecovery(),D=_===2||_===3?A+f:A;if(!i.isValid(D))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let P=i.toBytes(D),M=e.fromBytes(nt(mc((_&1)===0),P)),q=c.inv(D),K=R(V(y,void 0,"msgHash")),rt=c.create(-K*q),ot=c.create(I*q),st=e.BASE.multiplyUnsafe(rt).add(M.multiplyUnsafe(ot));if(st.is0())throw new Error("invalid recovery: point at infinify");return st.assertValidity(),st}hasHighS(){return g(this.s)}toBytes(y=S.format){if(Xo(y),y==="der")return Te(Dt.hexFromSig(this));let{r:A,s:I}=this,_=c.toBytes(A),D=c.toBytes(I);return y==="recovered"?(B(),nt(Uint8Array.of(this.assertRecovery()),_,D)):nt(_,D)}toHex(y){return _e(this.toBytes(y))}}Object.freeze(C.prototype),Object.freeze(C);let U=r.bits2int===void 0?function(y){if(y.length>8192)throw new Error("input is too large");let A=ae(y),I=y.length*8-a;return I>0?A>>BigInt(I):A}:r.bits2int,R=r.bits2int_modN===void 0?function(y){return c.create(U(y))}:r.bits2int_modN,T=or(a);function N(x){return Ie("num < 2^"+a,x,Ut,T),c.toBytes(x)}function j(x,y){return V(x,void 0,"message"),y?V(n(x),void 0,"prehashed message"):x}function F(x,y,A){let{lowS:I,prehash:_,extraEntropy:D}=Wo(A,S);x=j(x,_);let P=R(x),M=c.fromBytes(y);if(!c.isValidNot0(M))throw new Error("invalid private key");let q=[N(M),N(P)];if(D!=null&&D!==!1){let st=D===!0?o(b.secretKey):D;q.push(V(st,void 0,"extraEntropy"))}let K=nt(...q),rt=P;function ot(st){let Q=U(st);if(!c.isValidNot0(Q))return;let yt=c.inv(Q),ye=e.BASE.multiply(Q).toAffine(),Me=c.create(ye.x);if(Me===Ut)return;let xr=c.create(yt*c.create(rt+Me*M));if(xr===Ut)return;let Ds=(ye.x===Me?0:2)|Number(ye.y&oe),Os=xr;return I&&g(xr)&&(Os=c.neg(xr),Ds^=1),new C(Me,Os,h?void 0:Ds)}return{seed:K,k2sig:ot}}function d(x,y,A={}){let{seed:I,k2sig:_}=F(x,y,A);return Ti(n.outputLen,c.BYTES,s)(I,_).toBytes(A.format)}function m(x,y,A,I={}){let{lowS:_,prehash:D,format:P}=Wo(I,S);if(A=V(A,void 0,"publicKey"),y=j(y,D),!ce(x)){let M=x instanceof C?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+M)}O(x,P);try{let M=C.fromBytes(x,P),q=e.fromBytes(A);if(_&&M.hasHighS())return!1;let{r:K,s:rt}=M,ot=R(y),st=c.inv(rt),Q=c.create(ot*st),yt=c.create(K*st),ye=e.BASE.multiplyUnsafe(Q).add(q.multiplyUnsafe(yt));return ye.is0()?!1:c.create(ye.x)===K}catch{return!1}}function E(x,y,A={}){let{prehash:I}=Wo(A,S);return y=j(y,I),C.fromBytes(x,"recovered").recoverPublicKey(y).toBytes()}return Object.freeze({keygen:u,getPublicKey:l,getSharedSecret:w,utils:p,lengths:b,Point:e,sign:d,verify:m,recoverPublicKey:E,Signature:C,hash:n})}var ts={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},_u={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var xc=BigInt(2);function Tu(e){let t=ts.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),f=BigInt(88),a=e*e*e%t,u=a*a*e%t,l=Y(u,r,t)*u%t,w=Y(l,r,t)*u%t,p=Y(w,xc,t)*a%t,b=Y(p,o,t)*p%t,S=Y(b,s,t)*b%t,h=Y(S,c,t)*S%t,g=Y(h,f,t)*h%t,v=Y(g,c,t)*S%t,B=Y(v,r,t)*u%t,O=Y(B,i,t)*b%t,C=Y(O,n,t)*a%t,U=Y(C,xc,t);if(!Jo.eql(Jo.sqr(U),e))throw new Error("Cannot find square root");return U}var Jo=De(ts.p,{sqrt:Tu}),Iu=pc(ts,{Fp:Jo,endo:_u}),Pe=bc(Iu,Ai);function gc(e,t,r,n){let o=$e.digest(r instanceof Uint8Array?r:r.subarray());if(jr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Pe.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new ar(String(s))});try{return n?.signal?.throwIfAborted(),Pe.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new ar(String(s))}}var nn=class{type="secp256k1";raw;_key;constructor(t){this._key=Ec(t),this.raw=wc(this._key)}toMultihash(){return At.digest(Ae(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return tt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:xt(this.raw,t.raw)}verify(t,r,n){return gc(this._key,r,t,n)}};function Sc(e){return new nn(e)}function wc(e){return Pe.Point.fromBytes(e).toBytes()}function Ec(e){try{return Pe.Point.fromBytes(e),e}catch(t){throw new gr(String(t))}}function vc(e){let{Type:t,Data:r}=hr.decode(e.digest),n=r??new Uint8Array;switch(t){case mt.Ed25519:return rc(n);case mt.secp256k1:return Sc(n);case mt.ECDSA:return ci(n);default:throw new Ve}}function Ae(e){return hr.encode({Type:mt[e.type],Data:e.raw})}var Ac=Symbol.for("nodejs.util.inspect.custom"),Cu=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()})`}[Bn]=!0;toString(){return this.string==null&&(this.string=tt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(Cu,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return xt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return xt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ac](){return`PeerId(${this.toString()})`}},on=class extends pr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},sn=class extends pr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},cn=class extends pr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Du=2336,mr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=At.digest(Et(this.url))}[Ac](){return`PeerId(${this.url})`}[Bn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(Du,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=et(t)),t.toString()===this.toString())}};var Ou=114,Bc=2336;function _c(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=je(tt.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return Ru(at.parse(e));if(t==null)throw new Ot('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=je(t.decode(e))}return Tc(r)}function Tc(e){if(Pu(e))return new on({multihash:e});if(Lu(e))try{let t=vc(e);if(t.type==="Ed25519")return new sn({multihash:e,publicKey:t});if(t.type==="secp256k1")return new cn({multihash:e,publicKey:t})}catch{let r=et(e.digest);return new mr(new URL(r))}throw new Er("Supplied PeerID Multihash is invalid")}function Ru(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Ou&&e.code!==Bc)throw new wr("Supplied PeerID CID is invalid");if(e.code===Bc){let t=et(e.multihash.digest);return new mr(new URL(t))}return Tc(e.multihash)}function Lu(e){return e.code===At.code}function Pu(e){return e.code===$e.code}var lt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},zt=class extends Error{static name="ValidationError";name="ValidationError"},an=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},fn=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var un=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,c=this.peekChar();if(c===void 0)return;let f=c==="0",a=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let l=this.readChar();if(l===void 0)return;let w=Number.parseInt(l,t);if(!Number.isNaN(w))return w});if(u===void 0)break;if(s*=t,s+=u,s>a||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&f&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[c]=t(s.subarray(0,i));return r.set(s.subarray(0,c),16-c),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var Uu=45,Nu=15,ln=new un;function Ic(e){if(!(e.length>Nu))return ln.new(e).parseWith(()=>ln.readIPv4Addr())}function Cc(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Uu))return ln.new(e).parseWith(()=>ln.readIPv6Addr())}function dn(e){return!!Ic(e)}function Dc(e){return!!Cc(e)}function rs(e){return t=>et(t,e)}function ns(e){return t=>Et(t,e)}function Ue(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function pe(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Oc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=Et(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=pe(n);return Kt([r,o],r.length+o.length)}function Rc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=Yt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=pe(n);return Kt([r,o],r.length+o.length)}function os(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=et(t,"base32"),o=Ue(r);return`${n}:${o}`}var ss=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new lt("Invalid byte value in IP address");t[n]=o}),t},Lc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=dn(r[n]),i;s&&(i=ss(r[n]),r[n]=et(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,et(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new lt("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},Pc=function(e){if(e.byteLength!==4)throw new lt("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},Uc=function(e){if(e.byteLength!==16)throw new lt("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new lt(`Invalid IPv6 address "${r}"`)}};function Nc(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new lt(`Invalid IPv6 address "${e}"`)}}var es=Object.values(Ye).map(e=>e.decoder),Fu=(function(){let e=es[0].or(es[1]);return es.slice(2).forEach(t=>e=e.or(t)),e})();function Fc(e){return Fu.decode(e)}function Kc(e){return t=>e.encoder.encode(t)}function Ku(e){if(parseInt(e).toString()!==e)throw new zt("Value must be an integer")}function ku(e){if(e<0)throw new zt("Value must be a positive integer, or zero")}function Mu(e){return t=>{if(t>e)throw new zt(`Value must be smaller than or equal to ${e}`)}}function Vu(...e){return t=>{for(let r of e)r(t)}}var yr=Vu(Ku,ku,Mu(65535));var ct=-1,is=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new fn(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},Zt=new is,el=[{code:4,name:"ip4",size:32,valueToBytes:ss,bytesToValue:Pc,validate:e=>{if(!dn(e))throw new zt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:pe,bytesToValue:Ue,validate:yr},{code:273,name:"udp",size:16,valueToBytes:pe,bytesToValue:Ue,validate:yr},{code:33,name:"dccp",size:16,valueToBytes:pe,bytesToValue:Ue,validate:yr},{code:41,name:"ip6",size:128,valueToBytes:Lc,bytesToValue:Uc,stringToValue:Nc,validate:e=>{if(!Dc(e))throw new zt(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:ct},{code:43,name:"ipcidr",size:8,bytesToValue:rs("base10"),valueToBytes:ns("base10")},{code:53,name:"dns",size:ct},{code:54,name:"dns4",size:ct},{code:55,name:"dns6",size:ct},{code:56,name:"dnsaddr",size:ct},{code:132,name:"sctp",size:16,valueToBytes:pe,bytesToValue:Ue,validate:yr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ct,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:ct,bytesToValue:rs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?ns("base58btc")(e):at.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:os,valueToBytes:Oc},{code:445,name:"onion3",size:296,bytesToValue:os,valueToBytes:Rc},{code:446,name:"garlic64",size:ct},{code:447,name:"garlic32",size:ct},{code:448,name:"tls"},{code:449,name:"sni",size:ct},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ct,bytesToValue:Kc(Mn),valueToBytes:Fc},{code:480,name:"http"},{code:481,name:"http-path",size:ct,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ct}];el.forEach(e=>{Zt.addProtocol(e)});function kc(e){let t=[],r=0;for(;r<e.length;){let n=No(e,r),o=Zt.getProtocol(n),s=Pt(n),i=rl(o,e,r+s),c=0;i>0&&o.size===ct&&(c=Pt(i));let f=s+c+i,a={code:n,name:o.name,bytes:e.subarray(r,r+f)};if(i>0){let u=r+s+c,l=e.subarray(u,u+i);a.value=o.bytesToValue?.(l)??et(l)}t.push(a),r+=f}return t}function Mc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Zt.getProtocol(n.code),s=Pt(n.code),i,c=0,f=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??Et(n.value),c=i.byteLength,o.size===ct&&(f=Pt(c)));let a=new Uint8Array(s+f+c),u=0;fr(n.code,a,u),u+=s,i!=null&&(o.size===ct&&(fr(c,a,u),u+=f),a.set(i,u)),n.bytes=a}r.push(n.bytes),t+=n.bytes.byteLength}return Kt(r,t)}function Vc(e){if(e.charAt(0)!=="/")throw new lt('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let c=s===e.length-1;if(i==="/"||c){let f=Zt.getProtocol(o);if(r==="protocol"){if(f.size==null||f.size===0){t.push({code:f.code,name:f.name}),n="",o="",r="protocol";continue}else if(c)throw new lt(`Component ${o} was missing value`);r="value"}else if(r==="value"){let a={code:f.code,name:f.name};if(f.size!=null&&f.size!==0){if(n==="")throw new lt(`Component ${o} was missing value`);a.value=f.stringToValue?.(n)??n}t.push(a),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new lt("Incomplete multiaddr");return t}function Hc(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=Zt.getProtocol(t.code);if(r==null)throw new lt(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function rl(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:No(t,r)}var nl=Symbol.for("nodejs.util.inspect.custom"),vs=Symbol.for("@multiformats/multiaddr");function ol(e){if(e==null&&(e="/"),qc(e))return e.getComponents();if(e instanceof Uint8Array)return kc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),Vc(e);if(Array.isArray(e))return e;throw new lt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var xn=class e{[vs]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=ol(t),r.validate!==!1&&sl(this)}get bytes(){return this.#r==null&&(this.#r=Mc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=Hc(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new an(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return xt(this.bytes,t.bytes)}[nl](){return`Multiaddr(${this.toString()})`}};function sl(e){e.getComponents().forEach(t=>{let r=Zt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function qc(e){return!!e?.[vs]}function zc(e){return new xn(e)}var Z=e=>({match:t=>{let r=t[0];return r==null||r.code!==e||r.value!=null?!1:t.slice(1)}}),L=(e,t)=>({match:r=>{let n=r[0];return n?.code!==e||n.value==null||t!=null&&n.value!==t?!1:r.slice(1)}}),jc=e=>({match:t=>e.match(t)===!1?t:!1}),k=e=>({match:t=>{let r=e.match(t);return r===!1?t:r}}),pt=(...e)=>({match:t=>{let r;for(let n of e){let o=n.match(t);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),H=(...e)=>({match:t=>{for(let r of e){let n=r.match(t);if(n===!1)return!1;t=n}return t}});function $(...e){function t(o){if(o==null)return!1;let s=o.getComponents();for(let i of e){let c=i.match(s);if(c===!1)return!1;s=c}return s}function r(o){return t(o)!==!1}function n(o){let s=t(o);return s===!1?!1:s.length===0}return{matchers:e,matches:r,exactMatch:n}}var il=L(421),fy=$(il),wn=L(54),En=L(55),Sn=L(56),Bs=L(53),uy=$(wn,k(L(421))),ly=$(En,k(L(421))),dy=$(Sn,k(L(421))),hy=$(pt(Bs,Sn,wn,En),k(L(421))),Zc=H(L(4),k(L(43))),$c=H(k(L(42)),L(41),k(L(43))),_s=pt(Zc,$c),ke=pt(_s,Bs,wn,En,Sn),py=$(pt(_s,H(pt(Bs,Sn,wn,En),k(L(421))))),my=$(Zc),yy=$($c),by=$(_s),Ts=H(ke,L(6)),br=H(ke,L(273)),xy=$(H(Ts,k(L(421)))),gy=$(br),Is=H(br,Z(460),k(L(421))),vn=H(br,Z(461),k(L(421))),cl=pt(Is,vn),wy=$(Is),Ey=$(vn),As=pt(ke,Ts,br,Is,vn),Yc=pt(H(As,Z(477),k(L(421)))),Sy=$(Yc),Gc=pt(H(As,Z(478),k(L(421))),H(As,Z(448),k(L(449)),Z(477),k(L(421)))),vy=$(Gc),Wc=H(br,Z(280),k(L(466)),k(L(466)),k(L(421))),Ay=$(Wc),Xc=H(vn,Z(465),k(L(466)),k(L(466)),k(L(421))),By=$(Xc),gn=pt(Yc,Gc,H(Ts,k(L(421))),H(cl,k(L(421))),H(ke,k(L(421))),Wc,Xc,L(421)),Qc=$(gn),al=H(k(gn),Z(290),jc(Z(281)),k(L(421))),_y=$(al),fl=pt(H(gn,Z(290),Z(281),k(L(421))),H(gn,Z(281),k(L(421))),H(Z(281),k(L(421)))),Ty=$(fl),ul=H(ke,pt(H(L(6,"80")),H(L(6),Z(480)),Z(480)),k(L(481)),k(L(421))),Iy=$(ul),ll=H(ke,pt(H(L(6,"443")),H(L(6,"443"),Z(480)),H(L(6),Z(443)),H(L(6),Z(448),Z(480)),H(Z(448),Z(480)),Z(448),Z(443)),k(L(481)),k(L(421))),Cy=$(ll),dl=pt(H(L(777),k(L(421)))),Dy=$(dl),hl=pt(H(L(400),k(L(421)))),Oy=$(hl);var pl="bootstrap",ml=50,yl=1e3,Cs=class extends Sr{static tag="bootstrap";log;timer;list;timeout;components;_init;constructor(t,r={list:[]}){if(r.list==null||r.list.length===0)throw new Error("Bootstrap requires a list of peer addresses");super(),this.components=t,this.log=t.logger.forComponent("libp2p:bootstrap"),this.timeout=r.timeout??yl,this.list=r.list.map(n=>zc(n)).filter(n=>Qc.matches(n)?n.getComponents().findLast(s=>s.code===421)?.value==null?(this.log.error("invalid bootstrap multiaddr without peer id"),!1):!0:(this.log.error("invalid multiaddr %a",n),!1)).map(n=>({id:_c(n.getComponents().findLast(o=>o.code===421)?.value??""),multiaddrs:[n]})),this._init=r}[Rs]=this;[Symbol.toStringTag]="@libp2p/bootstrap";[Ls]=["@libp2p/peer-discovery"];isStarted(){return!!this.timer}start(){this.isStarted()||(this.log("Starting bootstrap node discovery, discovering peers after %s ms",this.timeout),this.timer=setTimeout(()=>{this._discoverBootstrapPeers().catch(t=>{this.log.error("failed to discover bootstrap peers - %e",t)})},this.timeout))}async _discoverBootstrapPeers(){if(this.timer!=null)for(let t of this.list){if(await this.components.peerStore.merge(t.id,{tags:{[this._init.tagName??pl]:{value:this._init.tagValue??ml,ttl:this._init.tagTTL}},multiaddrs:t.multiaddrs}),this.timer==null)return;this.safeDispatchEvent("peer",{detail:t}),this.components.connectionManager.openConnection(t.id).catch(r=>{this.log.error("could not dial bootstrap peer %p - %e",t.id,r)})}}stop(){this.timer!=null&&clearTimeout(this.timer),this.timer=void 0}};function bl(e){return t=>new Cs(t,e)}return na(xl);})();
|
|
2
|
+
"use strict";var Libp2PBootstrap=(()=>{var Yn=Object.defineProperty;var Sf=Object.getOwnPropertyDescriptor;var vf=Object.getOwnPropertyNames;var Af=Object.prototype.hasOwnProperty;var $=(e,t)=>{for(var r in t)Yn(e,r,{get:t[r],enumerable:!0})},Bf=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of vf(t))!Af.call(e,o)&&o!==r&&Yn(e,o,{get:()=>t[o],enumerable:!(n=Sf(t,o))||n.enumerable});return e};var Cf=e=>Bf(Yn({},"__esModule",{value:!0}),e);var Qh={};$(Qh,{bootstrap:()=>Xh});var It=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},kr=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Mr=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},Vr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var tr=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var _i=Symbol.for("@libp2p/peer-discovery");var Gn=Symbol.for("@libp2p/peer-id");function _f(e){return typeof e?.handleEvent=="function"}function Df(e){return(e!==!0&&e!==!1&&e?.once)??!1}var zr=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 o=Df(n);super.addEventListener(t,i=>{if(o){let a=this.#t.get(i.type);a!=null&&(a=a.filter(({callback:f})=>f!==r),this.#t.set(i.type,a))}_f(r)?r.handleEvent(i):r(i)},n);let s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:r,once:o})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#t.set(t,o))}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var Di=Symbol.for("@libp2p/service-capabilities");var to={};$(to,{base58btc:()=>rt,base58flickr:()=>Pf});var Ip=new Uint8Array(0);function Ii(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Pt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Ti(e){return new TextEncoder().encode(e)}function Oi(e){return new TextDecoder().decode(e)}function If(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,f=e.charAt(0),c=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function d(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var E=0,p=0,b=0,S=h.length;b!==S&&h[b]===0;)b++,E++;for(var v=(S-b)*u+1>>>0,D=new Uint8Array(v);b!==S;){for(var _=h[b],R=0,O=v-1;(_!==0||R<p)&&O!==-1;O--,R++)_+=256*D[O]>>>0,D[O]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");p=R,b++}for(var C=v-p;C!==v&&D[C]===0;)C++;for(var N=f.repeat(E);C<v;++C)N+=e.charAt(D[C]);return N}function g(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var E=0;if(h[E]!==" "){for(var p=0,b=0;h[E]===f;)p++,E++;for(var S=(h.length-E)*c+1>>>0,v=new Uint8Array(S);h[E];){var D=r[h.charCodeAt(E)];if(D===255)return;for(var _=0,R=S-1;(D!==0||_<b)&&R!==-1;R--,_++)D+=a*v[R]>>>0,v[R]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");b=_,E++}if(h[E]!==" "){for(var O=S-b;O!==S&&v[O]===0;)O++;for(var C=new Uint8Array(p+(S-O)),N=p;O!==S;)C[N++]=v[O++];return C}}}function m(h){var E=g(h);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:d,decodeUnsafe:g,decode:m}}var Tf=If,Of=Tf,Ui=Of;var Wn=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")}},Xn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ri(this,t)}},Qn=class{decoders;constructor(t){this.decoders=t}or(t){return Ri(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 Ri(e,t){return new Qn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Jn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Wn(t,r,n),this.decoder=new Xn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Se({name:e,prefix:t,encode:r,decode:n}){return new Jn(e,t,r,n)}function Zt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Ui(r,e);return Se({prefix:t,name:e,encode:n,decode:s=>Pt(o(s))})}function Lf(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,f=0;for(let c=0;c<o;++c){let u=t[e[c]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,i+=r,i>=8&&(i-=8,s[f++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Uf(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let f=0;f<e.length;++f)for(a=a<<8|e[f],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Rf(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function X({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=Rf(n);return Se({prefix:t,name:e,encode(s){return Uf(s,n,r)},decode(s){return Lf(s,o,r,e)}})}var rt=Zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Pf=Zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var eo={};$(eo,{base32:()=>Yt,base32hex:()=>kf,base32hexpad:()=>Vf,base32hexpadupper:()=>zf,base32hexupper:()=>Mf,base32pad:()=>Ff,base32padupper:()=>Kf,base32upper:()=>Nf,base32z:()=>Hf});var Yt=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Nf=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ff=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Kf=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),kf=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Mf=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Vf=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),zf=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Hf=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ro={};$(ro,{base36:()=>er,base36upper:()=>qf});var er=Zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),qf=Zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var jf=Fi,Pi=128,$f=127,Zf=~$f,Yf=Math.pow(2,31);function Fi(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Yf;)t[r++]=e&255|Pi,e/=128;for(;e&Zf;)t[r++]=e&255|Pi,e>>>=7;return t[r]=e|0,Fi.bytes=r-n+1,t}var Gf=no,Wf=128,Ni=127;function no(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw no.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Ni)<<o:(i&Ni)*Math.pow(2,o),o+=7}while(i>=Wf);return no.bytes=s-n,r}var Xf=Math.pow(2,7),Qf=Math.pow(2,14),Jf=Math.pow(2,21),tu=Math.pow(2,28),eu=Math.pow(2,35),ru=Math.pow(2,42),nu=Math.pow(2,49),ou=Math.pow(2,56),su=Math.pow(2,63),iu=function(e){return e<Xf?1:e<Qf?2:e<Jf?3:e<tu?4:e<eu?5:e<ru?6:e<nu?7:e<ou?8:e<su?9:10},au={encode:jf,decode:Gf,encodingLength:iu},cu=au,rr=cu;function nr(e,t=0){return[rr.decode(e,t),rr.decode.bytes]}function ve(e,t,r=0){return rr.encode(e,t,r),t}function Ae(e){return rr.encodingLength(e)}function Ce(e,t){let r=t.byteLength,n=Ae(e),o=n+Ae(r),s=new Uint8Array(o+r);return ve(e,s,0),ve(r,s,n),s.set(t,o),new Be(e,r,t,s)}function or(e){let t=Pt(e),[r,n]=nr(t),[o,s]=nr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Be(r,o,i,t)}function Ki(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ii(e.bytes,r.bytes)}}var Be=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function ki(e,t){let{bytes:r,version:n}=e;return n===0?uu(r,oo(e),t??rt.encoder):du(r,oo(e),t??Yt.encoder)}var Mi=new WeakMap;function oo(e){let t=Mi.get(e);if(t==null){let r=new Map;return Mi.set(e,r),r}return t}var ft=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==sr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==lu)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=Ce(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&&Ki(t.multihash,n.multihash)}toString(t){return ki(this,t)}toJSON(){return{"/":ki(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??Vi(n,o,s.bytes))}else if(r[hu]===!0){let{version:n,multihash:o,code:s}=r,i=or(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==sr)throw new Error(`Version 0 CID must use dag-pb (code: ${sr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Vi(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,sr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Pt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Be(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[d,g]=nr(t.subarray(r));return r+=g,d},o=n(),s=sr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),f=n(),c=r+f,u=c-i;return{version:o,codec:s,multihashCode:a,digestSize:f,multihashSize:u,size:c}}static parse(t,r){let[n,o]=fu(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return oo(s).set(n,t),s}};function fu(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 Yt.prefix:{let r=t??Yt;return[Yt.prefix,r.decode(e)]}case er.prefix:{let r=t??er;return[er.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 uu(e,t,r){let{prefix:n}=r;if(n!==rt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function du(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var sr=112,lu=18;function Vi(e,t,r){let n=Ae(e),o=n+Ae(t),s=new Uint8Array(o+r.byteLength);return ve(e,s,0),ve(t,s,n),s.set(r,o),s}var hu=Symbol.for("@ipld/js-cid/CID");var so={};$(so,{identity:()=>St});var zi=0,pu="identity",Hi=Pt;function mu(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 Ce(zi,Hi(e))}var St={code:zi,name:pu,encode:Hi,digest:mu};function Nt(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 bu(e){return e.buffer instanceof ArrayBuffer}function De(e){return bu(e)?e:e.slice()}async function qi(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,De(t),De(r.subarray()));return n?.signal?.throwIfAborted(),s}function Ft(e=0){return new Uint8Array(e)}function ir(e=0){return new Uint8Array(e)}function io(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ir(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}function ji(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}var Zi=Symbol.for("@achingbrain/uint8arraylist");function $i(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function qr(e){return!!e?.[Zi]}var xt=class e{bufs;length;[Zi]=!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(qr(n)){r+=n.byteLength;for(let o of n.bufs)this.bufs.push(o)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=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(qr(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=$i(this.bufs,t);return r.buf[r.index]}set(t,r){let n=$i(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(qr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return io(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:io(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=n,s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,f=a+i.byteLength;if(o=f,t>=f)continue;let c=t>=a&&t<f,u=r>a&&r<=f;if(c&&u){if(t===a&&r===f){n.push(i);break}let d=t-a;n.push(i.subarray(d,d+(r-t)));break}if(c){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(u){if(r===f){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!qr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let d=0;d<s;d++)i[d]=-1;for(let d=0;d<o;d++)i[n[d]]=d;let a=i,f=this.byteLength-n.byteLength,c=n.byteLength-1,u;for(let d=r;d<=f;d+=u){u=0;for(let g=c;g>=0;g--){let m=this.get(d+g);if(n[g]!==m){u=Math.max(1,g-a[m]);break}}if(u===0)return d}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=ir(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Ft(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Ft(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Ft(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=ir(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Ft(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Ft(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Ft(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Ft(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Ft(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!ji(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var lo={};$(lo,{base10:()=>Au});var c0=new Uint8Array(0);function Yi(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Kt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return ae(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return ae(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function Gi(e){return new TextEncoder().encode(e)}function Wi(e){return new TextDecoder().decode(e)}function yu(e){return e?.buffer instanceof ArrayBuffer}function ae(e){return yu(e)?e:e.slice()}function xu(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,f=e.charAt(0),c=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function d(h){if(h instanceof Uint8Array||(ArrayBuffer.isView(h)?h=new Uint8Array(h.buffer,h.byteOffset,h.byteLength):Array.isArray(h)&&(h=Uint8Array.from(h))),!(h instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(h.length===0)return"";for(var E=0,p=0,b=0,S=h.length;b!==S&&h[b]===0;)b++,E++;for(var v=(S-b)*u+1>>>0,D=new Uint8Array(v);b!==S;){for(var _=h[b],R=0,O=v-1;(_!==0||R<p)&&O!==-1;O--,R++)_+=256*D[O]>>>0,D[O]=_%a>>>0,_=_/a>>>0;if(_!==0)throw new Error("Non-zero carry");p=R,b++}for(var C=v-p;C!==v&&D[C]===0;)C++;for(var N=f.repeat(E);C<v;++C)N+=e.charAt(D[C]);return N}function g(h){if(typeof h!="string")throw new TypeError("Expected String");if(h.length===0)return new Uint8Array;var E=0;if(h[E]!==" "){for(var p=0,b=0;h[E]===f;)p++,E++;for(var S=(h.length-E)*c+1>>>0,v=new Uint8Array(S);h[E];){var D=r[h.charCodeAt(E)];if(D===255)return;for(var _=0,R=S-1;(D!==0||_<b)&&R!==-1;R--,_++)D+=a*v[R]>>>0,v[R]=D%256>>>0,D=D/256>>>0;if(D!==0)throw new Error("Non-zero carry");b=_,E++}if(h[E]!==" "){for(var O=S-b;O!==S&&v[O]===0;)O++;for(var C=new Uint8Array(p+(S-O)),N=p;O!==S;)C[N++]=v[O++];return C}}}function m(h){var E=g(h);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:d,decodeUnsafe:g,decode:m}}var gu=xu,wu=gu,Qi=wu;var ao=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")}},co=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Ji(this,t)}},fo=class{decoders;constructor(t){this.decoders=t}or(t){return Ji(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 Ji(e,t){return new fo({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var uo=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new ao(t,r,n),this.decoder=new co(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ie({name:e,prefix:t,encode:r,decode:n}){return new uo(e,t,r,n)}function Gt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Qi(r,e);return Ie({prefix:t,name:e,encode:n,decode:s=>Kt(o(s))})}function Eu(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,f=0;for(let c=0;c<o;++c){let u=t[e[c]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|u,i+=r,i>=8&&(i-=8,s[f++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Su(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let f=0;f<e.length;++f)for(a=a<<8|e[f],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function vu(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function Q({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=vu(n);return Ie({prefix:t,name:e,encode(s){return Su(s,n,r)},decode(s){return Eu(s,o,r,e)}})}var Au=Gt({prefix:"9",name:"base10",alphabet:"0123456789"});var ho={};$(ho,{base16:()=>Bu,base16upper:()=>Cu});var Bu=Q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Cu=Q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var po={};$(po,{base2:()=>_u});var _u=Q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var mo={};$(mo,{base256emoji:()=>Lu});var ta=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}"),Du=ta.reduce((e,t,r)=>(e[r]=t,e),[]),Iu=ta.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Tu(e){return e.reduce((t,r)=>(t+=Du[r],t),"")}function Ou(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Iu[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Lu=Ie({prefix:"\u{1F680}",name:"base256emoji",encode:Tu,decode:Ou});var bo={};$(bo,{base32:()=>Te,base32hex:()=>Nu,base32hexpad:()=>Ku,base32hexpadupper:()=>ku,base32hexupper:()=>Fu,base32pad:()=>Ru,base32padupper:()=>Pu,base32upper:()=>Uu,base32z:()=>Mu});var Te=Q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Uu=Q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Ru=Q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Pu=Q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Nu=Q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Fu=Q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ku=Q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ku=Q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Mu=Q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var yo={};$(yo,{base36:()=>ar,base36upper:()=>Vu});var ar=Gt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Vu=Gt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var xo={};$(xo,{base58btc:()=>Tt,base58flickr:()=>zu});var Tt=Gt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),zu=Gt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var go={};$(go,{base64:()=>Hu,base64pad:()=>qu,base64url:()=>ju,base64urlpad:()=>$u});var Hu=Q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),qu=Q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),ju=Q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),$u=Q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var wo={};$(wo,{base8:()=>Zu});var Zu=Q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Eo={};$(Eo,{identity:()=>Yu});var Yu=Ie({prefix:"\0",name:"identity",encode:e=>Wi(e),decode:e=>Gi(e)});var A0=new TextEncoder,B0=new TextDecoder;var vo={};$(vo,{identity:()=>yd});var Xu=na,ea=128,Qu=127,Ju=~Qu,td=Math.pow(2,31);function na(e,t,r){t=t||[],r=r||0;for(var n=r;e>=td;)t[r++]=e&255|ea,e/=128;for(;e&Ju;)t[r++]=e&255|ea,e>>>=7;return t[r]=e|0,na.bytes=r-n+1,t}var ed=So,rd=128,ra=127;function So(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw So.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&ra)<<o:(i&ra)*Math.pow(2,o),o+=7}while(i>=rd);return So.bytes=s-n,r}var nd=Math.pow(2,7),od=Math.pow(2,14),sd=Math.pow(2,21),id=Math.pow(2,28),ad=Math.pow(2,35),cd=Math.pow(2,42),fd=Math.pow(2,49),ud=Math.pow(2,56),dd=Math.pow(2,63),ld=function(e){return e<nd?1:e<od?2:e<sd?3:e<id?4:e<ad?5:e<cd?6:e<fd?7:e<ud?8:e<dd?9:10},hd={encode:Xu,decode:ed,encodingLength:ld},pd=hd,cr=pd;function fr(e,t=0){return[cr.decode(e,t),cr.decode.bytes]}function Oe(e,t,r=0){return cr.encode(e,t,r),t}function Le(e){return cr.encodingLength(e)}function Re(e,t){let r=t.byteLength,n=Le(e),o=n+Le(r),s=new Uint8Array(o+r);return Oe(e,s,0),Oe(r,s,n),s.set(t,o),new Ue(e,r,t,s)}function oa(e){let t=Kt(e),[r,n]=fr(t),[o,s]=fr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ue(r,o,i,t)}function sa(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Yi(e.bytes,r.bytes)}}var Ue=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=ae(n),this.bytes=ae(o)}};var ia=0,md="identity",aa=Kt;function bd(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 Re(ia,aa(e))}var yd={code:ia,name:md,encode:aa,digest:bd};var Co={};$(Co,{sha256:()=>gd,sha512:()=>wd});var xd=20;function Bo({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Ao(e,t,r,n,o)}var Ao=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??xd,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?ca(n,this.code,r?.truncate):n.then(o=>ca(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ca(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 Re(t,e)}function ua(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var gd=Bo({name:"sha2-256",code:18,encode:ua("SHA-256")}),wd=Bo({name:"sha2-512",code:19,encode:ua("SHA-512")});function da(e,t){let{bytes:r,version:n}=e;return n===0?Sd(r,_o(e),t??Tt.encoder):vd(r,_o(e),t??Te.encoder)}var la=new WeakMap;function _o(e){let t=la.get(e);if(t==null){let r=new Map;return la.set(e,r),r}return t}var $r=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=ae(o),this["/"]=this.bytes}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==dr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ad)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=Re(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&&sa(t.multihash,n.multihash)}toString(t){return da(this,t)}toJSON(){return{"/":da(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??ha(n,o,s.bytes))}else if(r[Bd]===!0){let{version:n,multihash:o,code:s}=r,i=oa(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==dr)throw new Error(`Version 0 CID must use dag-pb (code: ${dr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=ha(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,dr,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Kt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Ue(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[d,g]=fr(t.subarray(r));return r+=g,d},o=n(),s=dr;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),f=n(),c=r+f,u=c-i;return{version:o,codec:s,multihashCode:a,digestSize:f,multihashSize:u,size:c}}static parse(t,r){let[n,o]=Ed(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return _o(s).set(n,t),s}};function Ed(e,t){switch(e[0]){case"Q":{let r=t??Tt;return[Tt.prefix,r.decode(`${Tt.prefix}${e}`)]}case Tt.prefix:{let r=t??Tt;return[Tt.prefix,r.decode(e)]}case Te.prefix:{let r=t??Te;return[Te.prefix,r.decode(e)]}case ar.prefix:{let r=t??ar;return[ar.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 Sd(e,t,r){let{prefix:n}=r;if(n!==Tt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function vd(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var dr=112,Ad=18;function ha(e,t,r){let n=Le(e),o=n+Le(t),s=new Uint8Array(o+r.byteLength);return Oe(e,s,0),Oe(t,s,n),s.set(r,o),s}var Bd=Symbol.for("@ipld/js-cid/CID");var Do={...Eo,...po,...wo,...lo,...ho,...bo,...yo,...xo,...go,...mo},Z0={...Co,...vo};function Io(e=0){return new Uint8Array(e)}function ma(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var pa=ma("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),To=ma("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=Io(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Cd={utf8:pa,"utf-8":pa,hex:Do.base16,latin1:To,ascii:To,binary:To,...Do},Zr=Cd;function Pe(e,t="utf8"){let r=Zr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function gt(e,t="utf8"){let r=Zr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var _d=parseInt("11111",2),Oo=parseInt("10000000",2),Dd=parseInt("01111111",2),ba={0:lr,1:lr,2:Id,3:Ld,4:Ud,5:Od,6:Td,16:lr,22:lr,48:lr};function Lo(e,t={offset:0}){let r=e[t.offset]&_d;if(t.offset++,ba[r]!=null)return ba[r](e,t);throw new Error("No decoder for tag "+r)}function hr(e,t){let r=0;if((e[t.offset]&Oo)===Oo){let n=e[t.offset]&Dd,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function lr(e,t){hr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Lo(e,t);if(n===null)break;r.push(n)}return r}function Id(e,t){let r=hr(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Td(e,t){let r=hr(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,f=[];for(;t.offset<n;){let c=e[t.offset];if(t.offset++,f.push(c&127),c<128){f.reverse();let u=0;for(let d=0;d<f.length;d++)u+=f[d]<<d*7;a+=`.${u}`,f=[]}}return a}function Od(e,t){return t.offset++,null}function Ld(e,t){let r=hr(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Ud(e,t){let r=hr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Rd(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new xt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Uo(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Rd(e.byteLength);return new xt(Uint8Array.from([t.byteLength|Oo]),t)}function ya(e){let t=new xt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new xt(Uint8Array.from([2]),Uo(t),t)}function xa(e){let t=Uint8Array.from([0]),r=new xt(t,e);return new xt(Uint8Array.from([3]),Uo(r),r)}function Yr(e,t=48){let r=new xt;for(let n of e)r.append(n);return new xt(Uint8Array.from([t]),Uo(r),r)}var Pd=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Nd=Uint8Array.from([6,5,43,129,4,0,34]),Fd=Uint8Array.from([6,5,43,129,4,0,35]),Kd={ext:!0,kty:"EC",crv:"P-256"},kd={ext:!0,kty:"EC",crv:"P-384"},Md={ext:!0,kty:"EC",crv:"P-521"},Ro=32,Po=48,No=66;function ga(e){let t=Lo(e);return wa(t)}function wa(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Ro*2+1)return n=gt(t.subarray(r,r+Ro),"base64url"),o=gt(t.subarray(r+Ro),"base64url"),new Ne({...Kd,key_ops:["verify"],x:n,y:o});if(t.byteLength===Po*2+1)return n=gt(t.subarray(r,r+Po),"base64url"),o=gt(t.subarray(r+Po),"base64url"),new Ne({...kd,key_ops:["verify"],x:n,y:o});if(t.byteLength===No*2+1)return n=gt(t.subarray(r,r+No),"base64url"),o=gt(t.subarray(r+No),"base64url"),new Ne({...Md,key_ops:["verify"],x:n,y:o});throw new It(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ea(e){return Yr([ya(Uint8Array.from([1])),Yr([Vd(e.crv)],160),Yr([xa(new xt(Uint8Array.from([4]),Pe(e.x??"","base64url"),Pe(e.y??"","base64url")))],161)]).subarray()}function Vd(e){if(e==="P-256")return Pd;if(e==="P-384")return Nd;if(e==="P-521")return Fd;throw new It(`Invalid curve ${e}`)}var Ne=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ea(this.jwk)),this._raw}toMultihash(){return St.digest(Fe(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Nt(this.raw,t.raw)}async verify(t,r,n){return qi(this.jwk,r,t,n)}};function Fo(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function Wt(e,t=""){if(typeof e!="number"){let r=t&&`"${t}" `;throw new TypeError(`${r}expected number, got ${typeof e}`)}if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new RangeError(`${r}expected integer >= 0, got ${e}`)}}function wt(e,t,r=""){let n=Fo(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,a=s?` of length ${t}`:"",f=n?`length=${o}`:`type=${typeof e}`,c=i+"expected Uint8Array"+a+", got "+f;throw n?new RangeError(c):new TypeError(c)}return e}function Gr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Wt(e.outputLen),Wt(e.blockLen),e.outputLen<1)throw new Error('"outputLen" must be >= 1');if(e.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Ke(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function Wr(e,t){wt(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function Mt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Xr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function vt(e,t){return e<<32-t|e>>>t}var va=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",zd=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Qr(e){if(wt(e),va)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=zd[e[r]];return t}var kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function Sa(e){if(e>=kt._0&&e<=kt._9)return e-kt._0;if(e>=kt.A&&e<=kt.F)return e-(kt.A-10);if(e>=kt.a&&e<=kt.f)return e-(kt.a-10)}function pr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(va)try{return Uint8Array.fromHex(e)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}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 o=0,s=0;o<r;o++,s+=2){let i=Sa(e.charCodeAt(s)),a=Sa(e.charCodeAt(s+1));if(i===void 0||a===void 0){let f=e[s]+e[s+1];throw new RangeError('hex string expected, got non-hex character "'+f+'" at index '+s)}n[o]=i*16+a}return n}function Ko(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];wt(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}function ko(e,t={}){let r=(o,s)=>e(s).update(o).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=o=>e(o),Object.assign(r,t),Object.freeze(r)}function Aa(e=32){Wt(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 Mo=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function Ba(e,t,r){return e&t^~e&r}function Ca(e,t,r){return e&t^e&r^t&r}var mr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,o){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Xr(this.buffer)}update(t){Ke(this),wt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let f=Xr(t);for(;o<=s-i;i+=o)this.process(f,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ke(this),Wr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Mt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let d=i;d<o;d++)r[d]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=Xr(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let c=f/4,u=this.get();if(c>u.length)throw new Error("_sha2: outputLen bigger than state");for(let d=0;d<c;d++)a.setUint32(4*d,u[d],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Vt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ut=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Jr=BigInt(4294967295),_a=BigInt(32);function Hd(e,t=!1){return t?{h:Number(e&Jr),l:Number(e>>_a&Jr)}:{h:Number(e>>_a&Jr)|0,l:Number(e&Jr)|0}}function Da(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Hd(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Vo=(e,t,r)=>e>>>r,zo=(e,t,r)=>e<<32-r|t>>>r,ce=(e,t,r)=>e>>>r|t<<32-r,fe=(e,t,r)=>e<<32-r|t>>>r,br=(e,t,r)=>e<<64-r|t>>>r-32,yr=(e,t,r)=>e>>>r-32|t<<64-r;function Ot(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Ia=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Ta=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Oa=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),La=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Ua=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Ra=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var jd=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]),Xt=new Uint32Array(64),Ho=class extends mr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:f}=this;return[t,r,n,o,s,i,a,f]}set(t,r,n,o,s,i,a,f){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=f|0}process(t,r){for(let d=0;d<16;d++,r+=4)Xt[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){let g=Xt[d-15],m=Xt[d-2],h=vt(g,7)^vt(g,18)^g>>>3,E=vt(m,17)^vt(m,19)^m>>>10;Xt[d]=E+Xt[d-7]+h+Xt[d-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:f,G:c,H:u}=this;for(let d=0;d<64;d++){let g=vt(a,6)^vt(a,11)^vt(a,25),m=u+g+Ba(a,f,c)+jd[d]+Xt[d]|0,E=(vt(n,2)^vt(n,13)^vt(n,22))+Ca(n,o,s)|0;u=c,c=f,f=a,a=i+m|0,i=s,s=o,o=n,n=m+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,f=f+this.F|0,c=c+this.G|0,u=u+this.H|0,this.set(n,o,s,i,a,f,c,u)}roundClean(){Mt(Xt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Mt(this.buffer)}},qo=class extends Ho{A=Vt[0]|0;B=Vt[1]|0;C=Vt[2]|0;D=Vt[3]|0;E=Vt[4]|0;F=Vt[5]|0;G=Vt[6]|0;H=Vt[7]|0;constructor(){super(32)}};var Pa=Da(["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))),$d=Pa[0],Zd=Pa[1],Qt=new Uint32Array(80),Jt=new Uint32Array(80),jo=class extends mr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:f,Eh:c,El:u,Fh:d,Fl:g,Gh:m,Gl:h,Hh:E,Hl:p}=this;return[t,r,n,o,s,i,a,f,c,u,d,g,m,h,E,p]}set(t,r,n,o,s,i,a,f,c,u,d,g,m,h,E,p){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=f|0,this.Eh=c|0,this.El=u|0,this.Fh=d|0,this.Fl=g|0,this.Gh=m|0,this.Gl=h|0,this.Hh=E|0,this.Hl=p|0}process(t,r){for(let v=0;v<16;v++,r+=4)Qt[v]=t.getUint32(r),Jt[v]=t.getUint32(r+=4);for(let v=16;v<80;v++){let D=Qt[v-15]|0,_=Jt[v-15]|0,R=ce(D,_,1)^ce(D,_,8)^Vo(D,_,7),O=fe(D,_,1)^fe(D,_,8)^zo(D,_,7),C=Qt[v-2]|0,N=Jt[v-2]|0,j=ce(C,N,19)^br(C,N,61)^Vo(C,N,6),F=fe(C,N,19)^yr(C,N,61)^zo(C,N,6),l=Oa(O,F,Jt[v-7],Jt[v-16]),y=La(l,R,j,Qt[v-7],Qt[v-16]);Qt[v]=y|0,Jt[v]=l|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:f,Dh:c,Dl:u,Eh:d,El:g,Fh:m,Fl:h,Gh:E,Gl:p,Hh:b,Hl:S}=this;for(let v=0;v<80;v++){let D=ce(d,g,14)^ce(d,g,18)^br(d,g,41),_=fe(d,g,14)^fe(d,g,18)^yr(d,g,41),R=d&m^~d&E,O=g&h^~g&p,C=Ua(S,_,O,Zd[v],Jt[v]),N=Ra(C,b,D,R,$d[v],Qt[v]),j=C|0,F=ce(n,o,28)^br(n,o,34)^br(n,o,39),l=fe(n,o,28)^yr(n,o,34)^yr(n,o,39),y=n&s^n&a^s&a,A=o&i^o&f^i&f;b=E|0,S=p|0,E=m|0,p=h|0,m=d|0,h=g|0,{h:d,l:g}=Ot(c|0,u|0,N|0,j|0),c=a|0,u=f|0,a=s|0,f=i|0,s=n|0,i=o|0;let w=Ia(j,l,A);n=Ta(w,N,F,y),o=w|0}({h:n,l:o}=Ot(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ot(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:f}=Ot(this.Ch|0,this.Cl|0,a|0,f|0),{h:c,l:u}=Ot(this.Dh|0,this.Dl|0,c|0,u|0),{h:d,l:g}=Ot(this.Eh|0,this.El|0,d|0,g|0),{h:m,l:h}=Ot(this.Fh|0,this.Fl|0,m|0,h|0),{h:E,l:p}=Ot(this.Gh|0,this.Gl|0,E|0,p|0),{h:b,l:S}=Ot(this.Hh|0,this.Hl|0,b|0,S|0),this.set(n,o,s,i,a,f,c,u,d,g,m,h,E,p,b,S)}roundClean(){Mt(Qt,Jt)}destroy(){this.destroyed=!0,Mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},$o=class extends jo{Ah=ut[0]|0;Al=ut[1]|0;Bh=ut[2]|0;Bl=ut[3]|0;Ch=ut[4]|0;Cl=ut[5]|0;Dh=ut[6]|0;Dl=ut[7]|0;Eh=ut[8]|0;El=ut[9]|0;Fh=ut[10]|0;Fl=ut[11]|0;Gh=ut[12]|0;Gl=ut[13]|0;Hh=ut[14]|0;Hl=ut[15]|0;constructor(){super(64)}};var Na=ko(()=>new qo,Mo(1));var tn=ko(()=>new $o,Mo(3));var V=(e,t,r)=>wt(e,t,r),Yo=Wt,ke=Qr,ot=(...e)=>Ko(...e),Me=e=>pr(e),ue=Fo,xr=e=>Aa(e),rn=BigInt(0),Zo=BigInt(1);function At(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function nn(e){if(typeof e=="bigint"){if(!en(e))throw new RangeError("positive bigint expected, got "+e)}else Yo(e);return e}function Bt(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 gr(e){let t=nn(e).toString(16);return t.length&1?"0"+t:t}function Fa(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?rn:BigInt("0x"+e)}function de(e){return Fa(Qr(e))}function Lt(e){return Fa(Qr(wr(wt(e)).reverse()))}function on(e,t){if(Wt(t),t===0)throw new RangeError("zero length");e=nn(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return pr(r.padStart(t*2,"0"))}function Go(e,t){return on(e,t).reverse()}function Ka(e,t){if(e=V(e),t=V(t),e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function wr(e){return Uint8Array.from(V(e))}function sn(e){if(typeof e!="string")throw new TypeError("ascii string expected, got "+typeof e);return Uint8Array.from(e,(t,r)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${e[r]}" with code ${n} at position ${r}`);return n})}var en=e=>typeof e=="bigint"&&rn<=e;function Yd(e,t,r){return en(e)&&en(t)&&en(r)&&t<=e&&e<r}function Ve(e,t,r,n){if(!Yd(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function ze(e){if(e<rn)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>rn;e>>=Zo,t+=1);return t}var Er=e=>(Zo<<BigInt(e))-Zo;function ka(e,t,r){if(Wt(e,"hashLen"),Wt(t,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=p=>new Uint8Array(p),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,f=n(e),c=n(e),u=0,d=()=>{f.fill(1),c.fill(0),u=0},g=(...p)=>r(c,ot(f,...p)),m=(p=o)=>{c=g(s,p),f=g(),p.length!==0&&(c=g(i,p),f=g())},h=()=>{if(u++>=a)throw new Error("drbg: tried max amount of iterations");let p=0,b=[];for(;p<t;){f=g();let S=f.slice();b.push(S),p+=f.length}return ot(...b)};return(p,b)=>{d(),m(p);let S;for(;(S=b(h()))===void 0;)m();return d(),S}}function Ct(e,t={},r={}){if(Object.prototype.toString.call(e)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,a){if(!a&&i!=="function"&&!Object.hasOwn(e,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let f=e[s];if(a&&f===void 0)return;let c=typeof f;if(c!==i||f===null)throw new TypeError(`param "${s}" is invalid: expected ${i}, got ${c}`)}let o=(s,i)=>Object.entries(s).forEach(([a,f])=>n(a,f,i));o(t,!1),o(r,!0)}var Wo=()=>{throw new Error("not implemented")};var dt=BigInt(0),J=BigInt(1),le=BigInt(2),Ha=BigInt(3),qa=BigInt(4),ja=BigInt(5),Gd=BigInt(7),$a=BigInt(8),Wd=BigInt(9),Za=BigInt(16);function et(e,t){if(t<=dt)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=dt?r:t+r}function G(e,t,r){if(t<dt)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >dt;)n*=n,n%=r;return n}function Ma(e,t){if(e===dt)throw new Error("invert: expected non-zero number");if(t<=dt)throw new Error("invert: expected positive modulus, got "+t);let r=et(e,t),n=t,o=dt,s=J,i=J,a=dt;for(;r!==dt;){let c=n/r,u=n-r*c,d=o-i*c,g=s-a*c;n=r,r=u,o=i,s=a,i=d,a=g}if(n!==J)throw new Error("invert: does not exist");return et(o,t)}function Xo(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function Ya(e,t){let r=e,n=(r.ORDER+J)/qa,o=r.pow(t,n);return Xo(r,o,t),o}function Xd(e,t){let r=e,n=(r.ORDER-ja)/$a,o=r.mul(t,le),s=r.pow(o,n),i=r.mul(t,s),a=r.mul(r.mul(i,le),s),f=r.mul(i,r.sub(a,r.ONE));return Xo(r,f,t),f}function Qd(e){let t=He(e),r=Ga(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Gd)/Za;return((a,f)=>{let c=a,u=c.pow(f,i),d=c.mul(u,n),g=c.mul(u,o),m=c.mul(u,s),h=c.eql(c.sqr(d),f),E=c.eql(c.sqr(g),f);u=c.cmov(u,d,h),d=c.cmov(m,g,E);let p=c.eql(c.sqr(d),f),b=c.cmov(u,d,p);return Xo(c,b,f),b})}function Ga(e){if(e<Ha)throw new Error("sqrt is not defined for small field");let t=e-J,r=0;for(;t%le===dt;)t/=le,r++;let n=le,o=He(e);for(;Va(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ya;let s=o.pow(n,t),i=(t+J)/le;return function(f,c){let u=f;if(u.is0(c))return c;if(Va(u,c)!==1)throw new Error("Cannot find square root");let d=r,g=u.mul(u.ONE,s),m=u.pow(c,t),h=u.pow(c,i);for(;!u.eql(m,u.ONE);){if(u.is0(m))return u.ZERO;let E=1,p=u.sqr(m);for(;!u.eql(p,u.ONE);)if(E++,p=u.sqr(p),E===d)throw new Error("Cannot find square root");let b=J<<BigInt(d-E-1),S=u.pow(g,b);d=E,g=u.sqr(S),m=u.mul(m,g),h=u.mul(h,S)}return h}}function Jd(e){return e%qa===Ha?Ya:e%$a===ja?Xd:e%Za===Wd?Qd(e):Ga(e)}var zt=(e,t)=>(et(e,t)&J)===J,tl=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Qo(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=tl.reduce((n,o)=>(n[o]="function",n),t);if(Ct(e,r),Bt(e.BYTES,"BYTES"),Bt(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=J)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function el(e,t,r){let n=e;if(r<dt)throw new Error("invalid exponent, negatives unsupported");if(r===dt)return n.ONE;if(r===J)return t;let o=n.ONE,s=t;for(;r>dt;)r&J&&(o=n.mul(o,s)),s=n.sqr(s),r>>=J;return o}function Sr(e,t,r=!1){let n=e,o=new Array(t.length).fill(r?n.ZERO:void 0),s=t.reduce((a,f,c)=>n.is0(f)?a:(o[c]=a,n.mul(a,f)),n.ONE),i=n.inv(s);return t.reduceRight((a,f,c)=>n.is0(f)?a:(o[c]=n.mul(a,o[c]),n.mul(a,f)),i),o}function Va(e,t){let r=e,n=(r.ORDER-J)/le,o=r.pow(t,n),s=r.eql(o,r.ONE),i=r.eql(o,r.ZERO),a=r.eql(o,r.neg(r.ONE));if(!s&&!i&&!a)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function rl(e,t){if(t!==void 0&&Yo(t),e<=dt)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=ze(e);if(t!==void 0&&t<r)throw new Error(`invalid n length: expected bit length (${r}) >= n.length (${t})`);let n=t!==void 0?t:r,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var za=new WeakMap,an=class{ORDER;BITS;BYTES;isLE;ZERO=dt;ONE=J;_lengths;_mod;constructor(t,r={}){if(t<=J)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:o,nByteLength:s}=rl(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,Object.freeze(this)}create(t){return et(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return dt<=t&&t<this.ORDER}is0(t){return t===dt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&J)===J}neg(t){return et(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return et(t*t,this.ORDER)}add(t,r){return et(t+r,this.ORDER)}sub(t,r){return et(t-r,this.ORDER)}mul(t,r){return et(t*r,this.ORDER)}pow(t,r){return el(this,t,r)}div(t,r){return et(t*Ma(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 Ma(t,this.ORDER)}sqrt(t){let r=za.get(this);return r||za.set(this,r=Jd(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?Go(t,this.BYTES):on(t,this.BYTES)}fromBytes(t,r=!1){V(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(t.length<1||!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let c=new Uint8Array(o);c.set(t,s?0:c.length-t.length),t=c}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let f=s?Lt(t):de(t);if(a&&(f=et(f,i)),!r&&!this.isValid(f))throw new Error("invalid field element: outside of range 0..ORDER");return f}invertBatch(t){return Sr(this,t)}cmov(t,r,n){return At(n,"condition"),n?r:t}};Object.freeze(an.prototype);function He(e,t={}){return new an(e,t)}function Wa(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=J)throw new Error("field order must be greater than 1");let t=ze(e-J);return Math.ceil(t/8)}function Jo(e){let t=Wa(e);return t+Math.ceil(t/2)}function ts(e,t,r=!1){V(e);let n=e.length,o=Wa(t),s=Math.max(Jo(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Lt(e):de(e),a=et(i,t-J)+J;return r?Go(a,o):on(a,o)}var qe=BigInt(0),he=BigInt(1);function vr(e,t){let r=t.negate();return e?r:t}function pe(e,t){let r=Sr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function tc(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function es(e,t){tc(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Er(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Xa(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),f=e>>i;a>n&&(a-=s,f+=he);let c=t*n,u=c+Math.abs(a)-1,d=a===0,g=a<0,m=t%2!==0;return{nextN:f,offset:u,isZero:d,isNeg:g,isNegF:m,offsetF:c}}var rs=new WeakMap,ec=new WeakMap;function ns(e){return ec.get(e)||1}function Qa(e){if(e!==qe)throw new Error("invalid wNAF")}var je=class{BASE;ZERO;Fn;bits;constructor(t,r){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=r}_unsafeLadder(t,r,n=this.ZERO){let o=t;for(;r>qe;)r&he&&(n=n.add(o)),o=o.double(),r>>=he;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=es(r,this.bits),s=[],i=t,a=i;for(let f=0;f<n;f++){a=i,s.push(a);for(let c=1;c<o;c++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,r,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=es(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:f,offset:c,isZero:u,isNeg:d,isNegF:g,offsetF:m}=Xa(n,a,i);n=f,u?s=s.add(vr(g,r[m])):o=o.add(vr(d,r[c]))}return Qa(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=es(t,this.bits);for(let i=0;i<s.windows&&n!==qe;i++){let{nextN:a,offset:f,isZero:c,isNeg:u}=Xa(n,i,s);if(n=a,!c){let d=r[f];o=o.add(u?d.negate():d)}}return Qa(n),o}getPrecomputes(t,r,n){let o=rs.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),rs.set(r,o))),o}cached(t,r,n){let o=ns(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=ns(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){tc(r,this.bits),ec.set(t,r),rs.delete(t)}hasCache(t){return ns(t)!==1}};function rc(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>qe||n>qe;)r&he&&(s=s.add(o)),n&he&&(i=i.add(o)),o=o.double(),r>>=he,n>>=he;return{p1:s,p2:i}}function Ja(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Qo(t),t}else return He(e,{isLE:r})}function cn(e,t,r={},n){if(n===void 0&&(n=e==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let f of["p","n","h"]){let c=t[f];if(!(typeof c=="bigint"&&c>qe))throw new Error(`CURVE.${f} must be positive bigint`)}let o=Ja(t.p,r.Fp,n),s=Ja(t.n,r.Fn,n),a=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let f of a)if(!o.isValid(t[f]))throw new Error(`CURVE.${f} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function fn(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var te=BigInt(0),at=BigInt(1),os=BigInt(2),nl=BigInt(8);function ol(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.add(e.mul(t.a,o),s),a=e.add(e.ONE,e.mul(t.d,e.mul(o,s)));return e.eql(i,a)}function nc(e,t={}){let r=t,n=cn("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:a}=i;Ct(r,{},{uvRatio:"function"});let f=os<<BigInt(s.BYTES*8)-at,c=E=>o.create(E),u=r.uvRatio===void 0?(E,p)=>{try{return{isValid:!0,value:o.sqrt(o.div(E,p))}}catch{return{isValid:!1,value:te}}}:r.uvRatio;if(!ol(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function d(E,p,b=!1){let S=b?at:te;return Ve("coordinate "+E,p,S,f),p}function g(E){if(!(E instanceof m))throw new Error("EdwardsPoint expected")}class m{static BASE=new m(i.Gx,i.Gy,at,c(i.Gx*i.Gy));static ZERO=new m(te,at,at,te);static Fp=o;static Fn=s;X;Y;Z;T;constructor(p,b,S,v){this.X=d("x",p),this.Y=d("y",b),this.Z=d("z",S,!0),this.T=d("t",v),Object.freeze(this)}static CURVE(){return i}static fromAffine(p){if(p instanceof m)throw new Error("extended point not allowed");let{x:b,y:S}=p||{};return d("x",b),d("y",S),new m(b,S,at,c(b*S))}static fromBytes(p,b=!1){let S=o.BYTES,{a:v,d:D}=i;p=wr(V(p,S,"point")),At(b,"zip215");let _=wr(p),R=p[S-1];_[S-1]=R&-129;let O=Lt(_),C=b?f:o.ORDER;Ve("point.y",O,te,C);let N=c(O*O),j=c(N-at),F=c(D*N-v),{isValid:l,value:y}=u(j,F);if(!l)throw new Error("bad point: invalid y coordinate");let A=(y&at)===at,w=(R&128)!==0;if(!b&&y===te&&w)throw new Error("bad point: x=0 and x_0=1");return w!==A&&(y=c(-y)),m.fromAffine({x:y,y:O})}static fromHex(p,b=!1){return m.fromBytes(Me(p),b)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,b=!0){return h.createCache(this,p),b||this.multiply(os),this}assertValidity(){let p=this,{a:b,d:S}=i;if(p.is0())throw new Error("bad point: ZERO");let{X:v,Y:D,Z:_,T:R}=p,O=c(v*v),C=c(D*D),N=c(_*_),j=c(N*N),F=c(O*b),l=c(N*c(F+C)),y=c(j+c(S*c(O*C)));if(l!==y)throw new Error("bad point: equation left != right (1)");let A=c(v*D),w=c(_*R);if(A!==w)throw new Error("bad point: equation left != right (2)")}equals(p){g(p);let{X:b,Y:S,Z:v}=this,{X:D,Y:_,Z:R}=p,O=c(b*R),C=c(D*v),N=c(S*R),j=c(_*v);return O===C&&N===j}is0(){return this.equals(m.ZERO)}negate(){return new m(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:p}=i,{X:b,Y:S,Z:v}=this,D=c(b*b),_=c(S*S),R=c(os*c(v*v)),O=c(p*D),C=b+S,N=c(c(C*C)-D-_),j=O+_,F=j-R,l=O-_,y=c(N*F),A=c(j*l),w=c(N*l),x=c(F*j);return new m(y,A,x,w)}add(p){g(p);let{a:b,d:S}=i,{X:v,Y:D,Z:_,T:R}=this,{X:O,Y:C,Z:N,T:j}=p,F=c(v*O),l=c(D*C),y=c(R*S*j),A=c(_*N),w=c((v+D)*(O+C)-F-l),x=A-y,B=A+y,T=c(l-b*F),I=c(w*x),L=c(B*T),P=c(w*T),M=c(x*B);return new m(I,L,M,P)}subtract(p){return g(p),this.add(p.negate())}multiply(p){if(!s.isValidNot0(p))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:b,f:S}=h.cached(this,p,v=>pe(m,v));return pe(m,[b,S])[0]}multiplyUnsafe(p){if(!s.isValid(p))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return p===te?m.ZERO:this.is0()||p===at?this:h.unsafe(this,p,b=>pe(m,b))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return h.unsafe(this,i.n).is0()}toAffine(p){let b=this,S=p,{X:v,Y:D,Z:_}=b,R=b.is0();S==null&&(S=R?nl:o.inv(_));let O=c(v*S),C=c(D*S),N=o.mul(_,S);if(R)return{x:te,y:at};if(N!==at)throw new Error("invZ was invalid");return{x:O,y:C}}clearCofactor(){return a===at?this:this.multiplyUnsafe(a)}toBytes(){let{x:p,y:b}=this.toAffine(),S=o.toBytes(b);return S[S.length-1]|=p&at?128:0,S}toHex(){return ke(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let h=new je(m,s.BITS);return s.BITS>=8&&m.BASE.precompute(8),Object.freeze(m.prototype),Object.freeze(m),m}var un=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){Wo()}static fromHex(t){Wo()}get x(){return this.toAffine().x}get y(){return this.toAffine().y}clearCofactor(){return this}assertValidity(){this.ep.assertValidity()}toAffine(t){return this.ep.toAffine(t)}toHex(){return ke(this.toBytes())}toString(){return this.toHex()}isTorsionFree(){return!0}isSmallOrder(){return!1}add(t){return this.assertSame(t),this.init(this.ep.add(t.ep))}subtract(t){return this.assertSame(t),this.init(this.ep.subtract(t.ep))}multiply(t){return this.init(this.ep.multiply(t))}multiplyUnsafe(t){return this.init(this.ep.multiplyUnsafe(t))}double(){return this.init(this.ep.double())}negate(){return this.init(this.ep.negate())}precompute(t,r){return this.ep.precompute(t,r),this}};function oc(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;Ct(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:a,Fn:f}=e,c=n.outputLen,u=2*a.BYTES;if(c!==void 0&&(Bt(c,"hash.outputLen"),c!==u))throw new Error(`hash.outputLen must be ${u}, got ${c}`);let d=o.randomBytes===void 0?xr:o.randomBytes,g=o.adjustScalarBytes===void 0?l=>l:o.adjustScalarBytes,m=o.domain===void 0?(l,y,A)=>{if(At(A,"phflag"),y.length||A)throw new Error("Contexts/pre-hash are not supported");return l}:o.domain;function h(l){return f.create(Lt(l))}function E(l){let y=O.secretKey;V(l,O.secretKey,"secretKey");let A=V(n(l),2*y,"hashedSecretKey"),w=g(A.slice(0,y)),x=A.slice(y,2*y),B=h(w);return{head:w,prefix:x,scalar:B}}function p(l){let{head:y,prefix:A,scalar:w}=E(l),x=i.multiply(w),B=x.toBytes();return{head:y,prefix:A,scalar:w,point:x,pointBytes:B}}function b(l){return p(l).pointBytes}function S(l=Uint8Array.of(),...y){let A=ot(...y);return h(n(m(A,V(l,void 0,"context"),!!s)))}function v(l,y,A={}){l=V(l,void 0,"message"),s&&(l=s(l));let{prefix:w,scalar:x,pointBytes:B}=p(y),T=S(A.context,w,l),I=i.multiply(T).toBytes(),L=S(A.context,I,B,l),P=f.create(T+L*x);if(!f.isValid(P))throw new Error("sign failed: invalid s");let M=ot(I,f.toBytes(P));return V(M,O.signature,"result")}let D={zip215:o.zip215};function _(l,y,A,w=D){let{context:x}=w,B=w.zip215===void 0?!!D.zip215:w.zip215,T=O.signature;l=V(l,T,"signature"),y=V(y,void 0,"message"),A=V(A,O.publicKey,"publicKey"),B!==void 0&&At(B,"zip215"),s&&(y=s(y));let I=T/2,L=l.subarray(0,I),P=Lt(l.subarray(I,T)),M,H,K;try{M=e.fromBytes(A,B),H=e.fromBytes(L,B),K=i.multiplyUnsafe(P)}catch{return!1}if(!B&&M.isSmallOrder())return!1;let nt=S(x,L,A,y);return H.add(M.multiplyUnsafe(nt)).subtract(K).clearCofactor().is0()}let R=a.BYTES,O={secretKey:R,publicKey:R,signature:2*R,seed:R};function C(l){return l=l===void 0?d(O.seed):l,V(l,O.seed,"seed")}function N(l){return ue(l)&&l.length===O.secretKey}function j(l,y){try{return!!e.fromBytes(l,y===void 0?D.zip215:y)}catch{return!1}}let F={getExtendedPublicKey:p,randomSecretKey:C,isValidSecretKey:N,isValidPublicKey:j,toMontgomery(l){let{y}=e.fromBytes(l),A=O.publicKey,w=A===32;if(!w&&A!==57)throw new Error("only defined for 25519 and 448");let x=w?a.div(at+y,at-y):a.div(y-at,y+at);return a.toBytes(x)},toMontgomerySecret(l){let y=O.secretKey;V(l,y);let A=n(l.subarray(0,y));return g(A).subarray(0,y)}};return Object.freeze(O),Object.freeze(F),Object.freeze({keygen:fn(C,b),getPublicKey:b,sign:v,verify:_,utils:F,Point:e,lengths:O})}function Ar(e,t){if(Bt(e),Bt(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(e<0||e>2**(8*t)-1)throw new Error("invalid I2OSP input: "+e);let r=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)r[n]=e&255,e>>>=8;return new Uint8Array(r)}function sl(e,t){let r=new Uint8Array(e.length);for(let n=0;n<e.length;n++)r[n]=e[n]^t[n];return r}function il(e){if(!ue(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?sn(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function ss(e,t,r,n){V(e),Bt(r),t=il(t),t.length>255&&(t=n(ot(sn("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(r/o);if(r>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let a=ot(t,Ar(t.length,1)),f=new Uint8Array(s),c=Ar(r,2),u=new Array(i),d=n(ot(f,e,c,Ar(0,1),a));u[0]=n(ot(d,Ar(1,1),a));for(let m=1;m<i;m++){let h=[sl(d,u[m-1]),Ar(m+1,1),a];u[m]=n(ot(...h))}return ot(...u).slice(0,r)}var sc="HashToScalar-";var al=BigInt(0),Ht=BigInt(1),ic=BigInt(2);var cl=BigInt(5),fl=BigInt(8),$e=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),fs={p:$e,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:fl,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function ul(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=$e,a=e*e%s*e%s,f=G(a,ic,s)*a%s,c=G(f,Ht,s)*e%s,u=G(c,cl,s)*c%s,d=G(u,t,s)*u%s,g=G(d,r,s)*d%s,m=G(g,n,s)*g%s,h=G(m,o,s)*m%s,E=G(h,o,s)*m%s,p=G(E,t,s)*u%s;return{pow_p_5_8:G(p,ic,s)*e%s,b2:a}}function dl(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var is=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function us(e,t){let r=$e,n=et(t*t*t,r),o=et(n*n*t,r),s=ul(e*o).pow_p_5_8,i=et(e*n*s,r),a=et(t*i*i,r),f=i,c=et(i*is,r),u=a===e,d=a===et(-e,r),g=a===et(-e*is,r);return u&&(i=f),(d||g)&&(i=c),zt(i,r)&&(i=et(-i,r)),{isValid:u||d,value:i}}var re=nc(fs,{uvRatio:us}),ee=re.Fp,fc=re.Fn;function ll(e){return oc(re,tn,Object.assign({adjustScalarBytes:dl,zip215:!0},e))}var uc=ll({});var as=is,hl=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),pl=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),ml=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),bl=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),ac=e=>us(Ht,e),yl=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),cs=e=>ee.create(Lt(e)&yl);function cc(e){let{d:t}=fs,r=$e,n=b=>ee.create(b),o=n(as*e*e),s=n((o+Ht)*ml),i=BigInt(-1),a=n((i-t*o)*n(o+t)),{isValid:f,value:c}=us(s,a),u=n(c*e);zt(u,r)||(u=n(-u)),f||(c=u),f||(i=o);let d=n(i*(o-Ht)*bl-a),g=c*c,m=n((c+c)*a),h=n(d*hl),E=n(Ht-g),p=n(Ht+g);return new re(n(m*p),n(E*h),n(h*p),n(m*E))}var ne=class e extends un{static BASE=new e(re.BASE);static ZERO=new e(re.ZERO);static Fp=ee;static Fn=fc;constructor(t){super(t)}static fromAffine(t){return new e(re.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static fromBytes(t){wt(t,32);let{a:r,d:n}=fs,o=$e,s=D=>ee.create(D),i=cs(t);if(!Ka(ee.toBytes(i),t)||zt(i,o))throw new Error("invalid ristretto255 encoding 1");let a=s(i*i),f=s(Ht+r*a),c=s(Ht-r*a),u=s(f*f),d=s(c*c),g=s(r*n*u-d),{isValid:m,value:h}=ac(s(g*d)),E=s(h*c),p=s(h*E*g),b=s((i+i)*E);zt(b,o)&&(b=s(-b));let S=s(f*p),v=s(b*S);if(!m||zt(v,o)||S===al)throw new Error("invalid ristretto255 encoding 2");return new e(new re(b,S,Ht,v))}static fromHex(t){return e.fromBytes(pr(t))}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=$e,i=p=>ee.create(p),a=i(i(n+r)*i(n-r)),f=i(t*r),c=i(f*f),{value:u}=ac(i(a*c)),d=i(u*a),g=i(u*f),m=i(d*g*o),h;if(zt(o*m,s)){let p=i(r*as),b=i(t*as);t=p,r=b,h=i(d*pl)}else h=g;zt(t*m,s)&&(r=i(-r));let E=i((n-r)*h);return zt(E,s)&&(E=i(-E)),ee.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=c=>ee.create(c),a=i(r*s)===i(n*o),f=i(n*s)===i(r*o);return a||f}is0(){return this.equals(e.ZERO)}};Object.freeze(ne.BASE);Object.freeze(ne.ZERO);Object.freeze(ne.prototype);Object.freeze(ne);var xl=Object.freeze({Point:ne,hashToCurve(e,t){let r=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=ss(e,r,64,tn);return xl.deriveToCurve(n)},hashToScalar(e,t={DST:sc}){let r=ss(e,t.DST,64,tn);return fc.create(Lt(r))},deriveToCurve(e){wt(e,64);let t=cs(e.subarray(0,32)),r=cc(t),n=cs(e.subarray(32,64)),o=cc(n);return new ne(r.add(o))}});var Br=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},dn=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var ln={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new dn("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 hn=32;var ds,gl=(async()=>{try{return await ln.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function wl(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await ln.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await ln.get().subtle.verify({name:"Ed25519"},n,De(t),De(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function El(e,t,r){return uc.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function dc(e,t,r){return ds==null&&(ds=await gl),ds?wl(e,t,r):El(e,t,r)}function pn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var mn=class{type="Ed25519";raw;constructor(t){this.raw=ls(t,hn)}toMultihash(){return St.digest(Fe(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Nt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=dc(this.raw,r,t);return pn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function hc(e){return e=ls(e,hn),new mn(e)}function ls(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new It(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var vl=Math.pow(2,7),Al=Math.pow(2,14),Bl=Math.pow(2,21),hs=Math.pow(2,28),ps=Math.pow(2,35),ms=Math.pow(2,42),bs=Math.pow(2,49),W=128,ht=127;function Ut(e){if(e<vl)return 1;if(e<Al)return 2;if(e<Bl)return 3;if(e<hs)return 4;if(e<ps)return 5;if(e<ms)return 6;if(e<bs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Cr(e,t,r=0){switch(Ut(e)){case 8:t[r++]=e&255|W,e/=128;case 7:t[r++]=e&255|W,e/=128;case 6:t[r++]=e&255|W,e/=128;case 5:t[r++]=e&255|W,e/=128;case 4:t[r++]=e&255|W,e>>>=7;case 3:t[r++]=e&255|W,e>>>=7;case 2:t[r++]=e&255|W,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function ys(e,t){let r=e[t],n=0;if(n+=r&ht,r<W||(r=e[t+1],n+=(r&ht)<<7,r<W)||(r=e[t+2],n+=(r&ht)<<14,r<W)||(r=e[t+3],n+=(r&ht)<<21,r<W)||(r=e[t+4],n+=(r&ht)*hs,r<W)||(r=e[t+5],n+=(r&ht)*ps,r<W)||(r=e[t+6],n+=(r&ht)*ms,r<W)||(r=e[t+7],n+=(r&ht)*bs,r<W))return n;throw new RangeError("Could not decode varint")}function Cl(e,t){let r=e.get(t),n=0;if(n+=r&ht,r<W||(r=e.get(t+1),n+=(r&ht)<<7,r<W)||(r=e.get(t+2),n+=(r&ht)<<14,r<W)||(r=e.get(t+3),n+=(r&ht)<<21,r<W)||(r=e.get(t+4),n+=(r&ht)*hs,r<W)||(r=e.get(t+5),n+=(r&ht)*ps,r<W)||(r=e.get(t+6),n+=(r&ht)*ms,r<W)||(r=e.get(t+7),n+=(r&ht)*bs,r<W))return n;throw new RangeError("Could not decode varint")}function xs(e,t=0){return e instanceof Uint8Array?ys(e,t):Cl(e,t)}var gs=new Float32Array([-0]),oe=new Uint8Array(gs.buffer);function pc(e,t,r){gs[0]=e,t[r]=oe[0],t[r+1]=oe[1],t[r+2]=oe[2],t[r+3]=oe[3]}function mc(e,t){return oe[0]=e[t],oe[1]=e[t+1],oe[2]=e[t+2],oe[3]=e[t+3],gs[0]}var ws=new Float64Array([-0]),pt=new Uint8Array(ws.buffer);function bc(e,t,r){ws[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 yc(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],ws[0]}var Dl=BigInt(Number.MAX_SAFE_INTEGER),Il=BigInt(Number.MIN_SAFE_INTEGER),Et=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 me;if(t<Dl&&t>Il)return this.fromNumber(Number(t));let r=t<0n;r&&(t=-t);let n=t>>32n,o=t-(n<<32n);return r&&(n=~n|0n,o=~o|0n,++o>xc&&(o=0n,++n>xc&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return me;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):me}},me=new Et(0,0);me.toBigInt=function(){return 0n};me.zzEncode=me.zzDecode=function(){return this};me.length=function(){return 1};var xc=4294967296n;function gc(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 wc(e,t,r){if(r-t<1)return"";let o,s=[],i=0,a;for(;t<r;)a=e[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(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,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(e[t++]&63)<<6|e[t++]&63,i>8191&&((o??(o=[])).push(String.fromCharCode.apply(String,s)),i=0);return o!=null?(i>0&&o.push(String.fromCharCode.apply(String,s.slice(0,i))),o.join("")):String.fromCharCode.apply(String,s.slice(0,i))}function Es(e,t,r){let n=r,o,s;for(let i=0;i<e.length;++i)o=e.charCodeAt(i),o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&((s=e.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128);return r-n}function _t(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function bn(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var Ss=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=t,this.pos=0,this.len=t.length}uint32(){let t=4294967295;if(t=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(t=(t|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(t=(t|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return t;if((this.pos+=5)>this.len)throw this.pos=this.len,_t(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw _t(this,4);return bn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw _t(this,4);return bn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw _t(this,4);let t=mc(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw _t(this,4);let t=yc(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),r=this.pos,n=this.pos+t;if(n>this.len)throw _t(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return wc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw _t(this,t);this.pos+=t}else do if(this.pos>=this.len)throw _t(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new Et(0,0),r=0;if(this.len-this.pos>4){for(;r<4;++r)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t;if(t.lo=(t.lo|(this.buf[this.pos]&127)<<28)>>>0,t.hi=(t.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return t;r=0}else{for(;r<3;++r){if(this.pos>=this.len)throw _t(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<r*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<r*7)>>>0,t}if(this.len-this.pos>4){for(;r<5;++r)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;r<5;++r){if(this.pos>=this.len)throw _t(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<r*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw _t(this,8);let t=bn(this.buf,this.pos+=4),r=bn(this.buf,this.pos+=4);return new Et(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=ys(this.buf,this.pos);return this.pos+=Ut(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 _r(e){return new Ss(e instanceof Uint8Array?e:e.subarray())}function yn(e,t,r){let n=_r(e);return t.decode(n,void 0,r)}function be(e=0){return new Uint8Array(e)}var vs={};$(vs,{base10:()=>Tl});var Tl=Zt({prefix:"9",name:"base10",alphabet:"0123456789"});var As={};$(As,{base16:()=>Ol,base16upper:()=>Ll});var Ol=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ll=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Bs={};$(Bs,{base2:()=>Ul});var Ul=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Cs={};$(Cs,{base256emoji:()=>Kl});var Sc=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}"),Rl=Sc.reduce((e,t,r)=>(e[r]=t,e),[]),Pl=Sc.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Nl(e){return e.reduce((t,r)=>(t+=Rl[r],t),"")}function Fl(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Pl[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Kl=Se({prefix:"\u{1F680}",name:"base256emoji",encode:Nl,decode:Fl});var Ds={};$(Ds,{base64:()=>kl,base64pad:()=>Ml,base64url:()=>_s,base64urlpad:()=>Vl});var kl=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ml=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),_s=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Vl=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Is={};$(Is,{base8:()=>zl});var zl=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ts={};$(Ts,{identity:()=>Hl});var Hl=Se({prefix:"\0",name:"identity",encode:e=>Oi(e),decode:e=>Ti(e)});var Wb=new TextEncoder,Xb=new TextDecoder;var Us={};$(Us,{sha256:()=>Dr,sha512:()=>Zl});var $l=20;function Ls({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Os(e,t,r,n,o)}var Os=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??$l,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?vc(n,this.code,r?.truncate):n.then(o=>vc(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function vc(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 Ce(t,e)}function Bc(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Dr=Ls({name:"sha2-256",code:18,encode:Bc("SHA-256")}),Zl=Ls({name:"sha2-512",code:19,encode:Bc("SHA-512")});var se={...Ts,...Bs,...Is,...vs,...As,...eo,...ro,...to,...Ds,...Cs},fy={...Us,...so};function _c(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Cc=_c("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Rs=_c("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=be(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Yl={utf8:Cc,"utf-8":Cc,hex:se.base16,latin1:Rs,ascii:Rs,binary:Rs,...se},Dc=Yl;function Ic(e,t="utf8"){let r=Dc[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function Ps(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return be(i);o+i>t&&(n=be(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var ye=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Ns(){}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}},Gl=Ps();function Wl(e){return globalThis.Buffer!=null?be(e):Gl(e)}var Tr=class{len;head;tail;states;constructor(){this.len=0,this.head=new ye(Ns,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new ye(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(xn,10,Et.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=Et.fromBigInt(t);return this._push(xn,r.length(),r)}uint64Number(t){return this._push(Cr,Ut(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=Et.fromBigInt(t).zzEncode();return this._push(xn,r.length(),r)}sint64Number(t){let r=Et.fromNumber(t).zzEncode();return this._push(xn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Fs,1,t?1:0)}fixed32(t){return this._push(Ir,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=Et.fromBigInt(t);return this._push(Ir,4,r.lo)._push(Ir,4,r.hi)}fixed64Number(t){let r=Et.fromNumber(t);return this._push(Ir,4,r.lo)._push(Ir,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(pc,4,t)}double(t){return this._push(bc,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Fs,1,0):this.uint32(r)._push(Ql,r,t)}string(t){let r=gc(t);return r!==0?this.uint32(r)._push(Es,r,t):this._push(Fs,1,0)}fork(){return this.states=new Ks(this),this.head=this.tail=new ye(Ns,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 ye(Ns,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=Wl(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Fs(e,t,r){t[r]=e&255}function Xl(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var ks=class extends ye{next;constructor(t,r){super(Xl,t,r),this.next=void 0}};function xn(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 Ir(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 Ql(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Tr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Jl,t,e),this},Tr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(th,t,e),this});function Jl(e,t,r){t.set(e,r)}function th(e,t,r){e.length<40?Es(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Ic(e),r)}function Ms(){return new Tr}function gn(e,t){let r=Ms();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*wn(e,t,r){let n=_r(e);yield*t.stream(n,void 0,"$",r)}var En={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Sn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function Vs(e){function t(s){if(e[s.toString()]==null)throw new Error("Invalid enum value");return e[s]}let r=function(i,a){let f=t(i);a.int32(f)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return Sn("enum",En.VARINT,r,n,o)}function vn(e,t,r){return Sn("message",En.LENGTH_DELIMITED,e,t,r)}var bt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(bt||(bt={}));var zs;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(zs||(zs={}));(function(e){e.codec=()=>Vs(zs)})(bt||(bt={}));var Or;(function(e){let t;e.codec=()=>(t==null&&(t=vn((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),bt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let f={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{f.Type=bt.codec().decode(s);break}case 2:{f.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return f},function*(s,i,a,f={}){let c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:bt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return gn(s,e.codec())}e.encode=r;function n(s,i){return yn(s,e.codec(),i)}e.decode=n;function o(s,i){return wn(s,e.codec(),i)}e.stream=o})(Or||(Or={}));var Hs;(function(e){let t;e.codec=()=>(t==null&&(t=vn((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),bt.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let f={},c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{f.Type=bt.codec().decode(s);break}case 2:{f.Data=s.bytes();break}default:{s.skipType(u&7);break}}}return f},function*(s,i,a,f={}){let c=i==null?s.len:s.pos+i;for(;s.pos<c;){let u=s.uint32();switch(u>>>3){case 1:{yield{field:`${a}.Type`,value:bt.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function r(s){return gn(s,e.codec())}e.encode=r;function n(s,i){return yn(s,e.codec(),i)}e.decode=n;function o(s,i){return wn(s,e.codec(),i)}e.stream=o})(Hs||(Hs={}));var An=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(Gr(t),wt(r,void 0,"key"),this.iHash=t.create(),typeof this.iHash.update!="function")throw new Error("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,o=new Uint8Array(n);o.set(r.length>n?t.create().update(r).digest():r);for(let s=0;s<o.length;s++)o[s]^=54;this.iHash.update(o),this.oHash=t.create();for(let s=0;s<o.length;s++)o[s]^=106;this.oHash.update(o),Mt(o)}update(t){return Ke(this),this.iHash.update(t),this}digestInto(t){Ke(this),Wr(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:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=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()}},Tc=(()=>{let e=((t,r,n)=>new An(t,r).update(n).digest());return e.create=(t,r)=>new An(t,r),e})();var Oc=(e,t)=>(e+(e>=0?t:-t)/Lc)/t;function rh(e,t,r){Ve("scalar",e,Rt,r);let[[n,o],[s,i]]=t,a=Oc(i*e,r),f=Oc(-o*e,r),c=e-a*n-f*s,u=-a*o-f*i,d=c<Rt,g=u<Rt;d&&(c=-c),g&&(u=-u);let m=Er(Math.ceil(ze(r)/2))+ie;if(c<Rt||c>=m||u<Rt||u>=m)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:c,k2neg:g,k2:u}}function js(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function qs(e,t){Ct(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return At(r.lowS,"lowS"),At(r.prehash,"prehash"),r.format!==void 0&&js(r.format),r}var $s=class extends Error{constructor(t=""){super(t)}},Dt={Err:$s,_tlv:{encode:(e,t)=>{let{Err:r}=Dt;if(Bt(e,"tag"),e<0||e>255)throw new r("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new r("tlv.encode: unpadded data");let n=t.length/2,o=gr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?gr(o.length/2|128):"";return gr(e)+s+o+t},decode(e,t){let{Err:r}=Dt;t=V(t,void 0,"DER data");let n=0;if(e<0||e>255)throw new r("tlv.encode: wrong tag");if(t.length<2||t[n++]!==e)throw new r("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let f=o&127;if(!f)throw new r("tlv.decode(long): indefinite length not supported");if(f>4)throw new r("tlv.decode(long): byte length is too big");let c=t.subarray(n,n+f);if(c.length!==f)throw new r("tlv.decode: length bytes not complete");if(c[0]===0)throw new r("tlv.decode(long): zero leftmost byte");for(let u of c)i=i<<8|u;if(n+=f,i<128)throw new r("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new r("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(e){let{Err:t}=Dt;if(nn(e),e<Rt)throw new t("integer: negative integers are not allowed");let r=gr(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}=Dt;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 de(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Dt,o=V(e,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:f}=n.decode(2,s),{v:c,l:u}=n.decode(2,f);if(u.length)throw new t("invalid signature: left bytes after parsing");return{r:r.decode(a),s:r.decode(c)}},hexFromSig(e){let{_tlv:t,_int:r}=Dt,n=t.encode(2,r.encode(e.r)),o=t.encode(2,r.encode(e.s)),s=n+o;return t.encode(48,s)}};Object.freeze(Dt._tlv);Object.freeze(Dt._int);Object.freeze(Dt);var Rt=BigInt(0),ie=BigInt(1),Lc=BigInt(2),Bn=BigInt(3),nh=BigInt(4);function Uc(e,t={}){let r=cn("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:a}=s;Ct(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:f,allowInfinityPoint:c}=t;if(f&&(!n.is0(s.a)||typeof f.beta!="bigint"||!Array.isArray(f.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let u=Pc(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function g(F,l,y){if(c&&l.is0())return Uint8Array.of(0);let{x:A,y:w}=l.toAffine(),x=n.toBytes(A);if(At(y,"isCompressed"),y){d();let B=!n.isOdd(w);return ot(Rc(B),x)}else return ot(Uint8Array.of(4),x,n.toBytes(w))}function m(F){V(F,void 0,"Point");let{publicKey:l,publicKeyUncompressed:y}=u,A=F.length,w=F[0],x=F.subarray(1);if(c&&A===1&&w===0)return{x:n.ZERO,y:n.ZERO};if(A===l&&(w===2||w===3)){let B=n.fromBytes(x);if(!n.isValid(B))throw new Error("bad point: is not on curve, wrong x");let T=p(B),I;try{I=n.sqrt(T)}catch(M){let H=M instanceof Error?": "+M.message:"";throw new Error("bad point: is not on curve, sqrt error"+H)}d();let L=n.isOdd(I);return(w&1)===1!==L&&(I=n.neg(I)),{x:B,y:I}}else if(A===y&&w===4){let B=n.BYTES,T=n.fromBytes(x.subarray(0,B)),I=n.fromBytes(x.subarray(B,B*2));if(!b(T,I))throw new Error("bad point: is not on curve");return{x:T,y:I}}else throw new Error(`bad point: got length ${A}, expected compressed=${l} or uncompressed=${y}`)}let h=t.toBytes===void 0?g:t.toBytes,E=t.fromBytes===void 0?m:t.fromBytes;function p(F){let l=n.sqr(F),y=n.mul(l,F);return n.add(n.add(y,n.mul(F,s.a)),s.b)}function b(F,l){let y=n.sqr(l),A=p(F);return n.eql(y,A)}if(!b(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(s.a,Bn),nh),v=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(S,v)))throw new Error("bad curve params: a or b");function D(F,l,y=!1){if(!n.isValid(l)||y&&n.is0(l))throw new Error(`bad point coordinate ${F}`);return l}function _(F){if(!(F instanceof C))throw new Error("Weierstrass Point expected")}function R(F){if(!f||!f.basises)throw new Error("no endo");return rh(F,f.basises,o.ORDER)}function O(F,l,y,A,w){return y=new C(n.mul(y.X,F),y.Y,y.Z),l=vr(A,l),y=vr(w,y),l.add(y)}class C{static BASE=new C(s.Gx,s.Gy,n.ONE);static ZERO=new C(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(l,y,A){this.X=D("x",l),this.Y=D("y",y,!0),this.Z=D("z",A),Object.freeze(this)}static CURVE(){return s}static fromAffine(l){let{x:y,y:A}=l||{};if(!l||!n.isValid(y)||!n.isValid(A))throw new Error("invalid affine point");if(l instanceof C)throw new Error("projective point not allowed");return n.is0(y)&&n.is0(A)?C.ZERO:new C(y,A,n.ONE)}static fromBytes(l){let y=C.fromAffine(E(V(l,void 0,"point")));return y.assertValidity(),y}static fromHex(l){return C.fromBytes(Me(l))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(l=8,y=!0){return j.createCache(this,l),y||this.multiply(Bn),this}assertValidity(){let l=this;if(l.is0()){if(t.allowInfinityPoint&&n.is0(l.X)&&n.eql(l.Y,n.ONE)&&n.is0(l.Z))return;throw new Error("bad point: ZERO")}let{x:y,y:A}=l.toAffine();if(!n.isValid(y)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!b(y,A))throw new Error("bad point: equation left != right");if(!l.isTorsionFree())throw new Error("bad point: not in prime-order subgroup")}hasEvenY(){let{y:l}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(l)}equals(l){_(l);let{X:y,Y:A,Z:w}=this,{X:x,Y:B,Z:T}=l,I=n.eql(n.mul(y,T),n.mul(x,w)),L=n.eql(n.mul(A,T),n.mul(B,w));return I&&L}negate(){return new C(this.X,n.neg(this.Y),this.Z)}double(){let{a:l,b:y}=s,A=n.mul(y,Bn),{X:w,Y:x,Z:B}=this,T=n.ZERO,I=n.ZERO,L=n.ZERO,P=n.mul(w,w),M=n.mul(x,x),H=n.mul(B,B),K=n.mul(w,x);return K=n.add(K,K),L=n.mul(w,B),L=n.add(L,L),T=n.mul(l,L),I=n.mul(A,H),I=n.add(T,I),T=n.sub(M,I),I=n.add(M,I),I=n.mul(T,I),T=n.mul(K,T),L=n.mul(A,L),H=n.mul(l,H),K=n.sub(P,H),K=n.mul(l,K),K=n.add(K,L),L=n.add(P,P),P=n.add(L,P),P=n.add(P,H),P=n.mul(P,K),I=n.add(I,P),H=n.mul(x,B),H=n.add(H,H),P=n.mul(H,K),T=n.sub(T,P),L=n.mul(H,M),L=n.add(L,L),L=n.add(L,L),new C(T,I,L)}add(l){_(l);let{X:y,Y:A,Z:w}=this,{X:x,Y:B,Z:T}=l,I=n.ZERO,L=n.ZERO,P=n.ZERO,M=s.a,H=n.mul(s.b,Bn),K=n.mul(y,x),nt=n.mul(A,B),st=n.mul(w,T),it=n.add(y,A),tt=n.add(x,B);it=n.mul(it,tt),tt=n.add(K,nt),it=n.sub(it,tt),tt=n.add(y,w);let yt=n.add(x,T);return tt=n.mul(tt,yt),yt=n.add(K,st),tt=n.sub(tt,yt),yt=n.add(A,w),I=n.add(B,T),yt=n.mul(yt,I),I=n.add(nt,st),yt=n.sub(yt,I),P=n.mul(M,tt),I=n.mul(H,st),P=n.add(I,P),I=n.sub(nt,P),P=n.add(nt,P),L=n.mul(I,P),nt=n.add(K,K),nt=n.add(nt,K),st=n.mul(M,st),tt=n.mul(H,tt),nt=n.add(nt,st),st=n.sub(K,st),st=n.mul(M,st),tt=n.add(tt,st),K=n.mul(nt,tt),L=n.add(L,K),K=n.mul(yt,tt),I=n.mul(it,I),I=n.sub(I,K),K=n.mul(it,nt),P=n.mul(yt,P),P=n.add(P,K),new C(I,L,P)}subtract(l){return _(l),this.add(l.negate())}is0(){return this.equals(C.ZERO)}multiply(l){let{endo:y}=t;if(!o.isValidNot0(l))throw new RangeError("invalid scalar: out of range");let A,w,x=B=>j.cached(this,B,T=>pe(C,T));if(y){let{k1neg:B,k1:T,k2neg:I,k2:L}=R(l),{p:P,f:M}=x(T),{p:H,f:K}=x(L);w=M.add(K),A=O(y.beta,P,H,B,I)}else{let{p:B,f:T}=x(l);A=B,w=T}return pe(C,[A,w])[0]}multiplyUnsafe(l){let{endo:y}=t,A=this,w=l;if(!o.isValid(w))throw new RangeError("invalid scalar: out of range");if(w===Rt||A.is0())return C.ZERO;if(w===ie)return A;if(j.hasCache(this))return this.multiply(w);if(y){let{k1neg:x,k1:B,k2neg:T,k2:I}=R(w),{p1:L,p2:P}=rc(C,A,B,I);return O(y.beta,L,P,x,T)}else return j.unsafe(A,w)}toAffine(l){let y=this,A=l,{X:w,Y:x,Z:B}=y;if(n.eql(B,n.ONE))return{x:w,y:x};let T=y.is0();A==null&&(A=T?n.ONE:n.inv(B));let I=n.mul(w,A),L=n.mul(x,A),P=n.mul(B,A);if(T)return{x:n.ZERO,y:n.ZERO};if(!n.eql(P,n.ONE))throw new Error("invZ was invalid");return{x:I,y:L}}isTorsionFree(){let{isTorsionFree:l}=t;return i===ie?!0:l?l(C,this):j.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:l}=t;return i===ie?this:l?l(C,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===ie?this.is0():this.clearCofactor().is0()}toBytes(l=!0){return At(l,"isCompressed"),this.assertValidity(),h(C,this,l)}toHex(l=!0){return ke(this.toBytes(l))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=o.BITS,j=new je(C,t.endo?Math.ceil(N/2):N);return N>=8&&C.BASE.precompute(8),Object.freeze(C.prototype),Object.freeze(C),C}function Rc(e){return Uint8Array.of(e?2:3)}function Pc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function oh(e,t={}){let{Fn:r}=e,n=t.randomBytes===void 0?xr:t.randomBytes,o=Object.assign(Pc(e.Fp,r),{seed:Math.max(Jo(r.ORDER),16)});function s(m){try{let h=r.fromBytes(m);return r.isValidNot0(h)}catch{return!1}}function i(m,h){let{publicKey:E,publicKeyUncompressed:p}=o;try{let b=m.length;return h===!0&&b!==E||h===!1&&b!==p?!1:!!e.fromBytes(m)}catch{return!1}}function a(m){return m=m===void 0?n(o.seed):m,ts(V(m,o.seed,"seed"),r.ORDER)}function f(m,h=!0){return e.BASE.multiply(r.fromBytes(m)).toBytes(h)}function c(m){let{secretKey:h,publicKey:E,publicKeyUncompressed:p}=o,b=r._lengths;if(!ue(m))return;let S=V(m,void 0,"key").length,v=S===E||S===p,D=S===h||!!b?.includes(S);if(!(v&&D))return v}function u(m,h,E=!0){if(c(m)===!0)throw new Error("first arg must be private key");if(c(h)===!1)throw new Error("second arg must be public key");let p=r.fromBytes(m);return e.fromBytes(h).multiply(p).toBytes(E)}let d={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},g=fn(a,f);return Object.freeze(d),Object.freeze(o),Object.freeze({getPublicKey:f,getSharedSecret:u,keygen:g,Point:e,utils:d,lengths:o})}function Nc(e,t,r={}){let n=t;Gr(n),Ct(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?xr:r.randomBytes,s=r.hmac===void 0?(w,x)=>Tc(n,w,x):r.hmac,{Fp:i,Fn:a}=e,{ORDER:f,BITS:c}=a,{keygen:u,getPublicKey:d,getSharedSecret:g,utils:m,lengths:h}=oh(e,r),E={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},p=f*Lc+ie<i.ORDER;function b(w){let x=f>>ie;return w>x}function S(w,x){if(!a.isValidNot0(x))throw new Error(`invalid signature ${w}: out of range 1..Point.Fn.ORDER`);return x}function v(){if(p)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function D(w,x){js(x);let B=h.signature,T=x==="compact"?B:x==="recovered"?B+1:void 0;return V(w,T)}class _{r;s;recovery;constructor(x,B,T){if(this.r=S("r",x),this.s=S("s",B),T!=null){if(v(),![0,1,2,3].includes(T))throw new Error("invalid recovery id");this.recovery=T}Object.freeze(this)}static fromBytes(x,B=E.format){D(x,B);let T;if(B==="der"){let{r:M,s:H}=Dt.toSig(V(x));return new _(M,H)}B==="recovered"&&(T=x[0],B="compact",x=x.subarray(1));let I=h.signature/2,L=x.subarray(0,I),P=x.subarray(I,I*2);return new _(a.fromBytes(L),a.fromBytes(P),T)}static fromHex(x,B){return this.fromBytes(Me(x),B)}assertRecovery(){let{recovery:x}=this;if(x==null)throw new Error("invalid recovery id: must be present");return x}addRecoveryBit(x){return new _(this.r,this.s,x)}recoverPublicKey(x){let{r:B,s:T}=this,I=this.assertRecovery(),L=I===2||I===3?B+f:B;if(!i.isValid(L))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let P=i.toBytes(L),M=e.fromBytes(ot(Rc((I&1)===0),P)),H=a.inv(L),K=O(V(x,void 0,"msgHash")),nt=a.create(-K*H),st=a.create(T*H),it=e.BASE.multiplyUnsafe(nt).add(M.multiplyUnsafe(st));if(it.is0())throw new Error("invalid recovery: point at infinify");return it.assertValidity(),it}hasHighS(){return b(this.s)}toBytes(x=E.format){if(js(x),x==="der")return Me(Dt.hexFromSig(this));let{r:B,s:T}=this,I=a.toBytes(B),L=a.toBytes(T);return x==="recovered"?(v(),ot(Uint8Array.of(this.assertRecovery()),I,L)):ot(I,L)}toHex(x){return ke(this.toBytes(x))}}Object.freeze(_.prototype),Object.freeze(_);let R=r.bits2int===void 0?function(x){if(x.length>8192)throw new Error("input is too large");let B=de(x),T=x.length*8-c;return T>0?B>>BigInt(T):B}:r.bits2int,O=r.bits2int_modN===void 0?function(x){return a.create(R(x))}:r.bits2int_modN,C=Er(c);function N(w){return Ve("num < 2^"+c,w,Rt,C),a.toBytes(w)}function j(w,x){return V(w,void 0,"message"),x?V(n(w),void 0,"prehashed message"):w}function F(w,x,B){let{lowS:T,prehash:I,extraEntropy:L}=qs(B,E);w=j(w,I);let P=O(w),M=a.fromBytes(x);if(!a.isValidNot0(M))throw new Error("invalid private key");let H=[N(M),N(P)];if(L!=null&&L!==!1){let it=L===!0?o(h.secretKey):L;H.push(V(it,void 0,"extraEntropy"))}let K=ot(...H),nt=P;function st(it){let tt=R(it);if(!a.isValidNot0(tt))return;let yt=a.inv(tt),Ee=e.BASE.multiply(tt).toAffine(),Je=a.create(Ee.x);if(Je===Rt)return;let Kr=a.create(yt*a.create(nt+Je*M));if(Kr===Rt)return;let Bi=(Ee.x===Je?0:2)|Number(Ee.y&ie),Ci=Kr;return T&&b(Kr)&&(Ci=a.neg(Kr),Bi^=1),new _(Je,Ci,p?void 0:Bi)}return{seed:K,k2sig:st}}function l(w,x,B={}){let{seed:T,k2sig:I}=F(w,x,B);return ka(n.outputLen,a.BYTES,s)(T,I).toBytes(B.format)}function y(w,x,B,T={}){let{lowS:I,prehash:L,format:P}=qs(T,E);if(B=V(B,void 0,"publicKey"),x=j(x,L),!ue(w)){let M=w instanceof _?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+M)}D(w,P);try{let M=_.fromBytes(w,P),H=e.fromBytes(B);if(I&&M.hasHighS())return!1;let{r:K,s:nt}=M,st=O(x),it=a.inv(nt),tt=a.create(st*it),yt=a.create(K*it),Ee=e.BASE.multiplyUnsafe(tt).add(H.multiplyUnsafe(yt));return Ee.is0()?!1:a.create(Ee.x)===K}catch{return!1}}function A(w,x,B={}){let{prehash:T}=qs(B,E);return x=j(x,T),_.fromBytes(w,"recovered").recoverPublicKey(x).toBytes()}return Object.freeze({keygen:u,getPublicKey:d,getSharedSecret:g,utils:m,lengths:h,Point:e,sign:l,verify:y,recoverPublicKey:A,Signature:_,hash:n})}var Ys={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},sh={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Fc=BigInt(2);function ih(e){let t=Ys.p,r=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),f=BigInt(88),c=e*e*e%t,u=c*c*e%t,d=G(u,r,t)*u%t,g=G(d,r,t)*u%t,m=G(g,Fc,t)*c%t,h=G(m,o,t)*m%t,E=G(h,s,t)*h%t,p=G(E,a,t)*E%t,b=G(p,f,t)*p%t,S=G(b,a,t)*E%t,v=G(S,r,t)*u%t,D=G(v,i,t)*h%t,_=G(D,n,t)*c%t,R=G(_,Fc,t);if(!Zs.eql(Zs.sqr(R),e))throw new Error("Cannot find square root");return R}var Zs=He(Ys.p,{sqrt:ih}),ah=Uc(Ys,{Fp:Zs,endo:sh}),Ze=Nc(ah,Na);function Kc(e,t,r,n){let o=Dr.digest(r instanceof Uint8Array?r:r.subarray());if(pn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ze.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Br(String(s))});try{return n?.signal?.throwIfAborted(),Ze.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new Br(String(s))}}var Cn=class{type="secp256k1";raw;_key;constructor(t){this._key=Mc(t),this.raw=kc(this._key)}toMultihash(){return St.digest(Fe(this))}toCID(){return ft.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:Nt(this.raw,t.raw)}verify(t,r,n){return Kc(this._key,r,t,n)}};function Vc(e){return new Cn(e)}function kc(e){return Ze.Point.fromBytes(e).toBytes()}function Mc(e){try{return Ze.Point.fromBytes(e),e}catch(t){throw new kr(String(t))}}function zc(e){let{Type:t,Data:r}=Or.decode(e.digest),n=r??new Uint8Array;switch(t){case bt.Ed25519:return hc(n);case bt.secp256k1:return Vc(n);case bt.ECDSA:return ga(n);default:throw new tr}}function Fe(e){return Or.encode({Type:bt[e.type],Data:e.raw})}var Hc=Symbol.for("nodejs.util.inspect.custom"),ch=114,Lr=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()})`}[Gn]=!0;toString(){return this.string==null&&(this.string=rt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ft.createV1(ch,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return Nt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return Nt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Hc](){return`PeerId(${this.toString()})`}},_n=class extends Lr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Dn=class extends Lr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},In=class extends Lr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},fh=2336,Ur=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=St.digest(Pe(this.url))}[Hc](){return`PeerId(${this.url})`}[Gn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ft.createV1(fh,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=gt(t)),t.toString()===this.toString())}};var uh=114,qc=2336;function jc(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=or(rt.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return dh(ft.parse(e));if(t==null)throw new It('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=or(t.decode(e))}return $c(r)}function $c(e){if(hh(e))return new _n({multihash:e});if(lh(e))try{let t=zc(e);if(t.type==="Ed25519")return new Dn({multihash:e,publicKey:t});if(t.type==="secp256k1")return new In({multihash:e,publicKey:t})}catch{let r=gt(e.digest);return new Ur(new URL(r))}throw new Vr("Supplied PeerID Multihash is invalid")}function dh(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==uh&&e.code!==qc)throw new Mr("Supplied PeerID CID is invalid");if(e.code===qc){let t=gt(e.multihash.digest);return new Ur(new URL(t))}return $c(e.multihash)}function lh(e){return e.code===St.code}function hh(e){return e.code===Dr.code}function Zc(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 Tn(e=0){return new Uint8Array(e)}function Rr(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=Tn(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}function Gc(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Yc=Gc("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Gs=Gc("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=Tn(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),ph={utf8:Yc,"utf-8":Yc,hex:se.base16,latin1:Gs,ascii:Gs,binary:Gs,...se},On=ph;function Pr(e,t="utf8"){let r=On[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function xe(e,t="utf8"){let r=On[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var lt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},qt=class extends Error{static name="ValidationError";name="ValidationError"},Ln=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Un=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var Rn=class{index=0;input="";new(t){return this.index=0,this.input=t,this}readAtomically(t){let r=this.index,n=t();return n===void 0&&(this.index=r),n}parseWith(t){let r=t();if(this.index===this.input.length)return r}peekChar(){if(!(this.index>=this.input.length))return this.input[this.index]}readChar(){if(!(this.index>=this.input.length))return this.input[this.index++]}readGivenChar(t){return this.readAtomically(()=>{let r=this.readChar();if(r===t)return r})}readSeparator(t,r,n){return this.readAtomically(()=>{if(!(r>0&&this.readGivenChar(t)===void 0))return n()})}readNumber(t,r,n,o){return this.readAtomically(()=>{let s=0,i=0,a=this.peekChar();if(a===void 0)return;let f=a==="0",c=2**(8*o)-1;for(;;){let u=this.readAtomically(()=>{let d=this.readChar();if(d===void 0)return;let g=Number.parseInt(d,t);if(!Number.isNaN(g))return g});if(u===void 0)break;if(s*=t,s+=u,s>c||(i+=1,r!==void 0&&i>r))return}if(i!==0)return!n&&f&&i>1?void 0:s})}readIPv4Addr(){return this.readAtomically(()=>{let t=new Uint8Array(4);for(let r=0;r<t.length;r++){let n=this.readSeparator(".",r,()=>this.readNumber(10,3,!1,1));if(n===void 0)return;t[r]=n}return t})}readIPv6Addr(){let t=r=>{for(let n=0;n<r.length/2;n++){let o=n*2;if(n<r.length-3){let i=this.readSeparator(":",n,()=>this.readIPv4Addr());if(i!==void 0)return r[o]=i[0],r[o+1]=i[1],r[o+2]=i[2],r[o+3]=i[3],[o+4,!0]}let s=this.readSeparator(":",n,()=>this.readNumber(16,4,!0,2));if(s===void 0)return[o,!1];r[o]=s>>8,r[o+1]=s&255}return[r.length,!1]};return this.readAtomically(()=>{let r=new Uint8Array(16),[n,o]=t(r);if(n===16)return r;if(o||this.readGivenChar(":")===void 0||this.readGivenChar(":")===void 0)return;let s=new Uint8Array(14),i=16-(n+2),[a]=t(s.subarray(0,i));return r.set(s.subarray(0,a),16-a),r})}readIPAddr(){return this.readIPv4Addr()??this.readIPv6Addr()}};var mh=45,bh=15,Pn=new Rn;function Wc(e){if(!(e.length>bh))return Pn.new(e).parseWith(()=>Pn.readIPv4Addr())}function Xc(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>mh))return Pn.new(e).parseWith(()=>Pn.readIPv6Addr())}function Nn(e){return!!Wc(e)}function Qc(e){return!!Xc(e)}function Xs(e){return t=>xe(t,e)}function Qs(e){return t=>Pr(t,e)}function Ye(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function ge(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}function Jc(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=Pr(t[0],"base32"),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ge(n);return Rr([r,o],r.length+o.length)}function tf(e){let t=e.split(":");if(t.length!==2)throw new Error(`failed to parse onion addr: ["'${t.join('", "')}'"]' does not contain a port number`);if(t[0].length!==56)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion3 address.`);let r=Yt.decode(`b${t[0]}`),n=parseInt(t[1],10);if(n<1||n>65536)throw new Error("Port number is not in range(1, 65536)");let o=ge(n);return Rr([r,o],r.length+o.length)}function Js(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=xe(t,"base32"),o=Ye(r);return`${n}:${o}`}var ti=function(e){e=e.toString().trim();let t=new Uint8Array(4);return e.split(/\./g).forEach((r,n)=>{let o=parseInt(r,10);if(isNaN(o)||o<0||o>255)throw new lt("Invalid byte value in IP address");t[n]=o}),t},ef=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=Nn(r[n]),i;s&&(i=ti(r[n]),r[n]=xe(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,xe(i.subarray(2,4),"base16"))}if(r[0]==="")for(;r.length<8;)r.unshift("0");else if(r[r.length-1]==="")for(;r.length<8;)r.push("0");else if(r.length<8){for(n=0;n<r.length&&r[n]!=="";n++);let s=[n,1];for(n=9-r.length;n>0;n--)s.push("0");r.splice.apply(r,s)}let o=new Uint8Array(t+16);for(n=0;n<r.length;n++){r[n]===""&&(r[n]="0");let s=parseInt(r[n],16);if(isNaN(s)||s<0||s>65535)throw new lt("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},rf=function(e){if(e.byteLength!==4)throw new lt("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},nf=function(e){if(e.byteLength!==16)throw new lt("IPv6 address was incorrect length");let t=[];for(let n=0;n<e.byteLength;n+=2){let o=e[n],s=e[n+1],i=`${o.toString(16).padStart(2,"0")}${s.toString(16).padStart(2,"0")}`;t.push(i)}let r=t.join(":");try{let n=new URL(`http://[${r}]`);return n.hostname.substring(1,n.hostname.length-1)}catch{throw new lt(`Invalid IPv6 address "${r}"`)}};function of(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new lt(`Invalid IPv6 address "${e}"`)}}var Ws=Object.values(se).map(e=>e.decoder),yh=(function(){let e=Ws[0].or(Ws[1]);return Ws.slice(2).forEach(t=>e=e.or(t)),e})();function sf(e){return yh.decode(e)}function af(e){return t=>e.encoder.encode(t)}function xh(e){if(parseInt(e).toString()!==e)throw new qt("Value must be an integer")}function gh(e){if(e<0)throw new qt("Value must be a positive integer, or zero")}function wh(e){return t=>{if(t>e)throw new qt(`Value must be smaller than or equal to ${e}`)}}function Eh(...e){return t=>{for(let r of e)r(t)}}var Nr=Eh(xh,gh,wh(65535));var ct=-1,ei=class{protocolsByCode=new Map;protocolsByName=new Map;getProtocol(t){let r;if(typeof t=="string"?r=this.protocolsByName.get(t):r=this.protocolsByCode.get(t),r==null)throw new Un(`Protocol ${t} was unknown`);return r}addProtocol(t){this.protocolsByCode.set(t.code,t),this.protocolsByName.set(t.name,t),t.aliases?.forEach(r=>{this.protocolsByName.set(r,t)})}removeProtocol(t){let r=this.protocolsByCode.get(t);r!=null&&(this.protocolsByCode.delete(r.code),this.protocolsByName.delete(r.name),r.aliases?.forEach(n=>{this.protocolsByName.delete(n)}))}},$t=new ei,Ph=[{code:4,name:"ip4",size:32,valueToBytes:ti,bytesToValue:rf,validate:e=>{if(!Nn(e))throw new qt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ge,bytesToValue:Ye,validate:Nr},{code:273,name:"udp",size:16,valueToBytes:ge,bytesToValue:Ye,validate:Nr},{code:33,name:"dccp",size:16,valueToBytes:ge,bytesToValue:Ye,validate:Nr},{code:41,name:"ip6",size:128,valueToBytes:ef,bytesToValue:nf,stringToValue:of,validate:e=>{if(!Qc(e))throw new qt(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:ct},{code:43,name:"ipcidr",size:8,bytesToValue:Xs("base10"),valueToBytes:Qs("base10")},{code:53,name:"dns",size:ct},{code:54,name:"dns4",size:ct},{code:55,name:"dns6",size:ct},{code:56,name:"dnsaddr",size:ct},{code:132,name:"sctp",size:16,valueToBytes:ge,bytesToValue:Ye,validate:Nr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ct,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:ct,bytesToValue:Xs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Qs("base58btc")(e):ft.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Js,valueToBytes:Jc},{code:445,name:"onion3",size:296,bytesToValue:Js,valueToBytes:tf},{code:446,name:"garlic64",size:ct},{code:447,name:"garlic32",size:ct},{code:448,name:"tls"},{code:449,name:"sni",size:ct},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ct,bytesToValue:af(_s),valueToBytes:sf},{code:480,name:"http"},{code:481,name:"http-path",size:ct,stringToValue:e=>`/${decodeURIComponent(e)}`,valueToString:e=>encodeURIComponent(e.substring(1))},{code:443,name:"https"},{code:477,name:"ws"},{code:478,name:"wss"},{code:479,name:"p2p-websocket-star"},{code:277,name:"p2p-stardust"},{code:275,name:"p2p-webrtc-star"},{code:276,name:"p2p-webrtc-direct"},{code:280,name:"webrtc-direct"},{code:281,name:"webrtc"},{code:290,name:"p2p-circuit"},{code:777,name:"memory",size:ct}];Ph.forEach(e=>{$t.addProtocol(e)});function cf(e){let t=[],r=0;for(;r<e.length;){let n=xs(e,r),o=$t.getProtocol(n),s=Ut(n),i=Nh(o,e,r+s),a=0;i>0&&o.size===ct&&(a=Ut(i));let f=s+a+i,c={code:n,name:o.name,bytes:e.subarray(r,r+f)};if(i>0){let u=r+s+a,d=e.subarray(u,u+i);c.value=o.bytesToValue?.(d)??xe(d)}t.push(c),r+=f}return t}function ff(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=$t.getProtocol(n.code),s=Ut(n.code),i,a=0,f=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??Pr(n.value),a=i.byteLength,o.size===ct&&(f=Ut(a)));let c=new Uint8Array(s+f+a),u=0;Cr(n.code,c,u),u+=s,i!=null&&(o.size===ct&&(Cr(a,c,u),u+=f),c.set(i,u)),n.bytes=c}r.push(n.bytes),t+=n.bytes.byteLength}return Rr(r,t)}function uf(e){if(e.charAt(0)!=="/")throw new lt('String multiaddr must start with "/"');let t=[],r="protocol",n="",o="";for(let s=1;s<e.length;s++){let i=e.charAt(s);i!=="/"&&(r==="protocol"?o+=e.charAt(s):n+=e.charAt(s));let a=s===e.length-1;if(i==="/"||a){let f=$t.getProtocol(o);if(r==="protocol"){if(f.size==null||f.size===0){t.push({code:f.code,name:f.name}),n="",o="",r="protocol";continue}else if(a)throw new lt(`Component ${o} was missing value`);r="value"}else if(r==="value"){let c={code:f.code,name:f.name};if(f.size!=null&&f.size!==0){if(n==="")throw new lt(`Component ${o} was missing value`);c.value=f.stringToValue?.(n)??n}t.push(c),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new lt("Incomplete multiaddr");return t}function df(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=$t.getProtocol(t.code);if(r==null)throw new lt(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Nh(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:xs(t,r)}var Fh=Symbol.for("nodejs.util.inspect.custom"),xi=Symbol.for("@multiformats/multiaddr");function Kh(e){if(e==null&&(e="/"),lf(e))return e.getComponents();if(e instanceof Uint8Array)return cf(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),uf(e);if(Array.isArray(e))return e;throw new lt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var zn=class e{[xi]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Kh(t),r.validate!==!1&&kh(this)}get bytes(){return this.#r==null&&(this.#r=ff(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=df(this.#t)),this.#e}toJSON(){return this.toString()}getComponents(){return[...this.#t.map(t=>({...t}))]}encapsulate(t){let r=new e(t);return new e([...this.#t,...r.getComponents()],{validate:!1})}decapsulate(t){let r=t.toString(),n=this.toString(),o=n.lastIndexOf(r);if(o<0)throw new Ln(`Address ${this.toString()} does not contain subaddress: ${r}`);return new e(n.slice(0,o),{validate:!1})}decapsulateCode(t){let r;for(let n=this.#t.length-1;n>-1;n--)if(this.#t[n].code===t){r=n;break}return new e(this.#t.slice(0,r),{validate:!1})}equals(t){return Zc(this.bytes,t.bytes)}[Fh](){return`Multiaddr(${this.toString()})`}};function kh(e){e.getComponents().forEach(t=>{let r=$t.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function lf(e){return!!e?.[xi]}function hf(e){return new zn(e)}var Z=e=>({match:t=>{let r=t[0];return r==null||r.code!==e||r.value!=null?!1:t.slice(1)}}),U=(e,t)=>({match:r=>{let n=r[0];return n?.code!==e||n.value==null||t!=null&&n.value!==t?!1:r.slice(1)}}),pf=e=>({match:t=>e.match(t)===!1?t:!1}),k=e=>({match:t=>{let r=e.match(t);return r===!1?t:r}}),mt=(...e)=>({match:t=>{let r;for(let n of e){let o=n.match(t);o!==!1&&(r==null||o.length<r.length)&&(r=o)}return r??!1}}),z=(...e)=>({match:t=>{for(let r of e){let n=r.match(t);if(n===!1)return!1;t=n}return t}});function Y(...e){function t(o){if(o==null)return!1;let s=o.getComponents();for(let i of e){let a=i.match(s);if(a===!1)return!1;s=a}return s}function r(o){return t(o)!==!1}function n(o){let s=t(o);return s===!1?!1:s.length===0}return{matchers:e,matches:r,exactMatch:n}}var Mh=U(421),aw=Y(Mh),qn=U(54),jn=U(55),$n=U(56),wi=U(53),cw=Y(qn,k(U(421))),fw=Y(jn,k(U(421))),uw=Y($n,k(U(421))),dw=Y(mt(wi,$n,qn,jn),k(U(421))),mf=z(U(4),k(U(43))),bf=z(k(U(42)),U(41),k(U(43))),Ei=mt(mf,bf),Qe=mt(Ei,wi,qn,jn,$n),lw=Y(mt(Ei,z(mt(wi,$n,qn,jn),k(U(421))))),hw=Y(mf),pw=Y(bf),mw=Y(Ei),Si=z(Qe,U(6)),Fr=z(Qe,U(273)),bw=Y(z(Si,k(U(421)))),yw=Y(Fr),vi=z(Fr,Z(460),k(U(421))),Zn=z(Fr,Z(461),k(U(421))),Vh=mt(vi,Zn),xw=Y(vi),gw=Y(Zn),gi=mt(Qe,Si,Fr,vi,Zn),yf=mt(z(gi,Z(477),k(U(421)))),ww=Y(yf),xf=mt(z(gi,Z(478),k(U(421))),z(gi,Z(448),k(U(449)),Z(477),k(U(421)))),Ew=Y(xf),gf=z(Fr,Z(280),k(U(466)),k(U(466)),k(U(421))),Sw=Y(gf),wf=z(Zn,Z(465),k(U(466)),k(U(466)),k(U(421))),vw=Y(wf),Hn=mt(yf,xf,z(Si,k(U(421))),z(Vh,k(U(421))),z(Qe,k(U(421))),gf,wf,U(421)),Ef=Y(Hn),zh=z(k(Hn),Z(290),pf(Z(281)),k(U(421))),Aw=Y(zh),Hh=mt(z(Hn,Z(290),Z(281),k(U(421))),z(Hn,Z(281),k(U(421))),z(Z(281),k(U(421)))),Bw=Y(Hh),qh=z(Qe,mt(z(U(6,"80")),z(U(6),Z(480)),Z(480)),k(U(481)),k(U(421))),Cw=Y(qh),jh=z(Qe,mt(z(U(6,"443")),z(U(6,"443"),Z(480)),z(U(6),Z(443)),z(U(6),Z(448),Z(480)),z(Z(448),Z(480)),Z(448),Z(443)),k(U(481)),k(U(421))),_w=Y(jh),$h=mt(z(U(777),k(U(421)))),Dw=Y($h),Zh=mt(z(U(400),k(U(421)))),Iw=Y(Zh);var Yh="bootstrap",Gh=50,Wh=1e3,Ai=class extends zr{static tag="bootstrap";log;timer;list;timeout;components;_init;constructor(t,r={list:[]}){if(r.list==null||r.list.length===0)throw new Error("Bootstrap requires a list of peer addresses");super(),this.components=t,this.log=t.logger.forComponent("libp2p:bootstrap"),this.timeout=r.timeout??Wh,this.list=r.list.map(n=>hf(n)).filter(n=>Ef.matches(n)?n.getComponents().findLast(s=>s.code===421)?.value==null?(this.log.error("invalid bootstrap multiaddr without peer id"),!1):!0:(this.log.error("invalid multiaddr %a",n),!1)).map(n=>({id:jc(n.getComponents().findLast(o=>o.code===421)?.value??""),multiaddrs:[n]})),this._init=r}[_i]=this;[Symbol.toStringTag]="@libp2p/bootstrap";[Di]=["@libp2p/peer-discovery"];isStarted(){return!!this.timer}start(){this.isStarted()||(this.log("Starting bootstrap node discovery, discovering peers after %s ms",this.timeout),this.timer=setTimeout(()=>{this._discoverBootstrapPeers().catch(t=>{this.log.error("failed to discover bootstrap peers - %e",t)})},this.timeout))}async _discoverBootstrapPeers(){if(this.timer!=null)for(let t of this.list){if(await this.components.peerStore.merge(t.id,{tags:{[this._init.tagName??Yh]:{value:this._init.tagValue??Gh,ttl:this._init.tagTTL}},multiaddrs:t.multiaddrs}),this.timer==null)return;this.safeDispatchEvent("peer",{detail:t}),this.components.connectionManager.openConnection(t.id).catch(r=>{this.log.error("could not dial bootstrap peer %p - %e",t.id,r)})}}stop(){this.timer!=null&&clearTimeout(this.timer),this.timer=void 0}};function Xh(e){return t=>new Ai(t,e)}return Cf(Qh);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|