@mcpsovereign/sdk 0.1.0 → 0.2.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/dist/index.d.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  export { AgentRuntime, createRuntime } from './runtime.js';
2
2
  export type { RuntimeConfig, RuntimeOptions } from './runtime.js';
3
+ export * from './wallet/index.js';
4
+ export { WalletSetupWizard } from './wallet/wizard.js';
5
+ export { LNDSetup, quickSetupLND } from './wallet/lnd-setup.js';
3
6
  export * from './onboarding/types.js';
4
7
  export { OnboardingWizard } from './onboarding/wizard.js';
5
8
  export { AgentHelperMCP, HELPER_TOOLS } from './mcp-helper/index.js';
@@ -427,5 +430,57 @@ export declare class SovereignClient {
427
430
  * Show available badges
428
431
  */
429
432
  showBadges(): Promise<void>;
433
+ /**
434
+ * Run the wallet setup wizard
435
+ * This must be completed before buying/selling
436
+ */
437
+ setupWallet(options?: {
438
+ outputHandler?: (message: string) => void;
439
+ inputHandler?: (prompt: string, options?: string[]) => Promise<string>;
440
+ }): Promise<{
441
+ configured: boolean;
442
+ lightningAddress?: string;
443
+ skipped: boolean;
444
+ }>;
445
+ /**
446
+ * Check if wallet is configured
447
+ */
448
+ isWalletConfigured(): Promise<boolean>;
449
+ /**
450
+ * Get the configured Lightning address
451
+ */
452
+ getLightningAddress(): Promise<string | null>;
453
+ /**
454
+ * Check if agent can transact (buy/sell)
455
+ */
456
+ canTransact(): Promise<{
457
+ allowed: boolean;
458
+ reason?: string;
459
+ }>;
460
+ /**
461
+ * Set up a self-hosted LND node
462
+ * Requires Docker. Uses Neutrino mode (no full Bitcoin node needed).
463
+ */
464
+ setupSelfHostedNode(options?: {
465
+ alias?: string;
466
+ network?: 'mainnet' | 'testnet';
467
+ }): Promise<{
468
+ success: boolean;
469
+ seed?: string[];
470
+ restHost?: string;
471
+ error?: string;
472
+ }>;
473
+ /**
474
+ * Get self-hosted node status
475
+ */
476
+ getNodeStatus(): Promise<{
477
+ running: boolean;
478
+ synced: boolean;
479
+ blockHeight?: number;
480
+ balance?: {
481
+ confirmed: number;
482
+ unconfirmed: number;
483
+ };
484
+ }>;
430
485
  }
431
486
  export default SovereignClient;
package/dist/index.js CHANGED
@@ -2,8 +2,13 @@
2
2
  // mcpSovereign SDK - Local-First Store Management
3
3
  // =============================================================================
4
4
  // Agents build their store locally (free), sync to marketplace (costs credits)
5
+ // Wallet required to buy/sell, but browsing is always free
5
6
  // Re-export runtime module (portable identity management)
6
7
  export { AgentRuntime, createRuntime } from './runtime.js';
8
+ // Re-export wallet module (Lightning-first payments)
9
+ export * from './wallet/index.js';
10
+ export { WalletSetupWizard } from './wallet/wizard.js';
11
+ export { LNDSetup, quickSetupLND } from './wallet/lnd-setup.js';
7
12
  // Re-export onboarding module
8
13
  export * from './onboarding/types.js';
9
14
  export { OnboardingWizard } from './onboarding/wizard.js';
@@ -498,6 +503,85 @@ export class SovereignClient {
498
503
  const wizard = new OnboardingWizard();
499
504
  wizard.showBadges();
500
505
  }
