@omnisat/lasereyes 0.0.117 → 0.0.118
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 +4 -0
- package/dist/index.umd.cjs +1 -1
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -147,6 +147,10 @@ const ul = "oyl", Hc = "unisat", ic = "xverse", ll = "phantom", fl = "leather",
|
|
|
147
147
|
name: "orange",
|
|
148
148
|
url: "https://www.orangewallet.com/"
|
|
149
149
|
},
|
|
150
|
+
phantom: {
|
|
151
|
+
name: "phantom",
|
|
152
|
+
url: "https://phantom.app/download"
|
|
153
|
+
},
|
|
150
154
|
oyl: {
|
|
151
155
|
name: "oyl",
|
|
152
156
|
url: "https://www.oyl.io/#get-wallet"
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(se,Qo){typeof exports=="object"&&typeof module<"u"?Qo(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],Qo):(se=typeof globalThis<"u"?globalThis:se||self,Qo(se.lasereyes={},se.React))})(this,function(se,Qo){"use strict";"use client";var BB=Object.defineProperty,UB=(e,t,r)=>t in e?BB(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Te=(e,t,r)=>UB(e,typeof t!="symbol"?t+"":t,r);function CB(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 Ky=Symbol("clean"),ei=[],ds=0;const ep=4;let qy=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=ds+ep;i<ei.length;)ei[i]===n?ei.splice(i,ep):i+=ep;let o=t.indexOf(n);~o&&(t.splice(o,1),--r.lc||r.off())}},notify(n,o){let i=!ei.length;for(let a of t)ei.push(a,r.value,n,o);if(i){for(ds=0;ds<ei.length;ds+=ep)ei[ds](ei[ds+1],ei[ds+2],ei[ds+3]);ei.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[Ky]=()=>{t=[],r.lc=0,r.off()}),r};const NB=5,rl=6,tp=10;let jB=(e,t,r,n)=>(e.events=e.events||{},e.events[r+tp]||(e.events[r+tp]=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+tp](),delete e.events[r+tp])}),zB=1e3,RB=(e,t)=>jB(e,r=>{let n=t(r);n&&e.events[rl].push(n)},NB,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]=[]}},zB)},process.env.NODE_ENV!=="production"){let i=e[Ky];e[Ky]=()=>{for(let a of e.events[rl])a();e.events[rl]=[],e.active=!1,i()}}return()=>{e.listen=n,e.off=o}});function Ui(e,t,r){let n=new Set([...t,void 0]);return e.listen((o,i,a)=>{n.has(a)&&r(o,i,a)})}function e8(e,t,r){let n=Ui(e,t,r);return r(e.value),n}let t8=(e={})=>{let t=qy(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 Lc="oyl",hs="unisat",ya="xverse",Hc="phantom",Dc="leather",ba="magic-eden",Kc="okx",qc="wizz",ps="orange",r8="op_net",nl="p2tr",n8="p2pkh",o8="p2sh-p2wpkh",rp="p2wpkh",LB="p2psh",i8="p2wsh",Fy="p2sh",HB={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/"},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"}},np="defaultWallet",$o={messagePrefix:`Bitcoin Signed Message:
|
|
1
|
+
(function(se,Qo){typeof exports=="object"&&typeof module<"u"?Qo(exports,require("react")):typeof define=="function"&&define.amd?define(["exports","react"],Qo):(se=typeof globalThis<"u"?globalThis:se||self,Qo(se.lasereyes={},se.React))})(this,function(se,Qo){"use strict";"use client";var BB=Object.defineProperty,UB=(e,t,r)=>t in e?BB(e,t,{enumerable:!0,configurable:!0,writable:!0,value:r}):e[t]=r,Te=(e,t,r)=>UB(e,typeof t!="symbol"?t+"":t,r);function CB(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 Ky=Symbol("clean"),ei=[],ds=0;const ep=4;let qy=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=ds+ep;i<ei.length;)ei[i]===n?ei.splice(i,ep):i+=ep;let o=t.indexOf(n);~o&&(t.splice(o,1),--r.lc||r.off())}},notify(n,o){let i=!ei.length;for(let a of t)ei.push(a,r.value,n,o);if(i){for(ds=0;ds<ei.length;ds+=ep)ei[ds](ei[ds+1],ei[ds+2],ei[ds+3]);ei.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[Ky]=()=>{t=[],r.lc=0,r.off()}),r};const NB=5,rl=6,tp=10;let jB=(e,t,r,n)=>(e.events=e.events||{},e.events[r+tp]||(e.events[r+tp]=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+tp](),delete e.events[r+tp])}),zB=1e3,RB=(e,t)=>jB(e,r=>{let n=t(r);n&&e.events[rl].push(n)},NB,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]=[]}},zB)},process.env.NODE_ENV!=="production"){let i=e[Ky];e[Ky]=()=>{for(let a of e.events[rl])a();e.events[rl]=[],e.active=!1,i()}}return()=>{e.listen=n,e.off=o}});function Ui(e,t,r){let n=new Set([...t,void 0]);return e.listen((o,i,a)=>{n.has(a)&&r(o,i,a)})}function e8(e,t,r){let n=Ui(e,t,r);return r(e.value),n}let t8=(e={})=>{let t=qy(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 Lc="oyl",hs="unisat",ya="xverse",Hc="phantom",Dc="leather",ba="magic-eden",Kc="okx",qc="wizz",ps="orange",r8="op_net",nl="p2tr",n8="p2pkh",o8="p2sh-p2wpkh",rp="p2wpkh",LB="p2psh",i8="p2wsh",Fy="p2sh",HB={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"}},np="defaultWallet",$o={messagePrefix:`Bitcoin Signed Message:
|
|
2
2
|
`,bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},DB={messagePrefix:`Bitcoin Signed Message:
|
|
3
3
|
`,bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239};function KB(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 FB(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 Ht={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},a8={};for(const e of Object.keys(Ht)){const t=Ht[e];a8[t]=e}const op="0123456789abcdefABCDEF",ip=op.split("").map(e=>e.codePointAt(0)),ap=Array(256).fill(!0).map((e,t)=>{const r=String.fromCodePoint(t),n=op.indexOf(r);return n<0?void 0:n<16?n:n-6}),s8=new TextEncoder,c8=new TextDecoder;function MB(e){return c8.decode(e)}function VB(e){return s8.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?ZB(t):GB(t)}function GB(e){let t="";for(let r=0;r<e.length;++r)t+=op[ap[ip[e[r]>>4]]],t+=op[ap[ip[e[r]&15]]];return t}function ZB(e){const t=new Uint8Array(e.length*2);for(let r=0;r<e.length;++r)t[r*2]=ip[e[r]>>4],t[r*2+1]=ip[e[r]&15];return c8.decode(t)}function wa(e){const t=s8.encode(e||""),r=new Uint8Array(Math.floor(t.length/2));let n;for(n=0;n<r.length;n++){const o=ap[t[n*2]],i=ap[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 WB(e){return btoa(String.fromCharCode(...e))}function u8(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 uo(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 XB(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 Hf(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 YB(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 JB(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 l8(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 f8(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 QB(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 d8(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 h8(e){return e<Ht.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}function eU(e,t,r){const n=h8(t);return n===1?uo(e,r,t):n===2?(uo(e,r,Ht.OP_PUSHDATA1),uo(e,r+1,t)):n===3?(uo(e,r,Ht.OP_PUSHDATA2),XB(e,r+1,t,"LE")):(uo(e,r,Ht.OP_PUSHDATA4),Hf(e,r+1,t,"LE")),n}function tU(e,t){const r=va(e,t);let n,o;if(r<Ht.OP_PUSHDATA1)n=r,o=1;else if(r===Ht.OP_PUSHDATA1){if(t+2>e.length)return null;n=va(e,t+1),o=2}else if(r===Ht.OP_PUSHDATA2){if(t+3>e.length)return null;n=JB(e,t+1,"LE"),o=3}else{if(t+5>e.length)return null;if(r!==Ht.OP_PUSHDATA4)throw new Error("Unexpected opcode");n=ol(e,t+1,"LE"),o=5}return{opcode:r,number:n,size:o}}function rU(e){return e>2147483647?5:e>8388607?4:e>32767?3:e>127?2:e>0?1:0}function nU(e){let t=Math.abs(e);const r=rU(t),n=new Uint8Array(r),o=e<0;for(let i=0;i<r;++i)uo(n,i,t&255),t>>=8;return n[r-1]&128?uo(n,r-1,o?128:0):o&&(n[r-1]|=128),n}function oU(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 Rbe(e){}function Lbe(e){}function iU(e,t){var r;return(r=void 0)==null?void 0:r.get(t)}function Df(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 pn(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)??Df(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},l=e.kind==="schema",u=(o==null?void 0:o.message)??e.message??iU(e.reference,c.lang)??(l?(c.lang,void 0):null)??n.message??(c.lang,void 0);u&&(c.message=typeof u=="function"?u(c):u),l&&(r.typed=!1),r.issues?r.issues.push(c):r.issues=[c]}function aU(e,t){const r=[...new Set(e)];return r.length>1?`(${r.join(` ${t} `)})`:r[0]??"never"}var sU=class extends Error{constructor(t){super(t[0].message),Te(this,"issues"),this.name="ValiError",this.issues=t}};function p8(e,t){return{kind:"validation",type:"every_item",reference:p8,async:!1,expects:null,requirement:e,message:t,_run(r,n){return r.typed&&!r.value.every(this.requirement)&&pn(this,"item",r,n),r}}}function My(e){return{kind:"validation",type:"integer",reference:My,async:!1,expects:null,requirement:Number.isInteger,message:e,_run(t,r){return t.typed&&!this.requirement(t.value)&&pn(this,"integer",t,r),t}}}function g8(e,t){return{kind:"validation",type:"length",reference:g8,async:!1,expects:`${e}`,requirement:e,message:t,_run(r,n){return r.typed&&r.value.length!==this.requirement&&pn(this,"length",r,n,{received:`${r.value.length}`}),r}}}function sp(e,t){return{kind:"validation",type:"max_value",reference:sp,async:!1,expects:`<=${e instanceof Date?e.toJSON():Df(e)}`,requirement:e,message:t,_run(r,n){return r.typed&&r.value>this.requirement&&pn(this,"value",r,n,{received:r.value instanceof Date?r.value.toJSON():Df(r.value)}),r}}}function cp(e,t){return{kind:"validation",type:"min_value",reference:cp,async:!1,expects:`>=${e instanceof Date?e.toJSON():Df(e)}`,requirement:e,message:t,_run(r,n){return r.typed&&r.value<this.requirement&&pn(this,"value",r,n,{received:r.value instanceof Date?r.value.toJSON():Df(r.value)}),r}}}function m8(e,t){return{kind:"validation",type:"regex",reference:m8,async:!1,expects:`${e}`,requirement:e,message:t,_run(r,n){return r.typed&&!this.requirement.test(r.value)&&pn(this,"format",r,n),r}}}function Vy(e,t,r){return typeof e.default=="function"?e.default(t,r):e.default}function up(e,t){return!e._run({typed:!1,value:t},{abortEarly:!0}).issues}function y8(){return{kind:"schema",type:"any",reference:y8,expects:"any",async:!1,_run(e){return e.typed=!0,e}}}function Vn(e,t){return{kind:"schema",type:"array",reference:Vn,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 l={type:"array",origin:"value",input:i,key:a,value:s};for(const u of c.issues)u.path?u.path.unshift(l):u.path=[l],(o=r.issues)==null||o.push(u);if(r.issues||(r.issues=c.issues),n.abortEarly){r.typed=!1;break}}c.typed||(r.typed=!1),r.value.push(c.value)}}else pn(this,"type",r,n);return r}}}function b8(e){return{kind:"schema",type:"bigint",reference:b8,expects:"bigint",async:!1,message:e,_run(t,r){return typeof t.value=="bigint"?t.typed=!0:pn(this,"type",t,r),t}}}function ti(e,t){return{kind:"schema",type:"custom",reference:ti,expects:"unknown",async:!1,check:e,message:t,_run(r,n){return this.check(r.value)?r.typed=!0:pn(this,"type",r,n),r}}}function lp(e,t){return{kind:"schema",type:"instance",reference:lp,expects:e.name,async:!1,class:e,message:t,_run(r,n){return r.value instanceof this.class?r.typed=!0:pn(this,"type",r,n),r}}}function Gy(e,...t){const r={kind:"schema",type:"nullable",reference:Gy,expects:`(${e.expects} | null)`,async:!1,wrapped:e,_run(n,o){return n.value===null&&("default"in this&&(n.value=Vy(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 w8(e,...t){const r={kind:"schema",type:"nullish",reference:w8,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=Vy(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 Gn(e){return{kind:"schema",type:"number",reference:Gn,expects:"number",async:!1,message:e,_run(t,r){return typeof t.value=="number"&&!isNaN(t.value)?t.typed=!0:pn(this,"type",t,r),t}}}function Br(e,t){return{kind:"schema",type:"object",reference:Br,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 l={type:"object",origin:"value",input:i,key:a,value:s};for(const u of c.issues)u.path?u.path.unshift(l):u.path=[l],(o=r.issues)==null||o.push(u);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 pn(this,"type",r,n);return r}}}function fp(e,...t){const r={kind:"schema",type:"optional",reference:fp,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,_run(n,o){return n.value===void 0&&("default"in this&&(n.value=Vy(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 Fc(e){return{kind:"schema",type:"string",reference:Fc,expects:"string",async:!1,message:e,_run(t,r){return typeof t.value=="string"?t.typed=!0:pn(this,"type",t,r),t}}}function Ci(e,t){return{kind:"schema",type:"tuple",reference:Ci,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 l={type:"array",origin:"value",input:i,key:a,value:s};for(const u of c.issues)u.path?u.path.unshift(l):u.path=[l],(o=r.issues)==null||o.push(u);if(r.issues||(r.issues=c.issues),n.abortEarly){r.typed=!1;break}}c.typed||(r.typed=!1),r.value.push(c.value)}}else pn(this,"type",r,n);return r}}}function v8(e){let t;if(e)for(const r of e)t?t.push(...r.issues):t=r.issues;return t}function Zy(e,t){return{kind:"schema",type:"union",reference:Zy,expects:aU(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];pn(this,"type",r,n,{issues:v8(i)}),r.typed=!0}else{if((a==null?void 0:a.length)===1)return a[0];pn(this,"type",r,n,{issues:v8(a)})}return r}}}function ar(e,t,r){const n=e._run({typed:!1,value:t},oU(r));if(n.issues)throw new sU(n.issues);return n.value}function gs(e,t){const r={};for(const n in e.entries)r[n]=fp(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 E8=new Uint8Array(32),k8=wa("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"),zr=e=>il(lp(Uint8Array),g8(e));function Kf(e,t){return e.length!==t.length?!1:e.every((r,n)=>me(r,t[n])===0)}function ri(e){if(!(e instanceof Uint8Array)||e.length<33)return!1;const t=e[0],r=e.slice(1,33);if(me(E8,r)===0||me(r,k8)>=0)return!1;if((t===2||t===3)&&e.length===33)return!0;const n=e.slice(33);return me(E8,n)===0||me(n,k8)>=0?!1:t===4&&e.length===65}const dp=254;function Wy(e){return!e||!("output"in e)||!(e.output instanceof Uint8Array)?!1:e.version!==void 0?(e.version&dp)===e.version:!0}function x8(e){return Array.isArray(e)?e.length!==2?!1:e.every(t=>x8(t)):Wy(e)}const cU=zr(32),uU=zr(20),S8=zr(32),Dt=lp(Uint8Array);il(Fc(),m8(/^([0-9a-f]{2})+$/i));const lU=il(Gn(),My(),cp(0),sp(255)),Ea=il(Gn(),My(),cp(0),sp(4294967295)),Xy=il(b8(),cp(0n),sp(0x7fffffffffffffffn)),A8=e=>Br(Object.entries(e).reduce((t,r)=>({...t,[r[0]]:w8(r[1])}),{})),_8=new Uint8Array(1);function $8(e){let t=0;for(;e[t]===0;)++t;return t===e.length?_8:(e=e.slice(t),e[0]&128?ir([_8,e]):e)}function T8(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 fU(e){const t=va(e,e.length-1);if(!Jy(t))throw new Error("Invalid hashType "+t);const r=qB(e.subarray(0,-1)),n=T8(r.r),o=T8(r.s);return{signature:ir([n,o]),hashType:t}}function dU(e,t){if(ar(Br({signature:zr(64),hashType:lU}),{signature:e,hashType:t}),!Jy(t))throw new Error("Invalid hashType "+t);const r=new Uint8Array(1);uo(r,0,t);const n=$8(e.slice(0,32)),o=$8(e.slice(32,64));return ir([FB(n,o),r])}const hU=Object.freeze(Object.defineProperty({__proto__:null,decode:fU,encode:dU},Symbol.toStringTag,{value:"Module"})),I8=Ht.OP_RESERVED,P8=Vn(Zy([lp(Uint8Array),Gn()]));function pU(e){return up(Gn(),e)&&(e===Ht.OP_0||e>=Ht.OP_1&&e<=Ht.OP_16||e===Ht.OP_1NEGATE)}function O8(e){return up(Dt,e)||pU(e)}function Yy(e){return up(il(y8(),p8(O8)),e)}function B8(e){return e.length-e.filter(O8).length}function hp(e){if(e.length===0)return Ht.OP_0;if(e.length===1){if(e[0]>=1&&e[0]<=16)return I8+e[0];if(e[0]===129)return Ht.OP_1NEGATE}}function U8(e){return e instanceof Uint8Array}function gU(e){return up(P8,e)}function pp(e){return e instanceof Uint8Array}function Zn(e){if(U8(e))return e;ar(P8,e);const t=e.reduce((o,i)=>pp(i)?i.length===1&&hp(i)!==void 0?o+1:o+h8(i.length)+i.length:o+1,0),r=new Uint8Array(t);let n=0;if(e.forEach(o=>{if(pp(o)){const i=hp(o);if(i!==void 0){uo(r,n,i),n+=1;return}n+=eU(r,o.length,n),r.set(o,n),n+=o.length}else uo(r,n,o),n+=1}),n!==r.length)throw new Error("Could not decode chunks");return r}function sr(e){if(gU(e))return e;ar(Dt,e);const t=[];let r=0;for(;r<e.length;){const n=e[r];if(n>Ht.OP_0&&n<=Ht.OP_PUSHDATA4){const o=tU(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=hp(i);a!==void 0?t.push(a):t.push(i)}else t.push(n),r+=1}return t}function mU(e){if(U8(e)&&(e=sr(e)),!e)throw new Error("Could not convert invalid chunks to ASM");return e.map(t=>{if(pp(t)){const r=hp(t);if(r===void 0)return Me(t);t=r}return a8[t]}).join(" ")}function yU(e){return e=sr(e),ar(ti(Yy),e),e.map(t=>pp(t)?t:t===Ht.OP_0?new Uint8Array(0):nU(t-I8))}function bU(e){return ri(e)}function Jy(e){const t=e&-129;return t>0&&t<4}function ka(e){return!(e instanceof Uint8Array)||!Jy(e[e.length-1])?!1:KB(e.slice(0,-1))}const qf=hU;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 To(e){let t;return()=>(t!==void 0||(t=e()),t)}const al=Ht,gp=al.OP_RESERVED;function mp(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(Br({network:Br({}),m:Gn(),n:Gn(),output:Dt,pubkeys:Vn(ti(ri),"Received invalid pubkey"),signatures:Vn(ti(r),"Expected signature to be of type isAcceptableSignature"),input:Dt})),e);const n={network:e.network||$o};let o=[],i=!1;function a(s){i||(i=!0,o=sr(s),n.m=o[0]-gp,n.n=o[o.length-2]-gp,n.pubkeys=o.slice(1,-2))}if(Re(n,"output",()=>{if(e.m&&n.n&&e.pubkeys)return Zn([].concat(gp+e.m,e.pubkeys,gp+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 Zn([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(Gn(),o[0],{message:"Output is invalid"}),ar(Gn(),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=>ri(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&&!Kf(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&&!Kf(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 C8=Ht;function N8(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(Br({network:Br({}),output:Dt,pubkey:ti(ri,"invalid pubkey"),signature:ti(ka,"Expected signature to be of type isCanonicalScriptSignature"),input:Dt})),e);const r=To(()=>sr(e.input)),n={name:"p2pk",network:e.network||$o};if(Re(n,"output",()=>{if(e.pubkey)return Zn([e.pubkey,C8.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 Zn([e.signature])}),Re(n,"witness",()=>{if(n.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==C8.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!ri(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 j8(e){if(!Number.isSafeInteger(e)||e<0)throw new Error(`positive integer expected, not ${e}`)}function wU(e){return e instanceof Uint8Array||e!=null&&typeof e=="object"&&e.constructor.name==="Uint8Array"}function yp(e,...t){if(!wU(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 vU(e){if(typeof e!="function"||typeof e.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");j8(e.outputLen),j8(e.blockLen)}function bp(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 EU(e,t){yp(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 Qy=e=>new DataView(e.buffer,e.byteOffset,e.byteLength),Ni=(e,t)=>e<<32-t|e>>>t,wp=(e,t)=>e<<t|e>>>32-t>>>0;new Uint8Array(new Uint32Array([287454020]).buffer)[0];function kU(e){if(typeof e!="string")throw new Error(`utf8ToBytes expected string, got ${typeof e}`);return new Uint8Array(new TextEncoder().encode(e))}function eb(e){return typeof e=="string"&&(e=kU(e)),yp(e),e}function xU(...e){let t=0;for(let n=0;n<e.length;n++){const o=e[n];yp(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 z8=class{clone(){return this._cloneInto()}};function tb(e){const t=n=>e().update(eb(n)).digest(),r=e();return t.outputLen=r.outputLen,t.blockLen=r.blockLen,t.create=()=>e(),t}function SU(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 AU(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,l=n?0:4;e.setUint32(t+c,a,n),e.setUint32(t+l,s,n)}const _U=(e,t,r)=>e&t^~e&r,$U=(e,t,r)=>e&t^e&r^t&r;let rb=class extends z8{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=Qy(this.buffer)}update(t){bp(this);const{view:r,buffer:n,blockLen:o}=this;t=eb(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=Qy(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){bp(this),EU(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;AU(n,o-8,BigInt(this.length*8),i),this.process(n,0);const s=Qy(t),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");const l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)s.setUint32(4*f,u[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 TU=new Uint8Array([7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8]),R8=new Uint8Array(new Array(16).fill(0).map((e,t)=>t)),IU=R8.map(e=>(9*e+5)%16);let nb=[R8],ob=[IU];for(let e=0;e<4;e++)for(let t of[nb,ob])t.push(t[e].map(r=>TU[r]));const L8=[[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)),PU=nb.map((e,t)=>e.map(r=>L8[t][r])),OU=ob.map((e,t)=>e.map(r=>L8[t][r])),BU=new Uint32Array([0,1518500249,1859775393,2400959708,2840853838]),UU=new Uint32Array([1352829926,1548603684,1836072691,2053994217,0]);function H8(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 vp=new Uint32Array(16);let CU=class extends rb{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)vp[g]=t.getUint32(r,!0);let n=this.h0|0,o=n,i=this.h1|0,a=i,s=this.h2|0,c=s,l=this.h3|0,u=l,f=this.h4|0,h=f;for(let g=0;g<5;g++){const y=4-g,m=BU[g],w=UU[g],v=nb[g],x=ob[g],E=PU[g],_=OU[g];for(let O=0;O<16;O++){const T=wp(n+H8(g,i,s,l)+vp[v[O]]+m,E[O])+f|0;n=f,f=l,l=wp(s,10)|0,s=i,i=T}for(let O=0;O<16;O++){const T=wp(o+H8(y,a,c,u)+vp[x[O]]+w,_[O])+h|0;o=h,h=u,u=wp(c,10)|0,c=a,a=T}}this.set(this.h1+s+u|0,this.h2+l+h|0,this.h3+f+o|0,this.h4+n+a|0,this.h0+i+c|0)}roundClean(){vp.fill(0)}destroy(){this.destroyed=!0,this.buffer.fill(0),this.set(0,0,0,0,0)}};const D8=tb(()=>new CU),NU=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 jU=class extends rb{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:l,H:u}=this;for(let f=0;f<64;f++){const h=Ni(s,6)^Ni(s,11)^Ni(s,25),g=u+h+_U(s,c,l)+NU[f]+ys[f]|0,y=(Ni(n,2)^Ni(n,13)^Ni(n,22))+$U(n,o,i)|0;u=l,l=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,l=l+this.G|0,u=u+this.H|0,this.set(n,o,i,a,s,c,l,u)}roundClean(){ys.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};const Yr=tb(()=>new jU);function xa(e){return D8(Yr(e))}function Mc(e){return Yr(Yr(e))}const zU={"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 Ep(e,t){return Yr(ir([zU[e],t]))}function RU(e){if(e.length>=255)throw new TypeError("Alphabet too long");const t=new Uint8Array(256);for(let l=0;l<t.length;l++)t[l]=255;for(let l=0;l<e.length;l++){const u=e.charAt(l),f=u.charCodeAt(0);if(t[f]!==255)throw new TypeError(u+" is ambiguous");t[f]=l}const r=e.length,n=e.charAt(0),o=Math.log(r)/Math.log(256),i=Math.log(256)/Math.log(r);function a(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";let u=0,f=0,h=0;const g=l.length;for(;h!==g&&l[h]===0;)h++,u++;const y=(g-h)*i+1>>>0,m=new Uint8Array(y);for(;h!==g;){let x=l[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(u);for(;w<y;++w)v+=e.charAt(m[w]);return v}function s(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;let u=0,f=0,h=0;for(;l[u]===n;)f++,u++;const g=(l.length-u)*o+1>>>0,y=new Uint8Array(g);for(;l[u];){let x=t[l.charCodeAt(u)];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,u++}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(l){const u=s(l);if(u)return u;throw new Error("Non-base"+r+" character")}return{encode:a,decodeUnsafe:s,decode:c}}var LU="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";const ib=RU(LU);function HU(e){function t(i){var a=Uint8Array.from(i),s=e(a),c=a.length+4,l=new Uint8Array(c);return l.set(a,0),l.set(s.subarray(0,4),a.length),ib.encode(l)}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=ib.decodeUnsafe(i);if(a!=null)return r(a)}function o(i){var a=ib.decode(i),s=r(a);if(s==null)throw new Error("Invalid checksum");return s}return{encode:t,decode:o,decodeUnsafe:n}}function DU(e){return Yr(Yr(e))}const cl=HU(DU),bs=Ht;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(Br({network:Br({}),address:Fc(),hash:uU,output:zr(25),pubkey:ti(ri),signature:ti(ka),input:Dt})),e);const r=To(()=>{const a=cl.decode(e.address),s=va(a,0),c=a.slice(1);return{version:s,hash:c}}),n=To(()=>sr(e.input)),o=e.network||$o,i={name:"p2pkh",network:o};if(Re(i,"address",()=>{if(!i.hash)return;const a=new Uint8Array(21);return uo(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 Zn([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 Zn([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(!ri(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 Mf=Ht;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(Br({network:Br({}),address:Fc(),hash:zr(20),output:zr(23),redeem:gs(Br({network:Br({}),output:Dt,input:Dt,witness:Vn(Dt)})),input:Dt,witness:Vn(Dt)})),e);let r=e.network;r||(r=e.redeem&&e.redeem.network||$o);const n={network:r},o=To(()=>{const s=cl.decode(e.address),c=va(s,0),l=s.slice(1);return{version:c,hash:l}}),i=To(()=>sr(e.input)),a=To(()=>{const s=i(),c=s[s.length-1];return{network:r,output:c===Mf.OP_FALSE?Uint8Array.from([]):c,input:Zn(s.slice(0,-1)),witness:e.witness||[]}});if(Re(n,"address",()=>{if(!n.hash)return;const s=new Uint8Array(21);return uo(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 Zn([Mf.OP_HASH160,n.hash,Mf.OP_EQUAL])}),Re(n,"redeem",()=>{if(e.input)return a()}),Re(n,"input",()=>{if(!(!e.redeem||!e.redeem.input||!e.redeem.output))return Zn([].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]!==Mf.OP_HASH160||e.output[1]!==20||e.output[22]!==Mf.OP_EQUAL)throw new TypeError("Output is invalid");const l=e.output.slice(2,22);if(s.length>0&&me(s,l)!==0)throw new TypeError("Hash mismatch");s=l}const c=l=>{if(l.output){const u=sr(l.output);if(!u||u.length<1)throw new TypeError("Redeem.output too short");if(l.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(B8(u)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const f=xa(l.output);if(s.length>0&&me(s,f)!==0)throw new TypeError("Hash mismatch");s=f}if(l.input){const u=l.input.length>0,f=l.witness&&l.witness.length>0;if(!u&&!f)throw new TypeError("Empty input");if(u&&f)throw new TypeError("Input and witness provided");if(u){const h=sr(l.input);if(!Yy(h))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const l=i();if(!l||l.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 l=a();if(e.redeem.output&&me(e.redeem.output,l.output)!==0)throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&me(e.redeem.input,l.input)!==0)throw new TypeError("Redeem.input mismatch")}c(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!Kf(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 KU(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}function qU(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 Vf={};Object.defineProperty(Vf,"__esModule",{value:!0});var Gf=Vf.bech32m=lo=Vf.bech32=void 0;const kp="qpzry9x8gf2tvdw0s3jn54khce6mua7l",K8={};for(let e=0;e<kp.length;e++){const t=kp.charAt(e);K8[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 q8(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 ab(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 FU(e){return ab(e,8,5,!0)}function MU(e){const t=ab(e,5,8,!1);if(Array.isArray(t))return t}function VU(e){const t=ab(e,5,8,!1);if(Array.isArray(t))return t;throw new Error(t)}function F8(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 l=q8(a);if(typeof l=="string")throw new Error(l);let u=a+"1";for(let f=0;f<s.length;++f){const h=s[f];if(h>>5)throw new Error("Non 5-bit word");l=ll(l)^h,u+=kp.charAt(h)}for(let f=0;f<6;++f)l=ll(l);l^=t;for(let f=0;f<6;++f){const h=l>>(5-f)*5&31;u+=kp.charAt(h)}return u}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(),l=a.toUpperCase();if(a!==c&&a!==l)return"Mixed-case string "+a;a=c;const u=a.lastIndexOf("1");if(u===-1)return"No separator character for "+a;if(u===0)return"Missing prefix for "+a;const f=a.slice(0,u),h=a.slice(u+1);if(h.length<6)return"Data too short";let g=q8(f);if(typeof g=="string")return g;const y=[];for(let m=0;m<h.length;++m){const w=h.charAt(m),v=K8[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:FU,fromWordsUnsafe:MU,fromWords:VU}}var lo=Vf.bech32=F8("bech32");Gf=Vf.bech32m=F8("bech32m");const M8=Ht,GU=new Uint8Array(0);function Zf(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(Br({address:Fc(),hash:zr(20),input:zr(0),network:Br({}),output:zr(22),pubkey:ti(ri,"Not a valid pubkey"),signature:ti(ka),witness:Vn(Dt)})),e);const r=To(()=>{const i=lo.decode(e.address),a=i.words.shift(),s=lo.fromWords(i.words);return{version:a,prefix:i.prefix,data:Uint8Array.from(s)}}),n=e.network||$o,o={name:"p2wpkh",network:n};if(Re(o,"address",()=>{if(!o.hash)return;const i=lo.toWords(o.hash);return i.unshift(0),lo.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 Zn([M8.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 GU}),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]!==M8.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,!ri(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(!ri(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 V8=Ht,sb=new Uint8Array(0);function xp(e){return!!(e instanceof Uint8Array&&e.length===65&&e[0]===4&&ri(e))}function Wf(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(A8({network:Br({}),address:Fc(),hash:cU,output:zr(34),redeem:A8({input:Dt,network:Br({}),output:Dt,witness:Vn(Dt)}),input:zr(0),witness:Vn(Dt)}),e);const r=To(()=>{const a=lo.decode(e.address),s=a.words.shift(),c=lo.fromWords(a.words);return{version:s,prefix:a.prefix,data:Uint8Array.from(c)}}),n=To(()=>sr(e.redeem.input));let o=e.network;o||(o=e.redeem&&e.redeem.network||$o);const i={network:o};if(Re(i,"address",()=>{if(!i.hash)return;const a=lo.toWords(i.hash);return a.unshift(0),lo.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 Yr(i.redeem.output)}),Re(i,"output",()=>{if(i.hash)return Zn([V8.OP_0,i.hash])}),Re(i,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:sb,witness:e.witness.slice(0,-1)}}),Re(i,"input",()=>{if(i.witness)return sb}),Re(i,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const a=yU(n());return i.redeem=Object.assign({witness:a},e.redeem),i.redeem.input=sb,[].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]!==V8.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(B8(s)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const c=Yr(e.redeem.output);if(a.length>0&&me(a,c)!==0)throw new TypeError("Hash mismatch");a=c}if(e.redeem.input&&!Yy(n()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!Kf(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&n().some(xp)||e.redeem.output&&(sr(e.redeem.output)||[]).some(xp))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(xp)||(sr(s)||[]).some(xp))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(i,e)}const Xf={};function G8(e){e?e!==Xf.eccLib&&(ZU(e),Xf.eccLib=e):Xf.eccLib=e}function cb(){if(!Xf.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return Xf.eccLib}const Sa=e=>wa(e);function ZU(e){Io(typeof e.isXOnlyPoint=="function"),Io(e.isXOnlyPoint(Sa("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),Io(e.isXOnlyPoint(Sa("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),Io(e.isXOnlyPoint(Sa("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),Io(e.isXOnlyPoint(Sa("0000000000000000000000000000000000000000000000000000000000000001"))),Io(!e.isXOnlyPoint(Sa("0000000000000000000000000000000000000000000000000000000000000000"))),Io(!e.isXOnlyPoint(Sa("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),Io(typeof e.xOnlyPointAddTweak=="function"),WU.forEach(t=>{const r=e.xOnlyPointAddTweak(Sa(t.pubkey),Sa(t.tweak));t.result===null?Io(r===null):(Io(r!==null),Io(r.parity===t.parity),Io(me(r.xOnlyPubkey,Sa(t.result))===0))})}function Io(e){if(!e)throw new Error("ecc library invalid")}const WU=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}],Z8="0123456789abcdefABCDEF";Z8.split("").map(e=>e.codePointAt(0));const W8=Array(256).fill(!0).map((e,t)=>{const r=String.fromCodePoint(t),n=Z8.indexOf(r);return n<0?void 0:n<16?n:n-6}),X8=new TextEncoder;new TextDecoder;function XU(e){return X8.encode(e)}function YU(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 JU(e){const t=X8.encode(e||""),r=new Uint8Array(Math.floor(t.length/2));let n;for(n=0;n<r.length;n++){const o=W8[t[n*2]],i=W8[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 Aa(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 Y8(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 QU(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 Vc(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 eC(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 tC(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 rC(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 nC=e=>{if(e<0||e>0xffffffffffffffffn)throw new RangeError("value out of range")};function oC(e){if(e<0||e>Number.MAX_SAFE_INTEGER||e%1!==0)throw new RangeError("value out of range")}function J8(e){typeof e=="number"?oC(e):nC(e)}function ws(e,t,r){J8(e),r===void 0&&(r=0),t===void 0&&(t=new Uint8Array(Po(e)));let n=0;return e<253?(t.set([Number(e)],r),n=1):e<=65535?(t.set([253],r),QU(t,r+1,Number(e),"LE"),n=3):e<=4294967295?(t.set([254],r),Vc(t,r+1,Number(e),"LE"),n=5):(t.set([255],r),eC(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=tC(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=rC(e,t+1,"LE");return{numberValue:n<=Number.MAX_SAFE_INTEGER?Number(n):null,bigintValue:n,bytes:9}}}function Po(e){return J8(e),e<253?1:e<=65535?3:e<=4294967295?5:9}const iC=9007199254740991;function aC(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 ub(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 Q8(e){const t=new Uint8Array(e.length);return t.set(e),t}let Wn=class AB{constructor(t,r=0){Te(this,"buffer"),Te(this,"offset"),this.buffer=t,this.offset=r,ar(Ci([Dt,Ea]),[t,r])}static withCapacity(t){return new AB(new Uint8Array(t))}writeUInt8(t){this.offset=uo(this.buffer,this.offset,t)}writeInt32(t){this.offset=l8(this.buffer,this.offset,t,"LE")}writeInt64(t){this.offset=f8(this.buffer,this.offset,BigInt(t),"LE")}writeUInt32(t){this.offset=Hf(this.buffer,this.offset,t,"LE")}writeUInt64(t){this.offset=YB(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}`)}},sC=class{constructor(t,r=0){Te(this,"buffer"),Te(this,"offset"),this.buffer=t,this.offset=r,ar(Ci([Dt,Ea]),[t,r])}readUInt8(){const t=va(this.buffer,this.offset);return this.offset++,t}readInt32(){const t=QB(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=d8(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){aC(t,iC);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 e4=192,cC=128,uC=e=>"left"in e&&"right"in e;function lb(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=db(n,i):n=db(i,n)}return n}function fb(e){if(Wy(e))return{hash:_a(e)};const t=[fb(e[0]),fb(e[1])];t.sort((o,i)=>me(o.hash,i.hash));const[r,n]=t;return{hash:db(r.hash,n.hash),left:r,right:n}}function Sp(e,t){if(uC(e)){const r=Sp(e.left,t);if(r!==void 0)return[...r,e.right.hash];const n=Sp(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||e4;return Ep("TapLeaf",ir([Uint8Array.from([t]),fC(e.output)]))}function lC(e,t){return Ep("TapTweak",ir(t?[e,t]:[e]))}function Ap(e,t){if(!(e instanceof Uint8Array)||e.length!==32||t&&t.length!==32)return null;const r=lC(e,t),n=cb().xOnlyPointAddTweak(e,r);return!n||n.xOnlyPubkey===null?null:{parity:n.parity,x:Uint8Array.from(n.xOnlyPubkey)}}function db(e,t){return Ep("TapBranch",ir([e,t]))}function fC(e){const t=Po(e.length),r=new Uint8Array(t);return ws(e.length,r),ir([r,e])}const t4=Ht,r4=1,dC=80;function Yf(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(Br({address:Fc(),input:zr(0),network:Br({}),output:zr(34),internalPubkey:zr(32),hash:zr(32),pubkey:zr(32),signature:Zy([zr(64),zr(65)]),witness:Vn(Dt),scriptTree:ti(x8,"Taptree is not of type isTaptree"),redeem:gs(Br({output:Dt,redeemVersion:Gn(),witness:Vn(Dt)})),redeemVersion:Gn()})),e);const r=To(()=>hb(e.address)),n=To(()=>{if(!(!e.witness||!e.witness.length))return e.witness.length>=2&&e.witness[e.witness.length-1][0]===dC?e.witness.slice(0,-1):e.witness.slice()}),o=To(()=>{if(e.scriptTree)return fb(e.scriptTree);if(e.hash)return{hash:e.hash}}),i=e.network||$o,a={name:"p2tr",network:i};if(Re(a,"address",()=>{if(!a.pubkey)return;const s=Gf.toWords(a.pubkey);return s.unshift(r4),Gf.encode(i.bech32,s)}),Re(a,"hash",()=>{const s=o();if(s)return s.hash;const c=n();if(c&&c.length>1){const l=c[c.length-1],u=l[0]&dp,f=c[c.length-2],h=_a({output:f,version:u});return lb(l,h)}return null}),Re(a,"output",()=>{if(a.pubkey)return Zn([t4.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:e4),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]&dp}}),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=Ap(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}),l=Sp(s,c);if(!l)return;const u=Ap(e.internalPubkey,s.hash);if(!u)return;const f=ir([Uint8Array.from([a.redeemVersion|u.parity]),e.internalPubkey].concat(l));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!==r4)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]!==t4.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 u=Ap(e.internalPubkey,a.hash);if(s.length>0&&me(s,u.x)!==0)throw new TypeError("Pubkey mismatch");s=u.x}if(s&&s.length&&!cb().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 u=_a({output:e.redeem.output,version:a.redeemVersion});if(!Sp(c,u))throw new TypeError("Redeem script not in tree")}const l=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&&!Kf(e.redeem.witness,a.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(l&&l.length)if(l.length===1){if(e.signature&&me(e.signature,l[0])!==0)throw new TypeError("Signature mismatch")}else{const u=l[l.length-1];if(u.length<33)throw new TypeError(`The control-block length is too small. Got ${u.length}, expected min 33.`);if((u.length-33)%32!==0)throw new TypeError(`The control-block length of ${u.length} is incorrect!`);const f=(u.length-33)/32;if(f>128)throw new TypeError(`The script path is too long. Got ${f}, expected max 128.`);const h=u.slice(1,33);if(e.internalPubkey&&me(e.internalPubkey,h)!==0)throw new TypeError("Internal pubkey mismatch");if(!cb().isXOnlyPoint(h))throw new TypeError("Invalid internalPubkey for p2tr witness");const g=u[0]&dp,y=l[l.length-2],m=_a({output:y,version:g}),w=lb(u,m),v=Ap(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!==(u[0]&1))throw new Error("Incorrect parity")}}return Object.assign(a,e)}const n4=40,o4=2,i4=16,a4=2,s4=80,c4="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 hC(e,t){const r=e.slice(2);if(r.length<o4||r.length>n4)throw new TypeError("Invalid program length for segwit address");const n=e[0]-s4;if(n<a4||n>i4)throw new TypeError("Invalid version for segwit address");if(e[1]!==r.length)throw new TypeError("Invalid script for segwit address");return console.warn(c4),pC(r,n,t.bech32)}function u4(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 hb(e){let t,r;try{t=lo.decode(e)}catch{}if(t){if(r=t.words[0],r!==0)throw new TypeError(e+" uses wrong encoding")}else if(t=Gf.decode(e),r=t.words[0],r===0)throw new TypeError(e+" uses wrong encoding");const n=lo.fromWords(t.words.slice(1));return{version:r,prefix:t.prefix,data:Uint8Array.from(n)}}function pC(e,t,r){const n=lo.toWords(e);return n.unshift(t),t===0?lo.encode(r,n):Gf.encode(r,n)}function Jf(e,t){t=t||$o;try{return Ff({output:e,network:t}).address}catch{}try{return ul({output:e,network:t}).address}catch{}try{return Zf({output:e,network:t}).address}catch{}try{return Wf({output:e,network:t}).address}catch{}try{return Yf({output:e,network:t}).address}catch{}try{return hC(e,t)}catch{}throw new Error(mU(e)+" has no matching Address")}function pb(e,t){t=t||$o;let r,n;try{r=u4(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=hb(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 Zf({hash:n.data}).output;if(n.data.length===32)return Wf({hash:n.data}).output}else if(n.version===1){if(n.data.length===32)return Yf({pubkey:n.data}).output}else if(n.version>=a4&&n.version<=i4&&n.data.length>=o4&&n.data.length<=n4)return console.warn(c4),Zn([n.version+s4,n.data])}}throw new Error(e+" has no matching Script")}function ji(e){const t=e.length;return Po(t)+t}function gC(e){const t=e.length;return Po(t)+e.reduce((r,n)=>r+ji(n),0)}const vs=new Uint8Array(0),l4=[],gb=wa("0000000000000000000000000000000000000000000000000000000000000000"),f4=wa("0000000000000000000000000000000000000000000000000000000000000001"),mC=wa("ffffffffffffffff"),yC={script:vs,valueBuffer:mC};function bC(e){return e.value!==void 0}const ni=class Xt{constructor(){Te(this,"version",1),Te(this,"locktime",0),Te(this,"ins",[]),Te(this,"outs",[])}static fromBuffer(t,r){const n=new sC(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 u=0;u<c;++u)o.ins.push({hash:n.readSlice(32),index:n.readUInt32(),script:n.readVarSlice(),sequence:n.readUInt32(),witness:l4});const l=n.readVarInt();for(let u=0;u<l;++u)o.outs.push({value:n.readInt64(),script:n.readVarSlice()});if(s){for(let u=0;u<c;++u)o.ins[u].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(S8,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(Ci([S8,Ea,Gy(fp(Ea)),Gy(fp(Dt))]),[t,r,n,o]),n==null&&(n=Xt.DEFAULT_SEQUENCE),this.ins.push({hash:t,index:r,script:o||vs,sequence:n,witness:l4})-1}addOutput(t,r){return ar(Ci([Dt,Xy]),[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)+Po(this.ins.length)+Po(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+gC(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(Ci([Ea,Dt,Gn()]),[t,r,n]),t>=this.ins.length)return f4;const o=Zn(sr(r).filter(s=>s!==Ht.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 f4;i.outs.length=t+1;for(let s=0;s<t;s++)i.outs[s]=yC;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 l8(a,a.length-4,n,"LE"),i.__toBuffer(a,0,!1),Mc(a)}hashForWitnessV1(t,r,n,o,i,a){if(ar(Ci([Ea,Vn(Dt),Vn(Xy),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,l=s===Xt.SIGHASH_NONE,u=s===Xt.SIGHASH_SINGLE;let f=vs,h=vs,g=vs,y=vs,m=vs;if(!c){let E=Wn.withCapacity(36*this.ins.length);this.ins.forEach(_=>{E.writeSlice(_.hash),E.writeUInt32(_.index)}),f=Yr(E.end()),E=Wn.withCapacity(8*this.ins.length),n.forEach(_=>E.writeInt64(_)),h=Yr(E.end()),E=Wn.withCapacity(r.map(ji).reduce((_,O)=>_+O)),r.forEach(_=>E.writeVarSlice(_)),g=Yr(E.end()),E=Wn.withCapacity(4*this.ins.length),this.ins.forEach(_=>E.writeUInt32(_.sequence)),y=Yr(E.end())}if(l||u){if(u&&t<this.outs.length){const E=this.outs[t],_=Wn.withCapacity(8+ji(E.script));_.writeInt64(E.value),_.writeVarSlice(E.script),m=Yr(_.end())}}else{if(!this.outs.length)throw new Error("Add outputs to the transaction before signing.");const E=this.outs.map(O=>8+ji(O.script)).reduce((O,T)=>O+T),_=Wn.withCapacity(E);this.outs.forEach(O=>{_.writeInt64(O.value),_.writeVarSlice(O.script)}),m=Yr(_.end())}const w=(i?2:0)+(a?1:0),v=174-(c?49:0)-(l?32:0)+(a?32:0)+(i?37:0),x=Wn.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),l||u||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=Wn.withCapacity(ji(a));E.writeVarSlice(a),x.writeSlice(Yr(E.end()))}return u&&x.writeSlice(m),i&&(x.writeSlice(i),x.writeUInt8(0),x.writeUInt32(4294967295)),Ep("TapSighash",ir([Uint8Array.from([0]),x.end()]))}hashForWitnessV0(t,r,n,o){ar(Ci([Ea,Dt,Xy,Ea]),[t,r,n,o]);let i=Uint8Array.from([]),a,s=gb,c=gb,l=gb;if(o&Xt.SIGHASH_ANYONECANPAY||(i=new Uint8Array(36*this.ins.length),a=new Wn(i,0),this.ins.forEach(f=>{a.writeSlice(f.hash),a.writeUInt32(f.index)}),c=Mc(i)),!(o&Xt.SIGHASH_ANYONECANPAY)&&(o&31)!==Xt.SIGHASH_SINGLE&&(o&31)!==Xt.SIGHASH_NONE&&(i=new Uint8Array(4*this.ins.length),a=new Wn(i,0),this.ins.forEach(f=>{a.writeUInt32(f.sequence)}),l=Mc(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 Wn(i,0),this.outs.forEach(h=>{a.writeInt64(h.value),a.writeVarSlice(h.script)}),s=Mc(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 Wn(i,0),a.writeInt64(f.value),a.writeVarSlice(f.script),s=Mc(i)}i=new Uint8Array(156+ji(r)),a=new Wn(i,0);const u=this.ins[t];return a.writeInt32(this.version),a.writeSlice(c),a.writeSlice(l),a.writeSlice(u.hash),a.writeUInt32(u.index),a.writeVarSlice(r),a.writeInt64(n),a.writeUInt32(u.sequence),a.writeSlice(s),a.writeUInt32(this.locktime),a.writeUInt32(o),Mc(i)}getHash(t){return t&&this.isCoinbase()?new Uint8Array(32):Mc(this.__toBuffer(void 0,void 0,t))}getId(){return Me(ub(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(Ci([Gn(),Dt]),[t,r]),this.ins[t].script=r}setWitness(t,r){ar(Ci([Gn(),Vn(Dt)]),[t,r]),this.ins[t].witness=r}__toBuffer(t,r,n=!1){t||(t=new Uint8Array(this.byteLength(n)));const o=new Wn(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=>{bC(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(ni,"DEFAULT_SEQUENCE",4294967295),Te(ni,"SIGHASH_DEFAULT",0),Te(ni,"SIGHASH_ALL",1),Te(ni,"SIGHASH_NONE",2),Te(ni,"SIGHASH_SINGLE",3),Te(ni,"SIGHASH_ANYONECANPAY",128),Te(ni,"SIGHASH_OUTPUT_MASK",3),Te(ni,"SIGHASH_INPUT_MASK",128),Te(ni,"ADVANCED_TRANSACTION_MARKER",0),Te(ni,"ADVANCED_TRANSACTION_FLAG",1);let kr=ni;var zi;(function(e){e[e.UNSIGNED_TX=0]="UNSIGNED_TX",e[e.GLOBAL_XPUB=1]="GLOBAL_XPUB"})(zi||(zi={}));var Ae;(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"})(Ae||(Ae={}));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 wC=e=>[...Array(e).keys()];function vC(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 wC(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 EC(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),Hf(o,i,c,"LE"),i+=4}),{key:r,value:o}}const kC="{ masterFingerprint: Uint8Array; extendedPubkey: Uint8Array; path: string; }";function xC(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 SC(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 AC=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:SC,check:xC,decode:vC,encode:EC,expected:kC},Symbol.toStringTag,{value:"Module"}));function _C(e){return{key:new Uint8Array([zi.UNSIGNED_TX]),value:e.toBuffer()}}const $C=Object.freeze(Object.defineProperty({__proto__:null,encode:_C},Symbol.toStringTag,{value:"Module"}));function TC(e){if(e.key[0]!==Ae.FINAL_SCRIPTSIG)throw new Error("Decode Error: could not decode finalScriptSig with key 0x"+Me(e.key));return e.value}function IC(e){return{key:new Uint8Array([Ae.FINAL_SCRIPTSIG]),value:e}}const PC="Uint8Array";function OC(e){return e instanceof Uint8Array}function BC(e,t){return!!e&&!!t&&e.finalScriptSig===void 0}const UC=Object.freeze(Object.defineProperty({__proto__:null,canAdd:BC,check:OC,decode:TC,encode:IC,expected:PC},Symbol.toStringTag,{value:"Module"}));function CC(e){if(e.key[0]!==Ae.FINAL_SCRIPTWITNESS)throw new Error("Decode Error: could not decode finalScriptWitness with key 0x"+Me(e.key));return e.value}function NC(e){return{key:new Uint8Array([Ae.FINAL_SCRIPTWITNESS]),value:e}}const jC="Uint8Array";function zC(e){return e instanceof Uint8Array}function RC(e,t){return!!e&&!!t&&e.finalScriptWitness===void 0}const LC=Object.freeze(Object.defineProperty({__proto__:null,canAdd:RC,check:zC,decode:CC,encode:NC,expected:jC},Symbol.toStringTag,{value:"Module"}));function HC(e){if(e.key[0]!==Ae.NON_WITNESS_UTXO)throw new Error("Decode Error: could not decode nonWitnessUtxo with key 0x"+Me(e.key));return e.value}function DC(e){return{key:new Uint8Array([Ae.NON_WITNESS_UTXO]),value:e}}const KC="Uint8Array";function qC(e){return e instanceof Uint8Array}function FC(e,t){return!!e&&!!t&&e.nonWitnessUtxo===void 0}const MC=Object.freeze(Object.defineProperty({__proto__:null,canAdd:FC,check:qC,decode:HC,encode:DC,expected:KC},Symbol.toStringTag,{value:"Module"}));function VC(e){if(e.key[0]!==Ae.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 GC(e){const t=new Uint8Array([Ae.PARTIAL_SIG]);return{key:ir([t,e.pubkey]),value:e.signature}}const ZC="{ pubkey: Uint8Array; signature: Uint8Array; }";function WC(e){return e.pubkey instanceof Uint8Array&&e.signature instanceof Uint8Array&&[33,65].includes(e.pubkey.length)&&[2,3,4].includes(e.pubkey[0])&&XC(e.signature)}function XC(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 YC(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 JC=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:YC,check:WC,decode:VC,encode:GC,expected:ZC},Symbol.toStringTag,{value:"Module"}));function QC(e){if(e.key[0]!==Ae.POR_COMMITMENT)throw new Error("Decode Error: could not decode porCommitment with key 0x"+Me(e.key));return MB(e.value)}function eN(e){return{key:new Uint8Array([Ae.POR_COMMITMENT]),value:VB(e)}}const tN="string";function rN(e){return typeof e=="string"}function nN(e,t){return!!e&&!!t&&e.porCommitment===void 0}const oN=Object.freeze(Object.defineProperty({__proto__:null,canAdd:nN,check:rN,decode:QC,encode:eN,expected:tN},Symbol.toStringTag,{value:"Module"}));function iN(e){if(e.key[0]!==Ae.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 aN(e){const t=Uint8Array.from([Ae.SIGHASH_TYPE]),r=new Uint8Array(4);return Hf(r,0,e,"LE"),{key:t,value:r}}const sN="number";function cN(e){return typeof e=="number"}function uN(e,t){return!!e&&!!t&&e.sighashType===void 0}const lN=Object.freeze(Object.defineProperty({__proto__:null,canAdd:uN,check:cN,decode:iN,encode:aN,expected:sN},Symbol.toStringTag,{value:"Module"}));function fN(e){if(e.key[0]!==Ae.TAP_KEY_SIG||e.key.length!==1)throw new Error("Decode Error: could not decode tapKeySig with key 0x"+Me(e.key));if(!d4(e.value))throw new Error("Decode Error: tapKeySig not a valid 64-65-byte BIP340 signature");return e.value}function dN(e){return{key:Uint8Array.from([Ae.TAP_KEY_SIG]),value:e}}const hN="Uint8Array";function d4(e){return e instanceof Uint8Array&&(e.length===64||e.length===65)}function pN(e,t){return!!e&&!!t&&e.tapKeySig===void 0}const gN=Object.freeze(Object.defineProperty({__proto__:null,canAdd:pN,check:d4,decode:fN,encode:dN,expected:hN},Symbol.toStringTag,{value:"Module"}));function mN(e){if(e.key[0]!==Ae.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 yN(e){const t=Uint8Array.from([Ae.TAP_LEAF_SCRIPT]),r=Uint8Array.from([e.leafVersion]);return{key:ir([t,e.controlBlock]),value:ir([e.script,r])}}const bN="{ controlBlock: Uint8Array; leafVersion: number, script: Uint8Array; }";function wN(e){return e.controlBlock instanceof Uint8Array&&(e.controlBlock.length-1)%32===0&&(e.controlBlock[0]&254)===e.leafVersion&&e.script instanceof Uint8Array}function vN(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 EN=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:vN,check:wN,decode:mN,encode:yN,expected:bN},Symbol.toStringTag,{value:"Module"}));function kN(e){if(e.key[0]!==Ae.TAP_MERKLE_ROOT||e.key.length!==1)throw new Error("Decode Error: could not decode tapMerkleRoot with key 0x"+Me(e.key));if(!h4(e.value))throw new Error("Decode Error: tapMerkleRoot not a 32-byte hash");return e.value}function xN(e){return{key:Uint8Array.from([Ae.TAP_MERKLE_ROOT]),value:e}}const SN="Uint8Array";function h4(e){return e instanceof Uint8Array&&e.length===32}function AN(e,t){return!!e&&!!t&&e.tapMerkleRoot===void 0}const _N=Object.freeze(Object.defineProperty({__proto__:null,canAdd:AN,check:h4,decode:kN,encode:xN,expected:SN},Symbol.toStringTag,{value:"Module"}));function $N(e){if(e.key[0]!==Ae.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 TN(e){const t=Uint8Array.from([Ae.TAP_SCRIPT_SIG]);return{key:ir([t,e.pubkey,e.leafHash]),value:e.signature}}const IN="{ pubkey: Uint8Array; leafHash: Uint8Array; signature: Uint8Array; }";function PN(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 ON(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 BN=Object.freeze(Object.defineProperty({__proto__:null,canAddToArray:ON,check:PN,decode:$N,encode:TN,expected:IN},Symbol.toStringTag,{value:"Module"}));function UN(e){if(e.key[0]!==Ae.WITNESS_UTXO)throw new Error("Decode Error: could not decode witnessUtxo with key 0x"+Me(e.key));const t=d8(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 CN(e){const{script:t,value:r}=e,n=Po(t.length),o=new Uint8Array(8+n+t.length);return f8(o,0,BigInt(r),"LE"),ws(t.length,o,8),o.set(t,8+n),{key:Uint8Array.from([Ae.WITNESS_UTXO]),value:o}}const NN="{ script: Uint8Array; value: bigint; }";function jN(e){return e.script instanceof Uint8Array&&typeof e.value=="bigint"}function zN(e,t){return!!e&&!!t&&e.witnessUtxo===void 0}const RN=Object.freeze(Object.defineProperty({__proto__:null,canAdd:zN,check:jN,decode:UN,encode:CN,expected:NN},Symbol.toStringTag,{value:"Module"}));function LN(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 HN(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 DN="{ leaves: [{ depth: number; leafVersion: number, script: Uint8Array; }] }";function KN(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 FN=Object.freeze(Object.defineProperty({__proto__:null,canAdd:qN,check:KN,decode:LN,encode:HN,expected:DN},Symbol.toStringTag,{value:"Module"})),MN=e=>[...Array(e).keys()],VN=e=>e.length===33&&[2,3].includes(e[0])||e.length===65&&e[0]===4;function mb(e,t=VN){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 l={masterFingerprint:s.value.slice(0,4),pubkey:c,path:"m"};for(const u of MN(s.value.length/4-1)){const f=ol(s.value,u*4+4,"LE"),h=!!(f&2147483648),g=f&2147483647;l.path+="/"+g.toString(10)+(h?"'":"")}return l}function n(s){const c=Uint8Array.from([e]),l=ir([c,s.pubkey]),u=s.path.split("/"),f=new Uint8Array(u.length*4);f.set(s.masterFingerprint,0);let h=4;return u.slice(1).forEach(g=>{const y=g.slice(-1)==="'";let m=2147483647&parseInt(y?g.slice(0,-1):g,10);y&&(m+=2147483648),Hf(f,h,m,"LE"),h+=4}),{key:l,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,l){const u=Me(c.pubkey);return l.has(u)?!1:(l.add(u),s.filter(f=>me(f.pubkey,c.pubkey)===0).length===0)}return{decode:r,encode:n,check:i,expected:o,canAddToArray:a}}function yb(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 p4(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 GN=e=>e.length===32;function g4(e){const t=mb(e,GN);function r(a){const{numberValue:s,bytes:c}=dl(a.value),l=t.decode({key:a.key,value:a.value.slice(c+Number(s)*32)}),u=new Array(Number(s));for(let f=0,h=c;f<s;f++,h+=32)u[f]=a.value.slice(h,h+32);return{...l,leafHashes:u}}function n(a){const s=t.encode(a),c=Po(a.leafHashes.length),l=new Uint8Array(c);ws(a.leafHashes.length,l);const u=ir([l,...a.leafHashes,s.value]);return{...s,value:u}}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 m4(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 y4(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 bb={unsignedTx:$C,globalXpub:AC,checkPubkey:yb([])},Rr={nonWitnessUtxo:MC,partialSig:JC,sighashType:lN,finalScriptSig:UC,finalScriptWitness:LC,porCommitment:oN,witnessUtxo:RN,bip32Derivation:mb(Ae.BIP32_DERIVATION),redeemScript:p4(Ae.REDEEM_SCRIPT),witnessScript:y4(Ae.WITNESS_SCRIPT),checkPubkey:yb([Ae.PARTIAL_SIG,Ae.BIP32_DERIVATION]),tapKeySig:gN,tapScriptSig:BN,tapLeafScript:EN,tapBip32Derivation:g4(Ae.TAP_BIP32_DERIVATION),tapInternalKey:m4(Ae.TAP_INTERNAL_KEY),tapMerkleRoot:_N},$a={bip32Derivation:mb(xr.BIP32_DERIVATION),redeemScript:p4(xr.REDEEM_SCRIPT),witnessScript:y4(xr.WITNESS_SCRIPT),checkPubkey:yb([xr.BIP32_DERIVATION]),tapBip32Derivation:g4(xr.TAP_BIP32_DERIVATION),tapTree:FN,tapInternalKey:m4(xr.TAP_INTERNAL_KEY)},ZN=Object.freeze(Object.defineProperty({__proto__:null,globals:bb,inputs:Rr,outputs:$a},Symbol.toStringTag,{value:"Module"})),_p=e=>[...Array(e).keys()];function b4(e){const t=e.map(WN);return t.push(Uint8Array.from([0])),ir(t)}function WN(e){const t=e.key.length,r=e.value.length,n=Po(t),o=Po(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 XN(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=[],l={};for(;!s();){const w=a(),v=Me(w.key);if(l[v])throw new Error("Format Error: Keys must be unique for global keymap: key "+v);l[v]=1,c.push(w)}const u=c.filter(w=>w.key[0]===zi.UNSIGNED_TX);if(u.length!==1)throw new Error("Format Error: Only one UNSIGNED_TX allowed");const f=t(u[0].value),{inputCount:h,outputCount:g}=f.getInputOutputCounts(),y=[],m=[];for(const w of _p(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 _p(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 w4(f,{globalMapKeyVals:c,inputKeyVals:y,outputKeyVals:m})}function gn(e,t,r){if(me(t,Uint8Array.from([r])))throw new Error(`Format Error: Invalid ${e} key: ${Me(t)}`)}function w4(e,{globalMapKeyVals:t,inputKeyVals:r,outputKeyVals:n}){const o={unsignedTx:e};let i=0;for(const u of t)switch(u.key[0]){case zi.UNSIGNED_TX:if(gn("global",u.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(bb.globalXpub.decode(u));break;default:o.unknownKeyVals||(o.unknownKeyVals=[]),o.unknownKeyVals.push(u)}const a=r.length,s=n.length,c=[],l=[];for(const u of _p(a)){const f={};for(const h of r[u])switch(Rr.checkPubkey(h),h.key[0]){case Ae.NON_WITNESS_UTXO:if(gn("input",h.key,Ae.NON_WITNESS_UTXO),f.nonWitnessUtxo!==void 0)throw new Error("Format Error: Input has multiple NON_WITNESS_UTXO");f.nonWitnessUtxo=Rr.nonWitnessUtxo.decode(h);break;case Ae.WITNESS_UTXO:if(gn("input",h.key,Ae.WITNESS_UTXO),f.witnessUtxo!==void 0)throw new Error("Format Error: Input has multiple WITNESS_UTXO");f.witnessUtxo=Rr.witnessUtxo.decode(h);break;case Ae.PARTIAL_SIG:f.partialSig===void 0&&(f.partialSig=[]),f.partialSig.push(Rr.partialSig.decode(h));break;case Ae.SIGHASH_TYPE:if(gn("input",h.key,Ae.SIGHASH_TYPE),f.sighashType!==void 0)throw new Error("Format Error: Input has multiple SIGHASH_TYPE");f.sighashType=Rr.sighashType.decode(h);break;case Ae.REDEEM_SCRIPT:if(gn("input",h.key,Ae.REDEEM_SCRIPT),f.redeemScript!==void 0)throw new Error("Format Error: Input has multiple REDEEM_SCRIPT");f.redeemScript=Rr.redeemScript.decode(h);break;case Ae.WITNESS_SCRIPT:if(gn("input",h.key,Ae.WITNESS_SCRIPT),f.witnessScript!==void 0)throw new Error("Format Error: Input has multiple WITNESS_SCRIPT");f.witnessScript=Rr.witnessScript.decode(h);break;case Ae.BIP32_DERIVATION:f.bip32Derivation===void 0&&(f.bip32Derivation=[]),f.bip32Derivation.push(Rr.bip32Derivation.decode(h));break;case Ae.FINAL_SCRIPTSIG:gn("input",h.key,Ae.FINAL_SCRIPTSIG),f.finalScriptSig=Rr.finalScriptSig.decode(h);break;case Ae.FINAL_SCRIPTWITNESS:gn("input",h.key,Ae.FINAL_SCRIPTWITNESS),f.finalScriptWitness=Rr.finalScriptWitness.decode(h);break;case Ae.POR_COMMITMENT:gn("input",h.key,Ae.POR_COMMITMENT),f.porCommitment=Rr.porCommitment.decode(h);break;case Ae.TAP_KEY_SIG:gn("input",h.key,Ae.TAP_KEY_SIG),f.tapKeySig=Rr.tapKeySig.decode(h);break;case Ae.TAP_SCRIPT_SIG:f.tapScriptSig===void 0&&(f.tapScriptSig=[]),f.tapScriptSig.push(Rr.tapScriptSig.decode(h));break;case Ae.TAP_LEAF_SCRIPT:f.tapLeafScript===void 0&&(f.tapLeafScript=[]),f.tapLeafScript.push(Rr.tapLeafScript.decode(h));break;case Ae.TAP_BIP32_DERIVATION:f.tapBip32Derivation===void 0&&(f.tapBip32Derivation=[]),f.tapBip32Derivation.push(Rr.tapBip32Derivation.decode(h));break;case Ae.TAP_INTERNAL_KEY:gn("input",h.key,Ae.TAP_INTERNAL_KEY),f.tapInternalKey=Rr.tapInternalKey.decode(h);break;case Ae.TAP_MERKLE_ROOT:gn("input",h.key,Ae.TAP_MERKLE_ROOT),f.tapMerkleRoot=Rr.tapMerkleRoot.decode(h);break;default:f.unknownKeyVals||(f.unknownKeyVals=[]),f.unknownKeyVals.push(h)}c.push(f)}for(const u of _p(s)){const f={};for(const h of n[u])switch($a.checkPubkey(h),h.key[0]){case xr.REDEEM_SCRIPT:if(gn("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(gn("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:gn("output",h.key,xr.TAP_INTERNAL_KEY),f.tapInternalKey=$a.tapInternalKey.decode(h);break;case xr.TAP_TREE:gn("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)}l.push(f)}return{globalMap:o,inputs:c,outputs:l}}function YN({globalMap:e,inputs:t,outputs:r}){const{globalKeyVals:n,inputKeyVals:o,outputKeyVals:i}=vb({globalMap:e,inputs:t,outputs:r}),a=b4(n),s=f=>f.length===0?[Uint8Array.from([0])]:f.map(b4),c=s(o),l=s(i),u=new Uint8Array(5);return u.set([112,115,98,116,255],0),ir([u,a].concat(c,l))}const JN=(e,t)=>me(e.key,t.key);function wb(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 l=(Array.isArray(s)?s:[s]).map(c.encode);return l.map(u=>Me(u.key)).forEach(u=>{if(r.has(u))throw new Error("Serialize Error: Duplicate key: "+u);r.add(u)}),i.concat(l)},[]),o=e.unknownKeyVals?e.unknownKeyVals.filter(i=>!r.has(Me(i.key))):[];return n.concat(o).sort(JN)}function vb({globalMap:e,inputs:t,outputs:r}){return{globalKeyVals:wb(e,bb),inputKeyVals:t.map(n=>wb(n,Rr)),outputKeyVals:r.map(n=>wb(n,$a))}}function QN(e){const t=e[0],r=vb(t),n=e.slice(1);if(n.length===0)throw new Error("Combine: Nothing to combine");const o=v4(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 l=v4(c);if(l===void 0||me(l.toBuffer(),o.toBuffer())!==0)throw new Error("Combine: One of the Psbts does not have the same transaction.");const u=vb(c);hl(u.globalKeyVals).forEach(Eb(i,r.globalKeyVals,u.globalKeyVals)),u.inputKeyVals.map(hl).forEach((f,h)=>f.forEach(Eb(a[h],r.inputKeyVals[h],u.inputKeyVals[h]))),u.outputKeyVals.map(hl).forEach((f,h)=>f.forEach(Eb(s[h],r.outputKeyVals[h],u.outputKeyVals[h])))}return w4(o,{globalMapKeyVals:r.globalKeyVals,inputKeyVals:r.inputKeyVals,outputKeyVals:r.outputKeyVals})}function Eb(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 v4(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 un(e,t){const r=e[t];if(r===void 0)throw new Error(`No input #${t}`);return r}function Qf(e,t){const r=e[t];if(r===void 0)throw new Error(`No output #${t}`);return r}function kb(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 xb(e){let t=0;return Object.keys(e).forEach(r=>{Number(isNaN(Number(r)))&&t++}),t}function ej(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 E4(e,t,r,n){throw new Error(`Data for ${e} key ${t} is incorrect: Expected ${r} and got ${JSON.stringify(n)}`)}function Sb(e){return(t,r)=>{for(const n of Object.keys(t)){const o=t[n],{canAdd:i,canAddToArray:a,check:s,expected:c}=ZN[e+"s"][n]||{},l=!!a;if(s)if(l){if(!Array.isArray(o)||r[n]&&!Array.isArray(r[n]))throw new Error(`Key type ${n} must be an array`);o.every(s)||E4(e,n,c,o);const u=r[n]||[],f=new Set;if(!o.every(h=>a(u,h,f)))throw new Error("Can not add duplicate data to array");r[n]=u.concat(o)}else{if(s(o)||E4(e,n,c,o),!i(r,o))throw new Error(`Can not add duplicate data to ${e}`);r[n]=o}}}}const tj=Sb("global"),k4=Sb("input"),x4=Sb("output");function rj(e,t){const r=e.length-1,n=un(e,r);k4(t,n)}function nj(e,t){const r=e.length-1,n=Qf(e,r);x4(t,n)}let S4=class{constructor(t){this.inputs=[],this.outputs=[],this.globalMap={unsignedTx:t}}static fromBase64(t,r){const n=u8(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=XN(t,r),o=new this(n.globalMap.unsignedTx);return Object.assign(o,n),o}toBase64(){const t=this.toBuffer();return WB(t)}toHex(){const t=this.toBuffer();return Me(t)}toBuffer(){return YN(this)}updateGlobal(t){return tj(t,this.globalMap),this}updateInput(t,r){const n=un(this.inputs,t);return k4(r,n),this}updateOutput(t,r){const n=Qf(this.outputs,t);return x4(r,n),this}addUnknownKeyValToGlobal(t){return kb(t,this.globalMap.unknownKeyVals,xb(zi)),this.globalMap.unknownKeyVals||(this.globalMap.unknownKeyVals=[]),this.globalMap.unknownKeyVals.push(t),this}addUnknownKeyValToInput(t,r){const n=un(this.inputs,t);return kb(r,n.unknownKeyVals,xb(Ae)),n.unknownKeyVals||(n.unknownKeyVals=[]),n.unknownKeyVals.push(r),this}addUnknownKeyValToOutput(t,r){const n=Qf(this.outputs,t);return kb(r,n.unknownKeyVals,xb(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)),rj(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)),nj(this.outputs,t),this}clearFinalizedInput(t){const r=un(this.inputs,t);ej(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=QN([this].concat(t));return Object.assign(this,r),this}getTransaction(){return this.globalMap.unsignedTx.toBuffer()}};function Gc(e){return t=>{try{return e({output:t}),!0}catch{return!1}}}const oj=Gc(mp),ij=Gc(N8),aj=Gc(Ff),$p=Gc(Zf),A4=Gc(Wf),_4=Gc(ul),$4=Gc(Yf);function Tp(e){let t=new Uint8Array(0);function r(a){t=ir([t,a])}function n(a){const s=t.length,c=Po(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 T4(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 Ip(e,t){return T4(e,t)!==-1}function sj(e,t){return cj(e).some(r=>I4(r,qf.decode,t))}function I4(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 cj(e){let t=[];if((e.partialSig||[]).length===0){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=uj(e)}else t=e.partialSig;return t.map(r=>r.signature)}function uj(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 ed=e=>e.length===32?e:e.slice(1,33);function P4(e,t,r){const n=xj(t,e,r);try{const o=Ej(t,n).concat(n.script).concat(n.controlBlock);return{finalScriptWitness:Tp(o)}}catch(o){throw new Error(`Can not finalize taproot input #${e}: ${o}`)}}function Pp(e,t){const r=t?Uint8Array.from([t]):Uint8Array.from([]);return ir([e,r])}function oi(e){return e&&!!(e.tapInternalKey||e.tapMerkleRoot||e.tapLeafScript&&e.tapLeafScript.length||e.tapBip32Derivation&&e.tapBip32Derivation.length||e.witnessUtxo&&$4(e.witnessUtxo.script))}function Ab(e,t){return e&&!!(e.tapInternalKey||e.tapTree||e.tapBip32Derivation&&e.tapBip32Derivation.length||t)}function O4(e,t,r){bj(e,t,r),vj(e,t,r)}function B4(e,t,r){wj(e,t,r),lj(e,t)}function lj(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=fj(r,n);if(o&&me(i,o)!==0)throw new Error("Error adding output. Script or address mismatch.")}}function fj(e,t){const r=t&&dj(t.leaves),{output:n}=Yf({internalPubkey:e,scriptTree:r});return n}function dj(e=[]){return e.length===1&&e[0].depth===0?{output:e[0].script,version:e[0].leafVersion}:yj(e)}function hj(e,t){return gj(e).some(r=>I4(r,pj,t))}function pj(e){return{signature:e.slice(0,64),hashType:e.slice(64)[0]||kr.SIGHASH_DEFAULT}}function gj(e){const t=[];if(e.tapKeySig&&t.push(e.tapKeySig),e.tapScriptSig&&t.push(...e.tapScriptSig.map(r=>r.signature)),!t.length){const r=mj(e.finalScriptWitness);r&&t.push(r)}return t}function mj(e){if(!e)return;const t=e.slice(2);if(t.length===64||t.length===65)return t}function yj(e){let t;for(const r of e)if(t=_b(r,t),!t)throw new Error("No room left to insert tapleaf in tree");return t}function _b(e,t,r=0){if(r>cC)throw new Error("Max taptree depth exceeded.");if(e.depth===r)return t?void 0:{output:e.script,version:e.leafVersion};if(Wy(t))return;const n=_b(e,t&&t[0],r+1);if(n)return[n,t&&t[1]];const o=_b(e,t&&t[1],r+1);if(o)return[t&&t[0],o]}function bj(e,t,r){const n=oi(e)&&pl(t),o=pl(e)&&oi(t),i=e===t&&oi(t)&&pl(t);if(n||o||i)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function wj(e,t,r){const n=Ab(e)&&pl(t),o=pl(e)&&Ab(t),i=e===t&&Ab(t)&&pl(t);if(n||o||i)throw new Error(`Invalid arguments for Psbt.${r}. Cannot use both taproot and non-taproot fields.`)}function vj(e,t,r){if(t.tapMerkleRoot){const n=(t.tapLeafScript||[]).every(i=>$b(i,t.tapMerkleRoot)),o=(e.tapLeafScript||[]).every(i=>$b(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=>$b(n,e.tapMerkleRoot)))throw new Error(`Invalid arguments for Psbt.${r}. Tapleaf not part of taptree.`)}function $b(e,t){if(!t)return!0;const r=_a({output:e.script,version:e.leafVersion}),n=lb(e.controlBlock,r);return me(n,t)===0}function Ej(e,t){const r=_a({output:t.script,version:t.leafVersion});return(e.tapScriptSig||[]).filter(n=>me(n.leafHash,r)===0).map(n=>kj(t.script,n)).sort((n,o)=>o.positionInScript-n.positionInScript).map(n=>n.signature)}function kj(e,t){return Object.assign({positionInScript:T4(t.pubkey,e)},t)}function xj(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=>Sj(o,e.tapScriptSig,r));if(!n)throw new Error(`Can not finalize taproot input #${t}. Signature for tapleaf script not found.`);return n}function Sj(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 Aj={network:$o,maximumFeeRate:5e3};let Lr=class ZE{constructor(t={},r=new S4(new U4)){Te(this,"data"),Te(this,"__CACHE"),Te(this,"opts"),this.data=r,this.opts=Object.assign({},Aj,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=u8(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=S4.fromBuffer(t,_j),o=new ZE(r,n);return Oj(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:Q8(t.hash),index:t.index,sequence:t.sequence}))}get txOutputs(){return this.__CACHE.__TX.outs.map(t=>{let r;try{r=Jf(t.script,this.opts.network)}catch{}return{script:Q8(t.script),value:t.value,address:r}})}combine(...t){return this.data.combine(...t.map(r=>r.data)),this}clone(){const t=ZE.fromBuffer(this.data.toBuffer());return t.opts=JSON.parse(JSON.stringify(this.opts)),t}setMaximumFeeRate(t){Op(t),this.opts.maximumFeeRate=t}setVersion(t){Op(t),td(this.data.inputs,"setVersion");const r=this.__CACHE;return r.__TX.version=t,r.__EXTRACTED_TX=void 0,this}setLocktime(t){Op(t),td(this.data.inputs,"setLocktime");const r=this.__CACHE;return r.__TX.locktime=t,r.__EXTRACTED_TX=void 0,this}setInputSequence(t,r){Op(r),td(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]");O4(t,t,"addInput"),td(this.data.inputs,"addInput"),t.witnessScript&&Cp(t.witnessScript);const r=this.__CACHE;this.data.addInput(t);const n=r.__TX.ins[r.__TX.ins.length-1];R4(r,n);const o=this.data.inputs.length-1,i=this.data.inputs[o];return i.nonWitnessUtxo&&Pb(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]");td(this.data.inputs,"addOutput");const{address:r}=t;if(typeof r=="string"){const{network:o}=this.opts,i=pb(r,o);t=Object.assign({},t,{script:i})}B4(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(N4))throw new Error("Not finalized");const r=this.__CACHE;if(t||Tj(this,r,this.opts),r.__EXTRACTED_TX)return r.__EXTRACTED_TX;const n=r.__TX.clone();return X4(this.data.inputs,n,r,!0),n}getFeeRate(){return K4("__FEE_RATE","fee rate",this.data.inputs,this.__CACHE)}getFee(){return K4("__FEE","fee",this.data.inputs,this.__CACHE)}finalizeAllInputs(){return un(this.data.inputs,0),rd(this.data.inputs.length).forEach(t=>this.finalizeInput(t)),this}finalizeInput(t,r){const n=un(this.data.inputs,t);return oi(n)?this._finalizeTaprootInput(t,n,void 0,r):this._finalizeInput(t,n,r)}finalizeTaprootInput(t,r,n=P4){const o=un(this.data.inputs,t);if(oi(o))return this._finalizeTaprootInput(t,o,r,n);throw new Error(`Cannot finalize input #${t}. Not Taproot.`)}_finalizeInput(t,r,n=Bj){const{script:o,isP2SH:i,isP2WSH:a,isSegwit:s}=jj(t,r,this.__CACHE);if(!o)throw new Error(`No script found for input #${t}`);Ij(r);const{finalScriptSig:c,finalScriptWitness:l}=n(t,r,o,s,i,a);if(c&&this.data.updateInput(t,{finalScriptSig:c}),l&&this.data.updateInput(t,{finalScriptWitness:l}),!c&&!l)throw new Error(`Unknown error finalizing input #${t}`);return this.data.clearFinalizedInput(t),this}_finalizeTaprootInput(t,r,n,o=P4){if(!r.witnessUtxo)throw new Error(`Cannot finalize input #${t}. Missing withness utxo.`);if(r.tapKeySig){const i=Yf({output:r.witnessUtxo.script,signature:r.tapKeySig}),a=Tp(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=un(this.data.inputs,t),n=Y4(t,r,this.__CACHE),o=Up(n,t,"input",r.redeemScript||Dj(r.finalScriptSig),r.witnessScript||Kj(r.finalScriptWitness)),i=o.type==="raw"?"":o.type+"-",a=Q4(o.meaningfulScript);return i+a}inputHasPubkey(t,r){const n=un(this.data.inputs,t);return Lj(r,n,t,this.__CACHE)}inputHasHDKey(t,r){const n=un(this.data.inputs,t),o=j4(r);return!!n.bip32Derivation&&n.bip32Derivation.some(o)}outputHasPubkey(t,r){const n=Qf(this.data.outputs,t);return Hj(r,n,t,this.__CACHE)}outputHasHDKey(t,r){const n=Qf(this.data.outputs,t),o=j4(r);return!!n.bip32Derivation&&n.bip32Derivation.some(o)}validateSignaturesOfAllInputs(t){return un(this.data.inputs,0),rd(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 oi(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,l,u;for(const f of a){const h=qf.decode(f.signature),{hash:g,script:y}=u!==h.hashType?F4(t,Object.assign({},o,{sighashType:h.hashType}),this.__CACHE,!0):{hash:c,script:l};u=h.hashType,c=g,l=y,z4(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&&ed(n);const s=n?Ib(t,o,this.data.inputs,n,this.__CACHE):Cj(t,o,this.data.inputs,this.__CACHE);if(!s.length)throw new Error("No signatures for this pubkey");const c=s.find(u=>!u.leafHash);let l=0;if(i&&c){if(!r(c.pubkey,c.hash,V4(i)))return!1;l++}if(a)for(const u of a){const f=s.find(h=>me(h.pubkey,u.pubkey)===0);if(f){if(!r(u.pubkey,f.hash,V4(u.signature)))return!1;l++}}return l>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 rd(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 rd(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 Z4(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=Z4(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 rd(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=un(this.data.inputs,t);return oi(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=un(this.data.inputs,t);if(oi(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}=q4(this.data.inputs,t,r.publicKey,this.__CACHE,n),a=[{pubkey:r.publicKey,signature:qf.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(l=>!l.leafHash).map(l=>Pp(n.signSchnorr(l.hash),r.sighashType))[0],c=a.filter(l=>!!l.leafHash).map(l=>({pubkey:ed(n.publicKey),signature:Pp(n.signSchnorr(l.hash),r.sighashType),leafHash:l.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=un(this.data.inputs,t);return oi(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=un(this.data.inputs,t);if(oi(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}=q4(this.data.inputs,t,r.publicKey,this.__CACHE,n);return Promise.resolve(r.sign(o)).then(a=>{const s=[{pubkey:r.publicKey,signature:qf.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(u=>!u.leafHash)[0];if(c){const u=Promise.resolve(n.signSchnorr(c.hash)).then(f=>({tapKeySig:Pp(f,r.sighashType)}));s.push(u)}const l=a.filter(u=>!!u.leafHash);if(l.length){const u=l.map(f=>Promise.resolve(n.signSchnorr(f.hash)).then(h=>({tapScriptSig:[{pubkey:ed(n.publicKey),signature:Pp(h,r.sighashType),leafHash:f.leafHash}]})));s.push(...u)}return Promise.all(s).then(u=>{u.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=Ib(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 Tb(this.__CACHE),this.data.toBuffer()}toHex(){return Tb(this.__CACHE),this.data.toHex()}toBase64(){return Tb(this.__CACHE),this.data.toBase64()}updateGlobal(t){return this.data.updateGlobal(t),this}updateInput(t,r){return r.witnessScript&&Cp(r.witnessScript),O4(this.data.inputs[t],r,"updateInput"),this.data.updateInput(t,r),r.nonWitnessUtxo&&Pb(this.__CACHE,this.data.inputs[t],t),this}updateOutput(t,r){const n=this.data.outputs[t];return B4(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 _j=e=>new U4(e);let U4=class{constructor(t=Uint8Array.from([2,0,0,0,0,0,0,0,0,0])){Te(this,"tx"),this.tx=kr.fromBuffer(t),Pj(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"?ub(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 $j(e,t,r){switch(r){case"pubkey":case"pubkeyhash":case"witnesspubkeyhash":return C4(1,e.partialSig);case"multisig":const n=mp({output:t});return C4(n.m,e.partialSig,n.pubkeys);default:return!1}}function Tb(e){if(e.__UNSAFE_SIGN_NONSEGWIT!==!1)throw new Error("Not BIP174 compliant, can not export")}function C4(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 N4(e){return!!e.finalScriptSig||!!e.finalScriptWitness}function j4(e){return t=>!(me(e.fingerprint,t.masterFingerprint)||me(e.derivePath(t.path).publicKey,t.pubkey))}function Op(e){if(typeof e!="number"||e!==Math.floor(e)||e>4294967295||e<0)throw new Error("Invalid 32 bit integer")}function Tj(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 td(e,t){e.forEach(r=>{if(oi(r)?hj(r,t):sj(r,t))throw new Error("Can not modify transaction, signatures exist.")})}function Ij(e){if(!e.sighashType||!e.partialSig)return;const{partialSig:t,sighashType:r}=e;t.forEach(n=>{const{hashType:o}=qf.decode(n.signature);if(r!==o)throw new Error("Signature sighash does not match input sighash type")})}function z4(e,t,r){if(!Ip(e,t))throw new Error(`Can not ${r} for this input with the key ${Me(e)}`)}function Pj(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 Oj(e,t){e.ins.forEach(r=>{R4(t,r)})}function R4(e,t){const r=Me(ub(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 L4(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 H4=L4(ul,"Redeem script"),D4=L4(Wf,"Witness script");function K4(e,t,r,n){if(!r.every(N4))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(),X4(r,o,n,i),e==="__FEE_RATE")return n.__FEE_RATE;if(e==="__FEE")return n.__FEE}function Bj(e,t,r,n,o,i){const a=Q4(r);if(!$j(t,r,a))throw new Error(`Can not finalize input #${e}`);return Uj(r,a,t.partialSig,n,o,i)}function Uj(e,t,r,n,o,i){let a,s;const c=Nj(e,t,r),l=i?Wf({redeem:c}):null,u=o?ul({redeem:l||c}):null;return n?(l?s=Tp(l.witness):s=Tp(c.witness),u&&(a=u.input)):u?a=u.input:a=c.input,{finalScriptSig:a,finalScriptWitness:s}}function q4(e,t,r,n,o){const i=un(e,t),{hash:a,sighashType:s,script:c}=F4(t,i,n,!1,o);return z4(r,c,"sign"),{hash:a,sighashType:s}}function F4(e,t,r,n,o){const i=r.__TX,a=t.sighashType||kr.SIGHASH_ALL;G4(a,o);let s,c;if(t.nonWitnessUtxo){const f=Bp(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:l,type:u}=Up(c.script,e,"input",t.redeemScript,t.witnessScript);if(["p2sh-p2wsh","p2wsh"].indexOf(u)>=0)s=i.hashForWitnessV0(e,l,c.value,a);else if($p(l)){const f=Ff({hash:l.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(l)}`);!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.
|
|
23
|
+
"version": "0.0.118",
|
|
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.
|
|
45
|
-
"@omnisat/lasereyes-react": "0.0.
|
|
44
|
+
"@omnisat/lasereyes-core": "0.0.43",
|
|
45
|
+
"@omnisat/lasereyes-react": "0.0.35",
|
|
46
46
|
"bip39": "^3.1.0"
|
|
47
47
|
},
|
|
48
48
|
"license": "MIT",
|