@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.
- package/README.md +229 -409
- 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,272 @@
|
|
|
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';
|
|
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
|
-
|
|
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
|
-
|
|
457
|
-
|
|
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
|
-
###
|
|
255
|
+
### v4.0.0 - ECIES Protocol v4.0
|
|
464
256
|
|
|
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 ✅
|
|
257
|
+
#### Major Protocol Upgrade (Breaking Change)
|
|
475
258
|
|
|
476
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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-
|
|
855
|
-
- [v2.0 Architecture](#
|
|
856
|
-
- [Binary Compatibility](#
|
|
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
|
|