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.
- package/dist/browser/shogun-core.js +83301 -148719
- package/dist/browser/shogun-core.js.map +1 -1
- package/dist/{src/index.js → index.js} +1 -15
- package/dist/types/{src/index.d.ts → index.d.ts} +0 -10
- package/dist/types/{src/types → types}/shogun.d.ts +2 -0
- package/package.json +1 -1
- package/dist/browser/_e6ae.shogun-core.js +0 -14
- package/dist/browser/_e6ae.shogun-core.js.map +0 -1
- package/dist/ship/examples/messenger-cli.js +0 -745
- package/dist/ship/examples/wallet-cli.js +0 -767
- package/dist/ship/implementation/SHIP_00.js +0 -478
- package/dist/ship/implementation/SHIP_01.js +0 -433
- package/dist/ship/implementation/SHIP_02.js +0 -1366
- package/dist/ship/implementation/SHIP_03.js +0 -855
- package/dist/ship/interfaces/ISHIP_00.js +0 -135
- package/dist/ship/interfaces/ISHIP_01.js +0 -128
- package/dist/ship/interfaces/ISHIP_02.js +0 -57
- package/dist/ship/interfaces/ISHIP_03.js +0 -61
- package/dist/types/ship/examples/messenger-cli.d.ts +0 -37
- package/dist/types/ship/examples/wallet-cli.d.ts +0 -131
- package/dist/types/ship/implementation/SHIP_00.d.ts +0 -113
- package/dist/types/ship/implementation/SHIP_01.d.ts +0 -80
- package/dist/types/ship/implementation/SHIP_02.d.ts +0 -297
- package/dist/types/ship/implementation/SHIP_03.d.ts +0 -127
- package/dist/types/ship/interfaces/ISHIP_00.d.ts +0 -410
- package/dist/types/ship/interfaces/ISHIP_01.d.ts +0 -343
- package/dist/types/ship/interfaces/ISHIP_02.d.ts +0 -470
- package/dist/types/ship/interfaces/ISHIP_03.d.ts +0 -295
- /package/dist/{src/config → config}/simplified-config.js +0 -0
- /package/dist/{src/core.js → core.js} +0 -0
- /package/dist/{src/examples → examples}/api-test.js +0 -0
- /package/dist/{src/examples → examples}/simple-api-test.js +0 -0
- /package/dist/{src/gundb → gundb}/api.js +0 -0
- /package/dist/{src/gundb → gundb}/crypto.js +0 -0
- /package/dist/{src/gundb → gundb}/db.js +0 -0
- /package/dist/{src/gundb → gundb}/derive.js +0 -0
- /package/dist/{src/gundb → gundb}/errors.js +0 -0
- /package/dist/{src/gundb → gundb}/index.js +0 -0
- /package/dist/{src/gundb → gundb}/rxjs.js +0 -0
- /package/dist/{src/gundb → gundb}/types.js +0 -0
- /package/dist/{src/interfaces → interfaces}/common.js +0 -0
- /package/dist/{src/interfaces → interfaces}/events.js +0 -0
- /package/dist/{src/interfaces → interfaces}/plugin.js +0 -0
- /package/dist/{src/interfaces → interfaces}/shogun.js +0 -0
- /package/dist/{src/managers → managers}/AuthManager.js +0 -0
- /package/dist/{src/managers → managers}/CoreInitializer.js +0 -0
- /package/dist/{src/managers → managers}/EventManager.js +0 -0
- /package/dist/{src/managers → managers}/PluginManager.js +0 -0
- /package/dist/{src/migration-test.js → migration-test.js} +0 -0
- /package/dist/{src/plugins → plugins}/base.js +0 -0
- /package/dist/{src/plugins → plugins}/index.js +0 -0
- /package/dist/{src/plugins → plugins}/nostr/index.js +0 -0
- /package/dist/{src/plugins → plugins}/nostr/nostrConnector.js +0 -0
- /package/dist/{src/plugins → plugins}/nostr/nostrConnectorPlugin.js +0 -0
- /package/dist/{src/plugins → plugins}/nostr/nostrSigner.js +0 -0
- /package/dist/{src/plugins → plugins}/nostr/types.js +0 -0
- /package/dist/{src/plugins → plugins}/oauth/index.js +0 -0
- /package/dist/{src/plugins → plugins}/oauth/oauthConnector.js +0 -0
- /package/dist/{src/plugins → plugins}/oauth/oauthPlugin.js +0 -0
- /package/dist/{src/plugins → plugins}/oauth/types.js +0 -0
- /package/dist/{src/plugins → plugins}/web3/index.js +0 -0
- /package/dist/{src/plugins → plugins}/web3/types.js +0 -0
- /package/dist/{src/plugins → plugins}/web3/web3Connector.js +0 -0
- /package/dist/{src/plugins → plugins}/web3/web3ConnectorPlugin.js +0 -0
- /package/dist/{src/plugins → plugins}/web3/web3Signer.js +0 -0
- /package/dist/{src/plugins → plugins}/webauthn/index.js +0 -0
- /package/dist/{src/plugins → plugins}/webauthn/types.js +0 -0
- /package/dist/{src/plugins → plugins}/webauthn/webauthn.js +0 -0
- /package/dist/{src/plugins → plugins}/webauthn/webauthnPlugin.js +0 -0
- /package/dist/{src/plugins → plugins}/webauthn/webauthnSigner.js +0 -0
- /package/dist/{src/storage → storage}/storage.js +0 -0
- /package/dist/types/{src/config → config}/simplified-config.d.ts +0 -0
- /package/dist/types/{src/core.d.ts → core.d.ts} +0 -0
- /package/dist/{src/types → types}/events.js +0 -0
- /package/dist/types/{src/examples → examples}/api-test.d.ts +0 -0
- /package/dist/types/{src/examples → examples}/simple-api-test.d.ts +0 -0
- /package/dist/types/{src/gundb → gundb}/api.d.ts +0 -0
- /package/dist/types/{src/gundb → gundb}/crypto.d.ts +0 -0
- /package/dist/types/{src/gundb → gundb}/db.d.ts +0 -0
- /package/dist/types/{src/gundb → gundb}/derive.d.ts +0 -0
- /package/dist/types/{src/gundb → gundb}/errors.d.ts +0 -0
- /package/dist/types/{src/gundb → gundb}/index.d.ts +0 -0
- /package/dist/types/{src/gundb → gundb}/rxjs.d.ts +0 -0
- /package/dist/types/{src/gundb → gundb}/types.d.ts +0 -0
- /package/dist/types/{src/interfaces → interfaces}/common.d.ts +0 -0
- /package/dist/types/{src/interfaces → interfaces}/events.d.ts +0 -0
- /package/dist/types/{src/interfaces → interfaces}/plugin.d.ts +0 -0
- /package/dist/types/{src/interfaces → interfaces}/shogun.d.ts +0 -0
- /package/dist/types/{src/managers → managers}/AuthManager.d.ts +0 -0
- /package/dist/types/{src/managers → managers}/CoreInitializer.d.ts +0 -0
- /package/dist/types/{src/managers → managers}/EventManager.d.ts +0 -0
- /package/dist/types/{src/managers → managers}/PluginManager.d.ts +0 -0
- /package/dist/types/{src/migration-test.d.ts → migration-test.d.ts} +0 -0
- /package/dist/types/{src/plugins → plugins}/base.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/index.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/nostr/index.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/nostr/nostrConnector.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/nostr/nostrConnectorPlugin.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/nostr/nostrSigner.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/nostr/types.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/oauth/index.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/oauth/oauthConnector.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/oauth/oauthPlugin.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/oauth/types.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/web3/index.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/web3/types.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/web3/web3Connector.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/web3/web3ConnectorPlugin.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/web3/web3Signer.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/webauthn/index.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/webauthn/types.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/webauthn/webauthn.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/webauthn/webauthnPlugin.d.ts +0 -0
- /package/dist/types/{src/plugins → plugins}/webauthn/webauthnSigner.d.ts +0 -0
- /package/dist/{src/types → types}/shogun.js +0 -0
- /package/dist/types/{src/storage → storage}/storage.d.ts +0 -0
- /package/dist/types/{src/types → types}/events.d.ts +0 -0
- /package/dist/types/{src/utils → utils}/errorHandler.d.ts +0 -0
- /package/dist/types/{src/utils → utils}/eventEmitter.d.ts +0 -0
- /package/dist/types/{src/utils → utils}/validation.d.ts +0 -0
- /package/dist/{src/utils → utils}/errorHandler.js +0 -0
- /package/dist/{src/utils → utils}/eventEmitter.js +0 -0
- /package/dist/{src/utils → utils}/validation.js +0 -0
|
@@ -1,745 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
/**
|
|
4
|
-
* Shogun Chat - CLI Interface
|
|
5
|
-
*
|
|
6
|
-
* End-to-end encrypted decentralized chat
|
|
7
|
-
* Simple and functional CLI interface
|
|
8
|
-
*/
|
|
9
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
-
exports.MessengerCLI = void 0;
|
|
11
|
-
const SHIP_00_1 = require("../implementation/SHIP_00");
|
|
12
|
-
const SHIP_01_1 = require("../implementation/SHIP_01");
|
|
13
|
-
// Only import readline in Node.js environment
|
|
14
|
-
let readline;
|
|
15
|
-
try {
|
|
16
|
-
if (typeof window === 'undefined') {
|
|
17
|
-
readline = require("readline");
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
catch (e) {
|
|
21
|
-
// Browser environment - readline not available
|
|
22
|
-
}
|
|
23
|
-
// ============================================================================
|
|
24
|
-
// COLORS
|
|
25
|
-
// ============================================================================
|
|
26
|
-
const colors = {
|
|
27
|
-
reset: "\x1b[0m",
|
|
28
|
-
bold: "\x1b[1m",
|
|
29
|
-
dim: "\x1b[2m",
|
|
30
|
-
red: "\x1b[31m",
|
|
31
|
-
green: "\x1b[32m",
|
|
32
|
-
yellow: "\x1b[33m",
|
|
33
|
-
blue: "\x1b[34m",
|
|
34
|
-
magenta: "\x1b[35m",
|
|
35
|
-
cyan: "\x1b[36m",
|
|
36
|
-
white: "\x1b[37m",
|
|
37
|
-
gray: "\x1b[90m",
|
|
38
|
-
};
|
|
39
|
-
const c = (color, text) => `${colors[color]}${text}${colors.reset}`;
|
|
40
|
-
// ============================================================================
|
|
41
|
-
// CHAT CLI
|
|
42
|
-
// ============================================================================
|
|
43
|
-
class MessengerCLI {
|
|
44
|
-
constructor() {
|
|
45
|
-
this.messaging = null;
|
|
46
|
-
this.currentUser = "";
|
|
47
|
-
this.recipient = "";
|
|
48
|
-
this.derivedAddress = "";
|
|
49
|
-
this.isAuthenticated = false;
|
|
50
|
-
this.channelToken = ""; // Token for channel messages
|
|
51
|
-
this.currentChannel = ""; // Current channel name
|
|
52
|
-
// Initialize identity layer (SHIP-00)
|
|
53
|
-
this.identity = new SHIP_00_1.SHIP_00({
|
|
54
|
-
gunOptions: {
|
|
55
|
-
peers: [
|
|
56
|
-
"https://peer.wallie.io/gun",
|
|
57
|
-
"https://v5g5jseqhgkp43lppgregcfbvi.srv.us/gun",
|
|
58
|
-
"https://relay.shogun-eco.xyz/gun",
|
|
59
|
-
],
|
|
60
|
-
radisk: true,
|
|
61
|
-
localStorage: false,
|
|
62
|
-
},
|
|
63
|
-
});
|
|
64
|
-
// Don't initialize readline in browser environment
|
|
65
|
-
if (typeof window !== 'undefined' || !readline) {
|
|
66
|
-
console.warn('MessengerCLI is designed for Node.js CLI usage only');
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
this.rl = readline.createInterface({
|
|
70
|
-
input: process.stdin,
|
|
71
|
-
output: process.stdout,
|
|
72
|
-
prompt: c("green", "➤ "),
|
|
73
|
-
});
|
|
74
|
-
this.setupHandlers();
|
|
75
|
-
}
|
|
76
|
-
// ========================================================================
|
|
77
|
-
// SETUP
|
|
78
|
-
// ========================================================================
|
|
79
|
-
setupHandlers() {
|
|
80
|
-
this.rl.on("line", async (line) => {
|
|
81
|
-
const input = line.trim();
|
|
82
|
-
if (!input) {
|
|
83
|
-
this.rl.prompt();
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
if (input.startsWith("/")) {
|
|
87
|
-
await this.handleCommand(input);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
await this.sendMessage(input);
|
|
91
|
-
}
|
|
92
|
-
this.rl.prompt();
|
|
93
|
-
});
|
|
94
|
-
this.rl.on("close", () => {
|
|
95
|
-
console.log("\n" + c("yellow", "👋 Arrivederci!"));
|
|
96
|
-
process.exit(0);
|
|
97
|
-
});
|
|
98
|
-
// Ctrl+C handler
|
|
99
|
-
process.on("SIGINT", () => {
|
|
100
|
-
this.rl.close();
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
// ========================================================================
|
|
104
|
-
// UTILITIES
|
|
105
|
-
// ========================================================================
|
|
106
|
-
async withTimeout(promise, timeoutMs, errorMessage) {
|
|
107
|
-
return Promise.race([
|
|
108
|
-
promise,
|
|
109
|
-
new Promise((_, reject) => setTimeout(() => reject(new Error(errorMessage)), timeoutMs)),
|
|
110
|
-
]);
|
|
111
|
-
}
|
|
112
|
-
// ========================================================================
|
|
113
|
-
// AUTH
|
|
114
|
-
// ========================================================================
|
|
115
|
-
async login(username, password) {
|
|
116
|
-
console.log(c("cyan", "🔐 Login in corso..."));
|
|
117
|
-
// Loading indicator
|
|
118
|
-
const loadingInterval = setInterval(() => {
|
|
119
|
-
process.stdout.write(c("gray", "."));
|
|
120
|
-
}, 500);
|
|
121
|
-
try {
|
|
122
|
-
// Prova login con timeout (SHIP-00)
|
|
123
|
-
let result = await this.withTimeout(this.identity.login(username, password), 15000, "Login timeout - verifica connessione ai peers");
|
|
124
|
-
clearInterval(loadingInterval);
|
|
125
|
-
console.log(""); // Nuova linea dopo i dots
|
|
126
|
-
// Se fallisce, prova signup (SHIP-00)
|
|
127
|
-
if (!result.success) {
|
|
128
|
-
console.log(c("yellow", "📝 Utente non trovato, creazione in corso..."));
|
|
129
|
-
const signupResult = await this.identity.signup(username, password);
|
|
130
|
-
if (signupResult.success) {
|
|
131
|
-
// Aspetta un momento per evitare race condition
|
|
132
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
133
|
-
// Riprova login
|
|
134
|
-
result = await this.identity.login(username, password);
|
|
135
|
-
}
|
|
136
|
-
else {
|
|
137
|
-
console.log(c("red", `❌ Signup fallito: ${signupResult.error}`));
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
if (result.success) {
|
|
142
|
-
this.currentUser = username;
|
|
143
|
-
this.derivedAddress = result.derivedAddress || "";
|
|
144
|
-
this.isAuthenticated = true;
|
|
145
|
-
console.log("");
|
|
146
|
-
console.log(c("green", "✅ Login effettuato!"));
|
|
147
|
-
console.log(c("gray", ` Username: ${c("bold", username)}`));
|
|
148
|
-
console.log(c("gray", ` Public Key: ${result.userPub?.substring(0, 40)}...`));
|
|
149
|
-
console.log(c("gray", ` Derived Address: ${c("cyan", result.derivedAddress || "")}`));
|
|
150
|
-
console.log("");
|
|
151
|
-
console.log(c("yellow", "📢 Pubblicazione chiave pubblica..."));
|
|
152
|
-
await this.identity.publishPublicKey();
|
|
153
|
-
// Aspetta che la chiave sia sincronizzata
|
|
154
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
155
|
-
console.log(c("green", "✅ Chiave pubblicata su GunDB"));
|
|
156
|
-
console.log("");
|
|
157
|
-
// Inizializza messaging layer (SHIP-01)
|
|
158
|
-
this.messaging = new SHIP_01_1.SHIP_01(this.identity);
|
|
159
|
-
console.log(c("green", "✅ Messaging inizializzato"));
|
|
160
|
-
// Ascolta messaggi (SHIP-01)
|
|
161
|
-
await this.messaging.listenForMessages((msg) => {
|
|
162
|
-
this.onMessageReceived(msg);
|
|
163
|
-
});
|
|
164
|
-
console.log(c("cyan", "💬 Chat pronta! Scrivi /help per i comandi disponibili"));
|
|
165
|
-
console.log("");
|
|
166
|
-
return true;
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
console.log(c("red", `❌ Login fallito: ${result.error}`));
|
|
170
|
-
return false;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
catch (error) {
|
|
174
|
-
clearInterval(loadingInterval);
|
|
175
|
-
console.log("");
|
|
176
|
-
console.log(c("red", `❌ Errore: ${error.message}`));
|
|
177
|
-
return false;
|
|
178
|
-
}
|
|
179
|
-
finally {
|
|
180
|
-
clearInterval(loadingInterval);
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
// ========================================================================
|
|
184
|
-
// MESSAGING
|
|
185
|
-
// ========================================================================
|
|
186
|
-
async sendMessage(content) {
|
|
187
|
-
if (!this.isAuthenticated || !this.messaging) {
|
|
188
|
-
console.log(c("red", "❌ Non autenticato. Usa /login"));
|
|
189
|
-
return;
|
|
190
|
-
}
|
|
191
|
-
try {
|
|
192
|
-
let result;
|
|
193
|
-
// Check if in channel mode or direct message mode
|
|
194
|
-
if (this.currentChannel && this.channelToken) {
|
|
195
|
-
// Send to channel with token encryption
|
|
196
|
-
result = await this.messaging.sendMessageWithToken(this.channelToken, content, this.currentChannel);
|
|
197
|
-
if (result.success) {
|
|
198
|
-
const time = new Date().toLocaleTimeString();
|
|
199
|
-
console.log(c("gray", `[${time}]`) +
|
|
200
|
-
" " +
|
|
201
|
-
c("magenta", `#${this.currentChannel}`) +
|
|
202
|
-
" " +
|
|
203
|
-
c("green", `${this.currentUser}:`) +
|
|
204
|
-
" " +
|
|
205
|
-
content);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
else if (this.recipient) {
|
|
209
|
-
// Send direct message with ECDH encryption
|
|
210
|
-
result = await this.messaging.sendMessage(this.recipient, content);
|
|
211
|
-
if (result.success) {
|
|
212
|
-
const time = new Date().toLocaleTimeString();
|
|
213
|
-
console.log(c("gray", `[${time}]`) +
|
|
214
|
-
" " +
|
|
215
|
-
c("green", `${this.currentUser}:`) +
|
|
216
|
-
" " +
|
|
217
|
-
content);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
220
|
-
else {
|
|
221
|
-
console.log(c("yellow", "⚠️ Usa /to <username> per messaggi diretti o /channel <nome> <token> per canali"));
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
if (!result.success) {
|
|
225
|
-
console.log(c("red", `❌ Errore invio: ${result.error}`));
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
catch (error) {
|
|
229
|
-
console.log(c("red", `❌ Errore: ${error.message}`));
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
onMessageReceived(message) {
|
|
233
|
-
const time = new Date(message.timestamp).toLocaleTimeString();
|
|
234
|
-
const fromUser = message.from.substring(0, 10) + "...";
|
|
235
|
-
console.log("");
|
|
236
|
-
console.log(c("cyan", "📨 Nuovo messaggio!"));
|
|
237
|
-
console.log(c("gray", `[${time}]`) +
|
|
238
|
-
" " +
|
|
239
|
-
c("cyan", `${fromUser}:`) +
|
|
240
|
-
" " +
|
|
241
|
-
message.content);
|
|
242
|
-
console.log("");
|
|
243
|
-
this.rl.prompt();
|
|
244
|
-
}
|
|
245
|
-
onChannelMessageReceived(message) {
|
|
246
|
-
const time = new Date(message.timestamp).toLocaleTimeString();
|
|
247
|
-
const fromUser = message.from.substring(0, 10) + "...";
|
|
248
|
-
console.log("");
|
|
249
|
-
console.log(c("magenta", `📡 #${message.channel}`));
|
|
250
|
-
console.log(c("gray", `[${time}]`) +
|
|
251
|
-
" " +
|
|
252
|
-
c("cyan", `${fromUser}:`) +
|
|
253
|
-
" " +
|
|
254
|
-
message.content);
|
|
255
|
-
console.log("");
|
|
256
|
-
this.rl.prompt();
|
|
257
|
-
}
|
|
258
|
-
// ========================================================================
|
|
259
|
-
// KEY PAIR MANAGEMENT
|
|
260
|
-
// ========================================================================
|
|
261
|
-
async exportKeyPair() {
|
|
262
|
-
try {
|
|
263
|
-
// Ottieni il SEA pair completo da SHIP-00
|
|
264
|
-
const seaPair = this.identity.exportKeyPair();
|
|
265
|
-
if (!seaPair) {
|
|
266
|
-
console.log(c("red", "❌ Impossibile accedere al SEA pair"));
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
// Converti in base64 per facilità di copia
|
|
270
|
-
const exportData = {
|
|
271
|
-
...seaPair,
|
|
272
|
-
alias: this.currentUser,
|
|
273
|
-
exportedAt: Date.now()
|
|
274
|
-
};
|
|
275
|
-
const jsonString = JSON.stringify(exportData);
|
|
276
|
-
const base64 = Buffer.from(jsonString).toString('base64');
|
|
277
|
-
console.log("");
|
|
278
|
-
console.log(c("green", "✅ KEY PAIR ESPORTATO"));
|
|
279
|
-
console.log(c("yellow", "═".repeat(60)));
|
|
280
|
-
console.log("");
|
|
281
|
-
console.log(c("bold", "🔑 SEA PAIR (Base64):"));
|
|
282
|
-
console.log("");
|
|
283
|
-
console.log(c("cyan", base64));
|
|
284
|
-
console.log("");
|
|
285
|
-
console.log(c("yellow", "═".repeat(60)));
|
|
286
|
-
console.log("");
|
|
287
|
-
console.log(c("gray", "💾 SALVA QUESTO KEY PAIR IN UN LUOGO SICURO!"));
|
|
288
|
-
console.log(c("gray", " Puoi usarlo per:"));
|
|
289
|
-
console.log(c("gray", " - Fare login: /login-pair <keypair>"));
|
|
290
|
-
console.log(c("gray", " - Importare: /import <keypair>"));
|
|
291
|
-
console.log(c("gray", " - Backup della tua identità"));
|
|
292
|
-
console.log("");
|
|
293
|
-
console.log(c("red", "⚠️ NON CONDIVIDERE MAI QUESTO KEY PAIR!"));
|
|
294
|
-
console.log(c("red", " Contiene le tue chiavi private!"));
|
|
295
|
-
console.log("");
|
|
296
|
-
// Salva anche su file (opzionale)
|
|
297
|
-
const fs = await import('fs');
|
|
298
|
-
const filename = `shogun-keypair-${this.currentUser}-${Date.now()}.txt`;
|
|
299
|
-
fs.writeFileSync(filename, base64);
|
|
300
|
-
console.log(c("green", `💾 Key pair salvato anche in: ${filename}`));
|
|
301
|
-
console.log("");
|
|
302
|
-
}
|
|
303
|
-
catch (error) {
|
|
304
|
-
console.log(c("red", `❌ Errore export: ${error.message}`));
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
async importKeyPair(base64KeyPair) {
|
|
308
|
-
try {
|
|
309
|
-
// Decodifica da base64
|
|
310
|
-
const jsonString = Buffer.from(base64KeyPair, 'base64').toString('utf-8');
|
|
311
|
-
const keyPairData = JSON.parse(jsonString);
|
|
312
|
-
// Verifica che abbia tutti i campi necessari
|
|
313
|
-
if (!keyPairData.pub || !keyPairData.priv || !keyPairData.epub || !keyPairData.epriv) {
|
|
314
|
-
console.log(c("red", "❌ Key pair invalido. Mancano campi obbligatori."));
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
console.log(c("cyan", "📥 Key pair importato con successo!"));
|
|
318
|
-
console.log(c("gray", ` Utente: ${keyPairData.alias || 'unknown'}`));
|
|
319
|
-
console.log(c("gray", ` Public Key: ${keyPairData.pub.substring(0, 30)}...`));
|
|
320
|
-
console.log("");
|
|
321
|
-
console.log(c("yellow", "💡 Usa /login-pair <keypair> per fare login"));
|
|
322
|
-
console.log("");
|
|
323
|
-
}
|
|
324
|
-
catch (error) {
|
|
325
|
-
console.log(c("red", `❌ Errore import: ${error.message}`));
|
|
326
|
-
console.log(c("gray", " Verifica che il key pair sia valido"));
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
async loginWithPair(base64KeyPair) {
|
|
330
|
-
console.log(c("cyan", "🔐 Login con key pair..."));
|
|
331
|
-
const loadingInterval = setInterval(() => {
|
|
332
|
-
process.stdout.write(c("gray", "."));
|
|
333
|
-
}, 500);
|
|
334
|
-
try {
|
|
335
|
-
// Decodifica key pair
|
|
336
|
-
const jsonString = Buffer.from(base64KeyPair, 'base64').toString('utf-8');
|
|
337
|
-
const keyPairData = JSON.parse(jsonString);
|
|
338
|
-
// Verifica validità
|
|
339
|
-
if (!keyPairData.pub || !keyPairData.priv || !keyPairData.epub || !keyPairData.epriv) {
|
|
340
|
-
throw new Error("Key pair invalido");
|
|
341
|
-
}
|
|
342
|
-
// Crea SEA pair object
|
|
343
|
-
const seaPair = {
|
|
344
|
-
pub: keyPairData.pub,
|
|
345
|
-
priv: keyPairData.priv,
|
|
346
|
-
epub: keyPairData.epub,
|
|
347
|
-
epriv: keyPairData.epriv
|
|
348
|
-
};
|
|
349
|
-
// Login con pair (SHIP-00)
|
|
350
|
-
const result = await this.withTimeout(this.identity.loginWithPair(seaPair), 15000, "Login timeout");
|
|
351
|
-
clearInterval(loadingInterval);
|
|
352
|
-
console.log("");
|
|
353
|
-
if (result.success) {
|
|
354
|
-
this.currentUser = keyPairData.alias || result.username || 'unknown';
|
|
355
|
-
this.derivedAddress = await this.identity.deriveEthereumAddress(seaPair.pub);
|
|
356
|
-
this.isAuthenticated = true;
|
|
357
|
-
console.log("");
|
|
358
|
-
console.log(c("green", "✅ Login con key pair effettuato!"));
|
|
359
|
-
console.log(c("gray", ` Username: ${c("bold", this.currentUser)}`));
|
|
360
|
-
console.log(c("gray", ` Public Key: ${seaPair.pub.substring(0, 40)}...`));
|
|
361
|
-
console.log(c("gray", ` Derived Address: ${c("cyan", this.derivedAddress)}`));
|
|
362
|
-
console.log("");
|
|
363
|
-
console.log(c("yellow", "📢 Pubblicazione chiave pubblica..."));
|
|
364
|
-
await this.identity.publishPublicKey();
|
|
365
|
-
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
366
|
-
console.log(c("green", "✅ Chiave pubblicata su GunDB"));
|
|
367
|
-
console.log("");
|
|
368
|
-
// Inizializza messaging (SHIP-01)
|
|
369
|
-
this.messaging = new SHIP_01_1.SHIP_01(this.identity);
|
|
370
|
-
// Ascolta messaggi
|
|
371
|
-
await this.messaging.listenForMessages((msg) => {
|
|
372
|
-
this.onMessageReceived(msg);
|
|
373
|
-
});
|
|
374
|
-
console.log(c("cyan", "💬 Chat pronta!"));
|
|
375
|
-
console.log("");
|
|
376
|
-
this.updatePrompt();
|
|
377
|
-
}
|
|
378
|
-
else {
|
|
379
|
-
console.log(c("red", `❌ Login fallito: ${result.error}`));
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
catch (error) {
|
|
383
|
-
clearInterval(loadingInterval);
|
|
384
|
-
console.log("");
|
|
385
|
-
console.log(c("red", `❌ Errore: ${error.message}`));
|
|
386
|
-
}
|
|
387
|
-
finally {
|
|
388
|
-
clearInterval(loadingInterval);
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
async wipeAllMessages() {
|
|
392
|
-
console.log("");
|
|
393
|
-
console.log(c("yellow", "⚠️ ATTENZIONE: Stai per cancellare TUTTI i messaggi dal nodo GunDB"));
|
|
394
|
-
console.log(c("yellow", " Questa operazione è IRREVERSIBILE!"));
|
|
395
|
-
console.log("");
|
|
396
|
-
// Conferma
|
|
397
|
-
this.rl.question(c("red", "Sei sicuro? Scrivi 'CONFERMA' per procedere: "), (answer) => {
|
|
398
|
-
if (answer.trim() === "CONFERMA") {
|
|
399
|
-
console.log(c("yellow", "🗑️ Cancellazione messaggi in corso..."));
|
|
400
|
-
// Ottieni tutti i messaggi (access GunDB through identity)
|
|
401
|
-
const gun = this.identity.shogun?.db?.gun;
|
|
402
|
-
if (!gun) {
|
|
403
|
-
console.log(c("red", "❌ Impossibile accedere a GunDB"));
|
|
404
|
-
this.rl.prompt();
|
|
405
|
-
return;
|
|
406
|
-
}
|
|
407
|
-
gun.get(SHIP_01_1.SHIP_01.NODES.MESSAGES).once((allMessages) => {
|
|
408
|
-
if (allMessages && typeof allMessages === 'object') {
|
|
409
|
-
let count = 0;
|
|
410
|
-
// Cancella ogni messaggio
|
|
411
|
-
for (const [messageId, data] of Object.entries(allMessages)) {
|
|
412
|
-
if (typeof data === "object" && data !== null && messageId !== '_') {
|
|
413
|
-
gun.get(SHIP_01_1.SHIP_01.NODES.MESSAGES).get(messageId).put(null);
|
|
414
|
-
count++;
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
console.log(c("green", `✅ ${count} messaggi cancellati dal nodo GunDB`));
|
|
418
|
-
}
|
|
419
|
-
else {
|
|
420
|
-
console.log(c("gray", "ℹ️ Nessun messaggio da cancellare"));
|
|
421
|
-
}
|
|
422
|
-
console.log("");
|
|
423
|
-
this.rl.prompt();
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
else {
|
|
427
|
-
console.log(c("gray", "❌ Cancellazione annullata"));
|
|
428
|
-
console.log("");
|
|
429
|
-
this.rl.prompt();
|
|
430
|
-
}
|
|
431
|
-
});
|
|
432
|
-
}
|
|
433
|
-
// ========================================================================
|
|
434
|
-
// COMMANDS
|
|
435
|
-
// ========================================================================
|
|
436
|
-
async handleCommand(cmd) {
|
|
437
|
-
const parts = cmd.split(" ");
|
|
438
|
-
const command = parts[0].toLowerCase();
|
|
439
|
-
const args = parts.slice(1);
|
|
440
|
-
switch (command) {
|
|
441
|
-
case "/login":
|
|
442
|
-
if (args.length >= 2) {
|
|
443
|
-
const [username, password] = args;
|
|
444
|
-
await this.login(username, password);
|
|
445
|
-
this.updatePrompt();
|
|
446
|
-
}
|
|
447
|
-
else {
|
|
448
|
-
console.log(c("yellow", "⚠️ Uso: /login <username> <password>"));
|
|
449
|
-
}
|
|
450
|
-
break;
|
|
451
|
-
case "/to":
|
|
452
|
-
case "/chat":
|
|
453
|
-
if (!this.isAuthenticated) {
|
|
454
|
-
console.log(c("red", "❌ Prima fai login: /login <username> <password>"));
|
|
455
|
-
break;
|
|
456
|
-
}
|
|
457
|
-
if (args[0]) {
|
|
458
|
-
this.recipient = args[0];
|
|
459
|
-
console.log(c("cyan", `💬 Chattando con ${c("bold", this.recipient)}`));
|
|
460
|
-
// Carica storico (SHIP-01)
|
|
461
|
-
if (!this.messaging) {
|
|
462
|
-
console.log(c("red", "❌ Messaging non inizializzato"));
|
|
463
|
-
break;
|
|
464
|
-
}
|
|
465
|
-
const history = await this.messaging.getMessageHistory(this.recipient);
|
|
466
|
-
if (history.length > 0) {
|
|
467
|
-
console.log(c("gray", `\n📚 Storico conversazione (${history.length} messaggi):\n`));
|
|
468
|
-
history.forEach((msg, i) => {
|
|
469
|
-
const time = new Date(msg.timestamp).toLocaleTimeString();
|
|
470
|
-
const isMe = msg.from === this.currentUser;
|
|
471
|
-
const from = isMe ? this.currentUser : this.recipient;
|
|
472
|
-
const color = isMe ? "green" : "cyan";
|
|
473
|
-
console.log(c("gray", `[${time}]`) +
|
|
474
|
-
" " +
|
|
475
|
-
c(color, `${from}:`) +
|
|
476
|
-
" " +
|
|
477
|
-
msg.content);
|
|
478
|
-
});
|
|
479
|
-
console.log("");
|
|
480
|
-
}
|
|
481
|
-
this.updatePrompt();
|
|
482
|
-
}
|
|
483
|
-
else {
|
|
484
|
-
console.log(c("yellow", "⚠️ Uso: /to <username>"));
|
|
485
|
-
}
|
|
486
|
-
break;
|
|
487
|
-
case "/help":
|
|
488
|
-
this.showHelp();
|
|
489
|
-
break;
|
|
490
|
-
case "/clear":
|
|
491
|
-
console.clear();
|
|
492
|
-
this.showHeader();
|
|
493
|
-
break;
|
|
494
|
-
case "/status":
|
|
495
|
-
this.showStatus();
|
|
496
|
-
break;
|
|
497
|
-
case "/logout":
|
|
498
|
-
this.identity.logout();
|
|
499
|
-
this.messaging = null;
|
|
500
|
-
this.isAuthenticated = false;
|
|
501
|
-
this.currentUser = "";
|
|
502
|
-
this.recipient = "";
|
|
503
|
-
console.log(c("yellow", "👋 Disconnesso"));
|
|
504
|
-
this.updatePrompt();
|
|
505
|
-
break;
|
|
506
|
-
case "/export":
|
|
507
|
-
case "/backup":
|
|
508
|
-
if (!this.isAuthenticated) {
|
|
509
|
-
console.log(c("red", "❌ Prima fai login"));
|
|
510
|
-
break;
|
|
511
|
-
}
|
|
512
|
-
await this.exportKeyPair();
|
|
513
|
-
break;
|
|
514
|
-
case "/import":
|
|
515
|
-
case "/restore":
|
|
516
|
-
if (args[0]) {
|
|
517
|
-
await this.importKeyPair(args[0]);
|
|
518
|
-
}
|
|
519
|
-
else {
|
|
520
|
-
console.log(c("yellow", "⚠️ Uso: /import <keypair-json-base64>"));
|
|
521
|
-
}
|
|
522
|
-
break;
|
|
523
|
-
case "/login-pair":
|
|
524
|
-
if (args[0]) {
|
|
525
|
-
await this.loginWithPair(args[0]);
|
|
526
|
-
}
|
|
527
|
-
else {
|
|
528
|
-
console.log(c("yellow", "⚠️ Uso: /login-pair <keypair-json-base64>"));
|
|
529
|
-
}
|
|
530
|
-
break;
|
|
531
|
-
case "/wipe":
|
|
532
|
-
case "/delete-all":
|
|
533
|
-
if (!this.isAuthenticated) {
|
|
534
|
-
console.log(c("red", "❌ Prima fai login"));
|
|
535
|
-
break;
|
|
536
|
-
}
|
|
537
|
-
await this.wipeAllMessages();
|
|
538
|
-
break;
|
|
539
|
-
case "/channel":
|
|
540
|
-
case "/join":
|
|
541
|
-
if (!this.isAuthenticated) {
|
|
542
|
-
console.log(c("red", "❌ Prima fai login"));
|
|
543
|
-
break;
|
|
544
|
-
}
|
|
545
|
-
if (args.length >= 2) {
|
|
546
|
-
const [channelName, token] = args;
|
|
547
|
-
await this.joinChannel(channelName, token);
|
|
548
|
-
}
|
|
549
|
-
else {
|
|
550
|
-
console.log(c("yellow", "⚠️ Uso: /channel <nome> <token>"));
|
|
551
|
-
}
|
|
552
|
-
break;
|
|
553
|
-
case "/leave":
|
|
554
|
-
this.leaveChannel();
|
|
555
|
-
break;
|
|
556
|
-
case "/exit":
|
|
557
|
-
case "/quit":
|
|
558
|
-
this.rl.close();
|
|
559
|
-
break;
|
|
560
|
-
default:
|
|
561
|
-
console.log(c("red", `❌ Comando sconosciuto: ${command}`));
|
|
562
|
-
console.log(c("gray", " Scrivi /help per aiuto"));
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
async joinChannel(channelName, token) {
|
|
566
|
-
if (!this.messaging) {
|
|
567
|
-
console.log(c("red", "❌ Messaging non inizializzato"));
|
|
568
|
-
return;
|
|
569
|
-
}
|
|
570
|
-
this.currentChannel = channelName;
|
|
571
|
-
this.channelToken = token;
|
|
572
|
-
this.recipient = ""; // Clear direct message recipient
|
|
573
|
-
console.log("");
|
|
574
|
-
console.log(c("magenta", `📡 Connesso al canale #${channelName}`));
|
|
575
|
-
console.log(c("gray", " Token: " + "*".repeat(token.length)));
|
|
576
|
-
console.log("");
|
|
577
|
-
// Listen for channel messages
|
|
578
|
-
await this.messaging.listenForTokenMessages(token, (msg) => this.onChannelMessageReceived(msg), channelName);
|
|
579
|
-
this.updatePrompt();
|
|
580
|
-
}
|
|
581
|
-
leaveChannel() {
|
|
582
|
-
if (!this.currentChannel) {
|
|
583
|
-
console.log(c("yellow", "⚠️ Non sei in un canale"));
|
|
584
|
-
return;
|
|
585
|
-
}
|
|
586
|
-
console.log(c("yellow", `👋 Uscito dal canale #${this.currentChannel}`));
|
|
587
|
-
this.currentChannel = "";
|
|
588
|
-
this.channelToken = "";
|
|
589
|
-
this.updatePrompt();
|
|
590
|
-
}
|
|
591
|
-
showHelp() {
|
|
592
|
-
console.log("");
|
|
593
|
-
console.log(c("bold", c("cyan", "📖 COMANDI DISPONIBILI")));
|
|
594
|
-
console.log("");
|
|
595
|
-
console.log(c("bold", "AUTENTICAZIONE:"));
|
|
596
|
-
console.log(" " + c("bold", "/login <user> <pass>") + " - Login/Signup con password");
|
|
597
|
-
console.log(" " + c("bold", "/login-pair <keypair>") + " - Login con SEA key pair");
|
|
598
|
-
console.log("");
|
|
599
|
-
console.log(c("bold", "MESSAGGISTICA:"));
|
|
600
|
-
console.log(" " + c("bold", "/to <username>") + " - Chat diretta con utente");
|
|
601
|
-
console.log(" " + c("bold", "/channel <nome> <token>") + " - Entra in canale criptato");
|
|
602
|
-
console.log(" " + c("bold", "/leave") + " - Esci dal canale");
|
|
603
|
-
console.log("");
|
|
604
|
-
console.log(c("bold", "KEY MANAGEMENT:"));
|
|
605
|
-
console.log(" " + c("bold", "/export") + " - Esporta il tuo key pair (backup)");
|
|
606
|
-
console.log(" " + c("bold", "/import <keypair>") + " - Mostra info su key pair");
|
|
607
|
-
console.log("");
|
|
608
|
-
console.log(c("bold", "UTILITÀ:"));
|
|
609
|
-
console.log(" " + c("bold", "/help") + " - Mostra questo aiuto");
|
|
610
|
-
console.log(" " + c("bold", "/status") + " - Mostra stato connessione");
|
|
611
|
-
console.log(" " + c("bold", "/clear") + " - Pulisci schermo");
|
|
612
|
-
console.log(" " + c("bold", "/wipe") + " - Cancella TUTTI i messaggi (⚠️)");
|
|
613
|
-
console.log(" " + c("bold", "/logout") + " - Disconnetti");
|
|
614
|
-
console.log(" " + c("bold", "/exit") + " - Esci dall'app");
|
|
615
|
-
console.log("");
|
|
616
|
-
console.log(c("bold", c("green", "🔐 SICUREZZA")));
|
|
617
|
-
console.log("");
|
|
618
|
-
console.log(" ✅ Crittografia end-to-end (ECDH + AES-GCM)");
|
|
619
|
-
console.log(" ✅ Canali con token condiviso (AES-256)");
|
|
620
|
-
console.log(" ✅ Storage decentralizzato P2P (GunDB)");
|
|
621
|
-
console.log(" ✅ Nessun server può leggere i messaggi");
|
|
622
|
-
console.log(" ✅ Key pair portabile (export/import)");
|
|
623
|
-
console.log(" ✅ Zero costi, completamente gratis");
|
|
624
|
-
console.log("");
|
|
625
|
-
console.log(c("bold", c("yellow", "💡 ESEMPI")));
|
|
626
|
-
console.log("");
|
|
627
|
-
console.log(" " + c("gray", "# Login normale"));
|
|
628
|
-
console.log(" " + c("gray", "/login alice password123"));
|
|
629
|
-
console.log("");
|
|
630
|
-
console.log(" " + c("gray", "# Chat diretta (ECDH)"));
|
|
631
|
-
console.log(" " + c("gray", "/to bob"));
|
|
632
|
-
console.log(" " + c("gray", "Ciao Bob! Come stai?"));
|
|
633
|
-
console.log("");
|
|
634
|
-
console.log(" " + c("gray", "# Canale criptato (token)"));
|
|
635
|
-
console.log(" " + c("gray", "/channel dev-team mySecretToken123"));
|
|
636
|
-
console.log(" " + c("gray", "Messaggio nel canale #dev-team"));
|
|
637
|
-
console.log("");
|
|
638
|
-
console.log(" " + c("gray", "# Export key pair (backup)"));
|
|
639
|
-
console.log(" " + c("gray", "/export"));
|
|
640
|
-
console.log("");
|
|
641
|
-
}
|
|
642
|
-
showStatus() {
|
|
643
|
-
console.log("");
|
|
644
|
-
console.log(c("bold", c("cyan", "📊 STATO SISTEMA")));
|
|
645
|
-
console.log("");
|
|
646
|
-
console.log(" " + c("gray", "Utente:") + " " + c("green", this.currentUser));
|
|
647
|
-
if (this.currentChannel) {
|
|
648
|
-
console.log(" " +
|
|
649
|
-
c("gray", "Canale:") +
|
|
650
|
-
" " +
|
|
651
|
-
c("magenta", `#${this.currentChannel}`));
|
|
652
|
-
}
|
|
653
|
-
else if (this.recipient) {
|
|
654
|
-
console.log(" " +
|
|
655
|
-
c("gray", "Chat con:") +
|
|
656
|
-
" " +
|
|
657
|
-
c("yellow", this.recipient));
|
|
658
|
-
}
|
|
659
|
-
else {
|
|
660
|
-
console.log(" " +
|
|
661
|
-
c("gray", "Destinatario:") +
|
|
662
|
-
" " +
|
|
663
|
-
c("gray", "(nessuno)"));
|
|
664
|
-
}
|
|
665
|
-
console.log(" " + c("gray", "Address:") + " " + c("cyan", this.derivedAddress));
|
|
666
|
-
console.log(" " +
|
|
667
|
-
c("gray", "Autenticato:") +
|
|
668
|
-
" " +
|
|
669
|
-
(this.isAuthenticated ? c("green", "✅ Sì") : c("red", "❌ No")));
|
|
670
|
-
console.log("");
|
|
671
|
-
}
|
|
672
|
-
showHeader() {
|
|
673
|
-
console.log("");
|
|
674
|
-
console.log(c("bold", c("cyan", "═══════════════════════════════════════════════════════")));
|
|
675
|
-
console.log(c("bold", c("cyan", " 🗡️ SHOGUN CHAT - Decentralized E2E Messaging")));
|
|
676
|
-
console.log(c("bold", c("cyan", "═══════════════════════════════════════════════════════")));
|
|
677
|
-
console.log("");
|
|
678
|
-
console.log(c("gray", " Powered by Shogun Core + GunDB"));
|
|
679
|
-
console.log(c("gray", " Zero-cost encrypted messaging over P2P network"));
|
|
680
|
-
console.log("");
|
|
681
|
-
}
|
|
682
|
-
updatePrompt() {
|
|
683
|
-
let prompt = "";
|
|
684
|
-
if (this.currentChannel) {
|
|
685
|
-
prompt =
|
|
686
|
-
c("green", `[${this.currentUser}]`) +
|
|
687
|
-
c("white", " → ") +
|
|
688
|
-
c("magenta", `#${this.currentChannel}`) +
|
|
689
|
-
c("green", " ➤ ");
|
|
690
|
-
}
|
|
691
|
-
else if (this.recipient) {
|
|
692
|
-
prompt =
|
|
693
|
-
c("green", `[${this.currentUser}]`) +
|
|
694
|
-
c("white", " → ") +
|
|
695
|
-
c("yellow", this.recipient) +
|
|
696
|
-
c("green", " ➤ ");
|
|
697
|
-
}
|
|
698
|
-
else if (this.currentUser) {
|
|
699
|
-
prompt = c("green", `[${this.currentUser}]`) + c("green", " ➤ ");
|
|
700
|
-
}
|
|
701
|
-
else {
|
|
702
|
-
prompt = c("gray", "➤ ");
|
|
703
|
-
}
|
|
704
|
-
this.rl.setPrompt(prompt);
|
|
705
|
-
}
|
|
706
|
-
// ========================================================================
|
|
707
|
-
// START
|
|
708
|
-
// ========================================================================
|
|
709
|
-
async start() {
|
|
710
|
-
this.showHeader();
|
|
711
|
-
const args = process.argv.slice(2);
|
|
712
|
-
if (args.length >= 2) {
|
|
713
|
-
// Auto-login
|
|
714
|
-
const [username, password] = args;
|
|
715
|
-
const success = await this.login(username, password);
|
|
716
|
-
if (success) {
|
|
717
|
-
this.updatePrompt();
|
|
718
|
-
this.rl.prompt();
|
|
719
|
-
}
|
|
720
|
-
else {
|
|
721
|
-
console.log(c("red", "❌ Auto-login fallito"));
|
|
722
|
-
this.rl.close();
|
|
723
|
-
}
|
|
724
|
-
}
|
|
725
|
-
else {
|
|
726
|
-
// Login manuale
|
|
727
|
-
console.log(c("cyan", "💡 Comandi disponibili:"));
|
|
728
|
-
console.log(c("yellow", " /login <username> <password>") +
|
|
729
|
-
c("gray", " - Login o crea account"));
|
|
730
|
-
console.log(c("yellow", " /help") +
|
|
731
|
-
c("gray", " - Mostra tutti i comandi"));
|
|
732
|
-
console.log("");
|
|
733
|
-
console.log(c("gray", " Oppure avvia con: yarn chat <username> <password>"));
|
|
734
|
-
console.log("");
|
|
735
|
-
this.updatePrompt();
|
|
736
|
-
this.rl.prompt();
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
exports.MessengerCLI = MessengerCLI;
|
|
741
|
-
// ============================================================================
|
|
742
|
-
// MAIN
|
|
743
|
-
// ============================================================================
|
|
744
|
-
const cli = new MessengerCLI();
|
|
745
|
-
cli.start().catch(console.error);
|