506
+ // ---------------------------------------------------------------------------
507
+ // Wallet (Lightning Network Integration)
508
+ // ---------------------------------------------------------------------------
509
+ /**
510
+ * Run the wallet setup wizard
511
+ * This must be completed before buying/selling
512
+ */
513
+ async setupWallet(options = {}) {
514
+ const { WalletSetupWizard, saveWalletConfig } = await import('./wallet/index.js');
515
+ const wizard = new WalletSetupWizard(options.outputHandler || console.log, options.inputHandler);
516
+ const result = await wizard.run();
517
+ if (result.config) {
518
+ saveWalletConfig(result.config);
519
+ }
520
+ return {
521
+ configured: result.config !== null,
522
+ lightningAddress: result.config?.lightningAddress,
523
+ skipped: result.skipped
524
+ };
525
+ }
526
+ /**
527
+ * Check if wallet is configured
528
+ */
529
+ async isWalletConfigured() {
530
+ const { isWalletConfigured } = await import('./wallet/index.js');
531
+ return isWalletConfigured();
532
+ }
533
+ /**
534
+ * Get the configured Lightning address
535
+ */
536
+ async getLightningAddress() {
537
+ const { getLightningAddress } = await import('./wallet/index.js');
538
+ return getLightningAddress();
539
+ }
540
+ /**
541
+ * Check if agent can transact (buy/sell)
542
+ */
543
+ async canTransact() {
544
+ const { canTransact } = await import('./wallet/index.js');
545
+ return canTransact();
546
+ }
547
+ /**
548
+ * Set up a self-hosted LND node
549
+ * Requires Docker. Uses Neutrino mode (no full Bitcoin node needed).
550
+ */
551
+ async setupSelfHostedNode(options = {}) {
552
+ const { LNDSetup } = await import('./wallet/lnd-setup.js');
553
+ const setup = new LNDSetup({
554
+ alias: options.alias || `SovereignAgent_${Date.now().toString(36)}`,
555
+ network: options.network || 'mainnet'
556
+ });
557
+ const result = await setup.setupLND();
558
+ if (result.success && result.credentials) {
559
+ // Save to wallet config
560
+ const { saveWalletConfig } = await import('./wallet/index.js');
561
+ saveWalletConfig({
562
+ provider: 'zeus',
563
+ nodeUri: result.credentials.restHost,
564
+ setupComplete: true,
565
+ verified: true,
566
+ verifiedAt: new Date().toISOString(),
567
+ createdAt: new Date().toISOString()
568
+ });
569
+ }
570
+ return {
571
+ success: result.success,
572
+ seed: result.walletSeed,
573
+ restHost: result.credentials?.restHost,
574
+ error: result.error
575
+ };
576
+ }
577
+ /**
578
+ * Get self-hosted node status
579
+ */
580
+ async getNodeStatus() {
581
+ const { LNDSetup } = await import('./wallet/lnd-setup.js');
582
+ const setup = new LNDSetup();
583
+ return setup.getStatus();
584
+ }
501
585
  }
502
586
  // Default export
503
587
  export default SovereignClient;
package/dist/setup.js CHANGED
@@ -16,6 +16,8 @@ import * as path from 'path';
16
16
  import * as readline from 'readline';
17
17
  import { SovereignClient } from './index.js';
18
18
  import { OnboardingWizard } from './onboarding/wizard.js';
19
+ import { WalletSetupWizard } from './wallet/wizard.js';
20
+ import { isWalletConfigured, saveWalletConfig, loadWalletConfig } from './wallet/index.js';
19
21
  import { STARTER_CREDITS, PLATFORM_CREDENTIALS } from './onboarding/starter-kit.js';
20
22
  // ============================================================
21
23
  // CONFIG PATHS
@@ -221,7 +223,51 @@ async function runSetup() {
221
223
  saveConfig(config);
222
224
  console.log('šŸ“ Created new configuration');
223
225
  }
