@babylonlabs-io/ts-sdk 0.0.0-semantic-release.2 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +124 -6
- package/dist/MockEthereumWallet-CKQlH2AM.cjs +2 -0
- package/dist/MockEthereumWallet-CKQlH2AM.cjs.map +1 -0
- package/dist/MockEthereumWallet-ibdry7pZ.js +127 -0
- package/dist/MockEthereumWallet-ibdry7pZ.js.map +1 -0
- package/dist/PayoutManager-Dg_i_S7w.cjs +2 -0
- package/dist/PayoutManager-Dg_i_S7w.cjs.map +1 -0
- package/dist/PayoutManager-rMj54HDh.js +1112 -0
- package/dist/PayoutManager-rMj54HDh.js.map +1 -0
- package/dist/challengeAssert-34HqeVFH.cjs +2 -0
- package/dist/challengeAssert-34HqeVFH.cjs.map +1 -0
- package/dist/challengeAssert-DVErOd8l.js +423 -0
- package/dist/challengeAssert-DVErOd8l.js.map +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.js +64 -1
- package/dist/index.js.map +1 -1
- package/dist/shared/index.cjs +1 -1
- package/dist/shared/index.d.ts +3 -1
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/index.js +5 -1
- package/dist/shared/index.js.map +1 -1
- package/dist/shared/wallets/__tests__/BitcoinWallet.test.d.ts +2 -0
- package/dist/shared/wallets/__tests__/BitcoinWallet.test.d.ts.map +1 -0
- package/dist/shared/wallets/__tests__/EthereumWallet.test.d.ts +2 -0
- package/dist/shared/wallets/__tests__/EthereumWallet.test.d.ts.map +1 -0
- package/dist/shared/wallets/index.d.ts +4 -0
- package/dist/shared/wallets/index.d.ts.map +1 -0
- package/dist/shared/wallets/interfaces/BitcoinWallet.d.ts +106 -0
- package/dist/shared/wallets/interfaces/BitcoinWallet.d.ts.map +1 -0
- package/dist/shared/wallets/interfaces/EthereumWallet.d.ts +6 -0
- package/dist/shared/wallets/interfaces/EthereumWallet.d.ts.map +1 -0
- package/dist/shared/wallets/interfaces/index.d.ts +4 -0
- package/dist/shared/wallets/interfaces/index.d.ts.map +1 -0
- package/dist/shared/wallets/mocks/MockBitcoinWallet.d.ts +29 -0
- package/dist/shared/wallets/mocks/MockBitcoinWallet.d.ts.map +1 -0
- package/dist/shared/wallets/mocks/MockEthereumWallet.d.ts +51 -0
- package/dist/shared/wallets/mocks/MockEthereumWallet.d.ts.map +1 -0
- package/dist/shared/wallets/mocks/index.d.ts +5 -0
- package/dist/shared/wallets/mocks/index.d.ts.map +1 -0
- package/dist/tbv/core/clients/index.d.ts +9 -0
- package/dist/tbv/core/clients/index.d.ts.map +1 -0
- package/dist/tbv/core/clients/mempool/index.d.ts +11 -0
- package/dist/tbv/core/clients/mempool/index.d.ts.map +1 -0
- package/dist/tbv/core/clients/mempool/mempoolApi.d.ts +94 -0
- package/dist/tbv/core/clients/mempool/mempoolApi.d.ts.map +1 -0
- package/dist/tbv/core/clients/mempool/types.d.ts +98 -0
- package/dist/tbv/core/clients/mempool/types.d.ts.map +1 -0
- package/dist/tbv/core/contracts/abis/BTCVaultsManager.abi.d.ts +187 -0
- package/dist/tbv/core/contracts/abis/BTCVaultsManager.abi.d.ts.map +1 -0
- package/dist/tbv/core/contracts/errors.d.ts +50 -0
- package/dist/tbv/core/contracts/errors.d.ts.map +1 -0
- package/dist/tbv/core/contracts/index.d.ts +11 -0
- package/dist/tbv/core/contracts/index.d.ts.map +1 -0
- package/dist/tbv/core/index.cjs +1 -1
- package/dist/tbv/core/index.d.ts +17 -1
- package/dist/tbv/core/index.d.ts.map +1 -1
- package/dist/tbv/core/index.js +61 -1
- package/dist/tbv/core/index.js.map +1 -1
- package/dist/tbv/core/managers/PayoutManager.d.ts +158 -0
- package/dist/tbv/core/managers/PayoutManager.d.ts.map +1 -0
- package/dist/tbv/core/managers/PeginManager.d.ts +333 -0
- package/dist/tbv/core/managers/PeginManager.d.ts.map +1 -0
- package/dist/tbv/core/managers/__tests__/PayoutManager.test.d.ts +8 -0
- package/dist/tbv/core/managers/__tests__/PayoutManager.test.d.ts.map +1 -0
- package/dist/tbv/core/managers/__tests__/PeginManager.test.d.ts +8 -0
- package/dist/tbv/core/managers/__tests__/PeginManager.test.d.ts.map +1 -0
- package/dist/tbv/core/managers/index.d.ts +75 -0
- package/dist/tbv/core/managers/index.d.ts.map +1 -0
- package/dist/tbv/core/primitives/index.cjs +2 -0
- package/dist/tbv/core/primitives/index.d.ts +87 -0
- package/dist/tbv/core/primitives/index.d.ts.map +1 -0
- package/dist/tbv/core/primitives/index.js +23 -0
- package/dist/tbv/{integrations/morpho → core/primitives}/index.js.map +1 -1
- package/dist/tbv/core/primitives/psbt/__tests__/constants.d.ts +137 -0
- package/dist/tbv/core/primitives/psbt/__tests__/constants.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/__tests__/helpers.d.ts +71 -0
- package/dist/tbv/core/primitives/psbt/__tests__/helpers.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/__tests__/payout.test.d.ts +8 -0
- package/dist/tbv/core/primitives/psbt/__tests__/payout.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/__tests__/pegin.test.d.ts +5 -0
- package/dist/tbv/core/primitives/psbt/__tests__/pegin.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/challengeAssert.d.ts +27 -0
- package/dist/tbv/core/primitives/psbt/challengeAssert.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/depositorPayout.d.ts +27 -0
- package/dist/tbv/core/primitives/psbt/depositorPayout.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/index.d.ts +27 -0
- package/dist/tbv/core/primitives/psbt/index.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/noPayout.d.ts +28 -0
- package/dist/tbv/core/primitives/psbt/noPayout.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/payout.d.ts +99 -0
- package/dist/tbv/core/primitives/psbt/payout.d.ts.map +1 -0
- package/dist/tbv/core/primitives/psbt/pegin.d.ts +88 -0
- package/dist/tbv/core/primitives/psbt/pegin.d.ts.map +1 -0
- package/dist/tbv/core/primitives/scripts/__tests__/payout.test.d.ts +5 -0
- package/dist/tbv/core/primitives/scripts/__tests__/payout.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/scripts/index.d.ts +10 -0
- package/dist/tbv/core/primitives/scripts/index.d.ts.map +1 -0
- package/dist/tbv/core/primitives/scripts/payout.d.ts +102 -0
- package/dist/tbv/core/primitives/scripts/payout.d.ts.map +1 -0
- package/dist/tbv/core/primitives/utils/__tests__/bitcoin.test.d.ts +5 -0
- package/dist/tbv/core/primitives/utils/__tests__/bitcoin.test.d.ts.map +1 -0
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts +132 -0
- package/dist/tbv/core/primitives/utils/bitcoin.d.ts.map +1 -0
- package/dist/tbv/core/primitives/utils/index.d.ts +9 -0
- package/dist/tbv/core/primitives/utils/index.d.ts.map +1 -0
- package/dist/tbv/core/utils/btc/index.d.ts +10 -0
- package/dist/tbv/core/utils/btc/index.d.ts.map +1 -0
- package/dist/tbv/core/utils/btc/psbtInputFields.d.ts +41 -0
- package/dist/tbv/core/utils/btc/psbtInputFields.d.ts.map +1 -0
- package/dist/tbv/core/utils/btc/scriptType.d.ts +34 -0
- package/dist/tbv/core/utils/btc/scriptType.d.ts.map +1 -0
- package/dist/tbv/core/utils/fee/constants.d.ts +25 -0
- package/dist/tbv/core/utils/fee/constants.d.ts.map +1 -0
- package/dist/tbv/core/utils/fee/index.d.ts +7 -0
- package/dist/tbv/core/utils/fee/index.d.ts.map +1 -0
- package/dist/tbv/core/utils/index.d.ts +16 -0
- package/dist/tbv/core/utils/index.d.ts.map +1 -0
- package/dist/tbv/core/utils/transaction/__tests__/btcTxHash.test.d.ts +5 -0
- package/dist/tbv/core/utils/transaction/__tests__/btcTxHash.test.d.ts.map +1 -0
- package/dist/tbv/core/utils/transaction/__tests__/createSplitTransaction.test.d.ts +5 -0
- package/dist/tbv/core/utils/transaction/__tests__/createSplitTransaction.test.d.ts.map +1 -0
- package/dist/tbv/core/utils/transaction/__tests__/fundPeginTransaction.test.d.ts +5 -0
- package/dist/tbv/core/utils/transaction/__tests__/fundPeginTransaction.test.d.ts.map +1 -0
- package/dist/tbv/core/utils/transaction/btcTxHash.d.ts +15 -0
- package/dist/tbv/core/utils/transaction/btcTxHash.d.ts.map +1 -0
- package/dist/tbv/core/utils/transaction/createSplitTransaction.d.ts +106 -0
- package/dist/tbv/core/utils/transaction/createSplitTransaction.d.ts.map +1 -0
- package/dist/tbv/core/utils/transaction/fundPeginTransaction.d.ts +70 -0
- package/dist/tbv/core/utils/transaction/fundPeginTransaction.d.ts.map +1 -0
- package/dist/tbv/core/utils/transaction/index.d.ts +9 -0
- package/dist/tbv/core/utils/transaction/index.d.ts.map +1 -0
- package/dist/tbv/core/utils/utxo/__tests__/selectUtxos.test.d.ts +5 -0
- package/dist/tbv/core/utils/utxo/__tests__/selectUtxos.test.d.ts.map +1 -0
- package/dist/tbv/core/utils/utxo/index.d.ts +7 -0
- package/dist/tbv/core/utils/utxo/index.d.ts.map +1 -0
- package/dist/tbv/core/utils/utxo/selectUtxos.d.ts +65 -0
- package/dist/tbv/core/utils/utxo/selectUtxos.d.ts.map +1 -0
- package/dist/tbv/index.cjs +1 -1
- package/dist/tbv/index.js +61 -1
- package/dist/tbv/index.js.map +1 -1
- package/dist/tbv/integrations/aave/clients/__tests__/spoke.test.d.ts +2 -0
- package/dist/tbv/integrations/aave/clients/__tests__/spoke.test.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/clients/__tests__/transaction.test.d.ts +2 -0
- package/dist/tbv/integrations/aave/clients/__tests__/transaction.test.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/clients/abis/AaveIntegrationController.abi.json.d.ts +1879 -0
- package/dist/tbv/integrations/aave/clients/abis/AaveSpoke.abi.json.d.ts +1262 -0
- package/dist/tbv/integrations/aave/clients/index.d.ts +4 -0
- package/dist/tbv/integrations/aave/clients/index.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/clients/query.d.ts +27 -0
- package/dist/tbv/integrations/aave/clients/query.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/clients/spoke.d.ts +161 -0
- package/dist/tbv/integrations/aave/clients/spoke.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/clients/transaction.d.ts +110 -0
- package/dist/tbv/integrations/aave/clients/transaction.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/config.d.ts +7 -0
- package/dist/tbv/integrations/aave/config.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/constants.d.ts +113 -0
- package/dist/tbv/integrations/aave/constants.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/index.cjs +2 -0
- package/dist/tbv/integrations/aave/index.cjs.map +1 -0
- package/dist/tbv/integrations/aave/index.d.ts +53 -0
- package/dist/tbv/integrations/aave/index.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/index.js +307 -0
- package/dist/tbv/integrations/aave/index.js.map +1 -0
- package/dist/tbv/integrations/aave/types.d.ts +66 -0
- package/dist/tbv/integrations/aave/types.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/utils/__tests__/aaveConversions.test.d.ts +5 -0
- package/dist/tbv/integrations/aave/utils/__tests__/aaveConversions.test.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/utils/__tests__/borrowRatio.test.d.ts +5 -0
- package/dist/tbv/integrations/aave/utils/__tests__/borrowRatio.test.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/utils/__tests__/debtUtils.test.d.ts +5 -0
- package/dist/tbv/integrations/aave/utils/__tests__/debtUtils.test.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/utils/__tests__/healthFactor.test.d.ts +5 -0
- package/dist/tbv/integrations/aave/utils/__tests__/healthFactor.test.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/utils/__tests__/vaultSelection.test.d.ts +2 -0
- package/dist/tbv/integrations/aave/utils/__tests__/vaultSelection.test.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/utils/__tests__/vaultSplit.test.d.ts +5 -0
- package/dist/tbv/integrations/aave/utils/__tests__/vaultSplit.test.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/utils/aaveConversions.d.ts +24 -0
- package/dist/tbv/integrations/aave/utils/aaveConversions.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/utils/borrowRatio.d.ts +15 -0
- package/dist/tbv/integrations/aave/utils/borrowRatio.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/utils/debtUtils.d.ts +14 -0
- package/dist/tbv/integrations/aave/utils/debtUtils.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/utils/healthFactor.d.ts +108 -0
- package/dist/tbv/integrations/aave/utils/healthFactor.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/utils/index.d.ts +10 -0
- package/dist/tbv/integrations/aave/utils/index.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/utils/vaultSelection.d.ts +33 -0
- package/dist/tbv/integrations/aave/utils/vaultSelection.d.ts.map +1 -0
- package/dist/tbv/integrations/aave/utils/vaultSplit.d.ts +191 -0
- package/dist/tbv/integrations/aave/utils/vaultSplit.d.ts.map +1 -0
- package/package.json +37 -7
- package/dist/shared/__tests__/example.test.d.ts +0 -6
- package/dist/shared/__tests__/example.test.d.ts.map +0 -1
- package/dist/tbv/core/__tests__/example.test.d.ts +0 -6
- package/dist/tbv/core/__tests__/example.test.d.ts.map +0 -1
- package/dist/tbv/integrations/morpho/index.cjs +0 -2
- package/dist/tbv/integrations/morpho/index.d.ts +0 -2
- package/dist/tbv/integrations/morpho/index.d.ts.map +0 -1
- package/dist/tbv/integrations/morpho/index.js +0 -2
- /package/dist/tbv/{integrations/morpho → core/primitives}/index.cjs.map +0 -0
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -3,18 +3,28 @@
|
|
|
3
3
|
[](https://github.com/babylonlabs-io/babylon-toolkit/actions/workflows/verify.yml)
|
|
4
4
|
[](https://www.npmjs.com/package/@babylonlabs-io/ts-sdk)
|
|
5
5
|
|
|
6
|
-
TypeScript SDK for
|
|
6
|
+
TypeScript SDK for Trustless Bitcoin Vaults
|
|
7
7
|
|
|
8
8
|
> **⚠️ Status**: Currently under active development.
|
|
9
9
|
|
|
10
10
|
## Overview
|
|
11
11
|
|
|
12
|
-
The Babylon TypeScript SDK
|
|
12
|
+
The Babylon TypeScript SDK is a production-ready toolkit for integrating Trustless Bitcoin Vaults into your applications. Currently provides comprehensive support for Trustless Bitcoin Vaults (TBV) including vault management and supported application integrations.
|
|
13
|
+
|
|
14
|
+
## What Are Trustless Bitcoin Vaults?
|
|
15
|
+
|
|
16
|
+
Trustless Bitcoin Vaults (TBV) let you lock Bitcoin and use it in applications on supported chains (like lending protocols) without giving up custody. The vault protocol enables:
|
|
17
|
+
|
|
18
|
+
- **Peg-in**: Lock BTC in a vault on Bitcoin to use as collateral ([protocol spec](https://github.com/babylonlabs-io/btc-vault/blob/main/docs/pegin.md))
|
|
19
|
+
- **Peg-out**: Unlock BTC from the vault back to your wallet ([protocol spec](https://github.com/babylonlabs-io/btc-vault/blob/main/docs/pegout.md))
|
|
20
|
+
- **DeFi Integration**: Use vaulted BTC in protocols like Aave
|
|
21
|
+
|
|
22
|
+
This SDK handles the complex Bitcoin and Ethereum interactions needed to create and manage these vaults.
|
|
13
23
|
|
|
14
24
|
### Key Features
|
|
15
25
|
|
|
16
|
-
- **🔐
|
|
17
|
-
-
|
|
26
|
+
- **🔐 Vault Management** - Vault creation (Pegin), vault redemption (Pegout), and vault lifecycle operations
|
|
27
|
+
- **🔌 Application Integrations** - Pre-built integrations starting with Aave (DeFi lending)
|
|
18
28
|
- **📦 Framework Agnostic** - Works with React, Vue, Angular, Node.js, or vanilla JavaScript
|
|
19
29
|
- **🎯 Type-Safe** - Comprehensive TypeScript types with full IDE support
|
|
20
30
|
- **🧩 Modular Design** - Use only what you need via subpath exports
|
|
@@ -22,12 +32,120 @@ The Babylon TypeScript SDK provides a production-ready, framework-agnostic toolk
|
|
|
22
32
|
|
|
23
33
|
## Installation
|
|
24
34
|
|
|
35
|
+
### Requirements
|
|
36
|
+
|
|
37
|
+
- Node.js >= 24.0.0
|
|
38
|
+
- Package manager: npm, yarn, or pnpm
|
|
39
|
+
|
|
40
|
+
### Install
|
|
41
|
+
|
|
25
42
|
```bash
|
|
26
|
-
npm
|
|
43
|
+
# npm
|
|
44
|
+
npm install @babylonlabs-io/ts-sdk viem
|
|
45
|
+
|
|
46
|
+
# yarn
|
|
47
|
+
yarn add @babylonlabs-io/ts-sdk viem
|
|
48
|
+
|
|
49
|
+
# pnpm
|
|
50
|
+
pnpm add @babylonlabs-io/ts-sdk viem
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Verify Installation
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
import { buildPeginPsbt } from "@babylonlabs-io/ts-sdk/tbv/core/primitives";
|
|
57
|
+
|
|
58
|
+
console.log("✅ SDK installed successfully!");
|
|
59
|
+
console.log("buildPeginPsbt type:", typeof buildPeginPsbt);
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
Run with: `npx tsx verify-install.ts`
|
|
63
|
+
|
|
64
|
+
> **Troubleshooting?** See [Troubleshooting Guide](./docs/get-started/troubleshooting.md) for Buffer polyfills, WASM setup, and bundler configuration.
|
|
65
|
+
|
|
66
|
+
## Package Structure
|
|
67
|
+
|
|
68
|
+
The SDK uses subpath exports for tree-shaking:
|
|
69
|
+
|
|
70
|
+
```typescript
|
|
71
|
+
// High-level managers (recommended for most users)
|
|
72
|
+
import { PeginManager, PayoutManager } from "@babylonlabs-io/ts-sdk/tbv/core";
|
|
73
|
+
|
|
74
|
+
// Low-level primitives (advanced use cases)
|
|
75
|
+
import {
|
|
76
|
+
buildPeginPsbt,
|
|
77
|
+
buildPayoutPsbt,
|
|
78
|
+
buildDepositorPayoutPsbt,
|
|
79
|
+
buildNoPayoutPsbt,
|
|
80
|
+
buildChallengeAssertPsbt,
|
|
81
|
+
} from "@babylonlabs-io/ts-sdk/tbv/core/primitives";
|
|
82
|
+
|
|
83
|
+
// Utilities
|
|
84
|
+
import { selectUtxosForPegin } from "@babylonlabs-io/ts-sdk/tbv/core";
|
|
85
|
+
|
|
86
|
+
// Shared types and wallet interfaces
|
|
87
|
+
import { BitcoinWallet, UTXO } from "@babylonlabs-io/ts-sdk/shared";
|
|
88
|
+
|
|
89
|
+
// Contract ABIs
|
|
90
|
+
import { BTCVaultsManagerABI } from "@babylonlabs-io/ts-sdk/tbv/core";
|
|
91
|
+
|
|
92
|
+
// Protocol integrations (Aave)
|
|
93
|
+
import {
|
|
94
|
+
buildAddCollateralTx,
|
|
95
|
+
buildBorrowTx,
|
|
96
|
+
getUserAccountData,
|
|
97
|
+
calculateHealthFactor,
|
|
98
|
+
} from "@babylonlabs-io/ts-sdk/tbv/integrations/aave";
|
|
27
99
|
```
|
|
28
100
|
|
|
101
|
+
## Choose Your API Level
|
|
102
|
+
|
|
103
|
+
The SDK provides two integration approaches:
|
|
104
|
+
|
|
105
|
+
### Managers (High-Level)
|
|
106
|
+
|
|
107
|
+
- **What**: Pre-built wallet orchestration for complete vault workflows
|
|
108
|
+
- **Best for**: Web apps, browser wallets (MetaMask, Unisat)
|
|
109
|
+
- **You provide**: Wallet interface
|
|
110
|
+
- **SDK handles**: Transaction building, signing coordination, contract calls
|
|
111
|
+
|
|
112
|
+
### Primitives (Low-Level, Advanced)
|
|
113
|
+
|
|
114
|
+
- **What**: Pure functions for building Bitcoin PSBTs
|
|
115
|
+
- **Best for**: Backend services, custom signing (KMS/HSM), full control
|
|
116
|
+
- **You provide**: Everything (signing logic, contract calls, broadcasting)
|
|
117
|
+
- **SDK handles**: Only PSBT construction and utility functions
|
|
118
|
+
|
|
119
|
+
## Trustless Bitcoin Vaults (TBV) Documentation
|
|
120
|
+
|
|
121
|
+
### 🚀 Quickstart
|
|
122
|
+
|
|
123
|
+
Step-by-step tutorials:
|
|
124
|
+
|
|
125
|
+
- **[Managers Quickstart](./docs/quickstart/managers.md)** - Create a Bitcoin vault with wallet integration (step-by-step)
|
|
126
|
+
- **[Primitives Quickstart](./docs/quickstart/primitives.md)** - Build vault PSBTs with custom signing logic (advanced)
|
|
127
|
+
|
|
128
|
+
### 🔌 Application Integrations
|
|
129
|
+
|
|
130
|
+
Use BTC vaults in DeFi protocols and applications:
|
|
131
|
+
|
|
132
|
+
- **Aave v4** - Use vaults as collateral to borrow assets
|
|
133
|
+
- [Overview & API Reference](./docs/integrations/aave/README.md)
|
|
134
|
+
- [Quickstart Guide](./docs/integrations/aave/quickstart.md)
|
|
135
|
+
|
|
136
|
+
### 🔍 API Reference
|
|
137
|
+
|
|
138
|
+
Auto-generated from TSDoc comments using [TypeDoc](https://typedoc.org/):
|
|
139
|
+
|
|
140
|
+
- **[API Reference](./docs/api/README.md)** - Complete auto-generated API documentation
|
|
141
|
+
|
|
142
|
+
### 🛠️ Troubleshooting
|
|
143
|
+
|
|
144
|
+
- **[Troubleshooting Guide](./docs/get-started/troubleshooting.md)** - Common issues and solutions
|
|
145
|
+
|
|
29
146
|
## Links
|
|
30
147
|
|
|
31
148
|
- [GitHub Repository](https://github.com/babylonlabs-io/babylon-toolkit)
|
|
32
|
-
- [
|
|
149
|
+
- [Report an Issue](https://github.com/babylonlabs-io/babylon-toolkit/issues)
|
|
33
150
|
- [NPM Package](https://www.npmjs.com/package/@babylonlabs-io/ts-sdk)
|
|
151
|
+
- [Contributing Guide](./CONTRIBUTING.md)
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var q=Object.defineProperty;var h=(n,i,s)=>i in n?q(n,i,{enumerable:!0,configurable:!0,writable:!0,value:s}):n[i]=s;var t=(n,i,s)=>h(n,typeof i!="symbol"?i+"":i,s);const o=require("buffer"),c={SIGNET:"signet"};class d{constructor(i={}){t(this,"config");this.config={publicKeyHex:i.publicKeyHex||"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2",address:i.address||"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks",network:i.network??c.SIGNET,shouldFailSigning:i.shouldFailSigning??!1}}async getPublicKeyHex(){return this.config.publicKeyHex}async getAddress(){return this.config.address}async signPsbt(i){if(this.config.shouldFailSigning)throw new Error("Mock signing failed");if(!i||i.length===0)throw new Error("Invalid PSBT: empty hex string");return i+"deadbeef"}async signPsbts(i){const s=[];for(const a of i){const e=await this.signPsbt(a);s.push(e)}return s}async signMessage(i,s){if(this.config.shouldFailSigning)throw new Error("Mock signing failed");if(!i||i.length===0)throw new Error("Invalid message: empty string");return o.Buffer.from(`mock-signature-${s}-${i}-${this.config.publicKeyHex}`).toString("base64")}async getNetwork(){return this.config.network}updateConfig(i){this.config={...this.config,...i}}reset(){this.config={publicKeyHex:"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2",address:"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks",network:c.SIGNET,shouldFailSigning:!1}}}class l{constructor(i={}){t(this,"account");t(this,"chain");t(this,"shouldFailOperations");t(this,"transactionDelay");t(this,"nonce",0);this.account={address:i.address||"0x742d35cc6634c0532925a3b844bc9e7595f0beb0"},this.chain={id:i.chainId??11155111},this.shouldFailOperations=i.shouldFailOperations??!1,this.transactionDelay=i.transactionDelay??0,this.signMessage=this.signMessage.bind(this),this.sendTransaction=this.sendTransaction.bind(this)}async signMessage(i){const s=i.message,a=i.account||this.account.address;if(this.shouldFailOperations)throw new Error("Mock signing failed");if(!s||s.length===0)throw new Error("Invalid message: empty string");const e=`personal_sign:${s}-${a}-${this.chain.id}`;return`0x${o.Buffer.from(e).toString("hex").slice(0,130).padEnd(130,"0")}`}async sendTransaction(i){var e;if(this.shouldFailOperations)throw new Error("Mock transaction failed");if(!i.to)throw new Error("Invalid transaction: missing 'to' address");this.transactionDelay>0&&await new Promise(r=>setTimeout(r,this.transactionDelay)),this.nonce++;const s=JSON.stringify({from:this.account.address,to:i.to,value:((e=i.value)==null?void 0:e.toString())||"0",nonce:this.nonce,chainId:this.chain.id});return`0x${o.Buffer.from(s).toString("hex").slice(0,64).padEnd(64,"0")}`}updateConfig(i){i.address!==void 0&&(this.account.address=i.address),i.chainId!==void 0&&(this.chain.id=i.chainId),i.shouldFailOperations!==void 0&&(this.shouldFailOperations=i.shouldFailOperations),i.transactionDelay!==void 0&&(this.transactionDelay=i.transactionDelay)}reset(){this.account.address="0x742d35cc6634c0532925a3b844bc9e7595f0beb0",this.chain.id=11155111,this.shouldFailOperations=!1,this.transactionDelay=0,this.nonce=0}getCurrentNonce(){return this.nonce}}exports.MockBitcoinWallet=d;exports.MockEthereumWallet=l;
|
|
2
|
+
//# sourceMappingURL=MockEthereumWallet-CKQlH2AM.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MockEthereumWallet-CKQlH2AM.cjs","sources":["../src/shared/wallets/interfaces/BitcoinWallet.ts","../src/shared/wallets/mocks/MockBitcoinWallet.ts","../src/shared/wallets/mocks/MockEthereumWallet.ts"],"sourcesContent":["/**\n * Bitcoin network types.\n * Using string literal union for maximum compatibility with wallet providers.\n */\nexport type BitcoinNetwork = \"mainnet\" | \"testnet\" | \"signet\";\n\n/**\n * Bitcoin network constants\n */\nexport const BitcoinNetworks = {\n MAINNET: \"mainnet\",\n TESTNET: \"testnet\",\n SIGNET: \"signet\",\n} as const;\n\n/**\n * Options for signing a specific input in a PSBT.\n */\nexport interface SignInputOptions {\n /** Input index to sign */\n index: number;\n /** Address for signing (optional) */\n address?: string;\n /** Public key for signing (optional, hex string) */\n publicKey?: string;\n /** Sighash types (optional) */\n sighashTypes?: number[];\n /** Disable tweak signer for Taproot script path spend (optional) */\n disableTweakSigner?: boolean;\n}\n\n/**\n * SignPsbt options for advanced signing scenarios.\n */\nexport interface SignPsbtOptions {\n /** Whether to automatically finalize the PSBT after signing */\n autoFinalized?: boolean;\n /**\n * Specific inputs to sign.\n * If not provided, wallet will attempt to sign all inputs it can.\n * Use this to restrict signing to specific inputs (e.g., only depositor's input).\n */\n signInputs?: SignInputOptions[];\n /** Contract information for the signing operation. */\n contracts?: Array<{\n /** Contract identifier. */\n id: string;\n /** Contract parameters. */\n params: Record<string, string | number | string[] | number[]>;\n }>;\n /** Action metadata. */\n action?: {\n /** Action name for tracking. */\n name: string;\n };\n}\n\n/**\n * This interface is designed to be compatible with @babylonlabs-io/wallet-connector's IBTCProvider\n *\n * Supports Unisat, Ledger, OKX, OneKey, Keystone, and other Bitcoin wallets.\n */\nexport interface BitcoinWallet {\n /**\n * Returns the wallet's public key as a hex string.\n *\n * For Taproot addresses, this should return the x-only public key\n * (32 bytes = 64 hex characters without 0x prefix).\n *\n * For compressed public keys (33 bytes = 66 hex characters),\n * consumers should strip the first byte to get x-only format.\n */\n getPublicKeyHex(): Promise<string>;\n\n /**\n * Returns the wallet's Bitcoin address.\n */\n getAddress(): Promise<string>;\n\n /**\n * Signs a PSBT and returns the signed PSBT as hex.\n *\n * @param psbtHex - The PSBT to sign in hex format\n * @param options - Optional signing parameters (e.g., autoFinalized, contracts)\n * @throws {Error} If the PSBT is invalid or signing fails\n */\n signPsbt(psbtHex: string, options?: SignPsbtOptions): Promise<string>;\n\n /**\n * Signs multiple PSBTs and returns the signed PSBTs as hex.\n * This allows batch signing with a single wallet interaction.\n *\n * @param psbtsHexes - Array of PSBTs to sign in hex format\n * @param options - Optional array of signing parameters for each PSBT\n * @throws {Error} If any PSBT is invalid or signing fails\n */\n signPsbts(\n psbtsHexes: string[],\n options?: SignPsbtOptions[],\n ): Promise<string[]>;\n\n /**\n * Signs a message for authentication or proof of ownership.\n *\n * @param message - The message to sign\n * @param type - The signing method: \"ecdsa\" for standard signatures, \"bip322-simple\" for BIP-322\n * @returns Base64-encoded signature\n */\n signMessage(\n message: string,\n type: \"bip322-simple\" | \"ecdsa\",\n ): Promise<string>;\n\n /**\n * Returns the Bitcoin network the wallet is connected to.\n *\n * @returns BitcoinNetwork enum value (MAINNET, TESTNET, SIGNET)\n */\n getNetwork(): Promise<BitcoinNetwork>;\n}\n","import { Buffer } from \"buffer\";\n\nimport { BitcoinNetworks, type BitcoinNetwork } from \"../interfaces\";\nimport type { BitcoinWallet } from \"../interfaces/BitcoinWallet\";\n\n/**\n * Configuration for MockBitcoinWallet.\n */\nexport interface MockBitcoinWalletConfig {\n publicKeyHex?: string;\n address?: string;\n network?: BitcoinNetwork;\n shouldFailSigning?: boolean;\n}\n\n/**\n * Mock Bitcoin wallet for testing.\n */\nexport class MockBitcoinWallet implements BitcoinWallet {\n private config: Required<MockBitcoinWalletConfig>;\n\n constructor(config: MockBitcoinWalletConfig = {}) {\n this.config = {\n publicKeyHex:\n config.publicKeyHex ||\n \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2\",\n address:\n config.address ||\n \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: config.network ?? BitcoinNetworks.SIGNET,\n shouldFailSigning: config.shouldFailSigning ?? false,\n };\n }\n\n async getPublicKeyHex(): Promise<string> {\n return this.config.publicKeyHex;\n }\n\n async getAddress(): Promise<string> {\n return this.config.address;\n }\n\n async signPsbt(psbtHex: string): Promise<string> {\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!psbtHex || psbtHex.length === 0) {\n throw new Error(\"Invalid PSBT: empty hex string\");\n }\n\n // In a real implementation, this would actually sign the PSBT\n // For the mock, we just return the input with a mock signature appended\n return psbtHex + \"deadbeef\";\n }\n\n async signPsbts(psbtsHexes: string[]): Promise<string[]> {\n const signedPsbts: string[] = [];\n for (const psbtHex of psbtsHexes) {\n const signedPsbt = await this.signPsbt(psbtHex);\n signedPsbts.push(signedPsbt);\n }\n return signedPsbts;\n }\n\n async signMessage(\n message: string,\n type: \"bip322-simple\" | \"ecdsa\",\n ): Promise<string> {\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // In a real implementation, this would create a proper signature\n // For the mock, we return a base64-like mock signature\n const mockSignature = Buffer.from(\n `mock-signature-${type}-${message}-${this.config.publicKeyHex}`,\n ).toString(\"base64\");\n return mockSignature;\n }\n\n async getNetwork(): Promise<BitcoinNetwork> {\n return this.config.network;\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockBitcoinWalletConfig>): void {\n this.config = {\n ...this.config,\n ...updates,\n };\n }\n\n /** Resets to default configuration. */\n reset(): void {\n this.config = {\n publicKeyHex:\n \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2\",\n address: \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: BitcoinNetworks.SIGNET,\n shouldFailSigning: false,\n };\n }\n}\n","import { Buffer } from \"buffer\";\nimport type { Address, Hex } from \"viem\";\n\n/**\n * Configuration for MockEthereumWallet.\n */\nexport interface MockEthereumWalletConfig {\n address?: Address;\n chainId?: number;\n shouldFailOperations?: boolean;\n transactionDelay?: number;\n}\n\n/**\n * Mock Ethereum wallet for testing.\n *\n * Provides the subset of viem's WalletClient methods used by the SDK.\n * Can be passed to functions expecting a WalletClient for testing purposes.\n */\nexport class MockEthereumWallet {\n // Public properties matching viem's WalletClient structure\n account: { address: Address };\n chain: { id: number };\n\n private shouldFailOperations: boolean;\n private transactionDelay: number;\n private nonce: number = 0;\n\n constructor(config: MockEthereumWalletConfig = {}) {\n // Use lowercase addresses to avoid EIP-55 checksum validation issues\n this.account = {\n address:\n config.address ||\n (\"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address),\n };\n\n this.chain = {\n id: config.chainId ?? 11155111, // Sepolia by default\n };\n\n this.shouldFailOperations = config.shouldFailOperations ?? false;\n this.transactionDelay = config.transactionDelay ?? 0;\n\n // Bind methods to preserve 'this' context when called\n this.signMessage = this.signMessage.bind(this);\n this.sendTransaction = this.sendTransaction.bind(this);\n }\n\n async signMessage(args: { message: string; account?: Address }): Promise<Hex> {\n const message = args.message;\n const account = args.account || this.account.address;\n\n if (this.shouldFailOperations) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // Generate a deterministic mock signature\n const signatureData = `personal_sign:${message}-${account}-${this.chain.id}`;\n const signature = `0x${Buffer.from(signatureData)\n .toString(\"hex\")\n .slice(0, 130)\n .padEnd(130, \"0\")}` as Hex;\n return signature;\n }\n\n async sendTransaction(tx: {\n to: Address;\n data?: Hex;\n value?: bigint;\n gas?: bigint;\n account?: { address: Address };\n chain?: { id: number };\n }): Promise<Hex> {\n if (this.shouldFailOperations) {\n throw new Error(\"Mock transaction failed\");\n }\n\n if (!tx.to) {\n throw new Error(\"Invalid transaction: missing 'to' address\");\n }\n\n // Simulate network delay if configured\n if (this.transactionDelay > 0) {\n await new Promise((resolve) =>\n setTimeout(resolve, this.transactionDelay),\n );\n }\n\n // Generate a deterministic mock transaction hash\n this.nonce++;\n const txData = JSON.stringify({\n from: this.account.address,\n to: tx.to,\n value: tx.value?.toString() || \"0\",\n nonce: this.nonce,\n chainId: this.chain.id,\n });\n\n const hash = `0x${Buffer.from(txData)\n .toString(\"hex\")\n .slice(0, 64)\n .padEnd(64, \"0\")}` as Hex;\n return hash;\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockEthereumWalletConfig>): void {\n if (updates.address !== undefined) {\n this.account.address = updates.address;\n }\n if (updates.chainId !== undefined) {\n this.chain.id = updates.chainId;\n }\n if (updates.shouldFailOperations !== undefined) {\n this.shouldFailOperations = updates.shouldFailOperations;\n }\n if (updates.transactionDelay !== undefined) {\n this.transactionDelay = updates.transactionDelay;\n }\n }\n\n /** Resets to default configuration and nonce. */\n reset(): void {\n this.account.address =\n \"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address;\n this.chain.id = 11155111;\n this.shouldFailOperations = false;\n this.transactionDelay = 0;\n this.nonce = 0;\n }\n\n /** Returns current nonce for testing. */\n getCurrentNonce(): number {\n return this.nonce;\n }\n}\n"],"names":["BitcoinNetworks","MockBitcoinWallet","config","__publicField","psbtHex","psbtsHexes","signedPsbts","signedPsbt","message","type","Buffer","updates","MockEthereumWallet","args","account","signatureData","tx","resolve","txData","_a"],"mappings":"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"}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
var q = Object.defineProperty;
|
|
2
|
+
var h = (n, i, s) => i in n ? q(n, i, { enumerable: !0, configurable: !0, writable: !0, value: s }) : n[i] = s;
|
|
3
|
+
var t = (n, i, s) => h(n, typeof i != "symbol" ? i + "" : i, s);
|
|
4
|
+
import { Buffer as o } from "buffer";
|
|
5
|
+
const c = {
|
|
6
|
+
SIGNET: "signet"
|
|
7
|
+
};
|
|
8
|
+
class g {
|
|
9
|
+
constructor(i = {}) {
|
|
10
|
+
t(this, "config");
|
|
11
|
+
this.config = {
|
|
12
|
+
publicKeyHex: i.publicKeyHex || "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2",
|
|
13
|
+
address: i.address || "tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks",
|
|
14
|
+
network: i.network ?? c.SIGNET,
|
|
15
|
+
shouldFailSigning: i.shouldFailSigning ?? !1
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
async getPublicKeyHex() {
|
|
19
|
+
return this.config.publicKeyHex;
|
|
20
|
+
}
|
|
21
|
+
async getAddress() {
|
|
22
|
+
return this.config.address;
|
|
23
|
+
}
|
|
24
|
+
async signPsbt(i) {
|
|
25
|
+
if (this.config.shouldFailSigning)
|
|
26
|
+
throw new Error("Mock signing failed");
|
|
27
|
+
if (!i || i.length === 0)
|
|
28
|
+
throw new Error("Invalid PSBT: empty hex string");
|
|
29
|
+
return i + "deadbeef";
|
|
30
|
+
}
|
|
31
|
+
async signPsbts(i) {
|
|
32
|
+
const s = [];
|
|
33
|
+
for (const e of i) {
|
|
34
|
+
const a = await this.signPsbt(e);
|
|
35
|
+
s.push(a);
|
|
36
|
+
}
|
|
37
|
+
return s;
|
|
38
|
+
}
|
|
39
|
+
async signMessage(i, s) {
|
|
40
|
+
if (this.config.shouldFailSigning)
|
|
41
|
+
throw new Error("Mock signing failed");
|
|
42
|
+
if (!i || i.length === 0)
|
|
43
|
+
throw new Error("Invalid message: empty string");
|
|
44
|
+
return o.from(
|
|
45
|
+
`mock-signature-${s}-${i}-${this.config.publicKeyHex}`
|
|
46
|
+
).toString("base64");
|
|
47
|
+
}
|
|
48
|
+
async getNetwork() {
|
|
49
|
+
return this.config.network;
|
|
50
|
+
}
|
|
51
|
+
/** Updates configuration for testing different scenarios. */
|
|
52
|
+
updateConfig(i) {
|
|
53
|
+
this.config = {
|
|
54
|
+
...this.config,
|
|
55
|
+
...i
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Resets to default configuration. */
|
|
59
|
+
reset() {
|
|
60
|
+
this.config = {
|
|
61
|
+
publicKeyHex: "a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2",
|
|
62
|
+
address: "tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks",
|
|
63
|
+
network: c.SIGNET,
|
|
64
|
+
shouldFailSigning: !1
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
class f {
|
|
69
|
+
constructor(i = {}) {
|
|
70
|
+
// Public properties matching viem's WalletClient structure
|
|
71
|
+
t(this, "account");
|
|
72
|
+
t(this, "chain");
|
|
73
|
+
t(this, "shouldFailOperations");
|
|
74
|
+
t(this, "transactionDelay");
|
|
75
|
+
t(this, "nonce", 0);
|
|
76
|
+
this.account = {
|
|
77
|
+
address: i.address || "0x742d35cc6634c0532925a3b844bc9e7595f0beb0"
|
|
78
|
+
}, this.chain = {
|
|
79
|
+
id: i.chainId ?? 11155111
|
|
80
|
+
// Sepolia by default
|
|
81
|
+
}, this.shouldFailOperations = i.shouldFailOperations ?? !1, this.transactionDelay = i.transactionDelay ?? 0, this.signMessage = this.signMessage.bind(this), this.sendTransaction = this.sendTransaction.bind(this);
|
|
82
|
+
}
|
|
83
|
+
async signMessage(i) {
|
|
84
|
+
const s = i.message, e = i.account || this.account.address;
|
|
85
|
+
if (this.shouldFailOperations)
|
|
86
|
+
throw new Error("Mock signing failed");
|
|
87
|
+
if (!s || s.length === 0)
|
|
88
|
+
throw new Error("Invalid message: empty string");
|
|
89
|
+
const a = `personal_sign:${s}-${e}-${this.chain.id}`;
|
|
90
|
+
return `0x${o.from(a).toString("hex").slice(0, 130).padEnd(130, "0")}`;
|
|
91
|
+
}
|
|
92
|
+
async sendTransaction(i) {
|
|
93
|
+
var a;
|
|
94
|
+
if (this.shouldFailOperations)
|
|
95
|
+
throw new Error("Mock transaction failed");
|
|
96
|
+
if (!i.to)
|
|
97
|
+
throw new Error("Invalid transaction: missing 'to' address");
|
|
98
|
+
this.transactionDelay > 0 && await new Promise(
|
|
99
|
+
(r) => setTimeout(r, this.transactionDelay)
|
|
100
|
+
), this.nonce++;
|
|
101
|
+
const s = JSON.stringify({
|
|
102
|
+
from: this.account.address,
|
|
103
|
+
to: i.to,
|
|
104
|
+
value: ((a = i.value) == null ? void 0 : a.toString()) || "0",
|
|
105
|
+
nonce: this.nonce,
|
|
106
|
+
chainId: this.chain.id
|
|
107
|
+
});
|
|
108
|
+
return `0x${o.from(s).toString("hex").slice(0, 64).padEnd(64, "0")}`;
|
|
109
|
+
}
|
|
110
|
+
/** Updates configuration for testing different scenarios. */
|
|
111
|
+
updateConfig(i) {
|
|
112
|
+
i.address !== void 0 && (this.account.address = i.address), i.chainId !== void 0 && (this.chain.id = i.chainId), i.shouldFailOperations !== void 0 && (this.shouldFailOperations = i.shouldFailOperations), i.transactionDelay !== void 0 && (this.transactionDelay = i.transactionDelay);
|
|
113
|
+
}
|
|
114
|
+
/** Resets to default configuration and nonce. */
|
|
115
|
+
reset() {
|
|
116
|
+
this.account.address = "0x742d35cc6634c0532925a3b844bc9e7595f0beb0", this.chain.id = 11155111, this.shouldFailOperations = !1, this.transactionDelay = 0, this.nonce = 0;
|
|
117
|
+
}
|
|
118
|
+
/** Returns current nonce for testing. */
|
|
119
|
+
getCurrentNonce() {
|
|
120
|
+
return this.nonce;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
export {
|
|
124
|
+
g as M,
|
|
125
|
+
f as a
|
|
126
|
+
};
|
|
127
|
+
//# sourceMappingURL=MockEthereumWallet-ibdry7pZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MockEthereumWallet-ibdry7pZ.js","sources":["../src/shared/wallets/interfaces/BitcoinWallet.ts","../src/shared/wallets/mocks/MockBitcoinWallet.ts","../src/shared/wallets/mocks/MockEthereumWallet.ts"],"sourcesContent":["/**\n * Bitcoin network types.\n * Using string literal union for maximum compatibility with wallet providers.\n */\nexport type BitcoinNetwork = \"mainnet\" | \"testnet\" | \"signet\";\n\n/**\n * Bitcoin network constants\n */\nexport const BitcoinNetworks = {\n MAINNET: \"mainnet\",\n TESTNET: \"testnet\",\n SIGNET: \"signet\",\n} as const;\n\n/**\n * Options for signing a specific input in a PSBT.\n */\nexport interface SignInputOptions {\n /** Input index to sign */\n index: number;\n /** Address for signing (optional) */\n address?: string;\n /** Public key for signing (optional, hex string) */\n publicKey?: string;\n /** Sighash types (optional) */\n sighashTypes?: number[];\n /** Disable tweak signer for Taproot script path spend (optional) */\n disableTweakSigner?: boolean;\n}\n\n/**\n * SignPsbt options for advanced signing scenarios.\n */\nexport interface SignPsbtOptions {\n /** Whether to automatically finalize the PSBT after signing */\n autoFinalized?: boolean;\n /**\n * Specific inputs to sign.\n * If not provided, wallet will attempt to sign all inputs it can.\n * Use this to restrict signing to specific inputs (e.g., only depositor's input).\n */\n signInputs?: SignInputOptions[];\n /** Contract information for the signing operation. */\n contracts?: Array<{\n /** Contract identifier. */\n id: string;\n /** Contract parameters. */\n params: Record<string, string | number | string[] | number[]>;\n }>;\n /** Action metadata. */\n action?: {\n /** Action name for tracking. */\n name: string;\n };\n}\n\n/**\n * This interface is designed to be compatible with @babylonlabs-io/wallet-connector's IBTCProvider\n *\n * Supports Unisat, Ledger, OKX, OneKey, Keystone, and other Bitcoin wallets.\n */\nexport interface BitcoinWallet {\n /**\n * Returns the wallet's public key as a hex string.\n *\n * For Taproot addresses, this should return the x-only public key\n * (32 bytes = 64 hex characters without 0x prefix).\n *\n * For compressed public keys (33 bytes = 66 hex characters),\n * consumers should strip the first byte to get x-only format.\n */\n getPublicKeyHex(): Promise<string>;\n\n /**\n * Returns the wallet's Bitcoin address.\n */\n getAddress(): Promise<string>;\n\n /**\n * Signs a PSBT and returns the signed PSBT as hex.\n *\n * @param psbtHex - The PSBT to sign in hex format\n * @param options - Optional signing parameters (e.g., autoFinalized, contracts)\n * @throws {Error} If the PSBT is invalid or signing fails\n */\n signPsbt(psbtHex: string, options?: SignPsbtOptions): Promise<string>;\n\n /**\n * Signs multiple PSBTs and returns the signed PSBTs as hex.\n * This allows batch signing with a single wallet interaction.\n *\n * @param psbtsHexes - Array of PSBTs to sign in hex format\n * @param options - Optional array of signing parameters for each PSBT\n * @throws {Error} If any PSBT is invalid or signing fails\n */\n signPsbts(\n psbtsHexes: string[],\n options?: SignPsbtOptions[],\n ): Promise<string[]>;\n\n /**\n * Signs a message for authentication or proof of ownership.\n *\n * @param message - The message to sign\n * @param type - The signing method: \"ecdsa\" for standard signatures, \"bip322-simple\" for BIP-322\n * @returns Base64-encoded signature\n */\n signMessage(\n message: string,\n type: \"bip322-simple\" | \"ecdsa\",\n ): Promise<string>;\n\n /**\n * Returns the Bitcoin network the wallet is connected to.\n *\n * @returns BitcoinNetwork enum value (MAINNET, TESTNET, SIGNET)\n */\n getNetwork(): Promise<BitcoinNetwork>;\n}\n","import { Buffer } from \"buffer\";\n\nimport { BitcoinNetworks, type BitcoinNetwork } from \"../interfaces\";\nimport type { BitcoinWallet } from \"../interfaces/BitcoinWallet\";\n\n/**\n * Configuration for MockBitcoinWallet.\n */\nexport interface MockBitcoinWalletConfig {\n publicKeyHex?: string;\n address?: string;\n network?: BitcoinNetwork;\n shouldFailSigning?: boolean;\n}\n\n/**\n * Mock Bitcoin wallet for testing.\n */\nexport class MockBitcoinWallet implements BitcoinWallet {\n private config: Required<MockBitcoinWalletConfig>;\n\n constructor(config: MockBitcoinWalletConfig = {}) {\n this.config = {\n publicKeyHex:\n config.publicKeyHex ||\n \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2\",\n address:\n config.address ||\n \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: config.network ?? BitcoinNetworks.SIGNET,\n shouldFailSigning: config.shouldFailSigning ?? false,\n };\n }\n\n async getPublicKeyHex(): Promise<string> {\n return this.config.publicKeyHex;\n }\n\n async getAddress(): Promise<string> {\n return this.config.address;\n }\n\n async signPsbt(psbtHex: string): Promise<string> {\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!psbtHex || psbtHex.length === 0) {\n throw new Error(\"Invalid PSBT: empty hex string\");\n }\n\n // In a real implementation, this would actually sign the PSBT\n // For the mock, we just return the input with a mock signature appended\n return psbtHex + \"deadbeef\";\n }\n\n async signPsbts(psbtsHexes: string[]): Promise<string[]> {\n const signedPsbts: string[] = [];\n for (const psbtHex of psbtsHexes) {\n const signedPsbt = await this.signPsbt(psbtHex);\n signedPsbts.push(signedPsbt);\n }\n return signedPsbts;\n }\n\n async signMessage(\n message: string,\n type: \"bip322-simple\" | \"ecdsa\",\n ): Promise<string> {\n if (this.config.shouldFailSigning) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // In a real implementation, this would create a proper signature\n // For the mock, we return a base64-like mock signature\n const mockSignature = Buffer.from(\n `mock-signature-${type}-${message}-${this.config.publicKeyHex}`,\n ).toString(\"base64\");\n return mockSignature;\n }\n\n async getNetwork(): Promise<BitcoinNetwork> {\n return this.config.network;\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockBitcoinWalletConfig>): void {\n this.config = {\n ...this.config,\n ...updates,\n };\n }\n\n /** Resets to default configuration. */\n reset(): void {\n this.config = {\n publicKeyHex:\n \"a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0c1d2e3f4a5b6c7d8e9f0a1b2\",\n address: \"tb1pqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqkx6jks\",\n network: BitcoinNetworks.SIGNET,\n shouldFailSigning: false,\n };\n }\n}\n","import { Buffer } from \"buffer\";\nimport type { Address, Hex } from \"viem\";\n\n/**\n * Configuration for MockEthereumWallet.\n */\nexport interface MockEthereumWalletConfig {\n address?: Address;\n chainId?: number;\n shouldFailOperations?: boolean;\n transactionDelay?: number;\n}\n\n/**\n * Mock Ethereum wallet for testing.\n *\n * Provides the subset of viem's WalletClient methods used by the SDK.\n * Can be passed to functions expecting a WalletClient for testing purposes.\n */\nexport class MockEthereumWallet {\n // Public properties matching viem's WalletClient structure\n account: { address: Address };\n chain: { id: number };\n\n private shouldFailOperations: boolean;\n private transactionDelay: number;\n private nonce: number = 0;\n\n constructor(config: MockEthereumWalletConfig = {}) {\n // Use lowercase addresses to avoid EIP-55 checksum validation issues\n this.account = {\n address:\n config.address ||\n (\"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address),\n };\n\n this.chain = {\n id: config.chainId ?? 11155111, // Sepolia by default\n };\n\n this.shouldFailOperations = config.shouldFailOperations ?? false;\n this.transactionDelay = config.transactionDelay ?? 0;\n\n // Bind methods to preserve 'this' context when called\n this.signMessage = this.signMessage.bind(this);\n this.sendTransaction = this.sendTransaction.bind(this);\n }\n\n async signMessage(args: { message: string; account?: Address }): Promise<Hex> {\n const message = args.message;\n const account = args.account || this.account.address;\n\n if (this.shouldFailOperations) {\n throw new Error(\"Mock signing failed\");\n }\n\n if (!message || message.length === 0) {\n throw new Error(\"Invalid message: empty string\");\n }\n\n // Generate a deterministic mock signature\n const signatureData = `personal_sign:${message}-${account}-${this.chain.id}`;\n const signature = `0x${Buffer.from(signatureData)\n .toString(\"hex\")\n .slice(0, 130)\n .padEnd(130, \"0\")}` as Hex;\n return signature;\n }\n\n async sendTransaction(tx: {\n to: Address;\n data?: Hex;\n value?: bigint;\n gas?: bigint;\n account?: { address: Address };\n chain?: { id: number };\n }): Promise<Hex> {\n if (this.shouldFailOperations) {\n throw new Error(\"Mock transaction failed\");\n }\n\n if (!tx.to) {\n throw new Error(\"Invalid transaction: missing 'to' address\");\n }\n\n // Simulate network delay if configured\n if (this.transactionDelay > 0) {\n await new Promise((resolve) =>\n setTimeout(resolve, this.transactionDelay),\n );\n }\n\n // Generate a deterministic mock transaction hash\n this.nonce++;\n const txData = JSON.stringify({\n from: this.account.address,\n to: tx.to,\n value: tx.value?.toString() || \"0\",\n nonce: this.nonce,\n chainId: this.chain.id,\n });\n\n const hash = `0x${Buffer.from(txData)\n .toString(\"hex\")\n .slice(0, 64)\n .padEnd(64, \"0\")}` as Hex;\n return hash;\n }\n\n /** Updates configuration for testing different scenarios. */\n updateConfig(updates: Partial<MockEthereumWalletConfig>): void {\n if (updates.address !== undefined) {\n this.account.address = updates.address;\n }\n if (updates.chainId !== undefined) {\n this.chain.id = updates.chainId;\n }\n if (updates.shouldFailOperations !== undefined) {\n this.shouldFailOperations = updates.shouldFailOperations;\n }\n if (updates.transactionDelay !== undefined) {\n this.transactionDelay = updates.transactionDelay;\n }\n }\n\n /** Resets to default configuration and nonce. */\n reset(): void {\n this.account.address =\n \"0x742d35cc6634c0532925a3b844bc9e7595f0beb0\" as Address;\n this.chain.id = 11155111;\n this.shouldFailOperations = false;\n this.transactionDelay = 0;\n this.nonce = 0;\n }\n\n /** Returns current nonce for testing. */\n getCurrentNonce(): number {\n return this.nonce;\n }\n}\n"],"names":["BitcoinNetworks","MockBitcoinWallet","config","__publicField","psbtHex","psbtsHexes","signedPsbts","signedPsbt","message","type","Buffer","updates","MockEthereumWallet","args","account","signatureData","tx","resolve","txData","_a"],"mappings":"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var G=Object.defineProperty;var J=(n,t,e)=>t in n?G(n,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):n[t]=e;var H=(n,t,e)=>J(n,typeof t!="symbol"?t+"":t,e);const b=require("bitcoinjs-lib"),p=require("buffer"),f=require("./challengeAssert-34HqeVFH.cjs"),v=require("viem");require("@babylonlabs-io/babylon-tbv-rust-wasm");require("@bitcoin-js/tiny-secp256k1-asmjs");function Q(n){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(n){for(const e in n)if(e!=="default"){const r=Object.getOwnPropertyDescriptor(n,e);Object.defineProperty(t,e,r.get?r:{enumerable:!0,get:()=>n[e]})}}return t.default=n,Object.freeze(t)}const A=Q(b),_=58,$=43,W=11,F=546,S=BigInt(F),M=30,R=2,tt=1.1;function N(n){return n<=R?M:0}function V(n,t,e){if(n.length===0)throw new Error("Insufficient funds: no UTXOs available");const r=n.filter(s=>{const c=p.Buffer.from(s.scriptPubKey,"hex");return!!b.script.decompile(c)});if(r.length===0)throw new Error("Insufficient funds: no valid UTXOs available (all have invalid scripts)");const a=[...r].sort((s,c)=>c.value-s.value),o=[];let u=0n,i=0n;for(const s of a){o.push(s),u+=BigInt(s.value);const c=o.length*_,l=2*$,d=c+l+W;if(i=BigInt(Math.ceil(d*e))+BigInt(N(e)),u-t-i>S){const y=BigInt(Math.ceil($*e));i+=y}if(u>=t+i){const y=u-t-i;return{selectedUTXOs:o,totalValue:u,fee:i,changeAmount:y}}}throw new Error(`Insufficient funds: need ${t+i} sats (${t} pegin + ${i} fee), have ${u} sats`)}function et(n){return n>S}function nt(){return F}function K(n){const e=n.substring(8,12)==="0001"?12:8,r=parseInt(n.substring(e,e+2),16),a=parseInt(n.substring(e+2,e+4),16);if(r!==0)throw new Error(`Expected 0 inputs from WASM, got ${r}`);if(a===0)throw new Error("Expected at least 1 output from WASM, got 0");const o=p.Buffer.from(n.substring(0,8),"hex").readUInt32LE(0),u=p.Buffer.from(n.substring(n.length-8),"hex").readUInt32LE(0),i=[];let s=e+4;for(let c=0;c<a;c++){const l=n.substring(s,s+16),d=Number(p.Buffer.from(l,"hex").readBigUInt64LE(0));s+=16;const g=parseInt(n.substring(s,s+2),16);s+=2;const y=n.substring(s,s+g*2),T=p.Buffer.from(y,"hex");s+=g*2,i.push({value:d,script:T})}return{version:o,locktime:u,outputs:i}}function L(n){const{unfundedTxHex:t,selectedUTXOs:e,changeAddress:r,changeAmount:a,network:o}=n,{version:u,locktime:i,outputs:s}=K(t),c=new A.Transaction;c.version=u,c.locktime=i;for(const l of e){const d=p.Buffer.from(l.txid,"hex").reverse();c.addInput(d,l.vout)}for(const l of s)c.addOutput(l.script,l.value);if(a>S){const l=A.address.toOutputScript(r,o);c.addOutput(l,Number(a))}return c.toHex()}function O(n){const t=n.startsWith("0x")?n.slice(2):n;return`0x${b.Transaction.fromHex(t).getId()}`}function rt(n,t,e){if(n.length===0)throw new Error("No input UTXOs provided for split transaction");if(t.length===0)throw new Error("No outputs specified for split transaction");for(const s of t)if(s.amount<=0n)throw new Error(`Invalid output amount for ${s.address}: ${s.amount} satoshis. Amount must be greater than zero.`);const r=f.getNetwork(e),a=new b.Transaction;a.version=2;for(const s of n){const c=p.Buffer.from(s.txid,"hex").reverse();a.addInput(c,s.vout)}const o=[];for(let s=0;s<t.length;s++){const c=t[s];let l;try{l=b.address.toOutputScript(c.address,r)}catch(d){throw new Error(`Failed to decode address "${c.address}": ${d instanceof Error?d.message:String(d)}`)}a.addOutput(l,Number(c.amount)),o.push({txid:"",vout:s,value:Number(c.amount),scriptPubKey:l.toString("hex")})}const u=a.toHex(),i=a.getId();for(const s of o)s.txid=i;return{txHex:u,txid:i,outputs:o}}function st(n,t,e){const r=b.Transaction.fromHex(n),a=new b.Psbt;if(a.setVersion(r.version),a.setLocktime(r.locktime),!p.Buffer.isBuffer(e)||e.length!==32)throw new Error(`Invalid publicKeyNoCoord: expected 32-byte Buffer (x-only pubkey), got ${p.Buffer.isBuffer(e)?`${e.length}-byte Buffer`:typeof e}`);if(t.length!==r.ins.length)throw new Error(`UTXO count mismatch: transaction has ${r.ins.length} input${r.ins.length!==1?"s":""}, but ${t.length} UTXO${t.length!==1?"s were":" was"} provided`);for(let o=0;o<r.ins.length;o++){const u=r.ins[o],i=t[o];if(!i)throw new Error(`Missing UTXO data for input ${o}`);const s=p.Buffer.from(u.hash).reverse().toString("hex"),c=u.index;if(i.txid!==s||i.vout!==c)throw new Error(`Input ${o} outpoint mismatch: transaction expects ${s}:${c}, but UTXO ${i.txid}:${i.vout} was provided. Ensure inputs array matches the order used in createSplitTransaction().`);const l=p.Buffer.from(i.scriptPubKey,"hex");if(!(l.length===34&&l[0]===81&&l[1]===32))throw new Error(`Input ${o} must be P2TR (Taproot). createSplitTransactionPsbt() requires P2TR inputs because it uses tapInternalKey for Taproot signing. ScriptPubKey: ${i.scriptPubKey.substring(0,20)}...`);const g={script:p.Buffer.from(i.scriptPubKey,"hex"),value:i.value};a.addInput({hash:u.hash,index:u.index,sequence:u.sequence,witnessUtxo:g,tapInternalKey:e})}for(const o of r.outs)a.addOutput({script:o.script,value:o.value});return a.toHex()}var k=(n=>(n.P2PKH="P2PKH",n.P2SH="P2SH",n.P2WPKH="P2WPKH",n.P2WSH="P2WSH",n.P2TR="P2TR",n.UNKNOWN="UNKNOWN",n))(k||{});function D(n){const t=n.length;return t===25&&n[0]===118&&n[1]===169&&n[2]===20&&n[23]===136&&n[24]===172?"P2PKH":t===23&&n[0]===169&&n[1]===20&&n[22]===135?"P2SH":t===22&&n[0]===0&&n[1]===20?"P2WPKH":t===34&&n[0]===0&&n[1]===32?"P2WSH":t===34&&n[0]===81&&n[1]===32?"P2TR":"UNKNOWN"}function X(n,t){const e=p.Buffer.from(n.scriptPubKey,"hex"),r=D(e);switch(r){case k.P2WPKH:return{witnessUtxo:{script:e,value:n.value}};case k.P2WSH:{if(!n.witnessScript)throw new Error("Missing witnessScript for P2WSH input");return{witnessUtxo:{script:e,value:n.value},witnessScript:p.Buffer.from(n.witnessScript,"hex")}}case k.P2TR:{if(t&&t.length!==32)throw new Error(`Invalid tapInternalKey length: expected 32 bytes, got ${t.length}`);return{witnessUtxo:{script:e,value:n.value},...t&&{tapInternalKey:t}}}default:throw new Error(`Unsupported script type: ${r}`)}}const q={mainnet:"https://mempool.space/api",testnet:"https://mempool.space/testnet/api",signet:"https://mempool.space/signet/api"};async function I(n,t){try{const e=await fetch(n,t);if(!e.ok){const a=await e.text();throw new Error(`Mempool API error (${e.status}): ${a||e.statusText}`)}const r=e.headers.get("content-type");return r!=null&&r.includes("application/json")?await e.json():await e.text()}catch(e){throw e instanceof Error?new Error(`Failed to fetch from mempool API: ${e.message}`):new Error("Failed to fetch from mempool API: Unknown error")}}async function z(n,t){try{const e=await fetch(`${t}/tx`,{method:"POST",body:n,headers:{"Content-Type":"text/plain"}});if(!e.ok){const a=await e.text();let o;try{o=JSON.parse(a).message}catch{o=a}throw new Error(o||`Failed to broadcast transaction: ${e.statusText}`)}return await e.text()}catch(e){throw e instanceof Error?new Error(`Failed to broadcast BTC transaction: ${e.message}`):new Error("Failed to broadcast BTC transaction: Unknown error")}}async function j(n,t){return I(`${t}/tx/${n}`)}async function ot(n,t){try{const e=await fetch(`${t}/tx/${n}/hex`);if(!e.ok){const r=await e.text();throw new Error(`Mempool API error (${e.status}): ${r||e.statusText}`)}return await e.text()}catch(e){throw e instanceof Error?new Error(`Failed to get transaction hex for ${n}: ${e.message}`):new Error(`Failed to get transaction hex for ${n}: Unknown error`)}}async function Y(n,t,e){const r=await j(n,e);if(t>=r.vout.length)throw new Error(`Invalid vout ${t} for transaction ${n} (has ${r.vout.length} outputs)`);const a=r.vout[t];return{txid:n,vout:t,value:a.value,scriptPubKey:a.scriptpubkey}}async function at(n,t){try{const e=await I(`${t}/address/${n}/utxo`),r=await I(`${t}/v1/validate-address/${n}`);if(!r.isvalid)throw new Error(`Invalid Bitcoin address: ${n}. Mempool API validation failed.`);return e.sort((o,u)=>u.value-o.value).map(o=>({txid:o.txid,vout:o.vout,value:o.value,scriptPubKey:r.scriptPubKey,confirmed:o.status.confirmed}))}catch(e){throw e instanceof Error?new Error(`Failed to get UTXOs for address ${n}: ${e.message}`):new Error(`Failed to get UTXOs for address ${n}: Unknown error`)}}function it(n){return q[n]}async function ct(n,t){return I(`${t}/address/${n}/txs`)}async function ut(n){const t=await fetch(`${n}/v1/fees/recommended`);if(!t.ok)throw new Error(`Failed to fetch network fees: ${t.status} ${t.statusText}`);const e=await t.json();if(typeof e.fastestFee!="number"||typeof e.halfHourFee!="number"||typeof e.hourFee!="number"||typeof e.economyFee!="number"||typeof e.minimumFee!="number")throw new Error("Invalid fee data structure from mempool API. Expected all fee fields to be numbers.");return e}const B=[{type:"function",name:"submitPeginRequest",inputs:[{name:"depositor",type:"address",internalType:"address"},{name:"depositorBtcPubKey",type:"bytes32",internalType:"bytes32"},{name:"btcPopSignature",type:"bytes",internalType:"bytes"},{name:"unsignedPegInTx",type:"bytes",internalType:"bytes"},{name:"vaultProvider",type:"address",internalType:"address"},{name:"depositorPayoutBtcAddress",type:"bytes",internalType:"bytes"},{name:"depositorLamportPkHash",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"payable"},{type:"function",name:"submitPeginRequest",inputs:[{name:"depositor",type:"address",internalType:"address"},{name:"depositorBtcPubKey",type:"bytes32",internalType:"bytes32"},{name:"btcPopSignature",type:"bytes",internalType:"bytes"},{name:"unsignedPegInTx",type:"bytes",internalType:"bytes"},{name:"vaultProvider",type:"address",internalType:"address"},{name:"referralCode",type:"uint32",internalType:"uint32"},{name:"depositorPayoutBtcAddress",type:"bytes",internalType:"bytes"},{name:"depositorLamportPkHash",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"payable"},{type:"function",name:"getPegInFee",inputs:[{name:"vaultProvider",type:"address",internalType:"address"}],outputs:[{name:"totalFee",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"getBTCVault",inputs:[{name:"vaultId",type:"bytes32",internalType:"bytes32"}],outputs:[{name:"vault",type:"tuple",internalType:"struct IBTCVaultsManager.BTCVault",components:[{name:"depositor",type:"address",internalType:"address"},{name:"depositorBtcPubKey",type:"bytes32",internalType:"bytes32"},{name:"unsignedPegInTx",type:"bytes",internalType:"bytes"},{name:"amount",type:"uint256",internalType:"uint256"},{name:"vaultProvider",type:"address",internalType:"address"},{name:"status",type:"uint8",internalType:"enum IBTCVaultsManager.BTCVaultStatus"},{name:"applicationController",type:"address",internalType:"address"},{name:"universalChallengersVersion",type:"uint16",internalType:"uint16"},{name:"appVaultKeepersVersion",type:"uint16",internalType:"uint16"},{name:"offchainParamsVersion",type:"uint16",internalType:"uint16"},{name:"createdAt",type:"uint256",internalType:"uint256"},{name:"verifiedAt",type:"uint256",internalType:"uint256"},{name:"depositorLamportPkHash",type:"bytes32",internalType:"bytes32"}]}],stateMutability:"view"},{type:"error",name:"InvalidPeginFee",inputs:[{name:"provided",type:"uint256",internalType:"uint256"},{name:"required",type:"uint256",internalType:"uint256"}]}],m={"0x04aabf33":"Vault already exists: This Bitcoin transaction has already been registered. Please select different UTXOs or use a different amount to create a unique transaction.","0x4fec082d":"Script mismatch: The Bitcoin transaction's taproot output does not match the expected vault script. This may be caused by incorrect vault participants or key configuration.","0x6cc363a5":"Invalid BTC proof of possession: The signature could not be verified. Please ensure you're signing with the correct Bitcoin wallet.","0x6c3f2bf6":"Invalid BTC public key: The Bitcoin public key format is invalid.","0x2c5211c6":"Invalid amount: The deposit amount is invalid or below the minimum required.","0x0405f772":"Application not registered: The application controller is not registered in the system.","0x24e165cc":"Invalid provider status: The vault provider is not in a valid state to accept deposits.","0xd92e233d":"Zero address: One of the required addresses is the zero address.","0x65aa7007":"BTC key mismatch: The Bitcoin public key does not match the expected key.","0x82b42900":"Unauthorized: You must be the depositor or vault provider to submit this transaction.","0x8baa579f":"Invalid signature: The BTC proof of possession signature could not be verified.","0x2f9d01e9":"Invalid BTC transaction: The Bitcoin transaction format is invalid.","0x5a3c6b3e":"Vault provider not registered: The selected vault provider is not registered.","0x979f4518":"Invalid pegin fee: The ETH fee sent does not match the required amount. This may indicate a fee rate change during the transaction."};function C(n){if(!n||typeof n!="object")return;const t=n;if(typeof t.data=="string"&&t.data.startsWith("0x"))return t.data;if(typeof t.details=="string"&&t.details.startsWith("0x"))return t.details;let e=t.cause,r=0;const a=5;for(;e&&typeof e=="object"&&r<a;){const i=e;if(typeof i.data=="string"&&i.data.startsWith("0x"))return i.data;e=i.cause,r++}const u=(typeof t.message=="string"?t.message:"").match(/\b(0x[a-fA-F0-9]{8})\b/);if(u)return u[1]}function lt(n){const t=C(n);if(t){const e=t.substring(0,10);return m[t]??m[e]}}function dt(n){const t=C(n);if(t===void 0)return!1;const e=t.substring(0,10);return t in m||e in m}function U(n){console.error("[Contract Error] Raw error:",n);const t=C(n);if(console.error("[Contract Error] Extracted error data:",t),t){const r=t.substring(0,10),a=m[t]??m[r];if(a)throw console.error("[Contract Error] Known error:",a),new Error(a)}const e=(n==null?void 0:n.message)||"";if(e.includes("gas limit too high")||e.includes("21000000")||e.includes("Internal JSON-RPC error")){const r=t?` (error code: ${t})`:"";throw console.error("[Contract Error] Transaction rejected. Error code:",t,"Message:",e),new Error(`Transaction failed: The contract rejected this transaction${r}. Possible causes: (1) Vault already exists for this transaction, (2) Invalid signature, (3) Unauthorized caller. Please check your transaction parameters and try again.`)}throw n instanceof Error?(console.error("[Contract Error] Unhandled error:",n.message),n):new Error(`Contract call failed: ${String(n)}`)}class pt{constructor(t){H(this,"config");this.config=t}async preparePegin(t){const e=await this.config.btcWallet.getPublicKeyHex(),r=e.length===66?e.slice(2):e,a=f.stripHexPrefix(t.vaultProviderBtcPubkey),o=t.vaultKeeperBtcPubkeys.map(f.stripHexPrefix),u=t.universalChallengerBtcPubkeys.map(f.stripHexPrefix),i=await f.buildPeginPsbt({depositorPubkey:r,vaultProviderPubkey:a,vaultKeeperPubkeys:o,universalChallengerPubkeys:u,timelockPegin:t.timelockPegin,pegInAmount:t.amount,depositorClaimValue:t.depositorClaimValue,network:this.config.btcNetwork}),s=t.amount+t.depositorClaimValue,c=V(t.availableUTXOs,s,t.feeRate),l=f.getNetwork(this.config.btcNetwork),d=L({unfundedTxHex:i.psbtHex,selectedUTXOs:c.selectedUTXOs,changeAddress:t.changeAddress,changeAmount:c.changeAmount,network:l}),g=O(d);return{btcTxHash:f.stripHexPrefix(g),fundedTxHex:d,vaultScriptPubKey:i.vaultScriptPubKey,selectedUTXOs:c.selectedUTXOs,fee:c.fee,changeAmount:c.changeAmount,ethTxHash:null}}async signAndBroadcast(t){const{fundedTxHex:e,depositorBtcPubkey:r}=t,a=e.startsWith("0x")?e.slice(2):e,o=b.Transaction.fromHex(a);if(o.ins.length===0)throw new Error("Transaction has no inputs");const u=new b.Psbt;u.setVersion(o.version),u.setLocktime(o.locktime);const i=r.startsWith("0x")?r.slice(2):r;if(i.length!==64||!/^[0-9a-fA-F]+$/.test(i))throw new Error("Invalid depositorBtcPubkey: expected 64 hex characters (x-only pubkey)");const s=p.Buffer.from(i,"hex");if(s.length!==32)throw new Error(`Invalid depositorBtcPubkey length: expected 32 bytes, got ${s.length}`);const c=this.config.mempoolApiUrl,l=o.ins.map(h=>{const x=p.Buffer.from(h.hash).reverse().toString("hex"),P=h.index;return Y(x,P,c).then(E=>({input:h,utxoData:E,txid:x,vout:P}))}),d=await Promise.all(l);for(const{input:h,utxoData:x,txid:P,vout:E}of d){const w=X({value:x.value,scriptPubKey:x.scriptPubKey},s);u.addInput({hash:h.hash,index:h.index,sequence:h.sequence,...w})}for(const h of o.outs)u.addOutput({script:h.script,value:h.value});const g=await this.config.btcWallet.signPsbt(u.toHex()),y=b.Psbt.fromHex(g);try{y.finalizeAllInputs()}catch{}const T=y.extractTransaction().toHex();return await z(T,c)}async registerPeginOnChain(t){const{depositorBtcPubkey:e,unsignedBtcTx:r,vaultProvider:a,onPopSigned:o,depositorPayoutBtcAddress:u,depositorLamportPkHash:i,preSignedBtcPopSignature:s}=t;if(!this.config.ethWallet.account)throw new Error("Ethereum wallet account not found");const c=this.config.ethWallet.account.address,l=await this.resolvePopSignature(c,s);o&&await o();const d=e.startsWith("0x")?e:`0x${e}`,g=r.startsWith("0x")?r:`0x${r}`,y=await this.resolvePayoutScriptPubKey(u),T=O(g);if(await this.checkVaultExists(T))throw new Error(`Vault already exists for this transaction (ID: ${T}). Vault IDs are deterministically derived from the unsigned Bitcoin transaction, so using the same UTXOs and amount will always produce the same vault. To create a new vault, please use different UTXOs or a different amount to generate a unique transaction.`);const h=v.createPublicClient({chain:this.config.ethChain,transport:v.http()});let x;try{x=await h.readContract({address:this.config.vaultContracts.btcVaultsManager,abi:B,functionName:"getPegInFee",args:[a]})}catch{throw new Error("Failed to query pegin fee from the contract. Please check your network connection and that the contract address is correct.")}const P=v.encodeFunctionData({abi:B,functionName:"submitPeginRequest",args:[c,d,l,g,a,y,i]});let E;try{E=await h.estimateGas({to:this.config.vaultContracts.btcVaultsManager,data:P,value:x,account:this.config.ethWallet.account.address})}catch(w){U(w)}try{return{ethTxHash:await this.config.ethWallet.sendTransaction({to:this.config.vaultContracts.btcVaultsManager,data:P,value:x,account:this.config.ethWallet.account,chain:this.config.ethChain,gas:E}),vaultId:T,btcPopSignature:l}}catch(w){U(w)}}async checkVaultExists(t){try{return(await v.createPublicClient({chain:this.config.ethChain,transport:v.http()}).readContract({address:this.config.vaultContracts.btcVaultsManager,abi:B,functionName:"getBTCVault",args:[t]})).depositor!==v.zeroAddress}catch{return!1}}async resolvePayoutScriptPubKey(t){let e;if(t)e=t;else{e=await this.config.btcWallet.getAddress();const a=await this.config.btcWallet.getPublicKeyHex();if(!f.isAddressFromPublicKey(e,a,this.config.btcNetwork))throw new Error("The BTC address from your wallet does not match the wallet's public key. Please ensure your wallet is using a supported address type (Taproot or Native SegWit).")}const r=f.getNetwork(this.config.btcNetwork);try{return`0x${A.address.toOutputScript(e,r).toString("hex")}`}catch{throw new Error(`Invalid BTC payout address: "${e}". Please provide a valid Bitcoin address for the ${this.config.btcNetwork} network.`)}}async resolvePopSignature(t,e){if(e)return e;const r=this.config.vaultContracts.btcVaultsManager,a=`${t.toLowerCase()}:${this.config.ethChain.id}:pegin:${r.toLowerCase()}`,o=await this.config.btcWallet.signMessage(a,"bip322-simple");return o.startsWith("0x")?o:`0x${p.Buffer.from(o,"base64").toString("hex")}`}getNetwork(){return this.config.btcNetwork}getVaultContractAddress(){return this.config.vaultContracts.btcVaultsManager}}class ft{constructor(t){H(this,"config");this.config=t}async signPayoutTransaction(t){const e=await this.config.btcWallet.getPublicKeyHex(),{depositorPubkey:r}=f.validateWalletPubkey(e,t.depositorBtcPubkey),a=await f.buildPayoutPsbt({payoutTxHex:t.payoutTxHex,peginTxHex:t.peginTxHex,assertTxHex:t.assertTxHex,depositorBtcPubkey:r,vaultProviderBtcPubkey:t.vaultProviderBtcPubkey,vaultKeeperBtcPubkeys:t.vaultKeeperBtcPubkeys,universalChallengerBtcPubkeys:t.universalChallengerBtcPubkeys,timelockPegin:t.timelockPegin,network:this.config.network}),o=await this.config.btcWallet.signPsbt(a.psbtHex,{autoFinalized:!1,signInputs:[{index:0,publicKey:e,disableTweakSigner:!0}]});return{signature:f.extractPayoutSignature(o,r),depositorBtcPubkey:r}}getNetwork(){return this.config.network}supportsBatchSigning(){return typeof this.config.btcWallet.signPsbts=="function"}async signPayoutTransactionsBatch(t){if(!this.supportsBatchSigning())throw new Error("Wallet does not support batch signing (signPsbts method not available)");const e=await this.config.btcWallet.getPublicKeyHex(),r=[],a=[],o=[];for(const s of t){const{depositorPubkey:c}=f.validateWalletPubkey(e,s.depositorBtcPubkey);o.push(c);const l=await f.buildPayoutPsbt({payoutTxHex:s.payoutTxHex,peginTxHex:s.peginTxHex,assertTxHex:s.assertTxHex,depositorBtcPubkey:c,vaultProviderBtcPubkey:s.vaultProviderBtcPubkey,vaultKeeperBtcPubkeys:s.vaultKeeperBtcPubkeys,universalChallengerBtcPubkeys:s.universalChallengerBtcPubkeys,timelockPegin:s.timelockPegin,network:this.config.network});r.push(l.psbtHex),a.push({autoFinalized:!1,signInputs:[{index:0,publicKey:e,disableTweakSigner:!0}]})}const u=await this.config.btcWallet.signPsbts(r,a);if(u.length!==t.length)throw new Error(`Expected ${t.length} signed PSBTs but received ${u.length}`);const i=[];for(let s=0;s<t.length;s++){const c=o[s],l=f.extractPayoutSignature(u[s],c);i.push({payoutSignature:l,depositorBtcPubkey:c})}return i}}exports.BTCVaultsManagerABI=B;exports.BTC_DUST_SAT=F;exports.BitcoinScriptType=k;exports.CONTRACT_ERRORS=m;exports.DUST_THRESHOLD=S;exports.FEE_SAFETY_MARGIN=tt;exports.LOW_RATE_ESTIMATION_ACCURACY_BUFFER=M;exports.MAX_NON_LEGACY_OUTPUT_SIZE=$;exports.MEMPOOL_API_URLS=q;exports.P2TR_INPUT_SIZE=_;exports.PayoutManager=ft;exports.PeginManager=pt;exports.TX_BUFFER_SIZE_OVERHEAD=W;exports.WALLET_RELAY_FEE_RATE_THRESHOLD=R;exports.calculateBtcTxHash=O;exports.createSplitTransaction=rt;exports.createSplitTransactionPsbt=st;exports.extractErrorData=C;exports.fundPeginTransaction=L;exports.getAddressTxs=ct;exports.getAddressUtxos=at;exports.getContractErrorMessage=lt;exports.getDustThreshold=nt;exports.getMempoolApiUrl=it;exports.getNetworkFees=ut;exports.getPsbtInputFields=X;exports.getScriptType=D;exports.getTxHex=ot;exports.getTxInfo=j;exports.getUtxoInfo=Y;exports.handleContractError=U;exports.isKnownContractError=dt;exports.parseUnfundedWasmTransaction=K;exports.pushTx=z;exports.rateBasedTxBufferFee=N;exports.selectUtxosForPegin=V;exports.shouldAddChangeOutput=et;
|
|
2
|
+
//# sourceMappingURL=PayoutManager-Dg_i_S7w.cjs.map
|