@libp2p/bootstrap 12.0.24-a34745c01 → 12.0.25
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/typedoc-urls.json +8 -0
- package/package.json +6 -6
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 Zn=Object.defineProperty;var vf=Object.getOwnPropertyDescriptor;var Af=Object.getOwnPropertyNames;var Bf=Object.prototype.hasOwnProperty;var $=(e,t)=>{for(var r in t)Zn(e,r,{get:t[r],enumerable:!0})},Cf=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Af(t))!Bf.call(e,o)&&o!==r&&Zn(e,o,{get:()=>t[o],enumerable:!(n=vf(t,o))||n.enumerable});return e};var _f=e=>Cf(Zn({},"__esModule",{value:!0}),e);var np={};$(np,{bootstrap:()=>rp});var Lt=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 Vr=class extends Error{static name="InvalidCIDError";constructor(t="Invalid CID"){super(t),this.name="InvalidCIDError"}},zr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var rr=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Bi=Symbol.for("@libp2p/peer-discovery");var Yn=Symbol.for("@libp2p/peer-id");function If(e){return typeof e?.handleEvent=="function"}function Df(e){return(e!==!0&&e!==!1&&e?.once)??!1}var Hr=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 c=this.#t.get(i.type);c!=null&&(c=c.filter(({callback:f})=>f!==r),this.#t.set(i.type,c))}If(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 Ci=Symbol.for("@libp2p/service-capabilities");var Jn={};$(Jn,{base58btc:()=>nt,base58flickr:()=>Nf});var Rp=new Uint8Array(0);function _i(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 fe(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return fe(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function Ii(e){return new TextEncoder().encode(e)}function Di(e){return new TextDecoder().decode(e)}function Tf(e){return e?.buffer instanceof ArrayBuffer}function fe(e){return Tf(e)?e:e.slice()}function Of(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 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,y=0,S=h.length;y!==S&&h[y]===0;)y++,E++;for(var v=(S-y)*u+1>>>0,I=new Uint8Array(v);y!==S;){for(var _=h[y],R=0,O=v-1;(_!==0||R<p)&&O!==-1;O--,R++)_+=256*I[O]>>>0,I[O]=_%c>>>0,_=_/c>>>0;if(_!==0)throw new Error("Non-zero carry");p=R,y++}for(var C=v-p;C!==v&&I[C]===0;)C++;for(var F=f.repeat(E);C<v;++C)F+=e.charAt(I[C]);return F}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,y=0;h[E]===f;)p++,E++;for(var S=(h.length-E)*a+1>>>0,v=new Uint8Array(S);h[E];){var I=r[h.charCodeAt(E)];if(I===255)return;for(var _=0,R=S-1;(I!==0||_<y)&&R!==-1;R--,_++)I+=c*v[R]>>>0,v[R]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");y=_,E++}if(h[E]!==" "){for(var O=S-y;O!==S&&v[O]===0;)O++;for(var C=new Uint8Array(p+(S-O)),F=p;O!==S;)C[F++]=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 Lf=Of,Uf=Lf,Oi=Uf;var Gn=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")}},Wn=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 Li(this,t)}},Xn=class{decoders;constructor(t){this.decoders=t}or(t){return Li(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Li(e,t){return new Xn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Qn=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 Gn(t,r,n),this.decoder=new Wn(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 Qn(e,t,r,n)}function Gt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Oi(r,e);return Be({prefix:t,name:e,encode:n,decode:s=>Nt(o(s))})}function Rf(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 Pf(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 Ff(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=Ff(n);return Be({prefix:t,name:e,encode(s){return Pf(s,n,r)},decode(s){return Rf(s,o,r,e)}})}var nt=Gt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Nf=Gt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var to={};$(to,{base32:()=>Wt,base32hex:()=>Vf,base32hexpad:()=>Hf,base32hexpadupper:()=>qf,base32hexupper:()=>zf,base32pad:()=>Mf,base32padupper:()=>kf,base32upper:()=>Kf,base32z:()=>jf});var Wt=X({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Kf=X({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Mf=X({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),kf=X({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Vf=X({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),zf=X({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Hf=X({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),qf=X({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),jf=X({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var eo={};$(eo,{base36:()=>nr,base36upper:()=>$f});var nr=Gt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),$f=Gt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Zf=Pi,Ui=128,Yf=127,Gf=~Yf,Wf=Math.pow(2,31);function Pi(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Wf;)t[r++]=e&255|Ui,e/=128;for(;e&Gf;)t[r++]=e&255|Ui,e>>>=7;return t[r]=e|0,Pi.bytes=r-n+1,t}var Xf=ro,Qf=128,Ri=127;function ro(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw ro.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Ri)<<o:(i&Ri)*Math.pow(2,o),o+=7}while(i>=Qf);return ro.bytes=s-n,r}var Jf=Math.pow(2,7),tu=Math.pow(2,14),eu=Math.pow(2,21),ru=Math.pow(2,28),nu=Math.pow(2,35),ou=Math.pow(2,42),su=Math.pow(2,49),iu=Math.pow(2,56),cu=Math.pow(2,63),au=function(e){return e<Jf?1:e<tu?2:e<eu?3:e<ru?4:e<nu?5:e<ou?6:e<su?7:e<iu?8:e<cu?9:10},fu={encode:Zf,decode:Xf,encodingLength:au},uu=fu,or=uu;function sr(e,t=0){return[or.decode(e,t),or.decode.bytes]}function Ce(e,t,r=0){return or.encode(e,t,r),t}function _e(e){return or.encodingLength(e)}function De(e,t){let r=t.byteLength,n=_e(e),o=n+_e(r),s=new Uint8Array(o+r);return Ce(e,s,0),Ce(r,s,n),s.set(t,o),new Ie(e,r,t,s)}function ir(e){let t=Nt(e),[r,n]=sr(t),[o,s]=sr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Ie(r,o,i,t)}function Fi(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&_i(e.bytes,r.bytes)}}var Ie=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=fe(n),this.bytes=fe(o)}};function Ni(e,t){let{bytes:r,version:n}=e;return n===0?lu(r,no(e),t??nt.encoder):hu(r,no(e),t??Wt.encoder)}var Ki=new WeakMap;function no(e){let t=Ki.get(e);if(t==null){let r=new Map;return Ki.set(e,r),r}return t}var ut=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=fe(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!==cr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==pu)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=De(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&&Fi(t.multihash,n.multihash)}toString(t){return Ni(this,t)}toJSON(){return{"/":Ni(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??Mi(n,o,s.bytes))}else if(r[mu]===!0){let{version:n,multihash:o,code:s}=r,i=ir(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!==cr)throw new Error(`Version 0 CID must use dag-pb (code: ${cr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Mi(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,cr,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 Ie(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]=sr(t.subarray(r));return r+=g,d},o=n(),s=cr;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]=du(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 no(s).set(n,t),s}};function du(e,t){switch(e[0]){case"Q":{let r=t??nt;return[nt.prefix,r.decode(`${nt.prefix}${e}`)]}case nt.prefix:{let r=t??nt;return[nt.prefix,r.decode(e)]}case Wt.prefix:{let r=t??Wt;return[Wt.prefix,r.decode(e)]}case nr.prefix:{let r=t??nr;return[nr.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 lu(e,t,r){let{prefix:n}=r;if(n!==nt.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 hu(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 cr=112,pu=18;function Mi(e,t,r){let n=_e(e),o=n+_e(t),s=new Uint8Array(o+r.byteLength);return Ce(e,s,0),Ce(t,s,n),s.set(r,o),s}var mu=Symbol.for("@ipld/js-cid/CID");var oo={};$(oo,{identity:()=>Bt});var ki=0,yu="identity",Vi=Nt;function bu(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 De(ki,Vi(e))}var Bt={code:ki,name:yu,encode:Vi,digest:bu};function vt(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 xu(e){return e.buffer instanceof ArrayBuffer}function Kt(e){return xu(e)?e:e.slice()}async function zi(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,Kt(t),Kt(r.subarray()));return n?.signal?.throwIfAborted(),s}function Mt(e=0){return new Uint8Array(e)}function ar(e=0){return new Uint8Array(e)}function so(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ar(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}function Hi(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 ji=Symbol.for("@achingbrain/uint8arraylist");function qi(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function jr(e){return!!e?.[ji]}var wt=class e{bufs;length;[ji]=!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(jr(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(jr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=qi(this.bufs,t);return r.buf[r.index]}set(t,r){let n=qi(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(jr(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 so(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:so(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 d=t-c;n.push(i.subarray(d,d+(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(!jr(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 c=i,f=this.byteLength-n.byteLength,a=n.byteLength-1,u;for(let d=r;d<=f;d+=u){u=0;for(let g=a;g>=0;g--){let m=this.get(d+g);if(n[g]!==m){u=Math.max(1,g-c[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=ar(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=Mt(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=Mt(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=Mt(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=ar(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=Mt(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=Mt(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=Mt(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=Mt(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=Mt(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(!Hi(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 io={};$(io,{base10:()=>gu});var gu=Gt({prefix:"9",name:"base10",alphabet:"0123456789"});var co={};$(co,{base16:()=>wu,base16upper:()=>Eu});var wu=X({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Eu=X({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ao={};$(ao,{base2:()=>Su});var Su=X({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var fo={};$(fo,{base256emoji:()=>_u});var $i=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}"),vu=$i.reduce((e,t,r)=>(e[r]=t,e),[]),Au=$i.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Bu(e){return e.reduce((t,r)=>(t+=vu[r],t),"")}function Cu(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Au[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var _u=Be({prefix:"\u{1F680}",name:"base256emoji",encode:Bu,decode:Cu});var lo={};$(lo,{base64:()=>Iu,base64pad:()=>Du,base64url:()=>uo,base64urlpad:()=>Tu});var Iu=X({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Du=X({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),uo=X({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Tu=X({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ho={};$(ho,{base8:()=>Ou});var Ou=X({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var po={};$(po,{identity:()=>Lu});var Lu=Be({prefix:"\0",name:"identity",encode:e=>Di(e),decode:e=>Ii(e)});var E0=new TextEncoder,S0=new TextDecoder;var bo={};$(bo,{sha256:()=>fr,sha512:()=>Fu});var Pu=20;function yo({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new mo(e,t,r,n,o)}var mo=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Pu,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?Zi(n,this.code,r?.truncate):n.then(o=>Zi(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Zi(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return De(t,e)}function Gi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var fr=yo({name:"sha2-256",code:18,encode:Gi("SHA-256")}),Fu=yo({name:"sha2-512",code:19,encode:Gi("SHA-512")});var ur={...po,...ao,...ho,...io,...co,...to,...eo,...Jn,...lo,...fo},R0={...bo,...oo};function ue(e=0){return new Uint8Array(e)}function Xi(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Wi=Xi("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),xo=Xi("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=ue(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Nu={utf8:Wi,"utf-8":Wi,hex:ur.base16,latin1:xo,ascii:xo,binary:xo,...ur},$r=Nu;function At(e,t="utf8"){let r=$r[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function et(e,t="utf8"){let r=$r[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var Ku=parseInt("11111",2),go=parseInt("10000000",2),Mu=parseInt("01111111",2),Qi={0:dr,1:dr,2:ku,3:Hu,4:qu,5:zu,6:Vu,16:dr,22:dr,48:dr};function wo(e,t={offset:0}){let r=e[t.offset]&Ku;if(t.offset++,Qi[r]!=null)return Qi[r](e,t);throw new Error("No decoder for tag "+r)}function lr(e,t){let r=0;if((e[t.offset]&go)===go){let n=e[t.offset]&Mu,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 dr(e,t){lr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=wo(e,t);if(n===null)break;r.push(n)}return r}function ku(e,t){let r=lr(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 Vu(e,t){let r=lr(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 d=0;d<f.length;d++)u+=f[d]<<d*7;c+=`.${u}`,f=[]}}return c}function zu(e,t){return t.offset++,null}function Hu(e,t){let r=lr(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 qu(e,t){let r=lr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function ju(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 Eo(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=ju(e.byteLength);return new wt(Uint8Array.from([t.byteLength|go]),t)}function Ji(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]),Eo(t),t)}function tc(e){let t=Uint8Array.from([0]),r=new wt(t,e);return new wt(Uint8Array.from([3]),Eo(r),r)}function Zr(e,t=48){let r=new wt;for(let n of e)r.append(n);return new wt(Uint8Array.from([t]),Eo(r),r)}var $u=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Zu=Uint8Array.from([6,5,43,129,4,0,34]),Yu=Uint8Array.from([6,5,43,129,4,0,35]),Gu={ext:!0,kty:"EC",crv:"P-256"},Wu={ext:!0,kty:"EC",crv:"P-384"},Xu={ext:!0,kty:"EC",crv:"P-521"},So=32,vo=48,Ao=66;function ec(e){let t=wo(e);return rc(t)}function rc(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===So*2+1)return n=et(t.subarray(r,r+So),"base64url"),o=et(t.subarray(r+So),"base64url"),new Oe({...Gu,key_ops:["verify"],x:n,y:o});if(t.byteLength===vo*2+1)return n=et(t.subarray(r,r+vo),"base64url"),o=et(t.subarray(r+vo),"base64url"),new Oe({...Wu,key_ops:["verify"],x:n,y:o});if(t.byteLength===Ao*2+1)return n=et(t.subarray(r,r+Ao),"base64url"),o=et(t.subarray(r+Ao),"base64url"),new Oe({...Xu,key_ops:["verify"],x:n,y:o});throw new Lt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function nc(e){return Zr([Ji(Uint8Array.from([1])),Zr([Qu(e.crv)],160),Zr([tc(new wt(Uint8Array.from([4]),At(e.x??"","base64url"),At(e.y??"","base64url")))],161)]).subarray()}function Qu(e){if(e==="P-256")return $u;if(e==="P-384")return Zu;if(e==="P-521")return Yu;throw new Lt(`Invalid curve ${e}`)}var Oe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=nc(this.jwk)),this._raw}toMultihash(){return Bt.digest(Le(this))}toCID(){return ut.createV1(114,this.toMultihash())}toString(){return nt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:vt(this.raw,t.raw)}async verify(t,r,n){return zi(this.jwk,r,t,n)}};function Bo(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in e&&e.BYTES_PER_ELEMENT===1}function Xt(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 Et(e,t,r=""){let n=Bo(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 Yr(e){if(typeof e!="function"||typeof e.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Xt(e.outputLen),Xt(e.blockLen),e.outputLen<1)throw new Error('"outputLen" must be >= 1');if(e.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Ue(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 Gr(e,t){Et(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 Vt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Wr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Ct(e,t){return e<<32-t|e>>>t}var sc=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Ju=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Xr(e){if(Et(e),sc)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Ju[e[r]];return t}var kt={_0:48,_9:57,A:65,F:70,a:97,f:102};function oc(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 hr(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(sc)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=oc(e.charCodeAt(s)),c=oc(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 Co(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];Et(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 _o(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 ic(e=32){Xt(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 Io=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function cc(e,t,r){return e&t^~e&r}function ac(e,t,r){return e&t^e&r^t&r}var pr=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=Wr(this.buffer)}update(t){Ue(this),Et(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=Wr(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){Ue(this),Gr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Vt(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 c=Wr(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 d=0;d<a;d++)c.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: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()}},zt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var dt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Qr=BigInt(4294967295),fc=BigInt(32);function td(e,t=!1){return t?{h:Number(e&Qr),l:Number(e>>fc&Qr)}:{h:Number(e>>fc&Qr)|0,l:Number(e&Qr)|0}}function uc(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}=td(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Do=(e,t,r)=>e>>>r,To=(e,t,r)=>e<<32-r|t>>>r,de=(e,t,r)=>e>>>r|t<<32-r,le=(e,t,r)=>e<<32-r|t>>>r,mr=(e,t,r)=>e<<64-r|t>>>r-32,yr=(e,t,r)=>e>>>r-32|t<<64-r;function Ut(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var dc=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),lc=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,hc=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),pc=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,mc=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),yc=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var rd=Uint32Array.from([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Qt=new Uint32Array(64),Oo=class extends pr{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 d=0;d<16;d++,r+=4)Qt[d]=t.getUint32(r,!1);for(let d=16;d<64;d++){let g=Qt[d-15],m=Qt[d-2],h=Ct(g,7)^Ct(g,18)^g>>>3,E=Ct(m,17)^Ct(m,19)^m>>>10;Qt[d]=E+Qt[d-7]+h+Qt[d-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:f,G:a,H:u}=this;for(let d=0;d<64;d++){let g=Ct(c,6)^Ct(c,11)^Ct(c,25),m=u+g+cc(c,f,a)+rd[d]+Qt[d]|0,E=(Ct(n,2)^Ct(n,13)^Ct(n,22))+ac(n,o,s)|0;u=a,a=f,f=c,c=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,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(){Vt(Qt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Vt(this.buffer)}},Lo=class extends Oo{A=zt[0]|0;B=zt[1]|0;C=zt[2]|0;D=zt[3]|0;E=zt[4]|0;F=zt[5]|0;G=zt[6]|0;H=zt[7]|0;constructor(){super(32)}};var bc=uc(["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))),nd=bc[0],od=bc[1],Jt=new Uint32Array(80),te=new Uint32Array(80),Uo=class extends pr{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:d,Fl:g,Gh:m,Gl:h,Hh:E,Hl:p}=this;return[t,r,n,o,s,i,c,f,a,u,d,g,m,h,E,p]}set(t,r,n,o,s,i,c,f,a,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=c|0,this.Dl=f|0,this.Eh=a|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)Jt[v]=t.getUint32(r),te[v]=t.getUint32(r+=4);for(let v=16;v<80;v++){let I=Jt[v-15]|0,_=te[v-15]|0,R=de(I,_,1)^de(I,_,8)^Do(I,_,7),O=le(I,_,1)^le(I,_,8)^To(I,_,7),C=Jt[v-2]|0,F=te[v-2]|0,j=de(C,F,19)^mr(C,F,61)^Do(C,F,6),N=le(C,F,19)^yr(C,F,61)^To(C,F,6),l=hc(O,N,te[v-7],te[v-16]),b=pc(l,R,j,Jt[v-7],Jt[v-16]);Jt[v]=b|0,te[v]=l|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:f,Dh:a,Dl:u,Eh:d,El:g,Fh:m,Fl:h,Gh:E,Gl:p,Hh:y,Hl:S}=this;for(let v=0;v<80;v++){let I=de(d,g,14)^de(d,g,18)^mr(d,g,41),_=le(d,g,14)^le(d,g,18)^yr(d,g,41),R=d&m^~d&E,O=g&h^~g&p,C=mc(S,_,O,od[v],te[v]),F=yc(C,y,I,R,nd[v],Jt[v]),j=C|0,N=de(n,o,28)^mr(n,o,34)^mr(n,o,39),l=le(n,o,28)^yr(n,o,34)^yr(n,o,39),b=n&s^n&c^s&c,A=o&i^o&f^i&f;y=E|0,S=p|0,E=m|0,p=h|0,m=d|0,h=g|0,{h:d,l:g}=Ut(a|0,u|0,F|0,j|0),a=c|0,u=f|0,c=s|0,f=i|0,s=n|0,i=o|0;let w=dc(j,l,A);n=lc(w,F,N,b),o=w|0}({h:n,l:o}=Ut(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ut(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:f}=Ut(this.Ch|0,this.Cl|0,c|0,f|0),{h:a,l:u}=Ut(this.Dh|0,this.Dl|0,a|0,u|0),{h:d,l:g}=Ut(this.Eh|0,this.El|0,d|0,g|0),{h:m,l:h}=Ut(this.Fh|0,this.Fl|0,m|0,h|0),{h:E,l:p}=Ut(this.Gh|0,this.Gl|0,E|0,p|0),{h:y,l:S}=Ut(this.Hh|0,this.Hl|0,y|0,S|0),this.set(n,o,s,i,c,f,a,u,d,g,m,h,E,p,y,S)}roundClean(){Vt(Jt,te)}destroy(){this.destroyed=!0,Vt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Ro=class extends Uo{Ah=dt[0]|0;Al=dt[1]|0;Bh=dt[2]|0;Bl=dt[3]|0;Ch=dt[4]|0;Cl=dt[5]|0;Dh=dt[6]|0;Dl=dt[7]|0;Eh=dt[8]|0;El=dt[9]|0;Fh=dt[10]|0;Fl=dt[11]|0;Gh=dt[12]|0;Gl=dt[13]|0;Hh=dt[14]|0;Hl=dt[15]|0;constructor(){super(64)}};var xc=_o(()=>new Lo,Io(1));var Jr=_o(()=>new Ro,Io(3));var V=(e,t,r)=>Et(e,t,r),Fo=Xt,Re=Xr,st=(...e)=>Co(...e),Pe=e=>hr(e),he=Bo,br=e=>ic(e),en=BigInt(0),Po=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 rn(e){if(typeof e=="bigint"){if(!tn(e))throw new RangeError("positive bigint expected, got "+e)}else Fo(e);return e}function It(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 xr(e){let t=rn(e).toString(16);return t.length&1?"0"+t:t}function gc(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?en:BigInt("0x"+e)}function pe(e){return gc(Xr(e))}function Rt(e){return gc(Xr(gr(Et(e)).reverse()))}function nn(e,t){if(Xt(t),t===0)throw new RangeError("zero length");e=rn(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return hr(r.padStart(t*2,"0"))}function No(e,t){return nn(e,t).reverse()}function wc(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 gr(e){return Uint8Array.from(V(e))}function on(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 tn=e=>typeof e=="bigint"&&en<=e;function sd(e,t,r){return tn(e)&&tn(t)&&tn(r)&&t<=e&&e<r}function Fe(e,t,r,n){if(!sd(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ne(e){if(e<en)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>en;e>>=Po,t+=1);return t}var wr=e=>(Po<<BigInt(e))-Po;function Ec(e,t,r){if(Xt(e,"hashLen"),Xt(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),c=1e3,f=n(e),a=n(e),u=0,d=()=>{f.fill(1),a.fill(0),u=0},g=(...p)=>r(a,st(f,...p)),m=(p=o)=>{a=g(s,p),f=g(),p.length!==0&&(a=g(i,p),f=g())},h=()=>{if(u++>=c)throw new Error("drbg: tried max amount of iterations");let p=0,y=[];for(;p<t;){f=g();let S=f.slice();y.push(S),p+=f.length}return st(...y)};return(p,y)=>{d(),m(p);let S;for(;(S=y(h()))===void 0;)m();return d(),S}}function Dt(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 Ko=()=>{throw new Error("not implemented")};var lt=BigInt(0),Q=BigInt(1),me=BigInt(2),Bc=BigInt(3),Cc=BigInt(4),_c=BigInt(5),id=BigInt(7),Ic=BigInt(8),cd=BigInt(9),Dc=BigInt(16);function rt(e,t){if(t<=lt)throw new Error("mod: expected positive modulus, got "+t);let r=e%t;return r>=lt?r:t+r}function G(e,t,r){if(t<lt)throw new Error("pow2: expected non-negative exponent, got "+t);let n=e;for(;t-- >lt;)n*=n,n%=r;return n}function Sc(e,t){if(e===lt)throw new Error("invert: expected non-zero number");if(t<=lt)throw new Error("invert: expected positive modulus, got "+t);let r=rt(e,t),n=t,o=lt,s=Q,i=Q,c=lt;for(;r!==lt;){let a=n/r,u=n-r*a,d=o-i*a,g=s-c*a;n=r,r=u,o=i,s=c,i=d,c=g}if(n!==Q)throw new Error("invert: does not exist");return rt(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 Tc(e,t){let r=e,n=(r.ORDER+Q)/Cc,o=r.pow(t,n);return Mo(r,o,t),o}function ad(e,t){let r=e,n=(r.ORDER-_c)/Ic,o=r.mul(t,me),s=r.pow(o,n),i=r.mul(t,s),c=r.mul(r.mul(i,me),s),f=r.mul(i,r.sub(c,r.ONE));return Mo(r,f,t),f}function fd(e){let t=Ke(e),r=Oc(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+id)/Dc;return((c,f)=>{let a=c,u=a.pow(f,i),d=a.mul(u,n),g=a.mul(u,o),m=a.mul(u,s),h=a.eql(a.sqr(d),f),E=a.eql(a.sqr(g),f);u=a.cmov(u,d,h),d=a.cmov(m,g,E);let p=a.eql(a.sqr(d),f),y=a.cmov(u,d,p);return Mo(a,y,f),y})}function Oc(e){if(e<Bc)throw new Error("sqrt is not defined for small field");let t=e-Q,r=0;for(;t%me===lt;)t/=me,r++;let n=me,o=Ke(e);for(;vc(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Tc;let s=o.pow(n,t),i=(t+Q)/me;return function(f,a){let u=f;if(u.is0(a))return a;if(vc(u,a)!==1)throw new Error("Cannot find square root");let d=r,g=u.mul(u.ONE,s),m=u.pow(a,t),h=u.pow(a,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 y=Q<<BigInt(d-E-1),S=u.pow(g,y);d=E,g=u.sqr(S),m=u.mul(m,g),h=u.mul(h,S)}return h}}function ud(e){return e%Cc===Bc?Tc:e%Ic===_c?ad:e%Dc===cd?fd(e):Oc(e)}var Ht=(e,t)=>(rt(e,t)&Q)===Q,dd=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function ko(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=dd.reduce((n,o)=>(n[o]="function",n),t);if(Dt(e,r),It(e.BYTES,"BYTES"),It(e.BITS,"BITS"),e.BYTES<1||e.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(e.ORDER<=Q)throw new Error("invalid field: expected ORDER > 1, got "+e.ORDER);return e}function ld(e,t,r){let n=e;if(r<lt)throw new Error("invalid exponent, negatives unsupported");if(r===lt)return n.ONE;if(r===Q)return t;let o=n.ONE,s=t;for(;r>lt;)r&Q&&(o=n.mul(o,s)),s=n.sqr(s),r>>=Q;return o}function Er(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 vc(e,t){let r=e,n=(r.ORDER-Q)/me,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 hd(e,t){if(t!==void 0&&Fo(t),e<=lt)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=Ne(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 Ac=new WeakMap,sn=class{ORDER;BITS;BYTES;isLE;ZERO=lt;ONE=Q;_lengths;_mod;constructor(t,r={}){if(t<=Q)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}=hd(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 rt(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return lt<=t&&t<this.ORDER}is0(t){return t===lt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&Q)===Q}neg(t){return rt(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return rt(t*t,this.ORDER)}add(t,r){return rt(t+r,this.ORDER)}sub(t,r){return rt(t-r,this.ORDER)}mul(t,r){return rt(t*r,this.ORDER)}pow(t,r){return ld(this,t,r)}div(t,r){return rt(t*Sc(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 Sc(t,this.ORDER)}sqrt(t){let r=Ac.get(this);return r||Ac.set(this,r=ud(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?No(t,this.BYTES):nn(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?Rt(t):pe(t);if(c&&(f=rt(f,i)),!r&&!this.isValid(f))throw new Error("invalid field element: outside of range 0..ORDER");return f}invertBatch(t){return Er(this,t)}cmov(t,r,n){return _t(n,"condition"),n?r:t}};Object.freeze(sn.prototype);function Ke(e,t={}){return new sn(e,t)}function Lc(e){if(typeof e!="bigint")throw new Error("field order must be bigint");if(e<=Q)throw new Error("field order must be greater than 1");let t=Ne(e-Q);return Math.ceil(t/8)}function Vo(e){let t=Lc(e);return t+Math.ceil(t/2)}function zo(e,t,r=!1){V(e);let n=e.length,o=Lc(t),s=Math.max(Vo(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Rt(e):pe(e),c=rt(i,t-Q)+Q;return r?No(c,o):nn(c,o)}var Me=BigInt(0),ye=BigInt(1);function Sr(e,t){let r=t.negate();return e?r:t}function be(e,t){let r=Er(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function Fc(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Ho(e,t){Fc(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=wr(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Uc(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+=ye);let a=t*n,u=a+Math.abs(c)-1,d=c===0,g=c<0,m=t%2!==0;return{nextN:f,offset:u,isZero:d,isNeg:g,isNegF:m,offsetF:a}}var qo=new WeakMap,Nc=new WeakMap;function jo(e){return Nc.get(e)||1}function Rc(e){if(e!==Me)throw new Error("invalid wNAF")}var ke=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>Me;)r&ye&&(n=n.add(o)),o=o.double(),r>>=ye;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=Ho(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=Ho(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:f,offset:a,isZero:u,isNeg:d,isNegF:g,offsetF:m}=Uc(n,c,i);n=f,u?s=s.add(Sr(g,r[m])):o=o.add(Sr(d,r[a]))}return Rc(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=Ho(t,this.bits);for(let i=0;i<s.windows&&n!==Me;i++){let{nextN:c,offset:f,isZero:a,isNeg:u}=Uc(n,i,s);if(n=c,!a){let d=r[f];o=o.add(u?d.negate():d)}}return Rc(n),o}getPrecomputes(t,r,n){let o=qo.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),qo.set(r,o))),o}cached(t,r,n){let o=jo(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=jo(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){Fc(r,this.bits),Nc.set(t,r),qo.delete(t)}hasCache(t){return jo(t)!==1}};function Kc(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Me||n>Me;)r&ye&&(s=s.add(o)),n&ye&&(i=i.add(o)),o=o.double(),r>>=ye,n>>=ye;return{p1:s,p2:i}}function Pc(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return ko(t),t}else return Ke(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 a=t[f];if(!(typeof a=="bigint"&&a>Me))throw new Error(`CURVE.${f} must be positive bigint`)}let o=Pc(t.p,r.Fp,n),s=Pc(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 an(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var ee=BigInt(0),at=BigInt(1),$o=BigInt(2),pd=BigInt(8);function md(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 Mc(e,t={}){let r=t,n=cn("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:c}=i;Dt(r,{},{uvRatio:"function"});let f=$o<<BigInt(s.BYTES*8)-at,a=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:ee}}}:r.uvRatio;if(!md(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function d(E,p,y=!1){let S=y?at:ee;return Fe("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,a(i.Gx*i.Gy));static ZERO=new m(ee,at,at,ee);static Fp=o;static Fn=s;X;Y;Z;T;constructor(p,y,S,v){this.X=d("x",p),this.Y=d("y",y),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:y,y:S}=p||{};return d("x",y),d("y",S),new m(y,S,at,a(y*S))}static fromBytes(p,y=!1){let S=o.BYTES,{a:v,d:I}=i;p=gr(V(p,S,"point")),_t(y,"zip215");let _=gr(p),R=p[S-1];_[S-1]=R&-129;let O=Rt(_),C=y?f:o.ORDER;Fe("point.y",O,ee,C);let F=a(O*O),j=a(F-at),N=a(I*F-v),{isValid:l,value:b}=u(j,N);if(!l)throw new Error("bad point: invalid y coordinate");let A=(b&at)===at,w=(R&128)!==0;if(!y&&b===ee&&w)throw new Error("bad point: x=0 and x_0=1");return w!==A&&(b=a(-b)),m.fromAffine({x:b,y:O})}static fromHex(p,y=!1){return m.fromBytes(Pe(p),y)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(p=8,y=!0){return h.createCache(this,p),y||this.multiply($o),this}assertValidity(){let p=this,{a:y,d:S}=i;if(p.is0())throw new Error("bad point: ZERO");let{X:v,Y:I,Z:_,T:R}=p,O=a(v*v),C=a(I*I),F=a(_*_),j=a(F*F),N=a(O*y),l=a(F*a(N+C)),b=a(j+a(S*a(O*C)));if(l!==b)throw new Error("bad point: equation left != right (1)");let A=a(v*I),w=a(_*R);if(A!==w)throw new Error("bad point: equation left != right (2)")}equals(p){g(p);let{X:y,Y:S,Z:v}=this,{X:I,Y:_,Z:R}=p,O=a(y*R),C=a(I*v),F=a(S*R),j=a(_*v);return O===C&&F===j}is0(){return this.equals(m.ZERO)}negate(){return new m(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:p}=i,{X:y,Y:S,Z:v}=this,I=a(y*y),_=a(S*S),R=a($o*a(v*v)),O=a(p*I),C=y+S,F=a(a(C*C)-I-_),j=O+_,N=j-R,l=O-_,b=a(F*N),A=a(j*l),w=a(F*l),x=a(N*j);return new m(b,A,x,w)}add(p){g(p);let{a:y,d:S}=i,{X:v,Y:I,Z:_,T:R}=this,{X:O,Y:C,Z:F,T:j}=p,N=a(v*O),l=a(I*C),b=a(R*S*j),A=a(_*F),w=a((v+I)*(O+C)-N-l),x=A-b,B=A+b,T=a(l-y*N),D=a(w*x),L=a(B*T),P=a(w*T),k=a(x*B);return new m(D,L,k,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:y,f:S}=h.cached(this,p,v=>be(m,v));return be(m,[y,S])[0]}multiplyUnsafe(p){if(!s.isValid(p))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return p===ee?m.ZERO:this.is0()||p===at?this:h.unsafe(this,p,y=>be(m,y))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return h.unsafe(this,i.n).is0()}toAffine(p){let y=this,S=p,{X:v,Y:I,Z:_}=y,R=y.is0();S==null&&(S=R?pd:o.inv(_));let O=a(v*S),C=a(I*S),F=o.mul(_,S);if(R)return{x:ee,y:at};if(F!==at)throw new Error("invZ was invalid");return{x:O,y:C}}clearCofactor(){return c===at?this:this.multiplyUnsafe(c)}toBytes(){let{x:p,y}=this.toAffine(),S=o.toBytes(y);return S[S.length-1]|=p&at?128:0,S}toHex(){return Re(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let h=new ke(m,s.BITS);return s.BITS>=8&&m.BASE.precompute(8),Object.freeze(m.prototype),Object.freeze(m),m}var fn=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){Ko()}static fromHex(t){Ko()}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 Re(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 kc(e,t,r={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=r;Dt(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&&(It(a,"hash.outputLen"),a!==u))throw new Error(`hash.outputLen must be ${u}, got ${a}`);let d=o.randomBytes===void 0?br:o.randomBytes,g=o.adjustScalarBytes===void 0?l=>l:o.adjustScalarBytes,m=o.domain===void 0?(l,b,A)=>{if(_t(A,"phflag"),b.length||A)throw new Error("Contexts/pre-hash are not supported");return l}:o.domain;function h(l){return f.create(Rt(l))}function E(l){let b=O.secretKey;V(l,O.secretKey,"secretKey");let A=V(n(l),2*b,"hashedSecretKey"),w=g(A.slice(0,b)),x=A.slice(b,2*b),B=h(w);return{head:w,prefix:x,scalar:B}}function p(l){let{head:b,prefix:A,scalar:w}=E(l),x=i.multiply(w),B=x.toBytes();return{head:b,prefix:A,scalar:w,point:x,pointBytes:B}}function y(l){return p(l).pointBytes}function S(l=Uint8Array.of(),...b){let A=st(...b);return h(n(m(A,V(l,void 0,"context"),!!s)))}function v(l,b,A={}){l=V(l,void 0,"message"),s&&(l=s(l));let{prefix:w,scalar:x,pointBytes:B}=p(b),T=S(A.context,w,l),D=i.multiply(T).toBytes(),L=S(A.context,D,B,l),P=f.create(T+L*x);if(!f.isValid(P))throw new Error("sign failed: invalid s");let k=st(D,f.toBytes(P));return V(k,O.signature,"result")}let I={zip215:o.zip215};function _(l,b,A,w=I){let{context:x}=w,B=w.zip215===void 0?!!I.zip215:w.zip215,T=O.signature;l=V(l,T,"signature"),b=V(b,void 0,"message"),A=V(A,O.publicKey,"publicKey"),B!==void 0&&_t(B,"zip215"),s&&(b=s(b));let D=T/2,L=l.subarray(0,D),P=Rt(l.subarray(D,T)),k,H,K;try{k=e.fromBytes(A,B),H=e.fromBytes(L,B),K=i.multiplyUnsafe(P)}catch{return!1}if(!B&&k.isSmallOrder())return!1;let ot=S(x,L,A,b);return H.add(k.multiplyUnsafe(ot)).subtract(K).clearCofactor().is0()}let R=c.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 F(l){return he(l)&&l.length===O.secretKey}function j(l,b){try{return!!e.fromBytes(l,b===void 0?I.zip215:b)}catch{return!1}}let N={getExtendedPublicKey:p,randomSecretKey:C,isValidSecretKey:F,isValidPublicKey:j,toMontgomery(l){let{y:b}=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?c.div(at+b,at-b):c.div(b-at,b+at);return c.toBytes(x)},toMontgomerySecret(l){let b=O.secretKey;V(l,b);let A=n(l.subarray(0,b));return g(A).subarray(0,b)}};return Object.freeze(O),Object.freeze(N),Object.freeze({keygen:an(C,y),getPublicKey:y,sign:v,verify:_,utils:N,Point:e,lengths:O})}function vr(e,t){if(It(e),It(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 yd(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 bd(e){if(!he(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?on(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function Zo(e,t,r,n){V(e),It(r),t=bd(t),t.length>255&&(t=n(st(on("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=st(t,vr(t.length,1)),f=new Uint8Array(s),a=vr(r,2),u=new Array(i),d=n(st(f,e,a,vr(0,1),c));u[0]=n(st(d,vr(1,1),c));for(let m=1;m<i;m++){let h=[yd(d,u[m-1]),vr(m+1,1),c];u[m]=n(st(...h))}return st(...u).slice(0,r)}var Vc="HashToScalar-";var xd=BigInt(0),qt=BigInt(1),zc=BigInt(2);var gd=BigInt(5),wd=BigInt(8),Ve=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Xo={p:Ve,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:wd,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Ed(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ve,c=e*e%s*e%s,f=G(c,zc,s)*c%s,a=G(f,qt,s)*e%s,u=G(a,gd,s)*a%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,zc,s)*e%s,b2:c}}function Sd(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var Yo=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Qo(e,t){let r=Ve,n=rt(t*t*t,r),o=rt(n*n*t,r),s=Ed(e*o).pow_p_5_8,i=rt(e*n*s,r),c=rt(t*i*i,r),f=i,a=rt(i*Yo,r),u=c===e,d=c===rt(-e,r),g=c===rt(-e*Yo,r);return u&&(i=f),(d||g)&&(i=a),Ht(i,r)&&(i=rt(-i,r)),{isValid:u||d,value:i}}var ne=Mc(Xo,{uvRatio:Qo}),re=ne.Fp,jc=ne.Fn;function vd(e){return kc(ne,Jr,Object.assign({adjustScalarBytes:Sd,zip215:!0},e))}var $c=vd({});var Go=Yo,Ad=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),Bd=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Cd=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),_d=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Hc=e=>Qo(qt,e),Id=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Wo=e=>re.create(Rt(e)&Id);function qc(e){let{d:t}=Xo,r=Ve,n=y=>re.create(y),o=n(Go*e*e),s=n((o+qt)*Cd),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:f,value:a}=Qo(s,c),u=n(a*e);Ht(u,r)||(u=n(-u)),f||(a=u),f||(i=o);let d=n(i*(o-qt)*_d-c),g=a*a,m=n((a+a)*c),h=n(d*Ad),E=n(qt-g),p=n(qt+g);return new ne(n(m*p),n(E*h),n(h*p),n(m*E))}var oe=class e extends fn{static BASE=new e(ne.BASE);static ZERO=new e(ne.ZERO);static Fp=re;static Fn=jc;constructor(t){super(t)}static fromAffine(t){return new e(ne.fromAffine(t))}assertSame(t){if(!(t instanceof e))throw new Error("RistrettoPoint expected")}init(t){return new e(t)}static fromBytes(t){Et(t,32);let{a:r,d:n}=Xo,o=Ve,s=I=>re.create(I),i=Wo(t);if(!wc(re.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),d=s(a*a),g=s(r*n*u-d),{isValid:m,value:h}=Hc(s(g*d)),E=s(h*a),p=s(h*E*g),y=s((i+i)*E);Ht(y,o)&&(y=s(-y));let S=s(f*p),v=s(y*S);if(!m||Ht(v,o)||S===xd)throw new Error("invalid ristretto255 encoding 2");return new e(new ne(y,S,qt,v))}static fromHex(t){return e.fromBytes(hr(t))}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Ve,i=p=>re.create(p),c=i(i(n+r)*i(n-r)),f=i(t*r),a=i(f*f),{value:u}=Hc(i(c*a)),d=i(u*c),g=i(u*f),m=i(d*g*o),h;if(Ht(o*m,s)){let p=i(r*Go),y=i(t*Go);t=p,r=y,h=i(d*Bd)}else h=g;Ht(t*m,s)&&(r=i(-r));let E=i((n-r)*h);return Ht(E,s)&&(E=i(-E)),re.toBytes(E)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=a=>re.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(oe.BASE);Object.freeze(oe.ZERO);Object.freeze(oe.prototype);Object.freeze(oe);var Dd=Object.freeze({Point:oe,hashToCurve(e,t){let r=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=Zo(e,r,64,Jr);return Dd.deriveToCurve(n)},hashToScalar(e,t={DST:Vc}){let r=Zo(e,t.DST,64,Jr);return jc.create(Rt(r))},deriveToCurve(e){Et(e,64);let t=Wo(e.subarray(0,32)),r=qc(t),n=Wo(e.subarray(32,64)),o=qc(n);return new oe(r.add(o))}});var Ar=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},un=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var dn={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new un("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 ln=32;var Jo,Td=(async()=>{try{return await dn.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Od(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await dn.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await dn.get().subtle.verify({name:"Ed25519"},n,Kt(t),Kt(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function Ld(e,t,r){return $c.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function Zc(e,t,r){return Jo==null&&(Jo=await Td),Jo?Od(e,t,r):Ld(e,t,r)}function Ud(e){return e?.buffer instanceof ArrayBuffer}function ts(e){if(Ud(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function xe(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ue(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return ts(r)}function hn(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var pn=class{type="Ed25519";raw;constructor(t){this.raw=es(t,ln)}toMultihash(){return Bt.digest(Le(this))}toCID(){return ut.createV1(114,this.toMultihash())}toString(){return nt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:vt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=Zc(this.raw,r,t);return hn(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Gc(e){return e=es(e,ln),new pn(e)}function es(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new Lt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var Pd=Math.pow(2,7),Fd=Math.pow(2,14),Nd=Math.pow(2,21),Wc=Math.pow(2,28),Xc=Math.pow(2,35),Qc=Math.pow(2,42),Jc=Math.pow(2,49),bt=128,se=127;function Br(e){if(e<Pd)return 1;if(e<Fd)return 2;if(e<Nd)return 3;if(e<Wc)return 4;if(e<Xc)return 5;if(e<Qc)return 6;if(e<Jc)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ta(e,t,r=0){switch(Br(e)){case 8:t[r++]=e&255|bt,e/=128;case 7:t[r++]=e&255|bt,e/=128;case 6:t[r++]=e&255|bt,e/=128;case 5:t[r++]=e&255|bt,e/=128;case 4:t[r++]=e&255|bt,e>>>=7;case 3:t[r++]=e&255|bt,e>>>=7;case 2:t[r++]=e&255|bt,e>>>=7;case 1:{t[r++]=e&255,e>>>=7;break}default:throw new Error("unreachable")}return t}function ea(e,t){let r=e[t],n=0;if(n+=r&se,r<bt||(r=e[t+1],n+=(r&se)<<7,r<bt)||(r=e[t+2],n+=(r&se)<<14,r<bt)||(r=e[t+3],n+=(r&se)<<21,r<bt)||(r=e[t+4],n+=(r&se)*Wc,r<bt)||(r=e[t+5],n+=(r&se)*Xc,r<bt)||(r=e[t+6],n+=(r&se)*Qc,r<bt)||(r=e[t+7],n+=(r&se)*Jc,r<bt))return n;throw new RangeError("Could not decode varint")}var rs=new Float32Array([-0]),ie=new Uint8Array(rs.buffer);function ra(e,t,r){rs[0]=e,t[r]=ie[0],t[r+1]=ie[1],t[r+2]=ie[2],t[r+3]=ie[3]}function na(e,t){return ie[0]=e[t],ie[1]=e[t+1],ie[2]=e[t+2],ie[3]=e[t+3],rs[0]}var ns=new Float64Array([-0]),pt=new Uint8Array(ns.buffer);function oa(e,t,r){ns[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 sa(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],ns[0]}var Kd=BigInt(Number.MAX_SAFE_INTEGER),Md=BigInt(Number.MIN_SAFE_INTEGER),St=class e{lo;hi;constructor(t,r){this.lo=t|0,this.hi=r|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(r+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(t=!1){if(t)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let r=~this.lo+1>>>0,n=~this.hi>>>0;return r===0&&(n=n+1>>>0),-(BigInt(r)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(t=!1){return this.toBigInt(t).toString()}zzEncode(){let t=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^t)>>>0,this.lo=(this.lo<<1^t)>>>0,this}zzDecode(){let t=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^t)>>>0,this.hi=(this.hi>>>1^t)>>>0,this}length(){let t=this.lo,r=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?r===0?t<16384?t<128?1:2:t<2097152?3:4:r<16384?r<128?5:6:r<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ge;if(t<Kd&&t>Md)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>ia&&(o=0n,++n>ia&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return ge;let r=t<0;r&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return r&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new e(n,o)}static from(t){return typeof t=="number"?e.fromNumber(t):typeof t=="bigint"?e.fromBigInt(t):typeof t=="string"?e.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new e(t.low>>>0,t.high>>>0):ge}},ge=new St(0,0);ge.toBigInt=function(){return 0n};ge.zzEncode=ge.zzDecode=function(){return this};ge.length=function(){return 1};var ia=4294967296n;function ca(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 aa(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 os(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 Tt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function mn(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,Tt(this,10);return t}int32(){return this.uint32()|0}sint32(){let t=this.uint32();return t>>>1^-(t&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Tt(this,4);return mn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Tt(this,4);return mn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Tt(this,4);let t=na(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Tt(this,4);let t=sa(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 Tt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return aa(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Tt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Tt(this);while((this.buf[this.pos++]&128)!==0);return this}skipType(t){switch(t){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(t=this.uint32()&7)!==4;)this.skipType(t);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${t} at offset ${this.pos}`)}return this}readLongVarint(){let t=new St(0,0),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 Tt(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 Tt(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 Tt(this,8);let t=mn(this.buf,this.pos+=4),r=mn(this.buf,this.pos+=4);return new St(t,r)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=ea(this.buf,this.pos);return this.pos+=Br(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 Cr(e){return new ss(e instanceof Uint8Array?e:e.subarray())}function yn(e,t,r){let n=Cr(e);return t.decode(n,void 0,r)}function we(e=0){return new Uint8Array(e)}var us={};$(us,{base10:()=>$d});var Iy=new Uint8Array(0);function ua(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 jt(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 da(e){return new TextEncoder().encode(e)}function la(e){return new TextDecoder().decode(e)}function kd(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 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,y=0,S=h.length;y!==S&&h[y]===0;)y++,E++;for(var v=(S-y)*u+1>>>0,I=new Uint8Array(v);y!==S;){for(var _=h[y],R=0,O=v-1;(_!==0||R<p)&&O!==-1;O--,R++)_+=256*I[O]>>>0,I[O]=_%c>>>0,_=_/c>>>0;if(_!==0)throw new Error("Non-zero carry");p=R,y++}for(var C=v-p;C!==v&&I[C]===0;)C++;for(var F=f.repeat(E);C<v;++C)F+=e.charAt(I[C]);return F}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,y=0;h[E]===f;)p++,E++;for(var S=(h.length-E)*a+1>>>0,v=new Uint8Array(S);h[E];){var I=r[h.charCodeAt(E)];if(I===255)return;for(var _=0,R=S-1;(I!==0||_<y)&&R!==-1;R--,_++)I+=c*v[R]>>>0,v[R]=I%256>>>0,I=I/256>>>0;if(I!==0)throw new Error("Non-zero carry");y=_,E++}if(h[E]!==" "){for(var O=S-y;O!==S&&v[O]===0;)O++;for(var C=new Uint8Array(p+(S-O)),F=p;O!==S;)C[F++]=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 Vd=kd,zd=Vd,pa=zd;var is=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")}},cs=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 ma(this,t)}},as=class{decoders;constructor(t){this.decoders=t}or(t){return ma(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 ma(e,t){return new as({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var fs=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 is(t,r,n),this.decoder=new cs(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ze({name:e,prefix:t,encode:r,decode:n}){return new fs(e,t,r,n)}function ce({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=pa(r,e);return ze({prefix:t,name:e,encode:n,decode:s=>jt(o(s))})}function Hd(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 qd(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 jd(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function J({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=jd(n);return ze({prefix:t,name:e,encode(s){return qd(s,n,r)},decode(s){return Hd(s,o,r,e)}})}var $d=ce({prefix:"9",name:"base10",alphabet:"0123456789"});var ds={};$(ds,{base16:()=>Zd,base16upper:()=>Yd});var Zd=J({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Yd=J({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var ls={};$(ls,{base2:()=>Gd});var Gd=J({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var hs={};$(hs,{base256emoji:()=>tl});var ya=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}"),Wd=ya.reduce((e,t,r)=>(e[r]=t,e),[]),Xd=ya.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Qd(e){return e.reduce((t,r)=>(t+=Wd[r],t),"")}function Jd(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Xd[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var tl=ze({prefix:"\u{1F680}",name:"base256emoji",encode:Qd,decode:Jd});var ps={};$(ps,{base32:()=>He,base32hex:()=>ol,base32hexpad:()=>il,base32hexpadupper:()=>cl,base32hexupper:()=>sl,base32pad:()=>rl,base32padupper:()=>nl,base32upper:()=>el,base32z:()=>al});var He=J({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),el=J({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),rl=J({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),nl=J({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),ol=J({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),sl=J({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),il=J({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),cl=J({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),al=J({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ms={};$(ms,{base36:()=>_r,base36upper:()=>fl});var _r=ce({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),fl=ce({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ys={};$(ys,{base58btc:()=>Pt,base58flickr:()=>ul});var Pt=ce({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ul=ce({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var bs={};$(bs,{base64:()=>dl,base64pad:()=>ll,base64url:()=>hl,base64urlpad:()=>pl});var dl=J({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ll=J({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),hl=J({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),pl=J({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var xs={};$(xs,{base8:()=>ml});var ml=J({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var gs={};$(gs,{identity:()=>yl});var yl=ze({prefix:"\0",name:"identity",encode:e=>la(e),decode:e=>da(e)});var qy=new TextEncoder,jy=new TextDecoder;var Es={};$(Es,{identity:()=>Ml});var gl=ga,ba=128,wl=127,El=~wl,Sl=Math.pow(2,31);function ga(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Sl;)t[r++]=e&255|ba,e/=128;for(;e&El;)t[r++]=e&255|ba,e>>>=7;return t[r]=e|0,ga.bytes=r-n+1,t}var vl=ws,Al=128,xa=127;function ws(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw ws.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&xa)<<o:(i&xa)*Math.pow(2,o),o+=7}while(i>=Al);return ws.bytes=s-n,r}var Bl=Math.pow(2,7),Cl=Math.pow(2,14),_l=Math.pow(2,21),Il=Math.pow(2,28),Dl=Math.pow(2,35),Tl=Math.pow(2,42),Ol=Math.pow(2,49),Ll=Math.pow(2,56),Ul=Math.pow(2,63),Rl=function(e){return e<Bl?1:e<Cl?2:e<_l?3:e<Il?4:e<Dl?5:e<Tl?6:e<Ol?7:e<Ll?8:e<Ul?9:10},Pl={encode:gl,decode:vl,encodingLength:Rl},Fl=Pl,Ir=Fl;function Dr(e,t=0){return[Ir.decode(e,t),Ir.decode.bytes]}function qe(e,t,r=0){return Ir.encode(e,t,r),t}function je(e){return Ir.encodingLength(e)}function Ze(e,t){let r=t.byteLength,n=je(e),o=n+je(r),s=new Uint8Array(o+r);return qe(e,s,0),qe(r,s,n),s.set(t,o),new $e(e,r,t,s)}function wa(e){let t=jt(e),[r,n]=Dr(t),[o,s]=Dr(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new $e(r,o,i,t)}function Ea(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&ua(e.bytes,r.bytes)}}var $e=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};var Sa=0,Nl="identity",va=jt;function Kl(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 Ze(Sa,va(e))}var Ml={code:Sa,name:Nl,encode:va,digest:Kl};var As={};$(As,{sha256:()=>Vl,sha512:()=>zl});var kl=20;function vs({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new Ss(e,t,r,n,o)}var Ss=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??kl,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?Aa(n,this.code,r?.truncate):n.then(o=>Aa(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Aa(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 Ze(t,e)}function Ca(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Vl=vs({name:"sha2-256",code:18,encode:Ca("SHA-256")}),zl=vs({name:"sha2-512",code:19,encode:Ca("SHA-512")});function _a(e,t){let{bytes:r,version:n}=e;return n===0?ql(r,Bs(e),t??Pt.encoder):jl(r,Bs(e),t??He.encoder)}var Ia=new WeakMap;function Bs(e){let t=Ia.get(e);if(t==null){let r=new Map;return Ia.set(e,r),r}return t}var xn=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!==Or)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==$l)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=Ze(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&&Ea(t.multihash,n.multihash)}toString(t){return _a(this,t)}toJSON(){return{"/":_a(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??Da(n,o,s.bytes))}else if(r[Zl]===!0){let{version:n,multihash:o,code:s}=r,i=wa(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!==Or)throw new Error(`Version 0 CID must use dag-pb (code: ${Or}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Da(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Or,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=jt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new $e(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[d,g]=Dr(t.subarray(r));return r+=g,d},o=n(),s=Or;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]=Hl(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 Bs(s).set(n,t),s}};function Hl(e,t){switch(e[0]){case"Q":{let r=t??Pt;return[Pt.prefix,r.decode(`${Pt.prefix}${e}`)]}case Pt.prefix:{let r=t??Pt;return[Pt.prefix,r.decode(e)]}case He.prefix:{let r=t??He;return[He.prefix,r.decode(e)]}case _r.prefix:{let r=t??_r;return[_r.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 ql(e,t,r){let{prefix:n}=r;if(n!==Pt.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 jl(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 Or=112,$l=18;function Da(e,t,r){let n=je(e),o=n+je(t),s=new Uint8Array(o+r.byteLength);return qe(e,s,0),qe(t,s,n),s.set(r,o),s}var Zl=Symbol.for("@ipld/js-cid/CID");var Cs={...gs,...ls,...xs,...us,...ds,...ps,...ms,...ys,...bs,...hs},hb={...As,...Es};function Oa(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Ta=Oa("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),_s=Oa("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=we(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Yl={utf8:Ta,"utf-8":Ta,hex:Cs.base16,latin1:_s,ascii:_s,binary:_s,...Cs},La=Yl;function Ua(e,t="utf8"){let r=La[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function Is(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return we(i);o+i>t&&(n=we(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var Ee=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function Ds(){}var Os=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Gl=Is();function Wl(e){return globalThis.Buffer!=null?we(e):Gl(e)}var Ur=class{len;head;tail;states;constructor(){this.len=0,this.head=new Ee(Ds,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new Ee(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Ls((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(gn,10,St.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let r=St.fromBigInt(t);return this._push(gn,r.length(),r)}uint64Number(t){return this._push(ta,Br(t),t)}uint64String(t){return this.uint64(BigInt(t))}int64(t){return this.uint64(t)}int64Number(t){return this.uint64Number(t)}int64String(t){return this.uint64String(t)}sint64(t){let r=St.fromBigInt(t).zzEncode();return this._push(gn,r.length(),r)}sint64Number(t){let r=St.fromNumber(t).zzEncode();return this._push(gn,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Ts,1,t?1:0)}fixed32(t){return this._push(Lr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=St.fromBigInt(t);return this._push(Lr,4,r.lo)._push(Lr,4,r.hi)}fixed64Number(t){let r=St.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(ra,4,t)}double(t){return this._push(oa,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Ts,1,0):this.uint32(r)._push(Ql,r,t)}string(t){let r=ca(t);return r!==0?this.uint32(r)._push(os,r,t):this._push(Ts,1,0)}fork(){return this.states=new Os(this),this.head=this.tail=new Ee(Ds,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 Ee(Ds,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 Ts(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 Ls=class extends Ee{next;constructor(t,r){super(Xl,t,r),this.next=void 0}};function gn(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 Ql(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(Ur.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Jl,t,e),this},Ur.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?os(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(Ua(e),r)}function Us(){return new Ur}function wn(e,t){let r=Us();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*En(e,t,r){let n=Cr(e);yield*t.stream(n,void 0,"$",r)}var Sn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function vn(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function Rs(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 vn("enum",Sn.VARINT,r,n,o)}function An(e,t,r){return vn("message",Sn.LENGTH_DELIMITED,e,t,r)}var xt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(xt||(xt={}));var Ps;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Ps||(Ps={}));(function(e){e.codec=()=>Rs(Ps)})(xt||(xt={}));var Rr;(function(e){let t;e.codec=()=>(t==null&&(t=An((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),xt.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=xt.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:xt.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 wn(s,e.codec())}e.encode=r;function n(s,i){return yn(s,e.codec(),i)}e.decode=n;function o(s,i){return En(s,e.codec(),i)}e.stream=o})(Rr||(Rr={}));var Fs;(function(e){let t;e.codec=()=>(t==null&&(t=An((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),xt.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=xt.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:xt.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 wn(s,e.codec())}e.encode=r;function n(s,i){return yn(s,e.codec(),i)}e.decode=n;function o(s,i){return En(s,e.codec(),i)}e.stream=o})(Fs||(Fs={}));var Bn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(Yr(t),Et(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),Vt(o)}update(t){return Ue(this),this.iHash.update(t),this}digestInto(t){Ue(this),Gr(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()}},Ra=(()=>{let e=((t,r,n)=>new Bn(t,r).update(n).digest());return e.create=(t,r)=>new Bn(t,r),e})();var Pa=(e,t)=>(e+(e>=0?t:-t)/Fa)/t;function rh(e,t,r){Fe("scalar",e,Ft,r);let[[n,o],[s,i]]=t,c=Pa(i*e,r),f=Pa(-o*e,r),a=e-c*n-f*s,u=-c*o-f*i,d=a<Ft,g=u<Ft;d&&(a=-a),g&&(u=-u);let m=wr(Math.ceil(Ne(r)/2))+ae;if(a<Ft||a>=m||u<Ft||u>=m)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:d,k1:a,k2neg:g,k2:u}}function Ks(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Ns(e,t){Dt(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&&Ks(r.format),r}var Ms=class extends Error{constructor(t=""){super(t)}},Ot={Err:Ms,_tlv:{encode:(e,t)=>{let{Err:r}=Ot;if(It(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=xr(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?xr(o.length/2|128):"";return xr(e)+s+o+t},decode(e,t){let{Err:r}=Ot;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}=Ot;if(rn(e),e<Ft)throw new t("integer: negative integers are not allowed");let r=xr(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}=Ot;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 pe(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Ot,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}=Ot,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(Ot._tlv);Object.freeze(Ot._int);Object.freeze(Ot);var Ft=BigInt(0),ae=BigInt(1),Fa=BigInt(2),Cn=BigInt(3),nh=BigInt(4);function Na(e,t={}){let r=cn("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:c}=s;Dt(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=Ma(n,o);function d(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function g(N,l,b){if(a&&l.is0())return Uint8Array.of(0);let{x:A,y:w}=l.toAffine(),x=n.toBytes(A);if(_t(b,"isCompressed"),b){d();let B=!n.isOdd(w);return st(Ka(B),x)}else return st(Uint8Array.of(4),x,n.toBytes(w))}function m(N){V(N,void 0,"Point");let{publicKey:l,publicKeyUncompressed:b}=u,A=N.length,w=N[0],x=N.subarray(1);if(a&&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),D;try{D=n.sqrt(T)}catch(k){let H=k instanceof Error?": "+k.message:"";throw new Error("bad point: is not on curve, sqrt error"+H)}d();let L=n.isOdd(D);return(w&1)===1!==L&&(D=n.neg(D)),{x:B,y:D}}else if(A===b&&w===4){let B=n.BYTES,T=n.fromBytes(x.subarray(0,B)),D=n.fromBytes(x.subarray(B,B*2));if(!y(T,D))throw new Error("bad point: is not on curve");return{x:T,y:D}}else throw new Error(`bad point: got length ${A}, expected compressed=${l} or uncompressed=${b}`)}let h=t.toBytes===void 0?g:t.toBytes,E=t.fromBytes===void 0?m:t.fromBytes;function p(N){let l=n.sqr(N),b=n.mul(l,N);return n.add(n.add(b,n.mul(N,s.a)),s.b)}function y(N,l){let b=n.sqr(l),A=p(N);return n.eql(b,A)}if(!y(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(s.a,Cn),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 I(N,l,b=!1){if(!n.isValid(l)||b&&n.is0(l))throw new Error(`bad point coordinate ${N}`);return l}function _(N){if(!(N instanceof C))throw new Error("Weierstrass Point expected")}function R(N){if(!f||!f.basises)throw new Error("no endo");return rh(N,f.basises,o.ORDER)}function O(N,l,b,A,w){return b=new C(n.mul(b.X,N),b.Y,b.Z),l=Sr(A,l),b=Sr(w,b),l.add(b)}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,b,A){this.X=I("x",l),this.Y=I("y",b,!0),this.Z=I("z",A),Object.freeze(this)}static CURVE(){return s}static fromAffine(l){let{x:b,y:A}=l||{};if(!l||!n.isValid(b)||!n.isValid(A))throw new Error("invalid affine point");if(l instanceof C)throw new Error("projective point not allowed");return n.is0(b)&&n.is0(A)?C.ZERO:new C(b,A,n.ONE)}static fromBytes(l){let b=C.fromAffine(E(V(l,void 0,"point")));return b.assertValidity(),b}static fromHex(l){return C.fromBytes(Pe(l))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(l=8,b=!0){return j.createCache(this,l),b||this.multiply(Cn),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:b,y:A}=l.toAffine();if(!n.isValid(b)||!n.isValid(A))throw new Error("bad point: x or y not field elements");if(!y(b,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:b,Y:A,Z:w}=this,{X:x,Y:B,Z:T}=l,D=n.eql(n.mul(b,T),n.mul(x,w)),L=n.eql(n.mul(A,T),n.mul(B,w));return D&&L}negate(){return new C(this.X,n.neg(this.Y),this.Z)}double(){let{a:l,b}=s,A=n.mul(b,Cn),{X:w,Y:x,Z:B}=this,T=n.ZERO,D=n.ZERO,L=n.ZERO,P=n.mul(w,w),k=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),D=n.mul(A,H),D=n.add(T,D),T=n.sub(k,D),D=n.add(k,D),D=n.mul(T,D),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),D=n.add(D,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,k),L=n.add(L,L),L=n.add(L,L),new C(T,D,L)}add(l){_(l);let{X:b,Y:A,Z:w}=this,{X:x,Y:B,Z:T}=l,D=n.ZERO,L=n.ZERO,P=n.ZERO,k=s.a,H=n.mul(s.b,Cn),K=n.mul(b,x),ot=n.mul(A,B),it=n.mul(w,T),ct=n.add(b,A),tt=n.add(x,B);ct=n.mul(ct,tt),tt=n.add(K,ot),ct=n.sub(ct,tt),tt=n.add(b,w);let gt=n.add(x,T);return tt=n.mul(tt,gt),gt=n.add(K,it),tt=n.sub(tt,gt),gt=n.add(A,w),D=n.add(B,T),gt=n.mul(gt,D),D=n.add(ot,it),gt=n.sub(gt,D),P=n.mul(k,tt),D=n.mul(H,it),P=n.add(D,P),D=n.sub(ot,P),P=n.add(ot,P),L=n.mul(D,P),ot=n.add(K,K),ot=n.add(ot,K),it=n.mul(k,it),tt=n.mul(H,tt),ot=n.add(ot,it),it=n.sub(K,it),it=n.mul(k,it),tt=n.add(tt,it),K=n.mul(ot,tt),L=n.add(L,K),K=n.mul(gt,tt),D=n.mul(ct,D),D=n.sub(D,K),K=n.mul(ct,ot),P=n.mul(gt,P),P=n.add(P,K),new C(D,L,P)}subtract(l){return _(l),this.add(l.negate())}is0(){return this.equals(C.ZERO)}multiply(l){let{endo:b}=t;if(!o.isValidNot0(l))throw new RangeError("invalid scalar: out of range");let A,w,x=B=>j.cached(this,B,T=>be(C,T));if(b){let{k1neg:B,k1:T,k2neg:D,k2:L}=R(l),{p:P,f:k}=x(T),{p:H,f:K}=x(L);w=k.add(K),A=O(b.beta,P,H,B,D)}else{let{p:B,f:T}=x(l);A=B,w=T}return be(C,[A,w])[0]}multiplyUnsafe(l){let{endo:b}=t,A=this,w=l;if(!o.isValid(w))throw new RangeError("invalid scalar: out of range");if(w===Ft||A.is0())return C.ZERO;if(w===ae)return A;if(j.hasCache(this))return this.multiply(w);if(b){let{k1neg:x,k1:B,k2neg:T,k2:D}=R(w),{p1:L,p2:P}=Kc(C,A,B,D);return O(b.beta,L,P,x,T)}else return j.unsafe(A,w)}toAffine(l){let b=this,A=l,{X:w,Y:x,Z:B}=b;if(n.eql(B,n.ONE))return{x:w,y:x};let T=b.is0();A==null&&(A=T?n.ONE:n.inv(B));let D=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:D,y:L}}isTorsionFree(){let{isTorsionFree:l}=t;return i===ae?!0:l?l(C,this):j.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:l}=t;return i===ae?this:l?l(C,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===ae?this.is0():this.clearCofactor().is0()}toBytes(l=!0){return _t(l,"isCompressed"),this.assertValidity(),h(C,this,l)}toHex(l=!0){return Re(this.toBytes(l))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let F=o.BITS,j=new ke(C,t.endo?Math.ceil(F/2):F);return F>=8&&C.BASE.precompute(8),Object.freeze(C.prototype),Object.freeze(C),C}function Ka(e){return Uint8Array.of(e?2:3)}function Ma(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?br:t.randomBytes,o=Object.assign(Ma(e.Fp,r),{seed:Math.max(Vo(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 y=m.length;return h===!0&&y!==E||h===!1&&y!==p?!1:!!e.fromBytes(m)}catch{return!1}}function c(m){return m=m===void 0?n(o.seed):m,zo(V(m,o.seed,"seed"),r.ORDER)}function f(m,h=!0){return e.BASE.multiply(r.fromBytes(m)).toBytes(h)}function a(m){let{secretKey:h,publicKey:E,publicKeyUncompressed:p}=o,y=r._lengths;if(!he(m))return;let S=V(m,void 0,"key").length,v=S===E||S===p,I=S===h||!!y?.includes(S);if(!(v&&I))return v}function u(m,h,E=!0){if(a(m)===!0)throw new Error("first arg must be private key");if(a(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:c},g=an(c,f);return Object.freeze(d),Object.freeze(o),Object.freeze({getPublicKey:f,getSharedSecret:u,keygen:g,Point:e,utils:d,lengths:o})}function ka(e,t,r={}){let n=t;Yr(n),Dt(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?br:r.randomBytes,s=r.hmac===void 0?(w,x)=>Ra(n,w,x):r.hmac,{Fp:i,Fn:c}=e,{ORDER:f,BITS:a}=c,{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*Fa+ae<i.ORDER;function y(w){let x=f>>ae;return w>x}function S(w,x){if(!c.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 I(w,x){Ks(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){I(x,B);let T;if(B==="der"){let{r:k,s:H}=Ot.toSig(V(x));return new _(k,H)}B==="recovered"&&(T=x[0],B="compact",x=x.subarray(1));let D=h.signature/2,L=x.subarray(0,D),P=x.subarray(D,D*2);return new _(c.fromBytes(L),c.fromBytes(P),T)}static fromHex(x,B){return this.fromBytes(Pe(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,D=this.assertRecovery(),L=D===2||D===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),k=e.fromBytes(st(Ka((D&1)===0),P)),H=c.inv(L),K=O(V(x,void 0,"msgHash")),ot=c.create(-K*H),it=c.create(T*H),ct=e.BASE.multiplyUnsafe(ot).add(k.multiplyUnsafe(it));if(ct.is0())throw new Error("invalid recovery: point at infinify");return ct.assertValidity(),ct}hasHighS(){return y(this.s)}toBytes(x=E.format){if(Ks(x),x==="der")return Pe(Ot.hexFromSig(this));let{r:B,s:T}=this,D=c.toBytes(B),L=c.toBytes(T);return x==="recovered"?(v(),st(Uint8Array.of(this.assertRecovery()),D,L)):st(D,L)}toHex(x){return Re(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=pe(x),T=x.length*8-a;return T>0?B>>BigInt(T):B}:r.bits2int,O=r.bits2int_modN===void 0?function(x){return c.create(R(x))}:r.bits2int_modN,C=wr(a);function F(w){return Fe("num < 2^"+a,w,Ft,C),c.toBytes(w)}function j(w,x){return V(w,void 0,"message"),x?V(n(w),void 0,"prehashed message"):w}function N(w,x,B){let{lowS:T,prehash:D,extraEntropy:L}=Ns(B,E);w=j(w,D);let P=O(w),k=c.fromBytes(x);if(!c.isValidNot0(k))throw new Error("invalid private key");let H=[F(k),F(P)];if(L!=null&&L!==!1){let ct=L===!0?o(h.secretKey):L;H.push(V(ct,void 0,"extraEntropy"))}let K=st(...H),ot=P;function it(ct){let tt=R(ct);if(!c.isValidNot0(tt))return;let gt=c.inv(tt),Ae=e.BASE.multiply(tt).toAffine(),er=c.create(Ae.x);if(er===Ft)return;let Mr=c.create(gt*c.create(ot+er*k));if(Mr===Ft)return;let vi=(Ae.x===er?0:2)|Number(Ae.y&ae),Ai=Mr;return T&&y(Mr)&&(Ai=c.neg(Mr),vi^=1),new _(er,Ai,p?void 0:vi)}return{seed:K,k2sig:it}}function l(w,x,B={}){let{seed:T,k2sig:D}=N(w,x,B);return Ec(n.outputLen,c.BYTES,s)(T,D).toBytes(B.format)}function b(w,x,B,T={}){let{lowS:D,prehash:L,format:P}=Ns(T,E);if(B=V(B,void 0,"publicKey"),x=j(x,L),!he(w)){let k=w instanceof _?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+k)}I(w,P);try{let k=_.fromBytes(w,P),H=e.fromBytes(B);if(D&&k.hasHighS())return!1;let{r:K,s:ot}=k,it=O(x),ct=c.inv(ot),tt=c.create(it*ct),gt=c.create(K*ct),Ae=e.BASE.multiplyUnsafe(tt).add(H.multiplyUnsafe(gt));return Ae.is0()?!1:c.create(Ae.x)===K}catch{return!1}}function A(w,x,B={}){let{prehash:T}=Ns(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:b,recoverPublicKey:A,Signature:_,hash:n})}var Vs={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 Va=BigInt(2);function ih(e){let t=Vs.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,d=G(u,r,t)*u%t,g=G(d,r,t)*u%t,m=G(g,Va,t)*a%t,h=G(m,o,t)*m%t,E=G(h,s,t)*h%t,p=G(E,c,t)*E%t,y=G(p,f,t)*p%t,S=G(y,c,t)*E%t,v=G(S,r,t)*u%t,I=G(v,i,t)*h%t,_=G(I,n,t)*a%t,R=G(_,Va,t);if(!ks.eql(ks.sqr(R),e))throw new Error("Cannot find square root");return R}var ks=Ke(Vs.p,{sqrt:ih}),ch=Na(Vs,{Fp:ks,endo:sh}),Ye=ka(ch,xc);function za(e,t,r,n){let o=fr.digest(r instanceof Uint8Array?r:r.subarray());if(hn(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ye.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Ar(String(s))});try{return n?.signal?.throwIfAborted(),Ye.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new Ar(String(s))}}var _n=class{type="secp256k1";raw;_key;constructor(t){this._key=qa(t),this.raw=Ha(this._key)}toMultihash(){return Bt.digest(Le(this))}toCID(){return ut.createV1(114,this.toMultihash())}toString(){return nt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:vt(this.raw,t.raw)}verify(t,r,n){return za(this._key,r,t,n)}};function ja(e){return new _n(e)}function Ha(e){return Ye.Point.fromBytes(e).toBytes()}function qa(e){try{return Ye.Point.fromBytes(e),e}catch(t){throw new kr(String(t))}}function $a(e){let{Type:t,Data:r}=Rr.decode(e.digest),n=r??new Uint8Array;switch(t){case xt.Ed25519:return Gc(n);case xt.secp256k1:return ja(n);case xt.ECDSA:return ec(n);default:throw new rr}}function Le(e){return Rr.encode({Type:xt[e.type],Data:e.raw})}var Za=Symbol.for("nodejs.util.inspect.custom"),ah=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()})`}[Yn]=!0;toString(){return this.string==null&&(this.string=nt.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return ut.createV1(ah,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return vt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return vt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Za](){return`PeerId(${this.toString()})`}},In=class extends Pr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Dn=class extends Pr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Tn=class extends Pr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},fh=2336,Fr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=Bt.digest(At(this.url))}[Za](){return`PeerId(${this.url})`}[Yn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return ut.createV1(fh,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=et(t)),t.toString()===this.toString())}};var uh=114,Ya=2336;function Ga(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=ir(nt.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return dh(ut.parse(e));if(t==null)throw new Lt('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=ir(t.decode(e))}return Wa(r)}function Wa(e){if(hh(e))return new In({multihash:e});if(lh(e))try{let t=$a(e);if(t.type==="Ed25519")return new Dn({multihash:e,publicKey:t});if(t.type==="secp256k1")return new Tn({multihash:e,publicKey:t})}catch{let r=et(e.digest);return new Fr(new URL(r))}throw new zr("Supplied PeerID Multihash is invalid")}function dh(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==uh&&e.code!==Ya)throw new Vr("Supplied PeerID CID is invalid");if(e.code===Ya){let t=et(e.multihash.digest);return new Fr(new URL(t))}return Wa(e.multihash)}function lh(e){return e.code===Bt.code}function hh(e){return e.code===fr.code}var ph=Math.pow(2,7),mh=Math.pow(2,14),yh=Math.pow(2,21),zs=Math.pow(2,28),Hs=Math.pow(2,35),qs=Math.pow(2,42),js=Math.pow(2,49),W=128,mt=127;function Ge(e){if(e<ph)return 1;if(e<mh)return 2;if(e<yh)return 3;if(e<zs)return 4;if(e<Hs)return 5;if(e<qs)return 6;if(e<js)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function $s(e,t,r=0){switch(Ge(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 bh(e,t){let r=e[t],n=0;if(n+=r&mt,r<W||(r=e[t+1],n+=(r&mt)<<7,r<W)||(r=e[t+2],n+=(r&mt)<<14,r<W)||(r=e[t+3],n+=(r&mt)<<21,r<W)||(r=e[t+4],n+=(r&mt)*zs,r<W)||(r=e[t+5],n+=(r&mt)*Hs,r<W)||(r=e[t+6],n+=(r&mt)*qs,r<W)||(r=e[t+7],n+=(r&mt)*js,r<W))return n;throw new RangeError("Could not decode varint")}function xh(e,t){let r=e.get(t),n=0;if(n+=r&mt,r<W||(r=e.get(t+1),n+=(r&mt)<<7,r<W)||(r=e.get(t+2),n+=(r&mt)<<14,r<W)||(r=e.get(t+3),n+=(r&mt)<<21,r<W)||(r=e.get(t+4),n+=(r&mt)*zs,r<W)||(r=e.get(t+5),n+=(r&mt)*Hs,r<W)||(r=e.get(t+6),n+=(r&mt)*qs,r<W)||(r=e.get(t+7),n+=(r&mt)*js,r<W))return n;throw new RangeError("Could not decode varint")}function Zs(e,t=0){return e instanceof Uint8Array?bh(e,t):xh(e,t)}var ht=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},$t=class extends Error{static name="ValidationError";name="ValidationError"},On=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},Ln=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 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>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 wh=45,Eh=15,Rn=new Un;function Xa(e){if(!(e.length>Eh))return Rn.new(e).parseWith(()=>Rn.readIPv4Addr())}function Qa(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>wh))return Rn.new(e).parseWith(()=>Rn.readIPv6Addr())}function Pn(e){return!!Xa(e)}function Ja(e){return!!Qa(e)}function Gs(e){return t=>et(t,e)}function Ws(e){return t=>At(t,e)}function We(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function Se(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}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!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=At(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=Se(n);return xe([r,o],r.length+o.length)}function ef(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=Wt.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=Se(n);return xe([r,o],r.length+o.length)}function Xs(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=et(t,"base32"),o=We(r);return`${n}:${o}`}var Qs=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 ht("Invalid byte value in IP address");t[n]=o}),t},rf=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=Pn(r[n]),i;s&&(i=Qs(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 ht("Invalid byte value in IP address");o[t++]=s>>8&255,o[t++]=s&255}return o},nf=function(e){if(e.byteLength!==4)throw new ht("IPv4 address was incorrect length");let t=[];for(let r=0;r<e.byteLength;r++)t.push(e[r]);return t.join(".")},of=function(e){if(e.byteLength!==16)throw new ht("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 ht(`Invalid IPv6 address "${r}"`)}};function sf(e){try{let t=new URL(`http://[${e}]`);return t.hostname.substring(1,t.hostname.length-1)}catch{throw new ht(`Invalid IPv6 address "${e}"`)}}var Ys=Object.values(ur).map(e=>e.decoder),Sh=(function(){let e=Ys[0].or(Ys[1]);return Ys.slice(2).forEach(t=>e=e.or(t)),e})();function cf(e){return Sh.decode(e)}function af(e){return t=>e.encoder.encode(t)}function vh(e){if(parseInt(e).toString()!==e)throw new $t("Value must be an integer")}function Ah(e){if(e<0)throw new $t("Value must be a positive integer, or zero")}function Bh(e){return t=>{if(t>e)throw new $t(`Value must be smaller than or equal to ${e}`)}}function Ch(...e){return t=>{for(let r of e)r(t)}}var Nr=Ch(vh,Ah,Bh(65535));var ft=-1,Js=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 Ln(`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)}))}},Yt=new Js,kh=[{code:4,name:"ip4",size:32,valueToBytes:Qs,bytesToValue:nf,validate:e=>{if(!Pn(e))throw new $t(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:Se,bytesToValue:We,validate:Nr},{code:273,name:"udp",size:16,valueToBytes:Se,bytesToValue:We,validate:Nr},{code:33,name:"dccp",size:16,valueToBytes:Se,bytesToValue:We,validate:Nr},{code:41,name:"ip6",size:128,valueToBytes:rf,bytesToValue:of,stringToValue:sf,validate:e=>{if(!Ja(e))throw new $t(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:ft},{code:43,name:"ipcidr",size:8,bytesToValue:Gs("base10"),valueToBytes:Ws("base10")},{code:53,name:"dns",size:ft},{code:54,name:"dns4",size:ft},{code:55,name:"dns6",size:ft},{code:56,name:"dnsaddr",size:ft},{code:132,name:"sctp",size:16,valueToBytes:Se,bytesToValue:We,validate:Nr},{code:301,name:"udt"},{code:302,name:"utp"},{code:400,name:"unix",size:ft,stringToValue:e=>decodeURIComponent(e),valueToString:e=>encodeURIComponent(e)},{code:421,name:"p2p",aliases:["ipfs"],size:ft,bytesToValue:Gs("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?Ws("base58btc")(e):ut.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:Xs,valueToBytes:tf},{code:445,name:"onion3",size:296,bytesToValue:Xs,valueToBytes:ef},{code:446,name:"garlic64",size:ft},{code:447,name:"garlic32",size:ft},{code:448,name:"tls"},{code:449,name:"sni",size:ft},{code:454,name:"noise"},{code:460,name:"quic"},{code:461,name:"quic-v1"},{code:465,name:"webtransport"},{code:466,name:"certhash",size:ft,bytesToValue:af(uo),valueToBytes:cf},{code:480,name:"http"},{code:481,name:"http-path",size:ft,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:ft}];kh.forEach(e=>{Yt.addProtocol(e)});function ff(e){let t=[],r=0;for(;r<e.length;){let n=Zs(e,r),o=Yt.getProtocol(n),s=Ge(n),i=Vh(o,e,r+s),c=0;i>0&&o.size===ft&&(c=Ge(i));let f=s+c+i,a={code:n,name:o.name,bytes:Kt(e.subarray(r,r+f))};if(i>0){let u=r+s+c,d=e.subarray(u,u+i);a.value=o.bytesToValue?.(d)??et(d)}t.push(a),r+=f}return t}function uf(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=Yt.getProtocol(n.code),s=Ge(n.code),i,c=0,f=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??At(n.value),c=i.byteLength,o.size===ft&&(f=Ge(c)));let a=new Uint8Array(s+f+c),u=0;$s(n.code,a,u),u+=s,i!=null&&(o.size===ft&&($s(c,a,u),u+=f),a.set(i,u)),n.bytes=a}r.push(n.bytes),t+=n.bytes.byteLength}return xe(r,t)}function df(e){if(e.charAt(0)!=="/")throw new ht('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=Yt.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 ht(`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 ht(`Component ${o} was missing value`);a.value=f.stringToValue?.(n)??n}t.push(a),n="",o="",r="protocol"}}}if(o!==""&&n!=="")throw new ht("Incomplete multiaddr");return t}function lf(e){return`/${e.flatMap(t=>{if(t.value==null)return t.name;let r=Yt.getProtocol(t.code);if(r==null)throw new ht(`Unknown protocol code ${t.code}`);return[t.name,r.valueToString?.(t.value)??t.value]}).join("/")}`}function Vh(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:Zs(t,r)}var zh=Symbol.for("nodejs.util.inspect.custom"),yi=Symbol.for("@multiformats/multiaddr");function Hh(e){if(e==null&&(e="/"),hf(e))return e.getComponents();if(e instanceof Uint8Array)return ff(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),df(e);if(Array.isArray(e))return e;throw new ht("Must be a string, Uint8Array, Component[], or another Multiaddr")}var Vn=class e{[yi]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=Hh(t),r.validate!==!1&&qh(this)}get bytes(){return this.#r==null&&(this.#r=uf(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=lf(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 On(`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 vt(this.bytes,t.bytes)}[zh](){return`Multiaddr(${this.toString()})`}};function qh(e){e.getComponents().forEach(t=>{let r=Yt.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function hf(e){return!!e?.[yi]}function pf(e){return new Vn(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)}}),mf=e=>({match:t=>e.match(t)===!1?t:!1}),M=e=>({match:t=>{let r=e.match(t);return r===!1?t:r}}),yt=(...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 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 jh=U(421),xw=Y(jh),Hn=U(54),qn=U(55),jn=U(56),xi=U(53),gw=Y(Hn,M(U(421))),ww=Y(qn,M(U(421))),Ew=Y(jn,M(U(421))),Sw=Y(yt(xi,jn,Hn,qn),M(U(421))),yf=z(U(4),M(U(43))),bf=z(M(U(42)),U(41),M(U(43))),gi=yt(yf,bf),tr=yt(gi,xi,Hn,qn,jn),vw=Y(yt(gi,z(yt(xi,jn,Hn,qn),M(U(421))))),Aw=Y(yf),Bw=Y(bf),Cw=Y(gi),wi=z(tr,U(6)),Kr=z(tr,U(273)),_w=Y(z(wi,M(U(421)))),Iw=Y(Kr),Ei=z(Kr,Z(460),M(U(421))),$n=z(Kr,Z(461),M(U(421))),$h=yt(Ei,$n),Dw=Y(Ei),Tw=Y($n),bi=yt(tr,wi,Kr,Ei,$n),xf=yt(z(bi,Z(477),M(U(421)))),Ow=Y(xf),gf=yt(z(bi,Z(478),M(U(421))),z(bi,Z(448),M(U(449)),Z(477),M(U(421)))),Lw=Y(gf),wf=z(Kr,Z(280),M(U(466)),M(U(466)),M(U(421))),Uw=Y(wf),Ef=z($n,Z(465),M(U(466)),M(U(466)),M(U(421))),Rw=Y(Ef),zn=yt(xf,gf,z(wi,M(U(421))),z($h,M(U(421))),z(tr,M(U(421))),wf,Ef,U(421)),Sf=Y(zn),Zh=z(M(zn),Z(290),mf(Z(281)),M(U(421))),Pw=Y(Zh),Yh=yt(z(zn,Z(290),Z(281),M(U(421))),z(zn,Z(281),M(U(421))),z(Z(281),M(U(421)))),Fw=Y(Yh),Gh=z(tr,yt(z(U(6,"80")),z(U(6),Z(480)),Z(480)),M(U(481)),M(U(421))),Nw=Y(Gh),Wh=z(tr,yt(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)),M(U(481)),M(U(421))),Kw=Y(Wh),Xh=yt(z(U(777),M(U(421)))),Mw=Y(Xh),Qh=yt(z(U(400),M(U(421)))),kw=Y(Qh);var Jh="bootstrap",tp=50,ep=1e3,Si=class extends Hr{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??ep,this.list=r.list.map(n=>pf(n)).filter(n=>Sf.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:Ga(n.getComponents().findLast(o=>o.code===421)?.value??""),multiaddrs:[n]})),this._init=r}[Bi]=this;[Symbol.toStringTag]="@libp2p/bootstrap";[Ci]=["@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??Jh]:{value:this._init.tagValue??tp,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 rp(e){return t=>new Si(t,e)}return _f(np);})();
|
|
2
|
+
"use strict";var Libp2PBootstrap=(()=>{var _n=Object.defineProperty;var ea=Object.getOwnPropertyDescriptor;var ra=Object.getOwnPropertyNames;var na=Object.prototype.hasOwnProperty;var wt=(e,t)=>{for(var r in t)_n(e,r,{get:t[r],enumerable:!0})},oa=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of ra(t))!na.call(e,o)&&o!==r&&_n(e,o,{get:()=>t[o],enumerable:!(n=ea(t,o))||n.enumerable});return e};var sa=e=>oa(_n({},"__esModule",{value:!0}),e);var vl={};wt(vl,{bootstrap:()=>Sl});var Lt=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Er=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Sr=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 qe=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Us=Symbol.for("@libp2p/peer-discovery");var Tn=Symbol.for("@libp2p/peer-id");function ia(e){return typeof e?.handleEvent=="function"}function ca(e){return(e!==!0&&e!==!1&&e?.once)??!1}var Ar=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=ca(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))}ia(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 Ns=Symbol.for("@libp2p/service-capabilities");var Ln={};wt(Ln,{base58btc:()=>et,base58flickr:()=>ma});var td=new Uint8Array(0);function Fs(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 ie(e);if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return ie(new Uint8Array(e.buffer,e.byteOffset,e.byteLength));throw new Error("Unknown type, must be binary type")}function Ks(e){return new TextEncoder().encode(e)}function ks(e){return new TextDecoder().decode(e)}function aa(e){return e?.buffer instanceof ArrayBuffer}function ie(e){return aa(e)?e:e.slice()}function fa(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,x=0,v=b.length;x!==v&&b[x]===0;)x++,S++;for(var B=(v-x)*u+1>>>0,O=new Uint8Array(B);x!==v;){for(var C=b[x],U=0,L=B-1;(C!==0||U<h)&&L!==-1;L--,U++)C+=256*O[L]>>>0,O[L]=C%c>>>0,C=C/c>>>0;if(C!==0)throw new Error("Non-zero carry");h=U,x++}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,x=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<x)&&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");x=C,S++}if(b[S]!==" "){for(var L=v-x;L!==v&&B[L]===0;)L++;for(var T=new Uint8Array(h+(v-L)),N=h;L!==v;)T[N++]=B[L++];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 ua=fa,la=ua,Vs=la;var In=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Cn=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 Hs(this,t)}},Dn=class{decoders;constructor(t){this.decoders=t}or(t){return Hs(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 Hs(e,t){return new Dn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var On=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new In(t,r,n),this.decoder=new Cn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function xe({name:e,prefix:t,encode:r,decode:n}){return new On(e,t,r,n)}function Yt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Vs(r,e);return xe({prefix:t,name:e,encode:n,decode:s=>kt(o(s))})}function da(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 ha(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 pa(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=pa(n);return xe({prefix:t,name:e,encode(s){return ha(s,n,r)},decode(s){return da(s,o,r,e)}})}var et=Yt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),ma=Yt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Rn={};wt(Rn,{base32:()=>Gt,base32hex:()=>xa,base32hexpad:()=>Ea,base32hexpadupper:()=>Sa,base32hexupper:()=>wa,base32pad:()=>ba,base32padupper:()=>ga,base32upper:()=>ya,base32z:()=>va});var Gt=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ya=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),ba=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ga=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),xa=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),wa=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ea=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Sa=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),va=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Pn={};wt(Pn,{base36:()=>ze,base36upper:()=>Aa});var ze=Yt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Aa=Yt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ba=js,qs=128,_a=127,Ta=~_a,Ia=Math.pow(2,31);function js(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Ia;)t[r++]=e&255|qs,e/=128;for(;e&Ta;)t[r++]=e&255|qs,e>>>=7;return t[r]=e|0,js.bytes=r-n+1,t}var Ca=Un,Da=128,zs=127;function Un(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw Un.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&zs)<<o:(i&zs)*Math.pow(2,o),o+=7}while(i>=Da);return Un.bytes=s-n,r}var Oa=Math.pow(2,7),La=Math.pow(2,14),Ra=Math.pow(2,21),Pa=Math.pow(2,28),Ua=Math.pow(2,35),Na=Math.pow(2,42),Fa=Math.pow(2,49),Ka=Math.pow(2,56),ka=Math.pow(2,63),Ma=function(e){return e<Oa?1:e<La?2:e<Ra?3:e<Pa?4:e<Ua?5:e<Na?6:e<Fa?7:e<Ka?8:e<ka?9:10},Va={encode:Ba,decode:Ca,encodingLength:Ma},Ha=Va,je=Ha;function Ze(e,t=0){return[je.decode(e,t),je.decode.bytes]}function we(e,t,r=0){return je.encode(e,t,r),t}function Ee(e){return je.encodingLength(e)}function ve(e,t){let r=t.byteLength,n=Ee(e),o=n+Ee(r),s=new Uint8Array(o+r);return we(e,s,0),we(r,s,n),s.set(t,o),new Se(e,r,t,s)}function $e(e){let t=kt(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 Se(r,o,i,t)}function Zs(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Fs(e.bytes,r.bytes)}}var Se=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=ie(n),this.bytes=ie(o)}};function $s(e,t){let{bytes:r,version:n}=e;return n===0?za(r,Nn(e),t??et.encoder):ja(r,Nn(e),t??Gt.encoder)}var Ys=new WeakMap;function Nn(e){let t=Ys.get(e);if(t==null){let r=new Map;return Ys.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=ie(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!==Ye)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Za)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=ve(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&&Zs(t.multihash,n.multihash)}toString(t){return $s(this,t)}toJSON(){return{"/":$s(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??Gs(n,o,s.bytes))}else if(r[$a]===!0){let{version:n,multihash:o,code:s}=r,i=$e(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!==Ye)throw new Error(`Version 0 CID must use dag-pb (code: ${Ye}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Gs(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ye,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 Se(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=Ye;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]=qa(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 Nn(s).set(n,t),s}};function qa(e,t){switch(e[0]){case"Q":{let r=t??et;return[et.prefix,r.decode(`${et.prefix}${e}`)]}case et.prefix:{let r=t??et;return[et.prefix,r.decode(e)]}case Gt.prefix:{let r=t??Gt;return[Gt.prefix,r.decode(e)]}case ze.prefix:{let r=t??ze;return[ze.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function za(e,t,r){let{prefix:n}=r;if(n!==et.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 ja(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 Ye=112,Za=18;function Gs(e,t,r){let n=Ee(e),o=n+Ee(t),s=new Uint8Array(o+r.byteLength);return we(e,s,0),we(t,s,n),s.set(r,o),s}var $a=Symbol.for("@ipld/js-cid/CID");var Fn={};wt(Fn,{identity:()=>At});var Ws=0,Ya="identity",Xs=kt;function Ga(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 ve(Ws,Xs(e))}var At={code:Ws,name:Ya,encode:Xs,digest:Ga};function gt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Wa(e){return e.buffer instanceof ArrayBuffer}function Bt(e){return Wa(e)?e:e.slice()}async function Qs(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,Bt(t),Bt(r.subarray()));return n?.signal?.throwIfAborted(),s}function Rt(e=0){return new Uint8Array(e)}function mt(e=0){return new Uint8Array(e)}function Xa(e){return e?.buffer instanceof ArrayBuffer}function Kn(e){if(Xa(e))return e;let t=e.slice();return new Uint8Array(t.buffer,0,t.byteLength)}function Pt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=mt(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return Kn(r)}var ti=Symbol.for("@achingbrain/uint8arraylist");function Js(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 _r(e){return!!e?.[ti]}var Et=class e{bufs;length;[ti]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(_r(n)){r+=n.byteLength;for(let 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(_r(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=Js(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Js(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(_r(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Pt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Pt(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(!_r(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let 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=mt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=Rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=Rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=Rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=mt(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=Rt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=Rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=Rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=Rt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=Rt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!gt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var kn={};wt(kn,{base10:()=>Qa});var Qa=Yt({prefix:"9",name:"base10",alphabet:"0123456789"});var Mn={};wt(Mn,{base16:()=>Ja,base16upper:()=>tf});var Ja=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),tf=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Vn={};wt(Vn,{base2:()=>ef});var ef=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Hn={};wt(Hn,{base256emoji:()=>cf});var ei=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}"),rf=ei.reduce((e,t,r)=>(e[r]=t,e),[]),nf=ei.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function of(e){return e.reduce((t,r)=>(t+=rf[r],t),"")}function sf(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=nf[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var cf=xe({prefix:"\u{1F680}",name:"base256emoji",encode:of,decode:sf});var zn={};wt(zn,{base64:()=>af,base64pad:()=>ff,base64url:()=>qn,base64urlpad:()=>uf});var af=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ff=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),qn=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),uf=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var jn={};wt(jn,{base8:()=>lf});var lf=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Zn={};wt(Zn,{identity:()=>df});var df=xe({prefix:"\0",name:"identity",encode:e=>ks(e),decode:e=>Ks(e)});var kd=new TextEncoder,Md=new TextDecoder;var Gn={};wt(Gn,{sha256:()=>Ge,sha512:()=>yf});var mf=20;function Yn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new $n(e,t,r,n,o)}var $n=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??mf,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?ri(n,this.code,r?.truncate):n.then(o=>ri(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function ri(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 ve(t,e)}function oi(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Ge=Yn({name:"sha2-256",code:18,encode:oi("SHA-256")}),yf=Yn({name:"sha2-512",code:19,encode:oi("SHA-512")});var We={...Zn,...Vn,...jn,...kn,...Mn,...Rn,...Pn,...Ln,...zn,...Hn},Qd={...Gn,...Fn};function ii(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var si=ii("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Wn=ii("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=mt(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),bf={utf8:si,"utf-8":si,hex:We.base16,latin1:Wn,ascii:Wn,binary:Wn,...We},Tr=bf;function xt(e,t="utf8"){let r=Tr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function J(e,t="utf8"){let r=Tr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var gf=parseInt("11111",2),Xn=parseInt("10000000",2),xf=parseInt("01111111",2),ci={0:Xe,1:Xe,2:wf,3:vf,4:Af,5:Sf,6:Ef,16:Xe,22:Xe,48:Xe};function Qn(e,t={offset:0}){let r=e[t.offset]&gf;if(t.offset++,ci[r]!=null)return ci[r](e,t);throw new Error("No decoder for tag "+r)}function Qe(e,t){let r=0;if((e[t.offset]&Xn)===Xn){let n=e[t.offset]&xf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Xe(e,t){Qe(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Qn(e,t);if(n===null)break;r.push(n)}return r}function wf(e,t){let r=Qe(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 Ef(e,t){let r=Qe(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 Sf(e,t){return t.offset++,null}function vf(e,t){let r=Qe(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 Af(e,t){let r=Qe(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Bf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new Et;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Jn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=Bf(e.byteLength);return new Et(Uint8Array.from([t.byteLength|Xn]),t)}function ai(e){let t=new Et,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new Et(Uint8Array.from([2]),Jn(t),t)}function fi(e){let t=Uint8Array.from([0]),r=new Et(t,e);return new Et(Uint8Array.from([3]),Jn(r),r)}function Ir(e,t=48){let r=new Et;for(let n of e)r.append(n);return new Et(Uint8Array.from([t]),Jn(r),r)}var _f=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Tf=Uint8Array.from([6,5,43,129,4,0,34]),If=Uint8Array.from([6,5,43,129,4,0,35]),Cf={ext:!0,kty:"EC",crv:"P-256"},Df={ext:!0,kty:"EC",crv:"P-384"},Of={ext:!0,kty:"EC",crv:"P-521"},to=32,eo=48,ro=66;function ui(e){let t=Qn(e);return li(t)}function li(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===to*2+1)return n=J(t.subarray(r,r+to),"base64url"),o=J(t.subarray(r+to),"base64url"),new Be({...Cf,key_ops:["verify"],x:n,y:o});if(t.byteLength===eo*2+1)return n=J(t.subarray(r,r+eo),"base64url"),o=J(t.subarray(r+eo),"base64url"),new Be({...Df,key_ops:["verify"],x:n,y:o});if(t.byteLength===ro*2+1)return n=J(t.subarray(r,r+ro),"base64url"),o=J(t.subarray(r+ro),"base64url"),new Be({...Of,key_ops:["verify"],x:n,y:o});throw new Lt(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function di(e){return Ir([ai(Uint8Array.from([1])),Ir([Lf(e.crv)],160),Ir([fi(new Et(Uint8Array.from([4]),xt(e.x??"","base64url"),xt(e.y??"","base64url")))],161)]).subarray()}function Lf(e){if(e==="P-256")return _f;if(e==="P-384")return Tf;if(e==="P-521")return If;throw new Lt(`Invalid curve ${e}`)}var Be=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=di(this.jwk)),this._raw}toMultihash(){return At.digest(_e(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return et.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}async verify(t,r,n){return Qs(this.jwk,r,t,n)}};function no(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 St(e,t,r=""){let n=no(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 Cr(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 Te(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 Dr(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 Vt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Or(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function _t(e,t){return e<<32-t|e>>>t}var pi=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Rf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Lr(e){if(St(e),pi)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Rf[e[r]];return t}var Mt={_0:48,_9:57,A:65,F:70,a:97,f:102};function hi(e){if(e>=Mt._0&&e<=Mt._9)return e-Mt._0;if(e>=Mt.A&&e<=Mt.F)return e-(Mt.A-10);if(e>=Mt.a&&e<=Mt.f)return e-(Mt.a-10)}function Je(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);if(pi)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=hi(e.charCodeAt(s)),c=hi(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 oo(...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 so(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 mi(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 io=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function yi(e,t,r){return e&t^~e&r}function bi(e,t,r){return e&t^e&r^t&r}var tr=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=Or(this.buffer)}update(t){Te(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=Or(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){Te(this),Dr(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Vt(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=Or(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()}},Ht=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 Rr=BigInt(4294967295),gi=BigInt(32);function Pf(e,t=!1){return t?{h:Number(e&Rr),l:Number(e>>gi&Rr)}:{h:Number(e>>gi&Rr)|0,l:Number(e&Rr)|0}}function xi(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}=Pf(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var co=(e,t,r)=>e>>>r,ao=(e,t,r)=>e<<32-r|t>>>r,ce=(e,t,r)=>e>>>r|t<<32-r,ae=(e,t,r)=>e<<32-r|t>>>r,er=(e,t,r)=>e<<64-r|t>>>r-32,rr=(e,t,r)=>e>>>r-32|t<<64-r;function Ut(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var wi=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),Ei=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,Si=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),vi=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Ai=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),Bi=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Nf=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),fo=class extends tr{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)Xt[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let w=Xt[l-15],p=Xt[l-2],b=_t(w,7)^_t(w,18)^w>>>3,S=_t(p,17)^_t(p,19)^p>>>10;Xt[l]=S+Xt[l-7]+b+Xt[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=_t(c,6)^_t(c,11)^_t(c,25),p=u+w+yi(c,f,a)+Nf[l]+Xt[l]|0,S=(_t(n,2)^_t(n,13)^_t(n,22))+bi(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(){Vt(Xt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Vt(this.buffer)}},uo=class extends fo{A=Ht[0]|0;B=Ht[1]|0;C=Ht[2]|0;D=Ht[3]|0;E=Ht[4]|0;F=Ht[5]|0;G=Ht[6]|0;H=Ht[7]|0;constructor(){super(32)}};var _i=xi(["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))),Ff=_i[0],Kf=_i[1],Qt=new Uint32Array(80),Jt=new Uint32Array(80),lo=class extends tr{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)Qt[B]=t.getUint32(r),Jt[B]=t.getUint32(r+=4);for(let B=16;B<80;B++){let O=Qt[B-15]|0,C=Jt[B-15]|0,U=ce(O,C,1)^ce(O,C,8)^co(O,C,7),L=ae(O,C,1)^ae(O,C,8)^ao(O,C,7),T=Qt[B-2]|0,N=Jt[B-2]|0,j=ce(T,N,19)^er(T,N,61)^co(T,N,6),F=ae(T,N,19)^rr(T,N,61)^ao(T,N,6),d=Si(L,F,Jt[B-7],Jt[B-16]),m=vi(d,U,j,Qt[B-7],Qt[B-16]);Qt[B]=m|0,Jt[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:x,Hl:v}=this;for(let B=0;B<80;B++){let O=ce(l,w,14)^ce(l,w,18)^er(l,w,41),C=ae(l,w,14)^ae(l,w,18)^rr(l,w,41),U=l&p^~l&S,L=w&b^~w&h,T=Ai(v,C,L,Kf[B],Jt[B]),N=Bi(T,x,O,U,Ff[B],Qt[B]),j=T|0,F=ce(n,o,28)^er(n,o,34)^er(n,o,39),d=ae(n,o,28)^rr(n,o,34)^rr(n,o,39),m=n&s^n&c^s&c,E=o&i^o&f^i&f;x=S|0,v=h|0,S=p|0,h=b|0,p=l|0,b=w|0,{h:l,l:w}=Ut(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 g=wi(j,d,E);n=Ei(g,N,F,m),o=g|0}({h:n,l:o}=Ut(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ut(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:f}=Ut(this.Ch|0,this.Cl|0,c|0,f|0),{h:a,l:u}=Ut(this.Dh|0,this.Dl|0,a|0,u|0),{h:l,l:w}=Ut(this.Eh|0,this.El|0,l|0,w|0),{h:p,l:b}=Ut(this.Fh|0,this.Fl|0,p|0,b|0),{h:S,l:h}=Ut(this.Gh|0,this.Gl|0,S|0,h|0),{h:x,l:v}=Ut(this.Hh|0,this.Hl|0,x|0,v|0),this.set(n,o,s,i,c,f,a,u,l,w,p,b,S,h,x,v)}roundClean(){Vt(Qt,Jt)}destroy(){this.destroyed=!0,Vt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},ho=class extends lo{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 Ti=so(()=>new uo,io(1));var Pr=so(()=>new ho,io(3));var V=(e,t,r)=>St(e,t,r),mo=Wt,Ie=Lr,nt=(...e)=>oo(...e),Ce=e=>Je(e),fe=no,nr=e=>mi(e),Nr=BigInt(0),po=BigInt(1);function Tt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new TypeError(r+"expected boolean, got type="+typeof e)}return e}function Fr(e){if(typeof e=="bigint"){if(!Ur(e))throw new RangeError("positive bigint expected, got "+e)}else mo(e);return e}function It(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 or(e){let t=Fr(e).toString(16);return t.length&1?"0"+t:t}function Ii(e){if(typeof e!="string")throw new TypeError("hex string expected, got "+typeof e);return e===""?Nr:BigInt("0x"+e)}function ue(e){return Ii(Lr(e))}function Nt(e){return Ii(Lr(sr(St(e)).reverse()))}function Kr(e,t){if(Wt(t),t===0)throw new RangeError("zero length");e=Fr(e);let r=e.toString(16);if(r.length>t*2)throw new RangeError("number too large");return Je(r.padStart(t*2,"0"))}function yo(e,t){return Kr(e,t).reverse()}function Ci(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 sr(e){return Uint8Array.from(V(e))}function kr(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 Ur=e=>typeof e=="bigint"&&Nr<=e;function kf(e,t,r){return Ur(e)&&Ur(t)&&Ur(r)&&t<=e&&e<r}function De(e,t,r,n){if(!kf(t,r,n))throw new RangeError("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Oe(e){if(e<Nr)throw new Error("expected non-negative bigint, got "+e);let t;for(t=0;e>Nr;e>>=po,t+=1);return t}var ir=e=>(po<<BigInt(e))-po;function Di(e,t,r){if(Wt(e,"hashLen"),Wt(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,x=[];for(;h<t;){f=w();let v=f.slice();x.push(v),h+=f.length}return nt(...x)};return(h,x)=>{l(),p(h);let v;for(;(v=x(b()))===void 0;)p();return l(),v}}function Ct(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 bo=()=>{throw new Error("not implemented")};var ut=BigInt(0),X=BigInt(1),le=BigInt(2),Pi=BigInt(3),Ui=BigInt(4),Ni=BigInt(5),Mf=BigInt(7),Fi=BigInt(8),Vf=BigInt(9),Ki=BigInt(16);function tt(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 Oi(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=tt(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 tt(o,t)}function go(e,t,r){let n=e;if(!n.eql(n.sqr(t),r))throw new Error("Cannot find square root")}function ki(e,t){let r=e,n=(r.ORDER+X)/Ui,o=r.pow(t,n);return go(r,o,t),o}function Hf(e,t){let r=e,n=(r.ORDER-Ni)/Fi,o=r.mul(t,le),s=r.pow(o,n),i=r.mul(t,s),c=r.mul(r.mul(i,le),s),f=r.mul(i,r.sub(c,r.ONE));return go(r,f,t),f}function qf(e){let t=Le(e),r=Mi(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+Mf)/Ki;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),x=a.cmov(u,l,h);return go(a,x,f),x})}function Mi(e){if(e<Pi)throw new Error("sqrt is not defined for small field");let t=e-X,r=0;for(;t%le===ut;)t/=le,r++;let n=le,o=Le(e);for(;Li(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return ki;let s=o.pow(n,t),i=(t+X)/le;return function(f,a){let u=f;if(u.is0(a))return a;if(Li(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 x=X<<BigInt(l-S-1),v=u.pow(w,x);l=S,w=u.sqr(v),p=u.mul(p,w),b=u.mul(b,v)}return b}}function zf(e){return e%Ui===Pi?ki:e%Fi===Ni?Hf:e%Ki===Vf?qf(e):Mi(e)}var qt=(e,t)=>(tt(e,t)&X)===X,jf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function xo(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=jf.reduce((n,o)=>(n[o]="function",n),t);if(Ct(e,r),It(e.BYTES,"BYTES"),It(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 Zf(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 cr(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 Li(e,t){let r=e,n=(r.ORDER-X)/le,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 $f(e,t){if(t!==void 0&&mo(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=Oe(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 Ri=new WeakMap,Mr=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}=$f(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 tt(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 tt(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return tt(t*t,this.ORDER)}add(t,r){return tt(t+r,this.ORDER)}sub(t,r){return tt(t-r,this.ORDER)}mul(t,r){return tt(t*r,this.ORDER)}pow(t,r){return Zf(this,t,r)}div(t,r){return tt(t*Oi(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 Oi(t,this.ORDER)}sqrt(t){let r=Ri.get(this);return r||Ri.set(this,r=zf(this.ORDER)),r(this,t)}toBytes(t){return this.isLE?yo(t,this.BYTES):Kr(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?Nt(t):ue(t);if(c&&(f=tt(f,i)),!r&&!this.isValid(f))throw new Error("invalid field element: outside of range 0..ORDER");return f}invertBatch(t){return cr(this,t)}cmov(t,r,n){return Tt(n,"condition"),n?r:t}};Object.freeze(Mr.prototype);function Le(e,t={}){return new Mr(e,t)}function Vi(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=Oe(e-X);return Math.ceil(t/8)}function wo(e){let t=Vi(e);return t+Math.ceil(t/2)}function Eo(e,t,r=!1){V(e);let n=e.length,o=Vi(t),s=Math.max(wo(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Nt(e):ue(e),c=tt(i,t-X)+X;return r?yo(c,o):Kr(c,o)}var Re=BigInt(0),de=BigInt(1);function ar(e,t){let r=t.negate();return e?r:t}function he(e,t){let r=cr(e.Fp,t.map(n=>n.Z));return t.map((n,o)=>e.fromAffine(n.toAffine(r[o])))}function ji(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function So(e,t){ji(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=ir(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Hi(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+=de);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 vo=new WeakMap,Zi=new WeakMap;function Ao(e){return Zi.get(e)||1}function qi(e){if(e!==Re)throw new Error("invalid wNAF")}var Pe=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>Re;)r&de&&(n=n.add(o)),o=o.double(),r>>=de;return n}precomputeWindow(t,r){let{windows:n,windowSize:o}=So(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=So(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:f,offset:a,isZero:u,isNeg:l,isNegF:w,offsetF:p}=Hi(n,c,i);n=f,u?s=s.add(ar(w,r[p])):o=o.add(ar(l,r[a]))}return qi(n),{p:o,f:s}}wNAFUnsafe(t,r,n,o=this.ZERO){let s=So(t,this.bits);for(let i=0;i<s.windows&&n!==Re;i++){let{nextN:c,offset:f,isZero:a,isNeg:u}=Hi(n,i,s);if(n=c,!a){let l=r[f];o=o.add(u?l.negate():l)}}return qi(n),o}getPrecomputes(t,r,n){let o=vo.get(r);return o||(o=this.precomputeWindow(r,t),t!==1&&(typeof n=="function"&&(o=n(o)),vo.set(r,o))),o}cached(t,r,n){let o=Ao(t);return this.wNAF(o,this.getPrecomputes(o,t,n),r)}unsafe(t,r,n,o){let s=Ao(t);return s===1?this._unsafeLadder(t,r,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),r,o)}createCache(t,r){ji(r,this.bits),Zi.set(t,r),vo.delete(t)}hasCache(t){return Ao(t)!==1}};function $i(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Re||n>Re;)r&de&&(s=s.add(o)),n&de&&(i=i.add(o)),o=o.double(),r>>=de,n>>=de;return{p1:s,p2:i}}function zi(e,t,r){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return xo(t),t}else return Le(e,{isLE:r})}function Vr(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>Re))throw new Error(`CURVE.${f} must be positive bigint`)}let o=zi(t.p,r.Fp,n),s=zi(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 Hr(e,t){return function(n){let o=e(n);return{secretKey:o,publicKey:t(o)}}}var te=BigInt(0),it=BigInt(1),Bo=BigInt(2),Yf=BigInt(8);function Gf(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 Yi(e,t={}){let r=t,n=Vr("edwards",e,r,r.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:c}=i;Ct(r,{},{uvRatio:"function"});let f=Bo<<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:te}}}:r.uvRatio;if(!Gf(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function l(S,h,x=!1){let v=x?it:te;return De("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(te,it,it,te);static Fp=o;static Fn=s;X;Y;Z;T;constructor(h,x,v,B){this.X=l("x",h),this.Y=l("y",x),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,y:v}=h||{};return l("x",x),l("y",v),new p(x,v,it,a(x*v))}static fromBytes(h,x=!1){let v=o.BYTES,{a:B,d:O}=i;h=sr(V(h,v,"point")),Tt(x,"zip215");let C=sr(h),U=h[v-1];C[v-1]=U&-129;let L=Nt(C),T=x?f:o.ORDER;De("point.y",L,te,T);let N=a(L*L),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,g=(U&128)!==0;if(!x&&m===te&&g)throw new Error("bad point: x=0 and x_0=1");return g!==E&&(m=a(-m)),p.fromAffine({x:m,y:L})}static fromHex(h,x=!1){return p.fromBytes(Ce(h),x)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(h=8,x=!0){return b.createCache(this,h),x||this.multiply(Bo),this}assertValidity(){let h=this,{a:x,d:v}=i;if(h.is0())throw new Error("bad point: ZERO");let{X:B,Y:O,Z:C,T:U}=h,L=a(B*B),T=a(O*O),N=a(C*C),j=a(N*N),F=a(L*x),d=a(N*a(F+T)),m=a(j+a(v*a(L*T)));if(d!==m)throw new Error("bad point: equation left != right (1)");let E=a(B*O),g=a(C*U);if(E!==g)throw new Error("bad point: equation left != right (2)")}equals(h){w(h);let{X:x,Y:v,Z:B}=this,{X:O,Y:C,Z:U}=h,L=a(x*U),T=a(O*B),N=a(v*U),j=a(C*B);return L===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:x,Y:v,Z:B}=this,O=a(x*x),C=a(v*v),U=a(Bo*a(B*B)),L=a(h*O),T=x+v,N=a(a(T*T)-O-C),j=L+C,F=j-U,d=L-C,m=a(N*F),E=a(j*d),g=a(N*d),y=a(F*j);return new p(m,E,y,g)}add(h){w(h);let{a:x,d:v}=i,{X:B,Y:O,Z:C,T:U}=this,{X:L,Y:T,Z:N,T:j}=h,F=a(B*L),d=a(O*T),m=a(U*v*j),E=a(C*N),g=a((B+O)*(L+T)-F-d),y=E-m,A=E+m,I=a(d-x*F),_=a(g*y),D=a(A*I),P=a(g*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:x,f:v}=b.cached(this,h,B=>he(p,B));return he(p,[x,v])[0]}multiplyUnsafe(h){if(!s.isValid(h))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return h===te?p.ZERO:this.is0()||h===it?this:b.unsafe(this,h,x=>he(p,x))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return b.unsafe(this,i.n).is0()}toAffine(h){let x=this,v=h,{X:B,Y:O,Z:C}=x,U=x.is0();v==null&&(v=U?Yf:o.inv(C));let L=a(B*v),T=a(O*v),N=o.mul(C,v);if(U)return{x:te,y:it};if(N!==it)throw new Error("invZ was invalid");return{x:L,y:T}}clearCofactor(){return c===it?this:this.multiplyUnsafe(c)}toBytes(){let{x:h,y:x}=this.toAffine(),v=o.toBytes(x);return v[v.length-1]|=h&it?128:0,v}toHex(){return Ie(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let b=new Pe(p,s.BITS);return s.BITS>=8&&p.BASE.precompute(8),Object.freeze(p.prototype),Object.freeze(p),p}var qr=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){bo()}static fromHex(t){bo()}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 Ie(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 Gi(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:c,Fn:f}=e,a=n.outputLen,u=2*c.BYTES;if(a!==void 0&&(It(a,"hash.outputLen"),a!==u))throw new Error(`hash.outputLen must be ${u}, got ${a}`);let l=o.randomBytes===void 0?nr:o.randomBytes,w=o.adjustScalarBytes===void 0?d=>d:o.adjustScalarBytes,p=o.domain===void 0?(d,m,E)=>{if(Tt(E,"phflag"),m.length||E)throw new Error("Contexts/pre-hash are not supported");return d}:o.domain;function b(d){return f.create(Nt(d))}function S(d){let m=L.secretKey;V(d,L.secretKey,"secretKey");let E=V(n(d),2*m,"hashedSecretKey"),g=w(E.slice(0,m)),y=E.slice(m,2*m),A=b(g);return{head:g,prefix:y,scalar:A}}function h(d){let{head:m,prefix:E,scalar:g}=S(d),y=i.multiply(g),A=y.toBytes();return{head:m,prefix:E,scalar:g,point:y,pointBytes:A}}function x(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:g,scalar:y,pointBytes:A}=h(m),I=v(E.context,g,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,L.signature,"result")}let O={zip215:o.zip215};function C(d,m,E,g=O){let{context:y}=g,A=g.zip215===void 0?!!O.zip215:g.zip215,I=L.signature;d=V(d,I,"signature"),m=V(m,void 0,"message"),E=V(E,L.publicKey,"publicKey"),A!==void 0&&Tt(A,"zip215"),s&&(m=s(m));let _=I/2,D=d.subarray(0,_),P=Nt(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,L={secretKey:U,publicKey:U,signature:2*U,seed:U};function T(d){return d=d===void 0?l(L.seed):d,V(d,L.seed,"seed")}function N(d){return fe(d)&&d.length===L.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=L.publicKey,g=E===32;if(!g&&E!==57)throw new Error("only defined for 25519 and 448");let y=g?c.div(it+m,it-m):c.div(m-it,m+it);return c.toBytes(y)},toMontgomerySecret(d){let m=L.secretKey;V(d,m);let E=n(d.subarray(0,m));return w(E).subarray(0,m)}};return Object.freeze(L),Object.freeze(F),Object.freeze({keygen:Hr(T,x),getPublicKey:x,sign:B,verify:C,utils:F,Point:e,lengths:L})}function fr(e,t){if(It(e),It(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 Wf(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 Xf(e){if(!fe(e)&&typeof e!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof e=="string"?kr(e):e;if(t.length===0)throw new Error("DST must be non-empty");return t}function _o(e,t,r,n){V(e),It(r),t=Xf(t),t.length>255&&(t=n(nt(kr("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,fr(t.length,1)),f=new Uint8Array(s),a=fr(r,2),u=new Array(i),l=n(nt(f,e,a,fr(0,1),c));u[0]=n(nt(l,fr(1,1),c));for(let p=1;p<i;p++){let b=[Wf(l,u[p-1]),fr(p+1,1),c];u[p]=n(nt(...b))}return nt(...u).slice(0,r)}var Wi="HashToScalar-";var Qf=BigInt(0),zt=BigInt(1),Xi=BigInt(2);var Jf=BigInt(5),tu=BigInt(8),Ue=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Do={p:Ue,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:tu,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function eu(e){let t=BigInt(10),r=BigInt(20),n=BigInt(40),o=BigInt(80),s=Ue,c=e*e%s*e%s,f=Y(c,Xi,s)*c%s,a=Y(f,zt,s)*e%s,u=Y(a,Jf,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,Xi,s)*e%s,b2:c}}function ru(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var To=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Oo(e,t){let r=Ue,n=tt(t*t*t,r),o=tt(n*n*t,r),s=eu(e*o).pow_p_5_8,i=tt(e*n*s,r),c=tt(t*i*i,r),f=i,a=tt(i*To,r),u=c===e,l=c===tt(-e,r),w=c===tt(-e*To,r);return u&&(i=f),(l||w)&&(i=a),qt(i,r)&&(i=tt(-i,r)),{isValid:u||l,value:i}}var re=Yi(Do,{uvRatio:Oo}),ee=re.Fp,tc=re.Fn;function nu(e){return Gi(re,Pr,Object.assign({adjustScalarBytes:ru,zip215:!0},e))}var ec=nu({});var Io=To,ou=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),su=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),iu=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),cu=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Qi=e=>Oo(zt,e),au=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Co=e=>ee.create(Nt(e)&au);function Ji(e){let{d:t}=Do,r=Ue,n=x=>ee.create(x),o=n(Io*e*e),s=n((o+zt)*iu),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:f,value:a}=Oo(s,c),u=n(a*e);qt(u,r)||(u=n(-u)),f||(a=u),f||(i=o);let l=n(i*(o-zt)*cu-c),w=a*a,p=n((a+a)*c),b=n(l*ou),S=n(zt-w),h=n(zt+w);return new re(n(p*h),n(S*b),n(b*h),n(p*S))}var ne=class e extends qr{static BASE=new e(re.BASE);static ZERO=new e(re.ZERO);static Fp=ee;static Fn=tc;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){St(t,32);let{a:r,d:n}=Do,o=Ue,s=O=>ee.create(O),i=Co(t);if(!Ci(ee.toBytes(i),t)||qt(i,o))throw new Error("invalid ristretto255 encoding 1");let c=s(i*i),f=s(zt+r*c),a=s(zt-r*c),u=s(f*f),l=s(a*a),w=s(r*n*u-l),{isValid:p,value:b}=Qi(s(w*l)),S=s(b*a),h=s(b*S*w),x=s((i+i)*S);qt(x,o)&&(x=s(-x));let v=s(f*h),B=s(x*v);if(!p||qt(B,o)||v===Qf)throw new Error("invalid ristretto255 encoding 2");return new e(new re(x,v,zt,B))}static fromHex(t){return e.fromBytes(Je(t))}toBytes(){let{X:t,Y:r,Z:n,T:o}=this.ep,s=Ue,i=h=>ee.create(h),c=i(i(n+r)*i(n-r)),f=i(t*r),a=i(f*f),{value:u}=Qi(i(c*a)),l=i(u*c),w=i(u*f),p=i(l*w*o),b;if(qt(o*p,s)){let h=i(r*Io),x=i(t*Io);t=h,r=x,b=i(l*su)}else b=w;qt(t*p,s)&&(r=i(-r));let S=i((n-r)*b);return qt(S,s)&&(S=i(-S)),ee.toBytes(S)}equals(t){this.assertSame(t);let{X:r,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=a=>ee.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(ne.BASE);Object.freeze(ne.ZERO);Object.freeze(ne.prototype);Object.freeze(ne);var fu=Object.freeze({Point:ne,hashToCurve(e,t){let r=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=_o(e,r,64,Pr);return fu.deriveToCurve(n)},hashToScalar(e,t={DST:Wi}){let r=_o(e,t.DST,64,Pr);return tc.create(Nt(r))},deriveToCurve(e){St(e,64);let t=Co(e.subarray(0,32)),r=Ji(t),n=Co(e.subarray(32,64)),o=Ji(n);return new ne(r.add(o))}});var ur=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},zr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var jr={get(e=globalThis){let t=e.crypto;if(t?.subtle==null)throw new zr("Missing Web Crypto API. The most likely cause of this error is that this page is being accessed from an insecure context (i.e. not HTTPS). For more information and possible resolutions see https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/README.md#web-crypto-api");return t}};var Zr=32;var Lo,uu=(async()=>{try{return await jr.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function lu(e,t,r){if(e.buffer instanceof ArrayBuffer){let n=await jr.get().subtle.importKey("raw",e.buffer,{name:"Ed25519"},!1,["verify"]);return await jr.get().subtle.verify({name:"Ed25519"},n,Bt(t),Bt(r instanceof Uint8Array?r:r.subarray()))}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function du(e,t,r){return ec.verify(t,r instanceof Uint8Array?r:r.subarray(),e)}async function rc(e,t,r){return Lo==null&&(Lo=await uu),Lo?lu(e,t,r):du(e,t,r)}function $r(e){return e==null?!1:typeof e.then=="function"&&typeof e.catch=="function"&&typeof e.finally=="function"}var Yr=class{type="Ed25519";raw;constructor(t){this.raw=Ro(t,Zr)}toMultihash(){return At.digest(_e(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return et.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}verify(t,r,n){n?.signal?.throwIfAborted();let o=rc(this.raw,r,t);return $r(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function oc(e){return e=Ro(e,Zr),new Yr(e)}function Ro(e,t){if(e=Uint8Array.from(e??[]),e.length!==t)throw new Lt(`Key must be a Uint8Array of length ${t}, got ${e.length}`);return e}var pu=Math.pow(2,7),mu=Math.pow(2,14),yu=Math.pow(2,21),Po=Math.pow(2,28),Uo=Math.pow(2,35),No=Math.pow(2,42),Fo=Math.pow(2,49),G=128,dt=127;function Ft(e){if(e<pu)return 1;if(e<mu)return 2;if(e<yu)return 3;if(e<Po)return 4;if(e<Uo)return 5;if(e<No)return 6;if(e<Fo)return 7;if(Number.MAX_SAFE_INTEGER!=null&&e>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function lr(e,t,r=0){switch(Ft(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 Ko(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)*Po,r<G)||(r=e[t+5],n+=(r&dt)*Uo,r<G)||(r=e[t+6],n+=(r&dt)*No,r<G)||(r=e[t+7],n+=(r&dt)*Fo,r<G))return n;throw new RangeError("Could not decode varint")}function bu(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)*Po,r<G)||(r=e.get(t+5),n+=(r&dt)*Uo,r<G)||(r=e.get(t+6),n+=(r&dt)*No,r<G)||(r=e.get(t+7),n+=(r&dt)*Fo,r<G))return n;throw new RangeError("Could not decode varint")}function ko(e,t=0){return e instanceof Uint8Array?Ko(e,t):bu(e,t)}var Mo=new Float32Array([-0]),oe=new Uint8Array(Mo.buffer);function sc(e,t,r){Mo[0]=e,t[r]=oe[0],t[r+1]=oe[1],t[r+2]=oe[2],t[r+3]=oe[3]}function ic(e,t){return oe[0]=e[t],oe[1]=e[t+1],oe[2]=e[t+2],oe[3]=e[t+3],Mo[0]}var Vo=new Float64Array([-0]),ht=new Uint8Array(Vo.buffer);function cc(e,t,r){Vo[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 ac(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],Vo[0]}var xu=BigInt(Number.MAX_SAFE_INTEGER),wu=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 pe;if(t<xu&&t>wu)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>fc&&(o=0n,++n>fc&&(n=0n))),new e(Number(o),Number(n))}static fromNumber(t){if(t===0)return pe;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):pe}},pe=new vt(0,0);pe.toBigInt=function(){return 0n};pe.zzEncode=pe.zzDecode=function(){return this};pe.length=function(){return 1};var fc=4294967296n;function uc(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 lc(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 Ho(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 Dt(e,t){return RangeError(`index out of range: ${e.pos} + ${t??1} > ${e.len}`)}function Gr(e,t){return(e[t-4]|e[t-3]<<8|e[t-2]<<16|e[t-1]<<24)>>>0}var qo=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(t){this.buf=Bt(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,Dt(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 Dt(this,4);return Gr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Dt(this,4);return Gr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Dt(this,4);let t=ic(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw Dt(this,4);let t=ac(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 Dt(this,t);return this.pos+=t,r===n?new Uint8Array(0):this.buf.subarray(r,n)}string(){let t=this.bytes();return lc(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw Dt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw Dt(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 Dt(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 Dt(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 Dt(this,8);let t=Gr(this.buf,this.pos+=4),r=Gr(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=Ko(this.buf,this.pos);return this.pos+=Ft(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 dr(e){return new qo(e instanceof Uint8Array?e:e.subarray())}function Wr(e,t,r){let n=dr(e);return t.decode(n,void 0,r)}function zo(e){let t=e??8192,r=t>>>1,n,o=t;return function(i){if(i<1||i>r)return mt(i);o+i>t&&(n=mt(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var me=class{fn;len;next;val;constructor(t,r,n){this.fn=t,this.len=r,this.next=void 0,this.val=n}};function jo(){}var $o=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Eu=zo();function Su(e){return globalThis.Buffer!=null?mt(e):Eu(e)}var pr=class{len;head;tail;states;constructor(){this.len=0,this.head=new me(jo,0,0),this.tail=this.head,this.states=null}_push(t,r,n){return this.tail=this.tail.next=new me(t,r,n),this.len+=r,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Yo((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(Xr,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(Xr,r.length(),r)}uint64Number(t){return this._push(lr,Ft(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(Xr,r.length(),r)}sint64Number(t){let r=vt.fromNumber(t).zzEncode();return this._push(Xr,r.length(),r)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Zo,1,t?1:0)}fixed32(t){return this._push(hr,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let r=vt.fromBigInt(t);return this._push(hr,4,r.lo)._push(hr,4,r.hi)}fixed64Number(t){let r=vt.fromNumber(t);return this._push(hr,4,r.lo)._push(hr,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(sc,4,t)}double(t){return this._push(cc,8,t)}bytes(t){let r=t.length>>>0;return r===0?this._push(Zo,1,0):this.uint32(r)._push(Au,r,t)}string(t){let r=uc(t);return r!==0?this.uint32(r)._push(Ho,r,t):this._push(Zo,1,0)}fork(){return this.states=new $o(this),this.head=this.tail=new me(jo,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new me(jo,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=Su(this.len),n=0;for(;t!=null;)t.fn(t.val,r,n),n+=t.len,t=t.next;return r}};function Zo(e,t,r){t[r]=e&255}function vu(e,t,r){for(;e>127;)t[r++]=e&127|128,e>>>=7;t[r]=e}var Yo=class extends me{next;constructor(t,r){super(vu,t,r),this.next=void 0}};function Xr(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 hr(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 Au(e,t,r){t.set(e,r)}globalThis.Buffer!=null&&(pr.prototype.bytes=function(e){let t=e.length>>>0;return this.uint32(t),t>0&&this._push(Bu,t,e),this},pr.prototype.string=function(e){let t=globalThis.Buffer.byteLength(e);return this.uint32(t),t>0&&this._push(_u,t,e),this});function Bu(e,t,r){t.set(e,r)}function _u(e,t,r){e.length<40?Ho(e,t,r):t.utf8Write!=null?t.utf8Write(e,r):t.set(xt(e),r)}function Go(){return new pr}function Qr(e,t){let r=Go();return t.encode(e,r,{lengthDelimited:!1}),r.finish()}function*Jr(e,t,r){let n=dr(e);yield*t.stream(n,void 0,"$",r)}var tn={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function en(e,t,r,n,o){return{name:e,type:t,encode:r,decode:n,stream:o}}function Wo(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 en("enum",tn.VARINT,r,n,o)}function rn(e,t,r){return en("message",tn.LENGTH_DELIMITED,e,t,r)}var yt;(function(e){e.RSA="RSA",e.Ed25519="Ed25519",e.secp256k1="secp256k1",e.ECDSA="ECDSA"})(yt||(yt={}));var Xo;(function(e){e[e.RSA=0]="RSA",e[e.Ed25519=1]="Ed25519",e[e.secp256k1=2]="secp256k1",e[e.ECDSA=3]="ECDSA"})(Xo||(Xo={}));(function(e){e.codec=()=>Wo(Xo)})(yt||(yt={}));var mr;(function(e){let t;e.codec=()=>(t==null&&(t=rn((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),yt.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=yt.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:yt.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 Qr(s,e.codec())}e.encode=r;function n(s,i){return Wr(s,e.codec(),i)}e.decode=n;function o(s,i){return Jr(s,e.codec(),i)}e.stream=o})(mr||(mr={}));var Qo;(function(e){let t;e.codec=()=>(t==null&&(t=rn((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),yt.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=yt.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:yt.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 Qr(s,e.codec())}e.encode=r;function n(s,i){return Wr(s,e.codec(),i)}e.decode=n;function o(s,i){return Jr(s,e.codec(),i)}e.stream=o})(Qo||(Qo={}));var nn=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,r){if(Cr(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),Vt(o)}update(t){return Te(this),this.iHash.update(t),this}digestInto(t){Te(this),Dr(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()}},hc=(()=>{let e=((t,r,n)=>new nn(t,r).update(n).digest());return e.create=(t,r)=>new nn(t,r),e})();var pc=(e,t)=>(e+(e>=0?t:-t)/mc)/t;function Iu(e,t,r){De("scalar",e,Kt,r);let[[n,o],[s,i]]=t,c=pc(i*e,r),f=pc(-o*e,r),a=e-c*n-f*s,u=-c*o-f*i,l=a<Kt,w=u<Kt;l&&(a=-a),w&&(u=-u);let p=ir(Math.ceil(Oe(r)/2))+se;if(a<Kt||a>=p||u<Kt||u>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:l,k1:a,k2neg:w,k2:u}}function ts(e){if(!["compact","recovered","der"].includes(e))throw new Error('Signature format must be "compact", "recovered", or "der"');return e}function Jo(e,t){Ct(e);let r={};for(let n of Object.keys(t))r[n]=e[n]===void 0?t[n]:e[n];return Tt(r.lowS,"lowS"),Tt(r.prehash,"prehash"),r.format!==void 0&&ts(r.format),r}var es=class extends Error{constructor(t=""){super(t)}},Ot={Err:es,_tlv:{encode:(e,t)=>{let{Err:r}=Ot;if(It(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=or(n);if(o.length/2&128)throw new r("tlv.encode: long form length too big");let s=n>127?or(o.length/2|128):"";return or(e)+s+o+t},decode(e,t){let{Err:r}=Ot;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}=Ot;if(Fr(e),e<Kt)throw new t("integer: negative integers are not allowed");let r=or(e);if(Number.parseInt(r[0],16)&8&&(r="00"+r),r.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return r},decode(e){let{Err:t}=Ot;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 ue(e)}},toSig(e){let{Err:t,_int:r,_tlv:n}=Ot,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}=Ot,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(Ot._tlv);Object.freeze(Ot._int);Object.freeze(Ot);var Kt=BigInt(0),se=BigInt(1),mc=BigInt(2),on=BigInt(3),Cu=BigInt(4);function yc(e,t={}){let r=Vr("weierstrass",e,t),n=r.Fp,o=r.Fn,s=r.CURVE,{h:i,n:c}=s;Ct(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=gc(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:g}=d.toAffine(),y=n.toBytes(E);if(Tt(m,"isCompressed"),m){l();let A=!n.isOdd(g);return nt(bc(A),y)}else return nt(Uint8Array.of(4),y,n.toBytes(g))}function p(F){V(F,void 0,"Point");let{publicKey:d,publicKeyUncompressed:m}=u,E=F.length,g=F[0],y=F.subarray(1);if(a&&E===1&&g===0)return{x:n.ZERO,y:n.ZERO};if(E===d&&(g===2||g===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(g&1)===1!==D&&(_=n.neg(_)),{x:A,y:_}}else if(E===m&&g===4){let A=n.BYTES,I=n.fromBytes(y.subarray(0,A)),_=n.fromBytes(y.subarray(A,A*2));if(!x(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 x(F,d){let m=n.sqr(d),E=h(F);return n.eql(m,E)}if(!x(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let v=n.mul(n.pow(s.a,on),Cu),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 Iu(F,f.basises,o.ORDER)}function L(F,d,m,E,g){return m=new T(n.mul(m.X,F),m.Y,m.Z),d=ar(E,d),m=ar(g,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(Ce(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(on),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(!x(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:g}=this,{X:y,Y:A,Z:I}=d,_=n.eql(n.mul(m,I),n.mul(y,g)),D=n.eql(n.mul(E,I),n.mul(A,g));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,on),{X:g,Y:y,Z:A}=this,I=n.ZERO,_=n.ZERO,D=n.ZERO,P=n.mul(g,g),M=n.mul(y,y),q=n.mul(A,A),K=n.mul(g,y);return K=n.add(K,K),D=n.mul(g,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:g}=this,{X:y,Y:A,Z:I}=d,_=n.ZERO,D=n.ZERO,P=n.ZERO,M=s.a,q=n.mul(s.b,on),K=n.mul(m,y),rt=n.mul(E,A),ot=n.mul(g,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,g);let bt=n.add(y,I);return Q=n.mul(Q,bt),bt=n.add(K,ot),Q=n.sub(Q,bt),bt=n.add(E,g),_=n.add(A,I),bt=n.mul(bt,_),_=n.add(rt,ot),bt=n.sub(bt,_),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(bt,Q),_=n.mul(st,_),_=n.sub(_,K),K=n.mul(st,rt),P=n.mul(bt,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,g,y=A=>j.cached(this,A,I=>he(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);g=M.add(K),E=L(m.beta,P,q,A,_)}else{let{p:A,f:I}=y(d);E=A,g=I}return he(T,[E,g])[0]}multiplyUnsafe(d){let{endo:m}=t,E=this,g=d;if(!o.isValid(g))throw new RangeError("invalid scalar: out of range");if(g===Kt||E.is0())return T.ZERO;if(g===se)return E;if(j.hasCache(this))return this.multiply(g);if(m){let{k1neg:y,k1:A,k2neg:I,k2:_}=U(g),{p1:D,p2:P}=$i(T,E,A,_);return L(m.beta,D,P,y,I)}else return j.unsafe(E,g)}toAffine(d){let m=this,E=d,{X:g,Y:y,Z:A}=m;if(n.eql(A,n.ONE))return{x:g,y};let I=m.is0();E==null&&(E=I?n.ONE:n.inv(A));let _=n.mul(g,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===se?!0:d?d(T,this):j.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:d}=t;return i===se?this:d?d(T,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===se?this.is0():this.clearCofactor().is0()}toBytes(d=!0){return Tt(d,"isCompressed"),this.assertValidity(),b(T,this,d)}toHex(d=!0){return Ie(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let N=o.BITS,j=new Pe(T,t.endo?Math.ceil(N/2):N);return N>=8&&T.BASE.precompute(8),Object.freeze(T.prototype),Object.freeze(T),T}function bc(e){return Uint8Array.of(e?2:3)}function gc(e,t){return{secretKey:t.BYTES,publicKey:1+e.BYTES,publicKeyUncompressed:1+2*e.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Du(e,t={}){let{Fn:r}=e,n=t.randomBytes===void 0?nr:t.randomBytes,o=Object.assign(gc(e.Fp,r),{seed:Math.max(wo(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 x=p.length;return b===!0&&x!==S||b===!1&&x!==h?!1:!!e.fromBytes(p)}catch{return!1}}function c(p){return p=p===void 0?n(o.seed):p,Eo(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,x=r._lengths;if(!fe(p))return;let v=V(p,void 0,"key").length,B=v===S||v===h,O=v===b||!!x?.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=Hr(c,f);return Object.freeze(l),Object.freeze(o),Object.freeze({getPublicKey:f,getSharedSecret:u,keygen:w,Point:e,utils:l,lengths:o})}function xc(e,t,r={}){let n=t;Cr(n),Ct(r,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),r=Object.assign({},r);let o=r.randomBytes===void 0?nr:r.randomBytes,s=r.hmac===void 0?(g,y)=>hc(n,g,y):r.hmac,{Fp:i,Fn:c}=e,{ORDER:f,BITS:a}=c,{keygen:u,getPublicKey:l,getSharedSecret:w,utils:p,lengths:b}=Du(e,r),S={prehash:!0,lowS:typeof r.lowS=="boolean"?r.lowS:!0,format:"compact",extraEntropy:!1},h=f*mc+se<i.ORDER;function x(g){let y=f>>se;return g>y}function v(g,y){if(!c.isValidNot0(y))throw new Error(`invalid signature ${g}: 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(g,y){ts(y);let A=b.signature,I=y==="compact"?A:y==="recovered"?A+1:void 0;return V(g,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}=Ot.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(Ce(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(bc((_&1)===0),P)),q=c.inv(D),K=L(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 x(this.s)}toBytes(y=S.format){if(ts(y),y==="der")return Ce(Ot.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 Ie(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=ue(y),I=y.length*8-a;return I>0?A>>BigInt(I):A}:r.bits2int,L=r.bits2int_modN===void 0?function(y){return c.create(U(y))}:r.bits2int_modN,T=ir(a);function N(g){return De("num < 2^"+a,g,Kt,T),c.toBytes(g)}function j(g,y){return V(g,void 0,"message"),y?V(n(g),void 0,"prehashed message"):g}function F(g,y,A){let{lowS:I,prehash:_,extraEntropy:D}=Jo(A,S);g=j(g,_);let P=L(g),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 bt=c.inv(Q),ge=e.BASE.multiply(Q).toAffine(),He=c.create(ge.x);if(He===Kt)return;let wr=c.create(bt*c.create(rt+He*M));if(wr===Kt)return;let Rs=(ge.x===He?0:2)|Number(ge.y&se),Ps=wr;return I&&x(wr)&&(Ps=c.neg(wr),Rs^=1),new C(He,Ps,h?void 0:Rs)}return{seed:K,k2sig:ot}}function d(g,y,A={}){let{seed:I,k2sig:_}=F(g,y,A);return Di(n.outputLen,c.BYTES,s)(I,_).toBytes(A.format)}function m(g,y,A,I={}){let{lowS:_,prehash:D,format:P}=Jo(I,S);if(A=V(A,void 0,"publicKey"),y=j(y,D),!fe(g)){let M=g instanceof C?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+M)}O(g,P);try{let M=C.fromBytes(g,P),q=e.fromBytes(A);if(_&&M.hasHighS())return!1;let{r:K,s:rt}=M,ot=L(y),st=c.inv(rt),Q=c.create(ot*st),bt=c.create(K*st),ge=e.BASE.multiplyUnsafe(Q).add(q.multiplyUnsafe(bt));return ge.is0()?!1:c.create(ge.x)===K}catch{return!1}}function E(g,y,A={}){let{prehash:I}=Jo(A,S);return y=j(y,I),C.fromBytes(g,"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 ns={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},Ou={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var wc=BigInt(2);function Lu(e){let t=ns.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,wc,t)*a%t,b=Y(p,o,t)*p%t,S=Y(b,s,t)*b%t,h=Y(S,c,t)*S%t,x=Y(h,f,t)*h%t,v=Y(x,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,wc,t);if(!rs.eql(rs.sqr(U),e))throw new Error("Cannot find square root");return U}var rs=Le(ns.p,{sqrt:Lu}),Ru=yc(ns,{Fp:rs,endo:Ou}),Ne=xc(Ru,Ti);function Ec(e,t,r,n){let o=Ge.digest(r instanceof Uint8Array?r:r.subarray());if($r(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ne.verify(t,s,e,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new ur(String(s))});try{return n?.signal?.throwIfAborted(),Ne.verify(t,o.digest,e,{prehash:!1,format:"der"})}catch(s){throw new ur(String(s))}}var sn=class{type="secp256k1";raw;_key;constructor(t){this._key=vc(t),this.raw=Sc(this._key)}toMultihash(){return At.digest(_e(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return et.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:gt(this.raw,t.raw)}verify(t,r,n){return Ec(this._key,r,t,n)}};function Ac(e){return new sn(e)}function Sc(e){return Ne.Point.fromBytes(e).toBytes()}function vc(e){try{return Ne.Point.fromBytes(e),e}catch(t){throw new Er(String(t))}}function Bc(e){let{Type:t,Data:r}=mr.decode(e.digest),n=r??new Uint8Array;switch(t){case yt.Ed25519:return oc(n);case yt.secp256k1:return Ac(n);case yt.ECDSA:return ui(n);default:throw new qe}}function _e(e){return mr.encode({Type:yt[e.type],Data:e.raw})}var _c=Symbol.for("nodejs.util.inspect.custom"),Pu=114,yr=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()})`}[Tn]=!0;toString(){return this.string==null&&(this.string=et.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return at.createV1(Pu,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return gt(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return gt(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[_c](){return`PeerId(${this.toString()})`}},cn=class extends yr{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},an=class extends yr{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},fn=class extends yr{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Uu=2336,br=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=At.digest(xt(this.url))}[_c](){return`PeerId(${this.url})`}[Tn]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return at.createV1(Uu,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=J(t)),t.toString()===this.toString())}};var Nu=114,Tc=2336;function Ic(e,t){let r;if(e.charAt(0)==="1"||e.charAt(0)==="Q")r=$e(et.decode(`z${e}`));else{if(e.startsWith("k51qzi5uqu5")||e.startsWith("kzwfwjn5ji4")||e.startsWith("k2k4r8")||e.startsWith("bafz"))return Fu(at.parse(e));if(t==null)throw new Lt('Please pass a multibase decoder for strings that do not start with "1" or "Q"');r=$e(t.decode(e))}return Cc(r)}function Cc(e){if(ku(e))return new cn({multihash:e});if(Ku(e))try{let t=Bc(e);if(t.type==="Ed25519")return new an({multihash:e,publicKey:t});if(t.type==="secp256k1")return new fn({multihash:e,publicKey:t})}catch{let r=J(e.digest);return new br(new URL(r))}throw new vr("Supplied PeerID Multihash is invalid")}function Fu(e){if(e?.multihash==null||e.version==null||e.version===1&&e.code!==Nu&&e.code!==Tc)throw new Sr("Supplied PeerID CID is invalid");if(e.code===Tc){let t=J(e.multihash.digest);return new br(new URL(t))}return Cc(e.multihash)}function Ku(e){return e.code===At.code}function ku(e){return e.code===Ge.code}var lt=class extends Error{static name="InvalidMultiaddrError";name="InvalidMultiaddrError"},jt=class extends Error{static name="ValidationError";name="ValidationError"},un=class extends Error{static name="InvalidParametersError";name="InvalidParametersError"},ln=class extends Error{static name="UnknownProtocolError";name="UnknownProtocolError"};var dn=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 Mu=45,Vu=15,hn=new dn;function Dc(e){if(!(e.length>Vu))return hn.new(e).parseWith(()=>hn.readIPv4Addr())}function Oc(e){if(e.includes("%")&&(e=e.split("%")[0]),!(e.length>Mu))return hn.new(e).parseWith(()=>hn.readIPv6Addr())}function pn(e){return!!Dc(e)}function Lc(e){return!!Oc(e)}function ss(e){return t=>J(t,e)}function is(e){return t=>xt(t,e)}function Fe(e){return new DataView(e.buffer).getUint16(e.byteOffset).toString()}function ye(e){let t=new ArrayBuffer(2);return new DataView(t).setUint16(0,typeof e=="string"?parseInt(e):e),new Uint8Array(t)}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!==16)throw new Error(`failed to parse onion addr: ${t[0]} not a Tor onion address.`);let r=xt(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=ye(n);return Pt([r,o],r.length+o.length)}function Pc(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=Gt.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=ye(n);return Pt([r,o],r.length+o.length)}function cs(e){let t=e.subarray(0,e.length-2),r=e.subarray(e.length-2),n=J(t,"base32"),o=Fe(r);return`${n}:${o}`}var as=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},Uc=function(e){let t=0;e=e.toString().trim();let r=e.split(":",8),n;for(n=0;n<r.length;n++){let s=pn(r[n]),i;s&&(i=as(r[n]),r[n]=J(i.subarray(0,2),"base16")),i!=null&&++n<8&&r.splice(n,0,J(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},Nc=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(".")},Fc=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 Kc(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 os=Object.values(We).map(e=>e.decoder),Hu=(function(){let e=os[0].or(os[1]);return os.slice(2).forEach(t=>e=e.or(t)),e})();function kc(e){return Hu.decode(e)}function Mc(e){return t=>e.encoder.encode(t)}function qu(e){if(parseInt(e).toString()!==e)throw new jt("Value must be an integer")}function zu(e){if(e<0)throw new jt("Value must be a positive integer, or zero")}function ju(e){return t=>{if(t>e)throw new jt(`Value must be smaller than or equal to ${e}`)}}function Zu(...e){return t=>{for(let r of e)r(t)}}var gr=Zu(qu,zu,ju(65535));var ct=-1,fs=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 ln(`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 fs,il=[{code:4,name:"ip4",size:32,valueToBytes:as,bytesToValue:Nc,validate:e=>{if(!pn(e))throw new jt(`Invalid IPv4 address "${e}"`)}},{code:6,name:"tcp",size:16,valueToBytes:ye,bytesToValue:Fe,validate:gr},{code:273,name:"udp",size:16,valueToBytes:ye,bytesToValue:Fe,validate:gr},{code:33,name:"dccp",size:16,valueToBytes:ye,bytesToValue:Fe,validate:gr},{code:41,name:"ip6",size:128,valueToBytes:Uc,bytesToValue:Fc,stringToValue:Kc,validate:e=>{if(!Lc(e))throw new jt(`Invalid IPv6 address "${e}"`)}},{code:42,name:"ip6zone",size:ct},{code:43,name:"ipcidr",size:8,bytesToValue:ss("base10"),valueToBytes:is("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:ye,bytesToValue:Fe,validate:gr},{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:ss("base58btc"),valueToBytes:e=>e.startsWith("Q")||e.startsWith("1")?is("base58btc")(e):at.parse(e).multihash.bytes},{code:444,name:"onion",size:96,bytesToValue:cs,valueToBytes:Rc},{code:445,name:"onion3",size:296,bytesToValue:cs,valueToBytes:Pc},{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:Mc(qn),valueToBytes:kc},{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}];il.forEach(e=>{$t.addProtocol(e)});function Vc(e){let t=[],r=0;for(;r<e.length;){let n=ko(e,r),o=$t.getProtocol(n),s=Ft(n),i=cl(o,e,r+s),c=0;i>0&&o.size===ct&&(c=Ft(i));let f=s+c+i,a={code:n,name:o.name,bytes:Bt(e.subarray(r,r+f))};if(i>0){let u=r+s+c,l=e.subarray(u,u+i);a.value=o.bytesToValue?.(l)??J(l)}t.push(a),r+=f}return t}function Hc(e){let t=0,r=[];for(let n of e){if(n.bytes==null){let o=$t.getProtocol(n.code),s=Ft(n.code),i,c=0,f=0;n.value!=null&&(i=o.valueToBytes?.(n.value)??xt(n.value),c=i.byteLength,o.size===ct&&(f=Ft(c)));let a=new Uint8Array(s+f+c),u=0;lr(n.code,a,u),u+=s,i!=null&&(o.size===ct&&(lr(c,a,u),u+=f),a.set(i,u)),n.bytes=a}r.push(n.bytes),t+=n.bytes.byteLength}return Pt(r,t)}function qc(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=$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(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 zc(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 cl(e,t,r){return e.size==null||e.size===0?0:e.size>0?e.size/8:ko(t,r)}var al=Symbol.for("nodejs.util.inspect.custom"),_s=Symbol.for("@multiformats/multiaddr");function fl(e){if(e==null&&(e="/"),jc(e))return e.getComponents();if(e instanceof Uint8Array)return Vc(e);if(typeof e=="string")return e=e.replace(/\/(\/)+/,"/").replace(/(\/)+$/,""),e===""&&(e="/"),qc(e);if(Array.isArray(e))return e;throw new lt("Must be a string, Uint8Array, Component[], or another Multiaddr")}var wn=class e{[_s]=!0;#t;#e;#r;constructor(t="/",r={}){this.#t=fl(t),r.validate!==!1&&ul(this)}get bytes(){return this.#r==null&&(this.#r=Hc(this.#t)),this.#r}toString(){return this.#e==null&&(this.#e=zc(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 un(`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 gt(this.bytes,t.bytes)}[al](){return`Multiaddr(${this.toString()})`}};function ul(e){e.getComponents().forEach(t=>{let r=$t.getProtocol(t.code);t.value!=null&&r.validate?.(t.value)})}function jc(e){return!!e?.[_s]}function Zc(e){return new wn(e)}var Z=e=>({match:t=>{let r=t[0];return r==null||r.code!==e||r.value!=null?!1:t.slice(1)}}),R=(e,t)=>({match:r=>{let n=r[0];return n?.code!==e||n.value==null||t!=null&&n.value!==t?!1:r.slice(1)}}),$c=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 ll=R(421),Py=$(ll),Sn=R(54),vn=R(55),An=R(56),Is=R(53),Uy=$(Sn,k(R(421))),Ny=$(vn,k(R(421))),Fy=$(An,k(R(421))),Ky=$(pt(Is,An,Sn,vn),k(R(421))),Yc=H(R(4),k(R(43))),Gc=H(k(R(42)),R(41),k(R(43))),Cs=pt(Yc,Gc),Ve=pt(Cs,Is,Sn,vn,An),ky=$(pt(Cs,H(pt(Is,An,Sn,vn),k(R(421))))),My=$(Yc),Vy=$(Gc),Hy=$(Cs),Ds=H(Ve,R(6)),xr=H(Ve,R(273)),qy=$(H(Ds,k(R(421)))),zy=$(xr),Os=H(xr,Z(460),k(R(421))),Bn=H(xr,Z(461),k(R(421))),dl=pt(Os,Bn),jy=$(Os),Zy=$(Bn),Ts=pt(Ve,Ds,xr,Os,Bn),Wc=pt(H(Ts,Z(477),k(R(421)))),$y=$(Wc),Xc=pt(H(Ts,Z(478),k(R(421))),H(Ts,Z(448),k(R(449)),Z(477),k(R(421)))),Yy=$(Xc),Qc=H(xr,Z(280),k(R(466)),k(R(466)),k(R(421))),Gy=$(Qc),Jc=H(Bn,Z(465),k(R(466)),k(R(466)),k(R(421))),Wy=$(Jc),En=pt(Wc,Xc,H(Ds,k(R(421))),H(dl,k(R(421))),H(Ve,k(R(421))),Qc,Jc,R(421)),ta=$(En),hl=H(k(En),Z(290),$c(Z(281)),k(R(421))),Xy=$(hl),pl=pt(H(En,Z(290),Z(281),k(R(421))),H(En,Z(281),k(R(421))),H(Z(281),k(R(421)))),Qy=$(pl),ml=H(Ve,pt(H(R(6,"80")),H(R(6),Z(480)),Z(480)),k(R(481)),k(R(421))),Jy=$(ml),yl=H(Ve,pt(H(R(6,"443")),H(R(6,"443"),Z(480)),H(R(6),Z(443)),H(R(6),Z(448),Z(480)),H(Z(448),Z(480)),Z(448),Z(443)),k(R(481)),k(R(421))),tb=$(yl),bl=pt(H(R(777),k(R(421)))),eb=$(bl),gl=pt(H(R(400),k(R(421)))),rb=$(gl);var xl="bootstrap",wl=50,El=1e3,Ls=class extends Ar{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??El,this.list=r.list.map(n=>Zc(n)).filter(n=>ta.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:Ic(n.getComponents().findLast(o=>o.code===421)?.value??""),multiaddrs:[n]})),this._init=r}[Us]=this;[Symbol.toStringTag]="@libp2p/bootstrap";[Ns]=["@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??xl]:{value:this._init.tagValue??wl,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 Sl(e){return t=>new Ls(t,e)}return sa(vl);})();
|
|
3
3
|
/*! Bundled license information:
|
|
4
4
|
|
|
5
5
|
@noble/curves/utils.js:
|