@gvnrdao/dh-sdk 0.0.324 → 0.0.328

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.
@@ -18,6 +18,7 @@ import { SDKError } from "../utils/error-handler";
18
18
  import type { CreateLoanRequest, CreateLoanResult, LoanDataDetail, UCDMintRequest, UCDMintResult, PartialPaymentRequest, PartialPaymentResult, BTCWithdrawalResult, RenewPositionRequest, RenewPositionResult, LiquidationRequest, LiquidationResult, ConfirmBalanceRequest, ConfirmBalanceResult, TermsWithFeesResult } from "../interfaces/chunks/loan-operations.i";
19
19
  import type { DiamondHandsSDKConfig } from "../interfaces/chunks/config.i";
20
20
  import type { PKPData } from "../interfaces/chunks/pkp-integration.i";
21
+ import { type AuthorizationProvider } from "../utils/authorization-provider.utils";
21
22
  import type { DhServerLoginPayload } from "../utils/eip712-login";
22
23
  import { type ReconciledWithdrawal } from "../utils/withdrawal-reconciliation.utils";
23
24
  import { ContractManager } from "./contract/contract-manager.module";
@@ -581,7 +582,15 @@ export declare class DiamondHandsSDK {
581
582
  * @param customBitcoinRpcUrl - Optional custom Bitcoin RPC URL (for local testing)
582
583
  * @returns Withdrawal result with transaction details
583
584
  */
584
- withdrawBTC(positionId: string, withdrawalAddress: string, withdrawalAmount: number): Promise<BTCWithdrawalResult>;
585
+ withdrawBTC(positionId: string, withdrawalAddress: string, withdrawalAmount: number,
586
+ /**
587
+ * An options bag rather than a fifth positional argument: this method is
588
+ * already three positional strings/numbers deep, and the next caller to
589
+ * add one would have to guess the order.
590
+ */
591
+ options?: {
592
+ authorizationProvider?: AuthorizationProvider;
593
+ }): Promise<BTCWithdrawalResult>;
585
594
  /**
586
595
  * TEMPORARY (multi-UTXO withdrawal fix, Phase A): fetch the vault's confirmed
587
596
  * UTXO set from lit-ops-server (`GET /api/lit/vault-utxos`) so the caller can
@@ -739,6 +748,11 @@ export declare class DiamondHandsSDK {
739
748
  * (`MAX_ATTESTATION_AGE = 1 hour`) and replay-protects via
740
749
  * `authorizedAt` binding.
741
750
  *
751
+ * WHO PAYS: in **service mode** lit-ops-server performs BOTH steps and its
752
+ * relayer funds the transaction — the borrower is never prompted, because the
753
+ * Bitcoin withdrawal this cleans up after has already settled. In **direct
754
+ * mode** (CLI / tests / hardhat) the SDK's own signer submits step 2.
755
+ *
742
756
  * `invalidatorTxid` is either:
743
757
  * - the borrower's own authorized broadcast (classified "consumed-as-authorized"
744
758
  * by the LIT validator), once it has ≥6 confirmations on the BTC
@@ -1071,6 +1085,16 @@ export declare class DiamondHandsSDK {
1071
1085
  agentActive: boolean | null;
1072
1086
  /** Agent expiry (unix seconds) — the ONLY time bound on every grant. Null without `user`. */
1073
1087
  agentValidUntil: number | null;
1088
+ /** SCOPE_WITHDRAW granted. Always false where the registry predates v2.1.0. */
1089
+ withdrawEnabled: boolean;
1090
+ /** Does the DEPLOYED registry honour SCOPE_WITHDRAW at all (v2.1.0+)? */
1091
+ withdrawScopeSupported: boolean;
1092
+ /**
1093
+ * Grant's post-withdrawal collateral floor in bps; 0 when WITHDRAW is not granted.
1094
+ * INERT AT ZERO DEBT — a ratio cannot bound a withdrawal once debt is 0. Never present this
1095
+ * as a cap on how much an agent may withdraw.
1096
+ */
1097
+ minWithdrawRatioBps: number;
1074
1098
  }>;
1075
1099
  /** Governance floor-of-floors for agent mints (bps). The UI's minimum for the floor editor. */
1076
1100
  getAgentMintFloorMinBps(): Promise<number>;
@@ -1161,7 +1185,56 @@ export declare class DiamondHandsSDK {
1161
1185
  hash: string;
1162
1186
  blockNumber: number;
1163
1187
  }>;
