@digitaldefiance/node-ecies-lib 3.0.8 → 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 +229 -409
  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,272 @@
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
- );
9
+ Part of [Express Suite](https://github.com/Digital-Defiance/express-suite)
49
10
 
50
- // Stream encrypt large file with <10MB RAM
51
- const fileStream = createReadStream('large-file.bin');
52
- const chunks: Buffer[] = [];
11
+ > Current Version: v4.1.0
53
12
 
54
- for await (const chunk of member.encryptDataStream(fileStream)) {
55
- chunks.push(chunk.data);
56
- }
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.
57
14
 
58
- // Stream decrypt
59
- const decryptedChunks: Buffer[] = [];
60
- for await (const chunk of member.decryptDataStream(chunks)) {
61
- decryptedChunks.push(chunk);
62
- }
63
- ```
15
+ ## Features
64
16
 
65
- ### v2.0 Simplified API
17
+ ### 🛡️ Core Cryptography (Protocol v4.0)
66
18
 
67
- ```typescript
68
- import { ECIESService, Member, MemberType, EmailString } from '@digitaldefiance/node-ecies-lib';
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.
69
32
 
70
- // Initialize the ECIES service (automatic i18n setup)
71
- const eciesService = new ECIESService();
33
+ ### 🆔 Identity & Management
72
34
 
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
- );
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.
80
43
 
81
- // Encrypt data
82
- const message = 'Hello, secure world!';
83
- const encrypted = member.encryptData(message);
44
+ ### 🚀 Advanced Capabilities
84
45
 
85
- // Decrypt data
86
- const decrypted = member.decryptData(encrypted);
87
- console.log(decrypted.toString()); // "Hello, secure world!"
88
- ```
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).
89
50
 
90
- ### v2.0 Builder Pattern
51
+ ## Compatibility
91
52
 
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
- ```
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).
119
54
 
120
- ## Core Components
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).
121
56
 
122
- ### ECIESService
57
+ This cross-platform interoperability is verified through extensive E2E testing suites.
123
58
 
124
- The main service class providing encryption, decryption, key management, and mnemonic generation.
125
-
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.
194
+ import { Member, MemberType } from '@digitaldefiance/node-ecies-lib';
195
+ import { EmailString } from '@digitaldefiance/ecies-lib';
356
196
 
357
- ## Related Packages
197
+ const ecies = new ECIESService();
358
198
 
