@chainsafe/libp2p-noise
Version:
Noise libp2p handshake for js-libp2p
2 lines • 147 kB
JavaScript
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.ChainsafeLibp2PNoise = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var ChainsafeLibp2PNoise=(()=>{var xn=Object.defineProperty;var ec=Object.getOwnPropertyDescriptor;var rc=Object.getOwnPropertyNames;var nc=Object.prototype.hasOwnProperty;var gt=(e,t)=>{for(var r in t)xn(e,r,{get:t[r],enumerable:!0})},sc=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of rc(t))!nc.call(e,s)&&s!==r&&xn(e,s,{get:()=>t[s],enumerable:!(n=ec(t,s))||n.enumerable});return e};var oc=e=>sc(xn({},"__esModule",{value:!0}),e);var lh={};gt(lh,{noise:()=>hh,pureJsCrypto:()=>mn});var Lr=class extends Error{static name="UnexpectedPeerError";constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError"}},Ir=class extends Error{static name="InvalidCryptoExchangeError";constructor(t="Invalid crypto exchange"){super(t),this.name="InvalidCryptoExchangeError"}},Q=class extends Error{static name="InvalidParametersError";constructor(t="Invalid parameters"){super(t),this.name="InvalidParametersError"}},xe=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var _r=class extends Error{static name="StreamResetError";constructor(t="The stream has been reset"){super(t),this.name="StreamResetError"}};var ee=class extends Error{static name="StreamStateError";constructor(t="The stream is in an invalid state"){super(t),this.name="StreamStateError"}},We=class extends Error{static name="StreamBufferError";constructor(t="The stream buffer was full"){super(t),this.name="StreamBufferError"}};var we=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Rr=class extends Event{data;constructor(t,r){super("message",r),this.data=t}},Ee=class extends Event{error;local;constructor(t,r,n){super("close",n),this.error=r,this.local=t}},Tr=class extends Ee{constructor(t,r){super(!0,t,r)}},Kr=class extends Ee{constructor(t,r){super(!1,t,r)}};var wn=Symbol.for("@libp2p/peer-id");var Cr=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 s=this.#t.get(t);s==null&&(s=[],this.#t.set(t,s)),s.push({callback:r,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(t,r,n){super.removeEventListener(t.toString(),r??null,n);let s=this.#t.get(t);s!=null&&(s=s.filter(({callback:o})=>o!==r),this.#t.set(t,s))}dispatchEvent(t){let r=super.dispatchEvent(t),n=this.#t.get(t.type);return n==null||(n=n.filter(({once:s})=>!s),this.#t.set(t.type,n)),r}safeDispatchEvent(t,r={}){return this.dispatchEvent(new CustomEvent(t,r))}};var To=Symbol.for("@libp2p/service-capabilities"),bh=Symbol.for("@libp2p/service-dependencies");var Bn={};gt(Bn,{base58btc:()=>rt,base58flickr:()=>lc});var zh=new Uint8Array(0);function Ko(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 Dt(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 Co(e){return new TextEncoder().encode(e)}function Do(e){return new TextDecoder().decode(e)}function ic(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 s=0;s<e.length;s++){var o=e.charAt(s),i=o.charCodeAt(0);if(r[i]!==255)throw new TypeError(o+" is ambiguous");r[i]=s}var a=e.length,c=e.charAt(0),h=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function u(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 S=0,l=0,g=0,B=d.length;g!==B&&d[g]===0;)g++,S++;for(var w=(B-g)*f+1>>>0,K=new Uint8Array(w);g!==B;){for(var P=d[g],M=0,O=w-1;(P!==0||M<l)&&O!==-1;O--,M++)P+=256*K[O]>>>0,K[O]=P%a>>>0,P=P/a>>>0;if(P!==0)throw new Error("Non-zero carry");l=M,g++}for(var L=w-l;L!==w&&K[L]===0;)L++;for(var A=c.repeat(S);L<w;++L)A+=e.charAt(K[L]);return A}function b(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var S=0;if(d[S]!==" "){for(var l=0,g=0;d[S]===c;)l++,S++;for(var B=(d.length-S)*h+1>>>0,w=new Uint8Array(B);d[S];){var K=r[d.charCodeAt(S)];if(K===255)return;for(var P=0,M=B-1;(K!==0||P<g)&&M!==-1;M--,P++)K+=a*w[M]>>>0,w[M]=K%256>>>0,K=K/256>>>0;if(K!==0)throw new Error("Non-zero carry");g=P,S++}if(d[S]!==" "){for(var O=B-g;O!==B&&w[O]===0;)O++;for(var L=new Uint8Array(l+(B-O)),A=l;O!==B;)L[A++]=w[O++];return L}}}function y(d){var S=b(d);if(S)return S;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:b,decode:y}}var ac=ic,cc=ac,No=cc;var En=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")}},Sn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let s=r.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 ko(this,t)}},An=class{decoders;constructor(t){this.decoders=t}or(t){return ko(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 ko(e,t){return new An({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var vn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,s){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=s,this.encoder=new En(t,r,n),this.decoder=new Sn(t,r,s)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Se({name:e,prefix:t,encode:r,decode:n}){return new vn(e,t,r,n)}function zt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:s}=No(r,e);return Se({prefix:t,name:e,encode:n,decode:o=>Dt(s(o))})}function fc(e,t,r,n){let s=e.length;for(;e[s-1]==="=";)--s;let o=new Uint8Array(s*r/8|0),i=0,a=0,c=0;for(let h=0;h<s;++h){let f=t[e[h]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<r|f,i+=r,i>=8&&(i-=8,o[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return o}function uc(e,t,r){let n=t[t.length-1]==="=",s=(1<<r)-1,o="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,o+=t[s&a>>i];if(i!==0&&(o+=t[s&a<<r-i]),n)for(;(o.length*r&7)!==0;)o+="=";return o}function hc(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function tt({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let s=hc(n);return Se({prefix:t,name:e,encode(o){return uc(o,n,r)},decode(o){return fc(o,s,r,e)}})}var rt=zt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),lc=zt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ln={};gt(Ln,{base32:()=>Ae,base32hex:()=>yc,base32hexpad:()=>bc,base32hexpadupper:()=>xc,base32hexupper:()=>gc,base32pad:()=>pc,base32padupper:()=>mc,base32upper:()=>dc,base32z:()=>wc});var Ae=tt({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),dc=tt({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),pc=tt({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),mc=tt({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),yc=tt({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),gc=tt({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),bc=tt({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),xc=tt({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),wc=tt({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var In={};gt(In,{base36:()=>Xe,base36upper:()=>Ec});var Xe=zt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Ec=zt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var Sc=Oo,Po=128,Ac=127,vc=~Ac,Bc=Math.pow(2,31);function Oo(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Bc;)t[r++]=e&255|Po,e/=128;for(;e&vc;)t[r++]=e&255|Po,e>>>=7;return t[r]=e|0,Oo.bytes=r-n+1,t}var Lc=_n,Ic=128,Mo=127;function _n(e,n){var r=0,n=n||0,s=0,o=n,i,a=e.length;do{if(o>=a)throw _n.bytes=0,new RangeError("Could not decode varint");i=e[o++],r+=s<28?(i&Mo)<<s:(i&Mo)*Math.pow(2,s),s+=7}while(i>=Ic);return _n.bytes=o-n,r}var _c=Math.pow(2,7),Rc=Math.pow(2,14),Tc=Math.pow(2,21),Kc=Math.pow(2,28),Cc=Math.pow(2,35),Dc=Math.pow(2,42),Uc=Math.pow(2,49),Nc=Math.pow(2,56),kc=Math.pow(2,63),Pc=function(e){return e<_c?1:e<Rc?2:e<Tc?3:e<Kc?4:e<Cc?5:e<Dc?6:e<Uc?7:e<Nc?8:e<kc?9:10},Mc={encode:Sc,decode:Lc,encodingLength:Pc},Oc=Mc,Je=Oc;function Qe(e,t=0){return[Je.decode(e,t),Je.decode.bytes]}function ve(e,t,r=0){return Je.encode(e,t,r),t}function Be(e){return Je.encodingLength(e)}function It(e,t){let r=t.byteLength,n=Be(e),s=n+Be(r),o=new Uint8Array(s+r);return ve(e,o,0),ve(r,o,n),o.set(t,s),new Le(e,r,t,o)}function Rn(e){let t=Dt(e),[r,n]=Qe(t),[s,o]=Qe(t.subarray(n)),i=t.subarray(n+o);if(i.byteLength!==s)throw new Error("Incorrect length");return new Le(r,s,i,t)}function Ho(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ko(e.bytes,r.bytes)}}var Le=class{code;size;digest;bytes;constructor(t,r,n,s){this.code=t,this.size=r,this.digest=n,this.bytes=s}};function qo(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return qc(r,Tn(e),t??rt.encoder);default:return Vc(r,Tn(e),t??Ae.encoder)}}var Vo=new WeakMap;function Tn(e){let t=Vo.get(e);if(t==null){let r=new Map;return Vo.set(e,r),r}return t}var lt=class e{code;version;multihash;bytes;"/";constructor(t,r,n,s){this.code=r,this.version=t,this.multihash=n,this.bytes=s,this["/"]=s}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!==tr)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Fc)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=It(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&&Ho(t.multihash,n.multihash)}toString(t){return qo(this,t)}toJSON(){return{"/":qo(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:s,multihash:o,bytes:i}=r;return new e(n,s,o,i??Fo(n,s,o.bytes))}else if(r[zc]===!0){let{version:n,multihash:s,code:o}=r,i=Rn(s);return e.create(n,o,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!==tr)throw new Error(`Version 0 CID must use dag-pb (code: ${tr}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let s=Fo(t,r,n.bytes);return new e(t,r,n,s)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,tr,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,s=Dt(t.subarray(n,n+r.multihashSize));if(s.byteLength!==r.multihashSize)throw new Error("Incorrect length");let o=s.subarray(r.multihashSize-r.digestSize),i=new Le(r.multihashCode,r.digestSize,o,s);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[u,b]=Qe(t.subarray(r));return r+=b,u},s=n(),o=tr;if(s===18?(s=0,r=0):o=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let i=r,a=n(),c=n(),h=r+c,f=h-i;return{version:s,codec:o,multihashCode:a,digestSize:c,multihashSize:f,size:h}}static parse(t,r){let[n,s]=Hc(t,r),o=e.decode(s);if(o.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Tn(o).set(n,t),o}};function Hc(e,t){switch(e[0]){case"Q":{let r=t??rt;return[rt.prefix,r.decode(`${rt.prefix}${e}`)]}case rt.prefix:{let r=t??rt;return[rt.prefix,r.decode(e)]}case Ae.prefix:{let r=t??Ae;return[Ae.prefix,r.decode(e)]}case Xe.prefix:{let r=t??Xe;return[Xe.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 qc(e,t,r){let{prefix:n}=r;if(n!==rt.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let s=t.get(n);if(s==null){let o=r.encode(e).slice(1);return t.set(n,o),o}else return s}function Vc(e,t,r){let{prefix:n}=r,s=t.get(n);if(s==null){let o=r.encode(e);return t.set(n,o),o}else return s}var tr=112,Fc=18;function Fo(e,t,r){let n=Be(e),s=n+Be(t),o=new Uint8Array(s+r.byteLength);return ve(e,o,0),ve(t,o,n),o.set(r,s),o}var zc=Symbol.for("@ipld/js-cid/CID");var Kn={};gt(Kn,{identity:()=>_t});var zo=0,Gc="identity",Go=Dt;function $c(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 It(zo,Go(e))}var _t={code:zo,name:Gc,encode:Go,digest:$c};function mt(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 st(e=0){return new Uint8Array(e)}function ft(e=0){return new Uint8Array(e)}function re(e,t){t==null&&(t=e.reduce((s,o)=>s+o.length,0));let r=ft(t),n=0;for(let s of e)r.set(s,n),n+=s.length;return r}var Zo=Symbol.for("@achingbrain/uint8arraylist");function $o(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let s=r+n.byteLength;if(t<s)return{buf:n,index:t-r};r=s}throw new RangeError("index is out of bounds")}function Ur(e){return!!e?.[Zo]}var $=class e{bufs;length;[Zo]=!0;constructor(...t){this.bufs=[],this.length=0,t.length>0&&this.appendAll(t)}*[Symbol.iterator](){yield*this.bufs}get byteLength(){return this.length}append(...t){this.appendAll(t)}appendAll(t){let r=0;for(let n of t)if(n instanceof Uint8Array)r+=n.byteLength,this.bufs.push(n);else if(Ur(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(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(t){let r=$o(this.bufs,t);return r.buf[r.index]}set(t,r){let n=$o(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(Ur(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:s}=this._subList(t,r);return re(n,s)}subarray(t,r){let{bufs:n,length:s}=this._subList(t,r);return n.length===1?n[0]:re(n,s)}sublist(t,r){let{bufs:n,length:s}=this._subList(t,r),o=new e;return o.length=s,o.bufs=[...n],o}_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=[],s=0;for(let o=0;o<this.bufs.length;o++){let i=this.bufs[o],a=s,c=a+i.byteLength;if(s=c,t>=c)continue;let h=t>=a&&t<c,f=r>a&&r<=c;if(h&&f){if(t===a&&r===c){n.push(i);break}let u=t-a;n.push(i.subarray(u,u+(r-t)));break}if(h){if(t===0){n.push(i);continue}n.push(i.subarray(t-a));continue}if(f){if(r===c){n.push(i);break}n.push(i.subarray(0,r-a));break}n.push(i)}return{bufs:n,length:r-t}}indexOf(t,r=0){if(!Ur(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 s=n.byteLength;if(s===0)throw new TypeError("search must be at least 1 byte long");let o=256,i=new Int32Array(o);for(let u=0;u<o;u++)i[u]=-1;for(let u=0;u<s;u++)i[n[u]]=u;let a=i,c=this.byteLength-n.byteLength,h=n.byteLength-1,f;for(let u=r;u<=c;u+=f){f=0;for(let b=h;b>=0;b--){let y=this.get(u+b);if(n[b]!==y){f=Math.max(1,b-a[y]);break}}if(f===0)return u}return-1}getInt8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getInt8(0)}setInt8(t,r){let n=ft(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 s=st(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt16(0,r,n),this.write(s,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 s=st(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setInt32(0,r,n),this.write(s,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 s=st(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigInt64(0,r,n),this.write(s,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=ft(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 s=st(2);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint16(0,r,n),this.write(s,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 s=st(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setUint32(0,r,n),this.write(s,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 s=st(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setBigUint64(0,r,n),this.write(s,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 s=st(4);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat32(0,r,n),this.write(s,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 s=st(8);new DataView(s.buffer,s.byteOffset,s.byteLength).setFloat64(0,r,n),this.write(s,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(!mt(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((s,o)=>s+o.byteLength,0)),n.length=r,n}};var Cn={};gt(Cn,{base10:()=>jc});var jc=zt({prefix:"9",name:"base10",alphabet:"0123456789"});var Dn={};gt(Dn,{base16:()=>Yc,base16upper:()=>Wc});var Yc=tt({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Wc=tt({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Un={};gt(Un,{base2:()=>Xc});var Xc=tt({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Nn={};gt(Nn,{base256emoji:()=>rf});var jo=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}"),Jc=jo.reduce((e,t,r)=>(e[r]=t,e),[]),Qc=jo.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function tf(e){return e.reduce((t,r)=>(t+=Jc[r],t),"")}function ef(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let s=Qc[n];if(s==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(s)}return new Uint8Array(t)}var rf=Se({prefix:"\u{1F680}",name:"base256emoji",encode:tf,decode:ef});var kn={};gt(kn,{base64:()=>nf,base64pad:()=>sf,base64url:()=>of,base64urlpad:()=>af});var nf=tt({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),sf=tt({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),of=tt({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),af=tt({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Pn={};gt(Pn,{base8:()=>cf});var cf=tt({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Mn={};gt(Mn,{identity:()=>ff});var ff=Se({prefix:"\0",name:"identity",encode:e=>Do(e),decode:e=>Co(e)});var Ll=new TextEncoder,Il=new TextDecoder;var qn={};gt(qn,{sha256:()=>Nr,sha512:()=>df});var lf=20;function Hn({name:e,code:t,encode:r,minDigestLength:n,maxDigestLength:s}){return new On(e,t,r,n,s)}var On=class{name;code;encode;minDigestLength;maxDigestLength;constructor(t,r,n,s,o){this.name=t,this.code=r,this.encode=n,this.minDigestLength=s??lf,this.maxDigestLength=o}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?Yo(n,this.code,r?.truncate):n.then(s=>Yo(s,this.code,r?.truncate))}else throw Error("Unknown type, must be binary type")}};function Yo(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 It(t,e)}function Xo(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Nr=Hn({name:"sha2-256",code:18,encode:Xo("SHA-256")}),df=Hn({name:"sha2-512",code:19,encode:Xo("SHA-512")});var Vn={...Mn,...Un,...Pn,...Cn,...Dn,...Ln,...In,...Bn,...kn,...Nn},Ol={...qn,...Kn};function Qo(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Jo=Qo("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Fn=Qo("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=ft(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),pf={utf8:Jo,"utf-8":Jo,hex:Vn.base16,latin1:Fn,ascii:Fn,binary:Fn,...Vn},kr=pf;function W(e,t="utf8"){let r=kr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function Z(e,t="utf8"){let r=kr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var mf=parseInt("11111",2),zn=parseInt("10000000",2),yf=parseInt("01111111",2),ti={0:er,1:er,2:gf,3:wf,4:Ef,5:xf,6:bf,16:er,22:er,48:er};function Ut(e,t={offset:0}){let r=e[t.offset]&mf;if(t.offset++,ti[r]!=null)return ti[r](e,t);throw new Error("No decoder for tag "+r)}function rr(e,t){let r=0;if((e[t.offset]&zn)===zn){let n=e[t.offset]&yf,s="0x";t.offset++;for(let o=0;o<n;o++,t.offset++)s+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(s,16)}else r=e[t.offset],t.offset++;return r}function er(e,t){rr(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Ut(e,t);if(n===null)break;r.push(n)}return r}function gf(e,t){let r=rr(e,t),n=t.offset,s=t.offset+r,o=[];for(let i=n;i<s;i++)i===n&&e[i]===0||o.push(e[i]);return t.offset+=r,Uint8Array.from(o)}function bf(e,t){let r=rr(e,t),n=t.offset+r,s=e[t.offset];t.offset++;let o=0,i=0;s<40?(o=0,i=s):s<80?(o=1,i=s-40):(o=2,i=s-80);let a=`${o}.${i}`,c=[];for(;t.offset<n;){let h=e[t.offset];if(t.offset++,c.push(h&127),h<128){c.reverse();let f=0;for(let u=0;u<c.length;u++)f+=c[u]<<u*7;a+=`.${f}`,c=[]}}return a}function xf(e,t){return t.offset++,null}function wf(e,t){let r=rr(e,t),n=e[t.offset];t.offset++;let s=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 s}function Ef(e,t){let r=rr(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function Sf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new $;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=Sf(e.byteLength);return new $(Uint8Array.from([t.byteLength|zn]),t)}function bt(e){let t=new $,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new $(Uint8Array.from([2]),Gn(t),t)}function Pr(e){let t=Uint8Array.from([0]),r=new $(t,e);return new $(Uint8Array.from([3]),Gn(r),r)}function Gt(e,t=48){let r=new $;for(let n of e)r.append(n);return new $(Uint8Array.from([t]),Gn(r),r)}async function ei(e,t,r,n){let s=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let o=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},s,t,r.subarray());return n?.signal?.throwIfAborted(),o}var Af=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),vf=Uint8Array.from([6,5,43,129,4,0,34]),Bf=Uint8Array.from([6,5,43,129,4,0,35]),Lf={ext:!0,kty:"EC",crv:"P-256"},If={ext:!0,kty:"EC",crv:"P-384"},_f={ext:!0,kty:"EC",crv:"P-521"},$n=32,Zn=48,jn=66;function ri(e){let t=Ut(e);return ni(t)}function ni(e){let t=e[1][1][0],r=1,n,s;if(t.byteLength===$n*2+1)return n=Z(t.subarray(r,r+$n),"base64url"),s=Z(t.subarray(r+$n),"base64url"),new _e({...Lf,key_ops:["verify"],x:n,y:s});if(t.byteLength===Zn*2+1)return n=Z(t.subarray(r,r+Zn),"base64url"),s=Z(t.subarray(r+Zn),"base64url"),new _e({...If,key_ops:["verify"],x:n,y:s});if(t.byteLength===jn*2+1)return n=Z(t.subarray(r,r+jn),"base64url"),s=Z(t.subarray(r+jn),"base64url"),new _e({..._f,key_ops:["verify"],x:n,y:s});throw new Q(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function si(e){return Gt([bt(Uint8Array.from([1])),Gt([Rf(e.crv)],160),Gt([Pr(new $(Uint8Array.from([4]),W(e.x??"","base64url"),W(e.y??"","base64url")))],161)]).subarray()}function Rf(e){if(e==="P-256")return Af;if(e==="P-384")return vf;if(e==="P-521")return Bf;throw new Q(`Invalid curve ${e}`)}var _e=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=si(this.jwk)),this._raw}toMultihash(){return _t.digest($t(this))}toCID(){return lt.createV1(114,this.toMultihash())}toString(){return rt.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:mt(this.raw,t.raw)}async verify(t,r,n){return ei(this.jwk,r,t,n)}};function ne(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function Et(e,t=""){if(!Number.isSafeInteger(e)||e<0){let r=t&&`"${t}" `;throw new Error(`${r}expected integer >= 0, got ${e}`)}}function H(e,t,r=""){let n=ne(e),s=e?.length,o=t!==void 0;if(!n||o&&s!==t){let i=r&&`"${r}" `,a=o?` of length ${t}`:"",c=n?`length=${s}`:`type=${typeof e}`;throw new Error(i+"expected Uint8Array"+a+", got "+c)}return e}function se(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash must wrapped by utils.createHasher");Et(e.outputLen),Et(e.blockLen)}function Re(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 ii(e,t){H(e,void 0,"digestInto() output");let r=t.outputLen;if(e.length<r)throw new Error('"digestInto() output" expected to be of length >='+r)}function At(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Mr(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function vt(e,t){return e<<32-t|e>>>t}var ai=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",Tf=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function kt(e){if(H(e),ai)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=Tf[e[r]];return t}var Nt={_0:48,_9:57,A:65,F:70,a:97,f:102};function oi(e){if(e>=Nt._0&&e<=Nt._9)return e-Nt._0;if(e>=Nt.A&&e<=Nt.F)return e-(Nt.A-10);if(e>=Nt.a&&e<=Nt.f)return e-(Nt.a-10)}function Pt(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if(ai)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 s=0,o=0;s<r;s++,o+=2){let i=oi(e.charCodeAt(o)),a=oi(e.charCodeAt(o+1));if(i===void 0||a===void 0){let c=e[o]+e[o+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+o)}n[s]=i*16+a}return n}function xt(...e){let t=0;for(let n=0;n<e.length;n++){let s=e[n];H(s),t+=s.length}let r=new Uint8Array(t);for(let n=0,s=0;n<e.length;n++){let o=e[n];r.set(o,s),s+=o.length}return r}function Yn(e,t={}){let r=(s,o)=>e(o).update(s).digest(),n=e(void 0);return r.outputLen=n.outputLen,r.blockLen=n.blockLen,r.create=s=>e(s),Object.assign(r,t),Object.freeze(r)}function Zt(e=32){let t=typeof globalThis=="object"?globalThis.crypto:null;if(typeof t?.getRandomValues!="function")throw new Error("crypto.getRandomValues must be defined");return t.getRandomValues(new Uint8Array(e))}var Wn=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function ci(e,t,r){return e&t^~e&r}function fi(e,t,r){return e&t^e&r^t&r}var nr=class{blockLen;outputLen;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(t,r,n,s){this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=s,this.buffer=new Uint8Array(t),this.view=Mr(this.buffer)}update(t){Re(this),H(t);let{view:r,buffer:n,blockLen:s}=this,o=t.length;for(let i=0;i<o;){let a=Math.min(s-this.pos,o-i);if(a===s){let c=Mr(t);for(;s<=o-i;i+=s)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===s&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Re(this),ii(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:s,isLE:o}=this,{pos:i}=this;r[i++]=128,At(this.buffer.subarray(i)),this.padOffset>s-i&&(this.process(n,0),i=0);for(let u=i;u<s;u++)r[u]=0;n.setBigUint64(s-8,BigInt(this.length*8),o),this.process(n,0);let a=Mr(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen must be aligned to 32bit");let h=c/4,f=this.get();if(h>f.length)throw new Error("_sha2: outputLen bigger than state");for(let u=0;u<h;u++)a.setUint32(4*u,f[u],o)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||=new this.constructor,t.set(...this.get());let{blockLen:r,buffer:n,length:s,finished:o,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=o,t.length=s,t.pos=a,s%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Mt=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var ut=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Or=BigInt(4294967295),ui=BigInt(32);function Kf(e,t=!1){return t?{h:Number(e&Or),l:Number(e>>ui&Or)}:{h:Number(e>>ui&Or)|0,l:Number(e&Or)|0}}function hi(e,t=!1){let r=e.length,n=new Uint32Array(r),s=new Uint32Array(r);for(let o=0;o<r;o++){let{h:i,l:a}=Kf(e[o],t);[n[o],s[o]]=[i,a]}return[n,s]}var Xn=(e,t,r)=>e>>>r,Jn=(e,t,r)=>e<<32-r|t>>>r,oe=(e,t,r)=>e>>>r|t<<32-r,ie=(e,t,r)=>e<<32-r|t>>>r,sr=(e,t,r)=>e<<64-r|t>>>r-32,or=(e,t,r)=>e>>>r-32|t<<64-r;function Rt(e,t,r,n){let s=(t>>>0)+(n>>>0);return{h:e+r+(s/2**32|0)|0,l:s|0}}var li=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),di=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,pi=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),mi=(e,t,r,n,s)=>t+r+n+s+(e/2**32|0)|0,yi=(e,t,r,n,s)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(s>>>0),gi=(e,t,r,n,s,o)=>t+r+n+s+o+(e/2**32|0)|0;var Df=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]),jt=new Uint32Array(64),Qn=class extends nr{constructor(t){super(64,t,8,!1)}get(){let{A:t,B:r,C:n,D:s,E:o,F:i,G:a,H:c}=this;return[t,r,n,s,o,i,a,c]}set(t,r,n,s,o,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=s|0,this.E=o|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let u=0;u<16;u++,r+=4)jt[u]=t.getUint32(r,!1);for(let u=16;u<64;u++){let b=jt[u-15],y=jt[u-2],d=vt(b,7)^vt(b,18)^b>>>3,S=vt(y,17)^vt(y,19)^y>>>10;jt[u]=S+jt[u-7]+d+jt[u-16]|0}let{A:n,B:s,C:o,D:i,E:a,F:c,G:h,H:f}=this;for(let u=0;u<64;u++){let b=vt(a,6)^vt(a,11)^vt(a,25),y=f+b+ci(a,c,h)+Df[u]+jt[u]|0,S=(vt(n,2)^vt(n,13)^vt(n,22))+fi(n,s,o)|0;f=h,h=c,c=a,a=i+y|0,i=o,o=s,s=n,n=y+S|0}n=n+this.A|0,s=s+this.B|0,o=o+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,h=h+this.G|0,f=f+this.H|0,this.set(n,s,o,i,a,c,h,f)}roundClean(){At(jt)}destroy(){this.set(0,0,0,0,0,0,0,0),At(this.buffer)}},ts=class extends Qn{A=Mt[0]|0;B=Mt[1]|0;C=Mt[2]|0;D=Mt[3]|0;E=Mt[4]|0;F=Mt[5]|0;G=Mt[6]|0;H=Mt[7]|0;constructor(){super(32)}};var bi=hi(["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))),Uf=bi[0],Nf=bi[1],Yt=new Uint32Array(80),Wt=new Uint32Array(80),es=class extends nr{constructor(t){super(128,t,16,!1)}get(){let{Ah:t,Al:r,Bh:n,Bl:s,Ch:o,Cl:i,Dh:a,Dl:c,Eh:h,El:f,Fh:u,Fl:b,Gh:y,Gl:d,Hh:S,Hl:l}=this;return[t,r,n,s,o,i,a,c,h,f,u,b,y,d,S,l]}set(t,r,n,s,o,i,a,c,h,f,u,b,y,d,S,l){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=s|0,this.Ch=o|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=h|0,this.El=f|0,this.Fh=u|0,this.Fl=b|0,this.Gh=y|0,this.Gl=d|0,this.Hh=S|0,this.Hl=l|0}process(t,r){for(let w=0;w<16;w++,r+=4)Yt[w]=t.getUint32(r),Wt[w]=t.getUint32(r+=4);for(let w=16;w<80;w++){let K=Yt[w-15]|0,P=Wt[w-15]|0,M=oe(K,P,1)^oe(K,P,8)^Xn(K,P,7),O=ie(K,P,1)^ie(K,P,8)^Jn(K,P,7),L=Yt[w-2]|0,A=Wt[w-2]|0,U=oe(L,A,19)^sr(L,A,61)^Xn(L,A,6),k=ie(L,A,19)^or(L,A,61)^Jn(L,A,6),T=pi(O,k,Wt[w-7],Wt[w-16]),x=mi(T,M,U,Yt[w-7],Yt[w-16]);Yt[w]=x|0,Wt[w]=T|0}let{Ah:n,Al:s,Bh:o,Bl:i,Ch:a,Cl:c,Dh:h,Dl:f,Eh:u,El:b,Fh:y,Fl:d,Gh:S,Gl:l,Hh:g,Hl:B}=this;for(let w=0;w<80;w++){let K=oe(u,b,14)^oe(u,b,18)^sr(u,b,41),P=ie(u,b,14)^ie(u,b,18)^or(u,b,41),M=u&y^~u&S,O=b&d^~b&l,L=yi(B,P,O,Nf[w],Wt[w]),A=gi(L,g,K,M,Uf[w],Yt[w]),U=L|0,k=oe(n,s,28)^sr(n,s,34)^sr(n,s,39),T=ie(n,s,28)^or(n,s,34)^or(n,s,39),x=n&o^n&a^o&a,p=s&i^s&c^i&c;g=S|0,B=l|0,S=y|0,l=d|0,y=u|0,d=b|0,{h:u,l:b}=Rt(h|0,f|0,A|0,U|0),h=a|0,f=c|0,a=o|0,c=i|0,o=n|0,i=s|0;let m=li(U,T,p);n=di(m,A,k,x),s=m|0}({h:n,l:s}=Rt(this.Ah|0,this.Al|0,n|0,s|0)),{h:o,l:i}=Rt(this.Bh|0,this.Bl|0,o|0,i|0),{h:a,l:c}=Rt(this.Ch|0,this.Cl|0,a|0,c|0),{h,l:f}=Rt(this.Dh|0,this.Dl|0,h|0,f|0),{h:u,l:b}=Rt(this.Eh|0,this.El|0,u|0,b|0),{h:y,l:d}=Rt(this.Fh|0,this.Fl|0,y|0,d|0),{h:S,l}=Rt(this.Gh|0,this.Gl|0,S|0,l|0),{h:g,l:B}=Rt(this.Hh|0,this.Hl|0,g|0,B|0),this.set(n,s,o,i,a,c,h,f,u,b,y,d,S,l,g,B)}roundClean(){At(Yt,Wt)}destroy(){At(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},rs=class extends es{Ah=ut[0]|0;Al=ut[1]|0;Bh=ut[2]|0;Bl=ut[3]|0;Ch=ut[4]|0;Cl=ut[5]|0;Dh=ut[6]|0;Dl=ut[7]|0;Eh=ut[8]|0;El=ut[9]|0;Fh=ut[10]|0;Fl=ut[11]|0;Gh=ut[12]|0;Gl=ut[13]|0;Hh=ut[14]|0;Hl=ut[15]|0;constructor(){super(64)}};var Tt=Yn(()=>new ts,Wn(1));var xi=Yn(()=>new rs,Wn(3));var ss=BigInt(0),ns=BigInt(1);function Ot(e,t=""){if(typeof e!="boolean"){let r=t&&`"${t}" `;throw new Error(r+"expected boolean, got type="+typeof e)}return e}function wi(e){if(typeof e=="bigint"){if(!Hr(e))throw new Error("positive bigint expected, got "+e)}else Et(e);return e}function ir(e){let t=wi(e).toString(16);return t.length&1?"0"+t:t}function Ei(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?ss:BigInt("0x"+e)}function Te(e){return Ei(kt(e))}function Kt(e){return Ei(kt(ae(H(e)).reverse()))}function qr(e,t){Et(t),e=wi(e);let r=Pt(e.toString(16).padStart(t*2,"0"));if(r.length!==t)throw new Error("number too large");return r}function ar(e,t){return qr(e,t).reverse()}function ae(e){return Uint8Array.from(e)}var Hr=e=>typeof e=="bigint"&&ss<=e;function kf(e,t,r){return Hr(e)&&Hr(t)&&Hr(r)&&t<=e&&e<r}function Xt(e,t,r,n){if(!kf(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function os(e){let t;for(t=0;e>ss;e>>=ns,t+=1);return t}var cr=e=>(ns<<BigInt(e))-ns;function Si(e,t,r){if(Et(e,"hashLen"),Et(t,"qByteLen"),typeof r!="function")throw new Error("hmacFn must be a function");let n=l=>new Uint8Array(l),s=Uint8Array.of(),o=Uint8Array.of(0),i=Uint8Array.of(1),a=1e3,c=n(e),h=n(e),f=0,u=()=>{c.fill(1),h.fill(0),f=0},b=(...l)=>r(h,xt(c,...l)),y=(l=s)=>{h=b(o,l),c=b(),l.length!==0&&(h=b(i,l),c=b())},d=()=>{if(f++>=a)throw new Error("drbg: tried max amount of iterations");let l=0,g=[];for(;l<t;){c=b();let B=c.slice();g.push(B),l+=c.length}return xt(...g)};return(l,g)=>{u(),y(l);let B;for(;!(B=g(d()));)y();return u(),B}}function Ct(e,t={},r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,i,a){let c=e[o];if(a&&c===void 0)return;let h=typeof c;if(h!==i||c===null)throw new Error(`param "${o}" is invalid: expected ${i}, got ${h}`)}let s=(o,i)=>Object.entries(o).forEach(([a,c])=>n(a,c,i));s(t,!1),s(r,!0)}function Ke(e){let t=new WeakMap;return(r,...n)=>{let s=t.get(r);if(s!==void 0)return s;let o=e(r,...n);return t.set(r,o),o}}var yt=BigInt(0),ot=BigInt(1),ce=BigInt(2),Bi=BigInt(3),Li=BigInt(4),Ii=BigInt(5),Pf=BigInt(7),_i=BigInt(8),Mf=BigInt(9),Ri=BigInt(16);function J(e,t){let r=e%t;return r>=yt?r:t+r}function X(e,t,r){let n=e;for(;t-- >yt;)n*=n,n%=r;return n}function Ai(e,t){if(e===yt)throw new Error("invert: expected non-zero number");if(t<=yt)throw new Error("invert: expected positive modulus, got "+t);let r=J(e,t),n=t,s=yt,o=ot,i=ot,a=yt;for(;r!==yt;){let h=n/r,f=n%r,u=s-i*h,b=o-a*h;n=r,r=f,s=i,o=a,i=u,a=b}if(n!==ot)throw new Error("invert: does not exist");return J(s,t)}function as(e,t,r){if(!e.eql(e.sqr(t),r))throw new Error("Cannot find square root")}function Ti(e,t){let r=(e.ORDER+ot)/Li,n=e.pow(t,r);return as(e,n,t),n}function Of(e,t){let r=(e.ORDER-Ii)/_i,n=e.mul(t,ce),s=e.pow(n,r),o=e.mul(t,s),i=e.mul(e.mul(o,ce),s),a=e.mul(o,e.sub(i,e.ONE));return as(e,a,t),a}function Hf(e){let t=Ce(e),r=Ki(e),n=r(t,t.neg(t.ONE)),s=r(t,n),o=r(t,t.neg(n)),i=(e+Pf)/Ri;return(a,c)=>{let h=a.pow(c,i),f=a.mul(h,n),u=a.mul(h,s),b=a.mul(h,o),y=a.eql(a.sqr(f),c),d=a.eql(a.sqr(u),c);h=a.cmov(h,f,y),f=a.cmov(b,u,d);let S=a.eql(a.sqr(f),c),l=a.cmov(h,f,S);return as(a,l,c),l}}function Ki(e){if(e<Bi)throw new Error("sqrt is not defined for small field");let t=e-ot,r=0;for(;t%ce===yt;)t/=ce,r++;let n=ce,s=Ce(e);for(;vi(s,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return Ti;let o=s.pow(n,t),i=(t+ot)/ce;return function(c,h){if(c.is0(h))return h;if(vi(c,h)!==1)throw new Error("Cannot find square root");let f=r,u=c.mul(c.ONE,o),b=c.pow(h,t),y=c.pow(h,i);for(;!c.eql(b,c.ONE);){if(c.is0(b))return c.ZERO;let d=1,S=c.sqr(b);for(;!c.eql(S,c.ONE);)if(d++,S=c.sqr(S),d===f)throw new Error("Cannot find square root");let l=ot<<BigInt(f-d-1),g=c.pow(u,l);f=d,u=c.sqr(g),b=c.mul(b,u),y=c.mul(y,g)}return y}}function qf(e){return e%Li===Bi?Ti:e%_i===Ii?Of:e%Ri===Mf?Hf(e):Ki(e)}var Ci=(e,t)=>(J(e,t)&ot)===ot,Vf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function cs(e){let t={ORDER:"bigint",BYTES:"number",BITS:"number"},r=Vf.reduce((n,s)=>(n[s]="function",n),t);return Ct(e,r),e}function Ff(e,t,r){if(r<yt)throw new Error("invalid exponent, negatives unsupported");if(r===yt)return e.ONE;if(r===ot)return t;let n=e.ONE,s=t;for(;r>yt;)r&ot&&(n=e.mul(n,s)),s=e.sqr(s),r>>=ot;return n}function fr(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),s=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),o=e.inv(s);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),o),n}function vi(e,t){let r=(e.ORDER-ot)/ce,n=e.pow(t,r),s=e.eql(n,e.ONE),o=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!s&&!o&&!i)throw new Error("invalid Legendre symbol result");return s?1:o?0:-1}function zf(e,t){t!==void 0&&Et(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}var is=class{ORDER;BITS;BYTES;isLE;ZERO=yt;ONE=ot;_lengths;_sqrt;_mod;constructor(t,r={}){if(t<=yt)throw new Error("invalid field: expected ORDER > 0, got "+t);let n;this.isLE=!1,r!=null&&typeof r=="object"&&(typeof r.BITS=="number"&&(n=r.BITS),typeof r.sqrt=="function"&&(this.sqrt=r.sqrt),typeof r.isLE=="boolean"&&(this.isLE=r.isLE),r.allowedLengths&&(this._lengths=r.allowedLengths?.slice()),typeof r.modFromBytes=="boolean"&&(this._mod=r.modFromBytes));let{nBitLength:s,nByteLength:o}=zf(t,n);if(o>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");this.ORDER=t,this.BITS=s,this.BYTES=o,this._sqrt=void 0,Object.preventExtensions(this)}create(t){return J(t,this.ORDER)}isValid(t){if(typeof t!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof t);return yt<=t&&t<this.ORDER}is0(t){return t===yt}isValidNot0(t){return!this.is0(t)&&this.isValid(t)}isOdd(t){return(t&ot)===ot}neg(t){return J(-t,this.ORDER)}eql(t,r){return t===r}sqr(t){return J(t*t,this.ORDER)}add(t,r){return J(t+r,this.ORDER)}sub(t,r){return J(t-r,this.ORDER)}mul(t,r){return J(t*r,this.ORDER)}pow(t,r){return Ff(this,t,r)}div(t,r){return J(t*Ai(r,this.ORDER),this.ORDER)}sqrN(t){return t*t}addN(t,r){return t+r}subN(t,r){return t-r}mulN(t,r){return t*r}inv(t){return Ai(t,this.ORDER)}sqrt(t){return this._sqrt||(this._sqrt=qf(this.ORDER)),this._sqrt(this,t)}toBytes(t){return this.isLE?ar(t,this.BYTES):qr(t,this.BYTES)}fromBytes(t,r=!1){H(t);let{_lengths:n,BYTES:s,isLE:o,ORDER:i,_mod:a}=this;if(n){if(!n.includes(t.length)||t.length>s)throw new Error("Field.fromBytes: expected "+n+" bytes, got "+t.length);let h=new Uint8Array(s);h.set(t,o?0:h.length-t.length),t=h}if(t.length!==s)throw new Error("Field.fromBytes: expected "+s+" bytes, got "+t.length);let c=o?Kt(t):Te(t);if(a&&(c=J(c,i)),!r&&!this.isValid(c))throw new Error("invalid field element: outside of range 0..ORDER");return c}invertBatch(t){return fr(this,t)}cmov(t,r,n){return n?r:t}};function Ce(e,t={}){return new is(e,t)}function Di(e){if(typeof e!="bigint")throw new Error("field order must be bigint");let t=e.toString(2).length;return Math.ceil(t/8)}function fs(e){let t=Di(e);return t+Math.ceil(t/2)}function us(e,t,r=!1){H(e);let n=e.length,s=Di(t),o=fs(t);if(n<16||n<o||n>1024)throw new Error("expected "+o+"-1024 bytes of input, got "+n);let i=r?Kt(e):Te(e),a=J(i,t-ot)+ot;return r?ar(a,s):qr(a,s)}var De=BigInt(0),fe=BigInt(1);function ur(e,t){let r=t.negate();return e?r:t}function ue(e,t){let r=fr(e.Fp,t.map(n=>n.Z));return t.map((n,s)=>e.fromAffine(n.toAffine(r[s])))}function Pi(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function hs(e,t){Pi(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),s=2**e,o=cr(e),i=BigInt(e);return{windows:r,windowSize:n,mask:o,maxNumber:s,shiftBy:i}}function Ui(e,t,r){let{windowSize:n,mask:s,maxNumber:o,shiftBy:i}=r,a=Number(e&s),c=e>>i;a>n&&(a-=o,c+=fe);let h=t*n,f=h+Math.abs(a)-1,u=a===0,b=a<0,y=t%2!==0;return{nextN:c,offset:f,isZero:u,isNeg:b,isNegF:y,offsetF:h}}var ls=new WeakMap,Mi=new WeakMap;function ds(e){return Mi.get(e)||1}function Ni(e){if(e!==De)throw new