@twin.org/identity-connector-entity-storage 0.0.3-next.9 → 0.9.0

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/docs/examples.md CHANGED
@@ -1 +1,221 @@
1
- # @twin.org/identity-connector-entity-storage - Examples
1
+ # Identity Connector Entity Storage Examples
2
+
3
+ These snippets demonstrate document, profile, and resolution workflows using entity storage connectors and model entities.
4
+
5
+ ## EntityStorageIdentityConnector
6
+
7
+ ```typescript
8
+ import { EntityStorageIdentityConnector } from '@twin.org/identity-connector-entity-storage';
9
+
10
+ const connector = new EntityStorageIdentityConnector({
11
+ didDocumentEntityStorageType: 'identity-document',
12
+ vaultConnectorType: 'vault'
13
+ });
14
+
15
+ const className = connector.className();
16
+ const createdDocument = await connector.createDocument('controller-1');
17
+ const vaultKey = EntityStorageIdentityConnector.buildVaultKey(createdDocument.id, 'did');
18
+
19
+ await connector.removeDocument('controller-1', createdDocument.id);
20
+
21
+ console.log(className); // EntityStorageIdentityConnector
22
+ console.log(vaultKey); // did:entity-storage:.../did
23
+ ```
24
+
25
+ ```typescript
26
+ import { EntityStorageIdentityConnector } from '@twin.org/identity-connector-entity-storage';
27
+ import { DidVerificationMethodType, ProofTypes } from '@twin.org/standards-w3c-did';
28
+
29
+ const connector = new EntityStorageIdentityConnector({
30
+ didDocumentEntityStorageType: 'identity-document',
31
+ vaultConnectorType: 'vault'
32
+ });
33
+
34
+ const identity = 'did:entity-storage:0x1234abcd';
35
+
36
+ const verificationMethod = await connector.addVerificationMethod(
37
+ 'controller-1',
38
+ identity,
39
+ DidVerificationMethodType.VerificationMethod,
40
+ 'signing-key'
41
+ );
42
+
43
+ await connector.removeVerificationMethod('controller-1', verificationMethod.id);
44
+
45
+ const service = await connector.addService(
46
+ 'controller-1',
47
+ identity,
48
+ 'linked-domain',
49
+ 'LinkedDomains',
50
+ 'https://example.org'
51
+ );
52
+
53
+ await connector.removeService('controller-1', service.id);
54
+
55
+ const createdCredential = await connector.createVerifiableCredential(
56
+ 'controller-1',
57
+ `${identity}#signing-key`,
58
+ 'urn:uuid:credential-001',
59
+ {
60
+ id: 'did:entity-storage:0x5678efab',
61
+ role: 'Engineer'
62
+ },
63
+ {
64
+ revocationIndex: 3
65
+ }
66
+ );
67
+
68
+ const verifiedCredential = await connector.checkVerifiableCredential(createdCredential.jwt);
69
+
70
+ await connector.revokeVerifiableCredentials('controller-1', identity, [3]);
71
+ await connector.unrevokeVerifiableCredentials('controller-1', identity, [3]);
72
+
73
+ const createdPresentation = await connector.createVerifiablePresentation(
74
+ 'controller-1',
75
+ `${identity}#signing-key`,
76
+ 'urn:uuid:presentation-001',
77
+ ['https://www.w3.org/2018/credentials/v1'],
78
+ ['VerifiablePresentation'],
79
+ [createdCredential.jwt]
80
+ );
81
+
82
+ const verifiedPresentation = await connector.checkVerifiablePresentation(createdPresentation.jwt);
83
+
84
+ const proof = await connector.createProof(
85
+ 'controller-1',
86
+ `${identity}#signing-key`,
87
+ ProofTypes.DataIntegrityProof,
88
+ {
89
+ id: 'urn:example:document-1',
90
+ status: 'active'
91
+ }
92
+ );
93
+
94
+ const proofVerified = await connector.verifyProof(
95
+ {
96
+ id: 'urn:example:document-1',
97
+ status: 'active'
98
+ },
99
+ proof
100
+ );
101
+
102
+ console.log(verifiedCredential.revoked); // false
103
+ console.log(verifiedPresentation.revoked); // false
104
+ console.log(proofVerified); // true
105
+ ```
106
+
107
+ ## EntityStorageIdentityProfileConnector
108
+
109
+ ```typescript
110
+ import { EntityStorageIdentityProfileConnector } from '@twin.org/identity-connector-entity-storage';
111
+
112
+ interface PublicProfile {
113
+ displayName: string;
114
+ region: string;
115
+ }
116
+
117
+ interface PrivateProfile {
118
+ email: string;
119
+ }
120
+
121
+ const profileConnector = new EntityStorageIdentityProfileConnector<PublicProfile, PrivateProfile>({
122
+ profileEntityStorageType: 'identity-profile'
123
+ });
124
+
125
+ const className = profileConnector.className();
126
+ const identity = 'did:entity-storage:0x1234abcd';
127
+
128
+ await profileConnector.create(
129
+ identity,
130
+ {
131
+ displayName: 'Alice',
132
+ region: 'Manchester'
133
+ },
134
+ {
135
+ email: 'alice@example.org'
136
+ }
137
+ );
138
+
139
+ const profile = await profileConnector.get(identity, ['displayName'], ['email']);
140
+
141
+ await profileConnector.update(
142
+ identity,
143
+ {
144
+ displayName: 'Alice Doe',
145
+ region: 'Manchester'
146
+ },
147
+ {
148
+ email: 'alice.doe@example.org'
149
+ }
150
+ );
151
+
152
+ const profileList = await profileConnector.list(
153
+ [
154
+ {
155
+ propertyName: 'displayName',
156
+ propertyValue: 'Alice Doe'
157
+ }
158
+ ],
159
+ undefined,
160
+ ['displayName'],
161
+ ['email'],
162
+ undefined,
163
+ 10
164
+ );
165
+
166
+ await profileConnector.remove(identity);
167
+
168
+ console.log(className); // EntityStorageIdentityProfileConnector
169
+ console.log(profile.publicProfile.displayName); // Alice
170
+ console.log(profileList.items.length); // 1
171
+ ```
172
+
173
+ ## EntityStorageIdentityResolverConnector
174
+
175
+ ```typescript
176
+ import { EntityStorageIdentityResolverConnector } from '@twin.org/identity-connector-entity-storage';
177
+
178
+ const resolverConnector = new EntityStorageIdentityResolverConnector({
179
+ didDocumentEntityStorageType: 'identity-document',
180
+ vaultConnectorType: 'vault'
181
+ });
182
+
183
+ const className = resolverConnector.className();
184
+ const didDocument = await resolverConnector.resolveDocument('did:entity-storage:0x1234abcd');
185
+
186
+ console.log(className); // EntityStorageIdentityResolverConnector
187
+ console.log(didDocument.id); // did:entity-storage:0x1234abcd
188
+ ```
189
+
190
+ ## IdentityDocument
191
+
192
+ ```typescript
193
+ import { IdentityDocument } from '@twin.org/identity-connector-entity-storage';
194
+
195
+ const identityDocument = new IdentityDocument();
196
+ identityDocument.id = 'did:entity-storage:0x1234abcd';
197
+ identityDocument.document = {
198
+ id: 'did:entity-storage:0x1234abcd'
199
+ };
200
+ identityDocument.signature = 'MEYCIQCyExampleSignature';
201
+ identityDocument.controller = 'controller-1';
202
+
203
+ console.log(identityDocument.id); // did:entity-storage:0x1234abcd
204
+ ```
205
+
206
+ ## IdentityProfile
207
+
208
+ ```typescript
209
+ import { IdentityProfile } from '@twin.org/identity-connector-entity-storage';
210
+
211
+ const identityProfile = new IdentityProfile();
212
+ identityProfile.identity = 'did:entity-storage:0x1234abcd';
213
+ identityProfile.publicProfile = {
214
+ displayName: 'Alice'
215
+ };
216
+ identityProfile.privateProfile = {
217
+ email: 'alice@example.org'
218
+ };
219
+
220
+ console.log(identityProfile.identity); // did:entity-storage:0x1234abcd
221
+ ```
@@ -28,7 +28,7 @@ The options for the identity connector.
28
28
 
29
29
  ## Properties
30
30
 
31
- ### CLASS\_NAME
31
+ ### CLASS\_NAME {#class_name}
32
32
 
33
33
  > `readonly` `static` **CLASS\_NAME**: `string`
34
34
 
@@ -36,7 +36,7 @@ Runtime name for the class.
36
36
 
37
37
  ***
38
38
 
39
- ### NAMESPACE
39
+ ### NAMESPACE {#namespace}
40
40
 
41
41
  > `readonly` `static` **NAMESPACE**: `string` = `"entity-storage"`
42
42
 
@@ -44,7 +44,7 @@ The namespace supported by the identity connector.
44
44
 
45
45
  ## Methods
46
46
 
47
- ### className()
47
+ ### className() {#classname}
48
48
 
49
49
  > **className**(): `string`
50
50
 
@@ -62,7 +62,7 @@ The class name of the component.
62
62
 
63
63
  ***
64
64
 
65
- ### createDocument()
65
+ ### createDocument() {#createdocument}
66
66
 
67
67
  > **createDocument**(`controller`): `Promise`\<`IDidDocument`\>
68
68
 
@@ -88,7 +88,7 @@ The created document.
88
88
 
89
89
  ***
90
90
 
91
- ### removeDocument()
91
+ ### removeDocument() {#removedocument}
92
92
 
93
93
  > **removeDocument**(`controller`, `documentId`): `Promise`\<`void`\>
94
94
 
@@ -112,7 +112,7 @@ The id of the document to remove.
112
112
 
113
113
  `Promise`\<`void`\>
114
114
 
115
- Nothing.
115
+ A promise that resolves when the document has been removed.
116
116
 
117
117
  #### Implementation of
118
118
 
@@ -120,7 +120,7 @@ Nothing.
120
120
 
121
121
  ***
122
122
 
123
- ### addVerificationMethod()
123
+ ### addVerificationMethod() {#addverificationmethod}
124
124
 
125
125
  > **addVerificationMethod**(`controller`, `documentId`, `verificationMethodType`, `verificationMethodId?`): `Promise`\<`IDidDocumentVerificationMethod`\>
126
126
 
@@ -172,7 +172,7 @@ NotSupportedError if the platform does not support multiple keys.
172
172
 
173
173
  ***
174
174
 
175
- ### removeVerificationMethod()
175
+ ### removeVerificationMethod() {#removeverificationmethod}
176
176
 
177
177
  > **removeVerificationMethod**(`controller`, `verificationMethodId`): `Promise`\<`void`\>
178
178
 
@@ -196,7 +196,7 @@ The id of the verification method.
196
196
 
197
197
  `Promise`\<`void`\>
198
198
 
199
- Nothing.
199
+ A promise that resolves when the verification method has been removed.
200
200
 
201
201
  #### Throws
202
202
 
@@ -212,7 +212,7 @@ NotSupportedError if the platform does not support multiple revocable keys.
212
212
 
213
213
  ***
214
214
 
215
- ### addService()
215
+ ### addService() {#addservice}
216
216
 
217
217
  > **addService**(`controller`, `documentId`, `serviceId`, `serviceType`, `serviceEndpoint`): `Promise`\<`IDidService`\>
218
218
 
@@ -240,15 +240,15 @@ The id of the service.
240
240
 
241
241
  ##### serviceType
242
242
 
243
- The type of the service.
243
+ `string` \| `string`[]
244
244
 
245
- `string` | `string`[]
245
+ The type of the service.
246
246
 
247
247
  ##### serviceEndpoint
248
248
 
249
- The endpoint for the service.
249
+ `string` \| `string`[]
250
250
 
251
- `string` | `string`[]
251
+ The endpoint for the service.
252
252
 
253
253
  #### Returns
254
254
 
@@ -266,7 +266,7 @@ NotFoundError if the id can not be resolved.
266
266
 
267
267
  ***
268
268
 
269
- ### removeService()
269
+ ### removeService() {#removeservice}
270
270
 
271
271
  > **removeService**(`controller`, `serviceId`): `Promise`\<`void`\>
272
272
 
@@ -290,7 +290,7 @@ The id of the service.
290
290
 
291
291
  `Promise`\<`void`\>
292
292
 
293
- Nothing.
293
+ A promise that resolves when the service has been removed.
294
294
 
295
295
  #### Throws
296
296
 
@@ -302,7 +302,101 @@ NotFoundError if the id can not be resolved.
302
302
 
303
303
  ***
304
304
 
305
- ### createVerifiableCredential()
305
+ ### addAlsoKnownAs() {#addalsoknownas}
306
+
307
+ > **addAlsoKnownAs**(`controller`, `documentId`, `alias`): `Promise`\<`void`\>
308
+
309
+ Add an alias to the alsoKnownAs property on the document.
310
+ If the alias is already present the operation is a no-op.
311
+
312
+ #### Parameters
313
+
314
+ ##### controller
315
+
316
+ `string`
317
+
318
+ The controller of the identity who can make changes.
319
+
320
+ ##### documentId
321
+
322
+ `string`
323
+
324
+ The id of the document to update.
325
+
326
+ ##### alias
327
+
328
+ `string`
329
+
330
+ The alias to add. Must be a Url or Urn (typically another DID).
331
+
332
+ #### Returns
333
+
334
+ `Promise`\<`void`\>
335
+
336
+ A promise that resolves when the alias has been added.
337
+
338
+ #### Throws
339
+
340
+ GeneralError if the alias is not a Url or Urn.
341
+
342
+ #### Throws
343
+
344
+ NotFoundError if the id can not be resolved.
345
+
346
+ #### Implementation of
347
+
348
+ `IIdentityConnector.addAlsoKnownAs`
349
+
350
+ ***
351
+
352
+ ### removeAlsoKnownAs() {#removealsoknownas}
353
+
354
+ > **removeAlsoKnownAs**(`controller`, `documentId`, `alias`): `Promise`\<`void`\>
355
+
356
+ Remove an alias from the alsoKnownAs property on the document.
357
+ If the alias is not present the operation is a no-op.
358
+
359
+ #### Parameters
360
+
361
+ ##### controller
362
+
363
+ `string`
364
+
365
+ The controller of the identity who can make changes.
366
+
367
+ ##### documentId
368
+
369
+ `string`
370
+
371
+ The id of the document to update.
372
+
373
+ ##### alias
374
+
375
+ `string`
376
+
377
+ The alias to remove. Must be a Url or Urn.
378
+
379
+ #### Returns
380
+
381
+ `Promise`\<`void`\>
382
+
383
+ A promise that resolves when the alias has been removed.
384
+
385
+ #### Throws
386
+
387
+ GeneralError if the alias is not a Url or Urn.
388
+
389
+ #### Throws
390
+
391
+ NotFoundError if the id can not be resolved.
392
+
393
+ #### Implementation of
394
+
395
+ `IIdentityConnector.removeAlsoKnownAs`
396
+
397
+ ***
398
+
399
+ ### createVerifiableCredential() {#createverifiablecredential}
306
400
 
307
401
  > **createVerifiableCredential**(`controller`, `verificationMethodId`, `id`, `subject`, `options?`): `Promise`\<\{ `verifiableCredential`: `IDidVerifiableCredentialV1`; `jwt`: `string`; \}\>
308
402
 
@@ -324,9 +418,9 @@ The verification method id to use.
324
418
 
325
419
  ##### id
326
420
 
327
- The id of the credential.
421
+ `string` \| `undefined`
328
422
 
329
- `string` | `undefined`
423
+ The id of the credential.
330
424
 
331
425
  ##### subject
332
426
 
@@ -350,6 +444,18 @@ The bitmap revocation index of the credential, if undefined will not have revoca
350
444
 
351
445
  The date the verifiable credential is valid until.
352
446
 
447
+ ###### jwtHeaderFields?
448
+
449
+ \{\[`id`: `string`\]: `string`; \}
450
+
451
+ Additional fields to add to the JWT header.
452
+
453
+ ###### jwtPayloadFields?
454
+
455
+ \{\[`id`: `string`\]: `string`; \}
456
+
457
+ Additional fields to add to the JWT payload.
458
+
353
459
  #### Returns
354
460
 
355
461
  `Promise`\<\{ `verifiableCredential`: `IDidVerifiableCredentialV1`; `jwt`: `string`; \}\>
@@ -366,23 +472,23 @@ NotFoundError if the id can not be resolved.
366
472
 
367
473
  ***
368
474
 
369
- ### checkVerifiableCredential()
475
+ ### checkVerifiableCredential() {#checkverifiablecredential}
370
476
 
371
- > **checkVerifiableCredential**(`credentialJwt`): `Promise`\<\{ `revoked`: `boolean`; `verifiableCredential?`: `IDidVerifiableCredentialV1`; \}\>
477
+ > **checkVerifiableCredential**(`credential`): `Promise`\<\{ `revoked`: `boolean`; `verifiableCredential?`: `IDidVerifiableCredential`; \}\>
372
478
 
373
479
  Check a verifiable credential is valid.
374
480
 
375
481
  #### Parameters
376
482
 
377
- ##### credentialJwt
483
+ ##### credential
378
484
 
379
- `string`
485
+ `string` \| `IDidVerifiableCredential`
380
486
 
381
487
  The credential to verify.
382
488
 
383
489
  #### Returns
384
490
 
385
- `Promise`\<\{ `revoked`: `boolean`; `verifiableCredential?`: `IDidVerifiableCredentialV1`; \}\>
491
+ `Promise`\<\{ `revoked`: `boolean`; `verifiableCredential?`: `IDidVerifiableCredential`; \}\>
386
492
 
387
493
  The credential stored in the jwt and the revocation status.
388
494
 
@@ -392,7 +498,7 @@ The credential stored in the jwt and the revocation status.
392
498
 
393
499
  ***
394
500
 
395
- ### revokeVerifiableCredentials()
501
+ ### revokeVerifiableCredentials() {#revokeverifiablecredentials}
396
502
 
397
503
  > **revokeVerifiableCredentials**(`controller`, `issuerDocumentId`, `credentialIndices`): `Promise`\<`void`\>
398
504
 
@@ -422,7 +528,7 @@ The revocation bitmap index or indices to revoke.
422
528
 
423
529
  `Promise`\<`void`\>
424
530
 
425
- Nothing.
531
+ A promise that resolves when the credentials have been revoked.
426
532
 
427
533
  #### Implementation of
428
534
 
@@ -430,7 +536,7 @@ Nothing.
430
536
 
431
537
  ***
432
538
 
433
- ### unrevokeVerifiableCredentials()
539
+ ### unrevokeVerifiableCredentials() {#unrevokeverifiablecredentials}
434
540
 
435
541
  > **unrevokeVerifiableCredentials**(`controller`, `issuerDocumentId`, `credentialIndices`): `Promise`\<`void`\>
436
542
 
@@ -460,7 +566,7 @@ The revocation bitmap index or indices to un revoke.
460
566
 
461
567
  `Promise`\<`void`\>
462
568
 
463
- Nothing.
569
+ A promise that resolves when the credentials have been unrevoked.
464
570
 
465
571
  #### Implementation of
466
572
 
@@ -468,9 +574,9 @@ Nothing.
468
574
 
469
575
  ***
470
576
 
471
- ### createVerifiablePresentation()
577
+ ### createVerifiablePresentation() {#createverifiablepresentation}
472
578
 
473
- > **createVerifiablePresentation**(`controller`, `verificationMethodId`, `presentationId`, `contexts`, `types`, `verifiableCredentials`, `expiresInMinutes?`): `Promise`\<\{ `verifiablePresentation`: `IDidVerifiablePresentationV1`; `jwt`: `string`; \}\>
579
+ > **createVerifiablePresentation**(`controller`, `verificationMethodId`, `presentationId`, `contexts`, `types`, `verifiableCredentials`, `options?`): `Promise`\<\{ `verifiablePresentation`: `IDidVerifiablePresentationV1`; `jwt`: `string`; \}\>
474
580
 
475
581
  Create a verifiable presentation from the supplied verifiable credentials.
476
582
 
@@ -490,21 +596,21 @@ The method to associate with the presentation.
490
596
 
491
597
  ##### presentationId
492
598
 
493
- The id of the presentation.
599
+ `string` \| `undefined`
494
600
 
495
- `string` | `undefined`
601
+ The id of the presentation.
496
602
 
497
603
  ##### contexts
498
604
 
499
- The contexts for the data stored in the verifiable credential.
605
+ `IJsonLdContextDefinitionRoot` \| `undefined`
500
606
 
501
- `IJsonLdContextDefinitionRoot` | `undefined`
607
+ The contexts for the data stored in the verifiable credential.
502
608
 
503
609
  ##### types
504
610
 
505
- The types for the data stored in the verifiable credential.
611
+ `string` \| `string`[] \| `undefined`
506
612
 
507
- `string` | `string`[] | `undefined`
613
+ The types for the data stored in the verifiable credential.
508
614
 
509
615
  ##### verifiableCredentials
510
616
 
@@ -512,11 +618,27 @@ The types for the data stored in the verifiable credential.
512
618
 
513
619
  The credentials to use for creating the presentation in jwt format.
514
620
 
515
- ##### expiresInMinutes?
621
+ ##### options?
516
622
 
517
- `number`
623
+ Additional options for creating the verifiable presentation.
624
+
625
+ ###### expirationDate?
626
+
627
+ `Date`
628
+
629
+ The date the verifiable presentation is valid until.
630
+
631
+ ###### jwtHeaderFields?
632
+
633
+ \{\[`id`: `string`\]: `string`; \}
634
+
635
+ Additional fields to add to the JWT header.
636
+
637
+ ###### jwtPayloadFields?
638
+
639
+ \{\[`id`: `string`\]: `string`; \}
518
640
 
519
- The time in minutes for the presentation to expire.
641
+ Additional fields to add to the JWT payload.
520
642
 
521
643
  #### Returns
522
644
 
@@ -534,17 +656,17 @@ NotFoundError if the id can not be resolved.
534
656
 
535
657
  ***
536
658
 
537
- ### checkVerifiablePresentation()
659
+ ### checkVerifiablePresentation() {#checkverifiablepresentation}
538
660
 
539
- > **checkVerifiablePresentation**(`presentationJwt`): `Promise`\<\{ `revoked`: `boolean`; `verifiablePresentation?`: `IDidVerifiablePresentationV1`; `issuers?`: `IDidDocument`[]; \}\>
661
+ > **checkVerifiablePresentation**(`presentation`): `Promise`\<\{ `revoked`: `boolean`; `verifiablePresentation?`: `IDidVerifiablePresentationV1`; `issuers?`: `IDidDocument`[]; \}\>
540
662
 
541
663
  Check a verifiable presentation is valid.
542
664
 
543
665
  #### Parameters
544
666
 
545
- ##### presentationJwt
667
+ ##### presentation
546
668
 
547
- `string`
669
+ `string` \| `IDidVerifiablePresentation`
548
670
 
549
671
  The presentation to verify.
550
672
 
@@ -560,11 +682,13 @@ The presentation stored in the jwt and the revocation status.
560
682
 
561
683
  ***
562
684
 
563
- ### createProof()
685
+ ### createProof() {#createproof}
564
686
 
565
687
  > **createProof**(`controller`, `verificationMethodId`, `proofType`, `unsecureDocument`): `Promise`\<`IProof`\>
566
688
 
567
689
  Create a proof for arbitrary data with the specified verification method.
690
+ This method uses async signing to ensure the private key never leaves the vault,
691
+ with algorithm validation to ensure key type compatibility.
568
692
 
569
693
  #### Parameters
570
694
 
@@ -598,13 +722,21 @@ The unsecure document to create the proof for.
598
722
 
599
723
  The proof.
600
724
 
725
+ #### Throws
726
+
727
+ NotFoundError if the identity or method is not found.
728
+
729
+ #### Throws
730
+
731
+ GeneralError if algorithm doesn't match key type or proof creation fails.
732
+
601
733
  #### Implementation of
602
734
 
603
735
  `IIdentityConnector.createProof`
604
736
 
605
737
  ***
606
738
 
607
- ### verifyProof()
739
+ ### verifyProof() {#verifyproof}
608
740
 
609
741
  > **verifyProof**(`document`, `proof`): `Promise`\<`boolean`\>
610
742