shogun-core 3.3.5 → 3.3.6

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.
Files changed (149) hide show
  1. package/dist/browser/shogun-core.js +79919 -190726
  2. package/dist/browser/shogun-core.js.map +1 -1
  3. package/dist/{src/index.js → index.js} +0 -1
  4. package/dist/{src/managers → managers}/CoreInitializer.js +0 -6
  5. package/dist/{src/storage → storage}/storage.js +0 -16
  6. package/dist/types/{src/index.d.ts → index.d.ts} +0 -1
  7. package/package.json +10 -26
  8. package/dist/browser/defaultVendors-node_modules_shogun-ipfs_node_modules_axios_index_js.shogun-core.js +0 -4078
  9. package/dist/browser/defaultVendors-node_modules_shogun-ipfs_node_modules_axios_index_js.shogun-core.js.map +0 -1
  10. package/dist/browser/defaultVendors-node_modules_shogun-ipfs_node_modules_is-ipfs_dist_src_index_js.shogun-core.js +0 -4908
  11. package/dist/browser/defaultVendors-node_modules_shogun-ipfs_node_modules_is-ipfs_dist_src_index_js.shogun-core.js.map +0 -1
  12. package/dist/browser/defaultVendors-node_modules_shogun-ipfs_node_modules_uint8-varint_dist_src_index_js-node_modu-0db5ba.shogun-core.js +0 -2109
  13. package/dist/browser/defaultVendors-node_modules_shogun-ipfs_node_modules_uint8-varint_dist_src_index_js-node_modu-0db5ba.shogun-core.js.map +0 -1
  14. package/dist/ship/examples/identity-cli.js +0 -511
  15. package/dist/ship/examples/messenger-cli.js +0 -745
  16. package/dist/ship/examples/stealth-cli.js +0 -433
  17. package/dist/ship/examples/storage-cli.js +0 -615
  18. package/dist/ship/examples/vault-cli.js +0 -444
  19. package/dist/ship/examples/wallet-cli.js +0 -767
  20. package/dist/ship/implementation/SHIP_00.js +0 -478
  21. package/dist/ship/implementation/SHIP_01.js +0 -433
  22. package/dist/ship/implementation/SHIP_02.js +0 -1366
  23. package/dist/ship/implementation/SHIP_03.js +0 -855
  24. package/dist/ship/implementation/SHIP_04.js +0 -589
  25. package/dist/ship/implementation/SHIP_05.js +0 -1064
  26. package/dist/ship/implementation/SHIP_06.js +0 -635
  27. package/dist/ship/index.js +0 -17
  28. package/dist/ship/interfaces/ISHIP_00.js +0 -135
  29. package/dist/ship/interfaces/ISHIP_01.js +0 -128
  30. package/dist/ship/interfaces/ISHIP_02.js +0 -57
  31. package/dist/ship/interfaces/ISHIP_03.js +0 -61
  32. package/dist/ship/interfaces/ISHIP_04.js +0 -62
  33. package/dist/ship/interfaces/ISHIP_05.js +0 -59
  34. package/dist/ship/interfaces/ISHIP_06.js +0 -194
  35. package/dist/types/ship/examples/identity-cli.d.ts +0 -40
  36. package/dist/types/ship/examples/messenger-cli.d.ts +0 -37
  37. package/dist/types/ship/examples/stealth-cli.d.ts +0 -31
  38. package/dist/types/ship/examples/storage-cli.d.ts +0 -48
  39. package/dist/types/ship/examples/vault-cli.d.ts +0 -13
  40. package/dist/types/ship/examples/wallet-cli.d.ts +0 -131
  41. package/dist/types/ship/implementation/SHIP_00.d.ts +0 -113
  42. package/dist/types/ship/implementation/SHIP_01.d.ts +0 -80
  43. package/dist/types/ship/implementation/SHIP_02.d.ts +0 -297
  44. package/dist/types/ship/implementation/SHIP_03.d.ts +0 -127
  45. package/dist/types/ship/implementation/SHIP_04.d.ts +0 -76
  46. package/dist/types/ship/implementation/SHIP_05.d.ts +0 -70
  47. package/dist/types/ship/implementation/SHIP_06.d.ts +0 -101
  48. package/dist/types/ship/index.d.ts +0 -14
  49. package/dist/types/ship/interfaces/ISHIP_00.d.ts +0 -410
  50. package/dist/types/ship/interfaces/ISHIP_01.d.ts +0 -343
  51. package/dist/types/ship/interfaces/ISHIP_02.d.ts +0 -470
  52. package/dist/types/ship/interfaces/ISHIP_03.d.ts +0 -295
  53. package/dist/types/ship/interfaces/ISHIP_04.d.ts +0 -245
  54. package/dist/types/ship/interfaces/ISHIP_05.d.ts +0 -234
  55. package/dist/types/ship/interfaces/ISHIP_06.d.ts +0 -522
  56. /package/dist/{src/config → config}/simplified-config.js +0 -0
  57. /package/dist/{src/core.js → core.js} +0 -0
  58. /package/dist/{src/examples → examples}/api-test.js +0 -0
  59. /package/dist/{src/examples → examples}/simple-api-test.js +0 -0
  60. /package/dist/{src/gundb → gundb}/api.js +0 -0
  61. /package/dist/{src/gundb → gundb}/crypto.js +0 -0
  62. /package/dist/{src/gundb → gundb}/db.js +0 -0
  63. /package/dist/{src/gundb → gundb}/derive.js +0 -0
  64. /package/dist/{src/gundb → gundb}/errors.js +0 -0
  65. /package/dist/{src/gundb → gundb}/index.js +0 -0
  66. /package/dist/{src/gundb → gundb}/rxjs.js +0 -0
  67. /package/dist/{src/gundb → gundb}/types.js +0 -0
  68. /package/dist/{src/interfaces → interfaces}/common.js +0 -0
  69. /package/dist/{src/interfaces → interfaces}/events.js +0 -0
  70. /package/dist/{src/interfaces → interfaces}/plugin.js +0 -0
  71. /package/dist/{src/interfaces → interfaces}/shogun.js +0 -0
  72. /package/dist/{src/managers → managers}/AuthManager.js +0 -0
  73. /package/dist/{src/managers → managers}/EventManager.js +0 -0
  74. /package/dist/{src/managers → managers}/PluginManager.js +0 -0
  75. /package/dist/{src/migration-test.js → migration-test.js} +0 -0
  76. /package/dist/{src/plugins → plugins}/base.js +0 -0
  77. /package/dist/{src/plugins → plugins}/index.js +0 -0
  78. /package/dist/{src/plugins → plugins}/nostr/index.js +0 -0
  79. /package/dist/{src/plugins → plugins}/nostr/nostrConnector.js +0 -0
  80. /package/dist/{src/plugins → plugins}/nostr/nostrConnectorPlugin.js +0 -0
  81. /package/dist/{src/plugins → plugins}/nostr/nostrSigner.js +0 -0
  82. /package/dist/{src/plugins → plugins}/nostr/types.js +0 -0
  83. /package/dist/{src/plugins → plugins}/oauth/index.js +0 -0
  84. /package/dist/{src/plugins → plugins}/oauth/oauthConnector.js +0 -0
  85. /package/dist/{src/plugins → plugins}/oauth/oauthPlugin.js +0 -0
  86. /package/dist/{src/plugins → plugins}/oauth/types.js +0 -0
  87. /package/dist/{src/plugins → plugins}/web3/index.js +0 -0
  88. /package/dist/{src/plugins → plugins}/web3/types.js +0 -0
  89. /package/dist/{src/plugins → plugins}/web3/web3Connector.js +0 -0
  90. /package/dist/{src/plugins → plugins}/web3/web3ConnectorPlugin.js +0 -0
  91. /package/dist/{src/plugins → plugins}/web3/web3Signer.js +0 -0
  92. /package/dist/{src/plugins → plugins}/webauthn/index.js +0 -0
  93. /package/dist/{src/plugins → plugins}/webauthn/types.js +0 -0
  94. /package/dist/{src/plugins → plugins}/webauthn/webauthn.js +0 -0
  95. /package/dist/{src/plugins → plugins}/webauthn/webauthnPlugin.js +0 -0
  96. /package/dist/{src/plugins → plugins}/webauthn/webauthnSigner.js +0 -0
  97. /package/dist/types/{src/config → config}/simplified-config.d.ts +0 -0
  98. /package/dist/types/{src/core.d.ts → core.d.ts} +0 -0
  99. /package/dist/{src/types → types}/events.js +0 -0
  100. /package/dist/types/{src/examples → examples}/api-test.d.ts +0 -0
  101. /package/dist/types/{src/examples → examples}/simple-api-test.d.ts +0 -0
  102. /package/dist/types/{src/gundb → gundb}/api.d.ts +0 -0
  103. /package/dist/types/{src/gundb → gundb}/crypto.d.ts +0 -0
  104. /package/dist/types/{src/gundb → gundb}/db.d.ts +0 -0
  105. /package/dist/types/{src/gundb → gundb}/derive.d.ts +0 -0
  106. /package/dist/types/{src/gundb → gundb}/errors.d.ts +0 -0
  107. /package/dist/types/{src/gundb → gundb}/index.d.ts +0 -0
  108. /package/dist/types/{src/gundb → gundb}/rxjs.d.ts +0 -0
  109. /package/dist/types/{src/gundb → gundb}/types.d.ts +0 -0
  110. /package/dist/types/{src/interfaces → interfaces}/common.d.ts +0 -0
  111. /package/dist/types/{src/interfaces → interfaces}/events.d.ts +0 -0
  112. /package/dist/types/{src/interfaces → interfaces}/plugin.d.ts +0 -0
  113. /package/dist/types/{src/interfaces → interfaces}/shogun.d.ts +0 -0
  114. /package/dist/types/{src/managers → managers}/AuthManager.d.ts +0 -0
  115. /package/dist/types/{src/managers → managers}/CoreInitializer.d.ts +0 -0
  116. /package/dist/types/{src/managers → managers}/EventManager.d.ts +0 -0
  117. /package/dist/types/{src/managers → managers}/PluginManager.d.ts +0 -0
  118. /package/dist/types/{src/migration-test.d.ts → migration-test.d.ts} +0 -0
  119. /package/dist/types/{src/plugins → plugins}/base.d.ts +0 -0
  120. /package/dist/types/{src/plugins → plugins}/index.d.ts +0 -0
  121. /package/dist/types/{src/plugins → plugins}/nostr/index.d.ts +0 -0
  122. /package/dist/types/{src/plugins → plugins}/nostr/nostrConnector.d.ts +0 -0
  123. /package/dist/types/{src/plugins → plugins}/nostr/nostrConnectorPlugin.d.ts +0 -0
  124. /package/dist/types/{src/plugins → plugins}/nostr/nostrSigner.d.ts +0 -0
  125. /package/dist/types/{src/plugins → plugins}/nostr/types.d.ts +0 -0
  126. /package/dist/types/{src/plugins → plugins}/oauth/index.d.ts +0 -0
  127. /package/dist/types/{src/plugins → plugins}/oauth/oauthConnector.d.ts +0 -0
  128. /package/dist/types/{src/plugins → plugins}/oauth/oauthPlugin.d.ts +0 -0
  129. /package/dist/types/{src/plugins → plugins}/oauth/types.d.ts +0 -0
  130. /package/dist/types/{src/plugins → plugins}/web3/index.d.ts +0 -0
  131. /package/dist/types/{src/plugins → plugins}/web3/types.d.ts +0 -0
  132. /package/dist/types/{src/plugins → plugins}/web3/web3Connector.d.ts +0 -0
  133. /package/dist/types/{src/plugins → plugins}/web3/web3ConnectorPlugin.d.ts +0 -0
  134. /package/dist/types/{src/plugins → plugins}/web3/web3Signer.d.ts +0 -0
  135. /package/dist/types/{src/plugins → plugins}/webauthn/index.d.ts +0 -0
  136. /package/dist/types/{src/plugins → plugins}/webauthn/types.d.ts +0 -0
  137. /package/dist/types/{src/plugins → plugins}/webauthn/webauthn.d.ts +0 -0
  138. /package/dist/types/{src/plugins → plugins}/webauthn/webauthnPlugin.d.ts +0 -0
  139. /package/dist/types/{src/plugins → plugins}/webauthn/webauthnSigner.d.ts +0 -0
  140. /package/dist/{src/types → types}/shogun.js +0 -0
  141. /package/dist/types/{src/storage → storage}/storage.d.ts +0 -0
  142. /package/dist/types/{src/types → types}/events.d.ts +0 -0
  143. /package/dist/types/{src/types → types}/shogun.d.ts +0 -0
  144. /package/dist/types/{src/utils → utils}/errorHandler.d.ts +0 -0
  145. /package/dist/types/{src/utils → utils}/eventEmitter.d.ts +0 -0
  146. /package/dist/types/{src/utils → utils}/validation.d.ts +0 -0
  147. /package/dist/{src/utils → utils}/errorHandler.js +0 -0
  148. /package/dist/{src/utils → utils}/eventEmitter.js +0 -0
  149. /package/dist/{src/utils → utils}/validation.js +0 -0