224
- // Step 3: Connect to server
226
+ // ===========================================================================
227
+ // STEP 3: WALLET SETUP (RUNS FIRST - GATED)
228
+ // ===========================================================================
229
+ // Wallet is required to buy/sell, but browsing is free
230
+ const walletConfigured = isWalletConfigured();
231
+ if (!walletConfigured) {
232
+ console.log('\n');
233
+ console.log('╔═══════════════════════════════════════════════════════════════════╗');
234
+ console.log('ā•‘ ā•‘');
235
+ console.log('ā•‘ ⚔ LIGHTNING WALLET SETUP REQUIRED ⚔ ā•‘');
236
+ console.log('ā•‘ ā•‘');
237
+ console.log('ā•‘ mcpSovereign runs on Bitcoin Lightning Network ā•‘');
238
+ console.log('ā•‘ You need a wallet to buy credits and sell products ā•‘');
239
+ console.log('ā•‘ ā•‘');
240
+ console.log('ā•‘ šŸ†“ Browsing the marketplace is always FREE ā•‘');
241
+ console.log('ā•‘ ā•‘');
242
+ console.log('ā•šā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•ā•');
243
+ console.log('\n');
244
+ const walletWizard = new WalletSetupWizard(console.log, async (prompt, options) => {
245
+ return await question(rl, prompt + ' ');
246
+ });
247
+ const walletResult = await walletWizard.run();
248
+ if (walletResult.config) {
249
+ saveWalletConfig(walletResult.config);
250
+ config.wallet_address = walletResult.config.lightningAddress || walletResult.config.nodeUri || null;
251
+ console.log('\nāœ… Wallet setup complete!\n');
252
+ }
253
+ else if (walletResult.skipped) {
254
+ console.log('\nā­ļø Wallet setup skipped. You can set it up later with:');
255
+ console.log(' npx @mcpsovereign/sdk setup-wallet\n');
256
+ }
257
+ saveConfig(config);
258
+ }
259
+ else {
260
+ const existingWallet = loadWalletConfig();
261
+ console.log('\nāœ… Wallet already configured');
262
+ if (existingWallet?.lightningAddress) {
263
+ console.log(` Lightning Address: ${existingWallet.lightningAddress}`);
264
+ }
265
+ else if (existingWallet?.nodeUri) {
266
+ console.log(` Self-hosted node: ${existingWallet.nodeUri}`);
267
+ }
268
+ console.log('');
269
+ }
270
+ // Step 4: Connect to server
225
271
  await showLoadingBar('🌐 Connecting to server', 1500);
226
272
  const { client, connected } = await connectToServer(config);
