@aibtc/mcp-server 1.4.0 → 1.6.0
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/README.md +30 -2
- package/dist/config/caip.d.ts +66 -0
- package/dist/config/caip.d.ts.map +1 -0
- package/dist/config/caip.js +84 -0
- package/dist/config/caip.js.map +1 -0
- package/dist/services/mempool-api.d.ts +183 -0
- package/dist/services/mempool-api.d.ts.map +1 -0
- package/dist/services/mempool-api.js +179 -0
- package/dist/services/mempool-api.js.map +1 -0
- package/dist/services/wallet-manager.d.ts +1 -0
- package/dist/services/wallet-manager.d.ts.map +1 -1
- package/dist/services/wallet-manager.js +13 -0
- package/dist/services/wallet-manager.js.map +1 -1
- package/dist/tools/bitcoin.tools.d.ts +15 -0
- package/dist/tools/bitcoin.tools.d.ts.map +1 -0
- package/dist/tools/bitcoin.tools.js +295 -0
- package/dist/tools/bitcoin.tools.js.map +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +3 -0
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/wallet-management.tools.d.ts.map +1 -1
- package/dist/tools/wallet-management.tools.js +3 -0
- package/dist/tools/wallet-management.tools.js.map +1 -1
- package/dist/tools/wallet.tools.d.ts.map +1 -1
- package/dist/tools/wallet.tools.js +3 -0
- package/dist/tools/wallet.tools.js.map +1 -1
- package/dist/transactions/bitcoin-builder.d.ts +171 -0
- package/dist/transactions/bitcoin-builder.d.ts.map +1 -0
- package/dist/transactions/bitcoin-builder.js +242 -0
- package/dist/transactions/bitcoin-builder.js.map +1 -0
- package/dist/transactions/builder.d.ts +10 -0
- package/dist/transactions/builder.d.ts.map +1 -1
- package/dist/transactions/builder.js.map +1 -1
- package/dist/utils/bitcoin.d.ts +92 -0
- package/dist/utils/bitcoin.d.ts.map +1 -0
- package/dist/utils/bitcoin.js +141 -0
- package/dist/utils/bitcoin.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/storage.d.ts +1 -0
- package/dist/utils/storage.d.ts.map +1 -1
- package/dist/utils/storage.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -98,6 +98,34 @@ Claude's wallets are stored locally on your machine:
|
|
|
98
98
|
- Mnemonics never stored in plaintext
|
|
99
99
|
- File permissions set to owner-only (0600)
|
|
100
100
|
|
|
101
|
+
## Bitcoin Address Derivation
|
|
102
|
+
|
|
103
|
+
Each wallet automatically derives both a **Stacks address** and a **Bitcoin address** from the same mnemonic using BIP39/BIP32 standards.
|
|
104
|
+
|
|
105
|
+
**Derivation Paths (BIP84):**
|
|
106
|
+
- Mainnet: `m/84'/0'/0'/0/0` (Bitcoin coin type 0)
|
|
107
|
+
- Testnet: `m/84'/1'/0'/0/0` (Bitcoin testnet coin type 1)
|
|
108
|
+
|
|
109
|
+
**Address Format:**
|
|
110
|
+
- Mainnet: `bc1q...` (Native SegWit P2WPKH)
|
|
111
|
+
- Testnet: `tb1q...` (Native SegWit P2WPKH)
|
|
112
|
+
|
|
113
|
+
**Current Support:**
|
|
114
|
+
- Read-only Bitcoin address derivation
|
|
115
|
+
- Same mnemonic produces both Stacks and Bitcoin addresses
|
|
116
|
+
- Bitcoin address included in wallet status and info
|
|
117
|
+
- No Bitcoin signing or transaction support (yet)
|
|
118
|
+
|
|
119
|
+
**Example:**
|
|
120
|
+
```
|
|
121
|
+
You: Create a wallet called "my-wallet"
|
|
122
|
+
Claude: I've created a wallet with:
|
|
123
|
+
Stacks address: ST1ABC...
|
|
124
|
+
Bitcoin address: bc1q...
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Both addresses are derived from the same recovery phrase, making it easy to manage both Layer 1 (Bitcoin) and Layer 2 (Stacks) assets.
|
|
128
|
+
|
|
101
129
|
## Available Tools (50+ total)
|
|
102
130
|
|
|
103
131
|
### Wallet Management
|
|
@@ -111,13 +139,13 @@ Claude's wallets are stored locally on your machine:
|
|
|
111
139
|
| `wallet_switch` | Switch Claude to a different wallet |
|
|
112
140
|
| `wallet_delete` | Delete a wallet |
|
|
113
141
|
| `wallet_export` | Export wallet mnemonic |
|
|
114
|
-
| `wallet_status` | Check if Claude's wallet is ready |
|
|
142
|
+
| `wallet_status` | Check if Claude's wallet is ready (includes Stacks and Bitcoin addresses) |
|
|
115
143
|
| `wallet_set_timeout` | Set how long wallet stays unlocked |
|
|
116
144
|
|
|
117
145
|
### Wallet & Balance
|
|
118
146
|
| Tool | Description |
|
|
119
147
|
|------|-------------|
|
|
120
|
-
| `get_wallet_info` | Get Claude's wallet
|
|
148
|
+
| `get_wallet_info` | Get Claude's wallet addresses (Stacks + Bitcoin) and status |
|
|
121
149
|
| `get_stx_balance` | Get STX balance for any address |
|
|
122
150
|
|
|
123
151
|
### STX Transfers
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CAIP-2 Chain Identifiers
|
|
3
|
+
*
|
|
4
|
+
* Chain-agnostic identifiers following the CAIP-2 specification:
|
|
5
|
+
* https://chainagnostic.org/CAIPs/caip-2
|
|
6
|
+
*
|
|
7
|
+
* Format: namespace:reference
|
|
8
|
+
* - Stacks uses "stacks" namespace with chain ID as reference
|
|
9
|
+
* - Bitcoin uses "bip122" namespace with genesis block hash prefix (32 chars)
|
|
10
|
+
*/
|
|
11
|
+
import type { Network } from "./networks.js";
|
|
12
|
+
/**
|
|
13
|
+
* CAIP-2 chain identifier type
|
|
14
|
+
*/
|
|
15
|
+
export type ChainId = string;
|
|
16
|
+
/**
|
|
17
|
+
* Stacks chain IDs
|
|
18
|
+
* - Mainnet: chain ID 1
|
|
19
|
+
* - Testnet: chain ID 2147483648 (0x80000000)
|
|
20
|
+
*/
|
|
21
|
+
export declare const STACKS_CHAIN_IDS: {
|
|
22
|
+
readonly mainnet: "stacks:1";
|
|
23
|
+
readonly testnet: "stacks:2147483648";
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Bitcoin chain IDs (BIP122 namespace)
|
|
27
|
+
* Using first 32 characters of genesis block hash as reference
|
|
28
|
+
* - Mainnet: 000000000019d6689c085ae165831e93
|
|
29
|
+
* - Testnet: 000000000933ea01ad0ee984209779ba
|
|
30
|
+
*/
|
|
31
|
+
export declare const BITCOIN_CHAIN_IDS: {
|
|
32
|
+
readonly mainnet: "bip122:000000000019d6689c085ae165831e93";
|
|
33
|
+
readonly testnet: "bip122:000000000933ea01ad0ee984209779ba";
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Get Stacks CAIP-2 chain ID for a network
|
|
37
|
+
*/
|
|
38
|
+
export declare function getStacksChainId(network: Network): ChainId;
|
|
39
|
+
/**
|
|
40
|
+
* Get Bitcoin CAIP-2 chain ID for a network
|
|
41
|
+
*/
|
|
42
|
+
export declare function getBitcoinChainId(network: Network): ChainId;
|
|
43
|
+
/**
|
|
44
|
+
* Parse CAIP-2 chain ID into namespace and reference
|
|
45
|
+
*/
|
|
46
|
+
export declare function parseChainId(chainId: ChainId): {
|
|
47
|
+
namespace: string;
|
|
48
|
+
reference: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Check if a chain ID is a Stacks chain
|
|
52
|
+
*/
|
|
53
|
+
export declare function isStacksChainId(chainId: ChainId): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Check if a chain ID is a Bitcoin chain
|
|
56
|
+
*/
|
|
57
|
+
export declare function isBitcoinChainId(chainId: ChainId): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* Get network from Stacks chain ID
|
|
60
|
+
*/
|
|
61
|
+
export declare function getNetworkFromStacksChainId(chainId: ChainId): Network | null;
|
|
62
|
+
/**
|
|
63
|
+
* Get network from Bitcoin chain ID
|
|
64
|
+
*/
|
|
65
|
+
export declare function getNetworkFromBitcoinChainId(chainId: ChainId): Network | null;
|
|
66
|
+
//# sourceMappingURL=caip.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caip.d.ts","sourceRoot":"","sources":["../../src/config/caip.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE7C;;GAEG;AACH,MAAM,MAAM,OAAO,GAAG,MAAM,CAAC;AAE7B;;;;GAIG;AACH,eAAO,MAAM,gBAAgB;;;CAGnB,CAAC;AAEX;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB;;;CAGpB,CAAC;AAEX;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAE1D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAE3D;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG;IAC9C,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;CACnB,CAMA;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAEzD;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAE1D;AAED;;GAEG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,GAAG,IAAI,CAI5E;AAED;;GAEG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,GAAG,IAAI,CAI7E"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CAIP-2 Chain Identifiers
|
|
3
|
+
*
|
|
4
|
+
* Chain-agnostic identifiers following the CAIP-2 specification:
|
|
5
|
+
* https://chainagnostic.org/CAIPs/caip-2
|
|
6
|
+
*
|
|
7
|
+
* Format: namespace:reference
|
|
8
|
+
* - Stacks uses "stacks" namespace with chain ID as reference
|
|
9
|
+
* - Bitcoin uses "bip122" namespace with genesis block hash prefix (32 chars)
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Stacks chain IDs
|
|
13
|
+
* - Mainnet: chain ID 1
|
|
14
|
+
* - Testnet: chain ID 2147483648 (0x80000000)
|
|
15
|
+
*/
|
|
16
|
+
export const STACKS_CHAIN_IDS = {
|
|
17
|
+
mainnet: "stacks:1",
|
|
18
|
+
testnet: "stacks:2147483648",
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* Bitcoin chain IDs (BIP122 namespace)
|
|
22
|
+
* Using first 32 characters of genesis block hash as reference
|
|
23
|
+
* - Mainnet: 000000000019d6689c085ae165831e93
|
|
24
|
+
* - Testnet: 000000000933ea01ad0ee984209779ba
|
|
25
|
+
*/
|
|
26
|
+
export const BITCOIN_CHAIN_IDS = {
|
|
27
|
+
mainnet: "bip122:000000000019d6689c085ae165831e93",
|
|
28
|
+
testnet: "bip122:000000000933ea01ad0ee984209779ba",
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Get Stacks CAIP-2 chain ID for a network
|
|
32
|
+
*/
|
|
33
|
+
export function getStacksChainId(network) {
|
|
34
|
+
return STACKS_CHAIN_IDS[network];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Get Bitcoin CAIP-2 chain ID for a network
|
|
38
|
+
*/
|
|
39
|
+
export function getBitcoinChainId(network) {
|
|
40
|
+
return BITCOIN_CHAIN_IDS[network];
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Parse CAIP-2 chain ID into namespace and reference
|
|
44
|
+
*/
|
|
45
|
+
export function parseChainId(chainId) {
|
|
46
|
+
const [namespace, reference] = chainId.split(":");
|
|
47
|
+
if (!namespace || !reference) {
|
|
48
|
+
throw new Error(`Invalid CAIP-2 chain ID: ${chainId}`);
|
|
49
|
+
}
|
|
50
|
+
return { namespace, reference };
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if a chain ID is a Stacks chain
|
|
54
|
+
*/
|
|
55
|
+
export function isStacksChainId(chainId) {
|
|
56
|
+
return chainId.startsWith("stacks:");
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Check if a chain ID is a Bitcoin chain
|
|
60
|
+
*/
|
|
61
|
+
export function isBitcoinChainId(chainId) {
|
|
62
|
+
return chainId.startsWith("bip122:");
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Get network from Stacks chain ID
|
|
66
|
+
*/
|
|
67
|
+
export function getNetworkFromStacksChainId(chainId) {
|
|
68
|
+
if (chainId === STACKS_CHAIN_IDS.mainnet)
|
|
69
|
+
return "mainnet";
|
|
70
|
+
if (chainId === STACKS_CHAIN_IDS.testnet)
|
|
71
|
+
return "testnet";
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get network from Bitcoin chain ID
|
|
76
|
+
*/
|
|
77
|
+
export function getNetworkFromBitcoinChainId(chainId) {
|
|
78
|
+
if (chainId === BITCOIN_CHAIN_IDS.mainnet)
|
|
79
|
+
return "mainnet";
|
|
80
|
+
if (chainId === BITCOIN_CHAIN_IDS.testnet)
|
|
81
|
+
return "testnet";
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=caip.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"caip.js","sourceRoot":"","sources":["../../src/config/caip.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AASH;;;;GAIG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,OAAO,EAAE,UAAU;IACnB,OAAO,EAAE,mBAAmB;CACpB,CAAC;AAEX;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,OAAO,EAAE,yCAAyC;IAClD,OAAO,EAAE,yCAAyC;CAC1C,CAAC;AAEX;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAgB;IAC/C,OAAO,gBAAgB,C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TXO and fee data
|
|
3
|
+
*
|
|
4
|
+
* Public API endpoints (no authentication required):
|
|
5
|
+
* - Mainnet: https://mempool.space/api
|
|
6
|
+
* - Testnet: https://mempool.space/testnet/api
|
|
7
|
+
*
|
|
8
|
+
* Documentation: https://mempool.space/docs/api
|
|
9
|
+
*/
|
|
10
|
+
import type { Network } from "../config/networks.js";
|
|
11
|
+
/**
|
|
12
|
+
* UTXO (Unspent Transaction Output) from mempool.space API
|
|
13
|
+
*/
|
|
14
|
+
export interface UTXO {
|
|
15
|
+
/**
|
|
16
|
+
* Transaction ID containing this UTXO
|
|
17
|
+
*/
|
|
18
|
+
txid: string;
|
|
19
|
+
/**
|
|
20
|
+
* Output index within the transaction
|
|
21
|
+
*/
|
|
22
|
+
vout: number;
|
|
23
|
+
/**
|
|
24
|
+
* UTXO status (confirmed or unconfirmed)
|
|
25
|
+
*/
|
|
26
|
+
status: {
|
|
27
|
+
confirmed: boolean;
|
|
28
|
+
block_height?: number;
|
|
29
|
+
block_hash?: string;
|
|
30
|
+
block_time?: number;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Value in satoshis
|
|
34
|
+
*/
|
|
35
|
+
value: number;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Fee estimates from mempool.space API (sat/vB)
|
|
39
|
+
*/
|
|
40
|
+
export interface FeeEstimates {
|
|
41
|
+
/**
|
|
42
|
+
* Fee rate for fastest confirmation (~10 min)
|
|
43
|
+
*/
|
|
44
|
+
fastestFee: number;
|
|
45
|
+
/**
|
|
46
|
+
* Fee rate for fast confirmation (~30 min)
|
|
47
|
+
*/
|
|
48
|
+
halfHourFee: number;
|
|
49
|
+
/**
|
|
50
|
+
* Fee rate for standard confirmation (~1 hour)
|
|
51
|
+
*/
|
|
52
|
+
hourFee: number;
|
|
53
|
+
/**
|
|
54
|
+
* Fee rate for economy confirmation (~24 hours)
|
|
55
|
+
*/
|
|
56
|
+
economyFee: number;
|
|
57
|
+
/**
|
|
58
|
+
* Minimum relay fee rate
|
|
59
|
+
*/
|
|
60
|
+
minimumFee: number;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Simplified fee tiers for user selection
|
|
64
|
+
*/
|
|
65
|
+
export interface FeeTiers {
|
|
66
|
+
/**
|
|
67
|
+
* Fast: ~10 minute confirmation
|
|
68
|
+
*/
|
|
69
|
+
fast: number;
|
|
70
|
+
/**
|
|
71
|
+
* Medium: ~30 minute confirmation
|
|
72
|
+
*/
|
|
73
|
+
medium: number;
|
|
74
|
+
/**
|
|
75
|
+
* Slow: ~1 hour confirmation
|
|
76
|
+
*/
|
|
77
|
+
slow: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get the mempool.space API base URL for a network
|
|
81
|
+
*/
|
|
82
|
+
export declare function getMempoolApiUrl(network: Network): string;
|
|
83
|
+
/**
|
|
84
|
+
* Get the mempool.space explorer URL for a network
|
|
85
|
+
*/
|
|
86
|
+
export declare function getMempoolExplorerUrl(network: Network): string;
|
|
87
|
+
/**
|
|
88
|
+
* Get transaction explorer URL
|
|
89
|
+
*/
|
|
90
|
+
export declare function getMempoolTxUrl(txid: string, network: Network): string;
|
|
91
|
+
/**
|
|
92
|
+
* Get address explorer URL
|
|
93
|
+
*/
|
|
94
|
+
export declare function getMempoolAddressUrl(address: string, network: Network): string;
|
|
95
|
+
/**
|
|
96
|
+
* mempool.space API client
|
|
97
|
+
*/
|
|
98
|
+
export declare class MempoolApi {
|
|
99
|
+
private readonly baseUrl;
|
|
100
|
+
private readonly network;
|
|
101
|
+
constructor(network: Network);
|
|
102
|
+
/**
|
|
103
|
+
* Get UTXOs for a Bitcoin address
|
|
104
|
+
*
|
|
105
|
+
* @param address - Bitcoin address (bc1... for mainnet, tb1... for testnet)
|
|
106
|
+
* @returns Array of UTXOs with txid, vout, value, and confirmation status
|
|
107
|
+
* @throws Error if API request fails
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```typescript
|
|
111
|
+
* const api = new MempoolApi('mainnet');
|
|
112
|
+
* const utxos = await api.getUtxos('bc1q...');
|
|
113
|
+
* const total = utxos.reduce((sum, u) => sum + u.value, 0);
|
|
114
|
+
* ```
|
|
115
|
+
*/
|
|
116
|
+
getUtxos(address: string): Promise<UTXO[]>;
|
|
117
|
+
/**
|
|
118
|
+
* Get current recommended fee estimates
|
|
119
|
+
*
|
|
120
|
+
* @returns Fee estimates in sat/vB for different confirmation targets
|
|
121
|
+
* @throws Error if API request fails
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* const api = new MempoolApi('mainnet');
|
|
126
|
+
* const fees = await api.getFeeEstimates();
|
|
127
|
+
* console.log(`Fast fee: ${fees.fastestFee} sat/vB`);
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
getFeeEstimates(): Promise<FeeEstimates>;
|
|
131
|
+
/**
|
|
132
|
+
* Get simplified fee tiers for user selection
|
|
133
|
+
*
|
|
134
|
+
* Maps mempool.space fee estimates to fast/medium/slow tiers:
|
|
135
|
+
* - Fast: fastestFee (~10 min)
|
|
136
|
+
* - Medium: halfHourFee (~30 min)
|
|
137
|
+
* - Slow: hourFee (~1 hour)
|
|
138
|
+
*
|
|
139
|
+
* @returns Fee tiers in sat/vB
|
|
140
|
+
* @throws Error if API request fails
|
|
141
|
+
*/
|
|
142
|
+
getFeeTiers(): Promise<FeeTiers>;
|
|
143
|
+
/**
|
|
144
|
+
* Get balance for a Bitcoin address (sum of UTXOs)
|
|
145
|
+
*
|
|
146
|
+
* @param address - Bitcoin address
|
|
147
|
+
* @returns Balance in satoshis
|
|
148
|
+
* @throws Error if API request fails
|
|
149
|
+
*/
|
|
150
|
+
getBalance(address: string): Promise<number>;
|
|
151
|
+
/**
|
|
152
|
+
* Get confirmed balance for a Bitcoin address
|
|
153
|
+
*
|
|
154
|
+
* @param address - Bitcoin address
|
|
155
|
+
* @returns Confirmed balance in satoshis (excludes unconfirmed UTXOs)
|
|
156
|
+
* @throws Error if API request fails
|
|
157
|
+
*/
|
|
158
|
+
getConfirmedBalance(address: string): Promise<number>;
|
|
159
|
+
/**
|
|
160
|
+
* Broadcast a signed transaction to the Bitcoin network
|
|
161
|
+
*
|
|
162
|
+
* @param txHex - Signed transaction as hex string
|
|
163
|
+
* @returns Transaction ID (txid)
|
|
164
|
+
* @throws Error if broadcast fails
|
|
165
|
+
*
|
|
166
|
+
* @example
|
|
167
|
+
* ```typescript
|
|
168
|
+
* const api = new MempoolApi('mainnet');
|
|
169
|
+
* const txid = await api.broadcastTransaction(signedTxHex);
|
|
170
|
+
* console.log(`Broadcast: ${getMempoolTxUrl(txid, 'mainnet')}`);
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
broadcastTransaction(txHex: string): Promise<string>;
|
|
174
|
+
/**
|
|
175
|
+
* Get the network this client is configured for
|
|
176
|
+
*/
|
|
177
|
+
getNetwork(): Network;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Create a mempool.space API client for the given network
|
|
181
|
+
*/
|
|
182
|
+
export declare function createMempoolApi(network: Network): MempoolApi;
|
|
183
|
+
//# sourceMappingURL=mempool-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mempool-api.d.ts","sourceRoot":"","sources":["../../src/services/mempool-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD;;GAEG;AACH,MAAM,WAAW,IAAI;IACnB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,MAAM,EAAE;QACN,SAAS,EAAE,OAAO,CAAC;QACnB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,UAAU,CAAC,EAAE,MAAM,CAAC;KACrB,CAAC;I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EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKlD;;;;;;OAMG;IACG,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAO3D;;;;;;;;;;;;;OAaG;IACG,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAqB1D;;OAEG;IACH,UAAU,IAAI,OAAO;CAGtB;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,CAE7D"}
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* mempool.space API client for Bitcoin UTXO and fee data
|
|
3
|
+
*
|
|
4
|
+
* Public API endpoints (no authentication required):
|
|
5
|
+
* - Mainnet: https://mempool.space/api
|
|
6
|
+
* - Testnet: https://mempool.space/testnet/api
|
|
7
|
+
*
|
|
8
|
+
* Documentation: https://mempool.space/docs/api
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Get the mempool.space API base URL for a network
|
|
12
|
+
*/
|
|
13
|
+
export function getMempoolApiUrl(network) {
|
|
14
|
+
return network === "mainnet"
|
|
15
|
+
? "https://mempool.space/api"
|
|
16
|
+
: "https://mempool.space/testnet/api";
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get the mempool.space explorer URL for a network
|
|
20
|
+
*/
|
|
21
|
+
export function getMempoolExplorerUrl(network) {
|
|
22
|
+
return network === "mainnet"
|
|
23
|
+
? "https://mempool.space"
|
|
24
|
+
: "https://mempool.space/testnet";
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Get transaction explorer URL
|
|
28
|
+
*/
|
|
29
|
+
export function getMempoolTxUrl(txid, network) {
|
|
30
|
+
return `${getMempoolExplorerUrl(network)}/tx/${txid}`;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Get address explorer URL
|
|
34
|
+
*/
|
|
35
|
+
export function getMempoolAddressUrl(address, network) {
|
|
36
|
+
return `${getMempoolExplorerUrl(network)}/address/${address}`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* mempool.space API client
|
|
40
|
+
*/
|
|
41
|
+
export class MempoolApi {
|
|
42
|
+
baseUrl;
|
|
43
|
+
network;
|
|
44
|
+
constructor(network) {
|
|
45
|
+
this.network = network;
|
|
46
|
+
this.baseUrl = getMempoolApiUrl(network);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Get UTXOs for a Bitcoin address
|
|
50
|
+
*
|
|
51
|
+
* @param address - Bitcoin address (bc1... for mainnet, tb1... for testnet)
|
|
52
|
+
* @returns Array of UTXOs with txid, vout, value, and confirmation status
|
|
53
|
+
* @throws Error if API request fails
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```typescript
|
|
57
|
+
* const api = new MempoolApi('mainnet');
|
|
58
|
+
* const utxos = await api.getUtxos('bc1q...');
|
|
59
|
+
* const total = utxos.reduce((sum, u) => sum + u.value, 0);
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
async getUtxos(address) {
|
|
63
|
+
const response = await fetch(`${this.baseUrl}/address/${address}/utxo`);
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
const errorText = await response.text().catch(() => "Unknown error");
|
|
66
|
+
throw new Error(`Failed to fetch UTXOs for ${address}: ${response.status} ${response.statusText} - ${errorText}`);
|
|
67
|
+
}
|
|
68
|
+
const utxos = await response.json();
|
|
69
|
+
return utxos;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Get current recommended fee estimates
|
|
73
|
+
*
|
|
74
|
+
* @returns Fee estimates in sat/vB for different confirmation targets
|
|
75
|
+
* @throws Error if API request fails
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```typescript
|
|
79
|
+
* const api = new MempoolApi('mainnet');
|
|
80
|
+
* const fees = await api.getFeeEstimates();
|
|
81
|
+
* console.log(`Fast fee: ${fees.fastestFee} sat/vB`);
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
async getFeeEstimates() {
|
|
85
|
+
const response = await fetch(`${this.baseUrl}/v1/fees/recommended`);
|
|
86
|
+
if (!response.ok) {
|
|
87
|
+
const errorText = await response.text().catch(() => "Unknown error");
|
|
88
|
+
throw new Error(`Failed to fetch fee estimates: ${response.status} ${response.statusText} - ${errorText}`);
|
|
89
|
+
}
|
|
90
|
+
const fees = await response.json();
|
|
91
|
+
return fees;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get simplified fee tiers for user selection
|
|
95
|
+
*
|
|
96
|
+
* Maps mempool.space fee estimates to fast/medium/slow tiers:
|
|
97
|
+
* - Fast: fastestFee (~10 min)
|
|
98
|
+
* - Medium: halfHourFee (~30 min)
|
|
99
|
+
* - Slow: hourFee (~1 hour)
|
|
100
|
+
*
|
|
101
|
+
* @returns Fee tiers in sat/vB
|
|
102
|
+
* @throws Error if API request fails
|
|
103
|
+
*/
|
|
104
|
+
async getFeeTiers() {
|
|
105
|
+
const estimates = await this.getFeeEstimates();
|
|
106
|
+
return {
|
|
107
|
+
fast: estimates.fastestFee,
|
|
108
|
+
medium: estimates.halfHourFee,
|
|
109
|
+
slow: estimates.hourFee,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Get balance for a Bitcoin address (sum of UTXOs)
|
|
114
|
+
*
|
|
115
|
+
* @param address - Bitcoin address
|
|
116
|
+
* @returns Balance in satoshis
|
|
117
|
+
* @throws Error if API request fails
|
|
118
|
+
*/
|
|
119
|
+
async getBalance(address) {
|
|
120
|
+
const utxos = await this.getUtxos(address);
|
|
121
|
+
return utxos.reduce((sum, utxo) => sum + utxo.value, 0);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Get confirmed balance for a Bitcoin address
|
|
125
|
+
*
|
|
126
|
+
* @param address - Bitcoin address
|
|
127
|
+
* @returns Confirmed balance in satoshis (excludes unconfirmed UTXOs)
|
|
128
|
+
* @throws Error if API request fails
|
|
129
|
+
*/
|
|
130
|
+
async getConfirmedBalance(address) {
|
|
131
|
+
const utxos = await this.getUtxos(address);
|
|
132
|
+
return utxos
|
|
133
|
+
.filter((utxo) => utxo.status.confirmed)
|
|
134
|
+
.reduce((sum, utxo) => sum + utxo.value, 0);
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Broadcast a signed transaction to the Bitcoin network
|
|
138
|
+
*
|
|
139
|
+
* @param txHex - Signed transaction as hex string
|
|
140
|
+
* @returns Transaction ID (txid)
|
|
141
|
+
* @throws Error if broadcast fails
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```typescript
|
|
145
|
+
* const api = new MempoolApi('mainnet');
|
|
146
|
+
* const txid = await api.broadcastTransaction(signedTxHex);
|
|
147
|
+
* console.log(`Broadcast: ${getMempoolTxUrl(txid, 'mainnet')}`);
|
|
148
|
+
* ```
|
|
149
|
+
*/
|
|
150
|
+
async broadcastTransaction(txHex) {
|
|
151
|
+
const response = await fetch(`${this.baseUrl}/tx`, {
|
|
152
|
+
method: "POST",
|
|
153
|
+
headers: {
|
|
154
|
+
"Content-Type": "text/plain",
|
|
155
|
+
},
|
|
156
|
+
body: txHex,
|
|
157
|
+
});
|
|
158
|
+
if (!response.ok) {
|
|
159
|
+
const errorText = await response.text().catch(() => "Unknown error");
|
|
160
|
+
throw new Error(`Failed to broadcast transaction: ${response.status} ${response.statusText} - ${errorText}`);
|
|
161
|
+
}
|
|
162
|
+
// Response is the txid as plain text
|
|
163
|
+
const txid = await response.text();
|
|
164
|
+
return txid.trim();
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get the network this client is configured for
|
|
168
|
+
*/
|
|
169
|
+
getNetwork() {
|
|
170
|
+
return this.network;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Create a mempool.space API client for the given network
|
|
175
|
+
*/
|
|
176
|
+
export function createMempoolApi(network) {
|
|
177
|
+
return new MempoolApi(network);
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=mempool-api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mempool-api.js","sourceRoot":"","sources":["../../src/services/mempool-api.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA2EH;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAgB;IAC/C,OAAO,OAAO,KAAK,SAAS;QAC1B,CAAC,CAAC,2BAA2B;QAC7B,CAAC,CAAC,mCAAmC,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAAgB;IACpD,OAAO,OAAO,KAAK,SAAS;QAC1B,CAAC,CAAC,uBAAuB;QACzB,CAAC,CAAC,+BAA+B,CAAC;AACtC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,OAAgB;IAC5D,OAAO,GAAG,qBAAqB,CAAC,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;AACxD,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,OAAe,EAAE,OAAgB;IACpE,OAAO,GAAG,qBAAqB,CAAC,OAAO,CAAC,YAAY,OAAO,EAAE,CAAC;AAChE,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,UAAU;IACJ,OAAO,CAAS;IAChB,OAAO,CAAU;IAElC,YAAY,OAAgB;QAC1B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,KAAK,CAAC,QAAQ,CAAC,OAAe;QAC5B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,IAAI,CAAC,OAAO,YAAY,OAAO,OAAO,CAAC,CAAC;QAExE,IAAI,CAAC,QAAQ,CAAC,EAAE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C,OAAO,CAAC;IACtB,CAAC;CACF;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,OAAgB;IAC/C,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC;AACjC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet-manager.d.ts","sourceRoot":"","sources":["../../src/services/wallet-manager.ts"],"names":[],"mappings":"AAGA,OAAO,EAcL,KAAK,cAAc,EAEpB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EAAW,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"wallet-manager.d.ts","sourceRoot":"","sources":["../../src/services/wallet-manager.ts"],"names":[],"mappings":"AAGA,OAAO,EAcL,KAAK,cAAc,EAEpB,MAAM,mBAAmB,CAAC;AAM3B,OAAO,EAAW,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAa1D;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,cAAM,aAAa;IACjB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAgB;IACvC,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,SAAS,CAA+B;IAChD,OAAO,CAAC,WAAW,CAAS;IAE5B,OAAO;IAEP;;OAEG;IACH,MAAM,CAAC,WAAW,IAAI,aAAa;IAOnC;;OAEG;YACW,iBAAiB;IAO/B;;OAEG;IACG,YAAY,CAChB,IAAI,EAAE,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IAAI,CAAC;IAgBxD;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAY1B;;OAEG;IACH,OAAO,CAAC,kBAAkB;CAM3B;AAGD,wBAAgB,gBAAgB,IAAI,aAAa,CAEhD"}
|
|
@@ -4,6 +4,7 @@ import { wordlist } from "@scure/bip39/wordlists/english.js";
|
|
|
4
4
|
import { encrypt, decrypt, generateWalletId, initializeStorage, readWalletIndex, readKeystore, writeKeystore, readAppConfig, writeAppConfig, addWalletToIndex, removeWalletFromIndex, deleteWalletStorage, updateWalletMetadata, } from "../utils/index.js";
|
|
5
5
|
import { WalletNotFoundError, InvalidPasswordError, InvalidMnemonicError, } from "../utils/errors.js";
|
|
6
6
|
import { NETWORK } from "../config/networks.js";
|
|
7
|
+
import { deriveBitcoinAddress, deriveBitcoinKeyPair } from "../utils/bitcoin.js";
|
|
7
8
|
/**
|
|
8
9
|
* Wallet manager singleton - handles wallet creation, encryption, and session management
|
|
9
10
|
*/
|
|
@@ -46,6 +47,8 @@ class WalletManager {
|
|
|
46
47
|
});
|
|
47
48
|
const stacksAccount = wallet.accounts[0];
|
|
48
49
|
const address = getStxAddress(stacksAccount, walletNetwork);
|
|
50
|
+
// Derive Bitcoin address
|
|
51
|
+
const { address: btcAddress } = deriveBitcoinAddress(mnemonic, walletNetwork);
|
|
49
52
|
// Encrypt mnemonic
|
|
50
53
|
const encrypted = await encrypt(mnemonic, password);
|
|
51
54
|
// Generate wallet ID
|
|
@@ -63,6 +66,7 @@ class WalletManager {
|
|
|
63
66
|
id: walletId,
|
|
64
67
|
name,
|
|
65
68
|
address,
|
|
69
|
+
btcAddress,
|
|
66
70
|
network: walletNetwork,
|
|
67
71
|
createdAt: new Date().toISOString(),
|
|
68
72
|
};
|
|
@@ -95,6 +99,8 @@ class WalletManager {
|
|
|
95
99
|
});
|
|
96
100
|
const stacksAccount = wallet.accounts[0];
|
|
97
101
|
const address = getStxAddress(stacksAccount, walletNetwork);
|
|
102
|
+
// Derive Bitcoin address
|
|
103
|
+
const { address: btcAddress } = deriveBitcoinAddress(normalizedMnemonic, walletNetwork);
|
|
98
104
|
// Encrypt mnemonic
|
|
99
105
|
const encrypted = await encrypt(normalizedMnemonic, password);
|
|
100
106
|
// Generate wallet ID
|
|
@@ -112,6 +118,7 @@ class WalletManager {
|
|
|
112
118
|
id: walletId,
|
|
113
119
|
name,
|
|
114
120
|
address,
|
|
121
|
+
btcAddress,
|
|
115
122
|
network: walletNetwork,
|
|
116
123
|
createdAt: new Date().toISOString(),
|
|
117
124
|
};
|
|
@@ -159,9 +166,14 @@ class WalletManager {
|
|
|
159
166
|
});
|
|
160
167
|
const stacksAccount = wallet.accounts[0];
|
|
161
168
|
const address = getStxAddress(stacksAccount, walletMeta.network);
|
|
169
|
+
// Derive Bitcoin key pair (includes private key for signing)
|
|
170
|
+
const { address: btcAddress, privateKey: btcPrivateKey, publicKeyBytes: btcPublicKey, } = deriveBitcoinKeyPair(mnemonic, walletMeta.network);
|
|
162
171
|
const account = {
|
|
163
172
|
address,
|
|
173
|
+
btcAddress,
|
|
164
174
|
privateKey: stacksAccount.stxPrivateKey,
|
|
175
|
+
btcPrivateKey,
|
|
176
|
+
btcPublicKey,
|
|
165
177
|
network: walletMeta.network,
|
|
166
178
|
};
|
|
167
179
|
// Update last used timestamp
|
|
@@ -229,6 +241,7 @@ class WalletManager {
|
|
|
229
241
|
return {
|
|
230
242
|
walletId: this.session.walletId,
|
|
231
243
|
address: this.session.account.address,
|
|
244
|
+
btcAddress: this.session.account.btcAddress,
|
|
232
245
|
expiresAt: this.session.expiresAt,
|
|
233
246
|
};
|
|
234
247
|
}
|