@quantiya/codevibe-claude-plugin 1.0.10 → 1.0.12
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/.claude-plugin/plugin.json +1 -1
- package/README.md +75 -245
- package/dist/server.js +16 -1162
- package/node_modules/@quantiya/codevibe-core/README.md +15 -6
- package/node_modules/@quantiya/codevibe-core/bin/codevibe.js +1 -1
- package/node_modules/@quantiya/codevibe-core/dist/index.js +216 -67
- package/node_modules/@quantiya/codevibe-core/package.json +12 -9
- package/node_modules/node-abi/abi_registry.json +7 -0
- package/node_modules/node-abi/package.json +1 -1
- package/package.json +11 -21
- package/dist/appsync-client.d.ts +0 -67
- package/dist/appsync-client.d.ts.map +0 -1
- package/dist/appsync-client.js +0 -858
- package/dist/appsync-client.js.map +0 -1
- package/dist/auth-cli.d.ts +0 -18
- package/dist/auth-cli.d.ts.map +0 -1
- package/dist/auth-cli.js +0 -472
- package/dist/auth-cli.js.map +0 -1
- package/dist/command-executor.d.ts +0 -20
- package/dist/command-executor.d.ts.map +0 -1
- package/dist/command-executor.js +0 -127
- package/dist/command-executor.js.map +0 -1
- package/dist/config.d.ts +0 -25
- package/dist/config.d.ts.map +0 -1
- package/dist/config.js +0 -106
- package/dist/config.js.map +0 -1
- package/dist/crypto-service.d.ts +0 -115
- package/dist/crypto-service.d.ts.map +0 -1
- package/dist/crypto-service.js +0 -278
- package/dist/crypto-service.js.map +0 -1
- package/dist/http-api.d.ts +0 -35
- package/dist/http-api.d.ts.map +0 -1
- package/dist/http-api.js +0 -334
- package/dist/http-api.js.map +0 -1
- package/dist/key-manager.d.ts +0 -87
- package/dist/key-manager.d.ts.map +0 -1
- package/dist/key-manager.js +0 -287
- package/dist/key-manager.js.map +0 -1
- package/dist/logger.d.ts +0 -2
- package/dist/logger.d.ts.map +0 -1
- package/dist/logger.js +0 -18
- package/dist/logger.js.map +0 -1
- package/dist/prompt-responder.d.ts +0 -22
- package/dist/prompt-responder.d.ts.map +0 -1
- package/dist/prompt-responder.js +0 -132
- package/dist/prompt-responder.js.map +0 -1
- package/dist/server.d.ts +0 -9
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js.map +0 -1
- package/dist/token-storage.d.ts +0 -39
- package/dist/token-storage.d.ts.map +0 -1
- package/dist/token-storage.js +0 -169
- package/dist/token-storage.js.map +0 -1
- package/dist/types.d.ts +0 -110
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -17
- package/dist/types.js.map +0 -1
- package/node_modules/@quantiya/codevibe-core/dist/appsync/appsync-client.js +0 -576
- package/node_modules/@quantiya/codevibe-core/dist/appsync/index.js +0 -10
- package/node_modules/@quantiya/codevibe-core/dist/appsync/queries.js +0 -189
- package/node_modules/@quantiya/codevibe-core/dist/auth/auth-cli.js +0 -217
- package/node_modules/@quantiya/codevibe-core/dist/auth/auth-service.js +0 -464
- package/node_modules/@quantiya/codevibe-core/dist/auth/fetch-helpers.js +0 -165
- package/node_modules/@quantiya/codevibe-core/dist/auth/index.js +0 -9
- package/node_modules/@quantiya/codevibe-core/dist/config/config.js +0 -123
- package/node_modules/@quantiya/codevibe-core/dist/config/index.js +0 -8
- package/node_modules/@quantiya/codevibe-core/dist/crypto/crypto-service.js +0 -284
- package/node_modules/@quantiya/codevibe-core/dist/crypto/index.js +0 -9
- package/node_modules/@quantiya/codevibe-core/dist/keychain/index.js +0 -8
- package/node_modules/@quantiya/codevibe-core/dist/keychain/keychain-manager.js +0 -375
- package/node_modules/@quantiya/codevibe-core/dist/logger/index.js +0 -8
- package/node_modules/@quantiya/codevibe-core/dist/logger/logger.js +0 -142
- package/node_modules/@quantiya/codevibe-core/dist/prompt-parser.js +0 -236
- package/node_modules/@quantiya/codevibe-core/dist/session/index.js +0 -7
- package/node_modules/@quantiya/codevibe-core/dist/session/session-resume.js +0 -151
- package/node_modules/@quantiya/codevibe-core/dist/types/auth.js +0 -3
- package/node_modules/@quantiya/codevibe-core/dist/types/encryption.js +0 -3
- package/node_modules/@quantiya/codevibe-core/dist/types/events.js +0 -28
- package/node_modules/@quantiya/codevibe-core/dist/types/index.js +0 -22
- package/node_modules/@quantiya/codevibe-core/dist/types/session.js +0 -22
package/dist/command-executor.js
DELETED
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CommandExecutor = void 0;
|
|
4
|
-
const child_process_1 = require("child_process");
|
|
5
|
-
const codevibe_core_1 = require("@quantiya/codevibe-core");
|
|
6
|
-
const logger_1 = require("./logger");
|
|
7
|
-
class CommandExecutor {
|
|
8
|
-
/**
|
|
9
|
-
* Execute a prompt in a specific Claude Code session
|
|
10
|
-
* @param sessionId The session ID to execute the prompt in
|
|
11
|
-
* @param prompt The prompt text to execute
|
|
12
|
-
* @returns Result of the command execution
|
|
13
|
-
*/
|
|
14
|
-
async executePrompt(sessionId, prompt) {
|
|
15
|
-
const config = (0, codevibe_core_1.getConfig)();
|
|
16
|
-
const timeout = config.claude.defaultTimeout;
|
|
17
|
-
logger_1.logger.info('Executing prompt from mobile', {
|
|
18
|
-
sessionId,
|
|
19
|
-
promptLength: prompt.length,
|
|
20
|
-
timeout,
|
|
21
|
-
});
|
|
22
|
-
return new Promise((resolve) => {
|
|
23
|
-
const args = [
|
|
24
|
-
'--resume', sessionId,
|
|
25
|
-
'--print',
|
|
26
|
-
'--output-format', 'stream-json',
|
|
27
|
-
prompt
|
|
28
|
-
];
|
|
29
|
-
logger_1.logger.debug('Spawning Claude command', {
|
|
30
|
-
command: config.claude.command,
|
|
31
|
-
args,
|
|
32
|
-
});
|
|
33
|
-
const child = (0, child_process_1.spawn)(config.claude.command, args, {
|
|
34
|
-
stdio: ['pipe', 'pipe', 'pipe'],
|
|
35
|
-
shell: true,
|
|
36
|
-
});
|
|
37
|
-
let stdout = '';
|
|
38
|
-
let stderr = '';
|
|
39
|
-
let timedOut = false;
|
|
40
|
-
// Set timeout
|
|
41
|
-
const timer = setTimeout(() => {
|
|
42
|
-
timedOut = true;
|
|
43
|
-
logger_1.logger.warn('Command execution timed out', { sessionId, timeout });
|
|
44
|
-
child.kill('SIGTERM');
|
|
45
|
-
}, timeout);
|
|
46
|
-
// Capture stdout
|
|
47
|
-
child.stdout?.on('data', (data) => {
|
|
48
|
-
const output = data.toString();
|
|
49
|
-
stdout += output;
|
|
50
|
-
logger_1.logger.debug('Command stdout', { output: output.slice(0, 200) });
|
|
51
|
-
});
|
|
52
|
-
// Capture stderr
|
|
53
|
-
child.stderr?.on('data', (data) => {
|
|
54
|
-
const output = data.toString();
|
|
55
|
-
stderr += output;
|
|
56
|
-
logger_1.logger.debug('Command stderr', { output: output.slice(0, 200) });
|
|
57
|
-
});
|
|
58
|
-
// Handle process exit
|
|
59
|
-
child.on('close', (code) => {
|
|
60
|
-
clearTimeout(timer);
|
|
61
|
-
const result = {
|
|
62
|
-
success: code === 0 && !timedOut,
|
|
63
|
-
output: stdout,
|
|
64
|
-
error: stderr,
|
|
65
|
-
exitCode: code || undefined,
|
|
66
|
-
timedOut,
|
|
67
|
-
};
|
|
68
|
-
if (result.success) {
|
|
69
|
-
logger_1.logger.info('Command executed successfully', {
|
|
70
|
-
sessionId,
|
|
71
|
-
exitCode: code,
|
|
72
|
-
outputLength: stdout.length,
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
logger_1.logger.error('Command execution failed', {
|
|
77
|
-
sessionId,
|
|
78
|
-
exitCode: code,
|
|
79
|
-
timedOut,
|
|
80
|
-
error: stderr.slice(0, 500),
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
resolve(result);
|
|
84
|
-
});
|
|
85
|
-
// Handle errors
|
|
86
|
-
child.on('error', (error) => {
|
|
87
|
-
clearTimeout(timer);
|
|
88
|
-
logger_1.logger.error('Failed to spawn command', { error: error.message });
|
|
89
|
-
resolve({
|
|
90
|
-
success: false,
|
|
91
|
-
error: error.message,
|
|
92
|
-
timedOut: false,
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
/**
|
|
98
|
-
* Check if interactive prompt is present in output
|
|
99
|
-
* This is a simple heuristic - looks for common prompt patterns
|
|
100
|
-
*/
|
|
101
|
-
detectInteractivePrompt(output) {
|
|
102
|
-
const patterns = [
|
|
103
|
-
/\[Y\/n\]/i,
|
|
104
|
-
/\[y\/N\]/i,
|
|
105
|
-
/\(y\/n\)/i,
|
|
106
|
-
/Continue\?/i,
|
|
107
|
-
/Proceed\?/i,
|
|
108
|
-
];
|
|
109
|
-
return patterns.some(pattern => pattern.test(output));
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Extract interactive prompt text from output
|
|
113
|
-
*/
|
|
114
|
-
extractPromptText(output) {
|
|
115
|
-
// Look for lines that end with prompt patterns
|
|
116
|
-
const lines = output.split('\n');
|
|
117
|
-
for (let i = lines.length - 1; i >= 0; i--) {
|
|
118
|
-
const line = lines[i].trim();
|
|
119
|
-
if (this.detectInteractivePrompt(line)) {
|
|
120
|
-
return line;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
exports.CommandExecutor = CommandExecutor;
|
|
127
|
-
//# sourceMappingURL=command-executor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"command-executor.js","sourceRoot":"","sources":["../src/command-executor.ts"],"names":[],"mappings":";;;AAAA,iDAAsC;AACtC,2DAAoD;AACpD,qCAAkC;AAGlC,MAAa,eAAe;IAC1B;;;;;OAKG;IACI,KAAK,CAAC,aAAa,CAAC,SAAiB,EAAE,MAAc;QAC1D,MAAM,MAAM,GAAG,IAAA,yBAAS,GAAE,CAAC;QAC3B,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC;QAE7C,eAAM,CAAC,IAAI,CAAC,8BAA8B,EAAE;YAC1C,SAAS;YACT,YAAY,EAAE,MA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AAC,KAAK,CAAC,CAAC;gBACpB,eAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;gBAElE,OAAO,CAAC;oBACN,OAAO,EAAE,KAAK;oBACd,KAAK,EAAE,KAAK,CAAC,OAAO;oBACpB,QAAQ,EAAE,KAAK;iBAChB,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;;OAGG;IACI,uBAAuB,CAAC,MAAc;QAC3C,MAAM,QAAQ,GAAG;YACf,WAAW;YACX,WAAW;YACX,WAAW;YACX,aAAa;YACb,YAAY;SACb,CAAC;QAEF,OAAO,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;IACxD,CAAC;IAED;;OAEG;IACI,iBAAiB,CAAC,MAAc;QACrC,+CAA+C;QAC/C,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACjC,KAAK,IAAI,CAAC,GAAG,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAC3C,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;YAC7B,IAAI,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC,EAAE,CAAC;gBACvC,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAtID,0CAsIC"}
|
package/dist/config.d.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
export interface Config {
|
|
2
|
-
server: {
|
|
3
|
-
port: number;
|
|
4
|
-
host: string;
|
|
5
|
-
dynamicPort: boolean;
|
|
6
|
-
};
|
|
7
|
-
aws: {
|
|
8
|
-
region: string;
|
|
9
|
-
appsyncUrl: string;
|
|
10
|
-
cognitoUserPoolId: string;
|
|
11
|
-
cognitoClientId: string;
|
|
12
|
-
cognitoDomain: string;
|
|
13
|
-
};
|
|
14
|
-
claude: {
|
|
15
|
-
command: string;
|
|
16
|
-
defaultTimeout: number;
|
|
17
|
-
};
|
|
18
|
-
logging: {
|
|
19
|
-
logFile: string;
|
|
20
|
-
level: 'debug' | 'info' | 'warn' | 'error';
|
|
21
|
-
};
|
|
22
|
-
}
|
|
23
|
-
export declare const config: Config;
|
|
24
|
-
export declare function validateConfig(): void;
|
|
25
|
-
//# sourceMappingURL=config.d.ts.map
|
package/dist/config.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAqBA,MAAM,WAAW,MAAM;IACrB,MAAM,EAAE;QACN,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,WAAW,EAAE,OAAO,CAAC;KACtB,CAAC;IACF,GAAG,EAAE;QACH,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,eAAe,EAAE,MAAM,CAAC;QACxB,aAAa,EAAE,MAAM,CAAC;KACvB,CAAC;IACF,MAAM,EAAE;QACN,OAAO,EAAE,MAAM,CAAC;QAChB,cAAc,EAAE,MAAM,CAAC;KACxB,CAAC;IACF,OAAO,EAAE;QACP,OAAO,EAAE,MAAM,CAAC;QAChB,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;KAC5C,CAAC;CACH;AAgBD,eAAO,MAAM,MAAM,EAAE,MAqBpB,CAAC;AAGF,wBAAgB,cAAc,IAAI,IAAI,CAmBrC"}
|
package/dist/config.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.config = void 0;
|
|
37
|
-
exports.validateConfig = validateConfig;
|
|
38
|
-
const dotenv = __importStar(require("dotenv"));
|
|
39
|
-
const path = __importStar(require("path"));
|
|
40
|
-
// Determine environment
|
|
41
|
-
// - If ENVIRONMENT is explicitly set, use that
|
|
42
|
-
// - Otherwise default to 'production' for marketplace users (no .env files)
|
|
43
|
-
const environment = process.env.ENVIRONMENT || 'production';
|
|
44
|
-
// Only load .env files if ENVIRONMENT is explicitly set (for development)
|
|
45
|
-
// This ensures marketplace users get production defaults without needing .env files
|
|
46
|
-
if (process.env.ENVIRONMENT) {
|
|
47
|
-
const envFile = `.env.${environment}`;
|
|
48
|
-
const envPath = path.resolve(__dirname, '..', envFile);
|
|
49
|
-
dotenv.config({ path: envPath, debug: false });
|
|
50
|
-
// Fallback to default .env if environment-specific file didn't load required vars
|
|
51
|
-
if (!process.env.APPSYNC_URL) {
|
|
52
|
-
dotenv.config({ debug: false });
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
function getOptionalEnv(key, defaultValue) {
|
|
56
|
-
return process.env[key] || defaultValue;
|
|
57
|
-
}
|
|
58
|
-
// Production defaults - these are public values (not secrets)
|
|
59
|
-
// Users can override via .env files for development
|
|
60
|
-
const PRODUCTION_DEFAULTS = {
|
|
61
|
-
APPSYNC_URL: 'https://jwhyxq4sgrgcdosewp5k4ns5ca.appsync-api.us-east-1.amazonaws.com/graphql',
|
|
62
|
-
COGNITO_USER_POOL_ID: 'us-east-1_mNRO0j5og',
|
|
63
|
-
COGNITO_CLIENT_ID: '5p04dbc9ojptc5r8n7605fg78f',
|
|
64
|
-
COGNITO_DOMAIN: 'codevibe-production.auth.us-east-1.amazoncognito.com',
|
|
65
|
-
};
|
|
66
|
-
// Configuration object
|
|
67
|
-
exports.config = {
|
|
68
|
-
server: {
|
|
69
|
-
port: parseInt(getOptionalEnv('PORT', '3456'), 10),
|
|
70
|
-
host: getOptionalEnv('HOST', 'localhost'),
|
|
71
|
-
dynamicPort: getOptionalEnv('DYNAMIC_PORT', 'true').toLowerCase() === 'true', // Default to dynamic port
|
|
72
|
-
},
|
|
73
|
-
aws: {
|
|
74
|
-
region: getOptionalEnv('AWS_REGION', 'us-east-1'),
|
|
75
|
-
appsyncUrl: getOptionalEnv('APPSYNC_URL', PRODUCTION_DEFAULTS.APPSYNC_URL),
|
|
76
|
-
cognitoUserPoolId: getOptionalEnv('COGNITO_USER_POOL_ID', PRODUCTION_DEFAULTS.COGNITO_USER_POOL_ID),
|
|
77
|
-
cognitoClientId: getOptionalEnv('COGNITO_CLIENT_ID', PRODUCTION_DEFAULTS.COGNITO_CLIENT_ID),
|
|
78
|
-
cognitoDomain: getOptionalEnv('COGNITO_DOMAIN', PRODUCTION_DEFAULTS.COGNITO_DOMAIN),
|
|
79
|
-
},
|
|
80
|
-
claude: {
|
|
81
|
-
command: getOptionalEnv('CLAUDE_COMMAND', 'claude'),
|
|
82
|
-
defaultTimeout: parseInt(getOptionalEnv('CLAUDE_TIMEOUT', '60000'), 10),
|
|
83
|
-
},
|
|
84
|
-
logging: {
|
|
85
|
-
logFile: getOptionalEnv('LOG_FILE', '/tmp/codevibe-claude-mcp.log'),
|
|
86
|
-
level: getOptionalEnv('LOG_LEVEL', 'info'),
|
|
87
|
-
},
|
|
88
|
-
};
|
|
89
|
-
// Validate configuration
|
|
90
|
-
function validateConfig() {
|
|
91
|
-
const errors = [];
|
|
92
|
-
// Only validate port if not using dynamic allocation
|
|
93
|
-
if (!exports.config.server.dynamicPort && (exports.config.server.port < 1024 || exports.config.server.port > 65535)) {
|
|
94
|
-
errors.push('PORT must be between 1024 and 65535');
|
|
95
|
-
}
|
|
96
|
-
if (!exports.config.aws.appsyncUrl.startsWith('https://')) {
|
|
97
|
-
errors.push('APPSYNC_URL must start with https://');
|
|
98
|
-
}
|
|
99
|
-
if (exports.config.claude.defaultTimeout < 1000) {
|
|
100
|
-
errors.push('CLAUDE_TIMEOUT must be at least 1000ms');
|
|
101
|
-
}
|
|
102
|
-
if (errors.length > 0) {
|
|
103
|
-
throw new Error(`Configuration validation failed:\n${errors.join('\n')}`);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
//# sourceMappingURL=config.js.map
|
package/dist/config.js.map
DELETED
|
@@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AC,EAAE,CAAC;QAClD,MAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;IACtD,CAAC;IAED,IAAI,cAAM,CAAC,MAAM,CAAC,cAAc,GAAG,IAAI,EAAE,CAAC;QACxC,MAAM,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;IACxD,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CAAC,qCAAqC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC5E,CAAC;AACH,CAAC"}
|
package/dist/crypto-service.d.ts
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { EncryptedSessionKey } from './types';
|
|
2
|
-
export declare class CryptoError extends Error {
|
|
3
|
-
constructor(message: string);
|
|
4
|
-
}
|
|
5
|
-
export declare const ENCRYPTION_VERSION = 1;
|
|
6
|
-
/**
|
|
7
|
-
* Service for end-to-end encryption operations
|
|
8
|
-
*/
|
|
9
|
-
export declare class CryptoService {
|
|
10
|
-
private static instance;
|
|
11
|
-
private constructor();
|
|
12
|
-
static getInstance(): CryptoService;
|
|
13
|
-
/**
|
|
14
|
-
* Generate a new ECDH P-256 key pair
|
|
15
|
-
* @returns Object with privateKey (PEM), publicKey (base64 raw)
|
|
16
|
-
*/
|
|
17
|
-
generateKeyPair(): {
|
|
18
|
-
privateKey: string;
|
|
19
|
-
publicKey: string;
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Generate a random 256-bit session key
|
|
23
|
-
* @returns Base64-encoded session key
|
|
24
|
-
*/
|
|
25
|
-
generateSessionKey(): string;
|
|
26
|
-
/**
|
|
27
|
-
* Derive a shared secret using ECDH and HKDF
|
|
28
|
-
* @param privateKeyBase64 Our private key (base64)
|
|
29
|
-
* @param publicKeyBase64 Other party's public key (base64)
|
|
30
|
-
* @returns 256-bit derived key as Buffer
|
|
31
|
-
*/
|
|
32
|
-
deriveSharedKey(privateKeyBase64: string, publicKeyBase64: string): Buffer;
|
|
33
|
-
/**
|
|
34
|
-
* Encrypt a session key for a target device using ECDH
|
|
35
|
-
* @param sessionKeyBase64 The session key to encrypt (base64)
|
|
36
|
-
* @param targetPublicKeyBase64 Target device's public key (base64)
|
|
37
|
-
* @returns EncryptedSessionKey containing encrypted key and ephemeral public key
|
|
38
|
-
*/
|
|
39
|
-
encryptSessionKey(sessionKeyBase64: string, targetPublicKeyBase64: string): Omit<EncryptedSessionKey, 'deviceId'>;
|
|
40
|
-
/**
|
|
41
|
-
* Decrypt a session key using our private key
|
|
42
|
-
* @param encryptedSessionKey The encrypted session key data
|
|
43
|
-
* @param privateKeyBase64 Our device's private key (base64)
|
|
44
|
-
* @returns Decrypted session key (base64)
|
|
45
|
-
*/
|
|
46
|
-
decryptSessionKey(encryptedSessionKey: EncryptedSessionKey, privateKeyBase64: string): string;
|
|
47
|
-
/**
|
|
48
|
-
* Encrypt content using AES-256-GCM
|
|
49
|
-
* @param content String content to encrypt
|
|
50
|
-
* @param sessionKeyBase64 Session key (base64)
|
|
51
|
-
* @returns Base64-encoded ciphertext (nonce + ciphertext + tag)
|
|
52
|
-
*/
|
|
53
|
-
encryptContent(content: string, sessionKeyBase64: string): string;
|
|
54
|
-
/**
|
|
55
|
-
* Decrypt content using AES-256-GCM
|
|
56
|
-
* @param encryptedContent Base64-encoded ciphertext
|
|
57
|
-
* @param sessionKeyBase64 Session key (base64)
|
|
58
|
-
* @returns Decrypted string content
|
|
59
|
-
*/
|
|
60
|
-
decryptContent(encryptedContent: string, sessionKeyBase64: string): string;
|
|
61
|
-
/**
|
|
62
|
-
* Encrypt JSON-serializable metadata
|
|
63
|
-
* @param metadata Object to encrypt
|
|
64
|
-
* @param sessionKeyBase64 Session key (base64)
|
|
65
|
-
* @returns Base64-encoded encrypted JSON
|
|
66
|
-
*/
|
|
67
|
-
encryptMetadata(metadata: Record<string, any>, sessionKeyBase64: string): string;
|
|
68
|
-
/**
|
|
69
|
-
* Decrypt encrypted metadata
|
|
70
|
-
* @param encryptedMetadata Base64-encoded encrypted JSON
|
|
71
|
-
* @param sessionKeyBase64 Session key (base64)
|
|
72
|
-
* @returns Decrypted object
|
|
73
|
-
*/
|
|
74
|
-
decryptMetadata(encryptedMetadata: string, sessionKeyBase64: string): Record<string, any>;
|
|
75
|
-
/**
|
|
76
|
-
* Encrypt binary data using AES-256-GCM
|
|
77
|
-
* @param data Binary data to encrypt (Buffer)
|
|
78
|
-
* @param sessionKeyBase64 Session key (base64)
|
|
79
|
-
* @returns Encrypted data (Buffer containing nonce + ciphertext + tag)
|
|
80
|
-
*/
|
|
81
|
-
encryptData(data: Buffer, sessionKeyBase64: string): Buffer;
|
|
82
|
-
/**
|
|
83
|
-
* Decrypt binary data using AES-256-GCM
|
|
84
|
-
* @param encryptedData Encrypted data (Buffer containing nonce + ciphertext + tag)
|
|
85
|
-
* @param sessionKeyBase64 Session key (base64)
|
|
86
|
-
* @returns Decrypted binary data (Buffer)
|
|
87
|
-
*/
|
|
88
|
-
decryptData(encryptedData: Buffer, sessionKeyBase64: string): Buffer;
|
|
89
|
-
/**
|
|
90
|
-
* Encrypt data using AES-256-GCM
|
|
91
|
-
* @param data Data to encrypt
|
|
92
|
-
* @param key Symmetric key (32 bytes)
|
|
93
|
-
* @returns Combined nonce + ciphertext + tag
|
|
94
|
-
*/
|
|
95
|
-
private encrypt;
|
|
96
|
-
/**
|
|
97
|
-
* Decrypt data using AES-256-GCM
|
|
98
|
-
* @param data Combined nonce + ciphertext + tag
|
|
99
|
-
* @param key Symmetric key (32 bytes)
|
|
100
|
-
* @returns Decrypted data
|
|
101
|
-
*/
|
|
102
|
-
private decrypt;
|
|
103
|
-
/**
|
|
104
|
-
* Serialize a private key for storage
|
|
105
|
-
* Note: Private key is already base64 from generateKeyPair
|
|
106
|
-
*/
|
|
107
|
-
serializePrivateKey(privateKeyBase64: string): string;
|
|
108
|
-
/**
|
|
109
|
-
* Deserialize a private key from storage
|
|
110
|
-
* Note: Private key is already base64
|
|
111
|
-
*/
|
|
112
|
-
deserializePrivateKey(base64: string): string;
|
|
113
|
-
}
|
|
114
|
-
export declare const cryptoService: CryptoService;
|
|
115
|
-
//# sourceMappingURL=crypto-service.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crypto-service.d.ts","sourceRoot":"","sources":["../src/crypto-service.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAG9C,qBAAa,WAAY,SAAQ,KAAK;gBACxB,OAAO,EAAE,MAAM;CAI5B;AAGD,eAAO,MAAM,kBAAkB,IAAI,CAAC;AAKpC;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAgB;IAEvC,OAAO;IAEP,MAAM,CAAC,WAAW,IAAI,aAAa;IASnC;;;OAGG;IACH,eAAe,IAAI;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE;IAkB5D;;;OAGG;IACH,kBAAkB,IAAI,MAAM;IAO5B;;;;;OAKG;IACH,eAAe,CAAC,gBAAgB,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM;IA+B1E;;;;;OAKG;IACH,iBAAiB,CACf,gBAAgB,EAAE,MAAM,EACxB,qBAAqB,EAAE,MAAM,GAC5B,IAAI,CAAC,mBAAmB,EAAE,UAAU,CAAC;IAoBxC;;;;;OAKG;IACH,iBAAiB,CACf,mBAAmB,EAAE,mBAAmB,EACxC,gBAAgB,EAAE,MAAM,GACvB,MAAM;IAgBT;;;;;OAKG;IACH,cAAc,CAAC,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,MAAM;IAOjE;;;;;OAKG;IACH,cAAc,CAAC,gBAAgB,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,MAAM;IAO1E;;;;;OAKG;IACH,eAAe,CACb,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC7B,gBAAgB,EAAE,MAAM,GACvB,MAAM;IAKT;;;;;OAKG;IACH,eAAe,CACb,iBAAiB,EAAE,MAAM,EACzB,gBAAgB,EAAE,MAAM,GACvB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;IAOtB;;;;;OAKG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,MAAM;IAK3D;;;;;OAKG;IACH,WAAW,CAAC,aAAa,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,GAAG,MAAM;IAOpE;;;;;OAKG;IACH,OAAO,CAAC,OAAO;IAYf;;;;;OAKG;IACH,OAAO,CAAC,OAAO;IAmBf;;;OAGG;IACH,mBAAmB,CAAC,gBAAgB,EAAE,MAAM,GAAG,MAAM;IAIrD;;;OAGG;IACH,qBAAqB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAG9C;AAGD,eAAO,MAAM,aAAa,eAA8B,CAAC"}
|
package/dist/crypto-service.js
DELETED
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// crypto-service.ts
|
|
4
|
-
// CodeVibe Claude Plugin
|
|
5
|
-
//
|
|
6
|
-
// End-to-end encryption service using ECDH P-256 and AES-256-GCM
|
|
7
|
-
//
|
|
8
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
-
if (k2 === undefined) k2 = k;
|
|
10
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(o, k2, desc);
|
|
15
|
-
}) : (function(o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
}));
|
|
19
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
20
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
21
|
-
}) : function(o, v) {
|
|
22
|
-
o["default"] = v;
|
|
23
|
-
});
|
|
24
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
25
|
-
var ownKeys = function(o) {
|
|
26
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
27
|
-
var ar = [];
|
|
28
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
29
|
-
return ar;
|
|
30
|
-
};
|
|
31
|
-
return ownKeys(o);
|
|
32
|
-
};
|
|
33
|
-
return function (mod) {
|
|
34
|
-
if (mod && mod.__esModule) return mod;
|
|
35
|
-
var result = {};
|
|
36
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
37
|
-
__setModuleDefault(result, mod);
|
|
38
|
-
return result;
|
|
39
|
-
};
|
|
40
|
-
})();
|
|
41
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
42
|
-
exports.cryptoService = exports.CryptoService = exports.ENCRYPTION_VERSION = exports.CryptoError = void 0;
|
|
43
|
-
const crypto = __importStar(require("crypto"));
|
|
44
|
-
// Errors that can occur during cryptographic operations
|
|
45
|
-
class CryptoError extends Error {
|
|
46
|
-
constructor(message) {
|
|
47
|
-
super(message);
|
|
48
|
-
this.name = 'CryptoError';
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
exports.CryptoError = CryptoError;
|
|
52
|
-
// Current encryption version for future algorithm upgrades
|
|
53
|
-
exports.ENCRYPTION_VERSION = 1;
|
|
54
|
-
// HKDF info string for key derivation
|
|
55
|
-
const HKDF_INFO = 'CodeVibe E2E v1';
|
|
56
|
-
/**
|
|
57
|
-
* Service for end-to-end encryption operations
|
|
58
|
-
*/
|
|
59
|
-
class CryptoService {
|
|
60
|
-
constructor() { }
|
|
61
|
-
static getInstance() {
|
|
62
|
-
if (!CryptoService.instance) {
|
|
63
|
-
CryptoService.instance = new CryptoService();
|
|
64
|
-
}
|
|
65
|
-
return CryptoService.instance;
|
|
66
|
-
}
|
|
67
|
-
// MARK: - Key Generation
|
|
68
|
-
/**
|
|
69
|
-
* Generate a new ECDH P-256 key pair
|
|
70
|
-
* @returns Object with privateKey (PEM), publicKey (base64 raw)
|
|
71
|
-
*/
|
|
72
|
-
generateKeyPair() {
|
|
73
|
-
const ecdh = crypto.createECDH('prime256v1');
|
|
74
|
-
ecdh.generateKeys();
|
|
75
|
-
// Get raw public key (uncompressed format without 0x04 prefix for compatibility)
|
|
76
|
-
const publicKeyRaw = ecdh.getPublicKey();
|
|
77
|
-
const publicKeyBase64 = publicKeyRaw.subarray(1).toString('base64'); // Skip 0x04 prefix
|
|
78
|
-
// Get private key as raw bytes
|
|
79
|
-
const privateKeyRaw = ecdh.getPrivateKey();
|
|
80
|
-
const privateKeyBase64 = privateKeyRaw.toString('base64');
|
|
81
|
-
return {
|
|
82
|
-
privateKey: privateKeyBase64,
|
|
83
|
-
publicKey: publicKeyBase64,
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Generate a random 256-bit session key
|
|
88
|
-
* @returns Base64-encoded session key
|
|
89
|
-
*/
|
|
90
|
-
generateSessionKey() {
|
|
91
|
-
const keyData = crypto.randomBytes(32); // 256 bits
|
|
92
|
-
return keyData.toString('base64');
|
|
93
|
-
}
|
|
94
|
-
// MARK: - Key Derivation
|
|
95
|
-
/**
|
|
96
|
-
* Derive a shared secret using ECDH and HKDF
|
|
97
|
-
* @param privateKeyBase64 Our private key (base64)
|
|
98
|
-
* @param publicKeyBase64 Other party's public key (base64)
|
|
99
|
-
* @returns 256-bit derived key as Buffer
|
|
100
|
-
*/
|
|
101
|
-
deriveSharedKey(privateKeyBase64, publicKeyBase64) {
|
|
102
|
-
try {
|
|
103
|
-
const ecdh = crypto.createECDH('prime256v1');
|
|
104
|
-
const privateKeyRaw = Buffer.from(privateKeyBase64, 'base64');
|
|
105
|
-
ecdh.setPrivateKey(privateKeyRaw);
|
|
106
|
-
// Add 0x04 prefix for uncompressed public key format
|
|
107
|
-
const publicKeyRaw = Buffer.concat([
|
|
108
|
-
Buffer.from([0x04]),
|
|
109
|
-
Buffer.from(publicKeyBase64, 'base64'),
|
|
110
|
-
]);
|
|
111
|
-
const sharedSecret = ecdh.computeSecret(publicKeyRaw);
|
|
112
|
-
// Derive key using HKDF-SHA256
|
|
113
|
-
const derivedKey = crypto.hkdfSync('sha256', sharedSecret, Buffer.alloc(0), // Empty salt
|
|
114
|
-
Buffer.from(HKDF_INFO, 'utf8'), 32 // 256 bits
|
|
115
|
-
);
|
|
116
|
-
return Buffer.from(derivedKey);
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
throw new CryptoError(`Failed to derive shared key: ${error}`);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
// MARK: - Session Key Encryption
|
|
123
|
-
/**
|
|
124
|
-
* Encrypt a session key for a target device using ECDH
|
|
125
|
-
* @param sessionKeyBase64 The session key to encrypt (base64)
|
|
126
|
-
* @param targetPublicKeyBase64 Target device's public key (base64)
|
|
127
|
-
* @returns EncryptedSessionKey containing encrypted key and ephemeral public key
|
|
128
|
-
*/
|
|
129
|
-
encryptSessionKey(sessionKeyBase64, targetPublicKeyBase64) {
|
|
130
|
-
// Generate ephemeral key pair for this encryption
|
|
131
|
-
const ephemeralKeyPair = this.generateKeyPair();
|
|
132
|
-
// Derive shared key using ephemeral private + target public
|
|
133
|
-
const sharedKey = this.deriveSharedKey(ephemeralKeyPair.privateKey, targetPublicKeyBase64);
|
|
134
|
-
// Encrypt session key with derived key
|
|
135
|
-
const sessionKeyData = Buffer.from(sessionKeyBase64, 'base64');
|
|
136
|
-
const encryptedData = this.encrypt(sessionKeyData, sharedKey);
|
|
137
|
-
return {
|
|
138
|
-
encryptedKey: encryptedData.toString('base64'),
|
|
139
|
-
ephemeralPublicKey: ephemeralKeyPair.publicKey,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Decrypt a session key using our private key
|
|
144
|
-
* @param encryptedSessionKey The encrypted session key data
|
|
145
|
-
* @param privateKeyBase64 Our device's private key (base64)
|
|
146
|
-
* @returns Decrypted session key (base64)
|
|
147
|
-
*/
|
|
148
|
-
decryptSessionKey(encryptedSessionKey, privateKeyBase64) {
|
|
149
|
-
// Derive shared key using our private + ephemeral public
|
|
150
|
-
const sharedKey = this.deriveSharedKey(privateKeyBase64, encryptedSessionKey.ephemeralPublicKey);
|
|
151
|
-
// Decrypt session key
|
|
152
|
-
const encryptedData = Buffer.from(encryptedSessionKey.encryptedKey, 'base64');
|
|
153
|
-
const decryptedData = this.decrypt(encryptedData, sharedKey);
|
|
154
|
-
return decryptedData.toString('base64');
|
|
155
|
-
}
|
|
156
|
-
// MARK: - Content Encryption/Decryption
|
|
157
|
-
/**
|
|
158
|
-
* Encrypt content using AES-256-GCM
|
|
159
|
-
* @param content String content to encrypt
|
|
160
|
-
* @param sessionKeyBase64 Session key (base64)
|
|
161
|
-
* @returns Base64-encoded ciphertext (nonce + ciphertext + tag)
|
|
162
|
-
*/
|
|
163
|
-
encryptContent(content, sessionKeyBase64) {
|
|
164
|
-
const sessionKey = Buffer.from(sessionKeyBase64, 'base64');
|
|
165
|
-
const contentData = Buffer.from(content, 'utf8');
|
|
166
|
-
const encryptedData = this.encrypt(contentData, sessionKey);
|
|
167
|
-
return encryptedData.toString('base64');
|
|
168
|
-
}
|
|
169
|
-
/**
|
|
170
|
-
* Decrypt content using AES-256-GCM
|
|
171
|
-
* @param encryptedContent Base64-encoded ciphertext
|
|
172
|
-
* @param sessionKeyBase64 Session key (base64)
|
|
173
|
-
* @returns Decrypted string content
|
|
174
|
-
*/
|
|
175
|
-
decryptContent(encryptedContent, sessionKeyBase64) {
|
|
176
|
-
const sessionKey = Buffer.from(sessionKeyBase64, 'base64');
|
|
177
|
-
const encryptedData = Buffer.from(encryptedContent, 'base64');
|
|
178
|
-
const decryptedData = this.decrypt(encryptedData, sessionKey);
|
|
179
|
-
return decryptedData.toString('utf8');
|
|
180
|
-
}
|
|
181
|
-
/**
|
|
182
|
-
* Encrypt JSON-serializable metadata
|
|
183
|
-
* @param metadata Object to encrypt
|
|
184
|
-
* @param sessionKeyBase64 Session key (base64)
|
|
185
|
-
* @returns Base64-encoded encrypted JSON
|
|
186
|
-
*/
|
|
187
|
-
encryptMetadata(metadata, sessionKeyBase64) {
|
|
188
|
-
const jsonString = JSON.stringify(metadata);
|
|
189
|
-
return this.encryptContent(jsonString, sessionKeyBase64);
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Decrypt encrypted metadata
|
|
193
|
-
* @param encryptedMetadata Base64-encoded encrypted JSON
|
|
194
|
-
* @param sessionKeyBase64 Session key (base64)
|
|
195
|
-
* @returns Decrypted object
|
|
196
|
-
*/
|
|
197
|
-
decryptMetadata(encryptedMetadata, sessionKeyBase64) {
|
|
198
|
-
const jsonString = this.decryptContent(encryptedMetadata, sessionKeyBase64);
|
|
199
|
-
return JSON.parse(jsonString);
|
|
200
|
-
}
|
|
201
|
-
// MARK: - Binary Data Encryption (for attachments)
|
|
202
|
-
/**
|
|
203
|
-
* Encrypt binary data using AES-256-GCM
|
|
204
|
-
* @param data Binary data to encrypt (Buffer)
|
|
205
|
-
* @param sessionKeyBase64 Session key (base64)
|
|
206
|
-
* @returns Encrypted data (Buffer containing nonce + ciphertext + tag)
|
|
207
|
-
*/
|
|
208
|
-
encryptData(data, sessionKeyBase64) {
|
|
209
|
-
const sessionKey = Buffer.from(sessionKeyBase64, 'base64');
|
|
210
|
-
return this.encrypt(data, sessionKey);
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Decrypt binary data using AES-256-GCM
|
|
214
|
-
* @param encryptedData Encrypted data (Buffer containing nonce + ciphertext + tag)
|
|
215
|
-
* @param sessionKeyBase64 Session key (base64)
|
|
216
|
-
* @returns Decrypted binary data (Buffer)
|
|
217
|
-
*/
|
|
218
|
-
decryptData(encryptedData, sessionKeyBase64) {
|
|
219
|
-
const sessionKey = Buffer.from(sessionKeyBase64, 'base64');
|
|
220
|
-
return this.decrypt(encryptedData, sessionKey);
|
|
221
|
-
}
|
|
222
|
-
// MARK: - Low-level Encryption
|
|
223
|
-
/**
|
|
224
|
-
* Encrypt data using AES-256-GCM
|
|
225
|
-
* @param data Data to encrypt
|
|
226
|
-
* @param key Symmetric key (32 bytes)
|
|
227
|
-
* @returns Combined nonce + ciphertext + tag
|
|
228
|
-
*/
|
|
229
|
-
encrypt(data, key) {
|
|
230
|
-
// Generate random 12-byte nonce (IV)
|
|
231
|
-
const nonce = crypto.randomBytes(12);
|
|
232
|
-
const cipher = crypto.createCipheriv('aes-256-gcm', key, nonce);
|
|
233
|
-
const ciphertext = Buffer.concat([cipher.update(data), cipher.final()]);
|
|
234
|
-
const tag = cipher.getAuthTag();
|
|
235
|
-
// Combine: nonce (12 bytes) + ciphertext + tag (16 bytes)
|
|
236
|
-
return Buffer.concat([nonce, ciphertext, tag]);
|
|
237
|
-
}
|
|
238
|
-
/**
|
|
239
|
-
* Decrypt data using AES-256-GCM
|
|
240
|
-
* @param data Combined nonce + ciphertext + tag
|
|
241
|
-
* @param key Symmetric key (32 bytes)
|
|
242
|
-
* @returns Decrypted data
|
|
243
|
-
*/
|
|
244
|
-
decrypt(data, key) {
|
|
245
|
-
// Extract: nonce (12 bytes) + ciphertext + tag (16 bytes)
|
|
246
|
-
const nonce = data.subarray(0, 12);
|
|
247
|
-
const tag = data.subarray(data.length - 16);
|
|
248
|
-
const ciphertext = data.subarray(12, data.length - 16);
|
|
249
|
-
const decipher = crypto.createDecipheriv('aes-256-gcm', key, nonce);
|
|
250
|
-
decipher.setAuthTag(tag);
|
|
251
|
-
try {
|
|
252
|
-
const decrypted = Buffer.concat([decipher.update(ciphertext), decipher.final()]);
|
|
253
|
-
return decrypted;
|
|
254
|
-
}
|
|
255
|
-
catch (error) {
|
|
256
|
-
throw new CryptoError('Decryption failed: Invalid ciphertext or authentication tag');
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
// MARK: - Key Serialization
|
|
260
|
-
/**
|
|
261
|
-
* Serialize a private key for storage
|
|
262
|
-
* Note: Private key is already base64 from generateKeyPair
|
|
263
|
-
*/
|
|
264
|
-
serializePrivateKey(privateKeyBase64) {
|
|
265
|
-
return privateKeyBase64;
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* Deserialize a private key from storage
|
|
269
|
-
* Note: Private key is already base64
|
|
270
|
-
*/
|
|
271
|
-
deserializePrivateKey(base64) {
|
|
272
|
-
return base64;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
exports.CryptoService = CryptoService;
|
|
276
|
-
// Export singleton instance
|
|
277
|
-
exports.cryptoService = CryptoService.getInstance();
|
|
278
|
-
//# sourceMappingURL=crypto-service.js.map
|