359
- - `@digitaldefiance/ecies-lib`: Browser-compatible ECIES library.
360
- - `@digitaldefiance/i18n-lib`: Internationalization support.
361
-
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';
436
-
437
- const container = new CryptoContainer();
438
- const eciesService = container.getECIESService();
439
- const pbkdf2Service = container.getPbkdf2Service();
440
- const aesGcmService = container.getAESGCMService();
441
- ```
248
+ ## ChangeLog
442
249
 
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
- }
250
+ ### v4.1.0
455
251
 
456
- // Safe result pattern
457
- const result: Result<Buffer, Error> = {
458
- success: true,
459
- data: encryptedData
460
- };
461
- ```
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`).
462
254
 
463
- ### Binary Compatibility
255
+ ### v4.0.0 - ECIES Protocol v4.0
464
256
 
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 ✅
257
+ #### Major Protocol Upgrade (Breaking Change)
475
258
 
476
- ### Performance
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).
477
264
 
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
265
+ ### v3.7.0 - Pluggable ID Provider System
482
266
 
483
- ## ChangeLog
267
+ - **Flexible IDs**: Introduced `IdProvider` architecture.
268
+ - **Auto-Sync**: Configuration automatically adapts to ID size.
269
+ - **Invariant Validation**: Runtime checks for configuration consistency.
484
270
 
485
271
  ### Version 3.0.8
486
272
 
@@ -517,6 +303,7 @@ No performance regression in v2.0:
517
303
  ### Version 3.0.1
518
304
 
519
305
  **Builder Improvements:**
306
+
520
307
  - **ECIESBuilder**: Separated `serviceConfig` (IECIESConfig) from `eciesConsts` (IECIESConstants)
521
308
  - Added `withServiceConfig()` method for runtime configuration
522
309
  - Renamed internal property from `eciesParams` to `eciesConsts` for clarity
@@ -528,17 +315,20 @@ No performance regression in v2.0:
528
315
  - Added `withCreatedBy()` method for tracking member creation
529
316
 
530
317
  **Internationalization:**
318
+
531
319
  - Added 13 new i18n string keys (3 builder errors, 10 streaming errors)
532
320
  - Translations provided in 8 languages: EN-US, EN-GB, FR, ES, DE, JA, UK, ZH-CN
533
321
  - Replaced all hardcoded error strings with i18n translations
534
322
  - Fixed circular dependency in i18n imports
535
323
 
536
324
  **Service Improvements:**
325
+
537
326
  - Added `mnemonicToSimpleKeyPair()` alias method for backward compatibility
538
327
  - Clarified `ECIESService.encryptMultiple()` signature (takes single Member, not array)
539
328
  - Enhanced error handling in multi-recipient processor
540
329
 
541
330
  **Test Improvements:**
331
+
542
332
  - Fixed encryption type byte expectations (Simple=33, Single=66, Multiple=99)
543
333
  - Fixed recipient ID sizes to use correct constant (12 bytes for ObjectID)
544
334
  - Added comprehensive binary compatibility tests for streaming/chunking
@@ -546,6 +336,7 @@ No performance regression in v2.0:
546
336
  - All 459 tests passing
547
337
 
548
338
  **Binary Compatibility:**
339
+
549
340
  - ✅ 100% compatible with browser @digitaldefiance/ecies-lib
550
341
  - ✅ Chunk header format verified (4-byte big-endian index + 1-byte flags)
551
342
  - ✅ Multi-recipient header format verified (big-endian byte order)
@@ -564,10 +355,12 @@ No performance regression in v2.0:
564
355
  **New APIs**:
565
356
 
566
357
  **Member Streaming Methods**:
358
+
567
359
  - `member.encryptDataStream(source, options?)` - Stream encryption with progress tracking
568
360
  - `member.decryptDataStream(source, options?)` - Stream decryption with progress tracking
569
361
 
570
362
  **EncryptionStream Service**:
363
+
571
364
  - `encryptStream(source, publicKey, options?)` - Single-recipient streaming
572
365
  - `encryptStreamMultiple(source, recipients, options?)` - Multi-recipient streaming
573
366
  - `decryptStream(source, privateKey, options?)` - Single-recipient decryption
@@ -576,6 +369,7 @@ No performance regression in v2.0:
576
369
  **Security Enhancements (16 validations)**:
577
370
 
578
371
  **Base ECIES Layer (8 fixes)**:
372
+
579
373
  - Public key all-zeros validation
580
374
  - Private key all-zeros validation
581
375
  - Shared secret all-zeros validation
@@ -586,6 +380,7 @@ No performance regression in v2.0:
586
380
  - Decrypted data validation
587
381
 
588
382
  **AES-GCM Layer (5 fixes)**:
383
+
589
384
  - Key length validation (16/24/32 bytes only)
590
385
  - IV length validation (16 bytes)
591
386
  - Null/undefined data rejection
@@ -593,29 +388,34 @@ No performance regression in v2.0:
593
388
  - Comprehensive decrypt input validation
594
389
 
595
390
  **Multi-Recipient Layer (3 fixes)**:
391
+
596
392
  - Chunk index bounds checking (uint32 range)
597
393
  - Data size validation (max 2GB)
598
394
  - Safe accumulation with overflow detection
599
395
 
600
396
  **New Services**:
397
+
601
398
  - `EncryptionStream` - High-level streaming API
602
399
  - `ChunkProcessor` - Single-recipient chunk processing
603
400
  - `MultiRecipientProcessor` - Multi-recipient chunk processing
604
401
  - `ProgressTracker` - Real-time progress tracking
605
402
 
606
403
  **New Interfaces**:
404
+
607
405
  - `IEncryptedChunk` - Encrypted chunk with metadata
608
406
  - `IMultiRecipientChunk` - Multi-recipient chunk format
609
407
  - `IStreamProgress` - Progress tracking information
610
408
  - `IStreamConfig` - Stream configuration options
611
409
 
612
410
  **Performance**:
411
+
613
412
  - 99% memory reduction (1GB file: 1GB RAM → <10MB RAM)
614
413
  - < 0.1% overhead from security validations
615
414
  - Single-recipient: ~50-100 MB/s throughput
616
415
  - Multi-recipient: ~40-80 MB/s throughput
617
416
 
618
417
  **Binary Compatibility**:
418
+
619
419
  - ✅ 100% compatible with @digitaldefiance/ecies-lib v2.2.0
620
420
  - ✅ Cross-platform encrypt/decrypt verified
621
421
  - ✅ All existing encryption formats unchanged
@@ -711,19 +511,21 @@ No performance regression in v2.0:
711
511
 
712
512
  ### Version 2.0.0 (2024-11-04)
713
513
 
714
- **Major Architecture Refactor - 100% Binary Compatible**
514
+ > **Major Architecture Refactor - 100% Binary Compatible**
715
515
 
716
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.
717
517
 
718
518
  #### Breaking Changes
719
519
 
720
520
  **Constructor Signatures Changed:**
521
+
721
522
  - `ECIESService`: `(engine, config)` → `(config?, eciesParams?)`
722
523
  - `Pbkdf2Service`: `(engine, profiles?, ...)` → `(profiles?, ...)`
723
524
  - `EciesMultiRecipient`: `(core, engine)` → `(core)`
724
525
  - `EciesSingleRecipientCore`: `(config, engine)` → `(config)`
725
526
 
726
527
  **Removed Parameters:**
528
+
727
529
  - All i18n engine parameters removed from constructors
728
530
  - Engines now auto-initialized from singleton 'default' instance
729
531
  - Errors retrieve engine automatically via `PluginTypedError`
@@ -731,19 +533,23 @@ This release modernizes the architecture following patterns from `@digitaldefian
731
533
  #### New Features
