@quantiya/codevibe-claude-plugin 1.0.11 → 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/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 +6 -13
- package/dist/appsync-client.js +0 -858
- package/dist/auth-cli.js +0 -472
- package/dist/command-executor.js +0 -127
- package/dist/config.js +0 -106
- package/dist/crypto-service.js +0 -278
- package/dist/http-api.js +0 -334
- package/dist/key-manager.js +0 -287
- package/dist/logger.js +0 -18
- package/dist/prompt-responder.js +0 -132
- package/dist/token-storage.js +0 -169
- package/dist/types.js +0 -17
- 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/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/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
|