@commit451/salamander 1.0.8 → 1.0.9
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/commands/runner-selection.d.ts.map +1 -1
- package/dist/commands/runner-selection.js +48 -4
- package/dist/commands/runner-selection.js.map +1 -1
- package/dist/services/api.d.ts +7 -0
- package/dist/services/api.d.ts.map +1 -1
- package/dist/services/api.js +6 -0
- package/dist/services/api.js.map +1 -1
- package/dist/services/command-listener.d.ts.map +1 -1
- package/dist/services/command-listener.js +46 -12
- package/dist/services/command-listener.js.map +1 -1
- package/dist/services/crypto.d.ts +52 -0
- package/dist/services/crypto.d.ts.map +1 -0
- package/dist/services/crypto.js +104 -0
- package/dist/services/crypto.js.map +1 -0
- package/dist/services/key-manager.d.ts +45 -0
- package/dist/services/key-manager.d.ts.map +1 -0
- package/dist/services/key-manager.js +123 -0
- package/dist/services/key-manager.js.map +1 -0
- package/dist/services/multi-device-key-manager.d.ts +56 -0
- package/dist/services/multi-device-key-manager.d.ts.map +1 -0
- package/dist/services/multi-device-key-manager.js +159 -0
- package/dist/services/multi-device-key-manager.js.map +1 -0
- package/dist/services/runner.d.ts +3 -3
- package/dist/services/runner.d.ts.map +1 -1
- package/dist/services/runner.js +24 -26
- package/dist/services/runner.js.map +1 -1
- package/dist/types/runner.d.ts +0 -6
- package/dist/types/runner.d.ts.map +1 -1
- package/dist/utils/encryption.d.ts +33 -0
- package/dist/utils/encryption.d.ts.map +1 -0
- package/dist/utils/encryption.js +71 -0
- package/dist/utils/encryption.js.map +1 -0
- package/dist/utils/storage.d.ts +1 -0
- package/dist/utils/storage.d.ts.map +1 -1
- package/dist/utils/storage.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner-selection.d.ts","sourceRoot":"","sources":["../../src/commands/runner-selection.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runner-selection.d.ts","sourceRoot":"","sources":["../../src/commands/runner-selection.ts"],"names":[],"mappings":"AASA,wBAAsB,mBAAmB,IAAI,OAAO,CAAC,IAAI,CAAC,CAiGzD"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { select } from '@inquirer/prompts';
|
|
1
|
+
import { confirm, select } from '@inquirer/prompts';
|
|
2
2
|
import chalk from 'chalk';
|
|
3
3
|
import { RunnerService } from '../services/runner.js';
|
|
4
4
|
import { CommandListener } from '../services/command-listener.js';
|
|
5
5
|
import { createRunnerFlow } from './create-runner.js';
|
|
6
6
|
import { deleteRunnerFlow } from './delete-runner.js';
|
|
7
|
+
import { AuthService } from '../services/auth.js';
|
|
7
8
|
export async function runnerSelectionFlow() {
|
|
8
9
|
console.log(chalk.blue('🏃 Runner Selection'));
|
|
9
10
|
try {
|
|
@@ -15,7 +16,8 @@ export async function runnerSelectionFlow() {
|
|
|
15
16
|
message: 'What would you like to do?',
|
|
16
17
|
choices: [
|
|
17
18
|
{ name: 'Create a new runner', value: 'create' },
|
|
18
|
-
{ name: 'Exit', value: 'exit' }
|
|
19
|
+
{ name: 'Exit', value: 'exit' },
|
|
20
|
+
{ name: 'Logout', value: 'logout' }
|
|
19
21
|
]
|
|
20
22
|
});
|
|
21
23
|
if (shouldCreate === 'create') {
|
|
@@ -23,6 +25,19 @@ export async function runnerSelectionFlow() {
|
|
|
23
25
|
// After creating a runner, restart the selection process
|
|
24
26
|
return runnerSelectionFlow();
|
|
25
27
|
}
|
|
28
|
+
else if (shouldCreate === 'logout') {
|
|
29
|
+
const confirmed = await confirm({
|
|
30
|
+
message: 'Are you sure you want to logout?',
|
|
31
|
+
default: false
|
|
32
|
+
});
|
|
33
|
+
if (confirmed) {
|
|
34
|
+
await handleLogout();
|
|
35
|
+
process.exit(0);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
return runnerSelectionFlow();
|
|
39
|
+
}
|
|
40
|
+
}
|
|
26
41
|
else {
|
|
27
42
|
console.log(chalk.blue('👋 Goodbye!'));
|
|
28
43
|
process.exit(0);
|
|
@@ -37,7 +52,8 @@ export async function runnerSelectionFlow() {
|
|
|
37
52
|
})),
|
|
38
53
|
{ name: '➕ Create new runner', value: 'create' },
|
|
39
54
|
{ name: '🗑️ Delete runner', value: 'delete' },
|
|
40
|
-
{ name: '🚪 Exit', value: 'exit' }
|
|
55
|
+
{ name: '🚪 Exit', value: 'exit' },
|
|
56
|
+
{ name: '❌ Logout', value: 'logout' }
|
|
41
57
|
];
|
|
42
58
|
const selection = await select({
|
|
43
59
|
message: 'Select a runner to start or choose an action:',
|
|
@@ -51,6 +67,19 @@ export async function runnerSelectionFlow() {
|
|
|
51
67
|
await deleteRunnerFlow();
|
|
52
68
|
return runnerSelectionFlow();
|
|
53
69
|
}
|
|
70
|
+
else if (selection === 'logout') {
|
|
71
|
+
const confirmed = await confirm({
|
|
72
|
+
message: 'Are you sure you want to logout?',
|
|
73
|
+
default: false
|
|
74
|
+
});
|
|
75
|
+
if (confirmed) {
|
|
76
|
+
await handleLogout();
|
|
77
|
+
process.exit(0);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
return runnerSelectionFlow();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
54
83
|
else if (selection === 'exit') {
|
|
55
84
|
console.log(chalk.blue('👋 Goodbye!'));
|
|
56
85
|
process.exit(0);
|
|
@@ -69,7 +98,6 @@ export async function runnerSelectionFlow() {
|
|
|
69
98
|
}
|
|
70
99
|
}
|
|
71
100
|
catch (error) {
|
|
72
|
-
console.error(chalk.red('❌ Error loading runners:'), error.message);
|
|
73
101
|
process.exit(1);
|
|
74
102
|
}
|
|
75
103
|
}
|
|
@@ -79,4 +107,20 @@ function formatRunnerChoice(runner) {
|
|
|
79
107
|
: '';
|
|
80
108
|
return `🤖 ${chalk.bold(runner.name)} ${chalk.gray(`[${runner.runnerType}]`)}${chalk.dim(lastMessage)}`;
|
|
81
109
|
}
|
|
110
|
+
async function handleLogout() {
|
|
111
|
+
try {
|
|
112
|
+
if (AuthService.isAuthenticated) {
|
|
113
|
+
await AuthService.signOut();
|
|
114
|
+
console.log(chalk.blue('👋 Goodbye!'));
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
console.log(chalk.yellow('⚠️ You are not currently signed in'));
|
|
118
|
+
console.log(chalk.blue('👋 Goodbye!'));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
console.error(chalk.red('❌ Error during logout:'), error.message);
|
|
123
|
+
console.log(chalk.blue('👋 Goodbye!'));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
82
126
|
//# sourceMappingURL=runner-selection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner-selection.js","sourceRoot":"","sources":["../../src/commands/runner-selection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"runner-selection.js","sourceRoot":"","sources":["../../src/commands/runner-selection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,MAAM,EAAC,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,aAAa,EAAC,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAC,eAAe,EAAC,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,WAAW,EAAC,MAAM,qBAAqB,CAAC;AAGhD,MAAM,CAAC,KAAK,UAAU,mBAAmB;IACrC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC;IAE/C,IAAI,CAAC;QACD,MAAM,YAAY,GAAG,MAAM,aAAa,CAAC,aAAa,EAAE,CAAC;QAEzD,IAAI,YAAY,CAAC,MAAM,KAAK,C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,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE,CAAC;AAC5G,CAAC;AAED,KAAK,UAAU,YAAY;IACvB,IAAI,CAAC;QACD,IAAI,WAAW,CAAC,eAAe,EAAE,CAAC;YAC9B,MAAM,WAAW,CAAC,OAAO,EAAE,CAAC;YAC5B,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;QAC3C,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,qCAAqC,CAAC,CAAC,CAAC;YACjE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;QAC3C,CAAC;IACL,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QAClB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,wBAAwB,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,CAAC;QAClE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC;IAC3C,CAAC;AACL,CAAC"}
|
package/dist/services/api.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ interface CreateRunnerRequest {
|
|
|
3
3
|
machineId: string;
|
|
4
4
|
machineName: string;
|
|
5
5
|
name: string;
|
|
6
|
+
encryptionVerification?: string;
|
|
6
7
|
}
|
|
7
8
|
interface UpdateRunnerRequest {
|
|
8
9
|
name?: string;
|
|
@@ -10,10 +11,16 @@ interface UpdateRunnerRequest {
|
|
|
10
11
|
updateLastUsed?: boolean | null;
|
|
11
12
|
lastMessage?: string;
|
|
12
13
|
}
|
|
14
|
+
export interface CreateMessageRequest {
|
|
15
|
+
content: string;
|
|
16
|
+
type: string;
|
|
17
|
+
senderName: string;
|
|
18
|
+
}
|
|
13
19
|
export declare class ApiService {
|
|
14
20
|
private static getAuthToken;
|
|
15
21
|
private static makeRequest;
|
|
16
22
|
static createRunner(request: CreateRunnerRequest): Promise<any>;
|
|
23
|
+
static createRunnerMessage(runnerId: string, request: CreateMessageRequest): Promise<any>;
|
|
17
24
|
static updateRunner(runnerId: string, request: UpdateRunnerRequest): Promise<any>;
|
|
18
25
|
static deleteRunner(runnerId: string): Promise<void>;
|
|
19
26
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/services/api.ts"],"names":[],"mappings":"AAeA,UAAU,mBAAmB;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/services/api.ts"],"names":[],"mappings":"AAeA,UAAU,mBAAmB;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACnC;AAED,UAAU,mBAAmB;IACzB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,mBAAmB,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACrC,cAAc,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,oBAAoB;IACjC,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,UAAU;mBACE,YAAY;mBAUZ,WAAW;WAwCnB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,GAAG,CAAC;WAOxD,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC;WAOlF,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,GAAG,CAAC;WAO1E,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAK7D"}
|
package/dist/services/api.js
CHANGED
|
@@ -53,6 +53,12 @@ export class ApiService {
|
|
|
53
53
|
body: JSON.stringify(request),
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
|
+
static async createRunnerMessage(runnerId, request) {
|
|
57
|
+
return await this.makeRequest(`/runner/${runnerId}/message`, {
|
|
58
|
+
method: 'POST',
|
|
59
|
+
body: JSON.stringify(request),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
56
62
|
static async updateRunner(runnerId, request) {
|
|
57
63
|
return await this.makeRequest(`/runner/${runnerId}`, {
|
|
58
64
|
method: 'PATCH',
|
package/dist/services/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/services/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,WAAW,CAAC;AAEtC,MAAM,YAAY,GAAG,iCAAiC,CAAC;AAEvD,MAAM,QAAS,SAAQ,KAAK;IAGb;IACA;IAHX,YACI,OAAe,EACR,MAAc,EACd,QAAc;QAErB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHR,WAAM,GAAN,MAAM,CAAQ;QACd,aAAQ,GAAR,QAAQ,CAAM;QAGrB,IAAI,CAAC,IAAI,GAAG,UAAU,CAAC;IAC3B,CAAC;CACJ;
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/services/api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,WAAW,CAAC;AAEtC,MAAM,YAAY,GAAG,iCAAiC,CAAC;AAEvD,MAAM,QAAS,SAAQ,KAAK;IAGb;IACA;IAHX,YACI,OAAe,EACR,MAAc,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ts","sourceRoot":"","sources":["../../src/services/command-listener.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"command-listener.d.ts","sourceRoot":"","sources":["../../src/services/command-listener.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,MAAM,oBAAoB,CAAC;AAQ1C,qBAAa,eAAe;IACxB,OAAO,CAAC,eAAe,CAAsC;IAC7D,OAAO,CAAC,cAAc,CAAS;IAEzB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAyI7C,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAQvD"}
|
|
@@ -2,6 +2,8 @@ import chalk from 'chalk';
|
|
|
2
2
|
import { RunnerService } from './runner.js';
|
|
3
3
|
import { CommandExecutor } from './executor.js';
|
|
4
4
|
import { generateDeviceId } from '../utils/device.js';
|
|
5
|
+
import { EncryptionService } from '../utils/encryption.js';
|
|
6
|
+
import { loadAuth, saveAuth } from '../utils/storage.js';
|
|
5
7
|
export class CommandListener {
|
|
6
8
|
activeListeners = new Map();
|
|
7
9
|
isShuttingDown = false;
|
|
@@ -15,10 +17,29 @@ export class CommandListener {
|
|
|
15
17
|
if (runner.machineId !== deviceId) {
|
|
16
18
|
throw new Error('Cannot listen to non-local runner');
|
|
17
19
|
}
|
|
20
|
+
// Generate or load encryption code
|
|
21
|
+
let encryptionCode;
|
|
22
|
+
const storedAuth = await loadAuth();
|
|
23
|
+
if (storedAuth?.encryptionCode) {
|
|
24
|
+
encryptionCode = storedAuth.encryptionCode;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// Generate new random encryption code
|
|
28
|
+
encryptionCode = EncryptionService.generateRandomSecret();
|
|
29
|
+
// Save to storage
|
|
30
|
+
const updatedAuth = { ...storedAuth, encryptionCode };
|
|
31
|
+
await saveAuth(updatedAuth);
|
|
32
|
+
}
|
|
18
33
|
console.log(chalk.blue(`👂 Started listening for commands on runner "${runner.name}"`));
|
|
19
34
|
console.log(chalk.gray(` Directory: ${runner.directory}`));
|
|
20
35
|
console.log(chalk.gray(` Type: ${runner.runnerType}`));
|
|
21
36
|
console.log('');
|
|
37
|
+
// Display encryption code prominently
|
|
38
|
+
console.log(chalk.bgGreen.black(' ENCRYPTION CODE '));
|
|
39
|
+
console.log(chalk.green(` ${encryptionCode}`));
|
|
40
|
+
console.log(chalk.gray(' Enter this code in your Salamander mobile app to securely'));
|
|
41
|
+
console.log(chalk.gray(' connect to this runner. Your messages and commands are end to end encrypted'));
|
|
42
|
+
console.log('');
|
|
22
43
|
console.log(chalk.yellow('⚠️ SECURITY WARNING'));
|
|
23
44
|
console.log(chalk.yellow(' Claude commands will be executed with --dangerously-skip-permissions'));
|
|
24
45
|
console.log(chalk.yellow(' This bypasses normal permission checks for file access and operations'));
|
|
@@ -30,36 +51,49 @@ export class CommandListener {
|
|
|
30
51
|
if (!updatedRunner || this.isShuttingDown)
|
|
31
52
|
return;
|
|
32
53
|
if (updatedRunner.pendingCommand) {
|
|
33
|
-
|
|
54
|
+
// Decrypt the pending command
|
|
55
|
+
const decryptResult = EncryptionService.decrypt(updatedRunner.pendingCommand, encryptionCode);
|
|
56
|
+
if (!decryptResult.success) {
|
|
57
|
+
console.log(chalk.red(`❌ Failed to decrypt command: ${updatedRunner.pendingCommand}`));
|
|
58
|
+
// Clear the bad command
|
|
59
|
+
await RunnerService.clearPendingCommand(runner.id);
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const decryptedCommand = decryptResult.decrypted;
|
|
63
|
+
console.log(chalk.cyan(`📨 Received command: ${decryptedCommand}`));
|
|
34
64
|
try {
|
|
35
65
|
// Clear the pending command immediately
|
|
36
66
|
await RunnerService.clearPendingCommand(runner.id);
|
|
37
|
-
// Execute the command
|
|
38
|
-
const result = await CommandExecutor.executeCommand(updatedRunner,
|
|
67
|
+
// Execute the decrypted command
|
|
68
|
+
const result = await CommandExecutor.executeCommand(updatedRunner, decryptedCommand);
|
|
69
|
+
// Encrypt the result
|
|
70
|
+
const encryptResult = EncryptionService.encrypt(result.output, encryptionCode);
|
|
71
|
+
const encryptedOutput = encryptResult.success ? encryptResult.encrypted : result.output;
|
|
39
72
|
// Create assistant message for the result
|
|
40
|
-
await RunnerService.createMessage({
|
|
41
|
-
content:
|
|
73
|
+
await RunnerService.createMessage(runner.id, {
|
|
74
|
+
content: encryptedOutput,
|
|
42
75
|
senderName: runner.name,
|
|
43
76
|
type: 'runner',
|
|
44
|
-
runnerId: runner.id
|
|
45
77
|
});
|
|
46
|
-
// Update the runner with the result
|
|
47
|
-
await RunnerService.updateRunnerAfterCommand(runner.id,
|
|
78
|
+
// Update the runner with the encrypted result
|
|
79
|
+
await RunnerService.updateRunnerAfterCommand(runner.id, encryptedOutput);
|
|
48
80
|
console.log(chalk.blue(`💌 Message sent`));
|
|
49
81
|
console.log(chalk.gray('Waiting for next command...'));
|
|
50
82
|
}
|
|
51
83
|
catch (error) {
|
|
52
84
|
console.error(chalk.red(`❌ Error processing command: ${error.message}`));
|
|
53
85
|
const errorMessage = `Error executing command: ${error.message}`;
|
|
86
|
+
// Encrypt the error message
|
|
87
|
+
const encryptResult = EncryptionService.encrypt(errorMessage, encryptionCode);
|
|
88
|
+
const encryptedError = encryptResult.success ? encryptResult.encrypted : errorMessage;
|
|
54
89
|
try {
|
|
55
90
|
// Create assistant message for the error
|
|
56
|
-
await RunnerService.createMessage({
|
|
57
|
-
content:
|
|
91
|
+
await RunnerService.createMessage(runner.id, {
|
|
92
|
+
content: encryptedError,
|
|
58
93
|
senderName: runner.name,
|
|
59
94
|
type: 'runner',
|
|
60
|
-
runnerId: runner.id
|
|
61
95
|
});
|
|
62
|
-
await RunnerService.updateRunnerAfterCommand(runner.id,
|
|
96
|
+
await RunnerService.updateRunnerAfterCommand(runner.id, encryptedError);
|
|
63
97
|
}
|
|
64
98
|
catch (updateError) {
|
|
65
99
|
console.error(chalk.red('Failed to update runner with error result'));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-listener.js","sourceRoot":"","sources":["../../src/services/command-listener.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAC,eAAe,EAAC,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"command-listener.js","sourceRoot":"","sources":["../../src/services/command-listener.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAC,eAAe,EAAC,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,iBAAiB,EAAC,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAGvD,MAAM,OAAO,eAAe;IAChB,eAAe,GAA4B,IAAI,GAAG,EAAE,CAAC;IACrD,cAAc,GAAG,KAAK,CAAC;IAE/B,KAAK,CAAC,cAAc,CAAC,MAAc;QAC/B,IAAI,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC;YACtC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,gCAAgC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;YAC1E,OAAO;QACX,CAAC;QAED,gCAAgC;QAChC,MAAM,QAAQ,GAAG,gBAAgB,EAAE,CAAC;QACpC,IAAI,MAAM,CAAC,SAAS,KAAK,QAAQ,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;QACzD,CA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B,OAAO,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAE/B,kCAAkC;QAClC,OAAO,CAAC,EAAE,CAAC,mBAAmB,EAAE,OAAO,CAAC,CAAC;QACzC,OAAO,CAAC,EAAE,CAAC,oBAAoB,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,QAAgB;QAChC,MAAM,WAAW,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;QACvD,IAAI,WAAW,EAAE,CAAC;YACd,WAAW,EAAE,CAAC;YACd,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAE1C,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
export interface KeyPair {
|
|
2
|
+
publicKey: string;
|
|
3
|
+
privateKey: string;
|
|
4
|
+
}
|
|
5
|
+
export interface EncryptedMessage {
|
|
6
|
+
encryptedData: string;
|
|
7
|
+
iv: string;
|
|
8
|
+
tag: string;
|
|
9
|
+
}
|
|
10
|
+
export declare class CryptoService {
|
|
11
|
+
private static readonly ALGORITHM;
|
|
12
|
+
private static readonly IV_LENGTH;
|
|
13
|
+
private static readonly TAG_LENGTH;
|
|
14
|
+
private static readonly KEY_LENGTH;
|
|
15
|
+
/**
|
|
16
|
+
* Generate an ECDH key pair for key exchange
|
|
17
|
+
*/
|
|
18
|
+
static generateECDHKeyPair(): KeyPair;
|
|
19
|
+
/**
|
|
20
|
+
* Derive a shared secret from ECDH key exchange
|
|
21
|
+
*/
|
|
22
|
+
static deriveSharedSecret(privateKey: string, publicKey: string): string;
|
|
23
|
+
/**
|
|
24
|
+
* Encrypt a message using AES-256-GCM
|
|
25
|
+
*/
|
|
26
|
+
static encrypt(message: string, key: string): EncryptedMessage;
|
|
27
|
+
/**
|
|
28
|
+
* Decrypt a message using AES-256-GCM
|
|
29
|
+
*/
|
|
30
|
+
static decrypt(encryptedMessage: EncryptedMessage, key: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Generate a random 256-bit key for symmetric encryption
|
|
33
|
+
*/
|
|
34
|
+
static generateRandomKey(): string;
|
|
35
|
+
/**
|
|
36
|
+
* Check if a message appears to be encrypted
|
|
37
|
+
*/
|
|
38
|
+
static isEncrypted(message: string): boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Safely encrypt a message, handling both string and object inputs
|
|
41
|
+
*/
|
|
42
|
+
static safeEncrypt(data: any, key: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Safely decrypt a message, throwing error if decryption fails
|
|
45
|
+
*/
|
|
46
|
+
static safeDecrypt(encryptedData: string, key: string): string;
|
|
47
|
+
/**
|
|
48
|
+
* Create a hash of the key for identification purposes
|
|
49
|
+
*/
|
|
50
|
+
static createKeyHash(key: string): string;
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=crypto.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.d.ts","sourceRoot":"","sources":["../../src/services/crypto.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,OAAO;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,gBAAgB;IAC7B,aAAa,EAAE,MAAM,CAAC;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;CACf;AAED,qBAAa,aAAa;IACtB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAiB;IAClD,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAM;IACvC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAM;IACxC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAM;IAExC;;OAEG;IACH,MAAM,CAAC,mBAAmB,IAAI,OAAO;IAUrC;;OAEG;IACH,MAAM,CAAC,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM;IAYxE;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,gBAAgB;IAmB9D;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,gBAAgB,EAAE,gBAAgB,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAevE;;OAEG;IACH,MAAM,CAAC,iBAAiB,IAAI,MAAM;IAKlC;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAS5C;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAMlD;;OAEG;IACH,MAAM,CAAC,WAAW,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM;IAS9D;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;CAG5C"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as crypto from 'node:crypto';
|
|
2
|
+
export class CryptoService {
|
|
3
|
+
static ALGORITHM = 'aes-256-gcm';
|
|
4
|
+
static IV_LENGTH = 16;
|
|
5
|
+
static TAG_LENGTH = 16;
|
|
6
|
+
static KEY_LENGTH = 32;
|
|
7
|
+
/**
|
|
8
|
+
* Generate an ECDH key pair for key exchange
|
|
9
|
+
*/
|
|
10
|
+
static generateECDHKeyPair() {
|
|
11
|
+
const ecdh = crypto.createECDH('secp256k1');
|
|
12
|
+
ecdh.generateKeys();
|
|
13
|
+
return {
|
|
14
|
+
publicKey: ecdh.getPublicKey('base64'),
|
|
15
|
+
privateKey: ecdh.getPrivateKey('base64')
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Derive a shared secret from ECDH key exchange
|
|
20
|
+
*/
|
|
21
|
+
static deriveSharedSecret(privateKey, publicKey) {
|
|
22
|
+
const ecdh = crypto.createECDH('secp256k1');
|
|
23
|
+
ecdh.setPrivateKey(privateKey, 'base64');
|
|
24
|
+
const sharedSecret = ecdh.computeSecret(publicKey, 'base64');
|
|
25
|
+
// Use HKDF to derive a proper encryption key
|
|
26
|
+
const derivedKey = crypto.hkdfSync('sha256', sharedSecret, '', 'salamander-e2e-encryption', CryptoService.KEY_LENGTH);
|
|
27
|
+
return Buffer.from(derivedKey).toString('base64');
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Encrypt a message using AES-256-GCM
|
|
31
|
+
*/
|
|
32
|
+
static encrypt(message, key) {
|
|
33
|
+
const keyBuffer = Buffer.from(key, 'base64');
|
|
34
|
+
const iv = crypto.randomBytes(CryptoService.IV_LENGTH);
|
|
35
|
+
const cipher = crypto.createCipheriv(CryptoService.ALGORITHM, keyBuffer, iv);
|
|
36
|
+
cipher.setAAD(Buffer.from('salamander'));
|
|
37
|
+
let encryptedData = cipher.update(message, 'utf8', 'base64');
|
|
38
|
+
encryptedData += cipher.final('base64');
|
|
39
|
+
const tag = cipher.getAuthTag();
|
|
40
|
+
return {
|
|
41
|
+
encryptedData,
|
|
42
|
+
iv: iv.toString('base64'),
|
|
43
|
+
tag: tag.toString('base64')
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Decrypt a message using AES-256-GCM
|
|
48
|
+
*/
|
|
49
|
+
static decrypt(encryptedMessage, key) {
|
|
50
|
+
const keyBuffer = Buffer.from(key, 'base64');
|
|
51
|
+
const iv = Buffer.from(encryptedMessage.iv, 'base64');
|
|
52
|
+
const tag = Buffer.from(encryptedMessage.tag, 'base64');
|
|
53
|
+
const decipher = crypto.createDecipheriv(CryptoService.ALGORITHM, keyBuffer, iv);
|
|
54
|
+
decipher.setAAD(Buffer.from('salamander'));
|
|
55
|
+
decipher.setAuthTag(tag);
|
|
56
|
+
let decryptedData = decipher.update(encryptedMessage.encryptedData, 'base64', 'utf8');
|
|
57
|
+
decryptedData += decipher.final('utf8');
|
|
58
|
+
return decryptedData;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Generate a random 256-bit key for symmetric encryption
|
|
62
|
+
*/
|
|
63
|
+
static generateRandomKey() {
|
|
64
|
+
const key = crypto.randomBytes(CryptoService.KEY_LENGTH);
|
|
65
|
+
return key.toString('base64');
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Check if a message appears to be encrypted
|
|
69
|
+
*/
|
|
70
|
+
static isEncrypted(message) {
|
|
71
|
+
try {
|
|
72
|
+
const parsed = JSON.parse(message);
|
|
73
|
+
return parsed.encryptedData && parsed.iv && parsed.tag;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Safely encrypt a message, handling both string and object inputs
|
|
81
|
+
*/
|
|
82
|
+
static safeEncrypt(data, key) {
|
|
83
|
+
const message = typeof data === 'string' ? data : JSON.stringify(data);
|
|
84
|
+
const encrypted = this.encrypt(message, key);
|
|
85
|
+
return JSON.stringify(encrypted);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Safely decrypt a message, throwing error if decryption fails
|
|
89
|
+
*/
|
|
90
|
+
static safeDecrypt(encryptedData, key) {
|
|
91
|
+
if (!this.isEncrypted(encryptedData)) {
|
|
92
|
+
throw new Error('Message is not encrypted - encryption is required');
|
|
93
|
+
}
|
|
94
|
+
const encryptedMessage = JSON.parse(encryptedData);
|
|
95
|
+
return this.decrypt(encryptedMessage, key);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Create a hash of the key for identification purposes
|
|
99
|
+
*/
|
|
100
|
+
static createKeyHash(key) {
|
|
101
|
+
return crypto.createHash('sha256').update(key).digest('hex').substring(0, 16);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=crypto.js.map
|
|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AAM,gBAAgB,GAAqB,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;QACrE,OAAO,IAAI,CAAC,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC,CAAC;IAC/C,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,aAAa,CAAC,GAAW;QAC5B,OAAO,MAAM,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IAClF,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { KeyPair } from './crypto.js';
|
|
2
|
+
export declare class KeyManagerService {
|
|
3
|
+
private static readonly KEYS_STORAGE_KEY;
|
|
4
|
+
private static readonly KEY_EXPIRY_DAYS;
|
|
5
|
+
/**
|
|
6
|
+
* Initialize keys for a new runner
|
|
7
|
+
*/
|
|
8
|
+
static initializeRunnerKeys(runnerId: string): Promise<KeyPair>;
|
|
9
|
+
/**
|
|
10
|
+
* Complete the key exchange with the Flutter app's public key
|
|
11
|
+
*/
|
|
12
|
+
static completeKeyExchange(runnerId: string, flutterPublicKey: string): Promise<string>;
|
|
13
|
+
/**
|
|
14
|
+
* Get the shared secret for encryption/decryption
|
|
15
|
+
*/
|
|
16
|
+
static getSharedSecret(runnerId: string): Promise<string | null>;
|
|
17
|
+
/**
|
|
18
|
+
* Get the CLI's public key for a runner
|
|
19
|
+
*/
|
|
20
|
+
static getPublicKey(runnerId: string): Promise<string | null>;
|
|
21
|
+
/**
|
|
22
|
+
* Check if keys exist and are properly initialized for a runner
|
|
23
|
+
*/
|
|
24
|
+
static hasValidKeys(runnerId: string): Promise<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
* Rotate keys for a runner (generate new key pair)
|
|
27
|
+
*/
|
|
28
|
+
static rotateKeys(runnerId: string): Promise<KeyPair>;
|
|
29
|
+
/**
|
|
30
|
+
* Remove keys for a runner (when runner is deleted)
|
|
31
|
+
*/
|
|
32
|
+
static removeRunnerKeys(runnerId: string): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Get all runners that have encryption keys
|
|
35
|
+
*/
|
|
36
|
+
static getEncryptedRunnerIds(): Promise<string[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Cleanup expired keys
|
|
39
|
+
*/
|
|
40
|
+
static cleanupExpiredKeys(): Promise<number>;
|
|
41
|
+
private static getRunnerKeys;
|
|
42
|
+
private static storeRunnerKeys;
|
|
43
|
+
private static getAllStoredKeys;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=key-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-manager.d.ts","sourceRoot":"","sources":["../../src/services/key-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,OAAO,EAAC,MAAM,aAAa,CAAC;AAUnD,qBAAa,iBAAiB;IAC1B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAA4B;IACpE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAM;IAE7C;;OAEG;WACU,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAYrE;;OAEG;WACU,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAoB7F;;OAEG;WACU,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAetE;;OAEG;WACU,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAKnE;;OAEG;WACU,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAK7D;;OAEG;WACU,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAK3D;;OAEG;WACU,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAM9D;;OAEG;WACU,qBAAqB,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;IAQvD;;OAEG;WACU,kBAAkB,IAAI,OAAO,CAAC,MAAM,CAAC;mBAwB7B,aAAa;mBAKb,eAAe;mBAMf,gBAAgB;CAGxC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { CryptoService } from './crypto.js';
|
|
2
|
+
import { StorageService } from '../utils/storage.js';
|
|
3
|
+
export class KeyManagerService {
|
|
4
|
+
static KEYS_STORAGE_KEY = 'salamander_runner_keys';
|
|
5
|
+
static KEY_EXPIRY_DAYS = 30;
|
|
6
|
+
/**
|
|
7
|
+
* Initialize keys for a new runner
|
|
8
|
+
*/
|
|
9
|
+
static async initializeRunnerKeys(runnerId) {
|
|
10
|
+
const ecdhKeyPair = CryptoService.generateECDHKeyPair();
|
|
11
|
+
const runnerKeys = {
|
|
12
|
+
ecdhKeyPair,
|
|
13
|
+
createdAt: Date.now()
|
|
14
|
+
};
|
|
15
|
+
await this.storeRunnerKeys(runnerId, runnerKeys);
|
|
16
|
+
return ecdhKeyPair;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Complete the key exchange with the Flutter app's public key
|
|
20
|
+
*/
|
|
21
|
+
static async completeKeyExchange(runnerId, flutterPublicKey) {
|
|
22
|
+
const runnerKeys = await this.getRunnerKeys(runnerId);
|
|
23
|
+
if (!runnerKeys) {
|
|
24
|
+
throw new Error(`No keys found for runner ${runnerId}`);
|
|
25
|
+
}
|
|
26
|
+
// Derive shared secret using our private key and Flutter's public key
|
|
27
|
+
const sharedSecret = CryptoService.deriveSharedSecret(runnerKeys.ecdhKeyPair.privateKey, flutterPublicKey);
|
|
28
|
+
// Update stored keys with shared secret
|
|
29
|
+
runnerKeys.sharedSecret = sharedSecret;
|
|
30
|
+
runnerKeys.keyHash = CryptoService.createKeyHash(sharedSecret);
|
|
31
|
+
await this.storeRunnerKeys(runnerId, runnerKeys);
|
|
32
|
+
return sharedSecret;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Get the shared secret for encryption/decryption
|
|
36
|
+
*/
|
|
37
|
+
static async getSharedSecret(runnerId) {
|
|
38
|
+
const runnerKeys = await this.getRunnerKeys(runnerId);
|
|
39
|
+
if (!runnerKeys?.sharedSecret) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
// Check if keys are expired
|
|
43
|
+
const daysSinceCreation = (Date.now() - runnerKeys.createdAt) / (1000 * 60 * 60 * 24);
|
|
44
|
+
if (daysSinceCreation > this.KEY_EXPIRY_DAYS) {
|
|
45
|
+
console.warn(`Keys for runner ${runnerId} have expired. Consider key rotation.`);
|
|
46
|
+
}
|
|
47
|
+
return runnerKeys.sharedSecret;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get the CLI's public key for a runner
|
|
51
|
+
*/
|
|
52
|
+
static async getPublicKey(runnerId) {
|
|
53
|
+
const runnerKeys = await this.getRunnerKeys(runnerId);
|
|
54
|
+
return runnerKeys?.ecdhKeyPair.publicKey ?? null;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Check if keys exist and are properly initialized for a runner
|
|
58
|
+
*/
|
|
59
|
+
static async hasValidKeys(runnerId) {
|
|
60
|
+
const runnerKeys = await this.getRunnerKeys(runnerId);
|
|
61
|
+
return !!(runnerKeys?.ecdhKeyPair && runnerKeys?.sharedSecret);
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Rotate keys for a runner (generate new key pair)
|
|
65
|
+
*/
|
|
66
|
+
static async rotateKeys(runnerId) {
|
|
67
|
+
console.log(`Rotating keys for runner ${runnerId}`);
|
|
68
|
+
return await this.initializeRunnerKeys(runnerId);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Remove keys for a runner (when runner is deleted)
|
|
72
|
+
*/
|
|
73
|
+
static async removeRunnerKeys(runnerId) {
|
|
74
|
+
const allKeys = await this.getAllStoredKeys();
|
|
75
|
+
delete allKeys[runnerId];
|
|
76
|
+
await StorageService.set(this.KEYS_STORAGE_KEY, allKeys);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Get all runners that have encryption keys
|
|
80
|
+
*/
|
|
81
|
+
static async getEncryptedRunnerIds() {
|
|
82
|
+
const allKeys = await this.getAllStoredKeys();
|
|
83
|
+
return Object.keys(allKeys).filter(runnerId => {
|
|
84
|
+
const keys = allKeys[runnerId];
|
|
85
|
+
return keys?.sharedSecret;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Cleanup expired keys
|
|
90
|
+
*/
|
|
91
|
+
static async cleanupExpiredKeys() {
|
|
92
|
+
const allKeys = await this.getAllStoredKeys();
|
|
93
|
+
const now = Date.now();
|
|
94
|
+
let cleanedCount = 0;
|
|
95
|
+
const updatedKeys = {};
|
|
96
|
+
for (const [runnerId, keys] of Object.entries(allKeys)) {
|
|
97
|
+
const daysSinceCreation = (now - keys.createdAt) / (1000 * 60 * 60 * 24);
|
|
98
|
+
if (daysSinceCreation <= this.KEY_EXPIRY_DAYS) {
|
|
99
|
+
updatedKeys[runnerId] = keys;
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
cleanedCount++;
|
|
103
|
+
console.log(`Cleaned up expired keys for runner ${runnerId}`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
await StorageService.set(this.KEYS_STORAGE_KEY, updatedKeys);
|
|
107
|
+
return cleanedCount;
|
|
108
|
+
}
|
|
109
|
+
// Private helper methods
|
|
110
|
+
static async getRunnerKeys(runnerId) {
|
|
111
|
+
const allKeys = await this.getAllStoredKeys();
|
|
112
|
+
return allKeys[runnerId] ?? null;
|
|
113
|
+
}
|
|
114
|
+
static async storeRunnerKeys(runnerId, keys) {
|
|
115
|
+
const allKeys = await this.getAllStoredKeys();
|
|
116
|
+
allKeys[runnerId] = keys;
|
|
117
|
+
await StorageService.set(this.KEYS_STORAGE_KEY, allKeys);
|
|
118
|
+
}
|
|
119
|
+
static async getAllStoredKeys() {
|
|
120
|
+
return (await StorageService.get(this.KEYS_STORAGE_KEY)) ?? {};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=key-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"key-manager.js","sourceRoot":"","sources":["../../src/services/key-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAU,MAAM,aAAa,CAAC;AACnD,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AASnD,MAAM,OAAO,iBAAiB;IAClB,MAAM,CAAU,gBAAgB,GAAG,wBAAwB,CAAC;IAC5D,MAAM,CAAU,eAAe,GAAG,EAAE,CAAC;IAE7C;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,QAAgB;QAC9C,MAAM,WAAW,GAAG,aAAa,CAAC,mBAAmB,EAAE,CAAC;QAExD,MAAM,UAAU,GAAe;YAC3B,WAAW;YACX,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACxB,CAAC;QAEF,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;QACjD,OAAO,WAAW,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,QAAgB,EAAE,gBAAwB;QACvE,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACtD,IAAI,CAAC,UAAU,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,4BAA4B,QAAQ,EAAE,CAAC,CAAC;QAC5D,CAAC;QAED,sEAAsE;QACtE,MAAM,YAAY,GAAG,aAAa,CAAC,kBAAkB,CACjD,UAAU,CAAC,WAAW,CAAC,UAA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SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;YAEzE,IAAI,iBAAiB,IAAI,IAAI,CAAC,eAAe,EAAE,CAAC;gBAC5C,WAAW,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;YACjC,CAAC;iBAAM,CAAC;gBACJ,YAAY,EAAE,CAAC;gBACf,OAAO,CAAC,GAAG,CAAC,sCAAsC,QAAQ,EAAE,CAAC,CAAC;YAClE,CAAC;QACL,CAAC;QAED,MAAM,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,EAAE,WAAW,CAAC,CAAC;QAC7D,OAAO,YAAY,CAAC;IACxB,CAAC;IAED,yBAAyB;IAEjB,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,QAAgB;QAC/C,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC9C,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC;IACrC,CAAC;IAEO,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,QAAgB,EAAE,IAAgB;QACnE,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC9C,OAAO,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC;QACzB,MAAM,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAC;IAC7D,CAAC;IAEO,MAAM,CAAC,KAAK,CAAC,gBAAgB;QACjC,OAAO,CAAC,MAAM,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,IAAI,EAAE,CAAC;IACnE,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type DeviceKey } from '../types/runner.js';
|
|
2
|
+
export declare class MultiDeviceKeyManagerService {
|
|
3
|
+
private static readonly KEYS_STORAGE_KEY;
|
|
4
|
+
private static readonly KEY_EXPIRY_DAYS;
|
|
5
|
+
/**
|
|
6
|
+
* Initialize keys for a new runner (CLI side)
|
|
7
|
+
*/
|
|
8
|
+
static initializeRunnerKeys(runnerId: string): Promise<{
|
|
9
|
+
publicKey: string;
|
|
10
|
+
privateKey: string;
|
|
11
|
+
}>;
|
|
12
|
+
/**
|
|
13
|
+
* Register a new device and derive shared secret
|
|
14
|
+
*/
|
|
15
|
+
static registerDevice(runnerId: string, deviceKey: DeviceKey): Promise<string>;
|
|
16
|
+
/**
|
|
17
|
+
* Remove a device from the runner
|
|
18
|
+
*/
|
|
19
|
+
static removeDevice(runnerId: string, deviceId: string): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Get shared secret for specific device
|
|
22
|
+
*/
|
|
23
|
+
static getSharedSecret(runnerId: string, deviceId: string): Promise<string | null>;
|
|
24
|
+
/**
|
|
25
|
+
* Get all registered device IDs for a runner
|
|
26
|
+
*/
|
|
27
|
+
static getRegisteredDevices(runnerId: string): Promise<string[]>;
|
|
28
|
+
/**
|
|
29
|
+
* Encrypt command for specific device
|
|
30
|
+
*/
|
|
31
|
+
static encryptForDevice(runnerId: string, deviceId: string, command: string): Promise<string>;
|
|
32
|
+
/**
|
|
33
|
+
* Encrypt command for all registered devices
|
|
34
|
+
*/
|
|
35
|
+
static encryptForAllDevices(runnerId: string, command: string): Promise<Record<string, string>>;
|
|
36
|
+
/**
|
|
37
|
+
* Decrypt command from specific device
|
|
38
|
+
*/
|
|
39
|
+
static decryptFromDevice(runnerId: string, deviceId: string, encryptedCommand: string): Promise<string>;
|
|
40
|
+
/**
|
|
41
|
+
* Check if runner has any registered devices
|
|
42
|
+
*/
|
|
43
|
+
static hasRegisteredDevices(runnerId: string): Promise<boolean>;
|
|
44
|
+
/**
|
|
45
|
+
* Clean up all keys for a runner
|
|
46
|
+
*/
|
|
47
|
+
static removeRunnerKeys(runnerId: string): Promise<void>;
|
|
48
|
+
/**
|
|
49
|
+
* Get CLI's public key for a runner
|
|
50
|
+
*/
|
|
51
|
+
static getCliPublicKey(runnerId: string): Promise<string | null>;
|
|
52
|
+
private static getRunnerKeys;
|
|
53
|
+
private static storeRunnerKeys;
|
|
54
|
+
private static getAllStoredKeys;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=multi-device-key-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-device-key-manager.d.ts","sourceRoot":"","sources":["../../src/services/multi-device-key-manager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAC,KAAK,SAAS,EAAC,MAAM,oBAAoB,CAAC;AASlD,qBAAa,4BAA4B;IACrC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAkC;IAC1E,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAM;IAE7C;;OAEG;WACU,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAC,CAAC;IAcrG;;OAEG;WACU,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC;IA6BpF;;OAEG;WACU,YAAY,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAa5E;;OAEG;WACU,eAAe,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAexF;;OAEG;WACU,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAStE;;OAEG;WACU,gBAAgB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IASnG;;OAEG;WACU,oBAAoB,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAuBrG;;OAEG;WACU,iBAAiB,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAS7G;;OAEG;WACU,oBAAoB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKrE;;OAEG;WACU,gBAAgB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAO9D;;OAEG;WACU,eAAe,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;mBAOjD,aAAa;mBAKb,eAAe;mBAMf,gBAAgB;CAGxC"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { CryptoService } from './crypto.js';
|
|
2
|
+
import { StorageService } from '../utils/storage.js';
|
|
3
|
+
export class MultiDeviceKeyManagerService {
|
|
4
|
+
static KEYS_STORAGE_KEY = 'salamander_multi_device_keys';
|
|
5
|
+
static KEY_EXPIRY_DAYS = 30;
|
|
6
|
+
/**
|
|
7
|
+
* Initialize keys for a new runner (CLI side)
|
|
8
|
+
*/
|
|
9
|
+
static async initializeRunnerKeys(runnerId) {
|
|
10
|
+
const ecdhKeyPair = CryptoService.generateECDHKeyPair();
|
|
11
|
+
const keyData = {
|
|
12
|
+
ecdhKeyPair,
|
|
13
|
+
sharedSecrets: {},
|
|
14
|
+
keyHashes: {},
|
|
15
|
+
createdAt: Date.now()
|
|
16
|
+
};
|
|
17
|
+
await this.storeRunnerKeys(runnerId, keyData);
|
|
18
|
+
return ecdhKeyPair;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Register a new device and derive shared secret
|
|
22
|
+
*/
|
|
23
|
+
static async registerDevice(runnerId, deviceKey) {
|
|
24
|
+
const keyData = await this.getRunnerKeys(runnerId);
|
|
25
|
+
if (!keyData) {
|
|
26
|
+
throw new Error(`No keys found for runner ${runnerId}`);
|
|
27
|
+
}
|
|
28
|
+
// Derive shared secret with this device
|
|
29
|
+
const sharedSecret = CryptoService.deriveSharedSecret(keyData.ecdhKeyPair.privateKey, deviceKey.publicKey);
|
|
30
|
+
const keyHash = CryptoService.createKeyHash(sharedSecret);
|
|
31
|
+
// Verify the key hash matches what the device expects
|
|
32
|
+
if (keyHash !== deviceKey.keyHash) {
|
|
33
|
+
throw new Error('Key hash mismatch during device registration');
|
|
34
|
+
}
|
|
35
|
+
// Store the shared secret for this device
|
|
36
|
+
keyData.sharedSecrets[deviceKey.deviceId] = sharedSecret;
|
|
37
|
+
keyData.keyHashes[deviceKey.deviceId] = keyHash;
|
|
38
|
+
await this.storeRunnerKeys(runnerId, keyData);
|
|
39
|
+
console.log(`✓ Device ${deviceKey.deviceId} registered for runner ${runnerId}`);
|
|
40
|
+
return sharedSecret;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Remove a device from the runner
|
|
44
|
+
*/
|
|
45
|
+
static async removeDevice(runnerId, deviceId) {
|
|
46
|
+
const keyData = await this.getRunnerKeys(runnerId);
|
|
47
|
+
if (!keyData) {
|
|
48
|
+
return; // No keys to clean up
|
|
49
|
+
}
|
|
50
|
+
delete keyData.sharedSecrets[deviceId];
|
|
51
|
+
delete keyData.keyHashes[deviceId];
|
|
52
|
+
await this.storeRunnerKeys(runnerId, keyData);
|
|
53
|
+
console.log(`Device ${deviceId} removed from runner ${runnerId}`);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Get shared secret for specific device
|
|
57
|
+
*/
|
|
58
|
+
static async getSharedSecret(runnerId, deviceId) {
|
|
59
|
+
const keyData = await this.getRunnerKeys(runnerId);
|
|
60
|
+
if (!keyData) {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
// Check if keys are expired
|
|
64
|
+
const daysSinceCreation = (Date.now() - keyData.createdAt) / (1000 * 60 * 60 * 24);
|
|
65
|
+
if (daysSinceCreation > this.KEY_EXPIRY_DAYS) {
|
|
66
|
+
console.warn(`Keys for runner ${runnerId} have expired. Consider key rotation.`);
|
|
67
|
+
}
|
|
68
|
+
return keyData.sharedSecrets[deviceId] || null;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Get all registered device IDs for a runner
|
|
72
|
+
*/
|
|
73
|
+
static async getRegisteredDevices(runnerId) {
|
|
74
|
+
const keyData = await this.getRunnerKeys(runnerId);
|
|
75
|
+
if (!keyData) {
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
return Object.keys(keyData.sharedSecrets);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Encrypt command for specific device
|
|
82
|
+
*/
|
|
83
|
+
static async encryptForDevice(runnerId, deviceId, command) {
|
|
84
|
+
const sharedSecret = await this.getSharedSecret(runnerId, deviceId);
|
|
85
|
+
if (!sharedSecret) {
|
|
86
|
+
throw new Error(`No shared secret found for device ${deviceId} on runner ${runnerId}`);
|
|
87
|
+
}
|
|
88
|
+
return CryptoService.safeEncrypt(command, sharedSecret);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Encrypt command for all registered devices
|
|
92
|
+
*/
|
|
93
|
+
static async encryptForAllDevices(runnerId, command) {
|
|
94
|
+
const keyData = await this.getRunnerKeys(runnerId);
|
|
95
|
+
if (!keyData) {
|
|
96
|
+
throw new Error(`No keys found for runner ${runnerId}`);
|
|
97
|
+
}
|
|
98
|
+
const encryptedCommands = {};
|
|
99
|
+
for (const [deviceId, sharedSecret] of Object.entries(keyData.sharedSecrets)) {
|
|
100
|
+
try {
|
|
101
|
+
encryptedCommands[deviceId] = CryptoService.safeEncrypt(command, sharedSecret);
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
console.warn(`Failed to encrypt command for device ${deviceId}: ${error}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
if (Object.keys(encryptedCommands).length === 0) {
|
|
108
|
+
throw new Error(`No devices registered for runner ${runnerId}`);
|
|
109
|
+
}
|
|
110
|
+
return encryptedCommands;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Decrypt command from specific device
|
|
114
|
+
*/
|
|
115
|
+
static async decryptFromDevice(runnerId, deviceId, encryptedCommand) {
|
|
116
|
+
const sharedSecret = await this.getSharedSecret(runnerId, deviceId);
|
|
117
|
+
if (!sharedSecret) {
|
|
118
|
+
throw new Error(`No shared secret found for device ${deviceId} on runner ${runnerId}`);
|
|
119
|
+
}
|
|
120
|
+
return CryptoService.safeDecrypt(encryptedCommand, sharedSecret);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Check if runner has any registered devices
|
|
124
|
+
*/
|
|
125
|
+
static async hasRegisteredDevices(runnerId) {
|
|
126
|
+
const devices = await this.getRegisteredDevices(runnerId);
|
|
127
|
+
return devices.length > 0;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Clean up all keys for a runner
|
|
131
|
+
*/
|
|
132
|
+
static async removeRunnerKeys(runnerId) {
|
|
133
|
+
const allKeys = await this.getAllStoredKeys();
|
|
134
|
+
delete allKeys[runnerId];
|
|
135
|
+
await StorageService.set(this.KEYS_STORAGE_KEY, allKeys);
|
|
136
|
+
console.log(`Cleaned up all keys for runner ${runnerId}`);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Get CLI's public key for a runner
|
|
140
|
+
*/
|
|
141
|
+
static async getCliPublicKey(runnerId) {
|
|
142
|
+
const keyData = await this.getRunnerKeys(runnerId);
|
|
143
|
+
return keyData?.ecdhKeyPair.publicKey || null;
|
|
144
|
+
}
|
|
145
|
+
// Private helper methods
|
|
146
|
+
static async getRunnerKeys(runnerId) {
|
|
147
|
+
const allKeys = await this.getAllStoredKeys();
|
|
148
|
+
return allKeys[runnerId] || null;
|
|
149
|
+
}
|
|
150
|
+
static async storeRunnerKeys(runnerId, keys) {
|
|
151
|
+
const allKeys = await this.getAllStoredKeys();
|
|
152
|
+
allKeys[runnerId] = keys;
|
|
153
|
+
await StorageService.set(this.KEYS_STORAGE_KEY, allKeys);
|
|
154
|
+
}
|
|
155
|
+
static async getAllStoredKeys() {
|
|
156
|
+
return (await StorageService.get(this.KEYS_STORAGE_KEY)) ?? {};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=multi-device-key-manager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multi-device-key-manager.js","sourceRoot":"","sources":["../../src/services/multi-device-key-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAC,cAAc,EAAC,MAAM,qBAAqB,CAAC;AAUnD,MAAM,OAAO,4BAA4B;IAC7B,MAAM,CAAU,gBAAgB,GAAG,8BAA8B,CAAC;IAClE,MAAM,CAAU,eAAe,GAAG,EAAE,CAAC;IAE7C;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,QAAgB;QAC9C,MAAM,WAAW,GAAG,aAAa,CAAC,mBAAmB,EAAE,CAAC;QAExD,MAAM,OAAO,GAAkB;YAC3B,WAAW;YACX,aAAa,EAAE,EAAE;YACjB,SAAS,EAAE,EAAE;YACb,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;SACxB,CAAC;QAEF,MAAM,IAAI,CAAC,eAAe,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC9C,OAAO,WAAW,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,QAAgB,EAAE,SAAoB;QAC9D,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACnD,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,4BAA4B,QAAQ,EAAE,C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AM,CAAC,KAAK,CAAC,gBAAgB;QACjC,OAAO,CAAC,MAAM,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC,IAAI,EAAE,CAAC;IACnE,CAAC"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateMessageRequest } from './api.js';
|
|
2
|
+
import { type CreateRunnerData, type Runner } from '../types/runner.js';
|
|
2
3
|
export declare class RunnerService {
|
|
3
4
|
private static readonly RUNNERS_COLLECTION;
|
|
4
|
-
private static readonly MESSAGES_COLLECTION;
|
|
5
5
|
static getAllRunners(): Promise<Runner[]>;
|
|
6
6
|
static createRunner(data: CreateRunnerData): Promise<Runner>;
|
|
7
7
|
static deleteRunner(runnerId: string): Promise<void>;
|
|
8
8
|
static clearPendingCommand(runnerId: string): Promise<void>;
|
|
9
9
|
static updateRunnerAfterCommand(runnerId: string, result: string): Promise<void>;
|
|
10
|
-
static createMessage(data:
|
|
10
|
+
static createMessage(runnerId: string, data: CreateMessageRequest): Promise<void>;
|
|
11
11
|
static listenToRunner(runnerId: string, callback: (runner: Runner | null) => void): () => void;
|
|
12
12
|
private static docToRunner;
|
|
13
13
|
private static parseRunnerType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/services/runner.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/services/runner.ts"],"names":[],"mappings":"AAGA,OAAO,EAAa,oBAAoB,EAAC,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAC,KAAK,gBAAgB,EAAE,KAAK,MAAM,EAAa,MAAM,oBAAoB,CAAC;AAKlF,qBAAa,aAAa;IACtB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAAa;WAE1C,aAAa,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;WAkBlC,YAAY,CAAC,IAAI,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC;WAmDrD,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAK7C,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAMpD,wBAAwB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;WAQzE,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IAavF,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,GAAG,MAAM,IAAI;IAa9F,OAAO,CAAC,MAAM,CAAC,WAAW;IAgB1B,OAAO,CAAC,MAAM,CAAC,eAAe;CAWjC"}
|
package/dist/services/runner.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { collection, doc, getDocs, onSnapshot, orderBy, query, where, } from 'firebase/firestore';
|
|
2
2
|
import { db } from '../config/firebase.js';
|
|
3
3
|
import { AuthService } from './auth.js';
|
|
4
4
|
import { ApiService } from './api.js';
|
|
5
5
|
import { RunnerType } from '../types/runner.js';
|
|
6
6
|
import { generateDeviceId, getDeviceDisplayName } from '../utils/device.js';
|
|
7
|
+
import { EncryptionService } from '../utils/encryption.js';
|
|
8
|
+
import { loadAuth, saveAuth } from '../utils/storage.js';
|
|
7
9
|
export class RunnerService {
|
|
8
10
|
static RUNNERS_COLLECTION = 'runners';
|
|
9
|
-
static MESSAGES_COLLECTION = 'messages';
|
|
10
11
|
static async getAllRunners() {
|
|
11
12
|
const userId = AuthService.userId;
|
|
12
13
|
const deviceId = generateDeviceId();
|
|
@@ -24,12 +25,28 @@ export class RunnerService {
|
|
|
24
25
|
}
|
|
25
26
|
const deviceId = generateDeviceId();
|
|
26
27
|
const deviceName = getDeviceDisplayName();
|
|
27
|
-
//
|
|
28
|
+
// Generate or load encryption code
|
|
29
|
+
let encryptionCode;
|
|
30
|
+
const storedAuth = await loadAuth();
|
|
31
|
+
if (storedAuth?.encryptionCode) {
|
|
32
|
+
encryptionCode = storedAuth.encryptionCode;
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
// Generate new random encryption code
|
|
36
|
+
encryptionCode = EncryptionService.generateRandomSecret();
|
|
37
|
+
// Save to storage
|
|
38
|
+
const updatedAuth = { ...storedAuth, encryptionCode };
|
|
39
|
+
await saveAuth(updatedAuth);
|
|
40
|
+
}
|
|
41
|
+
// Create verification string
|
|
42
|
+
const encryptionVerification = EncryptionService.createVerificationString(encryptionCode);
|
|
43
|
+
// Create runner via API with encryption verification
|
|
28
44
|
const response = await ApiService.createRunner({
|
|
29
45
|
name: data.name,
|
|
30
46
|
directory: data.directory,
|
|
31
47
|
machineId: deviceId,
|
|
32
|
-
machineName: deviceName
|
|
48
|
+
machineName: deviceName,
|
|
49
|
+
encryptionVerification
|
|
33
50
|
});
|
|
34
51
|
const runnerId = response.id;
|
|
35
52
|
return {
|
|
@@ -59,34 +76,15 @@ export class RunnerService {
|
|
|
59
76
|
lastMessage: result ?? ''
|
|
60
77
|
});
|
|
61
78
|
}
|
|
62
|
-
static async createMessage(data) {
|
|
79
|
+
static async createMessage(runnerId, data) {
|
|
63
80
|
const userId = AuthService.userId;
|
|
64
81
|
if (!userId) {
|
|
65
82
|
throw new Error('User not authenticated');
|
|
66
83
|
}
|
|
67
|
-
if (!
|
|
84
|
+
if (!runnerId) {
|
|
68
85
|
throw new Error('Runner ID is required to create a message');
|
|
69
86
|
}
|
|
70
|
-
|
|
71
|
-
content: data.content ?? '',
|
|
72
|
-
senderName: data.senderName ?? '',
|
|
73
|
-
type: data.type,
|
|
74
|
-
userId,
|
|
75
|
-
timestamp: serverTimestamp()
|
|
76
|
-
};
|
|
77
|
-
// Store message in the runner's messages subcollection
|
|
78
|
-
const runnerDocRef = doc(db, this.RUNNERS_COLLECTION, data.runnerId);
|
|
79
|
-
const messagesCollectionRef = collection(runnerDocRef, this.MESSAGES_COLLECTION);
|
|
80
|
-
const docRef = await addDoc(messagesCollectionRef, messageData);
|
|
81
|
-
return {
|
|
82
|
-
id: docRef.id,
|
|
83
|
-
content: data.content,
|
|
84
|
-
senderName: data.senderName,
|
|
85
|
-
type: data.type,
|
|
86
|
-
userId,
|
|
87
|
-
timestamp: new Date(),
|
|
88
|
-
runnerId: data.runnerId
|
|
89
|
-
};
|
|
87
|
+
await ApiService.createRunnerMessage(runnerId, data);
|
|
90
88
|
}
|
|
91
89
|
static listenToRunner(runnerId, callback) {
|
|
92
90
|
const runnerDoc = doc(db, this.RUNNERS_COLLECTION, runnerId);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/services/runner.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/services/runner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,GAAE,MAAM,oBAAoB,CAAC;AAChG,OAAO,EAAC,EAAE,EAAC,MAAM,uBAAuB,CAAC;AACzC,OAAO,EAAC,WAAW,EAAC,MAAM,WAAW,CAAC;AACtC,OAAO,EAAC,UAAU,EAAuB,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAqC,UAAU,EAAC,MAAM,oBAAoB,CAAC;AAClF,OAAO,EAAC,gBAAgB,EAAE,oBAAoB,EAAC,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAC,iBAAiB,EAAC,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAC,MAAM,qBAAqB,CAAC;AAEvD,MAAM,OAAO,aAAa;IACd,MAAM,CAAU,kBAAkB,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AAE;YACzB,UAAU,EAAE,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC;YACjD,SAAS,EAAE,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,IAAI;YAC3C,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,IAAI;YACzC,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,SAAS;YAC1C,WAAW,EAAE,IAAI,CAAC,WAAW,IAAI,SAAS;YAC1C,SAAS,EAAE,IAAI,CAAC,SAAS,IAAI,SAAS;YACtC,cAAc,EAAE,IAAI,CAAC,cAAc,IAAI,SAAS;SACnD,CAAC;IACN,CAAC;IAEO,MAAM,CAAC,eAAe,CAAC,IAAY;QACvC,QAAQ,IAAI,EAAE,CAAC;YACX,KAAK,OAAO;gBACR,OAAO,UAAU,CAAC,KAAK,CAAC;YAC5B,KAAK,QAAQ;gBACT,OAAO,UAAU,CAAC,MAAM,CAAC;YAC7B,KAAK,QAAQ,CAAC;YACd;gBACI,OAAO,UAAU,CAAC,MAAM,CAAC;QACjC,CAAC;IACL,CAAC"}
|
package/dist/types/runner.d.ts
CHANGED
|
@@ -30,12 +30,6 @@ export interface Message {
|
|
|
30
30
|
userId: string;
|
|
31
31
|
runnerId?: string;
|
|
32
32
|
}
|
|
33
|
-
export interface CreateMessageData {
|
|
34
|
-
content: string;
|
|
35
|
-
senderName: string;
|
|
36
|
-
type: 'user' | 'runner' | 'error';
|
|
37
|
-
runnerId: string;
|
|
38
|
-
}
|
|
39
33
|
export interface User {
|
|
40
34
|
id: string;
|
|
41
35
|
email: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/types/runner.ts"],"names":[],"mappings":"AAAA,oBAAY,UAAU;IAClB,MAAM,WAAW;IACjB,KAAK,UAAU;IACf,MAAM,WAAW;CACpB;AAED,MAAM,WAAW,MAAM;IACnB,EAAE,EAAE,MAAM,CAAC;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AE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,gBAAgB;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,UAAU,CAAC;CAC1B;AAED,MAAM,WAAW,OAAO;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,IAAI,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,OAAO,CAAC;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,IAAI;IACjB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,gBAAgB,EAAE,MAAM,CAAC;IACzB,SAAS,EAAE,IAAI,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAC;CACzB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export interface EncryptionResult {
|
|
2
|
+
encrypted: string;
|
|
3
|
+
success: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface DecryptionResult {
|
|
6
|
+
decrypted: string;
|
|
7
|
+
success: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class EncryptionService {
|
|
10
|
+
/**
|
|
11
|
+
* Generate a random shared secret
|
|
12
|
+
* This ensures the backend never knows the encryption key
|
|
13
|
+
*/
|
|
14
|
+
static generateRandomSecret(): string;
|
|
15
|
+
/**
|
|
16
|
+
* Simple XOR-based encryption compatible with Dart implementation
|
|
17
|
+
*/
|
|
18
|
+
static encrypt(data: string, secret: string): EncryptionResult;
|
|
19
|
+
/**
|
|
20
|
+
* Simple XOR-based decryption
|
|
21
|
+
*/
|
|
22
|
+
static decrypt(encryptedData: string, secret: string): DecryptionResult;
|
|
23
|
+
/**
|
|
24
|
+
* Create verification string encrypted with the secret
|
|
25
|
+
* This can be stored on the runner to verify the correct secret
|
|
26
|
+
*/
|
|
27
|
+
static createVerificationString(secret: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* Verify if a secret is correct by trying to decrypt the verification string
|
|
30
|
+
*/
|
|
31
|
+
static verifySecret(encryptedVerification: string, secret: string): boolean;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=encryption.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.d.ts","sourceRoot":"","sources":["../../src/utils/encryption.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,gBAAgB;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,gBAAgB;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;CACpB;AAED,qBAAa,iBAAiB;IAC1B;;;OAGG;IACH,MAAM,CAAC,oBAAoB,IAAI,MAAM;IAMrC;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,gBAAgB;IAqB9D;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,gBAAgB;IAsBvE;;;OAGG;IACH,MAAM,CAAC,wBAAwB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAMvD;;OAEG;IACH,MAAM,CAAC,YAAY,CAAC,qBAAqB,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO;CAI9E"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { createHash, randomBytes } from 'crypto';
|
|
2
|
+
export class EncryptionService {
|
|
3
|
+
/**
|
|
4
|
+
* Generate a random shared secret
|
|
5
|
+
* This ensures the backend never knows the encryption key
|
|
6
|
+
*/
|
|
7
|
+
static generateRandomSecret() {
|
|
8
|
+
// Generate 8 random bytes and convert to hex for a 16-character string
|
|
9
|
+
const randomBuffer = randomBytes(8);
|
|
10
|
+
return randomBuffer.toString('hex').toUpperCase();
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Simple XOR-based encryption compatible with Dart implementation
|
|
14
|
+
*/
|
|
15
|
+
static encrypt(data, secret) {
|
|
16
|
+
try {
|
|
17
|
+
// Use a hash of the secret to create consistent encryption
|
|
18
|
+
const secretHash = createHash('sha256').update(secret).digest('hex');
|
|
19
|
+
const keyBytes = Buffer.from(secretHash.substring(0, 32), 'utf8');
|
|
20
|
+
const dataBytes = Buffer.from(data, 'utf8');
|
|
21
|
+
const encrypted = Buffer.alloc(dataBytes.length);
|
|
22
|
+
for (let i = 0; i < dataBytes.length; i++) {
|
|
23
|
+
encrypted[i] = dataBytes[i] ^ keyBytes[i % keyBytes.length];
|
|
24
|
+
}
|
|
25
|
+
// Convert to hex string
|
|
26
|
+
const result = encrypted.toString('hex');
|
|
27
|
+
return { encrypted: result, success: true };
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
return { encrypted: '', success: false };
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Simple XOR-based decryption
|
|
35
|
+
*/
|
|
36
|
+
static decrypt(encryptedData, secret) {
|
|
37
|
+
try {
|
|
38
|
+
// Use a hash of the secret to create consistent decryption key
|
|
39
|
+
const secretHash = createHash('sha256').update(secret).digest('hex');
|
|
40
|
+
const keyBytes = Buffer.from(secretHash.substring(0, 32), 'utf8');
|
|
41
|
+
// Convert hex string back to bytes
|
|
42
|
+
const encrypted = Buffer.from(encryptedData, 'hex');
|
|
43
|
+
const decrypted = Buffer.alloc(encrypted.length);
|
|
44
|
+
for (let i = 0; i < encrypted.length; i++) {
|
|
45
|
+
decrypted[i] = encrypted[i] ^ keyBytes[i % keyBytes.length];
|
|
46
|
+
}
|
|
47
|
+
const result = decrypted.toString('utf8');
|
|
48
|
+
return { decrypted: result, success: true };
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
return { decrypted: '', success: false };
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Create verification string encrypted with the secret
|
|
56
|
+
* This can be stored on the runner to verify the correct secret
|
|
57
|
+
*/
|
|
58
|
+
static createVerificationString(secret) {
|
|
59
|
+
const verificationText = 'salamander_verification_success';
|
|
60
|
+
const result = this.encrypt(verificationText, secret);
|
|
61
|
+
return result.encrypted;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Verify if a secret is correct by trying to decrypt the verification string
|
|
65
|
+
*/
|
|
66
|
+
static verifySecret(encryptedVerification, secret) {
|
|
67
|
+
const result = this.decrypt(encryptedVerification, secret);
|
|
68
|
+
return result.success && result.decrypted === 'salamander_verification_success';
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=encryption.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"encryption.js","sourceRoot":"","sources":["../../src/utils/encryption.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,WAAW,EAAC,MAAM,QAAQ,CAAC;AAY/C,MAAM,OAAO,iBAAiB;IAC1B;;;OAGG;IACH,MAAM,CAAC,oBAAoB;QACvB,uEAAuE;QACvE,MAAM,YAAY,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC;QACpC,OAAO,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;IACtD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,OAAO,CAAC,IAAY,EAAE,MAAc;QACvC,IAAI,CAAC;YACD,2DAA2D;YAC3D,MAAM,UAAU,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACrE,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CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/utils/storage.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,UAAU;IACvB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,cAAc,CAAC,EAAE,MAAM,CAAC;CAC3B;AAWD,wBAAsB,QAAQ,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC,CAG9D;AAED,wBAAsB,QAAQ,IAAI,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAO3D;AAED,wBAAsB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAM/C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/utils/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,IAAI,EAAE,EAAC,MAAM,IAAI,CAAC;AAClC,OAAO,EAAC,IAAI,EAAC,MAAM,MAAM,CAAC;AAC1B,OAAO,EAAC,OAAO,EAAC,MAAM,IAAI,CAAC;AAE3B,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,EAAE,EAAE,aAAa,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../src/utils/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,IAAI,EAAE,EAAC,MAAM,IAAI,CAAC;AAClC,OAAO,EAAC,IAAI,EAAC,MAAM,MAAM,CAAC;AAC1B,OAAO,EAAC,OAAO,EAAC,M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