@digitaldefiance/ecies-lib 4.7.11 → 4.7.12
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 +71 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -306,7 +306,7 @@ The ID provider system is a core architectural feature that enables flexible ide
|
|
|
306
306
|
|
|
307
307
|
### How Member Uses ID Providers
|
|
308
308
|
|
|
309
|
-
The `Member` class relies on `
|
|
309
|
+
The `Member` class relies on the `ECIESService`'s configured `idProvider` (accessed via `eciesService.constants.idProvider`) for three critical operations:
|
|
310
310
|
|
|
311
311
|
1. **ID Generation** - Creating unique identifiers for new members
|
|
312
312
|
2. **Serialization** - Converting binary IDs to strings for storage/transmission
|
|
@@ -315,13 +315,16 @@ The `Member` class relies on `Constants.idProvider` for three critical operation
|
|
|
315
315
|
#### Internal Implementation
|
|
316
316
|
|
|
317
317
|
```typescript
|
|
318
|
-
// 1. ID Generation (in Member
|
|
319
|
-
|
|
318
|
+
// 1. ID Generation (in Member.newMember())
|
|
319
|
+
// Uses the configured idProvider from the ECIESService
|
|
320
|
+
const idProvider = eciesService.constants.idProvider;
|
|
321
|
+
|
|
322
|
+
const newId = idProvider.generate();
|
|
320
323
|
|
|
321
324
|
// 2. Serialization (in Member.toJson())
|
|
322
325
|
public toJson(): string {
|
|
323
326
|
const storage = {
|
|
324
|
-
id:
|
|
327
|
+
id: this._eciesService.constants.idProvider.serialize(this._id), // Uint8Array → string
|
|
325
328
|
// ... other fields
|
|
326
329
|
};
|
|
327
330
|
return JSON.stringify(storage);
|
|
@@ -330,11 +333,15 @@ public toJson(): string {
|
|
|
330
333
|
// 3. Deserialization (in Member.fromJson())
|
|
331
334
|
public static fromJson(json: string, eciesService: ECIESService): Member {
|
|
332
335
|
const storage = JSON.parse(json);
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
)
|
|
336
|
+
const id = eciesService.constants.idProvider.deserialize(storage.id); // string → Uint8Array
|
|
337
|
+
|
|
338
|
+
// Validates ID length matches configured provider (warns if mismatch)
|
|
339
|
+
const expectedLength = eciesService.constants.idProvider.byteLength;
|
|
340
|
+
if (id.length !== expectedLength) {
|
|
341
|
+
console.warn(`Member ID length mismatch...`);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return new Member(eciesService, /* ... */, id);
|
|
338
345
|
}
|
|
339
346
|
```
|
|
340
347
|
|
|
@@ -490,28 +497,32 @@ console.log(restored.id); // Uint8Array(12) [80, 127, 31, 119, ...]
|
|
|
490
497
|
#### Working with Member IDs
|
|
491
498
|
|
|
492
499
|
```typescript
|
|
493
|
-
import { Member,
|
|
500
|
+
import { Member, ECIESService, createRuntimeConfiguration, GuidV4Provider } from '@digitaldefiance/ecies-lib';
|
|
494
501
|
|
|
495
|
-
|
|
502
|
+
// Create service with custom idProvider
|
|
503
|
+
const config = createRuntimeConfiguration({ idProvider: new GuidV4Provider() });
|
|
504
|
+
const ecies = new ECIESService(config);
|
|
505
|
+
|
|
506
|
+
const { member } = Member.newMember(ecies, /* ... */);
|
|
496
507
|
|
|
497
508
|
// Get binary ID
|
|
498
509
|
const binaryId: Uint8Array = member.id;
|
|
499
510
|
|
|
500
|
-
// Convert to string for display/storage
|
|
501
|
-
const stringId =
|
|
511
|
+
// Convert to string for display/storage (uses service's configured idProvider)
|
|
512
|
+
const stringId = ecies.constants.idProvider.serialize(member.id);
|
|
502
513
|
console.log(`Member ID: ${stringId}`);
|
|
503
514
|
|
|
504
515
|
// Convert string back to binary
|
|
505
|
-
const restoredId =
|
|
516
|
+
const restoredId = ecies.constants.idProvider.deserialize(stringId);
|
|
506
517
|
|
|
507
518
|
// Compare IDs (constant-time comparison)
|
|
508
|
-
const isEqual =
|
|
519
|
+
const isEqual = ecies.constants.idProvider.equals(member.id, restoredId);
|
|
509
520
|
|
|
510
521
|
// Validate ID format
|
|
511
|
-
const isValid =
|
|
522
|
+
const isValid = ecies.constants.idProvider.validate(member.id);
|
|
512
523
|
|
|
513
524
|
// Clone ID (defensive copy)
|
|
514
|
-
const idCopy =
|
|
525
|
+
const idCopy = ecies.constants.idProvider.clone(member.id);
|
|
515
526
|
```
|
|
516
527
|
|
|
517
528
|
### Multi-Recipient Encryption with Different ID Providers
|
|
@@ -589,11 +600,11 @@ console.log(config.idProvider.byteLength); // 20
|
|
|
589
600
|
|
|
590
601
|
3. **Consistent Configuration**: Use the same ID provider across your entire application to ensure compatibility
|
|
591
602
|
|
|
592
|
-
4. **Serialization for Storage**: Always use `idProvider.serialize()` when storing IDs in databases or transmitting over networks
|
|
603
|
+
4. **Serialization for Storage**: Always use `ecies.constants.idProvider.serialize()` when storing IDs in databases or transmitting over networks
|
|
593
604
|
|
|
594
605
|
5. **Validation**: Validate IDs when receiving them from external sources:
|
|
595
606
|
```typescript
|
|
596
|
-
if (!
|
|
607
|
+
if (!ecies.constants.idProvider.validate(receivedId)) {
|
|
597
608
|
throw new Error('Invalid ID format');
|
|
598
609
|
}
|
|
599
610
|
```
|
|
@@ -608,6 +619,7 @@ console.log(config.idProvider.byteLength); // 20
|
|
|
608
619
|
// config.ts
|
|
609
620
|
import { createRuntimeConfiguration, GuidV4Provider, ConstantsRegistry } from '@digitaldefiance/ecies-lib';
|
|
610
621
|
|
|
622
|
+
|
|
611
623
|
export const APP_CONFIG_KEY = 'app-config';
|
|
612
624
|
|
|
613
625
|
const config = createRuntimeConfiguration({
|
|
@@ -657,7 +669,7 @@ const deviceEcies = new ECIESService(deviceConfig);
|
|
|
657
669
|
#### Pattern 3: ID Provider Abstraction Layer
|
|
658
670
|
|
|
659
671
|
```typescript
|
|
660
|
-
import {
|
|
672
|
+
import { Member, ECIESService, MemberType, EmailString } from '@digitaldefiance/ecies-lib';
|
|
661
673
|
|
|
662
674
|
class MemberService {
|
|
663
675
|
constructor(private ecies: ECIESService) {}
|
|
@@ -672,15 +684,15 @@ class MemberService {
|
|
|
672
684
|
}
|
|
673
685
|
|
|
674
686
|
serializeMemberId(id: Uint8Array): string {
|
|
675
|
-
return
|
|
687
|
+
return this.ecies.constants.idProvider.serialize(id);
|
|
676
688
|
}
|
|
677
689
|
|
|
678
690
|
deserializeMemberId(id: string): Uint8Array {
|
|
679
|
-
return
|
|
691
|
+
return this.ecies.constants.idProvider.deserialize(id);
|
|
680
692
|
}
|
|
681
693
|
|
|
682
694
|
validateMemberId(id: Uint8Array): boolean {
|
|
683
|
-
return
|
|
695
|
+
return this.ecies.constants.idProvider.validate(id);
|
|
684
696
|
}
|
|
685
697
|
}
|
|
686
698
|
```
|
|
@@ -694,6 +706,8 @@ class MemberService {
|
|
|
694
706
|
- Accepts either `IConstants` (from `createRuntimeConfiguration`) or `Partial<IECIESConfig>` for backward compatibility
|
|
695
707
|
- When `IConstants` is provided, ECIES configuration is automatically extracted
|
|
696
708
|
- Optional `eciesParams` provides default values for any missing configuration
|
|
709
|
+
- **`constants`**: Returns the full `IConstants` configuration including `idProvider`
|
|
710
|
+
- **`config`**: Returns `IECIESConfig` for backward compatibility
|
|
697
711
|
- **`EciesCryptoCore`**: Low-level cryptographic primitives (keys, signatures, ECDH).
|
|
698
712
|
- **`EciesMultiRecipient`**: Specialized service for handling multi-recipient messages.
|
|
699
713
|
- **`EciesFileService`**: Helper for chunked file encryption.
|
|
@@ -948,6 +962,40 @@ The library maintains **100% test coverage** with over 1,200 tests, including:
|
|
|
948
962
|
|
|
949
963
|
## ChangeLog
|
|
950
964
|
|
|
965
|
+
### v4.7.12
|
|
966
|
+
|
|
967
|
+
**Bug Fix: idProvider Configuration Now Respected by Member.newMember()**
|
|
968
|
+
|
|
969
|
+
This release fixes a critical bug where `Member.newMember()` ignored the configured `idProvider` in `ECIESService` and always used the default `Constants.idProvider`.
|
|
970
|
+
|
|
971
|
+
**What Changed:**
|
|
972
|
+
- `ECIESService` now stores the full `IConstants` configuration (not just `IECIESConfig`)
|
|
973
|
+
- New `ECIESService.constants` getter provides access to the complete configuration including `idProvider`
|
|
974
|
+
- `Member.newMember()` now uses `eciesService.constants.idProvider.generate()` for ID generation
|
|
975
|
+
- `Member.toJson()` and `Member.fromJson()` now use the service's configured `idProvider` for serialization
|
|
976
|
+
- `Member.fromJson()` validates ID length and warns if it doesn't match the configured `idProvider`
|
|
977
|
+
|
|
978
|
+
**Before (Broken):**
|
|
979
|
+
```typescript
|
|
980
|
+
const config = createRuntimeConfiguration({ idProvider: new GuidV4Provider() });
|
|
981
|
+
const service = new ECIESService(config);
|
|
982
|
+
const { member } = Member.newMember(service, MemberType.User, 'Alice', email);
|
|
983
|
+
console.log(member.id.length); // 12 (wrong - used default ObjectIdProvider)
|
|
984
|
+
```
|
|
985
|
+
|
|
986
|
+
**After (Fixed):**
|
|
987
|
+
```typescript
|
|
988
|
+
const config = createRuntimeConfiguration({ idProvider: new GuidV4Provider() });
|
|
989
|
+
const service = new ECIESService(config);
|
|
990
|
+
const { member } = Member.newMember(service, MemberType.User, 'Alice', email);
|
|
991
|
+
console.log(member.id.length); // 16 (correct - uses configured GuidV4Provider)
|
|
992
|
+
```
|
|
993
|
+
|
|
994
|
+
**Backward Compatibility:**
|
|
995
|
+
- Existing code using default `idProvider` continues to work unchanged
|
|
996
|
+
- The `ECIESService.config` getter still returns `IECIESConfig` for backward compatibility
|
|
997
|
+
- `Member.fromJson()` warns but doesn't fail on ID length mismatch (for compatibility with existing serialized data)
|
|
998
|
+
|
|
951
999
|
### v4.4.2
|
|
952
1000
|
|
|
953
1001
|
- Update test-utils
|