UNPKG

@stacks/profile

Version:

Library for Stacks profiles

2 lines 169 kB
/*! For license information please see index.js.LICENSE.txt */ !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.StacksProfile=e():t.StacksProfile=e()}(this,(()=>(()=>{var t,e,n={525:(t,e)=>{"use strict";function n(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`Wrong positive integer: ${t}`)}function r(t){if("boolean"!=typeof t)throw new Error(`Expected boolean, not ${t}`)}function i(t,...e){if(!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(e.length>0&&!e.includes(t.length))throw new TypeError(`Expected Uint8Array of length ${e}, not of length=${t.length}`)}function o(t){if("function"!=typeof t||"function"!=typeof t.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");n(t.outputLen),n(t.blockLen)}function s(t,e=!0){if(t.destroyed)throw new Error("Hash instance has been destroyed");if(e&&t.finished)throw new Error("Hash#digest() has already been called")}function a(t,e){i(t);const n=e.outputLen;if(t.length<n)throw new Error(`digestInto() expects output buffer of length at least ${n}`)}Object.defineProperty(e,"__esModule",{value:!0}),e.output=e.exists=e.hash=e.bytes=e.bool=e.number=void 0,e.number=n,e.bool=r,e.bytes=i,e.hash=o,e.exists=s,e.output=a;const c={number:n,bool:r,bytes:i,hash:o,exists:s,output:a};e.default=c},350:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.SHA2=void 0;const r=n(525),i=n(64);class o extends i.Hash{constructor(t,e,n,r){super(),this.blockLen=t,this.outputLen=e,this.padOffset=n,this.isLE=r,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=(0,i.createView)(this.buffer)}update(t){r.default.exists(this);const{view:e,buffer:n,blockLen:o}=this,s=(t=(0,i.toBytes)(t)).length;for(let r=0;r<s;){const a=Math.min(o-this.pos,s-r);if(a!==o)n.set(t.subarray(r,r+a),this.pos),this.pos+=a,r+=a,this.pos===o&&(this.process(e,0),this.pos=0);else{const e=(0,i.createView)(t);for(;o<=s-r;r+=o)this.process(e,r)}}return this.length+=t.length,this.roundClean(),this}digestInto(t){r.default.exists(this),r.default.output(t,this),this.finished=!0;const{buffer:e,view:n,blockLen:o,isLE:s}=this;let{pos:a}=this;e[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>o-a&&(this.process(n,0),a=0);for(let t=a;t<o;t++)e[t]=0;!function(t,e,n,r){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,n,r);const i=BigInt(32),o=BigInt(4294967295),s=Number(n>>i&o),a=Number(n&o),c=r?4:0,u=r?0:4;t.setUint32(e+c,s,r),t.setUint32(e+u,a,r)}(n,o-8,BigInt(8*this.length),s),this.process(n,0);const c=(0,i.createView)(t),u=this.outputLen;if(u%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const f=u/4,l=this.get();if(f>l.length)throw new Error("_sha2: outputLen bigger than state");for(let t=0;t<f;t++)c.setUint32(4*t,l[t],s)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const n=t.slice(0,e);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:n,length:r,finished:i,destroyed:o,pos:s}=this;return t.length=r,t.pos=s,t.finished=i,t.destroyed=o,r%e&&t.buffer.set(n),t}}e.SHA2=o},661:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.crypto=void 0,e.crypto={node:void 0,web:"object"==typeof self&&"crypto"in self?self.crypto:void 0}},514:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.hmac=void 0;const r=n(525),i=n(64);class o extends i.Hash{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,r.default.hash(t);const n=(0,i.toBytes)(e);if(this.iHash=t.create(),"function"!=typeof this.iHash.update)throw new TypeError("Expected instance of class which extends utils.Hash");this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;const o=this.blockLen,s=new Uint8Array(o);s.set(n.length>o?t.create().update(n).digest():n);for(let t=0;t<s.length;t++)s[t]^=54;this.iHash.update(s),this.oHash=t.create();for(let t=0;t<s.length;t++)s[t]^=106;this.oHash.update(s),s.fill(0)}update(t){return r.default.exists(this),this.iHash.update(t),this}digestInto(t){r.default.exists(this),r.default.bytes(t,this.outputLen),this.finished=!0,this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){const t=new Uint8Array(this.oHash.outputLen);return this.digestInto(t),t}_cloneInto(t){t||(t=Object.create(Object.getPrototypeOf(this),{}));const{oHash:e,iHash:n,finished:r,destroyed:i,blockLen:o,outputLen:s}=this;return t.finished=r,t.destroyed=i,t.blockLen=o,t.outputLen=s,t.oHash=e._cloneInto(t.oHash),t.iHash=n._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}e.hmac=(t,e,n)=>new o(t,e).update(n).digest(),e.hmac.create=(t,e)=>new o(t,e)},53:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.sha224=e.sha256=void 0;const r=n(350),i=n(64),o=(t,e,n)=>t&e^t&n^e&n,s=new Uint32Array([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]),a=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),c=new Uint32Array(64);class u extends r.SHA2{constructor(){super(64,32,8,!1),this.A=0|a[0],this.B=0|a[1],this.C=0|a[2],this.D=0|a[3],this.E=0|a[4],this.F=0|a[5],this.G=0|a[6],this.H=0|a[7]}get(){const{A:t,B:e,C:n,D:r,E:i,F:o,G:s,H:a}=this;return[t,e,n,r,i,o,s,a]}set(t,e,n,r,i,o,s,a){this.A=0|t,this.B=0|e,this.C=0|n,this.D=0|r,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(t,e){for(let n=0;n<16;n++,e+=4)c[n]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=c[t-15],n=c[t-2],r=(0,i.rotr)(e,7)^(0,i.rotr)(e,18)^e>>>3,o=(0,i.rotr)(n,17)^(0,i.rotr)(n,19)^n>>>10;c[t]=o+c[t-7]+r+c[t-16]|0}let{A:n,B:r,C:a,D:u,E:f,F:l,G:h,H:p}=this;for(let t=0;t<64;t++){const e=p+((0,i.rotr)(f,6)^(0,i.rotr)(f,11)^(0,i.rotr)(f,25))+((d=f)&l^~d&h)+s[t]+c[t]|0,y=((0,i.rotr)(n,2)^(0,i.rotr)(n,13)^(0,i.rotr)(n,22))+o(n,r,a)|0;p=h,h=l,l=f,f=u+e|0,u=a,a=r,r=n,n=e+y|0}var d;n=n+this.A|0,r=r+this.B|0,a=a+this.C|0,u=u+this.D|0,f=f+this.E|0,l=l+this.F|0,h=h+this.G|0,p=p+this.H|0,this.set(n,r,a,u,f,l,h,p)}roundClean(){c.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}}class f extends u{constructor(){super(),this.A=-1056596264,this.B=914150663,this.C=812702999,this.D=-150054599,this.E=-4191439,this.F=1750603025,this.G=1694076839,this.H=-1090891868,this.outputLen=28}}e.sha256=(0,i.wrapConstructor)((()=>new u)),e.sha224=(0,i.wrapConstructor)((()=>new f))},64:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.randomBytes=e.wrapConstructorWithOpts=e.wrapConstructor=e.checkOpts=e.Hash=e.concatBytes=e.toBytes=e.utf8ToBytes=e.asyncLoop=e.nextTick=e.hexToBytes=e.bytesToHex=e.isLE=e.rotr=e.createView=e.u32=e.u8=void 0;const r=n(661);if(e.u8=t=>new Uint8Array(t.buffer,t.byteOffset,t.byteLength),e.u32=t=>new Uint32Array(t.buffer,t.byteOffset,Math.floor(t.byteLength/4)),e.createView=t=>new DataView(t.buffer,t.byteOffset,t.byteLength),e.rotr=(t,e)=>t<<32-e|t>>>e,e.isLE=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0],!e.isLE)throw new Error("Non little-endian hardware is not supported");const i=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function o(t){if("string"!=typeof t)throw new TypeError("utf8ToBytes expected string, got "+typeof t);return(new TextEncoder).encode(t)}function s(t){if("string"==typeof t&&(t=o(t)),!(t instanceof Uint8Array))throw new TypeError(`Expected input type is Uint8Array (got ${typeof t})`);return t}e.bytesToHex=function(t){if(!(t instanceof Uint8Array))throw new Error("Uint8Array expected");let e="";for(let n=0;n<t.length;n++)e+=i[t[n]];return e},e.hexToBytes=function(t){if("string"!=typeof t)throw new TypeError("hexToBytes: expected string, got "+typeof t);if(t.length%2)throw new Error("hexToBytes: received invalid unpadded hex");const e=new Uint8Array(t.length/2);for(let n=0;n<e.length;n++){const r=2*n,i=t.slice(r,r+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");e[n]=o}return e},e.nextTick=async()=>{},e.asyncLoop=async function(t,n,r){let i=Date.now();for(let o=0;o<t;o++){r(o);const t=Date.now()-i;t>=0&&t<n||(await(0,e.nextTick)(),i+=t)}},e.utf8ToBytes=o,e.toBytes=s,e.concatBytes=function(...t){if(!t.every((t=>t instanceof Uint8Array)))throw new Error("Uint8Array list expected");if(1===t.length)return t[0];const e=t.reduce(((t,e)=>t+e.length),0),n=new Uint8Array(e);for(let e=0,r=0;e<t.length;e++){const i=t[e];n.set(i,r),r+=i.length}return n},e.Hash=class{clone(){return this._cloneInto()}},e.checkOpts=function(t,e){if(void 0!==e&&("object"!=typeof e||(n=e,"[object Object]"!==Object.prototype.toString.call(n)||n.constructor!==Object)))throw new TypeError("Options should be object or undefined");var n;return Object.assign(t,e)},e.wrapConstructor=function(t){const e=e=>t().update(s(e)).digest(),n=t();return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=()=>t(),e},e.wrapConstructorWithOpts=function(t){const e=(e,n)=>t(n).update(s(e)).digest(),n=t({});return e.outputLen=n.outputLen,e.blockLen=n.blockLen,e.create=e=>t(e),e},e.randomBytes=function(t=32){if(r.crypto.web)return r.crypto.web.getRandomValues(new Uint8Array(t));if(r.crypto.node)return new Uint8Array(r.crypto.node.randomBytes(t).buffer);throw new Error("The environment doesn't have randomBytes function")}},698:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.utils=e.schnorr=e.verify=e.signSync=e.sign=e.getSharedSecret=e.recoverPublicKey=e.getPublicKey=e.Signature=e.Point=e.CURVE=void 0;const r=n(695),i=BigInt(0),o=BigInt(1),s=BigInt(2),a=BigInt(3),c=BigInt(8),u=Object.freeze({a:i,b:BigInt(7),P:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:o,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee")});e.CURVE=u;const f=(t,e)=>(t+e/s)/e,l={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar(t){const{n:e}=u,n=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),r=-o*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=n,a=BigInt("0x100000000000000000000000000000000"),c=f(s*t,e),l=f(-r*t,e);let h=$(t-c*n-l*i,e),p=$(-c*r-l*s,e);const d=h>a,y=p>a;if(d&&(h=e-h),y&&(p=e-p),h>a||p>a)throw new Error("splitScalarEndo: Endomorphism failed, k="+t);return{k1neg:d,k1:h,k2neg:y,k2:p}}},h=32,p=32,d=h+1,y=2*h+1;function g(t){const{a:e,b:n}=u,r=$(t*t),i=$(r*t);return $(i+e*t+n)}const m=u.a===i;class b extends Error{constructor(t){super(t)}}function v(t){if(!(t instanceof w))throw new TypeError("JacobianPoint expected")}class w{constructor(t,e,n){this.x=t,this.y=e,this.z=n}static fromAffine(t){if(!(t instanceof S))throw new TypeError("JacobianPoint#fromAffine: expected Point");return t.equals(S.ZERO)?w.ZERO:new w(t.x,t.y,o)}static toAffineBatch(t){const e=function(t,e=u.P){const n=new Array(t.length),r=z(t.reduce(((t,r,o)=>r===i?t:(n[o]=t,$(t*r,e))),o),e);return t.reduceRight(((t,r,o)=>r===i?t:(n[o]=$(t*n[o],e),$(t*r,e))),r),n}(t.map((t=>t.z)));return t.map(((t,n)=>t.toAffine(e[n])))}static normalizeZ(t){return w.toAffineBatch(t).map(w.fromAffine)}equals(t){v(t);const{x:e,y:n,z:r}=this,{x:i,y:o,z:s}=t,a=$(r*r),c=$(s*s),u=$(e*c),f=$(i*a),l=$($(n*s)*c),h=$($(o*r)*a);return u===f&&l===h}negate(){return new w(this.x,$(-this.y),this.z)}double(){const{x:t,y:e,z:n}=this,r=$(t*t),i=$(e*e),o=$(i*i),u=t+i,f=$(s*($(u*u)-r-o)),l=$(a*r),h=$(l*l),p=$(h-s*f),d=$(l*(f-p)-c*o),y=$(s*e*n);return new w(p,d,y)}add(t){v(t);const{x:e,y:n,z:r}=this,{x:o,y:a,z:c}=t;if(o===i||a===i)return this;if(e===i||n===i)return t;const u=$(r*r),f=$(c*c),l=$(e*f),h=$(o*u),p=$($(n*c)*f),d=$($(a*r)*u),y=$(h-l),g=$(d-p);if(y===i)return g===i?this.double():w.ZERO;const m=$(y*y),b=$(y*m),x=$(l*m),E=$(g*g-b-s*x),S=$(g*(x-E)-p*b),A=$(r*c*y);return new w(E,S,A)}subtract(t){return this.add(t.negate())}multiplyUnsafe(t){const e=w.ZERO;if("bigint"==typeof t&&t===i)return e;let n=H(t);if(n===o)return this;if(!m){let t=e,r=this;for(;n>i;)n&o&&(t=t.add(r)),r=r.double(),n>>=o;return t}let{k1neg:r,k1:s,k2neg:a,k2:c}=l.splitScalar(n),u=e,f=e,h=this;for(;s>i||c>i;)s&o&&(u=u.add(h)),c&o&&(f=f.add(h)),h=h.double(),s>>=o,c>>=o;return r&&(u=u.negate()),a&&(f=f.negate()),f=new w($(f.x*l.beta),f.y,f.z),u.add(f)}precomputeWindow(t){const e=m?128/t+1:256/t+1,n=[];let r=this,i=r;for(let o=0;o<e;o++){i=r,n.push(i);for(let e=1;e<2**(t-1);e++)i=i.add(r),n.push(i);r=i.double()}return n}wNAF(t,e){!e&&this.equals(w.BASE)&&(e=S.BASE);const n=e&&e._WINDOW_SIZE||1;if(256%n)throw new Error("Point#wNAF: Invalid precomputation window, must be power of 2");let r=e&&E.get(e);r||(r=this.precomputeWindow(n),e&&1!==n&&(r=w.normalizeZ(r),E.set(e,r)));let i=w.ZERO,s=w.BASE;const a=1+(m?128/n:256/n),c=2**(n-1),u=BigInt(2**n-1),f=2**n,l=BigInt(n);for(let e=0;e<a;e++){const n=e*c;let a=Number(t&u);t>>=l,a>c&&(a-=f,t+=o);const h=n,p=n+Math.abs(a)-1,d=e%2!=0,y=a<0;0===a?s=s.add(x(d,r[h])):i=i.add(x(y,r[p]))}return{p:i,f:s}}multiply(t,e){let n,r,i=H(t);if(m){const{k1neg:t,k1:o,k2neg:s,k2:a}=l.splitScalar(i);let{p:c,f:u}=this.wNAF(o,e),{p:f,f:h}=this.wNAF(a,e);c=x(t,c),f=x(s,f),f=new w($(f.x*l.beta),f.y,f.z),n=c.add(f),r=u.add(h)}else{const{p:t,f:o}=this.wNAF(i,e);n=t,r=o}return w.normalizeZ([n,r])[0]}toAffine(t){const{x:e,y:n,z:r}=this,i=this.equals(w.ZERO);null==t&&(t=i?c:z(r));const s=t,a=$(s*s),u=$(a*s),f=$(e*a),l=$(n*u),h=$(r*s);if(i)return S.ZERO;if(h!==o)throw new Error("invZ was invalid");return new S(f,l)}}function x(t,e){const n=e.negate();return t?n:e}w.BASE=new w(u.Gx,u.Gy,o),w.ZERO=new w(i,o,i);const E=new WeakMap;class S{constructor(t,e){this.x=t,this.y=e}_setWindowSize(t){this._WINDOW_SIZE=t,E.delete(this)}hasEvenY(){return this.y%s===i}static fromCompressedHex(t){const e=32===t.length,n=U(e?t:t.subarray(1));if(!W(n))throw new Error("Point is not on curve");let r=function(t){const{P:e}=u,n=BigInt(6),r=BigInt(11),i=BigInt(22),o=BigInt(23),c=BigInt(44),f=BigInt(88),l=t*t*t%e,h=l*l*t%e,p=D(h,a)*h%e,d=D(p,a)*h%e,y=D(d,s)*l%e,g=D(y,r)*y%e,m=D(g,i)*g%e,b=D(m,c)*m%e,v=D(b,f)*b%e,w=D(v,c)*m%e,x=D(w,a)*h%e,E=D(x,o)*g%e,S=D(E,n)*l%e,A=D(S,s);if(A*A%e!==t)throw new Error("Cannot find square root");return A}(g(n));const i=(r&o)===o;e?i&&(r=$(-r)):1==(1&t[0])!==i&&(r=$(-r));const c=new S(n,r);return c.assertValidity(),c}static fromUncompressedHex(t){const e=U(t.subarray(1,h+1)),n=U(t.subarray(h+1,2*h+1)),r=new S(e,n);return r.assertValidity(),r}static fromHex(t){const e=L(t),n=e.length,r=e[0];if(n===h)return this.fromCompressedHex(e);if(n===d&&(2===r||3===r))return this.fromCompressedHex(e);if(n===y&&4===r)return this.fromUncompressedHex(e);throw new Error(`Point.fromHex: received invalid point. Expected 32-${d} compressed bytes or ${y} uncompressed bytes, not ${n}`)}static fromPrivateKey(t){return S.BASE.multiply(Z(t))}static fromSignature(t,e,n){const{r,s:i}=X(e);if(![0,1,2,3].includes(n))throw new Error("Cannot recover: invalid recovery bit");const o=M(L(t)),{n:s}=u,a=2===n||3===n?r+s:r,c=z(a,s),f=$(-o*c,s),l=$(i*c,s),h=1&n?"03":"02",p=S.fromHex(h+T(a)),d=S.BASE.multiplyAndAddUnsafe(p,f,l);if(!d)throw new Error("Cannot recover signature: point at infinify");return d.assertValidity(),d}toRawBytes(t=!1){return C(this.toHex(t))}toHex(t=!1){const e=T(this.x);return t?`${this.hasEvenY()?"02":"03"}${e}`:`04${e}${T(this.y)}`}toHexX(){return this.toHex(!0).slice(2)}toRawX(){return this.toRawBytes(!0).slice(1)}assertValidity(){const t="Point is not on elliptic curve",{x:e,y:n}=this;if(!W(e)||!W(n))throw new Error(t);const r=$(n*n);if($(r-g(e))!==i)throw new Error(t)}equals(t){return this.x===t.x&&this.y===t.y}negate(){return new S(this.x,$(-this.y))}double(){return w.fromAffine(this).double().toAffine()}add(t){return w.fromAffine(this).add(w.fromAffine(t)).toAffine()}subtract(t){return this.add(t.negate())}multiply(t){return w.fromAffine(this).multiply(t,this).toAffine()}multiplyAndAddUnsafe(t,e,n){const r=w.fromAffine(this),s=e===i||e===o||this!==S.BASE?r.multiplyUnsafe(e):r.multiply(e),a=w.fromAffine(t).multiplyUnsafe(n),c=s.add(a);return c.equals(w.ZERO)?void 0:c.toAffine()}}function A(t){return Number.parseInt(t[0],16)>=8?"00"+t:t}function k(t){if(t.length<2||2!==t[0])throw new Error(`Invalid signature integer tag: ${P(t)}`);const e=t[1],n=t.subarray(2,e+2);if(!e||n.length!==e)throw new Error("Invalid signature integer: wrong length");if(0===n[0]&&n[1]<=127)throw new Error("Invalid signature integer: trailing length");return{data:U(n),left:t.subarray(e+2)}}e.Point=S,S.BASE=new S(u.Gx,u.Gy),S.ZERO=new S(i,i);class j{constructor(t,e){this.r=t,this.s=e,this.assertValidity()}static fromCompact(t){const e=t instanceof Uint8Array,n="Signature.fromCompact";if("string"!=typeof t&&!e)throw new TypeError(`${n}: Expected string or Uint8Array`);const r=e?P(t):t;if(128!==r.length)throw new Error(`${n}: Expected 64-byte hex`);return new j(N(r.slice(0,64)),N(r.slice(64,128)))}static fromDER(t){const e=t instanceof Uint8Array;if("string"!=typeof t&&!e)throw new TypeError("Signature.fromDER: Expected string or Uint8Array");const{r:n,s:r}=function(t){if(t.length<2||48!=t[0])throw new Error(`Invalid signature tag: ${P(t)}`);if(t[1]!==t.length-2)throw new Error("Invalid signature: incorrect length");const{data:e,left:n}=k(t.subarray(2)),{data:r,left:i}=k(n);if(i.length)throw new Error(`Invalid signature: left bytes after parsing: ${P(i)}`);return{r:e,s:r}}(e?t:C(t));return new j(n,r)}static fromHex(t){return this.fromDER(t)}assertValidity(){const{r:t,s:e}=this;if(!K(t))throw new Error("Invalid Signature: r must be 0 < r < n");if(!K(e))throw new Error("Invalid Signature: s must be 0 < s < n")}hasHighS(){const t=u.n>>o;return this.s>t}normalizeS(){return this.hasHighS()?new j(this.r,$(-this.s,u.n)):this}toDERRawBytes(){return C(this.toDERHex())}toDERHex(){const t=A(B(this.s)),e=A(B(this.r)),n=t.length/2,r=e.length/2,i=B(n),o=B(r);return`30${B(r+n+4)}02${o}${e}02${i}${t}`}toRawBytes(){return this.toDERRawBytes()}toHex(){return this.toDERHex()}toCompactRawBytes(){return C(this.toCompactHex())}toCompactHex(){return T(this.r)+T(this.s)}}function _(...t){if(!t.every((t=>t instanceof Uint8Array)))throw new Error("Uint8Array list expected");if(1===t.length)return t[0];const e=t.reduce(((t,e)=>t+e.length),0),n=new Uint8Array(e);for(let e=0,r=0;e<t.length;e++){const i=t[e];n.set(i,r),r+=i.length}return n}e.Signature=j;const O=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));function P(t){if(!(t instanceof Uint8Array))throw new Error("Expected Uint8Array");let e="";for(let n=0;n<t.length;n++)e+=O[t[n]];return e}const F=BigInt("0x10000000000000000000000000000000000000000000000000000000000000000");function T(t){if("bigint"!=typeof t)throw new Error("Expected bigint");if(!(i<=t&&t<F))throw new Error("Expected number 0 <= n < 2^256");return t.toString(16).padStart(64,"0")}function I(t){const e=C(T(t));if(32!==e.length)throw new Error("Error: expected 32 bytes");return e}function B(t){const e=t.toString(16);return 1&e.length?`0${e}`:e}function N(t){if("string"!=typeof t)throw new TypeError("hexToNumber: expected string, got "+typeof t);return BigInt(`0x${t}`)}function C(t){if("string"!=typeof t)throw new TypeError("hexToBytes: expected string, got "+typeof t);if(t.length%2)throw new Error("hexToBytes: received invalid unpadded hex"+t.length);const e=new Uint8Array(t.length/2);for(let n=0;n<e.length;n++){const r=2*n,i=t.slice(r,r+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");e[n]=o}return e}function U(t){return N(P(t))}function L(t){return t instanceof Uint8Array?Uint8Array.from(t):C(t)}function H(t){if("number"==typeof t&&Number.isSafeInteger(t)&&t>0)return BigInt(t);if("bigint"==typeof t&&K(t))return t;throw new TypeError("Expected valid private scalar: 0 < scalar < curve.n")}function $(t,e=u.P){const n=t%e;return n>=i?n:e+n}function D(t,e){const{P:n}=u;let r=t;for(;e-- >i;)r*=r,r%=n;return r}function z(t,e=u.P){if(t===i||e<=i)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let n=$(t,e),r=e,s=i,a=o,c=o,f=i;for(;n!==i;){const t=r/n,e=r%n,i=s-c*t,o=a-f*t;r=n,n=e,s=c,a=f,c=i,f=o}if(r!==o)throw new Error("invert: does not exist");return $(s,e)}function M(t,e=!1){const n=function(t){const e=8*t.length-8*p,n=U(t);return e>0?n>>BigInt(e):n}(t);if(e)return n;const{n:r}=u;return n>=r?n-r:n}let R,q;class V{constructor(t,e){if(this.hashLen=t,this.qByteLen=e,"number"!=typeof t||t<2)throw new Error("hashLen must be a number");if("number"!=typeof e||e<2)throw new Error("qByteLen must be a number");this.v=new Uint8Array(t).fill(1),this.k=new Uint8Array(t).fill(0),this.counter=0}hmac(...t){return e.utils.hmacSha256(this.k,...t)}hmacSync(...t){return q(this.k,...t)}checkSync(){if("function"!=typeof q)throw new b("hmacSha256Sync needs to be set")}incr(){if(this.counter>=1e3)throw new Error("Tried 1,000 k values for sign(), all were invalid");this.counter+=1}async reseed(t=new Uint8Array){this.k=await this.hmac(this.v,Uint8Array.from([0]),t),this.v=await this.hmac(this.v),0!==t.length&&(this.k=await this.hmac(this.v,Uint8Array.from([1]),t),this.v=await this.hmac(this.v))}reseedSync(t=new Uint8Array){this.checkSync(),this.k=this.hmacSync(this.v,Uint8Array.from([0]),t),this.v=this.hmacSync(this.v),0!==t.length&&(this.k=this.hmacSync(this.v,Uint8Array.from([1]),t),this.v=this.hmacSync(this.v))}async generate(){this.incr();let t=0;const e=[];for(;t<this.qByteLen;){this.v=await this.hmac(this.v);const n=this.v.slice();e.push(n),t+=this.v.length}return _(...e)}generateSync(){this.checkSync(),this.incr();let t=0;const e=[];for(;t<this.qByteLen;){this.v=this.hmacSync(this.v);const n=this.v.slice();e.push(n),t+=this.v.length}return _(...e)}}function K(t){return i<t&&t<u.n}function W(t){return i<t&&t<u.P}function G(t,e,n,r=!0){const{n:s}=u,a=M(t,!0);if(!K(a))return;const c=z(a,s),f=S.BASE.multiply(a),l=$(f.x,s);if(l===i)return;const h=$(c*$(e+n*l,s),s);if(h===i)return;let p=new j(l,h),d=(f.x===p.r?0:2)|Number(f.y&o);return r&&p.hasHighS()&&(p=p.normalizeS(),d^=1),{sig:p,recovery:d}}function Z(t){let e;if("bigint"==typeof t)e=t;else if("number"==typeof t&&Number.isSafeInteger(t)&&t>0)e=BigInt(t);else if("string"==typeof t){if(t.length!==2*p)throw new Error("Expected 32 bytes of private key");e=N(t)}else{if(!(t instanceof Uint8Array))throw new TypeError("Expected valid private key");if(t.length!==p)throw new Error("Expected 32 bytes of private key");e=U(t)}if(!K(e))throw new Error("Expected private key: 0 < key < n");return e}function J(t){return t instanceof S?(t.assertValidity(),t):S.fromHex(t)}function X(t){if(t instanceof j)return t.assertValidity(),t;try{return j.fromDER(t)}catch(e){return j.fromCompact(t)}}function Y(t){const e=t instanceof Uint8Array,n="string"==typeof t,r=(e||n)&&t.length;return e?r===d||r===y:n?r===2*d||r===2*y:t instanceof S}function Q(t){return U(t.length>h?t.slice(0,h):t)}function tt(t){const e=Q(t),n=$(e,u.n);return et(n<i?e:n)}function et(t){return I(t)}function nt(t,n,r){if(null==t)throw new Error(`sign: expected valid message hash, not "${t}"`);const i=L(t),o=Z(n),s=[et(o),tt(i)];if(null!=r){!0===r&&(r=e.utils.randomBytes(h));const t=L(r);if(t.length!==h)throw new Error(`sign: Expected ${h} bytes of extra data`);s.push(t)}return{seed:_(...s),m:Q(i),d:o}}function rt(t,e){const{sig:n,recovery:r}=t,{der:i,recovered:o}=Object.assign({canonical:!0,der:!0},e),s=i?n.toDERRawBytes():n.toCompactRawBytes();return o?[s,r]:s}e.getPublicKey=function(t,e=!1){return S.fromPrivateKey(t).toRawBytes(e)},e.recoverPublicKey=function(t,e,n,r=!1){return S.fromSignature(t,e,n).toRawBytes(r)},e.getSharedSecret=function(t,e,n=!1){if(Y(t))throw new TypeError("getSharedSecret: first arg must be private key");if(!Y(e))throw new TypeError("getSharedSecret: second arg must be public key");const r=J(e);return r.assertValidity(),r.multiply(Z(t)).toRawBytes(n)},e.sign=async function(t,e,n={}){const{seed:r,m:i,d:o}=nt(t,e,n.extraEntropy),s=new V(32,p);let a;for(await s.reseed(r);!(a=G(await s.generate(),i,o,n.canonical));)await s.reseed();return rt(a,n)},e.signSync=function(t,e,n={}){const{seed:r,m:i,d:o}=nt(t,e,n.extraEntropy),s=new V(32,p);let a;for(s.reseedSync(r);!(a=G(s.generateSync(),i,o,n.canonical));)s.reseedSync();return rt(a,n)};const it={strict:!0};function ot(t){return $(U(t),u.n)}e.verify=function(t,e,n,r=it){let i;try{i=X(t),e=L(e)}catch(t){return!1}const{r:o,s}=i;if(r.strict&&i.hasHighS())return!1;const a=M(e);let c;try{c=J(n)}catch(t){return!1}const{n:f}=u,l=z(s,f),h=$(a*l,f),p=$(o*l,f),d=S.BASE.multiplyAndAddUnsafe(c,h,p);return!!d&&$(d.x,f)===o};class st{constructor(t,e){this.r=t,this.s=e,this.assertValidity()}static fromHex(t){const e=L(t);if(64!==e.length)throw new TypeError(`SchnorrSignature.fromHex: expected 64 bytes, not ${e.length}`);const n=U(e.subarray(0,32)),r=U(e.subarray(32,64));return new st(n,r)}assertValidity(){const{r:t,s:e}=this;if(!W(t)||!K(e))throw new Error("Invalid signature")}toHex(){return T(this.r)+T(this.s)}toRawBytes(){return C(this.toHex())}}class at{constructor(t,n,r=e.utils.randomBytes()){if(null==t)throw new TypeError(`sign: Expected valid message, not "${t}"`);this.m=L(t);const{x:i,scalar:o}=this.getScalar(Z(n));if(this.px=i,this.d=o,this.rand=L(r),32!==this.rand.length)throw new TypeError("sign: Expected 32 bytes of aux randomness")}getScalar(t){const e=S.fromPrivateKey(t),n=e.hasEvenY()?t:u.n-t;return{point:e,scalar:n,x:e.toRawX()}}initNonce(t,e){return I(t^U(e))}finalizeNonce(t){const e=$(U(t),u.n);if(e===i)throw new Error("sign: Creation of signature failed. k is zero");const{point:n,x:r,scalar:o}=this.getScalar(e);return{R:n,rx:r,k:o}}finalizeSig(t,e,n,r){return new st(t.x,$(e+n*r,u.n)).toRawBytes()}error(){throw new Error("sign: Invalid signature produced")}async calc(){const{m:t,d:n,px:r,rand:i}=this,o=e.utils.taggedHash,s=this.initNonce(n,await o(pt.aux,i)),{R:a,rx:c,k:u}=this.finalizeNonce(await o(pt.nonce,s,r,t)),f=ot(await o(pt.challenge,c,r,t)),l=this.finalizeSig(a,u,f,n);return await ft(l,t,r)||this.error(),l}calcSync(){const{m:t,d:n,px:r,rand:i}=this,o=e.utils.taggedHashSync,s=this.initNonce(n,o(pt.aux,i)),{R:a,rx:c,k:u}=this.finalizeNonce(o(pt.nonce,s,r,t)),f=ot(o(pt.challenge,c,r,t)),l=this.finalizeSig(a,u,f,n);return lt(l,t,r)||this.error(),l}}function ct(t,e,n){const r=t instanceof st,i=r?t:st.fromHex(t);return r&&i.assertValidity(),{...i,m:L(e),P:J(n)}}function ut(t,e,n,r){const i=S.BASE.multiplyAndAddUnsafe(e,Z(n),$(-r,u.n));return!(!i||!i.hasEvenY()||i.x!==t)}async function ft(t,n,r){try{const{r:i,s:o,m:s,P:a}=ct(t,n,r),c=ot(await e.utils.taggedHash(pt.challenge,I(i),a.toRawX(),s));return ut(i,a,o,c)}catch(t){return!1}}function lt(t,n,r){try{const{r:i,s:o,m:s,P:a}=ct(t,n,r),c=ot(e.utils.taggedHashSync(pt.challenge,I(i),a.toRawX(),s));return ut(i,a,o,c)}catch(t){if(t instanceof b)throw t;return!1}}e.schnorr={Signature:st,getPublicKey:function(t){return S.fromPrivateKey(t).toRawX()},sign:async function(t,e,n){return new at(t,e,n).calc()},verify:ft,signSync:function(t,e,n){return new at(t,e,n).calcSync()},verifySync:lt},S.BASE._setWindowSize(8);const ht={node:r,web:"object"==typeof self&&"crypto"in self?self.crypto:void 0},pt={challenge:"BIP0340/challenge",aux:"BIP0340/aux",nonce:"BIP0340/nonce"},dt={};e.utils={bytesToHex:P,hexToBytes:C,concatBytes:_,mod:$,invert:z,isValidPrivateKey(t){try{return Z(t),!0}catch(t){return!1}},_bigintTo32Bytes:I,_normalizePrivateKey:Z,hashToPrivateKey:t=>{t=L(t);const e=p+8;if(t.length<e||t.length>1024)throw new Error("Expected valid bytes of private key as per FIPS 186");return I($(U(t),u.n-o)+o)},randomBytes:(t=32)=>{if(ht.web)return ht.web.getRandomValues(new Uint8Array(t));if(ht.node){const{randomBytes:e}=ht.node;return Uint8Array.from(e(t))}throw new Error("The environment doesn't have randomBytes function")},randomPrivateKey:()=>e.utils.hashToPrivateKey(e.utils.randomBytes(p+8)),precompute(t=8,e=S.BASE){const n=e===S.BASE?e:new S(e.x,e.y);return n._setWindowSize(t),n.multiply(a),n},sha256:async(...t)=>{if(ht.web){const e=await ht.web.subtle.digest("SHA-256",_(...t));return new Uint8Array(e)}if(ht.node){const{createHash:e}=ht.node,n=e("sha256");return t.forEach((t=>n.update(t))),Uint8Array.from(n.digest())}throw new Error("The environment doesn't have sha256 function")},hmacSha256:async(t,...e)=>{if(ht.web){const n=await ht.web.subtle.importKey("raw",t,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]),r=_(...e),i=await ht.web.subtle.sign("HMAC",n,r);return new Uint8Array(i)}if(ht.node){const{createHmac:n}=ht.node,r=n("sha256",t);return e.forEach((t=>r.update(t))),Uint8Array.from(r.digest())}throw new Error("The environment doesn't have hmac-sha256 function")},sha256Sync:void 0,hmacSha256Sync:void 0,taggedHash:async(t,...n)=>{let r=dt[t];if(void 0===r){const n=await e.utils.sha256(Uint8Array.from(t,(t=>t.charCodeAt(0))));r=_(n,n),dt[t]=r}return e.utils.sha256(r,...n)},taggedHashSync:(t,...e)=>{if("function"!=typeof R)throw new b("sha256Sync is undefined, you need to set it");let n=dt[t];if(void 0===n){const e=R(Uint8Array.from(t,(t=>t.charCodeAt(0))));n=_(e,e),dt[t]=n}return R(n,...e)},_JacobianPoint:w},Object.defineProperties(e.utils,{sha256Sync:{configurable:!1,get:()=>R,set(t){R||(R=t)}},hmacSha256Sync:{configurable:!1,get:()=>q,set(t){q||(q=t)}}})},166:t=>{"use strict";t.exports=function(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),n=0;n<e.length;n++)e[n]=255;for(var r=0;r<t.length;r++){var i=t.charAt(r),o=i.charCodeAt(0);if(255!==e[o])throw new TypeError(i+" is ambiguous");e[o]=r}var s=t.length,a=t.charAt(0),c=Math.log(s)/Math.log(256),u=Math.log(256)/Math.log(s);function f(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return new Uint8Array;for(var n=0,r=0,i=0;t[n]===a;)r++,n++;for(var o=(t.length-n)*c+1>>>0,u=new Uint8Array(o);t[n];){var f=e[t.charCodeAt(n)];if(255===f)return;for(var l=0,h=o-1;(0!==f||l<i)&&-1!==h;h--,l++)f+=s*u[h]>>>0,u[h]=f%256>>>0,f=f/256>>>0;if(0!==f)throw new Error("Non-zero carry");i=l,n++}for(var p=o-i;p!==o&&0===u[p];)p++;for(var d=new Uint8Array(r+(o-p)),y=r;p!==o;)d[y++]=u[p++];return d}return{encode:function(e){if(e instanceof Uint8Array||(ArrayBuffer.isView(e)?e=new Uint8Array(e.buffer,e.byteOffset,e.byteLength):Array.isArray(e)&&(e=Uint8Array.from(e))),!(e instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===e.length)return"";for(var n=0,r=0,i=0,o=e.length;i!==o&&0===e[i];)i++,n++;for(var c=(o-i)*u+1>>>0,f=new Uint8Array(c);i!==o;){for(var l=e[i],h=0,p=c-1;(0!==l||h<r)&&-1!==p;p--,h++)l+=256*f[p]>>>0,f[p]=l%s>>>0,l=l/s>>>0;if(0!==l)throw new Error("Non-zero carry");r=h,i++}for(var d=c-r;d!==c&&0===f[d];)d++;for(var y=a.repeat(n);d<c;++d)y+=t.charAt(f[d]);return y},decodeUnsafe:f,decode:function(t){var e=f(t);if(e)return e;throw new Error("Non-base"+s+" character")}}}},766:(t,e)=>{"use strict";e.byteLength=function(t){var e=a(t),n=e[0],r=e[1];return 3*(n+r)/4-r},e.toByteArray=function(t){var e,n,o=a(t),s=o[0],c=o[1],u=new i(function(t,e,n){return 3*(e+n)/4-n}(0,s,c)),f=0,l=c>0?s-4:s;for(n=0;n<l;n+=4)e=r[t.charCodeAt(n)]<<18|r[t.charCodeAt(n+1)]<<12|r[t.charCodeAt(n+2)]<<6|r[t.charCodeAt(n+3)],u[f++]=e>>16&255,u[f++]=e>>8&255,u[f++]=255&e;return 2===c&&(e=r[t.charCodeAt(n)]<<2|r[t.charCodeAt(n+1)]>>4,u[f++]=255&e),1===c&&(e=r[t.charCodeAt(n)]<<10|r[t.charCodeAt(n+1)]<<4|r[t.charCodeAt(n+2)]>>2,u[f++]=e>>8&255,u[f++]=255&e),u},e.fromByteArray=function(t){for(var e,r=t.length,i=r%3,o=[],s=16383,a=0,u=r-i;a<u;a+=s)o.push(c(t,a,a+s>u?u:a+s));return 1===i?(e=t[r-1],o.push(n[e>>2]+n[e<<4&63]+"==")):2===i&&(e=(t[r-2]<<8)+t[r-1],o.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"=")),o.join("")};for(var n=[],r=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0;s<64;++s)n[s]=o[s],r[o.charCodeAt(s)]=s;function a(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=t.indexOf("=");return-1===n&&(n=e),[n,n===e?0:4-n%4]}function c(t,e,r){for(var i,o,s=[],a=e;a<r;a+=3)i=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(255&t[a+2]),s.push(n[(o=i)>>18&63]+n[o>>12&63]+n[o>>6&63]+n[63&o]);return s.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},98:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.c32ToB58=e.b58ToC32=e.c32addressDecode=e.c32address=e.versions=void 0;const r=n(392),i=n(716),o=n(64);e.versions={mainnet:{p2pkh:22,p2sh:20},testnet:{p2pkh:26,p2sh:21}};const s={};s[0]=e.versions.mainnet.p2pkh,s[5]=e.versions.mainnet.p2sh,s[111]=e.versions.testnet.p2pkh,s[196]=e.versions.testnet.p2sh;const a={};function c(t,e){if(!e.match(/^[0-9a-fA-F]{40}$/))throw new Error("Invalid argument: not a hash160 hex string");return`S${(0,r.c32checkEncode)(t,e)}`}function u(t){if(t.length<=5)throw new Error("Invalid c32 address: invalid length");if("S"!=t[0])throw new Error('Invalid c32 address: must start with "S"');return(0,r.c32checkDecode)(t.slice(1))}a[e.versions.mainnet.p2pkh]=0,a[e.versions.mainnet.p2sh]=5,a[e.versions.testnet.p2pkh]=111,a[e.versions.testnet.p2sh]=196,e.c32address=c,e.c32addressDecode=u,e.b58ToC32=function(t,e=-1){const n=i.decode(t),r=(0,o.bytesToHex)(n.data),a=parseInt((0,o.bytesToHex)(n.prefix),16);let u;return e<0?(u=a,void 0!==s[a]&&(u=s[a])):u=e,c(u,r)},e.c32ToB58=function(t,e=-1){const n=u(t),r=n[0],o=n[1];let s;e<0?(s=r,void 0!==a[r]&&(s=a[r])):s=e;let c=s.toString(16);return 1===c.length&&(c=`0${c}`),i.encode(o,c)}},716:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.decode=e.encode=void 0;const r=n(53),i=n(64),o=n(166),s="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";e.encode=function(t,e="00"){const n="string"==typeof t?(0,i.hexToBytes)(t):t,a="string"==typeof e?(0,i.hexToBytes)(e):t;if(!(n instanceof Uint8Array&&a instanceof Uint8Array))throw new TypeError("Argument must be of type Uint8Array or string");const c=(0,r.sha256)((0,r.sha256)(new Uint8Array([...a,...n])));return o(s).encode([...a,...n,...c.slice(0,4)])},e.decode=function(t){const e=o(s).decode(t),n=e.slice(0,1),i=e.slice(1,-4),a=(0,r.sha256)((0,r.sha256)(new Uint8Array([...n,...i])));return e.slice(-4).forEach(((t,e)=>{if(t!==a[e])throw new Error("Invalid checksum")})),{prefix:n,data:i}}},392:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.c32checkDecode=e.c32checkEncode=void 0;const r=n(53),i=n(64),o=n(103);function s(t){const e=(0,r.sha256)((0,r.sha256)((0,i.hexToBytes)(t)));return(0,i.bytesToHex)(e.slice(0,4))}e.c32checkEncode=function(t,e){if(t<0||t>=32)throw new Error("Invalid version (must be between 0 and 31)");if(!e.match(/^[0-9a-fA-F]*$/))throw new Error("Invalid data (not a hex string)");(e=e.toLowerCase()).length%2!=0&&(e=`0${e}`);let n=t.toString(16);1===n.length&&(n=`0${n}`);const r=s(`${n}${e}`),i=(0,o.c32encode)(`${e}${r}`);return`${o.c32[t]}${i}`},e.c32checkDecode=function(t){t=(0,o.c32normalize)(t);const e=(0,o.c32decode)(t.slice(1)),n=t[0],r=o.c32.indexOf(n),i=e.slice(-8);let a=r.toString(16);if(1===a.length&&(a=`0${a}`),s(`${a}${e.substring(0,e.length-8)}`)!==i)throw new Error("Invalid c32check string: checksum mismatch");return[r,e.substring(0,e.length-8)]}},103:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.c32decode=e.c32normalize=e.c32encode=e.c32=void 0;const r=n(64);e.c32="0123456789ABCDEFGHJKMNPQRSTVWXYZ";const i="0123456789abcdef";function o(t){return t.toUpperCase().replace(/O/g,"0").replace(/L|I/g,"1")}e.c32encode=function(t,n){if(!t.match(/^[0-9a-fA-F]*$/))throw new Error("Not a hex-encoded string");t.length%2!=0&&(t=`0${t}`);let o=[],s=0;for(let n=(t=t.toLowerCase()).length-1;n>=0;n--)if(s<4){const r=i.indexOf(t[n])>>s;let a=0;0!==n&&(a=i.indexOf(t[n-1]));const c=1+s,u=a%(1<<c)<<5-c,f=e.c32[r+u];s=c,o.unshift(f)}else s=0;let a=0;for(let t=0;t<o.length&&"0"===o[t];t++)a++;o=o.slice(a);const c=(new TextDecoder).decode((0,r.hexToBytes)(t)).match(/^\u0000*/),u=c?c[0].length:0;for(let t=0;t<u;t++)o.unshift(e.c32[0]);if(n){const t=n-o.length;for(let n=0;n<t;n++)o.unshift(e.c32[0])}return o.join("")},e.c32normalize=o,e.c32decode=function(t,n){if(!(t=o(t)).match(`^[${e.c32}]*$`))throw new Error("Not a c32-encoded string");const r=t.match(`^${e.c32[0]}*`),s=r?r[0].length:0;let a=[],c=0,u=0;for(let n=t.length-1;n>=0;n--){4===u&&(a.unshift(i[c]),u=0,c=0);const r=(e.c32.indexOf(t[n])<<u)+c,o=i[r%16];if(u+=1,c=r>>4,c>1<<u)throw new Error("Panic error in decoding.");a.unshift(o)}a.unshift(i[c]),a.length%2==1&&a.unshift("0");let f=0;for(let t=0;t<a.length&&"0"===a[t];t++)f++;a=a.slice(f-f%2);let l=a.join("");for(let t=0;t<s;t++)l=`00${l}`;if(n){const t=2*n-l.length;for(let e=0;e<t;e+=2)l=`00${l}`}return l}},870:(t,e,n)=>{"use strict";e.H4=void 0;n(103),n(392);const r=n(98);Object.defineProperty(e,"H4",{enumerable:!0,get:function(){return r.c32address}})},59:()=>{},959:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.decode=e.encode=e.unescape=e.escape=e.pad=void 0;const r=n(766);function i(t){return`${t}${"=".repeat(4-(t.length%4||4))}`}function o(t){return t.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function s(t){return i(t).replace(/-/g,"+").replace(/_/g,"/")}e.pad=i,e.escape=o,e.unescape=s,e.encode=function(t){return o((0,r.fromByteArray)((new TextEncoder).encode(t)))},e.decode=function(t){return(new TextDecoder).decode((0,r.toByteArray)(i(s(t))))}},996:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.cryptoClients=e.SECP256K1Client=void 0;const r=n(869);Object.defineProperty(e,"SECP256K1Client",{enumerable:!0,get:function(){return r.SECP256K1Client}});const i={ES256K:r.SECP256K1Client};e.cryptoClients=i},869:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.SECP256K1Client=void 0;const r=n(514),i=n(53),o=n(698),s=n(575),a=n(643),c=n(64);o.utils.hmacSha256Sync=(t,...e)=>{const n=r.hmac.create(i.sha256,t);return e.forEach((t=>n.update(t))),n.digest()};class u{static derivePublicKey(t,e=!0){return 66===t.length&&(t=t.slice(0,64)),t.length<64&&(t=t.padStart(64,"0")),(0,c.bytesToHex)(o.getPublicKey(t,e))}static signHash(t,e,n="jose"){if(!t||!e)throw new a.MissingParametersError("a signing input hash and private key are all required");const r=o.signSync(t,e.slice(0,64),{der:!0,canonical:!1});if("der"===n)return(0,c.bytesToHex)(r);if("jose"===n)return(0,s.derToJose)(r,"ES256");throw Error("Invalid signature format")}static loadSignature(t){return(0,s.joseToDer)(t,"ES256")}static verifyHash(t,e,n){if(!t||!e||!n)throw new a.MissingParametersError("a signing input hash, der signature, and public key are all required");return o.verify(e,t,n,{strict:!1})}}e.SECP256K1Client=u,u.algorithmName="ES256K"},874:function(t,e,n){"use strict";var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{c(r.next(t))}catch(t){o(t)}}function a(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.hashSha256Async=e.hashSha256=void 0;const i=n(53);function o(t){return(0,i.sha256)(t)}e.hashSha256=o,e.hashSha256Async=function(t){return r(this,void 0,void 0,(function*(){try{if("undefined"!=typeof crypto&&void 0!==crypto.subtle){const e="string"==typeof t?(new TextEncoder).encode(t):t,n=yield crypto.subtle.digest("SHA-256",e);return new Uint8Array(n)}{const e=n(812);if(!e.createHash)throw new Error("`crypto` module does not contain `createHash`");return Promise.resolve(e.createHash("sha256").update(t).digest())}}catch(e){return console.log(e),console.log('Crypto lib not found. Neither the global `crypto.subtle` Web Crypto API, nor the or the Node.js `require("crypto").createHash` module is available. Falling back to JS implementation.'),Promise.resolve(o(t))}}))}},917:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.decodeToken=void 0;const r=n(959);e.decodeToken=function(t){if("string"==typeof t){const e=t.split(".");return{header:JSON.parse(r.decode(e[0])),payload:JSON.parse(r.decode(e[1])),signature:e[2]}}if("object"==typeof t){if("string"!=typeof t.payload)throw new Error("Expected token payload to be a base64 or json string");let e=t.payload;"{"!==t.payload[0]&&(e=r.decode(e));const n=[];return t.header.map((t=>{const e=JSON.parse(r.decode(t));n.push(e)})),{header:n,payload:JSON.parse(e),signature:t.signature}}}},575:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.joseToDer=e.derToJose=void 0;const r=n(766),i=n(959);function o(t){return(t/8|0)+(t%8==0?0:1)}const s={ES256:o(256),ES384:o(384),ES512:o(521)};function a(t){const e=s[t];if(e)return e;throw new Error(`Unknown algorithm "${t}"`)}const c=128;function u(t){if(t instanceof Uint8Array)return t;if("string"==typeof t)return(0,r.toByteArray)((0,i.pad)(t));throw new TypeError("ECDSA signature must be a Base64 string or a Uint8Array")}function f(t,e,n){let r=0;for(;e+r<n&&0===t[e+r];)++r;return t[e+r]>=c&&--r,r}e.derToJose=function(t,e){const n=u(t),o=a(e),s=o+1,c=n.length;let f=0;if(48!==n[f++])throw new Error('Could not find expected "seq"');let l=n[f++];if(129===l&&(l=n[f++]),c-f<l)throw new Error(`"seq" specified length of "${l}", only "${c-f}" remaining`);if(2!==n[f++])throw new Error('Could not find expected "int" for "r"');const h=n[f++];if(c-f-2<h)throw new Error(`"r" specified length of "${h}", only "${c-f-2}" available`);if(s<h)throw new Error(`"r" specified length of "${h}", max of "${s}" is acceptable`);const p=f;if(f+=h,2!==n[f++])throw new Error('Could not find expected "int" for "s"');const d=n[f++];if(c-f!==d)throw new Error(`"s" specified length of "${d}", expected "${c-f}"`);if(s<d)throw new Error(`"s" specified length of "${d}", max of "${s}" is acceptable`);const y=f;if(f+=d,f!==c)throw new Error(`Expected to consume entire array, but "${c-f}" bytes remain`);const g=o-h,m=o-d,b=new Uint8Array(g+h+m+d);for(f=0;f<g;++f)b[f]=0;b.set(n.subarray(p+Math.max(-g,0),p+h),f),f=o;for(const t=f;f<t+m;++f)b[f]=0;return b.set(n.subarray(y+Math.max(-m,0),y+d),f),(0,i.escape)((0,r.fromByteArray)(b))},e.joseToDer=function(t,e){t=u(t);const n=a(e),r=t.length;if(r!==2*n)throw new TypeError(`"${e}" signatures must be "${2*n}" bytes, saw "${r}"`);const i=f(t,0,n),o=f(t,n,t.length),s=n-i,l=n-o,h=2+s+1+1+l,p=h<c,d=new Uint8Array((p?2:3)+h);let y=0;return d[y++]=48,p?d[y++]=h:(d[y++]=129,d[y++]=255&h),d[y++]=2,d[y++]=s,i<0?(d[y++]=0,d.set(t.subarray(0,n),y),y+=n):(d.set(t.subarray(i,n),y),y+=n-i),d[y++]=2,d[y++]=l,o<0?(d[y++]=0,d.set(t.subarray(n),y)):d.set(t.subarray(n+o),y),d}},643:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.InvalidTokenError=e.MissingParametersError=void 0;class n extends Error{constructor(t){super(),this.name="MissingParametersError",this.message=t||""}}e.MissingParametersError=n;class r extends Error{constructor(t){super(),this.name="InvalidTokenError",this.message=t||""}}e.InvalidTokenError=r},474:function(t,e,n){"use strict";var r=this&&this.__createBinding||(Object.create?function(t,e,n,r){void 0===r&&(r=n);var i=Object.getOwnPropertyDescriptor(e,n);i&&!("get"in i?!e.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return e[n]}}),Object.defineProperty(t,r,i)}:function(t,e,n,r){void 0===r&&(r=n),t[r]=e[n]}),i=this&&this.__exportStar||function(t,e){for(var n in t)"default"===n||Object.prototype.hasOwnProperty.call(e,n)||r(e,t,n)};Object.defineProperty(e,"__esModule",{value:!0}),i(n(650),e),i(n(458),e),i(n(917),e),i(n(643),e),i(n(996),e)},650:function(t,e,n){"use strict";var r=this&&this.__awaiter||function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function s(t){try{c(r.next(t))}catch(t){o(t)}}function a(t){try{c(r.throw(t))}catch(t){o(t)}}function c(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,a)}c((r=r.apply(t,e||[])).next())}))};Object.defineProperty(e,"__esModule",{value:!0}),e.TokenSigner=e.createUnsecuredToken=void 0;const i=n(959),o=n(996),s=n(643),a=n(874);function c(t,e){const n=[],r=i.encode(JSON.stringify(e));n.push(r);const o=i.encode(JSON.stringify(t));return n.push(o),n.join(".")}e.createUnsecuredToken=function(t){return c(t,{typ:"JWT",alg:"none"})+"."},e.TokenSigner=class{constructor(t,e){if(!t||!e)throw new s.MissingParametersError("a signing algorithm and private key are required");if("string"!=typeof t)throw new Error("signing algorithm parameter must be a string");if(t=t.toUpperCase(),!o.cryptoClients.hasOwnProperty(t))throw new Error("invalid signing algorithm");this.tokenType="JWT",this.cryptoClient=o.cryptoClients[t],this.rawPrivateKey=e}header(t={}){const e={typ:this.tokenType,alg:this.cryptoClient.algorithmName};return Object.assign({},e,t)}sign(t,e=!1,n={}){const r=this.header(n),i=c(t,r),o=(0,a.hashSha256)(i);return this.createWithSignedHash(t,e,r,i,o)}signAsync(t,e=!1,n={}){return r(this,void 0,void 0,(function*(){const r=this.header(n),i=c(t,r),o=yield(0,a.hashSha256Async)(i);return this.createWithSignedHash(t,e,r,i,o)}))}createWithSignedHash(t,e,n,r,o){const s=this.cryptoClient.signHash(o,this.rawPrivateKey);return e?{header:[i.encode(JSON.stringify(n))],payload:JSON.stringify(t),signature:[s]}:[r,s].join(".")}}},458:(t,e,n)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.TokenVerifier=void 0;const r=n(959),i=n(996),o=n(643),s=n(874);e.TokenVerifier=class{constructor(t,e){if(!t||!e)throw new o.MissingParametersError("a signing algorithm and public key are required");if("string"!=typeof t)throw"signing algorithm parameter must be a string";if(t=t.toUpperCase(),!i.cryptoClients.hasOwnProperty(t))throw"invalid signing algorithm";this.tokenType="JWT",this.cryptoClient=i.cryptoClients[t],this.rawPublicKey=e}verify(t){return"string"==typeof t?this.verifyCompact(t,!1):"object"==typeof t&&this.verifyExpanded(t,!1)}verifyAsync(t){return"string"==typeof t?this.verifyCompact(t,!0):"object"==typeof t?this.verifyExpanded(t,!0):Promise.resolve(!1)}verifyCompact(t,e){const n=t.split("."),r=n[0]+"."+n[1],i=t=>{const e=this.cryptoClient.loadSignature(n[2]);return this.cryptoClient.verifyHash(t,e,this.rawPublicKey)};if(e)return(0,s.hashSha256Async)(r).then((t=>i(t)));{const t=(0,s.hashSha256)(r);return i(t)}}verifyExpanded(t,e){const n=[t.header.join("."),r.encode(t.payload)].join(".");let i=!0;const o=e=>(t.signature.map((t=>{const n=this.cryptoClient.loadSignature(t);this.cryptoClient.verifyHash(e,n,this.rawPublicKey)||(i=!1)})),i);if(e)return(0,s.hashSha256Async)(n).then((t=>o(t)));{const t=(0,s.hashSha256)(n);return o(t)}}}},907:(t,e,n)=>{t=n.nmd(t);var r="__lodash_hash_undefined__",i=9007199254740991,o="[object Arguments]",s="[object Boolean]",a="[object Date]",c="[object Function]",u="[object GeneratorFunction]",f="[object Map]",l="[object Number]",h="[object Object]",p="[object Promise]",d="[object RegExp]",y="[object Set]",g="[object String]",m="[object Symbol]",b="[object WeakMap]",v="[object ArrayBuffer]",w="[object DataView]",x="[object Float32Array]",E="[object Float64Array]",S="[object Int8Array]",A="[object Int16Array]",k="[object Int32Array]",j="[object Uint8Array]",_="[object Uint8ClampedArray]",O="[object Uint16Array]",P="[object Uint32Array]",F=/\w*$/,T=/^\[object .+?Constructor\]$/,I=/^(?:0|[1-9]\d*)$/,B={};B[o]=B["[object Array]"]=B[v]=B[w]=B[s]=B[a]=B[x]=B[E]=B[S]=B[A]=B[k]=B[f]=B[l]=B[h]=B[d]=B[y]=B[g]=B[m]=B[j]=B[_]=B[O]=B[P]=!0,B["[object Error]"]=B[c]=B[b]=!1;var N="object"==typeof n.g&&n.g&&n.g.Object===Object&&n.g,C="object"==typeof self&&self&&self.Object===Object&&self,U=N||C||Function("return this")(),L=e&&!e.nodeType&&e,H=L&&t&&!t.nodeType&&t,$=H&&H.exports===L;function D(t,e){return t.set(e[0],e[1]),t}function z(t,e){return t.add(e),t}function M(t,e,n,r){var i=-1,o=t?t.length:0;for(r&&o&&(n=t[++i]);++i<o;)n=e(n,t[i],i,t);return n}function R(t){var e=!1;if(null!=t&&"function"!=typeof t.toString)try{e=!!(t+"")}catch(t){}return e}function q(t){var e=-1,n=Array(t.size);return t.forEach((function(t,r){n[++e]=[r,t]})),n}function V(t,e){return function(n){return t(e(n))}}function K(t){var e=-1,n=Array(t.size);return t.forEach((function(t){n[++e]=t})),n}var W,G=Array.prototype,Z=Function.prototype,J=Object.prototype,X=U["__core-js_shared__"],Y=(W=/[^.]+$/.exec(X&&X.keys&&X.keys.IE_PROTO||""))?"Symbol(src)_1."+W:"",Q=Z.toString,tt=J.hasOwnProperty,et=J.toString,nt=RegExp("^"+Q.call(tt).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),rt=$?U.Buffer:void 0,it=U.Symbol,ot=U.Uint8Array,st=V(Object.getPrototypeOf,Object),at=Object.create,ct=J.propertyIsEnumerable,ut=G.splice,ft=Object.getOwnPropertySymbols,lt=rt?rt.isBuffer:void 0,ht=V(Object.keys,Object),pt=Ut(U,"DataView"),dt=Ut(U,"Map"),yt=Ut(U,"Promise"),gt=Ut(U,"Set"),mt=Ut(U,"WeakMap"),bt=Ut(Object,"create"),vt=zt(pt),wt=zt(dt),xt=zt(yt),Et=zt(gt),St=zt(mt),At=it?it.prototype:void 0,kt=At?At.valueOf:void 0;function jt(t){var e=-1,n=t?t.length:0;for(this.clear();+