@digitaldefiance/node-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 +126 -4
- package/package.json +2 -2
- package/src/examples/typed-configuration-usage.d.ts +54 -0
- package/src/examples/typed-configuration-usage.d.ts.map +1 -0
- package/src/examples/typed-configuration-usage.js +178 -0
- package/src/examples/typed-configuration-usage.js.map +1 -0
- package/src/index.d.ts +1 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +2 -0
- package/src/index.js.map +1 -1
- package/src/member.d.ts +52 -0
- package/src/member.d.ts.map +1 -1
- package/src/member.js +72 -0
- package/src/member.js.map +1 -1
- package/src/services/ecies/multi-recipient.d.ts +1 -1
- package/src/services/ecies/multi-recipient.d.ts.map +1 -1
- package/src/services/ecies/multi-recipient.js +3 -4
- package/src/services/ecies/multi-recipient.js.map +1 -1
- package/src/services/encryption-stream.d.ts.map +1 -1
- package/src/services/encryption-stream.js +12 -4
- package/src/services/encryption-stream.js.map +1 -1
- package/src/services/multi-recipient-processor.d.ts.map +1 -1
- package/src/services/multi-recipient-processor.js +2 -3
- package/src/services/multi-recipient-processor.js.map +1 -1
- package/src/typed-configuration.d.ts +208 -0
- package/src/typed-configuration.d.ts.map +1 -0
- package/src/typed-configuration.js +230 -0
- package/src/typed-configuration.js.map +1 -0
package/README.md
CHANGED
|
@@ -163,7 +163,89 @@ const decrypted = ecies.decryptSimpleOrSingleWithHeader(false, privateKey, encry
|
|
|
163
163
|
console.log(decrypted.toString()); // "Hello, Secure World!"
|
|
164
164
|
```
|
|
165
165
|
|
|
166
|
-
### 2.
|
|
166
|
+
### 2. Strong Typing with ID Providers (New in v4.10.7)
|
|
167
|
+
|
|
168
|
+
The Node.js library now includes a comprehensive strong typing system for ID providers, eliminating the need for manual type casting and providing compile-time type safety.
|
|
169
|
+
|
|
170
|
+
#### The Problem (Before v4.10.7)
|
|
171
|
+
|
|
172
|
+
```typescript
|
|
173
|
+
const Constants = getNodeRuntimeConfiguration();
|
|
174
|
+
const id = Constants.idProvider.generate(); // Returns Uint8Array (no strong typing)
|
|
175
|
+
const obj = Constants.idProvider.fromBytes(bytes); // Returns unknown (requires casting)
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
#### The Solution (v4.10.7+)
|
|
179
|
+
|
|
180
|
+
**Enhanced Provider (Drop-in Replacement):**
|
|
181
|
+
```typescript
|
|
182
|
+
import { getEnhancedNodeIdProvider } from '@digitaldefiance/node-ecies-lib';
|
|
183
|
+
|
|
184
|
+
const provider = getEnhancedNodeIdProvider<ObjectId>();
|
|
185
|
+
const id = provider.generateTyped(); // Returns ObjectId (strongly typed)
|
|
186
|
+
const obj = provider.fromBytesTyped(bytes); // Returns ObjectId (no casting needed)
|
|
187
|
+
|
|
188
|
+
// Original methods still work for backward compatibility
|
|
189
|
+
const rawBytes = provider.generate(); // Returns Uint8Array
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
**Simple Typed Provider (Clean API):**
|
|
193
|
+
```typescript
|
|
194
|
+
import { getTypedNodeIdProvider } from '@digitaldefiance/node-ecies-lib';
|
|
195
|
+
|
|
196
|
+
const provider = getTypedNodeIdProvider<ObjectId>();
|
|
197
|
+
const id = provider.generateTyped(); // Returns ObjectId
|
|
198
|
+
const bytes = provider.toBytesTyped(id); // Type-safe conversion
|
|
199
|
+
const restored = provider.fromBytesTyped(bytes); // Type-safe restoration
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**Complete Typed Configuration:**
|
|
203
|
+
```typescript
|
|
204
|
+
import { createNodeObjectIdConfiguration } from '@digitaldefiance/node-ecies-lib';
|
|
205
|
+
|
|
206
|
+
const config = createNodeObjectIdConfiguration();
|
|
207
|
+
const objectId = config.generateId(); // Returns ObjectId (strongly typed)
|
|
208
|
+
const bytes = config.idToBytes(objectId); // Convert to bytes
|
|
209
|
+
const restored = config.idFromBytes(bytes); // Convert back to ObjectId
|
|
210
|
+
|
|
211
|
+
// Access full Node.js runtime configuration
|
|
212
|
+
const constants = config.constants; // Complete IConstants with ObjectIdProvider
|
|
213
|
+
```
|
|
214
|
+
|
|
215
|
+
**Custom Provider Types:**
|
|
216
|
+
```typescript
|
|
217
|
+
import {
|
|
218
|
+
createNodeTypedConfiguration,
|
|
219
|
+
GuidV4Provider,
|
|
220
|
+
UuidProvider
|
|
221
|
+
} from '@digitaldefiance/node-ecies-lib';
|
|
222
|
+
|
|
223
|
+
// GUID configuration
|
|
224
|
+
const guidConfig = createNodeTypedConfiguration<string>({
|
|
225
|
+
idProvider: new GuidV4Provider()
|
|
226
|
+
});
|
|
227
|
+
const guidId = guidConfig.generateId(); // Returns GUID object (strongly typed)
|
|
228
|
+
|
|
229
|
+
// UUID configuration
|
|
230
|
+
const uuidConfig = createNodeTypedConfiguration<string>({
|
|
231
|
+
idProvider: new UuidProvider()
|
|
232
|
+
});
|
|
233
|
+
const uuidId = uuidConfig.generateId(); // Returns UUID string (strongly typed)
|
|
234
|
+
```
|
|
235
|
+
|
|
236
|
+
**Integration with ECIESService:**
|
|
237
|
+
```typescript
|
|
238
|
+
import { ECIESService, createNodeObjectIdConfiguration } from '@digitaldefiance/node-ecies-lib';
|
|
239
|
+
|
|
240
|
+
const config = createNodeObjectIdConfiguration();
|
|
241
|
+
const service = new ECIESService(config.constants);
|
|
242
|
+
|
|
243
|
+
// Service uses the configured typed provider
|
|
244
|
+
console.log(service.idProvider.name); // "ObjectID"
|
|
245
|
+
console.log(service.idProvider.byteLength); // 12
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### 3. Using Custom ID Providers (e.g., GUID)
|
|
167
249
|
|
|
168
250
|
```typescript
|
|
169
251
|
import {
|
|
@@ -198,7 +280,7 @@ const ecies2 = new ECIESService({
|
|
|
198
280
|
const ecies3 = new ECIESService();
|
|
199
281
|
```
|
|
200
282
|
|
|
201
|
-
###
|
|
283
|
+
### 4. Streaming Encryption (Large Files)
|
|
202
284
|
|
|
203
285
|
Encrypt gigabytes of data with minimal memory footprint (<10MB).
|
|
204
286
|
|
|
@@ -223,7 +305,7 @@ async function processFile(filePath: string, publicKey: Buffer) {
|
|
|
223
305
|
}
|
|
224
306
|
```
|
|
225
307
|
|
|
226
|
-
###
|
|
308
|
+
### 5. Voting System (Node.js Optimized)
|
|
227
309
|
|
|
228
310
|
The Node.js voting system extends the browser implementation with Buffer support and mongoose integration:
|
|
229
311
|
|
|
@@ -311,7 +393,7 @@ console.log(member.id); // Buffer (size depends on provider)
|
|
|
311
393
|
const encrypted = member.encryptData('My Secrets');
|
|
312
394
|
```
|
|
313
395
|
|
|
314
|
-
###
|
|
396
|
+
### 6. Member System
|
|
315
397
|
|
|
316
398
|
### Core Services
|
|
317
399
|
|
|
@@ -571,6 +653,46 @@ describe('Integration with suite-core-lib', () => {
|
|
|
571
653
|
|
|
572
654
|
## ChangeLog
|
|
573
655
|
|
|
656
|
+
### v4.10.7 - Strong Typing for ID Providers
|
|
657
|
+
|
|
658
|
+
**Major Features:**
|
|
659
|
+
- **Strong Typing System**: Added comprehensive strong typing for Node.js ID provider operations
|
|
660
|
+
- `getEnhancedNodeIdProvider<T>()`: Drop-in replacement with both original and typed methods
|
|
661
|
+
- `getTypedNodeIdProvider<T>()`: Simple typed provider with minimal API surface
|
|
662
|
+
- `createNodeTypedConfiguration<T>()`: Complete typed configuration wrapper
|
|
663
|
+
- `createNodeObjectIdConfiguration()`: Pre-configured ObjectId setup
|
|
664
|
+
- **Type Safety Benefits**: Eliminates manual casting and provides compile-time type safety
|
|
665
|
+
- `generateTyped()`: Returns strongly-typed IDs (ObjectId, string, etc.)
|
|
666
|
+
- `fromBytesTyped()`: Type-safe byte conversion without casting
|
|
667
|
+
- `toBytesTyped()`, `serializeTyped()`, `deserializeTyped()`: Complete typed API
|
|
668
|
+
- **Backward Compatibility**: Enhanced providers include original methods for seamless migration
|
|
669
|
+
- **Integration Ready**: Works seamlessly with ECIESService and Member system
|
|
670
|
+
|
|
671
|
+
**Usage Examples:**
|
|
672
|
+
```typescript
|
|
673
|
+
// Enhanced provider (drop-in replacement)
|
|
674
|
+
const provider = getEnhancedNodeIdProvider<ObjectId>();
|
|
675
|
+
const id = provider.generateTyped(); // Returns ObjectId (strongly typed)
|
|
676
|
+
|
|
677
|
+
// Complete typed configuration
|
|
678
|
+
const config = createNodeObjectIdConfiguration();
|
|
679
|
+
const objectId = config.generateId(); // Returns ObjectId
|
|
680
|
+
const bytes = config.idToBytes(objectId); // Type-safe conversion
|
|
681
|
+
|
|
682
|
+
// Custom provider types
|
|
683
|
+
const guidConfig = createNodeTypedConfiguration<string>({
|
|
684
|
+
idProvider: new GuidV4Provider()
|
|
685
|
+
});
|
|
686
|
+
const guidId = guidConfig.generateId(); // Returns GUID object (strongly typed)
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
**Breaking Changes:** None - fully backward compatible
|
|
690
|
+
|
|
691
|
+
**Files Added:**
|
|
692
|
+
- `src/typed-configuration.ts` - Main implementation
|
|
693
|
+
- `src/typed-configuration.spec.ts` - Comprehensive tests
|
|
694
|
+
- `src/examples/typed-configuration-usage.ts` - Usage examples
|
|
695
|
+
|
|
574
696
|
### v4.10.6 - Voting System & PlatformID Integration
|
|
575
697
|
|
|
576
698
|
**Major Features:**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitaldefiance/node-ecies-lib",
|
|
3
|
-
"version": "4.10.
|
|
3
|
+
"version": "4.10.8",
|
|
4
4
|
"description": "Digital Defiance Node ECIES Library",
|
|
5
5
|
"homepage": "https://github.com/Digital-Defiance/node-ecies-lib",
|
|
6
6
|
"repository": {
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
"license": "MIT",
|
|
63
63
|
"packageManager": "yarn@4.10.3",
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@digitaldefiance/ecies-lib": "4.10.
|
|
65
|
+
"@digitaldefiance/ecies-lib": "4.10.8",
|
|
66
66
|
"@digitaldefiance/express-suite-test-utils": "1.0.14",
|
|
67
67
|
"@digitaldefiance/i18n-lib": "3.8.16",
|
|
68
68
|
"@ethereumjs/wallet": "^10.0.0",
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Usage examples for Node.js ECIES typed configuration system
|
|
3
|
+
*
|
|
4
|
+
* This file demonstrates how to use the strongly-typed ID provider system
|
|
5
|
+
* in Node.js applications for better type safety and developer experience.
|
|
6
|
+
*
|
|
7
|
+
* @version 4.10.7
|
|
8
|
+
* @since 4.10.7
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Example 1: Enhanced ID Provider (Drop-in Replacement)
|
|
12
|
+
*
|
|
13
|
+
* The enhanced provider includes both original and typed methods,
|
|
14
|
+
* making it a perfect drop-in replacement for existing code.
|
|
15
|
+
*/
|
|
16
|
+
declare function enhancedProviderExample(): void;
|
|
17
|
+
/**
|
|
18
|
+
* Example 2: Simple Typed Provider (Minimal API)
|
|
19
|
+
*
|
|
20
|
+
* The typed provider only exposes strongly-typed methods,
|
|
21
|
+
* providing a clean API surface for new code.
|
|
22
|
+
*/
|
|
23
|
+
declare function typedProviderExample(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Example 3: Complete Typed Configuration
|
|
26
|
+
*
|
|
27
|
+
* The typed configuration provides access to the full Node.js runtime
|
|
28
|
+
* configuration plus convenient typed ID helpers.
|
|
29
|
+
*/
|
|
30
|
+
declare function typedConfigurationExample(): void;
|
|
31
|
+
/**
|
|
32
|
+
* Example 4: Custom Provider Configuration
|
|
33
|
+
*
|
|
34
|
+
* Demonstrates how to use different ID providers with strong typing.
|
|
35
|
+
*/
|
|
36
|
+
declare function customProviderExample(): void;
|
|
37
|
+
/**
|
|
38
|
+
* Example 5: Type Safety Demonstration
|
|
39
|
+
*
|
|
40
|
+
* Shows how the typed system prevents common type-related errors.
|
|
41
|
+
*/
|
|
42
|
+
declare function typeSafetyExample(): void;
|
|
43
|
+
/**
|
|
44
|
+
* Example 6: Integration with ECIESService
|
|
45
|
+
*
|
|
46
|
+
* Shows how to use typed configurations with the ECIES service.
|
|
47
|
+
*/
|
|
48
|
+
declare function eciesIntegrationExample(): void;
|
|
49
|
+
/**
|
|
50
|
+
* Run all examples
|
|
51
|
+
*/
|
|
52
|
+
declare function runAllExamples(): void;
|
|
53
|
+
export { enhancedProviderExample, typedProviderExample, typedConfigurationExample, customProviderExample, typeSafetyExample, eciesIntegrationExample, runAllExamples, };
|
|
54
|
+
//# sourceMappingURL=typed-configuration-usage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-configuration-usage.d.ts","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/examples/typed-configuration-usage.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAYH;;;;;GAKG;AACH,iBAAS,uBAAuB,SAkB/B;AAED;;;;;GAKG;AACH,iBAAS,oBAAoB,SAqB5B;AAED;;;;;GAKG;AACH,iBAAS,yBAAyB,SAkBjC;AAED;;;;GAIG;AACH,iBAAS,qBAAqB,SAqB7B;AAED;;;;GAIG;AACH,iBAAS,iBAAiB,SAwBzB;AAED;;;;GAIG;AACH,iBAAS,uBAAuB,SAmB/B;AAED;;GAEG;AACH,iBAAS,cAAc,SAsBtB;AAGD,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,yBAAyB,EACzB,qBAAqB,EACrB,iBAAiB,EACjB,uBAAuB,EACvB,cAAc,GACf,CAAC"}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Usage examples for Node.js ECIES typed configuration system
|
|
4
|
+
*
|
|
5
|
+
* This file demonstrates how to use the strongly-typed ID provider system
|
|
6
|
+
* in Node.js applications for better type safety and developer experience.
|
|
7
|
+
*
|
|
8
|
+
* @version 4.10.7
|
|
9
|
+
* @since 4.10.7
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.enhancedProviderExample = enhancedProviderExample;
|
|
13
|
+
exports.typedProviderExample = typedProviderExample;
|
|
14
|
+
exports.typedConfigurationExample = typedConfigurationExample;
|
|
15
|
+
exports.customProviderExample = customProviderExample;
|
|
16
|
+
exports.typeSafetyExample = typeSafetyExample;
|
|
17
|
+
exports.eciesIntegrationExample = eciesIntegrationExample;
|
|
18
|
+
exports.runAllExamples = runAllExamples;
|
|
19
|
+
const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
|
|
20
|
+
const typed_configuration_1 = require("../typed-configuration");
|
|
21
|
+
/**
|
|
22
|
+
* Example 1: Enhanced ID Provider (Drop-in Replacement)
|
|
23
|
+
*
|
|
24
|
+
* The enhanced provider includes both original and typed methods,
|
|
25
|
+
* making it a perfect drop-in replacement for existing code.
|
|
26
|
+
*/
|
|
27
|
+
function enhancedProviderExample() {
|
|
28
|
+
console.log('=== Enhanced Provider Example ===');
|
|
29
|
+
// Get enhanced provider with strong typing
|
|
30
|
+
const provider = (0, typed_configuration_1.getEnhancedNodeIdProvider)();
|
|
31
|
+
// Original methods still work (backward compatibility)
|
|
32
|
+
const rawBytes = provider.generate(); // Returns Uint8Array
|
|
33
|
+
// const _unknownObj = provider.fromBytes(rawBytes); // Returns unknown (requires casting)
|
|
34
|
+
// New typed methods provide type safety
|
|
35
|
+
const typedId = provider.generateTyped(); // Returns ObjectId (strongly typed)
|
|
36
|
+
const typedFromBytes = provider.fromBytesTyped(rawBytes); // Returns ObjectId (no casting needed)
|
|
37
|
+
console.log('Provider name:', provider.name);
|
|
38
|
+
console.log('Byte length:', provider.byteLength);
|
|
39
|
+
console.log('Typed ID generated:', typedId);
|
|
40
|
+
console.log('Round-trip successful:', typedFromBytes);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Example 2: Simple Typed Provider (Minimal API)
|
|
44
|
+
*
|
|
45
|
+
* The typed provider only exposes strongly-typed methods,
|
|
46
|
+
* providing a clean API surface for new code.
|
|
47
|
+
*/
|
|
48
|
+
function typedProviderExample() {
|
|
49
|
+
console.log('=== Typed Provider Example ===');
|
|
50
|
+
// Get simple typed provider
|
|
51
|
+
const provider = (0, typed_configuration_1.getTypedNodeIdProvider)();
|
|
52
|
+
// Only typed methods available
|
|
53
|
+
const typedId = provider.generateTyped(); // Returns ObjectId
|
|
54
|
+
const bytes = provider.toBytesTyped(typedId); // Convert to bytes
|
|
55
|
+
const restored = provider.fromBytesTyped(bytes); // Convert back to ObjectId
|
|
56
|
+
// Serialization methods
|
|
57
|
+
const serialized = provider.serializeTyped(typedId);
|
|
58
|
+
const deserialized = provider.deserializeTyped(serialized);
|
|
59
|
+
console.log('Provider name:', provider.name);
|
|
60
|
+
console.log('Byte length:', provider.byteLength);
|
|
61
|
+
console.log('Original ID:', typedId);
|
|
62
|
+
console.log('Restored ID:', restored);
|
|
63
|
+
console.log('Serialized:', serialized);
|
|
64
|
+
console.log('Deserialized:', deserialized);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Example 3: Complete Typed Configuration
|
|
68
|
+
*
|
|
69
|
+
* The typed configuration provides access to the full Node.js runtime
|
|
70
|
+
* configuration plus convenient typed ID helpers.
|
|
71
|
+
*/
|
|
72
|
+
function typedConfigurationExample() {
|
|
73
|
+
console.log('=== Typed Configuration Example ===');
|
|
74
|
+
// Create ObjectId configuration
|
|
75
|
+
const config = (0, typed_configuration_1.createNodeObjectIdConfiguration)();
|
|
76
|
+
// Access full Node.js runtime configuration
|
|
77
|
+
console.log('PBKDF2 algorithm:', config.constants.PBKDF2.ALGORITHM);
|
|
78
|
+
console.log('Member ID length:', config.constants.MEMBER_ID_LENGTH);
|
|
79
|
+
// Use convenient typed methods
|
|
80
|
+
const objectId = config.generateId(); // Returns ObjectId
|
|
81
|
+
const bytes = config.idToBytes(objectId);
|
|
82
|
+
const restored = config.idFromBytes(bytes);
|
|
83
|
+
console.log('Generated ObjectId:', objectId);
|
|
84
|
+
console.log('Byte length:', bytes.length);
|
|
85
|
+
console.log('Restored ObjectId:', restored);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Example 4: Custom Provider Configuration
|
|
89
|
+
*
|
|
90
|
+
* Demonstrates how to use different ID providers with strong typing.
|
|
91
|
+
*/
|
|
92
|
+
function customProviderExample() {
|
|
93
|
+
console.log('=== Custom Provider Example ===');
|
|
94
|
+
// GUID configuration
|
|
95
|
+
const guidConfig = (0, typed_configuration_1.createNodeTypedConfiguration)({
|
|
96
|
+
idProvider: new ecies_lib_1.GuidV4Provider(),
|
|
97
|
+
});
|
|
98
|
+
// UUID configuration
|
|
99
|
+
const uuidConfig = (0, typed_configuration_1.createNodeTypedConfiguration)({
|
|
100
|
+
idProvider: new ecies_lib_1.UuidProvider(),
|
|
101
|
+
});
|
|
102
|
+
// Generate typed IDs
|
|
103
|
+
// const _guidId = guidConfig.generateId(); // Returns GUID object (strongly typed)
|
|
104
|
+
// const _uuidId = uuidConfig.generateId(); // Returns UUID string (strongly typed)
|
|
105
|
+
console.log('GUID provider name:', guidConfig.constants.idProvider.name);
|
|
106
|
+
console.log('GUID byte length:', guidConfig.constants.idProvider.byteLength);
|
|
107
|
+
console.log('UUID provider name:', uuidConfig.constants.idProvider.name);
|
|
108
|
+
console.log('UUID byte length:', uuidConfig.constants.idProvider.byteLength);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Example 5: Type Safety Demonstration
|
|
112
|
+
*
|
|
113
|
+
* Shows how the typed system prevents common type-related errors.
|
|
114
|
+
*/
|
|
115
|
+
function typeSafetyExample() {
|
|
116
|
+
console.log('=== Type Safety Example ===');
|
|
117
|
+
const objectIdConfig = (0, typed_configuration_1.createNodeObjectIdConfiguration)();
|
|
118
|
+
const guidConfig = (0, typed_configuration_1.createNodeTypedConfiguration)({
|
|
119
|
+
idProvider: new ecies_lib_1.GuidV4Provider(),
|
|
120
|
+
});
|
|
121
|
+
// Generate strongly-typed IDs
|
|
122
|
+
const objectId = objectIdConfig.generateId(); // ObjectId type
|
|
123
|
+
const guidId = guidConfig.generateId(); // GUID object type
|
|
124
|
+
// Type-safe operations (no casting needed)
|
|
125
|
+
const objectIdBytes = objectIdConfig.idToBytes(objectId);
|
|
126
|
+
const guidBytes = guidConfig.idToBytes(guidId);
|
|
127
|
+
// Restore with type safety
|
|
128
|
+
const restoredObjectId = objectIdConfig.idFromBytes(objectIdBytes);
|
|
129
|
+
const restoredGuid = guidConfig.idFromBytes(guidBytes);
|
|
130
|
+
console.log('ObjectId bytes length:', objectIdBytes.length);
|
|
131
|
+
console.log('GUID bytes length:', guidBytes.length);
|
|
132
|
+
console.log('ObjectId restored:', restoredObjectId);
|
|
133
|
+
console.log('GUID restored:', restoredGuid);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Example 6: Integration with ECIESService
|
|
137
|
+
*
|
|
138
|
+
* Shows how to use typed configurations with the ECIES service.
|
|
139
|
+
*/
|
|
140
|
+
function eciesIntegrationExample() {
|
|
141
|
+
console.log('=== ECIES Integration Example ===');
|
|
142
|
+
// Import ECIESService (commented out to avoid circular dependencies in examples)
|
|
143
|
+
// import { ECIESService } from '../services/ecies/service';
|
|
144
|
+
// Create typed configuration
|
|
145
|
+
const config = (0, typed_configuration_1.createNodeObjectIdConfiguration)();
|
|
146
|
+
// Use with ECIESService
|
|
147
|
+
// const service = new ECIESService(config.constants);
|
|
148
|
+
// The service will use the configured ID provider
|
|
149
|
+
// console.log('Service ID provider:', service.idProvider.name);
|
|
150
|
+
// console.log('Service ID byte length:', service.idProvider.byteLength);
|
|
151
|
+
console.log('Configuration ready for ECIESService');
|
|
152
|
+
console.log('ID provider:', config.constants.idProvider.name);
|
|
153
|
+
console.log('Byte length:', config.constants.idProvider.byteLength);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Run all examples
|
|
157
|
+
*/
|
|
158
|
+
function runAllExamples() {
|
|
159
|
+
console.log('Node.js ECIES Typed Configuration Examples\n');
|
|
160
|
+
enhancedProviderExample();
|
|
161
|
+
console.log();
|
|
162
|
+
typedProviderExample();
|
|
163
|
+
console.log();
|
|
164
|
+
typedConfigurationExample();
|
|
165
|
+
console.log();
|
|
166
|
+
customProviderExample();
|
|
167
|
+
console.log();
|
|
168
|
+
typeSafetyExample();
|
|
169
|
+
console.log();
|
|
170
|
+
eciesIntegrationExample();
|
|
171
|
+
console.log();
|
|
172
|
+
console.log('All examples completed successfully!');
|
|
173
|
+
}
|
|
174
|
+
// Run examples if this file is executed directly
|
|
175
|
+
if (require.main === module) {
|
|
176
|
+
runAllExamples();
|
|
177
|
+
}
|
|
178
|
+
//# sourceMappingURL=typed-configuration-usage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typed-configuration-usage.js","sourceRoot":"","sources":["../../../../../packages/digitaldefiance-node-ecies-lib/src/examples/typed-configuration-usage.ts"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;;AA+MD,0DAAuB;AACvB,oDAAoB;AACpB,8DAAyB;AACzB,sDAAqB;AACrB,8CAAiB;AACjB,0DAAuB;AACvB,wCAAc;AAnNhB,0DAA0E;AAG1E,gEAKgC;AAEhC;;;;;GAKG;AACH,SAAS,uBAAuB;IAC9B,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,CAAC;IAEjD,2CAA2C;IAC3C,MAAM,QAAQ,GAAG,IAAA,+CAAyB,GAAY,CAAC;IAEvD,uDAAuD;IACvD,MAAM,QAAQ,GAAG,QAAQ,CAAC,QAAQ,EAAE,CAAC,CAAC,qBAAqB;IAC3D,0FAA0F;IAE1F,wCAAwC;IACxC,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,EAAE,CAAC,CAAC,oCAAoC;IAC9E,MAAM,cAAc,GAAG,QAAQ,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,uCAAuC;IAEjG,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,QAAQ,CAAC,IAAI,CAAC,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from './services/voting.service';
|
|
|
19
19
|
export { IsolatedPublicKey } from './isolated-public';
|
|
20
20
|
export { IsolatedPrivateKey } from './isolated-private';
|
|
21
21
|
export type { PrivateKey, PublicKey, KeyPair as PaillierKeyPair, } from 'paillier-bigint';
|
|
22
|
+
export * from './typed-configuration';
|
|
22
23
|
//# sourceMappingURL=index.d.ts.map
|
package/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-node-ecies-lib/src/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AAGtB,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAGhC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,cAAc,2BAA2B,CAAC;AAG1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGxD,YAAY,EACV,UAAU,EACV,SAAS,EACT,OAAO,IAAI,eAAe,GAC3B,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-node-ecies-lib/src/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAC;AAC3B,cAAc,QAAQ,CAAC;AACvB,cAAc,OAAO,CAAC;AAGtB,cAAc,aAAa,CAAC;AAC5B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,iBAAiB,CAAC;AAGhC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAC5D,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAChE,OAAO,EAAE,uBAAuB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9D,cAAc,2BAA2B,CAAC;AAG1C,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAGxD,YAAY,EACV,UAAU,EACV,SAAS,EACT,OAAO,IAAI,eAAe,GAC3B,MAAM,iBAAiB,CAAC;AAGzB,cAAc,uBAAuB,CAAC"}
|
package/src/index.js
CHANGED
|
@@ -34,4 +34,6 @@ var isolated_public_1 = require("./isolated-public");
|
|
|
34
34
|
Object.defineProperty(exports, "IsolatedPublicKey", { enumerable: true, get: function () { return isolated_public_1.IsolatedPublicKey; } });
|
|
35
35
|
var isolated_private_1 = require("./isolated-private");
|
|
36
36
|
Object.defineProperty(exports, "IsolatedPrivateKey", { enumerable: true, get: function () { return isolated_private_1.IsolatedPrivateKey; } });
|
|
37
|
+
// Typed configuration system for strong typing with ID providers
|
|
38
|
+
tslib_1.__exportStar(require("./typed-configuration"), exports);
|
|
37
39
|
//# sourceMappingURL=index.js.map
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-node-ecies-lib/src/index.ts"],"names":[],"mappings":";;;;AAAA,0BAA0B;AAC1B,qDAA2B;AAC3B,iDAAuB;AACvB,gDAAsB;AAEtB,4CAA4C;AAC5C,sDAA4B;AAC5B,yDAA+B;AAC/B,iDAAuB;AACvB,uDAA6B;AAC7B,mDAAyB;AACzB,kDAAwB;AACxB,0DAAgC;AAEhC,iDAAiD;AACjD,8CAAmD;AAA1C,wGAAA,aAAa,OAAA;AACtB,8DAA4D;AAAnD,iHAAA,cAAc,OAAA;AACvB,2DAAiC;AACjC,kEAAgE;AAAvD,qHAAA,gBAAgB,OAAA;AACzB,kFAA+E;AAAtE,oIAAA,uBAAuB,OAAA;AAChC,4CAAkD;AAAzC,uGAAA,aAAa,OAAA;AACtB,gEAA8D;AAArD,mHAAA,eAAe,OAAA;AACxB,oEAA0C;AAE1C,kCAAkC;AAClC,qDAAsD;AAA7C,oHAAA,iBAAiB,OAAA;AAC1B,uDAAwD;AAA/C,sHAAA,kBAAkB,OAAA"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/digitaldefiance-node-ecies-lib/src/index.ts"],"names":[],"mappings":";;;;AAAA,0BAA0B;AAC1B,qDAA2B;AAC3B,iDAAuB;AACvB,gDAAsB;AAEtB,4CAA4C;AAC5C,sDAA4B;AAC5B,yDAA+B;AAC/B,iDAAuB;AACvB,uDAA6B;AAC7B,mDAAyB;AACzB,kDAAwB;AACxB,0DAAgC;AAEhC,iDAAiD;AACjD,8CAAmD;AAA1C,wGAAA,aAAa,OAAA;AACtB,8DAA4D;AAAnD,iHAAA,cAAc,OAAA;AACvB,2DAAiC;AACjC,kEAAgE;AAAvD,qHAAA,gBAAgB,OAAA;AACzB,kFAA+E;AAAtE,oIAAA,uBAAuB,OAAA;AAChC,4CAAkD;AAAzC,uGAAA,aAAa,OAAA;AACtB,gEAA8D;AAArD,mHAAA,eAAe,OAAA;AACxB,oEAA0C;AAE1C,kCAAkC;AAClC,qDAAsD;AAA7C,oHAAA,iBAAiB,OAAA;AAC1B,uDAAwD;AAA/C,sHAAA,kBAAkB,OAAA;AAS3B,iEAAiE;AACjE,gEAAsC"}
|
package/src/member.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { EmailString, IIdProvider, MemberErrorType, MemberType, SecureBuffer, SecureString } from '@digitaldefiance/ecies-lib';
|
|
2
2
|
import { Wallet } from '@ethereumjs/wallet';
|
|
3
|
+
import type { ObjectId } from 'mongodb';
|
|
3
4
|
import type { PrivateKey, PublicKey } from 'paillier-bigint';
|
|
4
5
|
import { PlatformID } from './interfaces';
|
|
5
6
|
import { IEncryptedChunk } from './interfaces/encrypted-chunk';
|
|
@@ -33,6 +34,24 @@ export declare class Member<TID extends PlatformID = Buffer> implements IMember<
|
|
|
33
34
|
private _wallet?;
|
|
34
35
|
private _votingPublicKey?;
|
|
35
36
|
private _votingPrivateKey?;
|
|
37
|
+
/**
|
|
38
|
+
* Creates a new Member instance.
|
|
39
|
+
*
|
|
40
|
+
* @example Using with typed configuration:
|
|
41
|
+
* ```typescript
|
|
42
|
+
* import { createNodeObjectIdConfiguration, getEnhancedNodeIdProvider } from '@digitaldefiance/node-ecies-lib';
|
|
43
|
+
*
|
|
44
|
+
* // Option 1: Use typed configuration
|
|
45
|
+
* const config = createNodeObjectIdConfiguration();
|
|
46
|
+
* const service = new ECIESService(config.constants);
|
|
47
|
+
* const { member } = Member.newMember(service, MemberType.User, 'Alice', email);
|
|
48
|
+
* // member.id is strongly typed as ObjectId
|
|
49
|
+
*
|
|
50
|
+
* // Option 2: Use enhanced provider for type-safe operations
|
|
51
|
+
* const provider = getEnhancedNodeIdProvider<ObjectId>();
|
|
52
|
+
* const typedId = provider.generateTyped(); // Returns ObjectId (strongly typed)
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
36
55
|
constructor(eciesService: ECIESService, type: MemberType, name: string, email: EmailString, publicKey: Buffer, privateKey?: SecureBuffer, wallet?: Wallet, id?: TID, dateCreated?: Date, dateUpdated?: Date, creatorId?: TID);
|
|
37
56
|
get id(): TID;
|
|
38
57
|
get idBytes(): Buffer;
|
|
@@ -101,5 +120,38 @@ export declare class Member<TID extends PlatformID = Buffer> implements IMember<
|
|
|
101
120
|
member: Member<TID>;
|
|
102
121
|
mnemonic: SecureString;
|
|
103
122
|
};
|
|
123
|
+
/**
|
|
124
|
+
* Example method demonstrating how to create a Member with strongly-typed ID providers.
|
|
125
|
+
* This shows the benefits of the new typed configuration system introduced in v4.10.7.
|
|
126
|
+
*
|
|
127
|
+
* @example
|
|
128
|
+
* ```typescript
|
|
129
|
+
* // ObjectId example with strong typing
|
|
130
|
+
* const { member } = Member.newMemberWithTypedId(
|
|
131
|
+
* MemberType.User,
|
|
132
|
+
* 'Alice',
|
|
133
|
+
* new EmailString('alice@example.com')
|
|
134
|
+
* );
|
|
135
|
+
* // member.id is strongly typed as ObjectId
|
|
136
|
+
*
|
|
137
|
+
* // GUID example with strong typing
|
|
138
|
+
* const { member: guidMember } = Member.newMemberWithTypedId<string>(
|
|
139
|
+
* MemberType.User,
|
|
140
|
+
* 'Bob',
|
|
141
|
+
* new EmailString('bob@example.com'),
|
|
142
|
+
* { idProvider: new GuidV4Provider() }
|
|
143
|
+
* );
|
|
144
|
+
* // guidMember.id is strongly typed as GUID object
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
static newMemberWithTypedId<TID extends PlatformID = ObjectId>(type: MemberType, name: string, email: EmailString, options?: {
|
|
148
|
+
idProvider?: IIdProvider<TID>;
|
|
149
|
+
forceMnemonic?: SecureString;
|
|
150
|
+
createdBy?: TID;
|
|
151
|
+
}): {
|
|
152
|
+
member: Member<TID>;
|
|
153
|
+
mnemonic: SecureString;
|
|
154
|
+
typedId: TID;
|
|
155
|
+
};
|
|
104
156
|
}
|
|
105
157
|
//# sourceMappingURL=member.d.ts.map
|
package/src/member.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"member.d.ts","sourceRoot":"","sources":["../../../../packages/digitaldefiance-node-ecies-lib/src/member.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,WAAW,EAEX,eAAe,EACf,UAAU,EACV,YAAY,EACZ,YAAY,EACb,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAO7D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,eAAe,EAAgB,MAAM,SAAS,CAAC;AAGxD;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;aAGtB,IAAI,EAAE,eAAe;gBADrC,OAAO,EAAE,MAAM,EACC,IAAI,EAAE,eAAe;CAKxC;AAED;;GAEG;AACH,qBAAa,MAAM,CAAC,GAAG,SAAS,UAAU,GAAG,MAAM,CAAE,YAAW,OAAO,CAAC,GAAG,CAAC;IAC1E,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAe;IAC7C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAM;IAC1B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAa;IACnC,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,MAAM,C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AAC,GAAG,CAAC;WAkBA,SAAS,CAAC,GAAG,SAAS,UAAU,GAAG,MAAM,EAErD,YAAY,EAAE,YAAY,EAE1B,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,WAAW,EAClB,aAAa,CAAC,EAAE,YAAY,EAC5B,SAAS,CAAC,EAAE,GAAG,GACd;QAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;QAAC,QAAQ,EAAE,YAAY,CAAA;KAAE;IAgElD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;WACW,oBAAoB,CAAC,GAAG,SAAS,UAAU,GAAG,QAAQ,EAClE,IAAI,EAAE,UAAU,EAChB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,WAAW,EAClB,OAAO,CAAC,EAAE;QACR,UAAU,CAAC,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;QAC9B,aAAa,CAAC,EAAE,YAAY,CAAC;QAC7B,SAAS,CAAC,EAAE,GAAG,CAAC;KACjB,GACA;QAAE,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;QAAC,QAAQ,EAAE,YAAY,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE;CA2CjE"}
|
package/src/member.js
CHANGED
|
@@ -6,6 +6,7 @@ const ecies_lib_1 = require("@digitaldefiance/ecies-lib");
|
|
|
6
6
|
const mongoose_types_1 = require("@digitaldefiance/mongoose-types");
|
|
7
7
|
const constants_1 = require("./constants");
|
|
8
8
|
const ecies_i18n_factory_1 = require("./i18n/ecies-i18n-factory");
|
|
9
|
+
const service_1 = require("./services/ecies/service");
|
|
9
10
|
const encryption_stream_1 = require("./services/encryption-stream");
|
|
10
11
|
const types_1 = require("./types");
|
|
11
12
|
const Constants = (0, constants_1.getNodeRuntimeConfiguration)();
|
|
@@ -41,6 +42,24 @@ class Member {
|
|
|
41
42
|
// Optional voting keys for homomorphic encryption voting systems
|
|
42
43
|
_votingPublicKey;
|
|
43
44
|
_votingPrivateKey;
|
|
45
|
+
/**
|
|
46
|
+
* Creates a new Member instance.
|
|
47
|
+
*
|
|
48
|
+
* @example Using with typed configuration:
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import { createNodeObjectIdConfiguration, getEnhancedNodeIdProvider } from '@digitaldefiance/node-ecies-lib';
|
|
51
|
+
*
|
|
52
|
+
* // Option 1: Use typed configuration
|
|
53
|
+
* const config = createNodeObjectIdConfiguration();
|
|
54
|
+
* const service = new ECIESService(config.constants);
|
|
55
|
+
* const { member } = Member.newMember(service, MemberType.User, 'Alice', email);
|
|
56
|
+
* // member.id is strongly typed as ObjectId
|
|
57
|
+
*
|
|
58
|
+
* // Option 2: Use enhanced provider for type-safe operations
|
|
59
|
+
* const provider = getEnhancedNodeIdProvider<ObjectId>();
|
|
60
|
+
* const typedId = provider.generateTyped(); // Returns ObjectId (strongly typed)
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
44
63
|
constructor(
|
|
45
64
|
// Add injected services as parameters
|
|
46
65
|
eciesService,
|
|
@@ -385,6 +404,59 @@ class Member {
|
|
|
385
404
|
mnemonic,
|
|
386
405
|
};
|
|
387
406
|
}
|
|
407
|
+
/**
|
|
408
|
+
* Example method demonstrating how to create a Member with strongly-typed ID providers.
|
|
409
|
+
* This shows the benefits of the new typed configuration system introduced in v4.10.7.
|
|
410
|
+
*
|
|
411
|
+
* @example
|
|
412
|
+
* ```typescript
|
|
413
|
+
* // ObjectId example with strong typing
|
|
414
|
+
* const { member } = Member.newMemberWithTypedId(
|
|
415
|
+
* MemberType.User,
|
|
416
|
+
* 'Alice',
|
|
417
|
+
* new EmailString('alice@example.com')
|
|
418
|
+
* );
|
|
419
|
+
* // member.id is strongly typed as ObjectId
|
|
420
|
+
*
|
|
421
|
+
* // GUID example with strong typing
|
|
422
|
+
* const { member: guidMember } = Member.newMemberWithTypedId<string>(
|
|
423
|
+
* MemberType.User,
|
|
424
|
+
* 'Bob',
|
|
425
|
+
* new EmailString('bob@example.com'),
|
|
426
|
+
* { idProvider: new GuidV4Provider() }
|
|
427
|
+
* );
|
|
428
|
+
* // guidMember.id is strongly typed as GUID object
|
|
429
|
+
* ```
|
|
430
|
+
*/
|
|
431
|
+
static newMemberWithTypedId(type, name, email, options) {
|
|
432
|
+
// Import the typed configuration functions dynamically to avoid circular dependencies
|
|
433
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-require-imports
|
|
434
|
+
const typedConfig = require('./typed-configuration');
|
|
435
|
+
// Create typed configuration
|
|
436
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
437
|
+
const config = options?.idProvider
|
|
438
|
+
? // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
439
|
+
typedConfig.createNodeTypedConfiguration({
|
|
440
|
+
idProvider: options.idProvider,
|
|
441
|
+
})
|
|
442
|
+
: // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
443
|
+
typedConfig.createNodeObjectIdConfiguration();
|
|
444
|
+
// Create service with typed configuration
|
|
445
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access
|
|
446
|
+
const service = new service_1.ECIESService(config.constants);
|
|
447
|
+
// Create member using the standard method
|
|
448
|
+
const result = Member.newMember(service, type, name, email, options?.forceMnemonic, options?.createdBy);
|
|
449
|
+
// Get enhanced provider for type-safe operations
|
|
450
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
451
|
+
const enhancedProvider = typedConfig.getEnhancedNodeIdProvider();
|
|
452
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment, @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
|
|
453
|
+
const typedId = enhancedProvider.fromBytesTyped(new Uint8Array(result.member.idBytes));
|
|
454
|
+
return {
|
|
455
|
+
member: result.member,
|
|
456
|
+
mnemonic: result.mnemonic,
|
|
457
|
+
typedId, // Strongly typed ID
|
|
458
|
+
};
|
|
459
|
+
}
|
|
388
460
|
}
|
|
389
461
|
exports.Member = Member;
|
|
390
462
|
//# sourceMappingURL=member.js.map
|