@digitaldefiance/ecies-lib 1.1.13 → 1.1.15
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 +273 -446
- package/dist/constants.js +68 -57
- package/dist/constants.js.map +1 -1
- package/dist/email-string.js +16 -9
- package/dist/email-string.js.map +1 -1
- package/dist/enumerations/ecies-encryption-type.js +27 -20
- package/dist/enumerations/ecies-encryption-type.js.map +1 -1
- package/dist/enumerations/ecies-error-type.js +5 -2
- package/dist/enumerations/ecies-error-type.js.map +1 -1
- package/dist/enumerations/ecies-string-key.js +5 -2
- package/dist/enumerations/ecies-string-key.js.map +1 -1
- package/dist/enumerations/guid-brand-type.js +5 -2
- package/dist/enumerations/guid-brand-type.js.map +1 -1
- package/dist/enumerations/guid-error-type.js +5 -2
- package/dist/enumerations/guid-error-type.js.map +1 -1
- package/dist/enumerations/index.js +30 -14
- package/dist/enumerations/index.js.map +1 -1
- package/dist/enumerations/invalid-email-type.js +5 -2
- package/dist/enumerations/invalid-email-type.js.map +1 -1
- package/dist/enumerations/length-encoding-type.js +5 -2
- package/dist/enumerations/length-encoding-type.js.map +1 -1
- package/dist/enumerations/length-error-type.js +5 -2
- package/dist/enumerations/length-error-type.js.map +1 -1
- package/dist/enumerations/member-error-type.js +6 -3
- package/dist/enumerations/member-error-type.js.map +1 -1
- package/dist/enumerations/member-type.js +6 -3
- package/dist/enumerations/member-type.js.map +1 -1
- package/dist/enumerations/password-login-error-type.js +5 -2
- package/dist/enumerations/password-login-error-type.js.map +1 -1
- package/dist/enumerations/pbkdf2-error-type.js +5 -2
- package/dist/enumerations/pbkdf2-error-type.js.map +1 -1
- package/dist/enumerations/pbkdf2-profile.js +5 -2
- package/dist/enumerations/pbkdf2-profile.js.map +1 -1
- package/dist/enumerations/secure-storage-error-type.js +5 -2
- package/dist/enumerations/secure-storage-error-type.js.map +1 -1
- package/dist/errors/disposed.js +8 -4
- package/dist/errors/disposed.js.map +1 -1
- package/dist/errors/ecies.js +11 -7
- package/dist/errors/ecies.js.map +1 -1
- package/dist/errors/guid.js +9 -5
- package/dist/errors/guid.js.map +1 -1
- package/dist/errors/handleable.js +5 -1
- package/dist/errors/handleable.js.map +1 -1
- package/dist/errors/index.js +27 -11
- package/dist/errors/index.js.map +1 -1
- package/dist/errors/invalid-email.js +9 -5
- package/dist/errors/invalid-email.js.map +1 -1
- package/dist/errors/length.js +9 -5
- package/dist/errors/length.js.map +1 -1
- package/dist/errors/member.js +9 -5
- package/dist/errors/member.js.map +1 -1
- package/dist/errors/pbkdf2.js +9 -5
- package/dist/errors/pbkdf2.js.map +1 -1
- package/dist/errors/secure-storage.js +9 -5
- package/dist/errors/secure-storage.js.map +1 -1
- package/dist/errors/simple-ecies.js +9 -5
- package/dist/errors/simple-ecies.js.map +1 -1
- package/dist/errors/simple-test-error.js +5 -1
- package/dist/errors/simple-test-error.js.map +1 -1
- package/dist/errors/translatable.js +6 -2
- package/dist/errors/translatable.js.map +1 -1
- package/dist/errors/typed-handleable.js +9 -5
- package/dist/errors/typed-handleable.js.map +1 -1
- package/dist/guid.js +113 -76
- package/dist/guid.js.map +1 -1
- package/dist/i18n-setup.js +675 -665
- package/dist/i18n-setup.js.map +1 -1
- package/dist/index.js +30 -14
- package/dist/index.js.map +1 -1
- package/dist/interfaces/checksum-config.js +2 -1
- package/dist/interfaces/checksum-consts.js +2 -1
- package/dist/interfaces/constants.js +2 -1
- package/dist/interfaces/ecies-config.js +2 -1
- package/dist/interfaces/ecies-consts.js +2 -1
- package/dist/interfaces/ecies-file-service.js +2 -1
- package/dist/interfaces/guid.js +2 -1
- package/dist/interfaces/handleable-error-options.js +2 -1
- package/dist/interfaces/handleable.js +2 -1
- package/dist/interfaces/index.js +31 -15
- package/dist/interfaces/index.js.map +1 -1
- package/dist/interfaces/library-error.js +2 -1
- package/dist/interfaces/member-operational.js +2 -1
- package/dist/interfaces/member-storage.js +2 -1
- package/dist/interfaces/member-with-mnemonic.js +2 -1
- package/dist/interfaces/pbkdf2-config.js +2 -1
- package/dist/interfaces/pbkdf2-consts.js +2 -1
- package/dist/interfaces/pbkdf2-result.js +2 -1
- package/dist/member.js +44 -37
- package/dist/member.js.map +1 -1
- package/dist/pbkdf2-profiles.js +2 -1
- package/dist/regexes.js +5 -2
- package/dist/regexes.js.map +1 -1
- package/dist/secure-buffer.js +22 -18
- package/dist/secure-buffer.js.map +1 -1
- package/dist/secure-string.js +24 -20
- package/dist/secure-string.js.map +1 -1
- package/dist/services/aes-gcm.js +13 -9
- package/dist/services/aes-gcm.js.map +1 -1
- package/dist/services/ecies/crypto-core.js +35 -31
- package/dist/services/ecies/crypto-core.js.map +1 -1
- package/dist/services/ecies/example.js +44 -37
- package/dist/services/ecies/example.js.map +1 -1
- package/dist/services/ecies/file.js +5 -1
- package/dist/services/ecies/file.js.map +1 -1
- package/dist/services/ecies/index.js +28 -10
- package/dist/services/ecies/index.js.map +1 -1
- package/dist/services/ecies/integration.js +28 -23
- package/dist/services/ecies/integration.js.map +1 -1
- package/dist/services/ecies/interfaces.js +2 -1
- package/dist/services/ecies/interfaces.js.map +1 -1
- package/dist/services/ecies/manual-test.js +34 -26
- package/dist/services/ecies/manual-test.js.map +1 -1
- package/dist/services/ecies/multi-recipient.js +51 -47
- package/dist/services/ecies/multi-recipient.js.map +1 -1
- package/dist/services/ecies/service.js +20 -16
- package/dist/services/ecies/service.js.map +1 -1
- package/dist/services/ecies/signature.js +13 -9
- package/dist/services/ecies/signature.js.map +1 -1
- package/dist/services/ecies/single-recipient.js +32 -28
- package/dist/services/ecies/single-recipient.js.map +1 -1
- package/dist/services/index.js +21 -5
- package/dist/services/index.js.map +1 -1
- package/dist/services/password-login.js +37 -33
- package/dist/services/password-login.js.map +1 -1
- package/dist/services/pbkdf2.js +12 -8
- package/dist/services/pbkdf2.js.map +1 -1
- package/dist/services/xor.js +5 -1
- package/dist/services/xor.js.map +1 -1
- package/dist/types/deep-partial.js +2 -1
- package/dist/types.js +2 -1
- package/dist/utils.js +69 -51
- package/dist/utils.js.map +1 -1
- package/package.json +2 -2
- package/dist/defaults.d.ts +0 -37
- package/dist/defaults.d.ts.map +0 -1
- package/dist/defaults.js +0 -323
- package/dist/defaults.js.map +0 -1
- package/dist/errors/typed.d.ts +0 -14
- package/dist/errors/typed.d.ts.map +0 -1
- package/dist/errors/typed.js +0 -48
- package/dist/errors/typed.js.map +0 -1
- package/dist/i18n-config.d.ts +0 -77
- package/dist/i18n-config.d.ts.map +0 -1
- package/dist/i18n-config.js +0 -88
- package/dist/i18n-config.js.map +0 -1
- package/dist/interfaces/defaults.d.ts +0 -35
- package/dist/interfaces/defaults.d.ts.map +0 -1
- package/dist/interfaces/defaults.js +0 -2
- package/dist/interfaces/defaults.js.map +0 -1
- package/dist/package.json +0 -63
package/README.md
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
# @digitaldefiance/ecies-lib
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Production-ready, browser-compatible ECIES (Elliptic Curve Integrated Encryption Scheme) library for TypeScript. Built on Web Crypto API and @noble/curves with comprehensive encryption, key management, and authentication services. Binary compatible with @digitaldefiance/node-ecies-lib for seamless cross-platform operations.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Features
|
|
6
6
|
|
|
7
7
|
### Core Cryptography
|
|
8
|
-
- **ECIES Encryption** –
|
|
9
|
-
- **
|
|
10
|
-
- **AES-GCM
|
|
11
|
-
- **PBKDF2
|
|
8
|
+
- **ECIES Encryption** – Simple (98-byte overhead), Single (106-byte overhead), Multiple (multi-recipient) modes
|
|
9
|
+
- **secp256k1 Curve** – ECDH key exchange and ECDSA signatures
|
|
10
|
+
- **AES-256-GCM** – Authenticated symmetric encryption via Web Crypto API
|
|
11
|
+
- **PBKDF2** – Configurable password-based key derivation profiles
|
|
12
12
|
|
|
13
13
|
### Key Management
|
|
14
|
-
- **BIP39
|
|
15
|
-
- **HD
|
|
16
|
-
- **Member System** –
|
|
17
|
-
- **Secure Storage** – Memory-safe SecureString
|
|
14
|
+
- **BIP39 Mnemonics** – 12/15/18/21/24-word phrase generation and key derivation
|
|
15
|
+
- **HD Wallets** – BIP32/BIP44 hierarchical deterministic derivation
|
|
16
|
+
- **Member System** – User abstraction with cryptographic operations
|
|
17
|
+
- **Secure Storage** – Memory-safe SecureString/SecureBuffer with XOR obfuscation and auto-zeroing
|
|
18
18
|
|
|
19
|
-
### Advanced
|
|
20
|
-
- **Multi-Recipient
|
|
21
|
-
- **File Encryption
|
|
22
|
-
- **Password Login
|
|
23
|
-
- **
|
|
19
|
+
### Advanced
|
|
20
|
+
- **Multi-Recipient** – Encrypt for up to 65,535 recipients efficiently
|
|
21
|
+
- **File Encryption** – Chunked 1MB segments for large files
|
|
22
|
+
- **Password Login** – Complete authentication with encrypted key storage
|
|
23
|
+
- **Signatures** – ECDSA message signing and verification
|
|
24
24
|
|
|
25
25
|
### Developer Experience
|
|
26
|
-
- **
|
|
27
|
-
- **
|
|
28
|
-
- **Runtime
|
|
29
|
-
- **
|
|
30
|
-
- **Cross-Platform** –
|
|
26
|
+
- **TypeScript** – Full type definitions and interfaces
|
|
27
|
+
- **i18n** – Error messages in 8 languages (en-US, en-GB, fr, es, de, zh-CN, ja, uk)
|
|
28
|
+
- **Runtime Config** – Injectable configuration profiles via ConstantsRegistry
|
|
29
|
+
- **Testing** – 32 test files with 389+ specs (unit, integration, e2e)
|
|
30
|
+
- **Cross-Platform** – Node.js 18+ and modern browsers
|
|
31
31
|
|
|
32
32
|
## Installation
|
|
33
33
|
|
|
@@ -35,68 +35,43 @@ A production-ready, browser-friendly implementation of Elliptic Curve Integrated
|
|
|
35
35
|
npm install @digitaldefiance/ecies-lib
|
|
36
36
|
# or
|
|
37
37
|
yarn add @digitaldefiance/ecies-lib
|
|
38
|
-
# or
|
|
39
|
-
pnpm add @digitaldefiance/ecies-lib
|
|
40
38
|
```
|
|
41
39
|
|
|
42
|
-
###
|
|
40
|
+
### Requirements
|
|
43
41
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
- **Browsers**: Modern browsers with Web Crypto API and BigInt support
|
|
47
|
-
- Chrome/Edge 60+
|
|
48
|
-
- Firefox 60+
|
|
49
|
-
- Safari 14+
|
|
50
|
-
- Opera 47+
|
|
42
|
+
**Node.js**: 18+ (Web Crypto API built-in)
|
|
43
|
+
- For Node < 18: `import { webcrypto } from 'crypto'; globalThis.crypto = webcrypto as unknown as Crypto;`
|
|
51
44
|
|
|
52
|
-
|
|
45
|
+
**Browsers**: Chrome/Edge 60+, Firefox 60+, Safari 14+, Opera 47+
|
|
53
46
|
|
|
54
|
-
|
|
55
|
-
- `@digitaldefiance/i18n-lib` - Internationalization engine
|
|
56
|
-
- `@noble/curves` - Elliptic curve cryptography
|
|
57
|
-
- `@scure/bip32`, `@scure/bip39` - HD wallet and mnemonic support
|
|
58
|
-
- `@ethereumjs/wallet` - Ethereum wallet compatibility
|
|
47
|
+
**Dependencies**: `@digitaldefiance/i18n-lib`, `@noble/curves`, `@scure/bip32`, `@scure/bip39`, `@ethereumjs/wallet`, `bson`, `ts-brand`
|
|
59
48
|
|
|
60
49
|
## Quick Start
|
|
61
50
|
|
|
62
|
-
### Basic Encryption
|
|
51
|
+
### Basic Encryption
|
|
63
52
|
|
|
64
53
|
```typescript
|
|
65
54
|
import { ECIESService } from '@digitaldefiance/ecies-lib';
|
|
66
55
|
|
|
67
|
-
// Initialize the service
|
|
68
56
|
const ecies = new ECIESService();
|
|
69
|
-
|
|
70
|
-
// Generate a mnemonic and derive keys
|
|
71
57
|
const mnemonic = ecies.generateNewMnemonic();
|
|
72
58
|
const { privateKey, publicKey } = ecies.mnemonicToSimpleKeyPair(mnemonic);
|
|
73
59
|
|
|
74
|
-
// Encrypt
|
|
60
|
+
// Encrypt
|
|
75
61
|
const message = new TextEncoder().encode('Hello, World!');
|
|
76
|
-
const encrypted = await ecies.encryptSimpleOrSingle(
|
|
77
|
-
false, // false = Single mode (with length prefix)
|
|
78
|
-
publicKey,
|
|
79
|
-
message
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
// Decrypt the message
|
|
83
|
-
const decrypted = await ecies.decryptSimpleOrSingleWithHeader(
|
|
84
|
-
false,
|
|
85
|
-
privateKey,
|
|
86
|
-
encrypted
|
|
87
|
-
);
|
|
62
|
+
const encrypted = await ecies.encryptSimpleOrSingle(false, publicKey, message);
|
|
88
63
|
|
|
64
|
+
// Decrypt
|
|
65
|
+
const decrypted = await ecies.decryptSimpleOrSingleWithHeader(false, privateKey, encrypted);
|
|
89
66
|
console.log(new TextDecoder().decode(decrypted)); // "Hello, World!"
|
|
90
67
|
```
|
|
91
68
|
|
|
92
|
-
###
|
|
69
|
+
### Member System
|
|
93
70
|
|
|
94
71
|
```typescript
|
|
95
72
|
import { ECIESService, Member, MemberType, EmailString } from '@digitaldefiance/ecies-lib';
|
|
96
73
|
|
|
97
74
|
const ecies = new ECIESService();
|
|
98
|
-
|
|
99
|
-
// Create a new member with generated keys
|
|
100
75
|
const { member, mnemonic } = Member.newMember(
|
|
101
76
|
ecies,
|
|
102
77
|
MemberType.User,
|
|
@@ -104,76 +79,52 @@ const { member, mnemonic } = Member.newMember(
|
|
|
104
79
|
new EmailString('alice@example.com')
|
|
105
80
|
);
|
|
106
81
|
|
|
107
|
-
// Encrypt
|
|
108
|
-
const
|
|
109
|
-
const encrypted = await member.encryptData(data);
|
|
110
|
-
|
|
111
|
-
// Decrypt the data
|
|
82
|
+
// Encrypt/decrypt
|
|
83
|
+
const encrypted = await member.encryptData('Sensitive data');
|
|
112
84
|
const decrypted = await member.decryptData(encrypted);
|
|
113
|
-
console.log(new TextDecoder().decode(decrypted));
|
|
114
85
|
|
|
115
|
-
// Sign
|
|
86
|
+
// Sign/verify
|
|
116
87
|
const signature = member.sign(new TextEncoder().encode('Message'));
|
|
117
|
-
const
|
|
88
|
+
const valid = member.verify(signature, new TextEncoder().encode('Message'));
|
|
118
89
|
```
|
|
119
90
|
|
|
120
91
|
## Core Services
|
|
121
92
|
|
|
122
|
-
### ECIESService
|
|
93
|
+
### ECIESService
|
|
123
94
|
|
|
124
|
-
|
|
95
|
+
Main encryption service with three modes:
|
|
125
96
|
|
|
126
97
|
```typescript
|
|
127
|
-
import { ECIESService
|
|
98
|
+
import { ECIESService } from '@digitaldefiance/ecies-lib';
|
|
128
99
|
|
|
129
100
|
const ecies = new ECIESService();
|
|
130
|
-
|
|
131
|
-
// Generate keys
|
|
132
101
|
const mnemonic = ecies.generateNewMnemonic();
|
|
133
|
-
const {
|
|
134
|
-
const { privateKey, publicKey } = ecies.seedToSimpleKeyPair(seed);
|
|
135
|
-
|
|
136
|
-
// Simple mode - minimal overhead, no length prefix
|
|
137
|
-
const simpleEncrypted = await ecies.encryptSimpleOrSingle(
|
|
138
|
-
true, // true = Simple mode
|
|
139
|
-
publicKey,
|
|
140
|
-
message
|
|
141
|
-
);
|
|
102
|
+
const { privateKey, publicKey } = ecies.mnemonicToSimpleKeyPair(mnemonic);
|
|
142
103
|
|
|
143
|
-
//
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
);
|
|
104
|
+
// Simple mode (98-byte overhead, no length prefix)
|
|
105
|
+
const simple = await ecies.encryptSimpleOrSingle(true, publicKey, message);
|
|
106
|
+
|
|
107
|
+
// Single mode (106-byte overhead, 8-byte length prefix)
|
|
108
|
+
const single = await ecies.encryptSimpleOrSingle(false, publicKey, message);
|
|
149
109
|
|
|
150
110
|
// Decrypt with automatic header parsing
|
|
151
|
-
const decrypted = await ecies.decryptSimpleOrSingleWithHeader(
|
|
152
|
-
false,
|
|
153
|
-
privateKey,
|
|
154
|
-
singleEncrypted
|
|
155
|
-
);
|
|
111
|
+
const decrypted = await ecies.decryptSimpleOrSingleWithHeader(false, privateKey, single);
|
|
156
112
|
```
|
|
157
113
|
|
|
158
|
-
###
|
|
114
|
+
### EciesMultiRecipient
|
|
159
115
|
|
|
160
|
-
Encrypt once for multiple recipients
|
|
116
|
+
Encrypt once for multiple recipients:
|
|
161
117
|
|
|
162
118
|
```typescript
|
|
163
|
-
import {
|
|
164
|
-
EciesMultiRecipient,
|
|
165
|
-
EciesCryptoCore,
|
|
166
|
-
ECIES,
|
|
167
|
-
concatUint8Arrays,
|
|
168
|
-
} from '@digitaldefiance/ecies-lib';
|
|
119
|
+
import { EciesMultiRecipient, EciesCryptoCore, Constants } from '@digitaldefiance/ecies-lib';
|
|
169
120
|
|
|
170
121
|
const config = {
|
|
171
|
-
curveName: ECIES.CURVE_NAME,
|
|
172
|
-
primaryKeyDerivationPath: ECIES.PRIMARY_KEY_DERIVATION_PATH,
|
|
173
|
-
mnemonicStrength: ECIES.MNEMONIC_STRENGTH,
|
|
174
|
-
symmetricAlgorithm: ECIES.SYMMETRIC.ALGORITHM,
|
|
175
|
-
symmetricKeyBits: ECIES.SYMMETRIC.KEY_BITS,
|
|
176
|
-
symmetricKeyMode: ECIES.SYMMETRIC.MODE,
|
|
122
|
+
curveName: Constants.ECIES.CURVE_NAME,
|
|
123
|
+
primaryKeyDerivationPath: Constants.ECIES.PRIMARY_KEY_DERIVATION_PATH,
|
|
124
|
+
mnemonicStrength: Constants.ECIES.MNEMONIC_STRENGTH,
|
|
125
|
+
symmetricAlgorithm: Constants.ECIES.SYMMETRIC.ALGORITHM,
|
|
126
|
+
symmetricKeyBits: Constants.ECIES.SYMMETRIC.KEY_BITS,
|
|
127
|
+
symmetricKeyMode: Constants.ECIES.SYMMETRIC.MODE,
|
|
177
128
|
};
|
|
178
129
|
|
|
179
130
|
const multi = new EciesMultiRecipient(config);
|
|
@@ -184,71 +135,52 @@ const recipients = await Promise.all(
|
|
|
184
135
|
[...Array(3)].map(async () => {
|
|
185
136
|
const { privateKey, publicKey } = await core.generateEphemeralKeyPair();
|
|
186
137
|
return {
|
|
187
|
-
id: crypto.getRandomValues(new Uint8Array(ECIES.MULTIPLE.RECIPIENT_ID_SIZE)),
|
|
138
|
+
id: crypto.getRandomValues(new Uint8Array(Constants.ECIES.MULTIPLE.RECIPIENT_ID_SIZE)),
|
|
188
139
|
privateKey,
|
|
189
140
|
publicKey,
|
|
190
141
|
};
|
|
191
142
|
})
|
|
192
143
|
);
|
|
193
144
|
|
|
194
|
-
// Encrypt for all
|
|
195
|
-
const message = new TextEncoder().encode('Broadcast message');
|
|
145
|
+
// Encrypt for all
|
|
196
146
|
const encrypted = await multi.encryptMultiple(
|
|
197
147
|
recipients.map(({ id, publicKey }) => ({ id, publicKey })),
|
|
198
|
-
message
|
|
199
|
-
);
|
|
200
|
-
|
|
201
|
-
// Build transport frame
|
|
202
|
-
const frame = concatUint8Arrays(
|
|
203
|
-
multi.buildHeader(encrypted),
|
|
204
|
-
encrypted.encryptedMessage
|
|
148
|
+
new TextEncoder().encode('Broadcast message')
|
|
205
149
|
);
|
|
206
150
|
|
|
207
151
|
// Any recipient can decrypt
|
|
208
152
|
const decrypted = await multi.decryptMultipleForRecipient(
|
|
209
|
-
multi.parseMessage(
|
|
153
|
+
multi.parseMessage(multi.buildHeader(encrypted) + encrypted.encryptedMessage),
|
|
210
154
|
recipients[0].id,
|
|
211
155
|
recipients[0].privateKey
|
|
212
156
|
);
|
|
213
157
|
```
|
|
214
158
|
|
|
215
|
-
###
|
|
159
|
+
### EciesFileService
|
|
216
160
|
|
|
217
|
-
Chunked file encryption
|
|
161
|
+
Chunked file encryption:
|
|
218
162
|
|
|
219
163
|
```typescript
|
|
220
164
|
import { ECIESService, EciesFileService } from '@digitaldefiance/ecies-lib';
|
|
221
165
|
|
|
222
166
|
const ecies = new ECIESService();
|
|
223
|
-
const
|
|
224
|
-
const { privateKey, publicKey } = ecies.mnemonicToSimpleKeyPair(mnemonic);
|
|
225
|
-
|
|
226
|
-
// Initialize file service with user's private key
|
|
167
|
+
const { privateKey, publicKey } = ecies.mnemonicToSimpleKeyPair(ecies.generateNewMnemonic());
|
|
227
168
|
const fileService = new EciesFileService(ecies, privateKey);
|
|
228
169
|
|
|
229
|
-
// Encrypt
|
|
230
|
-
const file = fileInput.files[0];
|
|
170
|
+
// Encrypt file (1MB chunks)
|
|
231
171
|
const encrypted = await fileService.encryptFile(file, publicKey);
|
|
232
172
|
|
|
233
|
-
// Decrypt
|
|
173
|
+
// Decrypt file
|
|
234
174
|
const decrypted = await fileService.decryptFile(encrypted);
|
|
235
175
|
|
|
236
|
-
// Download
|
|
176
|
+
// Download
|
|
237
177
|
fileService.downloadEncryptedFile(encrypted, 'document.enc');
|
|
238
|
-
|
|
239
|
-
// Download decrypted file
|
|
240
178
|
fileService.downloadDecryptedFile(decrypted, 'document.pdf');
|
|
241
179
|
```
|
|
242
180
|
|
|
243
|
-
|
|
244
|
-
- Chunks files into 1MB segments for memory efficiency
|
|
245
|
-
- Encrypts each chunk independently
|
|
246
|
-
- Includes metadata header with chunk information
|
|
247
|
-
- Supports files of any size within browser memory limits
|
|
181
|
+
### PasswordLoginService
|
|
248
182
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
Complete password-based authentication system:
|
|
183
|
+
Password-based authentication:
|
|
252
184
|
|
|
253
185
|
```typescript
|
|
254
186
|
import {
|
|
@@ -265,204 +197,168 @@ const ecies = new ECIESService();
|
|
|
265
197
|
const pbkdf2 = new Pbkdf2Service(engine);
|
|
266
198
|
const passwordLogin = new PasswordLoginService(ecies, pbkdf2, engine);
|
|
267
199
|
|
|
268
|
-
// Setup
|
|
200
|
+
// Setup
|
|
269
201
|
const mnemonic = ecies.generateNewMnemonic();
|
|
270
202
|
const password = new SecureString('MySecurePassword123!');
|
|
271
|
-
|
|
272
|
-
const wallet = await passwordLogin.setupPasswordLoginLocalStorageBundle(
|
|
203
|
+
await passwordLogin.setupPasswordLoginLocalStorageBundle(
|
|
273
204
|
mnemonic,
|
|
274
205
|
password,
|
|
275
206
|
Pbkdf2ProfileEnum.BROWSER_PASSWORD
|
|
276
207
|
);
|
|
277
208
|
|
|
278
|
-
//
|
|
279
|
-
const { wallet
|
|
209
|
+
// Login
|
|
210
|
+
const { wallet, mnemonic: recovered } =
|
|
280
211
|
await passwordLogin.getWalletAndMnemonicFromLocalStorageBundle(password);
|
|
281
212
|
|
|
282
|
-
// Check
|
|
213
|
+
// Check setup
|
|
283
214
|
if (PasswordLoginService.isPasswordLoginSetup()) {
|
|
284
|
-
console.log('
|
|
215
|
+
console.log('Ready');
|
|
285
216
|
}
|
|
286
217
|
```
|
|
287
218
|
|
|
288
|
-
###
|
|
219
|
+
### Pbkdf2Service
|
|
289
220
|
|
|
290
|
-
|
|
221
|
+
Key derivation with profiles:
|
|
291
222
|
|
|
292
223
|
```typescript
|
|
293
|
-
import {
|
|
294
|
-
Pbkdf2Service,
|
|
295
|
-
Pbkdf2ProfileEnum,
|
|
296
|
-
IPbkdf2Config,
|
|
297
|
-
getEciesI18nEngine,
|
|
298
|
-
} from '@digitaldefiance/ecies-lib';
|
|
224
|
+
import { Pbkdf2Service, Pbkdf2ProfileEnum, getEciesI18nEngine } from '@digitaldefiance/ecies-lib';
|
|
299
225
|
|
|
300
|
-
const
|
|
301
|
-
const pbkdf2 = new Pbkdf2Service(engine);
|
|
226
|
+
const pbkdf2 = new Pbkdf2Service(getEciesI18nEngine());
|
|
302
227
|
|
|
303
|
-
// Use
|
|
304
|
-
const password = new TextEncoder().encode('password123');
|
|
228
|
+
// Use built-in profile
|
|
305
229
|
const result = await pbkdf2.deriveKeyFromPasswordWithProfileAsync(
|
|
306
|
-
|
|
230
|
+
new TextEncoder().encode('password123'),
|
|
307
231
|
Pbkdf2ProfileEnum.HIGH_SECURITY
|
|
308
232
|
);
|
|
309
233
|
|
|
310
234
|
console.log(result.hash); // Derived key
|
|
311
|
-
console.log(result.salt); //
|
|
312
|
-
console.log(result.iterations); //
|
|
235
|
+
console.log(result.salt); // Salt
|
|
236
|
+
console.log(result.iterations); // 5,000,000
|
|
313
237
|
|
|
314
238
|
// Custom profiles
|
|
315
|
-
const
|
|
239
|
+
const custom = new Pbkdf2Service(getEciesI18nEngine(), {
|
|
316
240
|
ULTRA_SECURE: {
|
|
317
241
|
hashBytes: 64,
|
|
318
242
|
saltBytes: 32,
|
|
319
243
|
iterations: 5000000,
|
|
320
244
|
algorithm: 'SHA-512',
|
|
321
245
|
},
|
|
322
|
-
|
|
323
|
-
hashBytes: 32,
|
|
324
|
-
saltBytes: 16,
|
|
325
|
-
iterations: 1000,
|
|
326
|
-
algorithm: 'SHA-256',
|
|
327
|
-
},
|
|
328
|
-
};
|
|
329
|
-
|
|
330
|
-
const customPbkdf2 = new Pbkdf2Service(engine, customProfiles);
|
|
331
|
-
const customResult = await customPbkdf2.deriveKeyFromPasswordWithProfileAsync(
|
|
332
|
-
password,
|
|
333
|
-
'ULTRA_SECURE'
|
|
334
|
-
);
|
|
246
|
+
});
|
|
335
247
|
```
|
|
336
248
|
|
|
337
249
|
**Built-in Profiles:**
|
|
338
250
|
- `BROWSER_PASSWORD`: 2M iterations, SHA-512, 32-byte hash
|
|
339
|
-
- `HIGH_SECURITY`: 5M iterations, SHA-256, 64-byte hash
|
|
340
|
-
- `TEST_FAST`: 1K iterations, SHA-512, 32-byte hash
|
|
251
|
+
- `HIGH_SECURITY`: 5M iterations, SHA-256, 64-byte hash
|
|
252
|
+
- `TEST_FAST`: 1K iterations, SHA-512, 32-byte hash
|
|
341
253
|
|
|
342
|
-
## Runtime
|
|
254
|
+
## Runtime Configuration
|
|
343
255
|
|
|
344
|
-
|
|
256
|
+
Injectable configuration profiles via ConstantsRegistry:
|
|
345
257
|
|
|
346
|
-
```
|
|
258
|
+
```typescript
|
|
347
259
|
import {
|
|
348
|
-
|
|
260
|
+
ConstantsRegistry,
|
|
349
261
|
registerRuntimeConfiguration,
|
|
350
262
|
getRuntimeConfiguration,
|
|
351
|
-
unregisterRuntimeConfiguration,
|
|
352
263
|
ECIESService,
|
|
353
264
|
Pbkdf2Service,
|
|
265
|
+
getEciesI18nEngine,
|
|
354
266
|
} from '@digitaldefiance/ecies-lib';
|
|
355
267
|
|
|
356
|
-
//
|
|
268
|
+
// Register profiles
|
|
357
269
|
registerRuntimeConfiguration('security-first', {
|
|
358
|
-
PBKDF2: {
|
|
359
|
-
ITERATIONS_PER_SECOND: 3_000_000,
|
|
360
|
-
},
|
|
270
|
+
PBKDF2: { ITERATIONS_PER_SECOND: 3_000_000 },
|
|
361
271
|
});
|
|
362
272
|
|
|
363
|
-
registerRuntimeConfiguration(
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
PBKDF2: {
|
|
367
|
-
ITERATIONS_PER_SECOND: 250_000,
|
|
368
|
-
},
|
|
369
|
-
},
|
|
370
|
-
{ baseKey: DefaultsRegistry.DEFAULT_KEY },
|
|
371
|
-
);
|
|
372
|
-
|
|
373
|
-
// 2. Spin up services that honor those profiles
|
|
374
|
-
const secureDefaults = getRuntimeConfiguration('security-first');
|
|
375
|
-
const secureEcies = new ECIESService(undefined, secureDefaults.ECIES);
|
|
376
|
-
const securePbkdf2 = new Pbkdf2Service(engine, secureDefaults.PBKDF2_PROFILES, secureDefaults.ECIES, secureDefaults.PBKDF2);
|
|
377
|
-
|
|
378
|
-
const perfDefaults = getRuntimeConfiguration('performance-first');
|
|
379
|
-
const perfEcies = new ECIESService(undefined, perfDefaults.ECIES);
|
|
273
|
+
registerRuntimeConfiguration('performance-first', {
|
|
274
|
+
PBKDF2: { ITERATIONS_PER_SECOND: 250_000 },
|
|
275
|
+
});
|
|
380
276
|
|
|
381
|
-
//
|
|
382
|
-
const
|
|
277
|
+
// Use profiles
|
|
278
|
+
const secureConfig = getRuntimeConfiguration('security-first');
|
|
279
|
+
const secureEcies = new ECIESService(undefined, secureConfig.ECIES);
|
|
280
|
+
const securePbkdf2 = new Pbkdf2Service(
|
|
281
|
+
getEciesI18nEngine(),
|
|
282
|
+
secureConfig.PBKDF2_PROFILES,
|
|
283
|
+
secureConfig.ECIES,
|
|
284
|
+
secureConfig.PBKDF2
|
|
285
|
+
);
|
|
383
286
|
|
|
384
|
-
//
|
|
287
|
+
// Cleanup
|
|
385
288
|
unregisterRuntimeConfiguration('performance-first');
|
|
386
289
|
```
|
|
387
290
|
|
|
388
|
-
|
|
291
|
+
**Registry API:**
|
|
292
|
+
- `ConstantsRegistry.get(key)` – Retrieve configuration
|
|
293
|
+
- `ConstantsRegistry.register(key, config)` – Register new profile
|
|
294
|
+
- `ConstantsRegistry.create(overrides)` – Create without registering
|
|
295
|
+
- `ConstantsRegistry.listKeys()` – List all keys
|
|
296
|
+
- `ConstantsRegistry.has(key)` – Check existence
|
|
297
|
+
- `ConstantsRegistry.unregister(key)` – Remove profile
|
|
298
|
+
- `ConstantsRegistry.clear()` – Reset to defaults
|
|
389
299
|
|
|
390
|
-
|
|
300
|
+
**Exports:**
|
|
301
|
+
- `Constants` – Frozen default configuration
|
|
302
|
+
- `createRuntimeConfiguration(overrides, base?)` – Deep merge and validate
|
|
303
|
+
- `PASSWORD_REGEX`, `MNEMONIC_REGEX` – Validation patterns
|
|
391
304
|
|
|
392
|
-
|
|
393
|
-
- **`createRuntimeConfiguration(overrides, base?)`** – clones a base configuration, applies partial overrides (deep merge), validates invariants, and returns a deeply frozen instance without touching the registry.
|
|
394
|
-
- **`DefaultsRegistry`** – registry API with `get`, `register`, `create`, `listKeys`, `has`, `unregister`, and `clear`. Registered profiles are validated and frozen, so consumers can safely share references.
|
|
395
|
-
- **Convenience functions** – `getRuntimeConfiguration`, `registerRuntimeConfiguration`, `unregisterRuntimeConfiguration`, and `clearRuntimeConfigurations` wrap the registry for common flows.
|
|
396
|
-
- **Regex exports** – `PASSWORD_REGEX` and `MNEMONIC_REGEX` are exported alongside the defaults for consumers that need the raw patterns.
|
|
305
|
+
## Secure Memory
|
|
397
306
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
> **Tip:** Services such as `ECIESService`, `Pbkdf2Service`, `AESGCMService`, and `PasswordLoginService` accept their respective configuration slices as constructor parameters. Wire them up with values from `getRuntimeConfiguration(key)` to scope behavior per feature area or tenant.
|
|
401
|
-
|
|
402
|
-
### Secure Memory Primitives
|
|
403
|
-
|
|
404
|
-
Protect sensitive data in memory:
|
|
307
|
+
XOR-obfuscated storage with checksums:
|
|
405
308
|
|
|
406
309
|
```typescript
|
|
407
310
|
import { SecureString, SecureBuffer } from '@digitaldefiance/ecies-lib';
|
|
408
311
|
|
|
409
|
-
// SecureString
|
|
312
|
+
// SecureString for passwords/mnemonics
|
|
410
313
|
const password = new SecureString('MyPassword123');
|
|
411
|
-
console.log(password.value); // Access
|
|
412
|
-
console.log(password.valueAsHexString); //
|
|
413
|
-
console.log(password.length); //
|
|
314
|
+
console.log(password.value); // Access value
|
|
315
|
+
console.log(password.valueAsHexString); // Hex format
|
|
316
|
+
console.log(password.length); // Length
|
|
414
317
|
password.dispose(); // Zero memory
|
|
415
318
|
|
|
416
|
-
// SecureBuffer
|
|
417
|
-
const
|
|
418
|
-
|
|
419
|
-
console.log(
|
|
420
|
-
console.log(
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
//
|
|
425
|
-
// -
|
|
426
|
-
// -
|
|
427
|
-
// -
|
|
428
|
-
// - Provide stack traces for debugging
|
|
319
|
+
// SecureBuffer for binary secrets
|
|
320
|
+
const key = new SecureBuffer(new Uint8Array(32));
|
|
321
|
+
console.log(key.value); // Uint8Array
|
|
322
|
+
console.log(key.valueAsString); // String
|
|
323
|
+
console.log(key.valueAsBase64String); // Base64
|
|
324
|
+
key.dispose(); // Zero memory
|
|
325
|
+
|
|
326
|
+
// Features:
|
|
327
|
+
// - XOR obfuscation in memory
|
|
328
|
+
// - Checksum validation
|
|
329
|
+
// - Disposal detection
|
|
330
|
+
// - Stack traces for debugging
|
|
429
331
|
```
|
|
430
332
|
|
|
431
|
-
|
|
333
|
+
## Value Objects
|
|
432
334
|
|
|
433
|
-
Type-safe wrappers
|
|
335
|
+
Type-safe wrappers:
|
|
434
336
|
|
|
435
337
|
```typescript
|
|
436
338
|
import { EmailString, GuidV4 } from '@digitaldefiance/ecies-lib';
|
|
437
339
|
|
|
438
|
-
// Validated
|
|
340
|
+
// Validated emails
|
|
439
341
|
const email = new EmailString('user@example.com');
|
|
440
|
-
console.log(email.toString());
|
|
441
|
-
console.log(email.length);
|
|
442
|
-
|
|
443
|
-
// Will throw on invalid email:
|
|
444
342
|
// new EmailString('invalid'); // throws InvalidEmailError
|
|
445
343
|
|
|
446
|
-
//
|
|
344
|
+
// GUIDs with multiple formats
|
|
447
345
|
const guid = GuidV4.new();
|
|
448
346
|
console.log(guid.asFullHexGuid); // "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
|
|
449
347
|
console.log(guid.asShortHexGuid); // "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
|
450
|
-
console.log(guid.asBase64Guid); // Base64
|
|
451
|
-
console.log(guid.asBigIntGuid); //
|
|
348
|
+
console.log(guid.asBase64Guid); // Base64
|
|
349
|
+
console.log(guid.asBigIntGuid); // BigInt
|
|
452
350
|
|
|
453
|
-
// Create from
|
|
351
|
+
// Create from formats
|
|
454
352
|
const fromHex = new GuidV4('550e8400-e29b-41d4-a716-446655440000');
|
|
455
353
|
const fromBase64 = new GuidV4('VQ6EAOKbQdSnFkRmVUQAAA==');
|
|
456
354
|
|
|
457
|
-
// Compare
|
|
458
|
-
if (guid.equals(fromHex)) {
|
|
459
|
-
console.log('GUIDs match');
|
|
460
|
-
}
|
|
355
|
+
// Compare
|
|
356
|
+
if (guid.equals(fromHex)) { /* ... */ }
|
|
461
357
|
```
|
|
462
358
|
|
|
463
359
|
## Error Handling
|
|
464
360
|
|
|
465
|
-
|
|
361
|
+
Typed errors with i18n (8 languages):
|
|
466
362
|
|
|
467
363
|
```typescript
|
|
468
364
|
import {
|
|
@@ -470,235 +366,127 @@ import {
|
|
|
470
366
|
ECIESErrorTypeEnum,
|
|
471
367
|
MemberError,
|
|
472
368
|
MemberErrorType,
|
|
473
|
-
GuidError,
|
|
474
|
-
GuidErrorType,
|
|
475
369
|
Pbkdf2Error,
|
|
476
370
|
Pbkdf2ErrorType,
|
|
477
371
|
} from '@digitaldefiance/ecies-lib';
|
|
478
372
|
|
|
479
|
-
// ECIES errors
|
|
480
373
|
try {
|
|
481
374
|
await ecies.decryptSimpleOrSingleWithHeader(false, privateKey, tamperedData);
|
|
482
375
|
} catch (error) {
|
|
483
376
|
if (error instanceof ECIESError) {
|
|
484
377
|
switch (error.type) {
|
|
485
378
|
case ECIESErrorTypeEnum.DecryptionFailed:
|
|
486
|
-
console.error('Decryption failed
|
|
379
|
+
console.error('Decryption failed');
|
|
487
380
|
break;
|
|
488
381
|
case ECIESErrorTypeEnum.InvalidEncryptionType:
|
|
489
|
-
console.error('Invalid encryption type
|
|
490
|
-
break;
|
|
491
|
-
case ECIESErrorTypeEnum.InvalidPublicKey:
|
|
492
|
-
console.error('Public key format is invalid');
|
|
382
|
+
console.error('Invalid encryption type');
|
|
493
383
|
break;
|
|
494
384
|
}
|
|
495
385
|
}
|
|
496
386
|
}
|
|
497
387
|
|
|
498
|
-
//
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
// All errors include:
|
|
510
|
-
// - Typed error codes (enums)
|
|
511
|
-
// - Localized messages (6 languages)
|
|
512
|
-
// - Stack traces
|
|
513
|
-
// - Optional context data
|
|
388
|
+
// Error categories:
|
|
389
|
+
// - ECIESError: Encryption/decryption
|
|
390
|
+
// - MemberError: Member operations
|
|
391
|
+
// - GuidError: GUID validation
|
|
392
|
+
// - Pbkdf2Error: Key derivation
|
|
393
|
+
// - LengthError: Data length
|
|
394
|
+
// - SecureStorageError: Memory operations
|
|
395
|
+
// - InvalidEmailError: Email validation
|
|
514
396
|
```
|
|
515
397
|
|
|
516
|
-
**Error Categories:**
|
|
517
|
-
- `ECIESError` - Encryption/decryption failures
|
|
518
|
-
- `MemberError` - Member operations
|
|
519
|
-
- `GuidError` - GUID validation
|
|
520
|
-
- `Pbkdf2Error` - Key derivation
|
|
521
|
-
- `LengthError` - Data length validation
|
|
522
|
-
- `SecureStorageError` - Secure memory operations
|
|
523
|
-
- `InvalidEmailError` - Email validation
|
|
524
|
-
|
|
525
398
|
## Architecture
|
|
526
399
|
|
|
527
|
-
###
|
|
400
|
+
### Structure
|
|
528
401
|
|
|
529
402
|
```
|
|
530
|
-
|
|
531
|
-
├──
|
|
532
|
-
│ ├──
|
|
533
|
-
│ │ ├──
|
|
534
|
-
│ │
|
|
535
|
-
│ │
|
|
536
|
-
│ │
|
|
537
|
-
│ │
|
|
538
|
-
│ │
|
|
539
|
-
│
|
|
540
|
-
│
|
|
541
|
-
│
|
|
542
|
-
│
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
├── tests/
|
|
559
|
-
│ ├── services/ # Service tests
|
|
560
|
-
│ ├── *.spec.ts # Unit tests
|
|
561
|
-
│ ├── *.e2e.spec.ts # Integration tests
|
|
562
|
-
│ └── support/ # Test utilities
|
|
563
|
-
└── package.json
|
|
403
|
+
src/
|
|
404
|
+
├── services/
|
|
405
|
+
│ ├── ecies/
|
|
406
|
+
│ │ ├── service.ts # ECIESService
|
|
407
|
+
│ │ ├── crypto-core.ts # EciesCryptoCore
|
|
408
|
+
│ │ ├── multi-recipient.ts # EciesMultiRecipient
|
|
409
|
+
│ │ ├── single-recipient.ts # EciesSingleRecipient
|
|
410
|
+
│ │ ├── file.ts # EciesFileService
|
|
411
|
+
│ │ └── signature.ts # EciesSignature
|
|
412
|
+
│ ├── aes-gcm.ts # AESGCMService
|
|
413
|
+
│ ├── pbkdf2.ts # Pbkdf2Service
|
|
414
|
+
│ ├── password-login.ts # PasswordLoginService
|
|
415
|
+
│ └── xor.ts # XorService
|
|
416
|
+
├── enumerations/ # Type-safe enums
|
|
417
|
+
├── errors/ # Typed error classes
|
|
418
|
+
├── interfaces/ # TypeScript interfaces
|
|
419
|
+
├── types/ # Type definitions
|
|
420
|
+
├── constants.ts # Constants & ConstantsRegistry
|
|
421
|
+
├── member.ts # Member class
|
|
422
|
+
├── secure-string.ts # SecureString
|
|
423
|
+
├── secure-buffer.ts # SecureBuffer
|
|
424
|
+
├── email-string.ts # EmailString
|
|
425
|
+
├── guid.ts # GuidV4
|
|
426
|
+
├── utils.ts # Utilities
|
|
427
|
+
├── i18n-setup.ts # i18n configuration
|
|
428
|
+
└── index.ts # Public API
|
|
429
|
+
|
|
430
|
+
tests/ # 32 test files, 389+ specs
|
|
564
431
|
```
|
|
565
432
|
|
|
566
433
|
### Key Concepts
|
|
567
434
|
|
|
568
435
|
**Encryption Modes:**
|
|
569
|
-
-
|
|
570
|
-
-
|
|
571
|
-
-
|
|
436
|
+
- Simple: 98-byte overhead (type + pubkey + IV + tag)
|
|
437
|
+
- Single: 106-byte overhead (Simple + 8-byte length)
|
|
438
|
+
- Multiple: Shared symmetric key per recipient
|
|
572
439
|
|
|
573
440
|
**Key Derivation:**
|
|
574
|
-
- BIP39
|
|
575
|
-
- Deterministic
|
|
576
|
-
-
|
|
577
|
-
|
|
578
|
-
**Security
|
|
579
|
-
- AES-GCM authenticated encryption
|
|
580
|
-
- ECDH key agreement
|
|
581
|
-
- PBKDF2
|
|
582
|
-
- Memory-safe storage with
|
|
441
|
+
- BIP39 mnemonic → BIP32 HD wallet → secp256k1 keypair
|
|
442
|
+
- Deterministic generation
|
|
443
|
+
- Custom derivation paths supported
|
|
444
|
+
|
|
445
|
+
**Security:**
|
|
446
|
+
- AES-256-GCM authenticated encryption
|
|
447
|
+
- ECDH key agreement (secp256k1)
|
|
448
|
+
- PBKDF2 with configurable iterations
|
|
449
|
+
- Memory-safe storage with auto-zeroing
|
|
583
450
|
- XOR obfuscation for in-memory secrets
|
|
584
451
|
|
|
585
|
-
## Quality gates
|
|
586
|
-
|
|
587
|
-
The project ships with mandatory linting, formatting, and testing commands:
|
|
588
|
-
|
|
589
|
-
```bash
|
|
590
|
-
yarn lint # ESLint across src/**/*.ts
|
|
591
|
-
yarn prettier:check # Enforce formatting
|
|
592
|
-
yarn test # Jest unit + e2e suites
|
|
593
|
-
yarn build # Compile TypeScript into dist/
|
|
594
|
-
```
|
|
595
|
-
|
|
596
|
-
Continuous integration mirrors these gates, and the repository currently passes 389 Jest specs (unit + e2e).
|
|
597
|
-
|
|
598
|
-
## Browser vs. Node tips
|
|
599
|
-
|
|
600
|
-
- **Node**: Node 18+ exposes `globalThis.crypto`. If you target older runtimes, polyfill before importing the library:
|
|
601
|
-
|
|
602
|
-
```ts
|
|
603
|
-
import { webcrypto } from 'crypto';
|
|
604
|
-
globalThis.crypto = webcrypto as unknown as Crypto;
|
|
605
|
-
```
|
|
606
|
-
|
|
607
|
-
- **Browser bundlers**: the package ships TypeScript sources; rely on your bundler (Vite, Webpack, Next.js) to tree-shake unused exports. All external dependencies are ESM-friendly.
|
|
608
|
-
- **Memory hygiene**: many helpers (e.g., `SecureBuffer`) provide `.dispose()` to zero sensitive data. Call them when you’re done.
|
|
609
|
-
|
|
610
|
-
## API Reference
|
|
611
|
-
|
|
612
|
-
### Main Exports
|
|
613
|
-
|
|
614
|
-
```typescript
|
|
615
|
-
// Services
|
|
616
|
-
export { ECIESService } from './services/ecies/service';
|
|
617
|
-
export { EciesCryptoCore } from './services/ecies/crypto-core';
|
|
618
|
-
export { EciesMultiRecipient } from './services/ecies/multi-recipient';
|
|
619
|
-
export { EciesFileService } from './services/ecies/file';
|
|
620
|
-
export { AESGCMService } from './services/aes-gcm';
|
|
621
|
-
export { Pbkdf2Service } from './services/pbkdf2';
|
|
622
|
-
export { PasswordLoginService } from './services/password-login';
|
|
623
|
-
export { XorService } from './services/xor';
|
|
624
|
-
|
|
625
|
-
// Member System
|
|
626
|
-
export { Member } from './member';
|
|
627
|
-
export { MemberType } from './enumerations/member-type';
|
|
628
|
-
|
|
629
|
-
// Secure Primitives
|
|
630
|
-
export { SecureString } from './secure-string';
|
|
631
|
-
export { SecureBuffer } from './secure-buffer';
|
|
632
|
-
export { EmailString } from './email-string';
|
|
633
|
-
export { GuidV4 } from './guid';
|
|
634
|
-
|
|
635
|
-
// Configuration
|
|
636
|
-
export { Defaults, ECIES, PBKDF2, CHECKSUM } from './defaults';
|
|
637
|
-
export { DefaultsRegistry } from './defaults';
|
|
638
|
-
export { Constants } from './constants';
|
|
639
|
-
|
|
640
|
-
// Enumerations
|
|
641
|
-
export { EciesEncryptionTypeEnum } from './enumerations/ecies-encryption-type';
|
|
642
|
-
export { Pbkdf2ProfileEnum } from './enumerations/pbkdf2-profile';
|
|
643
|
-
export { MemberErrorType } from './enumerations/member-error-type';
|
|
644
|
-
export { ECIESErrorTypeEnum } from './enumerations/ecies-error-type';
|
|
645
|
-
|
|
646
|
-
// Errors
|
|
647
|
-
export { ECIESError } from './errors/ecies';
|
|
648
|
-
export { MemberError } from './errors/member';
|
|
649
|
-
export { GuidError } from './errors/guid';
|
|
650
|
-
export { Pbkdf2Error } from './errors/pbkdf2';
|
|
651
|
-
|
|
652
|
-
// Utilities
|
|
653
|
-
export * from './utils';
|
|
654
|
-
|
|
655
|
-
// Internationalization
|
|
656
|
-
export { getEciesI18nEngine } from './i18n-setup';
|
|
657
|
-
```
|
|
658
|
-
|
|
659
452
|
## Development
|
|
660
453
|
|
|
661
|
-
###
|
|
454
|
+
### Commands
|
|
662
455
|
|
|
663
456
|
```bash
|
|
664
|
-
yarn install
|
|
665
|
-
yarn build
|
|
666
|
-
yarn test
|
|
667
|
-
yarn
|
|
668
|
-
yarn
|
|
457
|
+
yarn install # Install dependencies
|
|
458
|
+
yarn build # Compile TypeScript
|
|
459
|
+
yarn test # Run all tests (389+ specs)
|
|
460
|
+
yarn test:stream # Stream test output
|
|
461
|
+
yarn lint # ESLint check
|
|
462
|
+
yarn lint:fix # Auto-fix issues
|
|
463
|
+
yarn prettier:check # Format check
|
|
464
|
+
yarn prettier:fix # Auto-format
|
|
465
|
+
yarn format # Fix all (prettier + lint)
|
|
669
466
|
```
|
|
670
467
|
|
|
671
468
|
### Testing
|
|
672
469
|
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
yarn test --watch # Watch mode
|
|
677
|
-
yarn test file.spec.ts # Run specific test
|
|
678
|
-
```
|
|
679
|
-
|
|
680
|
-
The library includes 380+ test specifications covering:
|
|
681
|
-
- Unit tests for all services and utilities
|
|
682
|
-
- Integration tests for encryption workflows
|
|
470
|
+
32 test files covering:
|
|
471
|
+
- Unit tests for all services
|
|
472
|
+
- Integration tests for workflows
|
|
683
473
|
- E2E tests for password login and file encryption
|
|
684
|
-
- Cross-platform compatibility
|
|
474
|
+
- Cross-platform compatibility
|
|
685
475
|
- Error handling and edge cases
|
|
686
476
|
|
|
687
|
-
###
|
|
477
|
+
### Quality Gates
|
|
688
478
|
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
yarn format # Fix all issues
|
|
695
|
-
```
|
|
479
|
+
CI enforces:
|
|
480
|
+
- ESLint (no errors)
|
|
481
|
+
- Prettier formatting
|
|
482
|
+
- 389+ Jest specs passing
|
|
483
|
+
- TypeScript compilation
|
|
696
484
|
|
|
697
|
-
## Platform
|
|
485
|
+
## Platform Notes
|
|
698
486
|
|
|
699
487
|
### Node.js
|
|
700
488
|
|
|
701
|
-
Node
|
|
489
|
+
Node 18+ includes Web Crypto API. For older versions:
|
|
702
490
|
|
|
703
491
|
```typescript
|
|
704
492
|
import { webcrypto } from 'crypto';
|
|
@@ -707,17 +495,16 @@ globalThis.crypto = webcrypto as unknown as Crypto;
|
|
|
707
495
|
|
|
708
496
|
### Browser
|
|
709
497
|
|
|
710
|
-
|
|
711
|
-
-
|
|
712
|
-
- No polyfills
|
|
713
|
-
- Tree-shakeable with
|
|
714
|
-
-
|
|
498
|
+
Works in all modern browsers:
|
|
499
|
+
- Web Crypto API for cryptography
|
|
500
|
+
- No polyfills needed
|
|
501
|
+
- Tree-shakeable with Vite/Webpack/Rollup
|
|
502
|
+
- ESM-compatible dependencies
|
|
715
503
|
|
|
716
|
-
### Bundler
|
|
504
|
+
### Bundler Config
|
|
717
505
|
|
|
718
506
|
**Vite:**
|
|
719
507
|
```javascript
|
|
720
|
-
// vite.config.js
|
|
721
508
|
export default {
|
|
722
509
|
optimizeDeps: {
|
|
723
510
|
include: ['@digitaldefiance/ecies-lib']
|
|
@@ -727,7 +514,6 @@ export default {
|
|
|
727
514
|
|
|
728
515
|
**Webpack:**
|
|
729
516
|
```javascript
|
|
730
|
-
// webpack.config.js
|
|
731
517
|
module.exports = {
|
|
732
518
|
resolve: {
|
|
733
519
|
fallback: {
|
|
@@ -740,7 +526,7 @@ module.exports = {
|
|
|
740
526
|
|
|
741
527
|
### Memory Management
|
|
742
528
|
|
|
743
|
-
Always dispose
|
|
529
|
+
Always dispose sensitive data:
|
|
744
530
|
|
|
745
531
|
```typescript
|
|
746
532
|
const password = new SecureString('secret');
|
|
@@ -749,13 +535,43 @@ try {
|
|
|
749
535
|
} finally {
|
|
750
536
|
password.dispose(); // Zeros memory
|
|
751
537
|
}
|
|
538
|
+
```
|
|
752
539
|
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
540
|
+
## API Reference
|
|
541
|
+
|
|
542
|
+
### Main Exports
|
|
543
|
+
|
|
544
|
+
```typescript
|
|
545
|
+
// Services
|
|
546
|
+
export { ECIESService, EciesCryptoCore, EciesMultiRecipient, EciesFileService };
|
|
547
|
+
export { AESGCMService, Pbkdf2Service, PasswordLoginService, XorService };
|
|
548
|
+
|
|
549
|
+
// Member System
|
|
550
|
+
export { Member, MemberType };
|
|
551
|
+
|
|
552
|
+
// Secure Primitives
|
|
553
|
+
export { SecureString, SecureBuffer, EmailString, GuidV4 };
|
|
554
|
+
|
|
555
|
+
// Configuration
|
|
556
|
+
export { Constants, ConstantsRegistry, CHECKSUM, ECIES, PBKDF2 };
|
|
557
|
+
export { createRuntimeConfiguration, getRuntimeConfiguration };
|
|
558
|
+
export { registerRuntimeConfiguration, unregisterRuntimeConfiguration };
|
|
559
|
+
export { PASSWORD_REGEX, MNEMONIC_REGEX };
|
|
560
|
+
|
|
561
|
+
// Enumerations
|
|
562
|
+
export { EciesEncryptionTypeEnum, Pbkdf2ProfileEnum };
|
|
563
|
+
export { MemberErrorType, ECIESErrorTypeEnum };
|
|
564
|
+
|
|
565
|
+
// Errors
|
|
566
|
+
export { ECIESError, MemberError, GuidError, Pbkdf2Error };
|
|
567
|
+
export { LengthError, SecureStorageError, InvalidEmailError };
|
|
568
|
+
|
|
569
|
+
// Utilities
|
|
570
|
+
export { concatUint8Arrays, uint8ArrayToHex, hexToUint8Array };
|
|
571
|
+
export { uint8ArrayToBase64, base64ToUint8Array };
|
|
572
|
+
|
|
573
|
+
// i18n
|
|
574
|
+
export { getEciesI18nEngine, EciesI18nEngine };
|
|
759
575
|
```
|
|
760
576
|
|
|
761
577
|
## Contributing
|
|
@@ -776,12 +592,23 @@ If you discover a vulnerability, please **do not** open a public issue. Email <s
|
|
|
776
592
|
|
|
777
593
|
MIT © Digital Defiance
|
|
778
594
|
|
|
779
|
-
##
|
|
595
|
+
## Links
|
|
780
596
|
|
|
781
|
-
|
|
597
|
+
- **Repository:** https://github.com/Digital-Defiance/ecies-lib
|
|
598
|
+
- **npm:** https://www.npmjs.com/package/@digitaldefiance/ecies-lib
|
|
599
|
+
- **Companion:** @digitaldefiance/node-ecies-lib (binary compatible)
|
|
782
600
|
|
|
783
601
|
## ChangeLog
|
|
784
602
|
|
|
603
|
+
### v1.1.15
|
|
604
|
+
|
|
605
|
+
- CommonJS
|
|
606
|
+
- Update i18n
|
|
607
|
+
|
|
608
|
+
### v1.1.14
|
|
609
|
+
|
|
610
|
+
- Update readme
|
|
611
|
+
|
|
785
612
|
### v1.1.13
|
|
786
613
|
|
|
787
614
|
- Upgrade i18n to plugin engine
|