@twin.org/identity-rest-client 0.0.3-next.2 → 0.0.3-next.21

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,175 @@
1
- # @twin.org/identity-rest-client - Examples
1
+ # Identity REST Client Examples
2
+
3
+ Use these examples to call identity REST endpoints from applications that need document lifecycle, credential, and profile operations.
4
+
5
+ ## IdentityRestClient
6
+
7
+ ```typescript
8
+ import { IdentityRestClient } from '@twin.org/identity-rest-client';
9
+
10
+ const client = new IdentityRestClient({
11
+ endpoint: 'http://localhost:8080'
12
+ });
13
+
14
+ const className = client.className();
15
+ const createdDocument = await client.identityCreate('iota');
16
+
17
+ await client.identityRemove(createdDocument.id);
18
+
19
+ console.log(className); // IdentityRestClient
20
+ console.log(createdDocument.id); // did:iota:tst:0x...
21
+ ```
22
+
23
+ ```typescript
24
+ import { IdentityRestClient } from '@twin.org/identity-rest-client';
25
+ import { DidVerificationMethodType, ProofTypes } from '@twin.org/standards-w3c-did';
26
+
27
+ const client = new IdentityRestClient({
28
+ endpoint: 'http://localhost:8080'
29
+ });
30
+
31
+ const did = 'did:iota:tst:0x1234abcd';
32
+
33
+ const verificationMethod = await client.verificationMethodCreate(
34
+ did,
35
+ DidVerificationMethodType.VerificationMethod,
36
+ 'signing-key'
37
+ );
38
+
39
+ await client.verificationMethodRemove(verificationMethod.id);
40
+
41
+ const service = await client.serviceCreate(
42
+ did,
43
+ 'linked-domain',
44
+ 'LinkedDomains',
45
+ 'https://example.org'
46
+ );
47
+
48
+ await client.serviceRemove(service.id);
49
+
50
+ const credentialCreateResult = await client.verifiableCredentialCreate(
51
+ `${did}#signing-key`,
52
+ 'urn:uuid:credential-001',
53
+ {
54
+ id: 'did:iota:tst:0x5678efab',
55
+ name: 'Alice'
56
+ },
57
+ {
58
+ revocationIndex: 2
59
+ }
60
+ );
61
+
62
+ const credentialVerificationResult = await client.verifiableCredentialVerify(
63
+ credentialCreateResult.jwt
64
+ );
65
+
66
+ await client.verifiableCredentialRevoke(did, 2);
67
+ await client.verifiableCredentialUnrevoke(did, 2);
68
+
69
+ const presentationCreateResult = await client.verifiablePresentationCreate(
70
+ `${did}#signing-key`,
71
+ 'urn:uuid:presentation-001',
72
+ ['https://www.w3.org/2018/credentials/v1'],
73
+ ['VerifiablePresentation'],
74
+ [credentialCreateResult.jwt]
75
+ );
76
+
77
+ const presentationVerificationResult = await client.verifiablePresentationVerify(
78
+ presentationCreateResult.jwt
79
+ );
80
+
81
+ const proof = await client.proofCreate(`${did}#signing-key`, ProofTypes.DataIntegrityProof, {
82
+ id: 'urn:example:doc-1',
83
+ name: 'Sample'
84
+ });
85
+
86
+ const proofVerified = await client.proofVerify(
87
+ {
88
+ id: 'urn:example:doc-1',
89
+ name: 'Sample'
90
+ },
91
+ proof
92
+ );
93
+
94
+ console.log(credentialVerificationResult.revoked); // false
95
+ console.log(presentationVerificationResult.revoked); // false
96
+ console.log(proofVerified); // true
97
+ ```
98
+
99
+ ## IdentityProfileRestClient
100
+
101
+ ```typescript
102
+ import { IdentityProfileRestClient } from '@twin.org/identity-rest-client';
103
+
104
+ interface PublicProfile {
105
+ displayName: string;
106
+ website: string;
107
+ }
108
+
109
+ interface PrivateProfile {
110
+ contactEmail: string;
111
+ }
112
+
113
+ const profileClient = new IdentityProfileRestClient<PublicProfile, PrivateProfile>({
114
+ endpoint: 'http://localhost:8080'
115
+ });
116
+
117
+ const className = profileClient.className();
118
+
119
+ await profileClient.create(
120
+ {
121
+ displayName: 'Alice',
122
+ website: 'https://example.org'
123
+ },
124
+ {
125
+ contactEmail: 'alice@example.org'
126
+ }
127
+ );
128
+
129
+ const profile = await profileClient.get(['displayName'], ['contactEmail']);
130
+ const publicProfile = await profileClient.getPublic(profile.identity, ['displayName']);
131
+
132
+ await profileClient.update(
133
+ {
134
+ displayName: 'Alice Doe',
135
+ website: 'https://example.org'
136
+ },
137
+ {
138
+ contactEmail: 'alice.doe@example.org'
139
+ }
140
+ );
141
+
142
+ const profileList = await profileClient.list(
143
+ [
144
+ {
145
+ propertyName: 'displayName',
146
+ propertyValue: 'Alice Doe'
147
+ }
148
+ ],
149
+ ['displayName'],
150
+ undefined,
151
+ 10
152
+ );
153
+
154
+ await profileClient.remove();
155
+
156
+ console.log(className); // IdentityProfileRestClient
157
+ console.log(publicProfile.displayName); // Alice
158
+ console.log(profileList.items.length); // 1
159
+ ```
160
+
161
+ ## IdentityResolverRestClient
162
+
163
+ ```typescript
164
+ import { IdentityResolverRestClient } from '@twin.org/identity-rest-client';
165
+
166
+ const resolverClient = new IdentityResolverRestClient({
167
+ endpoint: 'http://localhost:8080'
168
+ });
169
+
170
+ const className = resolverClient.className();
171
+ const didDocument = await resolverClient.identityResolve('did:iota:tst:0x1234abcd');
172
+
173
+ console.log(className); // IdentityResolverRestClient
174
+ console.log(didDocument.id); // did:iota:tst:0x1234abcd
175
+ ```
@@ -46,7 +46,7 @@ The configuration for the client.
46
46
 
47
47
  ## Properties
48
48
 
49
- ### CLASS\_NAME
49
+ ### CLASS\_NAME {#class_name}
50
50
 
51
51
  > `readonly` `static` **CLASS\_NAME**: `string`
52
52
 
@@ -54,7 +54,7 @@ Runtime name for the class.
54
54
 
55
55
  ## Methods
56
56
 
57
- ### className()
57
+ ### className() {#classname}
58
58
 
59
59
  > **className**(): `string`
60
60
 
@@ -72,7 +72,7 @@ The class name of the component.
72
72
 
73
73
  ***
74
74
 
75
- ### create()
75
+ ### create() {#create}
76
76
 
77
77
  > **create**(`publicProfile?`, `privateProfile?`): `Promise`\<`void`\>
78
78
 
@@ -104,7 +104,7 @@ Nothing.
104
104
 
105
105
  ***
106
106
 
107
- ### get()
107
+ ### get() {#get}
108
108
 
109
109
  > **get**(`publicPropertyNames?`, `privatePropertyNames?`): `Promise`\<\{ `identity`: `string`; `publicProfile?`: `Partial`\<`T`\>; `privateProfile?`: `Partial`\<`U`\>; \}\>
110
110
 
@@ -136,7 +136,7 @@ The identity and the items properties.
136
136
 
137
137
  ***
138
138
 
139
- ### getPublic()
139
+ ### getPublic() {#getpublic}
140
140
 
141
141
  > **getPublic**(`identity`, `propertyNames?`): `Promise`\<`Partial`\<`T`\>\>
142
142
 
@@ -168,7 +168,7 @@ The items properties.
168
168
 
169
169
  ***
170
170
 
171
- ### update()
171
+ ### update() {#update}
172
172
 
173
173
  > **update**(`publicProfile?`, `privateProfile?`): `Promise`\<`void`\>
174
174
 
@@ -200,7 +200,7 @@ Nothing.
200
200
 
201
201
  ***
202
202
 
203
- ### remove()
203
+ ### remove() {#remove}
204
204
 
205
205
  > **remove**(): `Promise`\<`void`\>
206
206
 
@@ -218,7 +218,7 @@ Nothing.
218
218
 
219
219
  ***
220
220
 
221
- ### list()
221
+ ### list() {#list}
222
222
 
223
223
  > **list**(`publicFilters?`, `publicPropertyNames?`, `cursor?`, `limit?`): `Promise`\<\{ `items`: `object`[]; `cursor?`: `string`; \}\>
224
224
 
@@ -36,7 +36,7 @@ The configuration for the client.
36
36
 
37
37
  ## Properties
38
38
 
39
- ### CLASS\_NAME
39
+ ### CLASS\_NAME {#class_name}
40
40
 
41
41
  > `readonly` `static` **CLASS\_NAME**: `string`
42
42
 
@@ -44,7 +44,7 @@ Runtime name for the class.
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
- ### identityResolve()
65
+ ### identityResolve() {#identityresolve}
66
66
 
67
67
  > **identityResolve**(`documentId`): `Promise`\<`IDidDocument`\>
68
68
 
@@ -36,7 +36,7 @@ The configuration for the client.
36
36
 
37
37
  ## Properties
38
38
 
39
- ### CLASS\_NAME
39
+ ### CLASS\_NAME {#class_name}
40
40
 
41
41
  > `readonly` `static` **CLASS\_NAME**: `string`
42
42
 
@@ -44,7 +44,7 @@ Runtime name for the class.
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
- ### identityCreate()
65
+ ### identityCreate() {#identitycreate}
66
66
 
67
67
  > **identityCreate**(`namespace?`): `Promise`\<`IDidDocument`\>
68
68
 
@@ -88,7 +88,7 @@ The created identity document.
88
88
 
89
89
  ***
90
90
 
91
- ### identityRemove()
91
+ ### identityRemove() {#identityremove}
92
92
 
93
93
  > **identityRemove**(`identity`): `Promise`\<`void`\>
94
94
 
@@ -114,7 +114,7 @@ Nothing.
114
114
 
115
115
  ***
116
116
 
117
- ### verificationMethodCreate()
117
+ ### verificationMethodCreate() {#verificationmethodcreate}
118
118
 
119
119
  > **verificationMethodCreate**(`identity`, `verificationMethodType`, `verificationMethodId?`): `Promise`\<`IDidDocumentVerificationMethod`\>
120
120
 
@@ -160,7 +160,7 @@ NotSupportedError if the platform does not support multiple keys.
160
160
 
161
161
  ***
162
162
 
163
- ### verificationMethodRemove()
163
+ ### verificationMethodRemove() {#verificationmethodremove}
164
164
 
165
165
  > **verificationMethodRemove**(`verificationMethodId`): `Promise`\<`void`\>
166
166
 
@@ -194,7 +194,7 @@ NotSupportedError if the platform does not support multiple revocable keys.
194
194
 
195
195
  ***
196
196
 
197
- ### serviceCreate()
197
+ ### serviceCreate() {#servicecreate}
198
198
 
199
199
  > **serviceCreate**(`identity`, `serviceId`, `serviceType`, `serviceEndpoint`): `Promise`\<`IDidService`\>
200
200
 
@@ -216,15 +216,15 @@ The id of the service.
216
216
 
217
217
  ##### serviceType
218
218
 
219
- The type of the service.
219
+ `string` \| `string`[]
220
220
 
221
- `string` | `string`[]
221
+ The type of the service.
222
222
 
223
223
  ##### serviceEndpoint
224
224
 
225
- The endpoint for the service.
225
+ `string` \| `string`[]
226
226
 
227
- `string` | `string`[]
227
+ The endpoint for the service.
228
228
 
229
229
  #### Returns
230
230
 
@@ -242,7 +242,7 @@ NotFoundError if the id can not be resolved.
242
242
 
243
243
  ***
244
244
 
245
- ### serviceRemove()
245
+ ### serviceRemove() {#serviceremove}
246
246
 
247
247
  > **serviceRemove**(`serviceId`): `Promise`\<`void`\>
248
248
 
@@ -272,7 +272,89 @@ NotFoundError if the id can not be resolved.
272
272
 
273
273
  ***
274
274
 
275
- ### verifiableCredentialCreate()
275
+ ### alsoKnownAsAdd() {#alsoknownasadd}
276
+
277
+ > **alsoKnownAsAdd**(`documentId`, `alias`): `Promise`\<`void`\>
278
+
279
+ Add an alias to the alsoKnownAs property on the document.
280
+ If the alias is already present the operation is a no-op.
281
+
282
+ #### Parameters
283
+
284
+ ##### documentId
285
+
286
+ `string`
287
+
288
+ The id of the document to update.
289
+
290
+ ##### alias
291
+
292
+ `string`
293
+
294
+ The alias to add. Must be a Url or Urn (typically another DID).
295
+
296
+ #### Returns
297
+
298
+ `Promise`\<`void`\>
299
+
300
+ Nothing.
301
+
302
+ #### Throws
303
+
304
+ GeneralError if the alias is not a Url or Urn.
305
+
306
+ #### Throws
307
+
308
+ NotFoundError if the id can not be resolved.
309
+
310
+ #### Implementation of
311
+
312
+ `IIdentityComponent.alsoKnownAsAdd`
313
+
314
+ ***
315
+
316
+ ### alsoKnownAsRemove() {#alsoknownasremove}
317
+
318
+ > **alsoKnownAsRemove**(`documentId`, `alias`): `Promise`\<`void`\>
319
+
320
+ Remove an alias from the alsoKnownAs property on the document.
321
+ If the alias is not present the operation is a no-op.
322
+
323
+ #### Parameters
324
+
325
+ ##### documentId
326
+
327
+ `string`
328
+
329
+ The id of the document to update.
330
+
331
+ ##### alias
332
+
333
+ `string`
334
+
335
+ The alias to remove. Must be a Url or Urn.
336
+
337
+ #### Returns
338
+
339
+ `Promise`\<`void`\>
340
+
341
+ Nothing.
342
+
343
+ #### Throws
344
+
345
+ GeneralError if the alias is not a Url or Urn.
346
+
347
+ #### Throws
348
+
349
+ NotFoundError if the id can not be resolved.
350
+
351
+ #### Implementation of
352
+
353
+ `IIdentityComponent.alsoKnownAsRemove`
354
+
355
+ ***
356
+
357
+ ### verifiableCredentialCreate() {#verifiablecredentialcreate}
276
358
 
277
359
  > **verifiableCredentialCreate**(`verificationMethodId`, `id`, `subject`, `options?`): `Promise`\<\{ `verifiableCredential`: `IDidVerifiableCredential`; `jwt`: `string`; \}\>
278
360
 
@@ -288,9 +370,9 @@ The verification method id to use.
288
370
 
289
371
  ##### id
290
372
 
291
- The id of the credential.
373
+ `string` \| `undefined`
292
374
 
293
- `string` | `undefined`
375
+ The id of the credential.
294
376
 
295
377
  ##### subject
296
378
 
@@ -330,17 +412,17 @@ NotFoundError if the id can not be resolved.
330
412
 
331
413
  ***
332
414
 
333
- ### verifiableCredentialVerify()
415
+ ### verifiableCredentialVerify() {#verifiablecredentialverify}
334
416
 
335
- > **verifiableCredentialVerify**(`credentialJwt`): `Promise`\<\{ `revoked`: `boolean`; `verifiableCredential?`: `IDidVerifiableCredential`; \}\>
417
+ > **verifiableCredentialVerify**(`credential`): `Promise`\<\{ `revoked`: `boolean`; `verifiableCredential?`: `IDidVerifiableCredential`; \}\>
336
418
 
337
419
  Verify a verifiable credential is valid.
338
420
 
339
421
  #### Parameters
340
422
 
341
- ##### credentialJwt
423
+ ##### credential
342
424
 
343
- `string`
425
+ `string` \| `IDidVerifiableCredential`
344
426
 
345
427
  The credential to verify.
346
428
 
@@ -356,7 +438,7 @@ The credential stored in the jwt and the revocation status.
356
438
 
357
439
  ***
358
440
 
359
- ### verifiableCredentialRevoke()
441
+ ### verifiableCredentialRevoke() {#verifiablecredentialrevoke}
360
442
 
361
443
  > **verifiableCredentialRevoke**(`issuerId`, `credentialIndex`): `Promise`\<`void`\>
362
444
 
@@ -388,7 +470,7 @@ Nothing.
388
470
 
389
471
  ***
390
472
 
391
- ### verifiableCredentialUnrevoke()
473
+ ### verifiableCredentialUnrevoke() {#verifiablecredentialunrevoke}
392
474
 
393
475
  > **verifiableCredentialUnrevoke**(`issuerId`, `credentialIndex`): `Promise`\<`void`\>
394
476
 
@@ -420,9 +502,9 @@ Nothing.
420
502
 
421
503
  ***
422
504
 
423
- ### verifiablePresentationCreate()
505
+ ### verifiablePresentationCreate() {#verifiablepresentationcreate}
424
506
 
425
- > **verifiablePresentationCreate**(`verificationMethodId`, `presentationId`, `contexts`, `types`, `verifiableCredentials`, `expiresInMinutes?`): `Promise`\<\{ `verifiablePresentation`: `IDidVerifiablePresentation`; `jwt`: `string`; \}\>
507
+ > **verifiablePresentationCreate**(`verificationMethodId`, `presentationId`, `contexts`, `types`, `verifiableCredentials`, `options?`): `Promise`\<\{ `verifiablePresentation`: `IDidVerifiablePresentation`; `jwt`: `string`; \}\>
426
508
 
427
509
  Create a verifiable presentation from the supplied verifiable credentials.
428
510
 
@@ -436,21 +518,21 @@ The method to associate with the presentation.
436
518
 
437
519
  ##### presentationId
438
520
 
439
- The id of the presentation.
521
+ `string` \| `undefined`
440
522
 
441
- `string` | `undefined`
523
+ The id of the presentation.
442
524
 
443
525
  ##### contexts
444
526
 
445
- The contexts for the data stored in the verifiable credential.
527
+ `IJsonLdContextDefinitionRoot` \| `undefined`
446
528
 
447
- `IJsonLdContextDefinitionRoot` | `undefined`
529
+ The contexts for the data stored in the verifiable credential.
448
530
 
449
531
  ##### types
450
532
 
451
- The types for the data stored in the verifiable credential.
533
+ `string` \| `string`[] \| `undefined`
452
534
 
453
- `string` | `string`[] | `undefined`
535
+ The types for the data stored in the verifiable credential.
454
536
 
455
537
  ##### verifiableCredentials
456
538
 
@@ -458,11 +540,15 @@ The types for the data stored in the verifiable credential.
458
540
 
459
541
  The credentials to use for creating the presentation in jwt format.
460
542
 
461
- ##### expiresInMinutes?
543
+ ##### options?
462
544
 
463
- `number`
545
+ Additional options for creating the verifiable presentation.
464
546
 
465
- The time in minutes for the presentation to expire.
547
+ ###### expirationDate?
548
+
549
+ `Date`
550
+
551
+ The date the verifiable presentation is valid until.
466
552
 
467
553
  #### Returns
468
554
 
@@ -480,17 +566,17 @@ NotFoundError if the id can not be resolved.
480
566
 
481
567
  ***
482
568
 
483
- ### verifiablePresentationVerify()
569
+ ### verifiablePresentationVerify() {#verifiablepresentationverify}
484
570
 
485
- > **verifiablePresentationVerify**(`presentationJwt`): `Promise`\<\{ `revoked`: `boolean`; `verifiablePresentation?`: `IDidVerifiablePresentation`; `issuers?`: `IDidDocument`[]; \}\>
571
+ > **verifiablePresentationVerify**(`presentation`): `Promise`\<\{ `revoked`: `boolean`; `verifiablePresentation?`: `IDidVerifiablePresentation`; `issuers?`: `IDidDocument`[]; \}\>
486
572
 
487
573
  Verify a verifiable presentation is valid.
488
574
 
489
575
  #### Parameters
490
576
 
491
- ##### presentationJwt
577
+ ##### presentation
492
578
 
493
- `string`
579
+ `string` \| `IDidVerifiablePresentation`
494
580
 
495
581
  The presentation to verify.
496
582
 
@@ -506,7 +592,7 @@ The presentation stored in the jwt and the revocation status.
506
592
 
507
593
  ***
508
594
 
509
- ### proofCreate()
595
+ ### proofCreate() {#proofcreate}
510
596
 
511
597
  > **proofCreate**(`verificationMethodId`, `proofType`, `unsecureDocument`): `Promise`\<`IProof`\>
512
598
 
@@ -544,7 +630,7 @@ The proof.
544
630
 
545
631
  ***
546
632
 
547
- ### proofVerify()
633
+ ### proofVerify() {#proofverify}
548
634
 
549
635
  > **proofVerify**(`document`, `proof`): `Promise`\<`boolean`\>
550
636
 
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "@twin.org/identity-rest-client",
3
- "version": "0.0.3-next.2",
4
- "description": "Identity contract implementation which can connect to REST endpoints",
3
+ "version": "0.0.3-next.21",
4
+ "description": "Client library for consuming identity REST endpoints through shared request and response contracts.",
5
5
  "repository": {
6
6
  "type": "git",
7
- "url": "git+https://github.com/twinfoundation/identity.git",
7
+ "url": "git+https://github.com/iotaledger/identity.git",
8
8
  "directory": "packages/identity-rest-client"
9
9
  },
10
10
  "author": "martyn.janes@iota.org",
@@ -20,7 +20,7 @@
20
20
  "@twin.org/data-core": "next",
21
21
  "@twin.org/data-json-ld": "next",
22
22
  "@twin.org/entity": "next",
23
- "@twin.org/identity-models": "0.0.3-next.2",
23
+ "@twin.org/identity-models": "0.0.3-next.21",
24
24
  "@twin.org/nameof": "next",
25
25
  "@twin.org/standards-w3c-did": "next"
26
26
  },
@@ -52,7 +52,7 @@
52
52
  "authentication"
53
53
  ],
54
54
  "bugs": {
55
- "url": "git+https://github.com/twinfoundation/identity/issues"
55
+ "url": "git+https://github.com/iotaledger/identity/issues"
56
56
  },
57
57
  "homepage": "https://twindev.org"
58
58
  }