1164
- /** Pre-flight the registry's `FloorBelowProtocolMin` guard with a message a user can act on. */
1188
+ /**
1189
+ * Grant the agent the WITHDRAW scope for a position (registry v2.1.0+). Borrower-signed.
1190
+ *
1191
+ * CONTRACT WALLETS ONLY, and this is enforced here rather than on-chain. The withdrawal
1192
+ * validator's only non-borrower arm is `checkSafeAgentWithdrawAuthorization`, which requires a
1193
+ * factory-provenanced `AgentModule` whose `safe()` is the borrower — something an EOA cannot
1194
+ * have. The registry deliberately does NOT check wallet type ("Callable by any borrower (this
1195
+ * function does not itself require a Safe)"), so an EOA can record a grant that no code path
1196
+ * will ever satisfy. Refusing here keeps the supported path from writing a dead record.
1197
+ *
1198
+ * That refusal is ergonomics, NOT enforcement — `enableAutoWithdraw` is `external` and reachable
1199
+ * from any wallet. The real reason delegated withdrawal is closed to EOAs is that they can sign
1200
+ * inside the ~44s window themselves, so delegating buys them nothing and only adds risk.
1201
+ *
1202
+ * @param minWithdrawRatioBps Post-withdrawal collateral-ratio floor for AGENT withdrawals.
1203
+ * Clamped by the same governance minimum as the mint floor. **Inert at zero debt** — it
1204
+ * is a ratio, and the post-withdrawal ratio is infinite for any amount once debt is 0.
1205
+ * The operative bound there is the quorum-gated destination allowlist. Do not surface
1206
+ * this to users as a cap on how much an agent may withdraw.
1207
+ * There is no in-place raise: changing it means disable-then-re-enable, deliberately —
1208
+ * on the one scope that moves custodied BTC, incident response can only disable outright.
1209
+ */
1210
+ enableAutoWithdraw(positionId: string, minWithdrawRatioBps: number, options?: {
1211
+ agentValiditySeconds?: number;
1212
+ }): Promise<{
1213
+ hash: string;
1214
+ blockNumber: number;
1215
+ agentAddress?: string;
1216
+ }>;
1217
+ /**
1218
+ * Revoke the WITHDRAW scope for a position (also zeroes its withdraw floor). Borrower-signed.
1219
+ *
1220
+ * No wallet-type check: revoking is the safe direction, and an EOA that recorded a grant before
1221
+ * this guard existed must be able to clear it.
1222
+ */
1223
+ disableAutoWithdraw(positionId: string): Promise<{
1224
+ hash: string;
1225
+ blockNumber: number;
1226
+ }>;
1227
+ /**
1228
+ * Layer 2 of the withdrawal-delegation gating: refuse to write a grant that could never be
1229
+ * satisfied. See `enableAutoWithdraw` for why this lives here and not in the registry.
1230
+ */
1231
+ private assertBorrowerIsContractWallet;
1232
+ /**
1233
+ * Pre-flight the registry's `FloorBelowProtocolMin` guard with a message a user can act on.
1234
+ *
1235
+ * `agentMintFloorMinBps` is the governance floor-of-floors for BOTH the mint and withdraw
1236
+ * grants — one lever, one invariant — so `scope` only shapes the message.
1237
+ */
1165
1238
  private assertMintFloorAtOrAboveProtocolMin;
