@sphereon/oid4vci-client 0.10.4-unstable.61 → 0.10.4-unstable.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 +512 -515
- package/dist/AccessTokenClient.d.ts +5 -5
- package/dist/AccessTokenClient.d.ts.map +1 -1
- package/dist/AccessTokenClient.js +25 -45
- package/dist/AccessTokenClient.js.map +1 -1
- package/dist/AuthorizationCodeClient.d.ts +5 -5
- package/dist/AuthorizationCodeClient.d.ts.map +1 -1
- package/dist/AuthorizationCodeClient.js +8 -19
- package/dist/AuthorizationCodeClient.js.map +1 -1
- package/dist/CredentialOfferClient.d.ts.map +1 -1
- package/dist/CredentialOfferClient.js +26 -14
- package/dist/CredentialOfferClient.js.map +1 -1
- package/dist/CredentialRequestClient.d.ts +8 -5
- package/dist/CredentialRequestClient.d.ts.map +1 -1
- package/dist/CredentialRequestClient.js +28 -16
- package/dist/CredentialRequestClient.js.map +1 -1
- package/dist/CredentialRequestClientBuilder.d.ts +7 -7
- package/dist/CredentialRequestClientBuilder.d.ts.map +1 -1
- package/dist/CredentialRequestClientBuilder.js +14 -13
- package/dist/CredentialRequestClientBuilder.js.map +1 -1
- package/dist/MetadataClient.d.ts +15 -5
- package/dist/MetadataClient.d.ts.map +1 -1
- package/dist/MetadataClient.js +33 -13
- package/dist/MetadataClient.js.map +1 -1
- package/dist/OpenID4VCIClient.d.ts +16 -9
- package/dist/OpenID4VCIClient.d.ts.map +1 -1
- package/dist/OpenID4VCIClient.js +91 -46
- package/dist/OpenID4VCIClient.js.map +1 -1
- package/dist/ProofOfPossessionBuilder.js +1 -1
- package/dist/ProofOfPossessionBuilder.js.map +1 -1
- package/dist/functions/ProofUtil.d.ts.map +1 -1
- package/dist/index.d.ts +1 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -8
- package/dist/index.js.map +1 -1
- package/lib/AccessTokenClient.ts +245 -277
- package/lib/AuthorizationCodeClient.ts +163 -183
- package/lib/CredentialOfferClient.ts +112 -99
- package/lib/CredentialRequestClient.ts +208 -187
- package/lib/CredentialRequestClientBuilder.ts +155 -153
- package/lib/MetadataClient.ts +208 -188
- package/lib/OpenID4VCIClient.ts +629 -579
- package/lib/ProofOfPossessionBuilder.ts +204 -204
- package/lib/__tests__/AccessTokenClient.spec.ts +211 -239
- package/lib/__tests__/CredentialRequestClient.spec.ts +311 -342
- package/lib/__tests__/CredentialRequestClientBuilder.spec.ts +131 -137
- package/lib/__tests__/EBSIE2E.spec.test.ts +145 -145
- package/lib/__tests__/IT.spec.ts +208 -421
- package/lib/__tests__/IssuanceInitiation.spec.ts +83 -116
- package/lib/__tests__/JsonURIConversions.spec.ts +146 -146
- package/lib/__tests__/MattrE2E.spec.test.ts +104 -104
- package/lib/__tests__/MetadataClient.spec.ts +260 -311
- package/lib/__tests__/MetadataMocks.ts +444 -483
- package/lib/__tests__/OpenID4VCIClient.spec.ts +202 -224
- package/lib/__tests__/{OpenID4VCIClientPARV1_0_11.spec.ts → OpenID4VCIClientPAR.spec.ts} +122 -122
- package/lib/__tests__/ProofOfPossessionBuilder.spec.ts +110 -110
- package/lib/__tests__/SdJwt.spec.ts +163 -167
- package/lib/__tests__/SphereonE2E.spec.test.ts +169 -169
- package/lib/__tests__/data/VciDataFixtures.ts +745 -1430
- package/lib/functions/AuthorizationUtil.ts +18 -18
- package/lib/functions/ProofUtil.ts +128 -128
- package/lib/index.ts +9 -16
- package/package.json +3 -3
- package/dist/AccessTokenClientV1_0_11.d.ts +0 -29
- package/dist/AccessTokenClientV1_0_11.d.ts.map +0 -1
- package/dist/AccessTokenClientV1_0_11.js +0 -212
- package/dist/AccessTokenClientV1_0_11.js.map +0 -1
- package/dist/AuthorizationCodeClientV1_0_11.d.ts +0 -9
- package/dist/AuthorizationCodeClientV1_0_11.d.ts.map +0 -1
- package/dist/AuthorizationCodeClientV1_0_11.js +0 -132
- package/dist/AuthorizationCodeClientV1_0_11.js.map +0 -1
- package/dist/CredentialOfferClientV1_0_11.d.ts +0 -10
- package/dist/CredentialOfferClientV1_0_11.d.ts.map +0 -1
- package/dist/CredentialOfferClientV1_0_11.js +0 -103
- package/dist/CredentialOfferClientV1_0_11.js.map +0 -1
- package/dist/CredentialRequestClientBuilderV1_0_11.d.ts +0 -46
- package/dist/CredentialRequestClientBuilderV1_0_11.d.ts.map +0 -1
- package/dist/CredentialRequestClientBuilderV1_0_11.js +0 -117
- package/dist/CredentialRequestClientBuilderV1_0_11.js.map +0 -1
- package/dist/CredentialRequestClientV1_0_11.d.ts +0 -44
- package/dist/CredentialRequestClientV1_0_11.d.ts.map +0 -1
- package/dist/CredentialRequestClientV1_0_11.js +0 -151
- package/dist/CredentialRequestClientV1_0_11.js.map +0 -1
- package/dist/MetadataClientV1_0_11.d.ts +0 -31
- package/dist/MetadataClientV1_0_11.d.ts.map +0 -1
- package/dist/MetadataClientV1_0_11.js +0 -182
- package/dist/MetadataClientV1_0_11.js.map +0 -1
- package/dist/OpenID4VCIClientV1_0_11.d.ts +0 -107
- package/dist/OpenID4VCIClientV1_0_11.d.ts.map +0 -1
- package/dist/OpenID4VCIClientV1_0_11.js +0 -462
- package/dist/OpenID4VCIClientV1_0_11.js.map +0 -1
- package/dist/functions/OpenIDUtils.d.ts +0 -12
- package/dist/functions/OpenIDUtils.d.ts.map +0 -1
- package/dist/functions/OpenIDUtils.js +0 -37
- package/dist/functions/OpenIDUtils.js.map +0 -1
- package/lib/AccessTokenClientV1_0_11.ts +0 -255
- package/lib/AuthorizationCodeClientV1_0_11.ts +0 -168
- package/lib/CredentialOfferClientV1_0_11.ts +0 -112
- package/lib/CredentialRequestClientBuilderV1_0_11.ts +0 -156
- package/lib/CredentialRequestClientV1_0_11.ts +0 -191
- package/lib/MetadataClientV1_0_11.ts +0 -189
- package/lib/OpenID4VCIClientV1_0_11.ts +0 -645
- package/lib/__tests__/CredentialRequestClientV1_0_11.spec.ts +0 -316
- package/lib/__tests__/IssuanceInitiationV1_0_11.spec.ts +0 -62
- package/lib/__tests__/OpenID4VCIClientV1_0_11.spec.ts +0 -202
- package/lib/functions/OpenIDUtils.ts +0 -25
package/README.md
CHANGED
|
@@ -1,515 +1,512 @@
|
|
|
1
|
-
<h1 align="center">
|
|
2
|
-
<br>
|
|
3
|
-
<a href="https://www.sphereon.com"><img src="https://sphereon.com/content/themes/sphereon/assets/img/logo.svg" alt="Sphereon" width="400"></a>
|
|
4
|
-
<br>OpenID for Verifiable Credential Issuance - Client
|
|
5
|
-
<br>
|
|
6
|
-
</h1>
|
|
7
|
-
|
|
8
|
-
[](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [](https://npm.im/@sphereon/oid4vci-client)
|
|
9
|
-
|
|
10
|
-
_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of
|
|
11
|
-
OpenID4VCI!_
|
|
12
|
-
|
|
13
|
-
# Background
|
|
14
|
-
|
|
15
|
-
A client to request and receive Verifiable Credentials using
|
|
16
|
-
the [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (
|
|
17
|
-
OpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.
|
|
18
|
-
|
|
19
|
-
OpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and
|
|
20
|
-
corresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to
|
|
21
|
-
receive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing
|
|
22
|
-
OAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.
|
|
23
|
-
It also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and
|
|
24
|
-
interoperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.
|
|
25
|
-
|
|
26
|
-
# Flows
|
|
27
|
-
|
|
28
|
-
The spec lists 2 flows. Currently only one is supported!
|
|
29
|
-
|
|
30
|
-
## Authorized Code Flow
|
|
31
|
-
|
|
32
|
-
This flow isn't supported yet!
|
|
33
|
-
|
|
34
|
-
## Pre-authorized Code Flow
|
|
35
|
-
|
|
36
|
-
The pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to
|
|
37
|
-
authenticate first.
|
|
38
|
-
|
|
39
|
-
The below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like
|
|
40
|
-
saving VCs) are out of scope for this library.
|
|
41
|
-
|
|
42
|
-

|
|
43
|
-
|
|
44
|
-
# OpenID4VCI Client
|
|
45
|
-
|
|
46
|
-
The OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a
|
|
47
|
-
client you can use to finish the pre-authorized code flows.
|
|
48
|
-
|
|
49
|
-
## Initiating the client
|
|
50
|
-
|
|
51
|
-
This initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also
|
|
52
|
-
already fetching the Server Metadata
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
console.log(client.
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
.
|
|
142
|
-
.
|
|
143
|
-
.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
const
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
229
|
-
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
232
|
-
*
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
*
|
|
238
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
*
|
|
278
|
-
*
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
.
|
|
311
|
-
.
|
|
312
|
-
.
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
.
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
//
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
//
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
const
|
|
440
|
-
|
|
441
|
-
//
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
})
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
//
|
|
496
|
-
//
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
* 11
|
|
514
|
-
*/
|
|
515
|
-
```
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
<br>
|
|
3
|
+
<a href="https://www.sphereon.com"><img src="https://sphereon.com/content/themes/sphereon/assets/img/logo.svg" alt="Sphereon" width="400"></a>
|
|
4
|
+
<br>OpenID for Verifiable Credential Issuance - Client
|
|
5
|
+
<br>
|
|
6
|
+
</h1>
|
|
7
|
+
|
|
8
|
+
[](https://github.com/Sphereon-Opensource/openid4vci-client/actions/workflows/main.yml) [](https://codecov.io/gh/Sphereon-Opensource/openid4vci-client) [](https://npm.im/@sphereon/oid4vci-client)
|
|
9
|
+
|
|
10
|
+
_IMPORTANT this package is in an early development stage and currently only supports the pre-authorized code flow of
|
|
11
|
+
OpenID4VCI!_
|
|
12
|
+
|
|
13
|
+
# Background
|
|
14
|
+
|
|
15
|
+
A client to request and receive Verifiable Credentials using
|
|
16
|
+
the [OpenID for Verifiable Credential Issuance](https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html) (
|
|
17
|
+
OpenID4VCI) specification for receiving Verifiable Credentials as a holder/subject.
|
|
18
|
+
|
|
19
|
+
OpenID4VCI defines an API designated as Credential Endpoint that is used to issue verifiable credentials and
|
|
20
|
+
corresponding OAuth 2.0 based authorization mechanisms (see [RFC6749]) that a Wallet uses to obtain authorization to
|
|
21
|
+
receive verifiable credentials. W3C formats as well as other Credential formats are supported. This allows existing
|
|
22
|
+
OAuth 2.0 deployments and OpenID Connect OPs (see [OpenID.Core]) to extend their service and become Credential Issuers.
|
|
23
|
+
It also allows new applications built using Verifiable Credentials to utilize OAuth 2.0 as integration and
|
|
24
|
+
interoperability layer. This package provides holder/wallet support to interact with OpenID4VCI capable Issuer systems.
|
|
25
|
+
|
|
26
|
+
# Flows
|
|
27
|
+
|
|
28
|
+
The spec lists 2 flows. Currently only one is supported!
|
|
29
|
+
|
|
30
|
+
## Authorized Code Flow
|
|
31
|
+
|
|
32
|
+
This flow isn't supported yet!
|
|
33
|
+
|
|
34
|
+
## Pre-authorized Code Flow
|
|
35
|
+
|
|
36
|
+
The pre-authorized code flow assumes the user is using an out-of-band mechanism outside the issuance flow to
|
|
37
|
+
authenticate first.
|
|
38
|
+
|
|
39
|
+
The below diagram shows the steps involved in the pre-authorized code flow. Note that wallet inner functionalities (like
|
|
40
|
+
saving VCs) are out of scope for this library.
|
|
41
|
+
|
|
42
|
+

|
|
43
|
+
|
|
44
|
+
# OpenID4VCI Client
|
|
45
|
+
|
|
46
|
+
The OpenID4VCI client is the main client you typically will want to use. It combines several lower level classes into a
|
|
47
|
+
client you can use to finish the pre-authorized code flows.
|
|
48
|
+
|
|
49
|
+
## Initiating the client
|
|
50
|
+
|
|
51
|
+
This initiates the client using a URI obtained from the Issuer using a link (URL) or QR code typically. We are also
|
|
52
|
+
already fetching the Server Metadata
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
import { OpenID4VCIClient } from '@sphereon/oid4vci-client';
|
|
56
|
+
|
|
57
|
+
// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.
|
|
58
|
+
const client = await OpenID4VCIClient.fromURI({
|
|
59
|
+
uri: 'openid-initiate-issuance://?issuer=https%3A%2F%2Fissuer.research.identiproof.io&credential_type=OpenBadgeCredentialUrl&pre-authorized_code=4jLs9xZHEfqcoow0kHE7d1a8hUk6Sy-5bVSV2MqBUGUgiFFQi-ImL62T-FmLIo8hKA1UdMPH0lM1xAgcFkJfxIw9L-lI3mVs0hRT8YVwsEM1ma6N3wzuCdwtMU4bcwKp&user_pin_required=true',
|
|
60
|
+
kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID. You can defer this also to when the acquireCredential method is called
|
|
61
|
+
alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called
|
|
62
|
+
clientId: 'test-clientId', // The clientId if the Authrozation Service requires it. If a clientId is needed you can defer this also to when the acquireAccessToken method is called
|
|
63
|
+
retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
console.log(client.getIssuer()); // https://issuer.research.identiproof.io
|
|
67
|
+
console.log(client.getCredentialEndpoint()); // https://issuer.research.identiproof.io/credential
|
|
68
|
+
console.log(client.getAccessTokenEndpoint()); // https://auth.research.identiproof.io/oauth2/token
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Using https scheme
|
|
72
|
+
```typescript
|
|
73
|
+
import { OpenID4VCIClient } from '@sphereon/oid4vci-client';
|
|
74
|
+
|
|
75
|
+
// The client is initiated from a URI. This URI is provided by the Issuer, typically as a URL or QR code.
|
|
76
|
+
const client = await OpenID4VCIClient.fromURI({
|
|
77
|
+
uri: 'https://launchpad.vii.electron.mattrlabs.io?credential_offer=%7B%22credential_issuer%22%3A%22https%3A%2F%2Flaunchpad.vii.electron.mattrlabs.io%22%2C%22credentials%22%3A%5B%7B%22format%22%3A%22ldp_vc%22%2C%22types%22%3A%5B%22OpenBadgeCredential%22%5D%7D%5D%2C%22grants%22%3A%7B%22urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Apre-authorized_code%22%3A%7B%22pre-authorized_code%22%3A%22UPZohaodPlLBnGsqB02n2tIupCIg8nKRRUEUHWA665X%22%7D%7D%7D',
|
|
78
|
+
kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#key-1', // Our DID. You can defer this also to when the acquireCredential method is called
|
|
79
|
+
alg: Alg.ES256, // The signing Algorithm we will use. You can defer this also to when the acquireCredential method is called
|
|
80
|
+
clientId: 'test-clientId', // The clientId if the Authrozation Service requires it. If a clientId is needed you can defer this also to when the acquireAccessToken method is called
|
|
81
|
+
retrieveServerMetadata: true, // Already retrieve the server metadata. Can also be done afterwards by invoking a method yourself.
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
console.log(client.getIssuer()); // https://launchpad.vii.electron.mattrlabs.io
|
|
85
|
+
console.log(client.getCredentialEndpoint()); // https://launchpad.vii.electron.mattrlabs.io/credential
|
|
86
|
+
console.log(client.getAccessTokenEndpoint()); // https://launchpad.vii.electron.mattrlabs.io/oauth2/token
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
## Server metadata
|
|
90
|
+
|
|
91
|
+
The OID4VCI Server metadata contains information about token endpoints, credential endpoints, as well as additional
|
|
92
|
+
information about supported Credentials, and their cryptographic suites and formats.
|
|
93
|
+
The code above already retrieved the metadata, so it will not be fetched again, and this method places the data in another variable. If you however have not used
|
|
94
|
+
the `retrieveServerMetadata` option, you can use this method to fetch it from the Issuer:
|
|
95
|
+
|
|
96
|
+
```typescript
|
|
97
|
+
const metadata = await client.retrieveServerMetadata();
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Access token from Authorization Server
|
|
101
|
+
|
|
102
|
+
Next we need to get an Access token from the OAuth2 Authorization Server using the token endpoint. This endpoint is
|
|
103
|
+
found from the metadata if the server supports it. Otherwise a default location based on the issuer value from the
|
|
104
|
+
Initiate Issuance Request is used.
|
|
105
|
+
|
|
106
|
+
```typescript
|
|
107
|
+
const accessToken = await client.acquireAccessToken({ pin: '1234' });
|
|
108
|
+
console.log(accessToken);
|
|
109
|
+
/**
|
|
110
|
+
* {
|
|
111
|
+
* access_token: 'ey6546.546654.64565',
|
|
112
|
+
* authorization_pending: false,
|
|
113
|
+
* c_nonce: 'c_nonce2022101300',
|
|
114
|
+
* c_nonce_expires_in: 2025101300,
|
|
115
|
+
* interval: 2025101300,
|
|
116
|
+
* token_type: 'Bearer',
|
|
117
|
+
* }
|
|
118
|
+
*/
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Getting the credential
|
|
122
|
+
|
|
123
|
+
Now it is time to get the credential. In order to achieve this, we will be using the metadata together with the access
|
|
124
|
+
token, but first we will have to create a so-called Proof of Possession. Please see
|
|
125
|
+
the [Proof of Posession](#proof-of-possession) chapter for more information.
|
|
126
|
+
|
|
127
|
+
The Proof of Possession using a signature callback function. The example uses the `jose` library.
|
|
128
|
+
|
|
129
|
+
```typescript
|
|
130
|
+
import * as jose from 'jose';
|
|
131
|
+
import { DIDDocument } from 'did-resolver';
|
|
132
|
+
|
|
133
|
+
const { privateKey, publicKey } = await jose.generateKeyPair('ES256');
|
|
134
|
+
|
|
135
|
+
// Must be JWS
|
|
136
|
+
async function signCallback(args: Jwt, kid: string): Promise<string> {
|
|
137
|
+
return await new jose.SignJWT({ ...args.payload })
|
|
138
|
+
.setProtectedHeader({ alg: args.header.alg })
|
|
139
|
+
.setIssuedAt()
|
|
140
|
+
.setIssuer(kid)
|
|
141
|
+
.setAudience(args.payload.aud)
|
|
142
|
+
.setExpirationTime('2h')
|
|
143
|
+
.sign(privateKey);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const callbacks: ProofOfPossessionCallbacks<DIDDocument> = {
|
|
147
|
+
signCallback,
|
|
148
|
+
};
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Now it is time to get the actual credential
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
const credentialResponse = await client.acquireCredentials({
|
|
155
|
+
credentialTypes: 'OpenBadgeCredential',
|
|
156
|
+
proofCallbacks: callbacks,
|
|
157
|
+
format: 'jwt_vc_json',
|
|
158
|
+
alg: Alg.ES256K,
|
|
159
|
+
kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#keys-1',
|
|
160
|
+
});
|
|
161
|
+
console.log(credentialResponse.credential);
|
|
162
|
+
// JWT format. (LDP / JSON-LD ('ldp_vc' / 'jwt_vc_json-ld') is also supported by the client)
|
|
163
|
+
// eyJhbGciOiJFUzI1NiIsInR5cCI6IkpXVCJ9.eyJ2YyI6eyJAY29udGV4dCI6WyJodHRwczovL3d3dy53My5vcmcvMjAxOC9jcmVkZW50aWFscy92MSIsImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL2V4YW1wbGVzL3YxIl0sImlkIjoiaHR0cDovL2V4YW1wbGUuZWR1L2NyZWRlbnRpYWxzLzM3MzIiLCJ0eXBlIjpbIlZlcmlmaWFibGVDcmVkZW50aWFsIiwiVW5pdmVyc2l0eURlZ3JlZUNyZWRlbnRpYWwiXSwiaXNzdWVyIjoiaHR0cHM6Ly9leGFtcGxlLmVkdS9pc3N1ZXJzLzU2NTA0OSIsImlzc3VhbmNlRGF0ZSI6IjIwMTAtMDEtMDFUMDA6MDA6MDBaIiwiY3JlZGVudGlhbFN1YmplY3QiOnsiaWQiOiJkaWQ6ZXhhbXBsZTplYmZlYjFmNzEyZWJjNmYxYzI3NmUxMmVjMjEiLCJkZWdyZWUiOnsidHlwZSI6IkJhY2hlbG9yRGVncmVlIiwibmFtZSI6IkJhY2hlbG9yIG9mIFNjaWVuY2UgYW5kIEFydHMifX19LCJpc3MiOiJodHRwczovL2V4YW1wbGUuZWR1L2lzc3VlcnMvNTY1MDQ5IiwibmJmIjoxMjYyMzA0MDAwLCJqdGkiOiJodHRwOi8vZXhhbXBsZS5lZHUvY3JlZGVudGlhbHMvMzczMiIsInN1YiI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMSJ9.z5vgMTK1nfizNCg5N-niCOL3WUIAL7nXy-nGhDZYO_-PNGeE-0djCpWAMH8fD8eWSID5PfkPBYkx_dfLJnQ7NA
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
# Using individual classes and methods instead of the client
|
|
167
|
+
|
|
168
|
+
Instead of using the OpenID4VCI Client, you can also use the separate classes if you want. This typically gives you a
|
|
169
|
+
bit more control and options, at the expense of a bit more complexity.
|
|
170
|
+
|
|
171
|
+
## Issuance Initiation
|
|
172
|
+
|
|
173
|
+
Issuance is started from a so-called Issuance Initiation Request by the Issuer. This typically is URI, exposed
|
|
174
|
+
as a link or a QR code. You can call the `CredentialOffer.fromURI(uri)` method to parse the URI into a Json object
|
|
175
|
+
containing the baseUrl and a `uri` JSON object
|
|
176
|
+
|
|
177
|
+
```typescript
|
|
178
|
+
import { CredentialOffer } from '@sphereon/oid4vci-client';
|
|
179
|
+
|
|
180
|
+
const initiationURI =
|
|
181
|
+
'https://issuer.example.com?issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy';
|
|
182
|
+
|
|
183
|
+
const initiationRequestWithUrl = CredentialOffer.fromURI(initiationURI);
|
|
184
|
+
console.log(initiationRequestWithUrl);
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* {
|
|
188
|
+
* "baseUrl": "https://server.example.com",
|
|
189
|
+
* "request": {
|
|
190
|
+
* "credential_type": [
|
|
191
|
+
* "https://did.example.org/healthCard",
|
|
192
|
+
* "https://did.example.org/driverLicense"
|
|
193
|
+
* ],
|
|
194
|
+
* "issuer": "https://server.example.com",
|
|
195
|
+
* "op_state": "eyJhbGciOiJSU0Et...FYUaBy"
|
|
196
|
+
* },
|
|
197
|
+
* "version": 9
|
|
198
|
+
* }
|
|
199
|
+
*/
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Getting OpenID4VCI Server and OIDC/OAuth2 metadata
|
|
203
|
+
|
|
204
|
+
The OpenID4VCI spec defines a server metadata object that contains information about the issuer and the credentials they
|
|
205
|
+
support. Next to this predefined endpoint there are also the well-known locations for OpenID Connect Discovery
|
|
206
|
+
configuration and
|
|
207
|
+
Oauth2 Authorization Server configuration. These contain for instance the token endpoints.
|
|
208
|
+
The MetadataClient checks the OpenID4VCI well-known location for the medata and existence of a token endpoint. If the
|
|
209
|
+
OpenID4VCI well-known location is not found, the OIDC/OAuth2 well-known locations will be tried:
|
|
210
|
+
|
|
211
|
+
Example:
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
import { MetadataClient } from '@sphereon/oid4vci-client';
|
|
215
|
+
|
|
216
|
+
const metadata = await MetadataClient.retrieveAllMetadataFromCredentialOffer(initiationRequestWithUrl);
|
|
217
|
+
|
|
218
|
+
console.log(metadata);
|
|
219
|
+
/**
|
|
220
|
+
* {
|
|
221
|
+
* issuer: 'https://server.example.com',
|
|
222
|
+
* credential_endpoint: 'https://server.example.com/credential',
|
|
223
|
+
* token_endpoint: 'https://server.example.com/token',
|
|
224
|
+
* jwks_uri: 'https://server.example.com/jwks',
|
|
225
|
+
* grant_types_supported: ['urn:ietf:params:oauth:grant-type:pre-authorized_code'],
|
|
226
|
+
* credentials_supported: {
|
|
227
|
+
* OpenBadgeCredential: {
|
|
228
|
+
* formats: {
|
|
229
|
+
* jwt_vc: {
|
|
230
|
+
* types: [
|
|
231
|
+
* 'https://imsglobal.github.io/openbadges-specification/ob_v3p0.html#OpenBadgeCredential',
|
|
232
|
+
* 'https://w3id.org/ngi/OpenBadgeExtendedCredential',
|
|
233
|
+
* ],
|
|
234
|
+
* binding_methods_supported: ['did'],
|
|
235
|
+
* cryptographic_suites_supported: ['ES256'],
|
|
236
|
+
* },
|
|
237
|
+
* },
|
|
238
|
+
* },
|
|
239
|
+
* },
|
|
240
|
+
* }
|
|
241
|
+
*/
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
## Acquiring the Access Token
|
|
245
|
+
|
|
246
|
+
Now you will need to get an access token from the oAuth2 Authorization Server (AS), using some values from
|
|
247
|
+
the `IssuanceInitiationRequestPayloadV9` payload.
|
|
248
|
+
For now, you can use the issuer hostname for the AS, as there is no way to know the AS from the Issuance Initiation for
|
|
249
|
+
known until the
|
|
250
|
+
following [OpenID Ticket](https://bitbucket.org/openid/connect/issues/1632/issuer-metadata-clarification-needed) is
|
|
251
|
+
resolved. So the token endpoint would become https://<issuer-hostname>/token.
|
|
252
|
+
The library allows to pass in a different value for the AS token endpoint as well, so you already can use a different AS
|
|
253
|
+
if you know the AS upfront. If no AS is provided the issuer value from the Issuance Initiation Request will be used.
|
|
254
|
+
|
|
255
|
+
```typescript
|
|
256
|
+
import { AccessTokenClient, AuthorizationServerOpts } from '@sphereon/oid4vci-client';
|
|
257
|
+
|
|
258
|
+
const clientId = 'abcd'; // This can be a random value or a clientId assigned by the Authorization Server (depends on the environment)
|
|
259
|
+
const pin = 1234; // A pincode which is shown out of band typically. Only use when the pin-code is required from the Issuance Initiation object.
|
|
260
|
+
|
|
261
|
+
// Allows to override the Authorization Server and provide other AS options. By default the issuer value will be used
|
|
262
|
+
const asOpts: AuthorizationServerOpts = {
|
|
263
|
+
clientId,
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const accessTokenResponse = AccessTokenClient.acquireAccessTokenUsingRequest({
|
|
267
|
+
credentialOffer,
|
|
268
|
+
asOpts,
|
|
269
|
+
pin,
|
|
270
|
+
metadata,
|
|
271
|
+
});
|
|
272
|
+
console.log(accessTokenResponse);
|
|
273
|
+
/**
|
|
274
|
+
* {
|
|
275
|
+
* access_token: "eyJhbGciOiJSUzI1NiIsInR5cCI6Ikp..sHQ"
|
|
276
|
+
* token_type: "bearer",
|
|
277
|
+
* expires_in: 86400
|
|
278
|
+
* }
|
|
279
|
+
*/
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
# Proof of Possession
|
|
283
|
+
|
|
284
|
+
Part of OpenID4VCI is the holder showing that they are in possession of a certain key, associated with the DID that will
|
|
285
|
+
be the subject of the to be issued Verifiable Credential.
|
|
286
|
+
This proof of possession will be created using a DID, it's associated keypair and the `ProofOfPossessionBuilder` class.
|
|
287
|
+
This Builder can be initiated from a JWT object if you want to create a JWT yourself, or it can be build using the
|
|
288
|
+
Initiate Issuance Request, Server metadata and some methods from the builder. Both approaches need a callback function
|
|
289
|
+
to sign the JWT and optionally a callback to verify the JWT.
|
|
290
|
+
The signature of the callback functions you need to implement are:
|
|
291
|
+
|
|
292
|
+
```typescript
|
|
293
|
+
export type JWTSignerCallback = (jwt: Jwt, kid: string) => Promise<string>;
|
|
294
|
+
export type JWTVerifyCallback = (args: { jwt: string; kid: string }) => Promise<void>;
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
This is an example of the signature callback function created using the `jose` library.
|
|
298
|
+
|
|
299
|
+
```typescript
|
|
300
|
+
import { Jwt } from '@sphereon/oid4vci-client';
|
|
301
|
+
|
|
302
|
+
const { privateKey, publicKey } = await jose.generateKeyPair('ES256');
|
|
303
|
+
|
|
304
|
+
// Must be JWS
|
|
305
|
+
async function signCallback(args: Jwt, kid: string): Promise<string> {
|
|
306
|
+
return await new jose.SignJWT({ ...args.payload })
|
|
307
|
+
.setProtectedHeader({ alg: args.header.alg })
|
|
308
|
+
.setIssuedAt()
|
|
309
|
+
.setIssuer(kid)
|
|
310
|
+
.setAudience(args.payload.aud)
|
|
311
|
+
.setExpirationTime('2h')
|
|
312
|
+
.sign(keypair.privateKey);
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
Alongside signing, you can optionally provide another callback function for verifying the created signature with
|
|
317
|
+
populating `verifyCallback`. The method is expected to throw errors in case problems with the JWT or it's signature are
|
|
318
|
+
found.
|
|
319
|
+
below is an example of such method. This example (like the previous one) uses `jose` to verify the jwt.
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
async function verifyCallback(args: { jwt: string; kid: string }): Promise<void> {
|
|
323
|
+
await jose.compactVerify(args.jwt, keypair.publicKey);
|
|
324
|
+
}
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
Some important interface around Proof of Possession:
|
|
328
|
+
|
|
329
|
+
```typescript
|
|
330
|
+
export enum Alg {
|
|
331
|
+
EdDSA = 'EdDSA',
|
|
332
|
+
ES256 = 'ES256',
|
|
333
|
+
ES256K = 'ES256K',
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export interface JWTHeader {
|
|
337
|
+
alg: Alg; // REQUIRED by the JWT signer
|
|
338
|
+
typ?: string; //JWT always
|
|
339
|
+
kid?: string; // CONDITIONAL. JWT header containing the key ID. If the Credential shall be bound to a DID, the kid refers to a DID URL which identifies a particular key in the DID Document that the Credential shall be bound to. MUST NOT be present if jwk or x5c is present.
|
|
340
|
+
jwk?: JWK; // CONDITIONAL. JWT header containing the key material the new Credential shall be bound to. MUST NOT be present if kid or x5c is present.
|
|
341
|
+
x5c?: string[]; // CONDITIONAL. JWT header containing a certificate or certificate chain corresponding to the key used to sign the JWT. This element may be used to convey a key attestation. In such a case, the actual key certificate will contain attributes related to the key properties. MUST NOT be present if kid or jwk is present.
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
export interface JWTPayload {
|
|
345
|
+
iss?: string; // REQUIRED (string). The value of this claim MUST be the client_id of the client making the credential request.
|
|
346
|
+
aud?: string; // REQUIRED (string). The value of this claim MUST be the issuer URL of credential issuer.
|
|
347
|
+
iat?: number; // REQUIRED (number). The value of this claim MUST be the time at which the proof was issued using the syntax defined in [RFC7519].
|
|
348
|
+
nonce?: string; // REQUIRED (string). The value type of this claim MUST be a string, where the value is a c_nonce provided by the credential issuer. //TODO: Marked as required not present in NGI flow
|
|
349
|
+
jti?: string; // A new nonce chosen by the wallet. Used to prevent replay
|
|
350
|
+
exp?: number; // Not longer than 5 minutes
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
export interface Jwt {
|
|
354
|
+
header?: JWTHeader;
|
|
355
|
+
payload?: JWTPayload;
|
|
356
|
+
}
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
The arguments requested by `jose` and `@sphereon/oid4vci-client`
|
|
360
|
+
|
|
361
|
+
```typescript
|
|
362
|
+
import { Jwt, ProofOfPossessionCallbacks } from '@sphereon/oid4vci-client';
|
|
363
|
+
|
|
364
|
+
const callbacks: ProofOfPossessionCallbacks = {
|
|
365
|
+
signCallback,
|
|
366
|
+
verifyCallback,
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
const keyPair = await jose.generateKeyPair('ES256');
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
### Using the builder from metadata and access token response
|
|
373
|
+
|
|
374
|
+
Normally you would use the Proof of Possession builder using the server metadata and access token response together with
|
|
375
|
+
the callbacks. There is however the possibility to use a JWT directly, which will be explained in the next section.
|
|
376
|
+
|
|
377
|
+
```typescript
|
|
378
|
+
import { ProofOfPossessionBuilder } from '@sphereon/oid4vci-client';
|
|
379
|
+
|
|
380
|
+
const proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromAccessTokenResponse({
|
|
381
|
+
accessTokenResponse,
|
|
382
|
+
callbacks,
|
|
383
|
+
})
|
|
384
|
+
.withEndpointMetadata(metadata)
|
|
385
|
+
.withClientId('s6BhdRkqt3')
|
|
386
|
+
.withKid('did:example:ebfeb1f712ebc6f1c276e12ec21/keys/1')
|
|
387
|
+
.build();
|
|
388
|
+
console.log(proofInput);
|
|
389
|
+
// {
|
|
390
|
+
// "proof_type": "jwt",
|
|
391
|
+
// "jwt": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI"
|
|
392
|
+
// }
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
### Using the builder with a self-created JWT
|
|
396
|
+
|
|
397
|
+
You can build/create a JWT yourself. You would still use the callbacks to sign the JWT. Please be aware that you will
|
|
398
|
+
have to use the `c_nonce` value from the Access Token response as `nonce` value!. You can provide another nonce using
|
|
399
|
+
the `jti` property.
|
|
400
|
+
|
|
401
|
+
```typescript
|
|
402
|
+
import { Jwt, ProofOfPossessionBuilder, ProofOfPossessionCallbacks } from '@sphereon/oid4vci-client';
|
|
403
|
+
|
|
404
|
+
const callbacks: ProofOfPossessionCallbacks = {
|
|
405
|
+
signCallback,
|
|
406
|
+
verifyCallback,
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
const keyPair = await jose.generateKeyPair('ES256');
|
|
410
|
+
|
|
411
|
+
// If you directly want to use a JWT, instead of using method on the ProofOfPossessionBuilder you can create JWT:
|
|
412
|
+
const jwt: Jwt = {
|
|
413
|
+
header: { alg: Alg.ES256, kid: 'did:example:ebfeb1f712ebc6f1c276e12ec21#1', typ: Typ.JWT },
|
|
414
|
+
payload: { iss: 's6BhdRkqt3', nonce: 'tZignsnFbp', jti: 'tZignsnFbp223', aud: 'https://issuer.example.com' },
|
|
415
|
+
};
|
|
416
|
+
|
|
417
|
+
const proofInput: ProofOfPossession = await ProofOfPossessionBuilder.fromJwt({
|
|
418
|
+
jwt,
|
|
419
|
+
callbacks,
|
|
420
|
+
}).build();
|
|
421
|
+
console.log(proofInput);
|
|
422
|
+
// {
|
|
423
|
+
// "proof_type": "jwt",
|
|
424
|
+
// "jwt": "eyJhbGciOiJSUzI1NiIsImtpZCI6ImRpZDpleGFtcGxlOmViZmViMWY3MTJlYmM2ZjFjMjc2ZTEyZWMyMS9rZXlzLzEifQ.eyJpc3MiOiJzNkJoZFJrcXQzIiwiYXVkIjoiaHR0cHM6Ly9zZXJ2ZXIuZXhhbXBsZS5jb20iLCJpYXQiOjE2NTkxNDU5MjQsIm5vbmNlIjoidFppZ25zbkZicCJ9.btetOcsJ_VOePkwlFf2kyxm6hEUvPRimf3M-Dn3Lmzcmt5QiPToXNWxe_0fEJlRf4Ith55YGB43ScBe6ScZmD1gfLELYQF7LLg97yYlx_Iu8RLA2dS_7EWzLD3ZIzyUGf_uMq3HwXGJKL-ihroRpRBvxRLdZCy-j62nAzoTsBnlr6n79VjkGtlxIjN_CLGIQBhc3du3enghY6N4s3oXFrxWMl7UzGKdjCYN6vSagDb0MURjdiDCsK_yX4NyNd0nGpxqGhVgMpuhqEcqyU0qWPyHF-swtGG5JVAOJGd_YkJS5vbia8UdyOJXnAAdEE1E62a2yUPahNDxMh1iIpS0WO7y6QexWXdb5fmnWDst89T3ELS8Hj2Vzsw1XPyk9XR9JmiDzmEZdH05Wf4M9pXUG4-8_7StB6Lxc7_xDJdk6JPbzFgAIhJa4F_3rfPuwMseSEQvD6bDFowkIiUpt1vXGGVjVm3N4I4Th4_A2QpW4mDzcTKoZq9MKlDGXeLQBtiKXmqs10Jvzpp3O7kBwH7Qm6VUdBxk_-wsWplUZC4IvCfv23hy2SyFnh5zC6Wtw3UcbrSH6LcD7g-RNTKe4fRekyDxqLRdEm60BOozgBoTNhnetCrQ3e7HrApj9EP0vqNyXdtGGWCA011HVDnz6lVzf5yijJB8hOPpkgYGRmHdRQwI"
|
|
425
|
+
// }
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
## Credential Issuance
|
|
429
|
+
|
|
430
|
+
Now it is time to request the actual Credential(s) from the Issuer. The example uses a DID:JWK. The DID:JWK should match
|
|
431
|
+
the keypair created earlier.
|
|
432
|
+
|
|
433
|
+
```typescript
|
|
434
|
+
import { CredentialRequestClientBuilder, CredentialResponse, ProofOfPossessionArgs } from '@sphereon/oid4vci-client';
|
|
435
|
+
|
|
436
|
+
const credentialRequestClient = CredentialRequestClientBuilder.fromCredentialOfferRequest(initiationRequestWithUrl, metadata).build();
|
|
437
|
+
|
|
438
|
+
// In 1 step:
|
|
439
|
+
const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingProof({
|
|
440
|
+
proofInput,
|
|
441
|
+
credentialType: 'OpenBadgeCredential', // Needs to match a type from the Initiate Issance Request!
|
|
442
|
+
format: 'jwt_vc', // Allows us to override the format
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
// Or in 2 steps:
|
|
446
|
+
// const credentialRequest: CredentialRequest = await credentialRequestClient.createCredentialRequest(proofOpts, { format: 'jwt_vc' }) // Allows us to override the format
|
|
447
|
+
// const credentialResponse: CredentialResponse = await credentialRequestClient.acquireCredentialsUsingRequest(credentialRequest)
|
|
448
|
+
```
|
|
449
|
+
|
|
450
|
+
# Helper Functions
|
|
451
|
+
|
|
452
|
+
Several utility functions are available
|
|
453
|
+
|
|
454
|
+
## convertJsonToURI:
|
|
455
|
+
|
|
456
|
+
Converts a Json object or string into an URI:
|
|
457
|
+
|
|
458
|
+
```typescript
|
|
459
|
+
import { convertJsonToURI } from '@sphereon/oid4vci-client';
|
|
460
|
+
|
|
461
|
+
const encodedURI = convertJsonToURI(
|
|
462
|
+
{
|
|
463
|
+
issuer: 'https://server.example.com',
|
|
464
|
+
credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],
|
|
465
|
+
op_state: 'eyJhbGciOiJSU0Et...FYUaBy',
|
|
466
|
+
},
|
|
467
|
+
{
|
|
468
|
+
arrayTypeProperties: ['credential_type'],
|
|
469
|
+
urlTypeProperties: ['issuer', 'credential_type'],
|
|
470
|
+
},
|
|
471
|
+
);
|
|
472
|
+
console.log(encodedURI);
|
|
473
|
+
// issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy
|
|
474
|
+
```
|
|
475
|
+
|
|
476
|
+
## convertURIToJsonObject:
|
|
477
|
+
|
|
478
|
+
Converts a URI into a Json object with URL decoded properties. Allows to provide which potential duplicate keys need to
|
|
479
|
+
be converted into an array.
|
|
480
|
+
|
|
481
|
+
```typescript
|
|
482
|
+
import { convertURIToJsonObject } from '@sphereon/oid4vci-client';
|
|
483
|
+
|
|
484
|
+
const decodedJson = convertURIToJsonObject(
|
|
485
|
+
'issuer=https%3A%2F%2Fserver%2Eexample%2Ecom&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FhealthCard&credential_type=https%3A%2F%2Fdid%2Eexample%2Eorg%2FdriverLicense&op_state=eyJhbGciOiJSU0Et...FYUaBy',
|
|
486
|
+
{
|
|
487
|
+
arrayTypeProperties: ['credential_type'],
|
|
488
|
+
requiredProperties: ['issuer', 'credential_type'],
|
|
489
|
+
},
|
|
490
|
+
);
|
|
491
|
+
console.log(decodedJson);
|
|
492
|
+
// {
|
|
493
|
+
// issuer: 'https://server.example.com',
|
|
494
|
+
// credential_type: ['https://did.example.org/healthCard', 'https://did.example1.org/driverLicense'],
|
|
495
|
+
// op_state: 'eyJhbGciOiJSU0Et...FYUaBy'
|
|
496
|
+
// }
|
|
497
|
+
```
|
|
498
|
+
|
|
499
|
+
## determineSpecVersionFromURI(uri: string): OpenId4VCIVersion
|
|
500
|
+
|
|
501
|
+
```typescript
|
|
502
|
+
const CREDENTIAL_OFFER_URI =
|
|
503
|
+
'openid-credential-offer://?' +
|
|
504
|
+
'credential_offer=%7B%22credential_issuer%22:%22https://credential-issuer.example.com%22,%22credentials%22:%5B%7B%22format%22:%22jwt_vc_json%22,%22types%22:%5B%22VerifiableCredential%22,%22UniversityDegreeCredential%22%5D%7D%5D,%22issuer_state%22:%22eyJhbGciOiJSU0Et...FYUaBy%22%7D';
|
|
505
|
+
|
|
506
|
+
const openId4VCIVersion = determineSpecVersionFromURI(CREDENTIAL_OFFER_URI);
|
|
507
|
+
console.log(openId4VCIVersion);
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* 11
|
|
511
|
+
*/
|
|
512
|
+
```
|