shogun-core 3.3.1 → 3.3.2

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 (147) hide show
  1. package/dist/ship/examples/ephemeral-cli.js +234 -0
  2. package/dist/ship/examples/identity-cli.js +503 -0
  3. package/dist/ship/examples/messenger-cli.js +745 -0
  4. package/dist/ship/examples/stealth-cli.js +433 -0
  5. package/dist/ship/examples/storage-cli.js +615 -0
  6. package/dist/ship/examples/vault-cli.js +444 -0
  7. package/dist/ship/examples/wallet-cli.js +767 -0
  8. package/dist/ship/implementation/SHIP_00.js +478 -0
  9. package/dist/ship/implementation/SHIP_01.js +433 -0
  10. package/dist/ship/implementation/SHIP_02.js +1366 -0
  11. package/dist/ship/implementation/SHIP_03.js +855 -0
  12. package/dist/ship/implementation/SHIP_04.js +589 -0
  13. package/dist/ship/implementation/SHIP_05.js +1064 -0
  14. package/dist/ship/implementation/SHIP_06.js +350 -0
  15. package/dist/ship/implementation/SHIP_07.js +635 -0
  16. package/dist/ship/index.js +17 -0
  17. package/dist/ship/interfaces/ISHIP_00.js +135 -0
  18. package/dist/ship/interfaces/ISHIP_01.js +128 -0
  19. package/dist/ship/interfaces/ISHIP_02.js +57 -0
  20. package/dist/ship/interfaces/ISHIP_03.js +61 -0
  21. package/dist/ship/interfaces/ISHIP_04.js +62 -0
  22. package/dist/ship/interfaces/ISHIP_05.js +59 -0
  23. package/dist/ship/interfaces/ISHIP_06.js +144 -0
  24. package/dist/ship/interfaces/ISHIP_07.js +194 -0
  25. package/dist/types/ship/examples/ephemeral-cli.d.ts +13 -0
  26. package/dist/types/ship/examples/identity-cli.d.ts +40 -0
  27. package/dist/types/ship/examples/messenger-cli.d.ts +37 -0
  28. package/dist/types/ship/examples/stealth-cli.d.ts +31 -0
  29. package/dist/types/ship/examples/storage-cli.d.ts +48 -0
  30. package/dist/types/ship/examples/vault-cli.d.ts +13 -0
  31. package/dist/types/ship/examples/wallet-cli.d.ts +131 -0
  32. package/dist/types/ship/implementation/SHIP_00.d.ts +113 -0
  33. package/dist/types/ship/implementation/SHIP_01.d.ts +80 -0
  34. package/dist/types/ship/implementation/SHIP_02.d.ts +297 -0
  35. package/dist/types/ship/implementation/SHIP_03.d.ts +127 -0
  36. package/dist/types/ship/implementation/SHIP_04.d.ts +76 -0
  37. package/dist/types/ship/implementation/SHIP_05.d.ts +70 -0
  38. package/dist/types/ship/implementation/SHIP_06.d.ts +66 -0
  39. package/dist/types/ship/implementation/SHIP_07.d.ts +101 -0
  40. package/dist/types/ship/index.d.ts +14 -0
  41. package/dist/types/ship/interfaces/ISHIP_00.d.ts +410 -0
  42. package/dist/types/ship/interfaces/ISHIP_01.d.ts +343 -0
  43. package/dist/types/ship/interfaces/ISHIP_02.d.ts +470 -0
  44. package/dist/types/ship/interfaces/ISHIP_03.d.ts +295 -0
  45. package/dist/types/ship/interfaces/ISHIP_04.d.ts +245 -0
  46. package/dist/types/ship/interfaces/ISHIP_05.d.ts +234 -0
  47. package/dist/types/ship/interfaces/ISHIP_06.d.ts +370 -0
  48. package/dist/types/ship/interfaces/ISHIP_07.d.ts +522 -0
  49. package/package.json +1 -1
  50. /package/dist/{config → src/config}/simplified-config.js +0 -0
  51. /package/dist/{core.js → src/core.js} +0 -0
  52. /package/dist/{examples → src/examples}/api-test.js +0 -0
  53. /package/dist/{examples → src/examples}/simple-api-test.js +0 -0
  54. /package/dist/{gundb → src/gundb}/api.js +0 -0
  55. /package/dist/{gundb → src/gundb}/crypto.js +0 -0
  56. /package/dist/{gundb → src/gundb}/db.js +0 -0
  57. /package/dist/{gundb → src/gundb}/derive.js +0 -0
  58. /package/dist/{gundb → src/gundb}/errors.js +0 -0
  59. /package/dist/{gundb → src/gundb}/index.js +0 -0
  60. /package/dist/{gundb → src/gundb}/rxjs.js +0 -0
  61. /package/dist/{gundb → src/gundb}/types.js +0 -0
  62. /package/dist/{index.js → src/index.js} +0 -0
  63. /package/dist/{interfaces → src/interfaces}/common.js +0 -0
  64. /package/dist/{interfaces → src/interfaces}/events.js +0 -0
  65. /package/dist/{interfaces → src/interfaces}/plugin.js +0 -0
  66. /package/dist/{interfaces → src/interfaces}/shogun.js +0 -0
  67. /package/dist/{managers → src/managers}/AuthManager.js +0 -0
  68. /package/dist/{managers → src/managers}/CoreInitializer.js +0 -0
  69. /package/dist/{managers → src/managers}/EventManager.js +0 -0
  70. /package/dist/{managers → src/managers}/PluginManager.js +0 -0
  71. /package/dist/{migration-test.js → src/migration-test.js} +0 -0
  72. /package/dist/{plugins → src/plugins}/base.js +0 -0
  73. /package/dist/{plugins → src/plugins}/index.js +0 -0
  74. /package/dist/{plugins → src/plugins}/nostr/index.js +0 -0
  75. /package/dist/{plugins → src/plugins}/nostr/nostrConnector.js +0 -0
  76. /package/dist/{plugins → src/plugins}/nostr/nostrConnectorPlugin.js +0 -0
  77. /package/dist/{plugins → src/plugins}/nostr/nostrSigner.js +0 -0
  78. /package/dist/{plugins → src/plugins}/nostr/types.js +0 -0
  79. /package/dist/{plugins → src/plugins}/oauth/index.js +0 -0
  80. /package/dist/{plugins → src/plugins}/oauth/oauthConnector.js +0 -0
  81. /package/dist/{plugins → src/plugins}/oauth/oauthPlugin.js +0 -0
  82. /package/dist/{plugins → src/plugins}/oauth/types.js +0 -0
  83. /package/dist/{plugins → src/plugins}/web3/index.js +0 -0
  84. /package/dist/{plugins → src/plugins}/web3/types.js +0 -0
  85. /package/dist/{plugins → src/plugins}/web3/web3Connector.js +0 -0
  86. /package/dist/{plugins → src/plugins}/web3/web3ConnectorPlugin.js +0 -0
  87. /package/dist/{plugins → src/plugins}/web3/web3Signer.js +0 -0
  88. /package/dist/{plugins → src/plugins}/webauthn/index.js +0 -0
  89. /package/dist/{plugins → src/plugins}/webauthn/types.js +0 -0
  90. /package/dist/{plugins → src/plugins}/webauthn/webauthn.js +0 -0
  91. /package/dist/{plugins → src/plugins}/webauthn/webauthnPlugin.js +0 -0
  92. /package/dist/{plugins → src/plugins}/webauthn/webauthnSigner.js +0 -0
  93. /package/dist/{storage → src/storage}/storage.js +0 -0
  94. /package/dist/{types → src/types}/events.js +0 -0
  95. /package/dist/{types → src/types}/shogun.js +0 -0
  96. /package/dist/{utils → src/utils}/errorHandler.js +0 -0
  97. /package/dist/{utils → src/utils}/eventEmitter.js +0 -0
  98. /package/dist/{utils → src/utils}/validation.js +0 -0
  99. /package/dist/types/{config → src/config}/simplified-config.d.ts +0 -0
  100. /package/dist/types/{core.d.ts → src/core.d.ts} +0 -0
  101. /package/dist/types/{examples → src/examples}/api-test.d.ts +0 -0
  102. /package/dist/types/{examples → src/examples}/simple-api-test.d.ts +0 -0
  103. /package/dist/types/{gundb → src/gundb}/api.d.ts +0 -0
  104. /package/dist/types/{gundb → src/gundb}/crypto.d.ts +0 -0
  105. /package/dist/types/{gundb → src/gundb}/db.d.ts +0 -0
  106. /package/dist/types/{gundb → src/gundb}/derive.d.ts +0 -0
  107. /package/dist/types/{gundb → src/gundb}/errors.d.ts +0 -0
  108. /package/dist/types/{gundb → src/gundb}/index.d.ts +0 -0
  109. /package/dist/types/{gundb → src/gundb}/rxjs.d.ts +0 -0
  110. /package/dist/types/{gundb → src/gundb}/types.d.ts +0 -0
  111. /package/dist/types/{index.d.ts → src/index.d.ts} +0 -0
  112. /package/dist/types/{interfaces → src/interfaces}/common.d.ts +0 -0
  113. /package/dist/types/{interfaces → src/interfaces}/events.d.ts +0 -0
  114. /package/dist/types/{interfaces → src/interfaces}/plugin.d.ts +0 -0
  115. /package/dist/types/{interfaces → src/interfaces}/shogun.d.ts +0 -0
  116. /package/dist/types/{managers → src/managers}/AuthManager.d.ts +0 -0
  117. /package/dist/types/{managers → src/managers}/CoreInitializer.d.ts +0 -0
  118. /package/dist/types/{managers → src/managers}/EventManager.d.ts +0 -0
  119. /package/dist/types/{managers → src/managers}/PluginManager.d.ts +0 -0
  120. /package/dist/types/{migration-test.d.ts → src/migration-test.d.ts} +0 -0
  121. /package/dist/types/{plugins → src/plugins}/base.d.ts +0 -0
  122. /package/dist/types/{plugins → src/plugins}/index.d.ts +0 -0
  123. /package/dist/types/{plugins → src/plugins}/nostr/index.d.ts +0 -0
  124. /package/dist/types/{plugins → src/plugins}/nostr/nostrConnector.d.ts +0 -0
  125. /package/dist/types/{plugins → src/plugins}/nostr/nostrConnectorPlugin.d.ts +0 -0
  126. /package/dist/types/{plugins → src/plugins}/nostr/nostrSigner.d.ts +0 -0
  127. /package/dist/types/{plugins → src/plugins}/nostr/types.d.ts +0 -0
  128. /package/dist/types/{plugins → src/plugins}/oauth/index.d.ts +0 -0
  129. /package/dist/types/{plugins → src/plugins}/oauth/oauthConnector.d.ts +0 -0
  130. /package/dist/types/{plugins → src/plugins}/oauth/oauthPlugin.d.ts +0 -0
  131. /package/dist/types/{plugins → src/plugins}/oauth/types.d.ts +0 -0
  132. /package/dist/types/{plugins → src/plugins}/web3/index.d.ts +0 -0
  133. /package/dist/types/{plugins → src/plugins}/web3/types.d.ts +0 -0
  134. /package/dist/types/{plugins → src/plugins}/web3/web3Connector.d.ts +0 -0
  135. /package/dist/types/{plugins → src/plugins}/web3/web3ConnectorPlugin.d.ts +0 -0
  136. /package/dist/types/{plugins → src/plugins}/web3/web3Signer.d.ts +0 -0
  137. /package/dist/types/{plugins → src/plugins}/webauthn/index.d.ts +0 -0
  138. /package/dist/types/{plugins → src/plugins}/webauthn/types.d.ts +0 -0
  139. /package/dist/types/{plugins → src/plugins}/webauthn/webauthn.d.ts +0 -0
  140. /package/dist/types/{plugins → src/plugins}/webauthn/webauthnPlugin.d.ts +0 -0
  141. /package/dist/types/{plugins → src/plugins}/webauthn/webauthnSigner.d.ts +0 -0
  142. /package/dist/types/{storage → src/storage}/storage.d.ts +0 -0
  143. /package/dist/types/{types → src/types}/events.d.ts +0 -0
  144. /package/dist/types/{types → src/types}/shogun.d.ts +0 -0
  145. /package/dist/types/{utils → src/utils}/errorHandler.d.ts +0 -0
  146. /package/dist/types/{utils → src/utils}/eventEmitter.d.ts +0 -0
  147. /package/dist/types/{utils → src/utils}/validation.d.ts +0 -0
