@pagopa/io-react-native-wallet 2.0.0-next.3 → 2.0.0-next.4

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.
Files changed (64) hide show
  1. package/lib/commonjs/credential/issuance/04-complete-user-authorization.js +75 -57
  2. package/lib/commonjs/credential/issuance/04-complete-user-authorization.js.map +1 -1
  3. package/lib/commonjs/credential/issuance/06-obtain-credential.js.map +1 -1
  4. package/lib/commonjs/credential/issuance/README.md +45 -34
  5. package/lib/commonjs/credential/issuance/types.js +1 -0
  6. package/lib/commonjs/credential/issuance/types.js.map +1 -1
  7. package/lib/commonjs/credential/presentation/07-evaluate-dcql-query.js +6 -13
  8. package/lib/commonjs/credential/presentation/07-evaluate-dcql-query.js.map +1 -1
  9. package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js +7 -8
  10. package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js.map +1 -1
  11. package/lib/commonjs/credential/presentation/types.js +1 -1
  12. package/lib/commonjs/credential/presentation/types.js.map +1 -1
  13. package/lib/commonjs/sd-jwt/index.js +6 -1
  14. package/lib/commonjs/sd-jwt/index.js.map +1 -1
  15. package/lib/commonjs/sd-jwt/types.js +25 -9
  16. package/lib/commonjs/sd-jwt/types.js.map +1 -1
  17. package/lib/commonjs/wallet-instance-attestation/types.js +1 -2
  18. package/lib/commonjs/wallet-instance-attestation/types.js.map +1 -1
  19. package/lib/module/credential/issuance/04-complete-user-authorization.js +76 -58
  20. package/lib/module/credential/issuance/04-complete-user-authorization.js.map +1 -1
  21. package/lib/module/credential/issuance/06-obtain-credential.js.map +1 -1
  22. package/lib/module/credential/issuance/README.md +45 -34
  23. package/lib/module/credential/issuance/types.js +1 -0
  24. package/lib/module/credential/issuance/types.js.map +1 -1
  25. package/lib/module/credential/presentation/07-evaluate-dcql-query.js +6 -13
  26. package/lib/module/credential/presentation/07-evaluate-dcql-query.js.map +1 -1
  27. package/lib/module/credential/presentation/07-evaluate-input-descriptor.js +7 -8
  28. package/lib/module/credential/presentation/07-evaluate-input-descriptor.js.map +1 -1
  29. package/lib/module/credential/presentation/types.js +1 -1
  30. package/lib/module/credential/presentation/types.js.map +1 -1
  31. package/lib/module/sd-jwt/index.js +6 -1
  32. package/lib/module/sd-jwt/index.js.map +1 -1
  33. package/lib/module/sd-jwt/types.js +25 -9
  34. package/lib/module/sd-jwt/types.js.map +1 -1
  35. package/lib/module/wallet-instance-attestation/types.js +1 -2
  36. package/lib/module/wallet-instance-attestation/types.js.map +1 -1
  37. package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts +7 -14
  38. package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts.map +1 -1
  39. package/lib/typescript/credential/issuance/06-obtain-credential.d.ts.map +1 -1
  40. package/lib/typescript/credential/issuance/types.d.ts +3 -0
  41. package/lib/typescript/credential/issuance/types.d.ts.map +1 -1
  42. package/lib/typescript/credential/presentation/01-start-flow.d.ts +2 -2
  43. package/lib/typescript/credential/presentation/07-evaluate-dcql-query.d.ts +4 -3
  44. package/lib/typescript/credential/presentation/07-evaluate-dcql-query.d.ts.map +1 -1
  45. package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts +9 -5
  46. package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts.map +1 -1
  47. package/lib/typescript/credential/presentation/types.d.ts +3 -4
  48. package/lib/typescript/credential/presentation/types.d.ts.map +1 -1
  49. package/lib/typescript/credential/status/types.d.ts +4 -4
  50. package/lib/typescript/sd-jwt/index.d.ts +68 -40
  51. package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
  52. package/lib/typescript/sd-jwt/types.d.ts +97 -46
  53. package/lib/typescript/sd-jwt/types.d.ts.map +1 -1
  54. package/package.json +1 -1
  55. package/src/credential/issuance/04-complete-user-authorization.ts +79 -85
  56. package/src/credential/issuance/06-obtain-credential.ts +4 -1
  57. package/src/credential/issuance/README.md +45 -34
  58. package/src/credential/issuance/types.ts +1 -0
  59. package/src/credential/presentation/07-evaluate-dcql-query.ts +16 -17
  60. package/src/credential/presentation/07-evaluate-input-descriptor.ts +16 -13
  61. package/src/credential/presentation/types.ts +1 -2
  62. package/src/sd-jwt/index.ts +5 -1
  63. package/src/sd-jwt/types.ts +24 -10
  64. package/src/wallet-instance-attestation/types.ts +1 -1
