@digitaldefiance/ecies-lib 1.0.23 → 1.0.25
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 +131 -4
- package/dist/constants.d.ts +0 -13
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +3 -164
- package/dist/constants.js.map +1 -1
- package/dist/defaults.d.ts +37 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +323 -0
- package/dist/defaults.js.map +1 -0
- package/dist/enumerations/ecies-string-key.d.ts +1 -0
- package/dist/enumerations/ecies-string-key.d.ts.map +1 -1
- package/dist/enumerations/ecies-string-key.js +1 -0
- package/dist/enumerations/ecies-string-key.js.map +1 -1
- package/dist/enumerations/pbkdf2-error-type.d.ts +1 -0
- package/dist/enumerations/pbkdf2-error-type.d.ts.map +1 -1
- package/dist/enumerations/pbkdf2-error-type.js +1 -0
- package/dist/enumerations/pbkdf2-error-type.js.map +1 -1
- package/dist/i18n-setup.d.ts.map +1 -1
- package/dist/i18n-setup.js +5 -0
- package/dist/i18n-setup.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/constants.d.ts +2 -29
- package/dist/interfaces/constants.d.ts.map +1 -1
- package/dist/interfaces/defaults.d.ts +35 -0
- package/dist/interfaces/defaults.d.ts.map +1 -0
- package/dist/interfaces/defaults.js +2 -0
- package/dist/interfaces/defaults.js.map +1 -0
- package/dist/interfaces/index.d.ts +1 -1
- package/dist/interfaces/index.d.ts.map +1 -1
- package/dist/interfaces/index.js +1 -1
- package/dist/interfaces/index.js.map +1 -1
- package/dist/interfaces/member-operational.d.ts +3 -2
- package/dist/interfaces/member-operational.d.ts.map +1 -1
- package/dist/member.d.ts +7 -9
- package/dist/member.d.ts.map +1 -1
- package/dist/member.js +13 -13
- package/dist/member.js.map +1 -1
- package/dist/regexes.d.ts +3 -0
- package/dist/regexes.d.ts.map +1 -0
- package/dist/regexes.js +3 -0
- package/dist/regexes.js.map +1 -0
- package/dist/services/aes-gcm.d.ts +4 -3
- package/dist/services/aes-gcm.d.ts.map +1 -1
- package/dist/services/aes-gcm.js +13 -10
- package/dist/services/aes-gcm.js.map +1 -1
- package/dist/services/ecies/crypto-core.d.ts +4 -2
- package/dist/services/ecies/crypto-core.d.ts.map +1 -1
- package/dist/services/ecies/crypto-core.js +9 -7
- package/dist/services/ecies/crypto-core.js.map +1 -1
- package/dist/services/ecies/multi-recipient.d.ts +5 -2
- package/dist/services/ecies/multi-recipient.d.ts.map +1 -1
- package/dist/services/ecies/multi-recipient.js +36 -34
- package/dist/services/ecies/multi-recipient.js.map +1 -1
- package/dist/services/ecies/service.d.ts +9 -5
- package/dist/services/ecies/service.d.ts.map +1 -1
- package/dist/services/ecies/service.js +16 -14
- package/dist/services/ecies/service.js.map +1 -1
- package/dist/services/ecies/single-recipient.d.ts +6 -3
- package/dist/services/ecies/single-recipient.d.ts.map +1 -1
- package/dist/services/ecies/single-recipient.js +27 -25
- package/dist/services/ecies/single-recipient.js.map +1 -1
- package/dist/services/password-login.d.ts +3 -1
- package/dist/services/password-login.d.ts.map +1 -1
- package/dist/services/password-login.js +6 -3
- package/dist/services/password-login.js.map +1 -1
- package/dist/services/pbkdf2.d.ts +7 -3
- package/dist/services/pbkdf2.d.ts.map +1 -1
- package/dist/services/pbkdf2.js +16 -7
- package/dist/services/pbkdf2.js.map +1 -1
- package/dist/types/deep-partial.d.ts +4 -0
- package/dist/types/deep-partial.d.ts.map +1 -0
- package/dist/types/deep-partial.js +2 -0
- package/dist/types/deep-partial.js.map +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -131,15 +131,35 @@ See `src/services/ecies/file.ts` and `tests/services/ecies/file.spec.ts` for str
|
|
|
131
131
|
The library also addresses user authentication workflows. `PasswordLoginService` manages PBKDF2 hashing, login challenges, and secure storage, while `Pbkdf2Service` exposes low-level derivation utilities and hardened presets.
|
|
132
132
|
|
|
133
133
|
```ts
|
|
134
|
-
import {
|
|
134
|
+
import {
|
|
135
|
+
PasswordLoginService,
|
|
136
|
+
Pbkdf2Service,
|
|
137
|
+
Pbkdf2ProfileEnum,
|
|
138
|
+
I18nEngine
|
|
139
|
+
} from '@digitaldefiance/ecies-lib';
|
|
135
140
|
|
|
136
141
|
const passwordService = new PasswordLoginService();
|
|
137
142
|
|
|
143
|
+
// Create a PBKDF2 service with default profiles
|
|
144
|
+
const engine = new I18nEngine(); // Your i18n engine instance
|
|
145
|
+
const pbkdf2Service = new Pbkdf2Service(engine);
|
|
146
|
+
|
|
147
|
+
// Or create with custom profiles
|
|
148
|
+
const customProfiles = {
|
|
149
|
+
CUSTOM_PROFILE: {
|
|
150
|
+
hashBytes: 32,
|
|
151
|
+
saltBytes: 16,
|
|
152
|
+
iterations: 100000,
|
|
153
|
+
algorithm: 'SHA-256'
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
const customPbkdf2Service = new Pbkdf2Service(engine, customProfiles);
|
|
157
|
+
|
|
138
158
|
// Derive a login hash with a hardened profile
|
|
139
159
|
const passwordBytes = new TextEncoder().encode('xX_password_Xx!');
|
|
140
|
-
const
|
|
160
|
+
const pbkdf2Result = await pbkdf2Service.deriveKeyFromPasswordWithProfileAsync(
|
|
141
161
|
passwordBytes,
|
|
142
|
-
|
|
162
|
+
Pbkdf2ProfileEnum.BROWSER_PASSWORD,
|
|
143
163
|
);
|
|
144
164
|
|
|
145
165
|
const loginPayload = await passwordService.generateLoginPayload({
|
|
@@ -150,6 +170,87 @@ const loginPayload = await passwordService.generateLoginPayload({
|
|
|
150
170
|
|
|
151
171
|
Check `src/services/password-login.ts` and the comprehensive spec files in `tests/password-login*.spec.ts` and `tests/pbkdf2*.spec.ts` for concrete edge cases.
|
|
152
172
|
|
|
173
|
+
### PBKDF2 Service Configuration
|
|
174
|
+
|
|
175
|
+
The `Pbkdf2Service` constructor accepts an optional profiles parameter, allowing you to customize or extend the default PBKDF2 configurations:
|
|
176
|
+
|
|
177
|
+
```ts
|
|
178
|
+
import { Pbkdf2Service, IPbkdf2Config } from '@digitaldefiance/ecies-lib';
|
|
179
|
+
|
|
180
|
+
// Using default profiles from constants
|
|
181
|
+
const pbkdf2Service = new Pbkdf2Service(engine);
|
|
182
|
+
|
|
183
|
+
// Using custom profiles
|
|
184
|
+
const customProfiles: Record<string, IPbkdf2Config> = {
|
|
185
|
+
HIGH_SECURITY: {
|
|
186
|
+
hashBytes: 64,
|
|
187
|
+
saltBytes: 32,
|
|
188
|
+
iterations: 200000,
|
|
189
|
+
algorithm: 'SHA-512'
|
|
190
|
+
},
|
|
191
|
+
FAST_TESTING: {
|
|
192
|
+
hashBytes: 32,
|
|
193
|
+
saltBytes: 16,
|
|
194
|
+
iterations: 1000,
|
|
195
|
+
algorithm: 'SHA-256'
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
const customPbkdf2Service = new Pbkdf2Service(engine, customProfiles);
|
|
200
|
+
|
|
201
|
+
// Use a custom profile
|
|
202
|
+
const result = await customPbkdf2Service.deriveKeyFromPasswordWithProfileAsync(
|
|
203
|
+
passwordBytes,
|
|
204
|
+
'HIGH_SECURITY'
|
|
205
|
+
);
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
This design allows for dependency injection of PBKDF2 profiles while maintaining backward compatibility with the default configurations.
|
|
209
|
+
|
|
210
|
+
## Runtime configuration registry
|
|
211
|
+
|
|
212
|
+
Many applications need different cryptographic trade-offs for different surfaces—e.g., a login form that prioritizes speed versus an administrative workflow that prefers extreme iteration counts. The library ships a registry that lets you register, retrieve, and extend immutable configuration profiles without mutating the global defaults.
|
|
213
|
+
|
|
214
|
+
```ts
|
|
215
|
+
import {
|
|
216
|
+
DefaultsRegistry,
|
|
217
|
+
registerRuntimeConfiguration,
|
|
218
|
+
getRuntimeConfiguration,
|
|
219
|
+
ECIESService,
|
|
220
|
+
Pbkdf2Service,
|
|
221
|
+
} from '@digitaldefiance/ecies-lib';
|
|
222
|
+
|
|
223
|
+
// 1. Register two named profiles
|
|
224
|
+
registerRuntimeConfiguration('security-first', {
|
|
225
|
+
PBKDF2: {
|
|
226
|
+
ITERATIONS_PER_SECOND: 3_000_000,
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
registerRuntimeConfiguration(
|
|
231
|
+
'performance-first',
|
|
232
|
+
{
|
|
233
|
+
PBKDF2: {
|
|
234
|
+
ITERATIONS_PER_SECOND: 250_000,
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
{ baseKey: DefaultsRegistry.DEFAULT_KEY },
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
// 2. Spin up services that honor those profiles
|
|
241
|
+
const secureDefaults = getRuntimeConfiguration('security-first');
|
|
242
|
+
const secureEcies = new ECIESService(undefined, secureDefaults.ECIES);
|
|
243
|
+
const securePbkdf2 = new Pbkdf2Service(engine, secureDefaults.PBKDF2_PROFILES, secureDefaults.ECIES, secureDefaults.PBKDF2);
|
|
244
|
+
|
|
245
|
+
const perfDefaults = getRuntimeConfiguration('performance-first');
|
|
246
|
+
const perfEcies = new ECIESService(undefined, perfDefaults.ECIES);
|
|
247
|
+
|
|
248
|
+
// 3. Optional: create throwaway profiles without registering them
|
|
249
|
+
const temporaryDefaults = DefaultsRegistry.create({ BcryptRounds: 8 });
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
Every profile returned by the registry is deeply frozen and validated so the low-level invariants (public key sizes, checksum parameters, etc.) stay consistent. Use `clearRuntimeConfigurations()` in tests to reset to the library defaults.
|
|
253
|
+
|
|
153
254
|
## Secure primitives & value objects
|
|
154
255
|
|
|
155
256
|
- `SecureString` / `SecureBuffer`: auto-zero, opt-in disposal, and helper methods for dealing with sensitive material.
|
|
@@ -178,7 +279,7 @@ try {
|
|
|
178
279
|
|
|
179
280
|
## Project structure
|
|
180
281
|
|
|
181
|
-
```
|
|
282
|
+
```text
|
|
182
283
|
packages/digitaldefiance-ecies-lib/
|
|
183
284
|
├─ src/
|
|
184
285
|
│ ├─ services/ # ECIES, AES-GCM, PBKDF2, password login
|
|
@@ -244,6 +345,32 @@ MIT © Digital Defiance
|
|
|
244
345
|
|
|
245
346
|
## ChangeLog
|
|
246
347
|
|
|
348
|
+
### v1.0.25: Rework configuration system again
|
|
349
|
+
|
|
350
|
+
- Sun Oct 12 2025 21:02:00 GMT-0700 (Pacific Daylight Time)
|
|
351
|
+
- Rework various services to support user-provided configurations
|
|
352
|
+
|
|
353
|
+
### v1.0.24: Rework pbdkf2 services, and other things and provide ways of overriding constants
|
|
354
|
+
|
|
355
|
+
- Sun Oct 12 2025 18:25:00 GMT-0700 (Pacific Daylight Time)
|
|
356
|
+
- Refactor Pbkdf2Service to accept custom profiles via constructor instead of using static constants
|
|
357
|
+
- Add dependency injection support for ECIES constants across all crypto services
|
|
358
|
+
- Update all service classes (AESGCMService, ECIESService, etc.) to accept configurable parameters
|
|
359
|
+
- Add new InvalidProfile error type with multilingual support (en, fr, zh, es, uk)
|
|
360
|
+
- Update Member class to support custom ECIES parameters in wallet operations
|
|
361
|
+
- Refactor tests to use mocked I18nEngine instead of global instance
|
|
362
|
+
- Maintain backward compatibility with default constants when no custom params provided
|
|
363
|
+
- Update README with examples showing custom profile configuration
|
|
364
|
+
- Bump version to 1.0.24
|
|
365
|
+
|
|
366
|
+
Breaking Changes:
|
|
367
|
+
- Pbkdf2Service constructor now requires I18nEngine as first parameter
|
|
368
|
+
- Service classes now accept optional parameter objects for customization
|
|
369
|
+
- Test setup requires explicit I18nEngine mocking
|
|
370
|
+
|
|
371
|
+
This change enables better testability, configurability, and dependency injection
|
|
372
|
+
while maintaining existing API compatibility for default use cases.
|
|
373
|
+
|
|
247
374
|
### v1.0.23: Patch release to fix constant exports
|
|
248
375
|
|
|
249
376
|
- Sun Oct 12 2025 16:20:00 GMT-0700 (Pacific Daylight Time)
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import { IChecksumConsts } from './interfaces';
|
|
2
1
|
import { IConstants } from './interfaces/constants';
|
|
3
|
-
import { IECIESConstants } from './interfaces/ecies-consts';
|
|
4
|
-
import { IPBkdf2Consts } from './interfaces/pbkdf2-consts';
|
|
5
|
-
import { Pbkdf2Profiles } from './pbkdf2-profiles';
|
|
6
2
|
export declare const UINT8_SIZE: number;
|
|
7
3
|
export declare const UINT16_SIZE: number;
|
|
8
4
|
export declare const UINT16_MAX: number;
|
|
@@ -14,14 +10,5 @@ export declare const UINT64_MAX: bigint;
|
|
|
14
10
|
* Standard size of a UUID v4 in bytes.
|
|
15
11
|
*/
|
|
16
12
|
export declare const GUID_SIZE: number;
|
|
17
|
-
/**
|
|
18
|
-
* Constants for checksum operations
|
|
19
|
-
* These values are critical for data integrity and MUST NOT be changed
|
|
20
|
-
* in an already established system as it will break all existing checksums.
|
|
21
|
-
*/
|
|
22
|
-
export declare const CHECKSUM: IChecksumConsts;
|
|
23
|
-
export declare const PBKDF2: IPBkdf2Consts;
|
|
24
|
-
export declare const PBKDF2_PROFILES: Pbkdf2Profiles;
|
|
25
|
-
export declare const ECIES: IECIESConstants;
|
|
26
13
|
export declare const Constants: IConstants;
|
|
27
14
|
//# sourceMappingURL=constants.d.ts.map
|
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAEpD,eAAO,MAAM,UAAU,EAAE,MAAmB,CAAC;AAC7C,eAAO,MAAM,WAAW,EAAE,MAAmB,CAAC;AAC9C,eAAO,MAAM,UAAU,EAAE,MAAuB,CAAC;AACjD,eAAO,MAAM,WAAW,EAAE,MAAmB,CAAC;AAC9C,eAAO,MAAM,UAAU,EAAE,MAA4B,CAAC;AACtD,eAAO,MAAM,WAAW,EAAE,MAAmB,CAAC;AAC9C,eAAO,MAAM,UAAU,EAAE,MAAuC,CAAC;AACjE;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,MAAoB,CAAC;AAI7C,eAAO,MAAM,SAAS,EAAE,UAiBb,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { ObjectId } from 'bson';
|
|
2
|
-
import {
|
|
3
|
-
import { Pbkdf2ProfileEnum } from './enumerations/pbkdf2-profile';
|
|
4
|
-
import { ECIESError } from './errors/ecies';
|
|
5
|
-
import { getCompatibleEciesEngine } from './i18n-setup';
|
|
2
|
+
import { MNEMONIC_REGEX, PASSWORD_REGEX } from './regexes';
|
|
6
3
|
export const UINT8_SIZE = 1;
|
|
7
4
|
export const UINT16_SIZE = 2;
|
|
8
5
|
export const UINT16_MAX = 65535;
|
|
@@ -14,122 +11,6 @@ export const UINT64_MAX = 18446744073709551615n;
|
|
|
14
11
|
* Standard size of a UUID v4 in bytes.
|
|
15
12
|
*/
|
|
16
13
|
export const GUID_SIZE = 16;
|
|
17
|
-
/**
|
|
18
|
-
* Constants for checksum operations
|
|
19
|
-
* These values are critical for data integrity and MUST NOT be changed
|
|
20
|
-
* in an already established system as it will break all existing checksums.
|
|
21
|
-
*/
|
|
22
|
-
export const CHECKSUM = Object.freeze({
|
|
23
|
-
/** Default hash bits for SHA3 */
|
|
24
|
-
SHA3_DEFAULT_HASH_BITS: 512,
|
|
25
|
-
/** Length of a SHA3 checksum buffer in bytes */
|
|
26
|
-
SHA3_BUFFER_LENGTH: 64,
|
|
27
|
-
/** algorithm to use for checksum */
|
|
28
|
-
ALGORITHM: 'sha3-512',
|
|
29
|
-
/** encoding to use for checksum */
|
|
30
|
-
ENCODING: 'hex',
|
|
31
|
-
});
|
|
32
|
-
export const PBKDF2 = Object.freeze({
|
|
33
|
-
ALGORITHM: 'SHA-256',
|
|
34
|
-
SALT_BYTES: 32,
|
|
35
|
-
/**
|
|
36
|
-
* Number of pbkdf2 iterations per second when hashing a password.
|
|
37
|
-
* This is the high-security default for user login operations.
|
|
38
|
-
*/
|
|
39
|
-
ITERATIONS_PER_SECOND: 1304000,
|
|
40
|
-
});
|
|
41
|
-
export const PBKDF2_PROFILES = Object.freeze({
|
|
42
|
-
[Pbkdf2ProfileEnum.BROWSER_PASSWORD]: Object.freeze({
|
|
43
|
-
hashBytes: 32,
|
|
44
|
-
saltBytes: 64,
|
|
45
|
-
iterations: 2000000,
|
|
46
|
-
algorithm: 'SHA-512',
|
|
47
|
-
}),
|
|
48
|
-
[Pbkdf2ProfileEnum.HIGH_SECURITY]: Object.freeze({
|
|
49
|
-
hashBytes: 64,
|
|
50
|
-
saltBytes: 32,
|
|
51
|
-
iterations: 5000000,
|
|
52
|
-
algorithm: 'SHA-256',
|
|
53
|
-
}),
|
|
54
|
-
[Pbkdf2ProfileEnum.TEST_FAST]: Object.freeze({
|
|
55
|
-
hashBytes: 32,
|
|
56
|
-
saltBytes: 64,
|
|
57
|
-
iterations: 1000,
|
|
58
|
-
algorithm: 'SHA-512',
|
|
59
|
-
}),
|
|
60
|
-
});
|
|
61
|
-
const ECIES_SYMMETRIC_KEY_SIZE = 32;
|
|
62
|
-
const ECIES_PUBLIC_KEY_LENGTH = 65;
|
|
63
|
-
const ECIES_RAW_PUBLIC_KEY_LENGTH = 64;
|
|
64
|
-
const ECIES_IV_SIZE = 16;
|
|
65
|
-
const ECIES_AUTH_TAG_SIZE = 16;
|
|
66
|
-
const ECIES_MULTIPLE_RECIPIENT_ID_SIZE = 16;
|
|
67
|
-
// Define the expected value for SIMPLE.FIXED_OVERHEAD_SIZE
|
|
68
|
-
const expectedSimpleOverhead = UINT8_SIZE + ECIES_PUBLIC_KEY_LENGTH + ECIES_IV_SIZE + ECIES_AUTH_TAG_SIZE;
|
|
69
|
-
// Define the expected value for MULTIPLE.FIXED_OVERHEAD_SIZE
|
|
70
|
-
// Includes: type (1) + IV (16) + auth tag (16) = 33 (no CRC, AES-GCM provides authentication)
|
|
71
|
-
const expectedMultipleOverhead = UINT8_SIZE + ECIES_IV_SIZE + ECIES_AUTH_TAG_SIZE;
|
|
72
|
-
// Update ENCRYPTED_KEY_SIZE to match Simple encryption (no CRC)
|
|
73
|
-
const expectedMultipleEncryptedKeySize = ECIES_PUBLIC_KEY_LENGTH +
|
|
74
|
-
ECIES_IV_SIZE +
|
|
75
|
-
ECIES_AUTH_TAG_SIZE +
|
|
76
|
-
ECIES_SYMMETRIC_KEY_SIZE;
|
|
77
|
-
export const ECIES = Object.freeze({
|
|
78
|
-
/** The elliptic curve to use for all ECDSA operations */
|
|
79
|
-
CURVE_NAME: 'secp256k1',
|
|
80
|
-
/** The primary key derivation path for HD wallets */
|
|
81
|
-
PRIMARY_KEY_DERIVATION_PATH: "m/44'/60'/0'/0/0",
|
|
82
|
-
SYMMETRIC_ALGORITHM_CONFIGURATION: 'aes-256-gcm',
|
|
83
|
-
/** Length of ECDSA signatures in bytes */
|
|
84
|
-
SIGNATURE_SIZE: 64,
|
|
85
|
-
/** Length of raw public keys in bytes (without 0x04 prefix) */
|
|
86
|
-
RAW_PUBLIC_KEY_LENGTH: ECIES_RAW_PUBLIC_KEY_LENGTH,
|
|
87
|
-
/** Length of public keys in bytes (with 0x04 prefix) */
|
|
88
|
-
PUBLIC_KEY_LENGTH: ECIES_PUBLIC_KEY_LENGTH,
|
|
89
|
-
PUBLIC_KEY_MAGIC: 0x04,
|
|
90
|
-
/** Mnemonic strength in bits. This will produce a 32-bit key for ECDSA */
|
|
91
|
-
MNEMONIC_STRENGTH: 256,
|
|
92
|
-
/** Symmetric encryption algorithm configuration */
|
|
93
|
-
SYMMETRIC: Object.freeze({
|
|
94
|
-
ALGORITHM: 'aes',
|
|
95
|
-
MODE: 'gcm',
|
|
96
|
-
KEY_BITS: 256,
|
|
97
|
-
KEY_SIZE: ECIES_SYMMETRIC_KEY_SIZE, // KEY_BITS / 8
|
|
98
|
-
}),
|
|
99
|
-
IV_SIZE: ECIES_IV_SIZE,
|
|
100
|
-
AUTH_TAG_SIZE: ECIES_AUTH_TAG_SIZE,
|
|
101
|
-
MAX_RAW_DATA_SIZE: 9007199254740991, // 2^53 - 1 (max safe integer for JS)
|
|
102
|
-
/**
|
|
103
|
-
* Message encrypts without data length or crc
|
|
104
|
-
*/
|
|
105
|
-
SIMPLE: Object.freeze({
|
|
106
|
-
FIXED_OVERHEAD_SIZE: expectedSimpleOverhead, // type (1) + public key (65) + IV (16) + auth tag (16)
|
|
107
|
-
DATA_LENGTH_SIZE: 0,
|
|
108
|
-
}),
|
|
109
|
-
/**
|
|
110
|
-
* Message encrypts with data length but no CRC (AES-GCM provides authentication)
|
|
111
|
-
*/
|
|
112
|
-
SINGLE: Object.freeze({
|
|
113
|
-
FIXED_OVERHEAD_SIZE: 106, // type (1) + public key (65) + IV (16) + auth tag (16) + data length (8)
|
|
114
|
-
DATA_LENGTH_SIZE: 8,
|
|
115
|
-
}),
|
|
116
|
-
/**
|
|
117
|
-
* Message encrypts for multiple recipients
|
|
118
|
-
*/
|
|
119
|
-
MULTIPLE: Object.freeze({
|
|
120
|
-
FIXED_OVERHEAD_SIZE: expectedMultipleOverhead, // type (1) + IV (16) + auth tag (16), no CRC
|
|
121
|
-
ENCRYPTED_KEY_SIZE: expectedMultipleEncryptedKeySize, // 129
|
|
122
|
-
MAX_RECIPIENTS: 65535,
|
|
123
|
-
RECIPIENT_ID_SIZE: ECIES_MULTIPLE_RECIPIENT_ID_SIZE,
|
|
124
|
-
RECIPIENT_COUNT_SIZE: 2,
|
|
125
|
-
DATA_LENGTH_SIZE: 8,
|
|
126
|
-
}),
|
|
127
|
-
ENCRYPTION_TYPE: Object.freeze({
|
|
128
|
-
SIMPLE: 33,
|
|
129
|
-
SINGLE: 66,
|
|
130
|
-
MULTIPLE: 99,
|
|
131
|
-
}),
|
|
132
|
-
});
|
|
133
14
|
const objectIdLength = new ObjectId().toHexString().length / 2;
|
|
134
15
|
export const Constants = Object.freeze({
|
|
135
16
|
/**
|
|
@@ -145,52 +26,10 @@ export const Constants = Object.freeze({
|
|
|
145
26
|
UINT64_MAX: UINT64_MAX,
|
|
146
27
|
HEX_RADIX: 16,
|
|
147
28
|
GUID_SIZE: GUID_SIZE,
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
PBKDF2: PBKDF2,
|
|
151
|
-
PBKDF2_PROFILES: PBKDF2_PROFILES,
|
|
152
|
-
/**
|
|
153
|
-
* Number of rounds for bcrypt hashing. Higher values increase security but also consume more CPU resources.
|
|
154
|
-
*/
|
|
155
|
-
BcryptRounds: 10,
|
|
156
|
-
/**
|
|
157
|
-
* Minimum password length
|
|
158
|
-
*/
|
|
159
|
-
PasswordMinLength: 8,
|
|
160
|
-
/**
|
|
161
|
-
* The regular expression for valid passwords.
|
|
162
|
-
*/
|
|
163
|
-
PasswordRegex: /^(?=.*[A-Za-z])(?=.*\d)(?=.*[!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?])[A-Za-z\d!@#$%^&*()_+\-=[\]{};':"\\|,.<>/?]{8,}$/,
|
|
164
|
-
/**
|
|
165
|
-
* The regular expression for valid mnemonic phrases.
|
|
166
|
-
* BIP39 - supports 12, 15, 18, 21, or 24 word mnemonics
|
|
167
|
-
*/
|
|
168
|
-
MnemonicRegex: /^(?:\w+\s){11}\w+$|^(?:\w+\s){14}\w+$|^(?:\w+\s){17}\w+$|^(?:\w+\s){20}\w+$|^(?:\w+\s){23}\w+$/i,
|
|
169
|
-
/**
|
|
170
|
-
* Matches a 64-character hexadecimal string (SHA-256).
|
|
171
|
-
*/
|
|
172
|
-
HmacRegex: /^[a-f0-9]{64}$/,
|
|
29
|
+
PasswordRegex: PASSWORD_REGEX,
|
|
30
|
+
MnemonicRegex: MNEMONIC_REGEX,
|
|
173
31
|
});
|
|
174
|
-
if (CHECKSUM.SHA3_BUFFER_LENGTH !== CHECKSUM.SHA3_DEFAULT_HASH_BITS / 8 ||
|
|
175
|
-
CHECKSUM.SHA3_BUFFER_LENGTH !== CHECKSUM.SHA3_DEFAULT_HASH_BITS / 8) {
|
|
176
|
-
throw new Error('Invalid checksum constants');
|
|
177
|
-
}
|
|
178
32
|
if (objectIdLength !== 12) {
|
|
179
33
|
console.warn('ObjectID length may have changed, breaking encryption', objectIdLength);
|
|
180
34
|
}
|
|
181
|
-
if (ECIES.MULTIPLE.ENCRYPTED_KEY_SIZE !== 129) {
|
|
182
|
-
throw new ECIESError(ECIESErrorTypeEnum.InvalidECIESMultipleEncryptedKeySize, getCompatibleEciesEngine());
|
|
183
|
-
}
|
|
184
|
-
if (ECIES.PUBLIC_KEY_LENGTH !== ECIES.RAW_PUBLIC_KEY_LENGTH + 1) {
|
|
185
|
-
throw new ECIESError(ECIESErrorTypeEnum.InvalidECIESPublicKeyLength, getCompatibleEciesEngine());
|
|
186
|
-
}
|
|
187
|
-
if (ECIES.MULTIPLE.RECIPIENT_COUNT_SIZE !== UINT16_SIZE) {
|
|
188
|
-
throw new ECIESError(ECIESErrorTypeEnum.InvalidECIESMultipleRecipientCountSize, getCompatibleEciesEngine());
|
|
189
|
-
}
|
|
190
|
-
if (ECIES.MULTIPLE.DATA_LENGTH_SIZE !== UINT64_SIZE) {
|
|
191
|
-
throw new ECIESError(ECIESErrorTypeEnum.InvalidECIESMultipleDataLengthSize, getCompatibleEciesEngine());
|
|
192
|
-
}
|
|
193
|
-
if (ECIES.MULTIPLE.RECIPIENT_ID_SIZE !== GUID_SIZE) {
|
|
194
|
-
throw new ECIESError(ECIESErrorTypeEnum.InvalidECIESMultipleRecipientIdSize, getCompatibleEciesEngine());
|
|
195
|
-
}
|
|
196
35
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAChC,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAG3D,MAAM,CAAC,MAAM,UAAU,GAAW,CAAU,CAAC;AAC7C,MAAM,CAAC,MAAM,WAAW,GAAW,CAAU,CAAC;AAC9C,MAAM,CAAC,MAAM,UAAU,GAAW,KAAc,CAAC;AACjD,MAAM,CAAC,MAAM,WAAW,GAAW,CAAU,CAAC;AAC9C,MAAM,CAAC,MAAM,UAAU,GAAW,UAAmB,CAAC;AACtD,MAAM,CAAC,MAAM,WAAW,GAAW,CAAU,CAAC;AAC9C,MAAM,CAAC,MAAM,UAAU,GAAW,qBAA8B,CAAC;AACjE;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAW,EAAW,CAAC;AAE7C,MAAM,cAAc,GAAG,IAAI,QAAQ,EAAE,CAAC,WAAW,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;AAE/D,MAAM,CAAC,MAAM,SAAS,GAAe,MAAM,CAAC,MAAM,CAAC;IACjD;;OAEG;IACH,gBAAgB,EAAE,cAAc;IAEhC,UAAU,EAAE,UAAU;IACtB,WAAW,EAAE,WAAW;IACxB,UAAU,EAAE,UAAU;IACtB,WAAW,EAAE,WAAW;IACxB,UAAU,EAAE,UAAU;IACtB,WAAW,EAAE,WAAW;IACxB,UAAU,EAAE,UAAU;IACtB,SAAS,EAAE,EAAW;IACtB,SAAS,EAAE,SAAS;IACpB,aAAa,EAAE,cAAc;IAC7B,aAAa,EAAE,cAAc;CACrB,CAAC,CAAC;AAEZ,IAAI,cAAc,KAAK,EAAE,EAAE,CAAC;IAC1B,OAAO,CAAC,IAAI,CACV,uDAAuD,EACvD,cAAc,CACf,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { IChecksumConsts } from './interfaces';
|
|
2
|
+
import { IDefaults, IDefaultsOverrides } from './interfaces/defaults';
|
|
3
|
+
import { IECIESConstants } from './interfaces/ecies-consts';
|
|
4
|
+
import { IPBkdf2Consts } from './interfaces/pbkdf2-consts';
|
|
5
|
+
import { Pbkdf2Profiles } from './pbkdf2-profiles';
|
|
6
|
+
/**
|
|
7
|
+
* Constants for checksum operations
|
|
8
|
+
* These values are critical for data integrity and MUST NOT be changed
|
|
9
|
+
* in an already established system as it will break all existing checksums.
|
|
10
|
+
*/
|
|
11
|
+
export declare const CHECKSUM: IChecksumConsts;
|
|
12
|
+
export declare const PBKDF2: IPBkdf2Consts;
|
|
13
|
+
export declare const PBKDF2_PROFILES: Pbkdf2Profiles;
|
|
14
|
+
export declare const ECIES: IECIESConstants;
|
|
15
|
+
export declare const Defaults: IDefaults;
|
|
16
|
+
export type ConfigurationKey = string | symbol;
|
|
17
|
+
export declare function createRuntimeConfiguration(overrides?: IDefaultsOverrides, base?: IDefaults): IDefaults;
|
|
18
|
+
export declare class DefaultsRegistry {
|
|
19
|
+
static readonly DEFAULT_KEY: ConfigurationKey;
|
|
20
|
+
static listKeys(): ConfigurationKey[];
|
|
21
|
+
static has(key: ConfigurationKey): boolean;
|
|
22
|
+
static get(key?: ConfigurationKey): IDefaults;
|
|
23
|
+
static create(overrides?: IDefaultsOverrides, baseKey?: ConfigurationKey): IDefaults;
|
|
24
|
+
static register(key: ConfigurationKey, configOrOverrides?: IDefaultsOverrides | IDefaults, options?: {
|
|
25
|
+
baseKey?: ConfigurationKey;
|
|
26
|
+
}): IDefaults;
|
|
27
|
+
static unregister(key: ConfigurationKey): boolean;
|
|
28
|
+
static clear(): void;
|
|
29
|
+
}
|
|
30
|
+
export declare function getRuntimeConfiguration(key?: ConfigurationKey): IDefaults;
|
|
31
|
+
export declare function registerRuntimeConfiguration(key: ConfigurationKey, configOrOverrides?: IDefaultsOverrides | IDefaults, options?: {
|
|
32
|
+
baseKey?: ConfigurationKey;
|
|
33
|
+
}): IDefaults;
|
|
34
|
+
export declare function unregisterRuntimeConfiguration(key: ConfigurationKey): boolean;
|
|
35
|
+
export declare function clearRuntimeConfigurations(): void;
|
|
36
|
+
export { PASSWORD_REGEX, MNEMONIC_REGEX } from './regexes';
|
|
37
|
+
//# sourceMappingURL=defaults.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGnD;;;;GAIG;AACH,eAAO,MAAM,QAAQ,EAAE,eAYZ,CAAC;AAEZ,eAAO,MAAM,MAAM,EAAE,aAQV,CAAC;AAEZ,eAAO,MAAM,eAAe,EAAE,cAmBnB,CAAC;AAyBZ,eAAO,MAAM,KAAK,EAAE,eAoElB,CAAC;AAEH,eAAO,MAAM,QAAQ,EAAE,SA0BZ,CAAC;AAEZ,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,MAAM,CAAC;AAsK/C,wBAAgB,0BAA0B,CACxC,SAAS,CAAC,EAAE,kBAAkB,EAC9B,IAAI,GAAE,SAAoB,GACzB,SAAS,CAKX;AAED,qBAAa,gBAAgB;IAC3B,gBAAuB,WAAW,mBAA6B;WAEjD,QAAQ,IAAI,gBAAgB,EAAE;WAI9B,GAAG,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO;WAInC,GAAG,CAAC,GAAG,GAAE,gBAA4C,GAAG,SAAS;WAOjE,MAAM,CAClB,SAAS,CAAC,EAAE,kBAAkB,EAC9B,OAAO,GAAE,gBAA4C,GACpD,SAAS;WAKE,QAAQ,CACpB,GAAG,EAAE,gBAAgB,EACrB,iBAAiB,CAAC,EAAE,kBAAkB,GAAG,SAAS,EAClD,OAAO,CAAC,EAAE;QAAE,OAAO,CAAC,EAAE,gBAAgB,CAAA;KAAE,GACvC,SAAS;WAgBE,UAAU,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO;WAO1C,KAAK,IAAI,IAAI;CAI5B;AAED,wBAAgB,uBAAuB,CACrC,GAAG,GAAE,gBAA4C,GAChD,SAAS,CAEX;AAED,wBAAgB,4BAA4B,CAC1C,GAAG,EAAE,gBAAgB,EACrB,iBAAiB,CAAC,EAAE,kBAAkB,GAAG,SAAS,EAClD,OAAO,CAAC,EAAE;IAAE,OAAO,CAAC,EAAE,gBAAgB,CAAA;CAAE,GACvC,SAAS,CAEX;AAED,wBAAgB,8BAA8B,CAC5C,GAAG,EAAE,gBAAgB,GACpB,OAAO,CAET;AAED,wBAAgB,0BAA0B,IAAI,IAAI,CAEjD;AAED,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC"}
|