@alephium/web3-wallet
Version:
Simple wallets for Alephium
2 lines • 1.05 MB
JavaScript
/*! For license information please see alephium-web3-wallet.min.js.LICENSE.txt */
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.alephium=t():e.alephium=t()}(self,(()=>(()=>{var e={9695:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0}),t.utils=t.schnorr=t.verify=t.signSync=t.sign=t.getSharedSecret=t.recoverPublicKey=t.getPublicKey=t.Signature=t.Point=t.CURVE=void 0;const n=r(7998),i=BigInt(0),o=BigInt(1),s=BigInt(2),a=BigInt(3),c=BigInt(8),f=Object.freeze({a:i,b:BigInt(7),P:BigInt("0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),n:BigInt("0xfffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141"),h:o,Gx:BigInt("55066263022277343669578718895168534326250603453777594175500187360389116729240"),Gy:BigInt("32670510020758816978083085130507043184471273380659243275938904335757337482424"),beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee")});t.CURVE=f;const u=(e,t)=>(e+t/s)/t,d={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar(e){const{n:t}=f,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-o*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,a=BigInt("0x100000000000000000000000000000000"),c=u(s*e,t),d=u(-n*e,t);let h=D(e-c*r-d*i,t),l=D(-c*n-d*s,t);const p=h>a,b=l>a;if(p&&(h=t-h),b&&(l=t-l),h>a||l>a)throw new Error("splitScalarEndo: Endomorphism failed, k="+e);return{k1neg:p,k1:h,k2neg:b,k2:l}}},h=32,l=32,p=h+1,b=2*h+1;function y(e){const{a:t,b:r}=f,n=D(e*e),i=D(n*e);return D(i+t*e+r)}const m=f.a===i;class g extends Error{constructor(e){super(e)}}function v(e){if(!(e instanceof w))throw new TypeError("JacobianPoint expected")}class w{constructor(e,t,r){this.x=e,this.y=t,this.z=r}static fromAffine(e){if(!(e instanceof A))throw new TypeError("JacobianPoint#fromAffine: expected Point");return e.equals(A.ZERO)?w.ZERO:new w(e.x,e.y,o)}static toAffineBatch(e){const t=function(e,t=f.P){const r=new Array(e.length),n=F(e.reduce(((e,n,o)=>n===i?e:(r[o]=e,D(e*n,t))),o),t);return e.reduceRight(((e,n,o)=>n===i?e:(r[o]=D(e*r[o],t),D(e*n,t))),n),r}(e.map((e=>e.z)));return e.map(((e,r)=>e.toAffine(t[r])))}static normalizeZ(e){return w.toAffineBatch(e).map(w.fromAffine)}equals(e){v(e);const{x:t,y:r,z:n}=this,{x:i,y:o,z:s}=e,a=D(n*n),c=D(s*s),f=D(t*c),u=D(i*a),d=D(D(r*s)*c),h=D(D(o*n)*a);return f===u&&d===h}negate(){return new w(this.x,D(-this.y),this.z)}double(){const{x:e,y:t,z:r}=this,n=D(e*e),i=D(t*t),o=D(i*i),f=e+i,u=D(s*(D(f*f)-n-o)),d=D(a*n),h=D(d*d),l=D(h-s*u),p=D(d*(u-l)-c*o),b=D(s*t*r);return new w(l,p,b)}add(e){v(e);const{x:t,y:r,z:n}=this,{x:o,y:a,z:c}=e;if(o===i||a===i)return this;if(t===i||r===i)return e;const f=D(n*n),u=D(c*c),d=D(t*u),h=D(o*f),l=D(D(r*c)*u),p=D(D(a*n)*f),b=D(h-d),y=D(p-l);if(b===i)return y===i?this.double():w.ZERO;const m=D(b*b),g=D(b*m),_=D(d*m),S=D(y*y-g-s*_),A=D(y*(_-S)-l*g),M=D(n*c*b);return new w(S,A,M)}subtract(e){return this.add(e.negate())}multiplyUnsafe(e){const t=w.ZERO;if("bigint"==typeof e&&e===i)return t;let r=L(e);if(r===o)return this;if(!m){let e=t,n=this;for(;r>i;)r&o&&(e=e.add(n)),n=n.double(),r>>=o;return e}let{k1neg:n,k1:s,k2neg:a,k2:c}=d.splitScalar(r),f=t,u=t,h=this;for(;s>i||c>i;)s&o&&(f=f.add(h)),c&o&&(u=u.add(h)),h=h.double(),s>>=o,c>>=o;return n&&(f=f.negate()),a&&(u=u.negate()),u=new w(D(u.x*d.beta),u.y,u.z),f.add(u)}precomputeWindow(e){const t=m?128/e+1:256/e+1,r=[];let n=this,i=n;for(let o=0;o<t;o++){i=n,r.push(i);for(let t=1;t<2**(e-1);t++)i=i.add(n),r.push(i);n=i.double()}return r}wNAF(e,t){!t&&this.equals(w.BASE)&&(t=A.BASE);const r=t&&t._WINDOW_SIZE||1;if(256%r)throw new Error("Point#wNAF: Invalid precomputation window, must be power of 2");let n=t&&S.get(t);n||(n=this.precomputeWindow(r),t&&1!==r&&(n=w.normalizeZ(n),S.set(t,n)));let i=w.ZERO,s=w.BASE;const a=1+(m?128/r:256/r),c=2**(r-1),f=BigInt(2**r-1),u=2**r,d=BigInt(r);for(let t=0;t<a;t++){const r=t*c;let a=Number(e&f);e>>=d,a>c&&(a-=u,e+=o);const h=r,l=r+Math.abs(a)-1,p=t%2!=0,b=a<0;0===a?s=s.add(_(p,n[h])):i=i.add(_(b,n[l]))}return{p:i,f:s}}multiply(e,t){let r,n,i=L(e);if(m){const{k1neg:e,k1:o,k2neg:s,k2:a}=d.splitScalar(i);let{p:c,f}=this.wNAF(o,t),{p:u,f:h}=this.wNAF(a,t);c=_(e,c),u=_(s,u),u=new w(D(u.x*d.beta),u.y,u.z),r=c.add(u),n=f.add(h)}else{const{p:e,f:o}=this.wNAF(i,t);r=e,n=o}return w.normalizeZ([r,n])[0]}toAffine(e){const{x:t,y:r,z:n}=this,i=this.equals(w.ZERO);null==e&&(e=i?c:F(n));const s=e,a=D(s*s),f=D(a*s),u=D(t*a),d=D(r*f),h=D(n*s);if(i)return A.ZERO;if(h!==o)throw new Error("invZ was invalid");return new A(u,d)}}function _(e,t){const r=t.negate();return e?r:t}w.BASE=new w(f.Gx,f.Gy,o),w.ZERO=new w(i,o,i);const S=new WeakMap;class A{constructor(e,t){this.x=e,this.y=t}_setWindowSize(e){this._WINDOW_SIZE=e,S.delete(this)}hasEvenY(){return this.y%s===i}static fromCompressedHex(e){const t=32===e.length,r=N(t?e:e.subarray(1));if(!G(r))throw new Error("Point is not on curve");let n=function(e){const{P:t}=f,r=BigInt(6),n=BigInt(11),i=BigInt(22),o=BigInt(23),c=BigInt(44),u=BigInt(88),d=e*e*e%t,h=d*d*e%t,l=q(h,a)*h%t,p=q(l,a)*h%t,b=q(p,s)*d%t,y=q(b,n)*b%t,m=q(y,i)*y%t,g=q(m,c)*m%t,v=q(g,u)*g%t,w=q(v,c)*m%t,_=q(w,a)*h%t,S=q(_,o)*y%t,A=q(S,r)*d%t,M=q(A,s);if(M*M%t!==e)throw new Error("Cannot find square root");return M}(y(r));const i=(n&o)===o;t?i&&(n=D(-n)):!(1&~e[0])!==i&&(n=D(-n));const c=new A(r,n);return c.assertValidity(),c}static fromUncompressedHex(e){const t=N(e.subarray(1,h+1)),r=N(e.subarray(h+1,2*h+1)),n=new A(t,r);return n.assertValidity(),n}static fromHex(e){const t=j(e),r=t.length,n=t[0];if(r===h)return this.fromCompressedHex(t);if(r===p&&(2===n||3===n))return this.fromCompressedHex(t);if(r===b&&4===n)return this.fromUncompressedHex(t);throw new Error(`Point.fromHex: received invalid point. Expected 32-${p} compressed bytes or ${b} uncompressed bytes, not ${r}`)}static fromPrivateKey(e){return A.BASE.multiply(J(e))}static fromSignature(e,t,r){const{r:n,s:i}=X(t);if(![0,1,2,3].includes(r))throw new Error("Cannot recover: invalid recovery bit");const o=H(j(e)),{n:s}=f,a=2===r||3===r?n+s:n,c=F(a,s),u=D(-o*c,s),d=D(i*c,s),h=1&r?"03":"02",l=A.fromHex(h+C(a)),p=A.BASE.multiplyAndAddUnsafe(l,u,d);if(!p)throw new Error("Cannot recover signature: point at infinify");return p.assertValidity(),p}toRawBytes(e=!1){return O(this.toHex(e))}toHex(e=!1){const t=C(this.x);return e?`${this.hasEvenY()?"02":"03"}${t}`:`04${t}${C(this.y)}`}toHexX(){return this.toHex(!0).slice(2)}toRawX(){return this.toRawBytes(!0).slice(1)}assertValidity(){const e="Point is not on elliptic curve",{x:t,y:r}=this;if(!G(t)||!G(r))throw new Error(e);const n=D(r*r);if(D(n-y(t))!==i)throw new Error(e)}equals(e){return this.x===e.x&&this.y===e.y}negate(){return new A(this.x,D(-this.y))}double(){return w.fromAffine(this).double().toAffine()}add(e){return w.fromAffine(this).add(w.fromAffine(e)).toAffine()}subtract(e){return this.add(e.negate())}multiply(e){return w.fromAffine(this).multiply(e,this).toAffine()}multiplyAndAddUnsafe(e,t,r){const n=w.fromAffine(this),s=t===i||t===o||this!==A.BASE?n.multiplyUnsafe(t):n.multiply(t),a=w.fromAffine(e).multiplyUnsafe(r),c=s.add(a);return c.equals(w.ZERO)?void 0:c.toAffine()}}function M(e){return Number.parseInt(e[0],16)>=8?"00"+e:e}function E(e){if(e.length<2||2!==e[0])throw new Error(`Invalid signature integer tag: ${I(e)}`);const t=e[1],r=e.subarray(2,t+2);if(!t||r.length!==t)throw new Error("Invalid signature integer: wrong length");if(0===r[0]&&r[1]<=127)throw new Error("Invalid signature integer: trailing length");return{data:N(r),left:e.subarray(t+2)}}t.Point=A,A.BASE=new A(f.Gx,f.Gy),A.ZERO=new A(i,i);class k{constructor(e,t){this.r=e,this.s=t,this.assertValidity()}static fromCompact(e){const t=e instanceof Uint8Array,r="Signature.fromCompact";if("string"!=typeof e&&!t)throw new TypeError(`${r}: Expected string or Uint8Array`);const n=t?I(e):e;if(128!==n.length)throw new Error(`${r}: Expected 64-byte hex`);return new k(R(n.slice(0,64)),R(n.slice(64,128)))}static fromDER(e){const t=e instanceof Uint8Array;if("string"!=typeof e&&!t)throw new TypeError("Signature.fromDER: Expected string or Uint8Array");const{r,s:n}=function(e){if(e.length<2||48!=e[0])throw new Error(`Invalid signature tag: ${I(e)}`);if(e[1]!==e.length-2)throw new Error("Invalid signature: incorrect length");const{data:t,left:r}=E(e.subarray(2)),{data:n,left:i}=E(r);if(i.length)throw new Error(`Invalid signature: left bytes after parsing: ${I(i)}`);return{r:t,s:n}}(t?e:O(e));return new k(r,n)}static fromHex(e){return this.fromDER(e)}assertValidity(){const{r:e,s:t}=this;if(!V(e))throw new Error("Invalid Signature: r must be 0 < r < n");if(!V(t))throw new Error("Invalid Signature: s must be 0 < s < n")}hasHighS(){const e=f.n>>o;return this.s>e}normalizeS(){return this.hasHighS()?new k(this.r,D(-this.s,f.n)):this}toDERRawBytes(){return O(this.toDERHex())}toDERHex(){const e=M(U(this.s)),t=M(U(this.r)),r=e.length/2,n=t.length/2,i=U(r),o=U(n);return`30${U(n+r+4)}02${o}${t}02${i}${e}`}toRawBytes(){return this.toDERRawBytes()}toHex(){return this.toDERHex()}toCompactRawBytes(){return O(this.toCompactHex())}toCompactHex(){return C(this.r)+C(this.s)}}function x(...e){if(!e.every((e=>e instanceof Uint8Array)))throw new Error("Uint8Array list expected");if(1===e.length)return e[0];const t=e.reduce(((e,t)=>e+t.length),0),r=new Uint8Array(t);for(let t=0,n=0;t<e.length;t++){const i=e[t];r.set(i,n),n+=i.length}return r}t.Signature=k;const B=Array.from({length:256},((e,t)=>t.toString(16).padStart(2,"0")));function I(e){if(!(e instanceof Uint8Array))throw new Error("Expected Uint8Array");let t="";for(let r=0;r<e.length;r++)t+=B[e[r]];return t}const T=BigInt("0x10000000000000000000000000000000000000000000000000000000000000000");function C(e){if("bigint"!=typeof e)throw new Error("Expected bigint");if(!(i<=e&&e<T))throw new Error("Expected number 0 <= n < 2^256");return e.toString(16).padStart(64,"0")}function P(e){const t=O(C(e));if(32!==t.length)throw new Error("Error: expected 32 bytes");return t}function U(e){const t=e.toString(16);return 1&t.length?`0${t}`:t}function R(e){if("string"!=typeof e)throw new TypeError("hexToNumber: expected string, got "+typeof e);return BigInt(`0x${e}`)}function O(e){if("string"!=typeof e)throw new TypeError("hexToBytes: expected string, got "+typeof e);if(e.length%2)throw new Error("hexToBytes: received invalid unpadded hex"+e.length);const t=new Uint8Array(e.length/2);for(let r=0;r<t.length;r++){const n=2*r,i=e.slice(n,n+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");t[r]=o}return t}function N(e){return R(I(e))}function j(e){return e instanceof Uint8Array?Uint8Array.from(e):O(e)}function L(e){if("number"==typeof e&&Number.isSafeInteger(e)&&e>0)return BigInt(e);if("bigint"==typeof e&&V(e))return e;throw new TypeError("Expected valid private scalar: 0 < scalar < curve.n")}function D(e,t=f.P){const r=e%t;return r>=i?r:t+r}function q(e,t){const{P:r}=f;let n=e;for(;t-- >i;)n*=n,n%=r;return n}function F(e,t=f.P){if(e===i||t<=i)throw new Error(`invert: expected positive integers, got n=${e} mod=${t}`);let r=D(e,t),n=t,s=i,a=o,c=o,u=i;for(;r!==i;){const e=n/r,t=n%r,i=s-c*e,o=a-u*e;n=r,r=t,s=c,a=u,c=i,u=o}if(n!==o)throw new Error("invert: does not exist");return D(s,t)}function H(e,t=!1){const r=function(e){const t=8*e.length-8*l,r=N(e);return t>0?r>>BigInt(t):r}(e);if(t)return r;const{n}=f;return r>=n?r-n:r}let z,K;class ${constructor(e,t){if(this.hashLen=e,this.qByteLen=t,"number"!=typeof e||e<2)throw new Error("hashLen must be a number");if("number"!=typeof t||t<2)throw new Error("qByteLen must be a number");this.v=new Uint8Array(e).fill(1),this.k=new Uint8Array(e).fill(0),this.counter=0}hmac(...e){return t.utils.hmacSha256(this.k,...e)}hmacSync(...e){return K(this.k,...e)}checkSync(){if("function"!=typeof K)throw new g("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(e=new Uint8Array){this.k=await this.hmac(this.v,Uint8Array.from([0]),e),this.v=await this.hmac(this.v),0!==e.length&&(this.k=await this.hmac(this.v,Uint8Array.from([1]),e),this.v=await this.hmac(this.v))}reseedSync(e=new Uint8Array){this.checkSync(),this.k=this.hmacSync(this.v,Uint8Array.from([0]),e),this.v=this.hmacSync(this.v),0!==e.length&&(this.k=this.hmacSync(this.v,Uint8Array.from([1]),e),this.v=this.hmacSync(this.v))}async generate(){this.incr();let e=0;const t=[];for(;e<this.qByteLen;){this.v=await this.hmac(this.v);const r=this.v.slice();t.push(r),e+=this.v.length}return x(...t)}generateSync(){this.checkSync(),this.incr();let e=0;const t=[];for(;e<this.qByteLen;){this.v=this.hmacSync(this.v);const r=this.v.slice();t.push(r),e+=this.v.length}return x(...t)}}function V(e){return i<e&&e<f.n}function G(e){return i<e&&e<f.P}function W(e,t,r,n=!0){const{n:s}=f,a=H(e,!0);if(!V(a))return;const c=F(a,s),u=A.BASE.multiply(a),d=D(u.x,s);if(d===i)return;const h=D(c*D(t+r*d,s),s);if(h===i)return;let l=new k(d,h),p=(u.x===l.r?0:2)|Number(u.y&o);return n&&l.hasHighS()&&(l=l.normalizeS(),p^=1),{sig:l,recovery:p}}function J(e){let t;if("bigint"==typeof e)t=e;else if("number"==typeof e&&Number.isSafeInteger(e)&&e>0)t=BigInt(e);else if("string"==typeof e){if(e.length!==2*l)throw new Error("Expected 32 bytes of private key");t=R(e)}else{if(!(e instanceof Uint8Array))throw new TypeError("Expected valid private key");if(e.length!==l)throw new Error("Expected 32 bytes of private key");t=N(e)}if(!V(t))throw new Error("Expected private key: 0 < key < n");return t}function Z(e){return e instanceof A?(e.assertValidity(),e):A.fromHex(e)}function X(e){if(e instanceof k)return e.assertValidity(),e;try{return k.fromDER(e)}catch(t){return k.fromCompact(e)}}function Y(e){const t=e instanceof Uint8Array,r="string"==typeof e,n=(t||r)&&e.length;return t?n===p||n===b:r?n===2*p||n===2*b:e instanceof A}function Q(e){return N(e.length>h?e.slice(0,h):e)}function ee(e){const t=Q(e),r=D(t,f.n);return te(r<i?t:r)}function te(e){return P(e)}function re(e,r,n){if(null==e)throw new Error(`sign: expected valid message hash, not "${e}"`);const i=j(e),o=J(r),s=[te(o),ee(i)];if(null!=n){!0===n&&(n=t.utils.randomBytes(h));const e=j(n);if(e.length!==h)throw new Error(`sign: Expected ${h} bytes of extra data`);s.push(e)}return{seed:x(...s),m:Q(i),d:o}}function ne(e,t){const{sig:r,recovery:n}=e,{der:i,recovered:o}=Object.assign({canonical:!0,der:!0},t),s=i?r.toDERRawBytes():r.toCompactRawBytes();return o?[s,n]:s}t.getPublicKey=function(e,t=!1){return A.fromPrivateKey(e).toRawBytes(t)},t.recoverPublicKey=function(e,t,r,n=!1){return A.fromSignature(e,t,r).toRawBytes(n)},t.getSharedSecret=function(e,t,r=!1){if(Y(e))throw new TypeError("getSharedSecret: first arg must be private key");if(!Y(t))throw new TypeError("getSharedSecret: second arg must be public key");const n=Z(t);return n.assertValidity(),n.multiply(J(e)).toRawBytes(r)},t.sign=async function(e,t,r={}){const{seed:n,m:i,d:o}=re(e,t,r.extraEntropy),s=new $(32,l);let a;for(await s.reseed(n);!(a=W(await s.generate(),i,o,r.canonical));)await s.reseed();return ne(a,r)},t.signSync=function(e,t,r={}){const{seed:n,m:i,d:o}=re(e,t,r.extraEntropy),s=new $(32,l);let a;for(s.reseedSync(n);!(a=W(s.generateSync(),i,o,r.canonical));)s.reseedSync();return ne(a,r)};const ie={strict:!0};function oe(e){return D(N(e),f.n)}t.verify=function(e,t,r,n=ie){let i;try{i=X(e),t=j(t)}catch(e){return!1}const{r:o,s}=i;if(n.strict&&i.hasHighS())return!1;const a=H(t);let c;try{c=Z(r)}catch(e){return!1}const{n:u}=f,d=F(s,u),h=D(a*d,u),l=D(o*d,u),p=A.BASE.multiplyAndAddUnsafe(c,h,l);return!!p&&D(p.x,u)===o};class se{constructor(e,t){this.r=e,this.s=t,this.assertValidity()}static fromHex(e){const t=j(e);if(64!==t.length)throw new TypeError(`SchnorrSignature.fromHex: expected 64 bytes, not ${t.length}`);const r=N(t.subarray(0,32)),n=N(t.subarray(32,64));return new se(r,n)}assertValidity(){const{r:e,s:t}=this;if(!G(e)||!V(t))throw new Error("Invalid signature")}toHex(){return C(this.r)+C(this.s)}toRawBytes(){return O(this.toHex())}}class ae{constructor(e,r,n=t.utils.randomBytes()){if(null==e)throw new TypeError(`sign: Expected valid message, not "${e}"`);this.m=j(e);const{x:i,scalar:o}=this.getScalar(J(r));if(this.px=i,this.d=o,this.rand=j(n),32!==this.rand.length)throw new TypeError("sign: Expected 32 bytes of aux randomness")}getScalar(e){const t=A.fromPrivateKey(e),r=t.hasEvenY()?e:f.n-e;return{point:t,scalar:r,x:t.toRawX()}}initNonce(e,t){return P(e^N(t))}finalizeNonce(e){const t=D(N(e),f.n);if(t===i)throw new Error("sign: Creation of signature failed. k is zero");const{point:r,x:n,scalar:o}=this.getScalar(t);return{R:r,rx:n,k:o}}finalizeSig(e,t,r,n){return new se(e.x,D(t+r*n,f.n)).toRawBytes()}error(){throw new Error("sign: Invalid signature produced")}async calc(){const{m:e,d:r,px:n,rand:i}=this,o=t.utils.taggedHash,s=this.initNonce(r,await o(le.aux,i)),{R:a,rx:c,k:f}=this.finalizeNonce(await o(le.nonce,s,n,e)),u=oe(await o(le.challenge,c,n,e)),d=this.finalizeSig(a,f,u,r);return await ue(d,e,n)||this.error(),d}calcSync(){const{m:e,d:r,px:n,rand:i}=this,o=t.utils.taggedHashSync,s=this.initNonce(r,o(le.aux,i)),{R:a,rx:c,k:f}=this.finalizeNonce(o(le.nonce,s,n,e)),u=oe(o(le.challenge,c,n,e)),d=this.finalizeSig(a,f,u,r);return de(d,e,n)||this.error(),d}}function ce(e,t,r){const n=e instanceof se,i=n?e:se.fromHex(e);return n&&i.assertValidity(),{...i,m:j(t),P:Z(r)}}function fe(e,t,r,n){const i=A.BASE.multiplyAndAddUnsafe(t,J(r),D(-n,f.n));return!(!i||!i.hasEvenY()||i.x!==e)}async function ue(e,r,n){try{const{r:i,s:o,m:s,P:a}=ce(e,r,n),c=oe(await t.utils.taggedHash(le.challenge,P(i),a.toRawX(),s));return fe(i,a,o,c)}catch(e){return!1}}function de(e,r,n){try{const{r:i,s:o,m:s,P:a}=ce(e,r,n),c=oe(t.utils.taggedHashSync(le.challenge,P(i),a.toRawX(),s));return fe(i,a,o,c)}catch(e){if(e instanceof g)throw e;return!1}}t.schnorr={Signature:se,getPublicKey:function(e){return A.fromPrivateKey(e).toRawX()},sign:async function(e,t,r){return new ae(e,t,r).calc()},verify:ue,signSync:function(e,t,r){return new ae(e,t,r).calcSync()},verifySync:de},A.BASE._setWindowSize(8);const he={node:n,web:"object"==typeof self&&"crypto"in self?self.crypto:void 0},le={challenge:"BIP0340/challenge",aux:"BIP0340/aux",nonce:"BIP0340/nonce"},pe={};t.utils={bytesToHex:I,hexToBytes:O,concatBytes:x,mod:D,invert:F,isValidPrivateKey(e){try{return J(e),!0}catch(e){return!1}},_bigintTo32Bytes:P,_normalizePrivateKey:J,hashToPrivateKey:e=>{e=j(e);const t=l+8;if(e.length<t||e.length>1024)throw new Error("Expected valid bytes of private key as per FIPS 186");return P(D(N(e),f.n-o)+o)},randomBytes:(e=32)=>{if(he.web)return he.web.getRandomValues(new Uint8Array(e));if(he.node){const{randomBytes:t}=he.node;return Uint8Array.from(t(e))}throw new Error("The environment doesn't have randomBytes function")},randomPrivateKey:()=>t.utils.hashToPrivateKey(t.utils.randomBytes(l+8)),precompute(e=8,t=A.BASE){const r=t===A.BASE?t:new A(t.x,t.y);return r._setWindowSize(e),r.multiply(a),r},sha256:async(...e)=>{if(he.web){const t=await he.web.subtle.digest("SHA-256",x(...e));return new Uint8Array(t)}if(he.node){const{createHash:t}=he.node,r=t("sha256");return e.forEach((e=>r.update(e))),Uint8Array.from(r.digest())}throw new Error("The environment doesn't have sha256 function")},hmacSha256:async(e,...t)=>{if(he.web){const r=await he.web.subtle.importKey("raw",e,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]),n=x(...t),i=await he.web.subtle.sign("HMAC",r,n);return new Uint8Array(i)}if(he.node){const{createHmac:r}=he.node,n=r("sha256",e);return t.forEach((e=>n.update(e))),Uint8Array.from(n.digest())}throw new Error("The environment doesn't have hmac-sha256 function")},sha256Sync:void 0,hmacSha256Sync:void 0,taggedHash:async(e,...r)=>{let n=pe[e];if(void 0===n){const r=await t.utils.sha256(Uint8Array.from(e,(e=>e.charCodeAt(0))));n=x(r,r),pe[e]=n}return t.utils.sha256(n,...r)},taggedHashSync:(e,...t)=>{if("function"!=typeof z)throw new g("sha256Sync is undefined, you need to set it");let r=pe[e];if(void 0===r){const t=z(Uint8Array.from(e,(e=>e.charCodeAt(0))));r=x(t,t),pe[e]=r}return z(r,...t)},_JacobianPoint:w},Object.defineProperties(t.utils,{sha256Sync:{configurable:!1,get:()=>z,set(e){z||(z=e)}},hmacSha256Sync:{configurable:!1,get:()=>K,set(e){K||(K=e)}}})},5737:(e,t,r)=>{"use strict";const n=t;n.bignum=r(4619),n.define=r(4082).define,n.base=r(7594),n.constants=r(6876),n.decoders=r(5126),n.encoders=r(122)},4082:(e,t,r)=>{"use strict";const n=r(122),i=r(5126),o=r(1193);function s(e,t){this.name=e,this.body=t,this.decoders={},this.encoders={}}t.define=function(e,t){return new s(e,t)},s.prototype._createNamed=function(e){const t=this.name;function r(e){this._initNamed(e,t)}return o(r,e),r.prototype._initNamed=function(t,r){e.call(this,t,r)},new r(this)},s.prototype._getDecoder=function(e){return e=e||"der",this.decoders.hasOwnProperty(e)||(this.decoders[e]=this._createNamed(i[e])),this.decoders[e]},s.prototype.decode=function(e,t,r){return this._getDecoder(t).decode(e,r)},s.prototype._getEncoder=function(e){return e=e||"der",this.encoders.hasOwnProperty(e)||(this.encoders[e]=this._createNamed(n[e])),this.encoders[e]},s.prototype.encode=function(e,t,r){return this._getEncoder(t).encode(e,r)}},3802:(e,t,r)=>{"use strict";const n=r(1193),i=r(8657).a,o=r(1628).Buffer;function s(e,t){i.call(this,t),o.isBuffer(e)?(this.base=e,this.offset=0,this.length=e.length):this.error("Input not Buffer")}function a(e,t){if(Array.isArray(e))this.length=0,this.value=e.map((function(e){return a.isEncoderBuffer(e)||(e=new a(e,t)),this.length+=e.length,e}),this);else if("number"==typeof e){if(!(0<=e&&e<=255))return t.error("non-byte EncoderBuffer value");this.value=e,this.length=1}else if("string"==typeof e)this.value=e,this.length=o.byteLength(e);else{if(!o.isBuffer(e))return t.error("Unsupported type: "+typeof e);this.value=e,this.length=e.length}}n(s,i),t.t=s,s.isDecoderBuffer=function(e){return e instanceof s||"object"==typeof e&&o.isBuffer(e.base)&&"DecoderBuffer"===e.constructor.name&&"number"==typeof e.offset&&"number"==typeof e.length&&"function"==typeof e.save&&"function"==typeof e.restore&&"function"==typeof e.isEmpty&&"function"==typeof e.readUInt8&&"function"==typeof e.skip&&"function"==typeof e.raw},s.prototype.save=function(){return{offset:this.offset,reporter:i.prototype.save.call(this)}},s.prototype.restore=function(e){const t=new s(this.base);return t.offset=e.offset,t.length=this.offset,this.offset=e.offset,i.prototype.restore.call(this,e.reporter),t},s.prototype.isEmpty=function(){return this.offset===this.length},s.prototype.readUInt8=function(e){return this.offset+1<=this.length?this.base.readUInt8(this.offset++,!0):this.error(e||"DecoderBuffer overrun")},s.prototype.skip=function(e,t){if(!(this.offset+e<=this.length))return this.error(t||"DecoderBuffer overrun");const r=new s(this.base);return r._reporterState=this._reporterState,r.offset=this.offset,r.length=this.offset+e,this.offset+=e,r},s.prototype.raw=function(e){return this.base.slice(e?e.offset:this.offset,this.length)},t.d=a,a.isEncoderBuffer=function(e){return e instanceof a||"object"==typeof e&&"EncoderBuffer"===e.constructor.name&&"number"==typeof e.length&&"function"==typeof e.join},a.prototype.join=function(e,t){return e||(e=o.alloc(this.length)),t||(t=0),0===this.length||(Array.isArray(this.value)?this.value.forEach((function(r){r.join(e,t),t+=r.length})):("number"==typeof this.value?e[t]=this.value:"string"==typeof this.value?e.write(this.value,t):o.isBuffer(this.value)&&this.value.copy(e,t),t+=this.length)),e}},7594:(e,t,r)=>{"use strict";const n=t;n.Reporter=r(8657).a,n.DecoderBuffer=r(3802).t,n.EncoderBuffer=r(3802).d,n.Node=r(2144)},2144:(e,t,r)=>{"use strict";const n=r(8657).a,i=r(3802).d,o=r(3802).t,s=r(5578),a=["seq","seqof","set","setof","objid","bool","gentime","utctime","null_","enum","int","objDesc","bitstr","bmpstr","charstr","genstr","graphstr","ia5str","iso646str","numstr","octstr","printstr","t61str","unistr","utf8str","videostr"],c=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(a);function f(e,t,r){const n={};this._baseState=n,n.name=r,n.enc=e,n.parent=t||null,n.children=null,n.tag=null,n.args=null,n.reverseArgs=null,n.choice=null,n.optional=!1,n.any=!1,n.obj=!1,n.use=null,n.useDecoder=null,n.key=null,n.default=null,n.explicit=null,n.implicit=null,n.contains=null,n.parent||(n.children=[],this._wrap())}e.exports=f;const u=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];f.prototype.clone=function(){const e=this._baseState,t={};u.forEach((function(r){t[r]=e[r]}));const r=new this.constructor(t.parent);return r._baseState=t,r},f.prototype._wrap=function(){const e=this._baseState;c.forEach((function(t){this[t]=function(){const r=new this.constructor(this);return e.children.push(r),r[t].apply(r,arguments)}}),this)},f.prototype._init=function(e){const t=this._baseState;s(null===t.parent),e.call(this),t.children=t.children.filter((function(e){return e._baseState.parent===this}),this),s.equal(t.children.length,1,"Root node can have only one child")},f.prototype._useArgs=function(e){const t=this._baseState,r=e.filter((function(e){return e instanceof this.constructor}),this);e=e.filter((function(e){return!(e instanceof this.constructor)}),this),0!==r.length&&(s(null===t.children),t.children=r,r.forEach((function(e){e._baseState.parent=this}),this)),0!==e.length&&(s(null===t.args),t.args=e,t.reverseArgs=e.map((function(e){if("object"!=typeof e||e.constructor!==Object)return e;const t={};return Object.keys(e).forEach((function(r){r==(0|r)&&(r|=0);const n=e[r];t[n]=r})),t})))},["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"].forEach((function(e){f.prototype[e]=function(){const t=this._baseState;throw new Error(e+" not implemented for encoding: "+t.enc)}})),a.forEach((function(e){f.prototype[e]=function(){const t=this._baseState,r=Array.prototype.slice.call(arguments);return s(null===t.tag),t.tag=e,this._useArgs(r),this}})),f.prototype.use=function(e){s(e);const t=this._baseState;return s(null===t.use),t.use=e,this},f.prototype.optional=function(){return this._baseState.optional=!0,this},f.prototype.def=function(e){const t=this._baseState;return s(null===t.default),t.default=e,t.optional=!0,this},f.prototype.explicit=function(e){const t=this._baseState;return s(null===t.explicit&&null===t.implicit),t.explicit=e,this},f.prototype.implicit=function(e){const t=this._baseState;return s(null===t.explicit&&null===t.implicit),t.implicit=e,this},f.prototype.obj=function(){const e=this._baseState,t=Array.prototype.slice.call(arguments);return e.obj=!0,0!==t.length&&this._useArgs(t),this},f.prototype.key=function(e){const t=this._baseState;return s(null===t.key),t.key=e,this},f.prototype.any=function(){return this._baseState.any=!0,this},f.prototype.choice=function(e){const t=this._baseState;return s(null===t.choice),t.choice=e,this._useArgs(Object.keys(e).map((function(t){return e[t]}))),this},f.prototype.contains=function(e){const t=this._baseState;return s(null===t.use),t.contains=e,this},f.prototype._decode=function(e,t){const r=this._baseState;if(null===r.parent)return e.wrapResult(r.children[0]._decode(e,t));let n,i=r.default,s=!0,a=null;if(null!==r.key&&(a=e.enterKey(r.key)),r.optional){let n=null;if(null!==r.explicit?n=r.explicit:null!==r.implicit?n=r.implicit:null!==r.tag&&(n=r.tag),null!==n||r.any){if(s=this._peekTag(e,n,r.any),e.isError(s))return s}else{const n=e.save();try{null===r.choice?this._decodeGeneric(r.tag,e,t):this._decodeChoice(e,t),s=!0}catch(e){s=!1}e.restore(n)}}if(r.obj&&s&&(n=e.enterObject()),s){if(null!==r.explicit){const t=this._decodeTag(e,r.explicit);if(e.isError(t))return t;e=t}const n=e.offset;if(null===r.use&&null===r.choice){let t;r.any&&(t=e.save());const n=this._decodeTag(e,null!==r.implicit?r.implicit:r.tag,r.any);if(e.isError(n))return n;r.any?i=e.raw(t):e=n}if(t&&t.track&&null!==r.tag&&t.track(e.path(),n,e.length,"tagged"),t&&t.track&&null!==r.tag&&t.track(e.path(),e.offset,e.length,"content"),r.any||(i=null===r.choice?this._decodeGeneric(r.tag,e,t):this._decodeChoice(e,t)),e.isError(i))return i;if(r.any||null!==r.choice||null===r.children||r.children.forEach((function(r){r._decode(e,t)})),r.contains&&("octstr"===r.tag||"bitstr"===r.tag)){const n=new o(i);i=this._getUse(r.contains,e._reporterState.obj)._decode(n,t)}}return r.obj&&s&&(i=e.leaveObject(n)),null===r.key||null===i&&!0!==s?null!==a&&e.exitKey(a):e.leaveKey(a,r.key,i),i},f.prototype._decodeGeneric=function(e,t,r){const n=this._baseState;return"seq"===e||"set"===e?null:"seqof"===e||"setof"===e?this._decodeList(t,e,n.args[0],r):/str$/.test(e)?this._decodeStr(t,e,r):"objid"===e&&n.args?this._decodeObjid(t,n.args[0],n.args[1],r):"objid"===e?this._decodeObjid(t,null,null,r):"gentime"===e||"utctime"===e?this._decodeTime(t,e,r):"null_"===e?this._decodeNull(t,r):"bool"===e?this._decodeBool(t,r):"objDesc"===e?this._decodeStr(t,e,r):"int"===e||"enum"===e?this._decodeInt(t,n.args&&n.args[0],r):null!==n.use?this._getUse(n.use,t._reporterState.obj)._decode(t,r):t.error("unknown tag: "+e)},f.prototype._getUse=function(e,t){const r=this._baseState;return r.useDecoder=this._use(e,t),s(null===r.useDecoder._baseState.parent),r.useDecoder=r.useDecoder._baseState.children[0],r.implicit!==r.useDecoder._baseState.implicit&&(r.useDecoder=r.useDecoder.clone(),r.useDecoder._baseState.implicit=r.implicit),r.useDecoder},f.prototype._decodeChoice=function(e,t){const r=this._baseState;let n=null,i=!1;return Object.keys(r.choice).some((function(o){const s=e.save(),a=r.choice[o];try{const r=a._decode(e,t);if(e.isError(r))return!1;n={type:o,value:r},i=!0}catch(t){return e.restore(s),!1}return!0}),this),i?n:e.error("Choice not matched")},f.prototype._createEncoderBuffer=function(e){return new i(e,this.reporter)},f.prototype._encode=function(e,t,r){const n=this._baseState;if(null!==n.default&&n.default===e)return;const i=this._encodeValue(e,t,r);return void 0===i||this._skipDefault(i,t,r)?void 0:i},f.prototype._encodeValue=function(e,t,r){const i=this._baseState;if(null===i.parent)return i.children[0]._encode(e,t||new n);let o=null;if(this.reporter=t,i.optional&&void 0===e){if(null===i.default)return;e=i.default}let s=null,a=!1;if(i.any)o=this._createEncoderBuffer(e);else if(i.choice)o=this._encodeChoice(e,t);else if(i.contains)s=this._getUse(i.contains,r)._encode(e,t),a=!0;else if(i.children)s=i.children.map((function(r){if("null_"===r._baseState.tag)return r._encode(null,t,e);if(null===r._baseState.key)return t.error("Child should have a key");const n=t.enterKey(r._baseState.key);if("object"!=typeof e)return t.error("Child expected, but input is not object");const i=r._encode(e[r._baseState.key],t,e);return t.leaveKey(n),i}),this).filter((function(e){return e})),s=this._createEncoderBuffer(s);else if("seqof"===i.tag||"setof"===i.tag){if(!i.args||1!==i.args.length)return t.error("Too many args for : "+i.tag);if(!Array.isArray(e))return t.error("seqof/setof, but data is not Array");const r=this.clone();r._baseState.implicit=null,s=this._createEncoderBuffer(e.map((function(r){const n=this._baseState;return this._getUse(n.args[0],e)._encode(r,t)}),r))}else null!==i.use?o=this._getUse(i.use,r)._encode(e,t):(s=this._encodePrimitive(i.tag,e),a=!0);if(!i.any&&null===i.choice){const e=null!==i.implicit?i.implicit:i.tag,r=null===i.implicit?"universal":"context";null===e?null===i.use&&t.error("Tag could be omitted only for .use()"):null===i.use&&(o=this._encodeComposite(e,a,r,s))}return null!==i.explicit&&(o=this._encodeComposite(i.explicit,!1,"context",o)),o},f.prototype._encodeChoice=function(e,t){const r=this._baseState,n=r.choice[e.type];return n||s(!1,e.type+" not found in "+JSON.stringify(Object.keys(r.choice))),n._encode(e.value,t)},f.prototype._encodePrimitive=function(e,t){const r=this._baseState;if(/str$/.test(e))return this._encodeStr(t,e);if("objid"===e&&r.args)return this._encodeObjid(t,r.reverseArgs[0],r.args[1]);if("objid"===e)return this._encodeObjid(t,null,null);if("gentime"===e||"utctime"===e)return this._encodeTime(t,e);if("null_"===e)return this._encodeNull();if("int"===e||"enum"===e)return this._encodeInt(t,r.args&&r.reverseArgs[0]);if("bool"===e)return this._encodeBool(t);if("objDesc"===e)return this._encodeStr(t,e);throw new Error("Unsupported tag: "+e)},f.prototype._isNumstr=function(e){return/^[0-9 ]*$/.test(e)},f.prototype._isPrintstr=function(e){return/^[A-Za-z0-9 '()+,-./:=?]*$/.test(e)}},8657:(e,t,r)=>{"use strict";const n=r(1193);function i(e){this._reporterState={obj:null,path:[],options:e||{},errors:[]}}function o(e,t){this.path=e,this.rethrow(t)}t.a=i,i.prototype.isError=function(e){return e instanceof o},i.prototype.save=function(){const e=this._reporterState;return{obj:e.obj,pathLen:e.path.length}},i.prototype.restore=function(e){const t=this._reporterState;t.obj=e.obj,t.path=t.path.slice(0,e.pathLen)},i.prototype.enterKey=function(e){return this._reporterState.path.push(e)},i.prototype.exitKey=function(e){const t=this._reporterState;t.path=t.path.slice(0,e-1)},i.prototype.leaveKey=function(e,t,r){const n=this._reporterState;this.exitKey(e),null!==n.obj&&(n.obj[t]=r)},i.prototype.path=function(){return this._reporterState.path.join("/")},i.prototype.enterObject=function(){const e=this._reporterState,t=e.obj;return e.obj={},t},i.prototype.leaveObject=function(e){const t=this._reporterState,r=t.obj;return t.obj=e,r},i.prototype.error=function(e){let t;const r=this._reporterState,n=e instanceof o;if(t=n?e:new o(r.path.map((function(e){return"["+JSON.stringify(e)+"]"})).join(""),e.message||e,e.stack),!r.options.partial)throw t;return n||r.errors.push(t),t},i.prototype.wrapResult=function(e){const t=this._reporterState;return t.options.partial?{result:this.isError(e)?null:e,errors:t.errors}:e},n(o,Error),o.prototype.rethrow=function(e){if(this.message=e+" at: "+(this.path||"(shallow)"),Error.captureStackTrace&&Error.captureStackTrace(this,o),!this.stack)try{throw new Error(this.message)}catch(e){this.stack=e.stack}return this}},1371:(e,t)=>{"use strict";function r(e){const t={};return Object.keys(e).forEach((function(r){(0|r)==r&&(r|=0);const n=e[r];t[n]=r})),t}t.tagClass={0:"universal",1:"application",2:"context",3:"private"},t.tagClassByName=r(t.tagClass),t.tag={0:"end",1:"bool",2:"int",3:"bitstr",4:"octstr",5:"null_",6:"objid",7:"objDesc",8:"external",9:"real",10:"enum",11:"embed",12:"utf8str",13:"relativeOid",16:"seq",17:"set",18:"numstr",19:"printstr",20:"t61str",21:"videostr",22:"ia5str",23:"utctime",24:"gentime",25:"graphstr",26:"iso646str",27:"genstr",28:"unistr",29:"charstr",30:"bmpstr"},t.tagByName=r(t.tag)},6876:(e,t,r)=>{"use strict";const n=t;n._reverse=function(e){const t={};return Object.keys(e).forEach((function(r){(0|r)==r&&(r|=0);const n=e[r];t[n]=r})),t},n.der=r(1371)},629:(e,t,r)=>{"use strict";const n=r(1193),i=r(4619),o=r(3802).t,s=r(2144),a=r(1371);function c(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new f,this.tree._init(e.body)}function f(e){s.call(this,"der",e)}function u(e,t){let r=e.readUInt8(t);if(e.isError(r))return r;const n=a.tagClass[r>>6],i=!(32&r);if(31&~r)r&=31;else{let n=r;for(r=0;!(128&~n);){if(n=e.readUInt8(t),e.isError(n))return n;r<<=7,r|=127&n}}return{cls:n,primitive:i,tag:r,tagStr:a.tag[r]}}function d(e,t,r){let n=e.readUInt8(r);if(e.isError(n))return n;if(!t&&128===n)return null;if(!(128&n))return n;const i=127&n;if(i>4)return e.error("length octect is too long");n=0;for(let t=0;t<i;t++){n<<=8;const t=e.readUInt8(r);if(e.isError(t))return t;n|=t}return n}e.exports=c,c.prototype.decode=function(e,t){return o.isDecoderBuffer(e)||(e=new o(e,t)),this.tree._decode(e,t)},n(f,s),f.prototype._peekTag=function(e,t,r){if(e.isEmpty())return!1;const n=e.save(),i=u(e,'Failed to peek tag: "'+t+'"');return e.isError(i)?i:(e.restore(n),i.tag===t||i.tagStr===t||i.tagStr+"of"===t||r)},f.prototype._decodeTag=function(e,t,r){const n=u(e,'Failed to decode tag of "'+t+'"');if(e.isError(n))return n;let i=d(e,n.primitive,'Failed to get length of "'+t+'"');if(e.isError(i))return i;if(!r&&n.tag!==t&&n.tagStr!==t&&n.tagStr+"of"!==t)return e.error('Failed to match tag: "'+t+'"');if(n.primitive||null!==i)return e.skip(i,'Failed to match body of: "'+t+'"');const o=e.save(),s=this._skipUntilEnd(e,'Failed to skip indefinite length body: "'+this.tag+'"');return e.isError(s)?s:(i=e.offset-o.offset,e.restore(o),e.skip(i,'Failed to match body of: "'+t+'"'))},f.prototype._skipUntilEnd=function(e,t){for(;;){const r=u(e,t);if(e.isError(r))return r;const n=d(e,r.primitive,t);if(e.isError(n))return n;let i;if(i=r.primitive||null!==n?e.skip(n):this._skipUntilEnd(e,t),e.isError(i))return i;if("end"===r.tagStr)break}},f.prototype._decodeList=function(e,t,r,n){const i=[];for(;!e.isEmpty();){const t=this._peekTag(e,"end");if(e.isError(t))return t;const o=r.decode(e,"der",n);if(e.isError(o)&&t)break;i.push(o)}return i},f.prototype._decodeStr=function(e,t){if("bitstr"===t){const t=e.readUInt8();return e.isError(t)?t:{unused:t,data:e.raw()}}if("bmpstr"===t){const t=e.raw();if(t.length%2==1)return e.error("Decoding of string type: bmpstr length mismatch");let r="";for(let e=0;e<t.length/2;e++)r+=String.fromCharCode(t.readUInt16BE(2*e));return r}if("numstr"===t){const t=e.raw().toString("ascii");return this._isNumstr(t)?t:e.error("Decoding of string type: numstr unsupported characters")}if("octstr"===t)return e.raw();if("objDesc"===t)return e.raw();if("printstr"===t){const t=e.raw().toString("ascii");return this._isPrintstr(t)?t:e.error("Decoding of string type: printstr unsupported characters")}return/str$/.test(t)?e.raw().toString():e.error("Decoding of string type: "+t+" unsupported")},f.prototype._decodeObjid=function(e,t,r){let n;const i=[];let o=0,s=0;for(;!e.isEmpty();)s=e.readUInt8(),o<<=7,o|=127&s,128&s||(i.push(o),o=0);128&s&&i.push(o);const a=i[0]/40|0,c=i[0]%40;if(n=r?i:[a,c].concat(i.slice(1)),t){let e=t[n.join(" ")];void 0===e&&(e=t[n.join(".")]),void 0!==e&&(n=e)}return n},f.prototype._decodeTime=function(e,t){const r=e.raw().toString();let n,i,o,s,a,c;if("gentime"===t)n=0|r.slice(0,4),i=0|r.slice(4,6),o=0|r.slice(6,8),s=0|r.slice(8,10),a=0|r.slice(10,12),c=0|r.slice(12,14);else{if("utctime"!==t)return e.error("Decoding "+t+" time is not supported yet");n=0|r.slice(0,2),i=0|r.slice(2,4),o=0|r.slice(4,6),s=0|r.slice(6,8),a=0|r.slice(8,10),c=0|r.slice(10,12),n=n<70?2e3+n:1900+n}return Date.UTC(n,i-1,o,s,a,c,0)},f.prototype._decodeNull=function(){return null},f.prototype._decodeBool=function(e){const t=e.readUInt8();return e.isError(t)?t:0!==t},f.prototype._decodeInt=function(e,t){const r=e.raw();let n=new i(r);return t&&(n=t[n.toString(10)]||n),n},f.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getDecoder("der").tree}},5126:(e,t,r)=>{"use strict";const n=t;n.der=r(629),n.pem=r(2932)},2932:(e,t,r)=>{"use strict";const n=r(1193),i=r(1628).Buffer,o=r(629);function s(e){o.call(this,e),this.enc="pem"}n(s,o),e.exports=s,s.prototype.decode=function(e,t){const r=e.toString().split(/[\r\n]+/g),n=t.label.toUpperCase(),s=/^-----(BEGIN|END) ([^-]+)-----$/;let a=-1,c=-1;for(let e=0;e<r.length;e++){const t=r[e].match(s);if(null!==t&&t[2]===n){if(-1!==a){if("END"!==t[1])break;c=e;break}if("BEGIN"!==t[1])break;a=e}}if(-1===a||-1===c)throw new Error("PEM section not found for: "+n);const f=r.slice(a+1,c).join("");f.replace(/[^a-z0-9+/=]+/gi,"");const u=i.from(f,"base64");return o.prototype.decode.call(this,u,t)}},5841:(e,t,r)=>{"use strict";const n=r(1193),i=r(1628).Buffer,o=r(2144),s=r(1371);function a(e){this.enc="der",this.name=e.name,this.entity=e,this.tree=new c,this.tree._init(e.body)}function c(e){o.call(this,"der",e)}function f(e){return e<10?"0"+e:e}e.exports=a,a.prototype.encode=function(e,t){return this.tree._encode(e,t).join()},n(c,o),c.prototype._encodeComposite=function(e,t,r,n){const o=function(e,t,r,n){let i;if("seqof"===e?e="seq":"setof"===e&&(e="set"),s.tagByName.hasOwnProperty(e))i=s.tagByName[e];else{if("number"!=typeof e||(0|e)!==e)return n.error("Unknown tag: "+e);i=e}return i>=31?n.error("Multi-octet tag encoding unsupported"):(t||(i|=32),i|=s.tagClassByName[r||"universal"]<<6,i)}(e,t,r,this.reporter);if(n.length<128){const e=i.alloc(2);return e[0]=o,e[1]=n.length,this._createEncoderBuffer([e,n])}let a=1;for(let e=n.length;e>=256;e>>=8)a++;const c=i.alloc(2+a);c[0]=o,c[1]=128|a;for(let e=1+a,t=n.length;t>0;e--,t>>=8)c[e]=255&t;return this._createEncoderBuffer([c,n])},c.prototype._encodeStr=function(e,t){if("bitstr"===t)return this._createEncoderBuffer([0|e.unused,e.data]);if("bmpstr"===t){const t=i.alloc(2*e.length);for(let r=0;r<e.length;r++)t.writeUInt16BE(e.charCodeAt(r),2*r);return this._createEncoderBuffer(t)}return"numstr"===t?this._isNumstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: numstr supports only digits and space"):"printstr"===t?this._isPrintstr(e)?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: printstr supports only latin upper and lower case letters, digits, space, apostrophe, left and rigth parenthesis, plus sign, comma, hyphen, dot, slash, colon, equal sign, question mark"):/str$/.test(t)||"objDesc"===t?this._createEncoderBuffer(e):this.reporter.error("Encoding of string type: "+t+" unsupported")},c.prototype._encodeObjid=function(e,t,r){if("string"==typeof e){if(!t)return this.reporter.error("string objid given, but no values map found");if(!t.hasOwnProperty(e))return this.reporter.error("objid not found in values map");e=t[e].split(/[\s.]+/g);for(let t=0;t<e.length;t++)e[t]|=0}else if(Array.isArray(e)){e=e.slice();for(let t=0;t<e.length;t++)e[t]|=0}if(!Array.isArray(e))return this.reporter.error("objid() should be either array or string, got: "+JSON.stringify(e));if(!r){if(e[1]>=40)return this.reporter.error("Second objid identifier OOB");e.splice(0,2,40*e[0]+e[1])}let n=0;for(let t=0;t<e.length;t++){let r=e[t];for(n++;r>=128;r>>=7)n++}const o=i.alloc(n);let s=o.length-1;for(let t=e.length-1;t>=0;t--){let r=e[t];for(o[s--]=127&r;(r>>=7)>0;)o[s--]=128|127&r}return this._createEncoderBuffer(o)},c.prototype._encodeTime=function(e,t){let r;const n=new Date(e);return"gentime"===t?r=[f(n.getUTCFullYear()),f(n.getUTCMonth()+1),f(n.getUTCDate()),f(n.getUTCHours()),f(n.getUTCMinutes()),f(n.getUTCSeconds()),"Z"].join(""):"utctime"===t?r=[f(n.getUTCFullYear()%100),f(n.getUTCMonth()+1),f(n.getUTCDate()),f(n.getUTCHours()),f(n.getUTCMinutes()),f(n.getUTCSeconds()),"Z"].join(""):this.reporter.error("Encoding "+t+" time is not supported yet"),this._encodeStr(r,"octstr")},c.prototype._encodeNull=function(){return this._createEncoderBuffer("")},c.prototype._encodeInt=function(e,t){if("string"==typeof e){if(!t)return this.reporter.error("String int or enum given, but no values map");if(!t.hasOwnProperty(e))return this.reporter.error("Values map doesn't contain: "+JSON.stringify(e));e=t[e]}if("number"!=typeof e&&!i.isBuffer(e)){const t=e.toArray();!e.sign&&128&t[0]&&t.unshift(0),e=i.from(t)}if(i.isBuffer(e)){let t=e.length;0===e.length&&t++;const r=i.alloc(t);return e.copy(r),0===e.length&&(r[0]=0),this._createEncoderBuffer(r)}if(e<128)return this._createEncoderBuffer(e);if(e<256)return this._createEncoderBuffer([0,e]);let r=1;for(let t=e;t>=256;t>>=8)r++;const n=new Array(r);for(let t=n.length-1;t>=0;t--)n[t]=255&e,e>>=8;return 128&n[0]&&n.unshift(0),this._createEncoderBuffer(i.from(n))},c.prototype._encodeBool=function(e){return this._createEncoderBuffer(e?255:0)},c.prototype._use=function(e,t){return"function"==typeof e&&(e=e(t)),e._getEncoder("der").tree},c.prototype._skipDefault=function(e,t,r){const n=this._baseState;let i;if(null===n.default)return!1;const o=e.join();if(void 0===n.defaultBuffer&&(n.defaultBuffer=this._encodeValue(n.default,t,r).join()),o.length!==n.defaultBuffer.length)return!1;for(i=0;i<o.length;i++)if(o[i]!==n.defaultBuffer[i])return!1;return!0}},122:(e,t,r)=>{"use strict";const n=t;n.der=r(5841),n.pem=r(8080)},8080:(e,t,r)=>{"use strict";const n=r(1193),i=r(5841);function o(e){i.call(this,e),this.enc="pem"}n(o,i),e.exports=o,o.prototype.encode=function(e,t){const r=i.prototype.encode.call(this,e).toString("base64"),n=["-----BEGIN "+t.label+"-----"];for(let e=0;e<r.length;e+=64)n.push(r.slice(e,e+64));return n.push("-----END "+t.label+"-----"),n.join("\n")}},1521:(e,t,r)=>{"use strict";var n=r(6608).Buffer;e.exports=function(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var i=0;i<e.length;i++){var o=e.charAt(i),s=o.charCodeAt(0);if(255!==t[s])throw new TypeError(o+" is ambiguous");t[s]=i}var a=e.length,c=e.charAt(0),f=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function d(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return n.alloc(0);for(var r=0,i=0,o=0;e[r]===c;)i++,r++;for(var s=(e.length-r)*f+1>>>0,u=new Uint8Array(s);e[r];){var d=t[e.charCodeAt(r)];if(255===d)return;for(var h=0,l=s-1;(0!==d||h<o)&&-1!==l;l--,h++)d+=a*u[l]>>>0,u[l]=d%256>>>0,d=d/256>>>0;if(0!==d)throw new Error("Non-zero carry");o=h,r++}for(var p=s-o;p!==s&&0===u[p];)p++;var b=n.allocUnsafe(i+(s-p));b.fill(0,0,i);for(var y=i;p!==s;)b[y++]=u[p++];return b}return{encode:function(t){if((Array.isArray(t)||t instanceof Uint8Array)&&(t=n.from(t)),!n.isBuffer(t))throw new TypeError("Expected Buffer");if(0===t.length)return"";for(var r=0,i=0,o=0,s=t.length;o!==s&&0===t[o];)o++,r++;for(var f=(s-o)*u+1>>>0,d=new Uint8Array(f);o!==s;){for(var h=t[o],l=0,p=f-1;(0!==h||l<i)&&-1!==p;p--,l++)h+=256*d[p]>>>0,d[p]=h%a>>>0,h=h/a>>>0;if(0!==h)throw new Error("Non-zero carry");i=l,o++}for(var b=f-i;b!==f&&0===d[b];)b++;for(var y=c.repeat(r);b<f;++b)y+=e.charAt(d[b]);return y},decodeUnsafe:d,decode:function(e){var t=d(e);if(t)return t;throw new Error("Non-base"+a+" character")}}}},4933:(e,t)=>{"use strict";t.byteLength=function(e){var t=a(e),r=t[0],n=t[1];return 3*(r+n)/4-n},t.toByteArray=function(e){var t,r,o=a(e),s=o[0],c=o[1],f=new i(function(e,t,r){return 3*(t+r)/4-r}(0,s,c)),u=0,d=c>0?s-4:s;for(r=0;r<d;r+=4)t=n[e.charCodeAt(r)]<<18|n[e.charCodeAt(r+1)]<<12|n[e.charCodeAt(r+2)]<<6|n[e.charCodeAt(r+3)],f[u++]=t>>16&255,f[u++]=t>>8&255,f[u++]=255&t;return 2===c&&(t=n[e.charCodeAt(r)]<<2|n[e.charCodeAt(r+1)]>>4,f[u++]=255&t),1===c&&(t=n[e.charCodeAt(r)]<<10|n[e.charCodeAt(r+1)]<<4|n[e.charCodeAt(r+2)]>>2,f[u++]=t>>8&255,f[u++]=255&t),f},t.fromByteArray=function(e){for(var t,n=e.length,i=n%3,o=[],s=16383,a=0,f=n-i;a<f;a+=s)o.push(c(e,a,a+s>f?f:a+s));return 1===i?(t=e[n-1],o.push(r[t>>2]+r[t<<4&63]+"==")):2===i&&(t=(e[n-2]<<8)+e[n-1],o.push(r[t>>10]+r[t>>4&63]+r[t<<2&63]+"=")),o.join("")};for(var r=[],n=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",s=0;s<64;++s)r[s]=o[s],n[o.charCodeAt(s)]=s;function a(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function c(e,t,n){for(var i,o,s=[],a=t;a<n;a+=3)i=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),s.push(r[(o=i)>>18&63]+r[o>>12&63]+r[o>>6&63]+r[63&o]);return s.join("")}n["-".charCodeAt(0)]=62,n["_".charCodeAt(0)]=63},4547:(e,t,r)=>{"use strict";Object.defineProperty(t,"__esModule",{value:!0});const n=r(4644),i=r(3064),o=r(3295),s=r(1042),a=r(5854);t.BIP32Factory=function(e){i.testEcc(e);const t=s.BufferN(32),r=s.compile({wif:s.UInt8,bip32:{public:s.UInt32,private:s.UInt32}}),c={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},f=2147483648,u=Math.pow(2,31)-1;function d(e){return s.String(e)&&null!==e.match(/^(m\/)?(\d+'?\/)*\d+'?$/)}function h(e){return s.UInt32(e)&&e<=u}class l{constructor(e,t){this.__D=e,this.__Q=t,this.lowR=!1}get publicKey(){return void 0===this.__Q&&(this.__Q=Buffer.from(e.pointFromScalar(this.__D,!0))),this.__Q}get privateKey(){return this.__D}sign(t,r){if(!this.privateKey)throw new Error("Missing private key");if(void 0===r&&(r=this.lowR),!1===r)return Buffer.from(e.sign(t,this.privateKey));{let r=Buffer.from(e.sign(t,this.privateKey));const n=Buffer.alloc(32,0);let i=0;for(;r[0]>127;)i++,n.writeUIntLE(i,0,6),r=Buffer.from(e.sign(t,this.privateKey,n));return r}}signSchnorr(t){if(!this.privateKey)throw new Error("Missing private key");if(!e.signSchnorr)throw new Error("signSchnorr not supported by ecc library");return Buffer.from(e.signSchnorr(t,this.privateKey))}verify(t,r){return e.verify(t,this.publicKey,r)}verifySchnorr(t,r){if(!e.verifySchnorr)throw new Error("verifySchnorr not supported by ecc library");return e.verifySchnorr(t,this.publicKey.subarray(1,33),r)}}class p extends l{constructor(e,t,n,i,o=0,a=0,c=0){super(e,t),this.chainCode=n,this.network=i,this.__DEPTH=o,this.__INDEX=a,this.__PARENT_FINGERPRINT=c,s(r,i)}get depth(){return this.__DEPTH}get index(){return this.__INDEX}get parentFingerprint(){return this.__PARENT_FINGERPRINT}get identifier(){return n.hash160(this.publicKey)}get fingerprint(){return this.identifier.slice(0,4)}get compressed(){return!0}isNeutered(){return void 0===this.__D}neutered(){return m(this.publicKey,this.chainCode,this.network,this.depth,this.index,this.parentFingerprint)}toBase58(){const e=this.network,t=this.isNeutered()?e.bip32.public:e.bip32.private,r=Buffer.allocUnsafe(78);return r.writeUInt32BE(t,0),r.writeUInt8(this.depth,4),r.writeUInt32BE(this.parentFingerprint,5),r.writeUInt32BE(this.index,9),this.chainCode.copy(r,13),this.isNeutered()?this.publicKey.copy(r,45):(r.wr