732
534
 
733
535
  **Builder Pattern** (`src/builders/`):
536
+
734
537
  - `ECIESBuilder`: Fluent API for service construction with `.withConstants()`, `.build()`
735
538
  - `MemberBuilder`: Fluent API for member creation with `.withType()`, `.withName()`, `.withEmail()`, `.build()`
736
539
 
737
540
  **Service Container** (`src/lib/`):
541
+
738
542
  - `CryptoContainer`: Dependency injection container
739
543
  - Provides ECIES, PBKDF2, and AES-GCM services with shared constants
740
544
  - Centralized service lifecycle management
741
545
 
742
546
  **Core Types** (`src/core/`):
547
+
743
548
  - `CryptoError`: Unified error class with `code`, `message`, `metadata` fields
744
549
  - `Result<T, E>`: Safe operation results: `{ success: true; data: T } | { success: false; error: E }`
745
550
 
746
551
  **Structural Improvements:**
552
+
747
553
  - Organized into `builders/`, `core/`, `lib/` folders
748
554
  - Clear separation of concerns
749
555
  - Enhanced code organization following v2.0 patterns
@@ -751,31 +557,36 @@ This release modernizes the architecture following patterns from `@digitaldefian
751
557
  #### Architecture Improvements
752
558
 
753
559
  **i18n Integration:**
560
+
754
561
  - Unified engine using singleton 'default' instance key
755
562
  - `NodeEciesComponent` registered with base engine
756
563
  - Automatic engine retrieval in error classes
757
564
  - 100% reduction in engine parameter duplication
758
565
 
759
566
  **Constructor Simplification:**
567
+
760
568
  - Removed engine parameters from all service constructors
761
569
  - Services use singleton pattern for i18n access
762
570
  - Cleaner API surface with fewer required parameters
763
571
  - Better developer experience
764
572
 
765
573
  **Constants Handling:**
574
+
766
575
  - ECIESService constructor handles undefined `eciesParams` with fallback to `Constants.ECIES`
767
576
  - Proper constants injection through builder pattern
768
577
  - Immutable configuration objects
769
578
 
770
- #### Testing & Compatibility
579
+ #### Testing and Compatibility
771
580
 
772
581
  **Test Results:**
582
+
773
583
  - ✅ 220/220 tests passing (100% of non-legacy tests)
774
584
  - ✅ 2 legacy i18n adapter tests skipped (deprecated)
775
585
  - ✅ 20/22 test suites passing
776
586
  - ✅ Test execution time: 385.946s
777
587
 
778
588
  **Binary Compatibility - 100% Verified:**
589
+
779
590
  - All encryption formats unchanged
780
591
  - Cross-platform compatibility maintained
781
592
  - Data encrypted with v1.x decrypts with v2.0
@@ -783,6 +594,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
783
594
  - Compatible with browser `@digitaldefiance/ecies-lib`
784
595
 
785
596
  **Compatibility Test Suites:**
597
+
786
598
  - ✅ `cross-platform-compatibility.e2e.spec.ts` (6.517s) - 21 tests
787
599
  - ✅ `ecies-bidirectional.e2e.spec.ts` - 8 tests
788
600
  - ✅ `ecies-compatibility.e2e.spec.ts` (7.778s) - Full interop
@@ -790,6 +602,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
790
602
  - ✅ `multi-recipient-ecies.e2e.spec.ts` - Multi-recipient
791
603
 
792
604
  **Performance - No Regression:**
605
+
793
606
  - Backend decryption: 31ms per 10 iterations
794
607
  - Frontend decryption: 82ms per 10 iterations
795
608
  - File operations (1MB): 16ms encrypt, 9ms decrypt
@@ -798,6 +611,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
798
611
  #### Migration Impact
799
612
 
800
613
  **Low Risk Migration:**
614
+
801
615
  - Simple constructor signature changes
802
616
  - No behavioral changes
803
617
  - No data format changes
@@ -805,11 +619,13 @@ This release modernizes the architecture following patterns from `@digitaldefian
805
619
  - Clear migration path with examples