1166
1239
  /**
1167
1240
  * Get Bitcoin balance for an address
@@ -326,7 +326,7 @@ var SEPOLIA_DEPLOYMENT = {
326
326
  CARRY_AGENT_REGISTRY: "0x5595CB538D44E6Cf179D20364fD631D0477e69f7",
327
327
  CARRY_AGENT_REGISTRY_IMPL: "0x1b11a3D5e46F3672E643c997f0d569DFf0b64a01",
328
328
  AGENT_DELEGATION_REGISTRY: "0x6AE7fc6bE0925126b9D25b1B7Ce5AD5d127ec025",
329
- AGENT_DELEGATION_REGISTRY_IMPL: "0x80C47350274513688e348D02506477A96B4afCCb",
329
+ AGENT_DELEGATION_REGISTRY_IMPL: "0xE931E4b9ceF2A48Ac7D57192da4B523756cFC310",
330
330
  DH_AGENT_DELEGATE: "0xa5A14489ae883960df6E1463A41a47aBE9Ecc5AF"
331
331
  }
332
332
  };
@@ -538,7 +538,7 @@ var MAINNET_DEPLOYMENT = {
538
538
  var LOCALHOST_DEPLOYMENT = {
539
539
  network: "localhost",
540
540
  chainId: 1337,
541
- timestamp: "2026-07-23T17:13:42.777Z",
541
+ timestamp: "2026-07-20T19:45:58.514Z",
542
542
  deployer: "",
543
543
  contracts: {
544
544
  MessageHashBuilder: "0xa82fF9aFd8f496c3d6ac40E2a0F282E47488CFc9",
@@ -558,30 +558,6 @@ var LOCALHOST_DEPLOYMENT = {
558
558
  PositionManager: "0x851356ae760d987E095750cCeb3bC6014560891C",
559
559
  OperationAuthorizationRegistry: "0xc96304e3c037f81dA488ed9dEa1D8F2a48278a75",
560
560
  PKPValidation: "0xD0141E899a65C95a556fE2B27e5982A6DE7fDD7A"
561
- },
562
- latestEnv: {
563
- UCD_TOKEN: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
564
- UCD_CONTROLLER: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
565
- POSITION_MANAGER: "0x851356ae760d987E095750cCeb3bC6014560891C",
566
- PKP_VALIDATION_REGISTRY: "0xD0141E899a65C95a556fE2B27e5982A6DE7fDD7A",
567
- PKP_VALIDATION_CID_V1: "0x12203af2054b0ab6e18d898ddfc7985593439fb82d22336133387c1169f98d3702ab",
568
- PKP_VALIDATION_CID_V3: "0x12203af2054b0ab6e18d898ddfc7985593439fb82d22336133387c1169f98d3702ab",
569
- PKP_ETH_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
570
- OPERATION_AUTHORIZATION_REGISTRY: "0xc96304e3c037f81dA488ed9dEa1D8F2a48278a75",
571
- UCD_MINT_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
572
- UCD_MINT_VALIDATOR_VERSION: 1,
573
- BTC_WITHDRAWAL_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
574
- BTC_WITHDRAWAL_VALIDATOR_VERSION: 3,
575
- UPDATE_BALANCE_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
576
- UPDATE_BALANCE_VALIDATOR_VERSION: 1,
577
- PROCESS_PAYMENT_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
578
- PROCESS_PAYMENT_VALIDATOR_VERSION: 1,
579
- EXTEND_POSITION_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
580
- EXTEND_POSITION_VALIDATOR_VERSION: 1,
581
- POSITION_MANAGER_CORE_MODULE: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
582
- LOAN_OPERATIONS_MANAGER_MODULE: "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
583
- TERM_MANAGER_MODULE: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
584
- COMMUNITY_MANAGER_MODULE: ""
585
561
  }
586
562
  };
587
563
  var ALL_DEPLOYMENTS = {
@@ -299,7 +299,7 @@ var SEPOLIA_DEPLOYMENT = {
299
299
  CARRY_AGENT_REGISTRY: "0x5595CB538D44E6Cf179D20364fD631D0477e69f7",
300
300
  CARRY_AGENT_REGISTRY_IMPL: "0x1b11a3D5e46F3672E643c997f0d569DFf0b64a01",
301
301
  AGENT_DELEGATION_REGISTRY: "0x6AE7fc6bE0925126b9D25b1B7Ce5AD5d127ec025",
302
- AGENT_DELEGATION_REGISTRY_IMPL: "0x80C47350274513688e348D02506477A96B4afCCb",
302
+ AGENT_DELEGATION_REGISTRY_IMPL: "0xE931E4b9ceF2A48Ac7D57192da4B523756cFC310",
303
303
  DH_AGENT_DELEGATE: "0xa5A14489ae883960df6E1463A41a47aBE9Ecc5AF"
304
304
  }
305
305
  };
@@ -511,7 +511,7 @@ var MAINNET_DEPLOYMENT = {
511
511
  var LOCALHOST_DEPLOYMENT = {
512
512
  network: "localhost",
513
513
  chainId: 1337,
514
- timestamp: "2026-07-23T17:13:42.777Z",
514
+ timestamp: "2026-07-20T19:45:58.514Z",
515
515
  deployer: "",
516
516
  contracts: {
517
517
  MessageHashBuilder: "0xa82fF9aFd8f496c3d6ac40E2a0F282E47488CFc9",
@@ -531,30 +531,6 @@ var LOCALHOST_DEPLOYMENT = {
531
531
  PositionManager: "0x851356ae760d987E095750cCeb3bC6014560891C",
532
532
  OperationAuthorizationRegistry: "0xc96304e3c037f81dA488ed9dEa1D8F2a48278a75",
533
533
  PKPValidation: "0xD0141E899a65C95a556fE2B27e5982A6DE7fDD7A"
534
- },
535
- latestEnv: {
536
- UCD_TOKEN: "0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512",
537
- UCD_CONTROLLER: "0xCf7Ed3AccA5a467e9e704C703E8D87F634fB0Fc9",
538
- POSITION_MANAGER: "0x851356ae760d987E095750cCeb3bC6014560891C",
539
- PKP_VALIDATION_REGISTRY: "0xD0141E899a65C95a556fE2B27e5982A6DE7fDD7A",
540
- PKP_VALIDATION_CID_V1: "0x12203af2054b0ab6e18d898ddfc7985593439fb82d22336133387c1169f98d3702ab",
541
- PKP_VALIDATION_CID_V3: "0x12203af2054b0ab6e18d898ddfc7985593439fb82d22336133387c1169f98d3702ab",
542
- PKP_ETH_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
543
- OPERATION_AUTHORIZATION_REGISTRY: "0xc96304e3c037f81dA488ed9dEa1D8F2a48278a75",
544
- UCD_MINT_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
545
- UCD_MINT_VALIDATOR_VERSION: 1,
546
- BTC_WITHDRAWAL_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
547
- BTC_WITHDRAWAL_VALIDATOR_VERSION: 3,
548
- UPDATE_BALANCE_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
549
- UPDATE_BALANCE_VALIDATOR_VERSION: 1,
550
- PROCESS_PAYMENT_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
551
- PROCESS_PAYMENT_VALIDATOR_VERSION: 1,
552
- EXTEND_POSITION_VALIDATOR_ADDRESS: "0x406f6a9855de2f5577b1525f0600461f02859bd0",
553
- EXTEND_POSITION_VALIDATOR_VERSION: 1,
554
- POSITION_MANAGER_CORE_MODULE: "0xB7f8BC63BbcaD18155201308C8f3540b07f84F5e",
555
- LOAN_OPERATIONS_MANAGER_MODULE: "0x68B1D87F95878fE05B998F19b66F4baba5De1aed",
556
- TERM_MANAGER_MODULE: "0x0DCd1Bf9A1b36cE34237eEaFef220932846BCD82",
557
- COMMUNITY_MANAGER_MODULE: ""
558
534
  }
559
535
  };
560
536
  var ALL_DEPLOYMENTS = {
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Borrower authorization, supplied by something other than the connected signer.
3
+ *
4
+ * WHY THIS EXISTS. Every loan operation carries an envelope the validator
5
+ * recovers a signer from, and the SDK builds it by calling
6
+ * `signer.signMessage()`. For an EOA that is one instant prompt. For a k-of-n
7
+ * Safe it is an EIP-1271 signature — a full owner quorum — and the operation
8
+ * also needs a second quorum to send the transaction, both inside a quantum
9
+ * window of 180s (~44s for withdrawals). That cannot be gathered, so a genuine
10
+ * multi-owner Safe could not complete a loan operation at all.
11
+ *
12
+ * The fix is for something that CAN sign instantly to sign the envelope: the
13
+ * Safe's delegated agent. This is the seam that lets a caller supply it.
14
+ *
15
+ * A PROVIDER, NOT A VALUE. The obvious API — hand in `{ timestamp, signature }`
16
+ * — is wrong, and the reason is the retry loops. Every operation re-signs on
17
+ * retry precisely because a quantum window can lapse between building the
18
+ * envelope and landing the transaction. A fixed value would be replayed on
19
+ * attempt 2 carrying attempt 1's timestamp, so the envelope would already be
20
+ * dead: a recoverable timing miss turned into a hard failure. A provider is
21
+ * called again per attempt and returns a fresh signature over a fresh window.
22
+ *
23
+ * THE SDK OWNS THE TIMESTAMP. It computes the quantum-aligned value and hands
24
+ * it to the provider, rather than accepting one back unseen, because the same
25
+ * value must be embedded in the protocol call that follows. Likewise `amount`
26
+ * is the SDK's own computed wei — a caller re-deriving it and differing by one
27
+ * wei produces a signature that recovers to a different address, which surfaces
28
+ * as an opaque authorization failure with nothing to point at.
29
+ */
30
+ /** Everything the authorization envelope binds, as the SDK computed it. */
31
+ export interface AuthorizationContext {
32
+ positionId: string;
33
+ /** Quantum-aligned, and the value the protocol call will carry. */
34
+ timestamp: number;
35
+ /** Wei, as a decimal string. The SDK's own value — never re-derive it. */
36
+ amount: string;
37
+ /** Renewals only: the term the envelope binds instead of an amount. */
38
+ selectedTerm?: number;
39
+ /** Withdrawals only: the destination the envelope binds. */
40
+ destinationAddress?: string;
41
+ }
42
+ /**
43
+ * Returns a signature over the envelope described by `ctx`. The returned
44
+ * `timestamp` is echoed back rather than assumed so a provider that had to
45
+ * re-align it can say so — but it SHOULD be the one it was given.
46
+ */
47
+ export type AuthorizationProvider = (ctx: AuthorizationContext) => Promise<{
48
+ timestamp: number;
49
+ signature: string;
50
+ }>;
51
+ /**
52
+ * Resolve what the `generate*Authorization` helpers should be handed: either a
53
+ * precomputed `{ timestamp, signature }` from the provider, or the live signer
54
+ * exactly as before.
55
+ *
56
+ * Call this INSIDE a retry loop, never above one — that is the whole point.
57
+ *
58
+ * @param nextQuantumTimestamp The SDK's quantum-aligned timestamp for THIS
59
+ * attempt. Passed in rather than computed here so the caller keeps a
60
+ * single source for the value it will also send on-chain.
61
+ */
62
+ export declare function resolveAuthorizationInput<TSigner>(provider: AuthorizationProvider | undefined, signer: TSigner, ctx: AuthorizationContext): Promise<TSigner | {
63
+ timestamp: number;
64
+ signature: string;
65
+ }>;
@@ -113,25 +113,19 @@ export interface BalanceConfirmationAuthorization {
113
113
  * - Signer address is recovered from signature by LIT Action
114
114
  * - LIT Action validates recovered address === position owner
115
115
  */
116
- export declare function generatePaymentAuthorization(positionId: string, amount: bigint, chainId: number, signer: Signer): Promise<PaymentOwnerAuthorization>;
116
+ export declare function generatePaymentAuthorization(positionId: string, amount: bigint, chainId: number, signerOrPrecomputed: Signer | {
117
+ timestamp: number;
118
+ signature: string;
119
+ }): Promise<PaymentOwnerAuthorization>;
117
120
  /**
118
- * Generate extend position authorization signature
119
- *
120
- * Creates a signature that matches the format expected by
121
- * extend-position-validator LIT Action.
122
- *
123
- * Message structure:
124
- * solidityKeccak256(
125
- * ["bytes32", "uint256", "uint256", "uint256", "bytes32"],
126
- * [positionId, timestamp, chainId, selectedTerm, actionHash]
127
- * )
121
+ * NOTE: `generateExtendAuthorization` does NOT live here.
128
122
  *
129
- * Where:
130
- * - actionHash = keccak256("extend-position")
131
- * - Signer address is recovered from signature by LIT Action
132
- * - LIT Action validates recovered address === position owner
123
+ * It used to — a second copy, without the precomputed-signature union, whose
124
+ * import in `diamond-hands-sdk.ts` was commented out ("Not used yet"). The live
125
+ * one is `utils/extend-authorization.utils.ts`, and that is the only one. The
126
+ * duplicate is removed rather than left dormant because an edit landing in the
127
+ * wrong copy is a silent no-op: the code looks changed, the behaviour does not.
133
128
  */
134
- export declare function generateExtendAuthorization(positionId: string, selectedTerm: number, chainId: number, signer: Signer): Promise<ExtendOwnerAuthorization>;
135
129
  /**
136
130
  * Optional Chipotle service fallback for `getPKPPublicKeyFromTokenId`.
137
131
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gvnrdao/dh-sdk",
3
- "version": "0.0.324",
3
+ "version": "0.0.328",
4
4
  "description": "TypeScript SDK for Diamond Hands Protocol - Bitcoin-backed lending with LIT Protocol PKPs",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -87,8 +87,8 @@
87
87
  },
88
88
  "sideEffects": false,
89
89
  "dependencies": {
90
- "@gvnrdao/dh-lit-actions": "^0.0.320",
91
- "@gvnrdao/dh-lit-ops": "^0.0.311",
90
+ "@gvnrdao/dh-lit-actions": "^0.0.321",
91
+ "@gvnrdao/dh-lit-ops": "^0.0.313",
92
92
  "@noble/hashes": "^1.5.0",
93
93
  "axios": "^1.17.0",
94
94
  "bech32": "^2.0.0",
@@ -1,2 +0,0 @@
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__={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]))}}};
@@ -1 +0,0 @@
1
- /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */