UNPKG

@chainsafe/libp2p-noise

Version:
2 lines 137 kB
(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 _n=Object.defineProperty;var Ja=Object.getOwnPropertyDescriptor;var Qa=Object.getOwnPropertyNames;var tc=Object.prototype.hasOwnProperty;var xt=(e,t)=>{for(var r in t)_n(e,r,{get:t[r],enumerable:!0})},ec=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of Qa(t))!tc.call(e,o)&&o!==r&&_n(e,o,{get:()=>t[o],enumerable:!(n=Ja(t,o))||n.enumerable});return e};var rc=e=>ec(_n({},"__esModule",{value:!0}),e);var dh={};xt(dh,{noise:()=>lh,pureJsCrypto:()=>Sn});var In=Symbol.for("@libp2p/peer-id");var Br=class extends Error{static name="UnexpectedPeerError";constructor(t="Unexpected Peer"){super(t),this.name="UnexpectedPeerError"}},_r=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"}},be=class extends Error{static name="InvalidPublicKeyError";constructor(t="Invalid public key"){super(t),this.name="InvalidPublicKeyError"}};var we=class extends Error{static name="UnsupportedKeyTypeError";constructor(t="Unsupported key type"){super(t),this.name="UnsupportedKeyTypeError"}};var Es=Symbol.for("@libp2p/service-capabilities"),xh=Symbol.for("@libp2p/service-dependencies");var Un={};xt(Un,{base58btc:()=>J,base58flickr:()=>fc});var Hh=new Uint8Array(0);function Ss(e,t){if(e===t)return!0;if(e.byteLength!==t.byteLength)return!1;for(let r=0;r<e.byteLength;r++)if(e[r]!==t[r])return!1;return!0}function kt(e){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 As(e){return new TextEncoder().encode(e)}function vs(e){return new TextDecoder().decode(e)}function nc(e,t){if(e.length>=255)throw new TypeError("Alphabet too long");for(var r=new Uint8Array(256),n=0;n<r.length;n++)r[n]=255;for(var o=0;o<e.length;o++){var s=e.charAt(o),i=s.charCodeAt(0);if(r[i]!==255)throw new TypeError(s+" is ambiguous");r[i]=o}var a=e.length,c=e.charAt(0),h=Math.log(a)/Math.log(256),f=Math.log(256)/Math.log(a);function u(w){if(w instanceof Uint8Array||(ArrayBuffer.isView(w)?w=new Uint8Array(w.buffer,w.byteOffset,w.byteLength):Array.isArray(w)&&(w=Uint8Array.from(w))),!(w instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(w.length===0)return"";for(var x=0,l=0,E=0,I=w.length;E!==I&&w[E]===0;)E++,x++;for(var _=(I-E)*f+1>>>0,P=new Uint8Array(_);E!==I;){for(var S=w[E],D=0,K=_-1;(S!==0||D<l)&&K!==-1;K--,D++)S+=256*P[K]>>>0,P[K]=S%a>>>0,S=S/a>>>0;if(S!==0)throw new Error("Non-zero carry");l=D,E++}for(var T=_-l;T!==_&&P[T]===0;)T++;for(var d=c.repeat(x);T<_;++T)d+=e.charAt(P[T]);return d}function m(w){if(typeof w!="string")throw new TypeError("Expected String");if(w.length===0)return new Uint8Array;var x=0;if(w[x]!==" "){for(var l=0,E=0;w[x]===c;)l++,x++;for(var I=(w.length-x)*h+1>>>0,_=new Uint8Array(I);w[x];){var P=r[w.charCodeAt(x)];if(P===255)return;for(var S=0,D=I-1;(P!==0||S<E)&&D!==-1;D--,S++)P+=a*_[D]>>>0,_[D]=P%256>>>0,P=P/256>>>0;if(P!==0)throw new Error("Non-zero carry");E=S,x++}if(w[x]!==" "){for(var K=I-E;K!==I&&_[K]===0;)K++;for(var T=new Uint8Array(l+(I-K)),d=l;K!==I;)T[d++]=_[K++];return T}}}function y(w){var x=m(w);if(x)return x;throw new Error(`Non-${t} character`)}return{encode:u,decodeUnsafe:m,decode:y}}var oc=nc,sc=oc,_s=sc;var Ln=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")}},Tn=class{name;prefix;baseDecode;prefixCodePoint;constructor(t,r,n){this.name=t,this.prefix=r;let o=r.codePointAt(0);if(o===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=o,this.baseDecode=n}decode(t){if(typeof t=="string"){if(t.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(t)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(t.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(t){return Is(this,t)}},Kn=class{decoders;constructor(t){this.decoders=t}or(t){return Is(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 Is(e,t){return new Kn({...e.decoders??{[e.prefix]:e},...t.decoders??{[t.prefix]:t}})}var Cn=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(t,r,n,o){this.name=t,this.prefix=r,this.baseEncode=n,this.baseDecode=o,this.encoder=new Ln(t,r,n),this.decoder=new Tn(t,r,o)}encode(t){return this.encoder.encode(t)}decode(t){return this.decoder.decode(t)}};function Ee({name:e,prefix:t,encode:r,decode:n}){return new Cn(e,t,r,n)}function jt({name:e,prefix:t,alphabet:r}){let{encode:n,decode:o}=_s(r,e);return Ee({prefix:t,name:e,encode:n,decode:s=>kt(o(s))})}function ic(e,t,r,n){let o=e.length;for(;e[o-1]==="=";)--o;let s=new Uint8Array(o*r/8|0),i=0,a=0,c=0;for(let h=0;h<o;++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,s[c++]=255&a>>i)}if(i>=r||(255&a<<8-i)!==0)throw new SyntaxError("Unexpected end of data");return s}function ac(e,t,r){let n=t[t.length-1]==="=",o=(1<<r)-1,s="",i=0,a=0;for(let c=0;c<e.length;++c)for(a=a<<8|e[c],i+=8;i>r;)i-=r,s+=t[o&a>>i];if(i!==0&&(s+=t[o&a<<r-i]),n)for(;(s.length*r&7)!==0;)s+="=";return s}function cc(e){let t={};for(let r=0;r<e.length;++r)t[e[r]]=r;return t}function $({name:e,prefix:t,bitsPerChar:r,alphabet:n}){let o=cc(n);return Ee({prefix:t,name:e,encode(s){return ac(s,n,r)},decode(s){return ic(s,o,r,e)}})}var J=jt({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),fc=jt({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Dn={};xt(Dn,{base32:()=>Se,base32hex:()=>dc,base32hexpad:()=>yc,base32hexpadupper:()=>mc,base32hexupper:()=>pc,base32pad:()=>hc,base32padupper:()=>lc,base32upper:()=>uc,base32z:()=>xc});var Se=$({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),uc=$({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),hc=$({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),lc=$({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),dc=$({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),pc=$({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),yc=$({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),mc=$({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),xc=$({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var Rn={};xt(Rn,{base36:()=>Ze,base36upper:()=>gc});var Ze=jt({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),gc=jt({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var bc=Ks,Ls=128,wc=127,Ec=~wc,Sc=Math.pow(2,31);function Ks(e,t,r){t=t||[],r=r||0;for(var n=r;e>=Sc;)t[r++]=e&255|Ls,e/=128;for(;e&Ec;)t[r++]=e&255|Ls,e>>>=7;return t[r]=e|0,Ks.bytes=r-n+1,t}var Ac=Pn,vc=128,Ts=127;function Pn(e,n){var r=0,n=n||0,o=0,s=n,i,a=e.length;do{if(s>=a)throw Pn.bytes=0,new RangeError("Could not decode varint");i=e[s++],r+=o<28?(i&Ts)<<o:(i&Ts)*Math.pow(2,o),o+=7}while(i>=vc);return Pn.bytes=s-n,r}var Bc=Math.pow(2,7),_c=Math.pow(2,14),Ic=Math.pow(2,21),Lc=Math.pow(2,28),Tc=Math.pow(2,35),Kc=Math.pow(2,42),Cc=Math.pow(2,49),Uc=Math.pow(2,56),Dc=Math.pow(2,63),Rc=function(e){return e<Bc?1:e<_c?2:e<Ic?3:e<Lc?4:e<Tc?5:e<Kc?6:e<Cc?7:e<Uc?8:e<Dc?9:10},Pc={encode:bc,decode:Ac,encodingLength:Rc},Nc=Pc,Ye=Nc;function Xe(e,t=0){return[Ye.decode(e,t),Ye.decode.bytes]}function Ae(e,t,r=0){return Ye.encode(e,t,r),t}function ve(e){return Ye.encodingLength(e)}function At(e,t){let r=t.byteLength,n=ve(e),o=n+ve(r),s=new Uint8Array(o+r);return Ae(e,s,0),Ae(r,s,n),s.set(t,o),new Be(e,r,t,s)}function Nn(e){let t=kt(e),[r,n]=Xe(t),[o,s]=Xe(t.subarray(n)),i=t.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new Be(r,o,i,t)}function Cs(e,t){if(e===t)return!0;{let r=t;return e.code===r.code&&e.size===r.size&&r.bytes instanceof Uint8Array&&Ss(e.bytes,r.bytes)}}var Be=class{code;size;digest;bytes;constructor(t,r,n,o){this.code=t,this.size=r,this.digest=n,this.bytes=o}};function Us(e,t){let{bytes:r,version:n}=e;switch(n){case 0:return Mc(r,kn(e),t??J.encoder);default:return Hc(r,kn(e),t??Se.encoder)}}var Ds=new WeakMap;function kn(e){let t=Ds.get(e);if(t==null){let r=new Map;return Ds.set(e,r),r}return t}var ct=class e{code;version;multihash;bytes;"/";constructor(t,r,n,o){this.code=r,this.version=t,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:t,multihash:r}=this;if(t!==We)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(r.code!==Oc)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=At(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&&Cs(t.multihash,n.multihash)}toString(t){return Us(this,t)}toJSON(){return{"/":Us(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(t){if(t==null)return null;let r=t;if(r instanceof e)return r;if(r["/"]!=null&&r["/"]===r.bytes||r.asCID===r){let{version:n,code:o,multihash:s,bytes:i}=r;return new e(n,o,s,i??Rs(n,o,s.bytes))}else if(r[qc]===!0){let{version:n,multihash:o,code:s}=r,i=Nn(o);return e.create(n,s,i)}else return null}static create(t,r,n){if(typeof r!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(t){case 0:{if(r!==We)throw new Error(`Version 0 CID must use dag-pb (code: ${We}) block encoding`);return new e(t,r,n,n.bytes)}case 1:{let o=Rs(t,r,n.bytes);return new e(t,r,n,o)}default:throw new Error("Invalid version")}}static createV0(t){return e.create(0,We,t)}static createV1(t,r){return e.create(1,t,r)}static decode(t){let[r,n]=e.decodeFirst(t);if(n.length!==0)throw new Error("Incorrect length");return r}static decodeFirst(t){let r=e.inspectBytes(t),n=r.size-r.multihashSize,o=kt(t.subarray(n,n+r.multihashSize));if(o.byteLength!==r.multihashSize)throw new Error("Incorrect length");let s=o.subarray(r.multihashSize-r.digestSize),i=new Be(r.multihashCode,r.digestSize,s,o);return[r.version===0?e.createV0(i):e.createV1(r.codec,i),t.subarray(r.size)]}static inspectBytes(t){let r=0,n=()=>{let[u,m]=Xe(t.subarray(r));return r+=m,u},o=n(),s=We;if(o===18?(o=0,r=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=r,a=n(),c=n(),h=r+c,f=h-i;return{version:o,codec:s,multihashCode:a,digestSize:c,multihashSize:f,size:h}}static parse(t,r){let[n,o]=kc(t,r),s=e.decode(o);if(s.version===0&&t[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return kn(s).set(n,t),s}};function kc(e,t){switch(e[0]){case"Q":{let r=t??J;return[J.prefix,r.decode(`${J.prefix}${e}`)]}case J.prefix:{let r=t??J;return[J.prefix,r.decode(e)]}case Se.prefix:{let r=t??Se;return[Se.prefix,r.decode(e)]}case Ze.prefix:{let r=t??Ze;return[Ze.prefix,r.decode(e)]}default:{if(t==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[e[0],t.decode(e)]}}}function Mc(e,t,r){let{prefix:n}=r;if(n!==J.prefix)throw Error(`Cannot string encode V0 in ${r.name} encoding`);let o=t.get(n);if(o==null){let s=r.encode(e).slice(1);return t.set(n,s),s}else return o}function Hc(e,t,r){let{prefix:n}=r,o=t.get(n);if(o==null){let s=r.encode(e);return t.set(n,s),s}else return o}var We=112,Oc=18;function Rs(e,t,r){let n=ve(e),o=n+ve(t),s=new Uint8Array(o+r.byteLength);return Ae(e,s,0),Ae(t,s,n),s.set(r,o),s}var qc=Symbol.for("@ipld/js-cid/CID");var Mn={};xt(Mn,{identity:()=>Kt});var Ps=0,Vc="identity",Ns=kt;function zc(e){return At(Ps,Ns(e))}var Kt={code:Ps,name:Vc,encode:Ns,digest:zc};function dt(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 tt(e=0){return new Uint8Array(e)}function et(e=0){return new Uint8Array(e)}function re(e,t){t==null&&(t=e.reduce((o,s)=>o+s.length,0));let r=et(t),n=0;for(let o of e)r.set(o,n),n+=o.length;return r}var Ms=Symbol.for("@achingbrain/uint8arraylist");function ks(e,t){if(t==null||t<0)throw new RangeError("index is out of bounds");let r=0;for(let n of e){let o=r+n.byteLength;if(t<o)return{buf:n,index:t-r};r=o}throw new RangeError("index is out of bounds")}function Lr(e){return!!e?.[Ms]}var z=class e{bufs;length;[Ms]=!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(Lr(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(Lr(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=ks(this.bufs,t);return r.buf[r.index]}set(t,r){let n=ks(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(Lr(t))for(let n=0;n<t.length;n++)this.set(r+n,t.get(n));else throw new Error("Could not write value, must be an Uint8Array or a Uint8ArrayList")}consume(t){if(t=Math.trunc(t),!(Number.isNaN(t)||t<=0)){if(t===this.byteLength){this.bufs=[],this.length=0;return}for(;this.bufs.length>0;)if(t>=this.bufs[0].byteLength)t-=this.bufs[0].byteLength,this.length-=this.bufs[0].byteLength,this.bufs.shift();else{this.bufs[0]=this.bufs[0].subarray(t),this.length-=t;break}}}slice(t,r){let{bufs:n,length:o}=this._subList(t,r);return re(n,o)}subarray(t,r){let{bufs:n,length:o}=this._subList(t,r);return n.length===1?n[0]:re(n,o)}sublist(t,r){let{bufs:n,length:o}=this._subList(t,r),s=new e;return s.length=o,s.bufs=[...n],s}_subList(t,r){if(t=t??0,r=r??this.length,t<0&&(t=this.length+t),r<0&&(r=this.length+r),t<0||r>this.length)throw new RangeError("index is out of bounds");if(t===r)return{bufs:[],length:0};if(t===0&&r===this.length)return{bufs:this.bufs,length:this.length};let n=[],o=0;for(let s=0;s<this.bufs.length;s++){let i=this.bufs[s],a=o,c=a+i.byteLength;if(o=c,t>=c)continue;let 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(!Lr(t)&&!(t instanceof Uint8Array))throw new TypeError('The "value" argument must be a Uint8ArrayList or Uint8Array');let n=t instanceof Uint8Array?t:t.subarray();if(r=Number(r??0),isNaN(r)&&(r=0),r<0&&(r=this.length+r),r<0&&(r=0),t.length===0)return r>this.length?this.length:r;let o=n.byteLength;if(o===0)throw new TypeError("search must be at least 1 byte long");let s=256,i=new Int32Array(s);for(let u=0;u<s;u++)i[u]=-1;for(let u=0;u<o;u++)i[n[u]]=u;let a=i,c=this.byteLength-n.byteLength,h=n.byteLength-1,f;for(let u=r;u<=c;u+=f){f=0;for(let m=h;m>=0;m--){let y=this.get(u+m);if(n[m]!==y){f=Math.max(1,m-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=et(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setInt8(0,r),this.write(n,t)}getInt16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt16(0,r)}setInt16(t,r,n){let o=tt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt16(0,r,n),this.write(o,t)}getInt32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getInt32(0,r)}setInt32(t,r,n){let o=tt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setInt32(0,r,n),this.write(o,t)}getBigInt64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigInt64(0,r)}setBigInt64(t,r,n){let o=tt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigInt64(0,r,n),this.write(o,t)}getUint8(t){let r=this.subarray(t,t+1);return new DataView(r.buffer,r.byteOffset,r.byteLength).getUint8(0)}setUint8(t,r){let n=et(1);new DataView(n.buffer,n.byteOffset,n.byteLength).setUint8(0,r),this.write(n,t)}getUint16(t,r){let n=this.subarray(t,t+2);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint16(0,r)}setUint16(t,r,n){let o=tt(2);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint16(0,r,n),this.write(o,t)}getUint32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getUint32(0,r)}setUint32(t,r,n){let o=tt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setUint32(0,r,n),this.write(o,t)}getBigUint64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getBigUint64(0,r)}setBigUint64(t,r,n){let o=tt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setBigUint64(0,r,n),this.write(o,t)}getFloat32(t,r){let n=this.subarray(t,t+4);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat32(0,r)}setFloat32(t,r,n){let o=tt(4);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat32(0,r,n),this.write(o,t)}getFloat64(t,r){let n=this.subarray(t,t+8);return new DataView(n.buffer,n.byteOffset,n.byteLength).getFloat64(0,r)}setFloat64(t,r,n){let o=tt(8);new DataView(o.buffer,o.byteOffset,o.byteLength).setFloat64(0,r,n),this.write(o,t)}equals(t){if(t==null||!(t instanceof e)||t.bufs.length!==this.bufs.length)return!1;for(let r=0;r<this.bufs.length;r++)if(!dt(this.bufs[r],t.bufs[r]))return!1;return!0}static fromUint8Arrays(t,r){let n=new e;return n.bufs=t,r==null&&(r=t.reduce((o,s)=>o+s.byteLength,0)),n.length=r,n}};var Hn={};xt(Hn,{base10:()=>Fc});var Fc=jt({prefix:"9",name:"base10",alphabet:"0123456789"});var On={};xt(On,{base16:()=>jc,base16upper:()=>Zc});var jc=$({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Zc=$({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var qn={};xt(qn,{base2:()=>Yc});var Yc=$({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var Vn={};xt(Vn,{base256emoji:()=>Qc});var Hs=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}"),Xc=Hs.reduce((e,t,r)=>(e[r]=t,e),[]),Wc=Hs.reduce((e,t,r)=>{let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);return e[n]=r,e},[]);function $c(e){return e.reduce((t,r)=>(t+=Xc[r],t),"")}function Jc(e){let t=[];for(let r of e){let n=r.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${r}`);let o=Wc[n];if(o==null)throw new Error(`Non-base256emoji character: ${r}`);t.push(o)}return new Uint8Array(t)}var Qc=Ee({prefix:"\u{1F680}",name:"base256emoji",encode:$c,decode:Jc});var zn={};xt(zn,{base64:()=>tf,base64pad:()=>ef,base64url:()=>rf,base64urlpad:()=>nf});var tf=$({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),ef=$({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),rf=$({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),nf=$({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Gn={};xt(Gn,{base8:()=>of});var of=$({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Fn={};xt(Fn,{identity:()=>sf});var sf=Ee({prefix:"\0",name:"identity",encode:e=>vs(e),decode:e=>As(e)});var El=new TextEncoder,Sl=new TextDecoder;var Yn={};xt(Yn,{sha256:()=>Tr,sha512:()=>ff});function Zn({name:e,code:t,encode:r}){return new jn(e,t,r)}var jn=class{name;code;encode;constructor(t,r,n){this.name=t,this.code=r,this.encode=n}digest(t){if(t instanceof Uint8Array){let r=this.encode(t);return r instanceof Uint8Array?At(this.code,r):r.then(n=>At(this.code,n))}else throw Error("Unknown type, must be binary type")}};function qs(e){return async t=>new Uint8Array(await crypto.subtle.digest(e,t))}var Tr=Zn({name:"sha2-256",code:18,encode:qs("SHA-256")}),ff=Zn({name:"sha2-512",code:19,encode:qs("SHA-512")});var Xn={...Fn,...qn,...Gn,...Hn,...On,...Dn,...Rn,...Un,...zn,...Vn},Rl={...Yn,...Mn};function zs(e,t,r,n){return{name:e,prefix:t,encoder:{name:e,prefix:t,encode:r},decoder:{decode:n}}}var Vs=zs("utf8","u",e=>"u"+new TextDecoder("utf8").decode(e),e=>new TextEncoder().encode(e.substring(1))),Wn=zs("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=et(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}),uf={utf8:Vs,"utf-8":Vs,hex:Xn.base16,latin1:Wn,ascii:Wn,binary:Wn,...Xn},Kr=uf;function Z(e,t="utf8"){let r=Kr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.decoder.decode(`${r.prefix}${e}`)}function V(e,t="utf8"){let r=Kr[t];if(r==null)throw new Error(`Unsupported encoding "${t}"`);return r.encoder.encode(e).substring(1)}var hf=parseInt("11111",2),$n=parseInt("10000000",2),lf=parseInt("01111111",2),Gs={0:$e,1:$e,2:df,3:mf,4:xf,5:yf,6:pf,16:$e,22:$e,48:$e};function Mt(e,t={offset:0}){let r=e[t.offset]&hf;if(t.offset++,Gs[r]!=null)return Gs[r](e,t);throw new Error("No decoder for tag "+r)}function Je(e,t){let r=0;if((e[t.offset]&$n)===$n){let n=e[t.offset]&lf,o="0x";t.offset++;for(let s=0;s<n;s++,t.offset++)o+=e[t.offset].toString(16).padStart(2,"0");r=parseInt(o,16)}else r=e[t.offset],t.offset++;return r}function $e(e,t){Je(e,t);let r=[];for(;!(t.offset>=e.byteLength);){let n=Mt(e,t);if(n===null)break;r.push(n)}return r}function df(e,t){let r=Je(e,t),n=t.offset,o=t.offset+r,s=[];for(let i=n;i<o;i++)i===n&&e[i]===0||s.push(e[i]);return t.offset+=r,Uint8Array.from(s)}function pf(e,t){let r=Je(e,t),n=t.offset+r,o=e[t.offset];t.offset++;let s=0,i=0;o<40?(s=0,i=o):o<80?(s=1,i=o-40):(s=2,i=o-80);let a=`${s}.${i}`,c=[];for(;t.offset<n;){let 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 yf(e,t){return t.offset++,null}function mf(e,t){let r=Je(e,t),n=e[t.offset];t.offset++;let o=e.subarray(t.offset,t.offset+r-1);if(t.offset+=r,n!==0)throw new Error("Unused bits in bit string is unimplemented");return o}function xf(e,t){let r=Je(e,t),n=e.subarray(t.offset,t.offset+r);return t.offset+=r,n}function gf(e){let t=e.toString(16);t.length%2===1&&(t="0"+t);let r=new z;for(let n=0;n<t.length;n+=2)r.append(Uint8Array.from([parseInt(`${t[n]}${t[n+1]}`,16)]));return r}function Jn(e){if(e.byteLength<128)return Uint8Array.from([e.byteLength]);let t=gf(e.byteLength);return new z(Uint8Array.from([t.byteLength|$n]),t)}function gt(e){let t=new z,r=128;return(e.subarray()[0]&r)===r&&t.append(Uint8Array.from([0])),t.append(e),new z(Uint8Array.from([2]),Jn(t),t)}function Cr(e){let t=Uint8Array.from([0]),r=new z(t,e);return new z(Uint8Array.from([3]),Jn(r),r)}function Zt(e,t=48){let r=new z;for(let n of e)r.append(n);return new z(Uint8Array.from([t]),Jn(r),r)}async function Fs(e,t,r,n){let o=await crypto.subtle.importKey("jwk",e,{name:"ECDSA",namedCurve:e.crv??"P-256"},!1,["verify"]);n?.signal?.throwIfAborted();let s=await crypto.subtle.verify({name:"ECDSA",hash:{name:"SHA-256"}},o,t,r.subarray());return n?.signal?.throwIfAborted(),s}var bf=Uint8Array.from([6,8,42,134,72,206,61,3,1,7]),wf=Uint8Array.from([6,5,43,129,4,0,34]),Ef=Uint8Array.from([6,5,43,129,4,0,35]),Sf={ext:!0,kty:"EC",crv:"P-256"},Af={ext:!0,kty:"EC",crv:"P-384"},vf={ext:!0,kty:"EC",crv:"P-521"},Qn=32,to=48,eo=66;function js(e){let t=Mt(e);return Zs(t)}function Zs(e){let t=e[1][1][0],r=1,n,o;if(t.byteLength===Qn*2+1)return n=V(t.subarray(r,r+Qn),"base64url"),o=V(t.subarray(r+Qn),"base64url"),new Ie({...Sf,key_ops:["verify"],x:n,y:o});if(t.byteLength===to*2+1)return n=V(t.subarray(r,r+to),"base64url"),o=V(t.subarray(r+to),"base64url"),new Ie({...Af,key_ops:["verify"],x:n,y:o});if(t.byteLength===eo*2+1)return n=V(t.subarray(r,r+eo),"base64url"),o=V(t.subarray(r+eo),"base64url"),new Ie({...vf,key_ops:["verify"],x:n,y:o});throw new Q(`coordinates were wrong length, got ${t.byteLength}, expected 65, 97 or 133`)}function Ys(e){return Zt([gt(Uint8Array.from([1])),Zt([Bf(e.crv)],160),Zt([Cr(new z(Uint8Array.from([4]),Z(e.x??"","base64url"),Z(e.y??"","base64url")))],161)]).subarray()}function Bf(e){if(e==="P-256")return bf;if(e==="P-384")return wf;if(e==="P-521")return Ef;throw new Q(`Invalid curve ${e}`)}var Ie=class{type="ECDSA";jwk;_raw;constructor(t){this.jwk=t}get raw(){return this._raw==null&&(this._raw=Ys(this.jwk)),this._raw}toMultihash(){return Kt.digest(Yt(this))}toCID(){return ct.createV1(114,this.toMultihash())}toString(){return J.encode(this.toMultihash().bytes).substring(1)}equals(t){return t==null||!(t.raw instanceof Uint8Array)?!1:dt(this.raw,t.raw)}async verify(t,r,n){return Fs(this.jwk,r,t,n)}};var ne=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;function Te(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name==="Uint8Array"}function oe(e){if(!Number.isSafeInteger(e)||e<0)throw new Error("positive integer expected, got "+e)}function ft(e,...t){if(!Te(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error("Uint8Array expected of length "+t+", got length="+e.length)}function Qe(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.createHasher");oe(e.outputLen),oe(e.blockLen)}function Ke(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 Ws(e,t){ft(e);let r=t.outputLen;if(e.length<r)throw new Error("digestInto() expects output buffer of length at least "+r)}function vt(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function Ur(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function Bt(e,t){return e<<32-t|e>>>t}var $s=typeof Uint8Array.from([]).toHex=="function"&&typeof Uint8Array.fromHex=="function",_f=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,"0"));function Ct(e){if(ft(e),$s)return e.toHex();let t="";for(let r=0;r<e.length;r++)t+=_f[e[r]];return t}var Ht={_0:48,_9:57,A:65,F:70,a:97,f:102};function Xs(e){if(e>=Ht._0&&e<=Ht._9)return e-Ht._0;if(e>=Ht.A&&e<=Ht.F)return e-(Ht.A-10);if(e>=Ht.a&&e<=Ht.f)return e-(Ht.a-10)}function Ce(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);if($s)return Uint8Array.fromHex(e);let t=e.length,r=t/2;if(t%2)throw new Error("hex string expected, got unpadded hex of length "+t);let n=new Uint8Array(r);for(let o=0,s=0;o<r;o++,s+=2){let i=Xs(e.charCodeAt(s)),a=Xs(e.charCodeAt(s+1));if(i===void 0||a===void 0){let c=e[s]+e[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[o]=i*16+a}return n}function Js(e){if(typeof e!="string")throw new Error("string expected");return new Uint8Array(new TextEncoder().encode(e))}function Xt(e){return typeof e=="string"&&(e=Js(e)),ft(e),e}function bt(...e){let t=0;for(let n=0;n<e.length;n++){let o=e[n];ft(o),t+=o.length}let r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){let s=e[n];r.set(s,o),o+=s.length}return r}var Le=class{};function ro(e){let t=n=>e().update(Xt(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function se(e=32){if(ne&&typeof ne.getRandomValues=="function")return ne.getRandomValues(new Uint8Array(e));if(ne&&typeof ne.randomBytes=="function")return Uint8Array.from(ne.randomBytes(e));throw new Error("crypto.getRandomValues must be defined")}function If(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);let o=BigInt(32),s=BigInt(4294967295),i=Number(r>>o&s),a=Number(r&s),c=n?4:0,h=n?0:4;e.setUint32(t+c,i,n),e.setUint32(t+h,a,n)}function Qs(e,t,r){return e&t^~e&r}function ti(e,t,r){return e&t^e&r^t&r}var tr=class extends Le{constructor(t,r,n,o){super(),this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.buffer=new Uint8Array(t),this.view=Ur(this.buffer)}update(t){Ke(this),t=Xt(t),ft(t);let{view:r,buffer:n,blockLen:o}=this,s=t.length;for(let i=0;i<s;){let a=Math.min(o-this.pos,s-i);if(a===o){let c=Ur(t);for(;o<=s-i;i+=o)this.process(c,i);continue}n.set(t.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){Ke(this),Ws(t,this),this.finished=!0;let{buffer:r,view:n,blockLen:o,isLE:s}=this,{pos:i}=this;r[i++]=128,vt(this.buffer.subarray(i)),this.padOffset>o-i&&(this.process(n,0),i=0);for(let u=i;u<o;u++)r[u]=0;If(n,o-8,BigInt(this.length*8),s),this.process(n,0);let a=Ur(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should 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],s)}digest(){let{buffer:t,outputLen:r}=this;this.digestInto(t);let n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());let{blockLen:r,buffer:n,length:o,finished:s,destroyed:i,pos:a}=this;return t.destroyed=i,t.finished=s,t.length=o,t.pos=a,o%r&&t.buffer.set(n),t}clone(){return this._cloneInto()}},Ot=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]);var st=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]);var Dr=BigInt(4294967295),ei=BigInt(32);function Lf(e,t=!1){return t?{h:Number(e&Dr),l:Number(e>>ei&Dr)}:{h:Number(e>>ei&Dr)|0,l:Number(e&Dr)|0}}function ri(e,t=!1){let r=e.length,n=new Uint32Array(r),o=new Uint32Array(r);for(let s=0;s<r;s++){let{h:i,l:a}=Lf(e[s],t);[n[s],o[s]]=[i,a]}return[n,o]}var no=(e,t,r)=>e>>>r,oo=(e,t,r)=>e<<32-r|t>>>r,ie=(e,t,r)=>e>>>r|t<<32-r,ae=(e,t,r)=>e<<32-r|t>>>r,er=(e,t,r)=>e<<64-r|t>>>r-32,rr=(e,t,r)=>e>>>r-32|t<<64-r;function Ut(e,t,r,n){let o=(t>>>0)+(n>>>0);return{h:e+r+(o/2**32|0)|0,l:o|0}}var ni=(e,t,r)=>(e>>>0)+(t>>>0)+(r>>>0),oi=(e,t,r,n)=>t+r+n+(e/2**32|0)|0,si=(e,t,r,n)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0),ii=(e,t,r,n,o)=>t+r+n+o+(e/2**32|0)|0,ai=(e,t,r,n,o)=>(e>>>0)+(t>>>0)+(r>>>0)+(n>>>0)+(o>>>0),ci=(e,t,r,n,o,s)=>t+r+n+o+s+(e/2**32|0)|0;var Kf=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]),Wt=new Uint32Array(64),Rr=class extends tr{constructor(t=32){super(64,t,8,!1),this.A=Ot[0]|0,this.B=Ot[1]|0,this.C=Ot[2]|0,this.D=Ot[3]|0,this.E=Ot[4]|0,this.F=Ot[5]|0,this.G=Ot[6]|0,this.H=Ot[7]|0}get(){let{A:t,B:r,C:n,D:o,E:s,F:i,G:a,H:c}=this;return[t,r,n,o,s,i,a,c]}set(t,r,n,o,s,i,a,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=s|0,this.F=i|0,this.G=a|0,this.H=c|0}process(t,r){for(let u=0;u<16;u++,r+=4)Wt[u]=t.getUint32(r,!1);for(let u=16;u<64;u++){let m=Wt[u-15],y=Wt[u-2],w=Bt(m,7)^Bt(m,18)^m>>>3,x=Bt(y,17)^Bt(y,19)^y>>>10;Wt[u]=x+Wt[u-7]+w+Wt[u-16]|0}let{A:n,B:o,C:s,D:i,E:a,F:c,G:h,H:f}=this;for(let u=0;u<64;u++){let m=Bt(a,6)^Bt(a,11)^Bt(a,25),y=f+m+Qs(a,c,h)+Kf[u]+Wt[u]|0,x=(Bt(n,2)^Bt(n,13)^Bt(n,22))+ti(n,o,s)|0;f=h,h=c,c=a,a=i+y|0,i=s,s=o,o=n,n=y+x|0}n=n+this.A|0,o=o+this.B|0,s=s+this.C|0,i=i+this.D|0,a=a+this.E|0,c=c+this.F|0,h=h+this.G|0,f=f+this.H|0,this.set(n,o,s,i,a,c,h,f)}roundClean(){vt(Wt)}destroy(){this.set(0,0,0,0,0,0,0,0),vt(this.buffer)}};var fi=ri(["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))),Cf=fi[0],Uf=fi[1],$t=new Uint32Array(80),Jt=new Uint32Array(80),so=class extends tr{constructor(t=64){super(128,t,16,!1),this.Ah=st[0]|0,this.Al=st[1]|0,this.Bh=st[2]|0,this.Bl=st[3]|0,this.Ch=st[4]|0,this.Cl=st[5]|0,this.Dh=st[6]|0,this.Dl=st[7]|0,this.Eh=st[8]|0,this.El=st[9]|0,this.Fh=st[10]|0,this.Fl=st[11]|0,this.Gh=st[12]|0,this.Gl=st[13]|0,this.Hh=st[14]|0,this.Hl=st[15]|0}get(){let{Ah:t,Al:r,Bh:n,Bl:o,Ch:s,Cl:i,Dh:a,Dl:c,Eh:h,El:f,Fh:u,Fl:m,Gh:y,Gl:w,Hh:x,Hl:l}=this;return[t,r,n,o,s,i,a,c,h,f,u,m,y,w,x,l]}set(t,r,n,o,s,i,a,c,h,f,u,m,y,w,x,l){this.Ah=t|0,this.Al=r|0,this.Bh=n|0,this.Bl=o|0,this.Ch=s|0,this.Cl=i|0,this.Dh=a|0,this.Dl=c|0,this.Eh=h|0,this.El=f|0,this.Fh=u|0,this.Fl=m|0,this.Gh=y|0,this.Gl=w|0,this.Hh=x|0,this.Hl=l|0}process(t,r){for(let _=0;_<16;_++,r+=4)$t[_]=t.getUint32(r),Jt[_]=t.getUint32(r+=4);for(let _=16;_<80;_++){let P=$t[_-15]|0,S=Jt[_-15]|0,D=ie(P,S,1)^ie(P,S,8)^no(P,S,7),K=ae(P,S,1)^ae(P,S,8)^oo(P,S,7),T=$t[_-2]|0,d=Jt[_-2]|0,g=ie(T,d,19)^er(T,d,61)^no(T,d,6),p=ae(T,d,19)^rr(T,d,61)^oo(T,d,6),b=si(K,p,Jt[_-7],Jt[_-16]),A=ii(b,D,g,$t[_-7],$t[_-16]);$t[_]=A|0,Jt[_]=b|0}let{Ah:n,Al:o,Bh:s,Bl:i,Ch:a,Cl:c,Dh:h,Dl:f,Eh:u,El:m,Fh:y,Fl:w,Gh:x,Gl:l,Hh:E,Hl:I}=this;for(let _=0;_<80;_++){let P=ie(u,m,14)^ie(u,m,18)^er(u,m,41),S=ae(u,m,14)^ae(u,m,18)^rr(u,m,41),D=u&y^~u&x,K=m&w^~m&l,T=ai(I,S,K,Uf[_],Jt[_]),d=ci(T,E,P,D,Cf[_],$t[_]),g=T|0,p=ie(n,o,28)^er(n,o,34)^er(n,o,39),b=ae(n,o,28)^rr(n,o,34)^rr(n,o,39),A=n&s^n&a^s&a,B=o&i^o&c^i&c;E=x|0,I=l|0,x=y|0,l=w|0,y=u|0,w=m|0,{h:u,l:m}=Ut(h|0,f|0,d|0,g|0),h=a|0,f=c|0,a=s|0,c=i|0,s=n|0,i=o|0;let v=ni(g,b,B);n=oi(v,d,p,A),o=v|0}({h:n,l:o}=Ut(this.Ah|0,this.Al|0,n|0,o|0)),{h:s,l:i}=Ut(this.Bh|0,this.Bl|0,s|0,i|0),{h:a,l:c}=Ut(this.Ch|0,this.Cl|0,a|0,c|0),{h,l:f}=Ut(this.Dh|0,this.Dl|0,h|0,f|0),{h:u,l:m}=Ut(this.Eh|0,this.El|0,u|0,m|0),{h:y,l:w}=Ut(this.Fh|0,this.Fl|0,y|0,w|0),{h:x,l}=Ut(this.Gh|0,this.Gl|0,x|0,l|0),{h:E,l:I}=Ut(this.Hh|0,this.Hl|0,E|0,I|0),this.set(n,o,s,i,a,c,h,f,u,m,y,w,x,l,E,I)}roundClean(){vt($t,Jt)}destroy(){vt(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var Pr=ro(()=>new Rr);var ui=ro(()=>new so);var co=BigInt(0),ao=BigInt(1);function qt(e,t){if(typeof t!="boolean")throw new Error(e+" boolean expected, got "+t)}function nr(e){let t=e.toString(16);return t.length&1?"0"+t:t}function hi(e){if(typeof e!="string")throw new Error("hex string expected, got "+typeof e);return e===""?co:BigInt("0x"+e)}function Ue(e){return hi(Ct(e))}function Dt(e){return ft(e),hi(Ct(Uint8Array.from(e).reverse()))}function Nr(e,t){return Ce(e.toString(16).padStart(t*2,"0"))}function Qt(e,t){return Nr(e,t).reverse()}function F(e,t,r){let n;if(typeof t=="string")try{n=Ce(t)}catch(s){throw new Error(e+" must be hex string or Uint8Array, cause: "+s)}else if(Te(t))n=Uint8Array.from(t);else throw new Error(e+" must be hex string or Uint8Array");let o=n.length;if(typeof r=="number"&&o!==r)throw new Error(e+" of length "+r+" expected, got "+o);return n}var io=e=>typeof e=="bigint"&&co<=e;function li(e,t,r){return io(e)&&io(t)&&io(r)&&t<=e&&e<r}function _t(e,t,r,n){if(!li(t,r,n))throw new Error("expected valid "+e+": "+r+" <= n < "+n+", got "+t)}function di(e){let t;for(t=0;e>co;e>>=ao,t+=1);return t}var ce=e=>(ao<<BigInt(e))-ao;function pi(e,t,r){if(typeof e!="number"||e<2)throw new Error("hashLen must be a number");if(typeof t!="number"||t<2)throw new Error("qByteLen must be a number");if(typeof r!="function")throw new Error("hmacFn must be a function");let n=y=>new Uint8Array(y),o=y=>Uint8Array.of(y),s=n(e),i=n(e),a=0,c=()=>{s.fill(1),i.fill(0),a=0},h=(...y)=>r(i,s,...y),f=(y=n(0))=>{i=h(o(0),y),s=h(),y.length!==0&&(i=h(o(1),y),s=h())},u=()=>{if(a++>=1e3)throw new Error("drbg: tried 1000 values");let y=0,w=[];for(;y<t;){s=h();let x=s.slice();w.push(x),y+=s.length}return bt(...w)};return(y,w)=>{c(),f(y);let x;for(;!(x=w(u()));)f();return c(),x}}function Rt(e,t,r={}){if(!e||typeof e!="object")throw new Error("expected valid options object");function n(o,s,i){let a=e[o];if(i&&a===void 0)return;let c=typeof a;if(c!==s||a===null)throw new Error(`param "${o}" is invalid: expected ${s}, got ${c}`)}Object.entries(t).forEach(([o,s])=>n(o,s,!1)),Object.entries(r).forEach(([o,s])=>n(o,s,!0))}function De(e){let t=new WeakMap;return(r,...n)=>{let o=t.get(r);if(o!==void 0)return o;let s=e(r,...n);return t.set(r,s),s}}var pt=BigInt(0),rt=BigInt(1),fe=BigInt(2),Df=BigInt(3),xi=BigInt(4),gi=BigInt(5),bi=BigInt(8);function Y(e,t){let r=e%t;return r>=pt?r:t+r}function X(e,t,r){let n=e;for(;t-- >pt;)n*=n,n%=r;return n}function yi(e,t){if(e===pt)throw new Error("invert: expected non-zero number");if(t<=pt)throw new Error("invert: expected positive modulus, got "+t);let r=Y(e,t),n=t,o=pt,s=rt,i=rt,a=pt;for(;r!==pt;){let h=n/r,f=n%r,u=o-i*h,m=s-a*h;n=r,r=f,o=i,s=a,i=u,a=m}if(n!==rt)throw new Error("invert: does not exist");return Y(o,t)}function wi(e,t){let r=(e.ORDER+rt)/xi,n=e.pow(t,r);if(!e.eql(e.sqr(n),t))throw new Error("Cannot find square root");return n}function Rf(e,t){let r=(e.ORDER-gi)/bi,n=e.mul(t,fe),o=e.pow(n,r),s=e.mul(t,o),i=e.mul(e.mul(s,fe),o),a=e.mul(s,e.sub(i,e.ONE));if(!e.eql(e.sqr(a),t))throw new Error("Cannot find square root");return a}function Pf(e){if(e<BigInt(3))throw new Error("sqrt is not defined for small field");let t=e-rt,r=0;for(;t%fe===pt;)t/=fe,r++;let n=fe,o=It(e);for(;mi(o,n)===1;)if(n++>1e3)throw new Error("Cannot find square root: probably non-prime P");if(r===1)return wi;let s=o.pow(n,t),i=(t+rt)/fe;return function(c,h){if(c.is0(h))return h;if(mi(c,h)!==1)throw new Error("Cannot find square root");let f=r,u=c.mul(c.ONE,s),m=c.pow(h,t),y=c.pow(h,i);for(;!c.eql(m,c.ONE);){if(c.is0(m))return c.ZERO;let w=1,x=c.sqr(m);for(;!c.eql(x,c.ONE);)if(w++,x=c.sqr(x),w===f)throw new Error("Cannot find square root");let l=rt<<BigInt(f-w-1),E=c.pow(u,l);f=w,u=c.sqr(E),m=c.mul(m,u),y=c.mul(y,E)}return y}}function Nf(e){return e%xi===Df?wi:e%bi===gi?Rf:Pf(e)}var Ei=(e,t)=>(Y(e,t)&rt)===rt,kf=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function fo(e){let t={ORDER:"bigint",MASK:"bigint",BYTES:"number",BITS:"number"},r=kf.reduce((n,o)=>(n[o]="function",n),t);return Rt(e,r),e}function Mf(e,t,r){if(r<pt)throw new Error("invalid exponent, negatives unsupported");if(r===pt)return e.ONE;if(r===rt)return t;let n=e.ONE,o=t;for(;r>pt;)r&rt&&(n=e.mul(n,o)),o=e.sqr(o),r>>=rt;return n}function or(e,t,r=!1){let n=new Array(t.length).fill(r?e.ZERO:void 0),o=t.reduce((i,a,c)=>e.is0(a)?i:(n[c]=i,e.mul(i,a)),e.ONE),s=e.inv(o);return t.reduceRight((i,a,c)=>e.is0(a)?i:(n[c]=e.mul(i,n[c]),e.mul(i,a)),s),n}function mi(e,t){let r=(e.ORDER-rt)/fe,n=e.pow(t,r),o=e.eql(n,e.ONE),s=e.eql(n,e.ZERO),i=e.eql(n,e.neg(e.ONE));if(!o&&!s&&!i)throw new Error("invalid Legendre symbol result");return o?1:s?0:-1}function Si(e,t){t!==void 0&&oe(t);let r=t!==void 0?t:e.toString(2).length,n=Math.ceil(r/8);return{nBitLength:r,nByteLength:n}}function It(e,t,r=!1,n={}){if(e<=pt)throw new Error("invalid field: expected ORDER > 0, got "+e);let o,s;if(typeof t=="object"&&t!=null){if(n.sqrt||r)throw new Error("cannot specify opts in two arguments");let f=t;f.BITS&&(o=f.BITS),f.sqrt&&(s=f.sqrt),typeof f.isLE=="boolean"&&(r=f.isLE)}else typeof t=="number"&&(o=t),n.sqrt&&(s=n.sqrt);let{nBitLength:i,nByteLength:a}=Si(e,o);if(a>2048)throw new Error("invalid field: expected ORDER of <= 2048 bytes");let c,h=Object.freeze({ORDER:e,isLE:r,BITS:i,BYTES:a,MASK:ce(i),ZERO:pt,ONE:rt,create:f=>Y(f,e),isValid:f=>{if(typeof f!="bigint")throw new Error("invalid field element: expected bigint, got "+typeof f);return pt<=f&&f<e},is0:f=>f===pt,isValidNot0:f=>!h.is0(f)&&h.isValid(f),isOdd:f=>(f&rt)===rt,neg:f=>Y(-f,e),eql:(f,u)=>f===u,sqr:f=>Y(f*f,e),add:(f,u)=>Y(f+u,e),sub:(f,u)=>Y(f-u,e),mul:(f,u)=>Y(f*u,e),pow:(f,u)=>Mf(h,f,u),div:(f,u)=>Y(f*yi(u,e),e),sqrN:f=>f*f,addN:(f,u)=>f+u,subN:(f,u)=>f-u,mulN:(f,u)=>f*u,inv:f=>yi(f,e),sqrt:s||(f=>(c||(c=Nf(e)),c(h,f))),toBytes:f=>r?Qt(f,a):Nr(f,a),fromBytes:f=>{if(f.length!==a)throw new Error("Field.fromBytes: expected "+a+" bytes, got "+f.length);return r?Dt(f):Ue(f)},invertBatch:f=>or(h,f),cmov:(f,u,m)=>m?u:f});return Object.freeze(h)}function Ai(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 uo(e){let t=Ai(e);return t+Math.ceil(t/2)}function vi(e,t,r=!1){let n=e.length,o=Ai(t),s=uo(t);if(n<16||n<s||n>1024)throw new Error("expected "+s+"-1024 bytes of input, got "+n);let i=r?Dt(e):Ue(e),a=Y(i,t-rt)+rt;return r?Qt(a,o):Nr(a,o)}var Pe=BigInt(0),ue=BigInt(1);function Re(e,t){let r=t.negate();return e?r:t}function kr(e,t,r){let n=t==="pz"?i=>i.pz:i=>i.ez,o=or(e.Fp,r.map(n));return r.map((i,a)=>i.toAffine(o[a])).map(e.fromAffine)}function Li(e,t){if(!Number.isSafeInteger(e)||e<=0||e>t)throw new Error("invalid window size, expected [1.."+t+"], got W="+e)}function ho(e,t){Li(e,t);let r=Math.ceil(t/e)+1,n=2**(e-1),o=2**e,s=ce(e),i=BigInt(e);return{windows:r,windowSize:n,mask:s,maxNumber:o,shiftBy:i}}function Bi(e,t,r){let{windowSize:n,mask:o,maxNumber:s,shiftBy:i}=r,a=Number(e&o),c=e>>i;a>n&&(a-=s,c+=ue);let h=t*n,f=h+Math.abs(a)-1,u=a===0,m=a<0,y=t%2!==0;return{nextN:c,offset:f,isZero:u,isNeg:m,isNegF:y,offsetF:h}}function Hf(e,t){if(!Array.isArray(e))throw new Error("array expected");e.forEach((r,n)=>{if(!(r instanceof t))throw new Error("invalid point at index "+n)})}function Of(e,t){if(!Array.isArray(e))throw new Error("array of scalars expected");e.forEach((r,n)=>{if(!t.isValid(r))throw new Error("invalid scalar at index "+n)})}var lo=new WeakMap,Ti=new WeakMap;function po(e){return Ti.get(e)||1}function _i(e){if(e!==Pe)throw new Error("invalid wNAF")}function Mr(e,t){return{constTimeNegate:Re,hasPrecomputes(r){return po(r)!==1},unsafeLadder(r,n,o=e.ZERO){let s=r;for(;n>Pe;)n&ue&&(o=o.add(s)),s=s.double(),n>>=ue;return o},precomputeWindow(r,n){let{windows:o,windowSize:s}=ho(n,t),i=[],a=r,c=a;for(let h=0;h<o;h++){c=a,i.push(c);for(let f=1;f<s;f++)c=c.add(a),i.push(c);a=c.double()}return i},wNAF(r,n,o){let s=e.ZERO,i=e.BASE,a=ho(r,t);for(let c=0;c<a.windows;c++){let{nextN:h,offset:f,isZero:u,isNeg:m,isNegF:y,offsetF:w}=Bi(o,c,a);o=h,u?i=i.add(Re(y,n[w])):s=s.add(Re(m,n[f]))}return _i(o),{p:s,f:i}},wNAFUnsafe(r,n,o,s=e.ZERO){let i=ho(r,t);for(let a=0;a<i.windows&&o!==Pe;a++){let{nextN:c,offset:h,isZero:f,isNeg:u}=Bi(o,a,i);if(o=c,!f){let m=n[h];s=s.add(u?m.negate():m)}}return _i(o),s},getPrecomputes(r,n,o){let s=lo.get(n);return s||(s=this.precomputeWindow(n,r),r!==1&&(typeof o=="function"&&(s=o(s)),lo.set(n,s))),s},wNAFCached(r,n,o){let s=po(r);return this.wNAF(s,this.getPrecomputes(s,r,o),n)},wNAFCachedUnsafe(r,n,o,s){let i=po(r);return i===1?this.unsafeLadder(r,n,s):this.wNAFUnsafe(i,this.getPrecomputes(i,r,o),n,s)},setWindowSize(r,n){Li(n,t),Ti.set(r,n),lo.delete(r)}}}function Ki(e,t,r,n){let o=t,s=e.ZERO,i=e.ZERO;for(;r>Pe||n>Pe;)r&ue&&(s=s.add(o)),n&ue&&(i=i.add(o)),o=o.double(),r>>=ue,n>>=ue;return{p1:s,p2:i}}function Hr(e,t,r,n){Hf(r,e),Of(n,t);let o=r.length,s=n.length;if(o!==s)throw new Error("arrays of points and scalars must have equal length");let i=e.ZERO,a=di(BigInt(o)),c=1;a>12?c=a-3:a>4?c=a-2:a>0&&(c=2);let h=ce(c),f=new Array(Number(h)+1).fill(i),u=Math.floor((t.BITS-1)/c)*c,m=i;for(let y=u;y>=0;y-=c){f.fill(i);for(let x=0;x<s;x++){let l=n[x],E=Number(l>>BigInt(y)&h);f[E]=f[E].add(r[x])}let w=i;for(let x=f.length-1,l=i;x>0;x--)l=l.add(f[x]),w=w.add(l);if(m=m.add(w),y!==0)for(let x=0;x<c;x++)m=m.double()}return m}function Ii(e,t){if(t){if(t.ORDER!==e)throw new Error("Field.ORDER must match order: Fp == p, Fn == n");return fo(t),t}else return It(e)}function Or(e,t,r={}){if(!t||typeof t!="object")throw new Error(`expected valid ${e} CURVE object`);for(let a of["p","n","h"]){let c=t[a];if(!(typeof c=="bigint"&&c>Pe))throw new Error(`CURVE.${a} must be positive bigint`)}let n=Ii(t.p,r.Fp),o=Ii(t.n,r.Fn),i=["Gx","Gy","a",e==="weierstrass"?"b":"d"];for(let a of i)if(!n.isValid(t[a]))throw new Error(`CURVE.${a} must be valid field element of CURVE.Fp`);return{Fp:n,Fn:o}}var Pt=BigInt(0),yt=BigInt(1),yo=BigInt(2),qf=BigInt(8),Vf={zip215:!0};function zf(e,t,r,n){let o=e.sqr(r),s=e.sqr(n),i=e.a