806
620
 
807
621
  **Estimated Migration Time:**
622
+
808
623
  - Small projects: 15-30 minutes
809
624
  - Medium projects: 1-2 hours
810
625
  - Large projects: 2-4 hours
811
626
 
812
627
  **Migration Steps:**
628
+
813
629
  1. Update ECIESService instantiation (remove engine parameter)
814
630
  2. Update Pbkdf2Service instantiation (remove engine parameter)
815
631
  3. Update EciesMultiRecipient instantiation (remove engine parameter)
@@ -819,6 +635,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
819
635
  #### Files Changed
820
636
 
821
637
  **New Files:**
638
+
822
639
  - `src/builders/ecies-builder.ts`
823
640
  - `src/builders/member-builder.ts`
824
641
  - `src/core/errors/crypto-error.ts`
@@ -826,6 +643,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
826
643
  - `src/lib/crypto-container.ts`
827
644
 
828
645
  **Modified Files:**
646
+
829
647
  - `src/services/ecies/service.ts` - Constructor signature
830
648
  - `src/services/pbkdf2.ts` - Constructor signature
831
649
  - `src/services/ecies/multi-recipient.ts` - Constructor signature
@@ -834,6 +652,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
834
652
  - `src/index.ts` - Added v2.0 exports
835
653
 
836
654
  **Test Files Updated:**
655
+
837
656
  - `tests/multi-recipient.spec.ts`
838
657
  - `tests/cross-platform-compatibility.e2e.spec.ts`
839
658
  - `tests/file.spec.ts`
@@ -844,6 +663,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
844
663
  #### Acknowledgments
845
664
 
846
665
  This refactor follows the successful v2.0 migration patterns established in:
666
+
847
667
  - `@digitaldefiance/ecies-lib` v2.0
848
668
  - `@digitaldefiance/i18n-lib` v2.0
849
669
 
@@ -851,9 +671,9 @@ Special thanks to the architecture improvements that enabled this clean migratio
851
671
 
852
672
  #### See Also
853
673
 
854
- - [Migration Guide](#migration-from-v1x-to-v20) - Detailed upgrade instructions
855
- - [v2.0 Architecture](#v20-architecture) - New components and patterns
856
- - [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
857
677
 
858
678
  ### Version 1.3.27
859
679