shogun-core 3.3.0 → 3.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/dist/browser/shogun-core.js +83301 -148719
  2. package/dist/browser/shogun-core.js.map +1 -1
  3. package/dist/{src/index.js → index.js} +1 -15
  4. package/dist/types/{src/index.d.ts → index.d.ts} +0 -10
  5. package/dist/types/{src/types → types}/shogun.d.ts +2 -0
  6. package/package.json +1 -1
  7. package/dist/browser/_e6ae.shogun-core.js +0 -14
  8. package/dist/browser/_e6ae.shogun-core.js.map +0 -1
  9. package/dist/ship/examples/messenger-cli.js +0 -745
  10. package/dist/ship/examples/wallet-cli.js +0 -767
  11. package/dist/ship/implementation/SHIP_00.js +0 -478
  12. package/dist/ship/implementation/SHIP_01.js +0 -433
  13. package/dist/ship/implementation/SHIP_02.js +0 -1366
  14. package/dist/ship/implementation/SHIP_03.js +0 -855
  15. package/dist/ship/interfaces/ISHIP_00.js +0 -135
  16. package/dist/ship/interfaces/ISHIP_01.js +0 -128
  17. package/dist/ship/interfaces/ISHIP_02.js +0 -57
  18. package/dist/ship/interfaces/ISHIP_03.js +0 -61
  19. package/dist/types/ship/examples/messenger-cli.d.ts +0 -37
  20. package/dist/types/ship/examples/wallet-cli.d.ts +0 -131
  21. package/dist/types/ship/implementation/SHIP_00.d.ts +0 -113
  22. package/dist/types/ship/implementation/SHIP_01.d.ts +0 -80
  23. package/dist/types/ship/implementation/SHIP_02.d.ts +0 -297
  24. package/dist/types/ship/implementation/SHIP_03.d.ts +0 -127
  25. package/dist/types/ship/interfaces/ISHIP_00.d.ts +0 -410
  26. package/dist/types/ship/interfaces/ISHIP_01.d.ts +0 -343
  27. package/dist/types/ship/interfaces/ISHIP_02.d.ts +0 -470
  28. package/dist/types/ship/interfaces/ISHIP_03.d.ts +0 -295
  29. /package/dist/{src/config → config}/simplified-config.js +0 -0
  30. /package/dist/{src/core.js → core.js} +0 -0
  31. /package/dist/{src/examples → examples}/api-test.js +0 -0
  32. /package/dist/{src/examples → examples}/simple-api-test.js +0 -0
  33. /package/dist/{src/gundb → gundb}/api.js +0 -0
  34. /package/dist/{src/gundb → gundb}/crypto.js +0 -0
  35. /package/dist/{src/gundb → gundb}/db.js +0 -0
  36. /package/dist/{src/gundb → gundb}/derive.js +0 -0
  37. /package/dist/{src/gundb → gundb}/errors.js +0 -0
  38. /package/dist/{src/gundb → gundb}/index.js +0 -0
  39. /package/dist/{src/gundb → gundb}/rxjs.js +0 -0
  40. /package/dist/{src/gundb → gundb}/types.js +0 -0
  41. /package/dist/{src/interfaces → interfaces}/common.js +0 -0
  42. /package/dist/{src/interfaces → interfaces}/events.js +0 -0
  43. /package/dist/{src/interfaces → interfaces}/plugin.js +0 -0
  44. /package/dist/{src/interfaces → interfaces}/shogun.js +0 -0
  45. /package/dist/{src/managers → managers}/AuthManager.js +0 -0
  46. /package/dist/{src/managers → managers}/CoreInitializer.js +0 -0
  47. /package/dist/{src/managers → managers}/EventManager.js +0 -0
  48. /package/dist/{src/managers → managers}/PluginManager.js +0 -0
  49. /package/dist/{src/migration-test.js → migration-test.js} +0 -0
  50. /package/dist/{src/plugins → plugins}/base.js +0 -0
  51. /package/dist/{src/plugins → plugins}/index.js +0 -0
  52. /package/dist/{src/plugins → plugins}/nostr/index.js +0 -0
  53. /package/dist/{src/plugins → plugins}/nostr/nostrConnector.js +0 -0
  54. /package/dist/{src/plugins → plugins}/nostr/nostrConnectorPlugin.js +0 -0
  55. /package/dist/{src/plugins → plugins}/nostr/nostrSigner.js +0 -0
  56. /package/dist/{src/plugins → plugins}/nostr/types.js +0 -0
  57. /package/dist/{src/plugins → plugins}/oauth/index.js +0 -0
  58. /package/dist/{src/plugins → plugins}/oauth/oauthConnector.js +0 -0
  59. /package/dist/{src/plugins → plugins}/oauth/oauthPlugin.js +0 -0
  60. /package/dist/{src/plugins → plugins}/oauth/types.js +0 -0
  61. /package/dist/{src/plugins → plugins}/web3/index.js +0 -0
  62. /package/dist/{src/plugins → plugins}/web3/types.js +0 -0
  63. /package/dist/{src/plugins → plugins}/web3/web3Connector.js +0 -0
  64. /package/dist/{src/plugins → plugins}/web3/web3ConnectorPlugin.js +0 -0
  65. /package/dist/{src/plugins → plugins}/web3/web3Signer.js +0 -0
  66. /package/dist/{src/plugins → plugins}/webauthn/index.js +0 -0
  67. /package/dist/{src/plugins → plugins}/webauthn/types.js +0 -0
  68. /package/dist/{src/plugins → plugins}/webauthn/webauthn.js +0 -0
  69. /package/dist/{src/plugins → plugins}/webauthn/webauthnPlugin.js +0 -0
  70. /package/dist/{src/plugins → plugins}/webauthn/webauthnSigner.js +0 -0
  71. /package/dist/{src/storage → storage}/storage.js +0 -0
  72. /package/dist/types/{src/config → config}/simplified-config.d.ts +0 -0
  73. /package/dist/types/{src/core.d.ts → core.d.ts} +0 -0
  74. /package/dist/{src/types → types}/events.js +0 -0
  75. /package/dist/types/{src/examples → examples}/api-test.d.ts +0 -0
  76. /package/dist/types/{src/examples → examples}/simple-api-test.d.ts +0 -0
  77. /package/dist/types/{src/gundb → gundb}/api.d.ts +0 -0
  78. /package/dist/types/{src/gundb → gundb}/crypto.d.ts +0 -0
  79. /package/dist/types/{src/gundb → gundb}/db.d.ts +0 -0
  80. /package/dist/types/{src/gundb → gundb}/derive.d.ts +0 -0
  81. /package/dist/types/{src/gundb → gundb}/errors.d.ts +0 -0
  82. /package/dist/types/{src/gundb → gundb}/index.d.ts +0 -0
  83. /package/dist/types/{src/gundb → gundb}/rxjs.d.ts +0 -0
  84. /package/dist/types/{src/gundb → gundb}/types.d.ts +0 -0
  85. /package/dist/types/{src/interfaces → interfaces}/common.d.ts +0 -0
  86. /package/dist/types/{src/interfaces → interfaces}/events.d.ts +0 -0
  87. /package/dist/types/{src/interfaces → interfaces}/plugin.d.ts +0 -0
  88. /package/dist/types/{src/interfaces → interfaces}/shogun.d.ts +0 -0
  89. /package/dist/types/{src/managers → managers}/AuthManager.d.ts +0 -0
  90. /package/dist/types/{src/managers → managers}/CoreInitializer.d.ts +0 -0
  91. /package/dist/types/{src/managers → managers}/EventManager.d.ts +0 -0
  92. /package/dist/types/{src/managers → managers}/PluginManager.d.ts +0 -0
  93. /package/dist/types/{src/migration-test.d.ts → migration-test.d.ts} +0 -0
  94. /package/dist/types/{src/plugins → plugins}/base.d.ts +0 -0
  95. /package/dist/types/{src/plugins → plugins}/index.d.ts +0 -0
  96. /package/dist/types/{src/plugins → plugins}/nostr/index.d.ts +0 -0
  97. /package/dist/types/{src/plugins → plugins}/nostr/nostrConnector.d.ts +0 -0
  98. /package/dist/types/{src/plugins → plugins}/nostr/nostrConnectorPlugin.d.ts +0 -0
  99. /package/dist/types/{src/plugins → plugins}/nostr/nostrSigner.d.ts +0 -0
  100. /package/dist/types/{src/plugins → plugins}/nostr/types.d.ts +0 -0
  101. /package/dist/types/{src/plugins → plugins}/oauth/index.d.ts +0 -0
  102. /package/dist/types/{src/plugins → plugins}/oauth/oauthConnector.d.ts +0 -0
  103. /package/dist/types/{src/plugins → plugins}/oauth/oauthPlugin.d.ts +0 -0
  104. /package/dist/types/{src/plugins → plugins}/oauth/types.d.ts +0 -0
  105. /package/dist/types/{src/plugins → plugins}/web3/index.d.ts +0 -0
  106. /package/dist/types/{src/plugins → plugins}/web3/types.d.ts +0 -0
  107. /package/dist/types/{src/plugins → plugins}/web3/web3Connector.d.ts +0 -0
  108. /package/dist/types/{src/plugins → plugins}/web3/web3ConnectorPlugin.d.ts +0 -0
  109. /package/dist/types/{src/plugins → plugins}/web3/web3Signer.d.ts +0 -0
  110. /package/dist/types/{src/plugins → plugins}/webauthn/index.d.ts +0 -0
  111. /package/dist/types/{src/plugins → plugins}/webauthn/types.d.ts +0 -0
  112. /package/dist/types/{src/plugins → plugins}/webauthn/webauthn.d.ts +0 -0
  113. /package/dist/types/{src/plugins → plugins}/webauthn/webauthnPlugin.d.ts +0 -0
  114. /package/dist/types/{src/plugins → plugins}/webauthn/webauthnSigner.d.ts +0 -0
  115. /package/dist/{src/types → types}/shogun.js +0 -0
  116. /package/dist/types/{src/storage → storage}/storage.d.ts +0 -0
  117. /package/dist/types/{src/types → types}/events.d.ts +0 -0
  118. /package/dist/types/{src/utils → utils}/errorHandler.d.ts +0 -0
  119. /package/dist/types/{src/utils → utils}/eventEmitter.d.ts +0 -0
  120. /package/dist/types/{src/utils → utils}/validation.d.ts +0 -0
  121. /package/dist/{src/utils → utils}/errorHandler.js +0 -0
  122. /package/dist/{src/utils → utils}/eventEmitter.js +0 -0
  123. /package/dist/{src/utils → utils}/validation.js +0 -0
