zetalink
Version:
ZetaLink enables users to bridge and cross-chain transfer native Bitcoin to select ZRC20 tokens across ZetaChain, Ethereum, Binance Smart Chain & Polygon, offering seamless cross-chain functionality and enhanced interoperability
1 lines • 306 kB
JavaScript
(()=>{var t,e,r={242:(t,e,r)=>{"use strict";var n=r(1048).Buffer,i=r(4261),o=r(4500),s=r(9688);var a,u,f=(a=i,u=Object.create(null),a&&Object.keys(a).forEach((function(t){if("default"!==t){var e=Object.getOwnPropertyDescriptor(a,t);Object.defineProperty(u,t,e.get?e:{enumerable:!0,get:function(){return a[t]}})}})),u.default=a,Object.freeze(u));const c="Expected Private",h="Expected Point",l="Expected Tweak",p="Expected Signature",d="Expected Extra Data (32 bytes)",y="Expected Scalar";f.utils.hmacSha256Sync=(t,...e)=>o.hmac(s.sha256,t,f.utils.concatBytes(...e)),f.utils.sha256Sync=(...t)=>s.sha256(f.utils.concatBytes(...t));const w=f.utils._normalizePrivateKey,g=32,b=32,m=new Uint8Array([255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,254,186,174,220,230,175,72,160,59,191,210,94,140,208,54,65,65]),_=32,E=new Uint8Array(32),v=new Uint8Array([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,69,81,35,25,80,183,95,196,64,45,161,114,47,201,186,238]);function S(t,e){for(let r=0;r<32;++r)if(t[r]!==e[r])return t[r]<e[r]?-1:1;return 0}function T(t){return 0===S(t,E)}function I(t){return t instanceof Uint8Array&&t.length===b&&!(S(t,m)>=0)}function k(t){return t instanceof Uint8Array&&64===t.length&&S(t.subarray(0,32),m)<0&&S(t.subarray(32,64),m)<0}function O(t){return t instanceof Uint8Array&&64===t.length&&S(t.subarray(0,32),v)<0}function A(t){return t instanceof Uint8Array&&t.length===g}function P(t){return void 0===t||t instanceof Uint8Array&&t.length===_}function B(t){if("string"!=typeof t)throw new TypeError("hexToNumber: expected string, got "+typeof t);return BigInt(`0x${t}`)}function x(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(64!==t.length)throw new Error("Expected 32 bytes of private scalar");e=B(t)}else{if(!(t instanceof Uint8Array))throw new TypeError("Expected valid private scalar");if(32!==t.length)throw new Error("Expected 32 bytes of private scalar");r=t,e=B(f.utils.bytesToHex(r))}var r;if(e<0)throw new Error("Expected private scalar >= 0");return e}const U=(t,e,r)=>{const n=f.Point.fromHex(t),i=x(e),o=f.Point.BASE.multiplyAndAddUnsafe(n,i,BigInt(1));if(!o)throw new Error("Tweaked point at infinity");return o.toRawBytes(r)};function R(t,e){return void 0===t?void 0===e||H(e):!!t}function N(t){try{return t()}catch(t){return null}}function C(t,e){if(32===t.length!==e)return!1;try{return!!f.Point.fromHex(t)}catch(t){return!1}}function L(t){return C(t,!1)}function H(t){return C(t,!1)&&33===t.length}function M(t){return f.utils.isValidPrivateKey(t)}function D(t){return C(t,!0)}function j(t){if(!L(t))throw new Error(h);return t.slice(1,33)}function F(t,e){if(!M(t))throw new Error(c);return N((()=>f.getPublicKey(t,R(e))))}e.isPoint=L,e.isPointCompressed=H,e.isPrivate=M,e.isXOnlyPoint=D,e.pointAdd=function(t,e,r){if(!L(t)||!L(e))throw new Error(h);return N((()=>{const n=f.Point.fromHex(t),i=f.Point.fromHex(e);return n.equals(i.negate())?null:n.add(i).toRawBytes(R(r,t))}))},e.pointAddScalar=function(t,e,r){if(!L(t))throw new Error(h);if(!I(e))throw new Error(l);return N((()=>U(t,e,R(r,t))))},e.pointCompress=function(t,e){if(!L(t))throw new Error(h);return f.Point.fromHex(t).toRawBytes(R(e,t))},e.pointFromScalar=F,e.pointMultiply=function(t,e,r){if(!L(t))throw new Error(h);if(!I(e))throw new Error(l);return N((()=>((t,e,r)=>{const n=f.Point.fromHex(t),i="string"==typeof e?e:f.utils.bytesToHex(e),o=BigInt(`0x${i}`);return n.multiply(o).toRawBytes(r)})(t,e,R(r,t))))},e.privateAdd=function(t,e){if(!1===M(t))throw new Error(c);if(!1===I(e))throw new Error(l);return N((()=>((t,e)=>{const r=w(t),n=x(e),i=f.utils._bigintTo32Bytes(f.utils.mod(r+n,f.CURVE.n));return f.utils.isValidPrivateKey(i)?i:null})(t,e)))},e.privateNegate=function(t){if(!1===M(t))throw new Error(c);return(t=>{const e=w(t),r=f.utils._bigintTo32Bytes(f.CURVE.n-e);return f.utils.isValidPrivateKey(r)?r:null})(t)},e.privateSub=function(t,e){if(!1===M(t))throw new Error(c);if(!1===I(e))throw new Error(l);return N((()=>((t,e)=>{const r=w(t),n=x(e),i=f.utils._bigintTo32Bytes(f.utils.mod(r-n,f.CURVE.n));return f.utils.isValidPrivateKey(i)?i:null})(t,e)))},e.recover=function(t,e,r,n){if(!A(t))throw new Error("Expected Hash");if(!k(e)||!function(t){return!(T(t.subarray(0,32))||T(t.subarray(32,64)))}(e))throw new Error(p);if(2&r&&!O(e))throw new Error("Bad Recovery Id");if(!D(e.subarray(0,32)))throw new Error(p);return f.recoverPublicKey(t,e,r,R(n))},e.sign=function(t,e,r){if(!M(e))throw new Error(c);if(!A(t))throw new Error(y);if(!P(r))throw new Error(d);return f.signSync(t,e,{der:!1,extraEntropy:r})},e.signRecoverable=function(t,e,r){if(!M(e))throw new Error(c);if(!A(t))throw new Error(y);if(!P(r))throw new Error(d);const[n,i]=f.signSync(t,e,{der:!1,extraEntropy:r,recovered:!0});return{signature:n,recoveryId:i}},e.signSchnorr=function(t,e,r=n.alloc(32,0)){if(!M(e))throw new Error(c);if(!A(t))throw new Error(y);if(!P(r))throw new Error(d);return f.schnorr.signSync(t,e,r)},e.verify=function(t,e,r,n){if(!L(e))throw new Error(h);if(!k(r))throw new Error(p);if(!A(t))throw new Error(y);return f.verify(r,t,e,{strict:n})},e.verifySchnorr=function(t,e,r){if(!D(e))throw new Error(h);if(!k(r))throw new Error(p);if(!A(t))throw new Error(y);return f.schnorr.verifySync(r,t,e)},e.xOnlyPointAddTweak=function(t,e){if(!D(t))throw new Error(h);if(!I(e))throw new Error(l);return N((()=>{const r=U(t,e,!0);return{parity:r[0]%2==1?1:0,xOnlyPubkey:r.slice(1)}}))},e.xOnlyPointFromPoint=j,e.xOnlyPointFromScalar=function(t){if(!M(t))throw new Error(c);return j(F(t))}},8460:(t,e)=>{"use strict";function r(t){if(!Number.isSafeInteger(t)||t<0)throw new Error(`positive integer expected, not ${t}`)}function n(t){if("boolean"!=typeof t)throw new Error(`boolean expected, not ${t}`)}function i(t){return t instanceof Uint8Array||null!=t&&"object"==typeof t&&"Uint8Array"===t.constructor.name}function o(t,...e){if(!i(t))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(t.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${t.length}`)}function s(t){if("function"!=typeof t||"function"!=typeof t.create)throw new Error("Hash should be wrapped by utils.wrapConstructor");r(t.outputLen),r(t.blockLen)}function a(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 u(t,e){o(t);const r=e.outputLen;if(t.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}Object.defineProperty(e,"__esModule",{value:!0}),e.output=e.exists=e.hash=e.bytes=e.bool=e.number=e.isBytes=void 0,e.number=r,e.bool=n,e.isBytes=i,e.bytes=o,e.hash=s,e.exists=a,e.output=u;const f={number:r,bool:n,bytes:o,hash:s,exists:a,output:u};e.default=f},6423:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.HashMD=e.Maj=e.Chi=void 0;const n=r(8460),i=r(9074);e.Chi=(t,e,r)=>t&e^~t&r;e.Maj=(t,e,r)=>t&e^t&r^e&r;class o extends i.Hash{constructor(t,e,r,n){super(),this.blockLen=t,this.outputLen=e,this.padOffset=r,this.isLE=n,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){(0,n.exists)(this);const{view:e,buffer:r,blockLen:o}=this,s=(t=(0,i.toBytes)(t)).length;for(let n=0;n<s;){const a=Math.min(o-this.pos,s-n);if(a!==o)r.set(t.subarray(n,n+a),this.pos),this.pos+=a,n+=a,this.pos===o&&(this.process(e,0),this.pos=0);else{const e=(0,i.createView)(t);for(;o<=s-n;n+=o)this.process(e,n)}}return this.length+=t.length,this.roundClean(),this}digestInto(t){(0,n.exists)(this),(0,n.output)(t,this),this.finished=!0;const{buffer:e,view:r,blockLen:o,isLE:s}=this;let{pos:a}=this;e[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>o-a&&(this.process(r,0),a=0);for(let t=a;t<o;t++)e[t]=0;!function(t,e,r,n){if("function"==typeof t.setBigUint64)return t.setBigUint64(e,r,n);const i=BigInt(32),o=BigInt(4294967295),s=Number(r>>i&o),a=Number(r&o),u=n?4:0,f=n?0:4;t.setUint32(e+u,s,n),t.setUint32(e+f,a,n)}(r,o-8,BigInt(8*this.length),s),this.process(r,0);const u=(0,i.createView)(t),f=this.outputLen;if(f%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const c=f/4,h=this.get();if(c>h.length)throw new Error("_sha2: outputLen bigger than state");for(let t=0;t<c;t++)u.setUint32(4*t,h[t],s)}digest(){const{buffer:t,outputLen:e}=this;this.digestInto(t);const r=t.slice(0,e);return this.destroy(),r}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:e,buffer:r,length:n,finished:i,destroyed:o,pos:s}=this;return t.length=n,t.pos=s,t.finished=i,t.destroyed=o,n%e&&t.buffer.set(r),t}}e.HashMD=o},6910:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.crypto=void 0,e.crypto="object"==typeof globalThis&&"crypto"in globalThis?globalThis.crypto:void 0},4500:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.hmac=e.HMAC=void 0;const n=r(8460),i=r(9074);class o extends i.Hash{constructor(t,e){super(),this.finished=!1,this.destroyed=!1,(0,n.hash)(t);const r=(0,i.toBytes)(e);if(this.iHash=t.create(),"function"!=typeof this.iHash.update)throw new Error("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(r.length>o?t.create().update(r).digest():r);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(0,n.exists)(this),this.iHash.update(t),this}digestInto(t){(0,n.exists)(this),(0,n.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:r,finished:n,destroyed:i,blockLen:o,outputLen:s}=this;return t.finished=n,t.destroyed=i,t.blockLen=o,t.outputLen=s,t.oHash=e._cloneInto(t.oHash),t.iHash=r._cloneInto(t.iHash),t}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}}e.HMAC=o;e.hmac=(t,e,r)=>new o(t,e).update(r).digest(),e.hmac.create=(t,e)=>new o(t,e)},71:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.ripemd160=e.RIPEMD160=void 0;const n=r(6423),i=r(9074),o=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),s=new Uint8Array(new Array(16).fill(0).map(((t,e)=>e))),a=s.map((t=>(9*t+5)%16));let u=[s],f=[a];for(let t=0;t<4;t++)for(let e of[u,f])e.push(e[t].map((t=>o[t])));const c=[[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8],[12,13,11,15,6,9,9,7,12,15,11,13,7,8,7,7],[13,15,14,11,7,7,6,8,13,14,13,12,5,5,6,9],[14,11,12,14,8,6,5,5,15,12,15,14,9,9,8,6],[15,12,13,13,9,5,8,6,14,11,12,11,8,6,5,5]].map((t=>new Uint8Array(t))),h=u.map(((t,e)=>t.map((t=>c[e][t])))),l=f.map(((t,e)=>t.map((t=>c[e][t])))),p=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),d=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function y(t,e,r,n){return 0===t?e^r^n:1===t?e&r|~e&n:2===t?(e|~r)^n:3===t?e&n|r&~n:e^(r|~n)}const w=new Uint32Array(16);class g extends n.HashMD{constructor(){super(64,20,8,!0),this.h0=1732584193,this.h1=-271733879,this.h2=-1732584194,this.h3=271733878,this.h4=-1009589776}get(){const{h0:t,h1:e,h2:r,h3:n,h4:i}=this;return[t,e,r,n,i]}set(t,e,r,n,i){this.h0=0|t,this.h1=0|e,this.h2=0|r,this.h3=0|n,this.h4=0|i}process(t,e){for(let r=0;r<16;r++,e+=4)w[r]=t.getUint32(e,!0);let r=0|this.h0,n=r,o=0|this.h1,s=o,a=0|this.h2,c=a,g=0|this.h3,b=g,m=0|this.h4,_=m;for(let t=0;t<5;t++){const e=4-t,E=p[t],v=d[t],S=u[t],T=f[t],I=h[t],k=l[t];for(let e=0;e<16;e++){const n=(0,i.rotl)(r+y(t,o,a,g)+w[S[e]]+E,I[e])+m|0;r=m,m=g,g=0|(0,i.rotl)(a,10),a=o,o=n}for(let t=0;t<16;t++){const r=(0,i.rotl)(n+y(e,s,c,b)+w[T[t]]+v,k[t])+_|0;n=_,_=b,b=0|(0,i.rotl)(c,10),c=s,s=r}}this.set(this.h1+a+b|0,this.h2+g+_|0,this.h3+m+n|0,this.h4+r+s|0,this.h0+o+c|0)}roundClean(){w.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}}e.RIPEMD160=g,e.ripemd160=(0,i.wrapConstructor)((()=>new g))},874:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.sha1=void 0;const n=r(6423),i=r(9074),o=new Uint32Array([1732584193,4023233417,2562383102,271733878,3285377520]),s=new Uint32Array(80);class a extends n.HashMD{constructor(){super(64,20,8,!1),this.A=0|o[0],this.B=0|o[1],this.C=0|o[2],this.D=0|o[3],this.E=0|o[4]}get(){const{A:t,B:e,C:r,D:n,E:i}=this;return[t,e,r,n,i]}set(t,e,r,n,i){this.A=0|t,this.B=0|e,this.C=0|r,this.D=0|n,this.E=0|i}process(t,e){for(let r=0;r<16;r++,e+=4)s[r]=t.getUint32(e,!1);for(let t=16;t<80;t++)s[t]=(0,i.rotl)(s[t-3]^s[t-8]^s[t-14]^s[t-16],1);let{A:r,B:o,C:a,D:u,E:f}=this;for(let t=0;t<80;t++){let e,c;t<20?(e=(0,n.Chi)(o,a,u),c=1518500249):t<40?(e=o^a^u,c=1859775393):t<60?(e=(0,n.Maj)(o,a,u),c=2400959708):(e=o^a^u,c=3395469782);const h=(0,i.rotl)(r,5)+e+f+c+s[t]|0;f=u,u=a,a=(0,i.rotl)(o,30),o=r,r=h}r=r+this.A|0,o=o+this.B|0,a=a+this.C|0,u=u+this.D|0,f=f+this.E|0,this.set(r,o,a,u,f)}roundClean(){s.fill(0)}destroy(){this.set(0,0,0,0,0),this.buffer.fill(0)}}e.sha1=(0,i.wrapConstructor)((()=>new a))},9688:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.sha224=e.sha256=void 0;const n=r(6423),i=r(9074),o=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]),s=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),a=new Uint32Array(64);class u extends n.HashMD{constructor(){super(64,32,8,!1),this.A=0|s[0],this.B=0|s[1],this.C=0|s[2],this.D=0|s[3],this.E=0|s[4],this.F=0|s[5],this.G=0|s[6],this.H=0|s[7]}get(){const{A:t,B:e,C:r,D:n,E:i,F:o,G:s,H:a}=this;return[t,e,r,n,i,o,s,a]}set(t,e,r,n,i,o,s,a){this.A=0|t,this.B=0|e,this.C=0|r,this.D=0|n,this.E=0|i,this.F=0|o,this.G=0|s,this.H=0|a}process(t,e){for(let r=0;r<16;r++,e+=4)a[r]=t.getUint32(e,!1);for(let t=16;t<64;t++){const e=a[t-15],r=a[t-2],n=(0,i.rotr)(e,7)^(0,i.rotr)(e,18)^e>>>3,o=(0,i.rotr)(r,17)^(0,i.rotr)(r,19)^r>>>10;a[t]=o+a[t-7]+n+a[t-16]|0}let{A:r,B:s,C:u,D:f,E:c,F:h,G:l,H:p}=this;for(let t=0;t<64;t++){const e=p+((0,i.rotr)(c,6)^(0,i.rotr)(c,11)^(0,i.rotr)(c,25))+(0,n.Chi)(c,h,l)+o[t]+a[t]|0,d=((0,i.rotr)(r,2)^(0,i.rotr)(r,13)^(0,i.rotr)(r,22))+(0,n.Maj)(r,s,u)|0;p=l,l=h,h=c,c=f+e|0,f=u,u=s,s=r,r=e+d|0}r=r+this.A|0,s=s+this.B|0,u=u+this.C|0,f=f+this.D|0,c=c+this.E|0,h=h+this.F|0,l=l+this.G|0,p=p+this.H|0,this.set(r,s,u,f,c,h,l,p)}roundClean(){a.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))},9074:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.randomBytes=e.wrapXOFConstructorWithOpts=e.wrapConstructorWithOpts=e.wrapConstructor=e.checkOpts=e.Hash=e.concatBytes=e.toBytes=e.utf8ToBytes=e.asyncLoop=e.nextTick=e.hexToBytes=e.bytesToHex=e.byteSwap32=e.byteSwapIfBE=e.byteSwap=e.isLE=e.rotl=e.rotr=e.createView=e.u32=e.u8=e.isBytes=void 0;const n=r(6910),i=r(8460);e.isBytes=function(t){return t instanceof Uint8Array||null!=t&&"object"==typeof t&&"Uint8Array"===t.constructor.name};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.rotl=(t,e)=>t<<e|t>>>32-e>>>0,e.isLE=68===new Uint8Array(new Uint32Array([287454020]).buffer)[0];e.byteSwap=t=>t<<24&4278190080|t<<8&16711680|t>>>8&65280|t>>>24&255,e.byteSwapIfBE=e.isLE?t=>t:t=>(0,e.byteSwap)(t),e.byteSwap32=function(t){for(let r=0;r<t.length;r++)t[r]=(0,e.byteSwap)(t[r])};const o=Array.from({length:256},((t,e)=>e.toString(16).padStart(2,"0")));e.bytesToHex=function(t){(0,i.bytes)(t);let e="";for(let r=0;r<t.length;r++)e+=o[t[r]];return e};const s={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function a(t){return t>=s._0&&t<=s._9?t-s._0:t>=s._A&&t<=s._F?t-(s._A-10):t>=s._a&&t<=s._f?t-(s._a-10):void 0}e.hexToBytes=function(t){if("string"!=typeof t)throw new Error("hex string expected, got "+typeof t);const e=t.length,r=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);const n=new Uint8Array(r);for(let e=0,i=0;e<r;e++,i+=2){const r=a(t.charCodeAt(i)),o=a(t.charCodeAt(i+1));if(void 0===r||void 0===o){const e=t[i]+t[i+1];throw new Error('hex string expected, got non-hex character "'+e+'" at index '+i)}n[e]=16*r+o}return n};function u(t){if("string"!=typeof t)throw new Error("utf8ToBytes expected string, got "+typeof t);return new Uint8Array((new TextEncoder).encode(t))}function f(t){return"string"==typeof t&&(t=u(t)),(0,i.bytes)(t),t}e.nextTick=async()=>{},e.asyncLoop=async function(t,r,n){let i=Date.now();for(let o=0;o<t;o++){n(o);const t=Date.now()-i;t>=0&&t<r||(await(0,e.nextTick)(),i+=t)}},e.utf8ToBytes=u,e.toBytes=f,e.concatBytes=function(...t){let e=0;for(let r=0;r<t.length;r++){const n=t[r];(0,i.bytes)(n),e+=n.length}const r=new Uint8Array(e);for(let e=0,n=0;e<t.length;e++){const i=t[e];r.set(i,n),n+=i.length}return r};e.Hash=class{clone(){return this._cloneInto()}};const c={}.toString;e.checkOpts=function(t,e){if(void 0!==e&&"[object Object]"!==c.call(e))throw new Error("Options should be object or undefined");return Object.assign(t,e)},e.wrapConstructor=function(t){const e=e=>t().update(f(e)).digest(),r=t();return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=()=>t(),e},e.wrapConstructorWithOpts=function(t){const e=(e,r)=>t(r).update(f(e)).digest(),r=t({});return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=e=>t(e),e},e.wrapXOFConstructorWithOpts=function(t){const e=(e,r)=>t(r).update(f(e)).digest(),r=t({});return e.outputLen=r.outputLen,e.blockLen=r.blockLen,e.create=e=>t(e),e},e.randomBytes=function(t=32){if(n.crypto&&"function"==typeof n.crypto.getRandomValues)return n.crypto.getRandomValues(new Uint8Array(t));throw new Error("crypto.getRandomValues must be defined")}},4261:(t,e,r)=>{"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 n=r(2028),i=BigInt(0),o=BigInt(1),s=BigInt(2),a=BigInt(3),u=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")});e.CURVE=f;const c=(t,e)=>(t+e/s)/e,h={beta:BigInt("0x7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee"),splitScalar(t){const{n:e}=f,r=BigInt("0x3086d221a7d46bcde86c90e49284eb15"),n=-o*BigInt("0xe4437ed6010e88286f547fa90abfe4c3"),i=BigInt("0x114ca50f7a8e2f3f657c1108d9d44cfd8"),s=r,a=BigInt("0x100000000000000000000000000000000"),u=c(s*t,e),h=c(-n*t,e);let l=D(t-u*r-h*i,e),p=D(-u*n-h*s,e);const d=l>a,y=p>a;if(d&&(l=e-l),y&&(p=e-p),l>a||p>a)throw new Error("splitScalarEndo: Endomorphism failed, k="+t);return{k1neg:d,k1:l,k2neg:y,k2:p}}},l=32,p=32,d=l+1,y=2*l+1;function w(t){const{a:e,b:r}=f,n=D(t*t),i=D(n*t);return D(i+e*t+r)}const g=f.a===i;class b extends Error{constructor(t){super(t)}}function m(t){if(!(t instanceof _))throw new TypeError("JacobianPoint expected")}class _{constructor(t,e,r){this.x=t,this.y=e,this.z=r}static fromAffine(t){if(!(t instanceof S))throw new TypeError("JacobianPoint#fromAffine: expected Point");return t.equals(S.ZERO)?_.ZERO:new _(t.x,t.y,o)}static toAffineBatch(t){const e=function(t,e=f.P){const r=new Array(t.length),n=t.reduce(((t,n,o)=>n===i?t:(r[o]=t,D(t*n,e))),o),s=F(n,e);return t.reduceRight(((t,n,o)=>n===i?t:(r[o]=D(t*r[o],e),D(t*n,e))),s),r}(t.map((t=>t.z)));return t.map(((t,r)=>t.toAffine(e[r])))}static normalizeZ(t){return _.toAffineBatch(t).map(_.fromAffine)}equals(t){m(t);const{x:e,y:r,z:n}=this,{x:i,y:o,z:s}=t,a=D(n*n),u=D(s*s),f=D(e*u),c=D(i*a),h=D(D(r*s)*u),l=D(D(o*n)*a);return f===c&&h===l}negate(){return new _(this.x,D(-this.y),this.z)}double(){const{x:t,y:e,z:r}=this,n=D(t*t),i=D(e*e),o=D(i*i),f=t+i,c=D(s*(D(f*f)-n-o)),h=D(a*n),l=D(h*h),p=D(l-s*c),d=D(h*(c-p)-u*o),y=D(s*e*r);return new _(p,d,y)}add(t){m(t);const{x:e,y:r,z:n}=this,{x:o,y:a,z:u}=t;if(o===i||a===i)return this;if(e===i||r===i)return t;const f=D(n*n),c=D(u*u),h=D(e*c),l=D(o*f),p=D(D(r*u)*c),d=D(D(a*n)*f),y=D(l-h),w=D(d-p);if(y===i)return w===i?this.double():_.ZERO;const g=D(y*y),b=D(y*g),E=D(h*g),v=D(w*w-b-s*E),S=D(w*(E-v)-p*b),T=D(n*u*y);return new _(v,S,T)}subtract(t){return this.add(t.negate())}multiplyUnsafe(t){const e=_.ZERO;if("bigint"==typeof t&&t===i)return e;let r=M(t);if(r===o)return this;if(!g){let t=e,n=this;for(;r>i;)r&o&&(t=t.add(n)),n=n.double(),r>>=o;return t}let{k1neg:n,k1:s,k2neg:a,k2:u}=h.splitScalar(r),f=e,c=e,l=this;for(;s>i||u>i;)s&o&&(f=f.add(l)),u&o&&(c=c.add(l)),l=l.double(),s>>=o,u>>=o;return n&&(f=f.negate()),a&&(c=c.negate()),c=new _(D(c.x*h.beta),c.y,c.z),f.add(c)}precomputeWindow(t){const e=g?128/t+1:256/t+1,r=[];let n=this,i=n;for(let o=0;o<e;o++){i=n,r.push(i);for(let e=1;e<2**(t-1);e++)i=i.add(n),r.push(i);n=i.double()}return r}wNAF(t,e){!e&&this.equals(_.BASE)&&(e=S.BASE);const r=e&&e._WINDOW_SIZE||1;if(256%r)throw new Error("Point#wNAF: Invalid precomputation window, must be power of 2");let n=e&&v.get(e);n||(n=this.precomputeWindow(r),e&&1!==r&&(n=_.normalizeZ(n),v.set(e,n)));let i=_.ZERO,s=_.BASE;const a=1+(g?128/r:256/r),u=2**(r-1),f=BigInt(2**r-1),c=2**r,h=BigInt(r);for(let e=0;e<a;e++){const r=e*u;let a=Number(t&f);t>>=h,a>u&&(a-=c,t+=o);const l=r,p=r+Math.abs(a)-1,d=e%2!=0,y=a<0;0===a?s=s.add(E(d,n[l])):i=i.add(E(y,n[p]))}return{p:i,f:s}}multiply(t,e){let r,n,i=M(t);if(g){const{k1neg:t,k1:o,k2neg:s,k2:a}=h.splitScalar(i);let{p:u,f}=this.wNAF(o,e),{p:c,f:l}=this.wNAF(a,e);u=E(t,u),c=E(s,c),c=new _(D(c.x*h.beta),c.y,c.z),r=u.add(c),n=f.add(l)}else{const{p:t,f:o}=this.wNAF(i,e);r=t,n=o}return _.normalizeZ([r,n])[0]}toAffine(t){const{x:e,y:r,z:n}=this,i=this.equals(_.ZERO);null==t&&(t=i?u:F(n));const s=t,a=D(s*s),f=D(a*s),c=D(e*a),h=D(r*f),l=D(n*s);if(i)return S.ZERO;if(l!==o)throw new Error("invZ was invalid");return new S(c,h)}}function E(t,e){const r=e.negate();return t?r:e}_.BASE=new _(f.Gx,f.Gy,o),_.ZERO=new _(i,o,i);const v=new WeakMap;class S{constructor(t,e){this.x=t,this.y=e}_setWindowSize(t){this._WINDOW_SIZE=t,v.delete(this)}hasEvenY(){return this.y%s===i}static fromCompressedHex(t){const e=32===t.length,r=L(e?t:t.subarray(1));if(!$(r))throw new Error("Point is not on curve");let n=function(t){const{P:e}=f,r=BigInt(6),n=BigInt(11),i=BigInt(22),o=BigInt(23),u=BigInt(44),c=BigInt(88),h=t*t*t%e,l=h*h*t%e,p=j(l,a)*l%e,d=j(p,a)*l%e,y=j(d,s)*h%e,w=j(y,n)*y%e,g=j(w,i)*w%e,b=j(g,u)*g%e,m=j(b,c)*b%e,_=j(m,u)*g%e,E=j(_,a)*l%e,v=j(E,o)*w%e,S=j(v,r)*h%e,T=j(S,s);if(T*T%e!==t)throw new Error("Cannot find square root");return T}(w(r));const i=(n&o)===o;if(e)i&&(n=D(-n));else{!(1&~t[0])!==i&&(n=D(-n))}const u=new S(r,n);return u.assertValidity(),u}static fromUncompressedHex(t){const e=L(t.subarray(1,l+1)),r=L(t.subarray(l+1,2*l+1)),n=new S(e,r);return n.assertValidity(),n}static fromHex(t){const e=H(t),r=e.length,n=e[0];if(r===l)return this.fromCompressedHex(e);if(r===d&&(2===n||3===n))return this.fromCompressedHex(e);if(r===y&&4===n)return this.fromUncompressedHex(e);throw new Error(`Point.fromHex: received invalid point. Expected 32-${d} compressed bytes or ${y} uncompressed bytes, not ${r}`)}static fromPrivateKey(t){return S.BASE.multiply(z(t))}static fromSignature(t,e,r){const{r:n,s:i}=J(e);if(![0,1,2,3].includes(r))throw new Error("Cannot recover: invalid recovery bit");const o=K(H(t)),{n:s}=f,a=2===r||3===r?n+s:n,u=F(a,s),c=D(-o*u,s),h=D(i*u,s),l=1&r?"03":"02",p=S.fromHex(l+x(a)),d=S.BASE.multiplyAndAddUnsafe(p,c,h);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=x(this.x);if(t){return`${this.hasEvenY()?"02":"03"}${e}`}return`04${e}${x(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:r}=this;if(!$(e)||!$(r))throw new Error(t);const n=D(r*r);if(D(n-w(e))!==i)throw new Error(t)}equals(t){return this.x===t.x&&this.y===t.y}negate(){return new S(this.x,D(-this.y))}double(){return _.fromAffine(this).double().toAffine()}add(t){return _.fromAffine(this).add(_.fromAffine(t)).toAffine()}subtract(t){return this.add(t.negate())}multiply(t){return _.fromAffine(this).multiply(t,this).toAffine()}multiplyAndAddUnsafe(t,e,r){const n=_.fromAffine(this),s=e===i||e===o||this!==S.BASE?n.multiplyUnsafe(e):n.multiply(e),a=_.fromAffine(t).multiplyUnsafe(r),u=s.add(a);return u.equals(_.ZERO)?void 0:u.toAffine()}}function T(t){return Number.parseInt(t[0],16)>=8?"00"+t:t}function I(t){if(t.length<2||2!==t[0])throw new Error(`Invalid signature integer tag: ${P(t)}`);const e=t[1],r=t.subarray(2,e+2);if(!e||r.length!==e)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:L(r),left:t.subarray(e+2)}}e.Point=S,S.BASE=new S(f.Gx,f.Gy),S.ZERO=new S(i,i);class k{constructor(t,e){this.r=t,this.s=e,this.assertValidity()}static fromCompact(t){const e=t instanceof Uint8Array,r="Signature.fromCompact";if("string"!=typeof t&&!e)throw new TypeError(`${r}: Expected string or Uint8Array`);const n=e?P(t):t;if(128!==n.length)throw new Error(`${r}: Expected 64-byte hex`);return new k(N(n.slice(0,64)),N(n.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,s:n}=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:r}=I(t.subarray(2)),{data:n,left:i}=I(r);if(i.length)throw new Error(`Invalid signature: left bytes after parsing: ${P(i)}`);return{r:e,s:n}}(e?t:C(t));return new k(r,n)}static fromHex(t){return this.fromDER(t)}assertValidity(){const{r:t,s:e}=this;if(!q(t))throw new Error("Invalid Signature: r must be 0 < r < n");if(!q(e))throw new Error("Invalid Signature: s must be 0 < s < n")}hasHighS(){const t=f.n>>o;return this.s>t}normalizeS(){return this.hasHighS()?new k(this.r,D(-this.s,f.n)):this}toDERRawBytes(){return C(this.toDERHex())}toDERHex(){const t=T(R(this.s)),e=T(R(this.r)),r=t.length/2,n=e.length/2,i=R(r),o=R(n);return`30${R(n+r+4)}02${o}${e}02${i}${t}`}toRawBytes(){return this.toDERRawBytes()}toHex(){return this.toDERHex()}toCompactRawBytes(){return C(this.toCompactHex())}toCompactHex(){return x(this.r)+x(this.s)}}function O(...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),r=new Uint8Array(e);for(let e=0,n=0;e<t.length;e++){const i=t[e];r.set(i,n),n+=i.length}return r}e.Signature=k;const A=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 r=0;r<t.length;r++)e+=A[t[r]];return e}const B=BigInt("0x10000000000000000000000000000000000000000000000000000000000000000");function x(t){if("bigint"!=typeof t)throw new Error("Expected bigint");if(!(i<=t&&t<B))throw new Error("Expected number 0 <= n < 2^256");return t.toString(16).padStart(64,"0")}function U(t){const e=C(x(t));if(32!==e.length)throw new Error("Error: expected 32 bytes");return e}function R(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 r=0;r<e.length;r++){const n=2*r,i=t.slice(n,n+2),o=Number.parseInt(i,16);if(Number.isNaN(o)||o<0)throw new Error("Invalid byte sequence");e[r]=o}return e}function L(t){return N(P(t))}function H(t){return t instanceof Uint8Array?Uint8Array.from(t):C(t)}function M(t){if("number"==typeof t&&Number.isSafeInteger(t)&&t>0)return BigInt(t);if("bigint"==typeof t&&q(t))return t;throw new TypeError("Expected valid private scalar: 0 < scalar < curve.n")}function D(t,e=f.P){const r=t%e;return r>=i?r:e+r}function j(t,e){const{P:r}=f;let n=t;for(;e-- >i;)n*=n,n%=r;return n}function F(t,e=f.P){if(t===i||e<=i)throw new Error(`invert: expected positive integers, got n=${t} mod=${e}`);let r=D(t,e),n=e,s=i,a=o,u=o,c=i;for(;r!==i;){const t=n/r,e=n%r,i=s-u*t,o=a-c*t;n=r,r=e,s=u,a=c,u=i,c=o}if(n!==o)throw new Error("invert: does not exist");return D(s,e)}function K(t,e=!1){const r=function(t){const e=8*t.length-8*p,r=L(t);return e>0?r>>BigInt(e):r}(t);if(e)return r;const{n}=f;return r>=n?r-n:r}let V,W;class G{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 W(this.k,...t)}checkSync(){if("function"!=typeof W)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 r=this.v.slice();e.push(r),t+=this.v.length}return O(...e)}generateSync(){this.checkSync(),this.incr();let t=0;const e=[];for(;t<this.qByteLen;){this.v=this.hmacSync(this.v);const r=this.v.slice();e.push(r),t+=this.v.length}return O(...e)}}function q(t){return i<t&&t<f.n}function $(t){return i<t&&t<f.P}function X(t,e,r,n=!0){const{n:s}=f,a=K(t,!0);if(!q(a))return;const u=F(a,s),c=S.BASE.multiply(a),h=D(c.x,s);if(h===i)return;const l=D(u*D(e+r*h,s),s);if(l===i)return;let p=new k(h,l),d=(c.x===p.r?0:2)|Number(c.y&o);return n&&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=L(t)}if(!q(e))throw new Error("Expected private key: 0 < key < n");return e}function Y(t){return t instanceof S?(t.assertValidity(),t):S.fromHex(t)}function J(t){if(t instanceof k)return t.assertValidity(),t;try{return k.fromDER(t)}catch(e){return k.fromCompact(t)}}function Z(t){const e=t instanceof Uint8Array,r="string"==typeof t,n=(e||r)&&t.length;return e?n===d||n===y:r?n===2*d||n===2*y:t instanceof S}function Q(t){return L(t.length>l?t.slice(0,l):t)}function tt(t){const e=Q(t),r=D(e,f.n);return et(r<i?e:r)}function et(t){return U(t)}function rt(t,r,n){if(null==t)throw new Error(`sign: expected valid message hash, not "${t}"`);const i=H(t),o=z(r),s=[et(o),tt(i)];if(null!=n){!0===n&&(n=e.utils.randomBytes(l));const t=H(n);if(t.length!==l)throw new Error(`sign: Expected ${l} bytes of extra data`);s.push(t)}return{seed:O(...s),m:Q(i),d:o}}function nt(t,e){const{sig:r,recovery:n}=t,{der:i,recovered:o}=Object.assign({canonical:!0,der:!0},e),s=i?r.toDERRawBytes():r.toCompactRawBytes();return o?[s,n]:s}e.getPublicKey=function(t,e=!1){return S.fromPrivateKey(t).toRawBytes(e)},e.recoverPublicKey=function(t,e,r,n=!1){return S.fromSignature(t,e,r).toRawBytes(n)},e.getSharedSecret=function(t,e,r=!1){if(Z(t))throw new TypeError("getSharedSecret: first arg must be private key");if(!Z(e))throw new TypeError("getSharedSecret: second arg must be public key");const n=Y(e);return n.assertValidity(),n.multiply(z(t)).toRawBytes(r)},e.sign=async function(t,e,r={}){const{seed:n,m:i,d:o}=rt(t,e,r.extraEntropy),s=new G(32,p);let a;for(await s.reseed(n);!(a=X(await s.generate(),i,o,r.canonical));)await s.reseed();return nt(a,r)},e.signSync=function(t,e,r={}){const{seed:n,m:i,d:o}=rt(t,e,r.extraEntropy),s=new G(32,p);let a;for(s.reseedSync(n);!(a=X(s.generateSync(),i,o,r.canonical));)s.reseedSync();return nt(a,r)};const it={strict:!0};function ot(t){return D(L(t),f.n)}e.verify=function(t,e,r,n=it){let i;try{i=J(t),e=H(e)}catch(t){return!1}const{r:o,s}=i;if(n.strict&&i.hasHighS())return!1;const a=K(e);let u;try{u=Y(r)}catch(t){return!1}const{n:c}=f,h=F(s,c),l=D(a*h,c),p=D(o*h,c),d=S.BASE.multiplyAndAddUnsafe(u,l,p);return!!d&&D(d.x,c)===o};class st{constructor(t,e){this.r=t,this.s=e,this.assertValidity()}static fromHex(t){const e=H(t);if(64!==e.length)throw new TypeError(`SchnorrSignature.fromHex: expected 64 bytes, not ${e.length}`);const r=L(e.subarray(0,32)),n=L(e.subarray(32,64));return new st(r,n)}assertValidity(){const{r:t,s:e}=this;if(!$(t)||!q(e))throw new Error("Invalid signature")}toHex(){return x(this.r)+x(this.s)}toRawBytes(){return C(this.toHex())}}class at{constructor(t,r,n=e.utils.randomBytes()){if(null==t)throw new TypeError(`sign: Expected valid message, not "${t}"`);this.m=H(t);const{x:i,scalar:o}=this.getScalar(z(r));if(this.px=i,this.d=o,this.rand=H(n),32!==this.rand.length)throw new TypeError("sign: Expected 32 bytes of aux randomness")}getScalar(t){const e=S.fromPrivateKey(t),r=e.hasEvenY()?t:f.n-t;return{point:e,scalar:r,x:e.toRawX()}}initNonce(t,e){return U(t^L(e))}finalizeNonce(t){const e=D(L(t),f.n);if(e===i)throw new Error("sign: Creation of signature failed. k is zero");const{point:r,x:n,scalar:o}=this.getScalar(e);return{R:r,rx:n,k:o}}finalizeSig(t,e,r,n){return new st(t.x,D(e+r*n,f.n)).toRawBytes()}error(){throw new Error("sign: Invalid signature produced")}async calc(){const{m:t,d:r,px:n,rand:i}=this,o=e.utils.taggedHash,s=this.initNonce(r,await o(pt.aux,i)),{R:a,rx:u,k:f}=this.finalizeNonce(await o(pt.nonce,s,n,t)),c=ot(await o(pt.challenge,u,n,t)),h=this.finalizeSig(a,f,c,r);return await ct(h,t,n)||this.error(),h}calcSync(){const{m:t,d:r,px:n,rand:i}=this,o=e.utils.taggedHashSync,s=this.initNonce(r,o(pt.aux,i)),{R:a,rx:u,k:f}=this.finalizeNonce(o(pt.nonce,s,n,t)),c=ot(o(pt.challenge,u,n,t)),h=this.finalizeSig(a,f,c,r);return ht(h,t,n)||this.error(),h}}function ut(t,e,r){const n=t instanceof st,i=n?t:st.fromHex(t);return n&&i.assertValidity(),{...i,m:H(e),P:Y(r)}}function ft(t,e,r,n){const i=S.BASE.multiplyAndAddUnsafe(e,z(r),D(-n,f.n));return!(!i||!i.hasEvenY()||i.x!==t)}async function ct(t,r,n){try{const{r:i,s:o,m:s,P:a}=ut(t,r,n),u=ot(await e.utils.taggedHash(pt.challenge,U(i),a.toRawX(),s));return ft(i,a,o,u)}catch(t){return!1}}function ht(t,r,n){try{const{r:i,s:o,m:s,P:a}=ut(t,r,n),u=ot(e.utils.taggedHashSync(pt.challenge,U(i),a.toRawX(),s));return ft(i,a,o,u)}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,r){return new at(t,e,r).calc()},verify:ct,signSync:function(t,e,r){return new at(t,e,r).calcSync()},verifySync:ht},S.BASE._setWindowSize(8);const lt={node:n,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:O,mod:D,invert:F,isValidPrivateKey(t){try{return z(t),!0}catch(t){return!1}},_bigintTo32Bytes:U,_normalizePrivateKey:z,hashToPrivateKey:t=>{t=H(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 U(D(L(t),f.n-o)+o)},randomBytes:(t=32)=>{if(lt.web)return lt.web.getRandomValues(new Uint8Array(t));if(lt.node){const{randomBytes:e}=lt.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 r=e===S.BASE?e:new S(e.x,e.y);return r._setWindowSize(t),r.multiply(a),r},sha256:async(...t)=>{if(lt.web){const e=await lt.web.subtle.digest("SHA-256",O(...t));return new Uint8Array(e)}if(lt.node){const{createHash:e}=lt.node,r=e("sha256");return t.forEach((t=>r.update(t))),Uint8Array.from(r.digest())}throw new Error("The environment doesn't have sha256 function")},hmacSha256:async(t,...e)=>{if(lt.web){const r=await lt.web.subtle.importKey("raw",t,{name:"HMAC",hash:{name:"SHA-256"}},!1,["sign"]),n=O(...e),i=await lt.web.subtle.sign("HMAC",r,n);return new Uint8Array(i)}if(lt.node){const{createHmac:r}=lt.node,n=r("sha256",t);return e.forEach((t=>n.update(t))),Uint8Array.from(n.digest())}throw new Error("The environment doesn't have hmac-sha256 function")},sha256Sync:void 0,hmacSha256Sync:void 0,taggedHash:async(t,...r)=>{let n=dt[t];if(void 0===n){const r=await e.utils.sha256(Uint8Array.from(t,(t=>t.charCodeAt(0))));n=O(r,r),dt[t]=n}return e.utils.sha256(n,...r)},taggedHashSync:(t,...e)=>{if("function"!=typeof V)throw new b("sha256Sync is undefined, you need to set it");let r=dt[t];if(void 0===r){const e=V(Uint8Array.from(t,(t=>t.charCodeAt(0))));r=O(e,e),dt[t]=r}return V(r,...e)},_JacobianPoint:_},Object.defineProperties(e.utils,{sha256Sync:{configurable:!1,get:()=>V,set(t){V||(V=t)}},hmacSha256Sync:{configurable:!1,get:()=>W,set(t){W||(W=t)}}})},7403:(t,e,r)=>{"use strict";var n=r(5636).Buffer;t.exports=function(t){if(t.length>=255)throw new TypeError("Alphabet too long");for(var e=new Uint8Array(256),r=0;r<e.length;r++)e[r]=255;for(var i=0;i<t.length;i++){var o=t.charAt(i),s=o.charCodeAt(0);if(255!==e[s])throw new TypeError(o+" is ambiguous");e[s]=i}var a=t.length,u=t.charAt(0),f=Math.log(a)/Math.log(256),c=Math.log(256)/Math.log(a);function h(t){if("string"!=typeof t)throw new TypeError("Expected String");if(0===t.length)return n.alloc(0);for(var r=0,i=0,o=0;t[r]===u;)i++,r++;for(var s=(t.length-r)*f+1>>>0,c=new Uint8Array(s);r<t.length;){var h=e[t.charCodeAt(r)];if(255===h)return;for(var l=0,p=s-1;(0!==h||l<o)&&-1!==p;p--,l++)h+=a*c[p]>>>0,c[p]=h%256>>>0,h=h/256>>>0;if(0!==h)throw new Error("Non-zero carry");o=l,r++}for(var d=s-o;d!==s&&0===c[d];)d++;var y=n.allocUnsafe(i+(s-d));y.fill(0,0,i);for(var w=i;d!==s;)y[w++]=c[d++];return y}return{encode:function(e){if((Array.isArray(e)||e instanceof Uint8Array)&&(e=n.from(e)),!n.isBuffer(e))throw new TypeError("Expected Buffer");if(0===e.length)return"";for(var r=0,i=0,o=0,s=e.length;o!==s&&0===e[o];)o++,r++;for(var f=(s-o)*c+1>>>0,h=new Uint8Array(f);o!==s;){for(var l=e[o],p=0,d=f-1;(0!==l||p<i)&&-1!==d;d--,p++)l+=256*h[d]>>>0,h[d]=l%a>>>0,l=l/a>>>0;if(0!==l)throw new Error("Non-zero carry");i=p,o++}for(var y=f-i;y!==f&&0===h[y];)y++;for(var w=u.repeat(r);y<f;++y)w+=t.charAt(h[y]);return w},decodeUnsafe:h,decode:function(t){var e=h(t);if(e)return e;throw new Error("Non-base"+a+" character")}}}},7991:(t,e)=>{"use strict";e.byteLength=function(t){var e=a(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,o=a(t),s=o[0],u=o[1],f=new i(function(t,e,r){return 3*(e+r)/4-r}(0,s,u)),c=0,h=u>0?s-4:s;for(r=0;r<h;r+=4)e=n[t.charCodeAt(r)]<<18|n[t.charCodeAt(r+1)]<<12|n[t.charCodeAt(r+2)]<<6|n[t.charCodeAt(r+3)],f[c++]=e>>16&255,f[c++]=e>>8&255,f[c++]=255&e;2===u&&(e=n[t.charCodeAt(r)]<<2|n[t.charCodeAt(r+1)]>>4,f[c++]=255&e);1===u&&(e=n[t.charCodeAt(r)]<<10|n[t.charCodeAt(r+1)]<<4|n[t.charCodeAt(r+2)]>>2,f[c++]=e>>8&255,f[c++]=255&e);return f},e.fromByteArray=function(t){for(var e,n=t.length,i=n%3,o=[],s=16383,a=0,f=n-i;a<f;a+=s)o.push(u(t,a,a+s>f?f:a+s));1===i?(e=t[n-1],o.push(r[e>>2]+r[e<<4&63]+"==")):2===i&&(e=(t[n-2]<<8)+t[n-1],o.push(r[e>>10]+r[e>>4&63]+r[e<<2&63]+"="));return 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(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function u(t,e,n){for(var i,o,s=[],a=e;a<n;a+=3)i=(t[a]<<16&16711680)+(t[a+1]<<8&65280)+(255&t[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},6586:(t,e)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.bech32m=e.bech32=void 0;const r="qpzry9x8gf2tvdw0s3jn54khce6mua7l",n={};for(let t=0;t<32;t++){const e=r.charAt(t);n[e]=t}function i(t){const e=t>>25;return(33554431&t)<<5^996825010&-(1&e)^642813549&-(e>>1&1)^513874426&-(e>>2&1)^1027748829&-(e>>3&1)^705979059&-(e>>4&1)}function o(t){let e=1;for(let r=0;r<t.length;++r){const n=t.charCodeAt(r);if(n<33||n>126)return"Invalid prefix ("+t+")";e=i(e)^n>>5}e=i(e);for(let r=0;r<t.length;++r){const n=t.charCodeAt(r);e=i(e)^31&n}return e}function s(t,e,r,n){let i=0,o=0;const s=(1<<r)-1,a=[];for(let n=0;n<t.length;++n)for(i=i<<e|t[n],o+=e;o>=r;)o-=r,a.push(i>>o&s);if(n)o>0&&a.push(i<<r-o&s);else{if(o>=e)return"Excess padding";if(i<<r-o&s)return"Non-zero padding"}return a}function a(t){return s(t,8,5,!0)}function u(t){const e=s(t,5,8,!1);if(Array.isArray(e))return e}function f(t){const e=s(t,5,8,!1);if(Array.isArray(e))return e;throw new Error(e)}function c(t){let e;function s(t,r){if(r=r||90,t.length<8)return t+" too short";if(t.length>r)return"Exceeds length limit";const s=t.toLowerCase(),a=t.toUpperCase();if(t!==s&&t!==a)return"Mixed-case string "+t;const u=(t=s).lastIndexOf("1");if(-1===u)return"No separator character for "+t;if(0===u)return"Missing prefix for "+t;const f=t.slice(0,u),c=t.slice(u+1);if(c.length<6)return"Data too short";let h=o(f);if("string"==typeof h)return h;const l=[];for(let t=0;t<c.length;++t){const e=c.charAt(t),r=n[e];if(void 0===r)return"Unknown character "+e;h=i(h)^r,t+6>=c.length||l.push(r)}return h!==e?"Invalid checksum for "+t:{prefix:f,words:l}}return e="bech32"===t?1:734539939,{decodeUnsafe:function(t,e){const r=s(t,e);if("object"==typeof r)return r},decode:function(t,e){const r=s(t,e);if("object"==typeof r)return r;throw new Error(r)},encode:function(t,n,s){if(s=s||90,t.length+7+n.length>s)throw new TypeError("Exceeds length limit");let a=o(t=t.toLowerCase());if("string"==typeof a)throw new Error(a);let u=t+"1";for(let t=0;t<n.length;++t){const e=n[t];if(e>>5)throw new Error("Non 5-bit word");a=i(a)^e,u+=r.charAt(e)}for(let t=0;t<6;++t)a=i(a);a^=e;for(let t=0;t<6;++t){u+=r.charAt(a>>5*(5-t)&31)}return u},toWords:a,fromWordsUnsafe:u,fromWords:f}}e.bech32=c("bech32"),e.bech32m=c("bech32m")},3162:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0});const n=r(6808);function i(t,e,r){return n=>{if(t.has(n))return;const i=r.filter((t=>t.key.toString("hex")===n))[0];e.push(i),t.add(n)}}function o(t){return t.globalMap.unsignedTx}function s(t){const e=new Set;return t.forEach((t=>{const r=t.key.toString("hex");if(e.has(r))throw new Error("Combine: KeyValue Map keys should be unique");e.add(r)})),e}e.combine=function(t){const e=t[0],r=n.psbtToKeyVals(e),a=t.slice(1);if(0===a.length)throw new Error("Combine: Nothing to combine");const u=o(e);if(void 0===u)throw new Error("Combine: Self missing transaction");const f=s(r.globalKeyVals),c=r.inputKeyVals.map(s),h=r.outputKeyVals.map(s);for(const t of a){const e=o(t);if(void 0===e||!e.toBuffer().equals(u.toBuffer()))throw new Error("Combine: One of the Psbts does not have the same transaction.");const a=n.psbtToKeyVals(t);s(a.globalKeyVals).forEach(i(f,r.globalKeyVals,a.globalKeyVals));a.inputKeyVals.map(s).forEach(((t,e)=>t.forEach(i(c[e],r.inputKeyVals[e],a.inputKeyVals[e]))));a.outputKeyVals.map(s).forEach(((t,e)=>t.forEach(i(h[e],r.outputKeyVals[e],a.outputKeyVals[e]))))}return n.psbtFromKeyVals(u,{globalMapKeyVals:r.globalKeyVals,inputKeyVals:r.inputKeyVals,outputKeyVals:r.outputKeyVals})}},9977:(t,e,r)=>{"use strict";var n=r(1048).Buffer;Object.defineProperty(e,"__esModule",{value:!0});const i=r(9889);e.decode=function(t){if(t.key[0]!==i.GlobalTypes.GLOBAL_XPUB)throw new Error("Decode Error: could not decode globalXpub with key 0x"+t.key.toString("hex"));if(79!==t.key.length||![2,3].includes(t.key[46]))throw new Error("Decode Error: globalXpub has invalid extended pubkey in key 0x"+t.key.toString("hex"));if(t.value.length/4%1!=0)throw new Error("Decode Error: Global GLOBAL_XPUB value length should be multiple of 4");const e=t.key.slice(1),r={masterFingerprint:t.value.slice(0,4),extendedPubkey:e,path:"m"};for(const e of(n=t.value.length/4-1,[...Array(n).keys()])){const n=t.value.readUInt32LE(4*e+4),i=!!(2147483648&n),o=2147483647&n;r.path+="/"+o.toString(10)+(i?"'":"")}var n;return r},e.encode=function(t){const e=n.from([i.GlobalTypes.GLOBAL_XPUB]),r=n.concat([e,t.extendedPubkey]),o=t.path.split("/"),s=n.allocUnsafe(4*o.length);t.masterFingerprint.copy(s,0);let a=4;return o.slice(1).forEach((t=>{const e="'"===t.slice(-1);let r=2147483647&parseInt(e?t.slice(0,-1):t,10);e&&(r+=2147483648),s.writeUInt32LE(r,a),a+=4})),{key:r,value:s}},e.expected="{ masterFingerprint: Buffer; extendedPubkey: Buffer; path: string; }",e.check=function(t){const e=t.extendedPubkey,r=t.masterFingerprint,i=t.path;return n.isBuffer(e)&&78===e.length&&[2,3].indexOf(e[45])>-1&&n.isBuffer(r)&&4===r.length&&"string"==typeof i&&!!i.match(/^m(\/\d+'?)*$/)},e.canAddToArray=function(t,e,r){const n=e.extendedPubkey.toString("hex");return!r.has(n)&&(r.add(n),0===t.filter((t=>t.extendedPubkey.equals(e.extendedPubkey))).length)}},3398:(t,e,r)=>{"use strict";var n=r(1048).Buffer;Object.defineProperty(e,"__esModule",{value:!0});const i=r(9889);e.encode=function(t){return{key:n.from([i.GlobalTypes.UNSIGNED_TX]),value:t.toBuffer()}}},6317:(t,e,r)=>{"use strict";Object.defineProperty(e,"__esModule",{value:!0});const n=r(9889),i=r(9977),o=r(3398),s=r(7312),a=r(4042),u=r(8730),f=r(5098),c=r(4474),h=r(9175),l=r(7279),p=r(7544),d=r(241),y=r(3155),w=r(4709),g=r(9574),b=r(6896),m=r(437),_=r(5400),E=r(2751),v=r(9632),S=r(9079),T={unsignedTx:o,globalXpub:i,checkPubkey:m.makeChecker([])};e.globals=T;const I={nonWitnessUtxo:u,partialSig:f,sighashType:h,finalScriptSig:s,finalScriptWitness:a,porCommitment:c,witnessUtxo:w,bip32Derivation:b.makeConverter(n.InputTypes.BIP32_DERIVATION),redeemScript:_.makeConverter(n.InputTypes.REDEEM_SCRIPT),witnessScript:S.makeConverter(n.InputTypes.WITNESS_SCRIPT),checkPubkey:m.makeChecker([n.InputTypes.PARTIAL_SIG,n.InputTypes.BIP32_DERIVATION]),tapKeySig:l,tapScriptSig:y,tapLeafScript:p,tapBip32Derivation:E.makeConverter(n.InputTypes.TAP_BIP32_DERIVATION),tapInternalKey:v.makeConverter(n.InputTypes.TAP_INTERNAL_KEY),tapMerkleRoot:d};e.inputs=I;const k={bip32Derivation:b.makeConverter(n.OutputTypes.BIP32_DERIVATION),redeemScript:_.makeConverter(n.OutputTypes.REDEEM_SCRIPT),witnessScript:S.makeConverter(n.OutputTypes.WITNESS_SCRIPT),checkPubkey:m.makeChecker([n.OutputTypes.BIP32_DERIVATION]),tapBip32Derivation:E.makeConverter(n.OutputTypes.TAP_BIP32_DERIVATION),tapTree:g,tapInternalKey:v.makeConverter(n.OutputTypes.TAP_INTERNAL_KEY)};e.outputs=k},7312:(t,e,r)=>{"use strict";var n=r(1048).Buffer;Object.defineProperty(e,"__esModule",{value:!0});const i=r(9889);e.decode=function(t){if(t.key[0]!==i.InputTypes.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+t.key.toString("hex"));return t.value},e.encode=function(t){return{key:n.from([i.InputTypes.FINAL_SCRIPTSIG]),value:t}},e.expected="Buffer",e.check=function(t){return n.isBuffer(t)},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.finalScriptSig}},4042:(t,e,r)=>{"use strict";var n=r(1048).Buffer;Object.defineProperty(e,"__esModule",{value:!0});const i=r(9889);e.decode=function(t){if(t.key[0]!==i.InputTypes.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+t.key.toString("hex"));return t.value},e.encode=function(t){return{key:n.from([i.InputTypes.FINAL_SCRIPTWITNESS]),value:t}},e.expected="Buffer",e.check=function(t){return n.isBuffer(t)},e.canAdd=function(t,e){return!!t&&!!e&&void 0===t.finalScriptWitness}},8730:(t,e,r)=>{"use strict";var n=r(1048).Buffer;Object.defineProperty(e,"__esModule",{value:!0});const i=r(9889);e.decode=function(t){if(t.key[0]!==i.InputTypes.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitn