UNPKG

@libp2p/pubsub-peer-discovery

Version:

A libp2p module that uses pubsub for mdns like peer discovery

2 lines 115 kB
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPubsubPeerDiscovery = factory()}(typeof self !== 'undefined' ? self : this, function () { "use strict";var Libp2PPubsubPeerDiscovery=(()=>{var Yr=Object.defineProperty;var Ji=Object.getOwnPropertyDescriptor;var Qi=Object.getOwnPropertyNames;var ta=Object.prototype.hasOwnProperty;var ut=(e,t)=>{for(var r in t)Yr(e,r,{get:t[r],enumerable:!0})},ea=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Qi(t))!ta.call(e,o)&&o!==r&&Yr(e,o,{get:()=>t[o],enumerable:!(n=Ji(t,o))||n.enumerable});return e};var ra=e=>ea(Yr({},"__esModule",{value:!0}),e);var Cu={};ut(Cu,{PubSubPeerDiscovery:()=>Zr,TOPIC:()=>Xi,pubsubPeerDiscovery:()=>_u});var Mo=Symbol.for("@libp2p/peer-discovery");var Xr=Symbol.for("@libp2p/peer-id");var W=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},ae=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var ce=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ar=class extends EventTarget{#t=new Map;constructor(){super()}listenerCount(t){let r=this.#t.get(t);return r==null?0:r.length}addEventListener(t,r,n){super.addEventListener(t,r,n);let o=this.#t.get(t);o==null&&(o=[],this.#t.set(t,o)),o.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let o=this.#t.get(t);o!=null&&(o=o.filter(({callback:s})=>s!==r),this.#t.set(t,o))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:o})=>!o),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var rn={};ut(rn,{base58btc:()=>V,base58flickr:()=>fa});var Uu=new Uint8Array(0);function Ho(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Ct(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function qo(e){return new TextEncoder().encode(e)}function Vo(e){return new TextDecoder().decode(e)}function na(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,c=e.charAt(0),l=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function u(S){if(S instanceof Uint8Array||(ArrayBuffer.isView(S)?S=new Uint8Array(S.buffer,S.byteOffset,S.byteLength):Array.isArray(S)&&(S=Uint8Array.from(S))),!(S instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(S.length===0)return"";for(var E=0,m=0,v=0,T=S.length;v!==T&&S[v]===0;)v++,E++;for(var I=(T-v)*f+1>>>0,L=new Uint8Array(I);v!==T;){for(var p=S[v],P=0,D=I-1;(p!==0||P<m)&&D!==-1;D--,P++)p+=256*L[D]>>>0,L[D]=p%a>>>0,p=p/a>>>0;if(p!==0)throw new Error("Non-zero carry");m=P,v++}for(var B=I-m;B!==I&&L[B]===0;)B++;for(var h=c.repeat(E);B<I;++B)h+=e.charAt(L[B]);return h}function x(S){if(typeof S!="string")throw new TypeError("Expected String");if(S.length===0)return new Uint8Array;var E=0;if(S[E]!==" "){for(var m=0,v=0;S[E]===c;)m++,E++;for(var T=(S.length-E)*l+1>>>0,I=new Uint8Array(T);S[E];){var L=r[S.charCodeAt(E)];if(L===255)return;for(var p=0,P=T-1;(L!==0||p<v)&&P!==-1;P--,p++)L+=a*I[P]>>>0,I[P]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");v=p,E++}if(S[E]!==" "){for(var D=T-v;D!==T&&I[D]===0;)D++;for(var B=new Uint8Array(m+(T-D)),h=m;D!==T;)B[h++]=I[D++];return B}}}function b(S){var E=x(S);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:x,decode:b}}var oa=na,sa=oa,Fo=sa;var Jr=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},Qr=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return jo(this,t)}},tn=class{decoders;constructor(t){this.decoders=t}or(t){return jo(this,t)}decode(t){let r=t[0],n=this.decoders[r];if(n!=null)return n.decode(t);throw RangeError(`Unable to decode multibase string ${JSON.stringify(t)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function jo(e,t){return new tn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var en=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Jr(t,r,n),this.decoder=new Qr(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function fe({name:e,prefix:t,encode:r,decode:n}){return new en(e,t,r,n)}function kt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=Fo(r,e);return fe({prefix:t,name:e,encode:n,decode:s=>Ct(o(s))})}function ia(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let l=0;l<o;++l){let f=t[e[l]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function aa(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function ca(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function j({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=ca(n);return fe({prefix:t,name:e,encode(s){return aa(s,n,r)},decode(s){return ia(s,o,r,e)}})}var V=kt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),fa=kt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var nn={};ut(nn,{base32:()=>Mt,base32hex:()=>da,base32hexpad:()=>ma,base32hexpadupper:()=>ya,base32hexupper:()=>pa,base32pad:()=>la,base32padupper:()=>ha,base32upper:()=>ua,base32z:()=>ba});var Mt=j({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),ua=j({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),la=j({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ha=j({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),da=j({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),pa=j({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),ma=j({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ya=j({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ba=j({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var on={};ut(on,{base36:()=>Le,base36upper:()=>xa});var Le=kt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),xa=kt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ga=Zo,Go=128,wa=127,Ea=~wa,Sa=Math.pow(2,31);function Zo(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Sa;)t[r++]=e&255|Go,e/=128;for(;e&Ea;)t[r++]=e&255|Go,e>>>=7;return t[r]=e|0,Zo.bytes=r-n+1,t}var va=sn,Aa=128,$o=127;function sn(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw sn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&$o)<<o:(i&$o)*Math.pow(2,o),o+=7}while(i>=Aa);return sn.bytes=s-n,r}var Ia=Math.pow(2,7),Ba=Math.pow(2,14),_a=Math.pow(2,21),Ca=Math.pow(2,28),Ta=Math.pow(2,35),Da=Math.pow(2,42),Pa=Math.pow(2,49),La=Math.pow(2,56),Oa=Math.pow(2,63),Ua=function(e){return e<Ia?1:e<Ba?2:e<_a?3:e<Ca?4:e<Ta?5:e<Da?6:e<Pa?7:e<La?8:e<Oa?9:10},Ka={encode:ga,decode:va,encodingLength:Ua},Ra=Ka,Oe=Ra;function Ue(e,t=0){return[Oe.decode(e,t),Oe.decode.bytes]}function ue(e,t,r=0){return Oe.encode(e,t,r),t}function le(e){return Oe.encodingLength(e)}function xt(e,t){let r=t.byteLength,n=le(e),o=n+le(r),s=new Uint8Array(o+r);return ue(e,s,0),ue(r,s,n),s.set(t,o),new he(e,r,t,s)}function an(e){let t=Ct(e),[r,n]=Ue(t),[o,s]=Ue(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new he(r,o,i,t)}function Wo(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ho(e.bytes,r.bytes)}}var he=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Yo(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return ka(r,cn(e),t??V.encoder);default:return Ma(r,cn(e),t??Mt.encoder)}}var Xo=new WeakMap;function cn(e){let t=Xo.get(e);if(t==null){let r=new Map;return Xo.set(e,r),r}return t}var Z=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==Ke)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Ha)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return e.createV0(r)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:t,digest:r}=this.multihash,n=xt(t,r);return e.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(t){return e.equals(this,t)}static equals(t,r){let n=r;return n!=null&&t.code===n.code&&t.version===n.version&&Wo(t.multihash,n.multihash)}toString(t){return Yo(this,t)}toJSON(){return{"/":Yo(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??Jo(n,o,s.bytes))}else if(r[qa]===!0){let{version:n,multihash:o,code:s}=r,i=an(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==Ke)throw new Error(`Version 0 CID must use dag-pb (code: ${Ke}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Jo(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,Ke,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Ct(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new he(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[u,x]=Ue(t.subarray(r));return r+=x,u},o=n(),s=Ke;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),l=r+c,f=l-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:l}}static parse(t,r){let[n,o]=Na(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return cn(s).set(n,t),s}};function Na(e,t){switch(e[0]){case"Q":{let r=t??V;return[V.prefix,r.decode(`${V.prefix}${e}`)]}case V.prefix:{let r=t??V;return[V.prefix,r.decode(e)]}case Mt.prefix:{let r=t??Mt;return[Mt.prefix,r.decode(e)]}case Le.prefix:{let r=t??Le;return[Le.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function ka(e,t,r){let{prefix:n}=r;if(n!==V.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function Ma(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var Ke=112,Ha=18;function Jo(e,t,r){let n=le(e),o=n+le(t),s=new Uint8Array(o+r.byteLength);return ue(e,s,0),ue(t,s,n),s.set(r,o),s}var qa=Symbol.for("@ipld/js-cid/CID");var fn={};ut(fn,{identity:()=>vt});var Qo=0,Va="identity",ts=Ct;function za(e){return xt(Qo,ts(e))}var vt={code:Qo,name:Va,encode:ts,digest:za};function nt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function gt(e=0){return new Uint8Array(e)}function ht(e=0){return new Uint8Array(e)}function Tt(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ht(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var rs=Symbol.for("@achingbrain/uint8arraylist");function es(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function fr(e){return!!e?.[rs]}var dt=class e{bufs;length;[rs]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(fr(n))r+=n.byteLength,this.bufs.push(...n.bufs);else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...t){this.prependAll(t)}prependAll(t){let r=0;for(let n of t.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(fr(n))r+=n.byteLength,this.bufs.unshift(...n.bufs);else throw new Error("Could not prepend value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}get(t){let r=es(this.bufs,t);return r.buf[r.index]}set(t,r){let n=es(this.bufs,t);n.buf[n.index]=r}write(t,r=0){if(t instanceof Uint8Array)for(let n=0;n<t.length;n++)this.set(r+n,t[n]);else if(fr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return Tt(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:Tt(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let l=t>=a&&t<c,f=r>a&&r<=c;if(l&&f){if(t===a&&r===c){n.push(i);break}let u=t-a;n.push(i.subarray(u,u+(r-t)));break}if(l){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!fr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let 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,l=n.byteLength-1,f;for(let u=r;u<=c;u+=f){f=0;for(let x=l;x>=0;x--){let b=this.get(u+x);if(n[x]!==b){f=Math.max(1,x-a[b]);break}}if(f===0)return u}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ht(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=gt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=gt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=gt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=ht(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=gt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=gt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=gt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=gt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=gt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!nt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var un={};ut(un,{base10:()=>Fa});var Fa=kt({prefix:"9",name:"base10",alphabet:"0123456789"});var ln={};ut(ln,{base16:()=>ja,base16upper:()=>Ga});var ja=j({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ga=j({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var hn={};ut(hn,{base2:()=>$a});var $a=j({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var dn={};ut(dn,{base256emoji:()=>Ja});var ns=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}"),Za=ns.reduce((e,t,r)=>(e[r]=t,e),[]),Wa=ns.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Ya(e){return e.reduce((t,r)=>(t+=Za[r],t),"")}function Xa(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Wa[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Ja=fe({prefix:"\u{1F680}",name:"base256emoji",encode:Ya,decode:Xa});var mn={};ut(mn,{base64:()=>Qa,base64pad:()=>tc,base64url:()=>pn,base64urlpad:()=>ec});var Qa=j({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),tc=j({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),pn=j({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),ec=j({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var yn={};ut(yn,{base8:()=>rc});var rc=j({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var bn={};ut(bn,{identity:()=>nc});var nc=fe({prefix:"\0",name:"identity",encode:e=>Vo(e),decode:e=>qo(e)});var bl=new TextEncoder,xl=new TextDecoder;var wn={};ut(wn,{sha256:()=>ur,sha512:()=>ic});function gn({name:e,code:t,encode:r}){return new xn(e,t,r)}var xn=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?xt(this.code,r):r.then(n=>xt(this.code,n))}else throw Error("Unknown type, must be binary type")}};function ss(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var ur=gn({name:"sha2-256",code:18,encode:ss("SHA-256")}),ic=gn({name:"sha2-512",code:19,encode:ss("SHA-512")});var Re={...bn,...hn,...yn,...un,...ln,...nn,...on,...rn,...mn,...dn},Dl={...wn,...fn};function as(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var is=as("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),En=as("ascii","a",e=>{let t="a";for(let r=0;r<e.length;r++)t+=String.fromCharCode(e[r]);return t},e=>{e=e.substring(1);let t=ht(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),ac={utf8:is,"utf-8":is,hex:Re.base16,latin1:En,ascii:En,binary:En,...Re},lr=ac;function k(e,t="utf8"){let r=lr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function R(e,t="utf8"){let r=lr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var cc=parseInt("11111",2),Sn=parseInt("10000000",2),fc=parseInt("01111111",2),cs={0:Ne,1:Ne,2:uc,3:dc,4:pc,5:hc,6:lc,16:Ne,22:Ne,48:Ne};function Dt(e,t={offset:0}){let r=e[t.offset]&cc;if(t.offset++,cs[r]!=null)return cs[r](e,t);throw new Error("No decoder for tag "+r)}function ke(e,t){let r=0;if((e[t.offset]&Sn)===Sn){let n=e[t.offset]&fc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Ne(e,t){ke(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Dt(e,t);if(n===null)break;r.push(n)}return r}function uc(e,t){let r=ke(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function lc(e,t){let r=ke(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let l=e[t.offset];if(t.offset++,c.push(l&127),l<128){c.reverse();let f=0;for(let u=0;u<c.length;u++)f+=c[u]<<u*7;a+=`.${f}`,c=[]}}return a}function hc(e,t){return t.offset++,null}function dc(e,t){let r=ke(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function pc(e,t){let r=ke(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function mc(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new dt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function vn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=mc(e.byteLength);return new dt(Uint8Array.from([t.byteLength|Sn]),t)}function lt(e){let t=new dt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new dt(Uint8Array.from([2]),vn(t),t)}function hr(e){let t=Uint8Array.from([0]),r=new dt(t,e);return new dt(Uint8Array.from([3]),vn(r),r)}function Ht(e,t=48){let r=new dt;for(let n of e)r.append(n);return new dt(Uint8Array.from([t]),vn(r),r)}async function fs(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var yc=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),bc=Uint8Array.from([6,5,43,129,4,0,34]),xc=Uint8Array.from([6,5,43,129,4,0,35]),gc={ext:!0,kty:"EC",crv:"P-256"},wc={ext:!0,kty:"EC",crv:"P-384"},Ec={ext:!0,kty:"EC",crv:"P-521"},An=32,In=48,Bn=66;function us(e){let t=Dt(e);return ls(t)}function ls(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===An*2+1)return n=R(t.subarray(r,r+An),"base64url"),o=R(t.subarray(r+An),"base64url"),new pe({...gc,key_ops:["verify"],x:n,y:o});if(t.byteLength===In*2+1)return n=R(t.subarray(r,r+In),"base64url"),o=R(t.subarray(r+In),"base64url"),new pe({...wc,key_ops:["verify"],x:n,y:o});if(t.byteLength===Bn*2+1)return n=R(t.subarray(r,r+Bn),"base64url"),o=R(t.subarray(r+Bn),"base64url"),new pe({...Ec,key_ops:["verify"],x:n,y:o});throw new W(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function hs(e){return Ht([lt(Uint8Array.from([1])),Ht([Sc(e.crv)],160),Ht([hr(new dt(Uint8Array.from([4]),k(e.x??"","base64url"),k(e.y??"","base64url")))],161)]).subarray()}function Sc(e){if(e==="P-256")return yc;if(e==="P-384")return bc;if(e==="P-521")return xc;throw new W(`Invalid curve ${e}`)}var pe=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=hs(this.jwk)),this._raw}toMultihash(){return vt.digest(qt(this))}toCID(){return Z.createV1(114,this.toMultihash())}toString(){return V.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:nt(this.raw,t.raw)}async verify(t,r,n){return fs(this.jwk,r,t,n)}};var Wt=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function ye(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Me(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function ot(e,...t){if(!ye(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function ps(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Me(e.outputLen),Me(e.blockLen)}function be(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function ms(e,t){ot(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Lt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function dr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function wt(e,t){return e<<32-t|e>>>t}var ys=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",vc=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function At(e){if(ot(e),ys)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=vc[e[r]];return t}var Pt={_0:48,_9:57,A:65,F:70,a:97,f:102};function ds(e){if(e>=Pt._0&&e<=Pt._9)return e-Pt._0;if(e>=Pt.A&&e<=Pt.F)return e-(Pt.A-10);if(e>=Pt.a&&e<=Pt.f)return e-(Pt.a-10)}function xe(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ys)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=ds(e.charCodeAt(s)),a=ds(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function bs(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function He(e){return typeof e=="string"&&(e=bs(e)),ot(e),e}function pt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];ot(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var me=class{};function _n(e){let t=n=>e().update(He(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function qe(e=32){if(Wt&&typeof Wt.getRandomValues=="function")return Wt.getRandomValues(new Uint8Array(e));if(Wt&&typeof Wt.randomBytes=="function")return Uint8Array.from(Wt.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function Ac(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),a=Number(r&s),c=n?4:0,l=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+l,a,n)}function xs(e,t,r){return e&t^~e&r}function gs(e,t,r){return e&t^e&r^t&r}var Ve=class extends me{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=dr(this.buffer)}update(t){be(this),t=He(t),ot(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=dr(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(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){be(this),ms(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Lt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let u=i;u<o;u++)r[u]=0;Ac(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=dr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,f=this.get();if(l>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<l;u++)a.setUint32(4*u,f[u],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ot=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 pr=BigInt(4294967295),ws=BigInt(32);function Ic(e,t=!1){return t?{h:Number(e&pr),l:Number(e>>ws&pr)}:{h:Number(e>>ws&pr)|0,l:Number(e&pr)|0}}function Es(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Ic(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var Cn=(e,t,r)=>e>>>r,Tn=(e,t,r)=>e<<32-r|t>>>r,Yt=(e,t,r)=>e>>>r|t<<32-r,Xt=(e,t,r)=>e<<32-r|t>>>r,ze=(e,t,r)=>e<<64-r|t>>>r-32,Fe=(e,t,r)=>e>>>r-32|t<<64-r;function It(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var Ss=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),vs=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,As=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),Is=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,Bs=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),_s=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var _c=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]),Vt=new Uint32Array(64),mr=class extends Ve{constructor(t=32){super(64,t,8,!1),this.A=Ot[0]|0,this.B=Ot[1]|0,this.C=Ot[2]|0,this.D=Ot[3]|0,this.E=Ot[4]|0,this.F=Ot[5]|0,this.G=Ot[6]|0,this.H=Ot[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let u=0;u<16;u++,r+=4)Vt[u]=t.getUint32(r,!1);for(let u=16;u<64;u++){let x=Vt[u-15],b=Vt[u-2],S=wt(x,7)^wt(x,18)^x>>>3,E=wt(b,17)^wt(b,19)^b>>>10;Vt[u]=E+Vt[u-7]+S+Vt[u-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:l,H:f}=this;for(let u=0;u<64;u++){let x=wt(a,6)^wt(a,11)^wt(a,25),b=f+x+xs(a,c,l)+_c[u]+Vt[u]|0,E=(wt(n,2)^wt(n,13)^wt(n,22))+gs(n,o,s)|0;f=l,l=c,c=a,a=i+b|0,i=s,s=o,o=n,n=b+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,l,f)}roundClean(){Lt(Vt)}destroy(){this.set(0,0,0,0,0,0,0,0),Lt(this.buffer)}};var Cs=Es(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(e=>BigInt(e))),Cc=Cs[0],Tc=Cs[1],zt=new Uint32Array(80),Ft=new Uint32Array(80),Dn=class extends Ve{constructor(t=64){super(128,t,16,!1),this.Ah=Q[0]|0,this.Al=Q[1]|0,this.Bh=Q[2]|0,this.Bl=Q[3]|0,this.Ch=Q[4]|0,this.Cl=Q[5]|0,this.Dh=Q[6]|0,this.Dl=Q[7]|0,this.Eh=Q[8]|0,this.El=Q[9]|0,this.Fh=Q[10]|0,this.Fl=Q[11]|0,this.Gh=Q[12]|0,this.Gl=Q[13]|0,this.Hh=Q[14]|0,this.Hl=Q[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:l,El:f,Fh:u,Fl:x,Gh:b,Gl:S,Hh:E,Hl:m}=this;return[t,r,n,o,s,i,a,c,l,f,u,x,b,S,E,m]}set(t,r,n,o,s,i,a,c,l,f,u,x,b,S,E,m){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=f|0,this.Fh=u|0,this.Fl=x|0,this.Gh=b|0,this.Gl=S|0,this.Hh=E|0,this.Hl=m|0}process(t,r){for(let I=0;I<16;I++,r+=4)zt[I]=t.getUint32(r),Ft[I]=t.getUint32(r+=4);for(let I=16;I<80;I++){let L=zt[I-15]|0,p=Ft[I-15]|0,P=Yt(L,p,1)^Yt(L,p,8)^Cn(L,p,7),D=Xt(L,p,1)^Xt(L,p,8)^Tn(L,p,7),B=zt[I-2]|0,h=Ft[I-2]|0,g=Yt(B,h,19)^ze(B,h,61)^Cn(B,h,6),d=Xt(B,h,19)^Fe(B,h,61)^Tn(B,h,6),y=As(D,d,Ft[I-7],Ft[I-16]),w=Is(y,P,g,zt[I-7],zt[I-16]);zt[I]=w|0,Ft[I]=y|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:l,Dl:f,Eh:u,El:x,Fh:b,Fl:S,Gh:E,Gl:m,Hh:v,Hl:T}=this;for(let I=0;I<80;I++){let L=Yt(u,x,14)^Yt(u,x,18)^ze(u,x,41),p=Xt(u,x,14)^Xt(u,x,18)^Fe(u,x,41),P=u&b^~u&E,D=x&S^~x&m,B=Bs(T,p,D,Tc[I],Ft[I]),h=_s(B,v,L,P,Cc[I],zt[I]),g=B|0,d=Yt(n,o,28)^ze(n,o,34)^ze(n,o,39),y=Xt(n,o,28)^Fe(n,o,34)^Fe(n,o,39),w=n&s^n&a^s&a,_=o&i^o&c^i&c;v=E|0,T=m|0,E=b|0,m=S|0,b=u|0,S=x|0,{h:u,l:x}=It(l|0,f|0,h|0,g|0),l=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let A=Ss(g,y,_);n=vs(A,h,d,w),o=A|0}({h:n,l:o}=It(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=It(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=It(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:f}=It(this.Dh|0,this.Dl|0,l|0,f|0),{h:u,l:x}=It(this.Eh|0,this.El|0,u|0,x|0),{h:b,l:S}=It(this.Fh|0,this.Fl|0,b|0,S|0),{h:E,l:m}=It(this.Gh|0,this.Gl|0,E|0,m|0),{h:v,l:T}=It(this.Hh|0,this.Hl|0,v|0,T|0),this.set(n,o,s,i,a,c,l,f,u,x,b,S,E,m,v,T)}roundClean(){Lt(zt,Ft)}destroy(){Lt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var yr=_n(()=>new mr);var Ts=_n(()=>new Dn);var On=BigInt(0),Ln=BigInt(1);function Ut(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}function je(e){let t=e.toString(16);return t.length&1?"0"+t:t}function Ds(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?On:BigInt("0x"+e)}function ge(e){return Ds(At(e))}function Jt(e){return ot(e),Ds(At(Uint8Array.from(e).reverse()))}function br(e,t){return xe(e.toString(16).padStart(t*2,"0"))}function we(e,t){return br(e,t).reverse()}function H(e,t,r){let n;if(typeof t=="string")try{n=xe(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(ye(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}var Pn=e=>typeof e=="bigint"&&On<=e;function Ps(e,t,r){return Pn(e)&&Pn(t)&&Pn(r)&&t<=e&&e<r}function jt(e,t,r,n){if(!Ps(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Ls(e){let t;for(t=0;e>On;e>>=Ln,t+=1);return t}var Qt=e=>(Ln<<BigInt(e))-Ln;function Os(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=b=>new Uint8Array(b),o=b=>Uint8Array.of(b),s=n(e),i=n(e),a=0,c=()=>{s.fill(1),i.fill(0),a=0},l=(...b)=>r(i,s,...b),f=(b=n(0))=>{i=l(o(0),b),s=l(),b.length!==0&&(i=l(o(1),b),s=l())},u=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let b=0,S=[];for(;b<t;){s=l();let E=s.slice();S.push(E),b+=s.length}return pt(...S)};return(b,S)=>{c(),f(b);let E;for(;!(E=S(u()));)f();return c(),E}}function Gt(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let a=e[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}function Ee(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var ct=BigInt(0),X=BigInt(1),te=BigInt(2),Dc=BigInt(3),Rs=BigInt(4),Ns=BigInt(5),ks=BigInt(8);function z(e,t){let r=e%t;return r>=ct?r:t+r}function q(e,t,r){let n=e;for(;t-- >ct;)n*=n,n%=r;return n}function Us(e,t){if(e===ct)throw new Error("invert: expected non-zero number");if(t<=ct)throw new Error("invert: expected positive modulus, got "+t);let r=z(e,t),n=t,o=ct,s=X,i=X,a=ct;for(;r!==ct;){let l=n/r,f=n%r,u=o-i*l,x=s-a*l;n=r,r=f,o=i,s=a,i=u,a=x}if(n!==X)throw new Error("invert: does not exist");return z(o,t)}function Ms(e,t){let r=(e.ORDER+X)/Rs,n=e.pow(t,r);if(!e.eql(e.sqr(n),t))throw new Error("Cannot find square root");return n}function Pc(e,t){let r=(e.ORDER-Ns)/ks,n=e.mul(t,te),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,te),o),a=e.mul(s,e.sub(i,e.ONE));if(!e.eql(e.sqr(a),t))throw new Error("Cannot find square root");return a}function Lc(e){if(e<BigInt(3))throw new Error("sqrt is not defined for small field");let t=e-X,r=0;for(;t%te===ct;)t/=te,r++;let n=te,o=Et(e);for(;Ks(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ms;let s=o.pow(n,t),i=(t+X)/te;return function(c,l){if(c.is0(l))return l;if(Ks(c,l)!==1)throw new Error("Cannot find square root");let f=r,u=c.mul(c.ONE,s),x=c.pow(l,t),b=c.pow(l,i);for(;!c.eql(x,c.ONE);){if(c.is0(x))return c.ZERO;let S=1,E=c.sqr(x);for(;!c.eql(E,c.ONE);)if(S++,E=c.sqr(E),S===f)throw new Error("Cannot find square root");let m=X<<BigInt(f-S-1),v=c.pow(u,m);f=S,u=c.sqr(v),x=c.mul(x,u),b=c.mul(b,v)}return b}}function Oc(e){return e%Rs===Dc?Ms:e%ks===Ns?Pc:Lc(e)}var Hs=(e,t)=>(z(e,t)&X)===X,Uc=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Un(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Uc.reduce((n,o)=>(n[o]="function",n),t);return Gt(e,r),e}function Kc(e,t,r){if(r<ct)throw new Error("invalid exponent, negatives unsupported");if(r===ct)return e.ONE;if(r===X)return t;let n=e.ONE,o=t;for(;r>ct;)r&X&&(n=e.mul(n,o)),o=e.sqr(o),r>>=X;return n}function Ge(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),s),n}function Ks(e,t){let r=(e.ORDER-X)/te,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function qs(e,t){t!==void 0&&Me(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function Et(e,t,r=!1,n={}){if(e<=ct)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=qs(e,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c,l=Object.freeze({ORDER:e,isLE:r,BITS:i,BYTES:a,MASK:Qt(i),ZERO:ct,ONE:X,create:f=>z(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return ct<=f&&f<e},is0:f=>f===ct,isValidNot0:f=>!l.is0(f)&&l.isValid(f),isOdd:f=>(f&X)===X,neg:f=>z(-f,e),eql:(f,u)=>f===u,sqr:f=>z(f*f,e),add:(f,u)=>z(f+u,e),sub:(f,u)=>z(f-u,e),mul:(f,u)=>z(f*u,e),pow:(f,u)=>Kc(l,f,u),div:(f,u)=>z(f*Us(u,e),e),sqrN:f=>f*f,addN:(f,u)=>f+u,subN:(f,u)=>f-u,mulN:(f,u)=>f*u,inv:f=>Us(f,e),sqrt:s||(f=>(c||(c=Oc(e)),c(l,f))),toBytes:f=>r?we(f,a):br(f,a),fromBytes:f=>{if(f.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);return r?Jt(f):ge(f)},invertBatch:f=>Ge(l,f),cmov:(f,u,x)=>x?u:f});return Object.freeze(l)}function Vs(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function Kn(e){let t=Vs(e);return t+Math.ceil(t/2)}function zs(e,t,r=!1){let n=e.length,o=Vs(t),s=Kn(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Jt(e):ge(e),a=z(i,t-X)+X;return r?we(a,o):br(a,o)}var ve=BigInt(0),ee=BigInt(1);function Se(e,t){let r=t.negate();return e?r:t}function xr(e,t,r){let n=t==="pz"?i=>i.pz:i=>i.ez,o=Ge(e.Fp,r.map(n));return r.map((i,a)=>i.toAffine(o[a])).map(e.fromAffine)}function $s(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function Rn(e,t){$s(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=Qt(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Fs(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),c=e>>i;a>n&&(a-=s,c+=ee);let l=t*n,f=l+Math.abs(a)-1,u=a===0,x=a<0,b=t%2!==0;return{nextN:c,offset:f,isZero:u,isNeg:x,isNegF:b,offsetF:l}}function Rc(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Nc(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var Nn=new WeakMap,Zs=new WeakMap;function kn(e){return Zs.get(e)||1}function js(e){if(e!==ve)throw new Error("invalid wNAF")}function gr(e,t){return{constTimeNegate:Se,hasPrecomputes(r){return kn(r)!==1},unsafeLadder(r,n,o=e.ZERO){let s=r;for(;n>ve;)n&ee&&(o=o.add(s)),s=s.double(),n>>=ee;return o},precomputeWindow(r,n){let{windows:o,windowSize:s}=Rn(n,t),i=[],a=r,c=a;for(let l=0;l<o;l++){c=a,i.push(c);for(let f=1;f<s;f++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(r,n,o){let s=e.ZERO,i=e.BASE,a=Rn(r,t);for(let c=0;c<a.windows;c++){let{nextN:l,offset:f,isZero:u,isNeg:x,isNegF:b,offsetF:S}=Fs(o,c,a);o=l,u?i=i.add(Se(b,n[S])):s=s.add(Se(x,n[f]))}return js(o),{p:s,f:i}},wNAFUnsafe(r,n,o,s=e.ZERO){let i=Rn(r,t);for(let a=0;a<i.windows&&o!==ve;a++){let{nextN:c,offset:l,isZero:f,isNeg:u}=Fs(o,a,i);if(o=c,!f){let x=n[l];s=s.add(u?x.negate():x)}}return js(o),s},getPrecomputes(r,n,o){let s=Nn.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&(typeof o=="function"&&(s=o(s)),Nn.set(n,s))),s},wNAFCached(r,n,o){let s=kn(r);return this.wNAF(s,this.getPrecomputes(s,r,o),n)},wNAFCachedUnsafe(r,n,o,s){let i=kn(r);return i===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,r,o),n,s)},setWindowSize(r,n){$s(n,t),Zs.set(r,n),Nn.delete(r)}}}function Ws(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>ve||n>ve;)r&ee&&(s=s.add(o)),n&ee&&(i=i.add(o)),o=o.double(),r>>=ee,n>>=ee;return{p1:s,p2:i}}function wr(e,t,r,n){Rc(r,e),Nc(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,a=Ls(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let l=Qt(c),f=new Array(Number(l)+1).fill(i),u=Math.floor((t.BITS-1)/c)*c,x=i;for(let b=u;b>=0;b-=c){f.fill(i);for(let E=0;E<s;E++){let m=n[E],v=Number(m>>BigInt(b)&l);f[v]=f[v].add(r[E])}let S=i;for(let E=f.length-1,m=i;E>0;E--)m=m.add(f[E]),S=S.add(m);if(x=x.add(S),b!==0)for(let E=0;E<c;E++)x=x.double()}return x}function Gs(e,t){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return Un(t),t}else return Et(e)}function Er(e,t,r={}){if(!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>ve))throw new Error(`CURVE.${a} mus