@@ -1,433 +0,0 @@
1
- #!/usr/bin/env tsx
2
- "use strict";
3
- /**
4
- * SHIP-03 Stealth Address CLI Example
5
- *
6
- * Demonstrates dual-key stealth addresses with Fluidkey integration
7
- *
8
- * Usage:
9
- * yarn stealth <username> <password>
10
- */
11
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
12
- if (k2 === undefined) k2 = k;
13
- var desc = Object.getOwnPropertyDescriptor(m, k);
14
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
15
- desc = { enumerable: true, get: function() { return m[k]; } };
16
- }
17
- Object.defineProperty(o, k2, desc);
18
- }) : (function(o, m, k, k2) {
19
- if (k2 === undefined) k2 = k;
20
- o[k2] = m[k];
21
- }));
22
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
23
- Object.defineProperty(o, "default", { enumerable: true, value: v });
24
- }) : function(o, v) {
25
- o["default"] = v;
26
- });
27
- var __importStar = (this && this.__importStar) || (function () {
28
- var ownKeys = function(o) {
29
- ownKeys = Object.getOwnPropertyNames || function (o) {
30
- var ar = [];
31
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
32
- return ar;
33
- };
34
- return ownKeys(o);
35
- };
36
- return function (mod) {
37
- if (mod && mod.__esModule) return mod;
38
- var result = {};
39
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
40
- __setModuleDefault(result, mod);
41
- return result;
42
- };
43
- })();
44
- Object.defineProperty(exports, "__esModule", { value: true });
45
- exports.StealthCLI = void 0;
46
- const SHIP_00_1 = require("../implementation/SHIP_00");
47
- const SHIP_02_1 = require("../implementation/SHIP_02");
48
- const SHIP_03_1 = require("../implementation/SHIP_03");
49
- const readline = __importStar(require("readline"));
50
- // ============================================================================
51
- // CLI Interface
52
- // ============================================================================
53
- class StealthCLI {
54
- constructor() {
55
- // Initialize SHIP-00 with local peer
56
- this.identity = new SHIP_00_1.SHIP_00({
57
- gunOptions: {
58
- peers: [
59
- "https://peer.wallie.io/gun",
60
- "https://v5g5jseqhgkp43lppgregcfbvi.srv.us/gun",
61
- "https://relay.shogun-eco.xyz/gun",
62
- ],
63
- radisk: true,
64
- localStorage: false,
65
- },
66
- });
67
- // Will be initialized after login
68
- this.eth = null;
69
- this.stealth = null;
70
- this.rl = readline.createInterface({
71
- input: process.stdin,
72
- output: process.stdout,
73
- });
74
- }
75
- // ==========================================================================
76
- // Authentication
77
- // ==========================================================================
78
- async login(username, password) {
79
- console.log(`\n🔐 Logging in as ${username}...`);
80
- const result = await this.identity.login(username, password);
81
- if (!result.success) {
82
- console.error(`❌ Login failed: ${result.error}`);
83
- return false;
84
- }
85
- console.log(`✅ Logged in as ${username}`);
86
- // Initialize SHIP-02 (HD Wallet)
87
- this.eth = new SHIP_02_1.SHIP_02(this.identity);
88
- await this.eth.initialize();
89
- console.log("✅ SHIP-02 (HD Wallet) initialized");
90
- // Initialize SHIP-03 (Stealth Addresses)
91
- this.stealth = new SHIP_03_1.SHIP_03(this.identity, this.eth);
92
- await this.stealth.initialize();
93
- console.log("✅ SHIP-03 (Stealth Addresses) initialized");
94
- return true;
95
- }
96
- async register(username, password) {
97
- console.log(`\n📝 Registering new user: ${username}...`);
98
- const result = await this.identity.signup(username, password);
99
- if (!result.success) {
100
- console.error(`❌ Registration failed: ${result.error}`);
101
- return false;
102
- }
103
- console.log(`✅ User registered: ${username}`);
104
- // Login after signup
105
- await this.identity.login(username, password);
106
- // Publish public key
107
- await this.identity.publishPublicKey();
108
- console.log("✅ Public key published");
109
- // Initialize SHIP-02 and SHIP-03
110
- this.eth = new SHIP_02_1.SHIP_02(this.identity);
111
- await this.eth.initialize();
112
- this.stealth = new SHIP_03_1.SHIP_03(this.identity, this.eth);
113
- await this.stealth.initialize();
114
- console.log("✅ Wallet and stealth systems initialized");
115
- return true;
116
- }
117
- // ==========================================================================
118
- // Stealth Operations
119
- // ==========================================================================
120
- async showStealthKeys() {
121
- console.log("\n📋 Your Stealth Keys:");
122
- console.log("━".repeat(60));
123
- const keys = await this.stealth.getStealthKeys();
124
- console.log("\n🔍 Viewing Key:");
125
- console.log(` Public: ${keys.viewingKey.publicKey}`);
126
- console.log(` Private: ${keys.viewingKey.privateKey.slice(0, 10)}...`);
127
- console.log("\n💰 Spending Key:");
128
- console.log(` Public: ${keys.spendingKey.publicKey}`);
129
- console.log(` Private: ${keys.spendingKey.privateKey.slice(0, 10)}...`);
130
- console.log("\n💡 Share the PUBLIC keys with others to receive stealth payments");
131
- console.log("━".repeat(60));
132
- }
133
- async generateStealthAddress() {
134
- console.log("\n🎭 Generate Stealth Address");
135
- console.log("━".repeat(60));
136
- const recipientInput = await this.prompt("Recipient username (or leave empty for self): ");
137
- let viewingKey;
138
- let spendingKey;
139
- if (recipientInput.trim()) {
140
- // Generate for another user
141
- console.log(`\n🔍 Looking up stealth keys for: ${recipientInput}`);
142
- const recipientKeys = await this.stealth.getPublicStealthKeysByUsername(recipientInput.trim());
143
- if (!recipientKeys) {
144
- console.error(`❌ Stealth keys not found for user: ${recipientInput}`);
145
- console.log("\n💡 The user needs to:");
146
- console.log(" 1. Run: yarn stealth ${recipientInput} <password>");
147
- console.log(" 2. Initialize SHIP-03 (happens automatically on login)");
148
- console.log(" 3. Their keys will be published to Gun network");
149
- return;
150
- }
151
- viewingKey = recipientKeys.viewingPublicKey;
152
- spendingKey = recipientKeys.spendingPublicKey;
153
- console.log(`✅ Found keys for ${recipientInput}`);
154
- }
155
- else {
156
- // Generate for self
157
- console.log("\n📍 Generating for yourself (self-payment)");
158
- const keys = await this.stealth.getStealthKeys();
159
- viewingKey = keys.viewingKey.publicKey;
160
- spendingKey = keys.spendingKey.publicKey;
161
- }
162
- const result = await this.stealth.generateStealthAddress(viewingKey, spendingKey);
163
- if (!result.success) {
164
- console.error(`❌ Failed: ${result.error}`);
165
- return;
166
- }
167
- console.log("\n✅ Stealth Address Generated:");
168
- console.log(` Address: ${result.stealthAddress}`);
169
- console.log(` Ephemeral: ${result.ephemeralPublicKey}`);
170
- console.log(` View Tag: ${result.viewTag}`);
171
- console.log("\n📤 Send payment to this address");
172
- console.log("📤 Share ephemeral key with recipient for scanning");
173
- console.log("━".repeat(60));
174
- }
175
- async openStealthAddress() {
176
- console.log("\n🔓 Open Stealth Address");
177
- console.log("━".repeat(60));
178
- const stealthAddress = await this.prompt("Enter stealth address to open: ");
179
- const ephemeralPubKey = await this.prompt("Enter ephemeral public key: ");
180
- try {
181
- const wallet = await this.stealth.openStealthAddress(stealthAddress.trim(), ephemeralPubKey.trim());
182
- console.log("\n✅ Stealth Address Opened:");
183
- console.log(` Address: ${wallet.address}`);
184
- console.log(` Private Key: ${wallet.privateKey.slice(0, 10)}...`);
185
- console.log("\n💰 You can now spend funds from this address");
186
- console.log("━".repeat(60));
187
- }
188
- catch (error) {
189
- console.error(`\n❌ Failed to open: ${error.message}`);
190
- console.log("This address may not belong to you.");
191
- }
192
- }
193
- async batchGenerateStealthAddresses() {
194
- console.log("\n🎯 Batch Generate Stealth Addresses");
195
- console.log("━".repeat(60));
196
- const count = parseInt(await this.prompt("How many addresses? "), 10);
197
- if (isNaN(count) || count < 1 || count > 10) {
198
- console.error("❌ Please enter a number between 1 and 10");
199
- return;
200
- }
201
- // For demo, generate all for self
202
- const keys = await this.stealth.getStealthKeys();
203
- const recipients = Array(count).fill({
204
- viewingKey: keys.viewingKey.publicKey,
205
- spendingKey: keys.spendingKey.publicKey,
206
- });
207
- console.log(`\n🔄 Generating ${count} stealth addresses...`);
208
- const results = await this.stealth.generateMultipleStealthAddresses(recipients);
209
- console.log("\n✅ Generated addresses:");
210
- results.forEach((r, i) => {
211
- if (r.success) {
212
- console.log(` ${i + 1}. ${r.stealthAddress}`);
213
- console.log(` Ephemeral: ${r.ephemeralPublicKey?.slice(0, 20)}...`);
214
- console.log(` View Tag: ${r.viewTag}`);
215
- }
216
- });
217
- console.log("━".repeat(60));
218
- }
219
- async scanForStealthPayments() {
220
- console.log("\n🔍 Scan for Stealth Payments");
221
- console.log("━".repeat(60));
222
- // Example announcements (in production, fetch from blockchain)
223
- console.log("\n💡 In production, this would scan blockchain for Announcement events");
224
- console.log("For demo, enter announcement data manually:\n");
225
- const stealthAddr = await this.prompt("Stealth address: ");
226
- const ephemeralKey = await this.prompt("Ephemeral public key: ");
227
- const isMine = await this.stealth.isStealthAddressMine(stealthAddr.trim(), ephemeralKey.trim());
228
- if (isMine) {
229
- console.log("\n✅ This stealth address belongs to you!");
230
- const owned = await this.stealth.getAllOwnedStealthAddresses();
231
- console.log(`\n💰 Total owned stealth addresses: ${owned.length}`);
232
- owned.forEach((addr, i) => {
233
- console.log(` ${i + 1}. ${addr.stealthAddress}`);
234
- });
235
- }
236
- else {
237
- console.log("\n❌ This stealth address does not belong to you");
238
- }
239
- console.log("━".repeat(60));
240
- }
241
- // ==========================================================================
242
- // Menu
243
- // ==========================================================================
244
- async showMenu() {
245
- console.log("\n🎭 SHIP-03 Stealth Address Manager");
246
- console.log("━".repeat(60));
247
- console.log("1. Show my stealth keys");
248
- console.log("2. Generate stealth address (for anyone)");
249
- console.log("3. Open stealth address (spend)");
250
- console.log("4. Batch generate stealth addresses");
251
- console.log("5. Scan for stealth payments");
252
- console.log("6. Lookup user's stealth keys");
253
- console.log("7. Export stealth keys");
254
- console.log("8. Show wallet info (SHIP-02)");
255
- console.log("9. Publish Stealth Keys (to Gun network)");
256
- console.log("10. Logout");
257
- console.log("━".repeat(60));
258
- const choice = await this.prompt("\nChoose option: ");
259
- switch (choice.trim()) {
260
- case "1":
261
- await this.showStealthKeys();
262
- break;
263
- case "2":
264
- await this.generateStealthAddress();
265
- break;
266
- case "3":
267
- await this.openStealthAddress();
268
- break;
269
- case "4":
270
- await this.batchGenerateStealthAddresses();
271
- break;
272
- case "5":
273
- await this.scanForStealthPayments();
274
- break;
275
- case "6":
276
- await this.lookupUserKeys();
277
- break;
278
- case "7":
279
- await this.exportKeys();
280
- break;
281
- case "8":
282
- await this.showWalletInfo();
283
- break;
284
- case "9":
285
- await this.publishKeys();
286
- break;
287
- case "10":
288
- console.log("\n👋 Goodbye!");
289
- this.rl.close();
290
- process.exit(0);
291
- return;
292
- default:
293
- console.log("❌ Invalid choice");
294
- }
295
- // Show menu again
296
- setTimeout(() => this.showMenu(), 100);
297
- }
298
- async lookupUserKeys() {
299
- console.log("\n🔍 Lookup User's Stealth Keys");
300
- console.log("━".repeat(60));
301
- const username = await this.prompt("Enter username to lookup: ");
302
- if (!username.trim()) {
303
- console.log("❌ Username required");
304
- return;
305
- }
306
- console.log(`\n🔍 Searching for ${username}...`);
307
- const keys = await this.stealth.getPublicStealthKeysByUsername(username.trim());
308
- if (!keys) {
309
- console.log(`\n❌ No stealth keys found for ${username}`);
310
- console.log("\n💡 Possible reasons:");
311
- console.log(" • User hasn't initialized SHIP-03");
312
- console.log(" • Username doesn't exist");
313
- console.log(" • Keys not yet synced to Gun network");
314
- return;
315
- }
316
- console.log(`\n✅ Stealth Keys for ${username}:`);
317
- console.log("━".repeat(60));
318
- console.log(`Viewing Public Key:`);
319
- console.log(` ${keys.viewingPublicKey}`);
320
- console.log(`\nSpending Public Key:`);
321
- console.log(` ${keys.spendingPublicKey}`);
322
- console.log("\n💡 You can now generate stealth addresses for this user");
323
- console.log("━".repeat(60));
324
- }
325
- async exportKeys() {
326
- console.log("\n📤 Export Stealth Keys");
327
- console.log("━".repeat(60));
328
- const encrypted = await this.stealth.exportStealthKeys();
329
- console.log("\n🔐 Encrypted keys (store safely):");
330
- console.log(encrypted);
331
- console.log("━".repeat(60));
332
- }
333
- async publishKeys() {
334
- console.log("\n📡 Publish Stealth Keys");
335
- console.log("━".repeat(60));
336
- try {
337
- await this.stealth.publishStealthKeys();
338
- console.log("✅ Stealth keys published successfully!");
339
- console.log("💡 Others can now generate stealth addresses for you");
340
- // Verify publication by reading back
341
- const currentUser = this.identity.getCurrentUser();
342
- if (currentUser?.pub) {
343
- console.log("\n🔍 Verifying publication...");
344
- const keys = await this.stealth.getPublicStealthKeys(currentUser.pub);
345
- if (keys) {
346
- console.log("✅ Verification successful - keys are accessible!");
347
- console.log(` Viewing: ${keys.viewingPublicKey.slice(0, 30)}...`);
348
- console.log(` Spending: ${keys.spendingPublicKey.slice(0, 30)}...`);
349
- }
350
- else {
351
- console.log("⚠️ Verification failed - keys may need time to propagate");
352
- console.log("💡 Wait a few seconds and try looking up your own keys");
353
- }
354
- }
355
- console.log("━".repeat(60));
356
- }
357
- catch (error) {
358
- console.log(`❌ Error: ${error.message}`);
359
- }
360
- }
361
- async showWalletInfo() {
362
- console.log("\n💼 Wallet Info (SHIP-02)");
363
- console.log("━".repeat(60));
364
- const primaryAddr = await this.eth.getPrimaryAddress();
365
- console.log(` Primary Address: ${primaryAddr}`);
366
- const masterPubKey = await this.eth.getMasterPublicKey();
367
- console.log(` Master Pub Key: ${masterPubKey.slice(0, 20)}...`);
368
- const allAddrs = await this.eth.getAllAddresses();
369
- console.log(` Total Addresses: ${allAddrs.length}`);
370
- console.log("━".repeat(60));
371
- }
372
- // ==========================================================================
373
- // Utilities
374
- // ==========================================================================
375
- async prompt(question) {
376
- return new Promise((resolve) => {
377
- this.rl.question(question, (answer) => {
378
- resolve(answer);
379
- });
380
- });
381
- }
382
- close() {
383
- this.rl.close();
384
- }
385
- }
386
- exports.StealthCLI = StealthCLI;
387
- // ============================================================================
388
- // Main Entry Point
389
- // ============================================================================
390
- async function main() {
391
- const args = process.argv.slice(2);
392
- if (args.length < 2) {
393
- console.log("\n🎭 SHIP-03 Stealth Address CLI");
394
- console.log("━".repeat(60));
395
- console.log("\nUsage:");
396
- console.log(" yarn stealth <username> <password>");
397
- console.log("\nExample:");
398
- console.log(" yarn stealth alice password123");
399
- console.log("\n━".repeat(60));
400
- process.exit(1);
401
- }
402
- const [username, password] = args;
403
- const cli = new StealthCLI();
404
- try {
405
- // Try login first
406
- let success = await cli.login(username, password);
407
- // If login fails, offer to register
408
- if (!success) {
409
- const shouldRegister = await cli.prompt(`\nUser ${username} not found. Register? (y/n): `);
410
- if (shouldRegister.toLowerCase() === "y") {
411
- success = await cli.register(username, password);
412
- }
413
- }
414
- if (success) {
415
- // Show menu
416
- await cli.showMenu();
417
- }
418
- else {
419
- console.log("\n❌ Authentication failed");
420
- cli.close();
421
- process.exit(1);
422
- }
423
- }
424
- catch (error) {
425
- console.error("\n❌ Error:", error);
426
- cli.close();
427
- process.exit(1);
428
- }
429
- }
430
- // Run if called directly
431
- if (require.main === module) {
432
- main();
433
- }