@digitaldefiance/node-ecies-lib 4.4.0 → 4.4.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 +191 -0
  2. package/package.json +6 -2
package/README.md CHANGED
@@ -245,8 +245,199 @@ yarn lint # ESLint check
245
245
  yarn format # Fix all (prettier + lint)
246
246
  ```
247
247
 
248
+ ## Testing
249
+
250
+ ### Testing Approach
251
+
252
+ The node-ecies-lib package uses comprehensive testing with 220+ tests covering all Node.js-specific cryptographic operations and binary compatibility with the browser-based ecies-lib.
253
+
254
+ **Test Framework**: Jest with TypeScript support
255
+ **Property-Based Testing**: fast-check for cryptographic properties
256
+ **Coverage Target**: 90%+ for all cryptographic operations
257
+ **Binary Compatibility**: Verified with @digitaldefiance/ecies-lib
258
+
259
+ ### Test Structure
260
+
261
+ ```
262
+ tests/
263
+ ├── unit/ # Unit tests for Node.js services
264
+ ├── integration/ # Integration tests for protocol flows
265
+ ├── e2e/ # End-to-end encryption/decryption tests
266
+ ├── compatibility/ # Cross-platform compatibility with ecies-lib
267
+ └── streaming/ # Streaming encryption tests
268
+ ```
269
+
270
+ ### Running Tests
271
+
272
+ ```bash
273
+ # Run all tests
274
+ npm test
275
+
276
+ # Run with coverage
277
+ npm test -- --coverage
278
+
279
+ # Run specific test suite
280
+ npm test -- ecies-service.spec.ts
281
+
282
+ # Run compatibility tests
283
+ npm test -- cross-platform-compatibility.e2e.spec.ts
284
+
285
+ # Run in watch mode
286
+ npm test -- --watch
287
+ ```
288
+
289
+ ### Test Patterns
290
+
291
+ #### Testing Node.js Encryption
292
+
293
+ ```typescript
294
+ import { ECIESService, registerNodeRuntimeConfiguration } from '@digitaldefiance/node-ecies-lib';
295
+ import { ObjectIdProvider } from '@digitaldefiance/ecies-lib';
296
+
297
+ describe('Node ECIES Encryption', () => {
298
+ let ecies: ECIESService;
299
+
300
+ beforeEach(() => {
301
+ registerNodeRuntimeConfiguration({
302
+ idProvider: new ObjectIdProvider()
303
+ });
304
+ ecies = new ECIESService();
305
+ });
306
+
307
+ it('should encrypt and decrypt with Buffer', () => {
308
+ const mnemonic = ecies.generateNewMnemonic();
309
+ const { privateKey, publicKey } = ecies.mnemonicToSimpleKeyPair(mnemonic);
310
+
311
+ const message = Buffer.from('Secret Message');
312
+ const encrypted = ecies.encryptSimpleOrSingle(false, publicKey, message);
313
+ const decrypted = ecies.decryptSimpleOrSingleWithHeader(false, privateKey, encrypted);
314
+
315
+ expect(decrypted.toString()).toBe('Secret Message');
316
+ });
317
+ });
318
+ ```
319
+
320
+ #### Testing Streaming Encryption
321
+
322
+ ```typescript
323
+ import { ECIESService, EncryptionStream } from '@digitaldefiance/node-ecies-lib';
324
+ import { createReadStream } from 'fs';
325
+
326
+ describe('Streaming Encryption', () => {
327
+ it('should encrypt large files efficiently', async () => {
328
+ const ecies = new ECIESService();
329
+ const stream = new EncryptionStream(ecies);
330
+
331
+ const { privateKey, publicKey } = ecies.mnemonicToSimpleKeyPair(ecies.generateNewMnemonic());
332
+ const fileStream = createReadStream('test-file.dat');
333
+
334
+ const encryptedChunks: Buffer[] = [];
335
+ for await (const chunk of stream.encryptStream(fileStream, publicKey)) {
336
+ encryptedChunks.push(chunk.data);
337
+ }
338
+
339
+ expect(encryptedChunks.length).toBeGreaterThan(0);
340
+ });
341
+ });
342
+ ```
343
+
344
+ #### Testing Binary Compatibility
345
+
346
+ ```typescript
347
+ import { ECIESService as NodeECIES } from '@digitaldefiance/node-ecies-lib';
348
+ import { ECIESService as BrowserECIES } from '@digitaldefiance/ecies-lib';
349
+
350
+ describe('Binary Compatibility', () => {
351
+ it('should decrypt browser-encrypted data in Node.js', async () => {
352
+ const browserEcies = new BrowserECIES();
353
+ const nodeEcies = new NodeECIES();
354
+
355
+ const mnemonic = browserEcies.generateNewMnemonic();
356
+ const { privateKey, publicKey } = browserEcies.mnemonicToSimpleKeyPair(mnemonic);
357
+
358
+ // Encrypt in browser
359
+ const message = new TextEncoder().encode('Cross-platform message');
360
+ const encrypted = await browserEcies.encryptSimpleOrSingle(false, publicKey, message);
361
+
362
+ // Decrypt in Node.js
363
+ const decrypted = nodeEcies.decryptSimpleOrSingleWithHeader(
364
+ false,
365
+ Buffer.from(privateKey),
366
+ Buffer.from(encrypted)
367
+ );
368
+
369
+ expect(decrypted.toString()).toBe('Cross-platform message');
370
+ });
371
+ });
372
+ ```
373
+
374
+ #### Property-Based Testing
375
+
376
+ ```typescript
377
+ import * as fc from 'fast-check';
378
+ import { ECIESService } from '@digitaldefiance/node-ecies-lib';
379
+
380
+ describe('Cryptographic Properties', () => {
381
+ it('should maintain encryption round-trip for any Buffer', () => {
382
+ const ecies = new ECIESService();
383
+ const { privateKey, publicKey } = ecies.mnemonicToSimpleKeyPair(ecies.generateNewMnemonic());
384
+
385
+ fc.assert(
386
+ fc.property(
387
+ fc.uint8Array({ minLength: 1, maxLength: 1000 }),
388
+ (data) => {
389
+ const message = Buffer.from(data);
390
+ const encrypted = ecies.encryptSimpleOrSingle(false, publicKey, message);
391
+ const decrypted = ecies.decryptSimpleOrSingleWithHeader(false, privateKey, encrypted);
392
+
393
+ expect(decrypted.equals(message)).toBe(true);
394
+ }
395
+ ),
396
+ { numRuns: 100 }
397
+ );
398
+ });
399
+ });
400
+ ```
401
+
402
+ ### Testing Best Practices
403
+
404
+ 1. **Configure runtime** before tests with `registerNodeRuntimeConfiguration()`
405
+ 2. **Test Buffer operations** specific to Node.js
406
+ 3. **Test streaming** for large file handling
407
+ 4. **Verify binary compatibility** with browser ecies-lib
408
+ 5. **Test all ID providers** (ObjectId, GUID, UUID, Custom)
409
+ 6. **Test error conditions** like invalid keys and corrupted data
410
+
411
+ ### Cross-Package Testing
412
+
413
+ Testing integration with other Express Suite packages:
414
+
415
+ ```typescript
416
+ import { ECIESService } from '@digitaldefiance/node-ecies-lib';
417
+ import { Member, MemberType, EmailString } from '@digitaldefiance/ecies-lib';
418
+
419
+ describe('Integration with suite-core-lib', () => {
420
+ it('should work with Member abstraction', () => {
421
+ const ecies = new ECIESService();
422
+ const { member, mnemonic } = Member.newMember(
423
+ ecies,
424
+ MemberType.User,
425
+ 'Alice',
426
+ new EmailString('alice@example.com')
427
+ );
428
+
429
+ const encrypted = member.encryptData('Secret');
430
+ expect(encrypted).toBeDefined();
431
+ });
432
+ });
433
+ ```
434
+
248
435
  ## ChangeLog
249
436
 
437
+ ### v4.4.1
438
+
439
+ - Update ecies lib
440
+
250
441
  ### v4.4.0
251
442
 
252
443
  - Improving dependency loops/constants/direcular dependency
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitaldefiance/node-ecies-lib",
3
- "version": "4.4.0",
3
+ "version": "4.4.1",
4
4
  "description": "Digital Defiance Node ECIES Library",
5
5
  "main": "src/index.js",
6
6
  "types": "src/index.d.ts",
@@ -48,7 +48,7 @@
48
48
  "license": "MIT",
49
49
  "packageManager": "yarn@4.10.3",
50
50
  "dependencies": {
51
- "@digitaldefiance/ecies-lib": "4.4.0",
51
+ "@digitaldefiance/ecies-lib": "4.4.1",
52
52
  "@digitaldefiance/i18n-lib": "3.8.0",
53
53
  "@ethereumjs/wallet": "^10.0.0",
54
54
  "@noble/curves": "^2.0.1",
@@ -60,6 +60,10 @@
60
60
  },
61
61
  "devDependencies": {
62
62
  "@digitaldefiance/express-suite-test-utils": "1.0.10",
63
+ "@typescript-eslint/eslint-plugin": "^8.48.0",
64
+ "@typescript-eslint/parser": "^8.48.0",
65
+ "eslint-plugin-import": "^2.32.0",
66
+ "eslint-plugin-prettier": "^5.5.4",
63
67
  "fast-check": "^4.3.0",
64
68
  "madge": "^8.0.0"
65
69
  },