@digitaldefiance/ecies-lib 4.10.7 → 4.10.8

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 CHANGED
@@ -8,7 +8,7 @@ Production-ready, browser-compatible ECIES (Elliptic Curve Integrated Encryption
8
8
 
9
9
  Part of [Express Suite](https://github.com/Digital-Defiance/express-suite)
10
10
 
11
- **Current Version: v4.10.6**
11
+ **Current Version: v4.10.7**
12
12
 
13
13
  This library implements a modern, enterprise-grade ECIES protocol (v4.0) featuring HKDF key derivation, AAD binding, and optimized multi-recipient encryption. It includes a pluggable ID provider system with PlatformID support, memory-efficient streaming encryption, comprehensive internationalization, and a complete cryptographic voting system with 15+ voting methods.
14
14
 
@@ -47,6 +47,7 @@ This library implements a modern, enterprise-grade ECIES protocol (v4.0) featuri
47
47
  - **PlatformID Type**: Generic type system supporting `Uint8Array | GuidV4 | ObjectId | string`
48
48
  - **Auto-Sync**: Configuration automatically adapts all cryptographic constants to the selected ID provider
49
49
  - **Member System**: User abstraction with cryptographic operations, fully integrated with the configured ID provider
50
+ - **Strong Typing**: New typed configuration system provides compile-time type safety for ID operations
50
51
  - **Key Management**:
51
52
  - **BIP39**: Mnemonic phrase generation (12-24 words).
52
53
  - **HD Wallets**: BIP32/BIP44 hierarchical deterministic derivation.
@@ -201,7 +202,8 @@ import {
201
202
  ECIESService,
202
203
  getEciesI18nEngine,
203
204
  createRuntimeConfiguration,
204
- ObjectIdProvider
205
+ ObjectIdProvider,
206
+ getEnhancedIdProvider
205
207
  } from '@digitaldefiance/ecies-lib';
206
208
 
207
209
  // 1. Initialize i18n (required once)
@@ -227,6 +229,12 @@ const encrypted = await ecies.encryptSimpleOrSingle(false, publicKey, message);
227
229
  const decrypted = await ecies.decryptSimpleOrSingleWithHeader(false, privateKey, encrypted);
228
230
 
229
231
  console.log(new TextDecoder().decode(decrypted)); // "Hello, Secure World!"
232
+
233
+ // 6. Strong Typing for ID Operations (NEW!)
234
+ const idProvider = getEnhancedIdProvider<ObjectId>();
235
+ const objectId = idProvider.generateTyped(); // Returns ObjectId - strongly typed!
236
+ const serialized = idProvider.serializeTyped(objectId); // Accepts ObjectId directly
237
+ const deserialized = idProvider.deserializeTyped(serialized); // Returns ObjectId
230
238
  ```
231
239
 
232
240
  ## Cryptographic Voting System
@@ -394,7 +402,55 @@ VotingSecurityValidator.validate(VotingMethod.Quadratic); // Throws error
394
402
  VotingSecurityValidator.validate(VotingMethod.Quadratic, { allowInsecure: true });
395
403
  ```
396
404
 
397
- ### 2. Using Custom ID Providers (e.g., GUID)
405
+ ### 2. Strong Typing for ID Providers (NEW!)
406
+
407
+ The library now provides strongly-typed alternatives to the weak typing pattern `Constants.idProvider.generate()`:
408
+
409
+ ```typescript
410
+ import {
411
+ getRuntimeConfiguration,
412
+ getEnhancedIdProvider,
413
+ getTypedIdProvider,
414
+ createObjectIdConfiguration
415
+ } from '@digitaldefiance/ecies-lib';
416
+ import { ObjectId } from 'bson';
417
+
418
+ // BEFORE: Weak typing (still works for compatibility)
419
+ const Constants = getRuntimeConfiguration();
420
+ const rawBytes = Constants.idProvider.generate(); // Returns Uint8Array, no strong typing
421
+ const nativeId = Constants.idProvider.fromBytes(rawBytes); // Returns unknown, requires casting
422
+
423
+ // AFTER: Strong typing - Option 1 (Enhanced Provider - Recommended)
424
+ const enhancedProvider = getEnhancedIdProvider<ObjectId>();
425
+
426
+ // Original methods still work exactly the same
427
+ const rawBytes2 = enhancedProvider.generate(); // Uint8Array (same as before)
428
+ const isValid = enhancedProvider.validate(rawBytes2); // boolean (same as before)
429
+
430
+ // Plus new strongly-typed methods
431
+ const objectId = enhancedProvider.generateTyped(); // ObjectId - strongly typed!
432
+ const validTyped = enhancedProvider.validateTyped(objectId); // boolean, accepts ObjectId
433
+ const serialized = enhancedProvider.serializeTyped(objectId); // string, accepts ObjectId
434
+ const deserialized = enhancedProvider.deserializeTyped(serialized); // ObjectId
435
+
436
+ // AFTER: Strong typing - Option 2 (Simple Typed Provider)
437
+ const typedProvider = getTypedIdProvider<ObjectId>();
438
+ const bytes = typedProvider.generate();
439
+ const typedId = typedProvider.fromBytes(bytes); // Returns ObjectId, not unknown!
440
+
441
+ // AFTER: Strong typing - Option 3 (Configuration Wrapper)
442
+ const config = createObjectIdConfiguration();
443
+ const configId = config.generateId(); // ObjectId directly!
444
+ const configValid = config.validateId(configId); // boolean, accepts ObjectId
445
+ ```
446
+
447
+ **Benefits:**
448
+ - ✅ **Full IntelliSense** - Autocomplete for native ID methods (`objectId.toHexString()`)
449
+ - ✅ **Compile-time checking** - Prevents type mismatches at build time
450
+ - ✅ **Zero breaking changes** - All existing code continues to work
451
+ - ✅ **Multiple migration paths** - Choose the approach that fits your use case
452
+
453
+ ### 3. Using Custom ID Providers (e.g., GUID)
398
454
 
399
455
  ```typescript
400
456
  import {
@@ -413,7 +469,7 @@ const ecies = new ECIESService(config);
413
469
  const id = config.idProvider.generate(); // Returns 16-byte Uint8Array
414
470
  ```
415
471
 
416
- ### 3. Streaming Encryption (Large Files)
472
+ ### 4. Streaming Encryption (Large Files)
417
473
 
418
474
  Encrypt gigabytes of data with minimal memory footprint (<10MB).
419
475
 
@@ -437,7 +493,7 @@ async function processFile(fileStream: ReadableStream, publicKey: Uint8Array) {
437
493
  }
438
494
  ```
439
495
 
440
- ### 4. Member System
496
+ ### 5. Member System
441
497
 
442
498
  The `Member` class provides a high-level user abstraction that integrates keys, IDs, and encryption.
443
499
 
@@ -973,6 +1029,27 @@ class MemberService {
973
1029
  - `get(key)`: Retrieve a configuration.
974
1030
  - **`createRuntimeConfiguration(overrides)`**: Creates a validated configuration object with your overrides.
975
1031
 
1032
+ ### Strong Typing System (NEW!)
1033
+
1034
+ - **`getEnhancedIdProvider<T>(key?)`**: Get a strongly-typed ID provider with enhanced convenience methods
1035
+ - Drop-in replacement for `Constants.idProvider` with both original and typed methods
1036
+ - `generateTyped()`: Generate ID with native type (e.g., `ObjectId`)
1037
+ - `validateTyped(id)`: Validate ID with native type
1038
+ - `serializeTyped(id)`: Serialize ID with native type
1039
+ - `deserializeTyped(str)`: Deserialize to native type
1040
+ - **`getTypedIdProvider<T>(key?)`**: Get a simple strongly-typed ID provider
1041
+ - Minimal API surface with type-safe conversions
1042
+ - `fromBytes(bytes)`: Returns native type instead of `unknown`
1043
+ - **`createObjectIdConfiguration(overrides?)`**: Create ObjectId-typed configuration
1044
+ - **`createGuidV4Configuration(overrides?)`**: Create GuidV4-typed configuration
1045
+ - **`createUint8ArrayConfiguration(overrides?)`**: Create Uint8Array-typed configuration
1046
+ - **`createUuidConfiguration(overrides?)`**: Create UUID string-typed configuration
1047
+ - **`TypedConfiguration<T>`**: Configuration wrapper with strongly-typed ID operations
1048
+ - `generateId()`: Generate ID with native type
1049
+ - `validateId(id)`: Validate ID with native type
1050
+ - `serializeId(id)`: Serialize ID with native type
1051
+ - `deserializeId(str)`: Deserialize to native type
1052
+
976
1053
  ### Secure Primitives
977
1054
 
978
1055
  - **`SecureString` / `SecureBuffer`**:
@@ -1181,6 +1258,59 @@ The library maintains **100% test coverage** with over 1,200 tests, including:
1181
1258
 
1182
1259
  ## ChangeLog
1183
1260
 
1261
+ ### v4.10.7 - Strong Typing for ID Providers
1262
+
1263
+ **Major Features:**
1264
+ - **Strong Typing System**: Added comprehensive strong typing solution for ID provider operations
1265
+ - `getEnhancedIdProvider<T>()`: Drop-in replacement for `Constants.idProvider` with typed methods
1266
+ - `getTypedIdProvider<T>()`: Simple typed provider for minimal API surface
1267
+ - `createObjectIdConfiguration()`: ObjectId-typed configuration factory
1268
+ - `TypedConfiguration<T>`: Configuration wrapper with strongly-typed ID operations
1269
+ - **Enhanced Developer Experience**:
1270
+ - Full IntelliSense support for native ID types (`ObjectId`, `GuidV4`, `string`, etc.)
1271
+ - Compile-time type checking prevents runtime type errors
1272
+ - Multiple migration paths to choose from based on use case
1273
+ - **Zero Breaking Changes**: All existing code continues to work unchanged
1274
+ - Original `Constants.idProvider` pattern still supported
1275
+ - Enhanced providers include all original methods plus typed alternatives
1276
+ - Backward compatibility maintained for all existing APIs
1277
+
1278
+ **New APIs:**
1279
+ - `getEnhancedIdProvider<T>(key?)`: Enhanced provider with typed convenience methods
1280
+ - `getTypedIdProvider<T>(key?)`: Simple typed provider
1281
+ - `createObjectIdConfiguration(overrides?)`: ObjectId-typed configuration
1282
+ - `createGuidV4Configuration(overrides?)`: GuidV4-typed configuration
1283
+ - `createUint8ArrayConfiguration(overrides?)`: Uint8Array-typed configuration
1284
+ - `createUuidConfiguration(overrides?)`: UUID string-typed configuration
1285
+ - `TypedIdProviderWrapper<T>`: Enhanced wrapper with typed methods
1286
+
1287
+ **Migration Examples:**
1288
+ ```typescript
1289
+ // BEFORE: Weak typing
1290
+ const Constants = getRuntimeConfiguration();
1291
+ const id = Constants.idProvider.generate(); // Uint8Array, no strong typing
1292
+
1293
+ // AFTER: Strong typing (multiple options)
1294
+ const enhancedProvider = getEnhancedIdProvider<ObjectId>();
1295
+ const objectId = enhancedProvider.generateTyped(); // ObjectId - strongly typed!
1296
+
1297
+ const typedProvider = getTypedIdProvider<ObjectId>();
1298
+ const typedId = typedProvider.fromBytes(bytes); // ObjectId, not unknown!
1299
+
1300
+ const config = createObjectIdConfiguration();
1301
+ const configId = config.generateId(); // ObjectId directly!
1302
+ ```
1303
+
1304
+ **Documentation:**
1305
+ - Added comprehensive migration guide (`src/migration-guide.md`)
1306
+ - Updated README with strong typing examples
1307
+ - Added usage examples and real-world migration patterns
1308
+
1309
+ **Testing:**
1310
+ - 14 new tests covering all strong typing scenarios
1311
+ - Property-based tests for type safety validation
1312
+ - Migration pattern tests for backward compatibility
1313
+
1184
1314
  ### v4.10.6 - Voting System & PlatformID Integration
1185
1315
 
1186
1316
  **Major Features:**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digitaldefiance/ecies-lib",
3
- "version": "4.10.7",
3
+ "version": "4.10.8",
4
4
  "description": "Digital Defiance ECIES Library",
5
5
  "homepage": "https://github.com/Digital-Defiance/ecies-lib",
6
6
  "repository": {
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Examples showing how to use the typed configuration system for strong ID provider typing.
3
+ * This demonstrates the solution to the original problem where Constants.idProvider.generate()
4
+ * had no strong typing.
5
+ */
6
+ declare function beforeExample(): void;
7
+ declare function afterExample(): void;
8
+ declare function realWorldUsage(): void;
9
+ declare function serviceIntegration(): void;
10
+ declare function typeSafetyDemo(): void;
11
+ export { beforeExample, afterExample, realWorldUsage, serviceIntegration, typeSafetyDemo, };
12
+ //# sourceMappingURL=typed-configuration-usage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typed-configuration-usage.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/examples/typed-configuration-usage.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAiBH,iBAAS,aAAa,SAKrB;AAMD,iBAAS,YAAY,SAsBpB;AAMD,iBAAS,cAAc,SAsBtB;AAMD,iBAAS,kBAAkB,SAU1B;AAMD,iBAAS,cAAc,SAgBtB;AAED,OAAO,EACL,aAAa,EACb,YAAY,EACZ,cAAc,EACd,kBAAkB,EAClB,cAAc,GACf,CAAC"}
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ /**
3
+ * Examples showing how to use the typed configuration system for strong ID provider typing.
4
+ * This demonstrates the solution to the original problem where Constants.idProvider.generate()
5
+ * had no strong typing.
6
+ */
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.beforeExample = beforeExample;
9
+ exports.afterExample = afterExample;
10
+ exports.realWorldUsage = realWorldUsage;
11
+ exports.serviceIntegration = serviceIntegration;
12
+ exports.typeSafetyDemo = typeSafetyDemo;
13
+ const constants_1 = require("../constants");
14
+ const guidv4_provider_1 = require("../lib/id-providers/guidv4-provider");
15
+ const typed_configuration_1 = require("../typed-configuration");
16
+ // ============================================================================
17
+ // BEFORE: Weak typing with getRuntimeConfiguration()
18
+ // ============================================================================
19
+ function beforeExample() {
20
+ // This was the original problem - no strong typing
21
+ const Constants = (0, constants_1.getRuntimeConfiguration)();
22
+ const id = Constants.idProvider.generate(); // Returns Uint8Array, loses type info
23
+ const _nativeId = Constants.idProvider.fromBytes(id); // Returns unknown, no type safety
24
+ }
25
+ // ============================================================================
26
+ // AFTER: Strong typing solutions
27
+ // ============================================================================
28
+ function afterExample() {
29
+ // Solution 1: Direct replacement for Constants.idProvider
30
+ const enhancedProvider = (0, typed_configuration_1.getEnhancedIdProvider)();
31
+ // Original methods still work exactly the same
32
+ const rawBytes = enhancedProvider.generate(); // Uint8Array (same as before)
33
+ const _isValid = enhancedProvider.validate(rawBytes); // boolean (same as before)
34
+ // But now you also have strongly-typed methods
35
+ const objectId = enhancedProvider.generateTyped(); // ObjectId - strongly typed!
36
+ const _validTyped = enhancedProvider.validateTyped(objectId); // boolean, accepts ObjectId
37
+ const serialized = enhancedProvider.serializeTyped(objectId); // string, accepts ObjectId
38
+ const _deserialized = enhancedProvider.deserializeTyped(serialized); // ObjectId
39
+ // Solution 2: Simple typed provider
40
+ const typedProvider = (0, typed_configuration_1.getTypedIdProvider)();
41
+ const bytes = typedProvider.generate();
42
+ const _typedId = typedProvider.fromBytes(bytes); // Returns ObjectId, not unknown!
43
+ // Solution 3: Configuration approach (for more complex scenarios)
44
+ const config = (0, typed_configuration_1.createObjectIdConfiguration)();
45
+ const _configId = config.generateId(); // Returns ObjectId - strongly typed!
46
+ }
47
+ // ============================================================================
48
+ // Real-world usage patterns
49
+ // ============================================================================
50
+ function realWorldUsage() {
51
+ // Pattern 1: Service initialization with strong typing
52
+ const config = (0, typed_configuration_1.createObjectIdConfiguration)();
53
+ // Now you can use config.idProvider with full type safety
54
+ const newId = config.generateId(); // ObjectId
55
+ const _isValid = config.validateId(newId); // boolean
56
+ const _idString = config.serializeId(newId); // string
57
+ // Pattern 2: Custom provider with type inference
58
+ const customProvider = new guidv4_provider_1.GuidV4Provider();
59
+ const typedConfig = (0, typed_configuration_1.createTypedConfiguration)({
60
+ idProvider: customProvider,
61
+ // Other overrides...
62
+ BcryptRounds: 12,
63
+ });
64
+ const _guidId = typedConfig.generateId(); // GuidV4 - automatically inferred!
65
+ // Pattern 3: Backward compatibility - access underlying constants
66
+ const _underlyingConstants = typedConfig.constants;
67
+ // This still works for existing code that expects IConstants
68
+ }
69
+ // ============================================================================
70
+ // Integration with ECIESService
71
+ // ============================================================================
72
+ function serviceIntegration() {
73
+ // The ECIESService can now use TypedConfiguration for better typing
74
+ const config = (0, typed_configuration_1.createObjectIdConfiguration)();
75
+ // Pass the underlying constants to existing services
76
+ // const service = new ECIESService<ObjectId>(config.constants);
77
+ // Or use the typed config directly for ID operations
78
+ const memberId = config.generateId(); // ObjectId
79
+ const _memberIdString = config.serializeId(memberId); // string
80
+ }
81
+ // ============================================================================
82
+ // Type safety demonstrations
83
+ // ============================================================================
84
+ function typeSafetyDemo() {
85
+ const objectIdConfig = (0, typed_configuration_1.createObjectIdConfiguration)();
86
+ const guidConfig = (0, typed_configuration_1.createGuidV4Configuration)({
87
+ idProvider: new guidv4_provider_1.GuidV4Provider(),
88
+ });
89
+ const objectId = objectIdConfig.generateId(); // ObjectId
90
+ const guid = guidConfig.generateId(); // GuidV4
91
+ // These operations are now type-safe:
92
+ objectIdConfig.serializeId(objectId); // ✅ Accepts ObjectId
93
+ guidConfig.serializeId(guid); // ✅ Accepts GuidV4
94
+ // These would be compile-time errors:
95
+ // objectIdConfig.serializeId(guid); // ❌ Type error: GuidV4 not assignable to ObjectId
96
+ // guidConfig.serializeId(objectId); // ❌ Type error: ObjectId not assignable to GuidV4
97
+ }
98
+ //# sourceMappingURL=typed-configuration-usage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typed-configuration-usage.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-ecies-lib/src/examples/typed-configuration-usage.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAuHD,sCAAa;AACb,oCAAY;AACZ,wCAAc;AACd,gDAAkB;AAClB,wCAAc;AAxHhB,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AAE/E,SAAS,cAAc;IACrB,MAAM,cAAc,GAAG,IAAA,iDAA2B,GAAE,CAAC;IACrD,MAAM,UAAU,GAAG,IAAA,+CAAyB,EAAC;QAC3C,UAAU,EAAE,IAAI,gCAAc,EAAE;KACjC,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,cAAc,CAAC,UAAU,EAAE,CAAC,CAAC,WAAW;IACzD,MAAM,IAAI,GAAG,UAAU,CAAC,UAAU,EAAE,CAAC,CAAC,SAAS;IAE/C,sCAAsC;IACtC,cAAc,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,qBAAqB;IAC3D,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC,mBAAmB;IAEjD,sCAAsC;IACtC,uFAAuF;IACvF,uFAAuF;AACzF,CAAC"}
package/src/index.d.ts CHANGED
@@ -15,6 +15,7 @@ export * from './lib/index';
15
15
  export { EciesComponentId, EciesI18nEngineKey, getEciesI18nEngine, getEciesTranslation, resetEciesI18nEngine, safeEciesTranslation, } from './i18n-setup';
16
16
  export { encryptionTypeEnumToType, encryptionTypeToString, ensureEciesEncryptionTypeEnum, validateEciesEncryptionTypeEnum, } from './utils/encryption-type-utils';
17
17
  export * from './constants';
18
+ export * from './typed-configuration';
18
19
  export * from './email-string';
19
20
  export * from './enumerations';
20
21
  export * from './errors';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-ecies-lib/src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,uBAAuB,CAAC;AAG/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAG5B,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AAItB,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,6BAA6B,EAC7B,+BAA+B,GAChC,MAAM,+BAA+B,CAAC;AASvC,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,YAAY,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AAGxB,cAAc,cAAc,CAAC;AAG7B,YAAY,EACV,UAAU,EACV,SAAS,EACT,OAAO,IAAI,eAAe,GAC3B,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-ecies-lib/src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,uBAAuB,CAAC;AAG/B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAG5B,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,cAAc,CAAC;AAItB,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACtB,6BAA6B,EAC7B,+BAA+B,GAChC,MAAM,+BAA+B,CAAC;AASvC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AACzE,YAAY,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AACtE,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC;AAC3C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AAGxB,cAAc,cAAc,CAAC;AAG7B,YAAY,EACV,UAAU,EACV,SAAS,EACT,OAAO,IAAI,eAAe,GAC3B,MAAM,iBAAiB,CAAC"}
package/src/index.js CHANGED
@@ -40,6 +40,7 @@ Object.defineProperty(exports, "validateEciesEncryptionTypeEnum", { enumerable:
40
40
  // Note: Existing services will be re-exported once migrated to v2
41
41
  // For now, import from main index.ts for backward compatibility
42
42
  tslib_1.__exportStar(require("./constants"), exports);
43
+ tslib_1.__exportStar(require("./typed-configuration"), exports);
43
44
  tslib_1.__exportStar(require("./email-string"), exports);
44
45
  tslib_1.__exportStar(require("./enumerations"), exports);
45
46
  tslib_1.__exportStar(require("./errors"), exports);
package/src/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-ecies-lib/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;AAEH,mEAAmE;AACnE,wEAAwE;AACxE,iCAA+B;AAE/B,kBAAkB;AAClB,2DAAiC;AACjC,uDAA6B;AAC7B,sDAA4B;AAE5B,UAAU;AACV,2CAOsB;AANpB,8GAAA,gBAAgB,OAAA;AAChB,gHAAA,kBAAkB,OAAA;AAClB,gHAAA,kBAAkB,OAAA;AAClB,iHAAA,mBAAmB,OAAA;AACnB,kHAAA,oBAAoB,OAAA;AACpB,kHAAA,oBAAoB,OAAA;AAGtB,mFAAmF;AACnF,mEAAmE;AACnE,uEAKuC;AAJrC,iIAAA,wBAAwB,OAAA;AACxB,+HAAA,sBAAsB,OAAA;AACtB,sIAAA,6BAA6B,OAAA;AAC7B,wIAAA,+BAA+B,OAAA;AAGjC,2DAA2D;AAC3D,oEAAoE;AACpE,8DAA8D;AAE9D,kEAAkE;AAClE,gEAAgE;AAEhE,sDAA4B;AAC5B,yDAA+B;AAC/B,yDAA+B;AAC/B,mDAAyB;AACzB,uDAA6B;AAC7B,uEAA6C;AAC7C,kEAAyE;AAAhE,4HAAA,wBAAwB,OAAA;AAEjC,qEAA2C;AAC3C,qEAA2C;AAC3C,uEAA6C;AAC7C,6DAAmC;AACnC,4DAAkC;AAClC,mDAAyB;AACzB,4DAAkC;AAClC,yDAA+B;AAC/B,0DAAgC;AAChC,0DAAgC;AAChC,qDAA2B;AAC3B,kDAAwB;AACxB,kDAAwB;AAExB,qEAAqE;AACrE,uDAA6B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-ecies-lib/src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;GASG;;;;AAEH,mEAAmE;AACnE,wEAAwE;AACxE,iCAA+B;AAE/B,kBAAkB;AAClB,2DAAiC;AACjC,uDAA6B;AAC7B,sDAA4B;AAE5B,UAAU;AACV,2CAOsB;AANpB,8GAAA,gBAAgB,OAAA;AAChB,gHAAA,kBAAkB,OAAA;AAClB,gHAAA,kBAAkB,OAAA;AAClB,iHAAA,mBAAmB,OAAA;AACnB,kHAAA,oBAAoB,OAAA;AACpB,kHAAA,oBAAoB,OAAA;AAGtB,mFAAmF;AACnF,mEAAmE;AACnE,uEAKuC;AAJrC,iIAAA,wBAAwB,OAAA;AACxB,+HAAA,sBAAsB,OAAA;AACtB,sIAAA,6BAA6B,OAAA;AAC7B,wIAAA,+BAA+B,OAAA;AAGjC,2DAA2D;AAC3D,oEAAoE;AACpE,8DAA8D;AAE9D,kEAAkE;AAClE,gEAAgE;AAEhE,sDAA4B;AAC5B,gEAAsC;AACtC,yDAA+B;AAC/B,yDAA+B;AAC/B,mDAAyB;AACzB,uDAA6B;AAC7B,uEAA6C;AAC7C,kEAAyE;AAAhE,4HAAA,wBAAwB,OAAA;AAEjC,qEAA2C;AAC3C,qEAA2C;AAC3C,uEAA6C;AAC7C,6DAAmC;AACnC,4DAAkC;AAClC,mDAAyB;AACzB,4DAAkC;AAClC,yDAA+B;AAC/B,0DAAgC;AAChC,0DAAgC;AAChC,qDAA2B;AAC3B,kDAAwB;AACxB,kDAAwB;AAExB,qEAAqE;AACrE,uDAA6B"}
@@ -0,0 +1,162 @@
1
+ import type { ObjectId } from 'bson';
2
+ import { type ConfigurationKey } from './constants';
3
+ import type { IConstants } from './interfaces/constants';
4
+ import type { IIdProvider } from './interfaces/id-provider';
5
+ import type { GuidV4 } from './lib/guid';
6
+ import type { DeepPartial } from './types/deep-partial';
7
+ /**
8
+ * Typed configuration wrapper that preserves ID provider type information.
9
+ * This provides strong typing for idProvider operations without making the entire
10
+ * constants system generic.
11
+ */
12
+ export declare class TypedConfiguration<TID> {
13
+ private readonly _constants;
14
+ private readonly _idProvider;
15
+ constructor(constants: IConstants);
16
+ /**
17
+ * Get the strongly-typed ID provider.
18
+ * This returns IIdProvider<TID> with full type safety.
19
+ */
20
+ get idProvider(): IIdProvider<TID>;
21
+ /**
22
+ * Get the underlying constants (for compatibility with existing code).
23
+ */
24
+ get constants(): IConstants;
25
+ /**
26
+ * Generate a new ID with strong typing.
27
+ */
28
+ generateId(): TID;
29
+ /**
30
+ * Validate an ID with strong typing.
31
+ */
32
+ validateId(id: TID): boolean;
33
+ /**
34
+ * Serialize an ID to string with strong typing.
35
+ */
36
+ serializeId(id: TID): string;
37
+ /**
38
+ * Deserialize a string to ID with strong typing.
39
+ */
40
+ deserializeId(str: string): TID;
41
+ }
42
+ /**
43
+ * Configuration factory functions that infer and preserve ID provider types.
44
+ */
45
+ /**
46
+ * Create a typed configuration with ObjectId provider.
47
+ * This is the default configuration with strong ObjectId typing.
48
+ */
49
+ export declare function createObjectIdConfiguration(overrides?: DeepPartial<IConstants>): TypedConfiguration<ObjectId>;
50
+ /**
51
+ * Create a typed configuration with GuidV4 provider.
52
+ */
53
+ export declare function createGuidV4Configuration(overrides?: DeepPartial<IConstants>): TypedConfiguration<GuidV4>;
54
+ /**
55
+ * Create a typed configuration with Uint8Array provider (generic bytes).
56
+ */
57
+ export declare function createUint8ArrayConfiguration(overrides?: DeepPartial<IConstants>): TypedConfiguration<Uint8Array>;
58
+ /**
59
+ * Create a typed configuration with UUID string provider.
60
+ */
61
+ export declare function createUuidConfiguration(overrides?: DeepPartial<IConstants>): TypedConfiguration<string>;
62
+ /**
63
+ * Get a strongly-typed ID provider from the default configuration.
64
+ * This is the direct equivalent of `getRuntimeConfiguration().idProvider` with strong typing.
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * // BEFORE: Weak typing
69
+ * const Constants = getRuntimeConfiguration();
70
+ * const id = Constants.idProvider.generate(); // Returns Uint8Array, no strong typing
71
+ *
72
+ * // AFTER: Strong typing
73
+ * const idProvider = getTypedIdProvider<ObjectId>();
74
+ * const id = idProvider.generateTyped(); // Returns ObjectId - strongly typed!
75
+ * ```
76
+ */
77
+ export declare function getTypedIdProvider<TID>(key?: ConfigurationKey): IIdProvider<TID>;
78
+ /**
79
+ * Enhanced ID provider wrapper that adds strongly-typed convenience methods
80
+ * while preserving all original functionality.
81
+ */
82
+ export declare class TypedIdProviderWrapper<TID> implements IIdProvider<TID> {
83
+ private readonly _provider;
84
+ constructor(provider: IIdProvider<TID>);
85
+ get byteLength(): number;
86
+ get name(): string;
87
+ generate(): Uint8Array;
88
+ validate(id: Uint8Array): boolean;
89
+ serialize(id: Uint8Array): string;
90
+ deserialize(str: string): Uint8Array;
91
+ toBytes(id: TID): Uint8Array;
92
+ fromBytes(bytes: Uint8Array): TID;
93
+ equals(a: TID, b: TID): boolean;
94
+ clone(id: TID): TID;
95
+ idToString(id: TID): string;
96
+ idFromString(str: string): TID;
97
+ /**
98
+ * Generate a new ID with strong typing.
99
+ * This is equivalent to generate() + fromBytes() but returns the native type directly.
100
+ */
101
+ generateTyped(): TID;
102
+ /**
103
+ * Validate an ID with strong typing.
104
+ * Accepts the native ID type and validates it.
105
+ */
106
+ validateTyped(id: TID): boolean;
107
+ /**
108
+ * Serialize an ID to string with strong typing.
109
+ * Accepts the native ID type directly.
110
+ */
111
+ serializeTyped(id: TID): string;
112
+ /**
113
+ * Deserialize a string to ID with strong typing.
114
+ * Returns the native ID type directly.
115
+ */
116
+ deserializeTyped(str: string): TID;
117
+ }
118
+ /**
119
+ * Get a strongly-typed ID provider with enhanced convenience methods.
120
+ * This provides the most ergonomic API for strongly-typed ID operations.
121
+ *
122
+ * @example
123
+ * ```typescript
124
+ * // Direct replacement for Constants.idProvider with strong typing
125
+ * const idProvider = getEnhancedIdProvider<ObjectId>();
126
+ *
127
+ * // All original methods work the same
128
+ * const bytes = idProvider.generate(); // Uint8Array
129
+ * const isValid = idProvider.validate(bytes); // boolean
130
+ *
131
+ * // Plus new strongly-typed methods
132
+ * const objectId = idProvider.generateTyped(); // ObjectId - strongly typed!
133
+ * const valid = idProvider.validateTyped(objectId); // boolean
134
+ * const serialized = idProvider.serializeTyped(objectId); // string
135
+ * const deserialized = idProvider.deserializeTyped(serialized); // ObjectId
136
+ * ```
137
+ */
138
+ export declare function getEnhancedIdProvider<TID>(key?: ConfigurationKey): TypedIdProviderWrapper<TID>;
139
+ /**
140
+ * Get a typed configuration from the registry.
141
+ * The type parameter must match the actual ID provider type.
142
+ *
143
+ * @example
144
+ * ```typescript
145
+ * // For ObjectId configurations
146
+ * const config = getTypedConfiguration<ObjectId>();
147
+ * const id = config.generateId(); // Returns ObjectId
148
+ *
149
+ * // For GUID configurations
150
+ * const guidConfig = getTypedConfiguration<GuidV4>('my-guid-config');
151
+ * const guid = guidConfig.generateId(); // Returns GuidV4
152
+ * ```
153
+ */
154
+ export declare function getTypedConfiguration<TID>(key?: ConfigurationKey): TypedConfiguration<TID>;
155
+ /**
156
+ * Type-safe configuration builder that infers the ID provider type.
157
+ * This provides the strongest typing by inferring TID from the idProvider.
158
+ */
159
+ export declare function createTypedConfiguration<TProvider extends IIdProvider<unknown>>(config: DeepPartial<IConstants> & {
160
+ idProvider: TProvider;
161
+ }): TypedConfiguration<TProvider extends IIdProvider<infer TID> ? TID : never>;
162
+ //# sourceMappingURL=typed-configuration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typed-configuration.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-ecies-lib/src/typed-configuration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACrC,OAAO,EAGL,KAAK,gBAAgB,EACtB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAC5D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAExD;;;;GAIG;AACH,qBAAa,kBAAkB,CAAC,GAAG;IACjC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAmB;gBAEnC,SAAS,EAAE,UAAU;IAKjC;;;OAGG;IACH,IAAI,UAAU,IAAI,WAAW,CAAC,GAAG,CAAC,CAEjC;IAED;;OAEG;IACH,IAAI,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
+ exports.TypedIdProviderWrapper = exports.TypedConfiguration = void 0;
4
+ exports.createObjectIdConfiguration = createObjectIdConfiguration;
5
+ exports.createGuidV4Configuration = createGuidV4Configuration;
6
+ exports.createUint8ArrayConfiguration = createUint8ArrayConfiguration;
7
+ exports.createUuidConfiguration = createUuidConfiguration;
8
+ exports.getTypedIdProvider = getTypedIdProvider;
9
+ exports.getEnhancedIdProvider = getEnhancedIdProvider;
10
+ exports.getTypedConfiguration = getTypedConfiguration;
11
+ exports.createTypedConfiguration = createTypedConfiguration;
12
+ const constants_1 = require("./constants");
13
+ /**
14
+ * Typed configuration wrapper that preserves ID provider type information.
15
+ * This provides strong typing for idProvider operations without making the entire
16
+ * constants system generic.
17
+ */
18
+ class TypedConfiguration {
19
+ _constants;
20
+ _idProvider;
21
+ constructor(constants) {
22
+ this._constants = constants;
23
+ this._idProvider = constants.idProvider;
24
+ }
25
+ /**
26
+ * Get the strongly-typed ID provider.
27
+ * This returns IIdProvider<TID> with full type safety.
28
+ */
29
+ get idProvider() {
30
+ return this._idProvider;
31
+ }
32
+ /**
33
+ * Get the underlying constants (for compatibility with existing code).
34
+ */
35
+ get constants() {
36
+ return this._constants;
37
+ }
38
+ /**
39
+ * Generate a new ID with strong typing.
40
+ */
41
+ generateId() {
42
+ const bytes = this._idProvider.generate();
43
+ return this._idProvider.fromBytes(bytes);
44
+ }
45
+ /**
46
+ * Validate an ID with strong typing.
47
+ */
48
+ validateId(id) {
49
+ const bytes = this._idProvider.toBytes(id);
50
+ return this._idProvider.validate(bytes);
51
+ }
52
+ /**
53
+ * Serialize an ID to string with strong typing.
54
+ */
55
+ serializeId(id) {
56
+ return this._idProvider.idToString(id);
57
+ }
58
+ /**
59
+ * Deserialize a string to ID with strong typing.
60
+ */
61
+ deserializeId(str) {
62
+ return this._idProvider.idFromString(str);
63
+ }
64
+ }
65
+ exports.TypedConfiguration = TypedConfiguration;
66
+ /**
67
+ * Configuration factory functions that infer and preserve ID provider types.
68
+ */
69
+ /**
70
+ * Create a typed configuration with ObjectId provider.
71
+ * This is the default configuration with strong ObjectId typing.
72
+ */
73
+ function createObjectIdConfiguration(overrides) {
74
+ const constants = (0, constants_1.createRuntimeConfiguration)(overrides);
75
+ return new TypedConfiguration(constants);
76
+ }
77
+ /**
78
+ * Create a typed configuration with GuidV4 provider.
79
+ */
80
+ function createGuidV4Configuration(overrides) {
81
+ const constants = (0, constants_1.createRuntimeConfiguration)(overrides);
82
+ return new TypedConfiguration(constants);
83
+ }
84
+ /**
85
+ * Create a typed configuration with Uint8Array provider (generic bytes).
86
+ */
87
+ function createUint8ArrayConfiguration(overrides) {
88
+ const constants = (0, constants_1.createRuntimeConfiguration)(overrides);
89
+ return new TypedConfiguration(constants);
90
+ }
91
+ /**
92
+ * Create a typed configuration with UUID string provider.
93
+ */
94
+ function createUuidConfiguration(overrides) {
95
+ const constants = (0, constants_1.createRuntimeConfiguration)(overrides);
96
+ return new TypedConfiguration(constants);
97
+ }
98
+ /**
99
+ * Get a strongly-typed ID provider from the default configuration.
100
+ * This is the direct equivalent of `getRuntimeConfiguration().idProvider` with strong typing.
101
+ *
102
+ * @example
103
+ * ```typescript
104
+ * // BEFORE: Weak typing
105
+ * const Constants = getRuntimeConfiguration();
106
+ * const id = Constants.idProvider.generate(); // Returns Uint8Array, no strong typing
107
+ *
108
+ * // AFTER: Strong typing
109
+ * const idProvider = getTypedIdProvider<ObjectId>();
110
+ * const id = idProvider.generateTyped(); // Returns ObjectId - strongly typed!
111
+ * ```
112
+ */
113
+ function getTypedIdProvider(key) {
114
+ const constants = (0, constants_1.getRuntimeConfiguration)(key);
115
+ return constants.idProvider;
116
+ }
117
+ /**
118
+ * Enhanced ID provider wrapper that adds strongly-typed convenience methods
119
+ * while preserving all original functionality.
120
+ */
121
+ class TypedIdProviderWrapper {
122
+ _provider;
123
+ constructor(provider) {
124
+ this._provider = provider;
125
+ }
126
+ // Delegate all original methods
127
+ get byteLength() {
128
+ return this._provider.byteLength;
129
+ }
130
+ get name() {
131
+ return this._provider.name;
132
+ }
133
+ generate() {
134
+ return this._provider.generate();
135
+ }
136
+ validate(id) {
137
+ return this._provider.validate(id);
138
+ }
139
+ serialize(id) {
140
+ return this._provider.serialize(id);
141
+ }
142
+ deserialize(str) {
143
+ return this._provider.deserialize(str);
144
+ }
145
+ toBytes(id) {
146
+ return this._provider.toBytes(id);
147
+ }
148
+ fromBytes(bytes) {
149
+ return this._provider.fromBytes(bytes);
150
+ }
151
+ equals(a, b) {
152
+ return this._provider.equals(a, b);
153
+ }
154
+ clone(id) {
155
+ return this._provider.clone(id);
156
+ }
157
+ idToString(id) {
158
+ return this._provider.idToString(id);
159
+ }
160
+ idFromString(str) {
161
+ return this._provider.idFromString(str);
162
+ }
163
+ // Add strongly-typed convenience methods
164
+ /**
165
+ * Generate a new ID with strong typing.
166
+ * This is equivalent to generate() + fromBytes() but returns the native type directly.
167
+ */
168
+ generateTyped() {
169
+ const bytes = this.generate();
170
+ return this.fromBytes(bytes);
171
+ }
172
+ /**
173
+ * Validate an ID with strong typing.
174
+ * Accepts the native ID type and validates it.
175
+ */
176
+ validateTyped(id) {
177
+ const bytes = this.toBytes(id);
178
+ return this.validate(bytes);
179
+ }
180
+ /**
181
+ * Serialize an ID to string with strong typing.
182
+ * Accepts the native ID type directly.
183
+ */
184
+ serializeTyped(id) {
185
+ return this.idToString(id);
186
+ }
187
+ /**
188
+ * Deserialize a string to ID with strong typing.
189
+ * Returns the native ID type directly.
190
+ */
191
+ deserializeTyped(str) {
192
+ return this.idFromString(str);
193
+ }
194
+ }
195
+ exports.TypedIdProviderWrapper = TypedIdProviderWrapper;
196
+ /**
197
+ * Get a strongly-typed ID provider with enhanced convenience methods.
198
+ * This provides the most ergonomic API for strongly-typed ID operations.
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * // Direct replacement for Constants.idProvider with strong typing
203
+ * const idProvider = getEnhancedIdProvider<ObjectId>();
204
+ *
205
+ * // All original methods work the same
206
+ * const bytes = idProvider.generate(); // Uint8Array
207
+ * const isValid = idProvider.validate(bytes); // boolean
208
+ *
209
+ * // Plus new strongly-typed methods
210
+ * const objectId = idProvider.generateTyped(); // ObjectId - strongly typed!
211
+ * const valid = idProvider.validateTyped(objectId); // boolean
212
+ * const serialized = idProvider.serializeTyped(objectId); // string
213
+ * const deserialized = idProvider.deserializeTyped(serialized); // ObjectId
214
+ * ```
215
+ */
216
+ function getEnhancedIdProvider(key) {
217
+ const provider = getTypedIdProvider(key);
218
+ return new TypedIdProviderWrapper(provider);
219
+ }
220
+ /**
221
+ * Get a typed configuration from the registry.
222
+ * The type parameter must match the actual ID provider type.
223
+ *
224
+ * @example
225
+ * ```typescript
226
+ * // For ObjectId configurations
227
+ * const config = getTypedConfiguration<ObjectId>();
228
+ * const id = config.generateId(); // Returns ObjectId
229
+ *
230
+ * // For GUID configurations
231
+ * const guidConfig = getTypedConfiguration<GuidV4>('my-guid-config');
232
+ * const guid = guidConfig.generateId(); // Returns GuidV4
233
+ * ```
234
+ */
235
+ function getTypedConfiguration(key) {
236
+ const constants = (0, constants_1.getRuntimeConfiguration)(key);
237
+ return new TypedConfiguration(constants);
238
+ }
239
+ /**
240
+ * Type-safe configuration builder that infers the ID provider type.
241
+ * This provides the strongest typing by inferring TID from the idProvider.
242
+ */
243
+ function createTypedConfiguration(config) {
244
+ const constants = (0, constants_1.createRuntimeConfiguration)(config);
245
+ return new TypedConfiguration(constants);
246
+ }
247
+ //# sourceMappingURL=typed-configuration.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typed-configuration.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-ecies-lib/src/typed-configuration.ts"],"names":[],"mappings":";;;AA+EA,kEAKC;AAKD,8DAKC;AAKD,sEAKC;AAKD,0DAKC;AAiBD,gDAKC;AA4GD,sDAKC;AAiBD,sDAKC;AAMD,4DASC;AA7RD,2CAIqB;AAMrB;;;;GAIG;AACH,MAAa,kBAAkB;IACZ,UAAU,CAAa;IACvB,WAAW,CAAmB;IAE/C,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