@omnisat/lasereyes 0.0.123 → 0.0.125

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -139,26 +139,26 @@ const fl = "oyl", Hc = "unisat", ic = "xverse", Fc = "phantom", dl = "leather",
139
139
  name: "okx",
140
140
  url: "https://chromewebstore.google.com/detail/okx-wallet/mcohilncbfahbmgdjkbpemcciiolgcge"
141
141
  },
142
- wizz: {
143
- name: "wizz",
144
- url: "https://wizzwallet.io/#extension"
145
- },
146
142
  orange: {
147
143
  name: "orange",
148
144
  url: "https://www.orangewallet.com/"
149
145
  },
150
- phantom: {
151
- name: "phantom",
152
- url: "https://phantom.app/download"
153
- },
154
146
  oyl: {
155
147
  name: "oyl",
156
148
  url: "https://www.oyl.io/#get-wallet"
157
149
  },
150
+ phantom: {
151
+ name: "phantom",
152
+ url: "https://phantom.app/download"
153
+ },
158
154
  unisat: {
159
155
  name: "unisat",
160
156
  url: "https://unisat.io/download"
161
157
  },
158
+ wizz: {
159
+ name: "wizz",
160
+ url: "https://wizzwallet.io/#extension"
161
+ },
162
162
  xverse: {
163
163
  name: "xverse",
164
164
  url: "https://www.xverse.app/download"
@@ -1,4 +1,4 @@
1
- (function(ie,Zo){typeof exports=="object"&&typeof module<"u"?Zo(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],Zo):(ie=typeof globalThis<"u"?globalThis:ie||self,Zo(ie.lasereyes={},ie.React))})(this,function(ie,Zo){"use strict";"use client";var DB=Object.defineProperty,KB=(e,t,r)=>t in e?DB(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Te=(e,t,r)=>KB(e,typeof t!="symbol"?t+"":t,r);function qB(e,t){for(var r=0;r<t.length;r++){const n=t[r];if(typeof n!="string"&&!Array.isArray(n)){for(const o in n)if(o!=="default"&&!(o in e)){const i=Object.getOwnPropertyDescriptor(n,o);i&&Object.defineProperty(e,o,i.get?i:{enumerable:!0,get:()=>n[o]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}let F1=Symbol("clean"),Xo=[],fs=0;const Jh=4;let D1=e=>{let t=[],r={get(){return r.lc||r.listen(()=>{})(),r.value},lc:0,listen(n){return r.lc=t.push(n),()=>{for(let i=fs+Jh;i<Xo.length;)Xo[i]===n?Xo.splice(i,Jh):i+=Jh;let o=t.indexOf(n);~o&&(t.splice(o,1),--r.lc||r.off())}},notify(n,o){let i=!Xo.length;for(let a of t)Xo.push(a,r.value,n,o);if(i){for(fs=0;fs<Xo.length;fs+=Jh)Xo[fs](Xo[fs+1],Xo[fs+2],Xo[fs+3]);Xo.length=0}},off(){},set(n){let o=r.value;o!==n&&(r.value=n,r.notify(o))},subscribe(n){let o=r.listen(n);return n(r.value),o},value:e};return process.env.NODE_ENV!=="production"&&(r[F1]=()=>{t=[],r.lc=0,r.off()}),r};const MB=5,rl=6,Qh=10;let VB=(e,t,r,n)=>(e.events=e.events||{},e.events[r+Qh]||(e.events[r+Qh]=n(o=>{e.events[r].reduceRight((i,a)=>(a(i),i),{shared:{},...o})})),e.events[r]=e.events[r]||[],e.events[r].push(t),()=>{let o=e.events[r],i=o.indexOf(t);o.splice(i,1),o.length||(delete e.events[r],e.events[r+Qh](),delete e.events[r+Qh])}),GB=1e3,WB=(e,t)=>VB(e,r=>{let n=t(r);n&&e.events[rl].push(n)},MB,r=>{let n=e.listen;e.listen=(...i)=>(!e.lc&&!e.active&&(e.active=!0,r()),n(...i));let o=e.off;if(e.events[rl]=[],e.off=()=>{o(),setTimeout(()=>{if(e.active&&!e.lc){e.active=!1;for(let i of e.events[rl])i();e.events[rl]=[]}},GB)},process.env.NODE_ENV!=="production"){let i=e[F1];e[F1]=()=>{for(let a of e.events[rl])a();e.events[rl]=[],e.active=!1,i()}}return()=>{e.listen=n,e.off=o}});function Bi(e,t,r){let n=new Set([...t,void 0]);return e.listen((o,i,a)=>{n.has(a)&&r(o,i,a)})}function r8(e,t,r){let n=Bi(e,t,r);return r(e.value),n}let n8=(e={})=>{let t=D1(e);return t.setKey=function(r,n){let o=t.value;typeof n>"u"&&r in t.value?(t.value={...t.value},delete t.value[r],t.notify(o,r)):t.value[r]!==n&&(t.value={...t.value,[r]:n},t.notify(o,r))},t};const Fc="oyl",ds="unisat",ba="xverse",hs="phantom",Dc="leather",Ci="magic-eden",Kc="okx",qc="wizz",ps="orange",o8="op_net",nl="p2tr",i8="p2pkh",a8="p2sh-p2wpkh",ep="p2wpkh",ZB="p2psh",s8="p2wsh",K1="p2sh",XB={leather:{name:"leather",url:"https://leather.io/install-extension"},"magic-eden":{name:"magic-eden",url:"https://wallet.magiceden.io/"},okx:{name:"okx",url:"https://chromewebstore.google.com/detail/okx-wallet/mcohilncbfahbmgdjkbpemcciiolgcge"},wizz:{name:"wizz",url:"https://wizzwallet.io/#extension"},orange:{name:"orange",url:"https://www.orangewallet.com/"},phantom:{name:"phantom",url:"https://phantom.app/download"},oyl:{name:"oyl",url:"https://www.oyl.io/#get-wallet"},unisat:{name:"unisat",url:"https://unisat.io/download"},xverse:{name:"xverse",url:"https://www.xverse.app/download"}},tp="defaultWallet",Yo={messagePrefix:`Bitcoin Signed Message:
1
+ (function(ie,Zo){typeof exports=="object"&&typeof module<"u"?Zo(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],Zo):(ie=typeof globalThis<"u"?globalThis:ie||self,Zo(ie.lasereyes={},ie.React))})(this,function(ie,Zo){"use strict";"use client";var DB=Object.defineProperty,KB=(e,t,r)=>t in e?DB(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Te=(e,t,r)=>KB(e,typeof t!="symbol"?t+"":t,r);function qB(e,t){for(var r=0;r<t.length;r++){const n=t[r];if(typeof n!="string"&&!Array.isArray(n)){for(const o in n)if(o!=="default"&&!(o in e)){const i=Object.getOwnPropertyDescriptor(n,o);i&&Object.defineProperty(e,o,i.get?i:{enumerable:!0,get:()=>n[o]})}}}return Object.freeze(Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}))}let F1=Symbol("clean"),Xo=[],fs=0;const Jh=4;let D1=e=>{let t=[],r={get(){return r.lc||r.listen(()=>{})(),r.value},lc:0,listen(n){return r.lc=t.push(n),()=>{for(let i=fs+Jh;i<Xo.length;)Xo[i]===n?Xo.splice(i,Jh):i+=Jh;let o=t.indexOf(n);~o&&(t.splice(o,1),--r.lc||r.off())}},notify(n,o){let i=!Xo.length;for(let a of t)Xo.push(a,r.value,n,o);if(i){for(fs=0;fs<Xo.length;fs+=Jh)Xo[fs](Xo[fs+1],Xo[fs+2],Xo[fs+3]);Xo.length=0}},off(){},set(n){let o=r.value;o!==n&&(r.value=n,r.notify(o))},subscribe(n){let o=r.listen(n);return n(r.value),o},value:e};return process.env.NODE_ENV!=="production"&&(r[F1]=()=>{t=[],r.lc=0,r.off()}),r};const MB=5,rl=6,Qh=10;let VB=(e,t,r,n)=>(e.events=e.events||{},e.events[r+Qh]||(e.events[r+Qh]=n(o=>{e.events[r].reduceRight((i,a)=>(a(i),i),{shared:{},...o})})),e.events[r]=e.events[r]||[],e.events[r].push(t),()=>{let o=e.events[r],i=o.indexOf(t);o.splice(i,1),o.length||(delete e.events[r],e.events[r+Qh](),delete e.events[r+Qh])}),GB=1e3,WB=(e,t)=>VB(e,r=>{let n=t(r);n&&e.events[rl].push(n)},MB,r=>{let n=e.listen;e.listen=(...i)=>(!e.lc&&!e.active&&(e.active=!0,r()),n(...i));let o=e.off;if(e.events[rl]=[],e.off=()=>{o(),setTimeout(()=>{if(e.active&&!e.lc){e.active=!1;for(let i of e.events[rl])i();e.events[rl]=[]}},GB)},process.env.NODE_ENV!=="production"){let i=e[F1];e[F1]=()=>{for(let a of e.events[rl])a();e.events[rl]=[],e.active=!1,i()}}return()=>{e.listen=n,e.off=o}});function Bi(e,t,r){let n=new Set([...t,void 0]);return e.listen((o,i,a)=>{n.has(a)&&r(o,i,a)})}function r8(e,t,r){let n=Bi(e,t,r);return r(e.value),n}let n8=(e={})=>{let t=D1(e);return t.setKey=function(r,n){let o=t.value;typeof n>"u"&&r in t.value?(t.value={...t.value},delete t.value[r],t.notify(o,r)):t.value[r]!==n&&(t.value={...t.value,[r]:n},t.notify(o,r))},t};const Fc="oyl",ds="unisat",ba="xverse",hs="phantom",Dc="leather",Ci="magic-eden",Kc="okx",qc="wizz",ps="orange",o8="op_net",nl="p2tr",i8="p2pkh",a8="p2sh-p2wpkh",ep="p2wpkh",ZB="p2psh",s8="p2wsh",K1="p2sh",XB={leather:{name:"leather",url:"https://leather.io/install-extension"},"magic-eden":{name:"magic-eden",url:"https://wallet.magiceden.io/"},okx:{name:"okx",url:"https://chromewebstore.google.com/detail/okx-wallet/mcohilncbfahbmgdjkbpemcciiolgcge"},orange:{name:"orange",url:"https://www.orangewallet.com/"},oyl:{name:"oyl",url:"https://www.oyl.io/#get-wallet"},phantom:{name:"phantom",url:"https://phantom.app/download"},unisat:{name:"unisat",url:"https://unisat.io/download"},wizz:{name:"wizz",url:"https://wizzwallet.io/#extension"},xverse:{name:"xverse",url:"https://www.xverse.app/download"}},tp="defaultWallet",Yo={messagePrefix:`Bitcoin Signed Message:
2
2
  `,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},YB={messagePrefix:`Bitcoin Signed Message:
3
3
  `,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};function JB(e){if(e.length<8||e.length>72||e[0]!==48||e[1]!==e.length-2||e[2]!==2)return!1;const t=e[3];if(t===0||5+t>=e.length||e[4+t]!==2)return!1;const r=e[5+t];return!(r===0||6+t+r!==e.length||e[4]&128||t>1&&e[4]===0&&!(e[5]&128)||e[t+6]&128||r>1&&e[t+6]===0&&!(e[t+7]&128))}function QB(e){if(e.length<8)throw new Error("DER sequence length is too short");if(e.length>72)throw new Error("DER sequence length is too long");if(e[0]!==48)throw new Error("Expected DER sequence");if(e[1]!==e.length-2)throw new Error("DER sequence length is invalid");if(e[2]!==2)throw new Error("Expected DER integer");const t=e[3];if(t===0)throw new Error("R length is zero");if(5+t>=e.length)throw new Error("R length is too long");if(e[4+t]!==2)throw new Error("Expected DER integer (2)");const r=e[5+t];if(r===0)throw new Error("S length is zero");if(6+t+r!==e.length)throw new Error("S length is invalid");if(e[4]&128)throw new Error("R value is negative");if(t>1&&e[4]===0&&!(e[5]&128))throw new Error("R value excessively padded");if(e[t+6]&128)throw new Error("S value is negative");if(r>1&&e[t+6]===0&&!(e[t+7]&128))throw new Error("S value excessively padded");return{r:e.slice(4,4+t),s:e.slice(6+t)}}function eC(e,t){const r=e.length,n=t.length;if(r===0)throw new Error("R length is zero");if(n===0)throw new Error("S length is zero");if(r>33)throw new Error("R length is too long");if(n>33)throw new Error("S length is too long");if(e[0]&128)throw new Error("R value is negative");if(t[0]&128)throw new Error("S value is negative");if(r>1&&e[0]===0&&!(e[1]&128))throw new Error("R value excessively padded");if(n>1&&t[0]===0&&!(t[1]&128))throw new Error("S value excessively padded");const o=new Uint8Array(6+r+n);return o[0]=48,o[1]=o.length-2,o[2]=2,o[3]=e.length,o.set(e,4),o[4+r]=2,o[5+r]=t.length,o.set(t,6+r),o}const Lt={OP_FALSE:0,OP_0:0,OP_PUSHDATA1:76,OP_PUSHDATA2:77,OP_PUSHDATA4:78,OP_1NEGATE:79,OP_RESERVED:80,OP_TRUE:81,OP_1:81,OP_2:82,OP_3:83,OP_4:84,OP_5:85,OP_6:86,OP_7:87,OP_8:88,OP_9:89,OP_10:90,OP_11:91,OP_12:92,OP_13:93,OP_14:94,OP_15:95,OP_16:96,OP_NOP:97,OP_VER:98,OP_IF:99,OP_NOTIF:100,OP_VERIF:101,OP_VERNOTIF:102,OP_ELSE:103,OP_ENDIF:104,OP_VERIFY:105,OP_RETURN:106,OP_TOALTSTACK:107,OP_FROMALTSTACK:108,OP_2DROP:109,OP_2DUP:110,OP_3DUP:111,OP_2OVER:112,OP_2ROT:113,OP_2SWAP:114,OP_IFDUP:115,OP_DEPTH:116,OP_DROP:117,OP_DUP:118,OP_NIP:119,OP_OVER:120,OP_PICK:121,OP_ROLL:122,OP_ROT:123,OP_SWAP:124,OP_TUCK:125,OP_CAT:126,OP_SUBSTR:127,OP_LEFT:128,OP_RIGHT:129,OP_SIZE:130,OP_INVERT:131,OP_AND:132,OP_OR:133,OP_XOR:134,OP_EQUAL:135,OP_EQUALVERIFY:136,OP_RESERVED1:137,OP_RESERVED2:138,OP_1ADD:139,OP_1SUB:140,OP_2MUL:141,OP_2DIV:142,OP_NEGATE:143,OP_ABS:144,OP_NOT:145,OP_0NOTEQUAL:146,OP_ADD:147,OP_SUB:148,OP_MUL:149,OP_DIV:150,OP_MOD:151,OP_LSHIFT:152,OP_RSHIFT:153,OP_BOOLAND:154,OP_BOOLOR:155,OP_NUMEQUAL:156,OP_NUMEQUALVERIFY:157,OP_NUMNOTEQUAL:158,OP_LESSTHAN:159,OP_GREATERTHAN:160,OP_LESSTHANOREQUAL:161,OP_GREATERTHANOREQUAL:162,OP_MIN:163,OP_MAX:164,OP_WITHIN:165,OP_RIPEMD160:166,OP_SHA1:167,OP_SHA256:168,OP_HASH160:169,OP_HASH256:170,OP_CODESEPARATOR:171,OP_CHECKSIG:172,OP_CHECKSIGVERIFY:173,OP_CHECKMULTISIG:174,OP_CHECKMULTISIGVERIFY:175,OP_NOP1:176,OP_NOP2:177,OP_CHECKLOCKTIMEVERIFY:177,OP_NOP3:178,OP_CHECKSEQUENCEVERIFY:178,OP_NOP4:179,OP_NOP5:180,OP_NOP6:181,OP_NOP7:182,OP_NOP8:183,OP_NOP9:184,OP_NOP10:185,OP_CHECKSIGADD:186,OP_PUBKEYHASH:253,OP_PUBKEY:254,OP_INVALIDOPCODE:255},c8={};for(const e of Object.keys(Lt)){const t=Lt[e];c8[t]=e}const rp="0123456789abcdefABCDEF",np=rp.split("").map(e=>e.codePointAt(0)),op=Array(256).fill(!0).map((e,t)=>{const r=String.fromCodePoint(t),n=rp.indexOf(r);return n<0?void 0:n<16?n:n-6}),u8=new TextEncoder,l8=new TextDecoder;function tC(e){return l8.decode(e)}function rC(e){return u8.encode(e)}function ir(e){const t=e.reduce((o,i)=>o+i.length,0),r=new Uint8Array(t);let n=0;for(const o of e)r.set(o,n),n+=o.length;return r}function Me(e){const t=e||new Uint8Array;return t.length>512?oC(t):nC(t)}function nC(e){let t="";for(let r=0;r<e.length;++r)t+=rp[op[np[e[r]>>4]]],t+=rp[op[np[e[r]&15]]];return t}function oC(e){const t=new Uint8Array(e.length*2);for(let r=0;r<e.length;++r)t[r*2]=np[e[r]>>4],t[r*2+1]=np[e[r]&15];return l8.decode(t)}function wa(e){const t=u8.encode(e||""),r=new Uint8Array(Math.floor(t.length/2));let n;for(n=0;n<r.length;n++){const o=op[t[n*2]],i=op[t[n*2+1]];if(o===void 0||i===void 0)break;r[n]=o<<4|i}return n===r.length?r:r.slice(0,n)}function iC(e){return btoa(String.fromCharCode(...e))}function f8(e){const t=atob(e),r=new Uint8Array(t.length);for(let n=0;n<t.length;n++)r[n]=t.charCodeAt(n);return r}function me(e,t){const r=Math.min(e.length,t.length);for(let n=0;n<r;++n)if(e[n]!==t[n])return e[n]<t[n]?-1:1;return e.length===t.length?0:e.length>t.length?1:-1}function ho(e,t,r){if(t+1>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r>255)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 255. Received ${r}`);return e[t]=r,t+1}function aC(e,t,r,n){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>65535)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 65535. Received ${r}`);return n==="LE"?(e[t]=r&255,e[t+1]=r>>8&255):(e[t]=r>>8&255,e[t+1]=r&255),t+2}function zf(e,t,r,n){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>4294967295)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= ${4294967295}. Received ${r}`);return n==="LE"?(e[t]=r&255,e[t+1]=r>>8&255,e[t+2]=r>>16&255,e[t+3]=r>>24&255):(e[t]=r>>24&255,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=r&255),t+4}function sC(e,t,r,n){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>0xffffffffffffffffn)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= ${0xffffffffffffffffn}. Received ${r}`);return n==="LE"?(e[t]=Number(r&0xffn),e[t+1]=Number(r>>8n&0xffn),e[t+2]=Number(r>>16n&0xffn),e[t+3]=Number(r>>24n&0xffn),e[t+4]=Number(r>>32n&0xffn),e[t+5]=Number(r>>40n&0xffn),e[t+6]=Number(r>>48n&0xffn),e[t+7]=Number(r>>56n&0xffn)):(e[t]=Number(r>>56n&0xffn),e[t+1]=Number(r>>48n&0xffn),e[t+2]=Number(r>>40n&0xffn),e[t+3]=Number(r>>32n&0xffn),e[t+4]=Number(r>>24n&0xffn),e[t+5]=Number(r>>16n&0xffn),e[t+6]=Number(r>>8n&0xffn),e[t+7]=Number(r&0xffn)),t+8}function va(e,t){if(t+1>e.length)throw new Error("Offset is outside the bounds of Uint8Array");return e[t]}function cC(e,t,r){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),r==="LE"){let n=0;return n=(n<<8)+e[t+1],n=(n<<8)+e[t],n}else{let n=0;return n=(n<<8)+e[t],n=(n<<8)+e[t+1],n}}function ol(e,t,r){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),r==="LE"){let n=0;return n=(n<<8)+e[t+3]>>>0,n=(n<<8)+e[t+2]>>>0,n=(n<<8)+e[t+1]>>>0,n=(n<<8)+e[t]>>>0,n}else{let n=0;return n=(n<<8)+e[t]>>>0,n=(n<<8)+e[t+1]>>>0,n=(n<<8)+e[t+2]>>>0,n=(n<<8)+e[t+3]>>>0,n}}function d8(e,t,r,n){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r>2147483647||r<-2147483648)throw new Error(`The value of "value" is out of range. It must be >= -2147483648 and <= 2147483647. Received ${r}`);return n=n.toUpperCase(),n==="LE"?(e[t]=r&255,e[t+1]=r>>8&255,e[t+2]=r>>16&255,e[t+3]=r>>24&255):(e[t]=r>>24&255,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=r&255),t+4}function h8(e,t,r,n){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r>0x7fffffffffffffffn||r<-0x8000000000000000n)throw new Error(`The value of "value" is out of range. It must be >= ${-0x8000000000000000n} and <= ${0x7fffffffffffffffn}. Received ${r}`);return n=n.toUpperCase(),n==="LE"?(e[t]=Number(r&0xffn),e[t+1]=Number(r>>8n&0xffn),e[t+2]=Number(r>>16n&0xffn),e[t+3]=Number(r>>24n&0xffn),e[t+4]=Number(r>>32n&0xffn),e[t+5]=Number(r>>40n&0xffn),e[t+6]=Number(r>>48n&0xffn),e[t+7]=Number(r>>56n&0xffn)):(e[t]=Number(r>>56n&0xffn),e[t+1]=Number(r>>48n&0xffn),e[t+2]=Number(r>>40n&0xffn),e[t+3]=Number(r>>32n&0xffn),e[t+4]=Number(r>>24n&0xffn),e[t+5]=Number(r>>16n&0xffn),e[t+6]=Number(r>>8n&0xffn),e[t+7]=Number(r&0xffn)),t+8}function uC(e,t,r){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),r==="LE"){const n=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24>>>0);return e[t+3]<=127?n:n-4294967296}else{const n=(e[t]<<24>>>0)+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];return e[t]<=127?n:n-4294967296}}function p8(e,t,r){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");r=r.toUpperCase();let n=0n;if(r==="LE")return n=(n<<8n)+BigInt(e[t+7]),n=(n<<8n)+BigInt(e[t+6]),n=(n<<8n)+BigInt(e[t+5]),n=(n<<8n)+BigInt(e[t+4]),n=(n<<8n)+BigInt(e[t+3]),n=(n<<8n)+BigInt(e[t+2]),n=(n<<8n)+BigInt(e[t+1]),n=(n<<8n)+BigInt(e[t]),e[t+7]<=127?n:n-0x10000000000000000n;{let o=0n;return o=(o<<8n)+BigInt(e[t]),o=(o<<8n)+BigInt(e[t+1]),o=(o<<8n)+BigInt(e[t+2]),o=(o<<8n)+BigInt(e[t+3]),o=(o<<8n)+BigInt(e[t+4]),o=(o<<8n)+BigInt(e[t+5]),o=(o<<8n)+BigInt(e[t+6]),o=(o<<8n)+BigInt(e[t+7]),e[t]<=127?o:o-0x10000000000000000n}}function g8(e){return e<Lt.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}function lC(e,t,r){const n=g8(t);return n===1?ho(e,r,t):n===2?(ho(e,r,Lt.OP_PUSHDATA1),ho(e,r+1,t)):n===3?(ho(e,r,Lt.OP_PUSHDATA2),aC(e,r+1,t,"LE")):(ho(e,r,Lt.OP_PUSHDATA4),zf(e,r+1,t,"LE")),n}function fC(e,t){const r=va(e,t);let n,o;if(r<Lt.OP_PUSHDATA1)n=r,o=1;else if(r===Lt.OP_PUSHDATA1){if(t+2>e.length)return null;n=va(e,t+1),o=2}else if(r===Lt.OP_PUSHDATA2){if(t+3>e.length)return null;n=cC(e,t+1,"LE"),o=3}else{if(t+5>e.length)return null;if(r!==Lt.OP_PUSHDATA4)throw new Error("Unexpected opcode");n=ol(e,t+1,"LE"),o=5}return{opcode:r,number:n,size:o}}function dC(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}function hC(e){let t=Math.abs(e);const r=dC(t),n=new Uint8Array(r),o=e<0;for(let i=0;i<r;++i)ho(n,i,t&255),t>>=8;return n[r-1]&128?ho(n,r-1,o?128:0):o&&(n[r-1]|=128),n}function pC(e){return{lang:(e==null?void 0:e.lang)??void 0,message:e==null?void 0:e.message,abortEarly:(e==null?void 0:e.abortEarly)??void 0,abortPipeEarly:(e==null?void 0:e.abortPipeEarly)??void 0}}function abe(e){}function sbe(e){}function gC(e,t){var r;return(r=void 0)==null?void 0:r.get(t)}function Rf(e){var t,r;const n=typeof e;return n==="string"?`"${e}"`:n==="number"||n==="bigint"||n==="boolean"?`${e}`:n==="object"||n==="function"?(e&&((r=(t=Object.getPrototypeOf(e))==null?void 0:t.constructor)==null?void 0:r.name))??"null":n}function wn(e,t,r,n,o){const i=o&&"input"in o?o.input:r.value,a=(o==null?void 0:o.expected)??e.expects??null,s=(o==null?void 0:o.received)??Rf(i),c={kind:e.kind,type:e.type,input:i,expected:a,received:s,message:`Invalid ${t}: ${a?`Expected ${a} but r`:"R"}eceived ${s}`,requirement:e.requirement,path:o==null?void 0:o.path,issues:o==null?void 0:o.issues,lang:n.lang,abortEarly:n.abortEarly,abortPipeEarly:n.abortPipeEarly},u=e.kind==="schema",l=(o==null?void 0:o.message)??e.message??gC(e.reference,c.lang)??(u?(c.lang,void 0):null)??n.message??(c.lang,void 0);l&&(c.message=typeof l=="function"?l(c):l),u&&(r.typed=!1),r.issues?r.issues.push(c):r.issues=[c]}function mC(e,t){const r=[...new Set(e)];return r.length>1?`(${r.join(` ${t} `)})`:r[0]??"never"}var yC=class extends Error{constructor(t){super(t[0].message),Te(this,"issues"),this.name="ValiError",this.issues=t}};function m8(e,t){return{kind:"validation",type:"every_item",reference:m8,async:!1,expects:null,requirement:e,message:t,_run(r,n){return r.typed&&!r.value.every(this.requirement)&&wn(this,"item",r,n),r}}}function q1(e){return{kind:"validation",type:"integer",reference:q1,async:!1,expects:null,requirement:Number.isInteger,message:e,_run(t,r){return t.typed&&!this.requirement(t.value)&&wn(this,"integer",t,r),t}}}function y8(e,t){return{kind:"validation",type:"length",reference:y8,async:!1,expects:`${e}`,requirement:e,message:t,_run(r,n){return r.typed&&r.value.length!==this.requirement&&wn(this,"length",r,n,{received:`${r.value.length}`}),r}}}function ip(e,t){return{kind:"validation",type:"max_value",reference:ip,async:!1,expects:`<=${e instanceof Date?e.toJSON():Rf(e)}`,requirement:e,message:t,_run(r,n){return r.typed&&r.value>this.requirement&&wn(this,"value",r,n,{received:r.value instanceof Date?r.value.toJSON():Rf(r.value)}),r}}}function ap(e,t){return{kind:"validation",type:"min_value",reference:ap,async:!1,expects:`>=${e instanceof Date?e.toJSON():Rf(e)}`,requirement:e,message:t,_run(r,n){return r.typed&&r.value<this.requirement&&wn(this,"value",r,n,{received:r.value instanceof Date?r.value.toJSON():Rf(r.value)}),r}}}function b8(e,t){return{kind:"validation",type:"regex",reference:b8,async:!1,expects:`${e}`,requirement:e,message:t,_run(r,n){return r.typed&&!this.requirement.test(r.value)&&wn(this,"format",r,n),r}}}function M1(e,t,r){return typeof e.default=="function"?e.default(t,r):e.default}function sp(e,t){return!e._run({typed:!1,value:t},{abortEarly:!0}).issues}function w8(){return{kind:"schema",type:"any",reference:w8,expects:"any",async:!1,_run(e){return e.typed=!0,e}}}function Wn(e,t){return{kind:"schema",type:"array",reference:Wn,expects:"Array",async:!1,item:e,message:t,_run(r,n){var o;const i=r.value;if(Array.isArray(i)){r.typed=!0,r.value=[];for(let a=0;a<i.length;a++){const s=i[a],c=this.item._run({typed:!1,value:s},n);if(c.issues){const u={type:"array",origin:"value",input:i,key:a,value:s};for(const l of c.issues)l.path?l.path.unshift(u):l.path=[u],(o=r.issues)==null||o.push(l);if(r.issues||(r.issues=c.issues),n.abortEarly){r.typed=!1;break}}c.typed||(r.typed=!1),r.value.push(c.value)}}else wn(this,"type",r,n);return r}}}function v8(e){return{kind:"schema",type:"bigint",reference:v8,expects:"bigint",async:!1,message:e,_run(t,r){return typeof t.value=="bigint"?t.typed=!0:wn(this,"type",t,r),t}}}function Jo(e,t){return{kind:"schema",type:"custom",reference:Jo,expects:"unknown",async:!1,check:e,message:t,_run(r,n){return this.check(r.value)?r.typed=!0:wn(this,"type",r,n),r}}}function cp(e,t){return{kind:"schema",type:"instance",reference:cp,expects:e.name,async:!1,class:e,message:t,_run(r,n){return r.value instanceof this.class?r.typed=!0:wn(this,"type",r,n),r}}}function V1(e,...t){const r={kind:"schema",type:"nullable",reference:V1,expects:`(${e.expects} | null)`,async:!1,wrapped:e,_run(n,o){return n.value===null&&("default"in this&&(n.value=M1(this,n,o)),n.value===null)?(n.typed=!0,n):this.wrapped._run(n,o)}};return 0 in t&&(r.default=t[0]),r}function E8(e,...t){const r={kind:"schema",type:"nullish",reference:E8,expects:`(${e.expects} | null | undefined)`,async:!1,wrapped:e,_run(n,o){return(n.value===null||n.value===void 0)&&("default"in this&&(n.value=M1(this,n,o)),n.value===null||n.value===void 0)?(n.typed=!0,n):this.wrapped._run(n,o)}};return 0 in t&&(r.default=t[0]),r}function Zn(e){return{kind:"schema",type:"number",reference:Zn,expects:"number",async:!1,message:e,_run(t,r){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:wn(this,"type",t,r),t}}}function Cr(e,t){return{kind:"schema",type:"object",reference:Cr,expects:"Object",async:!1,entries:e,message:t,_run(r,n){var o;const i=r.value;if(i&&typeof i=="object"){r.typed=!0,r.value={};for(const a in this.entries){const s=i[a],c=this.entries[a]._run({typed:!1,value:s},n);if(c.issues){const u={type:"object",origin:"value",input:i,key:a,value:s};for(const l of c.issues)l.path?l.path.unshift(u):l.path=[u],(o=r.issues)==null||o.push(l);if(r.issues||(r.issues=c.issues),n.abortEarly){r.typed=!1;break}}c.typed||(r.typed=!1),(c.value!==void 0||a in i)&&(r.value[a]=c.value)}}else wn(this,"type",r,n);return r}}}function up(e,...t){const r={kind:"schema",type:"optional",reference:up,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,_run(n,o){return n.value===void 0&&("default"in this&&(n.value=M1(this,n,o)),n.value===void 0)?(n.typed=!0,n):this.wrapped._run(n,o)}};return 0 in t&&(r.default=t[0]),r}function Mc(e){return{kind:"schema",type:"string",reference:Mc,expects:"string",async:!1,message:e,_run(t,r){return typeof t.value=="string"?t.typed=!0:wn(this,"type",t,r),t}}}function Ui(e,t){return{kind:"schema",type:"tuple",reference:Ui,expects:"Array",async:!1,items:e,message:t,_run(r,n){var o;const i=r.value;if(Array.isArray(i)){r.typed=!0,r.value=[];for(let a=0;a<this.items.length;a++){const s=i[a],c=this.items[a]._run({typed:!1,value:s},n);if(c.issues){const u={type:"array",origin:"value",input:i,key:a,value:s};for(const l of c.issues)l.path?l.path.unshift(u):l.path=[u],(o=r.issues)==null||o.push(l);if(r.issues||(r.issues=c.issues),n.abortEarly){r.typed=!1;break}}c.typed||(r.typed=!1),r.value.push(c.value)}}else wn(this,"type",r,n);return r}}}function k8(e){let t;if(e)for(const r of e)t?t.push(...r.issues):t=r.issues;return t}function G1(e,t){return{kind:"schema",type:"union",reference:G1,expects:mC(e.map(r=>r.expects),"|"),async:!1,options:e,message:t,_run(r,n){let o,i,a;for(const s of this.options){const c=s._run({typed:!1,value:r.value},n);if(c.typed)if(c.issues)i?i.push(c):i=[c];else{o=c;break}else a?a.push(c):a=[c]}if(o)return o;if(i){if(i.length===1)return i[0];wn(this,"type",r,n,{issues:k8(i)}),r.typed=!0}else{if((a==null?void 0:a.length)===1)return a[0];wn(this,"type",r,n,{issues:k8(a)})}return r}}}function ar(e,t,r){const n=e._run({typed:!1,value:t},pC(r));if(n.issues)throw new yC(n.issues);return n.value}function gs(e,t){const r={};for(const n in e.entries)r[n]=up(e.entries[n]);return{...e,entries:r}}function il(...e){return{...e[0],pipe:e,_run(t,r){for(const n of e)if(n.kind!=="metadata"){if(t.issues&&(n.kind==="schema"||n.kind==="transformation")){t.typed=!1;break}(!t.issues||!r.abortEarly&&!r.abortPipeEarly)&&(t=n._run(t,r))}return t}}}const x8=new Uint8Array(32),A8=wa("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),Rr=e=>il(cp(Uint8Array),y8(e));function Lf(e,t){return e.length!==t.length?!1:e.every((r,n)=>me(r,t[n])===0)}function Qo(e){if(!(e instanceof Uint8Array)||e.length<33)return!1;const t=e[0],r=e.slice(1,33);if(me(x8,r)===0||me(r,A8)>=0)return!1;if((t===2||t===3)&&e.length===33)return!0;const n=e.slice(33);return me(x8,n)===0||me(n,A8)>=0?!1:t===4&&e.length===65}const lp=254;function W1(e){return!e||!("output"in e)||!(e.output instanceof Uint8Array)?!1:e.version!==void 0?(e.version&lp)===e.version:!0}function S8(e){return Array.isArray(e)?e.length!==2?!1:e.every(t=>S8(t)):W1(e)}const bC=Rr(32),wC=Rr(20),_8=Rr(32),Ht=cp(Uint8Array);il(Mc(),b8(/^([0-9a-f]{2})+$/i));const vC=il(Zn(),q1(),ap(0),ip(255)),Ea=il(Zn(),q1(),ap(0),ip(4294967295)),Z1=il(v8(),ap(0n),ip(0x7fffffffffffffffn)),$8=e=>Cr(Object.entries(e).reduce((t,r)=>({...t,[r[0]]:E8(r[1])}),{})),T8=new Uint8Array(1);function I8(e){let t=0;for(;e[t]===0;)++t;return t===e.length?T8:(e=e.slice(t),e[0]&128?ir([T8,e]):e)}function O8(e){e[0]===0&&(e=e.slice(1));const t=new Uint8Array(32),r=Math.max(0,32-e.length);return t.set(e,r),t}function EC(e){const t=va(e,e.length-1);if(!Y1(t))throw new Error("Invalid hashType "+t);const r=QB(e.subarray(0,-1)),n=O8(r.r),o=O8(r.s);return{signature:ir([n,o]),hashType:t}}function kC(e,t){if(ar(Cr({signature:Rr(64),hashType:vC}),{signature:e,hashType:t}),!Y1(t))throw new Error("Invalid hashType "+t);const r=new Uint8Array(1);ho(r,0,t);const n=I8(e.slice(0,32)),o=I8(e.slice(32,64));return ir([eC(n,o),r])}const xC=Object.freeze(Object.defineProperty({__proto__:null,decode:EC,encode:kC},Symbol.toStringTag,{value:"Module"})),P8=Lt.OP_RESERVED,B8=Wn(G1([cp(Uint8Array),Zn()]));function AC(e){return sp(Zn(),e)&&(e===Lt.OP_0||e>=Lt.OP_1&&e<=Lt.OP_16||e===Lt.OP_1NEGATE)}function C8(e){return sp(Ht,e)||AC(e)}function X1(e){return sp(il(w8(),m8(C8)),e)}function U8(e){return e.length-e.filter(C8).length}function fp(e){if(e.length===0)return Lt.OP_0;if(e.length===1){if(e[0]>=1&&e[0]<=16)return P8+e[0];if(e[0]===129)return Lt.OP_1NEGATE}}function N8(e){return e instanceof Uint8Array}function SC(e){return sp(B8,e)}function dp(e){return e instanceof Uint8Array}function Xn(e){if(N8(e))return e;ar(B8,e);const t=e.reduce((o,i)=>dp(i)?i.length===1&&fp(i)!==void 0?o+1:o+g8(i.length)+i.length:o+1,0),r=new Uint8Array(t);let n=0;if(e.forEach(o=>{if(dp(o)){const i=fp(o);if(i!==void 0){ho(r,n,i),n+=1;return}n+=lC(r,o.length,n),r.set(o,n),n+=o.length}else ho(r,n,o),n+=1}),n!==r.length)throw new Error("Could not decode chunks");return r}function sr(e){if(SC(e))return e;ar(Ht,e);const t=[];let r=0;for(;r<e.length;){const n=e[r];if(n>Lt.OP_0&&n<=Lt.OP_PUSHDATA4){const o=fC(e,r);if(o===null||(r+=o.size,r+o.number>e.length))return null;const i=e.slice(r,r+o.number);r+=o.number;const a=fp(i);a!==void 0?t.push(a):t.push(i)}else t.push(n),r+=1}return t}function _C(e){if(N8(e)&&(e=sr(e)),!e)throw new Error("Could not convert invalid chunks to ASM");return e.map(t=>{if(dp(t)){const r=fp(t);if(r===void 0)return Me(t);t=r}return c8[t]}).join(" ")}function $C(e){return e=sr(e),ar(Jo(X1),e),e.map(t=>dp(t)?t:t===Lt.OP_0?new Uint8Array(0):hC(t-P8))}function TC(e){return Qo(e)}function Y1(e){const t=e&-129;return t>0&&t<4}function ka(e){return!(e instanceof Uint8Array)||!Y1(e[e.length-1])?!1:JB(e.slice(0,-1))}const Hf=xC;function Re(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){const n=r.call(this);return this[t]=n,n},set(n){Object.defineProperty(this,t,{configurable:!0,enumerable:!0,value:n,writable:!0})}})}function $o(e){let t;return()=>(t!==void 0||(t=e()),t)}const al=Lt,hp=al.OP_RESERVED;function pp(e,t){if(!e.input&&!e.output&&!(e.pubkeys&&e.m!==void 0)&&!e.signatures)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{});function r(s){return ka(s)||(t.allowIncomplete&&s===al.OP_0)!==void 0}ar(gs(Cr({network:Cr({}),m:Zn(),n:Zn(),output:Ht,pubkeys:Wn(Jo(Qo),"Received invalid pubkey"),signatures:Wn(Jo(r),"Expected signature to be of type isAcceptableSignature"),input:Ht})),e);const n={network:e.network||Yo};let o=[],i=!1;function a(s){i||(i=!0,o=sr(s),n.m=o[0]-hp,n.n=o[o.length-2]-hp,n.pubkeys=o.slice(1,-2))}if(Re(n,"output",()=>{if(e.m&&n.n&&e.pubkeys)return Xn([].concat(hp+e.m,e.pubkeys,hp+n.n,al.OP_CHECKMULTISIG))}),Re(n,"m",()=>{if(n.output)return a(n.output),n.m}),Re(n,"n",()=>{if(n.pubkeys)return n.pubkeys.length}),Re(n,"pubkeys",()=>{if(e.output)return a(e.output),n.pubkeys}),Re(n,"signatures",()=>{if(e.input)return sr(e.input).slice(1)}),Re(n,"input",()=>{if(e.signatures)return Xn([al.OP_0].concat(e.signatures))}),Re(n,"witness",()=>{if(n.input)return[]}),Re(n,"name",()=>{if(!(!n.m||!n.n))return`p2ms(${n.m} of ${n.n})`}),t.validate){if(e.output){if(a(e.output),ar(Zn(),o[0],{message:"Output is invalid"}),ar(Zn(),o[o.length-2],{message:"Output is invalid"}),o[o.length-1]!==al.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(n.m<=0||n.n>16||n.m>n.n||n.n!==o.length-3)throw new TypeError("Output is invalid");if(!n.pubkeys.every(s=>Qo(s)))throw new TypeError("Output is invalid");if(e.m!==void 0&&e.m!==n.m)throw new TypeError("m mismatch");if(e.n!==void 0&&e.n!==n.n)throw new TypeError("n mismatch");if(e.pubkeys&&!Lf(e.pubkeys,n.pubkeys))throw new TypeError("Pubkeys mismatch")}if(e.pubkeys){if(e.n!==void 0&&e.n!==e.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(n.n=e.pubkeys.length,n.n<n.m)throw new TypeError("Pubkey count cannot be less than m")}if(e.signatures){if(e.signatures.length<n.m)throw new TypeError("Not enough signatures provided");if(e.signatures.length>n.m)throw new TypeError("Too many signatures provided")}if(e.input){if(e.input[0]!==al.OP_0)throw new TypeError("Input is invalid");if(n.signatures.length===0||!n.signatures.every(r))throw new TypeError("Input has invalid signature(s)");if(e.signatures&&!Lf(e.signatures,n.signatures))throw new TypeError("Signature mismatch");if(e.m!==void 0&&e.m!==e.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(n,e)}const j8=Lt;function z8(e,t){if(!e.input&&!e.output&&!e.pubkey&&!e.input&&!e.signature)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ar(gs(Cr({network:Cr({}),output:Ht,pubkey:Jo(Qo,"invalid pubkey"),signature:Jo(ka,"Expected signature to be of type isCanonicalScriptSignature"),input:Ht})),e);const r=$o(()=>sr(e.input)),n={name:"p2pk",network:e.network||Yo};if(Re(n,"output",()=>{if(e.pubkey)return Xn([e.pubkey,j8.OP_CHECKSIG])}),Re(n,"pubkey",()=>{if(e.output)return e.output.slice(1,-1)}),Re(n,"signature",()=>{if(e.input)return r()[0]}),Re(n,"input",()=>{if(e.signature)return Xn([e.signature])}),Re(n,"witness",()=>{if(n.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==j8.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!Qo(n.pubkey))throw new TypeError("Output pubkey is invalid");if(e.pubkey&&me(e.pubkey,n.pubkey)!==0)throw new TypeError("Pubkey mismatch")}if(e.signature&&e.input&&me(e.input,n.input)!==0)throw new TypeError("Signature mismatch");if(e.input){if(r().length!==1)throw new TypeError("Input is invalid");if(!ka(n.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(n,e)}function R8(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function IC(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function gp(e,...t){if(!IC(e))throw new Error("Uint8Array expected");if(t.length>0&&!t.includes(e.length))throw new Error(`Uint8Array expected of length ${t}, not of length=${e.length}`)}function OC(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");R8(e.outputLen),R8(e.blockLen)}function mp(e,t=!0){if(e.destroyed)throw new Error("Hash instance has been destroyed");if(t&&e.finished)throw new Error("Hash#digest() has already been called")}function PC(e,t){gp(e);const r=t.outputLen;if(e.length<r)throw new Error(`digestInto() expects output buffer of length at least ${r}`)}const sl=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;/*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */const J1=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Ni=(e,t)=>e<<32-t|e>>>t,yp=(e,t)=>e<<t|e>>>32-t>>>0;new Uint8Array(new Uint32Array([287454020]).buffer)[0];function BC(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function Q1(e){return typeof e=="string"&&(e=BC(e)),gp(e),e}function CC(...e){let t=0;for(let n=0;n<e.length;n++){const o=e[n];gp(o),t+=o.length}const r=new Uint8Array(t);for(let n=0,o=0;n<e.length;n++){const i=e[n];r.set(i,o),o+=i.length}return r}let L8=class{clone(){return this._cloneInto()}};function ey(e){const t=n=>e().update(Q1(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function UC(e=32){if(sl&&typeof sl.getRandomValues=="function")return sl.getRandomValues(new Uint8Array(e));if(sl&&typeof sl.randomBytes=="function")return sl.randomBytes(e);throw new Error("crypto.getRandomValues must be defined")}function NC(e,t,r,n){if(typeof e.setBigUint64=="function")return e.setBigUint64(t,r,n);const o=BigInt(32),i=BigInt(4294967295),a=Number(r>>o&i),s=Number(r&i),c=n?4:0,u=n?0:4;e.setUint32(t+c,a,n),e.setUint32(t+u,s,n)}const jC=(e,t,r)=>e&t^~e&r,zC=(e,t,r)=>e&t^e&r^t&r;let ty=class extends L8{constructor(t,r,n,o){super(),this.blockLen=t,this.outputLen=r,this.padOffset=n,this.isLE=o,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(t),this.view=J1(this.buffer)}update(t){mp(this);const{view:r,buffer:n,blockLen:o}=this;t=Q1(t);const i=t.length;for(let a=0;a<i;){const s=Math.min(o-this.pos,i-a);if(s===o){const c=J1(t);for(;o<=i-a;a+=o)this.process(c,a);continue}n.set(t.subarray(a,a+s),this.pos),this.pos+=s,a+=s,this.pos===o&&(this.process(r,0),this.pos=0)}return this.length+=t.length,this.roundClean(),this}digestInto(t){mp(this),PC(t,this),this.finished=!0;const{buffer:r,view:n,blockLen:o,isLE:i}=this;let{pos:a}=this;r[a++]=128,this.buffer.subarray(a).fill(0),this.padOffset>o-a&&(this.process(n,0),a=0);for(let f=a;f<o;f++)r[f]=0;NC(n,o-8,BigInt(this.length*8),i),this.process(n,0);const s=J1(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const u=c/4,l=this.get();if(u>l.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<u;f++)s.setUint32(4*f,l[f],i)}digest(){const{buffer:t,outputLen:r}=this;this.digestInto(t);const n=t.slice(0,r);return this.destroy(),n}_cloneInto(t){t||(t=new this.constructor),t.set(...this.get());const{blockLen:r,buffer:n,length:o,finished:i,destroyed:a,pos:s}=this;return t.length=o,t.pos=s,t.finished=i,t.destroyed=a,o%r&&t.buffer.set(n),t}};const RC=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),H8=new Uint8Array(new Array(16).fill(0).map((e,t)=>t)),LC=H8.map(e=>(9*e+5)%16);let ry=[H8],ny=[LC];for(let e=0;e<4;e++)for(let t of[ry,ny])t.push(t[e].map(r=>RC[r]));const F8=[[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(e=>new Uint8Array(e)),HC=ry.map((e,t)=>e.map(r=>F8[t][r])),FC=ny.map((e,t)=>e.map(r=>F8[t][r])),DC=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),KC=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function D8(e,t,r,n){return e===0?t^r^n:e===1?t&r|~t&n:e===2?(t|~r)^n:e===3?t&n|r&~n:t^(r|~n)}const bp=new Uint32Array(16);let qC=class extends ty{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:r,h2:n,h3:o,h4:i}=this;return[t,r,n,o,i]}set(t,r,n,o,i){this.h0=t|0,this.h1=r|0,this.h2=n|0,this.h3=o|0,this.h4=i|0}process(t,r){for(let g=0;g<16;g++,r+=4)bp[g]=t.getUint32(r,!0);let n=this.h0|0,o=n,i=this.h1|0,a=i,s=this.h2|0,c=s,u=this.h3|0,l=u,f=this.h4|0,h=f;for(let g=0;g<5;g++){const y=4-g,m=DC[g],w=KC[g],v=ry[g],x=ny[g],E=HC[g],$=FC[g];for(let P=0;P<16;P++){const T=yp(n+D8(g,i,s,u)+bp[v[P]]+m,E[P])+f|0;n=f,f=u,u=yp(s,10)|0,s=i,i=T}for(let P=0;P<16;P++){const T=yp(o+D8(y,a,c,l)+bp[x[P]]+w,$[P])+h|0;o=h,h=l,l=yp(c,10)|0,c=a,a=T}}this.set(this.h1+s+l|0,this.h2+u+h|0,this.h3+f+o|0,this.h4+n+a|0,this.h0+i+c|0)}roundClean(){bp.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}};const K8=ey(()=>new qC),MC=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]),ms=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),ys=new Uint32Array(64);let VC=class extends ty{constructor(){super(64,32,8,!1),this.A=ms[0]|0,this.B=ms[1]|0,this.C=ms[2]|0,this.D=ms[3]|0,this.E=ms[4]|0,this.F=ms[5]|0,this.G=ms[6]|0,this.H=ms[7]|0}get(){const{A:t,B:r,C:n,D:o,E:i,F:a,G:s,H:c}=this;return[t,r,n,o,i,a,s,c]}set(t,r,n,o,i,a,s,c){this.A=t|0,this.B=r|0,this.C=n|0,this.D=o|0,this.E=i|0,this.F=a|0,this.G=s|0,this.H=c|0}process(t,r){for(let f=0;f<16;f++,r+=4)ys[f]=t.getUint32(r,!1);for(let f=16;f<64;f++){const h=ys[f-15],g=ys[f-2],y=Ni(h,7)^Ni(h,18)^h>>>3,m=Ni(g,17)^Ni(g,19)^g>>>10;ys[f]=m+ys[f-7]+y+ys[f-16]|0}let{A:n,B:o,C:i,D:a,E:s,F:c,G:u,H:l}=this;for(let f=0;f<64;f++){const h=Ni(s,6)^Ni(s,11)^Ni(s,25),g=l+h+jC(s,c,u)+MC[f]+ys[f]|0,y=(Ni(n,2)^Ni(n,13)^Ni(n,22))+zC(n,o,i)|0;l=u,u=c,c=s,s=a+g|0,a=i,i=o,o=n,n=g+y|0}n=n+this.A|0,o=o+this.B|0,i=i+this.C|0,a=a+this.D|0,s=s+this.E|0,c=c+this.F|0,u=u+this.G|0,l=l+this.H|0,this.set(n,o,i,a,s,c,u,l)}roundClean(){ys.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const en=ey(()=>new VC);function xa(e){return K8(en(e))}function Vc(e){return en(en(e))}const GC={"BIP0340/challenge":Uint8Array.from([123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124,123,181,45,122,159,239,88,50,62,177,191,122,64,125,179,130,210,243,242,216,27,177,34,79,73,254,81,143,109,72,211,124]),"BIP0340/aux":Uint8Array.from([241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144,241,239,78,94,192,99,202,218,109,148,202,250,157,152,126,160,105,38,88,57,236,193,31,151,45,119,165,46,216,193,204,144]),"BIP0340/nonce":Uint8Array.from([7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47,7,73,119,52,167,155,203,53,91,155,140,125,3,79,18,28,244,52,215,62,247,45,218,25,135,0,97,251,82,191,235,47]),TapLeaf:Uint8Array.from([174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238,174,234,143,220,66,8,152,49,5,115,75,88,8,29,30,38,56,211,95,28,181,64,8,212,211,87,202,3,190,120,233,238]),TapBranch:Uint8Array.from([25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21,25,65,161,242,229,110,185,95,162,169,241,148,190,92,1,247,33,111,51,237,130,176,145,70,52,144,208,91,245,22,160,21]),TapSighash:Uint8Array.from([244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49,244,10,72,223,75,42,112,200,180,146,75,242,101,70,97,237,61,149,253,102,163,19,235,135,35,117,151,198,40,228,160,49]),TapTweak:Uint8Array.from([232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233,232,15,225,99,156,156,160,80,227,175,27,57,193,67,198,62,66,156,188,235,21,217,64,251,181,197,161,244,175,87,197,233]),"KeyAgg list":Uint8Array.from([72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240,72,28,151,28,60,11,70,215,240,178,117,174,89,141,78,44,126,215,49,156,89,74,92,110,199,158,160,212,153,2,148,240]),"KeyAgg coefficient":Uint8Array.from([191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129,191,201,4,3,77,28,136,232,200,14,34,229,61,36,86,109,100,130,78,214,66,114,129,192,145,0,249,77,205,82,201,129])};function wp(e,t){return en(ir([GC[e],t]))}function WC(e){if(e.length>=255)throw new TypeError("Alphabet too long");const t=new Uint8Array(256);for(let u=0;u<t.length;u++)t[u]=255;for(let u=0;u<e.length;u++){const l=e.charAt(u),f=l.charCodeAt(0);if(t[f]!==255)throw new TypeError(l+" is ambiguous");t[f]=u}const r=e.length,n=e.charAt(0),o=Math.log(r)/Math.log(256),i=Math.log(256)/Math.log(r);function a(u){if(u instanceof Uint8Array||(ArrayBuffer.isView(u)?u=new Uint8Array(u.buffer,u.byteOffset,u.byteLength):Array.isArray(u)&&(u=Uint8Array.from(u))),!(u instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(u.length===0)return"";let l=0,f=0,h=0;const g=u.length;for(;h!==g&&u[h]===0;)h++,l++;const y=(g-h)*i+1>>>0,m=new Uint8Array(y);for(;h!==g;){let x=u[h],E=0;for(let $=y-1;(x!==0||E<f)&&$!==-1;$--,E++)x+=256*m[$]>>>0,m[$]=x%r>>>0,x=x/r>>>0;if(x!==0)throw new Error("Non-zero carry");f=E,h++}let w=y-f;for(;w!==y&&m[w]===0;)w++;let v=n.repeat(l);for(;w<y;++w)v+=e.charAt(m[w]);return v}function s(u){if(typeof u!="string")throw new TypeError("Expected String");if(u.length===0)return new Uint8Array;let l=0,f=0,h=0;for(;u[l]===n;)f++,l++;const g=(u.length-l)*o+1>>>0,y=new Uint8Array(g);for(;u[l];){let x=t[u.charCodeAt(l)];if(x===255)return;let E=0;for(let $=g-1;(x!==0||E<h)&&$!==-1;$--,E++)x+=r*y[$]>>>0,y[$]=x%256>>>0,x=x/256>>>0;if(x!==0)throw new Error("Non-zero carry");h=E,l++}let m=g-h;for(;m!==g&&y[m]===0;)m++;const w=new Uint8Array(f+(g-m));let v=f;for(;m!==g;)w[v++]=y[m++];return w}function c(u){const l=s(u);if(l)return l;throw new Error("Non-base"+r+" character")}return{encode:a,decodeUnsafe:s,decode:c}}var ZC="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";const oy=WC(ZC);function XC(e){function t(i){var a=Uint8Array.from(i),s=e(a),c=a.length+4,u=new Uint8Array(c);return u.set(a,0),u.set(s.subarray(0,4),a.length),oy.encode(u)}function r(i){var a=i.slice(0,-4),s=i.slice(-4),c=e(a);if(!(s[0]^c[0]|s[1]^c[1]|s[2]^c[2]|s[3]^c[3]))return a}function n(i){var a=oy.decodeUnsafe(i);if(a!=null)return r(a)}function o(i){var a=oy.decode(i),s=r(a);if(s==null)throw new Error("Invalid checksum");return s}return{encode:t,decode:o,decodeUnsafe:n}}function YC(e){return en(en(e))}const cl=XC(YC),bs=Lt;function Ff(e,t){if(!e.address&&!e.hash&&!e.output&&!e.pubkey&&!e.input)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ar(gs(Cr({network:Cr({}),address:Mc(),hash:wC,output:Rr(25),pubkey:Jo(Qo),signature:Jo(ka),input:Ht})),e);const r=$o(()=>{const a=cl.decode(e.address),s=va(a,0),c=a.slice(1);return{version:s,hash:c}}),n=$o(()=>sr(e.input)),o=e.network||Yo,i={name:"p2pkh",network:o};if(Re(i,"address",()=>{if(!i.hash)return;const a=new Uint8Array(21);return ho(a,0,o.pubKeyHash),a.set(i.hash,1),cl.encode(a)}),Re(i,"hash",()=>{if(e.output)return e.output.slice(3,23);if(e.address)return r().hash;if(e.pubkey||i.pubkey)return xa(e.pubkey||i.pubkey)}),Re(i,"output",()=>{if(i.hash)return Xn([bs.OP_DUP,bs.OP_HASH160,i.hash,bs.OP_EQUALVERIFY,bs.OP_CHECKSIG])}),Re(i,"pubkey",()=>{if(e.input)return n()[1]}),Re(i,"signature",()=>{if(e.input)return n()[0]}),Re(i,"input",()=>{if(e.pubkey&&e.signature)return Xn([e.signature,e.pubkey])}),Re(i,"witness",()=>{if(i.input)return[]}),t.validate){let a=Uint8Array.from([]);if(e.address){if(r().version!==o.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(r().hash.length!==20)throw new TypeError("Invalid address");a=r().hash}if(e.hash){if(a.length>0&&me(a,e.hash)!==0)throw new TypeError("Hash mismatch");a=e.hash}if(e.output){if(e.output.length!==25||e.output[0]!==bs.OP_DUP||e.output[1]!==bs.OP_HASH160||e.output[2]!==20||e.output[23]!==bs.OP_EQUALVERIFY||e.output[24]!==bs.OP_CHECKSIG)throw new TypeError("Output is invalid");const s=e.output.slice(3,23);if(a.length>0&&me(a,s)!==0)throw new TypeError("Hash mismatch");a=s}if(e.pubkey){const s=xa(e.pubkey);if(a.length>0&&me(a,s)!==0)throw new TypeError("Hash mismatch");a=s}if(e.input){const s=n();if(s.length!==2)throw new TypeError("Input is invalid");if(!ka(s[0]))throw new TypeError("Input has invalid signature");if(!Qo(s[1]))throw new TypeError("Input has invalid pubkey");if(e.signature&&me(e.signature,s[0])!==0)throw new TypeError("Signature mismatch");if(e.pubkey&&me(e.pubkey,s[1])!==0)throw new TypeError("Pubkey mismatch");const c=xa(s[1]);if(a.length>0&&me(a,c)!==0)throw new TypeError("Hash mismatch")}}return Object.assign(i,e)}const Df=Lt;function ul(e,t){if(!e.address&&!e.hash&&!e.output&&!e.redeem&&!e.input)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ar(gs(Cr({network:Cr({}),address:Mc(),hash:Rr(20),output:Rr(23),redeem:gs(Cr({network:Cr({}),output:Ht,input:Ht,witness:Wn(Ht)})),input:Ht,witness:Wn(Ht)})),e);let r=e.network;r||(r=e.redeem&&e.redeem.network||Yo);const n={network:r},o=$o(()=>{const s=cl.decode(e.address),c=va(s,0),u=s.slice(1);return{version:c,hash:u}}),i=$o(()=>sr(e.input)),a=$o(()=>{const s=i(),c=s[s.length-1];return{network:r,output:c===Df.OP_FALSE?Uint8Array.from([]):c,input:Xn(s.slice(0,-1)),witness:e.witness||[]}});if(Re(n,"address",()=>{if(!n.hash)return;const s=new Uint8Array(21);return ho(s,0,n.network.scriptHash),s.set(n.hash,1),cl.encode(s)}),Re(n,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return o().hash;if(n.redeem&&n.redeem.output)return xa(n.redeem.output)}),Re(n,"output",()=>{if(n.hash)return Xn([Df.OP_HASH160,n.hash,Df.OP_EQUAL])}),Re(n,"redeem",()=>{if(e.input)return a()}),Re(n,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return Xn([].concat(sr(e.redeem.input),e.redeem.output))}),Re(n,"witness",()=>{if(n.redeem&&n.redeem.witness)return n.redeem.witness;if(n.input)return[]}),Re(n,"name",()=>{const s=["p2sh"];return n.redeem!==void 0&&n.redeem.name!==void 0&&s.push(n.redeem.name),s.join("-")}),t.validate){let s=Uint8Array.from([]);if(e.address){if(o().version!==r.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(o().hash.length!==20)throw new TypeError("Invalid address");s=o().hash}if(e.hash){if(s.length>0&&me(s,e.hash)!==0)throw new TypeError("Hash mismatch");s=e.hash}if(e.output){if(e.output.length!==23||e.output[0]!==Df.OP_HASH160||e.output[1]!==20||e.output[22]!==Df.OP_EQUAL)throw new TypeError("Output is invalid");const u=e.output.slice(2,22);if(s.length>0&&me(s,u)!==0)throw new TypeError("Hash mismatch");s=u}const c=u=>{if(u.output){const l=sr(u.output);if(!l||l.length<1)throw new TypeError("Redeem.output too short");if(u.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(U8(l)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const f=xa(u.output);if(s.length>0&&me(s,f)!==0)throw new TypeError("Hash mismatch");s=f}if(u.input){const l=u.input.length>0,f=u.witness&&u.witness.length>0;if(!l&&!f)throw new TypeError("Empty input");if(l&&f)throw new TypeError("Input and witness provided");if(l){const h=sr(u.input);if(!X1(h))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const u=i();if(!u||u.length<1)throw new TypeError("Input too short");if(!(a().output instanceof Uint8Array))throw new TypeError("Input is invalid");c(a())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==r)throw new TypeError("Network mismatch");if(e.input){const u=a();if(e.redeem.output&&me(e.redeem.output,u.output)!==0)throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&me(e.redeem.input,u.input)!==0)throw new TypeError("Redeem.input mismatch")}c(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!Lf(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(n,e)}var rt=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function JC(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function QC(e){if(e.__esModule)return e;var t=e.default;if(typeof t=="function"){var r=function n(){return this instanceof n?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};r.prototype=t.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(e).forEach(function(n){var o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(r,n,o.get?o:{enumerable:!0,get:function(){return e[n]}})}),r}var Kf={};Object.defineProperty(Kf,"__esModule",{value:!0});var qf=Kf.bech32m=po=Kf.bech32=void 0;const vp="qpzry9x8gf2tvdw0s3jn54khce6mua7l",q8={};for(let e=0;e<vp.length;e++){const t=vp.charAt(e);q8[t]=e}function ll(e){const t=e>>25;return(e&33554431)<<5^-(t>>0&1)&996825010^-(t>>1&1)&642813549^-(t>>2&1)&513874426^-(t>>3&1)&1027748829^-(t>>4&1)&705979059}function M8(e){let t=1;for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);if(n<33||n>126)return"Invalid prefix ("+e+")";t=ll(t)^n>>5}t=ll(t);for(let r=0;r<e.length;++r){const n=e.charCodeAt(r);t=ll(t)^n&31}return t}function iy(e,t,r,n){let o=0,i=0;const a=(1<<r)-1,s=[];for(let c=0;c<e.length;++c)for(o=o<<t|e[c],i+=t;i>=r;)i-=r,s.push(o>>i&a);if(n)i>0&&s.push(o<<r-i&a);else{if(i>=t)return"Excess padding";if(o<<r-i&a)return"Non-zero padding"}return s}function eU(e){return iy(e,8,5,!0)}function tU(e){const t=iy(e,5,8,!1);if(Array.isArray(t))return t}function rU(e){const t=iy(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function V8(e){let t;e==="bech32"?t=1:t=734539939;function r(a,s,c){if(c=c||90,a.length+7+s.length>c)throw new TypeError("Exceeds length limit");a=a.toLowerCase();let u=M8(a);if(typeof u=="string")throw new Error(u);let l=a+"1";for(let f=0;f<s.length;++f){const h=s[f];if(h>>5)throw new Error("Non 5-bit word");u=ll(u)^h,l+=vp.charAt(h)}for(let f=0;f<6;++f)u=ll(u);u^=t;for(let f=0;f<6;++f){const h=u>>(5-f)*5&31;l+=vp.charAt(h)}return l}function n(a,s){if(s=s||90,a.length<8)return a+" too short";if(a.length>s)return"Exceeds length limit";const c=a.toLowerCase(),u=a.toUpperCase();if(a!==c&&a!==u)return"Mixed-case string "+a;a=c;const l=a.lastIndexOf("1");if(l===-1)return"No separator character for "+a;if(l===0)return"Missing prefix for "+a;const f=a.slice(0,l),h=a.slice(l+1);if(h.length<6)return"Data too short";let g=M8(f);if(typeof g=="string")return g;const y=[];for(let m=0;m<h.length;++m){const w=h.charAt(m),v=q8[w];if(v===void 0)return"Unknown character "+w;g=ll(g)^v,!(m+6>=h.length)&&y.push(v)}return g!==t?"Invalid checksum for "+a:{prefix:f,words:y}}function o(a,s){const c=n(a,s);if(typeof c=="object")return c}function i(a,s){const c=n(a,s);if(typeof c=="object")return c;throw new Error(c)}return{decodeUnsafe:o,decode:i,encode:r,toWords:eU,fromWordsUnsafe:tU,fromWords:rU}}var po=Kf.bech32=V8("bech32");qf=Kf.bech32m=V8("bech32m");const G8=Lt,nU=new Uint8Array(0);function Mf(e,t){if(!e.address&&!e.hash&&!e.output&&!e.pubkey&&!e.witness)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ar(gs(Cr({address:Mc(),hash:Rr(20),input:Rr(0),network:Cr({}),output:Rr(22),pubkey:Jo(Qo,"Not a valid pubkey"),signature:Jo(ka),witness:Wn(Ht)})),e);const r=$o(()=>{const i=po.decode(e.address),a=i.words.shift(),s=po.fromWords(i.words);return{version:a,prefix:i.prefix,data:Uint8Array.from(s)}}),n=e.network||Yo,o={name:"p2wpkh",network:n};if(Re(o,"address",()=>{if(!o.hash)return;const i=po.toWords(o.hash);return i.unshift(0),po.encode(n.bech32,i)}),Re(o,"hash",()=>{if(e.output)return e.output.slice(2,22);if(e.address)return r().data;if(e.pubkey||o.pubkey)return xa(e.pubkey||o.pubkey)}),Re(o,"output",()=>{if(o.hash)return Xn([G8.OP_0,o.hash])}),Re(o,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.witness)return e.witness[1]}),Re(o,"signature",()=>{if(e.witness)return e.witness[0]}),Re(o,"input",()=>{if(o.witness)return nU}),Re(o,"witness",()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]}),t.validate){let i=Uint8Array.from([]);if(e.address){if(n&&n.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==0)throw new TypeError("Invalid address version");if(r().data.length!==20)throw new TypeError("Invalid address data");i=r().data}if(e.hash){if(i.length>0&&me(i,e.hash)!==0)throw new TypeError("Hash mismatch");i=e.hash}if(e.output){if(e.output.length!==22||e.output[0]!==G8.OP_0||e.output[1]!==20)throw new TypeError("Output is invalid");if(i.length>0&&me(i,e.output.slice(2))!==0)throw new TypeError("Hash mismatch");i=e.output.slice(2)}if(e.pubkey){const a=xa(e.pubkey);if(i.length>0&&me(i,a)!==0)throw new TypeError("Hash mismatch");if(i=a,!Qo(e.pubkey)||e.pubkey.length!==33)throw new TypeError("Invalid pubkey for p2wpkh")}if(e.witness){if(e.witness.length!==2)throw new TypeError("Witness is invalid");if(!ka(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!Qo(e.witness[1])||e.witness[1].length!==33)throw new TypeError("Witness has invalid pubkey");if(e.signature&&me(e.signature,e.witness[0])!==0)throw new TypeError("Signature mismatch");if(e.pubkey&&me(e.pubkey,e.witness[1])!==0)throw new TypeError("Pubkey mismatch");const a=xa(e.witness[1]);if(i.length>0&&me(i,a)!==0)throw new TypeError("Hash mismatch")}}return Object.assign(o,e)}const W8=Lt,ay=new Uint8Array(0);function Ep(e){return!!(e instanceof Uint8Array&&e.length===65&&e[0]===4&&Qo(e))}function Vf(e,t){if(!e.address&&!e.hash&&!e.output&&!e.redeem&&!e.witness)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ar($8({network:Cr({}),address:Mc(),hash:bC,output:Rr(34),redeem:$8({input:Ht,network:Cr({}),output:Ht,witness:Wn(Ht)}),input:Rr(0),witness:Wn(Ht)}),e);const r=$o(()=>{const a=po.decode(e.address),s=a.words.shift(),c=po.fromWords(a.words);return{version:s,prefix:a.prefix,data:Uint8Array.from(c)}}),n=$o(()=>sr(e.redeem.input));let o=e.network;o||(o=e.redeem&&e.redeem.network||Yo);const i={network:o};if(Re(i,"address",()=>{if(!i.hash)return;const a=po.toWords(i.hash);return a.unshift(0),po.encode(o.bech32,a)}),Re(i,"hash",()=>{if(e.output)return e.output.slice(2);if(e.address)return r().data;if(i.redeem&&i.redeem.output)return en(i.redeem.output)}),Re(i,"output",()=>{if(i.hash)return Xn([W8.OP_0,i.hash])}),Re(i,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:ay,witness:e.witness.slice(0,-1)}}),Re(i,"input",()=>{if(i.witness)return ay}),Re(i,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const a=$C(n());return i.redeem=Object.assign({witness:a},e.redeem),i.redeem.input=ay,[].concat(a,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),Re(i,"name",()=>{const a=["p2wsh"];return i.redeem!==void 0&&i.redeem.name!==void 0&&a.push(i.redeem.name),a.join("-")}),t.validate){let a=Uint8Array.from([]);if(e.address){if(r().prefix!==o.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==0)throw new TypeError("Invalid address version");if(r().data.length!==32)throw new TypeError("Invalid address data");a=r().data}if(e.hash){if(a.length>0&&me(a,e.hash)!==0)throw new TypeError("Hash mismatch");a=e.hash}if(e.output){if(e.output.length!==34||e.output[0]!==W8.OP_0||e.output[1]!==32)throw new TypeError("Output is invalid");const s=e.output.slice(2);if(a.length>0&&me(a,s)!==0)throw new TypeError("Hash mismatch");a=s}if(e.redeem){if(e.redeem.network&&e.redeem.network!==o)throw new TypeError("Network mismatch");if(e.redeem.input&&e.redeem.input.length>0&&e.redeem.witness&&e.redeem.witness.length>0)throw new TypeError("Ambiguous witness source");if(e.redeem.output){const s=sr(e.redeem.output);if(!s||s.length<1)throw new TypeError("Redeem.output is invalid");if(e.redeem.output.byteLength>3600)throw new TypeError("Redeem.output unspendable if larger than 3600 bytes");if(U8(s)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const c=en(e.redeem.output);if(a.length>0&&me(a,c)!==0)throw new TypeError("Hash mismatch");a=c}if(e.redeem.input&&!X1(n()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!Lf(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&n().some(Ep)||e.redeem.output&&(sr(e.redeem.output)||[]).some(Ep))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(e.witness&&e.witness.length>0){const s=e.witness[e.witness.length-1];if(e.redeem&&e.redeem.output&&me(e.redeem.output,s)!==0)throw new TypeError("Witness and redeem.output mismatch");if(e.witness.some(Ep)||(sr(s)||[]).some(Ep))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(i,e)}const Gf={};function Z8(e){e?e!==Gf.eccLib&&(oU(e),Gf.eccLib=e):Gf.eccLib=e}function sy(){if(!Gf.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return Gf.eccLib}const Aa=e=>wa(e);function oU(e){To(typeof e.isXOnlyPoint=="function"),To(e.isXOnlyPoint(Aa("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),To(e.isXOnlyPoint(Aa("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),To(e.isXOnlyPoint(Aa("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),To(e.isXOnlyPoint(Aa("0000000000000000000000000000000000000000000000000000000000000001"))),To(!e.isXOnlyPoint(Aa("0000000000000000000000000000000000000000000000000000000000000000"))),To(!e.isXOnlyPoint(Aa("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),To(typeof e.xOnlyPointAddTweak=="function"),iU.forEach(t=>{const r=e.xOnlyPointAddTweak(Aa(t.pubkey),Aa(t.tweak));t.result===null?To(r===null):(To(r!==null),To(r.parity===t.parity),To(me(r.xOnlyPubkey,Aa(t.result))===0))})}function To(e){if(!e)throw new Error("ecc library invalid")}const iU=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}],X8="0123456789abcdefABCDEF";X8.split("").map(e=>e.codePointAt(0));const Y8=Array(256).fill(!0).map((e,t)=>{const r=String.fromCodePoint(t),n=X8.indexOf(r);return n<0?void 0:n<16?n:n-6}),J8=new TextEncoder;new TextDecoder;function aU(e){return J8.encode(e)}function sU(e){const t=e.reduce((o,i)=>o+i.length,0),r=new Uint8Array(t);let n=0;for(const o of e)r.set(o,n),n+=o.length;return r}function cU(e){const t=J8.encode(e||""),r=new Uint8Array(Math.floor(t.length/2));let n;for(n=0;n<r.length;n++){const o=Y8[t[n*2]],i=Y8[t[n*2+1]];if(o===void 0||i===void 0)break;r[n]=o<<4|i}return n===r.length?r:r.slice(0,n)}function Sa(e,t){const r=Math.min(e.length,t.length);for(let n=0;n<r;++n)if(e[n]!==t[n])return e[n]<t[n]?-1:1;return e.length===t.length?0:e.length>t.length?1:-1}function Q8(e,t,r){if(t+1>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r>255)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 255. Received ${r}`);e[t]=r}function uU(e,t,r,n){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>65535)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= 65535. Received ${r}`);n==="LE"?(e[t]=r&255,e[t+1]=r>>8&255):(e[t]=r>>8&255,e[t+1]=r&255)}function Gc(e,t,r,n){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>4294967295)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= ${4294967295}. Received ${r}`);n==="LE"?(e[t]=r&255,e[t+1]=r>>8&255,e[t+2]=r>>16&255,e[t+3]=r>>24&255):(e[t]=r>>24&255,e[t+1]=r>>16&255,e[t+2]=r>>8&255,e[t+3]=r&255)}function lU(e,t,r,n){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(n=n.toUpperCase(),r>0xffffffffffffffffn)throw new Error(`The value of "value" is out of range. It must be >= 0 and <= ${0xffffffffffffffffn}. Received ${r}`);n==="LE"?(e[t]=Number(r&0xffn),e[t+1]=Number(r>>8n&0xffn),e[t+2]=Number(r>>16n&0xffn),e[t+3]=Number(r>>24n&0xffn),e[t+4]=Number(r>>32n&0xffn),e[t+5]=Number(r>>40n&0xffn),e[t+6]=Number(r>>48n&0xffn),e[t+7]=Number(r>>56n&0xffn)):(e[t]=Number(r>>56n&0xffn),e[t+1]=Number(r>>48n&0xffn),e[t+2]=Number(r>>40n&0xffn),e[t+3]=Number(r>>32n&0xffn),e[t+4]=Number(r>>24n&0xffn),e[t+5]=Number(r>>16n&0xffn),e[t+6]=Number(r>>8n&0xffn),e[t+7]=Number(r&0xffn))}function fU(e,t,r){if(t+2>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),r==="LE"){let n=0;return n=(n<<8)+e[t+1],n=(n<<8)+e[t],n}else{let n=0;return n=(n<<8)+e[t],n=(n<<8)+e[t+1],n}}function fl(e,t,r){if(t+4>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),r==="LE"){let n=0;return n=(n<<8)+e[t+3]>>>0,n=(n<<8)+e[t+2]>>>0,n=(n<<8)+e[t+1]>>>0,n=(n<<8)+e[t]>>>0,n}else{let n=0;return n=(n<<8)+e[t]>>>0,n=(n<<8)+e[t+1]>>>0,n=(n<<8)+e[t+2]>>>0,n=(n<<8)+e[t+3]>>>0,n}}function dU(e,t,r){if(t+8>e.length)throw new Error("Offset is outside the bounds of Uint8Array");if(r=r.toUpperCase(),r==="LE"){let n=0n;return n=(n<<8n)+BigInt(e[t+7]),n=(n<<8n)+BigInt(e[t+6]),n=(n<<8n)+BigInt(e[t+5]),n=(n<<8n)+BigInt(e[t+4]),n=(n<<8n)+BigInt(e[t+3]),n=(n<<8n)+BigInt(e[t+2]),n=(n<<8n)+BigInt(e[t+1]),n=(n<<8n)+BigInt(e[t]),n}else{let n=0n;return n=(n<<8n)+BigInt(e[t]),n=(n<<8n)+BigInt(e[t+1]),n=(n<<8n)+BigInt(e[t+2]),n=(n<<8n)+BigInt(e[t+3]),n=(n<<8n)+BigInt(e[t+4]),n=(n<<8n)+BigInt(e[t+5]),n=(n<<8n)+BigInt(e[t+6]),n=(n<<8n)+BigInt(e[t+7]),n}}const hU=e=>{if(e<0||e>0xffffffffffffffffn)throw new RangeError("value out of range")};function pU(e){if(e<0||e>Number.MAX_SAFE_INTEGER||e%1!==0)throw new RangeError("value out of range")}function eE(e){typeof e=="number"?pU(e):hU(e)}function ws(e,t,r){eE(e),r===void 0&&(r=0),t===void 0&&(t=new Uint8Array(Io(e)));let n=0;return e<253?(t.set([Number(e)],r),n=1):e<=65535?(t.set([253],r),uU(t,r+1,Number(e),"LE"),n=3):e<=4294967295?(t.set([254],r),Gc(t,r+1,Number(e),"LE"),n=5):(t.set([255],r),lU(t,r+1,BigInt(e),"LE"),n=9),{buffer:t,bytes:n}}function dl(e,t){t===void 0&&(t=0);const r=e.at(t);if(r===void 0)throw new Error("buffer too small");if(r<253)return{numberValue:r,bigintValue:BigInt(r),bytes:1};if(r===253){const n=fU(e,t+1,"LE");return{numberValue:n,bigintValue:BigInt(n),bytes:3}}else if(r===254){const n=fl(e,t+1,"LE");return{numberValue:n,bigintValue:BigInt(n),bytes:5}}else{const n=dU(e,t+1,"LE");return{numberValue:n<=Number.MAX_SAFE_INTEGER?Number(n):null,bigintValue:n,bytes:9}}}function Io(e){return eE(e),e<253?1:e<=65535?3:e<=4294967295?5:9}const gU=9007199254740991;function mU(e,t){if(typeof e!="number"&&typeof e!="bigint")throw new Error("cannot write a non-number as a number");if(e<0&&e<BigInt(0))throw new Error("specified a negative value for writing an unsigned value");if(e>t&&e>BigInt(t))throw new Error("RangeError: value out of range");if(Math.floor(Number(e))!==Number(e))throw new Error("value has a fractional component")}function cy(e){if(e.length<1)return e;let t=e.length-1,r=0;for(let n=0;n<e.length/2;n++)r=e[n],e[n]=e[t],e[t]=r,t--;return e}function tE(e){const t=new Uint8Array(e.length);return t.set(e),t}let Yn=class NB{constructor(t,r=0){Te(this,"buffer"),Te(this,"offset"),this.buffer=t,this.offset=r,ar(Ui([Ht,Ea]),[t,r])}static withCapacity(t){return new NB(new Uint8Array(t))}writeUInt8(t){this.offset=ho(this.buffer,this.offset,t)}writeInt32(t){this.offset=d8(this.buffer,this.offset,t,"LE")}writeInt64(t){this.offset=h8(this.buffer,this.offset,BigInt(t),"LE")}writeUInt32(t){this.offset=zf(this.buffer,this.offset,t,"LE")}writeUInt64(t){this.offset=sC(this.buffer,this.offset,BigInt(t),"LE")}writeVarInt(t){const{bytes:r}=ws(t,this.buffer,this.offset);this.offset+=r}writeSlice(t){if(this.buffer.length<this.offset+t.length)throw new Error("Cannot write slice out of bounds");this.buffer.set(t,this.offset),this.offset+=t.length}writeVarSlice(t){this.writeVarInt(t.length),this.writeSlice(t)}writeVector(t){this.writeVarInt(t.length),t.forEach(r=>this.writeVarSlice(r))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}},yU=class{constructor(t,r=0){Te(this,"buffer"),Te(this,"offset"),this.buffer=t,this.offset=r,ar(Ui([Ht,Ea]),[t,r])}readUInt8(){const t=va(this.buffer,this.offset);return this.offset++,t}readInt32(){const t=uC(this.buffer,this.offset,"LE");return this.offset+=4,t}readUInt32(){const t=ol(this.buffer,this.offset,"LE");return this.offset+=4,t}readInt64(){const t=p8(this.buffer,this.offset,"LE");return this.offset+=8,t}readVarInt(){const{bigintValue:t,bytes:r}=dl(this.buffer,this.offset);return this.offset+=r,t}readSlice(t){mU(t,gU);const r=Number(t);if(this.buffer.length<this.offset+r)throw new Error("Cannot read slice out of bounds");const n=this.buffer.slice(this.offset,this.offset+r);return this.offset+=r,n}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const t=this.readVarInt(),r=[];for(let n=0;n<t;n++)r.push(this.readVarSlice());return r}};const rE=192,bU=128,wU=e=>"left"in e&&"right"in e;function uy(e,t){if(e.length<33)throw new TypeError(`The control-block length is too small. Got ${e.length}, expected min 33.`);const r=(e.length-33)/32;let n=t;for(let o=0;o<r;o++){const i=e.slice(33+32*o,65+32*o);me(n,i)<0?n=fy(n,i):n=fy(i,n)}return n}function ly(e){if(W1(e))return{hash:_a(e)};const t=[ly(e[0]),ly(e[1])];t.sort((o,i)=>me(o.hash,i.hash));const[r,n]=t;return{hash:fy(r.hash,n.hash),left:r,right:n}}function kp(e,t){if(wU(e)){const r=kp(e.left,t);if(r!==void 0)return[...r,e.right.hash];const n=kp(e.right,t);if(n!==void 0)return[...n,e.left.hash]}else if(me(e.hash,t)===0)return[]}function _a(e){const t=e.version||rE;return wp("TapLeaf",ir([Uint8Array.from([t]),EU(e.output)]))}function vU(e,t){return wp("TapTweak",ir(t?[e,t]:[e]))}function xp(e,t){if(!(e instanceof Uint8Array)||e.length!==32||t&&t.length!==32)return null;const r=vU(e,t),n=sy().xOnlyPointAddTweak(e,r);return!n||n.xOnlyPubkey===null?null:{parity:n.parity,x:Uint8Array.from(n.xOnlyPubkey)}}function fy(e,t){return wp("TapBranch",ir([e,t]))}function EU(e){const t=Io(e.length),r=new Uint8Array(t);return ws(e.length,r),ir([r,e])}const nE=Lt,oE=1,kU=80;function Wf(e,t){if(!e.address&&!e.output&&!e.pubkey&&!e.internalPubkey&&!(e.witness&&e.witness.length>1))throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),ar(gs(Cr({address:Mc(),input:Rr(0),network:Cr({}),output:Rr(34),internalPubkey:Rr(32),hash:Rr(32),pubkey:Rr(32),signature:G1([Rr(64),Rr(65)]),witness:Wn(Ht),scriptTree:Jo(S8,"Taptree is not of type isTaptree"),redeem:gs(Cr({output:Ht,redeemVersion:Zn(),witness:Wn(Ht)})),redeemVersion:Zn()})),e);const r=$o(()=>dy(e.address)),n=$o(()=>{if(!(!e.witness||!e.witness.length))return e.witness.length>=2&&e.witness[e.witness.length-1][0]===kU?e.witness.slice(0,-1):e.witness.slice()}),o=$o(()=>{if(e.scriptTree)return ly(e.scriptTree);if(e.hash)return{hash:e.hash}}),i=e.network||Yo,a={name:"p2tr",network:i};if(Re(a,"address",()=>{if(!a.pubkey)return;const s=qf.toWords(a.pubkey);return s.unshift(oE),qf.encode(i.bech32,s)}),Re(a,"hash",()=>{const s=o();if(s)return s.hash;const c=n();if(c&&c.length>1){const u=c[c.length-1],l=u[0]&lp,f=c[c.length-2],h=_a({output:f,version:l});return uy(u,h)}return null}),Re(a,"output",()=>{if(a.pubkey)return Xn([nE.OP_1,a.pubkey])}),Re(a,"redeemVersion",()=>e.redeemVersion?e.redeemVersion:e.redeem&&e.redeem.redeemVersion!==void 0&&e.redeem.redeemVersion!==null?e.redeem.redeemVersion:rE),Re(a,"redeem",()=>{const s=n();if(!(!s||s.length<2))return{output:s[s.length-2],witness:s.slice(0,-2),redeemVersion:s[s.length-1][0]&lp}}),Re(a,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.output)return e.output.slice(2);if(e.address)return r().data;if(a.internalPubkey){const s=xp(a.internalPubkey,a.hash);if(s)return s.x}}),Re(a,"internalPubkey",()=>{if(e.internalPubkey)return e.internalPubkey;const s=n();if(s&&s.length>1)return s[s.length-1].slice(1,33)}),Re(a,"signature",()=>{if(e.signature)return e.signature;const s=n();if(!(!s||s.length!==1))return s[0]}),Re(a,"witness",()=>{if(e.witness)return e.witness;const s=o();if(s&&e.redeem&&e.redeem.output&&e.internalPubkey){const c=_a({output:e.redeem.output,version:a.redeemVersion}),u=kp(s,c);if(!u)return;const l=xp(e.internalPubkey,s.hash);if(!l)return;const f=ir([Uint8Array.from([a.redeemVersion|l.parity]),e.internalPubkey].concat(u));return[e.redeem.output,f]}if(e.signature)return[e.signature]}),t.validate){let s=Uint8Array.from([]);if(e.address){if(i&&i.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(r().version!==oE)throw new TypeError("Invalid address version");if(r().data.length!==32)throw new TypeError("Invalid address data");s=r().data}if(e.pubkey){if(s.length>0&&me(s,e.pubkey)!==0)throw new TypeError("Pubkey mismatch");s=e.pubkey}if(e.output){if(e.output.length!==34||e.output[0]!==nE.OP_1||e.output[1]!==32)throw new TypeError("Output is invalid");if(s.length>0&&me(s,e.output.slice(2))!==0)throw new TypeError("Pubkey mismatch");s=e.output.slice(2)}if(e.internalPubkey){const l=xp(e.internalPubkey,a.hash);if(s.length>0&&me(s,l.x)!==0)throw new TypeError("Pubkey mismatch");s=l.x}if(s&&s.length&&!sy().isXOnlyPoint(s))throw new TypeError("Invalid pubkey for p2tr");const c=o();if(e.hash&&c&&me(e.hash,c.hash)!==0)throw new TypeError("Hash mismatch");if(e.redeem&&e.redeem.output&&c){const l=_a({output:e.redeem.output,version:a.redeemVersion});if(!kp(c,l))throw new TypeError("Redeem script not in tree")}const u=n();if(e.redeem&&a.redeem){if(e.redeem.redeemVersion&&e.redeem.redeemVersion!==a.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(e.redeem.output){if(sr(e.redeem.output).length===0)throw new TypeError("Redeem.output is invalid");if(a.redeem.output&&me(e.redeem.output,a.redeem.output)!==0)throw new TypeError("Redeem.output and witness mismatch")}if(e.redeem.witness&&a.redeem.witness&&!Lf(e.redeem.witness,a.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(u&&u.length)if(u.length===1){if(e.signature&&me(e.signature,u[0])!==0)throw new TypeError("Signature mismatch")}else{const l=u[u.length-1];if(l.length<33)throw new TypeError(`The control-block length is too small. Got ${l.length}, expected min 33.`);if((l.length-33)%32!==0)throw new TypeError(`The control-block length of ${l.length} is incorrect!`);const f=(l.length-33)/32;if(f>128)throw new TypeError(`The script path is too long. Got ${f}, expected max 128.`);const h=l.slice(1,33);if(e.internalPubkey&&me(e.internalPubkey,h)!==0)throw new TypeError("Internal pubkey mismatch");if(!sy().isXOnlyPoint(h))throw new TypeError("Invalid internalPubkey for p2tr witness");const g=l[0]&lp,y=u[u.length-2],m=_a({output:y,version:g}),w=uy(l,m),v=xp(h,w);if(!v)throw new TypeError("Invalid outputKey for p2tr witness");if(s.length&&me(s,v.x)!==0)throw new TypeError("Pubkey mismatch for p2tr witness");if(v.parity!==(l[0]&1))throw new Error("Incorrect parity")}}return Object.assign(a,e)}const iE=40,aE=2,sE=16,cE=2,uE=80,lE="WARNING: Sending to a future segwit version address can lead to loss of funds. End users MUST be warned carefully in the GUI and asked if they wish to proceed with caution. Wallets should verify the segwit version from the output of fromBech32, then decide when it is safe to use which version of segwit.";function xU(e,t){const r=e.slice(2);if(r.length<aE||r.length>iE)throw new TypeError("Invalid program length for segwit address");const n=e[0]-uE;if(n<cE||n>sE)throw new TypeError("Invalid version for segwit address");if(e[1]!==r.length)throw new TypeError("Invalid script for segwit address");return console.warn(lE),AU(r,n,t.bech32)}function fE(e){const t=cl.decode(e);if(t.length<21)throw new TypeError(e+" is too short");if(t.length>21)throw new TypeError(e+" is too long");const r=va(t,0),n=t.slice(1);return{version:r,hash:n}}function dy(e){let t,r;try{t=po.decode(e)}catch{}if(t){if(r=t.words[0],r!==0)throw new TypeError(e+" uses wrong encoding")}else if(t=qf.decode(e),r=t.words[0],r===0)throw new TypeError(e+" uses wrong encoding");const n=po.fromWords(t.words.slice(1));return{version:r,prefix:t.prefix,data:Uint8Array.from(n)}}function AU(e,t,r){const n=po.toWords(e);return n.unshift(t),t===0?po.encode(r,n):qf.encode(r,n)}function Zf(e,t){t=t||Yo;try{return Ff({output:e,network:t}).address}catch{}try{return ul({output:e,network:t}).address}catch{}try{return Mf({output:e,network:t}).address}catch{}try{return Vf({output:e,network:t}).address}catch{}try{return Wf({output:e,network:t}).address}catch{}try{return xU(e,t)}catch{}throw new Error(_C(e)+" has no matching Address")}function hy(e,t){t=t||Yo;let r,n;try{r=fE(e)}catch{}if(r){if(r.version===t.pubKeyHash)return Ff({hash:r.hash}).output;if(r.version===t.scriptHash)return ul({hash:r.hash}).output}else{try{n=dy(e)}catch{}if(n){if(n.prefix!==t.bech32)throw new Error(e+" has an invalid prefix");if(n.version===0){if(n.data.length===20)return Mf({hash:n.data}).output;if(n.data.length===32)return Vf({hash:n.data}).output}else if(n.version===1){if(n.data.length===32)return Wf({pubkey:n.data}).output}else if(n.version>=cE&&n.version<=sE&&n.data.length>=aE&&n.data.length<=iE)return console.warn(lE),Xn([n.version+uE,n.data])}}throw new Error(e+" has no matching Script")}function ji(e){const t=e.length;return Io(t)+t}function SU(e){const t=e.length;return Io(t)+e.reduce((r,n)=>r+ji(n),0)}const vs=new Uint8Array(0),dE=[],py=wa("0000000000000000000000000000000000000000000000000000000000000000"),hE=wa("0000000000000000000000000000000000000000000000000000000000000001"),_U=wa("ffffffffffffffff"),$U={script:vs,valueBuffer:_U};function TU(e){return e.value!==void 0}const ei=class Xt{constructor(){Te(this,"version",1),Te(this,"locktime",0),Te(this,"ins",[]),Te(this,"outs",[])}static fromBuffer(t,r){const n=new yU(t),o=new Xt;o.version=n.readInt32();const i=n.readUInt8(),a=n.readUInt8();let s=!1;i===Xt.ADVANCED_TRANSACTION_MARKER&&a===Xt.ADVANCED_TRANSACTION_FLAG?s=!0:n.offset-=2;const c=n.readVarInt();for(let l=0;l<c;++l)o.ins.push({hash:n.readSlice(32),index:n.readUInt32(),script:n.readVarSlice(),sequence:n.readUInt32(),witness:dE});const u=n.readVarInt();for(let l=0;l<u;++l)o.outs.push({value:n.readInt64(),script:n.readVarSlice()});if(s){for(let l=0;l<c;++l)o.ins[l].witness=n.readVector();if(!o.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(o.locktime=n.readUInt32(),r)return o;if(n.offset!==t.length)throw new Error("Transaction has unexpected data");return o}static fromHex(t){return Xt.fromBuffer(wa(t),!1)}static isCoinbaseHash(t){ar(_8,t);for(let r=0;r<32;++r)if(t[r]!==0)return!1;return!0}isCoinbase(){return this.ins.length===1&&Xt.isCoinbaseHash(this.ins[0].hash)}addInput(t,r,n,o){return ar(Ui([_8,Ea,V1(up(Ea)),V1(up(Ht))]),[t,r,n,o]),n==null&&(n=Xt.DEFAULT_SEQUENCE),this.ins.push({hash:t,index:r,script:o||vs,sequence:n,witness:dE})-1}addOutput(t,r){return ar(Ui([Ht,Z1]),[t,r]),this.outs.push({script:t,value:r})-1}hasWitnesses(){return this.ins.some(t=>t.witness.length!==0)}weight(){const t=this.byteLength(!1),r=this.byteLength(!0);return t*3+r}virtualSize(){return Math.ceil(this.weight()/4)}byteLength(t=!0){const r=t&&this.hasWitnesses();return(r?10:8)+Io(this.ins.length)+Io(this.outs.length)+this.ins.reduce((n,o)=>n+40+ji(o.script),0)+this.outs.reduce((n,o)=>n+8+ji(o.script),0)+(r?this.ins.reduce((n,o)=>n+SU(o.witness),0):0)}clone(){const t=new Xt;return t.version=this.version,t.locktime=this.locktime,t.ins=this.ins.map(r=>({hash:r.hash,index:r.index,script:r.script,sequence:r.sequence,witness:r.witness})),t.outs=this.outs.map(r=>({script:r.script,value:r.value})),t}hashForSignature(t,r,n){if(ar(Ui([Ea,Ht,Zn()]),[t,r,n]),t>=this.ins.length)return hE;const o=Xn(sr(r).filter(s=>s!==Lt.OP_CODESEPARATOR)),i=this.clone();if((n&31)===Xt.SIGHASH_NONE)i.outs=[],i.ins.forEach((s,c)=>{c!==t&&(s.sequence=0)});else if((n&31)===Xt.SIGHASH_SINGLE){if(t>=this.outs.length)return hE;i.outs.length=t+1;for(let s=0;s<t;s++)i.outs[s]=$U;i.ins.forEach((s,c)=>{c!==t&&(s.sequence=0)})}n&Xt.SIGHASH_ANYONECANPAY?(i.ins=[i.ins[t]],i.ins[0].script=o):(i.ins.forEach(s=>{s.script=vs}),i.ins[t].script=o);const a=new Uint8Array(i.byteLength(!1)+4);return d8(a,a.length-4,n,"LE"),i.__toBuffer(a,0,!1),Vc(a)}hashForWitnessV1(t,r,n,o,i,a){if(ar(Ui([Ea,Wn(Ht),Wn(Z1),Ea]),[t,r,n,o]),n.length!==this.ins.length||r.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const s=o===Xt.SIGHASH_DEFAULT?Xt.SIGHASH_ALL:o&Xt.SIGHASH_OUTPUT_MASK,c=(o&Xt.SIGHASH_INPUT_MASK)===Xt.SIGHASH_ANYONECANPAY,u=s===Xt.SIGHASH_NONE,l=s===Xt.SIGHASH_SINGLE;let f=vs,h=vs,g=vs,y=vs,m=vs;if(!c){let E=Yn.withCapacity(36*this.ins.length);this.ins.forEach($=>{E.writeSlice($.hash),E.writeUInt32($.index)}),f=en(E.end()),E=Yn.withCapacity(8*this.ins.length),n.forEach($=>E.writeInt64($)),h=en(E.end()),E=Yn.withCapacity(r.map(ji).reduce(($,P)=>$+P)),r.forEach($=>E.writeVarSlice($)),g=en(E.end()),E=Yn.withCapacity(4*this.ins.length),this.ins.forEach($=>E.writeUInt32($.sequence)),y=en(E.end())}if(u||l){if(l&&t<this.outs.length){const E=this.outs[t],$=Yn.withCapacity(8+ji(E.script));$.writeInt64(E.value),$.writeVarSlice(E.script),m=en($.end())}}else{if(!this.outs.length)throw new Error("Add outputs to the transaction before signing.");const E=this.outs.map(P=>8+ji(P.script)).reduce((P,T)=>P+T),$=Yn.withCapacity(E);this.outs.forEach(P=>{$.writeInt64(P.value),$.writeVarSlice(P.script)}),m=en($.end())}const w=(i?2:0)+(a?1:0),v=174-(c?49:0)-(u?32:0)+(a?32:0)+(i?37:0),x=Yn.withCapacity(v);if(x.writeUInt8(o),x.writeInt32(this.version),x.writeUInt32(this.locktime),x.writeSlice(f),x.writeSlice(h),x.writeSlice(g),x.writeSlice(y),u||l||x.writeSlice(m),x.writeUInt8(w),c){const E=this.ins[t];x.writeSlice(E.hash),x.writeUInt32(E.index),x.writeInt64(n[t]),x.writeVarSlice(r[t]),x.writeUInt32(E.sequence)}else x.writeUInt32(t);if(a){const E=Yn.withCapacity(ji(a));E.writeVarSlice(a),x.writeSlice(en(E.end()))}return l&&x.writeSlice(m),i&&(x.writeSlice(i),x.writeUInt8(0),x.writeUInt32(4294967295)),wp("TapSighash",ir([Uint8Array.from([0]),x.end()]))}hashForWitnessV0(t,r,n,o){ar(Ui([Ea,Ht,Z1,Ea]),[t,r,n,o]);let i=Uint8Array.from([]),a,s=py,c=py,u=py;if(o&Xt.SIGHASH_ANYONECANPAY||(i=new Uint8Array(36*this.ins.length),a=new Yn(i,0),this.ins.forEach(f=>{a.writeSlice(f.hash),a.writeUInt32(f.index)}),c=Vc(i)),!(o&Xt.SIGHASH_ANYONECANPAY)&&(o&31)!==Xt.SIGHASH_SINGLE&&(o&31)!==Xt.SIGHASH_NONE&&(i=new Uint8Array(4*this.ins.length),a=new Yn(i,0),this.ins.forEach(f=>{a.writeUInt32(f.sequence)}),u=Vc(i)),(o&31)!==Xt.SIGHASH_SINGLE&&(o&31)!==Xt.SIGHASH_NONE){const f=this.outs.reduce((h,g)=>h+8+ji(g.script),0);i=new Uint8Array(f),a=new Yn(i,0),this.outs.forEach(h=>{a.writeInt64(h.value),a.writeVarSlice(h.script)}),s=Vc(i)}else if((o&31)===Xt.SIGHASH_SINGLE&&t<this.outs.length){const f=this.outs[t];i=new Uint8Array(8+ji(f.script)),a=new Yn(i,0),a.writeInt64(f.value),a.writeVarSlice(f.script),s=Vc(i)}i=new Uint8Array(156+ji(r)),a=new Yn(i,0);const l=this.ins[t];return a.writeInt32(this.version),a.writeSlice(c),a.writeSlice(u),a.writeSlice(l.hash),a.writeUInt32(l.index),a.writeVarSlice(r),a.writeInt64(n),a.writeUInt32(l.sequence),a.writeSlice(s),a.writeUInt32(this.locktime),a.writeUInt32(o),Vc(i)}getHash(t){return t&&this.isCoinbase()?new Uint8Array(32):Vc(this.__toBuffer(void 0,void 0,t))}getId(){return Me(cy(this.getHash(!1)))}toBuffer(t,r){return this.__toBuffer(t,r,!0)}toHex(){return Me(this.toBuffer(void 0,void 0))}setInputScript(t,r){ar(Ui([Zn(),Ht]),[t,r]),this.ins[t].script=r}setWitness(t,r){ar(Ui([Zn(),Wn(Ht)]),[t,r]),this.ins[t].witness=r}__toBuffer(t,r,n=!1){t||(t=new Uint8Array(this.byteLength(n)));const o=new Yn(t,r||0);o.writeInt32(this.version);const i=n&&this.hasWitnesses();return i&&(o.writeUInt8(Xt.ADVANCED_TRANSACTION_MARKER),o.writeUInt8(Xt.ADVANCED_TRANSACTION_FLAG)),o.writeVarInt(this.ins.length),this.ins.forEach(a=>{o.writeSlice(a.hash),o.writeUInt32(a.index),o.writeVarSlice(a.script),o.writeUInt32(a.sequence)}),o.writeVarInt(this.outs.length),this.outs.forEach(a=>{TU(a)?o.writeInt64(a.value):o.writeSlice(a.valueBuffer),o.writeVarSlice(a.script)}),i&&this.ins.forEach(a=>{o.writeVector(a.witness)}),o.writeUInt32(this.locktime),r!==void 0?t.slice(r,o.offset):t}};Te(ei,"DEFAULT_SEQUENCE",4294967295),Te(ei,"SIGHASH_DEFAULT",0),Te(ei,"SIGHASH_ALL",1),Te(ei,"SIGHASH_NONE",2),Te(ei,"SIGHASH_SINGLE",3),Te(ei,"SIGHASH_ANYONECANPAY",128),Te(ei,"SIGHASH_OUTPUT_MASK",3),Te(ei,"SIGHASH_INPUT_MASK",128),Te(ei,"ADVANCED_TRANSACTION_MARKER",0),Te(ei,"ADVANCED_TRANSACTION_FLAG",1);let kr=ei;var zi;(function(e){e[e.UNSIGNED_TX=0]="UNSIGNED_TX",e[e.GLOBAL_XPUB=1]="GLOBAL_XPUB"})(zi||(zi={}));var Se;(function(e){e[e.NON_WITNESS_UTXO=0]="NON_WITNESS_UTXO",e[e.WITNESS_UTXO=1]="WITNESS_UTXO",e[e.PARTIAL_SIG=2]="PARTIAL_SIG",e[e.SIGHASH_TYPE=3]="SIGHASH_TYPE",e[e.REDEEM_SCRIPT=4]="REDEEM_SCRIPT",e[e.WITNESS_SCRIPT=5]="WITNESS_SCRIPT",e[e.BIP32_DERIVATION=6]="BIP32_DERIVATION",e[e.FINAL_SCRIPTSIG=7]="FINAL_SCRIPTSIG",e[e.FINAL_SCRIPTWITNESS=8]="FINAL_SCRIPTWITNESS",e[e.POR_COMMITMENT=9]="POR_COMMITMENT",e[e.TAP_KEY_SIG=19]="TAP_KEY_SIG",e[e.TAP_SCRIPT_SIG=20]="TAP_SCRIPT_SIG",e[e.TAP_LEAF_SCRIPT=21]="TAP_LEAF_SCRIPT",e[e.TAP_BIP32_DERIVATION=22]="TAP_BIP32_DERIVATION",e[e.TAP_INTERNAL_KEY=23]="TAP_INTERNAL_KEY",e[e.TAP_MERKLE_ROOT=24]="TAP_MERKLE_ROOT"})(Se||(Se={}));var xr;(function(e){e[e.REDEEM_SCRIPT=0]="REDEEM_SCRIPT",e[e.WITNESS_SCRIPT=1]="WITNESS_SCRIPT",e[e.BIP32_DERIVATION=2]="BIP32_DERIVATION",e[e.TAP_INTERNAL_KEY=5]="TAP_INTERNAL_KEY",e[e.TAP_TREE=6]="TAP_TREE",e[e.TAP_BIP32_DERIVATION=7]="TAP_BIP32_DERIVATION"})(xr||(xr={}));const IU=e=>[...Array(e).keys()];function OU(e){if(e.key[0]!==zi.GLOBAL_XPUB)throw new Error("Decode Error: could not decode globalXpub with key 0x"+Me(e.key));if(e.key.length!==79||![2,3].includes(e.key[46]))throw new Error("Decode Error: globalXpub has invalid extended pubkey in key 0x"+Me(e.key));if(e.value.length/4%1!==0)throw new Error("Decode Error: Global GLOBAL_XPUB value length should be multiple of 4");const t=e.key.slice(1),r={masterFingerprint:e.value.slice(0,4),extendedPubkey:t,path:"m"};for(const n of IU(e.value.length/4-1)){const o=ol(e.value,n*4+4,"LE"),i=!!(o&2147483648),a=o&2147483647;r.path+="/"+a.toString(10)+(i?"'":"")}return r}function PU(e){const t=new Uint8Array([zi.GLOBAL_XPUB]),r=ir([t,e.extendedPubkey]),n=e.path.split("/"),o=new Uint8Array(n.length*4);o.set(e.masterFingerprint,0);let i=4;return n.slice(1).forEach(a=>{const s=a.slice(-1)==="'";let c=2147483647&parseInt(s?a.slice(0,-1):a,10);s&&(c+=2147483648),zf(o,i,c,"LE"),i+=4}),{key:r,value:o}}const BU="{ masterFingerprint: Uint8Array; extendedPubkey: Uint8Array; path: string; }";function CU(e){const t=e.extendedPubkey,r=e.masterFingerprint,n=e.path;return t instanceof Uint8Array&&t.length===78&&[2,3].indexOf(t[45])>-1&&r instanceof Uint8Array&&r.length===4&&typeof n=="string"&&!!n.match(/^m(\/\d+'?)*$/)}function UU(e,t,r){const n=Me(t.extendedPubkey);return r.has(n)?!1:(r.add(n),e.filter(o=>me(o.extendedPubkey,t.extendedPubkey)).length===0)}const NU=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:UU,check:CU,decode:OU,encode:PU,expected:BU},Symbol.toStringTag,{value:"Module"}));function jU(e){return{key:new Uint8Array([zi.UNSIGNED_TX]),value:e.toBuffer()}}const zU=Object.freeze(Object.defineProperty({__proto__:null,encode:jU},Symbol.toStringTag,{value:"Module"}));function RU(e){if(e.key[0]!==Se.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+Me(e.key));return e.value}function LU(e){return{key:new Uint8Array([Se.FINAL_SCRIPTSIG]),value:e}}const HU="Uint8Array";function FU(e){return e instanceof Uint8Array}function DU(e,t){return!!e&&!!t&&e.finalScriptSig===void 0}const KU=Object.freeze(Object.defineProperty({__proto__:null,canAdd:DU,check:FU,decode:RU,encode:LU,expected:HU},Symbol.toStringTag,{value:"Module"}));function qU(e){if(e.key[0]!==Se.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+Me(e.key));return e.value}function MU(e){return{key:new Uint8Array([Se.FINAL_SCRIPTWITNESS]),value:e}}const VU="Uint8Array";function GU(e){return e instanceof Uint8Array}function WU(e,t){return!!e&&!!t&&e.finalScriptWitness===void 0}const ZU=Object.freeze(Object.defineProperty({__proto__:null,canAdd:WU,check:GU,decode:qU,encode:MU,expected:VU},Symbol.toStringTag,{value:"Module"}));function XU(e){if(e.key[0]!==Se.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitnessUtxo with key 0x"+Me(e.key));return e.value}function YU(e){return{key:new Uint8Array([Se.NON_WITNESS_UTXO]),value:e}}const JU="Uint8Array";function QU(e){return e instanceof Uint8Array}function eN(e,t){return!!e&&!!t&&e.nonWitnessUtxo===void 0}const tN=Object.freeze(Object.defineProperty({__proto__:null,canAdd:eN,check:QU,decode:XU,encode:YU,expected:JU},Symbol.toStringTag,{value:"Module"}));function rN(e){if(e.key[0]!==Se.PARTIAL_SIG)throw new Error("Decode Error: could not decode partialSig with key 0x"+Me(e.key));if(!(e.key.length===34||e.key.length===66)||![2,3,4].includes(e.key[1]))throw new Error("Decode Error: partialSig has invalid pubkey in key 0x"+Me(e.key));return{pubkey:e.key.slice(1),signature:e.value}}function nN(e){const t=new Uint8Array([Se.PARTIAL_SIG]);return{key:ir([t,e.pubkey]),value:e.signature}}const oN="{ pubkey: Uint8Array; signature: Uint8Array; }";function iN(e){return e.pubkey instanceof Uint8Array&&e.signature instanceof Uint8Array&&[33,65].includes(e.pubkey.length)&&[2,3,4].includes(e.pubkey[0])&&aN(e.signature)}function aN(e){if(!(e instanceof Uint8Array)||e.length<9||e[0]!==48||e.length!==e[1]+3||e[2]!==2)return!1;const t=e[3];if(t>33||t<1||e[3+t+1]!==2)return!1;const r=e[3+t+2];return!(r>33||r<1||e.length!==3+t+2+r+2)}function sN(e,t,r){const n=Me(t.pubkey);return r.has(n)?!1:(r.add(n),e.filter(o=>me(o.pubkey,t.pubkey)===0).length===0)}const cN=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:sN,check:iN,decode:rN,encode:nN,expected:oN},Symbol.toStringTag,{value:"Module"}));function uN(e){if(e.key[0]!==Se.POR_COMMITMENT)throw new Error("Decode Error: could not decode porCommitment with key 0x"+Me(e.key));return tC(e.value)}function lN(e){return{key:new Uint8Array([Se.POR_COMMITMENT]),value:rC(e)}}const fN="string";function dN(e){return typeof e=="string"}function hN(e,t){return!!e&&!!t&&e.porCommitment===void 0}const pN=Object.freeze(Object.defineProperty({__proto__:null,canAdd:hN,check:dN,decode:uN,encode:lN,expected:fN},Symbol.toStringTag,{value:"Module"}));function gN(e){if(e.key[0]!==Se.SIGHASH_TYPE)throw new Error("Decode Error: could not decode sighashType with key 0x"+Me(e.key));return Number(ol(e.value,0,"LE"))}function mN(e){const t=Uint8Array.from([Se.SIGHASH_TYPE]),r=new Uint8Array(4);return zf(r,0,e,"LE"),{key:t,value:r}}const yN="number";function bN(e){return typeof e=="number"}function wN(e,t){return!!e&&!!t&&e.sighashType===void 0}const vN=Object.freeze(Object.defineProperty({__proto__:null,canAdd:wN,check:bN,decode:gN,encode:mN,expected:yN},Symbol.toStringTag,{value:"Module"}));function EN(e){if(e.key[0]!==Se.TAP_KEY_SIG||e.key.length!==1)throw new Error("Decode Error: could not decode tapKeySig with key 0x"+Me(e.key));if(!pE(e.value))throw new Error("Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature");return e.value}function kN(e){return{key:Uint8Array.from([Se.TAP_KEY_SIG]),value:e}}const xN="Uint8Array";function pE(e){return e instanceof Uint8Array&&(e.length===64||e.length===65)}function AN(e,t){return!!e&&!!t&&e.tapKeySig===void 0}const SN=Object.freeze(Object.defineProperty({__proto__:null,canAdd:AN,check:pE,decode:EN,encode:kN,expected:xN},Symbol.toStringTag,{value:"Module"}));function _N(e){if(e.key[0]!==Se.TAP_LEAF_SCRIPT)throw new Error("Decode Error: could not decode tapLeafScript with key 0x"+Me(e.key));if((e.key.length-2)%32!==0)throw new Error("Decode Error: tapLeafScript has invalid control block in key 0x"+Me(e.key));const t=e.value[e.value.length-1];if((e.key[1]&254)!==t)throw new Error("Decode Error: tapLeafScript bad leaf version in key 0x"+Me(e.key));const r=e.value.slice(0,-1);return{controlBlock:e.key.slice(1),script:r,leafVersion:t}}function $N(e){const t=Uint8Array.from([Se.TAP_LEAF_SCRIPT]),r=Uint8Array.from([e.leafVersion]);return{key:ir([t,e.controlBlock]),value:ir([e.script,r])}}const TN="{ controlBlock: Uint8Array; leafVersion: number, script: Uint8Array; }";function IN(e){return e.controlBlock instanceof Uint8Array&&(e.controlBlock.length-1)%32===0&&(e.controlBlock[0]&254)===e.leafVersion&&e.script instanceof Uint8Array}function ON(e,t,r){const n=Me(t.controlBlock);return r.has(n)?!1:(r.add(n),e.filter(o=>me(o.controlBlock,t.controlBlock)===0).length===0)}const PN=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:ON,check:IN,decode:_N,encode:$N,expected:TN},Symbol.toStringTag,{value:"Module"}));function BN(e){if(e.key[0]!==Se.TAP_MERKLE_ROOT||e.key.length!==1)throw new Error("Decode Error: could not decode tapMerkleRoot with key 0x"+Me(e.key));if(!gE(e.value))throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");return e.value}function CN(e){return{key:Uint8Array.from([Se.TAP_MERKLE_ROOT]),value:e}}const UN="Uint8Array";function gE(e){return e instanceof Uint8Array&&e.length===32}function NN(e,t){return!!e&&!!t&&e.tapMerkleRoot===void 0}const jN=Object.freeze(Object.defineProperty({__proto__:null,canAdd:NN,check:gE,decode:BN,encode:CN,expected:UN},Symbol.toStringTag,{value:"Module"}));function zN(e){if(e.key[0]!==Se.TAP_SCRIPT_SIG)throw new Error("Decode Error: could not decode tapScriptSig with key 0x"+Me(e.key));if(e.key.length!==65)throw new Error("Decode Error: tapScriptSig has invalid key 0x"+Me(e.key));if(e.value.length!==64&&e.value.length!==65)throw new Error("Decode Error: tapScriptSig has invalid signature in key 0x"+Me(e.key));const t=e.key.slice(1,33),r=e.key.slice(33);return{pubkey:t,leafHash:r,signature:e.value}}function RN(e){const t=Uint8Array.from([Se.TAP_SCRIPT_SIG]);return{key:ir([t,e.pubkey,e.leafHash]),value:e.signature}}const LN="{ pubkey: Uint8Array; leafHash: Uint8Array; signature: Uint8Array; }";function HN(e){return e.pubkey instanceof Uint8Array&&e.leafHash instanceof Uint8Array&&e.signature instanceof Uint8Array&&e.pubkey.length===32&&e.leafHash.length===32&&(e.signature.length===64||e.signature.length===65)}function FN(e,t,r){const n=Me(t.pubkey)+Me(t.leafHash);return r.has(n)?!1:(r.add(n),e.filter(o=>me(o.pubkey,t.pubkey)===0&&me(o.leafHash,t.leafHash)===0).length===0)}const DN=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:FN,check:HN,decode:zN,encode:RN,expected:LN},Symbol.toStringTag,{value:"Module"}));function KN(e){if(e.key[0]!==Se.WITNESS_UTXO)throw new Error("Decode Error: could not decode witnessUtxo with key 0x"+Me(e.key));const t=p8(e.value,0,"LE");let r=8;const{numberValue:n,bytes:o}=dl(e.value,r);r+=o;const i=e.value.slice(r);if(i.length!==n)throw new Error("Decode Error: WITNESS_UTXO script is not proper length");return{script:i,value:t}}function qN(e){const{script:t,value:r}=e,n=Io(t.length),o=new Uint8Array(8+n+t.length);return h8(o,0,BigInt(r),"LE"),ws(t.length,o,8),o.set(t,8+n),{key:Uint8Array.from([Se.WITNESS_UTXO]),value:o}}const MN="{ script: Uint8Array; value: bigint; }";function VN(e){return e.script instanceof Uint8Array&&typeof e.value=="bigint"}function GN(e,t){return!!e&&!!t&&e.witnessUtxo===void 0}const WN=Object.freeze(Object.defineProperty({__proto__:null,canAdd:GN,check:VN,decode:KN,encode:qN,expected:MN},Symbol.toStringTag,{value:"Module"}));function ZN(e){if(e.key[0]!==xr.TAP_TREE||e.key.length!==1)throw new Error("Decode Error: could not decode tapTree with key 0x"+Me(e.key));let t=0;const r=[];for(;t<e.value.length;){const n=e.value[t++],o=e.value[t++],{numberValue:i,bytes:a}=dl(e.value,t);t+=a,r.push({depth:n,leafVersion:o,script:e.value.slice(t,t+i)}),t+=i}return{leaves:r}}function XN(e){const t=Uint8Array.from([xr.TAP_TREE]),r=[].concat(...e.leaves.map(n=>[Uint8Array.of(n.depth,n.leafVersion),ws(BigInt(n.script.length)).buffer,n.script]));return{key:t,value:ir(r)}}const YN="{ leaves: [{ depth: number; leafVersion: number, script: Uint8Array; }] }";function JN(e){return Array.isArray(e.leaves)&&e.leaves.every(t=>t.depth>=0&&t.depth<=128&&(t.leafVersion&254)===t.leafVersion&&t.script instanceof Uint8Array)}function QN(e,t){return!!e&&!!t&&e.tapTree===void 0}const ej=Object.freeze(Object.defineProperty({__proto__:null,canAdd:QN,check:JN,decode:ZN,encode:XN,expected:YN},Symbol.toStringTag,{value:"Module"})),tj=e=>[...Array(e).keys()],rj=e=>e.length===33&&[2,3].includes(e[0])||e.length===65&&e[0]===4;function gy(e,t=rj){function r(s){if(s.key[0]!==e)throw new Error("Decode Error: could not decode bip32Derivation with key 0x"+Me(s.key));const c=s.key.slice(1);if(!t(c))throw new Error("Decode Error: bip32Derivation has invalid pubkey in key 0x"+Me(s.key));if(s.value.length/4%1!==0)throw new Error("Decode Error: Input BIP32_DERIVATION value length should be multiple of 4");const u={masterFingerprint:s.value.slice(0,4),pubkey:c,path:"m"};for(const l of tj(s.value.length/4-1)){const f=ol(s.value,l*4+4,"LE"),h=!!(f&2147483648),g=f&2147483647;u.path+="/"+g.toString(10)+(h?"'":"")}return u}function n(s){const c=Uint8Array.from([e]),u=ir([c,s.pubkey]),l=s.path.split("/"),f=new Uint8Array(l.length*4);f.set(s.masterFingerprint,0);let h=4;return l.slice(1).forEach(g=>{const y=g.slice(-1)==="'";let m=2147483647&parseInt(y?g.slice(0,-1):g,10);y&&(m+=2147483648),zf(f,h,m,"LE"),h+=4}),{key:u,value:f}}const o="{ masterFingerprint: Uint8Array; pubkey: Uint8Array; path: string; }";function i(s){return s.pubkey instanceof Uint8Array&&s.masterFingerprint instanceof Uint8Array&&typeof s.path=="string"&&t(s.pubkey)&&s.masterFingerprint.length===4}function a(s,c,u){const l=Me(c.pubkey);return u.has(l)?!1:(u.add(l),s.filter(f=>me(f.pubkey,c.pubkey)===0).length===0)}return{decode:r,encode:n,check:i,expected:o,canAddToArray:a}}function my(e){return t;function t(r){let n;if(e.includes(r.key[0])&&(n=r.key.slice(1),!(n.length===33||n.length===65)||![2,3,4].includes(n[0])))throw new Error("Format Error: invalid pubkey in key 0x"+Me(r.key));return n}}function mE(e){function t(a){if(a.key[0]!==e)throw new Error("Decode Error: could not decode redeemScript with key 0x"+Me(a.key));return a.value}function r(a){return{key:Uint8Array.from([e]),value:a}}const n="Uint8Array";function o(a){return a instanceof Uint8Array}function i(a,s){return!!a&&!!s&&a.redeemScript===void 0}return{decode:t,encode:r,check:o,expected:n,canAdd:i}}const nj=e=>e.length===32;function yE(e){const t=gy(e,nj);function r(a){const{numberValue:s,bytes:c}=dl(a.value),u=t.decode({key:a.key,value:a.value.slice(c+Number(s)*32)}),l=new Array(Number(s));for(let f=0,h=c;f<s;f++,h+=32)l[f]=a.value.slice(h,h+32);return{...u,leafHashes:l}}function n(a){const s=t.encode(a),c=Io(a.leafHashes.length),u=new Uint8Array(c);ws(a.leafHashes.length,u);const l=ir([u,...a.leafHashes,s.value]);return{...s,value:l}}const o="{ masterFingerprint: Uint8Array; pubkey: Uint8Array; path: string; leafHashes: Uint8Array[]; }";function i(a){return Array.isArray(a.leafHashes)&&a.leafHashes.every(s=>s instanceof Uint8Array&&s.length===32)&&t.check(a)}return{decode:r,encode:n,check:i,expected:o,canAddToArray:t.canAddToArray}}function bE(e){function t(a){if(a.key[0]!==e||a.key.length!==1)throw new Error("Decode Error: could not decode tapInternalKey with key 0x"+Me(a.key));if(a.value.length!==32)throw new Error("Decode Error: tapInternalKey not a 32-byte x-only pubkey");return a.value}function r(a){return{key:Uint8Array.from([e]),value:a}}const n="Uint8Array";function o(a){return a instanceof Uint8Array&&a.length===32}function i(a,s){return!!a&&!!s&&a.tapInternalKey===void 0}return{decode:t,encode:r,check:o,expected:n,canAdd:i}}function wE(e){function t(a){if(a.key[0]!==e)throw new Error("Decode Error: could not decode witnessScript with key 0x"+Me(a.key));return a.value}function r(a){return{key:Uint8Array.from([e]),value:a}}const n="Uint8Array";function o(a){return a instanceof Uint8Array}function i(a,s){return!!a&&!!s&&a.witnessScript===void 0}return{decode:t,encode:r,check:o,expected:n,canAdd:i}}const yy={unsignedTx:zU,globalXpub:NU,checkPubkey:my([])},Lr={nonWitnessUtxo:tN,partialSig:cN,sighashType:vN,finalScriptSig:KU,finalScriptWitness:ZU,porCommitment:pN,witnessUtxo:WN,bip32Derivation:gy(Se.BIP32_DERIVATION),redeemScript:mE(Se.REDEEM_SCRIPT),witnessScript:wE(Se.WITNESS_SCRIPT),checkPubkey:my([Se.PARTIAL_SIG,Se.BIP32_DERIVATION]),tapKeySig:SN,tapScriptSig:DN,tapLeafScript:PN,tapBip32Derivation:yE(Se.TAP_BIP32_DERIVATION),tapInternalKey:bE(Se.TAP_INTERNAL_KEY),tapMerkleRoot:jN},$a={bip32Derivation:gy(xr.BIP32_DERIVATION),redeemScript:mE(xr.REDEEM_SCRIPT),witnessScript:wE(xr.WITNESS_SCRIPT),checkPubkey:my([xr.BIP32_DERIVATION]),tapBip32Derivation:yE(xr.TAP_BIP32_DERIVATION),tapTree:ej,tapInternalKey:bE(xr.TAP_INTERNAL_KEY)},oj=Object.freeze(Object.defineProperty({__proto__:null,globals:yy,inputs:Lr,outputs:$a},Symbol.toStringTag,{value:"Module"})),Ap=e=>[...Array(e).keys()];function vE(e){const t=e.map(ij);return t.push(Uint8Array.from([0])),ir(t)}function ij(e){const t=e.key.length,r=e.value.length,n=Io(t),o=Io(r),i=new Uint8Array(n+t+o+r);return ws(t,i,0),i.set(e.key,n),ws(r,i,n+t),i.set(e.value,n+t+o),i}function aj(e,t){let r=0;function n(){const{numberValue:w,bytes:v}=dl(e,r);r+=v;const x=e.slice(r,r+Number(w));return r+=Number(w),x}function o(){const w=ol(e,r,"BE");return r+=4,w}function i(){const w=va(e,r);return r+=1,w}function a(){const w=n(),v=n();return{key:w,value:v}}function s(){if(r>=e.length)throw new Error("Format Error: Unexpected End of PSBT");const w=va(e,r)===0;return w&&r++,w}if(o()!==1886610036)throw new Error("Format Error: Invalid Magic Number");if(i()!==255)throw new Error("Format Error: Magic Number must be followed by 0xff separator");const c=[],u={};for(;!s();){const w=a(),v=Me(w.key);if(u[v])throw new Error("Format Error: Keys must be unique for global keymap: key "+v);u[v]=1,c.push(w)}const l=c.filter(w=>w.key[0]===zi.UNSIGNED_TX);if(l.length!==1)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const f=t(l[0].value),{inputCount:h,outputCount:g}=f.getInputOutputCounts(),y=[],m=[];for(const w of Ap(h)){const v={},x=[];for(;!s();){const E=a(),$=Me(E.key);if(v[$])throw new Error("Format Error: Keys must be unique for each input: input index "+w+" key "+$);v[$]=1,x.push(E)}y.push(x)}for(const w of Ap(g)){const v={},x=[];for(;!s();){const E=a(),$=Me(E.key);if(v[$])throw new Error("Format Error: Keys must be unique for each output: output index "+w+" key "+$);v[$]=1,x.push(E)}m.push(x)}return EE(f,{globalMapKeyVals:c,inputKeyVals:y,outputKeyVals:m})}function vn(e,t,r){if(me(t,Uint8Array.from([r])))throw new Error(`Format Error: Invalid ${e} key: ${Me(t)}`)}function EE(e,{globalMapKeyVals:t,inputKeyVals:r,outputKeyVals:n}){const o={unsignedTx:e};let i=0;for(const l of t)switch(l.key[0]){case zi.UNSIGNED_TX:if(vn("global",l.key,zi.UNSIGNED_TX),i>0)throw new Error("Format Error: GlobalMap has multiple UNSIGNED_TX");i++;break;case zi.GLOBAL_XPUB:o.globalXpub===void 0&&(o.globalXpub=[]),o.globalXpub.push(yy.globalXpub.decode(l));break;default:o.unknownKeyVals||(o.unknownKeyVals=[]),o.unknownKeyVals.push(l)}const a=r.length,s=n.length,c=[],u=[];for(const l of Ap(a)){const f={};for(const h of r[l])switch(Lr.checkPubkey(h),h.key[0]){case Se.NON_WITNESS_UTXO:if(vn("input",h.key,Se.NON_WITNESS_UTXO),f.nonWitnessUtxo!==void 0)throw new Error("Format Error: Input has multiple NON_WITNESS_UTXO");f.nonWitnessUtxo=Lr.nonWitnessUtxo.decode(h);break;case Se.WITNESS_UTXO:if(vn("input",h.key,Se.WITNESS_UTXO),f.witnessUtxo!==void 0)throw new Error("Format Error: Input has multiple WITNESS_UTXO");f.witnessUtxo=Lr.witnessUtxo.decode(h);break;case Se.PARTIAL_SIG:f.partialSig===void 0&&(f.partialSig=[]),f.partialSig.push(Lr.partialSig.decode(h));break;case Se.SIGHASH_TYPE:if(vn("input",h.key,Se.SIGHASH_TYPE),f.sighashType!==void 0)throw new Error("Format Error: Input has multiple SIGHASH_TYPE");f.sighashType=Lr.sighashType.decode(h);break;case Se.REDEEM_SCRIPT:if(vn("input",h.key,Se.REDEEM_SCRIPT),f.redeemScript!==void 0)throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");f.redeemScript=Lr.redeemScript.decode(h);break;case Se.WITNESS_SCRIPT:if(vn("input",h.key,Se.WITNESS_SCRIPT),f.witnessScript!==void 0)throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");f.witnessScript=Lr.witnessScript.decode(h);break;case Se.BIP32_DERIVATION:f.bip32Derivation===void 0&&(f.bip32Derivation=[]),f.bip32Derivation.push(Lr.bip32Derivation.decode(h));break;case Se.FINAL_SCRIPTSIG:vn("input",h.key,Se.FINAL_SCRIPTSIG),f.finalScriptSig=Lr.finalScriptSig.decode(h);break;case Se.FINAL_SCRIPTWITNESS:vn("input",h.key,Se.FINAL_SCRIPTWITNESS),f.finalScriptWitness=Lr.finalScriptWitness.decode(h);break;case Se.POR_COMMITMENT:vn("input",h.key,Se.POR_COMMITMENT),f.porCommitment=Lr.porCommitment.decode(h);break;case Se.TAP_KEY_SIG:vn("input",h.key,Se.TAP_KEY_SIG),f.tapKeySig=Lr.tapKeySig.decode(h);break;case Se.TAP_SCRIPT_SIG:f.tapScriptSig===void 0&&(f.tapScriptSig=[]),f.tapScriptSig.push(Lr.tapScriptSig.decode(h));break;case Se.TAP_LEAF_SCRIPT:f.tapLeafScript===void 0&&(f.tapLeafScript=[]),f.tapLeafScript.push(Lr.tapLeafScript.decode(h));break;case Se.TAP_BIP32_DERIVATION:f.tapBip32Derivation===void 0&&(f.tapBip32Derivation=[]),f.tapBip32Derivation.push(Lr.tapBip32Derivation.decode(h));break;case Se.TAP_INTERNAL_KEY:vn("input",h.key,Se.TAP_INTERNAL_KEY),f.tapInternalKey=Lr.tapInternalKey.decode(h);break;case Se.TAP_MERKLE_ROOT:vn("input",h.key,Se.TAP_MERKLE_ROOT),f.tapMerkleRoot=Lr.tapMerkleRoot.decode(h);break;default:f.unknownKeyVals||(f.unknownKeyVals=[]),f.unknownKeyVals.push(h)}c.push(f)}for(const l of Ap(s)){const f={};for(const h of n[l])switch($a.checkPubkey(h),h.key[0]){case xr.REDEEM_SCRIPT:if(vn("output",h.key,xr.REDEEM_SCRIPT),f.redeemScript!==void 0)throw new Error("Format Error: Output has multiple REDEEM_SCRIPT");f.redeemScript=$a.redeemScript.decode(h);break;case xr.WITNESS_SCRIPT:if(vn("output",h.key,xr.WITNESS_SCRIPT),f.witnessScript!==void 0)throw new Error("Format Error: Output has multiple WITNESS_SCRIPT");f.witnessScript=$a.witnessScript.decode(h);break;case xr.BIP32_DERIVATION:f.bip32Derivation===void 0&&(f.bip32Derivation=[]),f.bip32Derivation.push($a.bip32Derivation.decode(h));break;case xr.TAP_INTERNAL_KEY:vn("output",h.key,xr.TAP_INTERNAL_KEY),f.tapInternalKey=$a.tapInternalKey.decode(h);break;case xr.TAP_TREE:vn("output",h.key,xr.TAP_TREE),f.tapTree=$a.tapTree.decode(h);break;case xr.TAP_BIP32_DERIVATION:f.tapBip32Derivation===void 0&&(f.tapBip32Derivation=[]),f.tapBip32Derivation.push($a.tapBip32Derivation.decode(h));break;default:f.unknownKeyVals||(f.unknownKeyVals=[]),f.unknownKeyVals.push(h)}u.push(f)}return{globalMap:o,inputs:c,outputs:u}}function sj({globalMap:e,inputs:t,outputs:r}){const{globalKeyVals:n,inputKeyVals:o,outputKeyVals:i}=wy({globalMap:e,inputs:t,outputs:r}),a=vE(n),s=f=>f.length===0?[Uint8Array.from([0])]:f.map(vE),c=s(o),u=s(i),l=new Uint8Array(5);return l.set([112,115,98,116,255],0),ir([l,a].concat(c,u))}const cj=(e,t)=>me(e.key,t.key);function by(e,t){const r=new Set,n=Object.entries(e).reduce((i,[a,s])=>{if(a==="unknownKeyVals")return i;const c=t[a];if(c===void 0)return i;const u=(Array.isArray(s)?s:[s]).map(c.encode);return u.map(l=>Me(l.key)).forEach(l=>{if(r.has(l))throw new Error("Serialize Error: Duplicate key: "+l);r.add(l)}),i.concat(u)},[]),o=e.unknownKeyVals?e.unknownKeyVals.filter(i=>!r.has(Me(i.key))):[];return n.concat(o).sort(cj)}function wy({globalMap:e,inputs:t,outputs:r}){return{globalKeyVals:by(e,yy),inputKeyVals:t.map(n=>by(n,Lr)),outputKeyVals:r.map(n=>by(n,$a))}}function uj(e){const t=e[0],r=wy(t),n=e.slice(1);if(n.length===0)throw new Error("Combine: Nothing to combine");const o=kE(t);if(o===void 0)throw new Error("Combine: Self missing transaction");const i=hl(r.globalKeyVals),a=r.inputKeyVals.map(hl),s=r.outputKeyVals.map(hl);for(const c of n){const u=kE(c);if(u===void 0||me(u.toBuffer(),o.toBuffer())!==0)throw new Error("Combine: One of the Psbts does not have the same transaction.");const l=wy(c);hl(l.globalKeyVals).forEach(vy(i,r.globalKeyVals,l.globalKeyVals)),l.inputKeyVals.map(hl).forEach((f,h)=>f.forEach(vy(a[h],r.inputKeyVals[h],l.inputKeyVals[h]))),l.outputKeyVals.map(hl).forEach((f,h)=>f.forEach(vy(s[h],r.outputKeyVals[h],l.outputKeyVals[h])))}return EE(o,{globalMapKeyVals:r.globalKeyVals,inputKeyVals:r.inputKeyVals,outputKeyVals:r.outputKeyVals})}function vy(e,t,r){return n=>{if(e.has(n))return;const o=r.filter(i=>Me(i.key)===n)[0];t.push(o),e.add(n)}}function kE(e){return e.globalMap.unsignedTx}function hl(e){const t=new Set;return e.forEach(r=>{const n=Me(r.key);if(t.has(n))throw new Error("Combine: KeyValue Map keys should be unique");t.add(n)}),t}function hn(e,t){const r=e[t];if(r===void 0)throw new Error(`No input #${t}`);return r}function Xf(e,t){const r=e[t];if(r===void 0)throw new Error(`No output #${t}`);return r}function Ey(e,t,r){if(e.key[0]<r)throw new Error("Use the method for your specific key instead of addUnknownKeyVal*");if(t&&t.filter(n=>me(n.key,e.key)===0).length!==0)throw new Error(`Duplicate Key: ${Me(e.key)}`)}function ky(e){let t=0;return Object.keys(e).forEach(r=>{Number(isNaN(Number(r)))&&t++}),t}function lj(e,t){let r=!1;if(t.nonWitnessUtxo||t.witnessUtxo){const n=!!t.redeemScript,o=!!t.witnessScript,i=!n||!!t.finalScriptSig,a=!o||!!t.finalScriptWitness,s=!!t.finalScriptSig||!!t.finalScriptWitness;r=i&&a&&s}if(r===!1)throw new Error(`Input #${e} has too much or too little data to clean`)}function xE(e,t,r,n){throw new Error(`Data for ${e} key ${t} is incorrect: Expected ${r} and got ${JSON.stringify(n)}`)}function xy(e){return(t,r)=>{for(const n of Object.keys(t)){const o=t[n],{canAdd:i,canAddToArray:a,check:s,expected:c}=oj[e+"s"][n]||{},u=!!a;if(s)if(u){if(!Array.isArray(o)||r[n]&&!Array.isArray(r[n]))throw new Error(`Key type ${n} must be an array`);o.every(s)||xE(e,n,c,o);const l=r[n]||[],f=new Set;if(!o.every(h=>a(l,h,f)))throw new Error("Can not add duplicate data to array");r[n]=l.concat(o)}else{if(s(o)||xE(e,n,c,o),!i(r,o))throw new Error(`Can not add duplicate data to ${e}`);r[n]=o}}}}const fj=xy("global"),AE=xy("input"),SE=xy("output");function dj(e,t){const r=e.length-1,n=hn(e,r);AE(t,n)}function hj(e,t){const r=e.length-1,n=Xf(e,r);SE(t,n)}let _E=class{constructor(t){this.inputs=[],this.outputs=[],this.globalMap={unsignedTx:t}}static fromBase64(t,r){const n=f8(t);return this.fromBuffer(n,r)}static fromHex(t,r){const n=wa(t);return this.fromBuffer(n,r)}static fromBuffer(t,r){const n=aj(t,r),o=new this(n.globalMap.unsignedTx);return Object.assign(o,n),o}toBase64(){const t=this.toBuffer();return iC(t)}toHex(){const t=this.toBuffer();return Me(t)}toBuffer(){return sj(this)}updateGlobal(t){return fj(t,this.globalMap),this}updateInput(t,r){const n=hn(this.inputs,t);return AE(r,n),this}updateOutput(t,r){const n=Xf(this.outputs,t);return SE(r,n),this}addUnknownKeyValToGlobal(t){return Ey(t,this.globalMap.unknownKeyVals,ky(zi)),this.globalMap.unknownKeyVals||(this.globalMap.unknownKeyVals=[]),this.globalMap.unknownKeyVals.push(t),this}addUnknownKeyValToInput(t,r){const n=hn(this.inputs,t);return Ey(r,n.unknownKeyVals,ky(Se)),n.unknownKeyVals||(n.unknownKeyVals=[]),n.unknownKeyVals.push(r),this}addUnknownKeyValToOutput(t,r){const n=Xf(this.outputs,t);return Ey(r,n.unknownKeyVals,ky(xr)),n.unknownKeyVals||(n.unknownKeyVals=[]),n.unknownKeyVals.push(r),this}addInput(t){this.globalMap.unsignedTx.addInput(t),this.inputs.push({unknownKeyVals:[]});const r=t.unknownKeyVals||[],n=this.inputs.length-1;if(!Array.isArray(r))throw new Error("unknownKeyVals must be an Array");return r.forEach(o=>this.addUnknownKeyValToInput(n,o)),dj(this.inputs,t),this}addOutput(t){this.globalMap.unsignedTx.addOutput(t),this.outputs.push({unknownKeyVals:[]});const r=t.unknownKeyVals||[],n=this.outputs.length-1;if(!Array.isArray(r))throw new Error("unknownKeyVals must be an Array");return r.forEach(o=>this.addUnknownKeyValToOutput(n,o)),hj(this.outputs,t),this}clearFinalizedInput(t){const r=hn(this.inputs,t);lj(t,r);for(const n of Object.keys(r))["witnessUtxo","nonWitnessUtxo","finalScriptSig","finalScriptWitness","unknownKeyVals"].includes(n)||delete r[n];return this}combine(...t){const r=uj([this].concat(t));return Object.assign(this,r),this}getTransaction(){return this.globalMap.unsignedTx.toBuffer()}};function Wc(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}const pj=Wc(pp),gj=Wc(z8),mj=Wc(Ff),Sp=Wc(Mf),$E=Wc(Vf),TE=Wc(ul),IE=Wc(Wf);function _p(e){let t=new Uint8Array(0);function r(a){t=ir([t,a])}function n(a){const s=t.length,c=Io(a);t=ir([t,new Uint8Array(c)]),ws(a,t,s)}function o(a){n(a.length),r(a)}function i(a){n(a.length),a.forEach(o)}return i(e),t}function OE(e,t){const r=xa(e),n=e.slice(1,33),o=sr(t);if(o===null)throw new Error("Unknown script error");return o.findIndex(i=>typeof i=="number"?!1:me(e,i)===0||me(r,i)===0||me(n,i)===0)}function $p(e,t){return OE(e,t)!==-1}function yj(e,t){return bj(e).some(r=>PE(r,Hf.decode,t))}function PE(e,t,r){const{hashType:n}=t(e),o=[];switch(n&kr.SIGHASH_ANYONECANPAY&&o.push("addInput"),n&31){case kr.SIGHASH_ALL:break;case kr.SIGHASH_SINGLE:case kr.SIGHASH_NONE:o.push("addOutput"),o.push("setInputSequence");break}return o.indexOf(r)===-1}function bj(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=wj(e)}else t=e.partialSig;return t.map(r=>r.signature)}function wj(e){const t=e.finalScriptSig?sr(e.finalScriptSig)||[]:[],r=e.finalScriptWitness?sr(e.finalScriptWitness)||[]:[];return t.concat(r).filter(n=>n instanceof Uint8Array&&ka(n)).map(n=>({signature:n}))}const Yf=e=>e.length===32?e:e.slice(1,33);function BE(e,t,r){const n=Cj(t,e,r);try{const o=Pj(t,n).concat(n.script).concat(n.controlBlock);return{finalScriptWitness:_p(o)}}catch(o){throw new Error(`Can not finalize taproot input #${e}: ${o}`)}}function Tp(e,t){const r=t?Uint8Array.from([t]):Uint8Array.from([]);return ir([e,r])}function ti(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&IE(e.witnessUtxo.script))}function Ay(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t)}function CE(e,t,r){Tj(e,t,r),Oj(e,t,r)}function UE(e,t,r){Ij(e,t,r),vj(e,t)}function vj(e,t){if(!t.tapTree&&!t.tapInternalKey)return;const r=t.tapInternalKey||e.tapInternalKey,n=t.tapTree||e.tapTree;if(r){const{script:o}=e,i=Ej(r,n);if(o&&me(i,o)!==0)throw new Error("Error adding output. Script or address mismatch.")}}function Ej(e,t){const r=t&&kj(t.leaves),{output:n}=Wf({internalPubkey:e,scriptTree:r});return n}function kj(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:$j(e)}function xj(e,t){return Sj(e).some(r=>PE(r,Aj,t))}function Aj(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||kr.SIGHASH_DEFAULT}}function Sj(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(r=>r.signature)),!t.length){const r=_j(e.finalScriptWitness);r&&t.push(r)}return t}function _j(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function $j(e){let t;for(const r of e)if(t=Sy(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function Sy(e,t,r=0){if(r>bU)throw new Error("Max taptree depth exceeded.");if(e.depth===r)return t?void 0:{output:e.script,version:e.leafVersion};if(W1(t))return;const n=Sy(e,t&&t[0],r+1);if(n)return[n,t&&t[1]];const o=Sy(e,t&&t[1],r+1);if(o)return[t&&t[0],o]}function Tj(e,t,r){const n=ti(e)&&pl(t),o=pl(e)&&ti(t),i=e===t&&ti(t)&&pl(t);if(n||o||i)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function Ij(e,t,r){const n=Ay(e)&&pl(t),o=pl(e)&&Ay(t),i=e===t&&Ay(t)&&pl(t);if(n||o||i)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function Oj(e,t,r){if(t.tapMerkleRoot){const n=(t.tapLeafScript||[]).every(i=>_y(i,t.tapMerkleRoot)),o=(e.tapLeafScript||[]).every(i=>_y(i,t.tapMerkleRoot));if(!n||!o)throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}else if(e.tapMerkleRoot&&!(t.tapLeafScript||[]).every(n=>_y(n,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}function _y(e,t){if(!t)return!0;const r=_a({output:e.script,version:e.leafVersion}),n=uy(e.controlBlock,r);return me(n,t)===0}function Pj(e,t){const r=_a({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(n=>me(n.leafHash,r)===0).map(n=>Bj(t.script,n)).sort((n,o)=>o.positionInScript-n.positionInScript).map(n=>n.signature)}function Bj(e,t){return Object.assign({positionInScript:OE(t.pubkey,e)},t)}function Cj(e,t,r){if(!e.tapScriptSig||!e.tapScriptSig.length)throw new Error(`Can not finalize taproot input #${t}. No tapleaf script signature provided.`);const n=(e.tapLeafScript||[]).sort((o,i)=>o.controlBlock.length-i.controlBlock.length).find(o=>Uj(o,e.tapScriptSig,r));if(!n)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return n}function Uj(e,t,r){const n=_a({output:e.script,version:e.leafVersion});return(!r||me(n,r)===0)&&t.find(o=>me(o.leafHash,n)===0)!==void 0}function pl(e){return e&&!!(e.redeemScript||e.witnessScript||e.bip32Derivation&&e.bip32Derivation.length)}const Nj={network:Yo,maximumFeeRate:5e3};let Hr=class X4{constructor(t={},r=new _E(new NE)){Te(this,"data"),Te(this,"__CACHE"),Te(this,"opts"),this.data=r,this.opts=Object.assign({},Nj,t),this.__CACHE={__NON_WITNESS_UTXO_TX_CACHE:[],__NON_WITNESS_UTXO_BUF_CACHE:[],__TX_IN_CACHE:{},__TX:this.data.globalMap.unsignedTx.tx,__UNSAFE_SIGN_NONSEGWIT:!1},this.data.inputs.length===0&&this.setVersion(2);const n=(o,i,a,s)=>Object.defineProperty(o,i,{enumerable:a,writable:s});n(this,"__CACHE",!1,!0),n(this,"opts",!1,!0)}static fromBase64(t,r={}){const n=f8(t);return this.fromBuffer(n,r)}static fromHex(t,r={}){const n=wa(t);return this.fromBuffer(n,r)}static fromBuffer(t,r={}){const n=_E.fromBuffer(t,jj),o=new X4(r,n);return Fj(o.__CACHE.__TX,o.__CACHE),o}get inputCount(){return this.data.inputs.length}get version(){return this.__CACHE.__TX.version}set version(t){this.setVersion(t)}get locktime(){return this.__CACHE.__TX.locktime}set locktime(t){this.setLocktime(t)}get txInputs(){return this.__CACHE.__TX.ins.map(t=>({hash:tE(t.hash),index:t.index,sequence:t.sequence}))}get txOutputs(){return this.__CACHE.__TX.outs.map(t=>{let r;try{r=Zf(t.script,this.opts.network)}catch{}return{script:tE(t.script),value:t.value,address:r}})}combine(...t){return this.data.combine(...t.map(r=>r.data)),this}clone(){const t=X4.fromBuffer(this.data.toBuffer());return t.opts=JSON.parse(JSON.stringify(this.opts)),t}setMaximumFeeRate(t){Ip(t),this.opts.maximumFeeRate=t}setVersion(t){Ip(t),Jf(this.data.inputs,"setVersion");const r=this.__CACHE;return r.__TX.version=t,r.__EXTRACTED_TX=void 0,this}setLocktime(t){Ip(t),Jf(this.data.inputs,"setLocktime");const r=this.__CACHE;return r.__TX.locktime=t,r.__EXTRACTED_TX=void 0,this}setInputSequence(t,r){Ip(r),Jf(this.data.inputs,"setInputSequence");const n=this.__CACHE;if(n.__TX.ins.length<=t)throw new Error("Input index too high");return n.__TX.ins[t].sequence=r,n.__EXTRACTED_TX=void 0,this}addInputs(t){return t.forEach(r=>this.addInput(r)),this}addInput(t){if(arguments.length>1||!t||t.hash===void 0||t.index===void 0)throw new Error("Invalid arguments for Psbt.addInput. Requires single object with at least [hash] and [index]");CE(t,t,"addInput"),Jf(this.data.inputs,"addInput"),t.witnessScript&&Bp(t.witnessScript);const r=this.__CACHE;this.data.addInput(t);const n=r.__TX.ins[r.__TX.ins.length-1];HE(r,n);const o=this.data.inputs.length-1,i=this.data.inputs[o];return i.nonWitnessUtxo&&Iy(this.__CACHE,i,o),r.__FEE=void 0,r.__FEE_RATE=void 0,r.__EXTRACTED_TX=void 0,this}addOutputs(t){return t.forEach(r=>this.addOutput(r)),this}addOutput(t){if(arguments.length>1||!t||t.value===void 0||t.address===void 0&&t.script===void 0)throw new Error("Invalid arguments for Psbt.addOutput. Requires single object with at least [script or address] and [value]");Jf(this.data.inputs,"addOutput");const{address:r}=t;if(typeof r=="string"){const{network:o}=this.opts,i=hy(r,o);t=Object.assign({},t,{script:i})}UE(t,t,"addOutput");const n=this.__CACHE;return this.data.addOutput(t),n.__FEE=void 0,n.__FEE_RATE=void 0,n.__EXTRACTED_TX=void 0,this}extractTransaction(t){if(!this.data.inputs.every(zE))throw new Error("Not finalized");const r=this.__CACHE;if(t||Rj(this,r,this.opts),r.__EXTRACTED_TX)return r.__EXTRACTED_TX;const n=r.__TX.clone();return JE(this.data.inputs,n,r,!0),n}getFeeRate(){return qE("__FEE_RATE","fee rate",this.data.inputs,this.__CACHE)}getFee(){return qE("__FEE","fee",this.data.inputs,this.__CACHE)}finalizeAllInputs(){return hn(this.data.inputs,0),Qf(this.data.inputs.length).forEach(t=>this.finalizeInput(t)),this}finalizeInput(t,r){const n=hn(this.data.inputs,t);return ti(n)?this._finalizeTaprootInput(t,n,void 0,r):this._finalizeInput(t,n,r)}finalizeTaprootInput(t,r,n=BE){const o=hn(this.data.inputs,t);if(ti(o))return this._finalizeTaprootInput(t,o,r,n);throw new Error(`Cannot finalize input #${t}. Not Taproot.`)}_finalizeInput(t,r,n=Dj){const{script:o,isP2SH:i,isP2WSH:a,isSegwit:s}=Vj(t,r,this.__CACHE);if(!o)throw new Error(`No script found for input #${t}`);Lj(r);const{finalScriptSig:c,finalScriptWitness:u}=n(t,r,o,s,i,a);if(c&&this.data.updateInput(t,{finalScriptSig:c}),u&&this.data.updateInput(t,{finalScriptWitness:u}),!c&&!u)throw new Error(`Unknown error finalizing input #${t}`);return this.data.clearFinalizedInput(t),this}_finalizeTaprootInput(t,r,n,o=BE){if(!r.witnessUtxo)throw new Error(`Cannot finalize input #${t}. Missing withness utxo.`);if(r.tapKeySig){const i=Wf({output:r.witnessUtxo.script,signature:r.tapKeySig}),a=_p(i.witness);this.data.updateInput(t,{finalScriptWitness:a})}else{const{finalScriptWitness:i}=o(t,r,n);this.data.updateInput(t,{finalScriptWitness:i})}return this.data.clearFinalizedInput(t),this}getInputType(t){const r=hn(this.data.inputs,t),n=QE(t,r,this.__CACHE),o=Pp(n,t,"input",r.redeemScript||Yj(r.finalScriptSig),r.witnessScript||Jj(r.finalScriptWitness)),i=o.type==="raw"?"":o.type+"-",a=t5(o.meaningfulScript);return i+a}inputHasPubkey(t,r){const n=hn(this.data.inputs,t);return Zj(r,n,t,this.__CACHE)}inputHasHDKey(t,r){const n=hn(this.data.inputs,t),o=RE(r);return!!n.bip32Derivation&&n.bip32Derivation.some(o)}outputHasPubkey(t,r){const n=Xf(this.data.outputs,t);return Xj(r,n,t,this.__CACHE)}outputHasHDKey(t,r){const n=Xf(this.data.outputs,t),o=RE(r);return!!n.bip32Derivation&&n.bip32Derivation.some(o)}validateSignaturesOfAllInputs(t){return hn(this.data.inputs,0),Qf(this.data.inputs.length).map(r=>this.validateSignaturesOfInput(r,t)).reduce((r,n)=>n===!0&&r,!0)}validateSignaturesOfInput(t,r,n){const o=this.data.inputs[t];return ti(o)?this.validateSignaturesOfTaprootInput(t,r,n):this._validateSignaturesOfInput(t,r,n)}_validateSignaturesOfInput(t,r,n){const o=this.data.inputs[t],i=(o||{}).partialSig;if(!o||!i||i.length<1)throw new Error("No signatures to validate");if(typeof r!="function")throw new Error("Need validator function to validate signatures");const a=n?i.filter(f=>me(f.pubkey,n)===0):i;if(a.length<1)throw new Error("No signatures for this pubkey");const s=[];let c,u,l;for(const f of a){const h=Hf.decode(f.signature),{hash:g,script:y}=l!==h.hashType?VE(t,Object.assign({},o,{sighashType:h.hashType}),this.__CACHE,!0):{hash:c,script:u};l=h.hashType,c=g,u=y,LE(f.pubkey,y,"verify"),s.push(r(f.pubkey,g,h.signature))}return s.every(f=>f===!0)}validateSignaturesOfTaprootInput(t,r,n){const o=this.data.inputs[t],i=(o||{}).tapKeySig,a=(o||{}).tapScriptSig;if(!o&&!i&&!(a&&!a.length))throw new Error("No signatures to validate");if(typeof r!="function")throw new Error("Need validator function to validate signatures");n=n&&Yf(n);const s=n?Ty(t,o,this.data.inputs,n,this.__CACHE):qj(t,o,this.data.inputs,this.__CACHE);if(!s.length)throw new Error("No signatures for this pubkey");const c=s.find(l=>!l.leafHash);let u=0;if(i&&c){if(!r(c.pubkey,c.hash,WE(i)))return!1;u++}if(a)for(const l of a){const f=s.find(h=>me(h.pubkey,l.pubkey)===0);if(f){if(!r(l.pubkey,f.hash,WE(l.signature)))return!1;u++}}return u>0}signAllInputsHD(t,r=[kr.SIGHASH_ALL]){if(!t||!t.publicKey||!t.fingerprint)throw new Error("Need HDSigner to sign input");const n=[];for(const o of Qf(this.data.inputs.length))try{this.signInputHD(o,t,r),n.push(!0)}catch{n.push(!1)}if(n.every(o=>o===!1))throw new Error("No inputs were signed");return this}signAllInputsHDAsync(t,r=[kr.SIGHASH_ALL]){return new Promise((n,o)=>{if(!t||!t.publicKey||!t.fingerprint)return o(new Error("Need HDSigner to sign input"));const i=[],a=[];for(const s of Qf(this.data.inputs.length))a.push(this.signInputHDAsync(s,t,r).then(()=>{i.push(!0)},()=>{i.push(!1)}));return Promise.all(a).then(()=>{if(i.every(s=>s===!1))return o(new Error("No inputs were signed"));n()})})}signInputHD(t,r,n=[kr.SIGHASH_ALL]){if(!r||!r.publicKey||!r.fingerprint)throw new Error("Need HDSigner to sign input");return XE(t,this.data.inputs,r).forEach(o=>this.signInput(t,o,n)),this}signInputHDAsync(t,r,n=[kr.SIGHASH_ALL]){return new Promise((o,i)=>{if(!r||!r.publicKey||!r.fingerprint)return i(new Error("Need HDSigner to sign input"));const a=XE(t,this.data.inputs,r).map(s=>this.signInputAsync(t,s,n));return Promise.all(a).then(()=>{o()}).catch(i)})}signAllInputs(t,r){if(!t||!t.publicKey)throw new Error("Need Signer to sign input");const n=[];for(const o of Qf(this.data.inputs.length))try{this.signInput(o,t,r),n.push(!0)}catch{n.push(!1)}if(n.every(o=>o===!1))throw new Error("No inputs were signed");return this}signAllInputsAsync(t,r){return new Promise((n,o)=>{if(!t||!t.publicKey)return o(new Error("Need Signer to sign input"));const i=[],a=[];for(const[s]of this.data.inputs.entries())a.push(this.signInputAsync(s,t,r).then(()=>{i.push(!0)},()=>{i.push(!1)}));return Promise.all(a).then(()=>{if(i.every(s=>s===!1))return o(new Error("No inputs were signed"));n()})})}signInput(t,r,n){if(!r||!r.publicKey)throw new Error("Need Signer to sign input");const o=hn(this.data.inputs,t);return ti(o)?this._signTaprootInput(t,o,r,void 0,n):this._signInput(t,r,n)}signTaprootInput(t,r,n,o){if(!r||!r.publicKey)throw new Error("Need Signer to sign input");const i=hn(this.data.inputs,t);if(ti(i))return this._signTaprootInput(t,i,r,n,o);throw new Error(`Input #${t} is not of type Taproot.`)}_signInput(t,r,n=[kr.SIGHASH_ALL]){const{hash:o,sighashType:i}=ME(this.data.inputs,t,r.publicKey,this.__CACHE,n),a=[{pubkey:r.publicKey,signature:Hf.encode(r.sign(o),i)}];return this.data.updateInput(t,{partialSig:a}),this}_signTaprootInput(t,r,n,o,i=[kr.SIGHASH_DEFAULT]){const a=this.checkTaprootHashesForSig(t,r,n,o,i),s=a.filter(u=>!u.leafHash).map(u=>Tp(n.signSchnorr(u.hash),r.sighashType))[0],c=a.filter(u=>!!u.leafHash).map(u=>({pubkey:Yf(n.publicKey),signature:Tp(n.signSchnorr(u.hash),r.sighashType),leafHash:u.leafHash}));return s&&this.data.updateInput(t,{tapKeySig:s}),c.length&&this.data.updateInput(t,{tapScriptSig:c}),this}signInputAsync(t,r,n){return Promise.resolve().then(()=>{if(!r||!r.publicKey)throw new Error("Need Signer to sign input");const o=hn(this.data.inputs,t);return ti(o)?this._signTaprootInputAsync(t,o,r,void 0,n):this._signInputAsync(t,r,n)})}signTaprootInputAsync(t,r,n,o){return Promise.resolve().then(()=>{if(!r||!r.publicKey)throw new Error("Need Signer to sign input");const i=hn(this.data.inputs,t);if(ti(i))return this._signTaprootInputAsync(t,i,r,n,o);throw new Error(`Input #${t} is not of type Taproot.`)})}_signInputAsync(t,r,n=[kr.SIGHASH_ALL]){const{hash:o,sighashType:i}=ME(this.data.inputs,t,r.publicKey,this.__CACHE,n);return Promise.resolve(r.sign(o)).then(a=>{const s=[{pubkey:r.publicKey,signature:Hf.encode(a,i)}];this.data.updateInput(t,{partialSig:s})})}async _signTaprootInputAsync(t,r,n,o,i=[kr.SIGHASH_DEFAULT]){const a=this.checkTaprootHashesForSig(t,r,n,o,i),s=[],c=a.filter(l=>!l.leafHash)[0];if(c){const l=Promise.resolve(n.signSchnorr(c.hash)).then(f=>({tapKeySig:Tp(f,r.sighashType)}));s.push(l)}const u=a.filter(l=>!!l.leafHash);if(u.length){const l=u.map(f=>Promise.resolve(n.signSchnorr(f.hash)).then(h=>({tapScriptSig:[{pubkey:Yf(n.publicKey),signature:Tp(h,r.sighashType),leafHash:f.leafHash}]})));s.push(...l)}return Promise.all(s).then(l=>{l.forEach(f=>this.data.updateInput(t,f))})}checkTaprootHashesForSig(t,r,n,o,i){if(typeof n.signSchnorr!="function")throw new Error(`Need Schnorr Signer to sign taproot input #${t}.`);const a=Ty(t,r,this.data.inputs,n.publicKey,this.__CACHE,o,i);if(!a||!a.length)throw new Error(`Can not sign for input #${t} with the key ${Me(n.publicKey)}`);return a}toBuffer(){return $y(this.__CACHE),this.data.toBuffer()}toHex(){return $y(this.__CACHE),this.data.toHex()}toBase64(){return $y(this.__CACHE),this.data.toBase64()}updateGlobal(t){return this.data.updateGlobal(t),this}updateInput(t,r){return r.witnessScript&&Bp(r.witnessScript),CE(this.data.inputs[t],r,"updateInput"),this.data.updateInput(t,r),r.nonWitnessUtxo&&Iy(this.__CACHE,this.data.inputs[t],t),this}updateOutput(t,r){const n=this.data.outputs[t];return UE(n,r,"updateOutput"),this.data.updateOutput(t,r),this}addUnknownKeyValToGlobal(t){return this.data.addUnknownKeyValToGlobal(t),this}addUnknownKeyValToInput(t,r){return this.data.addUnknownKeyValToInput(t,r),this}addUnknownKeyValToOutput(t,r){return this.data.addUnknownKeyValToOutput(t,r),this}clearFinalizedInput(t){return this.data.clearFinalizedInput(t),this}};const jj=e=>new NE(e);let NE=class{constructor(t=Uint8Array.from([2,0,0,0,0,0,0,0,0,0])){Te(this,"tx"),this.tx=kr.fromBuffer(t),Hj(this.tx),Object.defineProperty(this,"tx",{enumerable:!1,writable:!0})}getInputOutputCounts(){return{inputCount:this.tx.ins.length,outputCount:this.tx.outs.length}}addInput(t){if(t.hash===void 0||t.index===void 0||!(t.hash instanceof Uint8Array)&&typeof t.hash!="string"||typeof t.index!="number")throw new Error("Error adding input.");const r=typeof t.hash=="string"?cy(wa(t.hash)):t.hash;this.tx.addInput(r,t.index,t.sequence)}addOutput(t){if(t.script===void 0||t.value===void 0||!(t.script instanceof Uint8Array)||typeof t.value!="bigint")throw new Error("Error adding output.");this.tx.addOutput(t.script,t.value)}toBuffer(){return this.tx.toBuffer()}};function zj(e,t,r){switch(r){case"pubkey":case"pubkeyhash":case"witnesspubkeyhash":return jE(1,e.partialSig);case"multisig":const n=pp({output:t});return jE(n.m,e.partialSig,n.pubkeys);default:return!1}}function $y(e){if(e.__UNSAFE_SIGN_NONSEGWIT!==!1)throw new Error("Not BIP174 compliant, can not export")}function jE(e,t,r){if(!t)return!1;let n;if(r?n=r.map(o=>{const i=Qj(o);return t.find(a=>me(a.pubkey,i)===0)}).filter(o=>!!o):n=t,n.length>e)throw new Error("Too many signatures");return n.length===e}function zE(e){return!!e.finalScriptSig||!!e.finalScriptWitness}function RE(e){return t=>!(me(e.fingerprint,t.masterFingerprint)||me(e.derivePath(t.path).publicKey,t.pubkey))}function Ip(e){if(typeof e!="number"||e!==Math.floor(e)||e>4294967295||e<0)throw new Error("Invalid 32 bit integer")}function Rj(e,t,r){const n=t.__FEE_RATE||e.getFeeRate(),o=t.__EXTRACTED_TX.virtualSize(),i=n*o;if(n>=r.maximumFeeRate)throw new Error(`Warning: You are paying around ${(i/1e8).toFixed(8)} in fees, which is ${n} satoshi per byte for a transaction with a VSize of ${o} bytes (segwit counted as 0.25 byte per byte). Use setMaximumFeeRate method to raise your threshold, or pass true to the first arg of extractTransaction.`)}function Jf(e,t){e.forEach(r=>{if(ti(r)?xj(r,t):yj(r,t))throw new Error("Can not modify transaction, signatures exist.")})}function Lj(e){if(!e.sighashType||!e.partialSig)return;const{partialSig:t,sighashType:r}=e;t.forEach(n=>{const{hashType:o}=Hf.decode(n.signature);if(r!==o)throw new Error("Signature sighash does not match input sighash type")})}function LE(e,t,r){if(!$p(e,t))throw new Error(`Can not ${r} for this input with the key ${Me(e)}`)}function Hj(e){if(!e.ins.every(t=>t.script&&t.script.length===0&&t.witness&&t.witness.length===0))throw new Error("Format Error: Transaction ScriptSigs are not empty")}function Fj(e,t){e.ins.forEach(r=>{HE(t,r)})}function HE(e,t){const r=Me(cy(Uint8Array.from(t.hash)))+":"+t.index;if(e.__TX_IN_CACHE[r])throw new Error("Duplicate input detected.");e.__TX_IN_CACHE[r]=1}function FE(e,t){return(r,n,o,i)=>{const a=e({redeem:{output:o}}).output;if(me(n,a))throw new Error(`${t} for ${i} #${r} doesn't match the scriptPubKey in the prevout`)}}const DE=FE(ul,"Redeem script"),KE=FE(Vf,"Witness script");function qE(e,t,r,n){if(!r.every(zE))throw new Error(`PSBT must be finalized to calculate ${t}`);if(e==="__FEE_RATE"&&n.__FEE_RATE)return n.__FEE_RATE;if(e==="__FEE"&&n.__FEE)return n.__FEE;let o,i=!0;if(n.__EXTRACTED_TX?(o=n.__EXTRACTED_TX,i=!1):o=n.__TX.clone(),JE(r,o,n,i),e==="__FEE_RATE")return n.__FEE_RATE;if(e==="__FEE")return n.__FEE}function Dj(e,t,r,n,o,i){const a=t5(r);if(!zj(t,r,a))throw new Error(`Can not finalize input #${e}`);return Kj(r,a,t.partialSig,n,o,i)}function Kj(e,t,r,n,o,i){let a,s;const c=Mj(e,t,r),u=i?Vf({redeem:c}):null,l=o?ul({redeem:u||c}):null;return n?(u?s=_p(u.witness):s=_p(c.witness),l&&(a=l.input)):l?a=l.input:a=c.input,{finalScriptSig:a,finalScriptWitness:s}}function ME(e,t,r,n,o){const i=hn(e,t),{hash:a,sighashType:s,script:c}=VE(t,i,n,!1,o);return LE(r,c,"sign"),{hash:a,sighashType:s}}function VE(e,t,r,n,o){const i=r.__TX,a=t.sighashType||kr.SIGHASH_ALL;ZE(a,o);let s,c;if(t.nonWitnessUtxo){const f=Op(r,t,e),h=i.ins[e].hash,g=f.getHash();if(me(h,g)!==0)throw new Error(`Non-witness UTXO hash for input #${e} doesn't match the hash specified in the prevout`);const y=i.ins[e].index;c=f.outs[y]}else if(t.witnessUtxo)c=t.witnessUtxo;else throw new Error("Need a Utxo input item for signing");const{meaningfulScript:u,type:l}=Pp(c.script,e,"input",t.redeemScript,t.witnessScript);if(["p2sh-p2wsh","p2wsh"].indexOf(l)>=0)s=i.hashForWitnessV0(e,u,c.value,a);else if(Sp(u)){const f=Ff({hash:u.slice(2)}).output;s=i.hashForWitnessV0(e,f,c.value,a)}else{if(t.nonWitnessUtxo===void 0&&r.__UNSAFE_SIGN_NONSEGWIT===!1)throw new Error(`Input #${e} has witnessUtxo but non-segwit script: ${Me(u)}`);!n&&r.__UNSAFE_SIGN_NONSEGWIT!==!1&&console.warn(`Warning: Signing non-segwit inputs without the full parent transaction means there is a chance that a miner could feed you incorrect information to trick you into paying large fees. This behavior is the same as Psbt's predecessor (TransactionBuilder - now removed) when signing non-segwit scripts. You are not able to export this Psbt with toBuffer|toBase64|toHex since it is not BIP174 compliant.
4
4
  *********************
package/package.json CHANGED
@@ -20,7 +20,7 @@
20
20
  "url": "https://github.com/omnisat/lasereyes-mono.git"
21
21
  },
22
22
  "private": false,
23
- "version": "0.0.123",
23
+ "version": "0.0.125",
24
24
  "type": "module",
25
25
  "main": "./dist/index.umd.cjs",
26
26
  "module": "./dist/index.js",
@@ -41,8 +41,8 @@
41
41
  "vite-plugin-dts": "^4.2.1"
42
42
  },
43
43
  "dependencies": {
44
- "@omnisat/lasereyes-core": "0.0.46",
45
- "@omnisat/lasereyes-react": "0.0.40",
44
+ "@omnisat/lasereyes-core": "0.0.47",
45
+ "@omnisat/lasereyes-react": "0.0.42",
46
46
  "bip39": "^3.1.0"
47
47
  },
48
48
  "license": "MIT",