@digitaldefiance/ecies-lib 4.12.0 → 4.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +67 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -203,7 +203,8 @@ import {
203
203
  getEciesI18nEngine,
204
204
  createRuntimeConfiguration,
205
205
  ObjectIdProvider,
206
- getEnhancedIdProvider
206
+ getEnhancedIdProvider,
207
+ AESGCMService
207
208
  } from '@digitaldefiance/ecies-lib';
208
209
 
209
210
  // 1. Initialize i18n (required once)
@@ -235,6 +236,24 @@ const idProvider = getEnhancedIdProvider<ObjectId>();
235
236
  const objectId = idProvider.generateTyped(); // Returns ObjectId - strongly typed!
236
237
  const serialized = idProvider.serializeTyped(objectId); // Accepts ObjectId directly
237
238
  const deserialized = idProvider.deserializeTyped(serialized); // Returns ObjectId
239
+
240
+ // 7. AES-GCM Service (Instance-based)
241
+ const aesGcm = new AESGCMService(); // Now instance-based, not static
242
+ const key = crypto.getRandomValues(new Uint8Array(32));
243
+ const data = new TextEncoder().encode('Sensitive Data');
244
+
245
+ // Encrypt with authentication tag
246
+ const { encrypted: aesEncrypted, iv, tag } = await aesGcm.encrypt(data, key, true);
247
+
248
+ // Decrypt
249
+ const combined = aesGcm.combineEncryptedDataAndTag(aesEncrypted, tag!);
250
+ const aesDecrypted = await aesGcm.decrypt(iv, combined, key, true);
251
+
252
+ // 8. JSON Encryption (NEW!)
253
+ const userData = { name: 'Alice', email: 'alice@example.com', age: 30 };
254
+ const encryptedJson = await aesGcm.encryptJson(userData, key);
255
+ const decryptedJson = await aesGcm.decryptJson<typeof userData>(encryptedJson, key);
256
+ console.log(decryptedJson); // { name: 'Alice', email: 'alice@example.com', age: 30 }
238
257
  ```
239
258
 
240
259
  ## Cryptographic Voting System
@@ -1258,6 +1277,53 @@ The library maintains **100% test coverage** with over 1,200 tests, including:
1258
1277
 
1259
1278
  ## ChangeLog
1260
1279
 
1280
+ ### v4.12.0 - AESGCMService Refactoring & JSON Encryption
1281
+
1282
+ **Breaking Changes:**
1283
+ - **AESGCMService is now instance-based**: Changed from abstract static class to regular instance-based class
1284
+ - All methods are now instance methods instead of static methods
1285
+ - Constructor accepts optional `IConstants` parameter for configuration
1286
+ - Example: `const aesGcm = new AESGCMService(); aesGcm.encrypt(...)` instead of `AESGCMService.encrypt(...)`
1287
+
1288
+ **New Features:**
1289
+ - **JSON Encryption Methods**: Added convenient methods for encrypting/decrypting JSON data
1290
+ - `encryptJson<T>(data: T, key: Uint8Array): Promise<Uint8Array>` - Encrypts any JSON-serializable data
1291
+ - `decryptJson<T>(encryptedData: Uint8Array, key: Uint8Array): Promise<T>` - Decrypts and parses JSON data
1292
+ - Automatically handles JSON serialization, encryption with auth tags, and IV management
1293
+ - Type-safe with TypeScript generics
1294
+
1295
+ **Architecture Improvements:**
1296
+ - Added `configuration` and `engine` instance properties to AESGCMService
1297
+ - Improved dependency injection support with optional constants parameter
1298
+ - Enhanced error handling with i18n support
1299
+ - Better alignment with browser/Node.js architectural patterns
1300
+
1301
+ **Migration Guide:**
1302
+ ```typescript
1303
+ // BEFORE (v4.10.x and earlier)
1304
+ import { AESGCMService } from '@digitaldefiance/ecies-lib';
1305
+
1306
+ const { encrypted, iv, tag } = await AESGCMService.encrypt(data, key, true);
1307
+ const combined = AESGCMService.combineEncryptedDataAndTag(encrypted, tag);
1308
+
1309
+ // AFTER (v4.11.0+)
1310
+ import { AESGCMService } from '@digitaldefiance/ecies-lib';
1311
+
1312
+ const aesGcm = new AESGCMService(); // Create instance
1313
+ const { encrypted, iv, tag } = await aesGcm.encrypt(data, key, true);
1314
+ const combined = aesGcm.combineEncryptedDataAndTag(encrypted, tag);
1315
+
1316
+ // NEW: JSON encryption
1317
+ const userData = { name: 'Alice', email: 'alice@example.com' };
1318
+ const encrypted = await aesGcm.encryptJson(userData, key);
1319
+ const decrypted = await aesGcm.decryptJson<typeof userData>(encrypted, key);
1320
+ ```
1321
+
1322
+ **Testing:**
1323
+ - Added 17 comprehensive tests for JSON encryption methods
1324
+ - Added 3 e2e tests for real-world JSON scenarios
1325
+ - All 1,200+ existing tests updated and passing
1326
+
1261
1327
  ### v4.10.7 - Strong Typing for ID Providers
1262
1328
 
1263
1329
  **Major Features:**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitaldefiance/ecies-lib",
3
- "version": "4.12.0",
3
+ "version": "4.12.1",
4
4
  "description": "Digital Defiance ECIES Library",
5
5
  "homepage": "https://github.com/Digital-Defiance/ecies-lib",
6
6
  "repository": {