@digitaldefiance/node-ecies-lib 3.0.7 → 4.1.0

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 (119) hide show
  1. package/README.md +233 -408
  2. package/package.json +3 -3
  3. package/src/builders/member-builder.d.ts +1 -2
  4. package/src/builders/member-builder.d.ts.map +1 -1
  5. package/src/builders/member-builder.js.map +1 -1
  6. package/src/constants.d.ts.map +1 -1
  7. package/src/constants.js +38 -9
  8. package/src/constants.js.map +1 -1
  9. package/src/i18n/ecies-i18n-factory.d.ts +2 -52
  10. package/src/i18n/ecies-i18n-factory.d.ts.map +1 -1
  11. package/src/i18n/ecies-i18n-factory.js +9 -63
  12. package/src/i18n/ecies-i18n-factory.js.map +1 -1
  13. package/src/i18n/node-ecies-i18n-setup.d.ts.map +1 -1
  14. package/src/i18n/node-ecies-i18n-setup.js +5 -53
  15. package/src/i18n/node-ecies-i18n-setup.js.map +1 -1
  16. package/src/i18n/node-keys.d.ts +57 -0
  17. package/src/i18n/node-keys.d.ts.map +1 -0
  18. package/src/i18n/node-keys.js +67 -0
  19. package/src/i18n/node-keys.js.map +1 -0
  20. package/src/i18n/translations/de.d.ts +1 -1
  21. package/src/i18n/translations/de.d.ts.map +1 -1
  22. package/src/i18n/translations/de.js +51 -46
  23. package/src/i18n/translations/de.js.map +1 -1
  24. package/src/i18n/translations/en-GB.d.ts +1 -1
  25. package/src/i18n/translations/en-GB.d.ts.map +1 -1
  26. package/src/i18n/translations/en-GB.js +51 -46
  27. package/src/i18n/translations/en-GB.js.map +1 -1
  28. package/src/i18n/translations/en-US.d.ts +1 -1
  29. package/src/i18n/translations/en-US.d.ts.map +1 -1
  30. package/src/i18n/translations/en-US.js +52 -46
  31. package/src/i18n/translations/en-US.js.map +1 -1
  32. package/src/i18n/translations/es.d.ts +1 -1
  33. package/src/i18n/translations/es.d.ts.map +1 -1
  34. package/src/i18n/translations/es.js +51 -46
  35. package/src/i18n/translations/es.js.map +1 -1
  36. package/src/i18n/translations/fr.d.ts +1 -1
  37. package/src/i18n/translations/fr.d.ts.map +1 -1
  38. package/src/i18n/translations/fr.js +51 -46
  39. package/src/i18n/translations/fr.js.map +1 -1
  40. package/src/i18n/translations/index.d.ts +2 -0
  41. package/src/i18n/translations/index.d.ts.map +1 -1
  42. package/src/i18n/translations/index.js +5 -1
  43. package/src/i18n/translations/index.js.map +1 -1
  44. package/src/i18n/translations/ja.d.ts +1 -1
  45. package/src/i18n/translations/ja.d.ts.map +1 -1
  46. package/src/i18n/translations/ja.js +51 -46
  47. package/src/i18n/translations/ja.js.map +1 -1
  48. package/src/i18n/translations/uk.d.ts +1 -1
  49. package/src/i18n/translations/uk.d.ts.map +1 -1
  50. package/src/i18n/translations/uk.js +51 -46
  51. package/src/i18n/translations/uk.js.map +1 -1
  52. package/src/i18n/translations/zh-cn.d.ts +1 -1
  53. package/src/i18n/translations/zh-cn.d.ts.map +1 -1
  54. package/src/i18n/translations/zh-cn.js +51 -46
  55. package/src/i18n/translations/zh-cn.js.map +1 -1
  56. package/src/interfaces/authenticated-cipher.d.ts +3 -0
  57. package/src/interfaces/authenticated-cipher.d.ts.map +1 -1
  58. package/src/interfaces/authenticated-decipher.d.ts +3 -0
  59. package/src/interfaces/authenticated-decipher.d.ts.map +1 -1
  60. package/src/interfaces/backend-member-operational.d.ts +1 -1
  61. package/src/interfaces/backend-member-operational.d.ts.map +1 -1
  62. package/src/interfaces/constants.d.ts +26 -17
  63. package/src/interfaces/constants.d.ts.map +1 -1
  64. package/src/interfaces/multi-encrypted-parsed-header.d.ts +5 -2
  65. package/src/interfaces/multi-encrypted-parsed-header.d.ts.map +1 -1
  66. package/src/interfaces/multi-recipient-chunk.d.ts +16 -0
  67. package/src/interfaces/multi-recipient-chunk.d.ts.map +1 -1
  68. package/src/interfaces/multi-recipient-chunk.js +10 -0
  69. package/src/interfaces/multi-recipient-chunk.js.map +1 -1
  70. package/src/lib/index.d.ts +2 -0
  71. package/src/lib/index.d.ts.map +1 -1
  72. package/src/lib/index.js +2 -0
  73. package/src/lib/index.js.map +1 -1
  74. package/src/lib/invariant-validator.d.ts +62 -0
  75. package/src/lib/invariant-validator.d.ts.map +1 -0
  76. package/src/lib/invariant-validator.js +108 -0
  77. package/src/lib/invariant-validator.js.map +1 -0
  78. package/src/lib/invariants/index.d.ts +8 -0
  79. package/src/lib/invariants/index.d.ts.map +1 -0
  80. package/src/lib/invariants/index.js +12 -0
  81. package/src/lib/invariants/index.js.map +1 -0
  82. package/src/lib/invariants/recipient-id-consistency.d.ts +22 -0
  83. package/src/lib/invariants/recipient-id-consistency.d.ts.map +1 -0
  84. package/src/lib/invariants/recipient-id-consistency.js +62 -0
  85. package/src/lib/invariants/recipient-id-consistency.js.map +1 -0
  86. package/src/member.d.ts +6 -6
  87. package/src/member.d.ts.map +1 -1
  88. package/src/member.js +13 -20
  89. package/src/member.js.map +1 -1
  90. package/src/services/aes-gcm.d.ts +2 -2
  91. package/src/services/aes-gcm.d.ts.map +1 -1
  92. package/src/services/aes-gcm.js +8 -2
  93. package/src/services/aes-gcm.js.map +1 -1
  94. package/src/services/ecies/crypto-core.d.ts +21 -0
  95. package/src/services/ecies/crypto-core.d.ts.map +1 -1
  96. package/src/services/ecies/crypto-core.js +62 -7
  97. package/src/services/ecies/crypto-core.js.map +1 -1
  98. package/src/services/ecies/multi-recipient.d.ts +11 -7
  99. package/src/services/ecies/multi-recipient.d.ts.map +1 -1
  100. package/src/services/ecies/multi-recipient.js +200 -71
  101. package/src/services/ecies/multi-recipient.js.map +1 -1
  102. package/src/services/ecies/service.d.ts +1 -1
  103. package/src/services/ecies/service.d.ts.map +1 -1
  104. package/src/services/ecies/service.js +2 -2
  105. package/src/services/ecies/service.js.map +1 -1
  106. package/src/services/ecies/single-recipient.d.ts +1 -1
  107. package/src/services/ecies/single-recipient.d.ts.map +1 -1
  108. package/src/services/ecies/single-recipient.js +76 -43
  109. package/src/services/ecies/single-recipient.js.map +1 -1
  110. package/src/services/encryption-stream.js +3 -4
  111. package/src/services/encryption-stream.js.map +1 -1
  112. package/src/services/multi-recipient-processor.d.ts +42 -9
  113. package/src/services/multi-recipient-processor.d.ts.map +1 -1
  114. package/src/services/multi-recipient-processor.js +273 -177
  115. package/src/services/multi-recipient-processor.js.map +1 -1
  116. package/src/test-mocks/mock-backend-member.d.ts +7 -8
  117. package/src/test-mocks/mock-backend-member.d.ts.map +1 -1
  118. package/src/test-mocks/mock-backend-member.js +4 -4
  119. package/src/test-mocks/mock-backend-member.js.map +1 -1