@@ -1,767 +0,0 @@
1
- "use strict";
2
- /**
3
- * SHIP-02 Example: Ethereum Wallet CLI
4
- *
5
- * Interactive CLI demonstrating SHIP-02 HD wallet derivation
6
- * Built on top of SHIP-00 identity
7
- *
8
- * Usage:
9
- * yarn wallet <username> <password>
10
- *
11
- * Features:
12
- * - Derive Ethereum addresses from identity (no mnemonics!)
13
- * - BIP-44 HD wallet support
14
- * - Sign transactions and messages
15
- * - Export/import address book
16
- * - Gun persistence
17
- *
18
- * Note: For stealth addresses, use `yarn stealth` (SHIP-03)
19
- */
20
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
21
- if (k2 === undefined) k2 = k;
22
- var desc = Object.getOwnPropertyDescriptor(m, k);
23
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
24
- desc = { enumerable: true, get: function() { return m[k]; } };
25
- }
26
- Object.defineProperty(o, k2, desc);
27
- }) : (function(o, m, k, k2) {
28
- if (k2 === undefined) k2 = k;
29
- o[k2] = m[k];
30
- }));
31
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
32
- Object.defineProperty(o, "default", { enumerable: true, value: v });
33
- }) : function(o, v) {
34
- o["default"] = v;
35
- });
36
- var __importStar = (this && this.__importStar) || (function () {
37
- var ownKeys = function(o) {
38
- ownKeys = Object.getOwnPropertyNames || function (o) {
39
- var ar = [];
40
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
41
- return ar;
42
- };
43
- return ownKeys(o);
44
- };
45
- return function (mod) {
46
- if (mod && mod.__esModule) return mod;
47
- var result = {};
48
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
49
- __setModuleDefault(result, mod);
50
- return result;
51
- };
52
- })();
53
- Object.defineProperty(exports, "__esModule", { value: true });
54
- exports.WalletCLI = void 0;
55
- const SHIP_00_1 = require("../implementation/SHIP_00");
56
- const SHIP_02_1 = require("../implementation/SHIP_02");
57
- const readline = __importStar(require("readline"));
58
- const ethers_1 = require("ethers");
59
- // ============================================================================
60
- // CLI INTERFACE
61
- // ============================================================================
62
- class WalletCLI {
63
- constructor(username, password) {
64
- this.running = false;
65
- this.username = username;
66
- // Initialize SHIP-00 identity
67
- this.identity = new SHIP_00_1.SHIP_00({
68
- gunOptions: {
69
- peers: [
70
- "https://peer.wallie.io/gun",
71
- "https://v5g5jseqhgkp43lppgregcfbvi.srv.us/gun",
72
- "https://relay.shogun-eco.xyz/gun",
73
- ],
74
- radisk: true,
75
- localStorage: false,
76
- },
77
- });
78
- // Initialize SHIP-02 wallet
79
- this.wallet = new SHIP_02_1.SHIP_02(this.identity);
80
- // Setup readline interface
81
- this.rl = readline.createInterface({
82
- input: process.stdin,
83
- output: process.stdout,
84
- });
85
- }
86
- /**
87
- * Start the CLI
88
- */
89
- async start(password) {
90
- console.clear();
91
- this.printHeader();
92
- try {
93
- // Step 1: Authenticate with SHIP-00
94
- await this.authenticate(password);
95
- // Step 2: Initialize SHIP-02
96
- await this.initializeWallet();
97
- // Step 3: Show main menu
98
- this.running = true;
99
- await this.mainMenu();
100
- }
101
- catch (error) {
102
- console.error("\n❌ Error:", error.message);
103
- this.cleanup();
104
- }
105
- }
106
- /**
107
- * Authenticate user with SHIP-00
108
- */
109
- async authenticate(password) {
110
- console.log("\n🔐 STEP 1: Authenticating with SHIP-00");
111
- console.log("═".repeat(60));
112
- try {
113
- // Try login first
114
- const loginResult = await this.identity.login(this.username, password);
115
- if (loginResult.success) {
116
- console.log(`✅ Logged in as: ${this.username}`);
117
- console.log(`📍 Public Key: ${loginResult.userPub?.substring(0, 20)}...`);
118
- }
119
- else {
120
- // If login fails, try signup
121
- console.log("🔄 User not found, creating new identity...");
122
- const signupResult = await this.identity.signup(this.username, password);
123
- if (!signupResult.success) {
124
- throw new Error(signupResult.error || "Authentication failed");
125
- }
126
- // Login after signup
127
- await this.identity.login(this.username, password);
128
- console.log(`✅ Created new identity: ${this.username}`);
129
- // Publish public key
130
- await this.identity.publishPublicKey();
131
- console.log("✅ Published public key to network");
132
- }
133
- }
134
- catch (error) {
135
- throw new Error(`Authentication failed: ${error.message}`);
136
- }
137
- }
138
- /**
139
- * Initialize SHIP-02 wallet
140
- */
141
- async initializeWallet() {
142
- console.log("\n💼 STEP 2: Initializing SHIP-02 Wallet");
143
- console.log("═".repeat(60));
144
- try {
145
- // Ask if user wants to use mnemonic mode
146
- const useMnemonicStr = await this.prompt("Use BIP-39 mnemonic for MetaMask compatibility? (y/n, default: n): ");
147
- const useMnemonic = useMnemonicStr.toLowerCase().trim() === "y";
148
- await this.wallet.initialize(useMnemonic);
149
- if (useMnemonic) {
150
- const mnemonic = await this.wallet.getMnemonic();
151
- if (mnemonic) {
152
- console.log("\n📝 Your BIP-39 Mnemonic (SAVE THIS!):");
153
- console.log("━".repeat(60));
154
- console.log(mnemonic);
155
- console.log("━".repeat(60));
156
- console.log("💡 You can import this in MetaMask for compatibility");
157
- // Show MetaMask addresses for verification
158
- const addresses = this.wallet.getStandardBIP44Addresses(mnemonic, 3);
159
- console.log("\n📍 First 3 MetaMask-compatible addresses:");
160
- addresses.forEach((addr, i) => {
161
- console.log(` ${i}: ${addr}`);
162
- });
163
- }
164
- }
165
- else {
166
- console.log("✅ Wallet derived from SHIP-00 identity (no mnemonic)");
167
- }
168
- // Derive primary address
169
- const primaryAddress = await this.wallet.getPrimaryAddress();
170
- console.log(`\n✅ Primary address: ${primaryAddress}`);
171
- // Set label for primary address
172
- await this.wallet.setAddressLabel(primaryAddress, "Main Wallet");
173
- }
174
- catch (error) {
175
- throw new Error(`Wallet initialization failed: ${error.message}`);
176
- }
177
- }
178
- /**
179
- * Main menu loop
180
- */
181
- async mainMenu() {
182
- while (this.running) {
183
- console.log("\n" + "═".repeat(60));
184
- console.log("🗡️ SHOGUN WALLET - Main Menu");
185
- console.log("═".repeat(60));
186
- console.log("1. View Addresses");
187
- console.log("2. Derive New Address");
188
- console.log("3. Derive BIP-44 Address");
189
- console.log("4. Derive Multiple Addresses");
190
- console.log("5. Sign Message");
191
- console.log("6. Sign Transaction");
192
- console.log("7. Export Address Book");
193
- console.log("8. Import Address Book");
194
- console.log("9. View Master Public Key");
195
- console.log("10. Export Wallet Data");
196
- console.log("11. Sync with Gun");
197
- console.log("12. View/Export Mnemonic");
198
- console.log("13. Verify MetaMask Addresses");
199
- console.log("14. Create Wallet (Frontend API)");
200
- console.log("15. Load All Wallets");
201
- console.log("16. Get Main Wallet");
202
- console.log("17. Export All User Data");
203
- console.log("18. Set RPC Provider");
204
- console.log("19. Send Transaction (RPC)");
205
- console.log("20. Exit");
206
- console.log("\n💡 For stealth addresses, use: yarn stealth");
207
- console.log("═".repeat(60));
208
- const choice = await this.prompt("Select option (1-20): ");
209
- switch (choice.trim()) {
210
- case "1":
211
- await this.viewAddresses();
212
- break;
213
- case "2":
214
- await this.deriveNewAddress();
215
- break;
216
- case "3":
217
- await this.deriveBIP44Address();
218
- break;
219
- case "4":
220
- await this.deriveMultipleAddresses();
221
- break;
222
- case "5":
223
- await this.signMessage();
224
- break;
225
- case "6":
226
- await this.signTransaction();
227
- break;
228
- case "7":
229
- await this.exportAddressBook();
230
- break;
231
- case "8":
232
- await this.importAddressBook();
233
- break;
234
- case "9":
235
- await this.viewMasterPublicKey();
236
- break;
237
- case "10":
238
- await this.exportWalletData();
239
- break;
240
- case "11":
241
- await this.syncWithGun();
242
- break;
243
- case "12":
244
- await this.viewExportMnemonic();
245
- break;
246
- case "13":
247
- await this.verifyMetaMaskAddresses();
248
- break;
249
- case "14":
250
- await this.createWalletFrontendAPI();
251
- break;
252
- case "15":
253
- await this.loadAllWallets();
254
- break;
255
- case "16":
256
- await this.viewMainWallet();
257
- break;
258
- case "17":
259
- await this.exportAllUserData();
260
- break;
261
- case "18":
262
- await this.setRpcProvider();
263
- break;
264
- case "19":
265
- await this.sendTransactionRPC();
266
- break;
267
- case "20":
268
- this.running = false;
269
- console.log("\n👋 Goodbye!");
270
- this.cleanup();
271
- break;
272
- default:
273
- console.log("❌ Invalid option");
274
- }
275
- }
276
- }
277
- /**
278
- * View all addresses
279
- */
280
- async viewAddresses() {
281
- console.log("\n📋 Your Addresses");
282
- console.log("═".repeat(60));
283
- const addresses = await this.wallet.getAllAddresses();
284
- if (addresses.length === 0) {
285
- console.log("No addresses yet. Derive one from the menu!");
286
- return;
287
- }
288
- for (const entry of addresses) {
289
- const label = entry.label || "Unnamed";
290
- console.log(`\n💼 Address #${entry.index}: ${label}`);
291
- console.log(` Address: ${entry.address}`);
292
- console.log(` Path: ${entry.path}`);
293
- console.log(` Public Key: ${entry.publicKey.substring(0, 20)}...`);
294
- console.log(` Created: ${new Date(entry.createdAt).toLocaleString()}`);
295
- }
296
- }
297
- /**
298
- * Derive new address with custom index
299
- */
300
- async deriveNewAddress() {
301
- console.log("\n🔑 Derive New Address");
302
- console.log("═".repeat(60));
303
- const indexStr = await this.prompt("Enter address index (default 0): ");
304
- const index = parseInt(indexStr) || 0;
305
- const result = await this.wallet.deriveBIP44Address(60, 0, 0, index);
306
- if (result.success && result.address) {
307
- console.log("✅ Address derived successfully!");
308
- console.log(` Address: ${result.address}`);
309
- console.log(` Path: ${result.path}`);
310
- const label = await this.prompt("Enter label (optional): ");
311
- if (label.trim()) {
312
- await this.wallet.setAddressLabel(result.address, label);
313
- console.log("✅ Label set");
314
- }
315
- }
316
- else {
317
- console.log(`❌ Error: ${result.error}`);
318
- }
319
- }
320
- /**
321
- * Derive BIP-44 address with custom parameters
322
- */
323
- async deriveBIP44Address() {
324
- console.log("\n🔑 Derive BIP-44 Address");
325
- console.log("═".repeat(60));
326
- const coinTypeStr = await this.prompt("Coin type (60 for Ethereum): ");
327
- const accountStr = await this.prompt("Account index (default 0): ");
328
- const changeStr = await this.prompt("Change chain (0=external, 1=internal): ");
329
- const indexStr = await this.prompt("Address index: ");
330
- const coinType = parseInt(coinTypeStr) || 60;
331
- const account = parseInt(accountStr) || 0;
332
- const change = parseInt(changeStr) || 0;
333
- const index = parseInt(indexStr) || 0;
334
- const result = await this.wallet.deriveBIP44Address(coinType, account, change, index);
335
- if (result.success && result.address) {
336
- console.log("✅ Address derived successfully!");
337
- console.log(` Address: ${result.address}`);
338
- console.log(` Path: ${result.path}`);
339
- }
340
- else {
341
- console.log(`❌ Error: ${result.error}`);
342
- }
343
- }
344
- /**
345
- * Derive multiple addresses at once
346
- */
347
- async deriveMultipleAddresses() {
348
- console.log("\n🔢 Derive Multiple Addresses");
349
- console.log("═".repeat(60));
350
- const countStr = await this.prompt("How many addresses to derive? ");
351
- const startIndexStr = await this.prompt("Starting index (default 0): ");
352
- const count = parseInt(countStr) || 1;
353
- const startIndex = parseInt(startIndexStr) || 0;
354
- if (count < 1 || count > 20) {
355
- console.log("❌ Please enter a number between 1 and 20");
356
- return;
357
- }
358
- console.log(`\n🔄 Deriving ${count} addresses...`);
359
- const results = await this.wallet.deriveMultipleAddresses(count, startIndex);
360
- console.log(`✅ Derived ${results.length} addresses:`);
361
- results.forEach((result, i) => {
362
- if (result.success && result.address) {
363
- console.log(` ${i + 1}. ${result.address}`);
364
- console.log(` Path: ${result.path}`);
365
- }
366
- });
367
- }
368
- /**
369
- * Import address book
370
- */
371
- async importAddressBook() {
372
- console.log("\n📥 Import Address Book");
373
- console.log("═".repeat(60));
374
- const jsonStr = await this.prompt("Paste address book JSON: ");
375
- try {
376
- const addressBook = JSON.parse(jsonStr);
377
- await this.wallet.importAddressBook(addressBook);
378
- console.log("✅ Address book imported successfully!");
379
- }
380
- catch (error) {
381
- console.log(`❌ Error: ${error.message}`);
382
- }
383
- }
384
- /**
385
- * Export encrypted wallet data
386
- */
387
- async exportWalletData() {
388
- console.log("\n📤 Export Wallet Data (Encrypted)");
389
- console.log("═".repeat(60));
390
- try {
391
- const encrypted = await this.wallet.exportWalletData();
392
- console.log("✅ Wallet data exported (encrypted with SHIP-00 keys):");
393
- console.log(encrypted);
394
- console.log("\n💡 Store this safely - you can restore your wallet with it");
395
- }
396
- catch (error) {
397
- console.log(`❌ Error: ${error.message}`);
398
- }
399
- }
400
- /**
401
- * Sync with Gun database
402
- */
403
- async syncWithGun() {
404
- console.log("\n🔄 Sync with Gun Database");
405
- console.log("═".repeat(60));
406
- try {
407
- // Enable persistence
408
- this.wallet.enableGunPersistence();
409
- // Sync
410
- await this.wallet.syncWithGun();
411
- console.log("✅ Synced successfully with Gun");
412
- console.log("💡 Address book is now backed up on Gun network");
413
- }
414
- catch (error) {
415
- console.log(`❌ Error: ${error.message}`);
416
- }
417
- }
418
- /**
419
- * View/Export mnemonic
420
- */
421
- async viewExportMnemonic() {
422
- console.log("\n📝 Mnemonic Management");
423
- console.log("═".repeat(60));
424
- const mnemonic = await this.wallet.getMnemonic();
425
- if (!mnemonic) {
426
- console.log("❌ No mnemonic available");
427
- console.log("💡 This wallet was initialized from SHIP-00 identity");
428
- console.log("💡 To use mnemonic mode, re-initialize with mnemonic option");
429
- return;
430
- }
431
- console.log("\n🔐 Your BIP-39 Mnemonic:");
432
- console.log("━".repeat(60));
433
- console.log(mnemonic);
434
- console.log("━".repeat(60));
435
- console.log("\n⚠️ KEEP THIS SAFE! Anyone with this can access your wallet");
436
- console.log("💡 You can import this in MetaMask, Trust Wallet, etc.");
437
- // Ask if user wants encrypted export
438
- const exportStr = await this.prompt("\nExport encrypted version? (y/n): ");
439
- if (exportStr.toLowerCase().trim() === "y") {
440
- const encrypted = await this.wallet.exportMnemonic();
441
- if (encrypted) {
442
- console.log("\n🔐 Encrypted Mnemonic:");
443
- console.log(encrypted);
444
- }
445
- }
446
- }
447
- /**
448
- * Verify addresses match MetaMask
449
- */
450
- async verifyMetaMaskAddresses() {
451
- console.log("\n🔍 Verify MetaMask Compatibility");
452
- console.log("═".repeat(60));
453
- const mnemonic = await this.wallet.getMnemonic();
454
- if (!mnemonic) {
455
- console.log("❌ No mnemonic available");
456
- console.log("💡 This feature requires mnemonic mode");
457
- return;
458
- }
459
- console.log("\n📍 Comparing addresses with MetaMask standard...");
460
- const standardAddresses = this.wallet.getStandardBIP44Addresses(mnemonic, 5);
461
- const derivedAddresses = await this.wallet.deriveMultipleAddresses(5, 0);
462
- console.log("\n📊 MetaMask Standard (m/44'/60'/0'/0/N):");
463
- standardAddresses.forEach((addr, i) => {
464
- console.log(` ${i}: ${addr}`);
465
- });
466
- console.log("\n📊 SHIP-02 Derived:");
467
- derivedAddresses.forEach((result, i) => {
468
- if (result.success && result.address) {
469
- console.log(` ${i}: ${result.address}`);
470
- // Check if matches
471
- const matches = result.address === standardAddresses[i];
472
- console.log(` ${matches ? "✅ MATCH" : "⚠️ DIFFERENT"}`);
473
- }
474
- });
475
- console.log("\n💡 If using mnemonic mode, addresses should match MetaMask");
476
- }
477
- /**
478
- * Sign message
479
- */
480
- async signMessage() {
481
- console.log("\n✍️ Sign Message");
482
- console.log("═".repeat(60));
483
- const message = await this.prompt("Enter message to sign: ");
484
- const addressInput = await this.prompt("Address to sign with (leave empty for primary): ");
485
- const address = addressInput || (await this.wallet.getPrimaryAddress());
486
- try {
487
- const signature = await this.wallet.signMessage(message, address);
488
- console.log("✅ Message signed successfully!");
489
- console.log(` Signature: ${signature}`);
490
- // Verify signature
491
- const isValid = await this.wallet.verifySignature(message, signature, address);
492
- console.log(` Verification: ${isValid ? "✅ Valid" : "❌ Invalid"}`);
493
- }
494
- catch (error) {
495
- console.log(`❌ Error: ${error.message}`);
496
- }
497
- }
498
- /**
499
- * Sign transaction
500
- */
501
- async signTransaction() {
502
- console.log("\n✍️ Sign Transaction");
503
- console.log("═".repeat(60));
504
- const to = await this.prompt("To address: ");
505
- const valueStr = await this.prompt("Value in ETH: ");
506
- const chainIdStr = await this.prompt("Chain ID (1 for mainnet): ");
507
- const addressInput = await this.prompt("Address to sign with (leave empty for primary): ");
508
- const address = addressInput || (await this.wallet.getPrimaryAddress());
509
- try {
510
- const tx = {
511
- to,
512
- value: ethers_1.ethers.parseEther(valueStr),
513
- chainId: parseInt(chainIdStr) || 1,
514
- gasLimit: BigInt(21000),
515
- };
516
- const result = await this.wallet.signTransaction(tx, address);
517
- if (result.success) {
518
- console.log("✅ Transaction signed successfully!");
519
- console.log(` Transaction Hash: ${result.txHash}`);
520
- console.log(` Signed Transaction: ${result.signedTransaction?.substring(0, 50)}...`);
521
- console.log("\n💡 You can now broadcast this transaction to the network");
522
- }
523
- else {
524
- console.log(`❌ Error: ${result.error}`);
525
- }
526
- }
527
- catch (error) {
528
- console.log(`❌ Error: ${error.message}`);
529
- }
530
- }
531
- /**
532
- * Export address book
533
- */
534
- async exportAddressBook() {
535
- console.log("\n📤 Export Address Book");
536
- console.log("═".repeat(60));
537
- const addressBook = await this.wallet.exportAddressBook();
538
- console.log(`✅ Address book exported`);
539
- console.log(` Total addresses: ${addressBook.addresses.length}`);
540
- console.log(` Master Public Key: ${addressBook.masterPublicKey.substring(0, 20)}...`);
541
- console.log(` Derivation Method: ${addressBook.derivationMethod}`);
542
- console.log("\n📋 Address Book JSON:");
543
- console.log(JSON.stringify(addressBook, null, 2));
544
- }
545
- /**
546
- * View master public key
547
- */
548
- async viewMasterPublicKey() {
549
- console.log("\n🔑 Master Public Key");
550
- console.log("═".repeat(60));
551
- const masterPubKey = await this.wallet.getMasterPublicKey();
552
- console.log(`Master Public Key (xpub):`);
553
- console.log(masterPubKey);
554
- console.log("\n💡 This key can derive all public addresses (but not sign)");
555
- }
556
- /**
557
- * Create wallet using frontend API
558
- */
559
- async createWalletFrontendAPI() {
560
- console.log("\n🆕 Create Wallet (Frontend API)");
561
- console.log("═".repeat(60));
562
- try {
563
- const walletInfo = await this.wallet.createWallet();
564
- console.log("✅ Wallet created successfully!");
565
- console.log(` Address: ${walletInfo.address}`);
566
- console.log(` Path: ${walletInfo.path}`);
567
- console.log(` Index: ${walletInfo.index}`);
568
- console.log(` Public Key: ${walletInfo.publicKey?.substring(0, 20)}...`);
569
- const label = await this.prompt("Enter label (optional): ");
570
- if (label.trim()) {
571
- await this.wallet.setAddressLabel(walletInfo.address, label);
572
- console.log("✅ Label set");
573
- }
574
- }
575
- catch (error) {
576
- console.log(`❌ Error: ${error.message}`);
577
- }
578
- }
579
- /**
580
- * Load all wallets using frontend API
581
- */
582
- async loadAllWallets() {
583
- console.log("\n📂 Load All Wallets");
584
- console.log("═".repeat(60));
585
- try {
586
- const wallets = await this.wallet.loadWallets();
587
- console.log(`✅ Loaded ${wallets.length} wallets:`);
588
- wallets.forEach((wallet, i) => {
589
- console.log(`\n💼 Wallet #${i}:`);
590
- console.log(` Address: ${wallet.address}`);
591
- console.log(` Path: ${wallet.path}`);
592
- console.log(` Public Key: ${wallet.publicKey?.substring(0, 20)}...`);
593
- });
594
- }
595
- catch (error) {
596
- console.log(`❌ Error: ${error.message}`);
597
- }
598
- }
599
- /**
600
- * View main wallet (derived from Gun keys)
601
- */
602
- async viewMainWallet() {
603
- console.log("\n🔑 Main Wallet (Gun-Derived)");
604
- console.log("═".repeat(60));
605
- try {
606
- const credentials = this.wallet.getMainWalletCredentials();
607
- console.log("✅ Main wallet credentials:");
608
- console.log(` Address: ${credentials.address}`);
609
- console.log(` Private Key: ${credentials.priv.substring(0, 20)}...`);
610
- console.log("\n💡 This wallet is derived from your Gun SEA keys");
611
- console.log("💡 It's different from BIP-44 derived wallets");
612
- }
613
- catch (error) {
614
- console.log(`❌ Error: ${error.message}`);
615
- }
616
- }
617
- /**
618
- * Export all user data (complete backup)
619
- */
620
- async exportAllUserData() {
621
- console.log("\n📦 Export All User Data");
622
- console.log("═".repeat(60));
623
- try {
624
- const backup = await this.wallet.exportAllUserData();
625
- console.log("✅ Complete backup created (encrypted):");
626
- console.log(backup.substring(0, 100) + "...");
627
- console.log("\n💡 This includes:");
628
- console.log(" - Mnemonic (encrypted)");
629
- console.log(" - All wallet keys");
630
- console.log(" - Gun SEA keypair");
631
- console.log(" - Address book");
632
- console.log("\n⚠️ KEEP THIS SAFE! Store in secure location.");
633
- }
634
- catch (error) {
635
- console.log(`❌ Error: ${error.message}`);
636
- }
637
- }
638
- /**
639
- * Set RPC provider URL
640
- */
641
- async setRpcProvider() {
642
- console.log("\n🌐 Set RPC Provider");
643
- console.log("═".repeat(60));
644
- console.log("💡 Examples:");
645
- console.log(" - Mainnet: https://mainnet.infura.io/v3/YOUR_KEY");
646
- console.log(" - Sepolia: https://sepolia.infura.io/v3/YOUR_KEY");
647
- console.log(" - Local: http://localhost:8545");
648
- const rpcUrl = await this.prompt("\nEnter RPC URL: ");
649
- try {
650
- await this.wallet.setRpcUrl(rpcUrl);
651
- console.log("✅ RPC Provider configured successfully");
652
- console.log("💡 You can now sign and send transactions");
653
- }
654
- catch (error) {
655
- console.log(`❌ Error: ${error.message}`);
656
- }
657
- }
658
- /**
659
- * Send transaction via RPC
660
- */
661
- async sendTransactionRPC() {
662
- console.log("\n📤 Send Transaction (via RPC)");
663
- console.log("═".repeat(60));
664
- // Check if RPC is configured
665
- const provider = this.wallet.getProvider();
666
- if (!provider) {
667
- console.log("❌ RPC Provider not configured!");
668
- console.log("💡 Use option 18 to configure RPC first");
669
- return;
670
- }
671
- const to = await this.prompt("To address: ");
672
- const valueStr = await this.prompt("Value in ETH: ");
673
- const addressInput = await this.prompt("Address to send from (leave empty for primary): ");
674
- const address = addressInput || (await this.wallet.getPrimaryAddress());
675
- // Ask for confirmation
676
- const waitInput = await this.prompt("Wait for confirmation? (y/n, default: y): ");
677
- const waitForConfirmation = waitInput.toLowerCase() !== "n";
678
- try {
679
- // Get nonce from network
680
- const nonce = await provider.getTransactionCount(address);
681
- const tx = {
682
- to,
683
- value: ethers_1.ethers.parseEther(valueStr),
684
- nonce,
685
- // Let ethers estimate gas
686
- };
687
- console.log("\n📝 Transaction Details:");
688
- console.log(` From: ${address}`);
689
- console.log(` To: ${to}`);
690
- console.log(` Value: ${valueStr} ETH`);
691
- console.log(` Nonce: ${nonce}`);
692
- const confirm = await this.prompt("\n⚠️ Confirm send? (yes/no): ");
693
- if (confirm.toLowerCase() !== "yes") {
694
- console.log("❌ Transaction cancelled");
695
- return;
696
- }
697
- console.log("\n⏳ Sending transaction...");
698
- const result = await this.wallet.sendTransaction(tx, address, waitForConfirmation);
699
- if (result.success) {
700
- console.log("\n✅ Transaction sent successfully!");
701
- console.log(` TX Hash: ${result.txHash}`);
702
- console.log(` Etherscan: https://etherscan.io/tx/${result.txHash}`);
703
- if (result.receipt) {
704
- console.log(`\n📦 Receipt:`);
705
- console.log(` Block: ${result.receipt.blockNumber}`);
706
- console.log(` Gas Used: ${result.receipt.gasUsed.toString()}`);
707
- console.log(` Status: ${result.receipt.status === 1 ? "✅ Success" : "❌ Failed"}`);
708
- }
709
- }
710
- else {
711
- console.log(`\n❌ Error: ${result.error}`);
712
- }
713
- }
714
- catch (error) {
715
- console.log(`\n❌ Error: ${error.message}`);
716
- }
717
- }
718
- /**
719
- * Print header
720
- */
721
- printHeader() {
722
- console.log("╔" + "═".repeat(58) + "╗");
723
- console.log("║" + " ".repeat(15) + "🗡️ SHOGUN WALLET 🗡️" + " ".repeat(15) + "║");
724
- console.log("║" + " ".repeat(12) + "SHIP-02: Address Derivation" + " ".repeat(12) + "║");
725
- console.log("╚" + "═".repeat(58) + "╝");
726
- }
727
- /**
728
- * Prompt user for input
729
- */
730
- prompt(question) {
731
- return new Promise((resolve) => {
732
- this.rl.question(question, (answer) => {
733
- resolve(answer);
734
- });
735
- });
736
- }
737
- /**
738
- * Cleanup and exit
739
- */
740
- cleanup() {
741
- this.rl.close();
742
- process.exit(0);
743
- }
744
- }
745
- exports.WalletCLI = WalletCLI;
746
- // ============================================================================
747
- // MAIN
748
- // ============================================================================
749
- async function main() {
750
- const args = process.argv.slice(2);
751
- if (args.length < 2) {
752
- console.log("Usage: yarn tsx ship/examples/wallet-cli.ts <username> <password>");
753
- console.log("\nExample:");
754
- console.log(" yarn tsx ship/examples/wallet-cli.ts alice mypassword123");
755
- process.exit(1);
756
- }
757
- const [username, password] = args;
758
- const cli = new WalletCLI(username, password);
759
- await cli.start(password);
760
- }
761
- // Run if executed directly
762
- if (require.main === module) {
763
- main().catch((error) => {
764
- console.error("Fatal error:", error);
765
- process.exit(1);
766
- });
767
- }