@aibtc/mcp-server 1.0.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 +340 -0
- package/dist/api.d.ts +9 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +79 -0
- package/dist/api.js.map +1 -0
- package/dist/config/contracts.d.ts +169 -0
- package/dist/config/contracts.d.ts.map +1 -0
- package/dist/config/contracts.js +250 -0
- package/dist/config/contracts.js.map +1 -0
- package/dist/config/index.d.ts +3 -0
- package/dist/config/index.d.ts.map +1 -0
- package/dist/config/index.js +3 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/networks.d.ts +11 -0
- package/dist/config/networks.d.ts.map +1 -0
- package/dist/config/networks.js +21 -0
- package/dist/config/networks.js.map +1 -0
- package/dist/endpoints/index.d.ts +2 -0
- package/dist/endpoints/index.d.ts.map +1 -0
- package/dist/endpoints/index.js +2 -0
- package/dist/endpoints/index.js.map +1 -0
- package/dist/endpoints/registry.d.ts +38 -0
- package/dist/endpoints/registry.d.ts.map +1 -0
- package/dist/endpoints/registry.js +935 -0
- package/dist/endpoints/registry.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +79 -0
- package/dist/index.js.map +1 -0
- package/dist/services/bitflow.service.d.ts +159 -0
- package/dist/services/bitflow.service.d.ts.map +1 -0
- package/dist/services/bitflow.service.js +325 -0
- package/dist/services/bitflow.service.js.map +1 -0
- package/dist/services/bns.service.d.ts +87 -0
- package/dist/services/bns.service.d.ts.map +1 -0
- package/dist/services/bns.service.js +312 -0
- package/dist/services/bns.service.js.map +1 -0
- package/dist/services/defi.service.d.ts +146 -0
- package/dist/services/defi.service.d.ts.map +1 -0
- package/dist/services/defi.service.js +461 -0
- package/dist/services/defi.service.js.map +1 -0
- package/dist/services/hiro-api.d.ts +438 -0
- package/dist/services/hiro-api.d.ts.map +1 -0
- package/dist/services/hiro-api.js +376 -0
- package/dist/services/hiro-api.js.map +1 -0
- package/dist/services/nft.service.d.ts +70 -0
- package/dist/services/nft.service.d.ts.map +1 -0
- package/dist/services/nft.service.js +148 -0
- package/dist/services/nft.service.js.map +1 -0
- package/dist/services/sbtc.service.d.ts +44 -0
- package/dist/services/sbtc.service.d.ts.map +1 -0
- package/dist/services/sbtc.service.js +100 -0
- package/dist/services/sbtc.service.js.map +1 -0
- package/dist/services/scaffold.service.d.ts +41 -0
- package/dist/services/scaffold.service.d.ts.map +1 -0
- package/dist/services/scaffold.service.js +1055 -0
- package/dist/services/scaffold.service.js.map +1 -0
- package/dist/services/stacking.service.d.ts +58 -0
- package/dist/services/stacking.service.d.ts.map +1 -0
- package/dist/services/stacking.service.js +153 -0
- package/dist/services/stacking.service.js.map +1 -0
- package/dist/services/tokens.service.d.ts +62 -0
- package/dist/services/tokens.service.d.ts.map +1 -0
- package/dist/services/tokens.service.js +119 -0
- package/dist/services/tokens.service.js.map +1 -0
- package/dist/services/wallet-manager.d.ts +107 -0
- package/dist/services/wallet-manager.d.ts.map +1 -0
- package/dist/services/wallet-manager.js +389 -0
- package/dist/services/wallet-manager.js.map +1 -0
- package/dist/services/x402.service.d.ts +26 -0
- package/dist/services/x402.service.d.ts.map +1 -0
- package/dist/services/x402.service.js +125 -0
- package/dist/services/x402.service.js.map +1 -0
- package/dist/tools/bitflow.tools.d.ts +3 -0
- package/dist/tools/bitflow.tools.d.ts.map +1 -0
- package/dist/tools/bitflow.tools.js +501 -0
- package/dist/tools/bitflow.tools.js.map +1 -0
- package/dist/tools/bns.tools.d.ts +3 -0
- package/dist/tools/bns.tools.d.ts.map +1 -0
- package/dist/tools/bns.tools.js +164 -0
- package/dist/tools/bns.tools.js.map +1 -0
- package/dist/tools/contract.tools.d.ts +3 -0
- package/dist/tools/contract.tools.d.ts.map +1 -0
- package/dist/tools/contract.tools.js +126 -0
- package/dist/tools/contract.tools.js.map +1 -0
- package/dist/tools/defi.tools.d.ts +3 -0
- package/dist/tools/defi.tools.d.ts.map +1 -0
- package/dist/tools/defi.tools.js +425 -0
- package/dist/tools/defi.tools.js.map +1 -0
- package/dist/tools/endpoint.tools.d.ts +3 -0
- package/dist/tools/endpoint.tools.d.ts.map +1 -0
- package/dist/tools/endpoint.tools.js +157 -0
- package/dist/tools/endpoint.tools.js.map +1 -0
- package/dist/tools/index.d.ts +6 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +52 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/nft.tools.d.ts +3 -0
- package/dist/tools/nft.tools.d.ts.map +1 -0
- package/dist/tools/nft.tools.js +154 -0
- package/dist/tools/nft.tools.js.map +1 -0
- package/dist/tools/openrouter.tools.d.ts +3 -0
- package/dist/tools/openrouter.tools.d.ts.map +1 -0
- package/dist/tools/openrouter.tools.js +664 -0
- package/dist/tools/openrouter.tools.js.map +1 -0
- package/dist/tools/query.tools.d.ts +3 -0
- package/dist/tools/query.tools.d.ts.map +1 -0
- package/dist/tools/query.tools.js +209 -0
- package/dist/tools/query.tools.js.map +1 -0
- package/dist/tools/sbtc.tools.d.ts +3 -0
- package/dist/tools/sbtc.tools.d.ts.map +1 -0
- package/dist/tools/sbtc.tools.js +103 -0
- package/dist/tools/sbtc.tools.js.map +1 -0
- package/dist/tools/scaffold.tools.d.ts +3 -0
- package/dist/tools/scaffold.tools.d.ts.map +1 -0
- package/dist/tools/scaffold.tools.js +216 -0
- package/dist/tools/scaffold.tools.js.map +1 -0
- package/dist/tools/stacking.tools.d.ts +3 -0
- package/dist/tools/stacking.tools.d.ts.map +1 -0
- package/dist/tools/stacking.tools.js +112 -0
- package/dist/tools/stacking.tools.js.map +1 -0
- package/dist/tools/tokens.tools.d.ts +3 -0
- package/dist/tools/tokens.tools.d.ts.map +1 -0
- package/dist/tools/tokens.tools.js +154 -0
- package/dist/tools/tokens.tools.js.map +1 -0
- package/dist/tools/transfer.tools.d.ts +3 -0
- package/dist/tools/transfer.tools.d.ts.map +1 -0
- package/dist/tools/transfer.tools.js +62 -0
- package/dist/tools/transfer.tools.js.map +1 -0
- package/dist/tools/wallet-management.tools.d.ts +6 -0
- package/dist/tools/wallet-management.tools.d.ts.map +1 -0
- package/dist/tools/wallet-management.tools.js +390 -0
- package/dist/tools/wallet-management.tools.js.map +1 -0
- package/dist/tools/wallet.tools.d.ts +3 -0
- package/dist/tools/wallet.tools.d.ts.map +1 -0
- package/dist/tools/wallet.tools.js +105 -0
- package/dist/tools/wallet.tools.js.map +1 -0
- package/dist/transactions/builder.d.ts +56 -0
- package/dist/transactions/builder.d.ts.map +1 -0
- package/dist/transactions/builder.js +134 -0
- package/dist/transactions/builder.js.map +1 -0
- package/dist/transactions/clarity-values.d.ts +67 -0
- package/dist/transactions/clarity-values.d.ts.map +1 -0
- package/dist/transactions/clarity-values.js +169 -0
- package/dist/transactions/clarity-values.js.map +1 -0
- package/dist/transactions/post-conditions.d.ts +27 -0
- package/dist/transactions/post-conditions.d.ts.map +1 -0
- package/dist/transactions/post-conditions.js +101 -0
- package/dist/transactions/post-conditions.js.map +1 -0
- package/dist/utils/encryption.d.ts +33 -0
- package/dist/utils/encryption.d.ts.map +1 -0
- package/dist/utils/encryption.js +110 -0
- package/dist/utils/encryption.js.map +1 -0
- package/dist/utils/errors.d.ts +84 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +132 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/formatting.d.ts +51 -0
- package/dist/utils/formatting.d.ts.map +1 -0
- package/dist/utils/formatting.js +114 -0
- package/dist/utils/formatting.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +6 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/storage.d.ts +90 -0
- package/dist/utils/storage.d.ts.map +1 -0
- package/dist/utils/storage.js +196 -0
- package/dist/utils/storage.js.map +1 -0
- package/dist/utils/validation.d.ts +67 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +74 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/wallet.d.ts +86 -0
- package/dist/wallet.d.ts.map +1 -0
- package/dist/wallet.js +279 -0
- package/dist/wallet.js.map +1 -0
- package/package.json +58 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { createJsonResponse, createErrorResponse } from "../utils/index.js";
|
|
3
|
+
import { getWalletManager } from "../services/wallet-manager.js";
|
|
4
|
+
import { NETWORK } from "../config/networks.js";
|
|
5
|
+
/**
|
|
6
|
+
* Register wallet management tools
|
|
7
|
+
*/
|
|
8
|
+
export function registerWalletManagementTools(server) {
|
|
9
|
+
/**
|
|
10
|
+
* Create a new wallet with BIP39 mnemonic
|
|
11
|
+
*/
|
|
12
|
+
server.registerTool("wallet_create", {
|
|
13
|
+
description: `Create a new wallet for the agent with a generated BIP39 24-word mnemonic.
|
|
14
|
+
The wallet is encrypted locally and stored in ~/.aibtc/.
|
|
15
|
+
IMPORTANT: Save the mnemonic securely - it will only be shown once!`,
|
|
16
|
+
inputSchema: {
|
|
17
|
+
name: z.string().describe("Name for the wallet (e.g., 'main', 'trading')"),
|
|
18
|
+
password: z
|
|
19
|
+
.string()
|
|
20
|
+
.min(8)
|
|
21
|
+
.describe("Password to protect the wallet (minimum 8 characters)"),
|
|
22
|
+
network: z
|
|
23
|
+
.enum(["mainnet", "testnet"])
|
|
24
|
+
.optional()
|
|
25
|
+
.describe("Network for the wallet (default: current network)"),
|
|
26
|
+
},
|
|
27
|
+
}, async ({ name, password, network }) => {
|
|
28
|
+
try {
|
|
29
|
+
const walletManager = getWalletManager();
|
|
30
|
+
const result = await walletManager.createWallet(name, password, network);
|
|
31
|
+
return createJsonResponse({
|
|
32
|
+
success: true,
|
|
33
|
+
message: "I now have a wallet! Here are the details. Please save the mnemonic securely.",
|
|
34
|
+
walletId: result.walletId,
|
|
35
|
+
address: result.address,
|
|
36
|
+
network: network || NETWORK,
|
|
37
|
+
mnemonic: result.mnemonic,
|
|
38
|
+
warning: "CRITICAL: Save this mnemonic phrase securely! It will NOT be shown again. " +
|
|
39
|
+
"This is the only way to recover the wallet if the password is forgotten.",
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
return createErrorResponse(error);
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
/**
|
|
47
|
+
* Import an existing wallet from mnemonic
|
|
48
|
+
*/
|
|
49
|
+
server.registerTool("wallet_import", {
|
|
50
|
+
description: `Import an existing wallet for the agent using a BIP39 mnemonic phrase.
|
|
51
|
+
The wallet is encrypted locally and stored in ~/.aibtc/.`,
|
|
52
|
+
inputSchema: {
|
|
53
|
+
name: z.string().describe("Name for the wallet"),
|
|
54
|
+
mnemonic: z.string().describe("24-word BIP39 mnemonic phrase"),
|
|
55
|
+
password: z
|
|
56
|
+
.string()
|
|
57
|
+
.min(8)
|
|
58
|
+
.describe("Password to protect the wallet (minimum 8 characters)"),
|
|
59
|
+
network: z
|
|
60
|
+
.enum(["mainnet", "testnet"])
|
|
61
|
+
.optional()
|
|
62
|
+
.describe("Network for the wallet (default: current network)"),
|
|
63
|
+
},
|
|
64
|
+
}, async ({ name, mnemonic, password, network }) => {
|
|
65
|
+
try {
|
|
66
|
+
const walletManager = getWalletManager();
|
|
67
|
+
const result = await walletManager.importWallet(name, mnemonic, password, network);
|
|
68
|
+
return createJsonResponse({
|
|
69
|
+
success: true,
|
|
70
|
+
message: "I now have access to this wallet and I'm ready to perform transactions.",
|
|
71
|
+
walletId: result.walletId,
|
|
72
|
+
address: result.address,
|
|
73
|
+
network: network || NETWORK,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
return createErrorResponse(error);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
/**
|
|
81
|
+
* Unlock a wallet for use
|
|
82
|
+
*/
|
|
83
|
+
server.registerTool("wallet_unlock", {
|
|
84
|
+
description: `Unlock the agent's wallet to enable transactions.
|
|
85
|
+
If no wallet ID is provided, unlocks the active wallet.`,
|
|
86
|
+
inputSchema: {
|
|
87
|
+
walletId: z
|
|
88
|
+
.string()
|
|
89
|
+
.optional()
|
|
90
|
+
.describe("Wallet ID to unlock (uses active wallet if not specified)"),
|
|
91
|
+
password: z.string().describe("Wallet password"),
|
|
92
|
+
},
|
|
93
|
+
}, async ({ walletId, password }) => {
|
|
94
|
+
try {
|
|
95
|
+
const walletManager = getWalletManager();
|
|
96
|
+
// Get wallet ID to unlock
|
|
97
|
+
let targetWalletId = walletId;
|
|
98
|
+
if (!targetWalletId) {
|
|
99
|
+
const activeId = await walletManager.getActiveWalletId();
|
|
100
|
+
if (!activeId) {
|
|
101
|
+
return createErrorResponse(new Error("I don't have a wallet yet. Use wallet_create to give me one, or wallet_list to see available wallets."));
|
|
102
|
+
}
|
|
103
|
+
targetWalletId = activeId;
|
|
104
|
+
}
|
|
105
|
+
const account = await walletManager.unlock(targetWalletId, password);
|
|
106
|
+
return createJsonResponse({
|
|
107
|
+
success: true,
|
|
108
|
+
message: "My wallet is now unlocked. I can perform transactions.",
|
|
109
|
+
walletId: targetWalletId,
|
|
110
|
+
address: account.address,
|
|
111
|
+
network: account.network,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
return createErrorResponse(error);
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
/**
|
|
119
|
+
* Lock the wallet (clear from memory)
|
|
120
|
+
*/
|
|
121
|
+
server.registerTool("wallet_lock", {
|
|
122
|
+
description: "Lock the agent's wallet, clearing sensitive data from memory.",
|
|
123
|
+
}, async () => {
|
|
124
|
+
try {
|
|
125
|
+
const walletManager = getWalletManager();
|
|
126
|
+
const wasUnlocked = walletManager.isUnlocked();
|
|
127
|
+
walletManager.lock();
|
|
128
|
+
return createJsonResponse({
|
|
129
|
+
success: true,
|
|
130
|
+
message: wasUnlocked
|
|
131
|
+
? "My wallet is now locked. I'll need it unlocked again to perform transactions."
|
|
132
|
+
: "My wallet was already locked.",
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
return createErrorResponse(error);
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
/**
|
|
140
|
+
* List available wallets
|
|
141
|
+
*/
|
|
142
|
+
server.registerTool("wallet_list", {
|
|
143
|
+
description: "List all wallets available for the agent to use.",
|
|
144
|
+
}, async () => {
|
|
145
|
+
try {
|
|
146
|
+
const walletManager = getWalletManager();
|
|
147
|
+
const wallets = await walletManager.listWallets();
|
|
148
|
+
const activeWalletId = await walletManager.getActiveWalletId();
|
|
149
|
+
const sessionInfo = walletManager.getSessionInfo();
|
|
150
|
+
if (wallets.length === 0) {
|
|
151
|
+
return createJsonResponse({
|
|
152
|
+
message: "I don't have any wallets yet. Use wallet_create to give me one.",
|
|
153
|
+
wallets: [],
|
|
154
|
+
totalCount: 0,
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
return createJsonResponse({
|
|
158
|
+
message: `I have ${wallets.length} wallet(s) available.`,
|
|
159
|
+
wallets: wallets.map((w) => ({
|
|
160
|
+
id: w.id,
|
|
161
|
+
name: w.name,
|
|
162
|
+
address: w.address,
|
|
163
|
+
network: w.network,
|
|
164
|
+
createdAt: w.createdAt,
|
|
165
|
+
lastUsed: w.lastUsed,
|
|
166
|
+
isActive: w.id === activeWalletId,
|
|
167
|
+
isUnlocked: sessionInfo?.walletId === w.id,
|
|
168
|
+
})),
|
|
169
|
+
totalCount: wallets.length,
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
catch (error) {
|
|
173
|
+
return createErrorResponse(error);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
/**
|
|
177
|
+
* Switch active wallet
|
|
178
|
+
*/
|
|
179
|
+
server.registerTool("wallet_switch", {
|
|
180
|
+
description: `Switch to a different wallet.
|
|
181
|
+
Note: The new wallet will need to be unlocked before use.`,
|
|
182
|
+
inputSchema: {
|
|
183
|
+
walletId: z.string().describe("Wallet ID to switch to"),
|
|
184
|
+
},
|
|
185
|
+
}, async ({ walletId }) => {
|
|
186
|
+
try {
|
|
187
|
+
const walletManager = getWalletManager();
|
|
188
|
+
await walletManager.switchWallet(walletId);
|
|
189
|
+
// Get wallet info
|
|
190
|
+
const wallets = await walletManager.listWallets();
|
|
191
|
+
const wallet = wallets.find((w) => w.id === walletId);
|
|
192
|
+
return createJsonResponse({
|
|
193
|
+
success: true,
|
|
194
|
+
activeWalletId: walletId,
|
|
195
|
+
address: wallet?.address,
|
|
196
|
+
network: wallet?.network,
|
|
197
|
+
message: "Switched to wallet. Use wallet_unlock to unlock it for transactions.",
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
catch (error) {
|
|
201
|
+
return createErrorResponse(error);
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
/**
|
|
205
|
+
* Delete a wallet
|
|
206
|
+
*/
|
|
207
|
+
server.registerTool("wallet_delete", {
|
|
208
|
+
description: `Permanently delete a wallet.
|
|
209
|
+
WARNING: This cannot be undone! Make sure you have backed up your mnemonic.`,
|
|
210
|
+
inputSchema: {
|
|
211
|
+
walletId: z.string().describe("Wallet ID to delete"),
|
|
212
|
+
password: z.string().describe("Wallet password for confirmation"),
|
|
213
|
+
confirm: z
|
|
214
|
+
.literal("DELETE")
|
|
215
|
+
.describe("Type 'DELETE' to confirm deletion"),
|
|
216
|
+
},
|
|
217
|
+
}, async ({ walletId, password, confirm }) => {
|
|
218
|
+
try {
|
|
219
|
+
if (confirm !== "DELETE") {
|
|
220
|
+
return createErrorResponse(new Error("Confirmation required: set confirm to 'DELETE'"));
|
|
221
|
+
}
|
|
222
|
+
const walletManager = getWalletManager();
|
|
223
|
+
// Get wallet info before deletion
|
|
224
|
+
const wallets = await walletManager.listWallets();
|
|
225
|
+
const wallet = wallets.find((w) => w.id === walletId);
|
|
226
|
+
await walletManager.deleteWallet(walletId, password);
|
|
227
|
+
return createJsonResponse({
|
|
228
|
+
success: true,
|
|
229
|
+
deletedWalletId: walletId,
|
|
230
|
+
deletedAddress: wallet?.address,
|
|
231
|
+
message: "Wallet deleted permanently.",
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
catch (error) {
|
|
235
|
+
return createErrorResponse(error);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
/**
|
|
239
|
+
* Export mnemonic (with security warning)
|
|
240
|
+
*/
|
|
241
|
+
server.registerTool("wallet_export", {
|
|
242
|
+
description: `Export the mnemonic phrase for a wallet.
|
|
243
|
+
WARNING: Only use this in a secure environment! Anyone with the mnemonic can access your funds.`,
|
|
244
|
+
inputSchema: {
|
|
245
|
+
walletId: z
|
|
246
|
+
.string()
|
|
247
|
+
.optional()
|
|
248
|
+
.describe("Wallet ID to export (uses active wallet if not specified)"),
|
|
249
|
+
password: z.string().describe("Wallet password"),
|
|
250
|
+
confirm: z
|
|
251
|
+
.literal("I_UNDERSTAND_THE_RISKS")
|
|
252
|
+
.describe("Type 'I_UNDERSTAND_THE_RISKS' to confirm"),
|
|
253
|
+
},
|
|
254
|
+
}, async ({ walletId, password, confirm }) => {
|
|
255
|
+
try {
|
|
256
|
+
if (confirm !== "I_UNDERSTAND_THE_RISKS") {
|
|
257
|
+
return createErrorResponse(new Error("Confirmation required: set confirm to 'I_UNDERSTAND_THE_RISKS'"));
|
|
258
|
+
}
|
|
259
|
+
const walletManager = getWalletManager();
|
|
260
|
+
// Get wallet ID
|
|
261
|
+
let targetWalletId = walletId;
|
|
262
|
+
if (!targetWalletId) {
|
|
263
|
+
const activeId = await walletManager.getActiveWalletId();
|
|
264
|
+
if (!activeId) {
|
|
265
|
+
return createErrorResponse(new Error("No wallet specified and no active wallet set."));
|
|
266
|
+
}
|
|
267
|
+
targetWalletId = activeId;
|
|
268
|
+
}
|
|
269
|
+
const mnemonic = await walletManager.exportMnemonic(targetWalletId, password);
|
|
270
|
+
return createJsonResponse({
|
|
271
|
+
walletId: targetWalletId,
|
|
272
|
+
mnemonic,
|
|
273
|
+
warning: "SECURITY WARNING: This mnemonic provides full access to your wallet. " +
|
|
274
|
+
"Store it securely and never share it with anyone.",
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
catch (error) {
|
|
278
|
+
return createErrorResponse(error);
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
/**
|
|
282
|
+
* Set auto-lock timeout
|
|
283
|
+
*/
|
|
284
|
+
server.registerTool("wallet_set_timeout", {
|
|
285
|
+
description: "Set how long the agent's wallet stays unlocked before automatically locking. Set to 0 to disable auto-lock.",
|
|
286
|
+
inputSchema: {
|
|
287
|
+
minutes: z
|
|
288
|
+
.number()
|
|
289
|
+
.min(0)
|
|
290
|
+
.describe("Minutes until auto-lock (0 = never auto-lock)"),
|
|
291
|
+
},
|
|
292
|
+
}, async ({ minutes }) => {
|
|
293
|
+
try {
|
|
294
|
+
const walletManager = getWalletManager();
|
|
295
|
+
await walletManager.setAutoLockTimeout(minutes);
|
|
296
|
+
const message = minutes === 0
|
|
297
|
+
? "Auto-lock disabled. My wallet will stay unlocked until manually locked."
|
|
298
|
+
: `Auto-lock set to ${minutes} minutes. My wallet will lock automatically after ${minutes} minutes of inactivity.`;
|
|
299
|
+
return createJsonResponse({
|
|
300
|
+
success: true,
|
|
301
|
+
message,
|
|
302
|
+
autoLockMinutes: minutes,
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
catch (error) {
|
|
306
|
+
return createErrorResponse(error);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
/**
|
|
310
|
+
* Get wallet status
|
|
311
|
+
*/
|
|
312
|
+
server.registerTool("wallet_status", {
|
|
313
|
+
description: "Get the agent's wallet status - whether it has a wallet, if it's unlocked, and what it can do.",
|
|
314
|
+
}, async () => {
|
|
315
|
+
try {
|
|
316
|
+
const walletManager = getWalletManager();
|
|
317
|
+
const sessionInfo = walletManager.getSessionInfo();
|
|
318
|
+
const activeWalletId = await walletManager.getActiveWalletId();
|
|
319
|
+
const hasWallets = await walletManager.hasWallets();
|
|
320
|
+
const hasMnemonic = !!process.env.CLIENT_MNEMONIC;
|
|
321
|
+
// Determine source and ready state
|
|
322
|
+
let readyForTransactions = false;
|
|
323
|
+
let message;
|
|
324
|
+
let nextAction = null;
|
|
325
|
+
if (sessionInfo) {
|
|
326
|
+
readyForTransactions = true;
|
|
327
|
+
message = "I have a wallet and it's unlocked. I can perform transactions.";
|
|
328
|
+
}
|
|
329
|
+
else if (hasMnemonic) {
|
|
330
|
+
readyForTransactions = true;
|
|
331
|
+
message = "I have a wallet configured and I'm ready to perform transactions.";
|
|
332
|
+
}
|
|
333
|
+
else if (hasWallets) {
|
|
334
|
+
message = "I have a wallet but it's locked. Please unlock it so I can perform transactions.";
|
|
335
|
+
nextAction = "Use wallet_unlock with the wallet password.";
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
message = "I don't have a wallet yet. Please assign me one so I can perform transactions.";
|
|
339
|
+
nextAction = "Use wallet_create to give me a new wallet, or wallet_import to assign an existing one.";
|
|
340
|
+
}
|
|
341
|
+
// Get active wallet info if exists
|
|
342
|
+
let activeWallet = null;
|
|
343
|
+
if (activeWalletId) {
|
|
344
|
+
const wallets = await walletManager.listWallets();
|
|
345
|
+
const wallet = wallets.find((w) => w.id === activeWalletId);
|
|
346
|
+
if (wallet) {
|
|
347
|
+
activeWallet = {
|
|
348
|
+
id: wallet.id,
|
|
349
|
+
name: wallet.name,
|
|
350
|
+
address: wallet.address,
|
|
351
|
+
network: wallet.network,
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
// Build response
|
|
356
|
+
const response = {
|
|
357
|
+
message,
|
|
358
|
+
readyForTransactions,
|
|
359
|
+
isUnlocked: !!sessionInfo,
|
|
360
|
+
currentNetwork: NETWORK,
|
|
361
|
+
};
|
|
362
|
+
if (sessionInfo) {
|
|
363
|
+
response.wallet = {
|
|
364
|
+
id: sessionInfo.walletId,
|
|
365
|
+
address: sessionInfo.address,
|
|
366
|
+
sessionExpiresAt: sessionInfo.expiresAt?.toISOString() || "never",
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
else if (activeWallet) {
|
|
370
|
+
response.wallet = activeWallet;
|
|
371
|
+
}
|
|
372
|
+
if (hasWallets && !sessionInfo && !hasMnemonic) {
|
|
373
|
+
const wallets = await walletManager.listWallets();
|
|
374
|
+
response.availableWallets = wallets.map((w) => ({
|
|
375
|
+
id: w.id,
|
|
376
|
+
name: w.name,
|
|
377
|
+
address: w.address,
|
|
378
|
+
}));
|
|
379
|
+
}
|
|
380
|
+
if (nextAction) {
|
|
381
|
+
response.nextAction = nextAction;
|
|
382
|
+
}
|
|
383
|
+
return createJsonResponse(response);
|
|
384
|
+
}
|
|
385
|
+
catch (error) {
|
|
386
|
+
return createErrorResponse(error);
|
|
387
|
+
}
|
|
388
|
+
});
|
|
389
|
+
}
|
|
390
|
+
//# sourceMappingURL=wallet-management.tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet-management.tools.js","sourceRoot":"","sources":["../../src/tools/wallet-management.tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,OAAO,EAAW,MAAM,uBAAuB,CAAC;AAEzD;;GAEG;AACH,MAAM,UAAU,6BAA6B,CAAC,MAAiB;IAC7D;;OAEG;IACH,MAAM,CAAC,YAAY,CACjB,eAAe,EACf;QACE,WAAW,EAAE;;oEAEiD;QAC9D,WAAW,EAAE;YACX,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,+CAA+C,CAAC;YAC1E,QAAQ,EAAE,CAAC;iBACR,MAAM,EAAE;iBACR,GAAG,CAAC,CA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ACnB,CAAC,CAAC,CAAC;YACN,CAAC;YAED,IAAI,UAAU,EAAE,CAAC;gBACf,QAAQ,CAAC,UAAU,GAAG,UAAU,CAAC;YACnC,CAAC;YAED,OAAO,kBAAkB,CAAC,QAAQ,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAC;QACpC,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.tools.d.ts","sourceRoot":"","sources":["../../src/tools/wallet.tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAOpE,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,SAAS,GAAG,IAAI,CA+G3D"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { getWalletAddress, NETWORK, API_URL } from "../services/x402.service.js";
|
|
3
|
+
import { getStxBalance } from "../services/hiro-api.js";
|
|
4
|
+
import { createJsonResponse, createErrorResponse } from "../utils/index.js";
|
|
5
|
+
import { getWalletManager } from "../services/wallet-manager.js";
|
|
6
|
+
export function registerWalletTools(server) {
|
|
7
|
+
// Get wallet info
|
|
8
|
+
server.registerTool("get_wallet_info", {
|
|
9
|
+
description: "Get the agent's wallet address and status. " +
|
|
10
|
+
"If the agent doesn't have a wallet yet, provides guidance on how to assign one.",
|
|
11
|
+
}, async () => {
|
|
12
|
+
try {
|
|
13
|
+
const walletManager = getWalletManager();
|
|
14
|
+
const hasWallets = await walletManager.hasWallets();
|
|
15
|
+
const sessionInfo = walletManager.getSessionInfo();
|
|
16
|
+
const hasMnemonic = !!process.env.CLIENT_MNEMONIC;
|
|
17
|
+
// Try to get wallet address
|
|
18
|
+
try {
|
|
19
|
+
const address = await getWalletAddress();
|
|
20
|
+
return createJsonResponse({
|
|
21
|
+
status: "ready",
|
|
22
|
+
message: "I have a wallet and I'm ready to perform transactions.",
|
|
23
|
+
address,
|
|
24
|
+
network: NETWORK,
|
|
25
|
+
apiUrl: API_URL,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
// No wallet available - provide helpful guidance
|
|
30
|
+
if (hasWallets) {
|
|
31
|
+
// Has wallets but not unlocked
|
|
32
|
+
const wallets = await walletManager.listWallets();
|
|
33
|
+
return createJsonResponse({
|
|
34
|
+
status: "locked",
|
|
35
|
+
message: "I have a wallet but it's locked. Please unlock it so I can perform transactions.",
|
|
36
|
+
wallets: wallets.map((w) => ({
|
|
37
|
+
id: w.id,
|
|
38
|
+
name: w.name,
|
|
39
|
+
address: w.address,
|
|
40
|
+
network: w.network,
|
|
41
|
+
})),
|
|
42
|
+
network: NETWORK,
|
|
43
|
+
hint: "Use wallet_unlock with the wallet password to unlock.",
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// No wallets at all
|
|
48
|
+
return createJsonResponse({
|
|
49
|
+
status: "no_wallet",
|
|
50
|
+
message: "I don't have a wallet yet. Would you like to assign me one? " +
|
|
51
|
+
"You can create a fresh wallet for me or import an existing one.",
|
|
52
|
+
network: NETWORK,
|
|
53
|
+
options: [
|
|
54
|
+
{
|
|
55
|
+
action: "wallet_create",
|
|
56
|
+
description: "Create a new wallet for the agent (generates a secure 24-word mnemonic)",
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
action: "wallet_import",
|
|
60
|
+
description: "Import an existing wallet for the agent to use",
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
hint: "Use wallet_create with a name and password to give me a wallet.",
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
return createErrorResponse(error);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
// Get STX balance
|
|
73
|
+
server.registerTool("get_stx_balance", {
|
|
74
|
+
description: "Get the STX balance for a wallet address.",
|
|
75
|
+
inputSchema: {
|
|
76
|
+
address: z
|
|
77
|
+
.string()
|
|
78
|
+
.optional()
|
|
79
|
+
.describe("Wallet address to check. Uses configured wallet if not provided."),
|
|
80
|
+
},
|
|
81
|
+
}, async ({ address }) => {
|
|
82
|
+
try {
|
|
83
|
+
const walletAddress = address || (await getWalletAddress());
|
|
84
|
+
const balance = await getStxBalance(walletAddress, NETWORK);
|
|
85
|
+
const stxBalance = (BigInt(balance.stx) / BigInt(1000000)).toString();
|
|
86
|
+
const stxLocked = (BigInt(balance.stxLocked) / BigInt(1000000)).toString();
|
|
87
|
+
return createJsonResponse({
|
|
88
|
+
address: walletAddress,
|
|
89
|
+
network: NETWORK,
|
|
90
|
+
balance: {
|
|
91
|
+
stx: stxBalance + " STX",
|
|
92
|
+
microStx: balance.stx,
|
|
93
|
+
},
|
|
94
|
+
locked: {
|
|
95
|
+
stx: stxLocked + " STX",
|
|
96
|
+
microStx: balance.stxLocked,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
return createErrorResponse(error);
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=wallet.tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wallet.tools.js","sourceRoot":"","sources":["../../src/tools/wallet.tools.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,6BAA6B,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC5E,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEjE,MAAM,UAAU,mBAAmB,CA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AAG,EAAE,UAAU,GAAG,MAAM;oBACxB,QAAQ,EAAE,OAAO,CAAC,GAAG;iBACtB;gBACD,MAAM,EAAE;oBACN,GAAG,EAAE,SAAS,GAAG,MAAM;oBACvB,QAAQ,EAAE,OAAO,CAAC,SAAS;iBAC5B;aACF,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAC;QACpC,CAAC;IACH,CAAC,CACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { ClarityValue, PostConditionMode, PostCondition } from "@stacks/transactions";
|
|
2
|
+
import { type Network } from "../config/networks.js";
|
|
3
|
+
export interface Account {
|
|
4
|
+
address: string;
|
|
5
|
+
privateKey: string;
|
|
6
|
+
network: Network;
|
|
7
|
+
}
|
|
8
|
+
export interface TransferResult {
|
|
9
|
+
txid: string;
|
|
10
|
+
rawTx: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ContractCallOptions {
|
|
13
|
+
contractAddress: string;
|
|
14
|
+
contractName: string;
|
|
15
|
+
functionName: string;
|
|
16
|
+
functionArgs: ClarityValue[];
|
|
17
|
+
postConditionMode?: PostConditionMode;
|
|
18
|
+
postConditions?: PostCondition[];
|
|
19
|
+
}
|
|
20
|
+
export interface ContractDeployOptions {
|
|
21
|
+
contractName: string;
|
|
22
|
+
codeBody: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Transfer STX tokens to a recipient
|
|
26
|
+
*/
|
|
27
|
+
export declare function transferStx(account: Account, recipient: string, amount: bigint, memo?: string): Promise<TransferResult>;
|
|
28
|
+
/**
|
|
29
|
+
* Call a smart contract function
|
|
30
|
+
*/
|
|
31
|
+
export declare function callContract(account: Account, options: ContractCallOptions): Promise<TransferResult>;
|
|
32
|
+
/**
|
|
33
|
+
* Deploy a smart contract
|
|
34
|
+
*/
|
|
35
|
+
export declare function deployContract(account: Account, options: ContractDeployOptions): Promise<TransferResult>;
|
|
36
|
+
/**
|
|
37
|
+
* Sign a transaction without broadcasting (for offline signing)
|
|
38
|
+
*/
|
|
39
|
+
export declare function signStxTransfer(account: Account, recipient: string, amount: bigint, memo?: string): Promise<{
|
|
40
|
+
signedTx: string;
|
|
41
|
+
txid: string;
|
|
42
|
+
}>;
|
|
43
|
+
/**
|
|
44
|
+
* Sign a contract call without broadcasting
|
|
45
|
+
*/
|
|
46
|
+
export declare function signContractCall(account: Account, options: ContractCallOptions): Promise<{
|
|
47
|
+
signedTx: string;
|
|
48
|
+
txid: string;
|
|
49
|
+
}>;
|
|
50
|
+
/**
|
|
51
|
+
* Broadcast a pre-signed transaction
|
|
52
|
+
*/
|
|
53
|
+
export declare function broadcastSignedTransaction(signedTx: string, network: Network): Promise<{
|
|
54
|
+
txid: string;
|
|
55
|
+
}>;
|
|
56
|
+
//# sourceMappingURL=builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../src/transactions/builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,YAAY,EACZ,iBAAiB,EACjB,aAAa,EACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAmC,KAAK,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAEtF,MAAM,WAAW,OAAO;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,mBAAmB;IAClC,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,YAAY,EAAE,CAAC;IAC7B,iBAAiB,CAAC,EAAE,iBAAiB,CAAC;IACtC,cAAc,CAAC,EAAE,a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