227
273
  if (connected) {
@@ -231,14 +277,16 @@ async function runSetup() {
231
277
  console.log('\nāš ļø Could not connect to server. Running in offline mode.');
232
278
  console.log(' You can still build products locally!\n');
233
279
  }
234
- // Step 4: First-time setup
280
+ // Step 5: First-time setup (authentication)
235
281
  if (isFirstRun || !config.setup_complete) {
236
282
  console.log('\nšŸŽ® First time setup detected!\n');
237
- // Ask for wallet address
238
- const walletInput = await question(rl, 'šŸ”‘ Enter your wallet address (or press Enter for demo mode): ');
239
- config.wallet_address = walletInput || `demo-agent-${Date.now()}`;
283
+ // Use wallet address if we have it, otherwise demo mode
284
+ if (!config.wallet_address) {
285
+ const walletInput = await question(rl, 'šŸ”‘ Enter your wallet address (or press Enter for demo mode): ');
286
+ config.wallet_address = walletInput || `demo-agent-${Date.now()}`;
287
+ }
240
288
  // Try to authenticate
241
- if (connected) {
289
+ if (connected && config.wallet_address) {
242
290
  await showLoadingBar('šŸ” Authenticating', 1000);
243
291
  const authResult = await client.authenticate(config.wallet_address);
244
292
  if (authResult.success && authResult.data) {
@@ -254,10 +302,10 @@ async function runSetup() {
254
302
  config.setup_complete = true;
255
303
  saveConfig(config);
256
304
  }
257
- // Step 5: Update MCP config
305
+ // Step 6: Update MCP config
258
306
  console.log('\nšŸ“‹ Configuring MCP integration...');
259
307
  updateMCPConfig();
260
- // Step 6: Run onboarding wizard if not complete
308
+ // Step 7: Run onboarding wizard if not complete
261
309
  if (!config.onboarding_complete) {
262
310
  console.log('\n');
263
311
  const runOnboarding = await question(rl, 'šŸŽ“ Run the onboarding wizard? (Y/n): ');
@@ -273,11 +321,11 @@ async function runSetup() {
273
321
  saveConfig(config);
274
322
  }
275
323
  }
276
- // Step 7: Save local store
324
+ // Step 8: Save local store
277
325
  await client.localStore.save();
278
- // Step 8: Show completion
326
+ // Step 9: Show completion
279
327
  console.log(SETUP_COMPLETE_BANNER);
280
- // Step 9: Show quick reference
328
+ // Step 10: Show quick reference
281
329
  console.log('\nšŸ“š Quick Reference:');
282
330
  console.log('─'.repeat(50));
283
331
  console.log('');
@@ -292,7 +340,8 @@ async function runSetup() {
292
340
  console.log('SDK Usage (in your code):');
293
341
  console.log(' import { SovereignClient } from "@mcpsovereign/sdk";');
294
342
  console.log(' const client = new SovereignClient();');
295
- console.log(' await client.onboard(); // Interactive setup');
343
+ console.log(' await client.setupWallet(); // Wallet setup');
344
+ console.log(' await client.onboard(); // Store onboarding');
296
345
  console.log('');
297
346
  console.log('Config Location: ' + CONFIG_DIR);
298
347
  console.log('');
@@ -328,10 +377,18 @@ Usage:
328
377
  npx @mcpsovereign/sdk <command>
329
378
 
330
379
  Commands:
331
- setup Run the setup wizard
332
- status Show current configuration
333
- reset Reset configuration and start fresh
334
- help Show this help message
380
+ setup Run the full setup wizard (wallet + onboarding)
381
+ setup-wallet Run only the wallet setup wizard
382
+ setup-lnd Set up a self-hosted Lightning node (Docker)
383
+ wallet Show wallet status or manage wallet
384
+ status Show current configuration
385
+ reset Reset configuration and start fresh
386
+ help Show this help message
387
+
388
+ Wallet Commands:
389
+ wallet status - Show wallet configuration
390
+ wallet verify - Verify Lightning address is reachable
391
+ wallet reset - Reset wallet configuration
335
392
 
336
393
  After setup, use the sovereign_* MCP tools in Claude!
337
394
  `);
@@ -348,6 +405,92 @@ async function resetConfig() {
348
405
  // ============================================================
349
406
  // MAIN ENTRY
350
407
  // ============================================================
408
+ async function runWalletSetup() {
409
+ const rl = readline.createInterface({
410
+ input: process.stdin,
411
+ output: process.stdout
412
+ });
413
+ const questionAsync = (prompt) => new Promise((resolve) => {
414
+ rl.question(prompt, resolve);
415
+ });
416
+ const wizard = new WalletSetupWizard(console.log, async (prompt, options) => {
417
+ return await questionAsync(prompt + ' ');
418
+ });
419
+ const result = await wizard.run();
420
+ if (result.config) {
421
+ saveWalletConfig(result.config);
422
+ console.log('\nāœ… Wallet configuration saved!\n');
423
+ }
424
+ rl.close();
425
+ }
426
+ async function runLNDSetup() {
427
+ const { LNDSetup } = await import('./wallet/lnd-setup.js');
428
+ console.log('\nšŸ–„ļø Self-Hosted Lightning Node Setup\n');
429
+ console.log('This will set up an LND node using Docker with Neutrino mode.');
430
+ console.log('No full Bitcoin node required - syncs in minutes!\n');
431
+ const rl = readline.createInterface({
432
+ input: process.stdin,
433
+ output: process.stdout
434
+ });
435
+ const alias = await new Promise((resolve) => {
436
+ rl.question('Node alias (press Enter for auto-generated): ', resolve);
437
+ });
438
+ rl.close();
439
+ const setup = new LNDSetup({
440
+ alias: alias || `SovereignAgent_${Date.now().toString(36)}`
441
+ });
442
+ // Check prerequisites
443
+ const prereqs = await setup.checkPrerequisites();
444
+ if (!prereqs.ready) {
445
+ console.log('\nāŒ Prerequisites not met:\n');
446
+ if (!prereqs.docker.installed) {
447
+ console.log(' • Docker is not installed');
448
+ console.log(' Install from: https://docs.docker.com/get-docker/\n');
449
+ }
450
+ else if (!prereqs.docker.running) {
451
+ console.log(' • Docker is installed but not running');
452
+ console.log(' Start Docker and try again\n');
453
+ }
454
+ if (!prereqs.compose) {
455
+ console.log(' • Docker Compose is not available\n');
456
+ }
457
+ if (!prereqs.diskSpace.sufficient) {
458
+ console.log(` • Insufficient disk space (need 5GB, have ${Math.round(prereqs.diskSpace.available / 1024 / 1024 / 1024)}GB)\n`);
459
+ }
460
+ return;
461
+ }
462
+ console.log('\nāœ… Prerequisites met. Starting setup...\n');
463
+ const result = await setup.setupLND();
464
+ if (result.success) {
465
+ console.log('\nāœ… LND node setup complete!\n');
466
+ if (result.walletSeed) {
467
+ console.log('āš ļø IMPORTANT: Your wallet seed has been saved to:');
468
+ console.log(` ~/.sovereign-lnd/BACKUP_SEED_DELETE_AFTER_BACKUP.txt`);
469
+ console.log(' Back it up and DELETE the file!\n');
470
+ }
471
+ if (result.credentials) {
472
+ // Save wallet config
473
+ saveWalletConfig({
474
+ provider: 'zeus',
475
+ nodeUri: result.credentials.restHost,
476
+ setupComplete: true,
477
+ verified: true,
478
+ verifiedAt: new Date().toISOString(),
479
+ createdAt: new Date().toISOString()
480
+ });
481
+ console.log('āœ… Wallet configuration saved!\n');
482
+ }
483
+ }
484
+ else {
485
+ console.log(`\nāŒ Setup failed: ${result.error}\n`);
486
+ console.log('Logs:');
487
+ result.logs.slice(-10).forEach(log => console.log(` ${log}`));
488
+ }
489
+ }
490
+ async function walletCommand(args) {
491
+ const { walletCLI } = await import('./wallet/index.js');
492
+ await walletCLI(args);
493
+ }
351
494
  async function main() {
352
495
  const args = process.argv.slice(2);
353
496
  const command = args[0] || 'setup';
@@ -355,6 +498,15 @@ async function main() {
355
498
  case 'setup':
356
499
  await runSetup();
357
500
  break;
501
+ case 'setup-wallet':
502
+ await runWalletSetup();
503
+ break;
504
+ case 'setup-lnd':
505
+ await runLNDSetup();
506
+ break;
507
+ case 'wallet':
508
+ await walletCommand(args.slice(1));
509
+ break;
358
510
  case 'status':
359
511
  await showStatus();
360
512
  break;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * mcpSovereign Wallet Module
3
+ *
4
+ * Lightning-first wallet setup and management for AI agents
5
+ *
6
+ * Features:
7
+ * - Guided wallet setup wizard
8
+ * - Lightning address validation
9
+ * - Self-hosted LND setup (Docker + Neutrino)
10
+ * - Payment helpers
11
+ */
12
+ export * from './types.js';
13
+ export { parseLightningAddress, verifyLightningAddress, getProviderFromAddress, createPaymentRequest, creditsToSats, satsToCredits, satsToDollars, dollarsToSats, formatSats, formatCredits, KNOWN_PROVIDERS, CREDITS_PER_SAT, SATS_PER_CREDIT } from './lightning.js';
14
+ export { LNDSetup, quickSetupLND } from './lnd-setup.js';
15
+ export type { LNDConfig, LNDCredentials, SetupResult } from './lnd-setup.js';
16
+ export { WalletSetupWizard } from './wizard.js';
17
+ import { WalletConfig } from './types.js';
18
+ /**
19
+ * Load saved wallet configuration
20
+ */
21
+ export declare function loadWalletConfig(): WalletConfig | null;
22
+ /**
23
+ * Save wallet configuration
24
+ */
25
+ export declare function saveWalletConfig(config: WalletConfig): void;
26
+ /**
27
+ * Check if wallet is set up
28
+ */
29
+ export declare function isWalletConfigured(): boolean;
30
+ /**
31
+ * Check if wallet is verified
32
+ */
33
+ export declare function isWalletVerified(): boolean;
34
+ /**
35
+ * Run the wallet setup wizard
36
+ */
37
+ export declare function runWalletSetup(options?: {
38
+ outputHandler?: (message: string) => void;
39
+ inputHandler?: (prompt: string, options?: string[]) => Promise<string>;
40
+ }): Promise<WalletConfig | null>;
41
+ /**
42
+ * Get the current Lightning address (if configured)
43
+ */
44
+ export declare function getLightningAddress(): string | null;
45
+ /**
46
+ * Quick check: can the agent buy/sell?
47
+ */
48
+ export declare function canTransact(): {
49
+ allowed: boolean;
50
+ reason?: string;
51
+ };
52
+ /**
53
+ * CLI entry point for wallet setup
54
+ */
55
+ export declare function walletCLI(args: string[]): Promise<void>;
@@ -0,0 +1,189 @@
1
+ /**
2
+ * mcpSovereign Wallet Module
3
+ *
4
+ * Lightning-first wallet setup and management for AI agents
5
+ *
6
+ * Features:
7
+ * - Guided wallet setup wizard
8
+ * - Lightning address validation
9
+ * - Self-hosted LND setup (Docker + Neutrino)
10
+ * - Payment helpers
11
+ */
12
+ // Types
13
+ export * from './types.js';
14
+ // Lightning utilities
15
+ export { parseLightningAddress, verifyLightningAddress, getProviderFromAddress, createPaymentRequest, creditsToSats, satsToCredits, satsToDollars, dollarsToSats, formatSats, formatCredits, KNOWN_PROVIDERS, CREDITS_PER_SAT, SATS_PER_CREDIT } from './lightning.js';
16
+ // LND Setup
17
+ export { LNDSetup, quickSetupLND } from './lnd-setup.js';
18
+ // Wallet Setup Wizard
19
+ export { WalletSetupWizard } from './wizard.js';
20
+ // ============================================================
21
+ // CONVENIENCE FUNCTIONS
22
+ // ============================================================
23
+ import { WalletSetupWizard } from './wizard.js';
24
+ import * as fs from 'fs';
25
+ import * as path from 'path';
26
+ const CONFIG_DIR = path.join(process.env.HOME || '.', '.mcpsovereign');
27
+ const WALLET_CONFIG_FILE = path.join(CONFIG_DIR, 'wallet.json');
28
+ /**
29
+ * Load saved wallet configuration
30
+ */
31
+ export function loadWalletConfig() {
32
+ try {
33
+ if (fs.existsSync(WALLET_CONFIG_FILE)) {
34
+ return JSON.parse(fs.readFileSync(WALLET_CONFIG_FILE, 'utf-8'));
35
+ }
36
+ }
37
+ catch {
38
+ // Ignore errors
39
+ }
40
+ return null;
41
+ }
42
+ /**
43
+ * Save wallet configuration
44
+ */
45
+ export function saveWalletConfig(config) {
46
+ try {
47
+ if (!fs.existsSync(CONFIG_DIR)) {
48
+ fs.mkdirSync(CONFIG_DIR, { recursive: true });
49
+ }
50
+ fs.writeFileSync(WALLET_CONFIG_FILE, JSON.stringify(config, null, 2));
51
+ }
52
+ catch (error) {
53
+ console.error('Failed to save wallet config:', error);
54
+ }
55
+ }
56
+ /**
57
+ * Check if wallet is set up
58
+ */
59
+ export function isWalletConfigured() {
60
+ const config = loadWalletConfig();
61
+ return config !== null && config.setupComplete;
62
+ }
63
+ /**
64
+ * Check if wallet is verified
65
+ */
66
+ export function isWalletVerified() {
67
+ const config = loadWalletConfig();
68
+ return config !== null && config.verified;
69
+ }
70
+ /**
71
+ * Run the wallet setup wizard
72
+ */
73
+ export async function runWalletSetup(options = {}) {
74
+ const wizard = new WalletSetupWizard(options.outputHandler || console.log, options.inputHandler);
75
+ const result = await wizard.run();
76
+ if (result.config) {
77
+ saveWalletConfig(result.config);
78
+ }
79
+ return result.config;
80
+ }
81
+ /**
82
+ * Get the current Lightning address (if configured)
83
+ */
84
+ export function getLightningAddress() {
85
+ const config = loadWalletConfig();
86
+ return config?.lightningAddress || null;
87
+ }
88
+ /**
89
+ * Quick check: can the agent buy/sell?
90
+ */
91
+ export function canTransact() {
92
+ const config = loadWalletConfig();
93
+ if (!config) {
94
+ return {
95
+ allowed: false,
96
+ reason: 'No wallet configured. Run: npx @mcpsovereign/sdk setup-wallet'
97
+ };
98
+ }
99
+ if (!config.setupComplete) {
100
+ return {
101
+ allowed: false,
102
+ reason: 'Wallet setup incomplete. Run: npx @mcpsovereign/sdk setup-wallet'
103
+ };
104
+ }
105
+ if (!config.lightningAddress && !config.nodeUri) {
106
+ return {
107
+ allowed: false,
108
+ reason: 'No Lightning address or node configured.'
109
+ };
110
+ }
111
+ return { allowed: true };
112
+ }
113
+ // ============================================================
114
+ // CLI COMMANDS
115
+ // ============================================================
116
+ /**
117
+ * CLI entry point for wallet setup
118
+ */
119
+ export async function walletCLI(args) {
120
+ const command = args[0] || 'status';
121
+ switch (command) {
122
+ case 'setup':
123
+ await runWalletSetup();
124
+ break;
125
+ case 'status': {
126
+ const config = loadWalletConfig();
127
+ if (!config) {
128
+ console.log('\nāŒ No wallet configured');
129
+ console.log(' Run: npx @mcpsovereign/sdk setup-wallet\n');
130
+ return;
131
+ }
132
+ console.log('\nšŸ’³ Wallet Status\n');
133
+ console.log('═'.repeat(50));
134
+ console.log(`Provider: ${config.provider}`);
135
+ if (config.lightningAddress) {
136
+ console.log(`Address: ${config.lightningAddress}`);
137
+ }
138
+ if (config.nodeUri) {
139
+ console.log(`Node: ${config.nodeUri}`);
140
+ }
141
+ console.log(`Verified: ${config.verified ? 'āœ… Yes' : 'āŒ No'}`);
142
+ console.log(`Setup Complete: ${config.setupComplete ? 'āœ… Yes' : 'āŒ No'}`);
143
+ console.log('');
144
+ break;
145
+ }
146
+ case 'verify': {
147
+ const config = loadWalletConfig();
148
+ if (!config?.lightningAddress) {
149
+ console.log('\nāŒ No Lightning address configured\n');
150
+ return;
151
+ }
152
+ const { verifyLightningAddress } = await import('./lightning.js');
153
+ console.log(`\nVerifying ${config.lightningAddress}...`);
154
+ const result = await verifyLightningAddress(config.lightningAddress);
155
+ if (result.valid) {
156
+ console.log('āœ… Wallet is reachable and can receive payments\n');
157
+ config.verified = true;
158
+ config.verifiedAt = new Date().toISOString();
159
+ saveWalletConfig(config);
160
+ }
161
+ else {
162
+ console.log(`āŒ Verification failed: ${result.error}\n`);
163
+ }
164
+ break;
165
+ }
166
+ case 'reset': {
167
+ if (fs.existsSync(WALLET_CONFIG_FILE)) {
168
+ fs.unlinkSync(WALLET_CONFIG_FILE);
169
+ console.log('\nāœ… Wallet configuration reset\n');
170
+ }
171
+ else {
172
+ console.log('\nNothing to reset\n');
173
+ }
174
+ break;
175
+ }
176
+ default:
177
+ console.log(`
178
+ mcpSovereign Wallet CLI
179
+
180
+ Usage: npx @mcpsovereign/sdk wallet <command>
181
+
182
+ Commands:
183
+ setup - Run the wallet setup wizard
184
+ status - Show current wallet configuration
185
+ verify - Verify your Lightning address
186
+ reset - Reset wallet configuration
187
+ `);
188
+ }
189
+ }