@digitaldefiance/node-ecies-lib 3.0.8 → 4.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +232 -408
- package/package.json +3 -3
- package/src/builders/member-builder.d.ts +1 -2
- package/src/builders/member-builder.d.ts.map +1 -1
- package/src/builders/member-builder.js.map +1 -1
- package/src/constants.d.ts.map +1 -1
- package/src/constants.js +38 -9
- package/src/constants.js.map +1 -1
- package/src/i18n/ecies-i18n-factory.d.ts +2 -52
- package/src/i18n/ecies-i18n-factory.d.ts.map +1 -1
- package/src/i18n/ecies-i18n-factory.js +9 -63
- package/src/i18n/ecies-i18n-factory.js.map +1 -1
- package/src/i18n/node-ecies-i18n-setup.d.ts.map +1 -1
- package/src/i18n/node-ecies-i18n-setup.js +5 -53
- package/src/i18n/node-ecies-i18n-setup.js.map +1 -1
- package/src/i18n/node-keys.d.ts +57 -0
- package/src/i18n/node-keys.d.ts.map +1 -0
- package/src/i18n/node-keys.js +67 -0
- package/src/i18n/node-keys.js.map +1 -0
- package/src/i18n/translations/de.d.ts +1 -1
- package/src/i18n/translations/de.d.ts.map +1 -1
- package/src/i18n/translations/de.js +51 -46
- package/src/i18n/translations/de.js.map +1 -1
- package/src/i18n/translations/en-GB.d.ts +1 -1
- package/src/i18n/translations/en-GB.d.ts.map +1 -1
- package/src/i18n/translations/en-GB.js +51 -46
- package/src/i18n/translations/en-GB.js.map +1 -1
- package/src/i18n/translations/en-US.d.ts +1 -1
- package/src/i18n/translations/en-US.d.ts.map +1 -1
- package/src/i18n/translations/en-US.js +52 -46
- package/src/i18n/translations/en-US.js.map +1 -1
- package/src/i18n/translations/es.d.ts +1 -1
- package/src/i18n/translations/es.d.ts.map +1 -1
- package/src/i18n/translations/es.js +51 -46
- package/src/i18n/translations/es.js.map +1 -1
- package/src/i18n/translations/fr.d.ts +1 -1
- package/src/i18n/translations/fr.d.ts.map +1 -1
- package/src/i18n/translations/fr.js +51 -46
- package/src/i18n/translations/fr.js.map +1 -1
- package/src/i18n/translations/index.d.ts +2 -0
- package/src/i18n/translations/index.d.ts.map +1 -1
- package/src/i18n/translations/index.js +5 -1
- package/src/i18n/translations/index.js.map +1 -1
- package/src/i18n/translations/ja.d.ts +1 -1
- package/src/i18n/translations/ja.d.ts.map +1 -1
- package/src/i18n/translations/ja.js +51 -46
- package/src/i18n/translations/ja.js.map +1 -1
- package/src/i18n/translations/uk.d.ts +1 -1
- package/src/i18n/translations/uk.d.ts.map +1 -1
- package/src/i18n/translations/uk.js +51 -46
- package/src/i18n/translations/uk.js.map +1 -1
- package/src/i18n/translations/zh-cn.d.ts +1 -1
- package/src/i18n/translations/zh-cn.d.ts.map +1 -1
- package/src/i18n/translations/zh-cn.js +51 -46
- package/src/i18n/translations/zh-cn.js.map +1 -1
- package/src/interfaces/authenticated-cipher.d.ts +3 -0
- package/src/interfaces/authenticated-cipher.d.ts.map +1 -1
- package/src/interfaces/authenticated-decipher.d.ts +3 -0
- package/src/interfaces/authenticated-decipher.d.ts.map +1 -1
- package/src/interfaces/backend-member-operational.d.ts +1 -1
- package/src/interfaces/backend-member-operational.d.ts.map +1 -1
- package/src/interfaces/constants.d.ts +26 -17
- package/src/interfaces/constants.d.ts.map +1 -1
- package/src/interfaces/multi-encrypted-parsed-header.d.ts +5 -2
- package/src/interfaces/multi-encrypted-parsed-header.d.ts.map +1 -1
- package/src/interfaces/multi-recipient-chunk.d.ts +16 -0
- package/src/interfaces/multi-recipient-chunk.d.ts.map +1 -1
- package/src/interfaces/multi-recipient-chunk.js +10 -0
- package/src/interfaces/multi-recipient-chunk.js.map +1 -1
- package/src/lib/index.d.ts +2 -0
- package/src/lib/index.d.ts.map +1 -1
- package/src/lib/index.js +2 -0
- package/src/lib/index.js.map +1 -1
- package/src/lib/invariant-validator.d.ts +62 -0
- package/src/lib/invariant-validator.d.ts.map +1 -0
- package/src/lib/invariant-validator.js +108 -0
- package/src/lib/invariant-validator.js.map +1 -0
- package/src/lib/invariants/index.d.ts +8 -0
- package/src/lib/invariants/index.d.ts.map +1 -0
- package/src/lib/invariants/index.js +12 -0
- package/src/lib/invariants/index.js.map +1 -0
- package/src/lib/invariants/recipient-id-consistency.d.ts +22 -0
- package/src/lib/invariants/recipient-id-consistency.d.ts.map +1 -0
- package/src/lib/invariants/recipient-id-consistency.js +62 -0
- package/src/lib/invariants/recipient-id-consistency.js.map +1 -0
- package/src/member.d.ts +6 -6
- package/src/member.d.ts.map +1 -1
- package/src/member.js +13 -20
- package/src/member.js.map +1 -1
- package/src/services/aes-gcm.d.ts +2 -2
- package/src/services/aes-gcm.d.ts.map +1 -1
- package/src/services/aes-gcm.js +8 -2
- package/src/services/aes-gcm.js.map +1 -1
- package/src/services/ecies/crypto-core.d.ts +21 -0
- package/src/services/ecies/crypto-core.d.ts.map +1 -1
- package/src/services/ecies/crypto-core.js +62 -7
- package/src/services/ecies/crypto-core.js.map +1 -1
- package/src/services/ecies/multi-recipient.d.ts +11 -7
- package/src/services/ecies/multi-recipient.d.ts.map +1 -1
- package/src/services/ecies/multi-recipient.js +200 -71
- package/src/services/ecies/multi-recipient.js.map +1 -1
- package/src/services/ecies/service.d.ts +1 -1
- package/src/services/ecies/service.d.ts.map +1 -1
- package/src/services/ecies/service.js +2 -2
- package/src/services/ecies/service.js.map +1 -1
- package/src/services/ecies/single-recipient.d.ts +1 -1
- package/src/services/ecies/single-recipient.d.ts.map +1 -1
- package/src/services/ecies/single-recipient.js +76 -43
- package/src/services/ecies/single-recipient.js.map +1 -1
- package/src/services/encryption-stream.js +3 -4
- package/src/services/encryption-stream.js.map +1 -1
- package/src/services/multi-recipient-processor.d.ts +42 -9
- package/src/services/multi-recipient-processor.d.ts.map +1 -1
- package/src/services/multi-recipient-processor.js +273 -177
- package/src/services/multi-recipient-processor.js.map +1 -1
- package/src/test-mocks/mock-backend-member.d.ts +7 -8
- package/src/test-mocks/mock-backend-member.d.ts.map +1 -1
- package/src/test-mocks/mock-backend-member.js +4 -4
- package/src/test-mocks/mock-backend-member.js.map +1 -1
package/README.md
CHANGED
|
@@ -1,486 +1,276 @@
|
|
|
1
1
|
# @digitaldefiance/node-ecies-lib
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/@digitaldefiance/node-ecies-lib)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
[](https://github.com/Digital-Defiance/ecies-lib)
|
|
4
6
|
|
|
5
|
-
|
|
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
|
-
|
|
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
|
-
|
|
51
|
-
const fileStream = createReadStream('large-file.bin');
|
|
52
|
-
const chunks: Buffer[] = [];
|
|
11
|
+
> Current Version: v4.1.0
|
|
53
12
|
|
|
54
|
-
|
|
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
|
-
|
|
59
|
-
const decryptedChunks: Buffer[] = [];
|
|
60
|
-
for await (const chunk of member.decryptDataStream(chunks)) {
|
|
61
|
-
decryptedChunks.push(chunk);
|
|
62
|
-
}
|
|
63
|
-
```
|
|
15
|
+
## Features
|
|
64
16
|
|
|
65
|
-
###
|
|
17
|
+
### 🛡️ Core Cryptography (Protocol v4.0)
|
|
66
18
|
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
71
|
-
const eciesService = new ECIESService();
|
|
33
|
+
### 🆔 Identity & Management
|
|
72
34
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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
|
-
|
|
82
|
-
const message = 'Hello, secure world!';
|
|
83
|
-
const encrypted = member.encryptData(message);
|
|
44
|
+
### 🚀 Advanced Capabilities
|
|
84
45
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
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
|
-
|
|
51
|
+
## Compatibility
|
|
91
52
|
|
|
92
|
-
|
|
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
|
-
|
|
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
|
-
|
|
57
|
+
This cross-platform interoperability is verified through extensive E2E testing suites.
|
|
123
58
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
**v2.0 Constructor:**
|
|
127
|
-
```typescript
|
|
128
|
-
constructor(config?: Partial<IECIESConfig>, eciesParams?: IECIESConstants)
|
|
129
|
-
```
|
|
59
|
+
## Installation
|
|
130
60
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
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
|
-
|
|
67
|
+
### Requirements
|
|
185
68
|
|
|
186
|
-
|
|
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
|
-
|
|
71
|
+
## Architecture & Protocol
|
|
195
72
|
|
|
196
|
-
|
|
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
|
-
|
|
75
|
+
The library implements a robust ECIES variant designed for security and efficiency.
|
|
204
76
|
|
|
205
|
-
|
|
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
|
-
|
|
208
|
-
|
|
209
|
-
|
|
80
|
+
```typescript
|
|
81
|
+
SymmetricKey = HKDF(
|
|
82
|
+
secret: ECDH(EphemeralPriv, RecipientPub),
|
|
83
|
+
salt: empty,
|
|
84
|
+
info: "ecies-v2-key-derivation"
|
|
85
|
+
)
|
|
86
|
+
```
|
|
210
87
|
|
|
211
|
-
|
|
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
|
-
|
|
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
|
-
|
|
216
|
-
- Data encrypted in Node.js can be decrypted in the browser.
|
|
100
|
+
### ID Provider System
|
|
217
101
|
|
|
218
|
-
|
|
102
|
+
The library is agnostic to the format of unique identifiers. The `IdProvider` system drives the entire configuration:
|
|
219
103
|
|
|
220
|
-
-
|
|
221
|
-
-
|
|
222
|
-
-
|
|
223
|
-
-
|
|
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
|
-
|
|
109
|
+
When you configure an ID provider, the library automatically:
|
|
226
110
|
|
|
227
|
-
|
|
111
|
+
- Updates `MEMBER_ID_LENGTH`.
|
|
112
|
+
- Updates `ECIES.MULTIPLE.RECIPIENT_ID_SIZE`.
|
|
113
|
+
- Validates that all internal constants are consistent.
|
|
228
114
|
|
|
229
|
-
|
|
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
|
-
|
|
117
|
+
### 1. Basic Configuration & Usage
|
|
243
118
|
|
|
244
119
|
```typescript
|
|
245
|
-
import {
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
//
|
|
252
|
-
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
### Constants
|
|
146
|
+
### 2. Using Custom ID Providers (e.g., GUID)
|
|
258
147
|
|
|
259
148
|
```typescript
|
|
260
|
-
import {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
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
|
-
###
|
|
164
|
+
### 3. Streaming Encryption (Large Files)
|
|
269
165
|
|
|
270
|
-
|
|
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 {
|
|
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
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
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
|
-
|
|
189
|
+
### 4. Member System
|
|
335
190
|
|
|
336
|
-
|
|
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
|
-
|
|
342
|
-
|
|
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
|
-
|
|
197
|
+
const ecies = new ECIESService();
|
|
358
198
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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
|
-
|
|
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
|
-
//
|
|
373
|
-
|
|
374
|
-
const service = new ECIESService(config);
|
|
209
|
+
// Encrypt data for this member
|
|
210
|
+
const encrypted = member.encryptData('My Secrets');
|
|
375
211
|
```
|
|
376
212
|
|
|
377
|
-
|
|
378
|
-
```typescript
|
|
379
|
-
// Before (v1.x)
|
|
380
|
-
const pbkdf2 = new Pbkdf2Service(engine, profiles);
|
|
213
|
+
## API Reference
|
|
381
214
|
|
|
382
|
-
|
|
383
|
-
const pbkdf2 = new Pbkdf2Service(profiles);
|
|
384
|
-
```
|
|
215
|
+
### Core Services
|
|
385
216
|
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
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
|
-
|
|
392
|
-
const multiRecipient = new EciesMultiRecipient(cryptoCore);
|
|
393
|
-
```
|
|
223
|
+
### Configuration & Registry
|
|
394
224
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
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
|
-
|
|
401
|
-
const singleRecipient = new EciesSingleRecipientCore(config);
|
|
402
|
-
```
|
|
229
|
+
### Secure Primitives
|
|
403
230
|
|
|
404
|
-
|
|
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
|
-
|
|
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
|
-
###
|
|
238
|
+
### Commands
|
|
414
239
|
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
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
|
-
|
|
434
|
-
```typescript
|
|
435
|
-
import { CryptoContainer } from '@digitaldefiance/node-ecies-lib';
|
|
248
|
+
## ChangeLog
|
|
436
249
|
|
|
437
|
-
|
|
438
|
-
const eciesService = container.getECIESService();
|
|
439
|
-
const pbkdf2Service = container.getPbkdf2Service();
|
|
440
|
-
const aesGcmService = container.getAESGCMService();
|
|
441
|
-
```
|
|
250
|
+
### v4.1.1
|
|
442
251
|
|
|
443
|
-
|
|
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
|
+
- Upgrade ecies
|
|
455
253
|
|
|
456
|
-
|
|
457
|
-
const result: Result<Buffer, Error> = {
|
|
458
|
-
success: true,
|
|
459
|
-
data: encryptedData
|
|
460
|
-
};
|
|
461
|
-
```
|
|
254
|
+
### v4.1.0
|
|
462
255
|
|
|
463
|
-
|
|
256
|
+
- **ID Provider Integration**: The `Member` model now fully utilizes the configured `IdProvider` for all ID operations, removing hard dependencies on specific ID formats.
|
|
257
|
+
- **Type Safety**: Enhanced type definitions for `Member` and `MemberBuilder` to support generic ID types (defaults to `Buffer`).
|
|
464
258
|
|
|
465
|
-
|
|
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
|
+
### v4.0.0 - ECIES Protocol v4.0
|
|
475
260
|
|
|
476
|
-
|
|
261
|
+
#### Major Protocol Upgrade (Breaking Change)
|
|
477
262
|
|
|
478
|
-
|
|
479
|
-
-
|
|
480
|
-
-
|
|
481
|
-
-
|
|
263
|
+
- **HKDF Key Derivation**: Replaced simple hashing with HKDF-SHA256.
|
|
264
|
+
- **AAD Binding**: Enforced binding of header and recipient IDs to encryption.
|
|
265
|
+
- **Shared Ephemeral Key**: Optimized multi-recipient encryption.
|
|
266
|
+
- **Compressed Keys**: Standardized on 33-byte compressed public keys.
|
|
267
|
+
- **IV/Key Sizes**: Optimized constants (12-byte IV, 60-byte encrypted key blocks).
|
|
482
268
|
|
|
483
|
-
|
|
269
|
+
### v3.7.0 - Pluggable ID Provider System
|
|
270
|
+
|
|
271
|
+
- **Flexible IDs**: Introduced `IdProvider` architecture.
|
|
272
|
+
- **Auto-Sync**: Configuration automatically adapts to ID size.
|
|
273
|
+
- **Invariant Validation**: Runtime checks for configuration consistency.
|
|
484
274
|
|
|
485
275
|
### Version 3.0.8
|
|
486
276
|
|
|
@@ -517,6 +307,7 @@ No performance regression in v2.0:
|
|
|
517
307
|
### Version 3.0.1
|
|
518
308
|
|
|
519
309
|
**Builder Improvements:**
|
|
310
|
+
|
|
520
311
|
- **ECIESBuilder**: Separated `serviceConfig` (IECIESConfig) from `eciesConsts` (IECIESConstants)
|
|
521
312
|
- Added `withServiceConfig()` method for runtime configuration
|
|
522
313
|
- Renamed internal property from `eciesParams` to `eciesConsts` for clarity
|
|
@@ -528,17 +319,20 @@ No performance regression in v2.0:
|
|
|
528
319
|
- Added `withCreatedBy()` method for tracking member creation
|
|
529
320
|
|
|
530
321
|
**Internationalization:**
|
|
322
|
+
|
|
531
323
|
- Added 13 new i18n string keys (3 builder errors, 10 streaming errors)
|
|
532
324
|
- Translations provided in 8 languages: EN-US, EN-GB, FR, ES, DE, JA, UK, ZH-CN
|
|
533
325
|
- Replaced all hardcoded error strings with i18n translations
|
|
534
326
|
- Fixed circular dependency in i18n imports
|
|
535
327
|
|
|
536
328
|
**Service Improvements:**
|
|
329
|
+
|
|
537
330
|
- Added `mnemonicToSimpleKeyPair()` alias method for backward compatibility
|
|
538
331
|
- Clarified `ECIESService.encryptMultiple()` signature (takes single Member, not array)
|
|
539
332
|
- Enhanced error handling in multi-recipient processor
|
|
540
333
|
|
|
541
334
|
**Test Improvements:**
|
|
335
|
+
|
|
542
336
|
- Fixed encryption type byte expectations (Simple=33, Single=66, Multiple=99)
|
|
543
337
|
- Fixed recipient ID sizes to use correct constant (12 bytes for ObjectID)
|
|
544
338
|
- Added comprehensive binary compatibility tests for streaming/chunking
|
|
@@ -546,6 +340,7 @@ No performance regression in v2.0:
|
|
|
546
340
|
- All 459 tests passing
|
|
547
341
|
|
|
548
342
|
**Binary Compatibility:**
|
|
343
|
+
|
|
549
344
|
- ✅ 100% compatible with browser @digitaldefiance/ecies-lib
|
|
550
345
|
- ✅ Chunk header format verified (4-byte big-endian index + 1-byte flags)
|
|
551
346
|
- ✅ Multi-recipient header format verified (big-endian byte order)
|
|
@@ -564,10 +359,12 @@ No performance regression in v2.0:
|
|
|
564
359
|
**New APIs**:
|
|
565
360
|
|
|
566
361
|
**Member Streaming Methods**:
|
|
362
|
+
|
|
567
363
|
- `member.encryptDataStream(source, options?)` - Stream encryption with progress tracking
|
|
568
364
|
- `member.decryptDataStream(source, options?)` - Stream decryption with progress tracking
|
|
569
365
|
|
|
570
366
|
**EncryptionStream Service**:
|
|
367
|
+
|
|
571
368
|
- `encryptStream(source, publicKey, options?)` - Single-recipient streaming
|
|
572
369
|
- `encryptStreamMultiple(source, recipients, options?)` - Multi-recipient streaming
|
|
573
370
|
- `decryptStream(source, privateKey, options?)` - Single-recipient decryption
|
|
@@ -576,6 +373,7 @@ No performance regression in v2.0:
|
|
|
576
373
|
**Security Enhancements (16 validations)**:
|
|
577
374
|
|
|
578
375
|
**Base ECIES Layer (8 fixes)**:
|
|
376
|
+
|
|
579
377
|
- Public key all-zeros validation
|
|
580
378
|
- Private key all-zeros validation
|
|
581
379
|
- Shared secret all-zeros validation
|
|
@@ -586,6 +384,7 @@ No performance regression in v2.0:
|
|
|
586
384
|
- Decrypted data validation
|
|
587
385
|
|
|
588
386
|
**AES-GCM Layer (5 fixes)**:
|
|
387
|
+
|
|
589
388
|
- Key length validation (16/24/32 bytes only)
|
|
590
389
|
- IV length validation (16 bytes)
|
|
591
390
|
- Null/undefined data rejection
|
|
@@ -593,29 +392,34 @@ No performance regression in v2.0:
|
|
|
593
392
|
- Comprehensive decrypt input validation
|
|
594
393
|
|
|
595
394
|
**Multi-Recipient Layer (3 fixes)**:
|
|
395
|
+
|
|
596
396
|
- Chunk index bounds checking (uint32 range)
|
|
597
397
|
- Data size validation (max 2GB)
|
|
598
398
|
- Safe accumulation with overflow detection
|
|
599
399
|
|
|
600
400
|
**New Services**:
|
|
401
|
+
|
|
601
402
|
- `EncryptionStream` - High-level streaming API
|
|
602
403
|
- `ChunkProcessor` - Single-recipient chunk processing
|
|
603
404
|
- `MultiRecipientProcessor` - Multi-recipient chunk processing
|
|
604
405
|
- `ProgressTracker` - Real-time progress tracking
|
|
605
406
|
|
|
606
407
|
**New Interfaces**:
|
|
408
|
+
|
|
607
409
|
- `IEncryptedChunk` - Encrypted chunk with metadata
|
|
608
410
|
- `IMultiRecipientChunk` - Multi-recipient chunk format
|
|
609
411
|
- `IStreamProgress` - Progress tracking information
|
|
610
412
|
- `IStreamConfig` - Stream configuration options
|
|
611
413
|
|
|
612
414
|
**Performance**:
|
|
415
|
+
|
|
613
416
|
- 99% memory reduction (1GB file: 1GB RAM → <10MB RAM)
|
|
614
417
|
- < 0.1% overhead from security validations
|
|
615
418
|
- Single-recipient: ~50-100 MB/s throughput
|
|
616
419
|
- Multi-recipient: ~40-80 MB/s throughput
|
|
617
420
|
|
|
618
421
|
**Binary Compatibility**:
|
|
422
|
+
|
|
619
423
|
- ✅ 100% compatible with @digitaldefiance/ecies-lib v2.2.0
|
|
620
424
|
- ✅ Cross-platform encrypt/decrypt verified
|
|
621
425
|
- ✅ All existing encryption formats unchanged
|
|
@@ -711,19 +515,21 @@ No performance regression in v2.0:
|
|
|
711
515
|
|
|
712
516
|
### Version 2.0.0 (2024-11-04)
|
|
713
517
|
|
|
714
|
-
**Major Architecture Refactor - 100% Binary Compatible**
|
|
518
|
+
> **Major Architecture Refactor - 100% Binary Compatible**
|
|
715
519
|
|
|
716
520
|
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
521
|
|
|
718
522
|
#### Breaking Changes
|
|
719
523
|
|
|
720
524
|
**Constructor Signatures Changed:**
|
|
525
|
+
|
|
721
526
|
- `ECIESService`: `(engine, config)` → `(config?, eciesParams?)`
|
|
722
527
|
- `Pbkdf2Service`: `(engine, profiles?, ...)` → `(profiles?, ...)`
|
|
723
528
|
- `EciesMultiRecipient`: `(core, engine)` → `(core)`
|
|
724
529
|
- `EciesSingleRecipientCore`: `(config, engine)` → `(config)`
|
|
725
530
|
|
|
726
531
|
**Removed Parameters:**
|
|
532
|
+
|
|
727
533
|
- All i18n engine parameters removed from constructors
|
|
728
534
|
- Engines now auto-initialized from singleton 'default' instance
|
|
729
535
|
- Errors retrieve engine automatically via `PluginTypedError`
|
|
@@ -731,19 +537,23 @@ This release modernizes the architecture following patterns from `@digitaldefian
|
|
|
731
537
|
#### New Features
|
|
732
538
|
|
|
733
539
|
**Builder Pattern** (`src/builders/`):
|
|
540
|
+
|
|
734
541
|
- `ECIESBuilder`: Fluent API for service construction with `.withConstants()`, `.build()`
|
|
735
542
|
- `MemberBuilder`: Fluent API for member creation with `.withType()`, `.withName()`, `.withEmail()`, `.build()`
|
|
736
543
|
|
|
737
544
|
**Service Container** (`src/lib/`):
|
|
545
|
+
|
|
738
546
|
- `CryptoContainer`: Dependency injection container
|
|
739
547
|
- Provides ECIES, PBKDF2, and AES-GCM services with shared constants
|
|
740
548
|
- Centralized service lifecycle management
|
|
741
549
|
|
|
742
550
|
**Core Types** (`src/core/`):
|
|
551
|
+
|
|
743
552
|
- `CryptoError`: Unified error class with `code`, `message`, `metadata` fields
|
|
744
553
|
- `Result<T, E>`: Safe operation results: `{ success: true; data: T } | { success: false; error: E }`
|
|
745
554
|
|
|
746
555
|
**Structural Improvements:**
|
|
556
|
+
|
|
747
557
|
- Organized into `builders/`, `core/`, `lib/` folders
|
|
748
558
|
- Clear separation of concerns
|
|
749
559
|
- Enhanced code organization following v2.0 patterns
|
|
@@ -751,31 +561,36 @@ This release modernizes the architecture following patterns from `@digitaldefian
|
|
|
751
561
|
#### Architecture Improvements
|
|
752
562
|
|
|
753
563
|
**i18n Integration:**
|
|
564
|
+
|
|
754
565
|
- Unified engine using singleton 'default' instance key
|
|
755
566
|
- `NodeEciesComponent` registered with base engine
|
|
756
567
|
- Automatic engine retrieval in error classes
|
|
757
568
|
- 100% reduction in engine parameter duplication
|
|
758
569
|
|
|
759
570
|
**Constructor Simplification:**
|
|
571
|
+
|
|
760
572
|
- Removed engine parameters from all service constructors
|
|
761
573
|
- Services use singleton pattern for i18n access
|
|
762
574
|
- Cleaner API surface with fewer required parameters
|
|
763
575
|
- Better developer experience
|
|
764
576
|
|
|
765
577
|
**Constants Handling:**
|
|
578
|
+
|
|
766
579
|
- ECIESService constructor handles undefined `eciesParams` with fallback to `Constants.ECIES`
|
|
767
580
|
- Proper constants injection through builder pattern
|
|
768
581
|
- Immutable configuration objects
|
|
769
582
|
|
|
770
|
-
#### Testing
|
|
583
|
+
#### Testing and Compatibility
|
|
771
584
|
|
|
772
585
|
**Test Results:**
|
|
586
|
+
|
|
773
587
|
- ✅ 220/220 tests passing (100% of non-legacy tests)
|
|
774
588
|
- ✅ 2 legacy i18n adapter tests skipped (deprecated)
|
|
775
589
|
- ✅ 20/22 test suites passing
|
|
776
590
|
- ✅ Test execution time: 385.946s
|
|
777
591
|
|
|
778
592
|
**Binary Compatibility - 100% Verified:**
|
|
593
|
+
|
|
779
594
|
- All encryption formats unchanged
|
|
780
595
|
- Cross-platform compatibility maintained
|
|
781
596
|
- Data encrypted with v1.x decrypts with v2.0
|
|
@@ -783,6 +598,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
|
|
|
783
598
|
- Compatible with browser `@digitaldefiance/ecies-lib`
|
|
784
599
|
|
|
785
600
|
**Compatibility Test Suites:**
|
|
601
|
+
|
|
786
602
|
- ✅ `cross-platform-compatibility.e2e.spec.ts` (6.517s) - 21 tests
|
|
787
603
|
- ✅ `ecies-bidirectional.e2e.spec.ts` - 8 tests
|
|
788
604
|
- ✅ `ecies-compatibility.e2e.spec.ts` (7.778s) - Full interop
|
|
@@ -790,6 +606,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
|
|
|
790
606
|
- ✅ `multi-recipient-ecies.e2e.spec.ts` - Multi-recipient
|
|
791
607
|
|
|
792
608
|
**Performance - No Regression:**
|
|
609
|
+
|
|
793
610
|
- Backend decryption: 31ms per 10 iterations
|
|
794
611
|
- Frontend decryption: 82ms per 10 iterations
|
|
795
612
|
- File operations (1MB): 16ms encrypt, 9ms decrypt
|
|
@@ -798,6 +615,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
|
|
|
798
615
|
#### Migration Impact
|
|
799
616
|
|
|
800
617
|
**Low Risk Migration:**
|
|
618
|
+
|
|
801
619
|
- Simple constructor signature changes
|
|
802
620
|
- No behavioral changes
|
|
803
621
|
- No data format changes
|
|
@@ -805,11 +623,13 @@ This release modernizes the architecture following patterns from `@digitaldefian
|
|
|
805
623
|
- Clear migration path with examples
|
|
806
624
|
|
|
807
625
|
**Estimated Migration Time:**
|
|
626
|
+
|
|
808
627
|
- Small projects: 15-30 minutes
|
|
809
628
|
- Medium projects: 1-2 hours
|
|
810
629
|
- Large projects: 2-4 hours
|
|
811
630
|
|
|
812
631
|
**Migration Steps:**
|
|
632
|
+
|
|
813
633
|
1. Update ECIESService instantiation (remove engine parameter)
|
|
814
634
|
2. Update Pbkdf2Service instantiation (remove engine parameter)
|
|
815
635
|
3. Update EciesMultiRecipient instantiation (remove engine parameter)
|
|
@@ -819,6 +639,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
|
|
|
819
639
|
#### Files Changed
|
|
820
640
|
|
|
821
641
|
**New Files:**
|
|
642
|
+
|
|
822
643
|
- `src/builders/ecies-builder.ts`
|
|
823
644
|
- `src/builders/member-builder.ts`
|
|
824
645
|
- `src/core/errors/crypto-error.ts`
|
|
@@ -826,6 +647,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
|
|
|
826
647
|
- `src/lib/crypto-container.ts`
|
|
827
648
|
|
|
828
649
|
**Modified Files:**
|
|
650
|
+
|
|
829
651
|
- `src/services/ecies/service.ts` - Constructor signature
|
|
830
652
|
- `src/services/pbkdf2.ts` - Constructor signature
|
|
831
653
|
- `src/services/ecies/multi-recipient.ts` - Constructor signature
|
|
@@ -834,6 +656,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
|
|
|
834
656
|
- `src/index.ts` - Added v2.0 exports
|
|
835
657
|
|
|
836
658
|
**Test Files Updated:**
|
|
659
|
+
|
|
837
660
|
- `tests/multi-recipient.spec.ts`
|
|
838
661
|
- `tests/cross-platform-compatibility.e2e.spec.ts`
|
|
839
662
|
- `tests/file.spec.ts`
|
|
@@ -844,6 +667,7 @@ This release modernizes the architecture following patterns from `@digitaldefian
|
|
|
844
667
|
#### Acknowledgments
|
|
845
668
|
|
|
846
669
|
This refactor follows the successful v2.0 migration patterns established in:
|
|
670
|
+
|
|
847
671
|
- `@digitaldefiance/ecies-lib` v2.0
|
|
848
672
|
- `@digitaldefiance/i18n-lib` v2.0
|
|
849
673
|
|
|
@@ -851,9 +675,9 @@ Special thanks to the architecture improvements that enabled this clean migratio
|
|
|
851
675
|
|
|
852
676
|
#### See Also
|
|
853
677
|
|
|
854
|
-
- [Migration Guide](#migration-
|
|
855
|
-
- [v2.0 Architecture](#
|
|
856
|
-
- [Binary Compatibility](#
|
|
678
|
+
- [Migration Guide](#migration-impact) - Detailed upgrade instructions
|
|
679
|
+
- [v2.0 Architecture](#architecture-improvements) - New components and patterns
|
|
680
|
+
- [Binary Compatibility](#testing-and-compatibility) - Compatibility guarantees
|
|
857
681
|
|
|
858
682
|
### Version 1.3.27
|
|
859
683
|
|