@@ -0,0 +1,444 @@
1
+ #!/usr/bin/env tsx
2
+ "use strict";
3
+ /**
4
+ * SHIP-07 Secure Vault CLI Example
5
+ *
6
+ * Test secure encrypted vault with SHIP-07
7
+ *
8
+ * Usage:
9
+ * tsx ship/examples/vault-cli.ts <username> <password>
10
+ *
11
+ * Example:
12
+ * tsx ship/examples/vault-cli.ts alice pass123
13
+ */
14
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ var desc = Object.getOwnPropertyDescriptor(m, k);
17
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
+ desc = { enumerable: true, get: function() { return m[k]; } };
19
+ }
20
+ Object.defineProperty(o, k2, desc);
21
+ }) : (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ }));
25
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
26
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
27
+ }) : function(o, v) {
28
+ o["default"] = v;
29
+ });
30
+ var __importStar = (this && this.__importStar) || (function () {
31
+ var ownKeys = function(o) {
32
+ ownKeys = Object.getOwnPropertyNames || function (o) {
33
+ var ar = [];
34
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
35
+ return ar;
36
+ };
37
+ return ownKeys(o);
38
+ };
39
+ return function (mod) {
40
+ if (mod && mod.__esModule) return mod;
41
+ var result = {};
42
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
43
+ __setModuleDefault(result, mod);
44
+ return result;
45
+ };
46
+ })();
47
+ Object.defineProperty(exports, "__esModule", { value: true });
48
+ const SHIP_00_1 = require("../implementation/SHIP_00");
49
+ const SHIP_07_1 = require("../implementation/SHIP_07");
50
+ const readline = __importStar(require("readline"));
51
+ const fs = __importStar(require("fs"));
52
+ // ============================================================================
53
+ // CONFIGURATION
54
+ // ============================================================================
55
+ const CONFIG = {
56
+ gunOptions: {
57
+ peers: [
58
+ "https://relay.shogun-eco.xyz/gun",
59
+ "https://peer.wallie.io/gun",
60
+ ],
61
+ radisk: true, // Enable persistence for vault
62
+ localStorage: false,
63
+ multicast: false,
64
+ },
65
+ };
66
+ // ============================================================================
67
+ // CLI INTERFACE
68
+ // ============================================================================
69
+ const rl = readline.createInterface({
70
+ input: process.stdin,
71
+ output: process.stdout,
72
+ });
73
+ function prompt(question) {
74
+ return new Promise((resolve) => {
75
+ rl.question(question, (answer) => {
76
+ resolve(answer);
77
+ });
78
+ });
79
+ }
80
+ // ============================================================================
81
+ // MAIN
82
+ // ============================================================================
83
+ async function main() {
84
+ console.clear();
85
+ console.log("=".repeat(70));
86
+ console.log("🗡️ SHOGUN SECURE VAULT - SHIP-07 Demo");
87
+ console.log("=".repeat(70));
88
+ console.log();
89
+ // Parse arguments
90
+ const args = process.argv.slice(2);
91
+ if (args.length < 2) {
92
+ console.log("Usage: tsx vault-cli.ts <username> <password>");
93
+ console.log();
94
+ console.log("Example:");
95
+ console.log(" tsx vault-cli.ts alice password123");
96
+ console.log();
97
+ process.exit(1);
98
+ }
99
+ const [username, password] = args;
100
+ try {
101
+ // ========================================================================
102
+ // 1. IDENTITY SETUP (SHIP-00)
103
+ // ========================================================================
104
+ console.log("📝 AUTHENTICATION (SHIP-00)");
105
+ console.log("-".repeat(70));
106
+ const identity = new SHIP_00_1.SHIP_00(CONFIG);
107
+ // Try login first
108
+ let authResult = await identity.login(username, password);
109
+ // If login fails, try signup
110
+ if (!authResult.success) {
111
+ console.log("⚠️ User not found, creating new account...");
112
+ authResult = await identity.signup(username, password);
113
+ }
114
+ if (!authResult.success) {
115
+ console.error("❌ Authentication failed:", authResult.error);
116
+ process.exit(1);
117
+ }
118
+ console.log("✅ Authenticated");
119
+ console.log(` Username: ${username}`);
120
+ console.log(` Public Key: ${authResult.userPub?.substring(0, 40)}...`);
121
+ if (authResult.derivedAddress) {
122
+ console.log(` Derived Address: ${authResult.derivedAddress}`);
123
+ }
124
+ console.log();
125
+ // ========================================================================
126
+ // 2. INITIALIZE VAULT (SHIP-07)
127
+ // ========================================================================
128
+ console.log("🔐 INITIALIZING VAULT (SHIP-07)");
129
+ console.log("-".repeat(70));
130
+ const vault = new SHIP_07_1.SHIP_07(identity);
131
+ await vault.initialize();
132
+ console.log("✅ Vault initialized");
133
+ console.log();
134
+ // Show stats
135
+ const stats = await vault.getStats();
136
+ console.log("📊 VAULT STATISTICS");
137
+ console.log("-".repeat(70));
138
+ console.log(` Total Records: ${stats.totalRecords}`);
139
+ console.log(` Active Records: ${stats.activeRecords}`);
140
+ console.log(` Deleted Records: ${stats.deletedRecords}`);
141
+ console.log(` Created: ${new Date(stats.created).toLocaleString()}`);
142
+ if (stats.recordsByType && Object.keys(stats.recordsByType).length > 0) {
143
+ console.log(` Records by Type:`);
144
+ Object.entries(stats.recordsByType).forEach(([type, count]) => {
145
+ console.log(` ${type}: ${count}`);
146
+ });
147
+ }
148
+ console.log();
149
+ // ========================================================================
150
+ // 3. INTERACTIVE VAULT MANAGER
151
+ // ========================================================================
152
+ console.log("💬 VAULT COMMANDS");
153
+ console.log("-".repeat(70));
154
+ console.log(" put <name> - Store encrypted data");
155
+ console.log(" get <name> - Retrieve decrypted data");
156
+ console.log(" list - List all records");
157
+ console.log(" delete <name> - Delete record (soft delete)");
158
+ console.log(" update <name> - Update existing record");
159
+ console.log(" search <query> - Search records");
160
+ console.log(" export [password] - Export vault backup");
161
+ console.log(" import <file> [pass] - Import vault backup");
162
+ console.log(" stats - Show vault statistics");
163
+ console.log(" compact - Permanently remove deleted");
164
+ console.log(" clear - Delete all records");
165
+ console.log(" help - Show this help");
166
+ console.log(" exit - Exit vault manager");
167
+ console.log();
168
+ console.log("=".repeat(70));
169
+ console.log();
170
+ // Command loop
171
+ let running = true;
172
+ function displayPrompt() {
173
+ if (running) {
174
+ process.stdout.write(`\nvault> `);
175
+ }
176
+ }
177
+ displayPrompt();
178
+ while (running) {
179
+ const input = await prompt("");
180
+ if (!input.trim()) {
181
+ displayPrompt();
182
+ continue;
183
+ }
184
+ const parts = input.trim().split(/\s+/);
185
+ const command = parts[0].toLowerCase();
186
+ const args = parts.slice(1);
187
+ try {
188
+ // ====================================================================
189
+ // COMMANDS
190
+ // ====================================================================
191
+ if (command === "exit" || command === "quit") {
192
+ console.log("\n👋 Exiting vault manager...");
193
+ running = false;
194
+ break;
195
+ }
196
+ else if (command === "help") {
197
+ console.log("\n💬 AVAILABLE COMMANDS:");
198
+ console.log(" put <name> - Store encrypted data");
199
+ console.log(" get <name> - Retrieve decrypted data");
200
+ console.log(" list - List all records");
201
+ console.log(" delete <name> - Delete record");
202
+ console.log(" update <name> - Update existing record");
203
+ console.log(" search <query> - Search records");
204
+ console.log(" export [password] - Export vault");
205
+ console.log(" import <file> [pass] - Import vault");
206
+ console.log(" stats - Show statistics");
207
+ console.log(" compact - Remove deleted permanently");
208
+ console.log(" clear - Delete all records");
209
+ console.log(" exit - Exit");
210
+ }
211
+ else if (command === "put") {
212
+ if (args.length === 0) {
213
+ console.log("\n❌ Usage: put <name>");
214
+ }
215
+ else {
216
+ const name = args[0];
217
+ const data = await prompt("Data: ");
218
+ const type = await prompt("Type (password/apiKey/privateKey/note): ");
219
+ const description = await prompt("Description: ");
220
+ const tags = await prompt("Tags (comma-separated): ");
221
+ const metadata = {
222
+ type: type || undefined,
223
+ description: description || undefined,
224
+ tags: tags ? tags.split(",").map(t => t.trim()) : undefined,
225
+ };
226
+ const result = await vault.put(name, data, metadata);
227
+ if (result.success) {
228
+ console.log(`\n✅ Record stored: ${name}`);
229
+ }
230
+ else {
231
+ console.log(`\n❌ Error: ${result.error}`);
232
+ }
233
+ }
234
+ }
235
+ else if (command === "get") {
236
+ if (args.length === 0) {
237
+ console.log("\n❌ Usage: get <name>");
238
+ }
239
+ else {
240
+ const name = args[0];
241
+ const record = await vault.get(name);
242
+ if (record) {
243
+ console.log(`\n📄 RECORD: ${name}`);
244
+ console.log("-".repeat(70));
245
+ console.log(` Data: ${JSON.stringify(record.data, null, 2)}`);
246
+ console.log(` Created: ${new Date(record.created).toLocaleString()}`);
247
+ console.log(` Updated: ${new Date(record.updated).toLocaleString()}`);
248
+ if (record.metadata) {
249
+ console.log(` Metadata:`);
250
+ console.log(` Type: ${record.metadata.type || "N/A"}`);
251
+ console.log(` Description: ${record.metadata.description || "N/A"}`);
252
+ console.log(` Tags: ${record.metadata.tags?.join(", ") || "N/A"}`);
253
+ }
254
+ }
255
+ else {
256
+ console.log(`\n❌ Record not found: ${name}`);
257
+ }
258
+ }
259
+ }
260
+ else if (command === "list") {
261
+ const filter = args[0];
262
+ const records = filter
263
+ ? await vault.list({ filterByType: filter })
264
+ : await vault.list();
265
+ console.log(`\n📚 RECORDS (${records.length}):`);
266
+ if (records.length === 0) {
267
+ console.log(" No records found");
268
+ }
269
+ else {
270
+ records.forEach((name, i) => {
271
+ console.log(` ${i + 1}. ${name}`);
272
+ });
273
+ }
274
+ }
275
+ else if (command === "delete") {
276
+ if (args.length === 0) {
277
+ console.log("\n❌ Usage: delete <name>");
278
+ }
279
+ else {
280
+ const name = args[0];
281
+ const confirm = await prompt(`Delete record "${name}"? (y/n): `);
282
+ if (confirm.toLowerCase() === "y") {
283
+ const result = await vault.delete(name);
284
+ if (result.success) {
285
+ console.log(`\n✅ Record deleted (soft): ${name}`);
286
+ console.log(" Use 'compact' to permanently remove");
287
+ }
288
+ else {
289
+ console.log(`\n❌ Error: ${result.error}`);
290
+ }
291
+ }
292
+ else {
293
+ console.log("\n❌ Cancelled");
294
+ }
295
+ }
296
+ }
297
+ else if (command === "update") {
298
+ if (args.length === 0) {
299
+ console.log("\n❌ Usage: update <name>");
300
+ }
301
+ else {
302
+ const name = args[0];
303
+ const exists = await vault.exists(name);
304
+ if (!exists) {
305
+ console.log(`\n❌ Record not found: ${name}`);
306
+ }
307
+ else {
308
+ const newData = await prompt("New data: ");
309
+ const result = await vault.update(name, newData);
310
+ if (result.success) {
311
+ console.log(`\n✅ Record updated: ${name}`);
312
+ }
313
+ else {
314
+ console.log(`\n❌ Error: ${result.error}`);
315
+ }
316
+ }
317
+ }
318
+ }
319
+ else if (command === "search") {
320
+ if (args.length === 0) {
321
+ console.log("\n❌ Usage: search <query>");
322
+ }
323
+ else {
324
+ const query = args.join(" ");
325
+ const matches = await vault.search(query);
326
+ console.log(`\n🔍 SEARCH RESULTS (${matches.length}):`);
327
+ if (matches.length === 0) {
328
+ console.log(" No matches found");
329
+ }
330
+ else {
331
+ matches.forEach((name, i) => {
332
+ console.log(` ${i + 1}. ${name}`);
333
+ });
334
+ }
335
+ }
336
+ }
337
+ else if (command === "export") {
338
+ const exportPassword = args[0];
339
+ const backup = await vault.export(exportPassword);
340
+ const filename = `vault-backup-${username}-${Date.now()}.enc`;
341
+ fs.writeFileSync(filename, backup);
342
+ console.log(`\n✅ VAULT EXPORTED`);
343
+ console.log(` File: ${filename}`);
344
+ console.log(` Size: ${backup.length} characters`);
345
+ console.log(` Encrypted: ${exportPassword ? "Yes" : "No"}`);
346
+ }
347
+ else if (command === "import") {
348
+ if (args.length === 0) {
349
+ console.log("\n❌ Usage: import <file> [password]");
350
+ }
351
+ else {
352
+ const filename = args[0];
353
+ const importPassword = args[1];
354
+ if (!fs.existsSync(filename)) {
355
+ console.log(`\n❌ File not found: ${filename}`);
356
+ }
357
+ else {
358
+ const backup = fs.readFileSync(filename, "utf-8");
359
+ const result = await vault.import(backup, importPassword, {
360
+ merge: true,
361
+ });
362
+ if (result.success) {
363
+ console.log(`\n✅ VAULT IMPORTED`);
364
+ console.log(` Records: ${result.recordCount || 0}`);
365
+ }
366
+ else {
367
+ console.log(`\n❌ Error: ${result.error}`);
368
+ }
369
+ }
370
+ }
371
+ }
372
+ else if (command === "stats") {
373
+ const stats = await vault.getStats();
374
+ console.log("\n📊 VAULT STATISTICS");
375
+ console.log("-".repeat(70));
376
+ console.log(` Total Records: ${stats.totalRecords}`);
377
+ console.log(` Active Records: ${stats.activeRecords}`);
378
+ console.log(` Deleted Records: ${stats.deletedRecords}`);
379
+ console.log(` Created: ${new Date(stats.created).toLocaleString()}`);
380
+ console.log(` Last Modified: ${new Date(stats.lastModified).toLocaleString()}`);
381
+ if (stats.recordsByType && Object.keys(stats.recordsByType).length > 0) {
382
+ console.log(` Records by Type:`);
383
+ Object.entries(stats.recordsByType).forEach(([type, count]) => {
384
+ console.log(` ${type}: ${count}`);
385
+ });
386
+ }
387
+ }
388
+ else if (command === "compact") {
389
+ const confirm = await prompt("Permanently remove deleted records? (y/n): ");
390
+ if (confirm.toLowerCase() === "y") {
391
+ const result = await vault.compact();
392
+ if (result.success) {
393
+ console.log(`\n✅ Vault compacted`);
394
+ console.log(` Removed: ${result.recordCount || 0} records`);
395
+ }
396
+ else {
397
+ console.log(`\n❌ Error: ${result.error}`);
398
+ }
399
+ }
400
+ else {
401
+ console.log("\n❌ Cancelled");
402
+ }
403
+ }
404
+ else if (command === "clear") {
405
+ const confirm = await prompt("Delete ALL records? (y/n): ");
406
+ if (confirm.toLowerCase() === "y") {
407
+ const result = await vault.clear();
408
+ if (result.success) {
409
+ console.log(`\n✅ Vault cleared`);
410
+ console.log(` Deleted: ${result.recordCount || 0} records`);
411
+ }
412
+ else {
413
+ console.log(`\n❌ Error: ${result.error}`);
414
+ }
415
+ }
416
+ else {
417
+ console.log("\n❌ Cancelled");
418
+ }
419
+ }
420
+ else {
421
+ console.log(`\n❌ Unknown command: ${command}`);
422
+ console.log("Type 'help' for available commands");
423
+ }
424
+ }
425
+ catch (error) {
426
+ console.error(`\n❌ Error: ${error.message}`);
427
+ }
428
+ displayPrompt();
429
+ }
430
+ }
431
+ catch (error) {
432
+ console.error("\n❌ Error:", error);
433
+ process.exit(1);
434
+ }
435
+ rl.close();
436
+ process.exit(0);
437
+ }
438
+ // ============================================================================
439
+ // RUN
440
+ // ============================================================================
441
+ main().catch((error) => {
442
+ console.error("Fatal error:", error);
443
+ process.exit(1);
444
+ });