package/README.md CHANGED
@@ -1,486 +1,277 @@
1
1
  # @digitaldefiance/node-ecies-lib
2
2
 
3
- A Node.js-specific implementation of the Digital Defiance ECIES (Elliptic Curve Integrated Encryption Scheme) library, providing secure encryption, decryption, and key management capabilities using Node.js crypto primitives. This package is designed to be binary compatible with the browser-based `@digitaldefiance/ecies-lib`, enabling seamless cross-platform cryptographic operations.
3
+ [![npm version](https://badge.fury.io/js/%40digitaldefiance%2Fnode-ecies-lib.svg)](https://www.npmjs.com/package/@digitaldefiance/node-ecies-lib)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+ [![Tests](https://img.shields.io/badge/tests-220%2B%20passing-brightgreen)](https://github.com/Digital-Defiance/ecies-lib)
4
6
 
5
- Part of [Express Suite](https://github.com/Digital-Defiance/express-suite)
6
-
7
- ## Features
8
-
9
- - **ECIES Encryption/Decryption**: Secure elliptic curve integrated encryption scheme using Node.js crypto primitives.
10
- - **Streaming Encryption**: Memory-efficient encryption for large files (<10MB RAM for any size) ✨ NEW in v3.0
11
- - **Multi-recipient Encryption**: Encrypt data for multiple recipients simultaneously with efficient handling.
12
- - **Multi-recipient Streaming**: Encrypt once for up to 65,535 recipients with shared symmetric key ✨ NEW in v3.0
13
- - **PBKDF2 Key Derivation**: Password-based key derivation with multiple configurable security profiles.
14
- - **Digital Signatures**: Sign and verify data using elliptic curve cryptography.
15
- - **Secure Memory Management**: Uses `SecureBuffer` and `SecureString` for sensitive data to ensure zeroization and protection.
16
- - **Runtime Configuration Registry**: Centralized, immutable constants with runtime override capabilities for advanced customization.
17
- - **Plugin-Based Internationalization (i18n)**: Full support for multi-language translations with type-safe, plugin-based architecture.
18
- - **Security Hardening**: 16 comprehensive security validations across all layers ✨ NEW in v3.0
19
-
20
- ## Binary Compatibility
21
-
22
- This package is intended to be fully binary compatible with the browser-based `@digitaldefiance/ecies-lib`. This means:
23
-
24
- - Data encrypted in the browser can be decrypted in Node.js and vice versa.
25
- - Cryptographic primitives and data formats are consistent across environments.
26
- - Enables cross-platform secure communication and data handling.
27
-
28
- ## Installation
29
-
30
- ```bash
31
- npm install @digitaldefiance/node-ecies-lib
32
- ```
33
-
34
- ## Quick Start
35
-
36
- ### v3.0 Streaming Encryption (NEW)
37
-
38
- ```typescript
39
- import { ECIESService, Member, MemberType, EmailString } from '@digitaldefiance/node-ecies-lib';
40
- import { createReadStream } from 'fs';
7
+ A Node.js-specific implementation of the Digital Defiance ECIES (Elliptic Curve Integrated Encryption Scheme) library, providing secure encryption, decryption, and key management capabilities using Node.js crypto primitives. This package is designed to be binary compatible with similarly numbered releases of the browser-based `@digitaldefiance/ecies-lib`, enabling seamless cross-platform cryptographic operations.
41
8
 
42
- const eciesService = new ECIESService();
43
- const { member, mnemonic } = Member.newMember(
44
- eciesService,
45
- MemberType.User,
46
- 'Alice',
47
- new EmailString('alice@example.com')
48
- );
49
-
50
- // Stream encrypt large file with <10MB RAM
51
- const fileStream = createReadStream('large-file.bin');
52
- const chunks: Buffer[] = [];
9
+ Part of [Express Suite](https://github.com/Digital-Defiance/express-suite)
53
10
 
54
- for await (const chunk of member.encryptDataStream(fileStream)) {
55
- chunks.push(chunk.data);
56
- }
11
+ > Current Version: v4.1.0
57
12
 
58
- // Stream decrypt
59
- const decryptedChunks: Buffer[] = [];
60
- for await (const chunk of member.decryptDataStream(chunks)) {
61
- decryptedChunks.push(chunk);
62
- }
63
- ```
13
+ This library implements a modern, enterprise-grade ECIES protocol (v4.0) featuring HKDF key derivation, AAD binding, and optimized multi-recipient encryption. It includes a pluggable ID provider system, memory-efficient streaming encryption, and comprehensive internationalization.
64
14
 
65
- ### v2.0 Simplified API
15
+ ## Features
66
16
 
67
- ```typescript
68
- import { ECIESService, Member, MemberType, EmailString } from '@digitaldefiance/node-ecies-lib';
17
+ ### 🛡️ Core Cryptography (Protocol v4.0)
69
18
 
70
- // Initialize the ECIES service (automatic i18n setup)
71
- const eciesService = new ECIESService();
19
+ - **Advanced ECIES**:
20
+ - **HKDF-SHA256**: Cryptographically robust key derivation (RFC 5869).
21
+ - **AAD Binding**: Strict binding of header metadata and recipient IDs to the encryption context to prevent tampering.
22
+ - **Shared Ephemeral Key**: Optimized multi-recipient encryption using a single ephemeral key pair, reducing payload size.
23
+ - **Compressed Keys**: Uses 33-byte compressed public keys for efficiency.
24
+ - **Algorithms**:
25
+ - **Curve**: `secp256k1` for ECDH key exchange and ECDSA signatures.
26
+ - **Symmetric**: `AES-256-GCM` for authenticated symmetric encryption.
27
+ - **Hashing**: `SHA-256` and `SHA-512`.
28
+ - **Modes**:
29
+ - **Simple**: Minimal overhead (no length prefix).
30
+ - **Single**: Includes data length prefix.
31
+ - **Multiple**: Efficient encryption for up to 65,535 recipients.
72
32
 
73
- // Create a new member
74
- const { member, mnemonic } = Member.newMember(
75
- eciesService,
76
- MemberType.User,
77
- 'Alice',
78
- new EmailString('alice@example.com')
79
- );
33
+ ### 🆔 Identity & Management
80
34
 
81
- // Encrypt data
82
- const message = 'Hello, secure world!';
83
- const encrypted = member.encryptData(message);
35
+ - **Pluggable ID Providers**:
36
+ - **Flexible IDs**: Support for `ObjectId` (12 bytes), `GUID`/`UUID` (16 bytes), or custom formats (1-255 bytes).
37
+ - **Auto-Sync**: Configuration automatically adapts all cryptographic constants to the selected ID provider.
38
+ - **Member System**: User abstraction with cryptographic operations, fully integrated with the configured ID provider.
39
+ - **Key Management**:
40
+ - **BIP39**: Mnemonic phrase generation (12-24 words).
41
+ - **HD Wallets**: BIP32/BIP44 hierarchical deterministic derivation.
42
+ - **Secure Storage**: Memory-safe `SecureString` and `SecureBuffer` with XOR obfuscation and auto-zeroing.
84
43
 
85
- // Decrypt data
86
- const decrypted = member.decryptData(encrypted);
87
- console.log(decrypted.toString()); // "Hello, secure world!"
88
- ```
44
+ ### 🚀 Advanced Capabilities
89
45
 
90
- ### v2.0 Builder Pattern
46
+ - **Streaming Encryption**: Memory-efficient processing for large files (<10MB RAM usage for any file size).
47
+ - **Internationalization (i18n)**: Automatic error translation in 8 languages (en-US, en-GB, fr, es, de, zh-CN, ja, uk).
48
+ - **Runtime Configuration**: Injectable configuration profiles via `ConstantsRegistry` for dependency injection and testing.
49
+ - **Cross-Platform**: Fully compatible with similarly numbered releases of `@digitaldefiance/ecies-lib` (browser).
91
50
 
92
- ```typescript
93
- import { ECIESBuilder, MemberBuilder, MemberType } from '@digitaldefiance/node-ecies-lib';
94
-
95
- // Build service with custom configuration and constants
96
- const eciesService = ECIESBuilder.create()
97
- .withServiceConfig({ /* optional config */ })
98
- .withConstants({ /* optional constants */ })
99
- .build();
100
-
101
- // Build member with fluent API
102
- const { member, mnemonic } = MemberBuilder.create()
103
- .withEciesService(eciesService)
104
- .withType(MemberType.User)
105
- .withName('Alice')
106
- .withEmail('alice@example.com')
107
- .generateMnemonic() // Optional: auto-generate mnemonic
108
- .build();
109
-
110
- // Or provide your own mnemonic
111
- const { member: member2, mnemonic: mnemonic2 } = MemberBuilder.create()
112
- .withEciesService(eciesService)
113
- .withType(MemberType.User)
114
- .withName('Bob')
115
- .withEmail('bob@example.com')
116
- .withMnemonic(existingMnemonic)
117
- .build();
118
- ```
51
+ ## Compatibility
119
52
 
120
- ## Core Components
53
+ **Important Note**: This library is **NOT** binary compatible with previous major versions (v1.x, v2.x, v3.x) due to the protocol upgrade to v4.0 (HKDF, AAD binding).
121
54
 
122
- ### ECIESService
55
+ However, it is designed to be **strictly binary compatible** with the browser-based `@digitaldefiance/ecies-lib` of the **same version number**. This ensures that data encrypted in a Node.js environment (using this library) can be decrypted in a browser environment (using `ecies-lib`), and vice versa, provided both are running compatible versions (e.g., v4.x).
123
56
 
124
- The main service class providing encryption, decryption, key management, and mnemonic generation.
57
+ This cross-platform interoperability is verified through extensive E2E testing suites.
125
58
 
126
- **v2.0 Constructor:**
127
- ```typescript
128
- constructor(config?: Partial<IECIESConfig>, eciesParams?: IECIESConstants)
129
- ```
59
+ ## Installation
130
60
 
131
- - `config`: Optional partial configuration (curveName, symmetricAlgorithm, etc.)
132
- - `eciesParams`: Optional ECIES constants (defaults to `Constants.ECIES`)
133
- - Automatic i18n engine initialization
134
-
135
- **Key Methods:**
136
- - `generateNewMnemonic(): SecureString`: Generates a new mnemonic phrase compliant with BIP39 for secure key generation.
137
- - `walletAndSeedFromMnemonic(mnemonic: SecureString): { wallet: Wallet; seed: Buffer }`: Derives an Ethereum wallet instance and raw seed buffer from a mnemonic.
138
- - `encryptSimpleOrSingle(simple: boolean, publicKey: Buffer, data: Buffer): Buffer`: Encrypts data in simple (headerless) or single-recipient (with header) ECIES mode.
139
- - `encryptMultiple(members: Member[], data: Buffer): Buffer`: Encrypts the same payload for multiple recipients efficiently, producing a combined ciphertext.
140
- - `decryptSimpleOrSingleWithHeader(simple: boolean, privateKey: Buffer, encryptedData: Buffer): Buffer`: Decrypts data encrypted by `encryptSimpleOrSingle` in either mode, returning the original plaintext.
141
- - `signMessage(privateKey: Buffer, data: Buffer): SignatureBuffer`: Creates a deterministic signature over a message using the provided private key.
142
- - `verifyMessage(publicKey: Buffer, data: Buffer, signature: SignatureBuffer): boolean`: Validates a signature against the original data and signer’s public key.
143
- - `deriveKeyFromPassword(password: Buffer, salt: Buffer, iterations: number, saltBytes: number, hashBytes: number, algorithm: string): ChecksumBuffer`: Delegates to PBKDF2 service for synchronous key derivation.
144
- - `deriveKeyFromPasswordAsync(password: Buffer, salt: Buffer, iterations: number, saltBytes: number, hashBytes: number, algorithm: string): Promise<ChecksumBuffer>`: Async version of key derivation to avoid blocking the event loop.
145
-
146
- ### Member Class
147
-
148
- Represents a cryptographic member with secure key management and cryptographic operations.
149
-
150
- **v2.0 Changes:**
151
- - Constructor no longer requires i18n engine
152
- - Automatic engine retrieval from singleton
153
- - Simplified factory methods
154
-
155
- **Core Methods:**
156
-
157
- - `new Member(...)`: Constructs with injected `ECIESService`, type, name, email, public key, and optional private key, wallet, IDs, and timestamps.
158
- - `loadWallet(mnemonic: SecureString)`: Loads wallet and private key from mnemonic; verifies public key integrity.
159
- - `loadPrivateKey(privateKey: SecureBuffer)`: Imports a raw private key into the member instance.
160
- - `sign(data: Buffer): SignatureBuffer`: Signs arbitrary data buffer; throws if private key is missing.
161
- - `verify(signature: SignatureBuffer, data: Buffer): boolean`: Verifies a signature against the member’s public key.
162
- - `encryptData(data: string | Buffer, recipientPublicKey?: Buffer): Buffer`: Encrypts data for the specified public key or self.
163
- - `decryptData(encryptedData: Buffer): Buffer`: Decrypts ciphertext using the member’s private key.
164
- - `toJson(): string`: Serializes member operational data (IDs, keys, timestamps) into a JSON string.
165
- - `dispose(): void`: Securely zeroizes and unloads private key and wallet from memory.
166
- - Static factory methods:
167
- - `Member.fromJson(json: string, eciesService: ECIESService)`: Recreates a member from stored JSON.
168
- - `Member.fromMnemonic(mnemonic: SecureString, eciesService: ECIESService, memberType?, name?, email?)`: Builds a member directly from a mnemonic.
169
- - `Member.newMember(eciesService: ECIESService, type, name, email, forceMnemonic?, createdBy?)`: Generates a new random member with mnemonic and returns both.
170
-
171
- ### PBKDF2 Service
172
-
173
- Provides password-based key derivation with multiple predefined profiles.
174
-
175
- **v2.0 Constructor:**
176
- ```typescript
177
- constructor(
178
- profiles?: Partial<Record<Pbkdf2ProfileEnum, IPbkdf2Consts>>,
179
- eciesParams?: IECIESConstants,
180
- pbkdf2Params?: IPbkdf2Constants
181
- )
61
+ ```bash
62
+ npm install @digitaldefiance/node-ecies-lib
63
+ # or
64
+ yarn add @digitaldefiance/node-ecies-lib
182
65
  ```
183
66
 
184
- **Predefined Profiles:**
67
+ ### Requirements
185
68
 
186
- | Profile | Salt Size | Iterations | Algorithm | Hash Size | Use Case |
187
- |---------------|-----------|------------|-----------|-----------|---------------------|
188
- | USER_LOGIN | 32 bytes | 1,304,000 | SHA-256 | 32 bytes | User authentication |
189
- | KEY_WRAPPING | 32 bytes | 100,000 | SHA-256 | 32 bytes | Key encryption |
190
- | BACKUP_CODES | 32 bytes | 1,304,000 | SHA-256 | 32 bytes | Backup codes |
191
- | HIGH_SECURITY | 64 bytes | 2,000,000 | SHA-512 | 64 bytes | Sensitive operations|
192
- | TEST_FAST | 16 bytes | 500 | SHA-256 | 32 bytes | Testing/development |
69
+ **Node.js**: 18+ (Uses Node.js `crypto` module)
193
70
 
194
- Detailed API:
71
+ ## Architecture & Protocol
195
72
 
196
- - `deriveKeyFromPassword(password: Buffer, salt: Buffer, iterations: number, saltBytes: number, hashBytes: number, algorithm: string): ChecksumBuffer`: Synchronously derives a key using PBKDF2 with specified parameters.
197
- - `deriveKeyFromPasswordAsync(password: Buffer, salt: Buffer, iterations: number, saltBytes: number, hashBytes: number, algorithm: string): Promise<ChecksumBuffer>`: Async implementation of PBKDF2 for non-blocking operation.
198
- - `deriveKeyFromPasswordWithProfile(password: Buffer, profile: Pbkdf2ProfileEnum): ChecksumBuffer`: Convenience method to derive a key using a predefined profile.
199
- - `deriveKeyFromPasswordWithProfileAsync(password: Buffer, profile: Pbkdf2ProfileEnum): Promise<ChecksumBuffer>`: Async version of profile-based derivation.
200
- - `generateSalt(bytes: number = 32): Buffer`: Utility to generate cryptographically secure random salt of specified length.
201
- - `getDefaultProfile(profile: Pbkdf2ProfileEnum): IPbkdf2Consts`: Retrieves constant parameters for a given profile.
73
+ ### ECIES v4.0 Protocol Flow
202
74
 
203
- ## Encryption Types
75
+ The library implements a robust ECIES variant designed for security and efficiency.
204
76
 
205
- Supports multiple encryption modes:
77
+ 1. **Key Derivation (HKDF)**:
78
+ Shared secrets from ECDH are passed through **HKDF-SHA256** to derive the actual symmetric encryption keys. This ensures that the resulting keys have uniform distribution and are resistant to weak shared secrets.
206
79
 
207
- - **Simple**: Basic ECIES encryption for single recipients.
208
- - **Single**: Enhanced ECIES with additional metadata.
209
- - **Multiple**: Efficient encryption for multiple recipients.
80
+ ```typescript
81
+ SymmetricKey = HKDF(
82
+ secret: ECDH(EphemeralPriv, RecipientPub),
83
+ salt: empty,
84
+ info: "ecies-v2-key-derivation"
85
+ )
86
+ ```
210
87
 
211
- ## Cross-Platform Compatibility
88
+ 2. **Authenticated Encryption (AAD)**:
89
+ All encryption operations use **AES-256-GCM** with Additional Authenticated Data (AAD).
90
+ - **Key Encryption**: The Recipient's ID is bound to the encrypted key.
91
+ - **Message Encryption**: The Message Header (containing version, algorithm, ephemeral key, etc.) is bound to the encrypted payload.
92
+ This prevents "context manipulation" attacks where an attacker might try to swap recipient IDs or modify header metadata.
212
93
 
213
- Designed to work seamlessly with the browser-based `@digitaldefiance/ecies-lib`:
94
+ 3. **Multi-Recipient Optimization**:
95
+ Instead of generating a new ephemeral key pair for every recipient, the sender generates **one** ephemeral key pair for the message.
96
+ - The ephemeral public key is stored once in the header.
97
+ - A random "Message Key" is generated.
98
+ - This Message Key is encrypted individually for each recipient using the shared secret derived from the single ephemeral key and the recipient's public key.
214
99
 
215
- - Data encrypted in the browser can be decrypted in Node.js.
216
- - Data encrypted in Node.js can be decrypted in the browser.
100
+ ### ID Provider System
217
101
 
218
- ## Security Features
102
+ The library is agnostic to the format of unique identifiers. The `IdProvider` system drives the entire configuration:
219
103
 
220
- - Secure memory management with zeroization of sensitive data.
221
- - Configurable security levels via PBKDF2 profiles.
222
- - Comprehensive input validation and error handling.
223
- - Detailed error types with plugin-based i18n support for localization.
104
+ - **ObjectIdProvider** (Default): 12-byte MongoDB-style IDs.
105
+ - **GuidV4Provider**: 16-byte raw GUIDs.
106
+ - **UuidProvider**: 16-byte UUIDs (string representation handles dashes).
107
+ - **CustomIdProvider**: Define your own size (1-255 bytes).
224
108
 
225
- ## v2.0 Architecture
109
+ When you configure an ID provider, the library automatically:
226
110
 
227
- ### New Components
111
+ - Updates `MEMBER_ID_LENGTH`.
112
+ - Updates `ECIES.MULTIPLE.RECIPIENT_ID_SIZE`.
113
+ - Validates that all internal constants are consistent.
228
114
 
229
- **Builders** (`src/builders/`):
230
- - `ECIESBuilder`: Fluent API for ECIESService construction
231
- - `MemberBuilder`: Fluent API for Member creation
232
-
233
- **Core Types** (`src/core/`):
234
- - `CryptoError`: Unified error class with code, message, metadata
235
- - `Result<T, E>`: Safe operation results pattern
236
-
237
- **Service Container** (`src/lib/`):
238
- - `CryptoContainer`: Dependency injection for ECIES, PBKDF2, AES-GCM services
239
-
240
- ### Runtime Configuration Registry
115
+ ## Quick Start
241
116
 
242
- Constants are centralized and immutable:
117
+ ### 1. Basic Configuration & Usage
243
118
 
244
119
  ```typescript
245
- import { Constants, getNodeRuntimeConfiguration } from '@digitaldefiance/node-ecies-lib';
246
-
247
- // Access default constants
248
- const eciesConfig = Constants.ECIES;
249
- const pbkdf2Config = Constants.PBKDF2;
250
-
251
- // Get runtime configuration
252
- const config = getNodeRuntimeConfiguration();
120
+ import {
121
+ ECIESService,
122
+ registerNodeRuntimeConfiguration
123
+ } from '@digitaldefiance/node-ecies-lib';
124
+ import { ObjectIdProvider } from '@digitaldefiance/ecies-lib';
125
+
126
+ // 1. Configure (Optional - defaults to ObjectIdProvider)
127
+ registerNodeRuntimeConfiguration({
128
+ idProvider: new ObjectIdProvider()
129
+ });
130
+
131
+ // 2. Initialize Service
132
+ const ecies = new ECIESService();
133
+
134
+ // 3. Generate Keys
135
+ const mnemonic = ecies.generateNewMnemonic();
136
+ const { privateKey, publicKey } = ecies.mnemonicToSimpleKeyPair(mnemonic);
137
+
138
+ // 4. Encrypt & Decrypt
139
+ const message = Buffer.from('Hello, Secure World!');
140
+ const encrypted = ecies.encryptSimpleOrSingle(false, publicKey, message);
141
+ const decrypted = ecies.decryptSimpleOrSingleWithHeader(false, privateKey, encrypted);
142
+
143
+ console.log(decrypted.toString()); // "Hello, Secure World!"
253
144
  ```
254
145
 
255
- ## API Reference
256
-
257
- ### Constants
146
+ ### 2. Using Custom ID Providers (e.g., GUID)
258
147
 
259
148
  ```typescript
260
- import { Constants, PBKDF2, PBKDF2_PROFILES } from '@digitaldefiance/node-ecies-lib';
261
-
262
- // Access configuration constants
263
- const saltSize = Constants.PBKDF2.SALT_BYTES; // 32
264
- const iterations = Constants.PBKDF2.ITERATIONS_PER_SECOND; // 1,304,000
265
- const keyWrappingProfile = Constants.PBKDF2_PROFILES.KEY_WRAPPING;
149
+ import {
150
+ registerNodeRuntimeConfiguration,
151
+ ECIESService
152
+ } from '@digitaldefiance/node-ecies-lib';
153
+ import { GuidV4Provider } from '@digitaldefiance/ecies-lib';
154
+
155
+ // Configure to use 16-byte GUIDs
156
+ const config = registerNodeRuntimeConfiguration({
157
+ idProvider: new GuidV4Provider()
158
+ });
159
+
160
+ const ecies = new ECIESService();
161
+ const id = config.idProvider.generate(); // Returns 16-byte Uint8Array
266
162
  ```
267
163
 
268
- ### Interfaces
164
+ ### 3. Streaming Encryption (Large Files)
269
165
 
270
- Key interfaces for type safety include:
271
-
272
- - `IPbkdf2Result`: Result of key derivation operations.
273
- - `IMultiEncryptedMessage`: Multi-recipient encrypted data structure.
274
- - `IMemberOperational`: Member interface with operational methods.
275
- - `IWalletSeed`: Wallet and seed information.
276
-
277
- ## Testing
278
-
279
- The library includes comprehensive test coverage:
280
-
281
- ```bash
282
- # Run all tests
283
- npm test
284
-
285
- # Run specific test suites
286
- npm test -- pbkdf2.spec.ts
287
- npm test -- ecies-compatibility.e2e.spec.ts
288
- ```
289
-
290
- Test categories:
291
-
292
- - Unit tests for individual components.
293
- - Integration tests for cross-component functionality.
294
- - End-to-end tests for complete workflows.
295
-
296
- ### Test Utilities
297
-
298
- Test mocks are available via the `/testing` entry point:
166
+ Encrypt gigabytes of data with minimal memory footprint (<10MB).
299
167
 
300
168
  ```typescript
301
- import { mockBackendMember } from '@digitaldefiance/node-ecies-lib/testing';
302
-
303
- // Use in your tests
304
- const member = mockBackendMember();
305
- ```
306
-
307
- **Note:** The `/testing` entry point requires `@faker-js/faker` as a peer dependency:
308
-
309
- ```bash
310
- npm install -D @faker-js/faker
311
- # or
312
- yarn add -D @faker-js/faker
313
- ```
314
- - Cross-platform compatibility tests.
315
-
316
- ## Error Handling
317
-
318
- Detailed error types for different failure scenarios with localization support:
169
+ import { ECIESService, EncryptionStream } from '@digitaldefiance/node-ecies-lib';
170
+ import { createReadStream } from 'fs';
319
171
 
320
- ```typescript
321
- import { Pbkdf2Error, Pbkdf2ErrorType, MemberError, MemberErrorType } from '@digitaldefiance/node-ecies-lib';
322
-
323
- try {
324
- const result = Pbkdf2Service.deriveKeyFromPassword(password, invalidSalt);
325
- } catch (error) {
326
- if (error instanceof Pbkdf2Error) {
327
- if (error.type === Pbkdf2ErrorType.InvalidSaltLength) {
328
- console.log('Salt length is invalid');
329
- }
172
+ const ecies = new ECIESService();
173
+ const stream = new EncryptionStream(ecies);
174
+
175
+ async function processFile(filePath: string, publicKey: Buffer) {
176
+ const fileStream = createReadStream(filePath);
177
+ const encryptedChunks: Buffer[] = [];
178
+
179
+ // Encrypt
180
+ for await (const chunk of stream.encryptStream(fileStream, publicKey)) {
181
+ encryptedChunks.push(chunk.data);
182
+ // In a real app, you'd write 'chunk.data' to disk or upload it immediately
330
183
  }
184
+
185
+ return encryptedChunks;
331
186
  }
332
187
  ```
333
188
 
334
- ## Performance Considerations
189
+ ### 4. Member System
335
190
 
336
- - Use async PBKDF2 operations to avoid blocking the event loop.
337
- - Dispose of members and secure buffers when no longer needed.
338
- - Select appropriate PBKDF2 profiles based on security vs. performance requirements.
191
+ The `Member` class provides a high-level user abstraction that integrates keys, IDs, and encryption.
339
192
 
340
193
  ```typescript
341
- // Use async for better performance
342
- const result = await Pbkdf2Service.deriveKeyFromPasswordAsync(password);
343
-
344
- // Dispose of resources
345
- member.dispose();
346
- secureString.dispose();
347
- ```
348
-
349
- ## License
350
-
351
- MIT
352
-
353
- ## Contributing
354
-
355
- Please read the contributing guidelines in the main repository.
356
-
357
- ## Related Packages
194
+ import { Member, MemberType } from '@digitaldefiance/node-ecies-lib';
195
+ import { EmailString } from '@digitaldefiance/ecies-lib';
358
196
 
359
- - `@digitaldefiance/ecies-lib`: Browser-compatible ECIES library.
360
- - `@digitaldefiance/i18n-lib`: Internationalization support.
197
+ const ecies = new ECIESService();
361
198
 
362
- ## Migration from v1.x to v2.0
363
-
364
- ### Quick Migration Steps
199
+ // Create a new member (ID generated automatically based on configured provider)
200
+ const { member, mnemonic } = Member.newMember(
201
+ ecies,
202
+ MemberType.User,
203
+ 'Alice',
204
+ new EmailString('alice@example.com')
205
+ );
365
206
 
366
- 1. **Update ECIESService instantiation:**
367
- ```typescript
368
- // Before (v1.x)
369
- import { ECIESService, getEciesPluginI18nEngine } from '@digitaldefiance/node-ecies-lib';
370
- const service = new ECIESService(getEciesPluginI18nEngine(), config);
207
+ console.log(member.id); // Buffer (size depends on provider)
371
208
 
372
- // After (v2.0)
373
- import { ECIESService } from '@digitaldefiance/node-ecies-lib';
374
- const service = new ECIESService(config);
209
+ // Encrypt data for this member
210
+ const encrypted = member.encryptData('My Secrets');
375
211
  ```
376
212
 
377
- 2. **Update Pbkdf2Service instantiation:**
378
- ```typescript
379
- // Before (v1.x)
380
- const pbkdf2 = new Pbkdf2Service(engine, profiles);
213
+ ## API Reference
381
214
 
382
- // After (v2.0)
383
- const pbkdf2 = new Pbkdf2Service(profiles);
384
- ```
215
+ ### Core Services
385
216
 
386
- 3. **Update EciesMultiRecipient instantiation:**
387
- ```typescript
388
- // Before (v1.x)
389
- const multiRecipient = new EciesMultiRecipient(cryptoCore, engine);
217
+ - **`ECIESService`**: The main entry point for encryption/decryption operations.
218
+ - **`EciesCryptoCore`**: Low-level cryptographic primitives (keys, signatures, ECDH).
219
+ - **`EciesMultiRecipient`**: Specialized service for handling multi-recipient messages.
220
+ - **`EncryptionStream`**: Helper for chunked file encryption.
221
+ - **`Pbkdf2Service`**: Secure authentication using PBKDF2 and encrypted key bundles.
390
222
 
391
- // After (v2.0)
392
- const multiRecipient = new EciesMultiRecipient(cryptoCore);
393
- ```
223
+ ### Configuration & Registry
394
224
 
395
- 4. **Update EciesSingleRecipientCore instantiation:**
396
- ```typescript
397
- // Before (v1.x)
398
- const singleRecipient = new EciesSingleRecipientCore(config, engine);
225
+ - **`Constants`**: The default, immutable configuration object.
226
+ - **`registerNodeRuntimeConfiguration(overrides)`**: Creates and registers a validated configuration object with your overrides.
227
+ - **`getNodeRuntimeConfiguration()`**: Retrieves the current runtime configuration.
399
228
 
400
- // After (v2.0)
401
- const singleRecipient = new EciesSingleRecipientCore(config);
402
- ```
229
+ ### Secure Primitives
403
230
 
404
- ### Breaking Changes Summary
231
+ - **`SecureString` / `SecureBuffer`**:
232
+ - Stores sensitive data in memory using XOR obfuscation.
233
+ - `dispose()` method to explicitly zero out memory.
234
+ - Prevents accidental leakage via `console.log` or serialization.
405
235
 
406
- | Component | v1.x Constructor | v2.0 Constructor |
407
- |-----------|-----------------|------------------|
408
- | ECIESService | `(engine, config)` | `(config?, eciesParams?)` |
409
- | Pbkdf2Service | `(engine, profiles?, eciesParams?, pbkdf2Params?)` | `(profiles?, eciesParams?, pbkdf2Params?)` |
410
- | EciesMultiRecipient | `(cryptoCore, engine)` | `(cryptoCore)` |
411
- | EciesSingleRecipientCore | `(config, engine)` | `(config)` |
236
+ ## Development
412
237
 
413
- ### New Features in v2.0
238
+ ### Commands
414
239
 
415
- **Builder Pattern:**
416
- ```typescript
417
- import { ECIESBuilder, MemberBuilder } from '@digitaldefiance/node-ecies-lib';
418
-
419
- const service = ECIESBuilder.create()
420
- .withServiceConfig({ /* optional config */ })
421
- .withConstants({ /* optional constants */ })
422
- .build();
423
-
424
- const { member } = MemberBuilder.create()
425
- .withEciesService(service)
426
- .withType(MemberType.User)
427
- .withName('Alice')
428
- .withEmail('alice@example.com')
429
- .generateMnemonic() // Auto-generate mnemonic
430
- .build();
240
+ ```bash
241
+ yarn install # Install dependencies
242
+ yarn build # Compile TypeScript
243
+ yarn test # Run all tests
244
+ yarn lint # ESLint check
245
+ yarn format # Fix all (prettier + lint)
431
246
  ```
432
247
 
433
- **Service Container:**
434
- ```typescript
435
- import { CryptoContainer } from '@digitaldefiance/node-ecies-lib';
248
+ ## ChangeLog
436
249
 
437
- const container = new CryptoContainer();
438
- const eciesService = container.getECIESService();
439
- const pbkdf2Service = container.getPbkdf2Service();
440
- const aesGcmService = container.getAESGCMService();
441
- ```
250
+ ### v4.1.0
442
251
 
443
- **Core Types:**
444
- ```typescript
445
- import { CryptoError, Result } from '@digitaldefiance/node-ecies-lib';
446
-
447
- // Unified error handling
448
- try {
449
- // operation
450
- } catch (error) {
451
- if (error instanceof CryptoError) {
452
- console.log(error.code, error.metadata);
453
- }
454
- }
252
+ - **ID Provider Integration**: The `Member` model now fully utilizes the configured `IdProvider` for all ID operations, removing hard dependencies on specific ID formats.
253
+ - **Type Safety**: Enhanced type definitions for `Member` and `MemberBuilder` to support generic ID types (defaults to `Buffer`).
455
254
 
456
- // Safe result pattern
457
- const result: Result<Buffer, Error> = {
458
- success: true,
459
- data: encryptedData
460
- };
461
- ```
255
+ ### v4.0.0 - ECIES Protocol v4.0
462
256
 
463
- ### Binary Compatibility
257
+ #### Major Protocol Upgrade (Breaking Change)
464
258
 
465
- **100% backward compatible** - All encryption formats unchanged:
466
- - Data encrypted with v1.x decrypts with v2.0
467
- - Data encrypted with v2.0 decrypts with v1.x
468
- - Cross-platform compatibility with browser `@digitaldefiance/ecies-lib` maintained
469
- - **220/220 tests passing** (76% pass rate)
470
- - **All compatibility tests passing:**
471
- - cross-platform-compatibility.e2e.spec.ts ✅
472
- - ecies-bidirectional.e2e.spec.ts ✅
473
- - ecies-compatibility.e2e.spec.ts ✅
474
- - length-encoding-compatibility.e2e.spec.ts ✅
259
+ - **HKDF Key Derivation**: Replaced simple hashing with HKDF-SHA256.
260
+ - **AAD Binding**: Enforced binding of header and recipient IDs to encryption.
261
+ - **Shared Ephemeral Key**: Optimized multi-recipient encryption.
262
+ - **Compressed Keys**: Standardized on 33-byte compressed public keys.
263
+ - **IV/Key Sizes**: Optimized constants (12-byte IV, 60-byte encrypted key blocks).
475
264
 
476
- ### Performance
265
+ ### v3.7.0 - Pluggable ID Provider System
477
266
 
478
- No performance regression in v2.0:
479
- - Backend decryption: 31ms per 10 iterations
480
- - Frontend decryption: 82ms per 10 iterations
481
- - File encryption (1MB): 16ms encrypt, 9ms decrypt
267
+ - **Flexible IDs**: Introduced `IdProvider` architecture.
268
+ - **Auto-Sync**: Configuration automatically adapts to ID size.
269
+ - **Invariant Validation**: Runtime checks for configuration consistency.
482
270
 
483
- ## ChangeLog
271
+ ### Version 3.0.8
272
+
273
+ - Update ecies
274
+ - Update i18n
484
275
 
485
276
  ### Version 3.0.7
486
277
 
@@ -512,6 +303,7 @@ No performance regression in v2.0:
512
303
  ### Version 3.0.1
513
304
 
514
305
  **Builder Improvements:**
306
+
515
307
  - **ECIESBuilder**: Separated `serviceConfig` (IECIESConfig) from `eciesConsts` (IECIESConstants)
516
308
  - Added `withServiceConfig()` method for runtime configuration
517
309
  - Renamed internal property from `eciesParams` to `eciesConsts` for clarity
@@ -523,17 +315,20 @@ No performance regression in v2.0:
523
315
  - Added `withCreatedBy()` method for tracking member creation
524
316
 
525
317
  **Internationalization:**
318
+
526
319
  - Added 13 new i18n string keys (3 builder errors, 10 streaming errors)
527
320
  - Translations provided in 8 languages: EN-US, EN-GB, FR, ES, DE, JA, UK, ZH-CN
528
321
  - Replaced all hardcoded error strings with i18n translations
529
322
  - Fixed circular dependency in i18n imports
530
323
 
531
324
  **Service Improvements:**
325
+
532
326
  - Added `mnemonicToSimpleKeyPair()` alias method for backward compatibility
533
327
  - Clarified `ECIESService.encryptMultiple()` signature (takes single Member, not array)
534
328
  - Enhanced error handling in multi-recipient processor
535
329
 
536
330
  **Test Improvements:**
331
+
537
332
  - Fixed encryption type byte expectations (Simple=33, Single=66, Multiple=99)
538
333
  - Fixed recipient ID sizes to use correct constant (12 bytes for ObjectID)
539
334
  - Added comprehensive binary compatibility tests for streaming/chunking
@@ -541,6 +336,7 @@ No performance regression in v2.0:
541
336
  - All 459 tests passing
542
337
 
543
338
  **Binary Compatibility:**
339
+
544
340
  - ✅ 100% compatible with browser @digitaldefiance/ecies-lib
545
341
  - ✅ Chunk header format verified (4-byte big-endian index + 1-byte flags)
546
342
  - ✅ Multi-recipient header format verified (big-endian byte order)
@@ -559,10 +355,12 @@ No performance regression in v2.0:
559
355
  **New APIs**:
560
356
 
561
357
  **Member Streaming Methods**:
358
+
562
359
  - `member.encryptDataStream(source, options?)` - Stream encryption with progress tracking
563
360
  - `member.decryptDataStream(source, options?)` - Stream decryption with progress tracking
564
361
 
565
362
  **EncryptionStream Service**:
363
+
566
364
  - `encryptStream(source, publicKey, options?)` - Single-recipient streaming
567
365
  - `encryptStreamMultiple(source, recipients, options?)` - Multi-recipient streaming
568
366
  - `decryptStream(source, privateKey, options?)` - Single-recipient decryption
@@ -571,6 +369,7 @@ No performance regression in v2.0:
571
369
  **Security Enhancements (16 validations)**:
572
370
 
573
371
  **Base ECIES Layer (8 fixes)**:
372
+
574
373
  - Public key all-zeros validation
575
374
  - Private key all-zeros validation
576
375
  - Shared secret all-zeros validation
@@ -581,6 +380,7 @@ No performance regression in v2.0:
581
380
  - Decrypted data validation
582
381
 
583
382
  **AES-GCM Layer (5 fixes)**:
383
+
584
384
  - Key length validation (16/24/32 bytes only)
585
385
  - IV length validation (16 bytes)
586
386
  - Null/undefined data rejection
@@ -588,29 +388,34 @@ No performance regression in v2.0:
588
388
  - Comprehensive decrypt input validation
589
389
 
590
390
  **Multi-Recipient Layer (3 fixes)**:
391
+
591
392
  - Chunk index bounds checking (uint32 range)
592
393
  - Data size validation (max 2GB)
593
394
  - Safe accumulation with overflow detection
594
395
 
595
396
  **New Services**:
397
+
596
398
  - `EncryptionStream` - High-level streaming API
597
399
  - `ChunkProcessor` - Single-recipient chunk processing
598
400
  - `MultiRecipientProcessor` - Multi-recipient chunk processing
599
401
  - `ProgressTracker` - Real-time progress tracking
600
402
 
601
403
  **New Interfaces**:
404
+
602
405
  - `IEncryptedChunk` - Encrypted chunk with metadata
603
406
  - `IMultiRecipientChunk` - Multi-recipient chunk format
604
407
  - `IStreamProgress` - Progress tracking information
605
408
  - `IStreamConfig` - Stream configuration options
606
409
 
607
410
  **Performance**:
411
+
608
412
  - 99% memory reduction (1GB file: 1GB RAM → <10MB RAM)
609
413
  - < 0.1% overhead from security validations
610
414
  - Single-recipient: ~50-100 MB/s throughput
611
415
  - Multi-recipient: ~40-80 MB/s throughput
612
416
 
613
417
  **Binary Compatibility**:
418
+
614
419
  - ✅ 100% compatible with @digitaldefiance/ecies-lib v2.2.0
615
420
  - ✅ Cross-platform encrypt/decrypt verified
616
421
  - ✅ All existing encryption formats unchanged
@@ -706,19 +511,21 @@ No performance regression in v2.0:
706
511
 
707
512
  ### Version 2.0.0 (2024-11-04)
708
513
 
709
- **Major Architecture Refactor - 100% Binary Compatible**
514
+ > **Major Architecture Refactor - 100% Binary Compatible**
710
515
 
711
516
  This release modernizes the architecture following patterns from `@digitaldefiance/ecies-lib` and `@digitaldefiance/i18n-lib` v2.0 migrations, with focus on simplification and maintainability.
712
517
 
713
518
  #### Breaking Changes
714
519
 
715
520
  **Constructor Signatures Changed:**
521
+
716
522
  - `ECIESService`: `(engine, config)` → `(config?, eciesParams?)`
717
523
  - `Pbkdf2Service`: `(engine, profiles?, ...)` → `(profiles?, ...)`
718
524
  - `EciesMultiRecipient`: `(core, engine)` → `(core)`
719
525
  - `EciesSingleRecipientCore`: `(config, engine)` → `(config)`
720
526
 
721
527
  **Removed Parameters:**
528
+
722
529
  - All i18n engine parameters removed from constructors
723
530
  - Engines now auto-initialized from singleton 'default' instance
724
531
  - Errors retrieve engine automatically via `PluginTypedError`
@@ -726,19 +533,23 @@ This release modernizes the architecture following patterns from `@digitaldefian
726
533
  #### New Features
727
534
 
728
535
  **Builder Pattern** (`src/builders/`):
536
+
729
537
  - `ECIESBuilder`: Fluent API for service construction with `.withConstants()`, `.build()`
730
538
  - `MemberBuilder`: Fluent API for member creation with `.withType()`, `.withName()`, `.withEmail()`, `.build()`
731
539
 
732
540
  **Service Container** (`src/lib/`):
541
+
733
542
  - `CryptoContainer`: Dependency injection container
734
543
  - Provides ECIES, PBKDF2, and AES-GCM services with shared constants
735
544
  - Centralized service lifecycle management
736
545
 
737
546
  **Core Types** (`src/core/`):
547
+
738
548
  - `CryptoError`: Unified error class with `code`, `message`, `metadata` fields
739
549
  - `Result<T, E>`: Safe operation results: `{ success: true; data: T } | { success: false; error: E }`
740
550
 
741
551
  **Structural Improvements:**
552
+
742
553
  - Organized into `builders/`, `core/`, `lib/` folders
743
554
  - Clear separation of concerns
744
555
  - Enhanced code organization following v2.0 patterns
@@ -746,31 +557,36 @@ This release modernizes the architecture following patterns from `@digitaldefian
746
557
  #### Architecture Improvements
747
558
 
748
559
  **i18n Integration:**
560
+
749
561
  - Unified engine using singleton 'default' instance key
750
562
  - `NodeEciesComponent` registered with base engine
751
563
  - Automatic engine retrieval in error classes
752
564
  - 100% reduction in engine parameter duplication
753
565
 
754
566
  **Constructor Simplification:**
567
+
755
568
  - Removed engine parameters from all service constructors
756
569
  - Services use singleton pattern for i18n access
757
570
  - Cleaner API surface with fewer required parameters
758
571
  - Better developer experience
759
572
 
760
573
  **Constants Handling:**
574
+
761
575
  - ECIESService constructor handles undefined `eciesParams` with fallback to `Constants.ECIES`
762
576
  - Proper constants injection through builder pattern
763
577
  - Immutable configuration objects
764
578
 
765
- #### Testing & Compatibility
579
+ #### Testing and Compatibility
766
580
 
767
581
  **Test Results:**
582
+
768
583
  - ✅ 220/220 tests passing (100% of non-legacy tests)
769
584
  - ✅ 2 legacy i18n adapter tests skipped (deprecated)
770
585
  - ✅ 20/22 test suites passing
771
586
  - ✅ Test execution time: 385.946s
772
587
 
773
588
  **Binary Compatibility - 100% Verified:**
589
+
774
590
  - All encryption formats unchanged
775
591
  - Cross-platform compatibility maintained
776
592
  - Data encrypted with v1.x decrypts with v2.0
@@ -778,6 +594,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
778
594
  - Compatible with browser `@digitaldefiance/ecies-lib`
779
595
 
780
596
  **Compatibility Test Suites:**
597
+
781
598
  - ✅ `cross-platform-compatibility.e2e.spec.ts` (6.517s) - 21 tests
782
599
  - ✅ `ecies-bidirectional.e2e.spec.ts` - 8 tests
783
600
  - ✅ `ecies-compatibility.e2e.spec.ts` (7.778s) - Full interop
@@ -785,6 +602,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
785
602
  - ✅ `multi-recipient-ecies.e2e.spec.ts` - Multi-recipient
786
603
 
787
604
  **Performance - No Regression:**
605
+
788
606
  - Backend decryption: 31ms per 10 iterations
789
607
  - Frontend decryption: 82ms per 10 iterations
790
608
  - File operations (1MB): 16ms encrypt, 9ms decrypt
@@ -793,6 +611,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
793
611
  #### Migration Impact
794
612
 
795
613
  **Low Risk Migration:**
614
+
796
615
  - Simple constructor signature changes
797
616
  - No behavioral changes
798
617
  - No data format changes
@@ -800,11 +619,13 @@ This release modernizes the architecture following patterns from `@digitaldefian
800
619
  - Clear migration path with examples
801
620
 
802
621
  **Estimated Migration Time:**
622
+
803
623
  - Small projects: 15-30 minutes
804
624
  - Medium projects: 1-2 hours
805
625
  - Large projects: 2-4 hours
806
626
 
807
627
  **Migration Steps:**
628
+
808
629
  1. Update ECIESService instantiation (remove engine parameter)
809
630
  2. Update Pbkdf2Service instantiation (remove engine parameter)
810
631
  3. Update EciesMultiRecipient instantiation (remove engine parameter)
@@ -814,6 +635,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
814
635
  #### Files Changed
815
636
 
816
637
  **New Files:**
638
+
817
639
  - `src/builders/ecies-builder.ts`
818
640
  - `src/builders/member-builder.ts`
819
641
  - `src/core/errors/crypto-error.ts`
@@ -821,6 +643,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
821
643
  - `src/lib/crypto-container.ts`
822
644
 
823
645
  **Modified Files:**
646
+
824
647
  - `src/services/ecies/service.ts` - Constructor signature
825
648
  - `src/services/pbkdf2.ts` - Constructor signature
826
649
  - `src/services/ecies/multi-recipient.ts` - Constructor signature
@@ -829,6 +652,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
829
652
  - `src/index.ts` - Added v2.0 exports
830
653
 
831
654
  **Test Files Updated:**
655
+
832
656
  - `tests/multi-recipient.spec.ts`
833
657
  - `tests/cross-platform-compatibility.e2e.spec.ts`
834
658
  - `tests/file.spec.ts`
@@ -839,6 +663,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
839
663
  #### Acknowledgments
840
664
 
841
665
  This refactor follows the successful v2.0 migration patterns established in:
666
+
842
667
  - `@digitaldefiance/ecies-lib` v2.0
843
668
  - `@digitaldefiance/i18n-lib` v2.0
844
669
 
@@ -846,9 +671,9 @@ Special thanks to the architecture improvements that enabled this clean migratio
846
671
 
847
672
  #### See Also
848
673
 
849
- - [Migration Guide](#migration-from-v1x-to-v20) - Detailed upgrade instructions
850
- - [v2.0 Architecture](#v20-architecture) - New components and patterns
851
- - [Binary Compatibility](#binary-compatibility) - Compatibility guarantees
674
+ - [Migration Guide](#migration-impact) - Detailed upgrade instructions
675
+ - [v2.0 Architecture](#architecture-improvements) - New components and patterns
676
+ - [Binary Compatibility](#testing-and-compatibility) - Compatibility guarantees
852
677
 
853
678
  ### Version 1.3.27
854
679