@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.
Files changed (77) hide show
  1. package/README.md +131 -4
  2. package/dist/constants.d.ts +0 -13
  3. package/dist/constants.d.ts.map +1 -1
  4. package/dist/constants.js +3 -164
  5. package/dist/constants.js.map +1 -1
  6. package/dist/defaults.d.ts +37 -0
  7. package/dist/defaults.d.ts.map +1 -0
  8. package/dist/defaults.js +323 -0
  9. package/dist/defaults.js.map +1 -0
  10. package/dist/enumerations/ecies-string-key.d.ts +1 -0
  11. package/dist/enumerations/ecies-string-key.d.ts.map +1 -1
  12. package/dist/enumerations/ecies-string-key.js +1 -0
  13. package/dist/enumerations/ecies-string-key.js.map +1 -1
  14. package/dist/enumerations/pbkdf2-error-type.d.ts +1 -0
  15. package/dist/enumerations/pbkdf2-error-type.d.ts.map +1 -1
  16. package/dist/enumerations/pbkdf2-error-type.js +1 -0
  17. package/dist/enumerations/pbkdf2-error-type.js.map +1 -1
  18. package/dist/i18n-setup.d.ts.map +1 -1
  19. package/dist/i18n-setup.js +5 -0
  20. package/dist/i18n-setup.js.map +1 -1
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +1 -0
  24. package/dist/index.js.map +1 -1
  25. package/dist/interfaces/constants.d.ts +2 -29
  26. package/dist/interfaces/constants.d.ts.map +1 -1
  27. package/dist/interfaces/defaults.d.ts +35 -0
  28. package/dist/interfaces/defaults.d.ts.map +1 -0
  29. package/dist/interfaces/defaults.js +2 -0
  30. package/dist/interfaces/defaults.js.map +1 -0
  31. package/dist/interfaces/index.d.ts +1 -1
  32. package/dist/interfaces/index.d.ts.map +1 -1
  33. package/dist/interfaces/index.js +1 -1
  34. package/dist/interfaces/index.js.map +1 -1
  35. package/dist/interfaces/member-operational.d.ts +3 -2
  36. package/dist/interfaces/member-operational.d.ts.map +1 -1
  37. package/dist/member.d.ts +7 -9
  38. package/dist/member.d.ts.map +1 -1
  39. package/dist/member.js +13 -13
  40. package/dist/member.js.map +1 -1
  41. package/dist/regexes.d.ts +3 -0
  42. package/dist/regexes.d.ts.map +1 -0
  43. package/dist/regexes.js +3 -0
  44. package/dist/regexes.js.map +1 -0
  45. package/dist/services/aes-gcm.d.ts +4 -3
  46. package/dist/services/aes-gcm.d.ts.map +1 -1
  47. package/dist/services/aes-gcm.js +13 -10
  48. package/dist/services/aes-gcm.js.map +1 -1
  49. package/dist/services/ecies/crypto-core.d.ts +4 -2
  50. package/dist/services/ecies/crypto-core.d.ts.map +1 -1
  51. package/dist/services/ecies/crypto-core.js +9 -7
  52. package/dist/services/ecies/crypto-core.js.map +1 -1
  53. package/dist/services/ecies/multi-recipient.d.ts +5 -2
  54. package/dist/services/ecies/multi-recipient.d.ts.map +1 -1
  55. package/dist/services/ecies/multi-recipient.js +36 -34
  56. package/dist/services/ecies/multi-recipient.js.map +1 -1
  57. package/dist/services/ecies/service.d.ts +9 -5
  58. package/dist/services/ecies/service.d.ts.map +1 -1
  59. package/dist/services/ecies/service.js +16 -14
  60. package/dist/services/ecies/service.js.map +1 -1
  61. package/dist/services/ecies/single-recipient.d.ts +6 -3
  62. package/dist/services/ecies/single-recipient.d.ts.map +1 -1
  63. package/dist/services/ecies/single-recipient.js +27 -25
  64. package/dist/services/ecies/single-recipient.js.map +1 -1
  65. package/dist/services/password-login.d.ts +3 -1
  66. package/dist/services/password-login.d.ts.map +1 -1
  67. package/dist/services/password-login.js +6 -3
  68. package/dist/services/password-login.js.map +1 -1
  69. package/dist/services/pbkdf2.d.ts +7 -3
  70. package/dist/services/pbkdf2.d.ts.map +1 -1
  71. package/dist/services/pbkdf2.js +16 -7
  72. package/dist/services/pbkdf2.js.map +1 -1
  73. package/dist/types/deep-partial.d.ts +4 -0
  74. package/dist/types/deep-partial.d.ts.map +1 -0
  75. package/dist/types/deep-partial.js +2 -0
  76. package/dist/types/deep-partial.js.map +1 -0
  77. 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 { PasswordLoginService, Pbkdf2Service } from '@digitaldefiance/ecies-lib';
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 pbkdf2 = await Pbkdf2Service.deriveKeyFromPasswordWithProfileAsync(
160
+ const pbkdf2Result = await pbkdf2Service.deriveKeyFromPasswordWithProfileAsync(
141
161
  passwordBytes,
142
- 'BROWSER_PASSWORD',
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)
@@ -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
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAE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CHANGED
@@ -1,8 +1,5 @@
1
1
  import { ObjectId } from 'bson';
2
- import { ECIESErrorTypeEnum } from './enumerations';
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
- CHECKSUM: CHECKSUM,
149
- ECIES: ECIES,
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
@@ -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,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AAOxD,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,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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,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