UNPKG

@libp2p/pubsub

Version:
2 lines • 139 kB
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PPubsub = factory()}(typeof self !== 'undefined' ? self : this, function () { "use strict";var Libp2PPubsub=(()=>{var Ra=Object.create;var Tr=Object.defineProperty;var Na=Object.getOwnPropertyDescriptor;var Ua=Object.getOwnPropertyNames;var ka=Object.getPrototypeOf,Ma=Object.prototype.hasOwnProperty;var Oa=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),yt=(e,t)=>{for(var r in t)Tr(e,r,{get:t[r],enumerable:!0})},ws=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Ua(t))!Ma.call(e,o)&&o!==r&&Tr(e,o,{get:()=>t[o],enumerable:!(n=Na(t,o))||n.enumerable});return e};var qa=(e,t,r)=>(r=e!=null?Ra(ka(e)):{},ws(t||!e||!e.__esModule?Tr(r,"default",{value:e,enumerable:!0}):r,e)),Ha=e=>ws(Tr({},"__esModule",{value:!0}),e);var wa=Oa((Sm,fs)=>{"use strict";var kf=Object.prototype.hasOwnProperty,pt="~";function Er(){}Object.create&&(Er.prototype=Object.create(null),new Er().__proto__||(pt=!1));function Mf(e,t,r){this.fn=e,this.context=t,this.once=r||!1}function ga(e,t,r,n,o){if(typeof r!="function")throw new TypeError("The listener must be a function");var s=new Mf(r,n||e,o),i=pt?pt+t:t;return e._events[i]?e._events[i].fn?e._events[i]=[e._events[i],s]:e._events[i].push(s):(e._events[i]=s,e._eventsCount++),e}function dn(e,t){--e._eventsCount===0?e._events=new Er:delete e._events[t]}function lt(){this._events=new Er,this._eventsCount=0}lt.prototype.eventNames=function(){var t=[],r,n;if(this._eventsCount===0)return t;for(n in r=this._events)kf.call(r,n)&&t.push(pt?n.slice(1):n);return Object.getOwnPropertySymbols?t.concat(Object.getOwnPropertySymbols(r)):t};lt.prototype.listeners=function(t){var r=pt?pt+t:t,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i};lt.prototype.listenerCount=function(t){var r=pt?pt+t:t,n=this._events[r];return n?n.fn?1:n.length:0};lt.prototype.emit=function(t,r,n,o,s,i){var c=pt?pt+t:t;if(!this._events[c])return!1;var a=this._events[c],f=arguments.length,p,l;if(a.fn){switch(a.once&&this.removeListener(t,a.fn,void 0,!0),f){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,r),!0;case 3:return a.fn.call(a.context,r,n),!0;case 4:return a.fn.call(a.context,r,n,o),!0;case 5:return a.fn.call(a.context,r,n,o,s),!0;case 6:return a.fn.call(a.context,r,n,o,s,i),!0}for(l=1,p=new Array(f-1);l<f;l++)p[l-1]=arguments[l];a.fn.apply(a.context,p)}else{var u=a.length,h;for(l=0;l<u;l++)switch(a[l].once&&this.removeListener(t,a[l].fn,void 0,!0),f){case 1:a[l].fn.call(a[l].context);break;case 2:a[l].fn.call(a[l].context,r);break;case 3:a[l].fn.call(a[l].context,r,n);break;case 4:a[l].fn.call(a[l].context,r,n,o);break;default:if(!p)for(h=1,p=new Array(f-1);h<f;h++)p[h-1]=arguments[h];a[l].fn.apply(a[l].context,p)}}return!0};lt.prototype.on=function(t,r,n){return ga(this,t,r,n,!1)};lt.prototype.once=function(t,r,n){return ga(this,t,r,n,!0)};lt.prototype.removeListener=function(t,r,n,o){var s=pt?pt+t:t;if(!this._events[s])return this;if(!r)return dn(this,s),this;var i=this._events[s];if(i.fn)i.fn===r&&(!o||i.once)&&(!n||i.context===n)&&dn(this,s);else{for(var c=0,a=[],f=i.length;c<f;c++)(i[c].fn!==r||o&&!i[c].once||n&&i[c].context!==n)&&a.push(i[c]);a.length?this._events[s]=a.length===1?a[0]:a:dn(this,s)}return this};lt.prototype.removeAllListeners=function(t){var r;return t?(r=pt?pt+t:t,this._events[r]&&dn(this,r)):(this._events=new Er,this._eventsCount=0),this};lt.prototype.off=lt.prototype.removeListener;lt.prototype.addListener=lt.prototype.on;lt.prefixed=pt;lt.EventEmitter=lt;typeof fs<"u"&&(fs.exports=lt)});var Gf={};yt(Gf,{PubSubBaseProtocol:()=>ys});var En=Symbol.for("@libp2p/peer-id");var Ge;(function(e){e.Accept="accept",e.Ignore="ignore",e.Reject="reject"})(Ge||(Ge={}));var Yf=Symbol.for("@libp2p/pubsub");var Z=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},Se=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var Cr=class extends Error{static name="InvalidMultihashError";constructor(t="Invalid Multihash"){super(t),this.name="InvalidMultihashError"}};var Q=class extends Error{static name="InvalidMessageError";constructor(t="Invalid message"){super(t),this.name="InvalidMessageError"}};var Dr=class extends Error{static name="NotStartedError";constructor(t="Not started"){super(t),this.name="NotStartedError"}};var ue=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var ve=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 In={};yt(In,{base58btc:()=>j,base58flickr:()=>Ya});var Jf=new Uint8Array(0);function xs(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Pt(e){if(e instanceof Uint8Array&&e.constructor.name==="Uint8Array")return e;if(e instanceof ArrayBuffer)return new Uint8Array(e);if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength);throw new Error("Unknown type, must be binary type")}function Es(e){return new TextEncoder().encode(e)}function Ss(e){return new TextDecoder().decode(e)}function Va(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var c=e.length,a=e.charAt(0),f=Math.log(c)/Math.log(256),p=Math.log(256)/Math.log(c);function l(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var E=0,S=0,b=0,A=d.length;b!==A&&d[b]===0;)b++,E++;for(var w=(A-b)*p+1>>>0,L=new Uint8Array(w);b!==A;){for(var P=d[b],M=0,k=w-1;(P!==0||M<S)&&k!==-1;k--,M++)P+=256*L[k]>>>0,L[k]=P%c>>>0,P=P/c>>>0;if(P!==0)throw new Error("Non-zero carry");S=M,b++}for(var R=w-S;R!==w&&L[R]===0;)R++;for(var x=a.repeat(E);R<w;++R)x+=e.charAt(L[R]);return x}function u(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var E=0;if(d[E]!==" "){for(var S=0,b=0;d[E]===a;)S++,E++;for(var A=(d.length-E)*f+1>>>0,w=new Uint8Array(A);d[E];){var L=r[d.charCodeAt(E)];if(L===255)return;for(var P=0,M=A-1;(L!==0||P<b)&&M!==-1;M--,P++)L+=c*w[M]>>>0,w[M]=L%256>>>0,L=L/256>>>0;if(L!==0)throw new Error("Non-zero carry");b=P,E++}if(d[E]!==" "){for(var k=A-b;k!==A&&w[k]===0;)k++;for(var R=new Uint8Array(S+(A-k)),x=S;k!==A;)R[x++]=w[k++];return R}}}function h(d){var E=u(d);if(E)return E;throw new Error(`Non-${t} character`)}return{encode:l,decodeUnsafe:u,decode:h}}var Fa=Va,za=Fa,As=za;var Sn=class{name;prefix;baseEncode;constructor(t,r,n){this.name=t,this.prefix=r,this.baseEncode=n}encode(t){if(t instanceof Uint8Array)return`${this.prefix}${this.baseEncode(t)}`;throw Error("Unknown type, must be binary type")}},vn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let 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 Bs(this,t)}},An=class{decoders;constructor(t){this.decoders=t}or(t){return Bs(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 Bs(e,t){return new An({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Bn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Sn(t,r,n),this.decoder=new vn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ae({name:e,prefix:t,encode:r,decode:n}){return new Bn(e,t,r,n)}function Xt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=As(r,e);return Ae({prefix:t,name:e,encode:n,decode:s=>Pt(o(s))})}function Ga(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,c=0,a=0;for(let f=0;f<o;++f){let p=t[e[f]];if(p===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<r|p,i+=r,i>=8&&(i-=8,s[a++]=255&c>>i)}if(i>=r||(255&c<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function Za(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,c=0;for(let a=0;a<e.length;++a)for(c=c<<8|e[a],i+=8;i>r;)i-=r,s+=t[o&c>>i];if(i!==0&&(s+=t[o&c<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function ja(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function W({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=ja(n);return Ae({prefix:t,name:e,encode(s){return Za(s,n,r)},decode(s){return Ga(s,o,r,e)}})}var j=Xt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Ya=Xt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var _n={};yt(_n,{base32:()=>Be,base32hex:()=>Ja,base32hexpad:()=>tc,base32hexpadupper:()=>ec,base32hexupper:()=>Qa,base32pad:()=>Xa,base32padupper:()=>Wa,base32upper:()=>$a,base32z:()=>rc});var Be=W({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),$a=W({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Xa=W({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Wa=W({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),Ja=W({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Qa=W({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),tc=W({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),ec=W({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),rc=W({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Ln={};yt(Ln,{base36:()=>Ze,base36upper:()=>nc});var Ze=Xt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),nc=Xt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var oc=Ls,Is=128,sc=127,ic=~sc,ac=Math.pow(2,31);function Ls(e,t,r){t=t||[],r=r||0;for(var n=r;e>=ac;)t[r++]=e&255|Is,e/=128;for(;e&ic;)t[r++]=e&255|Is,e>>>=7;return t[r]=e|0,Ls.bytes=r-n+1,t}var cc=Tn,uc=128,_s=127;function Tn(e,n){var r=0,n=n||0,o=0,s=n,i,c=e.length;do{if(s>=c)throw Tn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&_s)<<o:(i&_s)*Math.pow(2,o),o+=7}while(i>=uc);return Tn.bytes=s-n,r}var fc=Math.pow(2,7),lc=Math.pow(2,14),hc=Math.pow(2,21),dc=Math.pow(2,28),pc=Math.pow(2,35),mc=Math.pow(2,42),yc=Math.pow(2,49),bc=Math.pow(2,56),gc=Math.pow(2,63),wc=function(e){return e<fc?1:e<lc?2:e<hc?3:e<dc?4:e<pc?5:e<mc?6:e<yc?7:e<bc?8:e<gc?9:10},xc={encode:oc,decode:cc,encodingLength:wc},Ec=xc,je=Ec;function Ye(e,t=0){return[je.decode(e,t),je.decode.bytes]}function Ie(e,t,r=0){return je.encode(e,t,r),t}function _e(e){return je.encodingLength(e)}function Tt(e,t){let r=t.byteLength,n=_e(e),o=n+_e(r),s=new Uint8Array(o+r);return Ie(e,s,0),Ie(r,s,n),s.set(t,o),new Le(e,r,t,s)}function Wt(e){let t=Pt(e),[r,n]=Ye(t),[o,s]=Ye(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Le(r,o,i,t)}function Ts(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&xs(e.bytes,r.bytes)}}var Le=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Cs(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return vc(r,Cn(e),t??j.encoder);default:return Ac(r,Cn(e),t??Be.encoder)}}var Ds=new WeakMap;function Cn(e){let t=Ds.get(e);if(t==null){let r=new Map;return Ds.set(e,r),r}return t}var at=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==$e)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Bc)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=Tt(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&&Ts(t.multihash,n.multihash)}toString(t){return Cs(this,t)}toJSON(){return{"/":Cs(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??Ps(n,o,s.bytes))}else if(r[Ic]===!0){let{version:n,multihash:o,code:s}=r,i=Wt(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!==$e)throw new Error(`Version 0 CID must use dag-pb (code: ${$e}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Ps(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,$e,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=Pt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Le(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[l,u]=Ye(t.subarray(r));return r+=u,l},o=n(),s=$e;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,c=n(),a=n(),f=r+a,p=f-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:p,size:f}}static parse(t,r){let[n,o]=Sc(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 Sc(e,t){switch(e[0]){case"Q":{let r=t??j;return[j.prefix,r.decode(`${j.prefix}${e}`)]}case j.prefix:{let r=t??j;return[j.prefix,r.decode(e)]}case Be.prefix:{let r=t??Be;return[Be.prefix,r.decode(e)]}case Ze.prefix:{let r=t??Ze;return[Ze.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function vc(e,t,r){let{prefix:n}=r;if(n!==j.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 Ac(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 $e=112,Bc=18;function Ps(e,t,r){let n=_e(e),o=n+_e(t),s=new Uint8Array(o+r.byteLength);return Ie(e,s,0),Ie(t,s,n),s.set(r,o),s}var Ic=Symbol.for("@ipld/js-cid/CID");var Dn={};yt(Dn,{identity:()=>Bt});var Ks=0,_c="identity",Rs=Pt;function Lc(e,t){if(t?.truncate!=null&&t.truncate!==e.byteLength){if(t.truncate<0||t.truncate>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,t.truncate)}return Tt(Ks,Rs(e))}var Bt={code:Ks,name:_c,encode:Rs,digest:Lc};function bt(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function Kt(e=0){return new Uint8Array(e)}function ct(e=0){return new Uint8Array(e)}function fe(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=ct(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Us=Symbol.for("@achingbrain/uint8arraylist");function Ns(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 Kr(e){return!!e?.[Us]}var rt=class e{bufs;length;[Us]=!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(Kr(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(Kr(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=Ns(this.bufs,t);return r.buf[r.index]}set(t,r){let n=Ns(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(Kr(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 fe(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:fe(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],c=o,a=c+i.byteLength;if(o=a,t>=a)continue;let f=t>=c&&t<a,p=r>c&&r<=a;if(f&&p){if(t===c&&r===a){n.push(i);break}let l=t-c;n.push(i.subarray(l,l+(r-t)));break}if(f){if(t===0){n.push(i);continue}n.push(i.subarray(t-c));continue}if(p){if(r===a){n.push(i);break}n.push(i.subarray(0,r-c));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Kr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let l=0;l<s;l++)i[l]=-1;for(let l=0;l<o;l++)i[n[l]]=l;let c=i,a=this.byteLength-n.byteLength,f=n.byteLength-1,p;for(let l=r;l<=a;l+=p){p=0;for(let u=f;u>=0;u--){let h=this.get(l+u);if(n[u]!==h){p=Math.max(1,u-c[h]);break}}if(p===0)return l}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ct(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=Kt(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=Kt(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=Kt(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=ct(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=Kt(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=Kt(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=Kt(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=Kt(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=Kt(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(!bt(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 Pn={};yt(Pn,{base10:()=>Tc});var Tc=Xt({prefix:"9",name:"base10",alphabet:"0123456789"});var Kn={};yt(Kn,{base16:()=>Cc,base16upper:()=>Dc});var Cc=W({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Dc=W({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Rn={};yt(Rn,{base2:()=>Pc});var Pc=W({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Nn={};yt(Nn,{base256emoji:()=>kc});var ks=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}"),Kc=ks.reduce((e,t,r)=>(e[r]=t,e),[]),Rc=ks.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function Nc(e){return e.reduce((t,r)=>(t+=Kc[r],t),"")}function Uc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Rc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var kc=Ae({prefix:"\u{1F680}",name:"base256emoji",encode:Nc,decode:Uc});var Un={};yt(Un,{base64:()=>Mc,base64pad:()=>Oc,base64url:()=>qc,base64urlpad:()=>Hc});var Mc=W({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Oc=W({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),qc=W({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Hc=W({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var kn={};yt(kn,{base8:()=>Vc});var Vc=W({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Mn={};yt(Mn,{identity:()=>Fc});var Fc=Ae({prefix:"\0",name:"identity",encode:e=>Ss(e),decode:e=>Es(e)});var Nl=new TextEncoder,Ul=new TextDecoder;var Hn={};yt(Hn,{sha256:()=>le,sha512:()=>jc});var Zc=20;function qn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:o}){return new On(e,t,r,n,o)}var On=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,o,s){this.name=t,this.code=r,this.encode=n,this.minDigestLength=o??Zc,this.maxDigestLength=s}digest(t,r){if(r?.truncate!=null){if(r.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&r.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(t instanceof Uint8Array){let n=this.encode(t);return n instanceof Uint8Array?Ms(n,this.code,r?.truncate):n.then(o=>Ms(o,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Ms(e,t,r){if(r!=null&&r!==e.byteLength){if(r>e.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${e.byteLength}`);e=e.subarray(0,r)}return Tt(t,e)}function qs(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var le=qn({name:"sha2-256",code:18,encode:qs("SHA-256")}),jc=qn({name:"sha2-512",code:19,encode:qs("SHA-512")});var Vn={...Mn,...Rn,...kn,...Pn,...Kn,..._n,...Ln,...In,...Un,...Nn},Yl={...Hn,...Dn};function Vs(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Hs=Vs("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Fn=Vs("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=ct(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),Yc={utf8:Hs,"utf-8":Hs,hex:Vn.base16,latin1:Fn,ascii:Fn,binary:Fn,...Vn},Rr=Yc;function F(e,t="utf8"){let r=Rr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function z(e,t="utf8"){let r=Rr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var $c=parseInt("11111",2),zn=parseInt("10000000",2),Xc=parseInt("01111111",2),Fs={0:Xe,1:Xe,2:Wc,3:tu,4:eu,5:Qc,6:Jc,16:Xe,22:Xe,48:Xe};function Rt(e,t={offset:0}){let r=e[t.offset]&$c;if(t.offset++,Fs[r]!=null)return Fs[r](e,t);throw new Error("No decoder for tag "+r)}function We(e,t){let r=0;if((e[t.offset]&zn)===zn){let n=e[t.offset]&Xc,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function Xe(e,t){We(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Rt(e,t);if(n===null)break;r.push(n)}return r}function Wc(e,t){let r=We(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function Jc(e,t){let r=We(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let c=`${s}.${i}`,a=[];for(;t.offset<n;){let f=e[t.offset];if(t.offset++,a.push(f&127),f<128){a.reverse();let p=0;for(let l=0;l<a.length;l++)p+=a[l]<<l*7;c+=`.${p}`,a=[]}}return c}function Qc(e,t){return t.offset++,null}function tu(e,t){let r=We(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function eu(e,t){let r=We(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function ru(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new rt;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Gn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=ru(e.byteLength);return new rt(Uint8Array.from([t.byteLength|zn]),t)}function gt(e){let t=new rt,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new rt(Uint8Array.from([2]),Gn(t),t)}function Nr(e){let t=Uint8Array.from([0]),r=new rt(t,e);return new rt(Uint8Array.from([3]),Gn(r),r)}function Qt(e,t=48){let r=new rt;for(let n of e)r.append(n);return new rt(Uint8Array.from([t]),Gn(r),r)}async function zs(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 nu=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),ou=Uint8Array.from([6,5,43,129,4,0,34]),su=Uint8Array.from([6,5,43,129,4,0,35]),iu={ext:!0,kty:"EC",crv:"P-256"},au={ext:!0,kty:"EC",crv:"P-384"},cu={ext:!0,kty:"EC",crv:"P-521"},Zn=32,jn=48,Yn=66;function $n(e){let t=Rt(e);return Gs(t)}function Gs(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Zn*2+1)return n=z(t.subarray(r,r+Zn),"base64url"),o=z(t.subarray(r+Zn),"base64url"),new Te({...iu,key_ops:["verify"],x:n,y:o});if(t.byteLength===jn*2+1)return n=z(t.subarray(r,r+jn),"base64url"),o=z(t.subarray(r+jn),"base64url"),new Te({...au,key_ops:["verify"],x:n,y:o});if(t.byteLength===Yn*2+1)return n=z(t.subarray(r,r+Yn),"base64url"),o=z(t.subarray(r+Yn),"base64url"),new Te({...cu,key_ops:["verify"],x:n,y:o});throw new Z(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Zs(e){return Qt([gt(Uint8Array.from([1])),Qt([uu(e.crv)],160),Qt([Nr(new rt(Uint8Array.from([4]),F(e.x??"","base64url"),F(e.y??"","base64url")))],161)]).subarray()}function uu(e){if(e==="P-256")return nu;if(e==="P-384")return ou;if(e==="P-521")return su;throw new Z(`Invalid curve ${e}`)}var Te=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Zs(this.jwk)),this._raw}toMultihash(){return Bt.digest(Nt(this))}toCID(){return at.createV1(114,this.toMultihash())}toString(){return j.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:bt(this.raw,t.raw)}async verify(t,r,n){return zs(this.jwk,r,t,n)}};var he=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function kt(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Je(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function wt(e,...t){if(!kt(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 Ur(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");Je(e.outputLen),Je(e.blockLen)}function De(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 Ys(e,t){wt(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function Mt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function kr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function It(e,t){return e<<32-t|e>>>t}var $s=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",fu=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function vt(e){if(wt(e),$s)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=fu[e[r]];return t}var Ut={_0:48,_9:57,A:65,F:70,a:97,f:102};function js(e){if(e>=Ut._0&&e<=Ut._9)return e-Ut._0;if(e>=Ut.A&&e<=Ut.F)return e-(Ut.A-10);if(e>=Ut.a&&e<=Ut.f)return e-(Ut.a-10)}function de(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if($s)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=js(e.charCodeAt(s)),c=js(e.charCodeAt(s+1));if(i===void 0||c===void 0){let a=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+a+'" at index '+s)}n[o]=i*16+c}return n}function Xn(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Qe(e){return typeof e=="string"&&(e=Xn(e)),wt(e),e}function ht(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];wt(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var Ce=class{};function Wn(e){let t=n=>e().update(Qe(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function te(e=32){if(he&&typeof he.getRandomValues=="function")return he.getRandomValues(new Uint8Array(e));if(he&&typeof he.randomBytes=="function")return Uint8Array.from(he.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function lu(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),c=Number(r&s),a=n?4:0,f=n?0:4;e.setUint32(t+a,i,n),e.setUint32(t+f,c,n)}function Xs(e,t,r){return e&t^~e&r}function Ws(e,t,r){return e&t^e&r^t&r}var tr=class extends Ce{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=kr(this.buffer)}update(t){De(this),t=Qe(t),wt(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let c=Math.min(o-this.pos,s-i);if(c===o){let a=kr(t);for(;o<=s-i;i+=o)this.process(a,i);continue}n.set(t.subarray(i,i+c),this.pos),this.pos+=c,i+=c,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){De(this),Ys(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,Mt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let l=i;l<o;l++)r[l]=0;lu(n,o-8,BigInt(this.length*8),s),this.process(n,0);let c=kr(t),a=this.outputLen;if(a%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let f=a/4,p=this.get();if(f>p.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<f;l++)c.setUint32(4*l,p[l],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:c}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=c,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ot=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var st=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Mr=BigInt(4294967295),Js=BigInt(32);function hu(e,t=!1){return t?{h:Number(e&Mr),l:Number(e>>Js&Mr)}:{h:Number(e>>Js&Mr)|0,l:Number(e&Mr)|0}}function Qs(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:c}=hu(e[s],t);[n[s],o[s]]=[i,c]}return[n,o]}var Jn=(e,t,r)=>e>>>r,Qn=(e,t,r)=>e<<32-r|t>>>r,pe=(e,t,r)=>e>>>r|t<<32-r,me=(e,t,r)=>e<<32-r|t>>>r,er=(e,t,r)=>e<<64-r|t>>>r-32,rr=(e,t,r)=>e>>>r-32|t<<64-r;function Ct(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ti=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),ei=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,ri=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ni=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,oi=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),si=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var pu=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]),ee=new Uint32Array(64),Or=class extends tr{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:c,H:a}=this;return[t,r,n,o,s,i,c,a]}set(t,r,n,o,s,i,c,a){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=c|0,this.H=a|0}process(t,r){for(let l=0;l<16;l++,r+=4)ee[l]=t.getUint32(r,!1);for(let l=16;l<64;l++){let u=ee[l-15],h=ee[l-2],d=It(u,7)^It(u,18)^u>>>3,E=It(h,17)^It(h,19)^h>>>10;ee[l]=E+ee[l-7]+d+ee[l-16]|0}let{A:n,B:o,C:s,D:i,E:c,F:a,G:f,H:p}=this;for(let l=0;l<64;l++){let u=It(c,6)^It(c,11)^It(c,25),h=p+u+Xs(c,a,f)+pu[l]+ee[l]|0,E=(It(n,2)^It(n,13)^It(n,22))+Ws(n,o,s)|0;p=f,f=a,a=c,c=i+h|0,i=s,s=o,o=n,n=h+E|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,c=c+this.E|0,a=a+this.F|0,f=f+this.G|0,p=p+this.H|0,this.set(n,o,s,i,c,a,f,p)}roundClean(){Mt(ee)}destroy(){this.set(0,0,0,0,0,0,0,0),Mt(this.buffer)}};var ii=Qs(["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))),mu=ii[0],yu=ii[1],re=new Uint32Array(80),ne=new Uint32Array(80),to=class extends tr{constructor(t=64){super(128,t,16,!1),this.Ah=st[0]|0,this.Al=st[1]|0,this.Bh=st[2]|0,this.Bl=st[3]|0,this.Ch=st[4]|0,this.Cl=st[5]|0,this.Dh=st[6]|0,this.Dl=st[7]|0,this.Eh=st[8]|0,this.El=st[9]|0,this.Fh=st[10]|0,this.Fl=st[11]|0,this.Gh=st[12]|0,this.Gl=st[13]|0,this.Hh=st[14]|0,this.Hl=st[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:c,Dl:a,Eh:f,El:p,Fh:l,Fl:u,Gh:h,Gl:d,Hh:E,Hl:S}=this;return[t,r,n,o,s,i,c,a,f,p,l,u,h,d,E,S]}set(t,r,n,o,s,i,c,a,f,p,l,u,h,d,E,S){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=c|0,this.Dl=a|0,this.Eh=f|0,this.El=p|0,this.Fh=l|0,this.Fl=u|0,this.Gh=h|0,this.Gl=d|0,this.Hh=E|0,this.Hl=S|0}process(t,r){for(let w=0;w<16;w++,r+=4)re[w]=t.getUint32(r),ne[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let L=re[w-15]|0,P=ne[w-15]|0,M=pe(L,P,1)^pe(L,P,8)^Jn(L,P,7),k=me(L,P,1)^me(L,P,8)^Qn(L,P,7),R=re[w-2]|0,x=ne[w-2]|0,T=pe(R,x,19)^er(R,x,61)^Jn(R,x,6),N=me(R,x,19)^rr(R,x,61)^Qn(R,x,6),C=ri(k,N,ne[w-7],ne[w-16]),g=ni(C,M,T,re[w-7],re[w-16]);re[w]=g|0,ne[w]=C|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:c,Cl:a,Dh:f,Dl:p,Eh:l,El:u,Fh:h,Fl:d,Gh:E,Gl:S,Hh:b,Hl:A}=this;for(let w=0;w<80;w++){let L=pe(l,u,14)^pe(l,u,18)^er(l,u,41),P=me(l,u,14)^me(l,u,18)^rr(l,u,41),M=l&h^~l&E,k=u&d^~u&S,R=oi(A,P,k,yu[w],ne[w]),x=si(R,b,L,M,mu[w],re[w]),T=R|0,N=pe(n,o,28)^er(n,o,34)^er(n,o,39),C=me(n,o,28)^rr(n,o,34)^rr(n,o,39),g=n&s^n&c^s&c,m=o&i^o&a^i&a;b=E|0,A=S|0,E=h|0,S=d|0,h=l|0,d=u|0,{h:l,l:u}=Ct(f|0,p|0,x|0,T|0),f=c|0,p=a|0,c=s|0,a=i|0,s=n|0,i=o|0;let y=ti(T,C,m);n=ei(y,x,N,g),o=y|0}({h:n,l:o}=Ct(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ct(this.Bh|0,this.Bl|0,s|0,i|0),{h:c,l:a}=Ct(this.Ch|0,this.Cl|0,c|0,a|0),{h:f,l:p}=Ct(this.Dh|0,this.Dl|0,f|0,p|0),{h:l,l:u}=Ct(this.Eh|0,this.El|0,l|0,u|0),{h,l:d}=Ct(this.Fh|0,this.Fl|0,h|0,d|0),{h:E,l:S}=Ct(this.Gh|0,this.Gl|0,E|0,S|0),{h:b,l:A}=Ct(this.Hh|0,this.Hl|0,b|0,A|0),this.set(n,o,s,i,c,a,f,p,l,u,h,d,E,S,b,A)}roundClean(){Mt(re,ne)}destroy(){Mt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var qr=Wn(()=>new Or);var ai=Wn(()=>new to);var no=BigInt(0),ro=BigInt(1);function qt(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}"`;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function xt(e,t,r=""){let n=kt(e),o=e?.length,s=t!==void 0;if(!n||s&&o!==t){let i=r&&`"${r}" `,c=s?` of length ${t}`:"",a=n?`length=${o}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+c+", got "+a)}return e}function nr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function ci(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?no:BigInt("0x"+e)}function Pe(e){return ci(vt(e))}function Ht(e){return wt(e),ci(vt(Uint8Array.from(e).reverse()))}function Hr(e,t){return de(e.toString(16).padStart(t*2,"0"))}function oo(e,t){return Hr(e,t).reverse()}function H(e,t,r){let n;if(typeof t=="string")try{n=de(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(kt(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}function ui(e,t){if(e.length!==t.length)return!1;let r=0;for(let n=0;n<e.length;n++)r|=e[n]^t[n];return r===0}function so(e){return Uint8Array.from(e)}var eo=e=>typeof e=="bigint"&&no<=e;function fi(e,t,r){return eo(e)&&eo(t)&&eo(r)&&t<=e&&e<r}function or(e,t,r,n){if(!fi(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function Vr(e){let t;for(t=0;e>no;e>>=ro,t+=1);return t}var oe=e=>(ro<<BigInt(e))-ro;function li(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=h=>new Uint8Array(h),o=h=>Uint8Array.of(h),s=n(e),i=n(e),c=0,a=()=>{s.fill(1),i.fill(0),c=0},f=(...h)=>r(i,s,...h),p=(h=n(0))=>{i=f(o(0),h),s=f(),h.length!==0&&(i=f(o(1),h),s=f())},l=()=>{if(c++>=1e3)throw new Error("drbg: tried 1000 values");let h=0,d=[];for(;h<t;){s=f();let E=s.slice();d.push(E),h+=s.length}return ht(...d)};return(h,d)=>{a(),p(h);let E;for(;!(E=d(l()));)p();return a(),E}}function se(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let c=e[o];if(i&&c===void 0)return;let a=typeof c;if(a!==s||c===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${a}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}var io=()=>{throw new Error("not implemented")};function Ke(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 dt=BigInt(0),nt=BigInt(1),ye=BigInt(2),pi=BigInt(3),mi=BigInt(4),yi=BigInt(5),bu=BigInt(7),bi=BigInt(8),gu=BigInt(9),gi=BigInt(16);function J(e,t){let r=e%t;return r>=dt?r:t+r}function G(e,t,r){let n=e;for(;t-- >dt;)n*=n,n%=r;return n}function hi(e,t){if(e===dt)throw new Error("invert: expected non-zero number");if(t<=dt)throw new Error("invert: expected positive modulus, got "+t);let r=J(e,t),n=t,o=dt,s=nt,i=nt,c=dt;for(;r!==dt;){let f=n/r,p=n%r,l=o-i*f,u=s-c*f;n=r,r=p,o=i,s=c,i=l,c=u}if(n!==nt)throw new Error("invert: does not exist");return J(o,t)}function ao(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function wi(e,t){let r=(e.ORDER+nt)/mi,n=e.pow(t,r);return ao(e,n,t),n}function wu(e,t){let r=(e.ORDER-yi)/bi,n=e.mul(t,ye),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,ye),o),c=e.mul(s,e.sub(i,e.ONE));return ao(e,c,t),c}function xu(e){let t=Et(e),r=xi(e),n=r(t,t.neg(t.ONE)),o=r(t,n),s=r(t,t.neg(n)),i=(e+bu)/gi;return(c,a)=>{let f=c.pow(a,i),p=c.mul(f,n),l=c.mul(f,o),u=c.mul(f,s),h=c.eql(c.sqr(p),a),d=c.eql(c.sqr(l),a);f=c.cmov(f,p,h),p=c.cmov(u,l,d);let E=c.eql(c.sqr(p),a),S=c.cmov(f,p,E);return ao(c,S,a),S}}function xi(e){if(e<pi)throw new Error("sqrt is not defined for small field");let t=e-nt,r=0;for(;t%ye===dt;)t/=ye,r++;let n=ye,o=Et(e);for(;di(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return wi;let s=o.pow(n,t),i=(t+nt)/ye;return function(a,f){if(a.is0(f))return f;if(di(a,f)!==1)throw new Error("Cannot find square root");let p=r,l=a.mul(a.ONE,s),u=a.pow(f,t),h=a.pow(f,i);for(;!a.eql(u,a.ONE);){if(a.is0(u))return a.ZERO;let d=1,E=a.sqr(u);for(;!a.eql(E,a.ONE);)if(d++,E=a.sqr(E),d===p)throw new Error("Cannot find square root");let S=nt<<BigInt(p-d-1),b=a.pow(l,S);p=d,l=a.sqr(b),u=a.mul(u,l),h=a.mul(h,b)}return h}}function Eu(e){return e%mi===pi?wi:e%bi===yi?wu:e%gi===gu?xu(e):xi(e)}var Vt=(e,t)=>(J(e,t)&nt)===nt,Su=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function co(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=Su.reduce((n,o)=>(n[o]="function",n),t);return se(e,r),e}function vu(e,t,r){if(r<dt)throw new Error("invalid exponent, negatives unsupported");if(r===dt)return e.ONE;if(r===nt)return t;let n=e.ONE,o=t;for(;r>dt;)r&nt&&(n=e.mul(n,o)),o=e.sqr(o),r>>=nt;return n}function sr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,c,a)=>e.is0(c)?i:(n[a]=i,e.mul(i,c)),e.ONE),s=e.inv(o);return t.reduceRight((i,c,a)=>e.is0(c)?i:(n[a]=e.mul(i,n[a]),e.mul(i,c)),s),n}function di(e,t){let r=(e.ORDER-nt)/ye,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.