@libp2p/floodsub
Version:
libp2p-floodsub, also known as pubsub-flood or just dumbsub, this implementation of pubsub focused on delivering an API for Publish/Subscribe, but with no CastTree Forming (it just floods the network).
2 lines • 153 kB
JavaScript
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PFloodsub = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var Libp2PFloodsub=(()=>{var Oa=Object.create;var Or=Object.defineProperty;var Na=Object.getOwnPropertyDescriptor;var Fa=Object.getOwnPropertyNames;var Ka=Object.getPrototypeOf,Ua=Object.prototype.hasOwnProperty;var Ma=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports),me=(t,e)=>{for(var r in e)Or(t,r,{get:e[r],enumerable:!0})},Ii=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Fa(e))!Ua.call(t,i)&&i!==r&&Or(t,i,{get:()=>e[i],enumerable:!(n=Na(e,i))||n.enumerable});return t};var qa=(t,e,r)=>(r=t!=null?Oa(Ka(t)):{},Ii(e||!t||!t.__esModule?Or(r,"default",{value:t,enumerable:!0}):r,t)),Va=t=>Ii(Or({},"__esModule",{value:!0}),t);var Ta=Ma((nb,wi)=>{"use strict";var Of=Object.prototype.hasOwnProperty,de="~";function Ir(){}Object.create&&(Ir.prototype=Object.create(null),new Ir().__proto__||(de=!1));function Nf(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function Ba(t,e,r,n,i){if(typeof r!="function")throw new TypeError("The listener must be a function");var s=new Nf(r,n||t,i),o=de?de+e:e;return t._events[o]?t._events[o].fn?t._events[o]=[t._events[o],s]:t._events[o].push(s):(t._events[o]=s,t._eventsCount++),t}function xn(t,e){--t._eventsCount===0?t._events=new Ir:delete t._events[e]}function he(){this._events=new Ir,this._eventsCount=0}he.prototype.eventNames=function(){var e=[],r,n;if(this._eventsCount===0)return e;for(n in r=this._events)Of.call(r,n)&&e.push(de?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(r)):e};he.prototype.listeners=function(e){var r=de?de+e:e,n=this._events[r];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,s=n.length,o=new Array(s);i<s;i++)o[i]=n[i].fn;return o};he.prototype.listenerCount=function(e){var r=de?de+e:e,n=this._events[r];return n?n.fn?1:n.length:0};he.prototype.emit=function(e,r,n,i,s,o){var a=de?de+e:e;if(!this._events[a])return!1;var c=this._events[a],u=arguments.length,f,l;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),u){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,r),!0;case 3:return c.fn.call(c.context,r,n),!0;case 4:return c.fn.call(c.context,r,n,i),!0;case 5:return c.fn.call(c.context,r,n,i,s),!0;case 6:return c.fn.call(c.context,r,n,i,s,o),!0}for(l=1,f=new Array(u-1);l<u;l++)f[l-1]=arguments[l];c.fn.apply(c.context,f)}else{var h=c.length,d;for(l=0;l<h;l++)switch(c[l].once&&this.removeListener(e,c[l].fn,void 0,!0),u){case 1:c[l].fn.call(c[l].context);break;case 2:c[l].fn.call(c[l].context,r);break;case 3:c[l].fn.call(c[l].context,r,n);break;case 4:c[l].fn.call(c[l].context,r,n,i);break;default:if(!f)for(d=1,f=new Array(u-1);d<u;d++)f[d-1]=arguments[d];c[l].fn.apply(c[l].context,f)}}return!0};he.prototype.on=function(e,r,n){return Ba(this,e,r,n,!1)};he.prototype.once=function(e,r,n){return Ba(this,e,r,n,!0)};he.prototype.removeListener=function(e,r,n,i){var s=de?de+e:e;if(!this._events[s])return this;if(!r)return xn(this,s),this;var o=this._events[s];if(o.fn)o.fn===r&&(!i||o.once)&&(!n||o.context===n)&&xn(this,s);else{for(var a=0,c=[],u=o.length;a<u;a++)(o[a].fn!==r||i&&!o[a].once||n&&o[a].context!==n)&&c.push(o[a]);c.length?this._events[s]=c.length===1?c[0]:c:xn(this,s)}return this};he.prototype.removeAllListeners=function(e){var r;return e?(r=de?de+e:e,this._events[r]&&xn(this,r)):(this._events=new Ir,this._eventsCount=0),this};he.prototype.off=he.prototype.removeListener;he.prototype.addListener=he.prototype.on;he.prefixed=de;he.EventEmitter=he;typeof wi<"u"&&(wi.exports=he)});var jf={};me(jf,{StrictNoSign:()=>Hf,StrictSign:()=>Vf,TopicValidatorResult:()=>$t,floodsub:()=>$f,isPubSub:()=>zf,protocol:()=>vi,pubSubSymbol:()=>Zt});var Zt=Symbol.for("@libp2p/pubsub");var $=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},At=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var Nr=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var J=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Fr=class extends Error{static name="NotStartedError";constructor(e="Not started"){super(e),this.name="NotStartedError"}};var ct=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var An=Symbol.for("@libp2p/peer-id");function Ha(t){return typeof t?.handleEvent=="function"}function za(t){return(t!==!0&&t!==!1&&t?.once)??!1}var It=class extends EventTarget{#e=new Map;constructor(){super()}listenerCount(e){let r=this.#e.get(e);return r==null?0:r.length}addEventListener(e,r,n){let i=za(n);super.addEventListener(e,o=>{if(i){let a=this.#e.get(o.type);a!=null&&(a=a.filter(({callback:c})=>c!==r),this.#e.set(o.type,a))}Ha(r)?r.handleEvent(o):r(o)},n);let s=this.#e.get(e);s==null&&(s=[],this.#e.set(e,s)),s.push({callback:r,once:i})}removeEventListener(e,r,n){super.removeEventListener(e.toString(),r??null,n);let i=this.#e.get(e);i!=null&&(i=i.filter(({callback:s})=>s!==r),this.#e.set(e,i))}safeDispatchEvent(e,r={}){return this.dispatchEvent(new CustomEvent(e,r))}};var Bi=Symbol.for("@libp2p/service-capabilities"),Ti=Symbol.for("@libp2p/service-dependencies");var Ln={};me(Ln,{base58btc:()=>Z,base58flickr:()=>Wa});var Sl=new Uint8Array(0);function _i(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}function Ke(t){if(t instanceof Uint8Array&&t.constructor.name==="Uint8Array")return t;if(t instanceof ArrayBuffer)return new Uint8Array(t);if(ArrayBuffer.isView(t))return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);throw new Error("Unknown type, must be binary type")}function Li(t){return new TextEncoder().encode(t)}function Di(t){return new TextDecoder().decode(t)}function $a(t,e){if(t.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 i=0;i<t.length;i++){var s=t.charAt(i),o=s.charCodeAt(0);if(r[o]!==255)throw new TypeError(s+" is ambiguous");r[o]=i}var a=t.length,c=t.charAt(0),u=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function l(m){if(m instanceof Uint8Array||(ArrayBuffer.isView(m)?m=new Uint8Array(m.buffer,m.byteOffset,m.byteLength):Array.isArray(m)&&(m=Uint8Array.from(m))),!(m instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(m.length===0)return"";for(var x=0,b=0,y=0,S=m.length;y!==S&&m[y]===0;)y++,x++;for(var I=(S-y)*f+1>>>0,k=new Uint8Array(I);y!==S;){for(var L=m[y],C=0,R=I-1;(L!==0||C<b)&&R!==-1;R--,C++)L+=256*k[R]>>>0,k[R]=L%a>>>0,L=L/a>>>0;if(L!==0)throw new Error("Non-zero carry");b=C,y++}for(var T=I-b;T!==I&&k[T]===0;)T++;for(var O=c.repeat(x);T<I;++T)O+=t.charAt(k[T]);return O}function h(m){if(typeof m!="string")throw new TypeError("Expected String");if(m.length===0)return new Uint8Array;var x=0;if(m[x]!==" "){for(var b=0,y=0;m[x]===c;)b++,x++;for(var S=(m.length-x)*u+1>>>0,I=new Uint8Array(S);m[x];){var k=r[m.charCodeAt(x)];if(k===255)return;for(var L=0,C=S-1;(k!==0||L<y)&&C!==-1;C--,L++)k+=a*I[C]>>>0,I[C]=k%256>>>0,k=k/256>>>0;if(k!==0)throw new Error("Non-zero carry");y=L,x++}if(m[x]!==" "){for(var R=S-y;R!==S&&I[R]===0;)R++;for(var T=new Uint8Array(b+(S-R)),O=b;R!==S;)T[O++]=I[R++];return T}}}function d(m){var x=h(m);if(x)return x;throw new Error(`Non-${e} character`)}return{encode:l,decodeUnsafe:h,decode:d}}var ja=$a,Za=ja,Ri=Za;var In=class{name;prefix;baseEncode;constructor(e,r,n){this.name=e,this.prefix=r,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},Bn=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,r,n){this.name=e,this.prefix=r;let i=r.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Pi(this,e)}},Tn=class{decoders;constructor(e){this.decoders=e}or(e){return Pi(this,e)}decode(e){let r=e[0],n=this.decoders[r];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Pi(t,e){return new Tn({...t.decoders??{[t.prefix]:t},...e.decoders??{[e.prefix]:e}})}var _n=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,r,n,i){this.name=e,this.prefix=r,this.baseEncode=n,this.baseDecode=i,this.encoder=new In(e,r,n),this.decoder=new Bn(e,r,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Bt({name:t,prefix:e,encode:r,decode:n}){return new _n(t,e,r,n)}function Ye({name:t,prefix:e,alphabet:r}){let{encode:n,decode:i}=Ri(r,t);return Bt({prefix:e,name:t,encode:n,decode:s=>Ke(i(s))})}function Ya(t,e,r,n){let i=t.length;for(;t[i-1]==="=";)--i;let s=new Uint8Array(i*r/8|0),o=0,a=0,c=0;for(let u=0;u<i;++u){let f=e[t[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,o+=r,o>=8&&(o-=8,s[c++]=255&a>>o)}if(o>=r||(255&a<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return s}function Ga(t,e,r){let n=e[e.length-1]==="=",i=(1<<r)-1,s="",o=0,a=0;for(let c=0;c<t.length;++c)for(a=a<<8|t[c],o+=8;o>r;)o-=r,s+=e[i&a>>o];if(o!==0&&(s+=e[i&a<<r-o]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function Xa(t){let e={};for(let r=0;r<t.length;++r)e[t[r]]=r;return e}function G({name:t,prefix:e,bitsPerChar:r,alphabet:n}){let i=Xa(n);return Bt({prefix:e,name:t,encode(s){return Ga(s,n,r)},decode(s){return Ya(s,i,r,t)}})}var Z=Ye({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Wa=Ye({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Dn={};me(Dn,{base32:()=>Tt,base32hex:()=>tc,base32hexpad:()=>nc,base32hexpadupper:()=>sc,base32hexupper:()=>rc,base32pad:()=>Qa,base32padupper:()=>ec,base32upper:()=>Ja,base32z:()=>ic});var Tt=G({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),Ja=G({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Qa=G({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),ec=G({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),tc=G({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),rc=G({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),nc=G({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),sc=G({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),ic=G({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var kn={};me(kn,{base36:()=>Yt,base36upper:()=>oc});var Yt=Ye({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),oc=Ye({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var ac=Ni,Ci=128,cc=127,uc=~cc,fc=Math.pow(2,31);function Ni(t,e,r){e=e||[],r=r||0;for(var n=r;t>=fc;)e[r++]=t&255|Ci,t/=128;for(;t&uc;)e[r++]=t&255|Ci,t>>>=7;return e[r]=t|0,Ni.bytes=r-n+1,e}var lc=Rn,hc=128,Oi=127;function Rn(t,n){var r=0,n=n||0,i=0,s=n,o,a=t.length;do{if(s>=a)throw Rn.bytes=0,new RangeError("Could not decode varint");o=t[s++],r+=i<28?(o&Oi)<<i:(o&Oi)*Math.pow(2,i),i+=7}while(o>=hc);return Rn.bytes=s-n,r}var dc=Math.pow(2,7),pc=Math.pow(2,14),mc=Math.pow(2,21),bc=Math.pow(2,28),yc=Math.pow(2,35),gc=Math.pow(2,42),wc=Math.pow(2,49),xc=Math.pow(2,56),Ec=Math.pow(2,63),vc=function(t){return t<dc?1:t<pc?2:t<mc?3:t<bc?4:t<yc?5:t<gc?6:t<wc?7:t<xc?8:t<Ec?9:10},Sc={encode:ac,decode:lc,encodingLength:vc},Ac=Sc,Gt=Ac;function Xt(t,e=0){return[Gt.decode(t,e),Gt.decode.bytes]}function _t(t,e,r=0){return Gt.encode(t,e,r),e}function Lt(t){return Gt.encodingLength(t)}function Pe(t,e){let r=e.byteLength,n=Lt(t),i=n+Lt(r),s=new Uint8Array(i+r);return _t(t,s,0),_t(r,s,n),s.set(e,i),new Dt(t,r,e,s)}function Ge(t){let e=Ke(t),[r,n]=Xt(e),[i,s]=Xt(e.subarray(n)),o=e.subarray(n+s);if(o.byteLength!==i)throw new Error("Incorrect length");return new Dt(r,i,o,e)}function Fi(t,e){if(t===e)return!0;{let r=e;return t.code===r.code&&t.size===r.size&&r.bytes instanceof Uint8Array&&_i(t.bytes,r.bytes)}}var Dt=class{code;size;digest;bytes;constructor(e,r,n,i){this.code=e,this.size=r,this.digest=n,this.bytes=i}};function Ki(t,e){let{bytes:r,version:n}=t;return n===0?Bc(r,Pn(t),e??Z.encoder):Tc(r,Pn(t),e??Tt.encoder)}var Ui=new WeakMap;function Pn(t){let e=Ui.get(t);if(e==null){let r=new Map;return Ui.set(t,r),r}return e}var ue=class t{code;version;multihash;bytes;"/";constructor(e,r,n,i){this.code=r,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}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:e,multihash:r}=this;if(e!==Wt)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==_c)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return t.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:e,digest:r}=this.multihash,n=Pe(e,r);return t.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(e){return t.equals(this,e)}static equals(e,r){let n=r;return n!=null&&e.code===n.code&&e.version===n.version&&Fi(e.multihash,n.multihash)}toString(e){return Ki(this,e)}toJSON(){return{"/":Ki(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let r=e;if(r instanceof t)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:i,multihash:s,bytes:o}=r;return new t(n,i,s,o??Mi(n,i,s.bytes))}else if(r[Lc]===!0){let{version:n,multihash:i,code:s}=r,o=Ge(i);return t.create(n,s,o)}else return null}static create(e,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(e){case 0:{if(r!==Wt)throw new Error(`Version 0 CID must use dag-pb (code: ${Wt}) block encoding`);return new t(e,r,n,n.bytes)}case 1:{let i=Mi(e,r,n.bytes);return new t(e,r,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return t.create(0,Wt,e)}static createV1(e,r){return t.create(1,e,r)}static decode(e){let[r,n]=t.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(e){let r=t.inspectBytes(e),n=r.size-r.multihashSize,i=Ke(e.subarray(n,n+r.multihashSize));if(i.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=i.subarray(r.multihashSize-r.digestSize),o=new Dt(r.multihashCode,r.digestSize,s,i);return[r.version===0?t.createV0(o):t.createV1(r.codec,o),e.subarray(r.size)]}static inspectBytes(e){let r=0,n=()=>{let[l,h]=Xt(e.subarray(r));return r+=h,l},i=n(),s=Wt;if(i===18?(i=0,r=0):s=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let o=r,a=n(),c=n(),u=r+c,f=u-o;return{version:i,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:u}}static parse(e,r){let[n,i]=Ic(e,r),s=t.decode(i);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Pn(s).set(n,e),s}};function Ic(t,e){switch(t[0]){case"Q":{let r=e??Z;return[Z.prefix,r.decode(`${Z.prefix}${t}`)]}case Z.prefix:{let r=e??Z;return[Z.prefix,r.decode(t)]}case Tt.prefix:{let r=e??Tt;return[Tt.prefix,r.decode(t)]}case Yt.prefix:{let r=e??Yt;return[Yt.prefix,r.decode(t)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[t[0],e.decode(t)]}}}function Bc(t,e,r){let{prefix:n}=r;if(n!==Z.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let i=e.get(n);if(i==null){let s=r.encode(t).slice(1);return e.set(n,s),s}else return i}function Tc(t,e,r){let{prefix:n}=r,i=e.get(n);if(i==null){let s=r.encode(t);return e.set(n,s),s}else return i}var Wt=112,_c=18;function Mi(t,e,r){let n=Lt(t),i=n+Lt(e),s=new Uint8Array(i+r.byteLength);return _t(t,s,0),_t(e,s,n),s.set(r,i),s}var Lc=Symbol.for("@ipld/js-cid/CID");var Cn={};me(Cn,{identity:()=>Be});var qi=0,Dc="identity",Vi=Ke;function kc(t,e){if(e?.truncate!=null&&e.truncate!==t.byteLength){if(e.truncate<0||e.truncate>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,e.truncate)}return Pe(qi,Vi(t))}var Be={code:qi,name:Dc,encode:Vi,digest:kc};function be(t,e){if(t===e)return!0;if(t.byteLength!==e.byteLength)return!1;for(let r=0;r<t.byteLength;r++)if(t[r]!==e[r])return!1;return!0}async function Hi(t,e,r,n){let i=await crypto.subtle.importKey("jwk",t,{name:"ECDSA",namedCurve:t.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},i,e,r.subarray());return n?.signal?.throwIfAborted(),s}function Ue(t=0){return new Uint8Array(t)}function ye(t=0){return new Uint8Array(t)}function ut(t,e){e==null&&(e=t.reduce((i,s)=>i+s.length,0));let r=ye(e),n=0;for(let i of t)r.set(i,n),n+=i.length;return r}var $i=Symbol.for("@achingbrain/uint8arraylist");function zi(t,e){if(e==null||e<0)throw new RangeError("index is out of bounds");let r=0;for(let n of t){let i=r+n.byteLength;if(e<i)return{buf:n,index:e-r};r=i}throw new RangeError("index is out of bounds")}function Ur(t){return!!t?.[$i]}var ie=class t{bufs;length;[$i]=!0;constructor(...e){this.bufs=[],this.length=0,e.length>0&&this.appendAll(e)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...e){this.appendAll(e)}appendAll(e){let r=0;for(let n of e)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Ur(n)){r+=n.byteLength;for(let i of n.bufs)this.bufs.push(i)}else throw new Error("Could not append value, must be an Uint8Array or a Uint8ArrayList");this.length+=r}prepend(...e){this.prependAll(e)}prependAll(e){let r=0;for(let n of e.reverse())if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.unshift(n);else if(Ur(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(e){let r=zi(this.bufs,e);return r.buf[r.index]}set(e,r){let n=zi(this.bufs,e);n.buf[n.index]=r}write(e,r=0){if(e instanceof Uint8Array)for(let n=0;n<e.length;n++)this.set(r+n,e[n]);else if(Ur(e))for(let n=0;n<e.length;n++)this.set(r+n,e.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(e){if(e=Math.trunc(e),!(Number.isNaN(e)||e<=0)){if(e===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(e>=this.bufs[0].byteLength)e-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(e),this.length-=e;break}}}slice(e,r){let{bufs:n,length:i}=this._subList(e,r);return ut(n,i)}subarray(e,r){let{bufs:n,length:i}=this._subList(e,r);return n.length===1?n[0]:ut(n,i)}sublist(e,r){let{bufs:n,length:i}=this._subList(e,r),s=new t;return s.length=i,s.bufs=n,s}_subList(e,r){if(e=e??0,r=r??this.length,e<0&&(e=this.length+e),r<0&&(r=this.length+r),e<0||r>this.length)throw new RangeError("index is out of bounds");if(e===r)return{bufs:[],length:0};if(e===0&&r===this.length)return{bufs:[...this.bufs],length:this.length};let n=[],i=0;for(let s=0;s<this.bufs.length;s++){let o=this.bufs[s],a=i,c=a+o.byteLength;if(i=c,e>=c)continue;let u=e>=a&&e<c,f=r>a&&r<=c;if(u&&f){if(e===a&&r===c){n.push(o);break}let l=e-a;n.push(o.subarray(l,l+(r-e)));break}if(u){if(e===0){n.push(o);continue}n.push(o.subarray(e-a));continue}if(f){if(r===c){n.push(o);break}n.push(o.subarray(0,r-a));break}n.push(o)}return{bufs:n,length:r-e}}indexOf(e,r=0){if(!Ur(e)&&!(e instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=e instanceof Uint8Array?e:e.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),e.length===0)return r>this.length?this.length:r;let i=n.byteLength;if(i===0)throw new TypeError("search must be at least 1 byte long");let s=256,o=new Int32Array(s);for(let l=0;l<s;l++)o[l]=-1;for(let l=0;l<i;l++)o[n[l]]=l;let a=o,c=this.byteLength-n.byteLength,u=n.byteLength-1,f;for(let l=r;l<=c;l+=f){f=0;for(let h=u;h>=0;h--){let d=this.get(l+h);if(n[h]!==d){f=Math.max(1,h-a[d]);break}}if(f===0)return l}return-1}getInt8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(e,r){let n=ye(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,e)}getInt16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(e,r,n){let i=Ue(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt16(0,r,n),this.write(i,e)}getInt32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(e,r,n){let i=Ue(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setInt32(0,r,n),this.write(i,e)}getBigInt64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(e,r,n){let i=Ue(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigInt64(0,r,n),this.write(i,e)}getUint8(e){let r=this.subarray(e,e+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(e,r){let n=ye(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,e)}getUint16(e,r){let n=this.subarray(e,e+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(e,r,n){let i=Ue(2);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint16(0,r,n),this.write(i,e)}getUint32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(e,r,n){let i=Ue(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setUint32(0,r,n),this.write(i,e)}getBigUint64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(e,r,n){let i=Ue(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setBigUint64(0,r,n),this.write(i,e)}getFloat32(e,r){let n=this.subarray(e,e+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(e,r,n){let i=Ue(4);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat32(0,r,n),this.write(i,e)}getFloat64(e,r){let n=this.subarray(e,e+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(e,r,n){let i=Ue(8);new DataView(i.buffer,i.byteOffset,i.byteLength).setFloat64(0,r,n),this.write(i,e)}equals(e){if(e==null||!(e instanceof t)||e.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!be(this.bufs[r],e.bufs[r]))return!1;return!0}static fromUint8Arrays(e,r){let n=new t;return n.bufs=e,r==null&&(r=e.reduce((i,s)=>i+s.byteLength,0)),n.length=r,n}};var On={};me(On,{base10:()=>Rc});var Rc=Ye({prefix:"9",name:"base10",alphabet:"0123456789"});var Nn={};me(Nn,{base16:()=>Pc,base16upper:()=>Cc});var Pc=G({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Cc=G({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Fn={};me(Fn,{base2:()=>Oc});var Oc=G({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Kn={};me(Kn,{base256emoji:()=>Mc});var ji=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}"),Nc=ji.reduce((t,e,r)=>(t[r]=e,t),[]),Fc=ji.reduce((t,e,r)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return t[n]=r,t},[]);function Kc(t){return t.reduce((e,r)=>(e+=Nc[r],e),"")}function Uc(t){let e=[];for(let r of t){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let i=Fc[n];if(i==null)throw new Error(`Non-base256emoji character: ${r}`);e.push(i)}return new Uint8Array(e)}var Mc=Bt({prefix:"\u{1F680}",name:"base256emoji",encode:Kc,decode:Uc});var Un={};me(Un,{base64:()=>qc,base64pad:()=>Vc,base64url:()=>Hc,base64urlpad:()=>zc});var qc=G({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Vc=G({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Hc=G({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),zc=G({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Mn={};me(Mn,{base8:()=>$c});var $c=G({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var qn={};me(qn,{identity:()=>jc});var jc=Bt({prefix:"\0",name:"identity",encode:t=>Di(t),decode:t=>Li(t)});var ah=new TextEncoder,ch=new TextDecoder;var zn={};me(zn,{sha256:()=>ft,sha512:()=>Xc});var Gc=20;function Hn({name:t,code:e,encode:r,minDigestLength:n,maxDigestLength:i}){return new Vn(t,e,r,n,i)}var Vn=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,r,n,i,s){this.name=e,this.code=r,this.encode=n,this.minDigestLength=i??Gc,this.maxDigestLength=s}digest(e,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(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?Zi(n,this.code,r?.truncate):n.then(i=>Zi(i,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Zi(t,e,r){if(r!=null&&r!==t.byteLength){if(r>t.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${t.byteLength}`);t=t.subarray(0,r)}return Pe(e,t)}function Gi(t){return async e=>new Uint8Array(await crypto.subtle.digest(t,e))}var ft=Hn({name:"sha2-256",code:18,encode:Gi("SHA-256")}),Xc=Hn({name:"sha2-512",code:19,encode:Gi("SHA-512")});var $n={...qn,...Fn,...Mn,...On,...Nn,...Dn,...kn,...Ln,...Un,...Kn},xh={...zn,...Cn};function Wi(t,e,r,n){return{name:t,prefix:e,encoder:{name:t,prefix:e,encode:r},decoder:{decode:n}}}var Xi=Wi("utf8","u",t=>"u"+new TextDecoder("utf8").decode(t),t=>new TextEncoder().encode(t.substring(1))),jn=Wi("ascii","a",t=>{let e="a";for(let r=0;r<t.length;r++)e+=String.fromCharCode(t[r]);return e},t=>{t=t.substring(1);let e=ye(t.length);for(let r=0;r<t.length;r++)e[r]=t.charCodeAt(r);return e}),Wc={utf8:Xi,"utf-8":Xi,hex:$n.base16,latin1:jn,ascii:jn,binary:jn,...$n},Mr=Wc;function z(t,e="utf8"){let r=Mr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.decoder.decode(`${r.prefix}${t}`)}function H(t,e="utf8"){let r=Mr[e];if(r==null)throw new Error(`Unsupported encoding "${e}"`);return r.encoder.encode(t).substring(1)}var Jc=parseInt("11111",2),Zn=parseInt("10000000",2),Qc=parseInt("01111111",2),Ji={0:Jt,1:Jt,2:eu,3:nu,4:su,5:ru,6:tu,16:Jt,22:Jt,48:Jt};function Me(t,e={offset:0}){let r=t[e.offset]&Jc;if(e.offset++,Ji[r]!=null)return Ji[r](t,e);throw new Error("No decoder for tag "+r)}function Qt(t,e){let r=0;if((t[e.offset]&Zn)===Zn){let n=t[e.offset]&Qc,i="0x";e.offset++;for(let s=0;s<n;s++,e.offset++)i+=t[e.offset].toString(16).padStart(2,"0");r=parseInt(i,16)}else r=t[e.offset],e.offset++;return r}function Jt(t,e){Qt(t,e);let r=[];for(;!(e.offset>=t.byteLength);){let n=Me(t,e);if(n===null)break;r.push(n)}return r}function eu(t,e){let r=Qt(t,e),n=e.offset,i=e.offset+r,s=[];for(let o=n;o<i;o++)o===n&&t[o]===0||s.push(t[o]);return e.offset+=r,Uint8Array.from(s)}function tu(t,e){let r=Qt(t,e),n=e.offset+r,i=t[e.offset];e.offset++;let s=0,o=0;i<40?(s=0,o=i):i<80?(s=1,o=i-40):(s=2,o=i-80);let a=`${s}.${o}`,c=[];for(;e.offset<n;){let u=t[e.offset];if(e.offset++,c.push(u&127),u<128){c.reverse();let f=0;for(let l=0;l<c.length;l++)f+=c[l]<<l*7;a+=`.${f}`,c=[]}}return a}function ru(t,e){return e.offset++,null}function nu(t,e){let r=Qt(t,e),n=t[e.offset];e.offset++;let i=t.subarray(e.offset,e.offset+r-1);if(e.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return i}function su(t,e){let r=Qt(t,e),n=t.subarray(e.offset,e.offset+r);return e.offset+=r,n}function iu(t){let e=t.toString(16);e.length%2===1&&(e="0"+e);let r=new ie;for(let n=0;n<e.length;n+=2)r.append(Uint8Array.from([parseInt(`${e[n]}${e[n+1]}`,16)]));return r}function Yn(t){if(t.byteLength<128)return Uint8Array.from([t.byteLength]);let e=iu(t.byteLength);return new ie(Uint8Array.from([e.byteLength|Zn]),e)}function ge(t){let e=new ie,r=128;return(t.subarray()[0]&r)===r&&e.append(Uint8Array.from([0])),e.append(t),new ie(Uint8Array.from([2]),Yn(e),e)}function qr(t){let e=Uint8Array.from([0]),r=new ie(e,t);return new ie(Uint8Array.from([3]),Yn(r),r)}function We(t,e=48){let r=new ie;for(let n of t)r.append(n);return new ie(Uint8Array.from([e]),Yn(r),r)}var ou=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),au=Uint8Array.from([6,5,43,129,4,0,34]),cu=Uint8Array.from([6,5,43,129,4,0,35]),uu={ext:!0,kty:"EC",crv:"P-256"},fu={ext:!0,kty:"EC",crv:"P-384"},lu={ext:!0,kty:"EC",crv:"P-521"},Gn=32,Xn=48,Wn=66;function Jn(t){let e=Me(t);return Qi(e)}function Qi(t){let e=t[1][1][0],r=1,n,i;if(e.byteLength===Gn*2+1)return n=H(e.subarray(r,r+Gn),"base64url"),i=H(e.subarray(r+Gn),"base64url"),new kt({...uu,key_ops:["verify"],x:n,y:i});if(e.byteLength===Xn*2+1)return n=H(e.subarray(r,r+Xn),"base64url"),i=H(e.subarray(r+Xn),"base64url"),new kt({...fu,key_ops:["verify"],x:n,y:i});if(e.byteLength===Wn*2+1)return n=H(e.subarray(r,r+Wn),"base64url"),i=H(e.subarray(r+Wn),"base64url"),new kt({...lu,key_ops:["verify"],x:n,y:i});throw new $(`coordinates were wrong length, got ${e.byteLength}, expected 65, 97 or 133`)}function eo(t){return We([ge(Uint8Array.from([1])),We([hu(t.crv)],160),We([qr(new ie(Uint8Array.from([4]),z(t.x??"","base64url"),z(t.y??"","base64url")))],161)]).subarray()}function hu(t){if(t==="P-256")return ou;if(t==="P-384")return au;if(t==="P-521")return cu;throw new $(`Invalid curve ${t}`)}var kt=class{type="ECDSA";jwk;_raw;constructor(e){this.jwk=e}get raw(){return this._raw==null&&(this._raw=eo(this.jwk)),this._raw}toMultihash(){return Be.digest(qe(this))}toCID(){return ue.createV1(114,this.toMultihash())}toString(){return Z.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:be(this.raw,e.raw)}async verify(e,r,n){return Hi(this.jwk,r,e,n)}};function Qn(t){return t instanceof Uint8Array||ArrayBuffer.isView(t)&&t.constructor.name==="Uint8Array"&&"BYTES_PER_ELEMENT"in t&&t.BYTES_PER_ELEMENT===1}function Je(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(`${r}expected number, got ${typeof t}`)}if(!Number.isSafeInteger(t)||t<0){let r=e&&`"${e}" `;throw new RangeError(`${r}expected integer >= 0, got ${t}`)}}function Se(t,e,r=""){let n=Qn(t),i=t?.length,s=e!==void 0;if(!n||s&&i!==e){let o=r&&`"${r}" `,a=s?` of length ${e}`:"",c=n?`length=${i}`:`type=${typeof t}`,u=o+"expected Uint8Array"+a+", got "+c;throw n?new RangeError(u):new TypeError(u)}return t}function Vr(t){if(typeof t!="function"||typeof t.create!="function")throw new TypeError("Hash must wrapped by utils.createHasher");if(Je(t.outputLen),Je(t.blockLen),t.outputLen<1)throw new Error('"outputLen" must be >= 1');if(t.blockLen<1)throw new Error('"blockLen" must be >= 1')}function Rt(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function Hr(t,e){Se(t,void 0,"digestInto() output");let r=e.outputLen;if(t.length<r)throw new RangeError('"digestInto() output" expected to be of length >='+r)}function He(...t){for(let e=0;e<t.length;e++)t[e].fill(0)}function zr(t){return new DataView(t.buffer,t.byteOffset,t.byteLength)}function Te(t,e){return t<<32-e|t>>>e}var ro=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",du=Array.from({length:256},(t,e)=>e.toString(16).padStart(2,"0"));function $r(t){if(Se(t),ro)return t.toHex();let e="";for(let r=0;r<t.length;r++)e+=du[t[r]];return e}var Ve={_0:48,_9:57,A:65,F:70,a:97,f:102};function to(t){if(t>=Ve._0&&t<=Ve._9)return t-Ve._0;if(t>=Ve.A&&t<=Ve.F)return t-(Ve.A-10);if(t>=Ve.a&&t<=Ve.f)return t-(Ve.a-10)}function er(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);if(ro)try{return Uint8Array.fromHex(t)}catch(i){throw i instanceof SyntaxError?new RangeError(i.message):i}let e=t.length,r=e/2;if(e%2)throw new RangeError("hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(r);for(let i=0,s=0;i<r;i++,s+=2){let o=to(t.charCodeAt(s)),a=to(t.charCodeAt(s+1));if(o===void 0||a===void 0){let c=t[s]+t[s+1];throw new RangeError('hex string expected, got non-hex character "'+c+'" at index '+s)}n[i]=o*16+a}return n}function es(...t){let e=0;for(let n=0;n<t.length;n++){let i=t[n];Se(i),e+=i.length}let r=new Uint8Array(e);for(let n=0,i=0;n<t.length;n++){let s=t[n];r.set(s,i),i+=s.length}return r}function ts(t,e={}){let r=(i,s)=>t(s).update(i).digest(),n=t(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.canXOF=n.canXOF,r.create=i=>t(i),Object.assign(r,e),Object.freeze(r)}function jr(t=32){Je(t,"bytesLength");let e=typeof globalThis=="object"?globalThis.crypto:null;if(typeof e?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");if(t>65536)throw new RangeError(`"bytesLength" expected <= 65536, got ${t}`);return e.getRandomValues(new Uint8Array(t))}var rs=t=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,t])});function no(t,e,r){return t&e^~t&r}function so(t,e,r){return t&e^t&r^e&r}var tr=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,r,n,i){this.blockLen=e,this.outputLen=r,this.padOffset=n,this.isLE=i,this.buffer=new Uint8Array(e),this.view=zr(this.buffer)}update(e){Rt(this),Se(e);let{view:r,buffer:n,blockLen:i}=this,s=e.length;for(let o=0;o<s;){let a=Math.min(i-this.pos,s-o);if(a===i){let c=zr(e);for(;i<=s-o;o+=i)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(r,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Rt(this),Hr(e,this),this.finished=!0;let{buffer:r,view:n,blockLen:i,isLE:s}=this,{pos:o}=this;r[o++]=128,He(this.buffer.subarray(o)),this.padOffset>i-o&&(this.process(n,0),o=0);for(let l=o;l<i;l++)r[l]=0;n.setBigUint64(i-8,BigInt(this.length*8),s),this.process(n,0);let a=zr(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let u=c/4,f=this.get();if(u>f.length)throw new Error("_sha2: outputLen bigger than state");for(let l=0;l<u;l++)a.setUint32(4*l,f[l],s)}digest(){let{buffer:e,outputLen:r}=this;this.digestInto(e);let n=e.slice(0,r);return this.destroy(),n}_cloneInto(e){e||=new this.constructor,e.set(...this.get());let{blockLen:r,buffer:n,length:i,finished:s,destroyed:o,pos:a}=this;return e.destroyed=o,e.finished=s,e.length=i,e.pos=a,i%r&&e.buffer.set(n),e}clone(){return this._cloneInto()}},ze=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ae=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Zr=BigInt(4294967295),io=BigInt(32);function pu(t,e=!1){return e?{h:Number(t&Zr),l:Number(t>>io&Zr)}:{h:Number(t>>io&Zr)|0,l:Number(t&Zr)|0}}function oo(t,e=!1){let r=t.length,n=new Uint32Array(r),i=new Uint32Array(r);for(let s=0;s<r;s++){let{h:o,l:a}=pu(t[s],e);[n[s],i[s]]=[o,a]}return[n,i]}var ns=(t,e,r)=>t>>>r,ss=(t,e,r)=>t<<32-r|e>>>r,lt=(t,e,r)=>t>>>r|e<<32-r,ht=(t,e,r)=>t<<32-r|e>>>r,rr=(t,e,r)=>t<<64-r|e>>>r-32,nr=(t,e,r)=>t>>>r-32|e<<64-r;function Ce(t,e,r,n){let i=(e>>>0)+(n>>>0);return{h:t+r+(i/2**32|0)|0,l:i|0}}var ao=(t,e,r)=>(t>>>0)+(e>>>0)+(r>>>0),co=(t,e,r,n)=>e+r+n+(t/2**32|0)|0,uo=(t,e,r,n)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0),fo=(t,e,r,n,i)=>e+r+n+i+(t/2**32|0)|0,lo=(t,e,r,n,i)=>(t>>>0)+(e>>>0)+(r>>>0)+(n>>>0)+(i>>>0),ho=(t,e,r,n,i,s)=>e+r+n+i+s+(t/2**32|0)|0;var bu=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]),Qe=new Uint32Array(64),is=class extends tr{constructor(e){super(64,e,8,!1)}get(){let{A:e,B:r,C:n,D:i,E:s,F:o,G:a,H:c}=this;return[e,r,n,i,s,o,a,c]}set(e,r,n,i,s,o,a,c){this.A=e|0,this.B=r|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,r){for(let l=0;l<16;l++,r+=4)Qe[l]=e.getUint32(r,!1);for(let l=16;l<64;l++){let h=Qe[l-15],d=Qe[l-2],m=Te(h,7)^Te(h,18)^h>>>3,x=Te(d,17)^Te(d,19)^d>>>10;Qe[l]=x+Qe[l-7]+m+Qe[l-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:u,H:f}=this;for(let l=0;l<64;l++){let h=Te(a,6)^Te(a,11)^Te(a,25),d=f+h+no(a,c,u)+bu[l]+Qe[l]|0,x=(Te(n,2)^Te(n,13)^Te(n,22))+so(n,i,s)|0;f=u,u=c,c=a,a=o+d|0,o=s,s=i,i=n,n=d+x|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,u=u+this.G|0,f=f+this.H|0,this.set(n,i,s,o,a,c,u,f)}roundClean(){He(Qe)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),He(this.buffer)}},os=class extends is{A=ze[0]|0;B=ze[1]|0;C=ze[2]|0;D=ze[3]|0;E=ze[4]|0;F=ze[5]|0;G=ze[6]|0;H=ze[7]|0;constructor(){super(32)}};var po=oo(["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(t=>BigInt(t))),yu=po[0],gu=po[1],et=new Uint32Array(80),tt=new Uint32Array(80),as=class extends tr{constructor(e){super(128,e,16,!1)}get(){let{Ah:e,Al:r,Bh:n,Bl:i,Ch:s,Cl:o,Dh:a,Dl:c,Eh:u,El:f,Fh:l,Fl:h,Gh:d,Gl:m,Hh:x,Hl:b}=this;return[e,r,n,i,s,o,a,c,u,f,l,h,d,m,x,b]}set(e,r,n,i,s,o,a,c,u,f,l,h,d,m,x,b){this.Ah=e|0,this.Al=r|0,this.Bh=n|0,this.Bl=i|0,this.Ch=s|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=u|0,this.El=f|0,this.Fh=l|0,this.Fl=h|0,this.Gh=d|0,this.Gl=m|0,this.Hh=x|0,this.Hl=b|0}process(e,r){for(let I=0;I<16;I++,r+=4)et[I]=e.getUint32(r),tt[I]=e.getUint32(r+=4);for(let I=16;I<80;I++){let k=et[I-15]|0,L=tt[I-15]|0,C=lt(k,L,1)^lt(k,L,8)^ns(k,L,7),R=ht(k,L,1)^ht(k,L,8)^ss(k,L,7),T=et[I-2]|0,O=tt[I-2]|0,V=lt(T,O,19)^rr(T,O,61)^ns(T,O,6),N=ht(T,O,19)^nr(T,O,61)^ss(T,O,6),p=uo(R,N,tt[I-7],tt[I-16]),g=fo(p,C,V,et[I-7],et[I-16]);et[I]=g|0,tt[I]=p|0}let{Ah:n,Al:i,Bh:s,Bl:o,Ch:a,Cl:c,Dh:u,Dl:f,Eh:l,El:h,Fh:d,Fl:m,Gh:x,Gl:b,Hh:y,Hl:S}=this;for(let I=0;I<80;I++){let k=lt(l,h,14)^lt(l,h,18)^rr(l,h,41),L=ht(l,h,14)^ht(l,h,18)^nr(l,h,41),C=l&d^~l&x,R=h&m^~h&b,T=lo(S,L,R,gu[I],tt[I]),O=ho(T,y,k,C,yu[I],et[I]),V=T|0,N=lt(n,i,28)^rr(n,i,34)^rr(n,i,39),p=ht(n,i,28)^nr(n,i,34)^nr(n,i,39),g=n&s^n&a^s&a,v=i&o^i&c^o&c;y=x|0,S=b|0,x=d|0,b=m|0,d=l|0,m=h|0,{h:l,l:h}=Ce(u|0,f|0,O|0,V|0),u=a|0,f=c|0,a=s|0,c=o|0,s=n|0,o=i|0;let E=ao(V,p,v);n=co(E,O,N,g),i=E|0}({h:n,l:i}=Ce(this.Ah|0,this.Al|0,n|0,i|0)),{h:s,l:o}=Ce(this.Bh|0,this.Bl|0,s|0,o|0),{h:a,l:c}=Ce(this.Ch|0,this.Cl|0,a|0,c|0),{h:u,l:f}=Ce(this.Dh|0,this.Dl|0,u|0,f|0),{h:l,l:h}=Ce(this.Eh|0,this.El|0,l|0,h|0),{h:d,l:m}=Ce(this.Fh|0,this.Fl|0,d|0,m|0),{h:x,l:b}=Ce(this.Gh|0,this.Gl|0,x|0,b|0),{h:y,l:S}=Ce(this.Hh|0,this.Hl|0,y|0,S|0),this.set(n,i,s,o,a,c,u,f,l,h,d,m,x,b,y,S)}roundClean(){He(et,tt)}destroy(){this.destroyed=!0,He(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},cs=class extends as{Ah=ae[0]|0;Al=ae[1]|0;Bh=ae[2]|0;Bl=ae[3]|0;Ch=ae[4]|0;Cl=ae[5]|0;Dh=ae[6]|0;Dl=ae[7]|0;Eh=ae[8]|0;El=ae[9]|0;Fh=ae[10]|0;Fl=ae[11]|0;Gh=ae[12]|0;Gl=ae[13]|0;Hh=ae[14]|0;Hl=ae[15]|0;constructor(){super(64)}};var Pt=ts(()=>new os,rs(1));var Yr=ts(()=>new cs,rs(3));var U=(t,e,r)=>Se(t,e,r),fs=Je,Ct=$r,re=(...t)=>es(...t),Ot=t=>er(t),dt=Qn,sr=t=>jr(t),Xr=BigInt(0),us=BigInt(1);function _e(t,e=""){if(typeof t!="boolean"){let r=e&&`"${e}" `;throw new TypeError(r+"expected boolean, got type="+typeof t)}return t}function Wr(t){if(typeof t=="bigint"){if(!Gr(t))throw new RangeError("positive bigint expected, got "+t)}else fs(t);return t}function Le(t,e=""){if(typeof t!="number"){let r=e&&`"${e}" `;throw new TypeError(r+"expected number, got type="+typeof t)}if(!Number.isSafeInteger(t)){let r=e&&`"${e}" `;throw new RangeError(r+"expected safe integer, got "+t)}}function ir(t){let e=Wr(t).toString(16);return e.length&1?"0"+e:e}function mo(t){if(typeof t!="string")throw new TypeError("hex string expected, got "+typeof t);return t===""?Xr:BigInt("0x"+t)}function pt(t){return mo($r(t))}function Oe(t){return mo($r(or(Se(t)).reverse()))}function Jr(t,e){if(Je(e),e===0)throw new RangeError("zero length");t=Wr(t);let r=t.toString(16);if(r.length>e*2)throw new RangeError("number too large");return er(r.padStart(e*2,"0"))}function ls(t,e){return Jr(t,e).reverse()}function bo(t,e){if(t=U(t),e=U(e),t.length!==e.length)return!1;let r=0;for(let n=0;n<t.length;n++)r|=t[n]^e[n];return r===0}function or(t){return Uint8Array.from(U(t))}function Qr(t){if(typeof t!="string")throw new TypeError("ascii string expected, got "+typeof t);return Uint8Array.from(t,(e,r)=>{let n=e.charCodeAt(0);if(e.length!==1||n>127)throw new RangeError(`string contains non-ASCII character "${t[r]}" with code ${n} at position ${r}`);return n})}var Gr=t=>typeof t=="bigint"&&Xr<=t;function wu(t,e,r){return Gr(t)&&Gr(e)&&Gr(r)&&e<=t&&t<r}function Nt(t,e,r,n){if(!wu(e,r,n))throw new RangeError("expected valid "+t+": "+r+" <= n < "+n+", got "+e)}function Ft(t){if(t<Xr)throw new Error("expected non-negative bigint, got "+t);let e;for(e=0;t>Xr;t>>=us,e+=1);return e}var ar=t=>(us<<BigInt(t))-us;function yo(t,e,r){if(Je(t,"hashLen"),Je(e,"qByteLen"),typeof r!="function")throw new TypeError("hmacFn must be a function");let n=b=>new Uint8Array(b),i=Uint8Array.of(),s=Uint8Array.of(0),o=Uint8Array.of(1),a=1e3,c=n(t),u=n(t),f=0,l=()=>{c.fill(1),u.fill(0),f=0},h=(...b)=>r(u,re(c,...b)),d=(b=i)=>{u=h(s,b),c=h(),b.length!==0&&(u=h(o,b),c=h())},m=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let b=0,y=[];for(;b<e;){c=h();let S=c.slice();y.push(S),b+=c.length}return re(...y)};return(b,y)=>{l(),d(b);let S;for(;(S=y(m()))===void 0;)d();return l(),S}}function De(t,e={},r={}){if(Object.prototype.toString.call(t)!=="[object Object]")throw new TypeError("expected valid options object");function n(s,o,a){if(!a&&o!=="function"&&!Object.hasOwn(t,s))throw new TypeError(`param "${s}" is invalid: expected own property`);let c=t[s];if(a&&c===void 0)return;let u=typeof c;if(u!==o||c===null)throw new TypeError(`param "${s}" is invalid: expected ${o}, got ${u}`)}let i=(s,o)=>Object.entries(s).forEach(([a,c])=>n(a,c,o));i(e,!1),i(r,!0)}var hs=()=>{throw new Error("not implemented")};var ce=BigInt(0),X=BigInt(1),mt=BigInt(2),Eo=BigInt(3),vo=BigInt(4),So=BigInt(5),xu=BigInt(7),Ao=BigInt(8),Eu=BigInt(9),Io=BigInt(16);function Q(t,e){if(e<=ce)throw new Error("mod: expected positive modulus, got "+e);let r=t%e;return r>=ce?r:e+r}function j(t,e,r){if(e<ce)throw new Error("pow2: expected non-negative exponent, got "+e);let n=t;for(;e-- >ce;)n*=n,n%=r;return n}function go(t,e){if(t===ce)throw new Error("invert: expected non-zero number");if(e<=ce)throw new Error("invert: expected positive modulus, got "+e);let r=Q(t,e),n=e,i=ce,s=X,o=X,a=ce;for(;r!==ce;){let u=n/r,f=n-r*u,l=i-o*u,h=s-a*u;n=r,r=f,i=o,s=a,o=l,a=h}if(n!==X)throw new Error("invert: does not exist");return Q(i,e)}function ds(t,e,r){let n=t;if(!n.eql(n.sqr(e),r))throw new Error("Cannot find square root")}function Bo(t,e){let r=t,n=(r.ORDER+X)/vo,i=r.pow(e,n);return ds(r,i,e),i}function vu(t,e){let r=t,n=(r.ORDER-So)/Ao,i=r.mul(e,mt),s=r.pow(i,n),o=r.mul(e,s),a=r.mul(r.mul(o,mt),s),c=r.mul(o,r.sub(a,r.ONE));return ds(r,c,e),c}function Su(t){let e=Kt(t),r=To(t),n=r(e,e.neg(e.ONE)),i=r(e,n),s=r(e,e.neg(n)),o=(t+xu)/Io;return((a,c)=>{let u=a,f=u.pow(c,o),l=u.mul(f,n),h=u.mul(f,i),d=u.mul(f,s),m=u.eql(u.sqr(l),c),x=u.eql(u.sqr(h),c);f=u.cmov(f,l,m),l=u.cmov(d,h,x);let b=u.eql(u.sqr(l),c),y=u.cmov(f,l,b);return ds(u,y,c),y})}function To(t){if(t<Eo)throw new Error("sqrt is not defined for small field");let e=t-X,r=0;for(;e%mt===ce;)e/=mt,r++;let n=mt,i=Kt(t);for(;wo(i,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Bo;let s=i.pow(n,e),o=(e+X)/mt;return function(c,u){let f=c;if(f.is0(u))return u;if(wo(f,u)!==1)throw new Error("Cannot find square root");let l=r,h=f.mul(f.ONE,s),d=f.pow(u,e),m=f.pow(u,o);for(;!f.eql(d,f.ONE);){if(f.is0(d))return f.ZERO;let x=1,b=f.sqr(d);for(;!f.eql(b,f.ONE);)if(x++,b=f.sqr(b),x===l)throw new Error("Cannot find square root");let y=X<<BigInt(l-x-1),S=f.pow(h,y);l=