@@ -29,20 +29,33 @@ export type DisclosureWithEncoded = {
29
29
  decoded: Disclosure;
30
30
  encoded: string;
31
31
  };
32
+ /**
33
+ * Type for a Verifiable Credential in SD-JWT format.
34
+ * It supports both the older and the new data model for backward compatibility.
35
+ */
32
36
  export type SdJwt4VC = z.infer<typeof SdJwt4VC>;
33
37
  export declare const SdJwt4VC: z.ZodObject<{
34
38
  header: z.ZodObject<{
35
- typ: z.ZodLiteral<"dc+sd-jwt">;
39
+ typ: z.ZodEnum<["vc+sd-jwt", "dc+sd-jwt"]>;
36
40
  alg: z.ZodString;
37
- kid: z.ZodOptional<z.ZodString>;
41
+ kid: z.ZodString;
42
+ trust_chain: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
43
+ x5c: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
44
+ vctm: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
38
45
  }, "strip", z.ZodTypeAny, {
39
46
  alg: string;
40
- typ: "dc+sd-jwt";
41
- kid?: string | undefined;
47
+ kid: string;
48
+ typ: "vc+sd-jwt" | "dc+sd-jwt";
49
+ trust_chain?: string[] | undefined;
50
+ x5c?: string[] | undefined;
51
+ vctm?: string[] | undefined;
42
52
  }, {
43
53
  alg: string;
44
- typ: "dc+sd-jwt";
45
- kid?: string | undefined;
54
+ kid: string;
55
+ typ: "vc+sd-jwt" | "dc+sd-jwt";
56
+ trust_chain?: string[] | undefined;
57
+ x5c?: string[] | undefined;
58
+ vctm?: string[] | undefined;
46
59
  }>;
47
60
  payload: z.ZodIntersection<z.ZodObject<{
48
61
  iss: z.ZodString;
@@ -50,7 +63,7 @@ export declare const SdJwt4VC: z.ZodObject<{
50
63
  iat: z.ZodOptional<z.ZodNumber>;
51
64
  exp: z.ZodNumber;
52
65
  _sd_alg: z.ZodLiteral<"sha-256">;
53
- status: z.ZodObject<{
66
+ status: z.ZodOptional<z.ZodUnion<[z.ZodObject<{
54
67
  status_assertion: z.ZodObject<{
55
68
  credential_hash_alg: z.ZodLiteral<"sha-256">;
56
69
  }, "strip", z.ZodTypeAny, {
@@ -66,7 +79,23 @@ export declare const SdJwt4VC: z.ZodObject<{
66
79
  status_assertion: {
67
80
  credential_hash_alg: "sha-256";
68
81
  };
69
- }>;
82
+ }>, z.ZodObject<{
83
+ status_attestation: z.ZodObject<{
84
+ credential_hash_alg: z.ZodLiteral<"sha-256">;
85
+ }, "strip", z.ZodTypeAny, {
86
+ credential_hash_alg: "sha-256";
87
+ }, {
88
+ credential_hash_alg: "sha-256";
89
+ }>;
90
+ }, "strip", z.ZodTypeAny, {
91
+ status_attestation: {
92
+ credential_hash_alg: "sha-256";
93
+ };
94
+ }, {
95
+ status_attestation: {
96
+ credential_hash_alg: "sha-256";
97
+ };
98
+ }>]>>;
70
99
  cnf: z.ZodObject<{
71
100
  jwk: z.ZodObject<{
72
101
  alg: z.ZodOptional<z.ZodString>;
@@ -190,16 +219,11 @@ export declare const SdJwt4VC: z.ZodObject<{
190
219
  };
191
220
  }>;
192
221
  vct: z.ZodString;
193
- "vct#integrity": z.ZodString;
194
- issuing_authority: z.ZodString;
195
- issuing_country: z.ZodString;
222
+ "vct#integrity": z.ZodOptional<z.ZodString>;
223
+ issuing_authority: z.ZodOptional<z.ZodString>;
224
+ issuing_country: z.ZodOptional<z.ZodString>;
196
225
  }, "strip", z.ZodTypeAny, {
197
226
  iss: string;
198
- status: {
199
- status_assertion: {
200
- credential_hash_alg: "sha-256";
201
- };
202
- };
203
227
  sub: string;
204
228
  exp: number;
205
229
  _sd_alg: "sha-256";
@@ -230,17 +254,21 @@ export declare const SdJwt4VC: z.ZodObject<{
230
254
  };
231
255
  };
232
256
  vct: string;
233
- "vct#integrity": string;
234
- issuing_authority: string;
235
- issuing_country: string;
236
257
  iat?: number | undefined;
237
- }, {
238
- iss: string;
239
- status: {
258
+ status?: {
240
259
  status_assertion: {
241
260
  credential_hash_alg: "sha-256";
242
261
  };
243
- };
262
+ } | {
263
+ status_attestation: {
264
+ credential_hash_alg: "sha-256";
265
+ };
266
+ } | undefined;
267
+ "vct#integrity"?: string | undefined;
268
+ issuing_authority?: string | undefined;
269
+ issuing_country?: string | undefined;
270
+ }, {
271
+ iss: string;
244
272
  sub: string;
245
273
  exp: number;
246
274
  _sd_alg: "sha-256";
@@ -271,10 +299,19 @@ export declare const SdJwt4VC: z.ZodObject<{
271
299
  };
272
300
  };
273
301
  vct: string;
274
- "vct#integrity": string;
275
- issuing_authority: string;
276
- issuing_country: string;
277
302
  iat?: number | undefined;
303
+ status?: {
304
+ status_assertion: {
305
+ credential_hash_alg: "sha-256";
306
+ };
307
+ } | {
308
+ status_attestation: {
309
+ credential_hash_alg: "sha-256";
310
+ };
311
+ } | undefined;
312
+ "vct#integrity"?: string | undefined;
313
+ issuing_authority?: string | undefined;
314
+ issuing_country?: string | undefined;
278
315
  }>, z.ZodObject<{
279
316
  _sd: z.ZodArray<z.ZodString, "many">;
280
317
  }, "strip", z.ZodTypeAny, {
@@ -285,16 +322,14 @@ export declare const SdJwt4VC: z.ZodObject<{
285
322
  }, "strip", z.ZodTypeAny, {
286
323
  header: {
287
324
  alg: string;
288
- typ: "dc+sd-jwt";
289
- kid?: string | undefined;
325
+ kid: string;
326
+ typ: "vc+sd-jwt" | "dc+sd-jwt";
327
+ trust_chain?: string[] | undefined;
328
+ x5c?: string[] | undefined;
329
+ vctm?: string[] | undefined;
290
330
  };
291
331
  payload: {
292
332
  iss: string;
293
- status: {
294
- status_assertion: {
295
- credential_hash_alg: "sha-256";
296
- };
297
- };
298
333
  sub: string;
299
334
  exp: number;
300
335
  _sd_alg: "sha-256";
@@ -325,26 +360,33 @@ export declare const SdJwt4VC: z.ZodObject<{
325
360
  };
326
361
  };
327
362
  vct: string;
328
- "vct#integrity": string;
329
- issuing_authority: string;
330
- issuing_country: string;
331
363
  iat?: number | undefined;
364
+ status?: {
365
+ status_assertion: {
366
+ credential_hash_alg: "sha-256";
367
+ };
368
+ } | {
369
+ status_attestation: {
370
+ credential_hash_alg: "sha-256";
371
+ };
372
+ } | undefined;
373
+ "vct#integrity"?: string | undefined;
374
+ issuing_authority?: string | undefined;
375
+ issuing_country?: string | undefined;
332
376
  } & {
333
377
  _sd: string[];
334
378
  };
335
379
  }, {
336
380
  header: {
337
381
  alg: string;
338
- typ: "dc+sd-jwt";
339
- kid?: string | undefined;
382
+ kid: string;
383
+ typ: "vc+sd-jwt" | "dc+sd-jwt";
384
+ trust_chain?: string[] | undefined;
385
+ x5c?: string[] | undefined;
386
+ vctm?: string[] | undefined;
340
387
  };
341
388
  payload: {
342
389
  iss: string;
343
- status: {
344
- status_assertion: {
345
- credential_hash_alg: "sha-256";
346
- };
347
- };
348
390
  sub: string;
349
391
  exp: number;
350
392
  _sd_alg: "sha-256";
@@ -375,10 +417,19 @@ export declare const SdJwt4VC: z.ZodObject<{
375
417
  };
376
418
  };
377
419
  vct: string;
378
- "vct#integrity": string;
379
- issuing_authority: string;
380
- issuing_country: string;
381
420
  iat?: number | undefined;
421
+ status?: {
422
+ status_assertion: {
423
+ credential_hash_alg: "sha-256";
424
+ };
425
+ } | {
426
+ status_attestation: {
427
+ credential_hash_alg: "sha-256";
428
+ };
429
+ } | undefined;
430
+ "vct#integrity"?: string | undefined;
431
+ issuing_authority?: string | undefined;
432
+ issuing_country?: string | undefined;
382
433
  } & {
383
434
  _sd: string[];
384
435
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/sd-jwt/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,QAAQ,aAAuC,CAAC;AAC7D,MAAM,MAAM,QAAQ,GAAG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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkCnB,CAAC;AAEH;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AACxD,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAevB,CAAC;AAEH;;;;GAIG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AACxD,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAcvB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pagopa/io-react-native-wallet",
3
- "version": "2.0.0-next.3",
3
+ "version": "2.0.0-next.4",
4
4
  "description": "Provide data structures, helpers and API for IO Wallet",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -10,16 +10,16 @@ import { IssuerResponseError, ValidationFailed } from "../../utils/errors";
10
10
  import type { EvaluateIssuerTrust } from "./02-evaluate-issuer-trust";
11
11
  import {
12
12
  decode,
13
- encodeBase64,
14
13
  SignJWT,
15
14
  type CryptoContext,
16
15
  } from "@pagopa/io-react-native-jwt";
17
- import { RequestObject } from "../presentation/types";
18
- import { v4 as uuidv4 } from "uuid";
16
+ import { type RemotePresentation, RequestObject } from "../presentation/types";
19
17
  import { ResponseUriResultShape } from "./types";
20
18
  import { getJwtFromFormPost } from "../../utils/decoder";
21
19
  import { AuthorizationError, AuthorizationIdpError } from "./errors";
22
20
  import { LogLevel, Logger } from "../../utils/logging";
21
+ import { Presentation } from "..";
22
+ import type { DcqlQuery } from "dcql";
23
23
 
24
24
  /**
25
25
  * The interface of the phase to complete User authorization via strong identification when the response mode is "query" and the request credential is a PersonIdentificationData.
@@ -30,11 +30,10 @@ export type CompleteUserAuthorizationWithQueryMode = (
30
30
 
31
31
  export type CompleteUserAuthorizationWithFormPostJwtMode = (
32
32
  requestObject: Out<GetRequestedCredentialToBePresented>,
33
+ pid: string,
33
34
  context: {
34
35
  wiaCryptoContext: CryptoContext;
35
36
  pidCryptoContext: CryptoContext;
36
- pid: string;
37
- walletInstanceAttestation: string;
38
37
  appFetch?: GlobalFetch["fetch"];
39
38
  }
40
39
  ) => Promise<AuthorizationResult>;
@@ -158,103 +157,54 @@ export const getRequestedCredentialToBePresented: GetRequestedCredentialToBePres
158
157
  };
159
158
 
160
159
  /**
161
- * WARNING: This function must be called after {@link startUserAuthorization}. The next function to be called is {@link completeUserAuthorizationWithFormPostJwtMode}.
160
+ * WARNING: This function must be called after {@link getRequestedCredentialToBePresented}. The next function to be called is {@link authorizeAccess}.
162
161
  * The interface of the phase to complete User authorization via presentation of existing credentials when the response mode is "form_post.jwt".
163
- * It is used as a first step to complete the user authorization by obtaining the requested credential to be presented from the authorization server.
164
- * The information is obtained by performing a GET request to the authorization endpoint with request_uri and client_id parameters.
165
- * @param issuerRequestUri the URI of the issuer where the request is sent
166
- * @param clientId Identifies the current client across all the requests of the issuing flow returned by {@link startUserAuthorization}
167
- * @param issuerConf The issuer configuration returned by {@link evaluateIssuerTrust}
168
- * @param context.walletInstanceAccestation the Wallet Instance's attestation to be presented
169
- * @param context.pid the PID to be presented
170
- * @param context.wiaCryptoContext The Wallet Instance's crypto context associated with the walletInstanceAttestation parameter
171
- * @param context.pidCryptoContext The PID crypto context associated with the pid parameter
172
- * @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
162
+ * The information is obtained by performing a POST request to the endpoint received in the response_uri field of the requestObject, where the Authorization Response payload is posted.
163
+ * Following this,the redirect_uri from the response is used to obtain the final authorization response.
164
+ * @param requestObject - The request object containing the necessary parameters for authorization.
165
+ * @param pid The `PID` that must be presented for the issuance of credentials.
166
+ * @param appFetch (optional) fetch api implementation. Default: built-in fetch
173
167
  * @throws {ValidationFailed} if an error while validating the response
174
168
  * @returns the authorization response which contains code, state and iss
175
169
  */
176
170
  export const completeUserAuthorizationWithFormPostJwtMode: CompleteUserAuthorizationWithFormPostJwtMode =
177
- async (requestObject, ctx) => {
171
+ async (
172
+ requestObject,
173
+ pid,
174
+ { wiaCryptoContext, pidCryptoContext, appFetch = fetch }
175
+ ) => {
178
176
  Logger.log(
179
177
  LogLevel.DEBUG,
180
178
  `The requeste credential is not a PersonIdentificationData, completing the user authorization with form_post.jwt mode`
181
179
  );
182
180
 
183
- const {
184
- wiaCryptoContext,
185
- pidCryptoContext,
186
- pid,
187
- walletInstanceAttestation,
188
- appFetch = fetch,
189
- } = ctx;
181
+ if (!requestObject.dcql_query) {
182
+ throw new Error("Invalid request object");
183
+ }
190
184
 
191
- const wiaWpToken = await new SignJWT(wiaCryptoContext)
192
- .setProtectedHeader({
193
- alg: "ES256",
194
- typ: "JWT",
195
- })
196
- .setPayload({
197
- vp: walletInstanceAttestation,
198
- jti: uuidv4().toString(),
199
- nonce: requestObject.nonce,
200
- })
201
- .setIssuedAt()
202
- .setExpirationTime("5m")
203
- .setAudience(requestObject.response_uri)
204
- .sign();
185
+ const dcqlQueryResult = Presentation.evaluateDcqlQuery(
186
+ [[pidCryptoContext, pid]],
187
+ requestObject.dcql_query as DcqlQuery
188
+ );
205
189
 
206
- const pidWpToken = await new SignJWT(pidCryptoContext)
207
- .setProtectedHeader({
208
- alg: "ES256",
209
- typ: "JWT",
190
+ const credentialsToPresent = dcqlQueryResult.map(
191
+ ({ requiredDisclosures, ...rest }) => ({
192
+ ...rest,
193
+ requestedClaims: requiredDisclosures.map(([, claimName]) => claimName),
210
194
  })
211
- .setPayload({
212
- vp: pid,
213
- jti: uuidv4().toString(),
214
- nonce: requestObject.nonce,
215
- })
216
- .setIssuedAt()
217
- .setExpirationTime("5m")
218
- .setAudience(requestObject.response_uri)
219
- .sign();
220
-
221
- Logger.log(
222
- LogLevel.DEBUG,
223
- `Wallet instance attestation JWT token: ${wiaWpToken}`
224
195
  );
225
196
 
226
- /* The path parameter refers to the vp_token variable of the authzResponsePayload and must point to the plain credential which
227
- * is cointaned in the `vp` property of the signed jwt token payload
228
- */
229
- const presentationSubmission = {
230
- definition_id: `${uuidv4()}`,
231
- id: `${uuidv4()}`,
232
- descriptor_map: [
233
- {
234
- id: "PersonIdentificationData",
235
- path: "$.vp_token[0].vp",
236
- format: "vc+sd-jwt",
237
- },
238
- {
239
- id: "WalletAttestation",
240
- path: "$.vp_token[1].vp",
241
- format: "jwt",
242
- },
243
- ],
244
- };
245
-
246
- Logger.log(
247
- LogLevel.DEBUG,
248
- `Presentation submission: ${JSON.stringify(presentationSubmission)}`
197
+ const remotePresentations = await Presentation.prepareRemotePresentations(
198
+ credentialsToPresent,
199
+ requestObject.nonce,
200
+ requestObject.client_id
249
201
  );
250
202
 
251
- const authzResponsePayload = encodeBase64(
252
- JSON.stringify({
253
- state: requestObject.state,
254
- presentation_submission: presentationSubmission,
255
- vp_token: [pidWpToken, wiaWpToken],
256
- })
257
- );
203
+ const authzResponsePayload = await createAuthzResponsePayload({
204
+ state: requestObject.state,
205
+ remotePresentations,
206
+ wiaCryptoContext,
207
+ });
258
208
 
259
209
  Logger.log(
260
210
  LogLevel.DEBUG,
@@ -334,3 +284,47 @@ export const parseAuthorizationResponse = (
334
284
  }
335
285
  return authResParsed.data;
336
286
  };
287
+
288
+ /**
289
+ * Creates the authorization response payload to be sent.
290
+ * This payload includes the state and the VP tokens for the presented credentials.
291
+ * The payload is encoded in Base64.
292
+ * @param state - The state parameter from the request object (optional).
293
+ * @param remotePresentations - An array of remote presentations containing credential IDs and their corresponding VP tokens.
294
+ * @returns The Base64 encoded authorization response payload.
295
+ */
296
+ const createAuthzResponsePayload = async ({
297
+ state,
298
+ remotePresentations,
299
+ wiaCryptoContext,
300
+ }: {
301
+ state?: string;
302
+ remotePresentations: RemotePresentation[];
303
+ wiaCryptoContext: CryptoContext;
304
+ }): Promise<string> => {
305
+ const { kid } = await wiaCryptoContext.getPublicKey();
306
+
307
+ return new SignJWT(wiaCryptoContext)
308
+ .setProtectedHeader({
309
+ typ: "jwt",
310
+ kid,
311
+ })
312
+ .setPayload({
313
+ /**
314
+ * TODO [SIW-2264]: `state` coming from `requestObject` is marked as `optional`
315
+ * At the moment, it is not entirely clear whether this value can indeed be omitted
316
+ * and, if so, what the consequences of its absence might be.
317
+ */
318
+ ...(state ? { state } : {}),
319
+ vp_token: remotePresentations.reduce(
320
+ (vp_token, { credentialId, vpToken }) => ({
321
+ ...vp_token,
322
+ [credentialId]: vpToken,
323
+ }),
324
+ {}
325
+ ),
326
+ })
327
+ .setIssuedAt()
328
+ .setExpirationTime("1h")
329
+ .sign();
330
+ };
@@ -33,7 +33,10 @@ export type ObtainCredential = (
33
33
  appFetch?: GlobalFetch["fetch"];
34
34
  },
35
35
  operationType?: "reissuing"
36
- ) => Promise<{ credential: string; format: string }>;
36
+ ) => Promise<{
37
+ credential: string;
38
+ format: string;
39
+ }>;
37
40
 
38
41
  export const createNonceProof = async (
39
42
  nonce: string,
@@ -72,8 +72,6 @@ The expected result from the authentication process is in `form_post.jwt` format
72
72
  <summary>Credential issuance flow</summary>
73
73
 
74
74
  ```ts
75
- // TODO: [SIW-2209] update documentation in PR #219
76
-
77
75
  // Retrieve the integrity key tag from the store and create its context
78
76
  const integrityKeyTag = "example"; // Let's assume this is the key tag used to create the wallet instance
79
77
  const integrityContext = getIntegrityContext(integrityKeyTag);
@@ -98,17 +96,13 @@ const walletInstanceAttestation =
98
96
  appFetch,
99
97
  });
100
98
 
101
- const credentialType = "someCredential"; // Let's assume this is the credential type
102
-
103
- const eid = {
99
+ const pid = {
104
100
  credential: "example",
105
101
  parsedCredential: "example"
106
102
  keyTag: "example";
107
- credentialType: "eid";
103
+ credentialType: "PersonIdentificationData";
108
104
  };
109
105
 
110
- const eidCryptoContext = createCryptoContextFor(eid.keyTag);
111
-
112
106
  // Create credential crypto context
113
107
  const credentialKeyTag = uuidv4().toString();
114
108
  await generate(credentialKeyTag); // Let's assume this function generates a new hardware-backed key pair
@@ -117,22 +111,26 @@ const credentialCryptoContext = createCryptoContextFor(credentialKeyTag);
117
111
  // Start the issuance flow
118
112
  const startFlow: Credential.Issuance.StartFlow = () => ({
119
113
  issuerUrl: WALLET_EAA_PROVIDER_BASE_URL,
120
- credentialType,
114
+ credentialId: "someCredentialId",
121
115
  });
122
116
 
123
- const { issuerUrl } = startFlow();
117
+ const { issuerUrl, credentialId } = startFlow();
124
118
 
125
119
  // Evaluate issuer trust
126
120
  const { issuerConf } = await Credential.Issuance.evaluateIssuerTrust(issuerUrl);
127
121
 
128
122
  // Start user authorization
129
- const { issuerRequestUri, clientId, codeVerifier, credentialDefinition } =
130
- await Credential.Issuance.startUserAuthorization(issuerConf, credentialType, {
131
- walletInstanceAttestation,
132
- redirectUri,
133
- wiaCryptoContext,
134
- appFetch,
135
- });
123
+ const { issuerRequestUri, clientId, codeVerifier } =
124
+ await Credential.Issuance.startUserAuthorization(
125
+ issuerConf,
126
+ [credentialId],
127
+ {
128
+ walletInstanceAttestation,
129
+ redirectUri: REDIRECT_URI,
130
+ wiaCryptoContext,
131
+ appFetch,
132
+ }
133
+ );
136
134
 
137
135
  const requestObject =
138
136
  await Credential.Issuance.getRequestedCredentialToBePresented(
@@ -142,13 +140,12 @@ const requestObject =
142
140
  appFetch
143
141
  );
144
142
 
145
- // The app here should ask the user to confirm the required data contained in the requestObject
146
-
147
143
  // Complete the user authorization via form_post.jwt mode
148
144
  const { code } =
149
145
  await Credential.Issuance.completeUserAuthorizationWithFormPostJwtMode(
150
146
  requestObject,
151
- { wiaCryptoContext, pidCryptoContext, pid, walletInstanceAttestation }
147
+ pid.credential,
148
+ { wiaCryptoContext, pidCryptoContext: createCryptoContextFor(pid.keyTag) }
152
149
  );
153
150
 
154
151
  // Generate the DPoP context which will be used for the whole issuance flow
@@ -159,7 +156,7 @@ const { accessToken } = await Credential.Issuance.authorizeAccess(
159
156
  issuerConf,
160
157
  code,
161
158
  clientId,
162
- redirectUri,
159
+ redirectUri: REDIRECT_URI,
163
160
  codeVerifier,
164
161
  {
165
162
  walletInstanceAttestation,
@@ -169,12 +166,19 @@ const { accessToken } = await Credential.Issuance.authorizeAccess(
169
166
  }
170
167
  );
171
168
 
172
- // Obtain the credential
173
- const { credential, format } = await Credential.Issuance.obtainCredential(
169
+ // For simplicity, in this example flow we work on a single credential.
170
+ const { credential_configuration_id, credential_identifiers } =
171
+ accessToken.authorization_details[0]!;
172
+
173
+ // Obtain the credential
174
+ const { credential } = await Credential.Issuance.obtainCredential(
174
175
  issuerConf,
175
176
  accessToken,
176
177
  clientId,
177
- credentialDefinition,
178
+ {
179
+ credential_configuration_id,
180
+ credential_identifier: credential_identifiers[0],
181
+ },
178
182
  {
179
183
  credentialCryptoContext,
180
184
  dPopCryptoContext,
@@ -186,22 +190,29 @@ const { credential, format } = await Credential.Issuance.obtainCredential(
186
190
  * Parse and verify the credential. The ignoreMissingAttributes flag must be set to false or omitted in production.
187
191
  * WARNING: includeUndefinedAttributes should not be set to true in production in order to get only claims explicitly declared by the issuer.
188
192
  */
189
- const { parsedCredential } = await Credential.Issuance.verifyAndParseCredential(
190
- issuerConf,
191
- credential,
192
- format,
193
- {
194
- credentialCryptoContext,
195
- ignoreMissingAttributes: true,
196
- includeUndefinedAttributes: false
197
- }
198
- );
193
+ const { parsedCredential } =
194
+ await Credential.Issuance.verifyAndParseCredential(
195
+ issuerConf,
196
+ credential,
197
+ credential_configuration_id,
198
+ {
199
+ credentialCryptoContext,
200
+ ignoreMissingAttributes: true,
201
+ includeUndefinedAttributes: false
202
+ }
203
+ );
204
+
205
+ const credentialType =
206
+ issuerConf.openid_credential_issuer.credential_configurations_supported[
207
+ credential_configuration_id
208
+ ].scope;
199
209
 
200
210
  return {
201
211
  parsedCredential,
202
212
  credential,
203
213
  keyTag: credentialKeyTag,
204
214
  credentialType,
215
+ credentialConfigurationId: credential_configuration_id,
205
216
  };
206
217
  ```
207
218
 
@@ -11,6 +11,7 @@ export type TokenResponse = z.infer<typeof TokenResponse>;
11
11
 
12
12
  export const TokenResponse = z.object({
13
13
  access_token: z.string(),
14
+ refresh_token: z.string().optional(),
14
15
  authorization_details: z.array(AuthorizationDetail),
15
16
  expires_in: z.number(),
16
17
  token_type: z.string(),