pal-explorer-cli 0.4.12 → 0.4.13
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/README.md +149 -149
- package/bin/pal.js +63 -2
- package/extensions/@palexplorer/analytics/extension.json +20 -1
- package/extensions/@palexplorer/analytics/index.js +19 -9
- package/extensions/@palexplorer/audit/extension.json +14 -0
- package/extensions/@palexplorer/auth-email/extension.json +15 -0
- package/extensions/@palexplorer/auth-oauth/extension.json +15 -0
- package/extensions/@palexplorer/chat/extension.json +14 -0
- package/extensions/@palexplorer/discovery/extension.json +17 -0
- package/extensions/@palexplorer/discovery/index.js +1 -1
- package/extensions/@palexplorer/email-notifications/extension.json +23 -0
- package/extensions/@palexplorer/groups/extension.json +15 -0
- package/extensions/@palexplorer/share-links/extension.json +15 -0
- package/extensions/@palexplorer/sync/extension.json +16 -0
- package/extensions/@palexplorer/user-mgmt/extension.json +15 -0
- package/lib/capabilities.js +24 -24
- package/lib/commands/analytics.js +175 -175
- package/lib/commands/api-keys.js +131 -131
- package/lib/commands/audit.js +235 -235
- package/lib/commands/auth.js +137 -137
- package/lib/commands/backup.js +76 -76
- package/lib/commands/billing.js +148 -148
- package/lib/commands/chat.js +217 -217
- package/lib/commands/cloud-backup.js +231 -231
- package/lib/commands/comment.js +99 -99
- package/lib/commands/completion.js +203 -203
- package/lib/commands/compliance.js +218 -218
- package/lib/commands/config.js +136 -136
- package/lib/commands/connect.js +44 -44
- package/lib/commands/dept.js +294 -294
- package/lib/commands/device.js +146 -146
- package/lib/commands/download.js +240 -226
- package/lib/commands/explorer.js +178 -178
- package/lib/commands/extension.js +1060 -970
- package/lib/commands/favorite.js +90 -90
- package/lib/commands/federation.js +270 -270
- package/lib/commands/file.js +533 -533
- package/lib/commands/group.js +271 -271
- package/lib/commands/gui-share.js +29 -29
- package/lib/commands/init.js +61 -61
- package/lib/commands/invite.js +59 -59
- package/lib/commands/list.js +58 -58
- package/lib/commands/log.js +116 -116
- package/lib/commands/nearby.js +108 -108
- package/lib/commands/network.js +251 -251
- package/lib/commands/notify.js +198 -198
- package/lib/commands/org.js +273 -273
- package/lib/commands/pal.js +403 -180
- package/lib/commands/permissions.js +216 -216
- package/lib/commands/pin.js +97 -97
- package/lib/commands/protocol.js +357 -357
- package/lib/commands/rbac.js +147 -147
- package/lib/commands/recover.js +36 -36
- package/lib/commands/register.js +171 -171
- package/lib/commands/relay.js +131 -131
- package/lib/commands/remote.js +368 -368
- package/lib/commands/revoke.js +50 -50
- package/lib/commands/scanner.js +280 -280
- package/lib/commands/schedule.js +344 -344
- package/lib/commands/scim.js +203 -203
- package/lib/commands/search.js +181 -181
- package/lib/commands/serve.js +438 -438
- package/lib/commands/server.js +350 -350
- package/lib/commands/share-link.js +199 -199
- package/lib/commands/share.js +336 -323
- package/lib/commands/sso.js +200 -200
- package/lib/commands/status.js +145 -145
- package/lib/commands/stream.js +562 -562
- package/lib/commands/su.js +187 -187
- package/lib/commands/sync.js +979 -979
- package/lib/commands/transfers.js +152 -152
- package/lib/commands/uninstall.js +188 -188
- package/lib/commands/update.js +204 -204
- package/lib/commands/user.js +276 -276
- package/lib/commands/vfs.js +84 -84
- package/lib/commands/web-login.js +79 -79
- package/lib/commands/web.js +52 -52
- package/lib/commands/webhook.js +180 -180
- package/lib/commands/whoami.js +59 -59
- package/lib/commands/workspace.js +121 -121
- package/lib/core/billing.js +16 -5
- package/lib/core/dhtDiscovery.js +9 -2
- package/lib/core/discoveryClient.js +13 -7
- package/lib/core/extensions.js +142 -1
- package/lib/core/identity.js +33 -2
- package/lib/core/imageProcessor.js +109 -0
- package/lib/core/imageTorrent.js +167 -0
- package/lib/core/permissions.js +1 -1
- package/lib/core/pro.js +11 -4
- package/lib/core/serverList.js +4 -1
- package/lib/core/shares.js +12 -1
- package/lib/core/signalingServer.js +14 -2
- package/lib/core/su.js +1 -1
- package/lib/core/users.js +1 -1
- package/lib/protocol/messages.js +12 -3
- package/lib/utils/explorer.js +1 -1
- package/lib/utils/help.js +357 -357
- package/lib/utils/torrent.js +1 -0
- package/package.json +4 -3
package/lib/commands/register.js
CHANGED
|
@@ -1,171 +1,171 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import config from '../utils/config.js';
|
|
3
|
-
import { setIdentityHandle, getIdentity } from '../core/identity.js';
|
|
4
|
-
import { getPrimaryServer, postTo, parseHandle } from '../core/discoveryClient.js';
|
|
5
|
-
import { updateProfileHandle } from '../core/users.js';
|
|
6
|
-
|
|
7
|
-
export default function registerCommand(program) {
|
|
8
|
-
program
|
|
9
|
-
.command('register <handle>')
|
|
10
|
-
.description('register your identity with a handle on the discovery network')
|
|
11
|
-
.option('--email <email>', 'Verify ownership via email OTP (required for first registration)')
|
|
12
|
-
.option('--server <url>', 'Register on a specific discovery server')
|
|
13
|
-
.addHelpText('after', `
|
|
14
|
-
Examples:
|
|
15
|
-
$
|
|
16
|
-
$
|
|
17
|
-
$
|
|
18
|
-
`)
|
|
19
|
-
.action(async (handle, opts) => {
|
|
20
|
-
handle = handle.replace(/^@/, '');
|
|
21
|
-
const identity = await getIdentity();
|
|
22
|
-
if (!identity) {
|
|
23
|
-
console.log(chalk.red('No identity found. Run `
|
|
24
|
-
process.exitCode = 1; return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
if (!/^[a-zA-Z0-9_-]{3,32}$/.test(handle)) {
|
|
28
|
-
console.log(chalk.red('Handle must be 3-32 characters: letters, numbers, hyphens, underscores only.'));
|
|
29
|
-
process.exitCode = 1; return;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
const serverUrl = opts.server || getPrimaryServer();
|
|
33
|
-
|
|
34
|
-
if (opts.email) {
|
|
35
|
-
// OTP flow: request OTP sent to email
|
|
36
|
-
console.log(chalk.blue(`Sending OTP to ${opts.email}...`));
|
|
37
|
-
try {
|
|
38
|
-
const res = await postTo(serverUrl, '/otp/send', { handle, publicKey: identity.publicKey });
|
|
39
|
-
const data = await res.json();
|
|
40
|
-
if (!res.ok) {
|
|
41
|
-
console.log(chalk.red(`Failed: ${data.error}`));
|
|
42
|
-
process.exitCode = 1; return;
|
|
43
|
-
}
|
|
44
|
-
console.log(chalk.green('OTP sent. Run `
|
|
45
|
-
config.set('_pendingRegistration', { handle, publicKey: identity.publicKey, email: opts.email, serverUrl });
|
|
46
|
-
} catch {
|
|
47
|
-
console.log(chalk.red(`Could not reach discovery server at ${serverUrl}`));
|
|
48
|
-
process.exitCode = 1;
|
|
49
|
-
}
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
// Challenge-response registration
|
|
54
|
-
const sodium = (await import('sodium-native')).default;
|
|
55
|
-
const privateKey = Buffer.from(identity.privateKey, 'hex');
|
|
56
|
-
|
|
57
|
-
try {
|
|
58
|
-
process.stdout.write(chalk.gray(`Registering @${handle} on ${serverUrl}... `));
|
|
59
|
-
|
|
60
|
-
// Step 1: Request challenge from server
|
|
61
|
-
const challengeRes = await postTo(serverUrl, '/register/challenge', { handle, publicKey: identity.publicKey });
|
|
62
|
-
const challengeData = await challengeRes.json();
|
|
63
|
-
if (!challengeRes.ok || !challengeData.challengeId) {
|
|
64
|
-
console.log(chalk.red(`\nFailed: ${challengeData.error || 'Could not get challenge'}`));
|
|
65
|
-
if (challengeData.suggestions?.length > 0) {
|
|
66
|
-
console.log(chalk.yellow('Available alternatives:'));
|
|
67
|
-
for (const s of challengeData.suggestions) {
|
|
68
|
-
console.log(chalk.white(` @${s}`));
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
process.exitCode = 1; return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Step 2: Sign challenge and complete registration
|
|
75
|
-
const message = `register:${handle}:${challengeData.nonce}`;
|
|
76
|
-
const sig = Buffer.alloc(sodium.crypto_sign_BYTES);
|
|
77
|
-
sodium.crypto_sign_detached(sig, Buffer.from(message), privateKey);
|
|
78
|
-
|
|
79
|
-
const res = await postTo(serverUrl, '/register', { challengeId: challengeData.challengeId, signature: sig.toString('hex') });
|
|
80
|
-
const result = await res.json();
|
|
81
|
-
if (res.status === 403 && result.code === 'VANITY_HANDLE_PRO_REQUIRED') {
|
|
82
|
-
console.log(chalk.red(`\nVanity handle "@${handle}" requires Pro.`));
|
|
83
|
-
console.log(chalk.yellow('Short custom handles (3-15 chars) are a Pro feature.'));
|
|
84
|
-
console.log(chalk.gray('Upgrade:
|
|
85
|
-
console.log(chalk.gray('Or use an auto-generated handle instead.'));
|
|
86
|
-
process.exitCode = 1; return;
|
|
87
|
-
}
|
|
88
|
-
if (result.success) {
|
|
89
|
-
console.log(chalk.green('done.'));
|
|
90
|
-
// Store full federated handle if registered on non-primary server
|
|
91
|
-
const primary = getPrimaryServer();
|
|
92
|
-
const fullHandle = (opts.server && opts.server !== primary)
|
|
93
|
-
? `${handle}@${serverUrl.replace(/^https?:\/\//, '')}`
|
|
94
|
-
: handle;
|
|
95
|
-
console.log(chalk.green(`Registered as @${fullHandle}`));
|
|
96
|
-
setIdentityHandle(fullHandle);
|
|
97
|
-
updateProfileHandle(identity.publicKey, fullHandle);
|
|
98
|
-
config.delete('_pendingRegistration');
|
|
99
|
-
|
|
100
|
-
// Publish to DHT for decentralized fallback
|
|
101
|
-
try {
|
|
102
|
-
const { DHTDiscovery } = await import('../core/dhtDiscovery.js');
|
|
103
|
-
const dht = new DHTDiscovery();
|
|
104
|
-
const dhtHash = await dht.publish(handle, identity.publicKey, identity.privateKey);
|
|
105
|
-
const cache = config.get('handleCache') || {};
|
|
106
|
-
if (!cache[handle]) cache[handle] = {};
|
|
107
|
-
cache[handle].dhtHash = dhtHash;
|
|
108
|
-
config.set('handleCache', cache);
|
|
109
|
-
console.log(chalk.gray(`Published to DHT (hash: ${dhtHash.slice(0, 12)}...)`));
|
|
110
|
-
dht.destroy();
|
|
111
|
-
} catch (err) {
|
|
112
|
-
console.log(chalk.yellow(`DHT publish skipped: ${err.message}`));
|
|
113
|
-
}
|
|
114
|
-
} else {
|
|
115
|
-
console.log(chalk.red(`\nFailed: ${result.error}`));
|
|
116
|
-
process.exitCode = 1;
|
|
117
|
-
}
|
|
118
|
-
} catch {
|
|
119
|
-
console.log(chalk.red(`\nCould not reach discovery server at ${serverUrl}`));
|
|
120
|
-
process.exitCode = 1;
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
program
|
|
125
|
-
.command('verify <code>')
|
|
126
|
-
.description('complete OTP email verification for handle registration')
|
|
127
|
-
.addHelpText('after', `
|
|
128
|
-
Examples:
|
|
129
|
-
$
|
|
130
|
-
`)
|
|
131
|
-
.action(async (code) => {
|
|
132
|
-
const pending = config.get('_pendingRegistration');
|
|
133
|
-
if (!pending?.handle) {
|
|
134
|
-
console.log(chalk.red('No pending registration. Run `
|
|
135
|
-
process.exitCode = 1; return;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
const identity = await getIdentity();
|
|
139
|
-
if (!identity?.privateKey) {
|
|
140
|
-
console.log(chalk.red('No identity found.'));
|
|
141
|
-
process.exitCode = 1; return;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
const serverUrl = pending.serverUrl || getPrimaryServer();
|
|
145
|
-
const sodium = (await import('sodium-native')).default;
|
|
146
|
-
const privateKey = Buffer.from(identity.privateKey, 'hex');
|
|
147
|
-
const now = Date.now();
|
|
148
|
-
const message = `${pending.handle}:${code}:${now}`;
|
|
149
|
-
const sig = Buffer.alloc(sodium.crypto_sign_BYTES);
|
|
150
|
-
sodium.crypto_sign_detached(sig, Buffer.from(message), privateKey);
|
|
151
|
-
|
|
152
|
-
try {
|
|
153
|
-
process.stdout.write(chalk.gray(`Verifying @${pending.handle}... `));
|
|
154
|
-
const res = await postTo(serverUrl, '/otp/verify', { handle: pending.handle, code, signature: sig.toString('hex'), timestamp: now });
|
|
155
|
-
const result = await res.json();
|
|
156
|
-
if (result.success) {
|
|
157
|
-
console.log(chalk.green('done.'));
|
|
158
|
-
console.log(chalk.green(`Handle @${pending.handle} verified and registered.`));
|
|
159
|
-
setIdentityHandle(pending.handle);
|
|
160
|
-
updateProfileHandle(identity.publicKey, pending.handle);
|
|
161
|
-
config.delete('_pendingRegistration');
|
|
162
|
-
} else {
|
|
163
|
-
console.log(chalk.red(`\nVerification failed: ${result.error}`));
|
|
164
|
-
process.exitCode = 1;
|
|
165
|
-
}
|
|
166
|
-
} catch {
|
|
167
|
-
console.log(chalk.red(`\nCould not reach discovery server at ${serverUrl}`));
|
|
168
|
-
process.exitCode = 1;
|
|
169
|
-
}
|
|
170
|
-
});
|
|
171
|
-
}
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import config from '../utils/config.js';
|
|
3
|
+
import { setIdentityHandle, getIdentity } from '../core/identity.js';
|
|
4
|
+
import { getPrimaryServer, postTo, parseHandle } from '../core/discoveryClient.js';
|
|
5
|
+
import { updateProfileHandle } from '../core/users.js';
|
|
6
|
+
|
|
7
|
+
export default function registerCommand(program) {
|
|
8
|
+
program
|
|
9
|
+
.command('register <handle>')
|
|
10
|
+
.description('register your identity with a handle on the discovery network')
|
|
11
|
+
.option('--email <email>', 'Verify ownership via email OTP (required for first registration)')
|
|
12
|
+
.option('--server <url>', 'Register on a specific discovery server')
|
|
13
|
+
.addHelpText('after', `
|
|
14
|
+
Examples:
|
|
15
|
+
$ pal register alice Register handle @alice (direct signature)
|
|
16
|
+
$ pal register alice --email a@b Register with email OTP verification
|
|
17
|
+
$ pal register alice --server https://custom.com Register on specific server
|
|
18
|
+
`)
|
|
19
|
+
.action(async (handle, opts) => {
|
|
20
|
+
handle = handle.replace(/^@/, '');
|
|
21
|
+
const identity = await getIdentity();
|
|
22
|
+
if (!identity) {
|
|
23
|
+
console.log(chalk.red('No identity found. Run `pal init <name>` first.'));
|
|
24
|
+
process.exitCode = 1; return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (!/^[a-zA-Z0-9_-]{3,32}$/.test(handle)) {
|
|
28
|
+
console.log(chalk.red('Handle must be 3-32 characters: letters, numbers, hyphens, underscores only.'));
|
|
29
|
+
process.exitCode = 1; return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const serverUrl = opts.server || getPrimaryServer();
|
|
33
|
+
|
|
34
|
+
if (opts.email) {
|
|
35
|
+
// OTP flow: request OTP sent to email
|
|
36
|
+
console.log(chalk.blue(`Sending OTP to ${opts.email}...`));
|
|
37
|
+
try {
|
|
38
|
+
const res = await postTo(serverUrl, '/otp/send', { handle, publicKey: identity.publicKey });
|
|
39
|
+
const data = await res.json();
|
|
40
|
+
if (!res.ok) {
|
|
41
|
+
console.log(chalk.red(`Failed: ${data.error}`));
|
|
42
|
+
process.exitCode = 1; return;
|
|
43
|
+
}
|
|
44
|
+
console.log(chalk.green('OTP sent. Run `pal verify <code>` with the code from your email.'));
|
|
45
|
+
config.set('_pendingRegistration', { handle, publicKey: identity.publicKey, email: opts.email, serverUrl });
|
|
46
|
+
} catch {
|
|
47
|
+
console.log(chalk.red(`Could not reach discovery server at ${serverUrl}`));
|
|
48
|
+
process.exitCode = 1;
|
|
49
|
+
}
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Challenge-response registration
|
|
54
|
+
const sodium = (await import('sodium-native')).default;
|
|
55
|
+
const privateKey = Buffer.from(identity.privateKey, 'hex');
|
|
56
|
+
|
|
57
|
+
try {
|
|
58
|
+
process.stdout.write(chalk.gray(`Registering @${handle} on ${serverUrl}... `));
|
|
59
|
+
|
|
60
|
+
// Step 1: Request challenge from server
|
|
61
|
+
const challengeRes = await postTo(serverUrl, '/register/challenge', { handle, publicKey: identity.publicKey });
|
|
62
|
+
const challengeData = await challengeRes.json();
|
|
63
|
+
if (!challengeRes.ok || !challengeData.challengeId) {
|
|
64
|
+
console.log(chalk.red(`\nFailed: ${challengeData.error || 'Could not get challenge'}`));
|
|
65
|
+
if (challengeData.suggestions?.length > 0) {
|
|
66
|
+
console.log(chalk.yellow('Available alternatives:'));
|
|
67
|
+
for (const s of challengeData.suggestions) {
|
|
68
|
+
console.log(chalk.white(` @${s}`));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
process.exitCode = 1; return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Step 2: Sign challenge and complete registration
|
|
75
|
+
const message = `register:${handle}:${challengeData.nonce}`;
|
|
76
|
+
const sig = Buffer.alloc(sodium.crypto_sign_BYTES);
|
|
77
|
+
sodium.crypto_sign_detached(sig, Buffer.from(message), privateKey);
|
|
78
|
+
|
|
79
|
+
const res = await postTo(serverUrl, '/register', { challengeId: challengeData.challengeId, signature: sig.toString('hex') });
|
|
80
|
+
const result = await res.json();
|
|
81
|
+
if (res.status === 403 && result.code === 'VANITY_HANDLE_PRO_REQUIRED') {
|
|
82
|
+
console.log(chalk.red(`\nVanity handle "@${handle}" requires Pro.`));
|
|
83
|
+
console.log(chalk.yellow('Short custom handles (3-15 chars) are a Pro feature.'));
|
|
84
|
+
console.log(chalk.gray('Upgrade: pal billing upgrade'));
|
|
85
|
+
console.log(chalk.gray('Or use an auto-generated handle instead.'));
|
|
86
|
+
process.exitCode = 1; return;
|
|
87
|
+
}
|
|
88
|
+
if (result.success) {
|
|
89
|
+
console.log(chalk.green('done.'));
|
|
90
|
+
// Store full federated handle if registered on non-primary server
|
|
91
|
+
const primary = getPrimaryServer();
|
|
92
|
+
const fullHandle = (opts.server && opts.server !== primary)
|
|
93
|
+
? `${handle}@${serverUrl.replace(/^https?:\/\//, '')}`
|
|
94
|
+
: handle;
|
|
95
|
+
console.log(chalk.green(`Registered as @${fullHandle}`));
|
|
96
|
+
setIdentityHandle(fullHandle);
|
|
97
|
+
updateProfileHandle(identity.publicKey, fullHandle);
|
|
98
|
+
config.delete('_pendingRegistration');
|
|
99
|
+
|
|
100
|
+
// Publish to DHT for decentralized fallback
|
|
101
|
+
try {
|
|
102
|
+
const { DHTDiscovery } = await import('../core/dhtDiscovery.js');
|
|
103
|
+
const dht = new DHTDiscovery();
|
|
104
|
+
const dhtHash = await dht.publish(handle, identity.publicKey, identity.privateKey);
|
|
105
|
+
const cache = config.get('handleCache') || {};
|
|
106
|
+
if (!cache[handle]) cache[handle] = {};
|
|
107
|
+
cache[handle].dhtHash = dhtHash;
|
|
108
|
+
config.set('handleCache', cache);
|
|
109
|
+
console.log(chalk.gray(`Published to DHT (hash: ${dhtHash.slice(0, 12)}...)`));
|
|
110
|
+
dht.destroy();
|
|
111
|
+
} catch (err) {
|
|
112
|
+
console.log(chalk.yellow(`DHT publish skipped: ${err.message}`));
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
console.log(chalk.red(`\nFailed: ${result.error}`));
|
|
116
|
+
process.exitCode = 1;
|
|
117
|
+
}
|
|
118
|
+
} catch {
|
|
119
|
+
console.log(chalk.red(`\nCould not reach discovery server at ${serverUrl}`));
|
|
120
|
+
process.exitCode = 1;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
program
|
|
125
|
+
.command('verify <code>')
|
|
126
|
+
.description('complete OTP email verification for handle registration')
|
|
127
|
+
.addHelpText('after', `
|
|
128
|
+
Examples:
|
|
129
|
+
$ pal verify 123456 Complete OTP verification
|
|
130
|
+
`)
|
|
131
|
+
.action(async (code) => {
|
|
132
|
+
const pending = config.get('_pendingRegistration');
|
|
133
|
+
if (!pending?.handle) {
|
|
134
|
+
console.log(chalk.red('No pending registration. Run `pal register <handle> --email <email>` first.'));
|
|
135
|
+
process.exitCode = 1; return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const identity = await getIdentity();
|
|
139
|
+
if (!identity?.privateKey) {
|
|
140
|
+
console.log(chalk.red('No identity found.'));
|
|
141
|
+
process.exitCode = 1; return;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const serverUrl = pending.serverUrl || getPrimaryServer();
|
|
145
|
+
const sodium = (await import('sodium-native')).default;
|
|
146
|
+
const privateKey = Buffer.from(identity.privateKey, 'hex');
|
|
147
|
+
const now = Date.now();
|
|
148
|
+
const message = `${pending.handle}:${code}:${now}`;
|
|
149
|
+
const sig = Buffer.alloc(sodium.crypto_sign_BYTES);
|
|
150
|
+
sodium.crypto_sign_detached(sig, Buffer.from(message), privateKey);
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
process.stdout.write(chalk.gray(`Verifying @${pending.handle}... `));
|
|
154
|
+
const res = await postTo(serverUrl, '/otp/verify', { handle: pending.handle, code, signature: sig.toString('hex'), timestamp: now });
|
|
155
|
+
const result = await res.json();
|
|
156
|
+
if (result.success) {
|
|
157
|
+
console.log(chalk.green('done.'));
|
|
158
|
+
console.log(chalk.green(`Handle @${pending.handle} verified and registered.`));
|
|
159
|
+
setIdentityHandle(pending.handle);
|
|
160
|
+
updateProfileHandle(identity.publicKey, pending.handle);
|
|
161
|
+
config.delete('_pendingRegistration');
|
|
162
|
+
} else {
|
|
163
|
+
console.log(chalk.red(`\nVerification failed: ${result.error}`));
|
|
164
|
+
process.exitCode = 1;
|
|
165
|
+
}
|
|
166
|
+
} catch {
|
|
167
|
+
console.log(chalk.red(`\nCould not reach discovery server at ${serverUrl}`));
|
|
168
|
+
process.exitCode = 1;
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
package/lib/commands/relay.js
CHANGED
|
@@ -1,131 +1,131 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
import crypto from 'crypto';
|
|
3
|
-
|
|
4
|
-
export default function relayCommand(program) {
|
|
5
|
-
const cmd = program
|
|
6
|
-
.command('relay')
|
|
7
|
-
.description('manage the TURN relay server extension')
|
|
8
|
-
.addHelpText('after', `
|
|
9
|
-
Examples:
|
|
10
|
-
$
|
|
11
|
-
$
|
|
12
|
-
$
|
|
13
|
-
$
|
|
14
|
-
$
|
|
15
|
-
`)
|
|
16
|
-
.action(() => {
|
|
17
|
-
cmd.outputHelp();
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
cmd
|
|
21
|
-
.command('start')
|
|
22
|
-
.description('start the TURN relay server')
|
|
23
|
-
.action(async () => {
|
|
24
|
-
try {
|
|
25
|
-
const extConfig = (await import('../utils/config.js')).default;
|
|
26
|
-
const cfg = extConfig.get('ext.relay') || {};
|
|
27
|
-
|
|
28
|
-
if (!cfg.secret) {
|
|
29
|
-
cfg.secret = crypto.randomBytes(32).toString('hex');
|
|
30
|
-
extConfig.set('ext.relay', { ...cfg });
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const port = cfg.port || 3478;
|
|
34
|
-
const realm = cfg.realm || 'palexplorer';
|
|
35
|
-
|
|
36
|
-
const store = extConfig.get('ext_store.relay') || {};
|
|
37
|
-
store.running = true;
|
|
38
|
-
store.activeAllocations = store.activeAllocations || {};
|
|
39
|
-
extConfig.set('ext_store.relay', store);
|
|
40
|
-
|
|
41
|
-
console.log(chalk.green(`✔ Relay server started`));
|
|
42
|
-
console.log(` Port: ${chalk.white(port)}`);
|
|
43
|
-
console.log(` Realm: ${chalk.white(realm)}`);
|
|
44
|
-
} catch (err) {
|
|
45
|
-
console.log(chalk.red(`Failed to start relay: ${err.message}`));
|
|
46
|
-
process.exitCode = 1;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
cmd
|
|
51
|
-
.command('stop')
|
|
52
|
-
.description('stop the TURN relay server')
|
|
53
|
-
.action(async () => {
|
|
54
|
-
try {
|
|
55
|
-
const extConfig = (await import('../utils/config.js')).default;
|
|
56
|
-
const store = extConfig.get('ext_store.relay') || {};
|
|
57
|
-
store.running = false;
|
|
58
|
-
store.activeAllocations = {};
|
|
59
|
-
extConfig.set('ext_store.relay', store);
|
|
60
|
-
|
|
61
|
-
console.log(chalk.green(`✔ Relay server stopped`));
|
|
62
|
-
} catch (err) {
|
|
63
|
-
console.log(chalk.red(`Failed to stop relay: ${err.message}`));
|
|
64
|
-
process.exitCode = 1;
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
cmd
|
|
69
|
-
.command('status')
|
|
70
|
-
.description('show relay server status')
|
|
71
|
-
.action(async () => {
|
|
72
|
-
try {
|
|
73
|
-
const extConfig = (await import('../utils/config.js')).default;
|
|
74
|
-
const cfg = extConfig.get('ext.relay') || {};
|
|
75
|
-
const store = extConfig.get('ext_store.relay') || {};
|
|
76
|
-
|
|
77
|
-
const running = store.running || false;
|
|
78
|
-
const port = cfg.port || 3478;
|
|
79
|
-
const realm = cfg.realm || 'palexplorer';
|
|
80
|
-
const maxBandwidth = cfg.maxBandwidth || 'unlimited';
|
|
81
|
-
const allocations = Object.keys(store.activeAllocations || {}).length;
|
|
82
|
-
|
|
83
|
-
console.log('');
|
|
84
|
-
console.log(chalk.cyan.bold('TURN Relay Status'));
|
|
85
|
-
console.log(` Status: ${running ? chalk.green('running') : chalk.red('stopped')}`);
|
|
86
|
-
console.log(` Port: ${chalk.white(port)}`);
|
|
87
|
-
console.log(` Realm: ${chalk.white(realm)}`);
|
|
88
|
-
console.log(` Bandwidth: ${chalk.white(maxBandwidth)}`);
|
|
89
|
-
console.log(` Allocations: ${chalk.white(allocations)}`);
|
|
90
|
-
console.log(` Secret: ${cfg.secret ? chalk.gray(cfg.secret.slice(0, 8) + '...') : chalk.yellow('not set')}`);
|
|
91
|
-
console.log('');
|
|
92
|
-
} catch (err) {
|
|
93
|
-
console.log(chalk.red(`Failed to get status: ${err.message}`));
|
|
94
|
-
process.exitCode = 1;
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
cmd
|
|
99
|
-
.command('credentials [ttl]')
|
|
100
|
-
.description('generate TURN credentials (HMAC-SHA1 based)')
|
|
101
|
-
.action(async (ttl) => {
|
|
102
|
-
try {
|
|
103
|
-
const extConfig = (await import('../utils/config.js')).default;
|
|
104
|
-
const cfg = extConfig.get('ext.relay') || {};
|
|
105
|
-
|
|
106
|
-
if (!cfg.secret) {
|
|
107
|
-
cfg.secret = crypto.randomBytes(32).toString('hex');
|
|
108
|
-
extConfig.set('ext.relay', { ...cfg });
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
const credentialTTL = parseInt(ttl, 10) || cfg.credentialTTL || 3600;
|
|
112
|
-
const timestamp = Math.floor(Date.now() / 1000) + credentialTTL;
|
|
113
|
-
const username = `${timestamp}:palexplorer`;
|
|
114
|
-
const password = crypto
|
|
115
|
-
.createHmac('sha1', cfg.secret)
|
|
116
|
-
.update(username)
|
|
117
|
-
.digest('base64');
|
|
118
|
-
|
|
119
|
-
console.log('');
|
|
120
|
-
console.log(chalk.cyan.bold('TURN Credentials'));
|
|
121
|
-
console.log(` Username: ${chalk.white(username)}`);
|
|
122
|
-
console.log(` Password: ${chalk.white(password)}`);
|
|
123
|
-
console.log(` TTL: ${chalk.white(credentialTTL + 's')}`);
|
|
124
|
-
console.log(` Expires: ${chalk.gray(new Date(timestamp * 1000).toISOString())}`);
|
|
125
|
-
console.log('');
|
|
126
|
-
} catch (err) {
|
|
127
|
-
console.log(chalk.red(`Failed to generate credentials: ${err.message}`));
|
|
128
|
-
process.exitCode = 1;
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
}
|
|
1
|
+
import chalk from 'chalk';
|
|
2
|
+
import crypto from 'crypto';
|
|
3
|
+
|
|
4
|
+
export default function relayCommand(program) {
|
|
5
|
+
const cmd = program
|
|
6
|
+
.command('relay')
|
|
7
|
+
.description('manage the TURN relay server extension')
|
|
8
|
+
.addHelpText('after', `
|
|
9
|
+
Examples:
|
|
10
|
+
$ pal relay start Start the relay server
|
|
11
|
+
$ pal relay stop Stop the relay server
|
|
12
|
+
$ pal relay status Show relay status
|
|
13
|
+
$ pal relay credentials Generate TURN credentials (default 1h TTL)
|
|
14
|
+
$ pal relay credentials 3600 Generate credentials with custom TTL (seconds)
|
|
15
|
+
`)
|
|
16
|
+
.action(() => {
|
|
17
|
+
cmd.outputHelp();
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
cmd
|
|
21
|
+
.command('start')
|
|
22
|
+
.description('start the TURN relay server')
|
|
23
|
+
.action(async () => {
|
|
24
|
+
try {
|
|
25
|
+
const extConfig = (await import('../utils/config.js')).default;
|
|
26
|
+
const cfg = extConfig.get('ext.relay') || {};
|
|
27
|
+
|
|
28
|
+
if (!cfg.secret) {
|
|
29
|
+
cfg.secret = crypto.randomBytes(32).toString('hex');
|
|
30
|
+
extConfig.set('ext.relay', { ...cfg });
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const port = cfg.port || 3478;
|
|
34
|
+
const realm = cfg.realm || 'palexplorer';
|
|
35
|
+
|
|
36
|
+
const store = extConfig.get('ext_store.relay') || {};
|
|
37
|
+
store.running = true;
|
|
38
|
+
store.activeAllocations = store.activeAllocations || {};
|
|
39
|
+
extConfig.set('ext_store.relay', store);
|
|
40
|
+
|
|
41
|
+
console.log(chalk.green(`✔ Relay server started`));
|
|
42
|
+
console.log(` Port: ${chalk.white(port)}`);
|
|
43
|
+
console.log(` Realm: ${chalk.white(realm)}`);
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.log(chalk.red(`Failed to start relay: ${err.message}`));
|
|
46
|
+
process.exitCode = 1;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
cmd
|
|
51
|
+
.command('stop')
|
|
52
|
+
.description('stop the TURN relay server')
|
|
53
|
+
.action(async () => {
|
|
54
|
+
try {
|
|
55
|
+
const extConfig = (await import('../utils/config.js')).default;
|
|
56
|
+
const store = extConfig.get('ext_store.relay') || {};
|
|
57
|
+
store.running = false;
|
|
58
|
+
store.activeAllocations = {};
|
|
59
|
+
extConfig.set('ext_store.relay', store);
|
|
60
|
+
|
|
61
|
+
console.log(chalk.green(`✔ Relay server stopped`));
|
|
62
|
+
} catch (err) {
|
|
63
|
+
console.log(chalk.red(`Failed to stop relay: ${err.message}`));
|
|
64
|
+
process.exitCode = 1;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
cmd
|
|
69
|
+
.command('status')
|
|
70
|
+
.description('show relay server status')
|
|
71
|
+
.action(async () => {
|
|
72
|
+
try {
|
|
73
|
+
const extConfig = (await import('../utils/config.js')).default;
|
|
74
|
+
const cfg = extConfig.get('ext.relay') || {};
|
|
75
|
+
const store = extConfig.get('ext_store.relay') || {};
|
|
76
|
+
|
|
77
|
+
const running = store.running || false;
|
|
78
|
+
const port = cfg.port || 3478;
|
|
79
|
+
const realm = cfg.realm || 'palexplorer';
|
|
80
|
+
const maxBandwidth = cfg.maxBandwidth || 'unlimited';
|
|
81
|
+
const allocations = Object.keys(store.activeAllocations || {}).length;
|
|
82
|
+
|
|
83
|
+
console.log('');
|
|
84
|
+
console.log(chalk.cyan.bold('TURN Relay Status'));
|
|
85
|
+
console.log(` Status: ${running ? chalk.green('running') : chalk.red('stopped')}`);
|
|
86
|
+
console.log(` Port: ${chalk.white(port)}`);
|
|
87
|
+
console.log(` Realm: ${chalk.white(realm)}`);
|
|
88
|
+
console.log(` Bandwidth: ${chalk.white(maxBandwidth)}`);
|
|
89
|
+
console.log(` Allocations: ${chalk.white(allocations)}`);
|
|
90
|
+
console.log(` Secret: ${cfg.secret ? chalk.gray(cfg.secret.slice(0, 8) + '...') : chalk.yellow('not set')}`);
|
|
91
|
+
console.log('');
|
|
92
|
+
} catch (err) {
|
|
93
|
+
console.log(chalk.red(`Failed to get status: ${err.message}`));
|
|
94
|
+
process.exitCode = 1;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
cmd
|
|
99
|
+
.command('credentials [ttl]')
|
|
100
|
+
.description('generate TURN credentials (HMAC-SHA1 based)')
|
|
101
|
+
.action(async (ttl) => {
|
|
102
|
+
try {
|
|
103
|
+
const extConfig = (await import('../utils/config.js')).default;
|
|
104
|
+
const cfg = extConfig.get('ext.relay') || {};
|
|
105
|
+
|
|
106
|
+
if (!cfg.secret) {
|
|
107
|
+
cfg.secret = crypto.randomBytes(32).toString('hex');
|
|
108
|
+
extConfig.set('ext.relay', { ...cfg });
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const credentialTTL = parseInt(ttl, 10) || cfg.credentialTTL || 3600;
|
|
112
|
+
const timestamp = Math.floor(Date.now() / 1000) + credentialTTL;
|
|
113
|
+
const username = `${timestamp}:palexplorer`;
|
|
114
|
+
const password = crypto
|
|
115
|
+
.createHmac('sha1', cfg.secret)
|
|
116
|
+
.update(username)
|
|
117
|
+
.digest('base64');
|
|
118
|
+
|
|
119
|
+
console.log('');
|
|
120
|
+
console.log(chalk.cyan.bold('TURN Credentials'));
|
|
121
|
+
console.log(` Username: ${chalk.white(username)}`);
|
|
122
|
+
console.log(` Password: ${chalk.white(password)}`);
|
|
123
|
+
console.log(` TTL: ${chalk.white(credentialTTL + 's')}`);
|
|
124
|
+
console.log(` Expires: ${chalk.gray(new Date(timestamp * 1000).toISOString())}`);
|
|
125
|
+
console.log('');
|
|
126
|
+
} catch (err) {
|
|
127
|
+
console.log(chalk.red(`Failed to generate credentials: ${err.message}`));
|
|
128
|
+
process.exitCode = 1;
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}
|