@gvnrdao/dh-sdk 0.0.166 → 0.0.205

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.
Files changed (71) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +86 -5
  3. package/browser/dist/397.browser.js +1 -1
  4. package/browser/dist/833.browser.js +1 -1
  5. package/browser/dist/browser.js +1 -13
  6. package/browser/dist/browser.js.LICENSE.txt +1 -70
  7. package/browser/dist/index.d.ts +3 -4
  8. package/browser/dist/index.d.ts.map +1 -1
  9. package/browser/dist/index.js +4 -3
  10. package/dist/constants/chunks/contract-abis.d.ts +7 -0
  11. package/dist/constants/chunks/deployment-addresses.d.ts +68 -0
  12. package/dist/constants/chunks/encrypted-provider-params.d.ts +21 -0
  13. package/dist/constants/chunks/environment.browser.d.ts +45 -0
  14. package/dist/constants/chunks/environment.d.ts +57 -0
  15. package/dist/constants/chunks/network-configs.d.ts +65 -0
  16. package/dist/constants/chunks/sdk-config.d.ts +33 -0
  17. package/dist/constants/chunks/sdk-limits.d.ts +66 -0
  18. package/dist/constants/index.d.ts +15 -0
  19. package/dist/graphs/client.d.ts +19 -0
  20. package/dist/graphs/diamond-hands.d.ts +248 -0
  21. package/dist/index.d.ts +47 -7391
  22. package/dist/index.js +4525 -16860
  23. package/dist/index.mjs +4489 -16801
  24. package/dist/interfaces/chunks/btc.i.d.ts +36 -0
  25. package/dist/interfaces/chunks/config.i.d.ts +250 -0
  26. package/dist/interfaces/chunks/contract-interactions.i.d.ts +64 -0
  27. package/dist/interfaces/chunks/contract-types.i.d.ts +165 -0
  28. package/dist/interfaces/chunks/lit-actions-results.i.d.ts +165 -0
  29. package/dist/interfaces/chunks/lit-actions.i.d.ts +98 -0
  30. package/dist/interfaces/chunks/loan-operations.i.d.ts +332 -0
  31. package/dist/interfaces/chunks/pkp-integration.i.d.ts +87 -0
  32. package/dist/interfaces/chunks/position-query.i.d.ts +76 -0
  33. package/dist/interfaces/chunks/requests.i.d.ts +55 -0
  34. package/dist/interfaces/chunks/ucd-minting.i.d.ts +34 -0
  35. package/dist/interfaces/chunks/utility.i.d.ts +64 -0
  36. package/dist/interfaces/index.d.ts +17 -0
  37. package/dist/modules/bitcoin/bitcoin-operations.module.d.ts +223 -0
  38. package/dist/modules/cache/cache-manager.module.d.ts +92 -0
  39. package/dist/modules/contract/contract-manager.module.d.ts +136 -0
  40. package/dist/modules/diamond-hands-sdk.d.ts +669 -0
  41. package/dist/modules/loan/loan-creator.module.d.ts +143 -0
  42. package/dist/modules/loan/loan-query.module.d.ts +206 -0
  43. package/dist/modules/mock/mock-token-manager.module.d.ts +83 -0
  44. package/dist/modules/pkp/pkp-manager.module.d.ts +136 -0
  45. package/dist/protocol/protocol-pause.d.ts +19 -0
  46. package/dist/server.d.ts +17 -0
  47. package/dist/server.js +285 -0
  48. package/dist/server.mjs +242 -0
  49. package/dist/types/authorization-params.d.ts +160 -0
  50. package/dist/types/branded/domain-values.d.ts +138 -0
  51. package/dist/types/branded/ids.d.ts +23 -0
  52. package/dist/types/event-types.d.ts +235 -0
  53. package/dist/types/graph-dtos.d.ts +228 -0
  54. package/dist/types/loanStatus.d.ts +10 -0
  55. package/dist/types/result.d.ts +120 -0
  56. package/dist/utils/bitcoin-address-cache.utils.d.ts +87 -0
  57. package/dist/utils/bitcoin-provider.utils.d.ts +48 -0
  58. package/dist/utils/bitcoin-signature.d.ts +20 -0
  59. package/dist/utils/chunks/bitcoin-utils.d.ts +75 -0
  60. package/dist/utils/chunks/eip1559-broadcast.utils.d.ts +24 -0
  61. package/dist/utils/error-handler.d.ts +106 -0
  62. package/dist/utils/ethers-interop.utils.d.ts +146 -0
  63. package/dist/utils/extend-authorization.utils.d.ts +61 -0
  64. package/dist/utils/lit-signature.utils.d.ts +6 -0
  65. package/dist/utils/logger.utils.d.ts +142 -0
  66. package/dist/utils/mint-authorization.utils.d.ts +224 -0
  67. package/dist/utils/quantum-timing.d.ts +75 -0
  68. package/dist/utils/signature-tempering.utils.d.ts +31 -0
  69. package/dist/utils/telegram-messaging.utils.d.ts +188 -0
  70. package/package.json +43 -22
  71. package/dist/index.d.mts +0 -7392
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) Diamond Hands Protocol
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -12,6 +12,23 @@ The official TypeScript SDK for the Diamond Hands Protocol, enabling developers
12
12
  npm install @gvnrdao/dh-sdk
13
13
  ```
14
14
 
15
+ ### Browser vs server (PKP mint / `PKP_MINT_PRIVATE_KEY`)
16
+
17
+ - **Default export** (`import { DiamondHandsSDK } from "@gvnrdao/dh-sdk"` and `import { loadSDKConfig } from "@gvnrdao/dh-sdk"` via constants) resolves **browser-safe** environment helpers (`environment.browser`) — suitable for frontends, read-only flows, and user-signed transactions. Do **not** put `PKP_MINT_PRIVATE_KEY` in client bundles.
18
+ - **Server / Node scripts** (lit-ops-server, CI, PKP mint wallets) should import Node env + optional mint key from the dedicated subpath:
19
+
20
+ ```typescript
21
+ import {
22
+ loadSDKConfig,
23
+ validateSDKEnvironment,
24
+ } from "@gvnrdao/dh-sdk/server";
25
+
26
+ validateSDKEnvironment({ requiresPrivateKey: true });
27
+ const cfg = loadSDKConfig(); // may include cfg.pkpMintPrivateKey when env is set
28
+ ```
29
+
30
+ See [`docs/security/SECRETS-POLICY.md`](../docs/security/SECRETS-POLICY.md). The repo enforces that only `src/server.ts` may import Node `environment.ts` (ESLint + `npm run lint:server-boundary`).
31
+
15
32
  ## Usage
16
33
 
17
34
  ### Basic Setup
@@ -19,8 +36,7 @@ npm install @gvnrdao/dh-sdk
19
36
  ```typescript
20
37
  import { DiamondHandsSDK } from "@gvnrdao/dh-sdk";
21
38
 
