@libp2p/peer-collections 7.0.15 → 7.0.17-500287203

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 CHANGED
@@ -1,10 +1,7 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPeerCollections = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PPeerCollections=(()=>{var Dr=Object.defineProperty;var ui=Object.getOwnPropertyDescriptor;var hi=Object.getOwnPropertyNames;var li=Object.prototype.hasOwnProperty;var ct=(r,t)=>{for(var e in t)Dr(r,e,{get:t[e],enumerable:!0})},di=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of hi(t))!li.call(r,o)&&o!==e&&Dr(r,o,{get:()=>t[o],enumerable:!(n=ui(t,o))||n.enumerable});return r};var pi=r=>di(Dr({},"__esModule",{value:!0}),r);var Ha={};ct(Ha,{PeerFilter:()=>Fe,PeerList:()=>Vt,PeerMap:()=>qt,PeerSet:()=>Ht,peerFilter:()=>ii,peerList:()=>ri,peerMap:()=>ti,peerSet:()=>ei,trackedPeerList:()=>fi,trackedPeerMap:()=>ci,trackedPeerSet:()=>ai});var _t=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Ye=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var je=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var ge=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Cr=Symbol.for("@libp2p/peer-id");var kr={};ct(kr,{base58btc:()=>j,base58flickr:()=>Ei});var Za=new Uint8Array(0);function oo(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function St(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function so(r){return new TextEncoder().encode(r)}function io(r){return new TextDecoder().decode(r)}function mi(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var a=r.length,c=r.charAt(0),f=Math.log(a)/Math.log(256),l=Math.log(256)/Math.log(a);function u(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var v=0,S=0,b=0,A=m.length;b!==A&&m[b]===0;)b++,v++;for(var y=(A-b)*l+1>>>0,B=new Uint8Array(y);b!==A;){for(var R=m[b],O=0,M=y-1;(R!==0||O<S)&&M!==-1;M--,O++)R+=256*B[M]>>>0,B[M]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");S=O,b++}for(var x=y-S;x!==y&&B[x]===0;)x++;for(var g=c.repeat(v);x<y;++x)g+=r.charAt(B[x]);return g}function w(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var v=0;if(m[v]!==" "){for(var S=0,b=0;m[v]===c;)S++,v++;for(var A=(m.length-v)*f+1>>>0,y=new Uint8Array(A);m[v];){var B=e[m.charCodeAt(v)];if(B===255)return;for(var R=0,O=A-1;(B!==0||R<b)&&O!==-1;O--,R++)B+=a*y[O]>>>0,y[O]=B%256>>>0,B=B/256>>>0;if(B!==0)throw new Error("Non-zero carry");b=R,v++}if(m[v]!==" "){for(var M=A-b;M!==A&&y[M]===0;)M++;for(var x=new Uint8Array(S+(A-M)),g=S;M!==A;)x[g++]=y[M++];return x}}}function _(m){var v=w(m);if(v)return v;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:w,decode:_}}var bi=mi,yi=bi,ao=yi;var Tr=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Ur=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.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 fo(this,t)}},Rr=class{decoders;constructor(t){this.decoders=t}or(t){return fo(this,t)}decode(t){let e=t[0],n=this.decoders[e];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 fo(r,t){return new Rr({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Kr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Tr(t,e,n),this.decoder=new Ur(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ee({name:r,prefix:t,encode:e,decode:n}){return new Kr(r,t,e,n)}function Tt({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=ao(e,r);return ee({prefix:t,name:r,encode:n,decode:s=>St(o(s))})}function gi(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,a=0,c=0;for(let f=0;f<o;++f){let l=t[r[f]];if(l===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<e|l,i+=e,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=e||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function xi(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],i+=8;i>e;)i-=e,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function wi(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function Y({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=wi(n);return ee({prefix:t,name:r,encode(s){return xi(s,n,e)},decode(s){return gi(s,o,e,r)}})}var j=Tt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ei=Tt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Nr={};ct(Nr,{base32:()=>re,base32hex:()=>vi,base32hexpad:()=>Ii,base32hexpadupper:()=>Li,base32hexupper:()=>Bi,base32pad:()=>Si,base32padupper:()=>Ai,base32upper:()=>_i,base32z:()=>Di});var re=Y({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),_i=Y({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Si=Y({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Ai=Y({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),vi=Y({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Bi=Y({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ii=Y({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Li=Y({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),Di=Y({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Or={};ct(Or,{base36:()=>xe,base36upper:()=>Ci});var xe=Tt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ci=Tt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Ti=lo,uo=128,Ui=127,Ri=~Ui,Ki=Math.pow(2,31);function lo(r,t,e){t=t||[],e=e||0;for(var n=e;r>=Ki;)t[e++]=r&255|uo,r/=128;for(;r&Ri;)t[e++]=r&255|uo,r>>>=7;return t[e]=r|0,lo.bytes=e-n+1,t}var ki=Mr,Ni=128,ho=127;function Mr(r,n){var e=0,n=n||0,o=0,s=n,i,a=r.length;do{if(s>=a)throw Mr.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&ho)<<o:(i&ho)*Math.pow(2,o),o+=7}while(i>=Ni);return Mr.bytes=s-n,e}var Oi=Math.pow(2,7),Mi=Math.pow(2,14),Pi=Math.pow(2,21),qi=Math.pow(2,28),Hi=Math.pow(2,35),Vi=Math.pow(2,42),zi=Math.pow(2,49),Fi=Math.pow(2,56),Zi=Math.pow(2,63),Yi=function(r){return r<Oi?1:r<Mi?2:r<Pi?3:r<qi?4:r<Hi?5:r<Vi?6:r<zi?7:r<Fi?8:r<Zi?9:10},ji={encode:Ti,decode:ki,encodingLength:Yi},Gi=ji,we=Gi;function Ee(r,t=0){return[we.decode(r,t),we.decode.bytes]}function ne(r,t,e=0){return we.encode(r,t,e),t}function oe(r){return we.encodingLength(r)}function ie(r,t){let e=t.byteLength,n=oe(r),o=n+oe(e),s=new Uint8Array(o+e);return ne(r,s,0),ne(e,s,n),s.set(t,o),new se(r,e,t,s)}function _e(r){let t=St(r),[e,n]=Ee(t),[o,s]=Ee(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new se(e,o,i,t)}function po(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&oo(r.bytes,e.bytes)}}var se=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function mo(r,t){let{bytes:e,version:n}=r;switch(n){case 0:return Xi(e,Pr(r),t??j.encoder);default:return Wi(e,Pr(r),t??re.encoder)}}var bo=new WeakMap;function Pr(r){let t=bo.get(r);if(t==null){let e=new Map;return bo.set(r,e),e}return t}var st=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,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:e}=this;if(t!==Se)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ji)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:e}=this.multihash,n=ie(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&po(t.multihash,n.multihash)}toString(t){return mo(this,t)}toJSON(){return{"/":mo(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 e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??yo(n,o,s.bytes))}else if(e[Qi]===!0){let{version:n,multihash:o,code:s}=e,i=_e(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="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(e!==Se)throw new Error(`Version 0 CID must use dag-pb (code: ${Se}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=yo(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Se,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=St(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new se(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[u,w]=Ee(t.subarray(e));return e+=w,u},o=n(),s=Se;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,a=n(),c=n(),f=e+c,l=f-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:l,size:f}}static parse(t,e){let[n,o]=$i(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Pr(s).set(n,t),s}};function $i(r,t){switch(r[0]){case"Q":{let e=t??j;return[j.prefix,e.decode(`${j.prefix}${r}`)]}case j.prefix:{let e=t??j;return[j.prefix,e.decode(r)]}case re.prefix:{let e=t??re;return[re.prefix,e.decode(r)]}case xe.prefix:{let e=t??xe;return[xe.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Xi(r,t,e){let{prefix:n}=e;if(n!==j.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function Wi(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Se=112,Ji=18;function yo(r,t,e){let n=oe(r),o=n+oe(t),s=new Uint8Array(o+e.byteLength);return ne(r,s,0),ne(t,s,n),s.set(e,o),s}var Qi=Symbol.for("@ipld/js-cid/CID");var qr={};ct(qr,{identity:()=>dt});var go=0,tc="identity",xo=St;function ec(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return ie(go,xo(r))}var dt={code:go,name:tc,encode:xo,digest:ec};function at(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function pt(r=0){return new Uint8Array(r)}function ft(r=0){return new Uint8Array(r)}function $e(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ft(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Eo=Symbol.for("@achingbrain/uint8arraylist");function wo(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function Xe(r){return!!r?.[Eo]}var ut=class r{bufs;length;[Eo]=!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 e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(Xe(n))e+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(Xe(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=wo(this.bufs,t);return e.buf[e.index]}set(t,e){let n=wo(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(Xe(t))for(let n=0;n<t.length;n++)this.set(e+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,e){let{bufs:n,length:o}=this._subList(t,e);return $e(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:$e(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=[...n],s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let f=t>=a&&t<c,l=e>a&&e<=c;if(f&&l){if(t===a&&e===c){n.push(i);break}let u=t-a;n.push(i.subarray(u,u+(e-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(l){if(e===c){n.push(i);break}n.push(i.subarray(0,e-a));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!Xe(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(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;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 u=0;u<s;u++)i[u]=-1;for(let u=0;u<o;u++)i[n[u]]=u;let a=i,c=this.byteLength-n.byteLength,f=n.byteLength-1,l;for(let u=e;u<=c;u+=l){l=0;for(let w=f;w>=0;w--){let _=this.get(u+w);if(n[w]!==_){l=Math.max(1,w-a[_]);break}}if(l===0)return u}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=ft(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=pt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=ft(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=pt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=pt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=pt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!at(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var Hr={};ct(Hr,{base10:()=>rc});var rc=Tt({prefix:"9",name:"base10",alphabet:"0123456789"});var Vr={};ct(Vr,{base16:()=>nc,base16upper:()=>oc});var nc=Y({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),oc=Y({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var zr={};ct(zr,{base2:()=>sc});var sc=Y({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Fr={};ct(Fr,{base256emoji:()=>uc});var _o=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}"),ic=_o.reduce((r,t,e)=>(r[e]=t,r),[]),cc=_o.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function ac(r){return r.reduce((t,e)=>(t+=ic[e],t),"")}function fc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=cc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var uc=ee({prefix:"\u{1F680}",name:"base256emoji",encode:ac,decode:fc});var Zr={};ct(Zr,{base64:()=>hc,base64pad:()=>lc,base64url:()=>dc,base64urlpad:()=>pc});var hc=Y({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),lc=Y({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),dc=Y({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),pc=Y({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Yr={};ct(Yr,{base8:()=>mc});var mc=Y({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var jr={};ct(jr,{identity:()=>bc});var bc=ee({prefix:"\0",name:"identity",encode:r=>io(r),decode:r=>so(r)});var Df=new TextEncoder,Cf=new TextDecoder;var Xr={};ct(Xr,{sha256:()=>Ae,sha512:()=>wc});var xc=20;function $r({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new Gr(r,t,e,n,o)}var Gr=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??xc,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.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?So(n,this.code,e?.truncate):n.then(o=>So(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function So(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return ie(t,r)}function vo(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Ae=$r({name:"sha2-256",code:18,encode:vo("SHA-256")}),wc=$r({name:"sha2-512",code:19,encode:vo("SHA-512")});var Wr={...jr,...zr,...Yr,...Hr,...Vr,...Nr,...Or,...kr,...Zr,...Fr},Vf={...Xr,...qr};function Io(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Bo=Io("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Jr=Io("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=ft(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),Ec={utf8:Bo,"utf-8":Bo,hex:Wr.base16,latin1:Jr,ascii:Jr,binary:Jr,...Wr},We=Ec;function $(r,t="utf8"){let e=We[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function lt(r,t="utf8"){let e=We[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var _c=parseInt("11111",2),Qr=parseInt("10000000",2),Sc=parseInt("01111111",2),Lo={0:ve,1:ve,2:Ac,3:Ic,4:Lc,5:Bc,6:vc,16:ve,22:ve,48:ve};function tn(r,t={offset:0}){let e=r[t.offset]&_c;if(t.offset++,Lo[e]!=null)return Lo[e](r,t);throw new Error("No decoder for tag "+e)}function Be(r,t){let e=0;if((r[t.offset]&Qr)===Qr){let n=r[t.offset]&Sc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function ve(r,t){Be(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=tn(r,t);if(n===null)break;e.push(n)}return e}function Ac(r,t){let e=Be(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function vc(r,t){let e=Be(r,t),n=t.offset+e,o=r[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let f=r[t.offset];if(t.offset++,c.push(f&127),f<128){c.reverse();let l=0;for(let u=0;u<c.length;u++)l+=c[u]<<u*7;a+=`.${l}`,c=[]}}return a}function Bc(r,t){return t.offset++,null}function Ic(r,t){let e=Be(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function Lc(r,t){let e=Be(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function Dc(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new ut;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function en(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=Dc(r.byteLength);return new ut(Uint8Array.from([t.byteLength|Qr]),t)}function Do(r){let t=new ut,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new ut(Uint8Array.from([2]),en(t),t)}function Co(r){let t=Uint8Array.from([0]),e=new ut(t,r);return new ut(Uint8Array.from([3]),en(e),e)}function Je(r,t=48){let e=new ut;for(let n of r)e.append(n);return new ut(Uint8Array.from([t]),en(e),e)}async function To(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}var Cc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),Tc=Uint8Array.from([6,5,43,129,4,0,34]),Uc=Uint8Array.from([6,5,43,129,4,0,35]),Rc={ext:!0,kty:"EC",crv:"P-256"},Kc={ext:!0,kty:"EC",crv:"P-384"},kc={ext:!0,kty:"EC",crv:"P-521"},rn=32,nn=48,on=66;function Uo(r){let t=tn(r);return Ro(t)}function Ro(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===rn*2+1)return n=lt(t.subarray(e,e+rn),"base64url"),o=lt(t.subarray(e+rn),"base64url"),new ce({...Rc,key_ops:["verify"],x:n,y:o});if(t.byteLength===nn*2+1)return n=lt(t.subarray(e,e+nn),"base64url"),o=lt(t.subarray(e+nn),"base64url"),new ce({...Kc,key_ops:["verify"],x:n,y:o});if(t.byteLength===on*2+1)return n=lt(t.subarray(e,e+on),"base64url"),o=lt(t.subarray(e+on),"base64url"),new ce({...kc,key_ops:["verify"],x:n,y:o});throw new _t(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ko(r){return Je([Do(Uint8Array.from([1])),Je([Nc(r.crv)],160),Je([Co(new ut(Uint8Array.from([4]),$(r.x??"","base64url"),$(r.y??"","base64url")))],161)]).subarray()}function Nc(r){if(r==="P-256")return Cc;if(r==="P-384")return Tc;if(r==="P-521")return Uc;throw new _t(`Invalid curve ${r}`)}var ce=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ko(this.jwk)),this._raw}toMultihash(){return dt.digest(ae(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}async verify(t,e,n){return To(this.jwk,e,t,n)}};function Ft(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"}function xt(r,t=""){if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new Error(`${e}expected integer >= 0, got ${r}`)}}function N(r,t,e=""){let n=Ft(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,a=s?` of length ${t}`:"",c=n?`length=${o}`:`type=${typeof r}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return r}function Qe(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash must wrapped by utils.createHasher");xt(r.outputLen),xt(r.blockLen)}function fe(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function No(r,t){N(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new Error('"digestInto() output" expected to be of length >='+e)}function vt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function tr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function mt(r,t){return r<<32-t|r>>>t}var Oo=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Oc=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function Bt(r){if(N(r),Oo)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=Oc[r[e]];return t}var At={_0:48,_9:57,A:65,F:70,a:97,f:102};function ko(r){if(r>=At._0&&r<=At._9)return r-At._0;if(r>=At.A&&r<=At.F)return r-(At.A-10);if(r>=At.a&&r<=At.f)return r-(At.a-10)}function It(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);if(Oo)return Uint8Array.fromHex(r);let t=r.length,e=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=ko(r.charCodeAt(s)),a=ko(r.charCodeAt(s+1));if(i===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function it(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];N(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function sn(r,t={}){let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function ue(r=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(r))}var cn=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function Mo(r,t,e){return r&t^~r&e}function Po(r,t,e){return r&t^r&e^t&e}var Ie=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=tr(this.buffer)}update(t){fe(this),N(t);let{view:e,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=tr(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){fe(this),No(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,vt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let u=i;u<o;u++)e[u]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let a=tr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let f=c/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<f;u++)a.setUint32(4*u,l[u],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:e,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Lt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var Q=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var er=BigInt(4294967295),qo=BigInt(32);function Mc(r,t=!1){return t?{h:Number(r&er),l:Number(r>>qo&er)}:{h:Number(r>>qo&er)|0,l:Number(r&er)|0}}function Ho(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:a}=Mc(r[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var an=(r,t,e)=>r>>>e,fn=(r,t,e)=>r<<32-e|t>>>e,Zt=(r,t,e)=>r>>>e|t<<32-e,Yt=(r,t,e)=>r<<32-e|t>>>e,Le=(r,t,e)=>r<<64-e|t>>>e-32,De=(r,t,e)=>r>>>e-32|t<<64-e;function wt(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var Vo=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),zo=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,Fo=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),Zo=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,Yo=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),jo=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var qc=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]),Ut=new Uint32Array(64),un=class extends Ie{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,e,n,o,s,i,a,c]}set(t,e,n,o,s,i,a,c){this.A=t|0,this.B=e|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,e){for(let u=0;u<16;u++,e+=4)Ut[u]=t.getUint32(e,!1);for(let u=16;u<64;u++){let w=Ut[u-15],_=Ut[u-2],m=mt(w,7)^mt(w,18)^w>>>3,v=mt(_,17)^mt(_,19)^_>>>10;Ut[u]=v+Ut[u-7]+m+Ut[u-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:f,H:l}=this;for(let u=0;u<64;u++){let w=mt(a,6)^mt(a,11)^mt(a,25),_=l+w+Mo(a,c,f)+qc[u]+Ut[u]|0,v=(mt(n,2)^mt(n,13)^mt(n,22))+Po(n,o,s)|0;l=f,f=c,c=a,a=i+_|0,i=s,s=o,o=n,n=_+v|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,f=f+this.G|0,l=l+this.H|0,this.set(n,o,s,i,a,c,f,l)}roundClean(){vt(Ut)}destroy(){this.set(0,0,0,0,0,0,0,0),vt(this.buffer)}},hn=class extends un{A=Lt[0]|0;B=Lt[1]|0;C=Lt[2]|0;D=Lt[3]|0;E=Lt[4]|0;F=Lt[5]|0;G=Lt[6]|0;H=Lt[7]|0;constructor(){super(32)}};var Go=Ho(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Hc=Go[0],Vc=Go[1],Rt=new Uint32Array(80),Kt=new Uint32Array(80),ln=class extends Ie{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:f,El:l,Fh:u,Fl:w,Gh:_,Gl:m,Hh:v,Hl:S}=this;return[t,e,n,o,s,i,a,c,f,l,u,w,_,m,v,S]}set(t,e,n,o,s,i,a,c,f,l,u,w,_,m,v,S){this.Ah=t|0,this.Al=e|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=f|0,this.El=l|0,this.Fh=u|0,this.Fl=w|0,this.Gh=_|0,this.Gl=m|0,this.Hh=v|0,this.Hl=S|0}process(t,e){for(let y=0;y<16;y++,e+=4)Rt[y]=t.getUint32(e),Kt[y]=t.getUint32(e+=4);for(let y=16;y<80;y++){let B=Rt[y-15]|0,R=Kt[y-15]|0,O=Zt(B,R,1)^Zt(B,R,8)^an(B,R,7),M=Yt(B,R,1)^Yt(B,R,8)^fn(B,R,7),x=Rt[y-2]|0,g=Kt[y-2]|0,K=Zt(x,g,19)^Le(x,g,61)^an(x,g,6),P=Yt(x,g,19)^De(x,g,61)^fn(x,g,6),C=Fo(M,P,Kt[y-7],Kt[y-16]),d=Zo(C,O,K,Rt[y-7],Rt[y-16]);Rt[y]=d|0,Kt[y]=C|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:f,Dl:l,Eh:u,El:w,Fh:_,Fl:m,Gh:v,Gl:S,Hh:b,Hl:A}=this;for(let y=0;y<80;y++){let B=Zt(u,w,14)^Zt(u,w,18)^Le(u,w,41),R=Yt(u,w,14)^Yt(u,w,18)^De(u,w,41),O=u&_^~u&v,M=w&m^~w&S,x=Yo(A,R,M,Vc[y],Kt[y]),g=jo(x,b,B,O,Hc[y],Rt[y]),K=x|0,P=Zt(n,o,28)^Le(n,o,34)^Le(n,o,39),C=Yt(n,o,28)^De(n,o,34)^De(n,o,39),d=n&s^n&a^s&a,p=o&i^o&c^i&c;b=v|0,A=S|0,v=_|0,S=m|0,_=u|0,m=w|0,{h:u,l:w}=wt(f|0,l|0,g|0,K|0),f=a|0,l=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let h=Vo(K,C,p);n=zo(h,g,P,d),o=h|0}({h:n,l:o}=wt(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=wt(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=wt(this.Ch|0,this.Cl|0,a|0,c|0),{h:f,l}=wt(this.Dh|0,this.Dl|0,f|0,l|0),{h:u,l:w}=wt(this.Eh|0,this.El|0,u|0,w|0),{h:_,l:m}=wt(this.Fh|0,this.Fl|0,_|0,m|0),{h:v,l:S}=wt(this.Gh|0,this.Gl|0,v|0,S|0),{h:b,l:A}=wt(this.Hh|0,this.Hl|0,b|0,A|0),this.set(n,o,s,i,a,c,f,l,u,w,_,m,v,S,b,A)}roundClean(){vt(Rt,Kt)}destroy(){vt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},dn=class extends ln{Ah=Q[0]|0;Al=Q[1]|0;Bh=Q[2]|0;Bl=Q[3]|0;Ch=Q[4]|0;Cl=Q[5]|0;Dh=Q[6]|0;Dl=Q[7]|0;Eh=Q[8]|0;El=Q[9]|0;Fh=Q[10]|0;Fl=Q[11]|0;Gh=Q[12]|0;Gl=Q[13]|0;Hh=Q[14]|0;Hl=Q[15]|0;constructor(){super(64)}};var $o=sn(()=>new hn,cn(1));var Xo=sn(()=>new dn,cn(3));var mn=BigInt(0),pn=BigInt(1);function Dt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new Error(e+"expected boolean, got type="+typeof r)}return r}function Wo(r){if(typeof r=="bigint"){if(!rr(r))throw new Error("positive bigint expected, got "+r)}else xt(r);return r}function Ce(r){let t=Wo(r).toString(16);return t.length&1?"0"+t:t}function Jo(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return r===""?mn:BigInt("0x"+r)}function he(r){return Jo(Bt(r))}function jt(r){return Jo(Bt(or(N(r)).reverse()))}function nr(r,t){xt(t),r=Wo(r);let e=It(r.toString(16).padStart(t*2,"0"));if(e.length!==t)throw new Error("number too large");return e}function bn(r,t){return nr(r,t).reverse()}function or(r){return Uint8Array.from(r)}var rr=r=>typeof r=="bigint"&&mn<=r;function zc(r,t,e){return rr(r)&&rr(t)&&rr(e)&&t<=r&&r<e}function Te(r,t,e,n){if(!zc(t,e,n))throw new Error("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function yn(r){let t;for(t=0;r>mn;r>>=pn,t+=1);return t}var Ue=r=>(pn<<BigInt(r))-pn;function Qo(r,t,e){if(xt(r,"hashLen"),xt(t,"qByteLen"),typeof e!="function")throw new Error("hmacFn must be a function");let n=S=>new Uint8Array(S),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(r),f=n(r),l=0,u=()=>{c.fill(1),f.fill(0),l=0},w=(...S)=>e(f,it(c,...S)),_=(S=o)=>{f=w(s,S),c=w(),S.length!==0&&(f=w(i,S),c=w())},m=()=>{if(l++>=a)throw new Error("drbg: tried max amount of iterations");let S=0,b=[];for(;S<t;){c=w();let A=c.slice();b.push(A),S+=c.length}return it(...b)};return(S,b)=>{u(),_(S);let A;for(;!(A=b(m()));)_();return u(),A}}function kt(r,t={},e={}){if(!r||typeof r!="object")throw new Error("expected valid options object");function n(s,i,a){let c=r[s];if(a&&c===void 0)return;let f=typeof c;if(f!==i||c===null)throw new Error(`param "${s}" is invalid: expected ${i}, got ${f}`)}let o=(s,i)=>Object.entries(s).forEach(([a,c])=>n(a,c,i));o(t,!1),o(e,!0)}function le(r){let t=new WeakMap;return(e,...n)=>{let o=t.get(e);if(o!==void 0)return o;let s=r(e,...n);return t.set(e,s),s}}var rt=BigInt(0),X=BigInt(1),Gt=BigInt(2),rs=BigInt(3),ns=BigInt(4),os=BigInt(5),Fc=BigInt(7),ss=BigInt(8),Zc=BigInt(9),is=BigInt(16);function G(r,t){let e=r%t;return e>=rt?e:t+e}function V(r,t,e){let n=r;for(;t-- >rt;)n*=n,n%=e;return n}function ts(r,t){if(r===rt)throw new Error("invert: expected non-zero number");if(t<=rt)throw new Error("invert: expected positive modulus, got "+t);let e=G(r,t),n=t,o=rt,s=X,i=X,a=rt;for(;e!==rt;){let f=n/e,l=n%e,u=o-i*f,w=s-a*f;n=e,e=l,o=i,s=a,i=u,a=w}if(n!==X)throw new Error("invert: does not exist");return G(o,t)}function xn(r,t,e){if(!r.eql(r.sqr(t),e))throw new Error("Cannot find square root")}function cs(r,t){let e=(r.ORDER+X)/ns,n=r.pow(t,e);return xn(r,n,t),n}function Yc(r,t){let e=(r.ORDER-os)/ss,n=r.mul(t,Gt),o=r.pow(n,e),s=r.mul(t,o),i=r.mul(r.mul(s,Gt),o),a=r.mul(s,r.sub(i,r.ONE));return xn(r,a,t),a}function jc(r){let t=de(r),e=as(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+Fc)/is;return(a,c)=>{let f=a.pow(c,i),l=a.mul(f,n),u=a.mul(f,o),w=a.mul(f,s),_=a.eql(a.sqr(l),c),m=a.eql(a.sqr(u),c);f=a.cmov(f,l,_),l=a.cmov(w,u,m);let v=a.eql(a.sqr(l),c),S=a.cmov(f,l,v);return xn(a,S,c),S}}function as(r){if(r<rs)throw new Error("sqrt is not defined for small field");let t=r-X,e=0;for(;t%Gt===rt;)t/=Gt,e++;let n=Gt,o=de(r);for(;es(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return cs;let s=o.pow(n,t),i=(t+X)/Gt;return function(c,f){if(c.is0(f))return f;if(es(c,f)!==1)throw new Error("Cannot find square root");let l=e,u=c.mul(c.ONE,s),w=c.pow(f,t),_=c.pow(f,i);for(;!c.eql(w,c.ONE);){if(c.is0(w))return c.ZERO;let m=1,v=c.sqr(w);for(;!c.eql(v,c.ONE);)if(m++,v=c.sqr(v),m===l)throw new Error("Cannot find square root");let S=X<<BigInt(l-m-1),b=c.pow(u,S);l=m,u=c.sqr(b),w=c.mul(w,u),_=c.mul(_,b)}return _}}function Gc(r){return r%ns===rs?cs:r%ss===os?Yc:r%is===Zc?jc(r):as(r)}var fs=(r,t)=>(G(r,t)&X)===X,$c=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function wn(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=$c.reduce((n,o)=>(n[o]="function",n),t);return kt(r,e),r}function Xc(r,t,e){if(e<rt)throw new Error("invalid exponent, negatives unsupported");if(e===rt)return r.ONE;if(e===X)return t;let n=r.ONE,o=t;for(;e>rt;)e&X&&(n=r.mul(n,o)),o=r.sqr(o),e>>=X;return n}function Re(r,t,e=!1){let n=new Array(t.length).fill(e?r.ZERO:void 0),o=t.reduce((i,a,c)=>r.is0(a)?i:(n[c]=i,r.mul(i,a)),r.ONE),s=r.inv(o);return t.reduceRight((i,a,c)=>r.is0(a)?i:(n[c]=r.mul(i,n[c]),r.mul(i,a)),s),n}function es(r,t){let e=(r.ORDER-X)/Gt,n=r.pow(t,e),o=r.eql(n,r.ONE),s=r.eql(n,r.ZERO),i=r.eql(n,r.neg(r.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Wc(r,t){t!==void 0&&xt(t);let e=t!==void 0?t:r.toString(2).length,n=Math.ceil(e/8);return{nBitLength:e,nByteLength:n}}var gn=class{ORDER;BITS;BYTES;isLE;ZERO=rt;ONE=X;_lengths;_sqrt;_mod;constructor(t,e={}){if(t<=rt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&(this.sqrt=e.sqrt),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=e.allowedLengths?.slice()),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=Wc(t,n);if(s>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=o,this.BYTES=s,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return G(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return rt<=t&&t<this.ORDER}is0(t){return t===rt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&X)===X}neg(t){return G(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return G(t*t,this.ORDER)}add(t,e){return G(t+e,this.ORDER)}sub(t,e){return G(t-e,this.ORDER)}mul(t,e){return G(t*e,this.ORDER)}pow(t,e){return Xc(this,t,e)}div(t,e){return G(t*ts(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return ts(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=Gc(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?bn(t,this.BYTES):nr(t,this.BYTES)}fromBytes(t,e=!1){N(t);let{_lengths:n,BYTES:o,isLE:s,ORDER:i,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>o)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let f=new Uint8Array(o);f.set(t,s?0:f.length-t.length),t=f}if(t.length!==o)throw new Error("Field.fromBytes: expected "+o+" bytes, got "+t.length);let c=s?jt(t):he(t);if(a&&(c=G(c,i)),!e&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return Re(this,t)}cmov(t,e,n){return n?e:t}};function de(r,t={}){return new gn(r,t)}function us(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let t=r.toString(2).length;return Math.ceil(t/8)}function En(r){let t=us(r);return t+Math.ceil(t/2)}function _n(r,t,e=!1){N(r);let n=r.length,o=us(t),s=En(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?jt(r):he(r),a=G(i,t-X)+X;return e?bn(a,o):nr(a,o)}var pe=BigInt(0),$t=BigInt(1);function Ke(r,t){let e=t.negate();return r?e:t}function Xt(r,t){let e=Re(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function ps(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function Sn(r,t){ps(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=Ue(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function hs(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,a=Number(r&o),c=r>>i;a>n&&(a-=s,c+=$t);let f=t*n,l=f+Math.abs(a)-1,u=a===0,w=a<0,_=t%2!==0;return{nextN:c,offset:l,isZero:u,isNeg:w,isNegF:_,offsetF:f}}var An=new WeakMap,ms=new WeakMap;function vn(r){return ms.get(r)||1}function ls(r){if(r!==pe)throw new Error("invalid wNAF")}var me=class{BASE;ZERO;Fn;bits;constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>pe;)e&$t&&(n=n.add(o)),o=o.double(),e>>=$t;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=Sn(e,this.bits),s=[],i=t,a=i;for(let c=0;c<n;c++){a=i,s.push(a);for(let f=1;f<o;f++)a=a.add(i),s.push(a);i=a.double()}return s}wNAF(t,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=Sn(t,this.bits);for(let a=0;a<i.windows;a++){let{nextN:c,offset:f,isZero:l,isNeg:u,isNegF:w,offsetF:_}=hs(n,a,i);n=c,l?s=s.add(Ke(w,e[_])):o=o.add(Ke(u,e[f]))}return ls(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=Sn(t,this.bits);for(let i=0;i<s.windows&&n!==pe;i++){let{nextN:a,offset:c,isZero:f,isNeg:l}=hs(n,i,s);if(n=a,!f){let u=e[c];o=o.add(l?u.negate():u)}}return ls(n),o}getPrecomputes(t,e,n){let o=An.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),An.set(e,o))),o}cached(t,e,n){let o=vn(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=vn(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){ps(e,this.bits),ms.set(t,e),An.delete(t)}hasCache(t){return vn(t)!==1}};function bs(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>pe||n>pe;)e&$t&&(s=s.add(o)),n&$t&&(i=i.add(o)),o=o.double(),e>>=$t,n>>=$t;return{p1:s,p2:i}}function ds(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return wn(t),t}else return de(r,{isLE:e})}function sr(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let c of["p","n","h"]){let f=t[c];if(!(typeof f=="bigint"&&f>pe))throw new Error(`CURVE.${c} must be positive bigint`)}let o=ds(t.p,e.Fp,n),s=ds(t.n,e.Fn,n),a=["Gx","Gy","a",r==="weierstrass"?"b":"d"];for(let c of a)if(!o.isValid(t[c]))throw new Error(`CURVE.${c} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:o,Fn:s}}function ir(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var Nt=BigInt(0),W=BigInt(1),Bn=BigInt(2),Jc=BigInt(8);function Qc(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),a=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,a)}function ys(r,t={}){let e=sr("edwards",r,t,t.FpFnLE),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i}=s;kt(t,{},{uvRatio:"function"});let a=Bn<<BigInt(o.BYTES*8)-W,c=S=>n.create(S),f=t.uvRatio||((S,b)=>{try{return{isValid:!0,value:n.sqrt(n.div(S,b))}}catch{return{isValid:!1,value:Nt}}});if(!Qc(n,s,s.Gx,s.Gy))throw new Error("bad curve params: generator point");function l(S,b,A=!1){let y=A?W:Nt;return Te("coordinate "+S,b,y,a),b}function u(S){if(!(S instanceof m))throw new Error("EdwardsPoint expected")}let w=le((S,b)=>{let{X:A,Y:y,Z:B}=S,R=S.is0();b==null&&(b=R?Jc:n.inv(B));let O=c(A*b),M=c(y*b),x=n.mul(B,b);if(R)return{x:Nt,y:W};if(x!==W)throw new Error("invZ was invalid");return{x:O,y:M}}),_=le(S=>{let{a:b,d:A}=s;if(S.is0())throw new Error("bad point: ZERO");let{X:y,Y:B,Z:R,T:O}=S,M=c(y*y),x=c(B*B),g=c(R*R),K=c(g*g),P=c(M*b),C=c(g*c(P+x)),d=c(K+c(A*c(M*x)));if(C!==d)throw new Error("bad point: equation left != right (1)");let p=c(y*B),h=c(R*O);if(p!==h)throw new Error("bad point: equation left != right (2)");return!0});class m{static BASE=new m(s.Gx,s.Gy,W,c(s.Gx*s.Gy));static ZERO=new m(Nt,W,W,Nt);static Fp=n;static Fn=o;X;Y;Z;T;constructor(b,A,y,B){this.X=l("x",b),this.Y=l("y",A),this.Z=l("z",y,!0),this.T=l("t",B),Object.freeze(this)}static CURVE(){return s}static fromAffine(b){if(b instanceof m)throw new Error("extended point not allowed");let{x:A,y}=b||{};return l("x",A),l("y",y),new m(A,y,W,c(A*y))}static fromBytes(b,A=!1){let y=n.BYTES,{a:B,d:R}=s;b=or(N(b,y,"point")),Dt(A,"zip215");let O=or(b),M=b[y-1];O[y-1]=M&-129;let x=jt(O),g=A?a:n.ORDER;Te("point.y",x,Nt,g);let K=c(x*x),P=c(K-W),C=c(R*K-B),{isValid:d,value:p}=f(P,C);if(!d)throw new Error("bad point: invalid y coordinate");let h=(p&W)===W,E=(M&128)!==0;if(!A&&p===Nt&&E)throw new Error("bad point: x=0 and x_0=1");return E!==h&&(p=c(-p)),m.fromAffine({x:p,y:x})}static fromHex(b,A=!1){return m.fromBytes(It(b),A)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(b=8,A=!0){return v.createCache(this,b),A||this.multiply(Bn),this}assertValidity(){_(this)}equals(b){u(b);let{X:A,Y:y,Z:B}=this,{X:R,Y:O,Z:M}=b,x=c(A*M),g=c(R*B),K=c(y*M),P=c(O*B);return x===g&&K===P}is0(){return this.equals(m.ZERO)}negate(){return new m(c(-this.X),this.Y,this.Z,c(-this.T))}double(){let{a:b}=s,{X:A,Y:y,Z:B}=this,R=c(A*A),O=c(y*y),M=c(Bn*c(B*B)),x=c(b*R),g=A+y,K=c(c(g*g)-R-O),P=x+O,C=P-M,d=x-O,p=c(K*C),h=c(P*d),E=c(K*d),I=c(C*P);return new m(p,h,I,E)}add(b){u(b);let{a:A,d:y}=s,{X:B,Y:R,Z:O,T:M}=this,{X:x,Y:g,Z:K,T:P}=b,C=c(B*x),d=c(R*g),p=c(M*y*P),h=c(O*K),E=c((B+R)*(x+g)-C-d),I=h-p,D=h+p,T=c(d-A*C),L=c(E*I),U=c(D*T),k=c(E*T),z=c(I*D);return new m(L,U,z,k)}subtract(b){return this.add(b.negate())}multiply(b){if(!o.isValidNot0(b))throw new Error("invalid scalar: expected 1 <= sc < curve.n");let{p:A,f:y}=v.cached(this,b,B=>Xt(m,B));return Xt(m,[A,y])[0]}multiplyUnsafe(b,A=m.ZERO){if(!o.isValid(b))throw new Error("invalid scalar: expected 0 <= sc < curve.n");return b===Nt?m.ZERO:this.is0()||b===W?this:v.unsafe(this,b,y=>Xt(m,y),A)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}isTorsionFree(){return v.unsafe(this,s.n).is0()}toAffine(b){return w(this,b)}clearCofactor(){return i===W?this:this.multiplyUnsafe(i)}toBytes(){let{x:b,y:A}=this.toAffine(),y=n.toBytes(A);return y[y.length-1]|=b&W?128:0,y}toHex(){return Bt(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let v=new me(m,o.BITS);return m.BASE.precompute(8),m}function gs(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');kt(e,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",mapToCurve:"function"});let{prehash:n}=e,{BASE:o,Fp:s,Fn:i}=r,a=e.randomBytes||ue,c=e.adjustScalarBytes||(x=>x),f=e.domain||((x,g,K)=>{if(Dt(K,"phflag"),g.length||K)throw new Error("Contexts/pre-hash are not supported");return x});function l(x){return i.create(jt(x))}function u(x){let g=y.secretKey;N(x,y.secretKey,"secretKey");let K=N(t(x),2*g,"hashedSecretKey"),P=c(K.slice(0,g)),C=K.slice(g,2*g),d=l(P);return{head:P,prefix:C,scalar:d}}function w(x){let{head:g,prefix:K,scalar:P}=u(x),C=o.multiply(P),d=C.toBytes();return{head:g,prefix:K,scalar:P,point:C,pointBytes:d}}function _(x){return w(x).pointBytes}function m(x=Uint8Array.of(),...g){let K=it(...g);return l(t(f(K,N(x,void 0,"context"),!!n)))}function v(x,g,K={}){x=N(x,void 0,"message"),n&&(x=n(x));let{prefix:P,scalar:C,pointBytes:d}=w(g),p=m(K.context,P,x),h=o.multiply(p).toBytes(),E=m(K.context,h,d,x),I=i.create(p+E*C);if(!i.isValid(I))throw new Error("sign failed: invalid s");let D=it(h,i.toBytes(I));return N(D,y.signature,"result")}let S={zip215:!0};function b(x,g,K,P=S){let{context:C,zip215:d}=P,p=y.signature;x=N(x,p,"signature"),g=N(g,void 0,"message"),K=N(K,y.publicKey,"publicKey"),d!==void 0&&Dt(d,"zip215"),n&&(g=n(g));let h=p/2,E=x.subarray(0,h),I=jt(x.subarray(h,p)),D,T,L;try{D=r.fromBytes(K,d),T=r.fromBytes(E,d),L=o.multiplyUnsafe(I)}catch{return!1}if(!d&&D.isSmallOrder())return!1;let U=m(C,T.toBytes(),D.toBytes(),g);return T.add(D.multiplyUnsafe(U)).subtract(L).clearCofactor().is0()}let A=s.BYTES,y={secretKey:A,publicKey:A,signature:2*A,seed:A};function B(x=a(y.seed)){return N(x,y.seed,"seed")}function R(x){return Ft(x)&&x.length===i.BYTES}function O(x,g){try{return!!r.fromBytes(x,g)}catch{return!1}}let M={getExtendedPublicKey:w,randomSecretKey:B,isValidSecretKey:R,isValidPublicKey:O,toMontgomery(x){let{y:g}=r.fromBytes(x),K=y.publicKey,P=K===32;if(!P&&K!==57)throw new Error("only defined for 25519 and 448");let C=P?s.div(W+g,W-g):s.div(g-W,g+W);return s.toBytes(C)},toMontgomerySecret(x){let g=y.secretKey;N(x,g);let K=t(x.subarray(0,g));return c(K).subarray(0,g)}};return Object.freeze({keygen:ir(B,_),getPublicKey:_,sign:v,verify:b,utils:M,Point:r,lengths:y})}var ta=BigInt(1),xs=BigInt(2);var ea=BigInt(5),ra=BigInt(8),In=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),na={p:In,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:ra,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function oa(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=In,a=r*r%s*r%s,c=V(a,xs,s)*a%s,f=V(c,ta,s)*r%s,l=V(f,ea,s)*f%s,u=V(l,t,s)*l%s,w=V(u,e,s)*u%s,_=V(w,n,s)*w%s,m=V(_,o,s)*_%s,v=V(m,o,s)*_%s,S=V(v,t,s)*l%s;return{pow_p_5_8:V(S,xs,s)*r%s,b2:a}}function sa(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var ws=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function ia(r,t){let e=In,n=G(t*t*t,e),o=G(n*n*t,e),s=oa(r*o).pow_p_5_8,i=G(r*n*s,e),a=G(t*i*i,e),c=i,f=G(i*ws,e),l=a===r,u=a===G(-r,e),w=a===G(-r*ws,e);return l&&(i=c),(u||w)&&(i=f),fs(i,e)&&(i=G(-i,e)),{isValid:l||u,value:i}}var ca=ys(na,{uvRatio:ia});function aa(r){return gs(ca,Xo,Object.assign({adjustScalarBytes:sa},r))}var Es=aa({});var ke=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},cr=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var _s={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new cr("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 ar=_s;var fr=32;var Ln,fa=(async()=>{try{return await ar.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function ua(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await ar.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await ar.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function ha(r,t,e){return Es.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Ss(r,t,e){return Ln==null&&(Ln=await fa),Ln?ua(r,t,e):ha(r,t,e)}function ur(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var hr=class{type="Ed25519";raw;constructor(t){this.raw=Dn(t,fr)}toMultihash(){return dt.digest(ae(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Ss(this.raw,e,t);return ur(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function vs(r){return r=Dn(r,fr),new hr(r)}function Dn(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new _t(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var da=Math.pow(2,7),pa=Math.pow(2,14),ma=Math.pow(2,21),Bs=Math.pow(2,28),Is=Math.pow(2,35),Ls=Math.pow(2,42),Ds=Math.pow(2,49),nt=128,Ot=127;function Ne(r){if(r<da)return 1;if(r<pa)return 2;if(r<ma)return 3;if(r<Bs)return 4;if(r<Is)return 5;if(r<Ls)return 6;if(r<Ds)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Cs(r,t,e=0){switch(Ne(r)){case 8:t[e++]=r&255|nt,r/=128;case 7:t[e++]=r&255|nt,r/=128;case 6:t[e++]=r&255|nt,r/=128;case 5:t[e++]=r&255|nt,r/=128;case 4:t[e++]=r&255|nt,r>>>=7;case 3:t[e++]=r&255|nt,r>>>=7;case 2:t[e++]=r&255|nt,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function Ts(r,t){let e=r[t],n=0;if(n+=e&Ot,e<nt||(e=r[t+1],n+=(e&Ot)<<7,e<nt)||(e=r[t+2],n+=(e&Ot)<<14,e<nt)||(e=r[t+3],n+=(e&Ot)<<21,e<nt)||(e=r[t+4],n+=(e&Ot)*Bs,e<nt)||(e=r[t+5],n+=(e&Ot)*Is,e<nt)||(e=r[t+6],n+=(e&Ot)*Ls,e<nt)||(e=r[t+7],n+=(e&Ot)*Ds,e<nt))return n;throw new RangeError("Could not decode varint")}var Cn=new Float32Array([-0]),Mt=new Uint8Array(Cn.buffer);function Us(r,t,e){Cn[0]=r,t[e]=Mt[0],t[e+1]=Mt[1],t[e+2]=Mt[2],t[e+3]=Mt[3]}function Rs(r,t){return Mt[0]=r[t],Mt[1]=r[t+1],Mt[2]=r[t+2],Mt[3]=r[t+3],Cn[0]}var Tn=new Float64Array([-0]),et=new Uint8Array(Tn.buffer);function Ks(r,t,e){Tn[0]=r,t[e]=et[0],t[e+1]=et[1],t[e+2]=et[2],t[e+3]=et[3],t[e+4]=et[4],t[e+5]=et[5],t[e+6]=et[6],t[e+7]=et[7]}function ks(r,t){return et[0]=r[t],et[1]=r[t+1],et[2]=r[t+2],et[3]=r[t+3],et[4]=r[t+4],et[5]=r[t+5],et[6]=r[t+6],et[7]=r[t+7],Tn[0]}var ba=BigInt(Number.MAX_SAFE_INTEGER),ya=BigInt(Number.MIN_SAFE_INTEGER),ht=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+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 e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(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,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return Wt;if(t<ba&&t>ya)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>Ns&&(o=0n,++n>Ns&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return Wt;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):Wt}},Wt=new ht(0,0);Wt.toBigInt=function(){return 0n};Wt.zzEncode=Wt.zzDecode=function(){return this};Wt.length=function(){return 1};var Ns=4294967296n;function Os(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function Ms(r,t,e){if(e-t<1)return"";let o,s=[],i=0,a;for(;t<e;)a=r[t++],a<128?s[i++]=a:a>191&&a<224?s[i++]=(a&31)<<6|r[t++]&63:a>239&&a<365?(a=((a&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(a>>10),s[i++]=56320+(a&1023)):s[i++]=(a&15)<<12|(r[t++]&63)<<6|r[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 Un(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function bt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function lr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var Rn=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,bt(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 bt(this,4);return lr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw bt(this,4);return lr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw bt(this,4);let t=Rs(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw bt(this,4);let t=ks(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw bt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return Ms(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw bt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw bt(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 ht(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*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;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw bt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw bt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw bt(this,8);let t=lr(this.buf,this.pos+=4),e=lr(this.buf,this.pos+=4);return new ht(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=Ts(this.buf,this.pos);return this.pos+=Ne(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 Oe(r){return new Rn(r instanceof Uint8Array?r:r.subarray())}function dr(r,t,e){let n=Oe(r);return t.decode(n,void 0,e)}function Kn(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ft(i);o+i>t&&(n=ft(t),o=0);let a=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),a}}var Jt=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function kn(){}var On=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},ga=Kn();function xa(r){return globalThis.Buffer!=null?ft(r):ga(r)}var Pe=class{len;head;tail;states;constructor(){this.len=0,this.head=new Jt(kn,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new Jt(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new Mn((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(pr,10,ht.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=ht.fromBigInt(t);return this._push(pr,e.length(),e)}uint64Number(t){return this._push(Cs,Ne(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 e=ht.fromBigInt(t).zzEncode();return this._push(pr,e.length(),e)}sint64Number(t){let e=ht.fromNumber(t).zzEncode();return this._push(pr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(Nn,1,t?1:0)}fixed32(t){return this._push(Me,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=ht.fromBigInt(t);return this._push(Me,4,e.lo)._push(Me,4,e.hi)}fixed64Number(t){let e=ht.fromNumber(t);return this._push(Me,4,e.lo)._push(Me,4,e.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(Us,4,t)}double(t){return this._push(Ks,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(Nn,1,0):this.uint32(e)._push(Ea,e,t)}string(t){let e=Os(t);return e!==0?this.uint32(e)._push(Un,e,t):this._push(Nn,1,0)}fork(){return this.states=new On(this),this.head=this.tail=new Jt(kn,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 Jt(kn,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=xa(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function Nn(r,t,e){t[e]=r&255}function wa(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var Mn=class extends Jt{next;constructor(t,e){super(wa,t,e),this.next=void 0}};function pr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Me(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Ea(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(Pe.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(_a,t,r),this},Pe.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(Sa,t,r),this});function _a(r,t,e){t.set(r,e)}function Sa(r,t,e){r.length<40?Un(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set($(r),e)}function Pn(){return new Pe}function mr(r,t){let e=Pn();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*br(r,t,e){let n=Oe(r);yield*t.stream(n,void 0,"$",e)}var yr={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function gr(r,t,e,n,o){return{name:r,type:t,encode:e,decode:n,stream:o}}function qn(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=function(i,a){let c=t(i);a.int32(c)},n=function(i){let a=i.int32();return t(a)},o=function*(i){let a=i.int32();yield t(a)};return gr("enum",yr.VARINT,e,n,o)}function xr(r,t,e){return gr("message",yr.LENGTH_DELIMITED,r,t,e)}var ot;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(ot||(ot={}));var Hn;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(Hn||(Hn={}));(function(r){r.codec=()=>qn(Hn)})(ot||(ot={}));var qe;(function(r){let t;r.codec=()=>(t==null&&(t=xr((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ot.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{c.Type=ot.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(l&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{yield{field:`${a}.Type`,value:ot.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),t);function e(s){return mr(s,r.codec())}r.encode=e;function n(s,i){return dr(s,r.codec(),i)}r.decode=n;function o(s,i){return br(s,r.codec(),i)}r.stream=o})(qe||(qe={}));var Vn;(function(r){let t;r.codec=()=>(t==null&&(t=xr((s,i,a={})=>{a.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ot.codec().encode(s.Type,i)),s.Data!=null&&(i.uint32(18),i.bytes(s.Data)),a.lengthDelimited!==!1&&i.ldelim()},(s,i,a={})=>{let c={},f=i==null?s.len:s.pos+i;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{c.Type=ot.codec().decode(s);break}case 2:{c.Data=s.bytes();break}default:{s.skipType(l&7);break}}}return c},function*(s,i,a,c={}){let f=i==null?s.len:s.pos+i;for(;s.pos<f;){let l=s.uint32();switch(l>>>3){case 1:{yield{field:`${a}.Type`,value:ot.codec().decode(s)};break}case 2:{yield{field:`${a}.Data`,value:s.bytes()};break}default:{s.skipType(l&7);break}}}})),t);function e(s){return mr(s,r.codec())}r.encode=e;function n(s,i){return dr(s,r.codec(),i)}r.decode=n;function o(s,i){return br(s,r.codec(),i)}r.stream=o})(Vn||(Vn={}));var wr=class{oHash;iHash;blockLen;outputLen;finished=!1;destroyed=!1;constructor(t,e){if(Qe(t),N(e,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(e.length>n?t.create().update(e).digest():e);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 fe(this),this.iHash.update(t),this}digestInto(t){fe(this),N(t,this.outputLen,"output"),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||=Object.create(Object.getPrototypeOf(this),{});let{oHash:e,iHash:n,finished:o,destroyed:s,blockLen:i,outputLen:a}=this;return t=t,t.finished=o,t.destroyed=s,t.blockLen=i,t.outputLen=a,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},zn=(r,t,e)=>new wr(r,t).update(e).digest();zn.create=(r,t)=>new wr(r,t);var qs=(r,t)=>(r+(r>=0?t:-t)/Hs)/t;function va(r,t,e){let[[n,o],[s,i]]=t,a=qs(i*r,e),c=qs(-o*r,e),f=r-a*n-c*s,l=-a*o-c*i,u=f<Ct,w=l<Ct;u&&(f=-f),w&&(l=-l);let _=Ue(Math.ceil(yn(e)/2))+be;if(f<Ct||f>=_||l<Ct||l>=_)throw new Error("splitScalar (endomorphism): failed, k="+r);return{k1neg:u,k1:f,k2neg:w,k2:l}}function Zn(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function Fn(r,t){let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return Dt(e.lowS,"lowS"),Dt(e.prehash,"prehash"),e.format!==void 0&&Zn(e.format),e}var Yn=class extends Error{constructor(t=""){super(t)}},Pt={Err:Yn,_tlv:{encode:(r,t)=>{let{Err:e}=Pt;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=Ce(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?Ce(o.length/2|128):"";return Ce(r)+s+o+t},decode(r,t){let{Err:e}=Pt,n=0;if(r<0||r>256)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("tlv.decode: wrong tlv");let o=t[n++],s=!!(o&128),i=0;if(!s)i=o;else{let c=o&127;if(!c)throw new e("tlv.decode(long): indefinite length not supported");if(c>4)throw new e("tlv.decode(long): byte length is too big");let f=t.subarray(n,n+c);if(f.length!==c)throw new e("tlv.decode: length bytes not complete");if(f[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let l of f)i=i<<8|l;if(n+=c,i<128)throw new e("tlv.decode(long): not minimal encoding")}let a=t.subarray(n,n+i);if(a.length!==i)throw new e("tlv.decode: wrong value length");return{v:a,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Pt;if(r<Ct)throw new t("integer: negative integers are not allowed");let e=Ce(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Pt;if(r[0]&128)throw new t("invalid signature integer: negative");if(r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return he(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Pt,o=N(r,void 0,"signature"),{v:s,l:i}=n.decode(48,o);if(i.length)throw new t("invalid signature: left bytes after parsing");let{v:a,l:c}=n.decode(2,s),{v:f,l}=n.decode(2,c);if(l.length)throw new t("invalid signature: left bytes after parsing");return{r:e.decode(a),s:e.decode(f)}},hexFromSig(r){let{_tlv:t,_int:e}=Pt,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}},Ct=BigInt(0),be=BigInt(1),Hs=BigInt(2),Er=BigInt(3),Ba=BigInt(4);function Vs(r,t={}){let e=sr("weierstrass",r,t),{Fp:n,Fn:o}=e,s=e.CURVE,{h:i,n:a}=s;kt(t,{},{allowInfinityPoint:"boolean",clearCofactor:"function",isTorsionFree:"function",fromBytes:"function",toBytes:"function",endo:"object"});let{endo:c}=t;if(c&&(!n.is0(s.a)||typeof c.beta!="bigint"||!Array.isArray(c.basises)))throw new Error('invalid endo: expected "beta": bigint and "basises": array');let f=Fs(n,o);function l(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function u(C,d,p){let{x:h,y:E}=d.toAffine(),I=n.toBytes(h);if(Dt(p,"isCompressed"),p){l();let D=!n.isOdd(E);return it(zs(D),I)}else return it(Uint8Array.of(4),I,n.toBytes(E))}function w(C){N(C,void 0,"Point");let{publicKey:d,publicKeyUncompressed:p}=f,h=C.length,E=C[0],I=C.subarray(1);if(h===d&&(E===2||E===3)){let D=n.fromBytes(I);if(!n.isValid(D))throw new Error("bad point: is not on curve, wrong x");let T=v(D),L;try{L=n.sqrt(T)}catch(z){let H=z instanceof Error?": "+z.message:"";throw new Error("bad point: is not on curve, sqrt error"+H)}l();let U=n.isOdd(L);return(E&1)===1!==U&&(L=n.neg(L)),{x:D,y:L}}else if(h===p&&E===4){let D=n.BYTES,T=n.fromBytes(I.subarray(0,D)),L=n.fromBytes(I.subarray(D,D*2));if(!S(T,L))throw new Error("bad point: is not on curve");return{x:T,y:L}}else throw new Error(`bad point: got length ${h}, expected compressed=${d} or uncompressed=${p}`)}let _=t.toBytes||u,m=t.fromBytes||w;function v(C){let d=n.sqr(C),p=n.mul(d,C);return n.add(n.add(p,n.mul(C,s.a)),s.b)}function S(C,d){let p=n.sqr(d),h=v(C);return n.eql(p,h)}if(!S(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let b=n.mul(n.pow(s.a,Er),Ba),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(b,A)))throw new Error("bad curve params: a or b");function y(C,d,p=!1){if(!n.isValid(d)||p&&n.is0(d))throw new Error(`bad point coordinate ${C}`);return d}function B(C){if(!(C instanceof g))throw new Error("Weierstrass Point expected")}function R(C){if(!c||!c.basises)throw new Error("no endo");return va(C,c.basises,o.ORDER)}let O=le((C,d)=>{let{X:p,Y:h,Z:E}=C;if(n.eql(E,n.ONE))return{x:p,y:h};let I=C.is0();d==null&&(d=I?n.ONE:n.inv(E));let D=n.mul(p,d),T=n.mul(h,d),L=n.mul(E,d);if(I)return{x:n.ZERO,y:n.ZERO};if(!n.eql(L,n.ONE))throw new Error("invZ was invalid");return{x:D,y:T}}),M=le(C=>{if(C.is0()){if(t.allowInfinityPoint&&!n.is0(C.Y))return;throw new Error("bad point: ZERO")}let{x:d,y:p}=C.toAffine();if(!n.isValid(d)||!n.isValid(p))throw new Error("bad point: x or y not field elements");if(!S(d,p))throw new Error("bad point: equation left != right");if(!C.isTorsionFree())throw new Error("bad point: not in prime-order subgroup");return!0});function x(C,d,p,h,E){return p=new g(n.mul(p.X,C),p.Y,p.Z),d=Ke(h,d),p=Ke(E,p),d.add(p)}class g{static BASE=new g(s.Gx,s.Gy,n.ONE);static ZERO=new g(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(d,p,h){this.X=y("x",d),this.Y=y("y",p,!0),this.Z=y("z",h),Object.freeze(this)}static CURVE(){return s}static fromAffine(d){let{x:p,y:h}=d||{};if(!d||!n.isValid(p)||!n.isValid(h))throw new Error("invalid affine point");if(d instanceof g)throw new Error("projective point not allowed");return n.is0(p)&&n.is0(h)?g.ZERO:new g(p,h,n.ONE)}static fromBytes(d){let p=g.fromAffine(m(N(d,void 0,"point")));return p.assertValidity(),p}static fromHex(d){return g.fromBytes(It(d))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,p=!0){return P.createCache(this,d),p||this.multiply(Er),this}assertValidity(){M(this)}hasEvenY(){let{y:d}=this.toAffine();if(!n.isOdd)throw new Error("Field doesn't support isOdd");return!n.isOdd(d)}equals(d){B(d);let{X:p,Y:h,Z:E}=this,{X:I,Y:D,Z:T}=d,L=n.eql(n.mul(p,T),n.mul(I,E)),U=n.eql(n.mul(h,T),n.mul(D,E));return L&&U}negate(){return new g(this.X,n.neg(this.Y),this.Z)}double(){let{a:d,b:p}=s,h=n.mul(p,Er),{X:E,Y:I,Z:D}=this,T=n.ZERO,L=n.ZERO,U=n.ZERO,k=n.mul(E,E),z=n.mul(I,I),H=n.mul(D,D),q=n.mul(E,I);return q=n.add(q,q),U=n.mul(E,D),U=n.add(U,U),T=n.mul(d,U),L=n.mul(h,H),L=n.add(T,L),T=n.sub(z,L),L=n.add(z,L),L=n.mul(T,L),T=n.mul(q,T),U=n.mul(h,U),H=n.mul(d,H),q=n.sub(k,H),q=n.mul(d,q),q=n.add(q,U),U=n.add(k,k),k=n.add(U,k),k=n.add(k,H),k=n.mul(k,q),L=n.add(L,k),H=n.mul(I,D),H=n.add(H,H),k=n.mul(H,q),T=n.sub(T,k),U=n.mul(H,z),U=n.add(U,U),U=n.add(U,U),new g(T,L,U)}add(d){B(d);let{X:p,Y:h,Z:E}=this,{X:I,Y:D,Z:T}=d,L=n.ZERO,U=n.ZERO,k=n.ZERO,z=s.a,H=n.mul(s.b,Er),q=n.mul(p,I),F=n.mul(h,D),J=n.mul(E,T),gt=n.add(p,h),Z=n.add(I,D);gt=n.mul(gt,Z),Z=n.add(q,F),gt=n.sub(gt,Z),Z=n.add(p,E);let tt=n.add(I,T);return Z=n.mul(Z,tt),tt=n.add(q,J),Z=n.sub(Z,tt),tt=n.add(h,E),L=n.add(D,T),tt=n.mul(tt,L),L=n.add(F,J),tt=n.sub(tt,L),k=n.mul(z,Z),L=n.mul(H,J),k=n.add(L,k),L=n.sub(F,k),k=n.add(F,k),U=n.mul(L,k),F=n.add(q,q),F=n.add(F,q),J=n.mul(z,J),Z=n.mul(H,Z),F=n.add(F,J),J=n.sub(q,J),J=n.mul(z,J),Z=n.add(Z,J),q=n.mul(F,Z),U=n.add(U,q),q=n.mul(tt,Z),L=n.mul(gt,L),L=n.sub(L,q),q=n.mul(gt,F),k=n.mul(tt,k),k=n.add(k,q),new g(L,U,k)}subtract(d){return this.add(d.negate())}is0(){return this.equals(g.ZERO)}multiply(d){let{endo:p}=t;if(!o.isValidNot0(d))throw new Error("invalid scalar: out of range");let h,E,I=D=>P.cached(this,D,T=>Xt(g,T));if(p){let{k1neg:D,k1:T,k2neg:L,k2:U}=R(d),{p:k,f:z}=I(T),{p:H,f:q}=I(U);E=z.add(q),h=x(p.beta,k,H,D,L)}else{let{p:D,f:T}=I(d);h=D,E=T}return Xt(g,[h,E])[0]}multiplyUnsafe(d){let{endo:p}=t,h=this;if(!o.isValid(d))throw new Error("invalid scalar: out of range");if(d===Ct||h.is0())return g.ZERO;if(d===be)return h;if(P.hasCache(this))return this.multiply(d);if(p){let{k1neg:E,k1:I,k2neg:D,k2:T}=R(d),{p1:L,p2:U}=bs(g,h,I,T);return x(p.beta,L,U,E,D)}else return P.unsafe(h,d)}toAffine(d){return O(this,d)}isTorsionFree(){let{isTorsionFree:d}=t;return i===be?!0:d?d(g,this):P.unsafe(this,a).is0()}clearCofactor(){let{clearCofactor:d}=t;return i===be?this:d?d(g,this):this.multiplyUnsafe(i)}isSmallOrder(){return this.multiplyUnsafe(i).is0()}toBytes(d=!0){return Dt(d,"isCompressed"),this.assertValidity(),_(g,this,d)}toHex(d=!0){return Bt(this.toBytes(d))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let K=o.BITS,P=new me(g,t.endo?Math.ceil(K/2):K);return g.BASE.precompute(8),g}function zs(r){return Uint8Array.of(r?2:3)}function Fs(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function Ia(r,t={}){let{Fn:e}=r,n=t.randomBytes||ue,o=Object.assign(Fs(r.Fp,e),{seed:En(e.ORDER)});function s(_){try{let m=e.fromBytes(_);return e.isValidNot0(m)}catch{return!1}}function i(_,m){let{publicKey:v,publicKeyUncompressed:S}=o;try{let b=_.length;return m===!0&&b!==v||m===!1&&b!==S?!1:!!r.fromBytes(_)}catch{return!1}}function a(_=n(o.seed)){return _n(N(_,o.seed,"seed"),e.ORDER)}function c(_,m=!0){return r.BASE.multiply(e.fromBytes(_)).toBytes(m)}function f(_){let{secretKey:m,publicKey:v,publicKeyUncompressed:S}=o;if(!Ft(_)||"_lengths"in e&&e._lengths||m===v)return;let b=N(_,void 0,"key").length;return b===v||b===S}function l(_,m,v=!0){if(f(_)===!0)throw new Error("first arg must be private key");if(f(m)===!1)throw new Error("second arg must be public key");let S=e.fromBytes(_);return r.fromBytes(m).multiply(S).toBytes(v)}let u={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:a},w=ir(a,c);return Object.freeze({getPublicKey:c,getSharedSecret:l,keygen:w,Point:r,utils:u,lengths:o})}function Zs(r,t,e={}){Qe(t),kt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let n=e.randomBytes||ue,o=e.hmac||((p,h)=>zn(t,p,h)),{Fp:s,Fn:i}=r,{ORDER:a,BITS:c}=i,{keygen:f,getPublicKey:l,getSharedSecret:u,utils:w,lengths:_}=Ia(r,e),m={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},v=a*Hs<s.ORDER;function S(p){let h=a>>be;return p>h}function b(p,h){if(!i.isValidNot0(h))throw new Error(`invalid signature ${p}: out of range 1..Point.Fn.ORDER`);return h}function A(){if(v)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function y(p,h){Zn(h);let E=_.signature,I=h==="compact"?E:h==="recovered"?E+1:void 0;return N(p,I)}class B{r;s;recovery;constructor(h,E,I){if(this.r=b("r",h),this.s=b("s",E),I!=null){if(A(),![0,1,2,3].includes(I))throw new Error("invalid recovery id");this.recovery=I}Object.freeze(this)}static fromBytes(h,E=m.format){y(h,E);let I;if(E==="der"){let{r:U,s:k}=Pt.toSig(N(h));return new B(U,k)}E==="recovered"&&(I=h[0],E="compact",h=h.subarray(1));let D=_.signature/2,T=h.subarray(0,D),L=h.subarray(D,D*2);return new B(i.fromBytes(T),i.fromBytes(L),I)}static fromHex(h,E){return this.fromBytes(It(h),E)}assertRecovery(){let{recovery:h}=this;if(h==null)throw new Error("invalid recovery id: must be present");return h}addRecoveryBit(h){return new B(this.r,this.s,h)}recoverPublicKey(h){let{r:E,s:I}=this,D=this.assertRecovery(),T=D===2||D===3?E+a:E;if(!s.isValid(T))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let L=s.toBytes(T),U=r.fromBytes(it(zs((D&1)===0),L)),k=i.inv(T),z=O(N(h,void 0,"msgHash")),H=i.create(-z*k),q=i.create(I*k),F=r.BASE.multiplyUnsafe(H).add(U.multiplyUnsafe(q));if(F.is0())throw new Error("invalid recovery: point at infinify");return F.assertValidity(),F}hasHighS(){return S(this.s)}toBytes(h=m.format){if(Zn(h),h==="der")return It(Pt.hexFromSig(this));let{r:E,s:I}=this,D=i.toBytes(E),T=i.toBytes(I);return h==="recovered"?(A(),it(Uint8Array.of(this.assertRecovery()),D,T)):it(D,T)}toHex(h){return Bt(this.toBytes(h))}}let R=e.bits2int||function(h){if(h.length>8192)throw new Error("input is too large");let E=he(h),I=h.length*8-c;return I>0?E>>BigInt(I):E},O=e.bits2int_modN||function(h){return i.create(R(h))},M=Ue(c);function x(p){return Te("num < 2^"+c,p,Ct,M),i.toBytes(p)}function g(p,h){return N(p,void 0,"message"),h?N(t(p),void 0,"prehashed message"):p}function K(p,h,E){let{lowS:I,prehash:D,extraEntropy:T}=Fn(E,m);p=g(p,D);let L=O(p),U=i.fromBytes(h);if(!i.isValidNot0(U))throw new Error("invalid private key");let k=[x(U),x(L)];if(T!=null&&T!==!1){let F=T===!0?n(_.secretKey):T;k.push(N(F,void 0,"extraEntropy"))}let z=it(...k),H=L;function q(F){let J=R(F);if(!i.isValidNot0(J))return;let gt=i.inv(J),Z=r.BASE.multiply(J).toAffine(),tt=i.create(Z.x);if(tt===Ct)return;let Ze=i.create(gt*i.create(H+tt*U));if(Ze===Ct)return;let ro=(Z.x===tt?0:2)|Number(Z.y&be),no=Ze;return I&&S(Ze)&&(no=i.neg(Ze),ro^=1),new B(tt,no,v?void 0:ro)}return{seed:z,k2sig:q}}function P(p,h,E={}){let{seed:I,k2sig:D}=K(p,h,E);return Qo(t.outputLen,i.BYTES,o)(I,D).toBytes(E.format)}function C(p,h,E,I={}){let{lowS:D,prehash:T,format:L}=Fn(I,m);if(E=N(E,void 0,"publicKey"),h=g(h,T),!Ft(p)){let U=p instanceof B?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+U)}y(p,L);try{let U=B.fromBytes(p,L),k=r.fromBytes(E);if(D&&U.hasHighS())return!1;let{r:z,s:H}=U,q=O(h),F=i.inv(H),J=i.create(q*F),gt=i.create(z*F),Z=r.BASE.multiplyUnsafe(J).add(k.multiplyUnsafe(gt));return Z.is0()?!1:i.create(Z.x)===z}catch{return!1}}function d(p,h,E={}){let{prehash:I}=Fn(E,m);return h=g(h,I),B.fromBytes(p,"recovered").recoverPublicKey(h).toBytes()}return Object.freeze({keygen:f,getPublicKey:l,getSharedSecret:u,utils:w,lengths:_,Point:r,sign:P,verify:C,recoverPublicKey:d,Signature:B,hash:t})}var Gn={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},La={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var Ys=BigInt(2);function Da(r){let t=Gn.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),a=BigInt(44),c=BigInt(88),f=r*r*r%t,l=f*f*r%t,u=V(l,e,t)*l%t,w=V(u,e,t)*l%t,_=V(w,Ys,t)*f%t,m=V(_,o,t)*_%t,v=V(m,s,t)*m%t,S=V(v,a,t)*v%t,b=V(S,c,t)*S%t,A=V(b,a,t)*v%t,y=V(A,e,t)*l%t,B=V(y,i,t)*m%t,R=V(B,n,t)*f%t,O=V(R,Ys,t);if(!jn.eql(jn.sqr(O),r))throw new Error("Cannot find square root");return O}var jn=de(Gn.p,{sqrt:Da}),Ca=Vs(Gn,{Fp:jn,endo:La}),ye=Zs(Ca,$o);function js(r,t,e,n){let o=Ae.digest(e instanceof Uint8Array?e:e.subarray());if(ur(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),ye.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new ke(String(s))});try{return n?.signal?.throwIfAborted(),ye.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new ke(String(s))}}var _r=class{type="secp256k1";raw;_key;constructor(t){this._key=$s(t),this.raw=Gs(this._key)}toMultihash(){return dt.digest(ae(this))}toCID(){return st.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}verify(t,e,n){return js(this._key,e,t,n)}};function Xs(r){return new _r(r)}function Gs(r){return ye.Point.fromBytes(r).toBytes()}function $s(r){try{return ye.Point.fromBytes(r),r}catch(t){throw new Ye(String(t))}}function Ws(r){let{Type:t,Data:e}=qe.decode(r.digest),n=e??new Uint8Array;switch(t){case ot.Ed25519:return vs(n);case ot.secp256k1:return Xs(n);case ot.ECDSA:return Uo(n);default:throw new ge}}function ae(r){return qe.encode({Type:ot[r.type],Data:r.raw})}var Js=Symbol.for("nodejs.util.inspect.custom"),Ta=114,He=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()})`}[Cr]=!0;toString(){return this.string==null&&(this.string=j.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return st.createV1(Ta,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return at(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return at(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Js](){return`PeerId(${this.toString()})`}},Sr=class extends He{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},Ar=class extends He{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},vr=class extends He{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},Ua=2336,Br=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=dt.digest($(this.url))}[Js](){return`PeerId(${this.url})`}[Cr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return st.createV1(Ua,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=lt(t)),t.toString()===this.toString())}};function Qs(r){if(Ka(r))return new Sr({multihash:r});if(Ra(r))try{let t=Ws(r);if(t.type==="Ed25519")return new Ar({multihash:r,publicKey:t});if(t.type==="secp256k1")return new vr({multihash:r,publicKey:t})}catch{let e=lt(r.digest);return new Br(new URL(e))}throw new je("Supplied PeerID Multihash is invalid")}function Ra(r){return r.code===dt.code}function Ka(r){return r.code===Ae.code}function Et(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function Ir(r){let t=_e(j.decode(`z${r}`));return Qs(t)}var qt=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return Et(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return Et(this.map.values(),t=>t.key)}values(){return Et(this.map.values(),t=>t.value)}get size(){return this.map.size}};function ti(){return new qt}var Ht=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return Et(this.set.entries(),t=>{let e=Ir(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Ir(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Et(this.set.values(),t=>Ir(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function ei(){return new Ht}var Vt=class r{list;constructor(t){if(this.list=[],t!=null)for(let e of t)this.list.push(e)}[Symbol.iterator](){return Et(this.list.entries(),t=>t[1])}concat(t){let e=new r(this);for(let n of t)e.push(n);return e}entries(){return Et(this.list.entries(),t=>[t[0],t[1]])}every(t){return this.list.every((e,n)=>t(e,n,this))}filter(t){let e=new r;return this.list.forEach((n,o)=>{t(n,o,this)&&e.push(n)}),e}find(t){let e=this.list.find((n,o)=>t(n,o,this));if(e!=null)return e}findIndex(t){return this.list.findIndex((e,n)=>t(e,n,this))}forEach(t){this.list.forEach((e,n)=>{t(e,n,this)})}includes(t){return this.includes(t)}indexOf(t){return this.list.findIndex(e=>e.equals(t))}pop(){let t=this.list.pop();if(t!=null)return t}push(...t){for(let e of t)this.list.push(e)}shift(){let t=this.list.shift();if(t!=null)return t}unshift(...t){let e=this.list.length;for(let n=t.length-1;n>-1;n--)e=this.list.unshift(t[n]);return e}clear(){this.list=[]}get length(){return this.list.length}};function ri(){return new Vt}var $n={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},ni={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},oi=new globalThis.TextEncoder;function ka(r,t){let e=$n[t],n=ni[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function Na(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=$n[t],o=ni[t],s=r;for(;s.length>0;){let i=oi.encodeInto(s,e);s=s.slice(i.read);for(let a=0;a<i.written;a++)o^=BigInt(e[a]),o=BigInt.asUintN(t,o*n)}return o}function Xn(r,{size:t=32,utf8Buffer:e}={}){if(!$n[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(e)return Na(r,t,e);r=oi.encode(r)}return ka(r,t)}var Ve={hash:r=>Number(Xn(r,{size:32})),hashV:(r,t)=>Oa(Ve.hash(r,t))};function Oa(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),$(t,"base16")}var Wn=64,yt=class{fp;h;seed;constructor(t,e,n,o=2){if(o>Wn)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=pt(o);for(let a=0;a<i.length;a++)i[a]=s[a];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?at(this.fp,t.fp):!1}};function Qt(r,t){return Math.floor(Math.random()*(t-r))+r}var te=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof yt))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof yt))throw new TypeError("Invalid Fingerprint");for(let e=0;e<this.contents.length;e++)if(this.contents[e]==null)return this.contents[e]=t,!0;return!0}swap(t){if(!(t instanceof yt))throw new TypeError("Invalid Fingerprint");let e=Qt(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof yt))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var Ma=500,ze=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(t){this.filterSize=t.filterSize,this.bucketSize=t.bucketSize??4,this.fingerprintSize=t.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=t.hash??Ve,this.seed=t.seed??Qt(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=$(t));let e=new yt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^e.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new te(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new te(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[Qt(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new te(this.bucketSize));for(let a=0;a<Ma;a++){let c=this.buckets[i].swap(e);if(c!=null&&(i=(i^c.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new te(this.bucketSize)),this.buckets[i].add(c)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=$(t));let e=new yt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(e)??!1;if(o)return o;let s=(n^e.hash())%this.filterSize;return this.buckets[s]?.has(e)??!1}remove(t){typeof t=="string"&&(t=$(t));let e=new yt(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(e)??!1;if(o)return this.count--,o;let s=(n^e.hash())%this.filterSize,i=this.buckets[s]?.remove(e)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},Pa={1:.5,2:.84,4:.95,8:.98};function qa(r=.001){return r>.002?2:r>1e-5?4:8}function si(r,t=.001){let e=qa(t),n=Pa[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),Wn);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var Lr=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(t){this.bucketSize=t.bucketSize??4,this.filterSize=t.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=t.fingerprintSize??2,this.scale=t.scale??2,this.hash=t.hash??Ve,this.seed=t.seed??Qt(0,Math.pow(2,10)),this.filterSeries=[new ze({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=$(t)),this.has(t))return!0;let e=this.filterSeries.find(n=>n.reliable);if(e==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);e=new ze({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(e)}return e.add(t)}has(t){typeof t=="string"&&(t=$(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=$(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,e)=>t+e.count,0)}};function Jn(r,t=.001,e){return new Lr({...si(r,t),...e??{}})}var Fe=class{filter;constructor(t,e){this.filter=Jn(t,e)}has(t){return this.filter.has(t.toMultihash().bytes)}add(t){this.filter.add(t.toMultihash().bytes)}remove(t){this.filter.remove?.(t.toMultihash().bytes)}};function ii(r,t=.001){return new Fe(r,t)}var Qn=class extends qt{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function ci(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Qn({name:t,metrics:e}):n=new qt,n}var to=class extends Ht{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}add(t){super.add(t),this.updateComponentMetric()}delete(t){super.delete(t),this.updateComponentMetric()}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function ai(r){let{name:t,metrics:e}=r,n;return e!=null?n=new to({name:t,metrics:e}):n=new Ht,n}var eo=class extends Vt{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}pop(){let t=super.pop();return this.updateComponentMetric(),t}push(...t){super.push(...t),this.updateComponentMetric()}shift(){let t=super.shift();return this.updateComponentMetric(),t}unshift(...t){let e=super.unshift(...t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.length)}};function fi(r){let{name:t,metrics:e}=r,n;return e!=null?n=new eo({name:t,metrics:e}):n=new Vt,n}return pi(Ha);})();
2
+ "use strict";var Libp2PPeerCollections=(()=>{var $r=Object.defineProperty;var Ki=Object.getOwnPropertyDescriptor;var Ni=Object.getOwnPropertyNames;var Mi=Object.prototype.hasOwnProperty;var ct=(r,t)=>{for(var e in t)$r(r,e,{get:t[e],enumerable:!0})},Pi=(r,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ni(t))!Mi.call(r,o)&&o!==e&&$r(r,o,{get:()=>t[o],enumerable:!(n=Ki(t,o))||n.enumerable});return r};var zi=r=>Pi($r({},"__esModule",{value:!0}),r);var wf={};ct(wf,{PeerFilter:()=>rr,PeerList:()=>$t,PeerMap:()=>Zt,PeerSet:()=>Yt,peerFilter:()=>Fi,peerList:()=>Li,peerMap:()=>Ii,peerSet:()=>Ti,trackedPeerList:()=>ki,trackedPeerMap:()=>Oi,trackedPeerSet:()=>Ui});var It=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},or=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var sr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Ie=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Gr=Symbol.for("@libp2p/peer-id");var tn={};ct(tn,{base58btc:()=>Z,base58flickr:()=>$i});var vf=new Uint8Array(0);function Lo(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}function Tt(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Do(r){return new TextEncoder().encode(r)}function Co(r){return new TextDecoder().decode(r)}function Hi(r,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(e[i]!==255)throw new TypeError(s+" is ambiguous");e[i]=o}var c=r.length,f=r.charAt(0),a=Math.log(c)/Math.log(256),u=Math.log(256)/Math.log(c);function h(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var _=0,d=0,x=0,S=y.length;x!==S&&y[x]===0;)x++,_++;for(var A=(S-x)*u+1>>>0,C=new Uint8Array(A);x!==S;){for(var L=y[x],O=0,R=A-1;(L!==0||O<d)&&R!==-1;R--,O++)L+=256*C[R]>>>0,C[R]=L%c>>>0,L=L/c>>>0;if(L!==0)throw new Error("Non-zero carry");d=O,x++}for(var I=A-d;I!==A&&C[I]===0;)I++;for(var U=f.repeat(_);I<A;++I)U+=r.charAt(C[I]);return U}function w(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var _=0;if(y[_]!==" "){for(var d=0,x=0;y[_]===f;)d++,_++;for(var S=(y.length-_)*a+1>>>0,A=new Uint8Array(S);y[_];){var C=e[y.charCodeAt(_)];if(C===255)return;for(var L=0,O=S-1;(C!==0||L<x)&&O!==-1;O--,L++)C+=c*A[O]>>>0,A[O]=C%256>>>0,C=C/256>>>0;if(C!==0)throw new Error("Non-zero carry");x=L,_++}if(y[_]!==" "){for(var R=S-x;R!==S&&A[R]===0;)R++;for(var I=new Uint8Array(d+(S-R)),U=d;R!==S;)I[U++]=A[R++];return I}}}function p(y){var _=w(y);if(_)return _;throw new Error(`Non-${t} character`)}return{encode:h,decodeUnsafe:w,decode:p}}var qi=Hi,Vi=qi,Fo=Vi;var Xr=class{name;prefix;baseEncode;constructor(t,e,n){this.name=t,this.prefix=e,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Wr=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,e,n){this.name=t,this.prefix=e;let o=e.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 Oo(this,t)}},Jr=class{decoders;constructor(t){this.decoders=t}or(t){return Oo(this,t)}decode(t){let e=t[0],n=this.decoders[e];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 Oo(r,t){return new Jr({...r.decoders??{[r.prefix]:r},...t.decoders??{[t.prefix]:t}})}var Qr=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,e,n,o){this.name=t,this.prefix=e,this.baseEncode=n,this.baseDecode=o,this.encoder=new Xr(t,e,n),this.decoder=new Wr(t,e,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function ae({name:r,prefix:t,encode:e,decode:n}){return new Qr(r,t,e,n)}function Ot({name:r,prefix:t,alphabet:e}){let{encode:n,decode:o}=Fo(e,r);return ae({prefix:t,name:r,encode:n,decode:s=>Tt(o(s))})}function ji(r,t,e,n){let o=r.length;for(;r[o-1]==="=";)--o;let s=new Uint8Array(o*e/8|0),i=0,c=0,f=0;for(let a=0;a<o;++a){let u=t[r[a]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<e|u,i+=e,i>=8&&(i-=8,s[f++]=255&c>>i)}if(i>=e||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Zi(r,t,e){let n=t[t.length-1]==="=",o=(1<<e)-1,s="",i=0,c=0;for(let f=0;f<r.length;++f)for(c=c<<8|r[f],i+=8;i>e;)i-=e,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<e-i]),n)for(;(s.length*e&7)!==0;)s+="=";return s}function Yi(r){let t={};for(let e=0;e<r.length;++e)t[r[e]]=e;return t}function q({name:r,prefix:t,bitsPerChar:e,alphabet:n}){let o=Yi(n);return ae({prefix:t,name:r,encode(s){return Zi(s,n,e)},decode(s){return ji(s,o,e,r)}})}var Z=Ot({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),$i=Ot({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var en={};ct(en,{base32:()=>fe,base32hex:()=>Ji,base32hexpad:()=>tc,base32hexpadupper:()=>ec,base32hexupper:()=>Qi,base32pad:()=>Xi,base32padupper:()=>Wi,base32upper:()=>Gi,base32z:()=>rc});var fe=q({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Gi=q({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Xi=q({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Wi=q({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ji=q({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qi=q({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),tc=q({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ec=q({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),rc=q({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var rn={};ct(rn,{base36:()=>Te,base36upper:()=>nc});var Te=Ot({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),nc=Ot({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var oc=Ko,Uo=128,sc=127,ic=~sc,cc=Math.pow(2,31);function Ko(r,t,e){t=t||[],e=e||0;for(var n=e;r>=cc;)t[e++]=r&255|Uo,r/=128;for(;r&ic;)t[e++]=r&255|Uo,r>>>=7;return t[e]=r|0,Ko.bytes=e-n+1,t}var ac=nn,fc=128,ko=127;function nn(r,n){var e=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw nn.bytes=0,new RangeError("Could not decode varint");i=r[s++],e+=o<28?(i&ko)<<o:(i&ko)*Math.pow(2,o),o+=7}while(i>=fc);return nn.bytes=s-n,e}var uc=Math.pow(2,7),hc=Math.pow(2,14),lc=Math.pow(2,21),dc=Math.pow(2,28),pc=Math.pow(2,35),mc=Math.pow(2,42),bc=Math.pow(2,49),yc=Math.pow(2,56),gc=Math.pow(2,63),xc=function(r){return r<uc?1:r<hc?2:r<lc?3:r<dc?4:r<pc?5:r<mc?6:r<bc?7:r<yc?8:r<gc?9:10},wc={encode:oc,decode:ac,encodingLength:xc},Ec=wc,Le=Ec;function De(r,t=0){return[Le.decode(r,t),Le.decode.bytes]}function ue(r,t,e=0){return Le.encode(r,t,e),t}function he(r){return Le.encodingLength(r)}function de(r,t){let e=t.byteLength,n=he(r),o=n+he(e),s=new Uint8Array(o+e);return ue(r,s,0),ue(e,s,n),s.set(t,o),new le(r,e,t,s)}function Ce(r){let t=Tt(r),[e,n]=De(t),[o,s]=De(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new le(e,o,i,t)}function No(r,t){if(r===t)return!0;{let e=t;return r.code===e.code&&r.size===e.size&&e.bytes instanceof Uint8Array&&Lo(r.bytes,e.bytes)}}var le=class{code;size;digest;bytes;constructor(t,e,n,o){this.code=t,this.size=e,this.digest=n,this.bytes=o}};function Mo(r,t){let{bytes:e,version:n}=r;return n===0?Sc(e,on(r),t??Z.encoder):vc(e,on(r),t??fe.encoder)}var Po=new WeakMap;function on(r){let t=Po.get(r);if(t==null){let e=new Map;return Po.set(r,e),e}return t}var it=class r{code;version;multihash;bytes;"/";constructor(t,e,n,o){this.code=e,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:e}=this;if(t!==Re)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(e.code!==Ac)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(e)}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:e}=this.multihash,n=de(t,e);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return r.equals(this,t)}static equals(t,e){let n=e;return n!=null&&t.code===n.code&&t.version===n.version&&No(t.multihash,n.multihash)}toString(t){return Mo(this,t)}toJSON(){return{"/":Mo(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 e=t;if(e instanceof r)return e;if(e["/"]!=null&&e["/"]===e.bytes||e.asCID===e){let{version:n,code:o,multihash:s,bytes:i}=e;return new r(n,o,s,i??zo(n,o,s.bytes))}else if(e[Bc]===!0){let{version:n,multihash:o,code:s}=e,i=Ce(o);return r.create(n,s,i)}else return null}static create(t,e,n){if(typeof e!="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(e!==Re)throw new Error(`Version 0 CID must use dag-pb (code: ${Re}) block encoding`);return new r(t,e,n,n.bytes)}case 1:{let o=zo(t,e,n.bytes);return new r(t,e,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return r.create(0,Re,t)}static createV1(t,e){return r.create(1,t,e)}static decode(t){let[e,n]=r.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return e}static decodeFirst(t){let e=r.inspectBytes(t),n=e.size-e.multihashSize,o=Tt(t.subarray(n,n+e.multihashSize));if(o.byteLength!==e.multihashSize)throw new Error("Incorrect length");let s=o.subarray(e.multihashSize-e.digestSize),i=new le(e.multihashCode,e.digestSize,s,o);return[e.version===0?r.createV0(i):r.createV1(e.codec,i),t.subarray(e.size)]}static inspectBytes(t){let e=0,n=()=>{let[h,w]=De(t.subarray(e));return e+=w,h},o=n(),s=Re;if(o===18?(o=0,e=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=e,c=n(),f=n(),a=e+f,u=a-i;return{version:o,codec:s,multihashCode:c,digestSize:f,multihashSize:u,size:a}}static parse(t,e){let[n,o]=_c(t,e),s=r.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return on(s).set(n,t),s}};function _c(r,t){switch(r[0]){case"Q":{let e=t??Z;return[Z.prefix,e.decode(`${Z.prefix}${r}`)]}case Z.prefix:{let e=t??Z;return[Z.prefix,e.decode(r)]}case fe.prefix:{let e=t??fe;return[fe.prefix,e.decode(r)]}case Te.prefix:{let e=t??Te;return[Te.prefix,e.decode(r)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],t.decode(r)]}}}function Sc(r,t,e){let{prefix:n}=e;if(n!==Z.prefix)throw Error(`Cannot string encode V0 in ${e.name} encoding`);let o=t.get(n);if(o==null){let s=e.encode(r).slice(1);return t.set(n,s),s}else return o}function vc(r,t,e){let{prefix:n}=e,o=t.get(n);if(o==null){let s=e.encode(r);return t.set(n,s),s}else return o}var Re=112,Ac=18;function zo(r,t,e){let n=he(r),o=n+he(t),s=new Uint8Array(o+e.byteLength);return ue(r,s,0),ue(t,s,n),s.set(e,o),s}var Bc=Symbol.for("@ipld/js-cid/CID");var sn={};ct(sn,{identity:()=>pt});var Ho=0,Ic="identity",qo=Tt;function Tc(r,t){if(t?.truncate!=null&&t.truncate!==r.byteLength){if(t.truncate<0||t.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t.truncate)}return de(Ho,qo(r))}var pt={code:Ho,name:Ic,encode:qo,digest:Tc};function at(r,t){if(r===t)return!0;if(r.byteLength!==t.byteLength)return!1;for(let e=0;e<r.byteLength;e++)if(r[e]!==t[e])return!1;return!0}async function Vo(r,t,e,n){let o=await crypto.subtle.importKey("jwk",r,{name:"ECDSA",namedCurve:r.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,e.subarray());return n?.signal?.throwIfAborted(),s}function mt(r=0){return new Uint8Array(r)}function ft(r=0){return new Uint8Array(r)}function cr(r,t){t==null&&(t=r.reduce((o,s)=>o+s.length,0));let e=ft(t),n=0;for(let o of r)e.set(o,n),n+=o.length;return e}var Zo=Symbol.for("@achingbrain/uint8arraylist");function jo(r,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let e=0;for(let n of r){let o=e+n.byteLength;if(t<o)return{buf:n,index:t-e};e=o}throw new RangeError("index is out of bounds")}function ar(r){return!!r?.[Zo]}var ut=class r{bufs;length;[Zo]=!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 e=0;for(let n of t)if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.push(n);else if(ar(n)){e+=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+=e}prepend(...t){this.prependAll(t)}prependAll(t){let e=0;for(let n of t.reverse())if(n instanceof Uint8Array)e+=n.byteLength,this.bufs.unshift(n);else if(ar(n))e+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=e}get(t){let e=jo(this.bufs,t);return e.buf[e.index]}set(t,e){let n=jo(this.bufs,t);n.buf[n.index]=e}write(t,e=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(e+n,t[n]);else if(ar(t))for(let n=0;n<t.length;n++)this.set(e+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,e){let{bufs:n,length:o}=this._subList(t,e);return cr(n,o)}subarray(t,e){let{bufs:n,length:o}=this._subList(t,e);return n.length===1?n[0]:cr(n,o)}sublist(t,e){let{bufs:n,length:o}=this._subList(t,e),s=new r;return s.length=o,s.bufs=n,s}_subList(t,e){if(t=t??0,e=e??this.length,t<0&&(t=this.length+t),e<0&&(e=this.length+e),t<0||e>this.length)throw new RangeError("index is out of bounds");if(t===e)return{bufs:[],length:0};if(t===0&&e===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=e>c&&e<=f;if(a&&u){if(t===c&&e===f){n.push(i);break}let h=t-c;n.push(i.subarray(h,h+(e-t)));break}if(a){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(u){if(e===f){n.push(i);break}n.push(i.subarray(0,e-c));break}n.push(i)}return{bufs:n,length:e-t}}indexOf(t,e=0){if(!ar(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(e=Number(e??0),isNaN(e)&&(e=0),e<0&&(e=this.length+e),e<0&&(e=0),t.length===0)return e>this.length?this.length:e;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 h=0;h<s;h++)i[h]=-1;for(let h=0;h<o;h++)i[n[h]]=h;let c=i,f=this.byteLength-n.byteLength,a=n.byteLength-1,u;for(let h=e;h<=f;h+=u){u=0;for(let w=a;w>=0;w--){let p=this.get(h+w);if(n[w]!==p){u=Math.max(1,w-c[p]);break}}if(u===0)return h}return-1}getInt8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getInt8(0)}setInt8(t,e){let n=ft(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,e),this.write(n,t)}getInt16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,e)}setInt16(t,e,n){let o=mt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,e,n),this.write(o,t)}getInt32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,e)}setInt32(t,e,n){let o=mt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,e,n),this.write(o,t)}getBigInt64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,e)}setBigInt64(t,e,n){let o=mt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,e,n),this.write(o,t)}getUint8(t){let e=this.subarray(t,t+1);return new DataView(e.buffer,e.byteOffset,e.byteLength).getUint8(0)}setUint8(t,e){let n=ft(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,e),this.write(n,t)}getUint16(t,e){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,e)}setUint16(t,e,n){let o=mt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,e,n),this.write(o,t)}getUint32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,e)}setUint32(t,e,n){let o=mt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,e,n),this.write(o,t)}getBigUint64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,e)}setBigUint64(t,e,n){let o=mt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,e,n),this.write(o,t)}getFloat32(t,e){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,e)}setFloat32(t,e,n){let o=mt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,e,n),this.write(o,t)}getFloat64(t,e){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,e)}setFloat64(t,e,n){let o=mt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,e,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof r)||t.bufs.length!==this.bufs.length)return!1;for(let e=0;e<this.bufs.length;e++)if(!at(this.bufs[e],t.bufs[e]))return!1;return!0}static fromUint8Arrays(t,e){let n=new r;return n.bufs=t,e==null&&(e=t.reduce((o,s)=>o+s.byteLength,0)),n.length=e,n}};var cn={};ct(cn,{base10:()=>Lc});var Lc=Ot({prefix:"9",name:"base10",alphabet:"0123456789"});var an={};ct(an,{base16:()=>Dc,base16upper:()=>Cc});var Dc=q({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Cc=q({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var fn={};ct(fn,{base2:()=>Rc});var Rc=q({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var un={};ct(un,{base256emoji:()=>Kc});var Yo=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}"),Fc=Yo.reduce((r,t,e)=>(r[e]=t,r),[]),Oc=Yo.reduce((r,t,e)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return r[n]=e,r},[]);function Uc(r){return r.reduce((t,e)=>(t+=Fc[e],t),"")}function kc(r){let t=[];for(let e of r){let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);let o=Oc[n];if(o==null)throw new Error(`Non-base256emoji character: ${e}`);t.push(o)}return new Uint8Array(t)}var Kc=ae({prefix:"\u{1F680}",name:"base256emoji",encode:Uc,decode:kc});var hn={};ct(hn,{base64:()=>Nc,base64pad:()=>Mc,base64url:()=>Pc,base64urlpad:()=>zc});var Nc=q({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Mc=q({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Pc=q({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),zc=q({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var ln={};ct(ln,{base8:()=>Hc});var Hc=q({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var dn={};ct(dn,{identity:()=>qc});var qc=ae({prefix:"\0",name:"identity",encode:r=>Co(r),decode:r=>Do(r)});var au=new TextEncoder,fu=new TextDecoder;var bn={};ct(bn,{sha256:()=>Fe,sha512:()=>Yc});var Zc=20;function mn({name:r,code:t,encode:e,minDigestLength:n,maxDigestLength:o}){return new pn(r,t,e,n,o)}var pn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,e,n,o,s){this.name=t,this.code=e,this.encode=n,this.minDigestLength=o??Zc,this.maxDigestLength=s}digest(t,e){if(e?.truncate!=null){if(e.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&e.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?$o(n,this.code,e?.truncate):n.then(o=>$o(o,this.code,e?.truncate))}else throw Error("Unknown type, must be binary type")}};function $o(r,t,e){if(e!=null&&e!==r.byteLength){if(e>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e)}return de(t,r)}function Xo(r){return async t=>new Uint8Array(await crypto.subtle.digest(r,t))}var Fe=mn({name:"sha2-256",code:18,encode:Xo("SHA-256")}),Yc=mn({name:"sha2-512",code:19,encode:Xo("SHA-512")});var yn={...dn,...fn,...ln,...cn,...an,...en,...rn,...tn,...hn,...un},Eu={...bn,...sn};function Jo(r,t,e,n){return{name:r,prefix:t,encoder:{name:r,prefix:t,encode:e},decoder:{decode:n}}}var Wo=Jo("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),gn=Jo("ascii","a",r=>{let t="a";for(let e=0;e<r.length;e++)t+=String.fromCharCode(r[e]);return t},r=>{r=r.substring(1);let t=ft(r.length);for(let e=0;e<r.length;e++)t[e]=r.charCodeAt(e);return t}),$c={utf8:Wo,"utf-8":Wo,hex:yn.base16,latin1:gn,ascii:gn,binary:gn,...yn},fr=$c;function J(r,t="utf8"){let e=fr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.decoder.decode(`${e.prefix}${r}`)}function dt(r,t="utf8"){let e=fr[t];if(e==null)throw new Error(`Unsupported encoding "${t}"`);return e.encoder.encode(r).substring(1)}var Gc=parseInt("11111",2),xn=parseInt("10000000",2),Xc=parseInt("01111111",2),Qo={0:Oe,1:Oe,2:Wc,3:ta,4:ea,5:Qc,6:Jc,16:Oe,22:Oe,48:Oe};function wn(r,t={offset:0}){let e=r[t.offset]&Gc;if(t.offset++,Qo[e]!=null)return Qo[e](r,t);throw new Error("No decoder for tag "+e)}function Ue(r,t){let e=0;if((r[t.offset]&xn)===xn){let n=r[t.offset]&Xc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=r[t.offset].toString(16).padStart(2,"0");e=parseInt(o,16)}else e=r[t.offset],t.offset++;return e}function Oe(r,t){Ue(r,t);let e=[];for(;!(t.offset>=r.byteLength);){let n=wn(r,t);if(n===null)break;e.push(n)}return e}function Wc(r,t){let e=Ue(r,t),n=t.offset,o=t.offset+e,s=[];for(let i=n;i<o;i++)i===n&&r[i]===0||s.push(r[i]);return t.offset+=e,Uint8Array.from(s)}function Jc(r,t){let e=Ue(r,t),n=t.offset+e,o=r[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=r[t.offset];if(t.offset++,f.push(a&127),a<128){f.reverse();let u=0;for(let h=0;h<f.length;h++)u+=f[h]<<h*7;c+=`.${u}`,f=[]}}return c}function Qc(r,t){return t.offset++,null}function ta(r,t){let e=Ue(r,t),n=r[t.offset];t.offset++;let o=r.subarray(t.offset,t.offset+e-1);if(t.offset+=e,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function ea(r,t){let e=Ue(r,t),n=r.subarray(t.offset,t.offset+e);return t.offset+=e,n}function ra(r){let t=r.toString(16);t.length%2===1&&(t="0"+t);let e=new ut;for(let n=0;n<t.length;n+=2)e.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return e}function En(r){if(r.byteLength<128)return Uint8Array.from([r.byteLength]);let t=ra(r.byteLength);return new ut(Uint8Array.from([t.byteLength|xn]),t)}function ts(r){let t=new ut,e=128;return(r.subarray()[0]&e)===e&&t.append(Uint8Array.from([0])),t.append(r),new ut(Uint8Array.from([2]),En(t),t)}function es(r){let t=Uint8Array.from([0]),e=new ut(t,r);return new ut(Uint8Array.from([3]),En(e),e)}function ur(r,t=48){let e=new ut;for(let n of r)e.append(n);return new ut(Uint8Array.from([t]),En(e),e)}var na=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),oa=Uint8Array.from([6,5,43,129,4,0,34]),sa=Uint8Array.from([6,5,43,129,4,0,35]),ia={ext:!0,kty:"EC",crv:"P-256"},ca={ext:!0,kty:"EC",crv:"P-384"},aa={ext:!0,kty:"EC",crv:"P-521"},_n=32,Sn=48,vn=66;function rs(r){let t=wn(r);return ns(t)}function ns(r){let t=r[1][1][0],e=1,n,o;if(t.byteLength===_n*2+1)return n=dt(t.subarray(e,e+_n),"base64url"),o=dt(t.subarray(e+_n),"base64url"),new pe({...ia,key_ops:["verify"],x:n,y:o});if(t.byteLength===Sn*2+1)return n=dt(t.subarray(e,e+Sn),"base64url"),o=dt(t.subarray(e+Sn),"base64url"),new pe({...ca,key_ops:["verify"],x:n,y:o});if(t.byteLength===vn*2+1)return n=dt(t.subarray(e,e+vn),"base64url"),o=dt(t.subarray(e+vn),"base64url"),new pe({...aa,key_ops:["verify"],x:n,y:o});throw new It(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function os(r){return ur([ts(Uint8Array.from([1])),ur([fa(r.crv)],160),ur([es(new ut(Uint8Array.from([4]),J(r.x??"","base64url"),J(r.y??"","base64url")))],161)]).subarray()}function fa(r){if(r==="P-256")return na;if(r==="P-384")return oa;if(r==="P-521")return sa;throw new It(`Invalid curve ${r}`)}var pe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=os(this.jwk)),this._raw}toMultihash(){return pt.digest(me(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}async verify(t,e,n){return Vo(this.jwk,e,t,n)}};function An(r){return r instanceof Uint8Array||ArrayBuffer.isView(r)&&r.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in r&&r.BYTES_PER_ELEMENT===1}function Ut(r,t=""){if(typeof r!="number"){let e=t&&`"${t}" `;throw new TypeError(`${e}expected number, got ${typeof r}`)}if(!Number.isSafeInteger(r)||r<0){let e=t&&`"${t}" `;throw new RangeError(`${e}expected integer >= 0, got ${r}`)}}function ht(r,t,e=""){let n=An(r),o=r?.length,s=t!==void 0;if(!n||s&&o!==t){let i=e&&`"${e}" `,c=s?` of length ${t}`:"",f=n?`length=${o}`:`type=${typeof r}`,a=i+"expected Uint8Array"+c+", got "+f;throw n?new RangeError(a):new TypeError(a)}return r}function hr(r){if(typeof r!="function"||typeof r.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Ut(r.outputLen),Ut(r.blockLen),r.outputLen<1)throw new Error('"outputLen" must be >= 1');if(r.blockLen<1)throw new Error('"blockLen" must be >= 1')}function be(r,t=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(t&&r.finished)throw new Error("Hash#digest() has already been called")}function lr(r,t){ht(r,void 0,"digestInto() output");let e=t.outputLen;if(r.length<e)throw new RangeError('"digestInto() output" expected to be of length >='+e)}function Dt(...r){for(let t=0;t<r.length;t++)r[t].fill(0)}function dr(r){return new DataView(r.buffer,r.byteOffset,r.byteLength)}function bt(r,t){return r<<32-t|r>>>t}var is=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",ua=Array.from({length:256},(r,t)=>t.toString(16).padStart(2,"0"));function pr(r){if(ht(r),is)return r.toHex();let t="";for(let e=0;e<r.length;e++)t+=ua[r[e]];return t}var Lt={_0:48,_9:57,A:65,F:70,a:97,f:102};function ss(r){if(r>=Lt._0&&r<=Lt._9)return r-Lt._0;if(r>=Lt.A&&r<=Lt.F)return r-(Lt.A-10);if(r>=Lt.a&&r<=Lt.f)return r-(Lt.a-10)}function ke(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);if(is)try{return Uint8Array.fromHex(r)}catch(o){throw o instanceof SyntaxError?new RangeError(o.message):o}let t=r.length,e=t/2;if(t%2)throw new RangeError("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(e);for(let o=0,s=0;o<e;o++,s+=2){let i=ss(r.charCodeAt(s)),c=ss(r.charCodeAt(s+1));if(i===void 0||c===void 0){let f=r[s]+r[s+1];throw new RangeError('hex string expected, got non-hex character "'+f+'" at index '+s)}n[o]=i*16+c}return n}function Bn(...r){let t=0;for(let n=0;n<r.length;n++){let o=r[n];ht(o),t+=o.length}let e=new Uint8Array(t);for(let n=0,o=0;n<r.length;n++){let s=r[n];e.set(s,o),o+=s.length}return e}function In(r,t={}){let e=(o,s)=>r(s).update(o).digest(),n=r(void 0);return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.canXOF=n.canXOF,e.create=o=>r(o),Object.assign(e,t),Object.freeze(e)}function cs(r=32){Ut(r,"bytesLength");let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(r>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${r}`);return t.getRandomValues(new Uint8Array(r))}var Tn=r=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,r])});function as(r,t,e){return r&t^~r&e}function fs(r,t,e){return r&t^r&e^t&e}var Ke=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,e,n,o){this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=dr(this.buffer)}update(t){be(this),ht(t);let{view:e,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=dr(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(e,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){be(this),lr(t,this),this.finished=!0;let{buffer:e,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;e[i++]=128,Dt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let h=i;h<o;h++)e[h]=0;n.setBigUint64(o-8,BigInt(this.length*8),s),this.process(n,0);let c=dr(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 h=0;h<a;h++)c.setUint32(4*h,u[h],s)}digest(){let{buffer:t,outputLen:e}=this;this.digestInto(t);let n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:e,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%e&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ct=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var tt=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var mr=BigInt(4294967295),us=BigInt(32);function ha(r,t=!1){return t?{h:Number(r&mr),l:Number(r>>us&mr)}:{h:Number(r>>us&mr)|0,l:Number(r&mr)|0}}function hs(r,t=!1){let e=r.length,n=new Uint32Array(e),o=new Uint32Array(e);for(let s=0;s<e;s++){let{h:i,l:c}=ha(r[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Ln=(r,t,e)=>r>>>e,Dn=(r,t,e)=>r<<32-e|t>>>e,Xt=(r,t,e)=>r>>>e|t<<32-e,Wt=(r,t,e)=>r<<32-e|t>>>e,Ne=(r,t,e)=>r<<64-e|t>>>e-32,Me=(r,t,e)=>r>>>e-32|t<<64-e;function St(r,t,e,n){let o=(t>>>0)+(n>>>0);return{h:r+e+(o/2**32|0)|0,l:o|0}}var ls=(r,t,e)=>(r>>>0)+(t>>>0)+(e>>>0),ds=(r,t,e,n)=>t+e+n+(r/2**32|0)|0,ps=(r,t,e,n)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0),ms=(r,t,e,n,o)=>t+e+n+o+(r/2**32|0)|0,bs=(r,t,e,n,o)=>(r>>>0)+(t>>>0)+(e>>>0)+(n>>>0)+(o>>>0),ys=(r,t,e,n,o,s)=>t+e+n+o+s+(r/2**32|0)|0;var da=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]),kt=new Uint32Array(64),Cn=class extends Ke{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:e,C:n,D:o,E:s,F:i,G:c,H:f}=this;return[t,e,n,o,s,i,c,f]}set(t,e,n,o,s,i,c,f){this.A=t|0,this.B=e|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,e){for(let h=0;h<16;h++,e+=4)kt[h]=t.getUint32(e,!1);for(let h=16;h<64;h++){let w=kt[h-15],p=kt[h-2],y=bt(w,7)^bt(w,18)^w>>>3,_=bt(p,17)^bt(p,19)^p>>>10;kt[h]=_+kt[h-7]+y+kt[h-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:f,G:a,H:u}=this;for(let h=0;h<64;h++){let w=bt(c,6)^bt(c,11)^bt(c,25),p=u+w+as(c,f,a)+da[h]+kt[h]|0,_=(bt(n,2)^bt(n,13)^bt(n,22))+fs(n,o,s)|0;u=a,a=f,f=c,c=i+p|0,i=s,s=o,o=n,n=p+_|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(){Dt(kt)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),Dt(this.buffer)}},Rn=class extends Cn{A=Ct[0]|0;B=Ct[1]|0;C=Ct[2]|0;D=Ct[3]|0;E=Ct[4]|0;F=Ct[5]|0;G=Ct[6]|0;H=Ct[7]|0;constructor(){super(32)}};var gs=hs(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),pa=gs[0],ma=gs[1],Kt=new Uint32Array(80),Nt=new Uint32Array(80),Fn=class extends Ke{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:e,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:f,Eh:a,El:u,Fh:h,Fl:w,Gh:p,Gl:y,Hh:_,Hl:d}=this;return[t,e,n,o,s,i,c,f,a,u,h,w,p,y,_,d]}set(t,e,n,o,s,i,c,f,a,u,h,w,p,y,_,d){this.Ah=t|0,this.Al=e|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=h|0,this.Fl=w|0,this.Gh=p|0,this.Gl=y|0,this.Hh=_|0,this.Hl=d|0}process(t,e){for(let A=0;A<16;A++,e+=4)Kt[A]=t.getUint32(e),Nt[A]=t.getUint32(e+=4);for(let A=16;A<80;A++){let C=Kt[A-15]|0,L=Nt[A-15]|0,O=Xt(C,L,1)^Xt(C,L,8)^Ln(C,L,7),R=Wt(C,L,1)^Wt(C,L,8)^Dn(C,L,7),I=Kt[A-2]|0,U=Nt[A-2]|0,z=Xt(I,U,19)^Ne(I,U,61)^Ln(I,U,6),k=Wt(I,U,19)^Me(I,U,61)^Dn(I,U,6),l=ps(R,k,Nt[A-7],Nt[A-16]),m=ms(l,O,z,Kt[A-7],Kt[A-16]);Kt[A]=m|0,Nt[A]=l|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:f,Dh:a,Dl:u,Eh:h,El:w,Fh:p,Fl:y,Gh:_,Gl:d,Hh:x,Hl:S}=this;for(let A=0;A<80;A++){let C=Xt(h,w,14)^Xt(h,w,18)^Ne(h,w,41),L=Wt(h,w,14)^Wt(h,w,18)^Me(h,w,41),O=h&p^~h&_,R=w&y^~w&d,I=bs(S,L,R,ma[A],Nt[A]),U=ys(I,x,C,O,pa[A],Kt[A]),z=I|0,k=Xt(n,o,28)^Ne(n,o,34)^Ne(n,o,39),l=Wt(n,o,28)^Me(n,o,34)^Me(n,o,39),m=n&s^n&c^s&c,E=o&i^o&f^i&f;x=_|0,S=d|0,_=p|0,d=y|0,p=h|0,y=w|0,{h,l:w}=St(a|0,u|0,U|0,z|0),a=c|0,u=f|0,c=s|0,f=i|0,s=n|0,i=o|0;let g=ls(z,l,E);n=ds(g,U,k,m),o=g|0}({h:n,l:o}=St(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=St(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:f}=St(this.Ch|0,this.Cl|0,c|0,f|0),{h:a,l:u}=St(this.Dh|0,this.Dl|0,a|0,u|0),{h,l:w}=St(this.Eh|0,this.El|0,h|0,w|0),{h:p,l:y}=St(this.Fh|0,this.Fl|0,p|0,y|0),{h:_,l:d}=St(this.Gh|0,this.Gl|0,_|0,d|0),{h:x,l:S}=St(this.Hh|0,this.Hl|0,x|0,S|0),this.set(n,o,s,i,c,f,a,u,h,w,p,y,_,d,x,S)}roundClean(){Dt(Kt,Nt)}destroy(){this.destroyed=!0,Dt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},On=class extends Fn{Ah=tt[0]|0;Al=tt[1]|0;Bh=tt[2]|0;Bl=tt[3]|0;Ch=tt[4]|0;Cl=tt[5]|0;Dh=tt[6]|0;Dl=tt[7]|0;Eh=tt[8]|0;El=tt[9]|0;Fh=tt[10]|0;Fl=tt[11]|0;Gh=tt[12]|0;Gl=tt[13]|0;Hh=tt[14]|0;Hl=tt[15]|0;constructor(){super(64)}};var xs=In(()=>new Rn,Tn(1));var br=In(()=>new On,Tn(3));var M=(r,t,e)=>ht(r,t,e),kn=Ut,ye=pr,G=(...r)=>Bn(...r),ge=r=>ke(r),Jt=An,Pe=r=>cs(r),gr=BigInt(0),Un=BigInt(1);function yt(r,t=""){if(typeof r!="boolean"){let e=t&&`"${t}" `;throw new TypeError(e+"expected boolean, got type="+typeof r)}return r}function xr(r){if(typeof r=="bigint"){if(!yr(r))throw new RangeError("positive bigint expected, got "+r)}else kn(r);return r}function gt(r,t=""){if(typeof r!="number"){let e=t&&`"${t}" `;throw new TypeError(e+"expected number, got type="+typeof r)}if(!Number.isSafeInteger(r)){let e=t&&`"${t}" `;throw new RangeError(e+"expected safe integer, got "+r)}}function ze(r){let t=xr(r).toString(16);return t.length&1?"0"+t:t}function ws(r){if(typeof r!="string")throw new TypeError("hex string expected, got "+typeof r);return r===""?gr:BigInt("0x"+r)}function Qt(r){return ws(pr(r))}function vt(r){return ws(pr(He(ht(r)).reverse()))}function wr(r,t){if(Ut(t),t===0)throw new RangeError("zero length");r=xr(r);let e=r.toString(16);if(e.length>t*2)throw new RangeError("number too large");return ke(e.padStart(t*2,"0"))}function Kn(r,t){return wr(r,t).reverse()}function Es(r,t){if(r=M(r),t=M(t),r.length!==t.length)return!1;let e=0;for(let n=0;n<r.length;n++)e|=r[n]^t[n];return e===0}function He(r){return Uint8Array.from(M(r))}function Er(r){if(typeof r!="string")throw new TypeError("ascii string expected, got "+typeof r);return Uint8Array.from(r,(t,e)=>{let n=t.charCodeAt(0);if(t.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${r[e]}" with code ${n} at position ${e}`);return n})}var yr=r=>typeof r=="bigint"&&gr<=r;function ba(r,t,e){return yr(r)&&yr(t)&&yr(e)&&t<=r&&r<e}function xe(r,t,e,n){if(!ba(t,e,n))throw new RangeError("expected valid "+r+": "+e+" <= n < "+n+", got "+t)}function we(r){if(r<gr)throw new Error("expected non-negative bigint, got "+r);let t;for(t=0;r>gr;r>>=Un,t+=1);return t}var qe=r=>(Un<<BigInt(r))-Un;function _s(r,t,e){if(Ut(r,"hashLen"),Ut(t,"qByteLen"),typeof e!="function")throw new TypeError("hmacFn must be a function");let n=d=>new Uint8Array(d),o=Uint8Array.of(),s=Uint8Array.of(0),i=Uint8Array.of(1),c=1e3,f=n(r),a=n(r),u=0,h=()=>{f.fill(1),a.fill(0),u=0},w=(...d)=>e(a,G(f,...d)),p=(d=o)=>{a=w(s,d),f=w(),d.length!==0&&(a=w(i,d),f=w())},y=()=>{if(u++>=c)throw new Error("drbg: tried max amount of iterations");let d=0,x=[];for(;d<t;){f=w();let S=f.slice();x.push(S),d+=f.length}return G(...x)};return(d,x)=>{h(),p(d);let S;for(;(S=x(y()))===void 0;)p();return h(),S}}function xt(r,t={},e={}){if(Object.prototype.toString.call(r)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,i,c){if(!c&&i!=="function"&&!Object.hasOwn(r,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let f=r[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(e,!0)}var Nn=()=>{throw new Error("not implemented")};var et=BigInt(0),V=BigInt(1),te=BigInt(2),Bs=BigInt(3),Is=BigInt(4),Ts=BigInt(5),ya=BigInt(7),Ls=BigInt(8),ga=BigInt(9),Ds=BigInt(16);function Y(r,t){if(t<=et)throw new Error("mod: expected positive modulus, got "+t);let e=r%t;return e>=et?e:t+e}function H(r,t,e){if(t<et)throw new Error("pow2: expected non-negative exponent, got "+t);let n=r;for(;t-- >et;)n*=n,n%=e;return n}function Ss(r,t){if(r===et)throw new Error("invert: expected non-zero number");if(t<=et)throw new Error("invert: expected positive modulus, got "+t);let e=Y(r,t),n=t,o=et,s=V,i=V,c=et;for(;e!==et;){let a=n/e,u=n-e*a,h=o-i*a,w=s-c*a;n=e,e=u,o=i,s=c,i=h,c=w}if(n!==V)throw new Error("invert: does not exist");return Y(o,t)}function Mn(r,t,e){let n=r;if(!n.eql(n.sqr(t),e))throw new Error("Cannot find square root")}function Cs(r,t){let e=r,n=(e.ORDER+V)/Is,o=e.pow(t,n);return Mn(e,o,t),o}function xa(r,t){let e=r,n=(e.ORDER-Ts)/Ls,o=e.mul(t,te),s=e.pow(o,n),i=e.mul(t,s),c=e.mul(e.mul(i,te),s),f=e.mul(i,e.sub(c,e.ONE));return Mn(e,f,t),f}function wa(r){let t=Ee(r),e=Rs(r),n=e(t,t.neg(t.ONE)),o=e(t,n),s=e(t,t.neg(n)),i=(r+ya)/Ds;return((c,f)=>{let a=c,u=a.pow(f,i),h=a.mul(u,n),w=a.mul(u,o),p=a.mul(u,s),y=a.eql(a.sqr(h),f),_=a.eql(a.sqr(w),f);u=a.cmov(u,h,y),h=a.cmov(p,w,_);let d=a.eql(a.sqr(h),f),x=a.cmov(u,h,d);return Mn(a,x,f),x})}function Rs(r){if(r<Bs)throw new Error("sqrt is not defined for small field");let t=r-V,e=0;for(;t%te===et;)t/=te,e++;let n=te,o=Ee(r);for(;vs(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(e===1)return Cs;let s=o.pow(n,t),i=(t+V)/te;return function(f,a){let u=f;if(u.is0(a))return a;if(vs(u,a)!==1)throw new Error("Cannot find square root");let h=e,w=u.mul(u.ONE,s),p=u.pow(a,t),y=u.pow(a,i);for(;!u.eql(p,u.ONE);){if(u.is0(p))return u.ZERO;let _=1,d=u.sqr(p);for(;!u.eql(d,u.ONE);)if(_++,d=u.sqr(d),_===h)throw new Error("Cannot find square root");let x=V<<BigInt(h-_-1),S=u.pow(w,x);h=_,w=u.sqr(S),p=u.mul(p,w),y=u.mul(y,S)}return y}}function Ea(r){return r%Is===Bs?Cs:r%Ls===Ts?xa:r%Ds===ga?wa(r):Rs(r)}var Rt=(r,t)=>(Y(r,t)&V)===V,_a=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Pn(r){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},e=_a.reduce((n,o)=>(n[o]="function",n),t);if(xt(r,e),gt(r.BYTES,"BYTES"),gt(r.BITS,"BITS"),r.BYTES<1||r.BITS<1)throw new Error("invalid field: expected BYTES/BITS > 0");if(r.ORDER<=V)throw new Error("invalid field: expected ORDER > 1, got "+r.ORDER);return r}function Sa(r,t,e){let n=r;if(e<et)throw new Error("invalid exponent, negatives unsupported");if(e===et)return n.ONE;if(e===V)return t;let o=n.ONE,s=t;for(;e>et;)e&V&&(o=n.mul(o,s)),s=n.sqr(s),e>>=V;return o}function Ve(r,t,e=!1){let n=r,o=new Array(t.length).fill(e?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 vs(r,t){let e=r,n=(e.ORDER-V)/te,o=e.pow(t,n),s=e.eql(o,e.ONE),i=e.eql(o,e.ZERO),c=e.eql(o,e.neg(e.ONE));if(!s&&!i&&!c)throw new Error("invalid Legendre symbol result");return s?1:i?0:-1}function va(r,t){if(t!==void 0&&kn(t),r<=et)throw new Error("invalid n length: expected positive n, got "+r);if(t!==void 0&&t<1)throw new Error("invalid n length: expected positive bit length, got "+t);let e=we(r);if(t!==void 0&&t<e)throw new Error(`invalid n length: expected bit length (${e}) >= n.length (${t})`);let n=t!==void 0?t:e,o=Math.ceil(n/8);return{nBitLength:n,nByteLength:o}}var As=new WeakMap,_r=class{ORDER;BITS;BYTES;isLE;ZERO=et;ONE=V;_lengths;_mod;constructor(t,e={}){if(t<=V)throw new Error("invalid field: expected ORDER > 1, got "+t);let n;this.isLE=!1,e!=null&&typeof e=="object"&&(typeof e.BITS=="number"&&(n=e.BITS),typeof e.sqrt=="function"&&Object.defineProperty(this,"sqrt",{value:e.sqrt,enumerable:!0}),typeof e.isLE=="boolean"&&(this.isLE=e.isLE),e.allowedLengths&&(this._lengths=Object.freeze(e.allowedLengths.slice())),typeof e.modFromBytes=="boolean"&&(this._mod=e.modFromBytes));let{nBitLength:o,nByteLength:s}=va(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 Y(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new TypeError("invalid field element: expected bigint, got "+typeof t);return et<=t&&t<this.ORDER}is0(t){return t===et}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&V)===V}neg(t){return Y(-t,this.ORDER)}eql(t,e){return t===e}sqr(t){return Y(t*t,this.ORDER)}add(t,e){return Y(t+e,this.ORDER)}sub(t,e){return Y(t-e,this.ORDER)}mul(t,e){return Y(t*e,this.ORDER)}pow(t,e){return Sa(this,t,e)}div(t,e){return Y(t*Ss(e,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,e){return t+e}subN(t,e){return t-e}mulN(t,e){return t*e}inv(t){return Ss(t,this.ORDER)}sqrt(t){let e=As.get(this);return e||As.set(this,e=Ea(this.ORDER)),e(this,t)}toBytes(t){return this.isLE?Kn(t,this.BYTES):wr(t,this.BYTES)}fromBytes(t,e=!1){M(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?vt(t):Qt(t);if(c&&(f=Y(f,i)),!e&&!this.isValid(f))throw new Error("invalid field element: outside of range 0..ORDER");return f}invertBatch(t){return Ve(this,t)}cmov(t,e,n){return yt(n,"condition"),n?e:t}};Object.freeze(_r.prototype);function Ee(r,t={}){return new _r(r,t)}function Fs(r){if(typeof r!="bigint")throw new Error("field order must be bigint");if(r<=V)throw new Error("field order must be greater than 1");let t=we(r-V);return Math.ceil(t/8)}function zn(r){let t=Fs(r);return t+Math.ceil(t/2)}function Hn(r,t,e=!1){M(r);let n=r.length,o=Fs(t),s=Math.max(zn(t),16);if(n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=e?vt(r):Qt(r),c=Y(i,t-V)+V;return e?Kn(c,o):wr(c,o)}var _e=BigInt(0),ee=BigInt(1);function je(r,t){let e=t.negate();return r?e:t}function re(r,t){let e=Ve(r.Fp,t.map(n=>n.Z));return t.map((n,o)=>r.fromAffine(n.toAffine(e[o])))}function Ks(r,t){if(!Number.isSafeInteger(r)||r<=0||r>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+r)}function qn(r,t){Ks(r,t);let e=Math.ceil(t/r)+1,n=2**(r-1),o=2**r,s=qe(r),i=BigInt(r);return{windows:e,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Os(r,t,e){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=e,c=Number(r&o),f=r>>i;c>n&&(c-=s,f+=ee);let a=t*n,u=a+Math.abs(c)-1,h=c===0,w=c<0,p=t%2!==0;return{nextN:f,offset:u,isZero:h,isNeg:w,isNegF:p,offsetF:a}}var Vn=new WeakMap,Ns=new WeakMap;function jn(r){return Ns.get(r)||1}function Us(r){if(r!==_e)throw new Error("invalid wNAF")}var Se=class{BASE;ZERO;Fn;bits;constructor(t,e){this.BASE=t.BASE,this.ZERO=t.ZERO,this.Fn=t.Fn,this.bits=e}_unsafeLadder(t,e,n=this.ZERO){let o=t;for(;e>_e;)e&ee&&(n=n.add(o)),o=o.double(),e>>=ee;return n}precomputeWindow(t,e){let{windows:n,windowSize:o}=qn(e,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,e,n){if(!this.Fn.isValid(n))throw new Error("invalid scalar");let o=this.ZERO,s=this.BASE,i=qn(t,this.bits);for(let c=0;c<i.windows;c++){let{nextN:f,offset:a,isZero:u,isNeg:h,isNegF:w,offsetF:p}=Os(n,c,i);n=f,u?s=s.add(je(w,e[p])):o=o.add(je(h,e[a]))}return Us(n),{p:o,f:s}}wNAFUnsafe(t,e,n,o=this.ZERO){let s=qn(t,this.bits);for(let i=0;i<s.windows&&n!==_e;i++){let{nextN:c,offset:f,isZero:a,isNeg:u}=Os(n,i,s);if(n=c,!a){let h=e[f];o=o.add(u?h.negate():h)}}return Us(n),o}getPrecomputes(t,e,n){let o=Vn.get(e);return o||(o=this.precomputeWindow(e,t),t!==1&&(typeof n=="function"&&(o=n(o)),Vn.set(e,o))),o}cached(t,e,n){let o=jn(t);return this.wNAF(o,this.getPrecomputes(o,t,n),e)}unsafe(t,e,n,o){let s=jn(t);return s===1?this._unsafeLadder(t,e,o):this.wNAFUnsafe(s,this.getPrecomputes(s,t,n),e,o)}createCache(t,e){Ks(e,this.bits),Ns.set(t,e),Vn.delete(t)}hasCache(t){return jn(t)!==1}};function Ms(r,t,e,n){let o=t,s=r.ZERO,i=r.ZERO;for(;e>_e||n>_e;)e&ee&&(s=s.add(o)),n&ee&&(i=i.add(o)),o=o.double(),e>>=ee,n>>=ee;return{p1:s,p2:i}}function ks(r,t,e){if(t){if(t.ORDER!==r)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Pn(t),t}else return Ee(r,{isLE:e})}function Sr(r,t,e={},n){if(n===void 0&&(n=r==="edwards"),!t||typeof t!="object")throw new Error(`expected valid ${r} CURVE object`);for(let f of["p","n","h"]){let a=t[f];if(!(typeof a=="bigint"&&a>_e))throw new Error(`CURVE.${f} must be positive bigint`)}let o=ks(t.p,e.Fp,n),s=ks(t.n,e.Fn,n),c=["Gx","Gy","a",r==="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 vr(r,t){return function(n){let o=r(n);return{secretKey:o,publicKey:t(o)}}}var Mt=BigInt(0),Q=BigInt(1),Zn=BigInt(2),Aa=BigInt(8);function Ba(r,t,e,n){let o=r.sqr(e),s=r.sqr(n),i=r.add(r.mul(t.a,o),s),c=r.add(r.ONE,r.mul(t.d,r.mul(o,s)));return r.eql(i,c)}function Ps(r,t={}){let e=t,n=Sr("edwards",r,e,e.FpFnLE),{Fp:o,Fn:s}=n,i=n.CURVE,{h:c}=i;xt(e,{},{uvRatio:"function"});let f=Zn<<BigInt(s.BYTES*8)-Q,a=_=>o.create(_),u=e.uvRatio===void 0?(_,d)=>{try{return{isValid:!0,value:o.sqrt(o.div(_,d))}}catch{return{isValid:!1,value:Mt}}}:e.uvRatio;if(!Ba(o,i,i.Gx,i.Gy))throw new Error("bad curve params: generator point");function h(_,d,x=!1){let S=x?Q:Mt;return xe("coordinate "+_,d,S,f),d}function w(_){if(!(_ instanceof p))throw new Error("EdwardsPoint expected")}class p{static BASE=new p(i.Gx,i.Gy,Q,a(i.Gx*i.Gy));static ZERO=new p(Mt,Q,Q,Mt);static Fp=o;static Fn=s;X;Y;Z;T;constructor(d,x,S,A){this.X=h("x",d),this.Y=h("y",x),this.Z=h("z",S,!0),this.T=h("t",A),Object.freeze(this)}static CURVE(){return i}static fromAffine(d){if(d instanceof p)throw new Error("extended point not allowed");let{x,y:S}=d||{};return h("x",x),h("y",S),new p(x,S,Q,a(x*S))}static fromBytes(d,x=!1){let S=o.BYTES,{a:A,d:C}=i;d=He(M(d,S,"point")),yt(x,"zip215");let L=He(d),O=d[S-1];L[S-1]=O&-129;let R=vt(L),I=x?f:o.ORDER;xe("point.y",R,Mt,I);let U=a(R*R),z=a(U-Q),k=a(C*U-A),{isValid:l,value:m}=u(z,k);if(!l)throw new Error("bad point: invalid y coordinate");let E=(m&Q)===Q,g=(O&128)!==0;if(!x&&m===Mt&&g)throw new Error("bad point: x=0 and x_0=1");return g!==E&&(m=a(-m)),p.fromAffine({x:m,y:R})}static fromHex(d,x=!1){return p.fromBytes(ge(d),x)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(d=8,x=!0){return y.createCache(this,d),x||this.multiply(Zn),this}assertValidity(){let d=this,{a:x,d:S}=i;if(d.is0())throw new Error("bad point: ZERO");let{X:A,Y:C,Z:L,T:O}=d,R=a(A*A),I=a(C*C),U=a(L*L),z=a(U*U),k=a(R*x),l=a(U*a(k+I)),m=a(z+a(S*a(R*I)));if(l!==m)throw new Error("bad point: equation left != right (1)");let E=a(A*C),g=a(L*O);if(E!==g)throw new Error("bad point: equation left != right (2)")}equals(d){w(d);let{X:x,Y:S,Z:A}=this,{X:C,Y:L,Z:O}=d,R=a(x*O),I=a(C*A),U=a(S*O),z=a(L*A);return R===I&&U===z}is0(){return this.equals(p.ZERO)}negate(){return new p(a(-this.X),this.Y,this.Z,a(-this.T))}double(){let{a:d}=i,{X:x,Y:S,Z:A}=this,C=a(x*x),L=a(S*S),O=a(Zn*a(A*A)),R=a(d*C),I=x+S,U=a(a(I*I)-C-L),z=R+L,k=z-O,l=R-L,m=a(U*k),E=a(z*l),g=a(U*l),b=a(k*z);return new p(m,E,b,g)}add(d){w(d);let{a:x,d:S}=i,{X:A,Y:C,Z:L,T:O}=this,{X:R,Y:I,Z:U,T:z}=d,k=a(A*R),l=a(C*I),m=a(O*S*z),E=a(L*U),g=a((A+C)*(R+I)-k-l),b=E-m,v=E+m,T=a(l-x*k),B=a(g*b),D=a(v*T),F=a(g*T),N=a(b*v);return new p(B,D,N,F)}subtract(d){return w(d),this.add(d.negate())}multiply(d){if(!s.isValidNot0(d))throw new RangeError("invalid scalar: expected 1 <= sc < curve.n");let{p:x,f:S}=y.cached(this,d,A=>re(p,A));return re(p,[x,S])[0]}multiplyUnsafe(d){if(!s.isValid(d))throw new RangeError("invalid scalar: expected 0 <= sc < curve.n");return d===Mt?p.ZERO:this.is0()||d===Q?this:y.unsafe(this,d,x=>re(p,x))}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return y.unsafe(this,i.n).is0()}toAffine(d){let x=this,S=d,{X:A,Y:C,Z:L}=x,O=x.is0();S==null&&(S=O?Aa:o.inv(L));let R=a(A*S),I=a(C*S),U=o.mul(L,S);if(O)return{x:Mt,y:Q};if(U!==Q)throw new Error("invZ was invalid");return{x:R,y:I}}clearCofactor(){return c===Q?this:this.multiplyUnsafe(c)}toBytes(){let{x:d,y:x}=this.toAffine(),S=o.toBytes(x);return S[S.length-1]|=d&Q?128:0,S}toHex(){return ye(this.toBytes())}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let y=new Se(p,s.BITS);return s.BITS>=8&&p.BASE.precompute(8),Object.freeze(p.prototype),Object.freeze(p),p}var Ar=class{static BASE;static ZERO;static Fp;static Fn;ep;constructor(t){this.ep=t}static fromBytes(t){Nn()}static fromHex(t){Nn()}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 ye(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,e){return this.ep.precompute(t,e),this}};function zs(r,t,e={}){if(typeof t!="function")throw new Error('"hash" function param is required');let n=t,o=e;xt(o,{},{adjustScalarBytes:"function",randomBytes:"function",domain:"function",prehash:"function",zip215:"boolean",mapToCurve:"function"});let{prehash:s}=o,{BASE:i,Fp:c,Fn:f}=r,a=n.outputLen,u=2*c.BYTES;if(a!==void 0&&(gt(a,"hash.outputLen"),a!==u))throw new Error(`hash.outputLen must be ${u}, got ${a}`);let h=o.randomBytes===void 0?Pe:o.randomBytes,w=o.adjustScalarBytes===void 0?l=>l:o.adjustScalarBytes,p=o.domain===void 0?(l,m,E)=>{if(yt(E,"phflag"),m.length||E)throw new Error("Contexts/pre-hash are not supported");return l}:o.domain;function y(l){return f.create(vt(l))}function _(l){let m=R.secretKey;M(l,R.secretKey,"secretKey");let E=M(n(l),2*m,"hashedSecretKey"),g=w(E.slice(0,m)),b=E.slice(m,2*m),v=y(g);return{head:g,prefix:b,scalar:v}}function d(l){let{head:m,prefix:E,scalar:g}=_(l),b=i.multiply(g),v=b.toBytes();return{head:m,prefix:E,scalar:g,point:b,pointBytes:v}}function x(l){return d(l).pointBytes}function S(l=Uint8Array.of(),...m){let E=G(...m);return y(n(p(E,M(l,void 0,"context"),!!s)))}function A(l,m,E={}){l=M(l,void 0,"message"),s&&(l=s(l));let{prefix:g,scalar:b,pointBytes:v}=d(m),T=S(E.context,g,l),B=i.multiply(T).toBytes(),D=S(E.context,B,v,l),F=f.create(T+D*b);if(!f.isValid(F))throw new Error("sign failed: invalid s");let N=G(B,f.toBytes(F));return M(N,R.signature,"result")}let C={zip215:o.zip215};function L(l,m,E,g=C){let{context:b}=g,v=g.zip215===void 0?!!C.zip215:g.zip215,T=R.signature;l=M(l,T,"signature"),m=M(m,void 0,"message"),E=M(E,R.publicKey,"publicKey"),v!==void 0&&yt(v,"zip215"),s&&(m=s(m));let B=T/2,D=l.subarray(0,B),F=vt(l.subarray(B,T)),N,P,K;try{N=r.fromBytes(E,v),P=r.fromBytes(D,v),K=i.multiplyUnsafe(F)}catch{return!1}if(!v&&N.isSmallOrder())return!1;let $=S(b,D,E,m);return P.add(N.multiplyUnsafe($)).subtract(K).clearCofactor().is0()}let O=c.BYTES,R={secretKey:O,publicKey:O,signature:2*O,seed:O};function I(l){return l=l===void 0?h(R.seed):l,M(l,R.seed,"seed")}function U(l){return Jt(l)&&l.length===R.secretKey}function z(l,m){try{return!!r.fromBytes(l,m===void 0?C.zip215:m)}catch{return!1}}let k={getExtendedPublicKey:d,randomSecretKey:I,isValidSecretKey:U,isValidPublicKey:z,toMontgomery(l){let{y:m}=r.fromBytes(l),E=R.publicKey,g=E===32;if(!g&&E!==57)throw new Error("only defined for 25519 and 448");let b=g?c.div(Q+m,Q-m):c.div(m-Q,m+Q);return c.toBytes(b)},toMontgomerySecret(l){let m=R.secretKey;M(l,m);let E=n(l.subarray(0,m));return w(E).subarray(0,m)}};return Object.freeze(R),Object.freeze(k),Object.freeze({keygen:vr(I,x),getPublicKey:x,sign:A,verify:L,utils:k,Point:r,lengths:R})}function Ze(r,t){if(gt(r),gt(t),t<0||t>4)throw new Error("invalid I2OSP length: "+t);if(r<0||r>2**(8*t)-1)throw new Error("invalid I2OSP input: "+r);let e=Array.from({length:t}).fill(0);for(let n=t-1;n>=0;n--)e[n]=r&255,r>>>=8;return new Uint8Array(e)}function Ia(r,t){let e=new Uint8Array(r.length);for(let n=0;n<r.length;n++)e[n]=r[n]^t[n];return e}function Ta(r){if(!Jt(r)&&typeof r!="string")throw new Error("DST must be Uint8Array or ascii string");let t=typeof r=="string"?Er(r):r;if(t.length===0)throw new Error("DST must be non-empty");return t}function Yn(r,t,e,n){M(r),gt(e),t=Ta(t),t.length>255&&(t=n(G(Er("H2C-OVERSIZE-DST-"),t)));let{outputLen:o,blockLen:s}=n,i=Math.ceil(e/o);if(e>65535||i>255)throw new Error("expand_message_xmd: invalid lenInBytes");let c=G(t,Ze(t.length,1)),f=new Uint8Array(s),a=Ze(e,2),u=new Array(i),h=n(G(f,r,a,Ze(0,1),c));u[0]=n(G(h,Ze(1,1),c));for(let p=1;p<i;p++){let y=[Ia(h,u[p-1]),Ze(p+1,1),c];u[p]=n(G(...y))}return G(...u).slice(0,e)}var Hs="HashToScalar-";var La=BigInt(0),Ft=BigInt(1),qs=BigInt(2);var Da=BigInt(5),Ca=BigInt(8),ve=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed"),Wn={p:ve,n:BigInt("0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed"),h:Ca,a:BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec"),d:BigInt("0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3"),Gx:BigInt("0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a"),Gy:BigInt("0x6666666666666666666666666666666666666666666666666666666666666658")};function Ra(r){let t=BigInt(10),e=BigInt(20),n=BigInt(40),o=BigInt(80),s=ve,c=r*r%s*r%s,f=H(c,qs,s)*c%s,a=H(f,Ft,s)*r%s,u=H(a,Da,s)*a%s,h=H(u,t,s)*u%s,w=H(h,e,s)*h%s,p=H(w,n,s)*w%s,y=H(p,o,s)*p%s,_=H(y,o,s)*p%s,d=H(_,t,s)*u%s;return{pow_p_5_8:H(d,qs,s)*r%s,b2:c}}function Fa(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}var $n=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752");function Jn(r,t){let e=ve,n=Y(t*t*t,e),o=Y(n*n*t,e),s=Ra(r*o).pow_p_5_8,i=Y(r*n*s,e),c=Y(t*i*i,e),f=i,a=Y(i*$n,e),u=c===r,h=c===Y(-r,e),w=c===Y(-r*$n,e);return u&&(i=f),(h||w)&&(i=a),Rt(i,e)&&(i=Y(-i,e)),{isValid:u||h,value:i}}var zt=Ps(Wn,{uvRatio:Jn}),Pt=zt.Fp,Zs=zt.Fn;function Oa(r){return zs(zt,br,Object.assign({adjustScalarBytes:Fa,zip215:!0},r))}var Ys=Oa({});var Gn=$n,Ua=BigInt("25063068953384623474111414158702152701244531502492656460079210482610430750235"),ka=BigInt("54469307008909316920995813868745141605393597292927456921205312896311721017578"),Ka=BigInt("1159843021668779879193775521855586647937357759715417654439879720876111806838"),Na=BigInt("40440834346308536858101042469323190826248399146238708352240133220865137265952"),Vs=r=>Jn(Ft,r),Ma=BigInt("0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"),Xn=r=>Pt.create(vt(r)&Ma);function js(r){let{d:t}=Wn,e=ve,n=x=>Pt.create(x),o=n(Gn*r*r),s=n((o+Ft)*Ka),i=BigInt(-1),c=n((i-t*o)*n(o+t)),{isValid:f,value:a}=Jn(s,c),u=n(a*r);Rt(u,e)||(u=n(-u)),f||(a=u),f||(i=o);let h=n(i*(o-Ft)*Na-c),w=a*a,p=n((a+a)*c),y=n(h*Ua),_=n(Ft-w),d=n(Ft+w);return new zt(n(p*d),n(_*y),n(y*d),n(p*_))}var Ht=class r extends Ar{static BASE=new r(zt.BASE);static ZERO=new r(zt.ZERO);static Fp=Pt;static Fn=Zs;constructor(t){super(t)}static fromAffine(t){return new r(zt.fromAffine(t))}assertSame(t){if(!(t instanceof r))throw new Error("RistrettoPoint expected")}init(t){return new r(t)}static fromBytes(t){ht(t,32);let{a:e,d:n}=Wn,o=ve,s=C=>Pt.create(C),i=Xn(t);if(!Es(Pt.toBytes(i),t)||Rt(i,o))throw new Error("invalid ristretto255 encoding 1");let c=s(i*i),f=s(Ft+e*c),a=s(Ft-e*c),u=s(f*f),h=s(a*a),w=s(e*n*u-h),{isValid:p,value:y}=Vs(s(w*h)),_=s(y*a),d=s(y*_*w),x=s((i+i)*_);Rt(x,o)&&(x=s(-x));let S=s(f*d),A=s(x*S);if(!p||Rt(A,o)||S===La)throw new Error("invalid ristretto255 encoding 2");return new r(new zt(x,S,Ft,A))}static fromHex(t){return r.fromBytes(ke(t))}toBytes(){let{X:t,Y:e,Z:n,T:o}=this.ep,s=ve,i=d=>Pt.create(d),c=i(i(n+e)*i(n-e)),f=i(t*e),a=i(f*f),{value:u}=Vs(i(c*a)),h=i(u*c),w=i(u*f),p=i(h*w*o),y;if(Rt(o*p,s)){let d=i(e*Gn),x=i(t*Gn);t=d,e=x,y=i(h*ka)}else y=w;Rt(t*p,s)&&(e=i(-e));let _=i((n-e)*y);return Rt(_,s)&&(_=i(-_)),Pt.toBytes(_)}equals(t){this.assertSame(t);let{X:e,Y:n}=this.ep,{X:o,Y:s}=t.ep,i=a=>Pt.create(a),c=i(e*s)===i(n*o),f=i(n*s)===i(e*o);return c||f}is0(){return this.equals(r.ZERO)}};Object.freeze(Ht.BASE);Object.freeze(Ht.ZERO);Object.freeze(Ht.prototype);Object.freeze(Ht);var Pa=Object.freeze({Point:Ht,hashToCurve(r,t){let e=t?.DST===void 0?"ristretto255_XMD:SHA-512_R255MAP_RO_":t.DST,n=Yn(r,e,64,br);return Pa.deriveToCurve(n)},hashToScalar(r,t={DST:Hs}){let e=Yn(r,t.DST,64,br);return Zs.create(vt(e))},deriveToCurve(r){ht(r,64);let t=Xn(r.subarray(0,32)),e=js(t),n=Xn(r.subarray(32,64)),o=js(n);return new Ht(e.add(o))}});var Ye=class extends Error{constructor(t="An error occurred while verifying a message"){super(t),this.name="VerificationError"}},Br=class extends Error{constructor(t="Missing Web Crypto API"){super(t),this.name="WebCryptoMissingError"}};var $s={get(r=globalThis){let t=r.crypto;if(t?.subtle==null)throw new Br("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 Ir=$s;var Tr=32;var Qn,za=(async()=>{try{return await Ir.get().subtle.generateKey({name:"Ed25519"},!0,["sign","verify"]),!0}catch{return!1}})();async function Ha(r,t,e){if(r.buffer instanceof ArrayBuffer){let n=await Ir.get().subtle.importKey("raw",r.buffer,{name:"Ed25519"},!1,["verify"]);return await Ir.get().subtle.verify({name:"Ed25519"},n,t,e instanceof Uint8Array?e:e.subarray())}throw new TypeError("WebCrypto does not support SharedArrayBuffer for Ed25519 keys")}function qa(r,t,e){return Ys.verify(t,e instanceof Uint8Array?e:e.subarray(),r)}async function Gs(r,t,e){return Qn==null&&(Qn=await za),Qn?Ha(r,t,e):qa(r,t,e)}function Lr(r){return r==null?!1:typeof r.then=="function"&&typeof r.catch=="function"&&typeof r.finally=="function"}var Dr=class{type="Ed25519";raw;constructor(t){this.raw=to(t,Tr)}toMultihash(){return pt.digest(me(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}verify(t,e,n){n?.signal?.throwIfAborted();let o=Gs(this.raw,e,t);return Lr(o)?o.then(s=>(n?.signal?.throwIfAborted(),s)):o}};function Ws(r){return r=to(r,Tr),new Dr(r)}function to(r,t){if(r=Uint8Array.from(r??[]),r.length!==t)throw new It(`Key must be a Uint8Array of length ${t}, got ${r.length}`);return r}var ja=Math.pow(2,7),Za=Math.pow(2,14),Ya=Math.pow(2,21),Js=Math.pow(2,28),Qs=Math.pow(2,35),ti=Math.pow(2,42),ei=Math.pow(2,49),nt=128,qt=127;function $e(r){if(r<ja)return 1;if(r<Za)return 2;if(r<Ya)return 3;if(r<Js)return 4;if(r<Qs)return 5;if(r<ti)return 6;if(r<ei)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function ri(r,t,e=0){switch($e(r)){case 8:t[e++]=r&255|nt,r/=128;case 7:t[e++]=r&255|nt,r/=128;case 6:t[e++]=r&255|nt,r/=128;case 5:t[e++]=r&255|nt,r/=128;case 4:t[e++]=r&255|nt,r>>>=7;case 3:t[e++]=r&255|nt,r>>>=7;case 2:t[e++]=r&255|nt,r>>>=7;case 1:{t[e++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return t}function ni(r,t){let e=r[t],n=0;if(n+=e&qt,e<nt||(e=r[t+1],n+=(e&qt)<<7,e<nt)||(e=r[t+2],n+=(e&qt)<<14,e<nt)||(e=r[t+3],n+=(e&qt)<<21,e<nt)||(e=r[t+4],n+=(e&qt)*Js,e<nt)||(e=r[t+5],n+=(e&qt)*Qs,e<nt)||(e=r[t+6],n+=(e&qt)*ti,e<nt)||(e=r[t+7],n+=(e&qt)*ei,e<nt))return n;throw new RangeError("Could not decode varint")}var eo=new Float32Array([-0]),Vt=new Uint8Array(eo.buffer);function oi(r,t,e){eo[0]=r,t[e]=Vt[0],t[e+1]=Vt[1],t[e+2]=Vt[2],t[e+3]=Vt[3]}function si(r,t){return Vt[0]=r[t],Vt[1]=r[t+1],Vt[2]=r[t+2],Vt[3]=r[t+3],eo[0]}var ro=new Float64Array([-0]),rt=new Uint8Array(ro.buffer);function ii(r,t,e){ro[0]=r,t[e]=rt[0],t[e+1]=rt[1],t[e+2]=rt[2],t[e+3]=rt[3],t[e+4]=rt[4],t[e+5]=rt[5],t[e+6]=rt[6],t[e+7]=rt[7]}function ci(r,t){return rt[0]=r[t],rt[1]=r[t+1],rt[2]=r[t+2],rt[3]=r[t+3],rt[4]=r[t+4],rt[5]=r[t+5],rt[6]=r[t+6],rt[7]=r[t+7],ro[0]}var $a=BigInt(Number.MAX_SAFE_INTEGER),Ga=BigInt(Number.MIN_SAFE_INTEGER),lt=class r{lo;hi;constructor(t,e){this.lo=t|0,this.hi=e|0}toNumber(t=!1){if(!t&&this.hi>>>31>0){let e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(e+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 e=~this.lo+1>>>0,n=~this.hi>>>0;return e===0&&(n=n+1>>>0),-(BigInt(e)+(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,e=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?e===0?t<16384?t<128?1:2:t<2097152?3:4:e<16384?e<128?5:6:e<2097152?7:8:n<128?9:10}static fromBigInt(t){if(t===0n)return ne;if(t<$a&&t>Ga)return this.fromNumber(Number(t));let e=t<0n;e&&(t=-t);let n=t>>32n,o=t-(n<<32n);return e&&(n=~n|0n,o=~o|0n,++o>ai&&(o=0n,++n>ai&&(n=0n))),new r(Number(o),Number(n))}static fromNumber(t){if(t===0)return ne;let e=t<0;e&&(t=-t);let n=t>>>0,o=(t-n)/4294967296>>>0;return e&&(o=~o>>>0,n=~n>>>0,++n>4294967295&&(n=0,++o>4294967295&&(o=0))),new r(n,o)}static from(t){return typeof t=="number"?r.fromNumber(t):typeof t=="bigint"?r.fromBigInt(t):typeof t=="string"?r.fromBigInt(BigInt(t)):t.low!=null||t.high!=null?new r(t.low>>>0,t.high>>>0):ne}},ne=new lt(0,0);ne.toBigInt=function(){return 0n};ne.zzEncode=ne.zzDecode=function(){return this};ne.length=function(){return 1};var ai=4294967296n;function fi(r){let t=0,e=0;for(let n=0;n<r.length;++n)e=r.charCodeAt(n),e<128?t+=1:e<2048?t+=2:(e&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,t+=4):t+=3;return t}function ui(r,t,e){if(e-t<1)return"";let o,s=[],i=0,c;for(;t<e;)c=r[t++],c<128?s[i++]=c:c>191&&c<224?s[i++]=(c&31)<<6|r[t++]&63:c>239&&c<365?(c=((c&7)<<18|(r[t++]&63)<<12|(r[t++]&63)<<6|r[t++]&63)-65536,s[i++]=55296+(c>>10),s[i++]=56320+(c&1023)):s[i++]=(c&15)<<12|(r[t++]&63)<<6|r[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 no(r,t,e){let n=e,o,s;for(let i=0;i<r.length;++i)o=r.charCodeAt(i),o<128?t[e++]=o:o<2048?(t[e++]=o>>6|192,t[e++]=o&63|128):(o&64512)===55296&&((s=r.charCodeAt(i+1))&64512)===56320?(o=65536+((o&1023)<<10)+(s&1023),++i,t[e++]=o>>18|240,t[e++]=o>>12&63|128,t[e++]=o>>6&63|128,t[e++]=o&63|128):(t[e++]=o>>12|224,t[e++]=o>>6&63|128,t[e++]=o&63|128);return e-n}function wt(r,t){return RangeError(`index out of range: ${r.pos} + ${t??1} > ${r.len}`)}function Cr(r,t){return(r[t-4]|r[t-3]<<8|r[t-2]<<16|r[t-1]<<24)>>>0}var oo=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,wt(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 wt(this,4);return Cr(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw wt(this,4);return Cr(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw wt(this,4);let t=si(this.buf,this.pos);return this.pos+=4,t}double(){if(this.pos+8>this.len)throw wt(this,4);let t=ci(this.buf,this.pos);return this.pos+=8,t}bytes(){let t=this.uint32(),e=this.pos,n=this.pos+t;if(n>this.len)throw wt(this,t);return this.pos+=t,e===n?new Uint8Array(0):this.buf.subarray(e,n)}string(){let t=this.bytes();return ui(t,0,t.length)}skip(t){if(typeof t=="number"){if(this.pos+t>this.len)throw wt(this,t);this.pos+=t}else do if(this.pos>=this.len)throw wt(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 lt(0,0),e=0;if(this.len-this.pos>4){for(;e<4;++e)if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*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;e=0}else{for(;e<3;++e){if(this.pos>=this.len)throw wt(this);if(t.lo=(t.lo|(this.buf[this.pos]&127)<<e*7)>>>0,this.buf[this.pos++]<128)return t}return t.lo=(t.lo|(this.buf[this.pos++]&127)<<e*7)>>>0,t}if(this.len-this.pos>4){for(;e<5;++e)if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}else for(;e<5;++e){if(this.pos>=this.len)throw wt(this);if(t.hi=(t.hi|(this.buf[this.pos]&127)<<e*7+3)>>>0,this.buf[this.pos++]<128)return t}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw wt(this,8);let t=Cr(this.buf,this.pos+=4),e=Cr(this.buf,this.pos+=4);return new lt(t,e)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let t=ni(this.buf,this.pos);return this.pos+=$e(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 Ge(r){return new oo(r instanceof Uint8Array?r:r.subarray())}function Rr(r,t,e){let n=Ge(r);return t.decode(n,void 0,e)}function so(r){let t=r??8192,e=t>>>1,n,o=t;return function(i){if(i<1||i>e)return ft(i);o+i>t&&(n=ft(t),o=0);let c=n.subarray(o,o+=i);return(o&7)!==0&&(o=(o|7)+1),c}}var oe=class{fn;len;next;val;constructor(t,e,n){this.fn=t,this.len=e,this.next=void 0,this.val=n}};function io(){}var ao=class{head;tail;len;next;constructor(t){this.head=t.head,this.tail=t.tail,this.len=t.len,this.next=t.states}},Xa=so();function Wa(r){return globalThis.Buffer!=null?ft(r):Xa(r)}var We=class{len;head;tail;states;constructor(){this.len=0,this.head=new oe(io,0,0),this.tail=this.head,this.states=null}_push(t,e,n){return this.tail=this.tail.next=new oe(t,e,n),this.len+=e,this}uint32(t){return this.len+=(this.tail=this.tail.next=new fo((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(Fr,10,lt.fromNumber(t)):this.uint32(t)}sint32(t){return this.uint32((t<<1^t>>31)>>>0)}uint64(t){let e=lt.fromBigInt(t);return this._push(Fr,e.length(),e)}uint64Number(t){return this._push(ri,$e(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 e=lt.fromBigInt(t).zzEncode();return this._push(Fr,e.length(),e)}sint64Number(t){let e=lt.fromNumber(t).zzEncode();return this._push(Fr,e.length(),e)}sint64String(t){return this.sint64(BigInt(t))}bool(t){return this._push(co,1,t?1:0)}fixed32(t){return this._push(Xe,4,t>>>0)}sfixed32(t){return this.fixed32(t)}fixed64(t){let e=lt.fromBigInt(t);return this._push(Xe,4,e.lo)._push(Xe,4,e.hi)}fixed64Number(t){let e=lt.fromNumber(t);return this._push(Xe,4,e.lo)._push(Xe,4,e.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(oi,4,t)}double(t){return this._push(ii,8,t)}bytes(t){let e=t.length>>>0;return e===0?this._push(co,1,0):this.uint32(e)._push(Qa,e,t)}string(t){let e=fi(t);return e!==0?this.uint32(e)._push(no,e,t):this._push(co,1,0)}fork(){return this.states=new ao(this),this.head=this.tail=new oe(io,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 oe(io,0,0),this.len=0),this}ldelim(){let t=this.head,e=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=t.next,this.tail=e,this.len+=n),this}finish(){let t=this.head.next,e=Wa(this.len),n=0;for(;t!=null;)t.fn(t.val,e,n),n+=t.len,t=t.next;return e}};function co(r,t,e){t[e]=r&255}function Ja(r,t,e){for(;r>127;)t[e++]=r&127|128,r>>>=7;t[e]=r}var fo=class extends oe{next;constructor(t,e){super(Ja,t,e),this.next=void 0}};function Fr(r,t,e){for(;r.hi!==0;)t[e++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)t[e++]=r.lo&127|128,r.lo=r.lo>>>7;t[e++]=r.lo}function Xe(r,t,e){t[e]=r&255,t[e+1]=r>>>8&255,t[e+2]=r>>>16&255,t[e+3]=r>>>24}function Qa(r,t,e){t.set(r,e)}globalThis.Buffer!=null&&(We.prototype.bytes=function(r){let t=r.length>>>0;return this.uint32(t),t>0&&this._push(tf,t,r),this},We.prototype.string=function(r){let t=globalThis.Buffer.byteLength(r);return this.uint32(t),t>0&&this._push(ef,t,r),this});function tf(r,t,e){t.set(r,e)}function ef(r,t,e){r.length<40?no(r,t,e):t.utf8Write!=null?t.utf8Write(r,e):t.set(J(r),e)}function uo(){return new We}function Or(r,t){let e=uo();return t.encode(r,e,{lengthDelimited:!1}),e.finish()}function*Ur(r,t,e){let n=Ge(r);yield*t.stream(n,void 0,"$",e)}var kr={VARINT:0,BIT64:1,LENGTH_DELIMITED:2,START_GROUP:3,END_GROUP:4,BIT32:5};function Kr(r,t,e,n,o){return{name:r,type:t,encode:e,decode:n,stream:o}}function ho(r){function t(s){if(r[s.toString()]==null)throw new Error("Invalid enum value");return r[s]}let e=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 Kr("enum",kr.VARINT,e,n,o)}function Nr(r,t,e){return Kr("message",kr.LENGTH_DELIMITED,r,t,e)}var ot;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1",r.ECDSA="ECDSA"})(ot||(ot={}));var lo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1",r[r.ECDSA=3]="ECDSA"})(lo||(lo={}));(function(r){r.codec=()=>ho(lo)})(ot||(ot={}));var Je;(function(r){let t;r.codec=()=>(t==null&&(t=Nr((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ot.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=ot.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:ot.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function e(s){return Or(s,r.codec())}r.encode=e;function n(s,i){return Rr(s,r.codec(),i)}r.decode=n;function o(s,i){return Ur(s,r.codec(),i)}r.stream=o})(Je||(Je={}));var po;(function(r){let t;r.codec=()=>(t==null&&(t=Nr((s,i,c={})=>{c.lengthDelimited!==!1&&i.fork(),s.Type!=null&&(i.uint32(8),ot.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=ot.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:ot.codec().decode(s)};break}case 2:{yield{field:`${c}.Data`,value:s.bytes()};break}default:{s.skipType(u&7);break}}}})),t);function e(s){return Or(s,r.codec())}r.encode=e;function n(s,i){return Rr(s,r.codec(),i)}r.decode=n;function o(s,i){return Ur(s,r.codec(),i)}r.stream=o})(po||(po={}));var Mr=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(t,e){if(hr(t),ht(e,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(e.length>n?t.create().update(e).digest():e);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),Dt(o)}update(t){return be(this),this.iHash.update(t),this}digestInto(t){be(this),lr(t,this),this.finished=!0;let e=t.subarray(0,this.outputLen);this.iHash.digestInto(e),this.oHash.update(e),this.oHash.digestInto(e),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:e,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=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},li=(()=>{let r=((t,e,n)=>new Mr(t,e).update(n).digest());return r.create=(t,e)=>new Mr(t,e),r})();var di=(r,t)=>(r+(r>=0?t:-t)/pi)/t;function nf(r,t,e){xe("scalar",r,At,e);let[[n,o],[s,i]]=t,c=di(i*r,e),f=di(-o*r,e),a=r-c*n-f*s,u=-c*o-f*i,h=a<At,w=u<At;h&&(a=-a),w&&(u=-u);let p=qe(Math.ceil(we(e)/2))+jt;if(a<At||a>=p||u<At||u>=p)throw new Error("splitScalar (endomorphism): failed for k");return{k1neg:h,k1:a,k2neg:w,k2:u}}function bo(r){if(!["compact","recovered","der"].includes(r))throw new Error('Signature format must be "compact", "recovered", or "der"');return r}function mo(r,t){xt(r);let e={};for(let n of Object.keys(t))e[n]=r[n]===void 0?t[n]:r[n];return yt(e.lowS,"lowS"),yt(e.prehash,"prehash"),e.format!==void 0&&bo(e.format),e}var yo=class extends Error{constructor(t=""){super(t)}},Et={Err:yo,_tlv:{encode:(r,t)=>{let{Err:e}=Et;if(gt(r,"tag"),r<0||r>255)throw new e("tlv.encode: wrong tag");if(typeof t!="string")throw new TypeError('"data" expected string, got type='+typeof t);if(t.length&1)throw new e("tlv.encode: unpadded data");let n=t.length/2,o=ze(n);if(o.length/2&128)throw new e("tlv.encode: long form length too big");let s=n>127?ze(o.length/2|128):"";return ze(r)+s+o+t},decode(r,t){let{Err:e}=Et;t=M(t,void 0,"DER data");let n=0;if(r<0||r>255)throw new e("tlv.encode: wrong tag");if(t.length<2||t[n++]!==r)throw new e("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 e("tlv.decode(long): indefinite length not supported");if(f>4)throw new e("tlv.decode(long): byte length is too big");let a=t.subarray(n,n+f);if(a.length!==f)throw new e("tlv.decode: length bytes not complete");if(a[0]===0)throw new e("tlv.decode(long): zero leftmost byte");for(let u of a)i=i<<8|u;if(n+=f,i<128)throw new e("tlv.decode(long): not minimal encoding")}let c=t.subarray(n,n+i);if(c.length!==i)throw new e("tlv.decode: wrong value length");return{v:c,l:t.subarray(n+i)}}},_int:{encode(r){let{Err:t}=Et;if(xr(r),r<At)throw new t("integer: negative integers are not allowed");let e=ze(r);if(Number.parseInt(e[0],16)&8&&(e="00"+e),e.length&1)throw new t("unexpected DER parsing assertion: unpadded hex");return e},decode(r){let{Err:t}=Et;if(r.length<1)throw new t("invalid signature integer: empty");if(r[0]&128)throw new t("invalid signature integer: negative");if(r.length>1&&r[0]===0&&!(r[1]&128))throw new t("invalid signature integer: unnecessary leading zero");return Qt(r)}},toSig(r){let{Err:t,_int:e,_tlv:n}=Et,o=M(r,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:e.decode(c),s:e.decode(a)}},hexFromSig(r){let{_tlv:t,_int:e}=Et,n=t.encode(2,e.encode(r.r)),o=t.encode(2,e.encode(r.s)),s=n+o;return t.encode(48,s)}};Object.freeze(Et._tlv);Object.freeze(Et._int);Object.freeze(Et);var At=BigInt(0),jt=BigInt(1),pi=BigInt(2),Pr=BigInt(3),of=BigInt(4);function mi(r,t={}){let e=Sr("weierstrass",r,t),n=e.Fp,o=e.Fn,s=e.CURVE,{h:i,n:c}=s;xt(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=yi(n,o);function h(){if(!n.isOdd)throw new Error("compression is not supported: Field does not have .isOdd()")}function w(k,l,m){if(a&&l.is0())return Uint8Array.of(0);let{x:E,y:g}=l.toAffine(),b=n.toBytes(E);if(yt(m,"isCompressed"),m){h();let v=!n.isOdd(g);return G(bi(v),b)}else return G(Uint8Array.of(4),b,n.toBytes(g))}function p(k){M(k,void 0,"Point");let{publicKey:l,publicKeyUncompressed:m}=u,E=k.length,g=k[0],b=k.subarray(1);if(a&&E===1&&g===0)return{x:n.ZERO,y:n.ZERO};if(E===l&&(g===2||g===3)){let v=n.fromBytes(b);if(!n.isValid(v))throw new Error("bad point: is not on curve, wrong x");let T=d(v),B;try{B=n.sqrt(T)}catch(N){let P=N instanceof Error?": "+N.message:"";throw new Error("bad point: is not on curve, sqrt error"+P)}h();let D=n.isOdd(B);return(g&1)===1!==D&&(B=n.neg(B)),{x:v,y:B}}else if(E===m&&g===4){let v=n.BYTES,T=n.fromBytes(b.subarray(0,v)),B=n.fromBytes(b.subarray(v,v*2));if(!x(T,B))throw new Error("bad point: is not on curve");return{x:T,y:B}}else throw new Error(`bad point: got length ${E}, expected compressed=${l} or uncompressed=${m}`)}let y=t.toBytes===void 0?w:t.toBytes,_=t.fromBytes===void 0?p:t.fromBytes;function d(k){let l=n.sqr(k),m=n.mul(l,k);return n.add(n.add(m,n.mul(k,s.a)),s.b)}function x(k,l){let m=n.sqr(l),E=d(k);return n.eql(m,E)}if(!x(s.Gx,s.Gy))throw new Error("bad curve params: generator point");let S=n.mul(n.pow(s.a,Pr),of),A=n.mul(n.sqr(s.b),BigInt(27));if(n.is0(n.add(S,A)))throw new Error("bad curve params: a or b");function C(k,l,m=!1){if(!n.isValid(l)||m&&n.is0(l))throw new Error(`bad point coordinate ${k}`);return l}function L(k){if(!(k instanceof I))throw new Error("Weierstrass Point expected")}function O(k){if(!f||!f.basises)throw new Error("no endo");return nf(k,f.basises,o.ORDER)}function R(k,l,m,E,g){return m=new I(n.mul(m.X,k),m.Y,m.Z),l=je(E,l),m=je(g,m),l.add(m)}class I{static BASE=new I(s.Gx,s.Gy,n.ONE);static ZERO=new I(n.ZERO,n.ONE,n.ZERO);static Fp=n;static Fn=o;X;Y;Z;constructor(l,m,E){this.X=C("x",l),this.Y=C("y",m,!0),this.Z=C("z",E),Object.freeze(this)}static CURVE(){return s}static fromAffine(l){let{x:m,y:E}=l||{};if(!l||!n.isValid(m)||!n.isValid(E))throw new Error("invalid affine point");if(l instanceof I)throw new Error("projective point not allowed");return n.is0(m)&&n.is0(E)?I.ZERO:new I(m,E,n.ONE)}static fromBytes(l){let m=I.fromAffine(_(M(l,void 0,"point")));return m.assertValidity(),m}static fromHex(l){return I.fromBytes(ge(l))}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(l=8,m=!0){return z.createCache(this,l),m||this.multiply(Pr),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:m,y:E}=l.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(!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(l);let{X:m,Y:E,Z:g}=this,{X:b,Y:v,Z:T}=l,B=n.eql(n.mul(m,T),n.mul(b,g)),D=n.eql(n.mul(E,T),n.mul(v,g));return B&&D}negate(){return new I(this.X,n.neg(this.Y),this.Z)}double(){let{a:l,b:m}=s,E=n.mul(m,Pr),{X:g,Y:b,Z:v}=this,T=n.ZERO,B=n.ZERO,D=n.ZERO,F=n.mul(g,g),N=n.mul(b,b),P=n.mul(v,v),K=n.mul(g,b);return K=n.add(K,K),D=n.mul(g,v),D=n.add(D,D),T=n.mul(l,D),B=n.mul(E,P),B=n.add(T,B),T=n.sub(N,B),B=n.add(N,B),B=n.mul(T,B),T=n.mul(K,T),D=n.mul(E,D),P=n.mul(l,P),K=n.sub(F,P),K=n.mul(l,K),K=n.add(K,D),D=n.add(F,F),F=n.add(D,F),F=n.add(F,P),F=n.mul(F,K),B=n.add(B,F),P=n.mul(b,v),P=n.add(P,P),F=n.mul(P,K),T=n.sub(T,F),D=n.mul(P,N),D=n.add(D,D),D=n.add(D,D),new I(T,B,D)}add(l){L(l);let{X:m,Y:E,Z:g}=this,{X:b,Y:v,Z:T}=l,B=n.ZERO,D=n.ZERO,F=n.ZERO,N=s.a,P=n.mul(s.b,Pr),K=n.mul(m,b),$=n.mul(E,v),X=n.mul(g,T),W=n.add(m,E),j=n.add(b,v);W=n.mul(W,j),j=n.add(K,$),W=n.sub(W,j),j=n.add(m,g);let st=n.add(b,T);return j=n.mul(j,st),st=n.add(K,X),j=n.sub(j,st),st=n.add(E,g),B=n.add(v,T),st=n.mul(st,B),B=n.add($,X),st=n.sub(st,B),F=n.mul(N,j),B=n.mul(P,X),F=n.add(B,F),B=n.sub($,F),F=n.add($,F),D=n.mul(B,F),$=n.add(K,K),$=n.add($,K),X=n.mul(N,X),j=n.mul(P,j),$=n.add($,X),X=n.sub(K,X),X=n.mul(N,X),j=n.add(j,X),K=n.mul($,j),D=n.add(D,K),K=n.mul(st,j),B=n.mul(W,B),B=n.sub(B,K),K=n.mul(W,$),F=n.mul(st,F),F=n.add(F,K),new I(B,D,F)}subtract(l){return L(l),this.add(l.negate())}is0(){return this.equals(I.ZERO)}multiply(l){let{endo:m}=t;if(!o.isValidNot0(l))throw new RangeError("invalid scalar: out of range");let E,g,b=v=>z.cached(this,v,T=>re(I,T));if(m){let{k1neg:v,k1:T,k2neg:B,k2:D}=O(l),{p:F,f:N}=b(T),{p:P,f:K}=b(D);g=N.add(K),E=R(m.beta,F,P,v,B)}else{let{p:v,f:T}=b(l);E=v,g=T}return re(I,[E,g])[0]}multiplyUnsafe(l){let{endo:m}=t,E=this,g=l;if(!o.isValid(g))throw new RangeError("invalid scalar: out of range");if(g===At||E.is0())return I.ZERO;if(g===jt)return E;if(z.hasCache(this))return this.multiply(g);if(m){let{k1neg:b,k1:v,k2neg:T,k2:B}=O(g),{p1:D,p2:F}=Ms(I,E,v,B);return R(m.beta,D,F,b,T)}else return z.unsafe(E,g)}toAffine(l){let m=this,E=l,{X:g,Y:b,Z:v}=m;if(n.eql(v,n.ONE))return{x:g,y:b};let T=m.is0();E==null&&(E=T?n.ONE:n.inv(v));let B=n.mul(g,E),D=n.mul(b,E),F=n.mul(v,E);if(T)return{x:n.ZERO,y:n.ZERO};if(!n.eql(F,n.ONE))throw new Error("invZ was invalid");return{x:B,y:D}}isTorsionFree(){let{isTorsionFree:l}=t;return i===jt?!0:l?l(I,this):z.unsafe(this,c).is0()}clearCofactor(){let{clearCofactor:l}=t;return i===jt?this:l?l(I,this):this.multiplyUnsafe(i)}isSmallOrder(){return i===jt?this.is0():this.clearCofactor().is0()}toBytes(l=!0){return yt(l,"isCompressed"),this.assertValidity(),y(I,this,l)}toHex(l=!0){return ye(this.toBytes(l))}toString(){return`<Point ${this.is0()?"ZERO":this.toHex()}>`}}let U=o.BITS,z=new Se(I,t.endo?Math.ceil(U/2):U);return U>=8&&I.BASE.precompute(8),Object.freeze(I.prototype),Object.freeze(I),I}function bi(r){return Uint8Array.of(r?2:3)}function yi(r,t){return{secretKey:t.BYTES,publicKey:1+r.BYTES,publicKeyUncompressed:1+2*r.BYTES,publicKeyHasPrefix:!0,signature:2*t.BYTES}}function sf(r,t={}){let{Fn:e}=r,n=t.randomBytes===void 0?Pe:t.randomBytes,o=Object.assign(yi(r.Fp,e),{seed:Math.max(zn(e.ORDER),16)});function s(p){try{let y=e.fromBytes(p);return e.isValidNot0(y)}catch{return!1}}function i(p,y){let{publicKey:_,publicKeyUncompressed:d}=o;try{let x=p.length;return y===!0&&x!==_||y===!1&&x!==d?!1:!!r.fromBytes(p)}catch{return!1}}function c(p){return p=p===void 0?n(o.seed):p,Hn(M(p,o.seed,"seed"),e.ORDER)}function f(p,y=!0){return r.BASE.multiply(e.fromBytes(p)).toBytes(y)}function a(p){let{secretKey:y,publicKey:_,publicKeyUncompressed:d}=o,x=e._lengths;if(!Jt(p))return;let S=M(p,void 0,"key").length,A=S===_||S===d,C=S===y||!!x?.includes(S);if(!(A&&C))return A}function u(p,y,_=!0){if(a(p)===!0)throw new Error("first arg must be private key");if(a(y)===!1)throw new Error("second arg must be public key");let d=e.fromBytes(p);return r.fromBytes(y).multiply(d).toBytes(_)}let h={isValidSecretKey:s,isValidPublicKey:i,randomSecretKey:c},w=vr(c,f);return Object.freeze(h),Object.freeze(o),Object.freeze({getPublicKey:f,getSharedSecret:u,keygen:w,Point:r,utils:h,lengths:o})}function gi(r,t,e={}){let n=t;hr(n),xt(e,{},{hmac:"function",lowS:"boolean",randomBytes:"function",bits2int:"function",bits2int_modN:"function"}),e=Object.assign({},e);let o=e.randomBytes===void 0?Pe:e.randomBytes,s=e.hmac===void 0?(g,b)=>li(n,g,b):e.hmac,{Fp:i,Fn:c}=r,{ORDER:f,BITS:a}=c,{keygen:u,getPublicKey:h,getSharedSecret:w,utils:p,lengths:y}=sf(r,e),_={prehash:!0,lowS:typeof e.lowS=="boolean"?e.lowS:!0,format:"compact",extraEntropy:!1},d=f*pi+jt<i.ORDER;function x(g){let b=f>>jt;return g>b}function S(g,b){if(!c.isValidNot0(b))throw new Error(`invalid signature ${g}: out of range 1..Point.Fn.ORDER`);return b}function A(){if(d)throw new Error('"recovered" sig type is not supported for cofactor >2 curves')}function C(g,b){bo(b);let v=y.signature,T=b==="compact"?v:b==="recovered"?v+1:void 0;return M(g,T)}class L{r;s;recovery;constructor(b,v,T){if(this.r=S("r",b),this.s=S("s",v),T!=null){if(A(),![0,1,2,3].includes(T))throw new Error("invalid recovery id");this.recovery=T}Object.freeze(this)}static fromBytes(b,v=_.format){C(b,v);let T;if(v==="der"){let{r:N,s:P}=Et.toSig(M(b));return new L(N,P)}v==="recovered"&&(T=b[0],v="compact",b=b.subarray(1));let B=y.signature/2,D=b.subarray(0,B),F=b.subarray(B,B*2);return new L(c.fromBytes(D),c.fromBytes(F),T)}static fromHex(b,v){return this.fromBytes(ge(b),v)}assertRecovery(){let{recovery:b}=this;if(b==null)throw new Error("invalid recovery id: must be present");return b}addRecoveryBit(b){return new L(this.r,this.s,b)}recoverPublicKey(b){let{r:v,s:T}=this,B=this.assertRecovery(),D=B===2||B===3?v+f:v;if(!i.isValid(D))throw new Error("invalid recovery id: sig.r+curve.n != R.x");let F=i.toBytes(D),N=r.fromBytes(G(bi((B&1)===0),F)),P=c.inv(D),K=R(M(b,void 0,"msgHash")),$=c.create(-K*P),X=c.create(T*P),W=r.BASE.multiplyUnsafe($).add(N.multiplyUnsafe(X));if(W.is0())throw new Error("invalid recovery: point at infinify");return W.assertValidity(),W}hasHighS(){return x(this.s)}toBytes(b=_.format){if(bo(b),b==="der")return ge(Et.hexFromSig(this));let{r:v,s:T}=this,B=c.toBytes(v),D=c.toBytes(T);return b==="recovered"?(A(),G(Uint8Array.of(this.assertRecovery()),B,D)):G(B,D)}toHex(b){return ye(this.toBytes(b))}}Object.freeze(L.prototype),Object.freeze(L);let O=e.bits2int===void 0?function(b){if(b.length>8192)throw new Error("input is too large");let v=Qt(b),T=b.length*8-a;return T>0?v>>BigInt(T):v}:e.bits2int,R=e.bits2int_modN===void 0?function(b){return c.create(O(b))}:e.bits2int_modN,I=qe(a);function U(g){return xe("num < 2^"+a,g,At,I),c.toBytes(g)}function z(g,b){return M(g,void 0,"message"),b?M(n(g),void 0,"prehashed message"):g}function k(g,b,v){let{lowS:T,prehash:B,extraEntropy:D}=mo(v,_);g=z(g,B);let F=R(g),N=c.fromBytes(b);if(!c.isValidNot0(N))throw new Error("invalid private key");let P=[U(N),U(F)];if(D!=null&&D!==!1){let W=D===!0?o(y.secretKey):D;P.push(M(W,void 0,"extraEntropy"))}let K=G(...P),$=F;function X(W){let j=O(W);if(!c.isValidNot0(j))return;let st=c.inv(j),ce=r.BASE.multiply(j).toAffine(),Be=c.create(ce.x);if(Be===At)return;let nr=c.create(st*c.create($+Be*N));if(nr===At)return;let Io=(ce.x===Be?0:2)|Number(ce.y&jt),To=nr;return T&&x(nr)&&(To=c.neg(nr),Io^=1),new L(Be,To,d?void 0:Io)}return{seed:K,k2sig:X}}function l(g,b,v={}){let{seed:T,k2sig:B}=k(g,b,v);return _s(n.outputLen,c.BYTES,s)(T,B).toBytes(v.format)}function m(g,b,v,T={}){let{lowS:B,prehash:D,format:F}=mo(T,_);if(v=M(v,void 0,"publicKey"),b=z(b,D),!Jt(g)){let N=g instanceof L?", use sig.toBytes()":"";throw new Error("verify expects Uint8Array signature"+N)}C(g,F);try{let N=L.fromBytes(g,F),P=r.fromBytes(v);if(B&&N.hasHighS())return!1;let{r:K,s:$}=N,X=R(b),W=c.inv($),j=c.create(X*W),st=c.create(K*W),ce=r.BASE.multiplyUnsafe(j).add(P.multiplyUnsafe(st));return ce.is0()?!1:c.create(ce.x)===K}catch{return!1}}function E(g,b,v={}){let{prehash:T}=mo(v,_);return b=z(b,T),L.fromBytes(g,"recovered").recoverPublicKey(b).toBytes()}return Object.freeze({keygen:u,getPublicKey:h,getSharedSecret:w,utils:p,lengths:y,Point:r,sign:l,verify:m,recoverPublicKey:E,Signature:L,hash:n})}var xo={p:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:BigInt(1),a:BigInt(0),b:BigInt(7),Gx:BigInt("0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"),Gy:BigInt("0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8")},cf={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),basises:[[BigInt("0x3086d221a7d46bcde86c90e49284eb15"),-BigInt("0xe4437ed6010e88286f547fa90abfe4c3")],[BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),BigInt("0x3086d221a7d46bcde86c90e49284eb15")]]};var xi=BigInt(2);function af(r){let t=xo.p,e=BigInt(3),n=BigInt(6),o=BigInt(11),s=BigInt(22),i=BigInt(23),c=BigInt(44),f=BigInt(88),a=r*r*r%t,u=a*a*r%t,h=H(u,e,t)*u%t,w=H(h,e,t)*u%t,p=H(w,xi,t)*a%t,y=H(p,o,t)*p%t,_=H(y,s,t)*y%t,d=H(_,c,t)*_%t,x=H(d,f,t)*d%t,S=H(x,c,t)*_%t,A=H(S,e,t)*u%t,C=H(A,i,t)*y%t,L=H(C,n,t)*a%t,O=H(L,xi,t);if(!go.eql(go.sqr(O),r))throw new Error("Cannot find square root");return O}var go=Ee(xo.p,{sqrt:af}),ff=mi(xo,{Fp:go,endo:cf}),Ae=gi(ff,xs);function wi(r,t,e,n){let o=Fe.digest(e instanceof Uint8Array?e:e.subarray());if(Lr(o))return o.then(({digest:s})=>(n?.signal?.throwIfAborted(),Ae.verify(t,s,r,{prehash:!1,format:"der"}))).catch(s=>{throw s.name==="AbortError"?s:new Ye(String(s))});try{return n?.signal?.throwIfAborted(),Ae.verify(t,o.digest,r,{prehash:!1,format:"der"})}catch(s){throw new Ye(String(s))}}var zr=class{type="secp256k1";raw;_key;constructor(t){this._key=_i(t),this.raw=Ei(this._key)}toMultihash(){return pt.digest(me(this))}toCID(){return it.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:at(this.raw,t.raw)}verify(t,e,n){return wi(this._key,e,t,n)}};function Si(r){return new zr(r)}function Ei(r){return Ae.Point.fromBytes(r).toBytes()}function _i(r){try{return Ae.Point.fromBytes(r),r}catch(t){throw new or(String(t))}}function vi(r){let{Type:t,Data:e}=Je.decode(r.digest),n=e??new Uint8Array;switch(t){case ot.Ed25519:return Ws(n);case ot.secp256k1:return Si(n);case ot.ECDSA:return rs(n);default:throw new Ie}}function me(r){return Je.encode({Type:ot[r.type],Data:r.raw})}var Ai=Symbol.for("nodejs.util.inspect.custom"),uf=114,Qe=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()})`}[Gr]=!0;toString(){return this.string==null&&(this.string=Z.encode(this.multihash.bytes).slice(1)),this.string}toMultihash(){return this.multihash}toCID(){return it.createV1(uf,this.multihash)}toJSON(){return this.toString()}equals(t){if(t==null)return!1;if(t instanceof Uint8Array)return at(this.multihash.bytes,t);if(typeof t=="string")return this.toString()===t;if(t?.toMultihash()?.bytes!=null)return at(this.multihash.bytes,t.toMultihash().bytes);throw new Error("not valid Id")}[Ai](){return`PeerId(${this.toString()})`}},Hr=class extends Qe{type="RSA";publicKey;constructor(t){super({...t,type:"RSA"}),this.publicKey=t.publicKey}},qr=class extends Qe{type="Ed25519";publicKey;constructor(t){super({...t,type:"Ed25519"}),this.publicKey=t.publicKey}},Vr=class extends Qe{type="secp256k1";publicKey;constructor(t){super({...t,type:"secp256k1"}),this.publicKey=t.publicKey}},hf=2336,jr=class{type="url";multihash;publicKey;url;constructor(t){this.url=t.toString(),this.multihash=pt.digest(J(this.url))}[Ai](){return`PeerId(${this.url})`}[Gr]=!0;toString(){return this.toCID().toString()}toMultihash(){return this.multihash}toCID(){return it.createV1(hf,this.toMultihash())}toJSON(){return this.toString()}equals(t){return t==null?!1:(t instanceof Uint8Array&&(t=dt(t)),t.toString()===this.toString())}};function Bi(r){if(df(r))return new Hr({multihash:r});if(lf(r))try{let t=vi(r);if(t.type==="Ed25519")return new qr({multihash:r,publicKey:t});if(t.type==="secp256k1")return new Vr({multihash:r,publicKey:t})}catch{let e=dt(r.digest);return new jr(new URL(e))}throw new sr("Supplied PeerID Multihash is invalid")}function lf(r){return r.code===pt.code}function df(r){return r.code===Fe.code}function Bt(r,t){let e={[Symbol.iterator]:()=>e,next:()=>{let n=r.next(),o=n.value;return n.done===!0||o==null?{done:!0,value:void 0}:{done:!1,value:t(o)}}};return e}function Zr(r){let t=Ce(Z.decode(`z${r}`));return Bi(t)}var Zt=class{map;constructor(t){if(this.map=new Map,t!=null)for(let[e,n]of t.entries())this.map.set(e.toString(),{key:e,value:n})}[Symbol.iterator](){return this.entries()}clear(){this.map.clear()}delete(t){return this.map.delete(t.toString())}entries(){return Bt(this.map.entries(),t=>[t[1].key,t[1].value])}forEach(t){this.map.forEach((e,n)=>{t(e.value,e.key,this)})}get(t){return this.map.get(t.toString())?.value}has(t){return this.map.has(t.toString())}set(t,e){this.map.set(t.toString(),{key:t,value:e})}keys(){return Bt(this.map.values(),t=>t.key)}values(){return Bt(this.map.values(),t=>t.value)}get size(){return this.map.size}};function Ii(){return new Zt}var Yt=class r{set;constructor(t){if(this.set=new Set,t!=null)for(let e of t)this.set.add(e.toString())}get size(){return this.set.size}[Symbol.iterator](){return this.values()}add(t){this.set.add(t.toString())}clear(){this.set.clear()}delete(t){this.set.delete(t.toString())}entries(){return Bt(this.set.entries(),t=>{let e=Zr(t[0]);return[e,e]})}forEach(t){this.set.forEach(e=>{let n=Zr(e);t(n,n,this)})}has(t){return this.set.has(t.toString())}values(){return Bt(this.set.values(),t=>Zr(t))}intersection(t){let e=new r;for(let n of t)this.has(n)&&e.add(n);return e}difference(t){let e=new r;for(let n of this)t.has(n)||e.add(n);return e}union(t){let e=new r;for(let n of t)e.add(n);for(let n of this)e.add(n);return e}};function Ti(){return new Yt}var $t=class r{list;constructor(t){if(this.list=[],t!=null)for(let e of t)this.list.push(e)}[Symbol.iterator](){return Bt(this.list.entries(),t=>t[1])}concat(t){let e=new r(this);for(let n of t)e.push(n);return e}entries(){return Bt(this.list.entries(),t=>[t[0],t[1]])}every(t){return this.list.every((e,n)=>t(e,n,this))}filter(t){let e=new r;return this.list.forEach((n,o)=>{t(n,o,this)&&e.push(n)}),e}find(t){let e=this.list.find((n,o)=>t(n,o,this));if(e!=null)return e}findIndex(t){return this.list.findIndex((e,n)=>t(e,n,this))}forEach(t){this.list.forEach((e,n)=>{t(e,n,this)})}includes(t){return this.includes(t)}indexOf(t){return this.list.findIndex(e=>e.equals(t))}pop(){let t=this.list.pop();if(t!=null)return t}push(...t){for(let e of t)this.list.push(e)}shift(){let t=this.list.shift();if(t!=null)return t}unshift(...t){let e=this.list.length;for(let n=t.length-1;n>-1;n--)e=this.list.unshift(t[n]);return e}clear(){this.list=[]}get length(){return this.list.length}};function Li(){return new $t}var wo={32:16777619n,64:1099511628211n,128:309485009821345068724781371n,256:374144419156711147060143317175368453031918731002211n,512:35835915874844867368919076489095108449946327955754392558399825615420669938882575126094039892345713852759n,1024:5016456510113118655434598811035278955030765345404790744303017523831112055108147451509157692220295382716162651878526895249385292291816524375083746691371804094271873160484737966720260389217684476157468082573n},Di={32:2166136261n,64:14695981039346656037n,128:144066263297769815596495629667062367629n,256:100029257958052580907070968620625704837092796014241193945225284501741471925557n,512:9659303129496669498009435400716310466090418745672637896108374329434462657994582932197716438449813051892206539805784495328239340083876191928701583869517785n,1024:14197795064947621068722070641403218320880622795441933960878474914617582723252296732303717722150864096521202355549365628174669108571814760471015076148029755969804077320157692458563003215304957150157403644460363550505412711285966361610267868082893823963790439336411086884584107735010676915n},Ci=new globalThis.TextEncoder;function pf(r,t){let e=wo[t],n=Di[t];for(let o=0;o<r.length;o++)n^=BigInt(r[o]),n=BigInt.asUintN(t,n*e);return n}function mf(r,t,e){if(e.length===0)throw new Error("The `utf8Buffer` option must have a length greater than zero");let n=wo[t],o=Di[t],s=r;for(;s.length>0;){let i=Ci.encodeInto(s,e);s=s.slice(i.read);for(let c=0;c<i.written;c++)o^=BigInt(e[c]),o=BigInt.asUintN(t,o*n)}return o}function Eo(r,{size:t=32,utf8Buffer:e}={}){if(!wo[t])throw new Error("The `size` option must be one of 32, 64, 128, 256, 512, or 1024");if(typeof r=="string"){if(e)return mf(r,t,e);r=Ci.encode(r)}return pf(r,t)}var tr={hash:r=>Number(Eo(r,{size:32})),hashV:(r,t)=>bf(tr.hash(r,t))};function bf(r){let t=r.toString(16);return t.length%2===1&&(t=`0${t}`),J(t,"base16")}var _o=64,_t=class{fp;h;seed;constructor(t,e,n,o=2){if(o>_o)throw new TypeError("Invalid Fingerprint Size");let s=e.hashV(t,n),i=mt(o);for(let c=0;c<i.length;c++)i[c]=s[c];i.length===0&&(i[0]=7),this.fp=i,this.h=e,this.seed=n}hash(){return this.h.hash(this.fp,this.seed)}equals(t){return t?.fp instanceof Uint8Array?at(this.fp,t.fp):!1}};function se(r,t){return Math.floor(Math.random()*(t-r))+r}var ie=class{contents;constructor(t){this.contents=new Array(t).fill(null)}has(t){if(!(t instanceof _t))throw new TypeError("Invalid Fingerprint");return this.contents.some(e=>t.equals(e))}add(t){if(!(t instanceof _t))throw new TypeError("Invalid Fingerprint");for(let e=0;e<this.contents.length;e++)if(this.contents[e]==null)return this.contents[e]=t,!0;return!0}swap(t){if(!(t instanceof _t))throw new TypeError("Invalid Fingerprint");let e=se(0,this.contents.length-1),n=this.contents[e];return this.contents[e]=t,n}remove(t){if(!(t instanceof _t))throw new TypeError("Invalid Fingerprint");let e=this.contents.findIndex(n=>t.equals(n));return e>-1?(this.contents[e]=null,!0):!1}};var yf=500,er=class{bucketSize;filterSize;fingerprintSize;buckets;count;hash;seed;constructor(t){this.filterSize=t.filterSize,this.bucketSize=t.bucketSize??4,this.fingerprintSize=t.fingerprintSize??2,this.count=0,this.buckets=[],this.hash=t.hash??tr,this.seed=t.seed??se(0,Math.pow(2,10))}add(t){typeof t=="string"&&(t=J(t));let e=new _t(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=(n^e.hash())%this.filterSize;if(this.buckets[n]==null&&(this.buckets[n]=new ie(this.bucketSize)),this.buckets[o]==null&&(this.buckets[o]=new ie(this.bucketSize)),this.buckets[n].add(e)||this.buckets[o].add(e))return this.count++,!0;let s=[n,o],i=s[se(0,s.length-1)];this.buckets[i]==null&&(this.buckets[i]=new ie(this.bucketSize));for(let c=0;c<yf;c++){let f=this.buckets[i].swap(e);if(f!=null&&(i=(i^f.hash())%this.filterSize,this.buckets[i]==null&&(this.buckets[i]=new ie(this.bucketSize)),this.buckets[i].add(f)))return this.count++,!0}return!1}has(t){typeof t=="string"&&(t=J(t));let e=new _t(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.has(e)??!1;if(o)return o;let s=(n^e.hash())%this.filterSize;return this.buckets[s]?.has(e)??!1}remove(t){typeof t=="string"&&(t=J(t));let e=new _t(t,this.hash,this.seed,this.fingerprintSize),n=this.hash.hash(t,this.seed)%this.filterSize,o=this.buckets[n]?.remove(e)??!1;if(o)return this.count--,o;let s=(n^e.hash())%this.filterSize,i=this.buckets[s]?.remove(e)??!1;return i&&this.count--,i}get reliable(){return Math.floor(100*(this.count/this.filterSize))<=90}},gf={1:.5,2:.84,4:.95,8:.98};function xf(r=.001){return r>.002?2:r>1e-5?4:8}function Ri(r,t=.001){let e=xf(t),n=gf[e],o=Math.round(r/n),s=Math.min(Math.ceil(Math.log2(1/t)+Math.log2(2*e)),_o);return{filterSize:o,bucketSize:e,fingerprintSize:s}}var Yr=class{filterSize;bucketSize;fingerprintSize;scale;filterSeries;hash;seed;constructor(t){this.bucketSize=t.bucketSize??4,this.filterSize=t.filterSize??(1<<18)/this.bucketSize,this.fingerprintSize=t.fingerprintSize??2,this.scale=t.scale??2,this.hash=t.hash??tr,this.seed=t.seed??se(0,Math.pow(2,10)),this.filterSeries=[new er({filterSize:this.filterSize,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed})]}add(t){if(typeof t=="string"&&(t=J(t)),this.has(t))return!0;let e=this.filterSeries.find(n=>n.reliable);if(e==null){let n=this.filterSize*Math.pow(this.scale,this.filterSeries.length);e=new er({filterSize:n,bucketSize:this.bucketSize,fingerprintSize:this.fingerprintSize,hash:this.hash,seed:this.seed}),this.filterSeries.push(e)}return e.add(t)}has(t){typeof t=="string"&&(t=J(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].has(t))return!0;return!1}remove(t){typeof t=="string"&&(t=J(t));for(let e=0;e<this.filterSeries.length;e++)if(this.filterSeries[e].remove(t))return!0;return!1}get count(){return this.filterSeries.reduce((t,e)=>t+e.count,0)}};function So(r,t=.001,e){return new Yr({...Ri(r,t),...e??{}})}var rr=class{filter;constructor(t,e){this.filter=So(t,e)}has(t){return this.filter.has(t.toMultihash().bytes)}add(t){this.filter.add(t.toMultihash().bytes)}remove(t){this.filter.remove?.(t.toMultihash().bytes)}};function Fi(r,t=.001){return new rr(r,t)}var vo=class extends Zt{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}set(t,e){return super.set(t,e),this.updateComponentMetric(),this}delete(t){let e=super.delete(t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Oi(r){let{name:t,metrics:e}=r,n;return e!=null?n=new vo({name:t,metrics:e}):n=new Zt,n}var Ao=class extends Yt{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}add(t){super.add(t),this.updateComponentMetric()}delete(t){super.delete(t),this.updateComponentMetric()}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.size)}};function Ui(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Ao({name:t,metrics:e}):n=new Yt,n}var Bo=class extends $t{metric;constructor(t){super();let{name:e,metrics:n}=t;this.metric=n.registerMetric(e),this.updateComponentMetric()}pop(){let t=super.pop();return this.updateComponentMetric(),t}push(...t){super.push(...t),this.updateComponentMetric()}shift(){let t=super.shift();return this.updateComponentMetric(),t}unshift(...t){let e=super.unshift(...t);return this.updateComponentMetric(),e}clear(){super.clear(),this.updateComponentMetric()}updateComponentMetric(){this.metric.update(this.length)}};function ki(r){let{name:t,metrics:e}=r,n;return e!=null?n=new Bo({name:t,metrics:e}):n=new $t,n}return zi(wf);})();
3
3
  /*! Bundled license information:
4
4
 
5
- @noble/hashes/utils.js:
6
- (*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
7
-
8
5
  @noble/curves/utils.js:
9
6
  @noble/curves/abstract/modular.js:
10
7
  @noble/curves/abstract/curve.js: