@pagopa/io-react-native-wallet 0.12.0 → 0.13.1

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 (205) hide show
  1. package/lib/commonjs/client/generated/wallet-provider.js +22 -22
  2. package/lib/commonjs/client/generated/wallet-provider.js.map +1 -1
  3. package/lib/commonjs/client/index.js +1 -2
  4. package/lib/commonjs/client/index.js.map +1 -1
  5. package/lib/commonjs/credential/issuance/02-evaluate-issuer-trust.js +2 -1
  6. package/lib/commonjs/credential/issuance/02-evaluate-issuer-trust.js.map +1 -1
  7. package/lib/commonjs/credential/issuance/03-start-credential-issuance.js +287 -0
  8. package/lib/commonjs/credential/issuance/03-start-credential-issuance.js.map +1 -0
  9. package/lib/commonjs/credential/issuance/03-start-user-authorization.js +55 -82
  10. package/lib/commonjs/credential/issuance/03-start-user-authorization.js.map +1 -1
  11. package/lib/commonjs/credential/issuance/04-complete-user-authorization.js +88 -0
  12. package/lib/commonjs/credential/issuance/04-complete-user-authorization.js.map +1 -1
  13. package/lib/commonjs/credential/issuance/05-authorize-access.js +55 -32
  14. package/lib/commonjs/credential/issuance/05-authorize-access.js.map +1 -1
  15. package/lib/commonjs/credential/issuance/06-obtain-credential.js +50 -77
  16. package/lib/commonjs/credential/issuance/06-obtain-credential.js.map +1 -1
  17. package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js +21 -44
  18. package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
  19. package/lib/commonjs/credential/issuance/index.js +7 -0
  20. package/lib/commonjs/credential/issuance/index.js.map +1 -1
  21. package/lib/commonjs/credential/issuance/types.js +28 -0
  22. package/lib/commonjs/credential/issuance/types.js.map +1 -0
  23. package/lib/commonjs/index.js.map +1 -1
  24. package/lib/commonjs/pid/sd-jwt/converters.js +5 -9
  25. package/lib/commonjs/pid/sd-jwt/converters.js.map +1 -1
  26. package/lib/commonjs/pid/sd-jwt/types.js +3 -3
  27. package/lib/commonjs/pid/sd-jwt/types.js.map +1 -1
  28. package/lib/commonjs/sd-jwt/__test__/converters.test.js +1 -1
  29. package/lib/commonjs/sd-jwt/__test__/converters.test.js.map +1 -1
  30. package/lib/commonjs/sd-jwt/__test__/index.test.js +30 -43
  31. package/lib/commonjs/sd-jwt/__test__/index.test.js.map +1 -1
  32. package/lib/commonjs/sd-jwt/__test__/types.test.js +16 -24
  33. package/lib/commonjs/sd-jwt/__test__/types.test.js.map +1 -1
  34. package/lib/commonjs/sd-jwt/index.js +3 -9
  35. package/lib/commonjs/sd-jwt/index.js.map +1 -1
  36. package/lib/commonjs/sd-jwt/types.js +11 -16
  37. package/lib/commonjs/sd-jwt/types.js.map +1 -1
  38. package/lib/commonjs/trust/types.js +70 -29
  39. package/lib/commonjs/trust/types.js.map +1 -1
  40. package/lib/commonjs/utils/auth.js +44 -0
  41. package/lib/commonjs/utils/auth.js.map +1 -0
  42. package/lib/commonjs/utils/errors.js +77 -2
  43. package/lib/commonjs/utils/errors.js.map +1 -1
  44. package/lib/commonjs/utils/misc.js +34 -1
  45. package/lib/commonjs/utils/misc.js.map +1 -1
  46. package/lib/commonjs/utils/par.js +23 -15
  47. package/lib/commonjs/utils/par.js.map +1 -1
  48. package/lib/commonjs/utils/pop.js +33 -0
  49. package/lib/commonjs/utils/pop.js.map +1 -0
  50. package/lib/commonjs/wallet-instance-attestation/issuing.js +17 -2
  51. package/lib/commonjs/wallet-instance-attestation/issuing.js.map +1 -1
  52. package/lib/commonjs/wallet-instance-attestation/types.js +7 -7
  53. package/lib/commonjs/wallet-instance-attestation/types.js.map +1 -1
  54. package/lib/module/client/generated/wallet-provider.js +16 -19
  55. package/lib/module/client/generated/wallet-provider.js.map +1 -1
  56. package/lib/module/client/index.js +1 -2
  57. package/lib/module/client/index.js.map +1 -1
  58. package/lib/module/credential/issuance/02-evaluate-issuer-trust.js +2 -1
  59. package/lib/module/credential/issuance/02-evaluate-issuer-trust.js.map +1 -1
  60. package/lib/module/credential/issuance/03-start-credential-issuance.js +276 -0
  61. package/lib/module/credential/issuance/03-start-credential-issuance.js.map +1 -0
  62. package/lib/module/credential/issuance/03-start-user-authorization.js +55 -79
  63. package/lib/module/credential/issuance/03-start-user-authorization.js.map +1 -1
  64. package/lib/module/credential/issuance/04-complete-user-authorization.js +85 -1
  65. package/lib/module/credential/issuance/04-complete-user-authorization.js.map +1 -1
  66. package/lib/module/credential/issuance/05-authorize-access.js +53 -32
  67. package/lib/module/credential/issuance/05-authorize-access.js.map +1 -1
  68. package/lib/module/credential/issuance/06-obtain-credential.js +49 -74
  69. package/lib/module/credential/issuance/06-obtain-credential.js.map +1 -1
  70. package/lib/module/credential/issuance/07-verify-and-parse-credential.js +21 -44
  71. package/lib/module/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
  72. package/lib/module/credential/issuance/index.js +2 -1
  73. package/lib/module/credential/issuance/index.js.map +1 -1
  74. package/lib/module/credential/issuance/types.js +18 -0
  75. package/lib/module/credential/issuance/types.js.map +1 -0
  76. package/lib/module/index.js.map +1 -1
  77. package/lib/module/pid/sd-jwt/converters.js +5 -9
  78. package/lib/module/pid/sd-jwt/converters.js.map +1 -1
  79. package/lib/module/pid/sd-jwt/types.js +3 -3
  80. package/lib/module/pid/sd-jwt/types.js.map +1 -1
  81. package/lib/module/sd-jwt/__test__/converters.test.js +1 -1
  82. package/lib/module/sd-jwt/__test__/converters.test.js.map +1 -1
  83. package/lib/module/sd-jwt/__test__/index.test.js +30 -43
  84. package/lib/module/sd-jwt/__test__/index.test.js.map +1 -1
  85. package/lib/module/sd-jwt/__test__/types.test.js +16 -24
  86. package/lib/module/sd-jwt/__test__/types.test.js.map +1 -1
  87. package/lib/module/sd-jwt/index.js +3 -9
  88. package/lib/module/sd-jwt/index.js.map +1 -1
  89. package/lib/module/sd-jwt/types.js +11 -16
  90. package/lib/module/sd-jwt/types.js.map +1 -1
  91. package/lib/module/sd-jwt/verifier.js.map +1 -1
  92. package/lib/module/trust/types.js +70 -29
  93. package/lib/module/trust/types.js.map +1 -1
  94. package/lib/module/utils/auth.js +35 -0
  95. package/lib/module/utils/auth.js.map +1 -0
  96. package/lib/module/utils/errors.js +71 -0
  97. package/lib/module/utils/errors.js.map +1 -1
  98. package/lib/module/utils/misc.js +31 -0
  99. package/lib/module/utils/misc.js.map +1 -1
  100. package/lib/module/utils/par.js +24 -16
  101. package/lib/module/utils/par.js.map +1 -1
  102. package/lib/module/utils/pop.js +24 -0
  103. package/lib/module/utils/pop.js.map +1 -0
  104. package/lib/module/wallet-instance-attestation/issuing.js +17 -2
  105. package/lib/module/wallet-instance-attestation/issuing.js.map +1 -1
  106. package/lib/module/wallet-instance-attestation/types.js +7 -7
  107. package/lib/module/wallet-instance-attestation/types.js.map +1 -1
  108. package/lib/typescript/client/generated/wallet-provider.d.ts +35 -13
  109. package/lib/typescript/client/generated/wallet-provider.d.ts.map +1 -1
  110. package/lib/typescript/client/index.d.ts.map +1 -1
  111. package/lib/typescript/credential/issuance/01-start-flow.d.ts +1 -0
  112. package/lib/typescript/credential/issuance/01-start-flow.d.ts.map +1 -1
  113. package/lib/typescript/credential/issuance/02-evaluate-issuer-trust.d.ts +2 -1
  114. package/lib/typescript/credential/issuance/02-evaluate-issuer-trust.d.ts.map +1 -1
  115. package/lib/typescript/credential/issuance/03-start-credential-issuance.d.ts +41 -0
  116. package/lib/typescript/credential/issuance/03-start-credential-issuance.d.ts.map +1 -0
  117. package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts +22 -17
  118. package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts.map +1 -1
  119. package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts +24 -12
  120. package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts.map +1 -1
  121. package/lib/typescript/credential/issuance/05-authorize-access.d.ts +21 -15
  122. package/lib/typescript/credential/issuance/05-authorize-access.d.ts.map +1 -1
  123. package/lib/typescript/credential/issuance/06-obtain-credential.d.ts +19 -26
  124. package/lib/typescript/credential/issuance/06-obtain-credential.d.ts.map +1 -1
  125. package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts +10 -15
  126. package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts.map +1 -1
  127. package/lib/typescript/credential/issuance/index.d.ts +3 -4
  128. package/lib/typescript/credential/issuance/index.d.ts.map +1 -1
  129. package/lib/typescript/credential/issuance/types.d.ts +63 -0
  130. package/lib/typescript/credential/issuance/types.d.ts.map +1 -0
  131. package/lib/typescript/credential/presentation/types.d.ts +6 -6
  132. package/lib/typescript/index.d.ts +2 -1
  133. package/lib/typescript/index.d.ts.map +1 -1
  134. package/lib/typescript/pid/sd-jwt/converters.d.ts.map +1 -1
  135. package/lib/typescript/pid/sd-jwt/types.d.ts +36 -36
  136. package/lib/typescript/pid/sd-jwt/types.d.ts.map +1 -1
  137. package/lib/typescript/sd-jwt/index.d.ts +40 -68
  138. package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
  139. package/lib/typescript/sd-jwt/types.d.ts +64 -121
  140. package/lib/typescript/sd-jwt/types.d.ts.map +1 -1
  141. package/lib/typescript/trust/index.d.ts +150 -48
  142. package/lib/typescript/trust/index.d.ts.map +1 -1
  143. package/lib/typescript/trust/types.d.ts +2838 -1740
  144. package/lib/typescript/trust/types.d.ts.map +1 -1
  145. package/lib/typescript/utils/auth.d.ts +52 -0
  146. package/lib/typescript/utils/auth.d.ts.map +1 -0
  147. package/lib/typescript/utils/errors.d.ts +36 -1
  148. package/lib/typescript/utils/errors.d.ts.map +1 -1
  149. package/lib/typescript/utils/integrity.d.ts +1 -1
  150. package/lib/typescript/utils/misc.d.ts +18 -0
  151. package/lib/typescript/utils/misc.d.ts.map +1 -1
  152. package/lib/typescript/utils/par.d.ts +8 -31
  153. package/lib/typescript/utils/par.d.ts.map +1 -1
  154. package/lib/typescript/utils/pop.d.ts +26 -0
  155. package/lib/typescript/utils/pop.d.ts.map +1 -0
  156. package/lib/typescript/wallet-instance-attestation/issuing.d.ts +2 -1
  157. package/lib/typescript/wallet-instance-attestation/issuing.d.ts.map +1 -1
  158. package/lib/typescript/wallet-instance-attestation/types.d.ts +59 -59
  159. package/lib/typescript/wallet-instance-attestation/types.d.ts.map +1 -1
  160. package/package.json +2 -1
  161. package/src/client/generated/wallet-provider.ts +24 -21
  162. package/src/client/index.ts +3 -8
  163. package/src/credential/issuance/01-start-flow.ts +1 -0
  164. package/src/credential/issuance/02-evaluate-issuer-trust.ts +2 -1
  165. package/src/credential/issuance/03-start-credential-issuance.ts +407 -0
  166. package/src/credential/issuance/03-start-user-authorization.ts +87 -92
  167. package/src/credential/issuance/04-complete-user-authorization.ts +114 -13
  168. package/src/credential/issuance/05-authorize-access.ts +73 -48
  169. package/src/credential/issuance/06-obtain-credential.ts +77 -111
  170. package/src/credential/issuance/07-verify-and-parse-credential.ts +30 -67
  171. package/src/credential/issuance/index.ts +6 -4
  172. package/src/credential/issuance/types.ts +25 -0
  173. package/src/index.ts +2 -1
  174. package/src/pid/sd-jwt/converters.ts +5 -11
  175. package/src/pid/sd-jwt/types.ts +8 -6
  176. package/src/sd-jwt/__test__/converters.test.ts +1 -1
  177. package/src/sd-jwt/__test__/index.test.ts +45 -74
  178. package/src/sd-jwt/__test__/types.test.ts +21 -33
  179. package/src/sd-jwt/index.ts +3 -12
  180. package/src/sd-jwt/types.ts +17 -22
  181. package/src/trust/types.ts +64 -32
  182. package/src/utils/auth.ts +37 -0
  183. package/src/utils/errors.ts +85 -1
  184. package/src/utils/integrity.ts +1 -1
  185. package/src/utils/misc.ts +43 -0
  186. package/src/utils/par.ts +29 -17
  187. package/src/utils/pop.ts +34 -0
  188. package/src/wallet-instance-attestation/issuing.ts +39 -2
  189. package/src/wallet-instance-attestation/types.ts +11 -7
  190. package/lib/commonjs/credential/issuance/07-confirm-credential.js +0 -6
  191. package/lib/commonjs/credential/issuance/07-confirm-credential.js.map +0 -1
  192. package/lib/commonjs/credential/issuance/08-confirm-credential.js +0 -6
  193. package/lib/commonjs/credential/issuance/08-confirm-credential.js.map +0 -1
  194. package/lib/module/credential/issuance/07-confirm-credential.js +0 -2
  195. package/lib/module/credential/issuance/07-confirm-credential.js.map +0 -1
  196. package/lib/module/credential/issuance/08-confirm-credential.js +0 -2
  197. package/lib/module/credential/issuance/08-confirm-credential.js.map +0 -1
  198. package/lib/typescript/credential/issuance/07-confirm-credential.d.ts +0 -11
  199. package/lib/typescript/credential/issuance/07-confirm-credential.d.ts.map +0 -1
  200. package/lib/typescript/credential/issuance/08-confirm-credential.d.ts +0 -11
  201. package/lib/typescript/credential/issuance/08-confirm-credential.d.ts.map +0 -1
  202. package/src/credential/issuance/07-confirm-credential.ts +0 -14
  203. package/src/credential/issuance/08-confirm-credential.ts +0 -14
  204. package/src/sd-jwt/__test__/converters.test.js +0 -24
  205. package/src/sd-jwt/verifier.js +0 -12
package/src/utils/misc.ts CHANGED
@@ -25,3 +25,46 @@ export type Out<FN> = FN extends (...args: any[]) => Promise<any>
25
25
  : FN extends (...args: any[]) => any
26
26
  ? ReturnType<FN>
27
27
  : never;
28
+
29
+ /**
30
+ * TODO [SIW-1310]: replace this function with a cryptographically secure one.
31
+ * @param size - The size of the string to generate
32
+ * @returns A random alphanumeric string of the given size
33
+ */
34
+ export const generateRandomAlphaNumericString = (size: number) =>
35
+ Array.from(Array(size), () =>
36
+ Math.floor(Math.random() * 36).toString(36)
37
+ ).join("");
38
+
39
+ /**
40
+ * Repeatedly checks a condition function until it returns true,
41
+ * then resolves the returned promise. If the condition function does not return true
42
+ * within the specified timeout, the promise is rejected.
43
+ *
44
+ * @param conditionFunction - A function that returns a boolean value.
45
+ * The promise resolves when this function returns true.
46
+ * @param timeout - An optional timeout in seconds. The promise is rejected if the
47
+ * condition function does not return true within this time.
48
+ * @returns A promise that resolves once the conditionFunction returns true or rejects if timed out.
49
+ */
50
+ export const until = (
51
+ conditionFunction: () => boolean,
52
+ timeoutSeconds?: number
53
+ ): Promise<void> =>
54
+ new Promise<void>((resolve, reject) => {
55
+ const start = Date.now();
56
+ const poll = () => {
57
+ if (conditionFunction()) {
58
+ resolve();
59
+ } else if (
60
+ timeoutSeconds !== undefined &&
61
+ Date.now() - start >= timeoutSeconds * 1000
62
+ ) {
63
+ reject(new Error("Timeout exceeded"));
64
+ } else {
65
+ setTimeout(poll, 400);
66
+ }
67
+ };
68
+
69
+ poll();
70
+ });
package/src/utils/par.ts CHANGED
@@ -6,13 +6,12 @@ import {
6
6
  import uuid from "react-native-uuid";
7
7
  import * as z from "zod";
8
8
  import * as WalletInstanceAttestation from "../wallet-instance-attestation";
9
- import { hasStatus } from "./misc";
9
+ import { generateRandomAlphaNumericString, hasStatus } from "./misc";
10
+ import { createPopToken } from "./pop";
10
11
 
11
12
  export type AuthorizationDetail = z.infer<typeof AuthorizationDetail>;
12
13
  export const AuthorizationDetail = z.object({
13
- credential_definition: z.object({
14
- type: z.string(),
15
- }),
14
+ credential_configuration_id: z.string(),
16
15
  format: z.union([z.literal("vc+sd-jwt"), z.literal("vc+mdoc-cbor")]),
17
16
  type: z.literal("openid_credential"),
18
17
  });
@@ -34,7 +33,8 @@ export const makeParRequest =
34
33
  async (
35
34
  clientId: string,
36
35
  codeVerifier: string,
37
- walletProviderBaseUrl: string,
36
+ redirectUri: string,
37
+ responseMode: string,
38
38
  parEndpoint: string,
39
39
  walletInstanceAttestation: string,
40
40
  authorizationDetails: AuthorizationDetails,
@@ -48,10 +48,19 @@ export const makeParRequest =
48
48
  const iss = WalletInstanceAttestation.decode(walletInstanceAttestation)
49
49
  .payload.cnf.jwk.kid;
50
50
 
51
+ const signedWiaPoP = await createPopToken(
52
+ {
53
+ jti: `${uuid.v4()}`,
54
+ aud,
55
+ iss,
56
+ },
57
+ wiaCryptoContext
58
+ );
59
+
51
60
  /** A code challenge is provided so that the PAR is bound
52
61
  to the subsequent authorization code request
53
62
  @see https://datatracker.ietf.org/doc/html/rfc9126#name-request */
54
- const codeChallengeMethod = "s256";
63
+ const codeChallengeMethod = "S256";
55
64
  const codeChallenge = await sha256ToBase64(codeVerifier);
56
65
 
57
66
  /** The PAR request token is signed used the Wallet Instance Attestation key.
@@ -60,23 +69,26 @@ export const makeParRequest =
60
69
  The key is matched by its kid */
61
70
  const signedJwtForPar = await new SignJWT(wiaCryptoContext)
62
71
  .setProtectedHeader({
72
+ typ: "jwk",
63
73
  kid: wiaPublicKey.kid,
64
74
  })
65
75
  .setPayload({
66
- iss,
67
- aud,
68
76
  jti: `${uuid.v4()}`,
69
- client_assertion_type: assertionType,
70
- authorization_details: authorizationDetails,
77
+ aud,
71
78
  response_type: "code",
72
- redirect_uri: walletProviderBaseUrl,
73
- state: `${uuid.v4()}`,
79
+ response_mode: responseMode,
74
80
  client_id: clientId,
75
- code_challenge_method: codeChallengeMethod,
81
+ iss,
82
+ state: generateRandomAlphaNumericString(32),
76
83
  code_challenge: codeChallenge,
84
+ code_challenge_method: codeChallengeMethod,
85
+ authorization_details: authorizationDetails,
86
+ redirect_uri: redirectUri,
87
+ client_assertion_type: assertionType,
88
+ client_assertion: walletInstanceAttestation + "~" + signedWiaPoP,
77
89
  })
78
- .setIssuedAt()
79
- .setExpirationTime("1h")
90
+ .setIssuedAt() //iat is set to now
91
+ .setExpirationTime("5min")
80
92
  .sign();
81
93
 
82
94
  /** The request body for the Pushed Authorization Request */
@@ -85,9 +97,9 @@ export const makeParRequest =
85
97
  client_id: clientId,
86
98
  code_challenge: codeChallenge,
87
99
  code_challenge_method: "S256",
88
- client_assertion_type: assertionType,
89
- client_assertion: walletInstanceAttestation,
90
100
  request: signedJwtForPar,
101
+ client_assertion_type: assertionType,
102
+ client_assertion: walletInstanceAttestation + "~" + signedWiaPoP,
91
103
  });
92
104
 
93
105
  return await appFetch(parEndpoint, {
@@ -0,0 +1,34 @@
1
+ import * as z from "zod";
2
+
3
+ import { SignJWT, type CryptoContext } from "@pagopa/io-react-native-jwt";
4
+
5
+ /**
6
+ * Create a signed PoP token
7
+ *
8
+ * @param payload The payload to be included in the token.
9
+ * @param crypto The crypto context that handles the key bound to the DPoP.
10
+ *
11
+ * @returns The signed crypto token.
12
+ */
13
+ export const createPopToken = async (
14
+ payload: PoPPayload,
15
+ crypto: CryptoContext
16
+ ): Promise<string> => {
17
+ const kid = await crypto.getPublicKey().then((_) => _.kid);
18
+ return new SignJWT(crypto)
19
+ .setPayload(payload)
20
+ .setProtectedHeader({
21
+ typ: "jwt-client-attestation-pop",
22
+ kid,
23
+ })
24
+ .setIssuedAt()
25
+ .setExpirationTime("5min")
26
+ .sign();
27
+ };
28
+
29
+ export type PoPPayload = z.infer<typeof PoPPayload>;
30
+ export const PoPPayload = z.object({
31
+ jti: z.string(),
32
+ aud: z.string(),
33
+ iss: z.string(),
34
+ });
@@ -1,9 +1,15 @@
1
1
  import { type CryptoContext } from "@pagopa/io-react-native-jwt";
2
2
  import { SignJWT, thumbprint } from "@pagopa/io-react-native-jwt";
3
+ import { z } from "zod";
3
4
  import { JWK, fixBase64EncodingOnKey } from "../utils/jwk";
4
5
  import { getWalletProviderClient } from "../client";
5
6
  import type { IntegrityContext } from "..";
6
- import { z } from "zod";
7
+ import {
8
+ WalletProviderResponseError,
9
+ WalletInstanceRevokedError,
10
+ WalletInstanceNotFoundError,
11
+ WalletInstanceAttestationIssuingError,
12
+ } from "../utils/errors";
7
13
 
8
14
  /**
9
15
  * Getter for an attestation request. The attestation request is a JWT that will be sent to the Wallet Provider to request a Wallet Instance Attestation.
@@ -64,6 +70,8 @@ export async function getAttestationRequest(
64
70
  * @param params.appFetch (optional) Http client
65
71
  * @param walletProviderBaseUrl Base url for the Wallet Provider
66
72
  * @returns The retrieved Wallet Instance Attestation token
73
+ * @throws {WalletInstanceRevokedError} The Wallet Instance was revoked
74
+ * @throws {WalletInstanceNotFoundError} The Wallet Instance does not exist
67
75
  */
68
76
  export const getAttestation = async ({
69
77
  wiaCryptoContext,
@@ -100,7 +108,36 @@ export const getAttestation = async ({
100
108
  assertion: signedAttestationRequest,
101
109
  },
102
110
  })
103
- .then((result) => z.string().parse(result));
111
+ .then((result) => z.string().parse(result))
112
+ .catch(handleAttestationCreationError);
104
113
 
105
114
  return wia;
106
115
  };
116
+
117
+ const handleAttestationCreationError = (e: unknown) => {
118
+ if (!(e instanceof WalletProviderResponseError)) {
119
+ throw e;
120
+ }
121
+
122
+ if (e.statusCode === 403) {
123
+ throw new WalletInstanceRevokedError(
124
+ "Unable to get an attestation for a revoked Wallet Instance",
125
+ e.claim,
126
+ e.reason
127
+ );
128
+ }
129
+
130
+ if (e.statusCode === 404) {
131
+ throw new WalletInstanceNotFoundError(
132
+ "Unable to get an attestation for a Wallet Instance that does not exist",
133
+ e.claim,
134
+ e.reason
135
+ );
136
+ }
137
+
138
+ throw new WalletInstanceAttestationIssuingError(
139
+ `Unable to obtain wallet instance attestation [response status code: ${e.statusCode}]`,
140
+ e.claim,
141
+ e.reason
142
+ );
143
+ };
@@ -60,16 +60,20 @@ export const WalletInstanceAttestationJwt = z.object({
60
60
  Jwt.shape.payload,
61
61
  z.object({
62
62
  sub: z.string(),
63
- attested_security_context: z.string(),
63
+ aal: z.string(),
64
64
  authorization_endpoint: z.string(),
65
65
  response_types_supported: z.array(z.string()),
66
66
  vp_formats_supported: z.object({
67
- jwt_vp_json: z.object({
68
- alg_values_supported: z.array(z.string()),
69
- }),
70
- jwt_vc_json: z.object({
71
- alg_values_supported: z.array(z.string()),
72
- }),
67
+ "vc+sd-jwt": z
68
+ .object({
69
+ "sd-jwt_alg_values": z.array(z.string()),
70
+ })
71
+ .optional(),
72
+ "vp+sd-jwt": z
73
+ .object({
74
+ "sd-jwt_alg_values": z.array(z.string()),
75
+ })
76
+ .optional(),
73
77
  }),
74
78
  request_object_signing_alg_values_supported: z.array(z.string()),
75
79
  presentation_definition_uri_supported: z.boolean(),
@@ -1,6 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- //# sourceMappingURL=07-confirm-credential.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../../src","sources":["credential/issuance/07-confirm-credential.ts"],"mappings":""}
@@ -1,6 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- //# sourceMappingURL=08-confirm-credential.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../../src","sources":["credential/issuance/08-confirm-credential.ts"],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=07-confirm-credential.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../../src","sources":["credential/issuance/07-confirm-credential.ts"],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=08-confirm-credential.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../../src","sources":["credential/issuance/08-confirm-credential.ts"],"mappings":""}
@@ -1,11 +0,0 @@
1
- import type { ObtainCredential } from "./06-obtain-credential";
2
- import type { Out } from "../../utils/misc";
3
- /**
4
- * The end of the issuing flow.
5
- * The User accepted the Credential and it can be stored in the device according to the app implementation preferences.
6
- * To be implemented.
7
- *
8
- * @returns The type of the Credential to be issued and the url of the Issuer
9
- */
10
- export type ConfirmCredential = (credential: Out<ObtainCredential>["credential"], format: Out<ObtainCredential>["format"]) => Promise<void>;
11
- //# sourceMappingURL=07-confirm-credential.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"07-confirm-credential.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/07-confirm-credential.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,UAAU,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC,YAAY,CAAC,EAC/C,MAAM,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,KACpC,OAAO,CAAC,IAAI,CAAC,CAAC"}
@@ -1,11 +0,0 @@
1
- import type { ObtainCredential } from "./06-obtain-credential";
2
- import type { Out } from "../../utils/misc";
3
- /**
4
- * The end of the issuing flow.
5
- * The User accepted the Credential and it can be stored in the device according to the app implementation preferences.
6
- * To be implemented.
7
- *
8
- * @returns The type of the Credential to be issued and the url of the Issuer
9
- */
10
- export type ConfirmCredential = (credential: Out<ObtainCredential>["credential"], format: Out<ObtainCredential>["format"]) => Promise<void>;
11
- //# sourceMappingURL=08-confirm-credential.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"08-confirm-credential.d.ts","sourceRoot":"","sources":["../../../../src/credential/issuance/08-confirm-credential.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;;;;;GAMG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAC9B,UAAU,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC,YAAY,CAAC,EAC/C,MAAM,EAAE,GAAG,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,KACpC,OAAO,CAAC,IAAI,CAAC,CAAC"}
@@ -1,14 +0,0 @@
1
- import type { ObtainCredential } from "./06-obtain-credential";
2
- import type { Out } from "../../utils/misc";
3
-
4
- /**
5
- * The end of the issuing flow.
6
- * The User accepted the Credential and it can be stored in the device according to the app implementation preferences.
7
- * To be implemented.
8
- *
9
- * @returns The type of the Credential to be issued and the url of the Issuer
10
- */
11
- export type ConfirmCredential = (
12
- credential: Out<ObtainCredential>["credential"],
13
- format: Out<ObtainCredential>["format"]
14
- ) => Promise<void>;
@@ -1,14 +0,0 @@
1
- import type { ObtainCredential } from "./06-obtain-credential";
2
- import type { Out } from "../../utils/misc";
3
-
4
- /**
5
- * The end of the issuing flow.
6
- * The User accepted the Credential and it can be stored in the device according to the app implementation preferences.
7
- * To be implemented.
8
- *
9
- * @returns The type of the Credential to be issued and the url of the Issuer
10
- */
11
- export type ConfirmCredential = (
12
- credential: Out<ObtainCredential>["credential"],
13
- format: Out<ObtainCredential>["format"]
14
- ) => Promise<void>;
@@ -1,24 +0,0 @@
1
- import { getValueFromDisclosures } from "../converters";
2
- const disclosures = [
3
- ["6w1_soRXFgaHKfpYn3cvfQ", "given_name", "Mario"],
4
- ["fuNp97Hf3wV6y48y-QZhIg", "birthdate", "1980-10-01"],
5
- [
6
- "p-9LzyWHZBVDvhXDWkN2xA",
7
- "place_of_birth",
8
- { country: "IT", locality: "Rome" },
9
- ],
10
- ];
11
- describe("getValueFromDisclosures", () => {
12
- it("should return correct value for given_name", () => {
13
- const success = getValueFromDisclosures(disclosures, "given_name");
14
- expect(success).toBe("Mario");
15
- });
16
- it("should return correct value for place_of_birth", () => {
17
- const success = getValueFromDisclosures(disclosures, "place_of_birth");
18
- expect(success).toEqual({ country: "IT", locality: "Rome" });
19
- });
20
- it("should fail", () => {
21
- const success = getValueFromDisclosures(disclosures, "given_surname");
22
- expect(success).toBeUndefined();
23
- });
24
- });
@@ -1,12 +0,0 @@
1
- import { sha256ToBase64 } from "@pagopa/io-react-native-jwt";
2
- import { ValidationFailed } from "../utils/errors";
3
- export const verifyDisclosure = async ({ encoded, decoded }, claims) => {
4
- let hash = await sha256ToBase64(encoded);
5
- if (!claims.includes(hash)) {
6
- throw new ValidationFailed(
7
- "Validation of disclosure failed",
8
- `${decoded}`,
9
- "Disclosure hash not found in claims"
10
- );
11
- }
12
- };