22
- // Initialize SDK
23
- const sdk = new DiamondHandsSDK({
39
+ const sdkResult = await DiamondHandsSDK.create({
24
40
  mode: "service", // or 'standalone'
25
41
  serviceEndpoint: "http://localhost:3001",
26
42
  contractAddresses: {
@@ -29,8 +45,10 @@ const sdk = new DiamondHandsSDK({
29
45
  // ... other contract addresses
30
46
  },
31
47
  });
32
-
33
- await sdk.initialize();
48
+ if (!sdkResult.success) {
49
+ throw sdkResult.error;
50
+ }
51
+ const sdk = sdkResult.value;
34
52
  ```
35
53
 
36
54
  ### Creating a Loan
@@ -50,6 +68,55 @@ if (result.success) {
50
68
  }
51
69
  ```
52
70
 
71
+ ### UCD mint gas (`requestMintUCD`)
72
+
73
+ `mintUCD` can consume very high gas. The SDK runs **`eth_estimateGas`** on the final calldata, adds **25% headroom**, and caps the limit at **10M**. Fees use **`getFeeData()`** when available, with fallbacks. Broadcasting uses **`signer.sendTransaction`** (EIP-1559 type 2), not manual `signDigest` / raw RPC.
74
+
75
+ If **estimateGas** fails but a **static call** succeeds, on **Sepolia (chain ID 11155111)** the SDK **automatically** sends with the **fixed ceiling**; on other chains it throws unless estimation succeeds.
76
+
77
+ ### Smart wallets and same-block limits (`PositionManager`)
78
+
79
+ The on-chain `PositionManager` applies a **flash-loan protection** modifier to **`createPosition`** and **`extendPosition`**: it rate-limits by **`tx.origin`** (the top-level EOA or account that sent the outer transaction), not by `msg.sender`. This is intentional (anti-abuse); it is **not** used for access control.
80
+
81
+ **Implications for integrators:**
82
+
83
+ - **Contract wallets (e.g. Safe)** can create and extend positions: the protocol sees `msg.sender` as the wallet. Ensure you do **not** put **two** guarded calls (`create` **or** `extend`) in **one** outer transaction (e.g. a Safe multicall batch), or the second can revert with `SameBlockInteraction`.
84
+ - At most **one successful** `createPosition` **or** `extendPosition` per **block** per **`tx.origin`**. Split operations across separate transactions/blocks if needed.
85
+ - Flows where **many users** share the **same** outer submitter in the **same block** (e.g. some **account-abstraction / bundler** setups) can **collide** on that limit because they share `tx.origin`. EOA-submitted Safe transactions are typically unaffected.
86
+
87
+ ### Liquidating Positions (MEV-Protected)
88
+
89
+ The SDK provides MEV-protected liquidation using a commit-reveal system:
90
+
91
+ ```typescript
92
+ // MEV-protected liquidation (recommended)
93
+ const liquidationResult = await sdk.liquidatePosition({
94
+ positionId: "0x...",
95
+ forceContractCall: false, // Use LIT action validation
96
+ });
97
+
98
+ // Legacy admin-only liquidation (faster, for testing)
99
+ const adminResult = await sdk.liquidatePositionAdmin({
100
+ positionId: "0x...",
101
+ forceContractCall: true, // Bypass LIT action
102
+ });
103
+ ```
104
+
105
+ #### MEV Protection Features
106
+
107
+ - **Commit-Reveal System**: Prevents front-running by separating intent from execution
108
+ - **Randomized Delays**: 60-300 second delays to avoid predictable timing attacks
109
+ - **Quantum Timestamps**: LIT Protocol signed timestamps prevent replay attacks
110
+ - **Role-Based Access**: Uses LIQUIDATOR_ROLE instead of admin privileges
111
+
112
+ #### Liquidation Process
113
+
114
+ 1. **Commit Phase**: Submit liquidation intent with LIT Action validation
115
+ 2. **MEV Protection**: Wait randomized delay (60-300 seconds)
116
+ 3. **Reveal Phase**: Execute liquidation with deadline enforcement
117
+
118
+ **Note**: The commit-reveal process takes 1-5 minutes due to MEV protection. Use `liquidatePositionAdmin()` for immediate execution during testing or emergency situations.
119
+
53
120
  ## Features
54
121
 
55
122
  - ✅ **Service & Standalone Modes**: Flexible deployment options
@@ -58,6 +125,7 @@ if (result.success) {
58
125
  - ✅ **PKP Integration**: Secure key management with LIT Protocol
59
126
  - ✅ **Smart Contract Integration**: Direct interaction with Diamond Hands contracts
60
127
  - ✅ **Bitcoin Operations**: Support for Bitcoin deposit verification
128
+ - ✅ **MEV-Protected Liquidations**: Commit-reveal system prevents front-running
61
129
  - ✅ **Telegram Notifications**: Optional event notifications (Node.js only)
62
130
 
63
131
  ## API Reference
@@ -67,11 +135,13 @@ if (result.success) {
67
135
  - `initialize()` - Initialize the SDK
68
136
  - `createLoan(request)` - Create a new loan position
69
137
  - `repayLoan(positionId, amount)` - Repay an existing loan
70
- - `liquidatePosition(positionId)` - Liquidate an undercollateralized position
138
+ - `liquidatePosition(request)` - Liquidate an undercollateralized position (MEV-protected)
139
+ - `liquidatePositionAdmin(request)` - Liquidate position using admin-only access (backward compatibility)
71
140
 
72
141
  ### Configuration Options
73
142
 
74
143
  See the full API documentation for detailed configuration options and method signatures.
144
+ - API Reference (TSDoc source): [`src/index.ts`](src/index.ts)
75
145
 
76
146
  ## Telegram Notifications
77
147
 
@@ -109,6 +179,7 @@ The SDK sends notifications for:
109
179
  - UCD minting
110
180
  - Partial payments
111
181
  - Loan renewals
182
+ - Position liquidations
112
183
  - Balance confirmations
113
184
  - BTC withdrawals
114
185
  - Operation failures
@@ -117,6 +188,16 @@ The SDK sends notifications for:
117
188
 
118
189
  Never expose your Telegram bot token in frontend code. If you need notifications from browser applications, use a backend webhook endpoint instead.
119
190
 
191
+ ## Development — TypeChain
192
+
193
+ After changing Solidity contracts that the SDK consumes:
194
+
195
+ 1. `cd contracts && npm run compile` (or from `sdk/`: `npm run sync:typechain`).
196
+ 2. Commit updated `contracts/typechain-types/**` with the contract changes.
197
+ 3. Update [`sdk/src/contracts/typechain-contracts.ts`](src/contracts/typechain-contracts.ts) re-exports if new contracts need SDK-facing types.
198
+
199
+ Full details: [`docs/TYPECHAIN_IMPLEMENTATION.md`](docs/TYPECHAIN_IMPLEMENTATION.md) (regeneration, commit policy, npm publish behavior).
200
+
120
201
  ## License
121
202
 
122
203
  MIT
@@ -1,2 +1,2 @@
1
1
  /*! For license information please see 397.browser.js.LICENSE.txt */
2
- export const __webpack_esm_id__=397;export const __webpack_esm_ids__=[397];export const __webpack_esm_modules__={204:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.p2data=void 0;const n=r(1834),i=r(94778),o=r(92992),s=r(96887),f=i.OPS;t.p2data=function(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,o.typeforce)({network:o.typeforce.maybe(o.typeforce.Object),output:o.typeforce.maybe(o.typeforce.Buffer),data:o.typeforce.maybe(o.typeforce.arrayOf(o.typeforce.Buffer))},e);const r={name:"embed",network:e.network||n.bitcoin};if(s.prop(r,"output",()=>{if(e.data)return i.compile([f.OP_RETURN].concat(e.data))}),s.prop(r,"data",()=>{if(e.output)return i.decompile(e.output).slice(1)}),t.validate&&e.output){const t=i.decompile(e.output);if(t[0]!==f.OP_RETURN)throw new TypeError("Output is invalid");if(!t.slice(1).every(o.typeforce.Buffer))throw new TypeError("Output is invalid");if(e.data&&!(0,o.stacksEqual)(e.data,r.data))throw new TypeError("Data mismatch")}return Object.assign(r,e)}},920:(e,t,r)=>{var n=r(38891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.getEccLib=t.initEccLib=void 0;const i={};t.initEccLib=function(e,t){var r;e?e!==i.eccLib&&(t?.DANGER_DO_NOT_VERIFY_ECCLIB||(s("function"==typeof(r=e).isXOnlyPoint),s(r.isXOnlyPoint(o("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),s(r.isXOnlyPoint(o("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),s(r.isXOnlyPoint(o("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),s(r.isXOnlyPoint(o("0000000000000000000000000000000000000000000000000000000000000001"))),s(!r.isXOnlyPoint(o("0000000000000000000000000000000000000000000000000000000000000000"))),s(!r.isXOnlyPoint(o("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),s("function"==typeof r.xOnlyPointAddTweak),f.forEach(e=>{const t=r.xOnlyPointAddTweak(o(e.pubkey),o(e.tweak));null===e.result?s(null===t):(s(null!==t),s(t.parity===e.parity),s(n.from(t.xOnlyPubkey).equals(o(e.result))))})),i.eccLib=e):i.eccLib=e},t.getEccLib=function(){if(!i.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return i.eccLib};const o=e=>n.from(e,"hex");function s(e){if(!e)throw new Error("ecc library invalid")}const f=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}]},1834:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.testnet=t.regtest=t.bitcoin=void 0,t.bitcoin={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},t.regtest={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},t.testnet={messagePrefix:"Bitcoin Signed Message:\n",bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239}},1920:(e,t,r)=>{var n=r(35601),i=r(31677),o=n.tfJSON,s=n.TfTypeError,f=n.TfPropertyTypeError,u=n.tfSubError,a=n.getValueTypeName,c={arrayOf:function(e,t){function r(r,n){return!!i.Array(r)&&!i.Nil(r)&&!(void 0!==t.minLength&&r.length<t.minLength)&&!(void 0!==t.maxLength&&r.length>t.maxLength)&&(void 0===t.length||r.length===t.length)&&r.every(function(t,r){try{return h(e,t,n)}catch(e){throw u(e,r)}})}return e=p(e),t=t||{},r.toJSON=function(){var r="["+o(e)+"]";return void 0!==t.length?r+="{"+t.length+"}":void 0===t.minLength&&void 0===t.maxLength||(r+="{"+(void 0===t.minLength?0:t.minLength)+","+(void 0===t.maxLength?1/0:t.maxLength)+"}"),r},r},maybe:function e(t){function r(r,n){return i.Nil(r)||t(r,n,e)}return t=p(t),r.toJSON=function(){return"?"+o(t)},r},map:function(e,t){function r(r,n){if(!i.Object(r))return!1;if(i.Nil(r))return!1;for(var o in r){try{t&&h(t,o,n)}catch(e){throw u(e,o,"key")}try{var s=r[o];h(e,s,n)}catch(e){throw u(e,o)}}return!0}return e=p(e),t&&(t=p(t)),r.toJSON=t?function(){return"{"+o(t)+": "+o(e)+"}"}:function(){return"{"+o(e)+"}"},r},object:function(e){var t={};for(var r in e)t[r]=p(e[r]);function n(e,r){if(!i.Object(e))return!1;if(i.Nil(e))return!1;var n;try{for(n in t)h(t[n],e[n],r)}catch(e){throw u(e,n)}if(r)for(n in e)if(!t[n])throw new f(void 0,n);return!0}return n.toJSON=function(){return o(t)},n},anyOf:function(){var e=[].slice.call(arguments).map(p);function t(t,r){return e.some(function(e){try{return h(e,t,r)}catch(e){return!1}})}return t.toJSON=function(){return e.map(o).join("|")},t},allOf:function(){var e=[].slice.call(arguments).map(p);function t(t,r){return e.every(function(e){try{return h(e,t,r)}catch(e){return!1}})}return t.toJSON=function(){return e.map(o).join(" & ")},t},quacksLike:function(e){function t(t){return e===a(t)}return t.toJSON=function(){return e},t},tuple:function(){var e=[].slice.call(arguments).map(p);function t(t,r){return!i.Nil(t)&&!i.Nil(t.length)&&(!r||t.length===e.length)&&e.every(function(e,n){try{return h(e,t[n],r)}catch(e){throw u(e,n)}})}return t.toJSON=function(){return"("+e.map(o).join(", ")+")"},t},value:function(e){function t(t){return t===e}return t.toJSON=function(){return e},t}};function p(e){if(i.String(e))return"?"===e[0]?c.maybe(e.slice(1)):i[e]||c.quacksLike(e);if(e&&i.Object(e)){if(i.Array(e)){if(1!==e.length)throw new TypeError("Expected compile() parameter of type Array of length 1");return c.arrayOf(e[0])}return c.object(e)}return i.Function(e)?e:c.value(e)}function h(e,t,r,n){if(i.Function(e)){if(e(t,r))return!0;throw new s(n||e,t)}return h(p(e),t,r)}for(var l in c.oneOf=c.anyOf,i)h[l]=i[l];for(l in c)h[l]=c[l];var d=r(13274);for(l in d)h[l]=d[l];h.compile=p,h.TfTypeError=s,h.TfPropertyTypeError=f,e.exports=h},10148:e=>{e.exports=function(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var i=e.charAt(n),o=i.charCodeAt(0);if(255!==t[o])throw new TypeError(i+" is ambiguous");t[o]=n}var s=e.length,f=e.charAt(0),u=Math.log(s)/Math.log(256),a=Math.log(256)/Math.log(s);function c(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;for(var r=0,n=0,i=0;e[r]===f;)n++,r++;for(var o=(e.length-r)*u+1>>>0,a=new Uint8Array(o);e[r];){var c=e.charCodeAt(r);if(c>255)return;var p=t[c];if(255===p)return;for(var h=0,l=o-1;(0!==p||h<i)&&-1!==l;l--,h++)p+=s*a[l]>>>0,a[l]=p%256>>>0,p=p/256>>>0;if(0!==p)throw new Error("Non-zero carry");i=h,r++}for(var d=o-i;d!==o&&0===a[d];)d++;for(var y=new Uint8Array(n+(o-d)),w=n;d!==o;)y[w++]=a[d++];return y}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";for(var r=0,n=0,i=0,o=t.length;i!==o&&0===t[i];)i++,r++;for(var u=(o-i)*a+1>>>0,c=new Uint8Array(u);i!==o;){for(var p=t[i],h=0,l=u-1;(0!==p||h<n)&&-1!==l;l--,h++)p+=256*c[l]>>>0,c[l]=p%s>>>0,p=p/s>>>0;if(0!==p)throw new Error("Non-zero carry");n=h,i++}for(var d=u-n;d!==u&&0===c[d];)d++;for(var y=f.repeat(r);d<u;++d)y+=e.charAt(c[d]);return y},decodeUnsafe:c,decode:function(e){var t=c(e);if(t)return t;throw new Error("Non-base"+s+" character")}}}},11643:(e,t,r)=>{const n=r(10148);e.exports=n("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")},12820:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.decode=t.encode=t.encodingLength=void 0;const n=r(45029);function i(e){return e<n.OPS.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}t.encodingLength=i,t.encode=function(e,t,r){const o=i(t);return 1===o?e.writeUInt8(t,r):2===o?(e.writeUInt8(n.OPS.OP_PUSHDATA1,r),e.writeUInt8(t,r+1)):3===o?(e.writeUInt8(n.OPS.OP_PUSHDATA2,r),e.writeUInt16LE(t,r+1)):(e.writeUInt8(n.OPS.OP_PUSHDATA4,r),e.writeUInt32LE(t,r+1)),o},t.decode=function(e,t){const r=e.readUInt8(t);let i,o;if(r<n.OPS.OP_PUSHDATA1)i=r,o=1;else if(r===n.OPS.OP_PUSHDATA1){if(t+2>e.length)return null;i=e.readUInt8(t+1),o=2}else if(r===n.OPS.OP_PUSHDATA2){if(t+3>e.length)return null;i=e.readUInt16LE(t+1),o=3}else{if(t+5>e.length)return null;if(r!==n.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");i=e.readUInt32LE(t+1),o=5}return{opcode:r,number:i,size:o}}},13274:(e,t,r)=>{var n=r(38891).Buffer,i=r(31677),o=r(35601);function s(e){return n.isBuffer(e)}function f(e){return"string"==typeof e&&/^([0-9a-f]{2})+$/i.test(e)}function u(e,t){var r=e.toJSON();function n(n){if(!e(n))return!1;if(n.length===t)return!0;throw o.tfCustomError(r+"(Length: "+t+")",r+"(Length: "+n.length+")")}return n.toJSON=function(){return r},n}var a=u.bind(null,i.Array),c=u.bind(null,s),p=u.bind(null,f),h=u.bind(null,i.String),l=Math.pow(2,53)-1,d={ArrayN:a,Buffer:s,BufferN:c,Finite:function(e){return"number"==typeof e&&isFinite(e)},Hex:f,HexN:p,Int8:function(e){return e<<24>>24===e},Int16:function(e){return e<<16>>16===e},Int32:function(e){return(0|e)===e},Int53:function(e){return"number"==typeof e&&e>=-l&&e<=l&&Math.floor(e)===e},Range:function(e,t,r){function n(n,i){return r(n,i)&&n>e&&n<t}return r=r||i.Number,n.toJSON=function(){return`${r.toJSON()} between [${e}, ${t}]`},n},StringN:h,UInt8:function(e){return(255&e)===e},UInt16:function(e){return(65535&e)===e},UInt32:function(e){return e>>>0===e},UInt53:function(e){return"number"==typeof e&&e>=0&&e<=l&&Math.floor(e)===e}};for(var y in d)d[y].toJSON=function(e){return e}.bind(null,y);e.exports=d},26236:(e,t,r)=>{var n=r(38891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.p2pkh=void 0;const i=r(58892),o=r(1834),s=r(94778),f=r(92992),u=r(96887),a=r(60709),c=s.OPS;t.p2pkh=function(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||{}),(0,f.typeforce)({network:f.typeforce.maybe(f.typeforce.Object),address:f.typeforce.maybe(f.typeforce.String),hash:f.typeforce.maybe(f.typeforce.BufferN(20)),output:f.typeforce.maybe(f.typeforce.BufferN(25)),pubkey:f.typeforce.maybe(f.isPoint),signature:f.typeforce.maybe(s.isCanonicalScriptSignature),input:f.typeforce.maybe(f.typeforce.Buffer)},e);const r=u.value(()=>{const t=n.from(a.decode(e.address));return{version:t.readUInt8(0),hash:t.slice(1)}}),p=u.value(()=>s.decompile(e.input)),h=e.network||o.bitcoin,l={name:"p2pkh",network:h};if(u.prop(l,"address",()=>{if(!l.hash)return;const e=n.allocUnsafe(21);return e.writeUInt8(h.pubKeyHash,0),l.hash.copy(e,1),a.encode(e)}),u.prop(l,"hash",()=>e.output?e.output.slice(3,23):e.address?r().hash:e.pubkey||l.pubkey?i.hash160(e.pubkey||l.pubkey):void 0),u.prop(l,"output",()=>{if(l.hash)return s.compile([c.OP_DUP,c.OP_HASH160,l.hash,c.OP_EQUALVERIFY,c.OP_CHECKSIG])}),u.prop(l,"pubkey",()=>{if(e.input)return p()[1]}),u.prop(l,"signature",()=>{if(e.input)return p()[0]}),u.prop(l,"input",()=>{if(e.pubkey&&e.signature)return s.compile([e.signature,e.pubkey])}),u.prop(l,"witness",()=>{if(l.input)return[]}),t.validate){let t=n.from([]);if(e.address){if(r().version!==h.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(20!==r().hash.length)throw new TypeError("Invalid address");t=r().hash}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(25!==e.output.length||e.output[0]!==c.OP_DUP||e.output[1]!==c.OP_HASH160||20!==e.output[2]||e.output[23]!==c.OP_EQUALVERIFY||e.output[24]!==c.OP_CHECKSIG)throw new TypeError("Output is invalid");const r=e.output.slice(3,23);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");t=r}if(e.pubkey){const r=i.hash160(e.pubkey);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");t=r}if(e.input){const r=p();if(2!==r.length)throw new TypeError("Input is invalid");if(!s.isCanonicalScriptSignature(r[0]))throw new TypeError("Input has invalid signature");if(!(0,f.isPoint)(r[1]))throw new TypeError("Input has invalid pubkey");if(e.signature&&!e.signature.equals(r[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(r[1]))throw new TypeError("Pubkey mismatch");const n=i.hash160(r[1]);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch")}}return Object.assign(l,e)}},31677:e=>{var t={Array:function(e){return null!=e&&e.constructor===Array},Boolean:function(e){return"boolean"==typeof e},Function:function(e){return"function"==typeof e},Nil:function(e){return null==e},Number:function(e){return"number"==typeof e},Object:function(e){return"object"==typeof e},String:function(e){return"string"==typeof e},"":function(){return!0}};for(var r in t.Null=t.Nil,t)t[r].toJSON=function(e){return e}.bind(null,r);e.exports=t},31817:(e,t,r)=>{var n=r(38891),i=n.Buffer;function o(e,t){for(var r in e)t[r]=e[r]}function s(e,t,r){return i(e,t,r)}i.from&&i.alloc&&i.allocUnsafe&&i.allocUnsafeSlow?e.exports=n:(o(n,t),t.Buffer=s),s.prototype=Object.create(i.prototype),o(i,s),s.from=function(e,t,r){if("number"==typeof e)throw new TypeError("Argument must not be a number");return i(e,t,r)},s.alloc=function(e,t,r){if("number"!=typeof e)throw new TypeError("Argument must be a number");var n=i(e);return void 0!==t?"string"==typeof r?n.fill(t,r):n.fill(t):n.fill(0),n},s.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return i(e)},s.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return n.SlowBuffer(e)}},34538:(e,t,r)=>{var n=r(38891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.encode=t.decode=t.check=void 0,t.check=function(e){if(e.length<8)return!1;if(e.length>72)return!1;if(48!==e[0])return!1;if(e[1]!==e.length-2)return!1;if(2!==e[2])return!1;const t=e[3];if(0===t)return!1;if(5+t>=e.length)return!1;if(2!==e[4+t])return!1;const r=e[5+t];return!(0===r||6+t+r!==e.length||128&e[4]||t>1&&0===e[4]&&!(128&e[5])||128&e[t+6]||r>1&&0===e[t+6]&&!(128&e[t+7]))},t.decode=function(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(48!==e[0])throw new Error("Expected DER sequence");if(e[1]!==e.length-2)throw new Error("DER sequence length is invalid");if(2!==e[2])throw new Error("Expected DER integer");const t=e[3];if(0===t)throw new Error("R length is zero");if(5+t>=e.length)throw new Error("R length is too long");if(2!==e[4+t])throw new Error("Expected DER integer (2)");const r=e[5+t];if(0===r)throw new Error("S length is zero");if(6+t+r!==e.length)throw new Error("S length is invalid");if(128&e[4])throw new Error("R value is negative");if(t>1&&0===e[4]&&!(128&e[5]))throw new Error("R value excessively padded");if(128&e[t+6])throw new Error("S value is negative");if(r>1&&0===e[t+6]&&!(128&e[t+7]))throw new Error("S value excessively padded");return{r:e.slice(4,4+t),s:e.slice(6+t)}},t.encode=function(e,t){const r=e.length,i=t.length;if(0===r)throw new Error("R length is zero");if(0===i)throw new Error("S length is zero");if(r>33)throw new Error("R length is too long");if(i>33)throw new Error("S length is too long");if(128&e[0])throw new Error("R value is negative");if(128&t[0])throw new Error("S value is negative");if(r>1&&0===e[0]&&!(128&e[1]))throw new Error("R value excessively padded");if(i>1&&0===t[0]&&!(128&t[1]))throw new Error("S value excessively padded");const o=n.allocUnsafe(6+r+i);return o[0]=48,o[1]=o.length-2,o[2]=2,o[3]=e.length,e.copy(o,4),o[4+r]=2,o[5+r]=t.length,t.copy(o,6+r),o}},35601:(e,t,r)=>{var n=r(31677);function i(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function o(e){return n.Nil(e)?"":i(e.constructor)}function s(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function f(e){return n.Function(e)?e.toJSON?e.toJSON():i(e):n.Array(e)?"Array":e&&n.Object(e)?"Object":void 0!==e?e:""}function u(e,t,r){var i=function(e){return n.Function(e)?"":n.String(e)?JSON.stringify(e):e&&n.Object(e)?"":e}(t);return"Expected "+f(e)+", got"+(""!==r?" "+r:"")+(""!==i?" "+i:"")}function a(e,t,r){r=r||o(t),this.message=u(e,t,r),s(this,a),this.__type=e,this.__value=t,this.__valueTypeName=r}function c(e,t,r,n,i){e?(i=i||o(n),this.message=function(e,t,r,n,i){var o='" of type ';return"key"===t&&(o='" with key type '),u('property "'+f(r)+o+f(e),n,i)}(e,r,t,n,i)):this.message='Unexpected property "'+t+'"',s(this,a),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=i}a.prototype=Object.create(Error.prototype),a.prototype.constructor=a,c.prototype=Object.create(Error.prototype),c.prototype.constructor=a,e.exports={TfTypeError:a,TfPropertyTypeError:c,tfCustomError:function(e,t){return new a(e,{},t)},tfSubError:function(e,t,r){return e instanceof c?(t=t+"."+e.__property,e=new c(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof a&&(e=new c(e.__type,t,r,e.__value,e.__valueTypeName)),s(e),e},tfJSON:f,getValueTypeName:o}},38191:(e,t,r)=>{var n=r(38891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.encode=t.decode=void 0;const i=r(34538),o=r(94778),s=r(92992),{typeforce:f}=s,u=n.alloc(1,0);function a(e){let t=0;for(;0===e[t];)++t;return t===e.length?u:128&(e=e.slice(t))[0]?n.concat([u,e],1+e.length):e}function c(e){0===e[0]&&(e=e.slice(1));const t=n.alloc(32,0),r=Math.max(0,32-e.length);return e.copy(t,r),t}t.decode=function(e){const t=e.readUInt8(e.length-1);if(!(0,o.isDefinedHashType)(t))throw new Error("Invalid hashType "+t);const r=i.decode(e.slice(0,-1)),s=c(r.r),f=c(r.s);return{signature:n.concat([s,f],64),hashType:t}},t.encode=function(e,t){if(f({signature:s.BufferN(64),hashType:s.UInt8},{signature:e,hashType:t}),!(0,o.isDefinedHashType)(t))throw new Error("Invalid hashType "+t);const r=n.allocUnsafe(1);r.writeUInt8(t,0);const u=a(e.slice(0,32)),c=a(e.slice(32,64));return n.concat([i.encode(u,c),r])}},43881:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.p2tr=void 0;const n=r(38891),i=r(1834),o=r(94778),s=r(92992),f=r(920),u=r(50102),a=r(96887),c=r(39771),p=r(60762),h=o.OPS;t.p2tr=function(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||{}),(0,s.typeforce)({address:s.typeforce.maybe(s.typeforce.String),input:s.typeforce.maybe(s.typeforce.BufferN(0)),network:s.typeforce.maybe(s.typeforce.Object),output:s.typeforce.maybe(s.typeforce.BufferN(34)),internalPubkey:s.typeforce.maybe(s.typeforce.BufferN(32)),hash:s.typeforce.maybe(s.typeforce.BufferN(32)),pubkey:s.typeforce.maybe(s.typeforce.BufferN(32)),signature:s.typeforce.maybe(s.typeforce.anyOf(s.typeforce.BufferN(64),s.typeforce.BufferN(65))),witness:s.typeforce.maybe(s.typeforce.arrayOf(s.typeforce.Buffer)),scriptTree:s.typeforce.maybe(s.isTaptree),redeem:s.typeforce.maybe({output:s.typeforce.maybe(s.typeforce.Buffer),redeemVersion:s.typeforce.maybe(s.typeforce.Number),witness:s.typeforce.maybe(s.typeforce.arrayOf(s.typeforce.Buffer))}),redeemVersion:s.typeforce.maybe(s.typeforce.Number)},e);const r=a.value(()=>(0,p.fromBech32)(e.address)),l=a.value(()=>{if(e.witness&&e.witness.length)return e.witness.length>=2&&80===e.witness[e.witness.length-1][0]?e.witness.slice(0,-1):e.witness.slice()}),d=a.value(()=>e.scriptTree?(0,u.toHashTree)(e.scriptTree):e.hash?{hash:e.hash}:void 0),y=e.network||i.bitcoin,w={name:"p2tr",network:y};if(a.prop(w,"address",()=>{if(!w.pubkey)return;const e=c.bech32m.toWords(w.pubkey);return e.unshift(1),c.bech32m.encode(y.bech32,e)}),a.prop(w,"hash",()=>{const e=d();if(e)return e.hash;const t=l();if(t&&t.length>1){const e=t[t.length-1],r=e[0]&s.TAPLEAF_VERSION_MASK,n=t[t.length-2],i=(0,u.tapleafHash)({output:n,version:r});return(0,u.rootHashFromPath)(e,i)}return null}),a.prop(w,"output",()=>{if(w.pubkey)return o.compile([h.OP_1,w.pubkey])}),a.prop(w,"redeemVersion",()=>e.redeemVersion?e.redeemVersion:e.redeem&&void 0!==e.redeem.redeemVersion&&null!==e.redeem.redeemVersion?e.redeem.redeemVersion:u.LEAF_VERSION_TAPSCRIPT),a.prop(w,"redeem",()=>{const e=l();if(e&&!(e.length<2))return{output:e[e.length-2],witness:e.slice(0,-2),redeemVersion:e[e.length-1][0]&s.TAPLEAF_VERSION_MASK}}),a.prop(w,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.output)return e.output.slice(2);if(e.address)return r().data;if(w.internalPubkey){const e=(0,u.tweakKey)(w.internalPubkey,w.hash);if(e)return e.x}}),a.prop(w,"internalPubkey",()=>{if(e.internalPubkey)return e.internalPubkey;const t=l();return t&&t.length>1?t[t.length-1].slice(1,33):void 0}),a.prop(w,"signature",()=>{if(e.signature)return e.signature;const t=l();return t&&1===t.length?t[0]:void 0}),a.prop(w,"witness",()=>{if(e.witness)return e.witness;const t=d();if(t&&e.redeem&&e.redeem.output&&e.internalPubkey){const r=(0,u.tapleafHash)({output:e.redeem.output,version:w.redeemVersion}),i=(0,u.findScriptPath)(t,r);if(!i)return;const o=(0,u.tweakKey)(e.internalPubkey,t.hash);if(!o)return;const s=n.Buffer.concat([n.Buffer.from([w.redeemVersion|o.parity]),e.internalPubkey].concat(i));return[e.redeem.output,s]}return e.signature?[e.signature]:void 0}),t.validate){let t=n.Buffer.from([]);if(e.address){if(y&&y.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(1!==r().version)throw new TypeError("Invalid address version");if(32!==r().data.length)throw new TypeError("Invalid address data");t=r().data}if(e.pubkey){if(t.length>0&&!t.equals(e.pubkey))throw new TypeError("Pubkey mismatch");t=e.pubkey}if(e.output){if(34!==e.output.length||e.output[0]!==h.OP_1||32!==e.output[1])throw new TypeError("Output is invalid");if(t.length>0&&!t.equals(e.output.slice(2)))throw new TypeError("Pubkey mismatch");t=e.output.slice(2)}if(e.internalPubkey){const r=(0,u.tweakKey)(e.internalPubkey,w.hash);if(t.length>0&&!t.equals(r.x))throw new TypeError("Pubkey mismatch");t=r.x}if(t&&t.length&&!(0,f.getEccLib)().isXOnlyPoint(t))throw new TypeError("Invalid pubkey for p2tr");const i=d();if(e.hash&&i&&!e.hash.equals(i.hash))throw new TypeError("Hash mismatch");if(e.redeem&&e.redeem.output&&i){const t=(0,u.tapleafHash)({output:e.redeem.output,version:w.redeemVersion});if(!(0,u.findScriptPath)(i,t))throw new TypeError("Redeem script not in tree")}const a=l();if(e.redeem&&w.redeem){if(e.redeem.redeemVersion&&e.redeem.redeemVersion!==w.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(e.redeem.output){if(0===o.decompile(e.redeem.output).length)throw new TypeError("Redeem.output is invalid");if(w.redeem.output&&!e.redeem.output.equals(w.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(e.redeem.witness&&w.redeem.witness&&!(0,s.stacksEqual)(e.redeem.witness,w.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(a&&a.length)if(1===a.length){if(e.signature&&!e.signature.equals(a[0]))throw new TypeError("Signature mismatch")}else{const r=a[a.length-1];if(r.length<33)throw new TypeError(`The control-block length is too small. Got ${r.length}, expected min 33.`);if((r.length-33)%32!=0)throw new TypeError(`The control-block length of ${r.length} is incorrect!`);const n=(r.length-33)/32;if(n>128)throw new TypeError(`The script path is too long. Got ${n}, expected max 128.`);const i=r.slice(1,33);if(e.internalPubkey&&!e.internalPubkey.equals(i))throw new TypeError("Internal pubkey mismatch");if(!(0,f.getEccLib)().isXOnlyPoint(i))throw new TypeError("Invalid internalPubkey for p2tr witness");const o=r[0]&s.TAPLEAF_VERSION_MASK,c=a[a.length-2],p=(0,u.tapleafHash)({output:c,version:o}),h=(0,u.rootHashFromPath)(r,p),l=(0,u.tweakKey)(i,h);if(!l)throw new TypeError("Invalid outputKey for p2tr witness");if(t.length&&!t.equals(l.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(l.parity!==(1&r[0]))throw new Error("Incorrect parity")}}return Object.assign(w,e)}},45029:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.REVERSE_OPS=t.OPS=void 0;const r={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};t.OPS=r;const n={};t.REVERSE_OPS=n;for(const e of Object.keys(r))n[r[e]]=e},50102:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.tweakKey=t.tapTweakHash=t.tapleafHash=t.findScriptPath=t.toHashTree=t.rootHashFromPath=t.MAX_TAPTREE_DEPTH=t.LEAF_VERSION_TAPSCRIPT=void 0;const n=r(38891),i=r(920),o=r(58892),s=r(85666),f=r(92992);function u(e){const r=e.version||t.LEAF_VERSION_TAPSCRIPT;return o.taggedHash("TapLeaf",n.Buffer.concat([n.Buffer.from([r]),p(e.output)]))}function a(e,t){return o.taggedHash("TapTweak",n.Buffer.concat(t?[e,t]:[e]))}function c(e,t){return o.taggedHash("TapBranch",n.Buffer.concat([e,t]))}function p(e){const t=s.varuint.encodingLength(e.length),r=n.Buffer.allocUnsafe(t);return s.varuint.encode(e.length,r),n.Buffer.concat([r,e])}t.LEAF_VERSION_TAPSCRIPT=192,t.MAX_TAPTREE_DEPTH=128,t.rootHashFromPath=function(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 t=0;t<r;t++){const r=e.slice(33+32*t,65+32*t);n=n.compare(r)<0?c(n,r):c(r,n)}return n},t.toHashTree=function e(t){if((0,f.isTapleaf)(t))return{hash:u(t)};const r=[e(t[0]),e(t[1])];r.sort((e,t)=>e.hash.compare(t.hash));const[n,i]=r;return{hash:c(n.hash,i.hash),left:n,right:i}},t.findScriptPath=function e(t,r){if("left"in(n=t)&&"right"in n){const n=e(t.left,r);if(void 0!==n)return[...n,t.right.hash];const i=e(t.right,r);if(void 0!==i)return[...i,t.left.hash]}else if(t.hash.equals(r))return[];var n},t.tapleafHash=u,t.tapTweakHash=a,t.tweakKey=function(e,t){if(!n.Buffer.isBuffer(e))return null;if(32!==e.length)return null;if(t&&32!==t.length)return null;const r=a(e,t),o=(0,i.getEccLib)().xOnlyPointAddTweak(e,r);return o&&null!==o.xOnlyPubkey?{parity:o.parity,x:n.Buffer.from(o.xOnlyPubkey)}:null}},57828:(e,t,r)=>{var n=r(38891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.p2sh=void 0;const i=r(58892),o=r(1834),s=r(94778),f=r(92992),u=r(96887),a=r(60709),c=s.OPS;t.p2sh=function(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||{}),(0,f.typeforce)({network:f.typeforce.maybe(f.typeforce.Object),address:f.typeforce.maybe(f.typeforce.String),hash:f.typeforce.maybe(f.typeforce.BufferN(20)),output:f.typeforce.maybe(f.typeforce.BufferN(23)),redeem:f.typeforce.maybe({network:f.typeforce.maybe(f.typeforce.Object),output:f.typeforce.maybe(f.typeforce.Buffer),input:f.typeforce.maybe(f.typeforce.Buffer),witness:f.typeforce.maybe(f.typeforce.arrayOf(f.typeforce.Buffer))}),input:f.typeforce.maybe(f.typeforce.Buffer),witness:f.typeforce.maybe(f.typeforce.arrayOf(f.typeforce.Buffer))},e);let r=e.network;r||(r=e.redeem&&e.redeem.network||o.bitcoin);const p={network:r},h=u.value(()=>{const t=n.from(a.decode(e.address));return{version:t.readUInt8(0),hash:t.slice(1)}}),l=u.value(()=>s.decompile(e.input)),d=u.value(()=>{const t=l(),i=t[t.length-1];return{network:r,output:i===c.OP_FALSE?n.from([]):i,input:s.compile(t.slice(0,-1)),witness:e.witness||[]}});if(u.prop(p,"address",()=>{if(!p.hash)return;const e=n.allocUnsafe(21);return e.writeUInt8(p.network.scriptHash,0),p.hash.copy(e,1),a.encode(e)}),u.prop(p,"hash",()=>e.output?e.output.slice(2,22):e.address?h().hash:p.redeem&&p.redeem.output?i.hash160(p.redeem.output):void 0),u.prop(p,"output",()=>{if(p.hash)return s.compile([c.OP_HASH160,p.hash,c.OP_EQUAL])}),u.prop(p,"redeem",()=>{if(e.input)return d()}),u.prop(p,"input",()=>{if(e.redeem&&e.redeem.input&&e.redeem.output)return s.compile([].concat(s.decompile(e.redeem.input),e.redeem.output))}),u.prop(p,"witness",()=>p.redeem&&p.redeem.witness?p.redeem.witness:p.input?[]:void 0),u.prop(p,"name",()=>{const e=["p2sh"];return void 0!==p.redeem&&void 0!==p.redeem.name&&e.push(p.redeem.name),e.join("-")}),t.validate){let t=n.from([]);if(e.address){if(h().version!==r.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(20!==h().hash.length)throw new TypeError("Invalid address");t=h().hash}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(23!==e.output.length||e.output[0]!==c.OP_HASH160||20!==e.output[1]||e.output[22]!==c.OP_EQUAL)throw new TypeError("Output is invalid");const r=e.output.slice(2,22);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");t=r}const o=e=>{if(e.output){const r=s.decompile(e.output);if(!r||r.length<1)throw new TypeError("Redeem.output too short");if(e.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(s.countNonPushOnlyOPs(r)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const n=i.hash160(e.output);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");t=n}if(e.input){const t=e.input.length>0,r=e.witness&&e.witness.length>0;if(!t&&!r)throw new TypeError("Empty input");if(t&&r)throw new TypeError("Input and witness provided");if(t){const t=s.decompile(e.input);if(!s.isPushOnly(t))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const e=l();if(!e||e.length<1)throw new TypeError("Input too short");if(!n.isBuffer(d().output))throw new TypeError("Input is invalid");o(d())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==r)throw new TypeError("Network mismatch");if(e.input){const t=d();if(e.redeem.output&&!e.redeem.output.equals(t.output))throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&!e.redeem.input.equals(t.input))throw new TypeError("Redeem.input mismatch")}o(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!(0,f.stacksEqual)(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(p,e)}},58892:(e,t,r)=>{var n=r(38891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.taggedHash=t.TAGGED_HASH_PREFIXES=t.TAGS=t.hash256=t.hash160=t.sha256=t.sha1=t.ripemd160=void 0;const i=r(74290),o=r(93553),s=r(7811);function f(e){return n.from((0,s.sha256)(Uint8Array.from(e)))}t.ripemd160=function(e){return n.from((0,i.ripemd160)(Uint8Array.from(e)))},t.sha1=function(e){return n.from((0,o.sha1)(Uint8Array.from(e)))},t.sha256=f,t.hash160=function(e){return n.from((0,i.ripemd160)((0,s.sha256)(Uint8Array.from(e))))},t.hash256=function(e){return n.from((0,s.sha256)((0,s.sha256)(Uint8Array.from(e))))},t.TAGS=["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],t.TAGGED_HASH_PREFIXES={"BIP0340/challenge":n.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":n.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":n.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:n.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:n.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:n.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:n.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":n.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":n.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])},t.taggedHash=function(e,r){return f(n.concat([t.TAGGED_HASH_PREFIXES[e],r]))}},60709:(e,t,r)=>{var{sha256:n}=r(7811),i=r(73088);e.exports=i(function(e){return n(n(e))})},60762:(e,t,r)=>{var n=r(38891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.toOutputScript=t.fromOutputScript=t.toBech32=t.toBase58Check=t.fromBech32=t.fromBase58Check=void 0;const i=r(1834),o=r(70393),s=r(94778),f=r(92992),u=r(39771),a=r(60709),c="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 p(e){const t=n.from(a.decode(e));if(t.length<21)throw new TypeError(e+" is too short");if(t.length>21)throw new TypeError(e+" is too long");return{version:t.readUInt8(0),hash:t.slice(1)}}function h(e){let t,r;try{t=u.bech32.decode(e)}catch(e){}if(t){if(r=t.words[0],0!==r)throw new TypeError(e+" uses wrong encoding")}else if(t=u.bech32m.decode(e),r=t.words[0],0===r)throw new TypeError(e+" uses wrong encoding");const i=u.bech32.fromWords(t.words.slice(1));return{version:r,prefix:t.prefix,data:n.from(i)}}function l(e,t,r){const n=u.bech32.toWords(e);return n.unshift(t),0===t?u.bech32.encode(r,n):u.bech32m.encode(r,n)}t.fromBase58Check=p,t.fromBech32=h,t.toBase58Check=function(e,t){(0,f.typeforce)((0,f.tuple)(f.Hash160bit,f.UInt8),arguments);const r=n.allocUnsafe(21);return r.writeUInt8(t,0),e.copy(r,1),a.encode(r)},t.toBech32=l,t.fromOutputScript=function(e,t){t=t||i.bitcoin;try{return o.p2pkh({output:e,network:t}).address}catch(e){}try{return o.p2sh({output:e,network:t}).address}catch(e){}try{return o.p2wpkh({output:e,network:t}).address}catch(e){}try{return o.p2wsh({output:e,network:t}).address}catch(e){}try{return o.p2tr({output:e,network:t}).address}catch(e){}try{return function(e,t){const r=e.slice(2);if(r.length<2||r.length>40)throw new TypeError("Invalid program length for segwit address");const n=e[0]-80;if(n<2||n>16)throw new TypeError("Invalid version for segwit address");if(e[1]!==r.length)throw new TypeError("Invalid script for segwit address");return console.warn(c),l(r,n,t.bech32)}(e,t)}catch(e){}throw new Error(s.toASM(e)+" has no matching Address")},t.toOutputScript=function(e,t){let r,n;t=t||i.bitcoin;try{r=p(e)}catch(e){}if(r){if(r.version===t.pubKeyHash)return o.p2pkh({hash:r.hash}).output;if(r.version===t.scriptHash)return o.p2sh({hash:r.hash}).output}else{try{n=h(e)}catch(e){}if(n){if(n.prefix!==t.bech32)throw new Error(e+" has an invalid prefix");if(0===n.version){if(20===n.data.length)return o.p2wpkh({hash:n.data}).output;if(32===n.data.length)return o.p2wsh({hash:n.data}).output}else if(1===n.version){if(32===n.data.length)return o.p2tr({pubkey:n.data}).output}else if(n.version>=2&&n.version<=16&&n.data.length>=2&&n.data.length<=40)return console.warn(c),s.compile([n.version+80,n.data])}}throw new Error(e+" has no matching Script")}},62329:(e,t,r)=>{var n=r(38891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.Transaction=void 0;const i=r(85666),o=r(58892),s=r(94778),f=r(94778),u=r(92992),{typeforce:a}=u;function c(e){const t=e.length;return i.varuint.encodingLength(t)+t}const p=n.allocUnsafe(0),h=[],l=n.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),d=n.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),y=n.from("ffffffffffffffff","hex"),w={script:p,valueBuffer:y};class m{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(e,t){const r=new i.BufferReader(e),n=new m;n.version=r.readInt32();const o=r.readUInt8(),s=r.readUInt8();let f=!1;o===m.ADVANCED_TRANSACTION_MARKER&&s===m.ADVANCED_TRANSACTION_FLAG?f=!0:r.offset-=2;const u=r.readVarInt();for(let e=0;e<u;++e)n.ins.push({hash:r.readSlice(32),index:r.readUInt32(),script:r.readVarSlice(),sequence:r.readUInt32(),witness:h});const a=r.readVarInt();for(let e=0;e<a;++e)n.outs.push({value:r.readUInt64(),script:r.readVarSlice()});if(f){for(let e=0;e<u;++e)n.ins[e].witness=r.readVector();if(!n.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(n.locktime=r.readUInt32(),t)return n;if(r.offset!==e.length)throw new Error("Transaction has unexpected data");return n}static fromHex(e){return m.fromBuffer(n.from(e,"hex"),!1)}static isCoinbaseHash(e){a(u.Hash256bit,e);for(let t=0;t<32;++t)if(0!==e[t])return!1;return!0}isCoinbase(){return 1===this.ins.length&&m.isCoinbaseHash(this.ins[0].hash)}addInput(e,t,r,n){return a(u.tuple(u.Hash256bit,u.UInt32,u.maybe(u.UInt32),u.maybe(u.Buffer)),arguments),u.Null(r)&&(r=m.DEFAULT_SEQUENCE),this.ins.push({hash:e,index:t,script:n||p,sequence:r,witness:h})-1}addOutput(e,t){return a(u.tuple(u.Buffer,u.Satoshi),arguments),this.outs.push({script:e,value:t})-1}hasWitnesses(){return this.ins.some(e=>0!==e.witness.length)}stripWitnesses(){this.ins.forEach(e=>{e.witness=h})}weight(){return 3*this.byteLength(!1)+this.byteLength(!0)}virtualSize(){return Math.ceil(this.weight()/4)}byteLength(e=!0){const t=e&&this.hasWitnesses();return(t?10:8)+i.varuint.encodingLength(this.ins.length)+i.varuint.encodingLength(this.outs.length)+this.ins.reduce((e,t)=>e+40+c(t.script),0)+this.outs.reduce((e,t)=>e+8+c(t.script),0)+(t?this.ins.reduce((e,t)=>e+function(e){const t=e.length;return i.varuint.encodingLength(t)+e.reduce((e,t)=>e+c(t),0)}(t.witness),0):0)}clone(){const e=new m;return e.version=this.version,e.locktime=this.locktime,e.ins=this.ins.map(e=>({hash:e.hash,index:e.index,script:e.script,sequence:e.sequence,witness:e.witness})),e.outs=this.outs.map(e=>({script:e.script,value:e.value})),e}hashForSignature(e,t,r){if(a(u.tuple(u.UInt32,u.Buffer,u.Number),arguments),e>=this.ins.length)return d;const i=s.compile(s.decompile(t).filter(e=>e!==f.OPS.OP_CODESEPARATOR)),c=this.clone();if((31&r)===m.SIGHASH_NONE)c.outs=[],c.ins.forEach((t,r)=>{r!==e&&(t.sequence=0)});else if((31&r)===m.SIGHASH_SINGLE){if(e>=this.outs.length)return d;c.outs.length=e+1;for(let t=0;t<e;t++)c.outs[t]=w;c.ins.forEach((t,r)=>{r!==e&&(t.sequence=0)})}r&m.SIGHASH_ANYONECANPAY?(c.ins=[c.ins[e]],c.ins[0].script=i):(c.ins.forEach(e=>{e.script=p}),c.ins[e].script=i);const h=n.allocUnsafe(c.byteLength(!1)+4);return h.writeInt32LE(r,h.length-4),c.__toBuffer(h,0,!1),o.hash256(h)}hashForWitnessV1(e,t,r,s,f,h){if(a(u.tuple(u.UInt32,a.arrayOf(u.Buffer),a.arrayOf(u.Satoshi),u.UInt32),arguments),r.length!==this.ins.length||t.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const l=s===m.SIGHASH_DEFAULT?m.SIGHASH_ALL:s&m.SIGHASH_OUTPUT_MASK,d=(s&m.SIGHASH_INPUT_MASK)===m.SIGHASH_ANYONECANPAY,y=l===m.SIGHASH_NONE,w=l===m.SIGHASH_SINGLE;let b=p,g=p,E=p,O=p,P=p;if(!d){let e=i.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(t=>{e.writeSlice(t.hash),e.writeUInt32(t.index)}),b=o.sha256(e.end()),e=i.BufferWriter.withCapacity(8*this.ins.length),r.forEach(t=>e.writeUInt64(t)),g=o.sha256(e.end()),e=i.BufferWriter.withCapacity(t.map(c).reduce((e,t)=>e+t)),t.forEach(t=>e.writeVarSlice(t)),E=o.sha256(e.end()),e=i.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(t=>e.writeUInt32(t.sequence)),O=o.sha256(e.end())}if(y||w){if(w&&e<this.outs.length){const t=this.outs[e],r=i.BufferWriter.withCapacity(8+c(t.script));r.writeUInt64(t.value),r.writeVarSlice(t.script),P=o.sha256(r.end())}}else{const e=this.outs.map(e=>8+c(e.script)).reduce((e,t)=>e+t),t=i.BufferWriter.withCapacity(e);this.outs.forEach(e=>{t.writeUInt64(e.value),t.writeVarSlice(e.script)}),P=o.sha256(t.end())}const S=(f?2:0)+(h?1:0),v=174-(d?49:0)-(y?32:0)+(h?32:0)+(f?37:0),_=i.BufferWriter.withCapacity(v);if(_.writeUInt8(s),_.writeInt32(this.version),_.writeUInt32(this.locktime),_.writeSlice(b),_.writeSlice(g),_.writeSlice(E),_.writeSlice(O),y||w||_.writeSlice(P),_.writeUInt8(S),d){const n=this.ins[e];_.writeSlice(n.hash),_.writeUInt32(n.index),_.writeUInt64(r[e]),_.writeVarSlice(t[e]),_.writeUInt32(n.sequence)}else _.writeUInt32(e);if(h){const e=i.BufferWriter.withCapacity(c(h));e.writeVarSlice(h),_.writeSlice(o.sha256(e.end()))}return w&&_.writeSlice(P),f&&(_.writeSlice(f),_.writeUInt8(0),_.writeUInt32(4294967295)),o.taggedHash("TapSighash",n.concat([n.from([0]),_.end()]))}hashForWitnessV0(e,t,r,s){a(u.tuple(u.UInt32,u.Buffer,u.Satoshi,u.UInt32),arguments);let f,p=n.from([]),h=l,d=l,y=l;if(s&m.SIGHASH_ANYONECANPAY||(p=n.allocUnsafe(36*this.ins.length),f=new i.BufferWriter(p,0),this.ins.forEach(e=>{f.writeSlice(e.hash),f.writeUInt32(e.index)}),d=o.hash256(p)),s&m.SIGHASH_ANYONECANPAY||(31&s)===m.SIGHASH_SINGLE||(31&s)===m.SIGHASH_NONE||(p=n.allocUnsafe(4*this.ins.length),f=new i.BufferWriter(p,0),this.ins.forEach(e=>{f.writeUInt32(e.sequence)}),y=o.hash256(p)),(31&s)!==m.SIGHASH_SINGLE&&(31&s)!==m.SIGHASH_NONE){const e=this.outs.reduce((e,t)=>e+8+c(t.script),0);p=n.allocUnsafe(e),f=new i.BufferWriter(p,0),this.outs.forEach(e=>{f.writeUInt64(e.value),f.writeVarSlice(e.script)}),h=o.hash256(p)}else if((31&s)===m.SIGHASH_SINGLE&&e<this.outs.length){const t=this.outs[e];p=n.allocUnsafe(8+c(t.script)),f=new i.BufferWriter(p,0),f.writeUInt64(t.value),f.writeVarSlice(t.script),h=o.hash256(p)}p=n.allocUnsafe(156+c(t)),f=new i.BufferWriter(p,0);const w=this.ins[e];return f.writeInt32(this.version),f.writeSlice(d),f.writeSlice(y),f.writeSlice(w.hash),f.writeUInt32(w.index),f.writeVarSlice(t),f.writeUInt64(r),f.writeUInt32(w.sequence),f.writeSlice(h),f.writeUInt32(this.locktime),f.writeUInt32(s),o.hash256(p)}getHash(e){return e&&this.isCoinbase()?n.alloc(32,0):o.hash256(this.__toBuffer(void 0,void 0,e))}getId(){return(0,i.reverseBuffer)(this.getHash(!1)).toString("hex")}toBuffer(e,t){return this.__toBuffer(e,t,!0)}toHex(){return this.toBuffer(void 0,void 0).toString("hex")}setInputScript(e,t){a(u.tuple(u.Number,u.Buffer),arguments),this.ins[e].script=t}setWitness(e,t){a(u.tuple(u.Number,[u.Buffer]),arguments),this.ins[e].witness=t}__toBuffer(e,t,r=!1){e||(e=n.allocUnsafe(this.byteLength(r)));const o=new i.BufferWriter(e,t||0);o.writeInt32(this.version);const s=r&&this.hasWitnesses();return s&&(o.writeUInt8(m.ADVANCED_TRANSACTION_MARKER),o.writeUInt8(m.ADVANCED_TRANSACTION_FLAG)),o.writeVarInt(this.ins.length),this.ins.forEach(e=>{o.writeSlice(e.hash),o.writeUInt32(e.index),o.writeVarSlice(e.script),o.writeUInt32(e.sequence)}),o.writeVarInt(this.outs.length),this.outs.forEach(e=>{void 0!==e.value?o.writeUInt64(e.value):o.writeSlice(e.valueBuffer),o.writeVarSlice(e.script)}),s&&this.ins.forEach(e=>{o.writeVector(e.witness)}),o.writeUInt32(this.locktime),void 0!==t?e.slice(t,o.offset):e}}t.Transaction=m,m.DEFAULT_SEQUENCE=4294967295,m.SIGHASH_DEFAULT=0,m.SIGHASH_ALL=1,m.SIGHASH_NONE=2,m.SIGHASH_SINGLE=3,m.SIGHASH_ANYONECANPAY=128,m.SIGHASH_OUTPUT_MASK=3,m.SIGHASH_INPUT_MASK=128,m.ADVANCED_TRANSACTION_MARKER=0,m.ADVANCED_TRANSACTION_FLAG=1},63929:(e,t,r)=>{var n=r(31817).Buffer;function i(e){if(e<0||e>9007199254740991||e%1!=0)throw new RangeError("value out of range")}function o(e){return i(e),e<253?1:e<=65535?3:e<=4294967295?5:9}e.exports={encode:function e(t,r,s){if(i(t),r||(r=n.allocUnsafe(o(t))),!n.isBuffer(r))throw new TypeError("buffer must be a Buffer instance");return s||(s=0),t<253?(r.writeUInt8(t,s),e.bytes=1):t<=65535?(r.writeUInt8(253,s),r.writeUInt16LE(t,s+1),e.bytes=3):t<=4294967295?(r.writeUInt8(254,s),r.writeUInt32LE(t,s+1),e.bytes=5):(r.writeUInt8(255,s),r.writeUInt32LE(t>>>0,s+1),r.writeUInt32LE(t/4294967296|0,s+5),e.bytes=9),r},decode:function e(t,r){if(!n.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");r||(r=0);var o=t.readUInt8(r);if(o<253)return e.bytes=1,o;if(253===o)return e.bytes=3,t.readUInt16LE(r+1);if(254===o)return e.bytes=5,t.readUInt32LE(r+1);e.bytes=9;var s=t.readUInt32LE(r+1),f=4294967296*t.readUInt32LE(r+5)+s;return i(f),f},encodingLength:o}},70393:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.p2tr=t.p2wsh=t.p2wpkh=t.p2sh=t.p2pkh=t.p2pk=t.p2ms=t.embed=void 0;const n=r(204);Object.defineProperty(t,"embed",{enumerable:!0,get:function(){return n.p2data}});const i=r(85391);Object.defineProperty(t,"p2ms",{enumerable:!0,get:function(){return i.p2ms}});const o=r(72854);Object.defineProperty(t,"p2pk",{enumerable:!0,get:function(){return o.p2pk}});const s=r(26236);Object.defineProperty(t,"p2pkh",{enumerable:!0,get:function(){return s.p2pkh}});const f=r(57828);Object.defineProperty(t,"p2sh",{enumerable:!0,get:function(){return f.p2sh}});const u=r(87135);Object.defineProperty(t,"p2wpkh",{enumerable:!0,get:function(){return u.p2wpkh}});const a=r(76693);Object.defineProperty(t,"p2wsh",{enumerable:!0,get:function(){return a.p2wsh}});const c=r(43881);Object.defineProperty(t,"p2tr",{enumerable:!0,get:function(){return c.p2tr}})},72854:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.p2pk=void 0;const n=r(1834),i=r(94778),o=r(92992),s=r(96887),f=i.OPS;t.p2pk=function(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||{}),(0,o.typeforce)({network:o.typeforce.maybe(o.typeforce.Object),output:o.typeforce.maybe(o.typeforce.Buffer),pubkey:o.typeforce.maybe(o.isPoint),signature:o.typeforce.maybe(i.isCanonicalScriptSignature),input:o.typeforce.maybe(o.typeforce.Buffer)},e);const r=s.value(()=>i.decompile(e.input)),u={name:"p2pk",network:e.network||n.bitcoin};if(s.prop(u,"output",()=>{if(e.pubkey)return i.compile([e.pubkey,f.OP_CHECKSIG])}),s.prop(u,"pubkey",()=>{if(e.output)return e.output.slice(1,-1)}),s.prop(u,"signature",()=>{if(e.input)return r()[0]}),s.prop(u,"input",()=>{if(e.signature)return i.compile([e.signature])}),s.prop(u,"witness",()=>{if(u.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==f.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,o.isPoint)(u.pubkey))throw new TypeError("Output pubkey is invalid");if(e.pubkey&&!e.pubkey.equals(u.pubkey))throw new TypeError("Pubkey mismatch")}if(e.signature&&e.input&&!e.input.equals(u.input))throw new TypeError("Signature mismatch");if(e.input){if(1!==r().length)throw new TypeError("Input is invalid");if(!i.isCanonicalScriptSignature(u.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(u,e)}},73088:(e,t,r)=>{var n=r(11643);e.exports=function(e){function t(t){var r=t.slice(0,-4),n=t.slice(-4),i=e(r);if(!(n[0]^i[0]|n[1]^i[1]|n[2]^i[2]|n[3]^i[3]))return r}return{encode:function(t){var r=Uint8Array.from(t),i=e(r),o=r.length+4,s=new Uint8Array(o);return s.set(r,0),s.set(i.subarray(0,4),r.length),n.encode(s,o)},decode:function(e){var r=t(n.decode(e));if(!r)throw new Error("Invalid checksum");return r},decodeUnsafe:function(e){var r=n.decodeUnsafe(e);if(r)return t(r)}}}},76693:(e,t,r)=>{var n=r(38891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.p2wsh=void 0;const i=r(58892),o=r(1834),s=r(94778),f=r(92992),u=r(96887),a=r(39771),c=s.OPS,p=n.alloc(0);function h(e){return!(!n.isBuffer(e)||65!==e.length||4!==e[0]||!(0,f.isPoint)(e))}t.p2wsh=function(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||{}),(0,f.typeforce)({network:f.typeforce.maybe(f.typeforce.Object),address:f.typeforce.maybe(f.typeforce.String),hash:f.typeforce.maybe(f.typeforce.BufferN(32)),output:f.typeforce.maybe(f.typeforce.BufferN(34)),redeem:f.typeforce.maybe({input:f.typeforce.maybe(f.typeforce.Buffer),network:f.typeforce.maybe(f.typeforce.Object),output:f.typeforce.maybe(f.typeforce.Buffer),witness:f.typeforce.maybe(f.typeforce.arrayOf(f.typeforce.Buffer))}),input:f.typeforce.maybe(f.typeforce.BufferN(0)),witness:f.typeforce.maybe(f.typeforce.arrayOf(f.typeforce.Buffer))},e);const r=u.value(()=>{const t=a.bech32.decode(e.address),r=t.words.shift(),i=a.bech32.fromWords(t.words);return{version:r,prefix:t.prefix,data:n.from(i)}}),l=u.value(()=>s.decompile(e.redeem.input));let d=e.network;d||(d=e.redeem&&e.redeem.network||o.bitcoin);const y={network:d};if(u.prop(y,"address",()=>{if(!y.hash)return;const e=a.bech32.toWords(y.hash);return e.unshift(0),a.bech32.encode(d.bech32,e)}),u.prop(y,"hash",()=>e.output?e.output.slice(2):e.address?r().data:y.redeem&&y.redeem.output?i.sha256(y.redeem.output):void 0),u.prop(y,"output",()=>{if(y.hash)return s.compile([c.OP_0,y.hash])}),u.prop(y,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:p,witness:e.witness.slice(0,-1)}}),u.prop(y,"input",()=>{if(y.witness)return p}),u.prop(y,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const t=s.toStack(l());return y.redeem=Object.assign({witness:t},e.redeem),y.redeem.input=p,[].concat(t,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),u.prop(y,"name",()=>{const e=["p2wsh"];return void 0!==y.redeem&&void 0!==y.redeem.name&&e.push(y.redeem.name),e.join("-")}),t.validate){let t=n.from([]);if(e.address){if(r().prefix!==d.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(0!==r().version)throw new TypeError("Invalid address version");if(32!==r().data.length)throw new TypeError("Invalid address data");t=r().data}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(34!==e.output.length||e.output[0]!==c.OP_0||32!==e.output[1])throw new TypeError("Output is invalid");const r=e.output.slice(2);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");t=r}if(e.redeem){if(e.redeem.network&&e.redeem.network!==d)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 r=s.decompile(e.redeem.output);if(!r||r.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(s.countNonPushOnlyOPs(r)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const n=i.sha256(e.redeem.output);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");t=n}if(e.redeem.input&&!s.isPushOnly(l()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!(0,f.stacksEqual)(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&l().some(h)||e.redeem.output&&(s.decompile(e.redeem.output)||[]).some(h))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(e.witness&&e.witness.length>0){const t=e.witness[e.witness.length-1];if(e.redeem&&e.redeem.output&&!e.redeem.output.equals(t))throw new TypeError("Witness and redeem.output mismatch");if(e.witness.some(h)||(s.decompile(t)||[]).some(h))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(y,e)}},77397:(e,t,r)=>{var n=r(38891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.signatureBlocksAction=t.checkInputForSig=t.pubkeyInScript=t.pubkeyPositionInScript=t.witnessStackToScriptWitness=t.isP2TR=t.isP2SHScript=t.isP2WSHScript=t.isP2WPKH=t.isP2PKH=t.isP2PK=t.isP2MS=void 0;const i=r(80862),o=r(94778),s=r(62329),f=r(58892),u=r(70393);function a(e){return t=>{try{return e({output:t}),!0}catch(e){return!1}}}function c(e,t){const r=(0,f.hash160)(e),n=e.slice(1,33),i=o.decompile(t);if(null===i)throw new Error("Unknown script error");return i.findIndex(t=>"number"!=typeof t&&(t.equals(e)||t.equals(r)||t.equals(n)))}function p(e,t,r){const{hashType:n}=t(e),i=[];switch(n&s.Transaction.SIGHASH_ANYONECANPAY&&i.push("addInput"),31&n){case s.Transaction.SIGHASH_ALL:break;case s.Transaction.SIGHASH_SINGLE:case s.Transaction.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence")}return-1===i.indexOf(r)}t.isP2MS=a(u.p2ms),t.isP2PK=a(u.p2pk),t.isP2PKH=a(u.p2pkh),t.isP2WPKH=a(u.p2wpkh),t.isP2WSHScript=a(u.p2wsh),t.isP2SHScript=a(u.p2sh),t.isP2TR=a(u.p2tr),t.witnessStackToScriptWitness=function(e){let t=n.allocUnsafe(0);function r(e){const r=t.length,o=i.encodingLength(e);t=n.concat([t,n.allocUnsafe(o)]),i.encode(e,t,r)}var o;return r((o=e).length),o.forEach(function(e){r(e.length),function(e){t=n.concat([t,n.from(e)])}(e)}),t},t.pubkeyPositionInScript=c,t.pubkeyInScript=function(e,t){return-1!==c(e,t)},t.checkInputForSig=function(e,t){return function(e){let t=[];if(0===(e.partialSig||[]).length){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=function(e){const t=e.finalScriptSig&&o.decompile(e.finalScriptSig)||[],r=e.finalScriptWitness&&o.decompile(e.finalScriptWitness)||[];return t.concat(r).filter(e=>n.isBuffer(e)&&o.isCanonicalScriptSignature(e)).map(e=>({signature:e}))}(e)}else t=e.partialSig;return t.map(e=>e.signature)}(e).some(e=>p(e,o.signature.decode,t))},t.signatureBlocksAction=p},80862:(e,t,r)=>{var n=r(38891).Buffer;function i(e){if(e<0||e>9007199254740991||e%1!=0)throw new RangeError("value out of range")}function o(e){return i(e),e<253?1:e<=65535?3:e<=4294967295?5:9}Object.defineProperty(t,"__esModule",{value:!0}),t.encode=function e(t,r,s){if(i(t),r||(r=n.allocUnsafe(o(t))),!n.isBuffer(r))throw new TypeError("buffer must be a Buffer instance");return s||(s=0),t<253?(r.writeUInt8(t,s),Object.assign(e,{bytes:1})):t<=65535?(r.writeUInt8(253,s),r.writeUInt16LE(t,s+1),Object.assign(e,{bytes:3})):t<=4294967295?(r.writeUInt8(254,s),r.writeUInt32LE(t,s+1),Object.assign(e,{bytes:5})):(r.writeUInt8(255,s),r.writeUInt32LE(t>>>0,s+1),r.writeUInt32LE(t/4294967296|0,s+5),Object.assign(e,{bytes:9})),r},t.decode=function e(t,r){if(!n.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");r||(r=0);const o=t.readUInt8(r);if(o<253)return Object.assign(e,{bytes:1}),o;if(253===o)return Object.assign(e,{bytes:3}),t.readUInt16LE(r+1);if(254===o)return Object.assign(e,{bytes:5}),t.readUInt32LE(r+1);{Object.assign(e,{bytes:9});const n=t.readUInt32LE(r+1),o=4294967296*t.readUInt32LE(r+5)+n;return i(o),o}},t.encodingLength=o},84068:(e,t,r)=>{var n=r(38891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.encode=t.decode=void 0,t.decode=function(e,t,r){t=t||4,r=void 0===r||r;const n=e.length;if(0===n)return 0;if(n>t)throw new TypeError("Script number overflow");if(r&&!(127&e[n-1]||!(n<=1)&&128&e[n-2]))throw new Error("Non-minimally encoded script number");if(5===n){const t=e.readUInt32LE(0),r=e.readUInt8(4);return 128&r?-(4294967296*(-129&r)+t):4294967296*r+t}let i=0;for(let t=0;t<n;++t)i|=e[t]<<8*t;return 128&e[n-1]?-(i&~(128<<8*(n-1))):i},t.encode=function(e){let t=Math.abs(e);const r=(i=t)>2147483647?5:i>8388607?4:i>32767?3:i>127?2:i>0?1:0;var i;const o=n.allocUnsafe(r),s=e<0;for(let e=0;e<r;++e)o.writeUInt8(255&t,e),t>>=8;return 128&o[r-1]?o.writeUInt8(s?128:0,r-1):s&&(o[r-1]|=128),o}},85391:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.p2ms=void 0;const n=r(1834),i=r(94778),o=r(92992),s=r(96887),f=i.OPS,u=f.OP_RESERVED;t.p2ms=function(e,t){if(!(e.input||e.output||e.pubkeys&&void 0!==e.m||e.signatures))throw new TypeError("Not enough data");function r(e){return i.isCanonicalScriptSignature(e)||void 0!==(t.allowIncomplete&&e===f.OP_0)}t=Object.assign({validate:!0},t||{}),(0,o.typeforce)({network:o.typeforce.maybe(o.typeforce.Object),m:o.typeforce.maybe(o.typeforce.Number),n:o.typeforce.maybe(o.typeforce.Number),output:o.typeforce.maybe(o.typeforce.Buffer),pubkeys:o.typeforce.maybe(o.typeforce.arrayOf(o.isPoint)),signatures:o.typeforce.maybe(o.typeforce.arrayOf(r)),input:o.typeforce.maybe(o.typeforce.Buffer)},e);const a={network:e.network||n.bitcoin};let c=[],p=!1;function h(e){p||(p=!0,c=i.decompile(e),a.m=c[0]-u,a.n=c[c.length-2]-u,a.pubkeys=c.slice(1,-2))}if(s.prop(a,"output",()=>{if(e.m&&a.n&&e.pubkeys)return i.compile([].concat(u+e.m,e.pubkeys,u+a.n,f.OP_CHECKMULTISIG))}),s.prop(a,"m",()=>{if(a.output)return h(a.output),a.m}),s.prop(a,"n",()=>{if(a.pubkeys)return a.pubkeys.length}),s.prop(a,"pubkeys",()=>{if(e.output)return h(e.output),a.pubkeys}),s.prop(a,"signatures",()=>{if(e.input)return i.decompile(e.input).slice(1)}),s.prop(a,"input",()=>{if(e.signatures)return i.compile([f.OP_0].concat(e.signatures))}),s.prop(a,"witness",()=>{if(a.input)return[]}),s.prop(a,"name",()=>{if(a.m&&a.n)return`p2ms(${a.m} of ${a.n})`}),t.validate){if(e.output){if(h(e.output),!o.typeforce.Number(c[0]))throw new TypeError("Output is invalid");if(!o.typeforce.Number(c[c.length-2]))throw new TypeError("Output is invalid");if(c[c.length-1]!==f.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(a.m<=0||a.n>16||a.m>a.n||a.n!==c.length-3)throw new TypeError("Output is invalid");if(!a.pubkeys.every(e=>(0,o.isPoint)(e)))throw new TypeError("Output is invalid");if(void 0!==e.m&&e.m!==a.m)throw new TypeError("m mismatch");if(void 0!==e.n&&e.n!==a.n)throw new TypeError("n mismatch");if(e.pubkeys&&!(0,o.stacksEqual)(e.pubkeys,a.pubkeys))throw new TypeError("Pubkeys mismatch")}if(e.pubkeys){if(void 0!==e.n&&e.n!==e.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(a.n=e.pubkeys.length,a.n<a.m)throw new TypeError("Pubkey count cannot be less than m")}if(e.signatures){if(e.signatures.length<a.m)throw new TypeError("Not enough signatures provided");if(e.signatures.length>a.m)throw new TypeError("Too many signatures provided")}if(e.input){if(e.input[0]!==f.OP_0)throw new TypeError("Input is invalid");if(0===a.signatures.length||!a.signatures.every(r))throw new TypeError("Input has invalid signature(s)");if(e.signatures&&!(0,o.stacksEqual)(e.signatures,a.signatures))throw new TypeError("Signature mismatch");if(void 0!==e.m&&e.m!==e.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(a,e)}},85666:(e,t,r)=>{var n=r(38891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.BufferReader=t.BufferWriter=t.cloneBuffer=t.reverseBuffer=t.writeUInt64LE=t.readUInt64LE=t.varuint=void 0;const i=r(92992),{typeforce:o}=i,s=r(63929);function f(e,t){if("number"!=typeof e)throw new Error("cannot write a non-number as a number");if(e<0)throw new Error("specified a negative value for writing an unsigned value");if(e>t)throw new Error("RangeError: value out of range");if(Math.floor(e)!==e)throw new Error("value has a fractional component")}function u(e,t){const r=e.readUInt32LE(t);let n=e.readUInt32LE(t+4);return n*=4294967296,f(n+r,9007199254740991),n+r}function a(e,t,r){return f(t,9007199254740991),e.writeInt32LE(-1&t,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}t.varuint=s,t.readUInt64LE=u,t.writeUInt64LE=a,t.reverseBuffer=function(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},t.cloneBuffer=function(e){const t=n.allocUnsafe(e.length);return e.copy(t),t};class c{static withCapacity(e){return new c(n.alloc(e))}constructor(e,t=0){this.buffer=e,this.offset=t,o(i.tuple(i.Buffer,i.UInt32),[e,t])}writeUInt8(e){this.offset=this.buffer.writeUInt8(e,this.offset)}writeInt32(e){this.offset=this.buffer.writeInt32LE(e,this.offset)}writeUInt32(e){this.offset=this.buffer.writeUInt32LE(e,this.offset)}writeUInt64(e){this.offset=a(this.buffer,e,this.offset)}writeVarInt(e){s.encode(e,this.buffer,this.offset),this.offset+=s.encode.bytes}writeSlice(e){if(this.buffer.length<this.offset+e.length)throw new Error("Cannot write slice out of bounds");this.offset+=e.copy(this.buffer,this.offset)}writeVarSlice(e){this.writeVarInt(e.length),this.writeSlice(e)}writeVector(e){this.writeVarInt(e.length),e.forEach(e=>this.writeVarSlice(e))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}}t.BufferWriter=c,t.BufferReader=class{constructor(e,t=0){this.buffer=e,this.offset=t,o(i.tuple(i.Buffer,i.UInt32),[e,t])}readUInt8(){const e=this.buffer.readUInt8(this.offset);return this.offset++,e}readInt32(){const e=this.buffer.readInt32LE(this.offset);return this.offset+=4,e}readUInt32(){const e=this.buffer.readUInt32LE(this.offset);return this.offset+=4,e}readUInt64(){const e=u(this.buffer,this.offset);return this.offset+=8,e}readVarInt(){const e=s.decode(this.buffer,this.offset);return this.offset+=s.decode.bytes,e}readSlice(e){if(this.buffer.length<this.offset+e)throw new Error("Cannot read slice out of bounds");const t=this.buffer.slice(this.offset,this.offset+e);return this.offset+=e,t}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const e=this.readVarInt(),t=[];for(let r=0;r<e;r++)t.push(this.readVarSlice());return t}}},87135:(e,t,r)=>{var n=r(38891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.p2wpkh=void 0;const i=r(58892),o=r(1834),s=r(94778),f=r(92992),u=r(96887),a=r(39771),c=s.OPS,p=n.alloc(0);t.p2wpkh=function(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||{}),(0,f.typeforce)({address:f.typeforce.maybe(f.typeforce.String),hash:f.typeforce.maybe(f.typeforce.BufferN(20)),input:f.typeforce.maybe(f.typeforce.BufferN(0)),network:f.typeforce.maybe(f.typeforce.Object),output:f.typeforce.maybe(f.typeforce.BufferN(22)),pubkey:f.typeforce.maybe(f.isPoint),signature:f.typeforce.maybe(s.isCanonicalScriptSignature),witness:f.typeforce.maybe(f.typeforce.arrayOf(f.typeforce.Buffer))},e);const r=u.value(()=>{const t=a.bech32.decode(e.address),r=t.words.shift(),i=a.bech32.fromWords(t.words);return{version:r,prefix:t.prefix,data:n.from(i)}}),h=e.network||o.bitcoin,l={name:"p2wpkh",network:h};if(u.prop(l,"address",()=>{if(!l.hash)return;const e=a.bech32.toWords(l.hash);return e.unshift(0),a.bech32.encode(h.bech32,e)}),u.prop(l,"hash",()=>e.output?e.output.slice(2,22):e.address?r().data:e.pubkey||l.pubkey?i.hash160(e.pubkey||l.pubkey):void 0),u.prop(l,"output",()=>{if(l.hash)return s.compile([c.OP_0,l.hash])}),u.prop(l,"pubkey",()=>e.pubkey?e.pubkey:e.witness?e.witness[1]:void 0),u.prop(l,"signature",()=>{if(e.witness)return e.witness[0]}),u.prop(l,"input",()=>{if(l.witness)return p}),u.prop(l,"witness",()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]}),t.validate){let t=n.from([]);if(e.address){if(h&&h.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(0!==r().version)throw new TypeError("Invalid address version");if(20!==r().data.length)throw new TypeError("Invalid address data");t=r().data}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(22!==e.output.length||e.output[0]!==c.OP_0||20!==e.output[1])throw new TypeError("Output is invalid");if(t.length>0&&!t.equals(e.output.slice(2)))throw new TypeError("Hash mismatch");t=e.output.slice(2)}if(e.pubkey){const r=i.hash160(e.pubkey);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");if(t=r,!(0,f.isPoint)(e.pubkey)||33!==e.pubkey.length)throw new TypeError("Invalid pubkey for p2wpkh")}if(e.witness){if(2!==e.witness.length)throw new TypeError("Witness is invalid");if(!s.isCanonicalScriptSignature(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,f.isPoint)(e.witness[1])||33!==e.witness[1].length)throw new TypeError("Witness has invalid pubkey");if(e.signature&&!e.signature.equals(e.witness[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(e.witness[1]))throw new TypeError("Pubkey mismatch");const r=i.hash160(e.witness[1]);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch")}}return Object.assign(l,e)}},92992:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.oneOf=t.Null=t.BufferN=t.Function=t.UInt32=t.UInt8=t.tuple=t.maybe=t.Hex=t.Buffer=t.String=t.Boolean=t.Array=t.Number=t.Hash256bit=t.Hash160bit=t.Buffer256bit=t.isTaptree=t.isTapleaf=t.TAPLEAF_VERSION_MASK=t.Satoshi=t.isPoint=t.stacksEqual=t.typeforce=void 0;const n=r(38891);t.typeforce=r(1920);const i=n.Buffer.alloc(32,0),o=n.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function s(e){return!(!e||!("output"in e)||!n.Buffer.isBuffer(e.output)||void 0!==e.version&&(e.version&t.TAPLEAF_VERSION_MASK)!==e.version)}t.stacksEqual=function(e,t){return e.length===t.length&&e.every((e,r)=>e.equals(t[r]))},t.isPoint=function(e){if(!n.Buffer.isBuffer(e))return!1;if(e.length<33)return!1;const t=e[0],r=e.slice(1,33);if(0===r.compare(i))return!1;if(r.compare(o)>=0)return!1;if((2===t||3===t)&&33===e.length)return!0;const s=e.slice(33);return 0!==s.compare(i)&&!(s.compare(o)>=0)&&4===t&&65===e.length},t.Satoshi=function(e){return t.typeforce.UInt53(e)&&e<=21e14},t.TAPLEAF_VERSION_MASK=254,t.isTapleaf=s,t.isTaptree=function e(r){return(0,t.Array)(r)?2===r.length&&r.every(t=>e(t)):s(r)},t.Buffer256bit=t.typeforce.BufferN(32),t.Hash160bit=t.typeforce.BufferN(20),t.Hash256bit=t.typeforce.BufferN(32),t.Number=t.typeforce.Number,t.Array=t.typeforce.Array,t.Boolean=t.typeforce.Boolean,t.String=t.typeforce.String,t.Buffer=t.typeforce.Buffer,t.Hex=t.typeforce.Hex,t.maybe=t.typeforce.maybe,t.tuple=t.typeforce.tuple,t.UInt8=t.typeforce.UInt8,t.UInt32=t.typeforce.UInt32,t.Function=t.typeforce.Function,t.BufferN=t.typeforce.BufferN,t.Null=t.typeforce.Null,t.oneOf=t.typeforce.oneOf},93553:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.sha1=t.SHA1=void 0;const n=r(29403);t.SHA1=n.SHA1,t.sha1=n.sha1},94778:(e,t,r)=>{var n=r(38891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.signature=t.number=t.isCanonicalScriptSignature=t.isDefinedHashType=t.isCanonicalPubKey=t.toStack=t.fromASM=t.toASM=t.decompile=t.compile=t.countNonPushOnlyOPs=t.isPushOnly=t.OPS=void 0;const i=r(34538),o=r(45029);Object.defineProperty(t,"OPS",{enumerable:!0,get:function(){return o.OPS}});const s=r(12820),f=r(84068),u=r(38191),a=r(92992),{typeforce:c}=a,p=o.OPS.OP_RESERVED;function h(e){return a.Buffer(e)||function(e){return a.Number(e)&&(e===o.OPS.OP_0||e>=o.OPS.OP_1&&e<=o.OPS.OP_16||e===o.OPS.OP_1NEGATE)}(e)}function l(e){return a.Array(e)&&e.every(h)}function d(e){return 0===e.length?o.OPS.OP_0:1===e.length?e[0]>=1&&e[0]<=16?p+e[0]:129===e[0]?o.OPS.OP_1NEGATE:void 0:void 0}function y(e){return n.isBuffer(e)}function w(e){return n.isBuffer(e)}function m(e){if(y(e))return e;c(a.Array,e);const t=e.reduce((e,t)=>w(t)?1===t.length&&void 0!==d(t)?e+1:e+s.encodingLength(t.length)+t.length:e+1,0),r=n.allocUnsafe(t);let i=0;if(e.forEach(e=>{if(w(e)){const t=d(e);if(void 0!==t)return r.writeUInt8(t,i),void(i+=1);i+=s.encode(r,e.length,i),e.copy(r,i),i+=e.length}else r.writeUInt8(e,i),i+=1}),i!==r.length)throw new Error("Could not decode chunks");return r}function b(e){if(t=e,a.Array(t))return e;var t;c(a.Buffer,e);const r=[];let n=0;for(;n<e.length;){const t=e[n];if(t>o.OPS.OP_0&&t<=o.OPS.OP_PUSHDATA4){const t=s.decode(e,n);if(null===t)return null;if(n+=t.size,n+t.number>e.length)return null;const i=e.slice(n,n+t.number);n+=t.number;const o=d(i);void 0!==o?r.push(o):r.push(i)}else r.push(t),n+=1}return r}function g(e){const t=-129&e;return t>0&&t<4}t.isPushOnly=l,t.countNonPushOnlyOPs=function(e){return e.length-e.filter(h).length},t.compile=m,t.decompile=b,t.toASM=function(e){if(y(e)&&(e=b(e)),!e)throw new Error("Could not convert invalid chunks to ASM");return e.map(e=>{if(w(e)){const t=d(e);if(void 0===t)return e.toString("hex");e=t}return o.REVERSE_OPS[e]}).join(" ")},t.fromASM=function(e){return c(a.String,e),m(e.split(" ").map(e=>void 0!==o.OPS[e]?o.OPS[e]:(c(a.Hex,e),n.from(e,"hex"))))},t.toStack=function(e){return e=b(e),c(l,e),e.map(e=>w(e)?e:e===o.OPS.OP_0?n.allocUnsafe(0):f.encode(e-p))},t.isCanonicalPubKey=function(e){return a.isPoint(e)},t.isDefinedHashType=g,t.isCanonicalScriptSignature=function(e){return!!n.isBuffer(e)&&!!g(e[e.length-1])&&i.check(e.slice(0,-1))},t.number=f,t.signature=u},96887:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.value=t.prop=void 0,t.prop=function(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){const e=r.call(this);return this[t]=e,e},set(e){Object.defineProperty(this,t,{configurable:!0,enumerable:!0,value:e,writable:!0})}})},t.value=function(e){let t;return()=>(void 0!==t||(t=e()),t)}}};
2
+ export const __webpack_esm_id__=397;export const __webpack_esm_ids__=[397];export const __webpack_esm_modules__={102:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.tweakKey=t.tapTweakHash=t.tapleafHash=t.findScriptPath=t.toHashTree=t.rootHashFromPath=t.MAX_TAPTREE_DEPTH=t.LEAF_VERSION_TAPSCRIPT=void 0;const n=r(8891),i=r(8539),o=r(8892),s=r(5666),f=r(2992);function u(e){const r=e.version||t.LEAF_VERSION_TAPSCRIPT;return o.taggedHash("TapLeaf",n.Buffer.concat([n.Buffer.from([r]),p(e.output)]))}function a(e,t){return o.taggedHash("TapTweak",n.Buffer.concat(t?[e,t]:[e]))}function c(e,t){return o.taggedHash("TapBranch",n.Buffer.concat([e,t]))}function p(e){const t=s.varuint.encodingLength(e.length),r=n.Buffer.allocUnsafe(t);return s.varuint.encode(e.length,r),n.Buffer.concat([r,e])}t.LEAF_VERSION_TAPSCRIPT=192,t.MAX_TAPTREE_DEPTH=128,t.rootHashFromPath=function(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 t=0;t<r;t++){const r=e.slice(33+32*t,65+32*t);n=n.compare(r)<0?c(n,r):c(r,n)}return n},t.toHashTree=function e(t){if((0,f.isTapleaf)(t))return{hash:u(t)};const r=[e(t[0]),e(t[1])];r.sort((e,t)=>e.hash.compare(t.hash));const[n,i]=r;return{hash:c(n.hash,i.hash),left:n,right:i}},t.findScriptPath=function e(t,r){if("left"in(n=t)&&"right"in n){const n=e(t.left,r);if(void 0!==n)return[...n,t.right.hash];const i=e(t.right,r);if(void 0!==i)return[...i,t.left.hash]}else if(t.hash.equals(r))return[];var n},t.tapleafHash=u,t.tapTweakHash=a,t.tweakKey=function(e,t){if(!n.Buffer.isBuffer(e))return null;if(32!==e.length)return null;if(t&&32!==t.length)return null;const r=a(e,t),o=(0,i.getEccLib)().xOnlyPointAddTweak(e,r);return o&&null!==o.xOnlyPubkey?{parity:o.parity,x:n.Buffer.from(o.xOnlyPubkey)}:null}},148:e=>{e.exports=function(e){if(e.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),r=0;r<t.length;r++)t[r]=255;for(var n=0;n<e.length;n++){var i=e.charAt(n),o=i.charCodeAt(0);if(255!==t[o])throw new TypeError(i+" is ambiguous");t[o]=n}var s=e.length,f=e.charAt(0),u=Math.log(s)/Math.log(256),a=Math.log(256)/Math.log(s);function c(e){if("string"!=typeof e)throw new TypeError("Expected String");if(0===e.length)return new Uint8Array;for(var r=0,n=0,i=0;e[r]===f;)n++,r++;for(var o=(e.length-r)*u+1>>>0,a=new Uint8Array(o);e[r];){var c=e.charCodeAt(r);if(c>255)return;var p=t[c];if(255===p)return;for(var h=0,l=o-1;(0!==p||h<i)&&-1!==l;l--,h++)p+=s*a[l]>>>0,a[l]=p%256>>>0,p=p/256>>>0;if(0!==p)throw new Error("Non-zero carry");i=h,r++}for(var d=o-i;d!==o&&0===a[d];)d++;for(var y=new Uint8Array(n+(o-d)),w=n;d!==o;)y[w++]=a[d++];return y}return{encode:function(t){if(t instanceof Uint8Array||(ArrayBuffer.isView(t)?t=new Uint8Array(t.buffer,t.byteOffset,t.byteLength):Array.isArray(t)&&(t=Uint8Array.from(t))),!(t instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(0===t.length)return"";for(var r=0,n=0,i=0,o=t.length;i!==o&&0===t[i];)i++,r++;for(var u=(o-i)*a+1>>>0,c=new Uint8Array(u);i!==o;){for(var p=t[i],h=0,l=u-1;(0!==p||h<n)&&-1!==l;l--,h++)p+=256*c[l]>>>0,c[l]=p%s>>>0,p=p/s>>>0;if(0!==p)throw new Error("Non-zero carry");n=h,i++}for(var d=u-n;d!==u&&0===c[d];)d++;for(var y=f.repeat(r);d<u;++d)y+=e.charAt(c[d]);return y},decodeUnsafe:c,decode:function(e){var t=c(e);if(t)return t;throw new Error("Non-base"+s+" character")}}}},204:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.p2data=void 0;const n=r(1834),i=r(4778),o=r(2992),s=r(6887),f=i.OPS;t.p2data=function(e,t){if(!e.data&&!e.output)throw new TypeError("Not enough data");t=Object.assign({validate:!0},t||{}),(0,o.typeforce)({network:o.typeforce.maybe(o.typeforce.Object),output:o.typeforce.maybe(o.typeforce.Buffer),data:o.typeforce.maybe(o.typeforce.arrayOf(o.typeforce.Buffer))},e);const r={name:"embed",network:e.network||n.bitcoin};if(s.prop(r,"output",()=>{if(e.data)return i.compile([f.OP_RETURN].concat(e.data))}),s.prop(r,"data",()=>{if(e.output)return i.decompile(e.output).slice(1)}),t.validate&&e.output){const t=i.decompile(e.output);if(t[0]!==f.OP_RETURN)throw new TypeError("Output is invalid");if(!t.slice(1).every(o.typeforce.Buffer))throw new TypeError("Output is invalid");if(e.data&&!(0,o.stacksEqual)(e.data,r.data))throw new TypeError("Data mismatch")}return Object.assign(r,e)}},393:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.p2tr=t.p2wsh=t.p2wpkh=t.p2sh=t.p2pkh=t.p2pk=t.p2ms=t.embed=void 0;const n=r(204);Object.defineProperty(t,"embed",{enumerable:!0,get:function(){return n.p2data}});const i=r(5391);Object.defineProperty(t,"p2ms",{enumerable:!0,get:function(){return i.p2ms}});const o=r(2854);Object.defineProperty(t,"p2pk",{enumerable:!0,get:function(){return o.p2pk}});const s=r(6236);Object.defineProperty(t,"p2pkh",{enumerable:!0,get:function(){return s.p2pkh}});const f=r(7828);Object.defineProperty(t,"p2sh",{enumerable:!0,get:function(){return f.p2sh}});const u=r(7135);Object.defineProperty(t,"p2wpkh",{enumerable:!0,get:function(){return u.p2wpkh}});const a=r(6693);Object.defineProperty(t,"p2wsh",{enumerable:!0,get:function(){return a.p2wsh}});const c=r(3881);Object.defineProperty(t,"p2tr",{enumerable:!0,get:function(){return c.p2tr}})},709:(e,t,r)=>{var{sha256:n}=r(7811),i=r(3088);e.exports=i(function(e){return n(n(e))})},862:(e,t,r)=>{var n=r(8891).Buffer;function i(e){if(e<0||e>9007199254740991||e%1!=0)throw new RangeError("value out of range")}function o(e){return i(e),e<253?1:e<=65535?3:e<=4294967295?5:9}Object.defineProperty(t,"__esModule",{value:!0}),t.encode=function e(t,r,s){if(i(t),r||(r=n.allocUnsafe(o(t))),!n.isBuffer(r))throw new TypeError("buffer must be a Buffer instance");return s||(s=0),t<253?(r.writeUInt8(t,s),Object.assign(e,{bytes:1})):t<=65535?(r.writeUInt8(253,s),r.writeUInt16LE(t,s+1),Object.assign(e,{bytes:3})):t<=4294967295?(r.writeUInt8(254,s),r.writeUInt32LE(t,s+1),Object.assign(e,{bytes:5})):(r.writeUInt8(255,s),r.writeUInt32LE(t>>>0,s+1),r.writeUInt32LE(t/4294967296|0,s+5),Object.assign(e,{bytes:9})),r},t.decode=function e(t,r){if(!n.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");r||(r=0);const o=t.readUInt8(r);if(o<253)return Object.assign(e,{bytes:1}),o;if(253===o)return Object.assign(e,{bytes:3}),t.readUInt16LE(r+1);if(254===o)return Object.assign(e,{bytes:5}),t.readUInt32LE(r+1);{Object.assign(e,{bytes:9});const n=t.readUInt32LE(r+1),o=4294967296*t.readUInt32LE(r+5)+n;return i(o),o}},t.encodingLength=o},1643:(e,t,r)=>{const n=r(148);e.exports=n("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")},1677:e=>{var t={Array:function(e){return null!=e&&e.constructor===Array},Boolean:function(e){return"boolean"==typeof e},Function:function(e){return"function"==typeof e},Nil:function(e){return null==e},Number:function(e){return"number"==typeof e},Object:function(e){return"object"==typeof e},String:function(e){return"string"==typeof e},"":function(){return!0}};for(var r in t.Null=t.Nil,t)t[r].toJSON=function(e){return e}.bind(null,r);e.exports=t},1817:(e,t,r)=>{var n=r(8891),i=n.Buffer;function o(e,t){for(var r in e)t[r]=e[r]}function s(e,t,r){return i(e,t,r)}i.from&&i.alloc&&i.allocUnsafe&&i.allocUnsafeSlow?e.exports=n:(o(n,t),t.Buffer=s),s.prototype=Object.create(i.prototype),o(i,s),s.from=function(e,t,r){if("number"==typeof e)throw new TypeError("Argument must not be a number");return i(e,t,r)},s.alloc=function(e,t,r){if("number"!=typeof e)throw new TypeError("Argument must be a number");var n=i(e);return void 0!==t?"string"==typeof r?n.fill(t,r):n.fill(t):n.fill(0),n},s.allocUnsafe=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return i(e)},s.allocUnsafeSlow=function(e){if("number"!=typeof e)throw new TypeError("Argument must be a number");return n.SlowBuffer(e)}},1834:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.testnet=t.regtest=t.bitcoin=void 0,t.bitcoin={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bc",bip32:{public:76067358,private:76066276},pubKeyHash:0,scriptHash:5,wif:128},t.regtest={messagePrefix:"Bitcoin Signed Message:\n",bech32:"bcrt",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239},t.testnet={messagePrefix:"Bitcoin Signed Message:\n",bech32:"tb",bip32:{public:70617039,private:70615956},pubKeyHash:111,scriptHash:196,wif:239}},1920:(e,t,r)=>{var n=r(5601),i=r(1677),o=n.tfJSON,s=n.TfTypeError,f=n.TfPropertyTypeError,u=n.tfSubError,a=n.getValueTypeName,c={arrayOf:function(e,t){function r(r,n){return!!i.Array(r)&&!i.Nil(r)&&!(void 0!==t.minLength&&r.length<t.minLength)&&!(void 0!==t.maxLength&&r.length>t.maxLength)&&(void 0===t.length||r.length===t.length)&&r.every(function(t,r){try{return h(e,t,n)}catch(e){throw u(e,r)}})}return e=p(e),t=t||{},r.toJSON=function(){var r="["+o(e)+"]";return void 0!==t.length?r+="{"+t.length+"}":void 0===t.minLength&&void 0===t.maxLength||(r+="{"+(void 0===t.minLength?0:t.minLength)+","+(void 0===t.maxLength?1/0:t.maxLength)+"}"),r},r},maybe:function e(t){function r(r,n){return i.Nil(r)||t(r,n,e)}return t=p(t),r.toJSON=function(){return"?"+o(t)},r},map:function(e,t){function r(r,n){if(!i.Object(r))return!1;if(i.Nil(r))return!1;for(var o in r){try{t&&h(t,o,n)}catch(e){throw u(e,o,"key")}try{var s=r[o];h(e,s,n)}catch(e){throw u(e,o)}}return!0}return e=p(e),t&&(t=p(t)),r.toJSON=t?function(){return"{"+o(t)+": "+o(e)+"}"}:function(){return"{"+o(e)+"}"},r},object:function(e){var t={};for(var r in e)t[r]=p(e[r]);function n(e,r){if(!i.Object(e))return!1;if(i.Nil(e))return!1;var n;try{for(n in t)h(t[n],e[n],r)}catch(e){throw u(e,n)}if(r)for(n in e)if(!t[n])throw new f(void 0,n);return!0}return n.toJSON=function(){return o(t)},n},anyOf:function(){var e=[].slice.call(arguments).map(p);function t(t,r){return e.some(function(e){try{return h(e,t,r)}catch(e){return!1}})}return t.toJSON=function(){return e.map(o).join("|")},t},allOf:function(){var e=[].slice.call(arguments).map(p);function t(t,r){return e.every(function(e){try{return h(e,t,r)}catch(e){return!1}})}return t.toJSON=function(){return e.map(o).join(" & ")},t},quacksLike:function(e){function t(t){return e===a(t)}return t.toJSON=function(){return e},t},tuple:function(){var e=[].slice.call(arguments).map(p);function t(t,r){return!i.Nil(t)&&!i.Nil(t.length)&&(!r||t.length===e.length)&&e.every(function(e,n){try{return h(e,t[n],r)}catch(e){throw u(e,n)}})}return t.toJSON=function(){return"("+e.map(o).join(", ")+")"},t},value:function(e){function t(t){return t===e}return t.toJSON=function(){return e},t}};function p(e){if(i.String(e))return"?"===e[0]?c.maybe(e.slice(1)):i[e]||c.quacksLike(e);if(e&&i.Object(e)){if(i.Array(e)){if(1!==e.length)throw new TypeError("Expected compile() parameter of type Array of length 1");return c.arrayOf(e[0])}return c.object(e)}return i.Function(e)?e:c.value(e)}function h(e,t,r,n){if(i.Function(e)){if(e(t,r))return!0;throw new s(n||e,t)}return h(p(e),t,r)}for(var l in c.oneOf=c.anyOf,i)h[l]=i[l];for(l in c)h[l]=c[l];var d=r(3274);for(l in d)h[l]=d[l];h.compile=p,h.TfTypeError=s,h.TfPropertyTypeError=f,e.exports=h},2329:(e,t,r)=>{var n=r(8891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.Transaction=void 0;const i=r(5666),o=r(8892),s=r(4778),f=r(4778),u=r(2992),{typeforce:a}=u;function c(e){const t=e.length;return i.varuint.encodingLength(t)+t}const p=n.allocUnsafe(0),h=[],l=n.from("0000000000000000000000000000000000000000000000000000000000000000","hex"),d=n.from("0000000000000000000000000000000000000000000000000000000000000001","hex"),y=n.from("ffffffffffffffff","hex"),w={script:p,valueBuffer:y};class m{constructor(){this.version=1,this.locktime=0,this.ins=[],this.outs=[]}static fromBuffer(e,t){const r=new i.BufferReader(e),n=new m;n.version=r.readInt32();const o=r.readUInt8(),s=r.readUInt8();let f=!1;o===m.ADVANCED_TRANSACTION_MARKER&&s===m.ADVANCED_TRANSACTION_FLAG?f=!0:r.offset-=2;const u=r.readVarInt();for(let e=0;e<u;++e)n.ins.push({hash:r.readSlice(32),index:r.readUInt32(),script:r.readVarSlice(),sequence:r.readUInt32(),witness:h});const a=r.readVarInt();for(let e=0;e<a;++e)n.outs.push({value:r.readUInt64(),script:r.readVarSlice()});if(f){for(let e=0;e<u;++e)n.ins[e].witness=r.readVector();if(!n.hasWitnesses())throw new Error("Transaction has superfluous witness data")}if(n.locktime=r.readUInt32(),t)return n;if(r.offset!==e.length)throw new Error("Transaction has unexpected data");return n}static fromHex(e){return m.fromBuffer(n.from(e,"hex"),!1)}static isCoinbaseHash(e){a(u.Hash256bit,e);for(let t=0;t<32;++t)if(0!==e[t])return!1;return!0}isCoinbase(){return 1===this.ins.length&&m.isCoinbaseHash(this.ins[0].hash)}addInput(e,t,r,n){return a(u.tuple(u.Hash256bit,u.UInt32,u.maybe(u.UInt32),u.maybe(u.Buffer)),arguments),u.Null(r)&&(r=m.DEFAULT_SEQUENCE),this.ins.push({hash:e,index:t,script:n||p,sequence:r,witness:h})-1}addOutput(e,t){return a(u.tuple(u.Buffer,u.Satoshi),arguments),this.outs.push({script:e,value:t})-1}hasWitnesses(){return this.ins.some(e=>0!==e.witness.length)}stripWitnesses(){this.ins.forEach(e=>{e.witness=h})}weight(){return 3*this.byteLength(!1)+this.byteLength(!0)}virtualSize(){return Math.ceil(this.weight()/4)}byteLength(e=!0){const t=e&&this.hasWitnesses();return(t?10:8)+i.varuint.encodingLength(this.ins.length)+i.varuint.encodingLength(this.outs.length)+this.ins.reduce((e,t)=>e+40+c(t.script),0)+this.outs.reduce((e,t)=>e+8+c(t.script),0)+(t?this.ins.reduce((e,t)=>e+function(e){const t=e.length;return i.varuint.encodingLength(t)+e.reduce((e,t)=>e+c(t),0)}(t.witness),0):0)}clone(){const e=new m;return e.version=this.version,e.locktime=this.locktime,e.ins=this.ins.map(e=>({hash:e.hash,index:e.index,script:e.script,sequence:e.sequence,witness:e.witness})),e.outs=this.outs.map(e=>({script:e.script,value:e.value})),e}hashForSignature(e,t,r){if(a(u.tuple(u.UInt32,u.Buffer,u.Number),arguments),e>=this.ins.length)return d;const i=s.compile(s.decompile(t).filter(e=>e!==f.OPS.OP_CODESEPARATOR)),c=this.clone();if((31&r)===m.SIGHASH_NONE)c.outs=[],c.ins.forEach((t,r)=>{r!==e&&(t.sequence=0)});else if((31&r)===m.SIGHASH_SINGLE){if(e>=this.outs.length)return d;c.outs.length=e+1;for(let t=0;t<e;t++)c.outs[t]=w;c.ins.forEach((t,r)=>{r!==e&&(t.sequence=0)})}r&m.SIGHASH_ANYONECANPAY?(c.ins=[c.ins[e]],c.ins[0].script=i):(c.ins.forEach(e=>{e.script=p}),c.ins[e].script=i);const h=n.allocUnsafe(c.byteLength(!1)+4);return h.writeInt32LE(r,h.length-4),c.__toBuffer(h,0,!1),o.hash256(h)}hashForWitnessV1(e,t,r,s,f,h){if(a(u.tuple(u.UInt32,a.arrayOf(u.Buffer),a.arrayOf(u.Satoshi),u.UInt32),arguments),r.length!==this.ins.length||t.length!==this.ins.length)throw new Error("Must supply prevout script and value for all inputs");const l=s===m.SIGHASH_DEFAULT?m.SIGHASH_ALL:s&m.SIGHASH_OUTPUT_MASK,d=(s&m.SIGHASH_INPUT_MASK)===m.SIGHASH_ANYONECANPAY,y=l===m.SIGHASH_NONE,w=l===m.SIGHASH_SINGLE;let b=p,g=p,E=p,O=p,P=p;if(!d){let e=i.BufferWriter.withCapacity(36*this.ins.length);this.ins.forEach(t=>{e.writeSlice(t.hash),e.writeUInt32(t.index)}),b=o.sha256(e.end()),e=i.BufferWriter.withCapacity(8*this.ins.length),r.forEach(t=>e.writeUInt64(t)),g=o.sha256(e.end()),e=i.BufferWriter.withCapacity(t.map(c).reduce((e,t)=>e+t)),t.forEach(t=>e.writeVarSlice(t)),E=o.sha256(e.end()),e=i.BufferWriter.withCapacity(4*this.ins.length),this.ins.forEach(t=>e.writeUInt32(t.sequence)),O=o.sha256(e.end())}if(y||w){if(w&&e<this.outs.length){const t=this.outs[e],r=i.BufferWriter.withCapacity(8+c(t.script));r.writeUInt64(t.value),r.writeVarSlice(t.script),P=o.sha256(r.end())}}else{const e=this.outs.map(e=>8+c(e.script)).reduce((e,t)=>e+t),t=i.BufferWriter.withCapacity(e);this.outs.forEach(e=>{t.writeUInt64(e.value),t.writeVarSlice(e.script)}),P=o.sha256(t.end())}const S=(f?2:0)+(h?1:0),v=174-(d?49:0)-(y?32:0)+(h?32:0)+(f?37:0),_=i.BufferWriter.withCapacity(v);if(_.writeUInt8(s),_.writeInt32(this.version),_.writeUInt32(this.locktime),_.writeSlice(b),_.writeSlice(g),_.writeSlice(E),_.writeSlice(O),y||w||_.writeSlice(P),_.writeUInt8(S),d){const n=this.ins[e];_.writeSlice(n.hash),_.writeUInt32(n.index),_.writeUInt64(r[e]),_.writeVarSlice(t[e]),_.writeUInt32(n.sequence)}else _.writeUInt32(e);if(h){const e=i.BufferWriter.withCapacity(c(h));e.writeVarSlice(h),_.writeSlice(o.sha256(e.end()))}return w&&_.writeSlice(P),f&&(_.writeSlice(f),_.writeUInt8(0),_.writeUInt32(4294967295)),o.taggedHash("TapSighash",n.concat([n.from([0]),_.end()]))}hashForWitnessV0(e,t,r,s){a(u.tuple(u.UInt32,u.Buffer,u.Satoshi,u.UInt32),arguments);let f,p=n.from([]),h=l,d=l,y=l;if(s&m.SIGHASH_ANYONECANPAY||(p=n.allocUnsafe(36*this.ins.length),f=new i.BufferWriter(p,0),this.ins.forEach(e=>{f.writeSlice(e.hash),f.writeUInt32(e.index)}),d=o.hash256(p)),s&m.SIGHASH_ANYONECANPAY||(31&s)===m.SIGHASH_SINGLE||(31&s)===m.SIGHASH_NONE||(p=n.allocUnsafe(4*this.ins.length),f=new i.BufferWriter(p,0),this.ins.forEach(e=>{f.writeUInt32(e.sequence)}),y=o.hash256(p)),(31&s)!==m.SIGHASH_SINGLE&&(31&s)!==m.SIGHASH_NONE){const e=this.outs.reduce((e,t)=>e+8+c(t.script),0);p=n.allocUnsafe(e),f=new i.BufferWriter(p,0),this.outs.forEach(e=>{f.writeUInt64(e.value),f.writeVarSlice(e.script)}),h=o.hash256(p)}else if((31&s)===m.SIGHASH_SINGLE&&e<this.outs.length){const t=this.outs[e];p=n.allocUnsafe(8+c(t.script)),f=new i.BufferWriter(p,0),f.writeUInt64(t.value),f.writeVarSlice(t.script),h=o.hash256(p)}p=n.allocUnsafe(156+c(t)),f=new i.BufferWriter(p,0);const w=this.ins[e];return f.writeInt32(this.version),f.writeSlice(d),f.writeSlice(y),f.writeSlice(w.hash),f.writeUInt32(w.index),f.writeVarSlice(t),f.writeUInt64(r),f.writeUInt32(w.sequence),f.writeSlice(h),f.writeUInt32(this.locktime),f.writeUInt32(s),o.hash256(p)}getHash(e){return e&&this.isCoinbase()?n.alloc(32,0):o.hash256(this.__toBuffer(void 0,void 0,e))}getId(){return(0,i.reverseBuffer)(this.getHash(!1)).toString("hex")}toBuffer(e,t){return this.__toBuffer(e,t,!0)}toHex(){return this.toBuffer(void 0,void 0).toString("hex")}setInputScript(e,t){a(u.tuple(u.Number,u.Buffer),arguments),this.ins[e].script=t}setWitness(e,t){a(u.tuple(u.Number,[u.Buffer]),arguments),this.ins[e].witness=t}__toBuffer(e,t,r=!1){e||(e=n.allocUnsafe(this.byteLength(r)));const o=new i.BufferWriter(e,t||0);o.writeInt32(this.version);const s=r&&this.hasWitnesses();return s&&(o.writeUInt8(m.ADVANCED_TRANSACTION_MARKER),o.writeUInt8(m.ADVANCED_TRANSACTION_FLAG)),o.writeVarInt(this.ins.length),this.ins.forEach(e=>{o.writeSlice(e.hash),o.writeUInt32(e.index),o.writeVarSlice(e.script),o.writeUInt32(e.sequence)}),o.writeVarInt(this.outs.length),this.outs.forEach(e=>{void 0!==e.value?o.writeUInt64(e.value):o.writeSlice(e.valueBuffer),o.writeVarSlice(e.script)}),s&&this.ins.forEach(e=>{o.writeVector(e.witness)}),o.writeUInt32(this.locktime),void 0!==t?e.slice(t,o.offset):e}}t.Transaction=m,m.DEFAULT_SEQUENCE=4294967295,m.SIGHASH_DEFAULT=0,m.SIGHASH_ALL=1,m.SIGHASH_NONE=2,m.SIGHASH_SINGLE=3,m.SIGHASH_ANYONECANPAY=128,m.SIGHASH_OUTPUT_MASK=3,m.SIGHASH_INPUT_MASK=128,m.ADVANCED_TRANSACTION_MARKER=0,m.ADVANCED_TRANSACTION_FLAG=1},2820:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.decode=t.encode=t.encodingLength=void 0;const n=r(5029);function i(e){return e<n.OPS.OP_PUSHDATA1?1:e<=255?2:e<=65535?3:5}t.encodingLength=i,t.encode=function(e,t,r){const o=i(t);return 1===o?e.writeUInt8(t,r):2===o?(e.writeUInt8(n.OPS.OP_PUSHDATA1,r),e.writeUInt8(t,r+1)):3===o?(e.writeUInt8(n.OPS.OP_PUSHDATA2,r),e.writeUInt16LE(t,r+1)):(e.writeUInt8(n.OPS.OP_PUSHDATA4,r),e.writeUInt32LE(t,r+1)),o},t.decode=function(e,t){const r=e.readUInt8(t);let i,o;if(r<n.OPS.OP_PUSHDATA1)i=r,o=1;else if(r===n.OPS.OP_PUSHDATA1){if(t+2>e.length)return null;i=e.readUInt8(t+1),o=2}else if(r===n.OPS.OP_PUSHDATA2){if(t+3>e.length)return null;i=e.readUInt16LE(t+1),o=3}else{if(t+5>e.length)return null;if(r!==n.OPS.OP_PUSHDATA4)throw new Error("Unexpected opcode");i=e.readUInt32LE(t+1),o=5}return{opcode:r,number:i,size:o}}},2854:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.p2pk=void 0;const n=r(1834),i=r(4778),o=r(2992),s=r(6887),f=i.OPS;t.p2pk=function(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||{}),(0,o.typeforce)({network:o.typeforce.maybe(o.typeforce.Object),output:o.typeforce.maybe(o.typeforce.Buffer),pubkey:o.typeforce.maybe(o.isPoint),signature:o.typeforce.maybe(i.isCanonicalScriptSignature),input:o.typeforce.maybe(o.typeforce.Buffer)},e);const r=s.value(()=>i.decompile(e.input)),u={name:"p2pk",network:e.network||n.bitcoin};if(s.prop(u,"output",()=>{if(e.pubkey)return i.compile([e.pubkey,f.OP_CHECKSIG])}),s.prop(u,"pubkey",()=>{if(e.output)return e.output.slice(1,-1)}),s.prop(u,"signature",()=>{if(e.input)return r()[0]}),s.prop(u,"input",()=>{if(e.signature)return i.compile([e.signature])}),s.prop(u,"witness",()=>{if(u.input)return[]}),t.validate){if(e.output){if(e.output[e.output.length-1]!==f.OP_CHECKSIG)throw new TypeError("Output is invalid");if(!(0,o.isPoint)(u.pubkey))throw new TypeError("Output pubkey is invalid");if(e.pubkey&&!e.pubkey.equals(u.pubkey))throw new TypeError("Pubkey mismatch")}if(e.signature&&e.input&&!e.input.equals(u.input))throw new TypeError("Signature mismatch");if(e.input){if(1!==r().length)throw new TypeError("Input is invalid");if(!i.isCanonicalScriptSignature(u.signature))throw new TypeError("Input has invalid signature")}}return Object.assign(u,e)}},2992:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.oneOf=t.Null=t.BufferN=t.Function=t.UInt32=t.UInt8=t.tuple=t.maybe=t.Hex=t.Buffer=t.String=t.Boolean=t.Array=t.Number=t.Hash256bit=t.Hash160bit=t.Buffer256bit=t.isTaptree=t.isTapleaf=t.TAPLEAF_VERSION_MASK=t.Satoshi=t.isPoint=t.stacksEqual=t.typeforce=void 0;const n=r(8891);t.typeforce=r(1920);const i=n.Buffer.alloc(32,0),o=n.Buffer.from("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f","hex");function s(e){return!(!e||!("output"in e)||!n.Buffer.isBuffer(e.output)||void 0!==e.version&&(e.version&t.TAPLEAF_VERSION_MASK)!==e.version)}t.stacksEqual=function(e,t){return e.length===t.length&&e.every((e,r)=>e.equals(t[r]))},t.isPoint=function(e){if(!n.Buffer.isBuffer(e))return!1;if(e.length<33)return!1;const t=e[0],r=e.slice(1,33);if(0===r.compare(i))return!1;if(r.compare(o)>=0)return!1;if((2===t||3===t)&&33===e.length)return!0;const s=e.slice(33);return 0!==s.compare(i)&&!(s.compare(o)>=0)&&4===t&&65===e.length},t.Satoshi=function(e){return t.typeforce.UInt53(e)&&e<=21e14},t.TAPLEAF_VERSION_MASK=254,t.isTapleaf=s,t.isTaptree=function e(r){return(0,t.Array)(r)?2===r.length&&r.every(t=>e(t)):s(r)},t.Buffer256bit=t.typeforce.BufferN(32),t.Hash160bit=t.typeforce.BufferN(20),t.Hash256bit=t.typeforce.BufferN(32),t.Number=t.typeforce.Number,t.Array=t.typeforce.Array,t.Boolean=t.typeforce.Boolean,t.String=t.typeforce.String,t.Buffer=t.typeforce.Buffer,t.Hex=t.typeforce.Hex,t.maybe=t.typeforce.maybe,t.tuple=t.typeforce.tuple,t.UInt8=t.typeforce.UInt8,t.UInt32=t.typeforce.UInt32,t.Function=t.typeforce.Function,t.BufferN=t.typeforce.BufferN,t.Null=t.typeforce.Null,t.oneOf=t.typeforce.oneOf},3088:(e,t,r)=>{var n=r(1643);e.exports=function(e){function t(t){var r=t.slice(0,-4),n=t.slice(-4),i=e(r);if(!(n[0]^i[0]|n[1]^i[1]|n[2]^i[2]|n[3]^i[3]))return r}return{encode:function(t){var r=Uint8Array.from(t),i=e(r),o=r.length+4,s=new Uint8Array(o);return s.set(r,0),s.set(i.subarray(0,4),r.length),n.encode(s,o)},decode:function(e){var r=t(n.decode(e));if(!r)throw new Error("Invalid checksum");return r},decodeUnsafe:function(e){var r=n.decodeUnsafe(e);if(r)return t(r)}}}},3274:(e,t,r)=>{var n=r(8891).Buffer,i=r(1677),o=r(5601);function s(e){return n.isBuffer(e)}function f(e){return"string"==typeof e&&/^([0-9a-f]{2})+$/i.test(e)}function u(e,t){var r=e.toJSON();function n(n){if(!e(n))return!1;if(n.length===t)return!0;throw o.tfCustomError(r+"(Length: "+t+")",r+"(Length: "+n.length+")")}return n.toJSON=function(){return r},n}var a=u.bind(null,i.Array),c=u.bind(null,s),p=u.bind(null,f),h=u.bind(null,i.String),l=Math.pow(2,53)-1,d={ArrayN:a,Buffer:s,BufferN:c,Finite:function(e){return"number"==typeof e&&isFinite(e)},Hex:f,HexN:p,Int8:function(e){return e<<24>>24===e},Int16:function(e){return e<<16>>16===e},Int32:function(e){return(0|e)===e},Int53:function(e){return"number"==typeof e&&e>=-l&&e<=l&&Math.floor(e)===e},Range:function(e,t,r){function n(n,i){return r(n,i)&&n>e&&n<t}return r=r||i.Number,n.toJSON=function(){return`${r.toJSON()} between [${e}, ${t}]`},n},StringN:h,UInt8:function(e){return(255&e)===e},UInt16:function(e){return(65535&e)===e},UInt32:function(e){return e>>>0===e},UInt53:function(e){return"number"==typeof e&&e>=0&&e<=l&&Math.floor(e)===e}};for(var y in d)d[y].toJSON=function(e){return e}.bind(null,y);e.exports=d},3553:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.sha1=t.SHA1=void 0;const n=r(9403);t.SHA1=n.SHA1,t.sha1=n.sha1},3881:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.p2tr=void 0;const n=r(8891),i=r(1834),o=r(4778),s=r(2992),f=r(8539),u=r(102),a=r(6887),c=r(9771),p=r(8381),h=o.OPS;t.p2tr=function(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||{}),(0,s.typeforce)({address:s.typeforce.maybe(s.typeforce.String),input:s.typeforce.maybe(s.typeforce.BufferN(0)),network:s.typeforce.maybe(s.typeforce.Object),output:s.typeforce.maybe(s.typeforce.BufferN(34)),internalPubkey:s.typeforce.maybe(s.typeforce.BufferN(32)),hash:s.typeforce.maybe(s.typeforce.BufferN(32)),pubkey:s.typeforce.maybe(s.typeforce.BufferN(32)),signature:s.typeforce.maybe(s.typeforce.anyOf(s.typeforce.BufferN(64),s.typeforce.BufferN(65))),witness:s.typeforce.maybe(s.typeforce.arrayOf(s.typeforce.Buffer)),scriptTree:s.typeforce.maybe(s.isTaptree),redeem:s.typeforce.maybe({output:s.typeforce.maybe(s.typeforce.Buffer),redeemVersion:s.typeforce.maybe(s.typeforce.Number),witness:s.typeforce.maybe(s.typeforce.arrayOf(s.typeforce.Buffer))}),redeemVersion:s.typeforce.maybe(s.typeforce.Number)},e);const r=a.value(()=>(0,p.fromBech32)(e.address)),l=a.value(()=>{if(e.witness&&e.witness.length)return e.witness.length>=2&&80===e.witness[e.witness.length-1][0]?e.witness.slice(0,-1):e.witness.slice()}),d=a.value(()=>e.scriptTree?(0,u.toHashTree)(e.scriptTree):e.hash?{hash:e.hash}:void 0),y=e.network||i.bitcoin,w={name:"p2tr",network:y};if(a.prop(w,"address",()=>{if(!w.pubkey)return;const e=c.bech32m.toWords(w.pubkey);return e.unshift(1),c.bech32m.encode(y.bech32,e)}),a.prop(w,"hash",()=>{const e=d();if(e)return e.hash;const t=l();if(t&&t.length>1){const e=t[t.length-1],r=e[0]&s.TAPLEAF_VERSION_MASK,n=t[t.length-2],i=(0,u.tapleafHash)({output:n,version:r});return(0,u.rootHashFromPath)(e,i)}return null}),a.prop(w,"output",()=>{if(w.pubkey)return o.compile([h.OP_1,w.pubkey])}),a.prop(w,"redeemVersion",()=>e.redeemVersion?e.redeemVersion:e.redeem&&void 0!==e.redeem.redeemVersion&&null!==e.redeem.redeemVersion?e.redeem.redeemVersion:u.LEAF_VERSION_TAPSCRIPT),a.prop(w,"redeem",()=>{const e=l();if(e&&!(e.length<2))return{output:e[e.length-2],witness:e.slice(0,-2),redeemVersion:e[e.length-1][0]&s.TAPLEAF_VERSION_MASK}}),a.prop(w,"pubkey",()=>{if(e.pubkey)return e.pubkey;if(e.output)return e.output.slice(2);if(e.address)return r().data;if(w.internalPubkey){const e=(0,u.tweakKey)(w.internalPubkey,w.hash);if(e)return e.x}}),a.prop(w,"internalPubkey",()=>{if(e.internalPubkey)return e.internalPubkey;const t=l();return t&&t.length>1?t[t.length-1].slice(1,33):void 0}),a.prop(w,"signature",()=>{if(e.signature)return e.signature;const t=l();return t&&1===t.length?t[0]:void 0}),a.prop(w,"witness",()=>{if(e.witness)return e.witness;const t=d();if(t&&e.redeem&&e.redeem.output&&e.internalPubkey){const r=(0,u.tapleafHash)({output:e.redeem.output,version:w.redeemVersion}),i=(0,u.findScriptPath)(t,r);if(!i)return;const o=(0,u.tweakKey)(e.internalPubkey,t.hash);if(!o)return;const s=n.Buffer.concat([n.Buffer.from([w.redeemVersion|o.parity]),e.internalPubkey].concat(i));return[e.redeem.output,s]}return e.signature?[e.signature]:void 0}),t.validate){let t=n.Buffer.from([]);if(e.address){if(y&&y.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(1!==r().version)throw new TypeError("Invalid address version");if(32!==r().data.length)throw new TypeError("Invalid address data");t=r().data}if(e.pubkey){if(t.length>0&&!t.equals(e.pubkey))throw new TypeError("Pubkey mismatch");t=e.pubkey}if(e.output){if(34!==e.output.length||e.output[0]!==h.OP_1||32!==e.output[1])throw new TypeError("Output is invalid");if(t.length>0&&!t.equals(e.output.slice(2)))throw new TypeError("Pubkey mismatch");t=e.output.slice(2)}if(e.internalPubkey){const r=(0,u.tweakKey)(e.internalPubkey,w.hash);if(t.length>0&&!t.equals(r.x))throw new TypeError("Pubkey mismatch");t=r.x}if(t&&t.length&&!(0,f.getEccLib)().isXOnlyPoint(t))throw new TypeError("Invalid pubkey for p2tr");const i=d();if(e.hash&&i&&!e.hash.equals(i.hash))throw new TypeError("Hash mismatch");if(e.redeem&&e.redeem.output&&i){const t=(0,u.tapleafHash)({output:e.redeem.output,version:w.redeemVersion});if(!(0,u.findScriptPath)(i,t))throw new TypeError("Redeem script not in tree")}const a=l();if(e.redeem&&w.redeem){if(e.redeem.redeemVersion&&e.redeem.redeemVersion!==w.redeem.redeemVersion)throw new TypeError("Redeem.redeemVersion and witness mismatch");if(e.redeem.output){if(0===o.decompile(e.redeem.output).length)throw new TypeError("Redeem.output is invalid");if(w.redeem.output&&!e.redeem.output.equals(w.redeem.output))throw new TypeError("Redeem.output and witness mismatch")}if(e.redeem.witness&&w.redeem.witness&&!(0,s.stacksEqual)(e.redeem.witness,w.redeem.witness))throw new TypeError("Redeem.witness and witness mismatch")}if(a&&a.length)if(1===a.length){if(e.signature&&!e.signature.equals(a[0]))throw new TypeError("Signature mismatch")}else{const r=a[a.length-1];if(r.length<33)throw new TypeError(`The control-block length is too small. Got ${r.length}, expected min 33.`);if((r.length-33)%32!=0)throw new TypeError(`The control-block length of ${r.length} is incorrect!`);const n=(r.length-33)/32;if(n>128)throw new TypeError(`The script path is too long. Got ${n}, expected max 128.`);const i=r.slice(1,33);if(e.internalPubkey&&!e.internalPubkey.equals(i))throw new TypeError("Internal pubkey mismatch");if(!(0,f.getEccLib)().isXOnlyPoint(i))throw new TypeError("Invalid internalPubkey for p2tr witness");const o=r[0]&s.TAPLEAF_VERSION_MASK,c=a[a.length-2],p=(0,u.tapleafHash)({output:c,version:o}),h=(0,u.rootHashFromPath)(r,p),l=(0,u.tweakKey)(i,h);if(!l)throw new TypeError("Invalid outputKey for p2tr witness");if(t.length&&!t.equals(l.x))throw new TypeError("Pubkey mismatch for p2tr witness");if(l.parity!==(1&r[0]))throw new Error("Incorrect parity")}}return Object.assign(w,e)}},3929:(e,t,r)=>{var n=r(1817).Buffer;function i(e){if(e<0||e>9007199254740991||e%1!=0)throw new RangeError("value out of range")}function o(e){return i(e),e<253?1:e<=65535?3:e<=4294967295?5:9}e.exports={encode:function e(t,r,s){if(i(t),r||(r=n.allocUnsafe(o(t))),!n.isBuffer(r))throw new TypeError("buffer must be a Buffer instance");return s||(s=0),t<253?(r.writeUInt8(t,s),e.bytes=1):t<=65535?(r.writeUInt8(253,s),r.writeUInt16LE(t,s+1),e.bytes=3):t<=4294967295?(r.writeUInt8(254,s),r.writeUInt32LE(t,s+1),e.bytes=5):(r.writeUInt8(255,s),r.writeUInt32LE(t>>>0,s+1),r.writeUInt32LE(t/4294967296|0,s+5),e.bytes=9),r},decode:function e(t,r){if(!n.isBuffer(t))throw new TypeError("buffer must be a Buffer instance");r||(r=0);var o=t.readUInt8(r);if(o<253)return e.bytes=1,o;if(253===o)return e.bytes=3,t.readUInt16LE(r+1);if(254===o)return e.bytes=5,t.readUInt32LE(r+1);e.bytes=9;var s=t.readUInt32LE(r+1),f=4294967296*t.readUInt32LE(r+5)+s;return i(f),f},encodingLength:o}},4068:(e,t,r)=>{var n=r(8891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.encode=t.decode=void 0,t.decode=function(e,t,r){t=t||4,r=void 0===r||r;const n=e.length;if(0===n)return 0;if(n>t)throw new TypeError("Script number overflow");if(r&&!(127&e[n-1]||!(n<=1)&&128&e[n-2]))throw new Error("Non-minimally encoded script number");if(5===n){const t=e.readUInt32LE(0),r=e.readUInt8(4);return 128&r?-(4294967296*(-129&r)+t):4294967296*r+t}let i=0;for(let t=0;t<n;++t)i|=e[t]<<8*t;return 128&e[n-1]?-(i&~(128<<8*(n-1))):i},t.encode=function(e){let t=Math.abs(e);const r=(i=t)>2147483647?5:i>8388607?4:i>32767?3:i>127?2:i>0?1:0;var i;const o=n.allocUnsafe(r),s=e<0;for(let e=0;e<r;++e)o.writeUInt8(255&t,e),t>>=8;return 128&o[r-1]?o.writeUInt8(s?128:0,r-1):s&&(o[r-1]|=128),o}},4538:(e,t,r)=>{var n=r(8891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.encode=t.decode=t.check=void 0,t.check=function(e){if(e.length<8)return!1;if(e.length>72)return!1;if(48!==e[0])return!1;if(e[1]!==e.length-2)return!1;if(2!==e[2])return!1;const t=e[3];if(0===t)return!1;if(5+t>=e.length)return!1;if(2!==e[4+t])return!1;const r=e[5+t];return!(0===r||6+t+r!==e.length||128&e[4]||t>1&&0===e[4]&&!(128&e[5])||128&e[t+6]||r>1&&0===e[t+6]&&!(128&e[t+7]))},t.decode=function(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(48!==e[0])throw new Error("Expected DER sequence");if(e[1]!==e.length-2)throw new Error("DER sequence length is invalid");if(2!==e[2])throw new Error("Expected DER integer");const t=e[3];if(0===t)throw new Error("R length is zero");if(5+t>=e.length)throw new Error("R length is too long");if(2!==e[4+t])throw new Error("Expected DER integer (2)");const r=e[5+t];if(0===r)throw new Error("S length is zero");if(6+t+r!==e.length)throw new Error("S length is invalid");if(128&e[4])throw new Error("R value is negative");if(t>1&&0===e[4]&&!(128&e[5]))throw new Error("R value excessively padded");if(128&e[t+6])throw new Error("S value is negative");if(r>1&&0===e[t+6]&&!(128&e[t+7]))throw new Error("S value excessively padded");return{r:e.slice(4,4+t),s:e.slice(6+t)}},t.encode=function(e,t){const r=e.length,i=t.length;if(0===r)throw new Error("R length is zero");if(0===i)throw new Error("S length is zero");if(r>33)throw new Error("R length is too long");if(i>33)throw new Error("S length is too long");if(128&e[0])throw new Error("R value is negative");if(128&t[0])throw new Error("S value is negative");if(r>1&&0===e[0]&&!(128&e[1]))throw new Error("R value excessively padded");if(i>1&&0===t[0]&&!(128&t[1]))throw new Error("S value excessively padded");const o=n.allocUnsafe(6+r+i);return o[0]=48,o[1]=o.length-2,o[2]=2,o[3]=e.length,e.copy(o,4),o[4+r]=2,o[5+r]=t.length,t.copy(o,6+r),o}},4778:(e,t,r)=>{var n=r(8891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.signature=t.number=t.isCanonicalScriptSignature=t.isDefinedHashType=t.isCanonicalPubKey=t.toStack=t.fromASM=t.toASM=t.decompile=t.compile=t.countNonPushOnlyOPs=t.isPushOnly=t.OPS=void 0;const i=r(4538),o=r(5029);Object.defineProperty(t,"OPS",{enumerable:!0,get:function(){return o.OPS}});const s=r(2820),f=r(4068),u=r(8191),a=r(2992),{typeforce:c}=a,p=o.OPS.OP_RESERVED;function h(e){return a.Buffer(e)||function(e){return a.Number(e)&&(e===o.OPS.OP_0||e>=o.OPS.OP_1&&e<=o.OPS.OP_16||e===o.OPS.OP_1NEGATE)}(e)}function l(e){return a.Array(e)&&e.every(h)}function d(e){return 0===e.length?o.OPS.OP_0:1===e.length?e[0]>=1&&e[0]<=16?p+e[0]:129===e[0]?o.OPS.OP_1NEGATE:void 0:void 0}function y(e){return n.isBuffer(e)}function w(e){return n.isBuffer(e)}function m(e){if(y(e))return e;c(a.Array,e);const t=e.reduce((e,t)=>w(t)?1===t.length&&void 0!==d(t)?e+1:e+s.encodingLength(t.length)+t.length:e+1,0),r=n.allocUnsafe(t);let i=0;if(e.forEach(e=>{if(w(e)){const t=d(e);if(void 0!==t)return r.writeUInt8(t,i),void(i+=1);i+=s.encode(r,e.length,i),e.copy(r,i),i+=e.length}else r.writeUInt8(e,i),i+=1}),i!==r.length)throw new Error("Could not decode chunks");return r}function b(e){if(t=e,a.Array(t))return e;var t;c(a.Buffer,e);const r=[];let n=0;for(;n<e.length;){const t=e[n];if(t>o.OPS.OP_0&&t<=o.OPS.OP_PUSHDATA4){const t=s.decode(e,n);if(null===t)return null;if(n+=t.size,n+t.number>e.length)return null;const i=e.slice(n,n+t.number);n+=t.number;const o=d(i);void 0!==o?r.push(o):r.push(i)}else r.push(t),n+=1}return r}function g(e){const t=-129&e;return t>0&&t<4}t.isPushOnly=l,t.countNonPushOnlyOPs=function(e){return e.length-e.filter(h).length},t.compile=m,t.decompile=b,t.toASM=function(e){if(y(e)&&(e=b(e)),!e)throw new Error("Could not convert invalid chunks to ASM");return e.map(e=>{if(w(e)){const t=d(e);if(void 0===t)return e.toString("hex");e=t}return o.REVERSE_OPS[e]}).join(" ")},t.fromASM=function(e){return c(a.String,e),m(e.split(" ").map(e=>void 0!==o.OPS[e]?o.OPS[e]:(c(a.Hex,e),n.from(e,"hex"))))},t.toStack=function(e){return e=b(e),c(l,e),e.map(e=>w(e)?e:e===o.OPS.OP_0?n.allocUnsafe(0):f.encode(e-p))},t.isCanonicalPubKey=function(e){return a.isPoint(e)},t.isDefinedHashType=g,t.isCanonicalScriptSignature=function(e){return!!n.isBuffer(e)&&!!g(e[e.length-1])&&i.check(e.slice(0,-1))},t.number=f,t.signature=u},5029:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.REVERSE_OPS=t.OPS=void 0;const r={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};t.OPS=r;const n={};t.REVERSE_OPS=n;for(const e of Object.keys(r))n[r[e]]=e},5391:(e,t,r)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.p2ms=void 0;const n=r(1834),i=r(4778),o=r(2992),s=r(6887),f=i.OPS,u=f.OP_RESERVED;t.p2ms=function(e,t){if(!(e.input||e.output||e.pubkeys&&void 0!==e.m||e.signatures))throw new TypeError("Not enough data");function r(e){return i.isCanonicalScriptSignature(e)||void 0!==(t.allowIncomplete&&e===f.OP_0)}t=Object.assign({validate:!0},t||{}),(0,o.typeforce)({network:o.typeforce.maybe(o.typeforce.Object),m:o.typeforce.maybe(o.typeforce.Number),n:o.typeforce.maybe(o.typeforce.Number),output:o.typeforce.maybe(o.typeforce.Buffer),pubkeys:o.typeforce.maybe(o.typeforce.arrayOf(o.isPoint)),signatures:o.typeforce.maybe(o.typeforce.arrayOf(r)),input:o.typeforce.maybe(o.typeforce.Buffer)},e);const a={network:e.network||n.bitcoin};let c=[],p=!1;function h(e){p||(p=!0,c=i.decompile(e),a.m=c[0]-u,a.n=c[c.length-2]-u,a.pubkeys=c.slice(1,-2))}if(s.prop(a,"output",()=>{if(e.m&&a.n&&e.pubkeys)return i.compile([].concat(u+e.m,e.pubkeys,u+a.n,f.OP_CHECKMULTISIG))}),s.prop(a,"m",()=>{if(a.output)return h(a.output),a.m}),s.prop(a,"n",()=>{if(a.pubkeys)return a.pubkeys.length}),s.prop(a,"pubkeys",()=>{if(e.output)return h(e.output),a.pubkeys}),s.prop(a,"signatures",()=>{if(e.input)return i.decompile(e.input).slice(1)}),s.prop(a,"input",()=>{if(e.signatures)return i.compile([f.OP_0].concat(e.signatures))}),s.prop(a,"witness",()=>{if(a.input)return[]}),s.prop(a,"name",()=>{if(a.m&&a.n)return`p2ms(${a.m} of ${a.n})`}),t.validate){if(e.output){if(h(e.output),!o.typeforce.Number(c[0]))throw new TypeError("Output is invalid");if(!o.typeforce.Number(c[c.length-2]))throw new TypeError("Output is invalid");if(c[c.length-1]!==f.OP_CHECKMULTISIG)throw new TypeError("Output is invalid");if(a.m<=0||a.n>16||a.m>a.n||a.n!==c.length-3)throw new TypeError("Output is invalid");if(!a.pubkeys.every(e=>(0,o.isPoint)(e)))throw new TypeError("Output is invalid");if(void 0!==e.m&&e.m!==a.m)throw new TypeError("m mismatch");if(void 0!==e.n&&e.n!==a.n)throw new TypeError("n mismatch");if(e.pubkeys&&!(0,o.stacksEqual)(e.pubkeys,a.pubkeys))throw new TypeError("Pubkeys mismatch")}if(e.pubkeys){if(void 0!==e.n&&e.n!==e.pubkeys.length)throw new TypeError("Pubkey count mismatch");if(a.n=e.pubkeys.length,a.n<a.m)throw new TypeError("Pubkey count cannot be less than m")}if(e.signatures){if(e.signatures.length<a.m)throw new TypeError("Not enough signatures provided");if(e.signatures.length>a.m)throw new TypeError("Too many signatures provided")}if(e.input){if(e.input[0]!==f.OP_0)throw new TypeError("Input is invalid");if(0===a.signatures.length||!a.signatures.every(r))throw new TypeError("Input has invalid signature(s)");if(e.signatures&&!(0,o.stacksEqual)(e.signatures,a.signatures))throw new TypeError("Signature mismatch");if(void 0!==e.m&&e.m!==e.signatures.length)throw new TypeError("Signature count mismatch")}}return Object.assign(a,e)}},5601:(e,t,r)=>{var n=r(1677);function i(e){return e.name||e.toString().match(/function (.*?)\s*\(/)[1]}function o(e){return n.Nil(e)?"":i(e.constructor)}function s(e,t){Error.captureStackTrace&&Error.captureStackTrace(e,t)}function f(e){return n.Function(e)?e.toJSON?e.toJSON():i(e):n.Array(e)?"Array":e&&n.Object(e)?"Object":void 0!==e?e:""}function u(e,t,r){var i=function(e){return n.Function(e)?"":n.String(e)?JSON.stringify(e):e&&n.Object(e)?"":e}(t);return"Expected "+f(e)+", got"+(""!==r?" "+r:"")+(""!==i?" "+i:"")}function a(e,t,r){r=r||o(t),this.message=u(e,t,r),s(this,a),this.__type=e,this.__value=t,this.__valueTypeName=r}function c(e,t,r,n,i){e?(i=i||o(n),this.message=function(e,t,r,n,i){var o='" of type ';return"key"===t&&(o='" with key type '),u('property "'+f(r)+o+f(e),n,i)}(e,r,t,n,i)):this.message='Unexpected property "'+t+'"',s(this,a),this.__label=r,this.__property=t,this.__type=e,this.__value=n,this.__valueTypeName=i}a.prototype=Object.create(Error.prototype),a.prototype.constructor=a,c.prototype=Object.create(Error.prototype),c.prototype.constructor=a,e.exports={TfTypeError:a,TfPropertyTypeError:c,tfCustomError:function(e,t){return new a(e,{},t)},tfSubError:function(e,t,r){return e instanceof c?(t=t+"."+e.__property,e=new c(e.__type,t,e.__label,e.__value,e.__valueTypeName)):e instanceof a&&(e=new c(e.__type,t,r,e.__value,e.__valueTypeName)),s(e),e},tfJSON:f,getValueTypeName:o}},5666:(e,t,r)=>{var n=r(8891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.BufferReader=t.BufferWriter=t.cloneBuffer=t.reverseBuffer=t.writeUInt64LE=t.readUInt64LE=t.varuint=void 0;const i=r(2992),{typeforce:o}=i,s=r(3929);function f(e,t){if("number"!=typeof e)throw new Error("cannot write a non-number as a number");if(e<0)throw new Error("specified a negative value for writing an unsigned value");if(e>t)throw new Error("RangeError: value out of range");if(Math.floor(e)!==e)throw new Error("value has a fractional component")}function u(e,t){const r=e.readUInt32LE(t);let n=e.readUInt32LE(t+4);return n*=4294967296,f(n+r,9007199254740991),n+r}function a(e,t,r){return f(t,9007199254740991),e.writeInt32LE(-1&t,r),e.writeUInt32LE(Math.floor(t/4294967296),r+4),r+8}t.varuint=s,t.readUInt64LE=u,t.writeUInt64LE=a,t.reverseBuffer=function(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},t.cloneBuffer=function(e){const t=n.allocUnsafe(e.length);return e.copy(t),t};class c{static withCapacity(e){return new c(n.alloc(e))}constructor(e,t=0){this.buffer=e,this.offset=t,o(i.tuple(i.Buffer,i.UInt32),[e,t])}writeUInt8(e){this.offset=this.buffer.writeUInt8(e,this.offset)}writeInt32(e){this.offset=this.buffer.writeInt32LE(e,this.offset)}writeUInt32(e){this.offset=this.buffer.writeUInt32LE(e,this.offset)}writeUInt64(e){this.offset=a(this.buffer,e,this.offset)}writeVarInt(e){s.encode(e,this.buffer,this.offset),this.offset+=s.encode.bytes}writeSlice(e){if(this.buffer.length<this.offset+e.length)throw new Error("Cannot write slice out of bounds");this.offset+=e.copy(this.buffer,this.offset)}writeVarSlice(e){this.writeVarInt(e.length),this.writeSlice(e)}writeVector(e){this.writeVarInt(e.length),e.forEach(e=>this.writeVarSlice(e))}end(){if(this.buffer.length===this.offset)return this.buffer;throw new Error(`buffer size ${this.buffer.length}, offset ${this.offset}`)}}t.BufferWriter=c,t.BufferReader=class{constructor(e,t=0){this.buffer=e,this.offset=t,o(i.tuple(i.Buffer,i.UInt32),[e,t])}readUInt8(){const e=this.buffer.readUInt8(this.offset);return this.offset++,e}readInt32(){const e=this.buffer.readInt32LE(this.offset);return this.offset+=4,e}readUInt32(){const e=this.buffer.readUInt32LE(this.offset);return this.offset+=4,e}readUInt64(){const e=u(this.buffer,this.offset);return this.offset+=8,e}readVarInt(){const e=s.decode(this.buffer,this.offset);return this.offset+=s.decode.bytes,e}readSlice(e){if(this.buffer.length<this.offset+e)throw new Error("Cannot read slice out of bounds");const t=this.buffer.slice(this.offset,this.offset+e);return this.offset+=e,t}readVarSlice(){return this.readSlice(this.readVarInt())}readVector(){const e=this.readVarInt(),t=[];for(let r=0;r<e;r++)t.push(this.readVarSlice());return t}}},6236:(e,t,r)=>{var n=r(8891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.p2pkh=void 0;const i=r(8892),o=r(1834),s=r(4778),f=r(2992),u=r(6887),a=r(709),c=s.OPS;t.p2pkh=function(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||{}),(0,f.typeforce)({network:f.typeforce.maybe(f.typeforce.Object),address:f.typeforce.maybe(f.typeforce.String),hash:f.typeforce.maybe(f.typeforce.BufferN(20)),output:f.typeforce.maybe(f.typeforce.BufferN(25)),pubkey:f.typeforce.maybe(f.isPoint),signature:f.typeforce.maybe(s.isCanonicalScriptSignature),input:f.typeforce.maybe(f.typeforce.Buffer)},e);const r=u.value(()=>{const t=n.from(a.decode(e.address));return{version:t.readUInt8(0),hash:t.slice(1)}}),p=u.value(()=>s.decompile(e.input)),h=e.network||o.bitcoin,l={name:"p2pkh",network:h};if(u.prop(l,"address",()=>{if(!l.hash)return;const e=n.allocUnsafe(21);return e.writeUInt8(h.pubKeyHash,0),l.hash.copy(e,1),a.encode(e)}),u.prop(l,"hash",()=>e.output?e.output.slice(3,23):e.address?r().hash:e.pubkey||l.pubkey?i.hash160(e.pubkey||l.pubkey):void 0),u.prop(l,"output",()=>{if(l.hash)return s.compile([c.OP_DUP,c.OP_HASH160,l.hash,c.OP_EQUALVERIFY,c.OP_CHECKSIG])}),u.prop(l,"pubkey",()=>{if(e.input)return p()[1]}),u.prop(l,"signature",()=>{if(e.input)return p()[0]}),u.prop(l,"input",()=>{if(e.pubkey&&e.signature)return s.compile([e.signature,e.pubkey])}),u.prop(l,"witness",()=>{if(l.input)return[]}),t.validate){let t=n.from([]);if(e.address){if(r().version!==h.pubKeyHash)throw new TypeError("Invalid version or Network mismatch");if(20!==r().hash.length)throw new TypeError("Invalid address");t=r().hash}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(25!==e.output.length||e.output[0]!==c.OP_DUP||e.output[1]!==c.OP_HASH160||20!==e.output[2]||e.output[23]!==c.OP_EQUALVERIFY||e.output[24]!==c.OP_CHECKSIG)throw new TypeError("Output is invalid");const r=e.output.slice(3,23);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");t=r}if(e.pubkey){const r=i.hash160(e.pubkey);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");t=r}if(e.input){const r=p();if(2!==r.length)throw new TypeError("Input is invalid");if(!s.isCanonicalScriptSignature(r[0]))throw new TypeError("Input has invalid signature");if(!(0,f.isPoint)(r[1]))throw new TypeError("Input has invalid pubkey");if(e.signature&&!e.signature.equals(r[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(r[1]))throw new TypeError("Pubkey mismatch");const n=i.hash160(r[1]);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch")}}return Object.assign(l,e)}},6693:(e,t,r)=>{var n=r(8891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.p2wsh=void 0;const i=r(8892),o=r(1834),s=r(4778),f=r(2992),u=r(6887),a=r(9771),c=s.OPS,p=n.alloc(0);function h(e){return!(!n.isBuffer(e)||65!==e.length||4!==e[0]||!(0,f.isPoint)(e))}t.p2wsh=function(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||{}),(0,f.typeforce)({network:f.typeforce.maybe(f.typeforce.Object),address:f.typeforce.maybe(f.typeforce.String),hash:f.typeforce.maybe(f.typeforce.BufferN(32)),output:f.typeforce.maybe(f.typeforce.BufferN(34)),redeem:f.typeforce.maybe({input:f.typeforce.maybe(f.typeforce.Buffer),network:f.typeforce.maybe(f.typeforce.Object),output:f.typeforce.maybe(f.typeforce.Buffer),witness:f.typeforce.maybe(f.typeforce.arrayOf(f.typeforce.Buffer))}),input:f.typeforce.maybe(f.typeforce.BufferN(0)),witness:f.typeforce.maybe(f.typeforce.arrayOf(f.typeforce.Buffer))},e);const r=u.value(()=>{const t=a.bech32.decode(e.address),r=t.words.shift(),i=a.bech32.fromWords(t.words);return{version:r,prefix:t.prefix,data:n.from(i)}}),l=u.value(()=>s.decompile(e.redeem.input));let d=e.network;d||(d=e.redeem&&e.redeem.network||o.bitcoin);const y={network:d};if(u.prop(y,"address",()=>{if(!y.hash)return;const e=a.bech32.toWords(y.hash);return e.unshift(0),a.bech32.encode(d.bech32,e)}),u.prop(y,"hash",()=>e.output?e.output.slice(2):e.address?r().data:y.redeem&&y.redeem.output?i.sha256(y.redeem.output):void 0),u.prop(y,"output",()=>{if(y.hash)return s.compile([c.OP_0,y.hash])}),u.prop(y,"redeem",()=>{if(e.witness)return{output:e.witness[e.witness.length-1],input:p,witness:e.witness.slice(0,-1)}}),u.prop(y,"input",()=>{if(y.witness)return p}),u.prop(y,"witness",()=>{if(e.redeem&&e.redeem.input&&e.redeem.input.length>0&&e.redeem.output&&e.redeem.output.length>0){const t=s.toStack(l());return y.redeem=Object.assign({witness:t},e.redeem),y.redeem.input=p,[].concat(t,e.redeem.output)}if(e.redeem&&e.redeem.output&&e.redeem.witness)return[].concat(e.redeem.witness,e.redeem.output)}),u.prop(y,"name",()=>{const e=["p2wsh"];return void 0!==y.redeem&&void 0!==y.redeem.name&&e.push(y.redeem.name),e.join("-")}),t.validate){let t=n.from([]);if(e.address){if(r().prefix!==d.bech32)throw new TypeError("Invalid prefix or Network mismatch");if(0!==r().version)throw new TypeError("Invalid address version");if(32!==r().data.length)throw new TypeError("Invalid address data");t=r().data}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(34!==e.output.length||e.output[0]!==c.OP_0||32!==e.output[1])throw new TypeError("Output is invalid");const r=e.output.slice(2);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");t=r}if(e.redeem){if(e.redeem.network&&e.redeem.network!==d)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 r=s.decompile(e.redeem.output);if(!r||r.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(s.countNonPushOnlyOPs(r)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const n=i.sha256(e.redeem.output);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");t=n}if(e.redeem.input&&!s.isPushOnly(l()))throw new TypeError("Non push-only scriptSig");if(e.witness&&e.redeem.witness&&!(0,f.stacksEqual)(e.witness,e.redeem.witness))throw new TypeError("Witness and redeem.witness mismatch");if(e.redeem.input&&l().some(h)||e.redeem.output&&(s.decompile(e.redeem.output)||[]).some(h))throw new TypeError("redeem.input or redeem.output contains uncompressed pubkey")}if(e.witness&&e.witness.length>0){const t=e.witness[e.witness.length-1];if(e.redeem&&e.redeem.output&&!e.redeem.output.equals(t))throw new TypeError("Witness and redeem.output mismatch");if(e.witness.some(h)||(s.decompile(t)||[]).some(h))throw new TypeError("Witness contains uncompressed pubkey")}}return Object.assign(y,e)}},6887:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.value=t.prop=void 0,t.prop=function(e,t,r){Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){const e=r.call(this);return this[t]=e,e},set(e){Object.defineProperty(this,t,{configurable:!0,enumerable:!0,value:e,writable:!0})}})},t.value=function(e){let t;return()=>(void 0!==t||(t=e()),t)}},7135:(e,t,r)=>{var n=r(8891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.p2wpkh=void 0;const i=r(8892),o=r(1834),s=r(4778),f=r(2992),u=r(6887),a=r(9771),c=s.OPS,p=n.alloc(0);t.p2wpkh=function(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||{}),(0,f.typeforce)({address:f.typeforce.maybe(f.typeforce.String),hash:f.typeforce.maybe(f.typeforce.BufferN(20)),input:f.typeforce.maybe(f.typeforce.BufferN(0)),network:f.typeforce.maybe(f.typeforce.Object),output:f.typeforce.maybe(f.typeforce.BufferN(22)),pubkey:f.typeforce.maybe(f.isPoint),signature:f.typeforce.maybe(s.isCanonicalScriptSignature),witness:f.typeforce.maybe(f.typeforce.arrayOf(f.typeforce.Buffer))},e);const r=u.value(()=>{const t=a.bech32.decode(e.address),r=t.words.shift(),i=a.bech32.fromWords(t.words);return{version:r,prefix:t.prefix,data:n.from(i)}}),h=e.network||o.bitcoin,l={name:"p2wpkh",network:h};if(u.prop(l,"address",()=>{if(!l.hash)return;const e=a.bech32.toWords(l.hash);return e.unshift(0),a.bech32.encode(h.bech32,e)}),u.prop(l,"hash",()=>e.output?e.output.slice(2,22):e.address?r().data:e.pubkey||l.pubkey?i.hash160(e.pubkey||l.pubkey):void 0),u.prop(l,"output",()=>{if(l.hash)return s.compile([c.OP_0,l.hash])}),u.prop(l,"pubkey",()=>e.pubkey?e.pubkey:e.witness?e.witness[1]:void 0),u.prop(l,"signature",()=>{if(e.witness)return e.witness[0]}),u.prop(l,"input",()=>{if(l.witness)return p}),u.prop(l,"witness",()=>{if(e.pubkey&&e.signature)return[e.signature,e.pubkey]}),t.validate){let t=n.from([]);if(e.address){if(h&&h.bech32!==r().prefix)throw new TypeError("Invalid prefix or Network mismatch");if(0!==r().version)throw new TypeError("Invalid address version");if(20!==r().data.length)throw new TypeError("Invalid address data");t=r().data}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(22!==e.output.length||e.output[0]!==c.OP_0||20!==e.output[1])throw new TypeError("Output is invalid");if(t.length>0&&!t.equals(e.output.slice(2)))throw new TypeError("Hash mismatch");t=e.output.slice(2)}if(e.pubkey){const r=i.hash160(e.pubkey);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");if(t=r,!(0,f.isPoint)(e.pubkey)||33!==e.pubkey.length)throw new TypeError("Invalid pubkey for p2wpkh")}if(e.witness){if(2!==e.witness.length)throw new TypeError("Witness is invalid");if(!s.isCanonicalScriptSignature(e.witness[0]))throw new TypeError("Witness has invalid signature");if(!(0,f.isPoint)(e.witness[1])||33!==e.witness[1].length)throw new TypeError("Witness has invalid pubkey");if(e.signature&&!e.signature.equals(e.witness[0]))throw new TypeError("Signature mismatch");if(e.pubkey&&!e.pubkey.equals(e.witness[1]))throw new TypeError("Pubkey mismatch");const r=i.hash160(e.witness[1]);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch")}}return Object.assign(l,e)}},7397:(e,t,r)=>{var n=r(8891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.signatureBlocksAction=t.checkInputForSig=t.pubkeyInScript=t.pubkeyPositionInScript=t.witnessStackToScriptWitness=t.isP2TR=t.isP2SHScript=t.isP2WSHScript=t.isP2WPKH=t.isP2PKH=t.isP2PK=t.isP2MS=void 0;const i=r(862),o=r(4778),s=r(2329),f=r(8892),u=r(393);function a(e){return t=>{try{return e({output:t}),!0}catch(e){return!1}}}function c(e,t){const r=(0,f.hash160)(e),n=e.slice(1,33),i=o.decompile(t);if(null===i)throw new Error("Unknown script error");return i.findIndex(t=>"number"!=typeof t&&(t.equals(e)||t.equals(r)||t.equals(n)))}function p(e,t,r){const{hashType:n}=t(e),i=[];switch(n&s.Transaction.SIGHASH_ANYONECANPAY&&i.push("addInput"),31&n){case s.Transaction.SIGHASH_ALL:break;case s.Transaction.SIGHASH_SINGLE:case s.Transaction.SIGHASH_NONE:i.push("addOutput"),i.push("setInputSequence")}return-1===i.indexOf(r)}t.isP2MS=a(u.p2ms),t.isP2PK=a(u.p2pk),t.isP2PKH=a(u.p2pkh),t.isP2WPKH=a(u.p2wpkh),t.isP2WSHScript=a(u.p2wsh),t.isP2SHScript=a(u.p2sh),t.isP2TR=a(u.p2tr),t.witnessStackToScriptWitness=function(e){let t=n.allocUnsafe(0);function r(e){const r=t.length,o=i.encodingLength(e);t=n.concat([t,n.allocUnsafe(o)]),i.encode(e,t,r)}var o;return r((o=e).length),o.forEach(function(e){r(e.length),function(e){t=n.concat([t,n.from(e)])}(e)}),t},t.pubkeyPositionInScript=c,t.pubkeyInScript=function(e,t){return-1!==c(e,t)},t.checkInputForSig=function(e,t){return function(e){let t=[];if(0===(e.partialSig||[]).length){if(!e.finalScriptSig&&!e.finalScriptWitness)return[];t=function(e){const t=e.finalScriptSig&&o.decompile(e.finalScriptSig)||[],r=e.finalScriptWitness&&o.decompile(e.finalScriptWitness)||[];return t.concat(r).filter(e=>n.isBuffer(e)&&o.isCanonicalScriptSignature(e)).map(e=>({signature:e}))}(e)}else t=e.partialSig;return t.map(e=>e.signature)}(e).some(e=>p(e,o.signature.decode,t))},t.signatureBlocksAction=p},7828:(e,t,r)=>{var n=r(8891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.p2sh=void 0;const i=r(8892),o=r(1834),s=r(4778),f=r(2992),u=r(6887),a=r(709),c=s.OPS;t.p2sh=function(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||{}),(0,f.typeforce)({network:f.typeforce.maybe(f.typeforce.Object),address:f.typeforce.maybe(f.typeforce.String),hash:f.typeforce.maybe(f.typeforce.BufferN(20)),output:f.typeforce.maybe(f.typeforce.BufferN(23)),redeem:f.typeforce.maybe({network:f.typeforce.maybe(f.typeforce.Object),output:f.typeforce.maybe(f.typeforce.Buffer),input:f.typeforce.maybe(f.typeforce.Buffer),witness:f.typeforce.maybe(f.typeforce.arrayOf(f.typeforce.Buffer))}),input:f.typeforce.maybe(f.typeforce.Buffer),witness:f.typeforce.maybe(f.typeforce.arrayOf(f.typeforce.Buffer))},e);let r=e.network;r||(r=e.redeem&&e.redeem.network||o.bitcoin);const p={network:r},h=u.value(()=>{const t=n.from(a.decode(e.address));return{version:t.readUInt8(0),hash:t.slice(1)}}),l=u.value(()=>s.decompile(e.input)),d=u.value(()=>{const t=l(),i=t[t.length-1];return{network:r,output:i===c.OP_FALSE?n.from([]):i,input:s.compile(t.slice(0,-1)),witness:e.witness||[]}});if(u.prop(p,"address",()=>{if(!p.hash)return;const e=n.allocUnsafe(21);return e.writeUInt8(p.network.scriptHash,0),p.hash.copy(e,1),a.encode(e)}),u.prop(p,"hash",()=>e.output?e.output.slice(2,22):e.address?h().hash:p.redeem&&p.redeem.output?i.hash160(p.redeem.output):void 0),u.prop(p,"output",()=>{if(p.hash)return s.compile([c.OP_HASH160,p.hash,c.OP_EQUAL])}),u.prop(p,"redeem",()=>{if(e.input)return d()}),u.prop(p,"input",()=>{if(e.redeem&&e.redeem.input&&e.redeem.output)return s.compile([].concat(s.decompile(e.redeem.input),e.redeem.output))}),u.prop(p,"witness",()=>p.redeem&&p.redeem.witness?p.redeem.witness:p.input?[]:void 0),u.prop(p,"name",()=>{const e=["p2sh"];return void 0!==p.redeem&&void 0!==p.redeem.name&&e.push(p.redeem.name),e.join("-")}),t.validate){let t=n.from([]);if(e.address){if(h().version!==r.scriptHash)throw new TypeError("Invalid version or Network mismatch");if(20!==h().hash.length)throw new TypeError("Invalid address");t=h().hash}if(e.hash){if(t.length>0&&!t.equals(e.hash))throw new TypeError("Hash mismatch");t=e.hash}if(e.output){if(23!==e.output.length||e.output[0]!==c.OP_HASH160||20!==e.output[1]||e.output[22]!==c.OP_EQUAL)throw new TypeError("Output is invalid");const r=e.output.slice(2,22);if(t.length>0&&!t.equals(r))throw new TypeError("Hash mismatch");t=r}const o=e=>{if(e.output){const r=s.decompile(e.output);if(!r||r.length<1)throw new TypeError("Redeem.output too short");if(e.output.byteLength>520)throw new TypeError("Redeem.output unspendable if larger than 520 bytes");if(s.countNonPushOnlyOPs(r)>201)throw new TypeError("Redeem.output unspendable with more than 201 non-push ops");const n=i.hash160(e.output);if(t.length>0&&!t.equals(n))throw new TypeError("Hash mismatch");t=n}if(e.input){const t=e.input.length>0,r=e.witness&&e.witness.length>0;if(!t&&!r)throw new TypeError("Empty input");if(t&&r)throw new TypeError("Input and witness provided");if(t){const t=s.decompile(e.input);if(!s.isPushOnly(t))throw new TypeError("Non push-only scriptSig")}}};if(e.input){const e=l();if(!e||e.length<1)throw new TypeError("Input too short");if(!n.isBuffer(d().output))throw new TypeError("Input is invalid");o(d())}if(e.redeem){if(e.redeem.network&&e.redeem.network!==r)throw new TypeError("Network mismatch");if(e.input){const t=d();if(e.redeem.output&&!e.redeem.output.equals(t.output))throw new TypeError("Redeem.output mismatch");if(e.redeem.input&&!e.redeem.input.equals(t.input))throw new TypeError("Redeem.input mismatch")}o(e.redeem)}if(e.witness&&e.redeem&&e.redeem.witness&&!(0,f.stacksEqual)(e.redeem.witness,e.witness))throw new TypeError("Witness and redeem.witness mismatch")}return Object.assign(p,e)}},8191:(e,t,r)=>{var n=r(8891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.encode=t.decode=void 0;const i=r(4538),o=r(4778),s=r(2992),{typeforce:f}=s,u=n.alloc(1,0);function a(e){let t=0;for(;0===e[t];)++t;return t===e.length?u:128&(e=e.slice(t))[0]?n.concat([u,e],1+e.length):e}function c(e){0===e[0]&&(e=e.slice(1));const t=n.alloc(32,0),r=Math.max(0,32-e.length);return e.copy(t,r),t}t.decode=function(e){const t=e.readUInt8(e.length-1);if(!(0,o.isDefinedHashType)(t))throw new Error("Invalid hashType "+t);const r=i.decode(e.slice(0,-1)),s=c(r.r),f=c(r.s);return{signature:n.concat([s,f],64),hashType:t}},t.encode=function(e,t){if(f({signature:s.BufferN(64),hashType:s.UInt8},{signature:e,hashType:t}),!(0,o.isDefinedHashType)(t))throw new Error("Invalid hashType "+t);const r=n.allocUnsafe(1);r.writeUInt8(t,0);const u=a(e.slice(0,32)),c=a(e.slice(32,64));return n.concat([i.encode(u,c),r])}},8381:(e,t,r)=>{var n=r(8891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.toOutputScript=t.fromOutputScript=t.toBech32=t.toBase58Check=t.fromBech32=t.fromBase58Check=void 0;const i=r(1834),o=r(393),s=r(4778),f=r(2992),u=r(9771),a=r(709),c="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 p(e){const t=n.from(a.decode(e));if(t.length<21)throw new TypeError(e+" is too short");if(t.length>21)throw new TypeError(e+" is too long");return{version:t.readUInt8(0),hash:t.slice(1)}}function h(e){let t,r;try{t=u.bech32.decode(e)}catch(e){}if(t){if(r=t.words[0],0!==r)throw new TypeError(e+" uses wrong encoding")}else if(t=u.bech32m.decode(e),r=t.words[0],0===r)throw new TypeError(e+" uses wrong encoding");const i=u.bech32.fromWords(t.words.slice(1));return{version:r,prefix:t.prefix,data:n.from(i)}}function l(e,t,r){const n=u.bech32.toWords(e);return n.unshift(t),0===t?u.bech32.encode(r,n):u.bech32m.encode(r,n)}t.fromBase58Check=p,t.fromBech32=h,t.toBase58Check=function(e,t){(0,f.typeforce)((0,f.tuple)(f.Hash160bit,f.UInt8),arguments);const r=n.allocUnsafe(21);return r.writeUInt8(t,0),e.copy(r,1),a.encode(r)},t.toBech32=l,t.fromOutputScript=function(e,t){t=t||i.bitcoin;try{return o.p2pkh({output:e,network:t}).address}catch(e){}try{return o.p2sh({output:e,network:t}).address}catch(e){}try{return o.p2wpkh({output:e,network:t}).address}catch(e){}try{return o.p2wsh({output:e,network:t}).address}catch(e){}try{return o.p2tr({output:e,network:t}).address}catch(e){}try{return function(e,t){const r=e.slice(2);if(r.length<2||r.length>40)throw new TypeError("Invalid program length for segwit address");const n=e[0]-80;if(n<2||n>16)throw new TypeError("Invalid version for segwit address");if(e[1]!==r.length)throw new TypeError("Invalid script for segwit address");return console.warn(c),l(r,n,t.bech32)}(e,t)}catch(e){}throw new Error(s.toASM(e)+" has no matching Address")},t.toOutputScript=function(e,t){let r,n;t=t||i.bitcoin;try{r=p(e)}catch(e){}if(r){if(r.version===t.pubKeyHash)return o.p2pkh({hash:r.hash}).output;if(r.version===t.scriptHash)return o.p2sh({hash:r.hash}).output}else{try{n=h(e)}catch(e){}if(n){if(n.prefix!==t.bech32)throw new Error(e+" has an invalid prefix");if(0===n.version){if(20===n.data.length)return o.p2wpkh({hash:n.data}).output;if(32===n.data.length)return o.p2wsh({hash:n.data}).output}else if(1===n.version){if(32===n.data.length)return o.p2tr({pubkey:n.data}).output}else if(n.version>=2&&n.version<=16&&n.data.length>=2&&n.data.length<=40)return console.warn(c),s.compile([n.version+80,n.data])}}throw new Error(e+" has no matching Script")}},8539:(e,t,r)=>{var n=r(8891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.getEccLib=t.initEccLib=void 0;const i={};t.initEccLib=function(e,t){var r;e?e!==i.eccLib&&(t?.DANGER_DO_NOT_VERIFY_ECCLIB||(s("function"==typeof(r=e).isXOnlyPoint),s(r.isXOnlyPoint(o("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"))),s(r.isXOnlyPoint(o("fffffffffffffffffffffffffffffffffffffffffffffffffffffffeeffffc2e"))),s(r.isXOnlyPoint(o("f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9"))),s(r.isXOnlyPoint(o("0000000000000000000000000000000000000000000000000000000000000001"))),s(!r.isXOnlyPoint(o("0000000000000000000000000000000000000000000000000000000000000000"))),s(!r.isXOnlyPoint(o("fffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f"))),s("function"==typeof r.xOnlyPointAddTweak),f.forEach(e=>{const t=r.xOnlyPointAddTweak(o(e.pubkey),o(e.tweak));null===e.result?s(null===t):(s(null!==t),s(t.parity===e.parity),s(n.from(t.xOnlyPubkey).equals(o(e.result))))})),i.eccLib=e):i.eccLib=e},t.getEccLib=function(){if(!i.eccLib)throw new Error("No ECC Library provided. You must call initEccLib() with a valid TinySecp256k1Interface instance");return i.eccLib};const o=e=>n.from(e,"hex");function s(e){if(!e)throw new Error("ecc library invalid")}const f=[{pubkey:"79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",tweak:"fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364140",parity:-1,result:null},{pubkey:"1617d38ed8d8657da4d4761e8057bc396ea9e4b9d29776d4be096016dbd2509b",tweak:"a8397a935f0dfceba6ba9618f6451ef4d80637abf4e6af2669fbc9de6a8fd2ac",parity:1,result:"e478f99dab91052ab39a33ea35fd5e6e4933f4d28023cd597c9a1f6760346adf"},{pubkey:"2c0b7cf95324a07d05398b240174dc0c2be444d96b159aa6c7f7b1e668680991",tweak:"823c3cd2142744b075a87eade7e1b8678ba308d566226a0056ca2b7a76f86b47",parity:0,result:"9534f8dc8c6deda2dc007655981c78b49c5d96c778fbf363462a11ec9dfd948c"}]},8892:(e,t,r)=>{var n=r(8891).Buffer;Object.defineProperty(t,"__esModule",{value:!0}),t.taggedHash=t.TAGGED_HASH_PREFIXES=t.TAGS=t.hash256=t.hash160=t.sha256=t.sha1=t.ripemd160=void 0;const i=r(4290),o=r(3553),s=r(7811);function f(e){return n.from((0,s.sha256)(Uint8Array.from(e)))}t.ripemd160=function(e){return n.from((0,i.ripemd160)(Uint8Array.from(e)))},t.sha1=function(e){return n.from((0,o.sha1)(Uint8Array.from(e)))},t.sha256=f,t.hash160=function(e){return n.from((0,i.ripemd160)((0,s.sha256)(Uint8Array.from(e))))},t.hash256=function(e){return n.from((0,s.sha256)((0,s.sha256)(Uint8Array.from(e))))},t.TAGS=["BIP0340/challenge","BIP0340/aux","BIP0340/nonce","TapLeaf","TapBranch","TapSighash","TapTweak","KeyAgg list","KeyAgg coefficient"],t.TAGGED_HASH_PREFIXES={"BIP0340/challenge":n.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":n.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":n.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:n.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:n.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:n.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:n.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":n.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":n.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])},t.taggedHash=function(e,r){return f(n.concat([t.TAGGED_HASH_PREFIXES[e],r]))}}};