@pagopa/io-react-native-wallet 0.11.1 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (217) hide show
  1. package/lib/commonjs/client/generated/wallet-provider.js +126 -0
  2. package/lib/commonjs/client/generated/wallet-provider.js.map +1 -0
  3. package/lib/commonjs/client/index.js +40 -0
  4. package/lib/commonjs/client/index.js.map +1 -0
  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 +56 -83
  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 +56 -33
  14. package/lib/commonjs/credential/issuance/05-authorize-access.js.map +1 -1
  15. package/lib/commonjs/credential/issuance/06-obtain-credential.js +51 -78
  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 +10 -1
  24. package/lib/commonjs/index.js.map +1 -1
  25. package/lib/commonjs/pid/sd-jwt/converters.js +5 -9
  26. package/lib/commonjs/pid/sd-jwt/converters.js.map +1 -1
  27. package/lib/commonjs/pid/sd-jwt/types.js +3 -3
  28. package/lib/commonjs/pid/sd-jwt/types.js.map +1 -1
  29. package/lib/commonjs/sd-jwt/__test__/converters.test.js +1 -1
  30. package/lib/commonjs/sd-jwt/__test__/converters.test.js.map +1 -1
  31. package/lib/commonjs/sd-jwt/__test__/index.test.js +30 -43
  32. package/lib/commonjs/sd-jwt/__test__/index.test.js.map +1 -1
  33. package/lib/commonjs/sd-jwt/__test__/types.test.js +16 -24
  34. package/lib/commonjs/sd-jwt/__test__/types.test.js.map +1 -1
  35. package/lib/commonjs/sd-jwt/index.js +3 -9
  36. package/lib/commonjs/sd-jwt/index.js.map +1 -1
  37. package/lib/commonjs/sd-jwt/types.js +11 -16
  38. package/lib/commonjs/sd-jwt/types.js.map +1 -1
  39. package/lib/commonjs/trust/types.js +70 -29
  40. package/lib/commonjs/trust/types.js.map +1 -1
  41. package/lib/commonjs/utils/auth.js +44 -0
  42. package/lib/commonjs/utils/auth.js.map +1 -0
  43. package/lib/commonjs/utils/errors.js +104 -1
  44. package/lib/commonjs/utils/errors.js.map +1 -1
  45. package/lib/commonjs/utils/integrity.js +2 -0
  46. package/lib/commonjs/utils/integrity.js.map +1 -0
  47. package/lib/commonjs/utils/misc.js +34 -1
  48. package/lib/commonjs/utils/misc.js.map +1 -1
  49. package/lib/commonjs/utils/par.js +23 -15
  50. package/lib/commonjs/utils/par.js.map +1 -1
  51. package/lib/commonjs/utils/pop.js +33 -0
  52. package/lib/commonjs/utils/pop.js.map +1 -0
  53. package/lib/commonjs/wallet-instance/index.js +29 -0
  54. package/lib/commonjs/wallet-instance/index.js.map +1 -0
  55. package/lib/commonjs/wallet-instance-attestation/issuing.js +62 -65
  56. package/lib/commonjs/wallet-instance-attestation/issuing.js.map +1 -1
  57. package/lib/commonjs/wallet-instance-attestation/types.js +8 -8
  58. package/lib/commonjs/wallet-instance-attestation/types.js.map +1 -1
  59. package/lib/module/client/generated/wallet-provider.js +102 -0
  60. package/lib/module/client/generated/wallet-provider.js.map +1 -0
  61. package/lib/module/client/index.js +33 -0
  62. package/lib/module/client/index.js.map +1 -0
  63. package/lib/module/credential/issuance/02-evaluate-issuer-trust.js +2 -1
  64. package/lib/module/credential/issuance/02-evaluate-issuer-trust.js.map +1 -1
  65. package/lib/module/credential/issuance/03-start-credential-issuance.js +276 -0
  66. package/lib/module/credential/issuance/03-start-credential-issuance.js.map +1 -0
  67. package/lib/module/credential/issuance/03-start-user-authorization.js +56 -80
  68. package/lib/module/credential/issuance/03-start-user-authorization.js.map +1 -1
  69. package/lib/module/credential/issuance/04-complete-user-authorization.js +85 -1
  70. package/lib/module/credential/issuance/04-complete-user-authorization.js.map +1 -1
  71. package/lib/module/credential/issuance/05-authorize-access.js +54 -33
  72. package/lib/module/credential/issuance/05-authorize-access.js.map +1 -1
  73. package/lib/module/credential/issuance/06-obtain-credential.js +50 -75
  74. package/lib/module/credential/issuance/06-obtain-credential.js.map +1 -1
  75. package/lib/module/credential/issuance/07-verify-and-parse-credential.js +21 -44
  76. package/lib/module/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
  77. package/lib/module/credential/issuance/index.js +2 -1
  78. package/lib/module/credential/issuance/index.js.map +1 -1
  79. package/lib/module/credential/issuance/types.js +18 -0
  80. package/lib/module/credential/issuance/types.js.map +1 -0
  81. package/lib/module/index.js +3 -1
  82. package/lib/module/index.js.map +1 -1
  83. package/lib/module/pid/sd-jwt/converters.js +5 -9
  84. package/lib/module/pid/sd-jwt/converters.js.map +1 -1
  85. package/lib/module/pid/sd-jwt/types.js +3 -3
  86. package/lib/module/pid/sd-jwt/types.js.map +1 -1
  87. package/lib/module/sd-jwt/__test__/converters.test.js +1 -1
  88. package/lib/module/sd-jwt/__test__/converters.test.js.map +1 -1
  89. package/lib/module/sd-jwt/__test__/index.test.js +30 -43
  90. package/lib/module/sd-jwt/__test__/index.test.js.map +1 -1
  91. package/lib/module/sd-jwt/__test__/types.test.js +16 -24
  92. package/lib/module/sd-jwt/__test__/types.test.js.map +1 -1
  93. package/lib/module/sd-jwt/index.js +3 -9
  94. package/lib/module/sd-jwt/index.js.map +1 -1
  95. package/lib/module/sd-jwt/types.js +11 -16
  96. package/lib/module/sd-jwt/types.js.map +1 -1
  97. package/lib/module/trust/types.js +70 -29
  98. package/lib/module/trust/types.js.map +1 -1
  99. package/lib/module/utils/auth.js +35 -0
  100. package/lib/module/utils/auth.js.map +1 -0
  101. package/lib/module/utils/errors.js +98 -0
  102. package/lib/module/utils/errors.js.map +1 -1
  103. package/lib/module/utils/integrity.js +2 -0
  104. package/lib/module/utils/integrity.js.map +1 -0
  105. package/lib/module/utils/misc.js +31 -0
  106. package/lib/module/utils/misc.js.map +1 -1
  107. package/lib/module/utils/par.js +24 -16
  108. package/lib/module/utils/par.js.map +1 -1
  109. package/lib/module/utils/pop.js +24 -0
  110. package/lib/module/utils/pop.js.map +1 -0
  111. package/lib/module/wallet-instance/index.js +23 -0
  112. package/lib/module/wallet-instance/index.js.map +1 -0
  113. package/lib/module/wallet-instance-attestation/issuing.js +63 -67
  114. package/lib/module/wallet-instance-attestation/issuing.js.map +1 -1
  115. package/lib/module/wallet-instance-attestation/types.js +8 -8
  116. package/lib/module/wallet-instance-attestation/types.js.map +1 -1
  117. package/lib/typescript/client/generated/wallet-provider.d.ts +264 -0
  118. package/lib/typescript/client/generated/wallet-provider.d.ts.map +1 -0
  119. package/lib/typescript/client/index.d.ts +7 -0
  120. package/lib/typescript/client/index.d.ts.map +1 -0
  121. package/lib/typescript/credential/issuance/01-start-flow.d.ts +1 -0
  122. package/lib/typescript/credential/issuance/01-start-flow.d.ts.map +1 -1
  123. package/lib/typescript/credential/issuance/02-evaluate-issuer-trust.d.ts +2 -1
  124. package/lib/typescript/credential/issuance/02-evaluate-issuer-trust.d.ts.map +1 -1
  125. package/lib/typescript/credential/issuance/03-start-credential-issuance.d.ts +41 -0
  126. package/lib/typescript/credential/issuance/03-start-credential-issuance.d.ts.map +1 -0
  127. package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts +23 -18
  128. package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts.map +1 -1
  129. package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts +24 -12
  130. package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts.map +1 -1
  131. package/lib/typescript/credential/issuance/05-authorize-access.d.ts +22 -16
  132. package/lib/typescript/credential/issuance/05-authorize-access.d.ts.map +1 -1
  133. package/lib/typescript/credential/issuance/06-obtain-credential.d.ts +19 -26
  134. package/lib/typescript/credential/issuance/06-obtain-credential.d.ts.map +1 -1
  135. package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts +10 -15
  136. package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts.map +1 -1
  137. package/lib/typescript/credential/issuance/index.d.ts +3 -4
  138. package/lib/typescript/credential/issuance/index.d.ts.map +1 -1
  139. package/lib/typescript/credential/issuance/types.d.ts +63 -0
  140. package/lib/typescript/credential/issuance/types.d.ts.map +1 -0
  141. package/lib/typescript/credential/presentation/types.d.ts +6 -6
  142. package/lib/typescript/index.d.ts +6 -1
  143. package/lib/typescript/index.d.ts.map +1 -1
  144. package/lib/typescript/pid/sd-jwt/converters.d.ts.map +1 -1
  145. package/lib/typescript/pid/sd-jwt/types.d.ts +36 -36
  146. package/lib/typescript/pid/sd-jwt/types.d.ts.map +1 -1
  147. package/lib/typescript/sd-jwt/index.d.ts +40 -68
  148. package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
  149. package/lib/typescript/sd-jwt/types.d.ts +64 -121
  150. package/lib/typescript/sd-jwt/types.d.ts.map +1 -1
  151. package/lib/typescript/trust/index.d.ts +150 -48
  152. package/lib/typescript/trust/index.d.ts.map +1 -1
  153. package/lib/typescript/trust/types.d.ts +2838 -1740
  154. package/lib/typescript/trust/types.d.ts.map +1 -1
  155. package/lib/typescript/utils/auth.d.ts +52 -0
  156. package/lib/typescript/utils/auth.d.ts.map +1 -0
  157. package/lib/typescript/utils/errors.d.ts +48 -0
  158. package/lib/typescript/utils/errors.d.ts.map +1 -1
  159. package/lib/typescript/utils/integrity.d.ts +21 -0
  160. package/lib/typescript/utils/integrity.d.ts.map +1 -0
  161. package/lib/typescript/utils/misc.d.ts +18 -0
  162. package/lib/typescript/utils/misc.d.ts.map +1 -1
  163. package/lib/typescript/utils/par.d.ts +8 -31
  164. package/lib/typescript/utils/par.d.ts.map +1 -1
  165. package/lib/typescript/utils/pop.d.ts +26 -0
  166. package/lib/typescript/utils/pop.d.ts.map +1 -0
  167. package/lib/typescript/wallet-instance/index.d.ts +7 -0
  168. package/lib/typescript/wallet-instance/index.d.ts.map +1 -0
  169. package/lib/typescript/wallet-instance-attestation/issuing.d.ts +17 -4
  170. package/lib/typescript/wallet-instance-attestation/issuing.d.ts.map +1 -1
  171. package/lib/typescript/wallet-instance-attestation/types.d.ts +64 -64
  172. package/lib/typescript/wallet-instance-attestation/types.d.ts.map +1 -1
  173. package/package.json +9 -5
  174. package/src/client/generated/wallet-provider.ts +173 -0
  175. package/src/client/index.ts +53 -0
  176. package/src/credential/issuance/01-start-flow.ts +1 -0
  177. package/src/credential/issuance/02-evaluate-issuer-trust.ts +2 -1
  178. package/src/credential/issuance/03-start-credential-issuance.ts +407 -0
  179. package/src/credential/issuance/03-start-user-authorization.ts +91 -92
  180. package/src/credential/issuance/04-complete-user-authorization.ts +114 -13
  181. package/src/credential/issuance/05-authorize-access.ts +74 -49
  182. package/src/credential/issuance/06-obtain-credential.ts +77 -111
  183. package/src/credential/issuance/07-verify-and-parse-credential.ts +30 -67
  184. package/src/credential/issuance/index.ts +6 -4
  185. package/src/credential/issuance/types.ts +25 -0
  186. package/src/index.ts +8 -0
  187. package/src/pid/sd-jwt/converters.ts +5 -11
  188. package/src/pid/sd-jwt/types.ts +8 -6
  189. package/src/sd-jwt/__test__/converters.test.ts +1 -1
  190. package/src/sd-jwt/__test__/index.test.ts +45 -74
  191. package/src/sd-jwt/__test__/types.test.ts +21 -33
  192. package/src/sd-jwt/index.ts +3 -12
  193. package/src/sd-jwt/types.ts +17 -22
  194. package/src/trust/types.ts +64 -32
  195. package/src/utils/auth.ts +37 -0
  196. package/src/utils/errors.ts +112 -0
  197. package/src/utils/integrity.ts +23 -0
  198. package/src/utils/misc.ts +43 -0
  199. package/src/utils/par.ts +29 -17
  200. package/src/utils/pop.ts +34 -0
  201. package/src/wallet-instance/index.ts +29 -0
  202. package/src/wallet-instance-attestation/issuing.ts +101 -97
  203. package/src/wallet-instance-attestation/types.ts +12 -8
  204. package/lib/commonjs/credential/issuance/07-confirm-credential.js +0 -6
  205. package/lib/commonjs/credential/issuance/07-confirm-credential.js.map +0 -1
  206. package/lib/commonjs/credential/issuance/08-confirm-credential.js +0 -6
  207. package/lib/commonjs/credential/issuance/08-confirm-credential.js.map +0 -1
  208. package/lib/module/credential/issuance/07-confirm-credential.js +0 -2
  209. package/lib/module/credential/issuance/07-confirm-credential.js.map +0 -1
  210. package/lib/module/credential/issuance/08-confirm-credential.js +0 -2
  211. package/lib/module/credential/issuance/08-confirm-credential.js.map +0 -1
  212. package/lib/typescript/credential/issuance/07-confirm-credential.d.ts +0 -11
  213. package/lib/typescript/credential/issuance/07-confirm-credential.d.ts.map +0 -1
  214. package/lib/typescript/credential/issuance/08-confirm-credential.d.ts +0 -11
  215. package/lib/typescript/credential/issuance/08-confirm-credential.d.ts.map +0 -1
  216. package/src/credential/issuance/07-confirm-credential.ts +0 -14
  217. package/src/credential/issuance/08-confirm-credential.ts +0 -14
@@ -39,29 +39,24 @@ export const SdJwt4VC = z.object({
39
39
  typ: z.literal("vc+sd-jwt"),
40
40
  alg: z.string(),
41
41
  kid: z.string().optional(),
42
- trust_chain: z.array(z.string()),
43
42
  }),
44
- payload: z.object({
45
- iss: z.string(),
46
- sub: z.string(),
47
- jti: z.string(),
48
- iat: UnixTime,
49
- exp: UnixTime,
50
- status: z.string(),
51
- cnf: z.object({
52
- jwk: JWK,
53
- }),
54
- type: z.string(),
55
- verified_claims: z.object({
56
- verification: z.intersection(
57
- z.object({
58
- trust_framework: z.literal("eidas"),
59
- assurance_level: z.string(),
43
+ payload: z.intersection(
44
+ z.object({
45
+ iss: z.string(),
46
+ sub: z.string(),
47
+ iat: UnixTime.optional(),
48
+ exp: UnixTime,
49
+ _sd_alg: z.literal("sha-256"),
50
+ status: z.object({
51
+ status_attestation: z.object({
52
+ credential_hash_alg: z.literal("sha-256"),
60
53
  }),
61
- ObfuscatedDisclosures
62
- ),
63
- claims: ObfuscatedDisclosures,
54
+ }),
55
+ cnf: z.object({
56
+ jwk: JWK,
57
+ }),
58
+ vct: z.string(),
64
59
  }),
65
- _sd_alg: z.literal("sha-256"),
66
- }),
60
+ ObfuscatedDisclosures
61
+ ),
67
62
  });
@@ -18,38 +18,48 @@ const RelyingPartyMetadata = z.object({
18
18
  // instruct the Wallet Solution on how to render the credential correctly
19
19
  type CredentialDisplayMetadata = z.infer<typeof CredentialDisplayMetadata>;
20
20
  const CredentialDisplayMetadata = z.object({
21
+ name: z.string(),
22
+ locale: z.string(),
23
+ logo: z
24
+ .object({
25
+ url: z.string(),
26
+ alt_text: z.string(),
27
+ })
28
+ .optional(), // TODO [SIW-1268]: should not be optional
29
+ background_color: z.string().optional(), // TODO [SIW-1268]: should not be optional
30
+ text_color: z.string().optional(), // TODO [SIW-1268]: should not be optional
31
+ });
32
+
33
+ // Metadata for displaying issuer information
34
+ type CredentialIssuerDisplayMetadata = z.infer<
35
+ typeof CredentialIssuerDisplayMetadata
36
+ >;
37
+ const CredentialIssuerDisplayMetadata = z.object({
21
38
  name: z.string(),
22
39
  locale: z.string(),
23
40
  logo: z.object({
24
41
  url: z.string(),
25
42
  alt_text: z.string(),
26
43
  }),
27
- background_color: z.string(),
28
- text_color: z.string(),
29
44
  });
30
45
 
31
- type CredentialDefinitionMetadata = z.infer<
32
- typeof CredentialDefinitionMetadata
33
- >;
34
- const CredentialDefinitionMetadata = z.object({
35
- type: z.array(z.string()),
36
- credentialSubject: z.record(
37
- z.object({
38
- mandatory: z.boolean(),
39
- display: z.array(z.object({ name: z.string(), locale: z.string() })),
40
- })
41
- ),
42
- });
46
+ type ClaimsMetadata = z.infer<typeof ClaimsMetadata>;
47
+ const ClaimsMetadata = z.record(
48
+ z.object({
49
+ value_type: z.string(),
50
+ display: z.array(z.object({ name: z.string(), locale: z.string() })),
51
+ })
52
+ );
43
53
 
44
54
  // Metadata for a credentia which i supported by a Issuer
45
55
  type SupportedCredentialMetadata = z.infer<typeof SupportedCredentialMetadata>;
46
56
  const SupportedCredentialMetadata = z.object({
47
- id: z.string(),
48
57
  format: z.union([z.literal("vc+sd-jwt"), z.literal("vc+mdoc-cbor")]),
49
- cryptographic_binding_methods_supported: z.array(z.string()),
50
- cryptographic_suites_supported: z.array(z.string()),
58
+ scope: z.string(),
51
59
  display: z.array(CredentialDisplayMetadata),
52
- credential_definition: CredentialDefinitionMetadata,
60
+ claims: ClaimsMetadata,
61
+ cryptographic_binding_methods_supported: z.array(z.string()),
62
+ credential_signing_alg_values_supported: z.array(z.string()),
53
63
  });
54
64
 
55
65
  export type EntityStatement = z.infer<typeof EntityStatement>;
@@ -101,19 +111,19 @@ const BaseEntityConfiguration = z.object({
101
111
  header: EntityConfigurationHeader,
102
112
  payload: z
103
113
  .object({
104
- exp: UnixTime,
105
- iat: UnixTime,
106
114
  iss: z.string(),
107
115
  sub: z.string(),
108
- jwks: z.object({
109
- keys: z.array(JWK),
110
- }),
116
+ iat: UnixTime,
117
+ exp: UnixTime,
118
+ authority_hints: z.array(z.string()).optional(),
111
119
  metadata: z
112
120
  .object({
113
121
  federation_entity: FederationEntityMetadata,
114
122
  })
115
123
  .passthrough(),
116
- authority_hints: z.array(z.string()).optional(),
124
+ jwks: z.object({
125
+ keys: z.array(JWK),
126
+ }),
117
127
  })
118
128
  .passthrough(),
119
129
  });
@@ -135,18 +145,42 @@ export const CredentialIssuerEntityConfiguration = BaseEntityConfiguration.and(
135
145
  metadata: z.object({
136
146
  openid_credential_issuer: z.object({
137
147
  credential_issuer: z.string(),
148
+ credential_endpoint: z.string(),
149
+ revocation_endpoint: z.string(),
150
+ status_attestation_endpoint: z.string(),
151
+ display: z.array(CredentialIssuerDisplayMetadata),
152
+ credential_configurations_supported: z.record(
153
+ SupportedCredentialMetadata
154
+ ),
155
+ jwks: z.object({ keys: z.array(JWK) }),
156
+ }),
157
+ oauth_authorization_server: z.object({
138
158
  authorization_endpoint: z.string(),
139
- token_endpoint: z.string(),
140
159
  pushed_authorization_request_endpoint: z.string(),
141
- dpop_signing_alg_values_supported: z.array(z.string()),
142
- credential_endpoint: z.string(),
143
- credentials_supported: z.array(SupportedCredentialMetadata),
160
+ dpop_signing_alg_values_supported: z.array(z.string()).optional(), // TODO [SIW-1268]: should not be optional
161
+ token_endpoint: z.string(),
162
+ introspection_endpoint: z.string().optional(), // TODO [SIW-1268]: should not be optional
163
+ client_registration_types_supported: z.array(z.string()),
164
+ code_challenge_methods_supported: z.array(z.string()),
165
+ authorization_details_types_supported: z.array(z.string()).optional(), // TODO [SIW-1268]: should not be optional,
166
+ acr_values_supported: z.array(z.string()),
167
+ grant_types_supported: z.array(z.string()),
168
+ issuer: z.string(),
144
169
  jwks: z.object({ keys: z.array(JWK) }),
170
+ scopes_supported: z.array(z.string()),
171
+ request_parameter_supported: z.boolean().optional(), // TODO [SIW-1268]: should not be optional
172
+ request_uri_parameter_supported: z.boolean().optional(), // TODO [SIW-1268]: should not be optional
173
+ response_types_supported: z.array(z.string()).optional(), // TODO [SIW-1268]: should not be optional
174
+ response_modes_supported: z.array(z.string()),
175
+ subject_types_supported: z.array(z.string()).optional(), // TODO [SIW-1268]: should not be optional
176
+ token_endpoint_auth_methods_supported: z.array(z.string()),
177
+ token_endpoint_auth_signing_alg_values_supported: z.array(z.string()),
178
+ request_object_signing_alg_values_supported: z.array(z.string()),
145
179
  }),
146
180
  /** Credential Issuers act as Relying Party
147
181
  when they require the presentation of other credentials.
148
182
  This does not apply for PID issuance, which requires CIE authz. */
149
- wallet_relying_party: RelyingPartyMetadata.optional(),
183
+ openid_relying_party: RelyingPartyMetadata.optional(),
150
184
  }),
151
185
  }),
152
186
  })
@@ -177,9 +211,7 @@ export const WalletProviderEntityConfiguration = BaseEntityConfiguration.and(
177
211
  wallet_provider: z
178
212
  .object({
179
213
  token_endpoint: z.string(),
180
- attested_security_context_values_supported: z
181
- .array(z.string())
182
- .optional(),
214
+ aal_values_supported: z.array(z.string()).optional(),
183
215
  grant_types_supported: z.array(z.string()),
184
216
  token_endpoint_auth_methods_supported: z.array(z.string()),
185
217
  token_endpoint_auth_signing_alg_values_supported: z.array(
@@ -0,0 +1,37 @@
1
+ import * as z from "zod";
2
+
3
+ /**
4
+ * Context for authorization during the {@link 03-start-user-authorization.ts} phase.
5
+ * It consists of a single method to identify the user which takes a URL and a redirect schema as input.
6
+ * Once the authorization is completed and the URL calls the redirect schema, the method should return the redirect URL.
7
+ */
8
+ export interface AuthorizationContext {
9
+ authorize: (url: string, redirectSchema: string) => Promise<string>;
10
+ }
11
+
12
+ /**
13
+ * The result of the identification process.
14
+ */
15
+ export const AuthorizationResultShape = z.object({
16
+ code: z.string(),
17
+ state: z.string(),
18
+ iss: z.string().optional(),
19
+ });
20
+
21
+ /**
22
+ * The error of the identification process.
23
+ * It follows the OAuth/OIDC error response format.
24
+ * @see https://openid.net/specs/openid-connect-core-1_0.html#AuthError
25
+ * @see https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.2.1
26
+ */
27
+ export const AuthorizationErrorShape = z.object({
28
+ error: z.string(), // not enforcing the error code format
29
+ error_description: z.string().optional(),
30
+ error_uri: z.string().optional(),
31
+ state: z.string().optional(),
32
+ });
33
+
34
+ /**
35
+ * Type of the identification result.
36
+ */
37
+ export type AuthorizationResult = z.infer<typeof AuthorizationResultShape>;
@@ -233,3 +233,115 @@ export class PidMetadataError extends Error {
233
233
  super(message);
234
234
  }
235
235
  }
236
+
237
+ /**
238
+ * An error subclass thrown when a Wallet Provider http request fail
239
+ *
240
+ */
241
+ export class WalletProviderResponseError extends IoWalletError {
242
+ static get code(): "ERR_IO_WALLET_PROVIDER_RESPONSE_FAILED" {
243
+ return "ERR_IO_WALLET_PROVIDER_RESPONSE_FAILED";
244
+ }
245
+
246
+ code = "ERR_IO_WALLET_PROVIDER_RESPONSE_FAILED";
247
+
248
+ /** The Claim for which the validation failed. */
249
+ claim: string;
250
+
251
+ /** Reason code for the validation failure. */
252
+ reason: string;
253
+
254
+ /** HTTP status code */
255
+ statusCode: number;
256
+
257
+ constructor(
258
+ message: string,
259
+ claim: string = "unspecified",
260
+ reason: string = "unspecified",
261
+ statusCode: number
262
+ ) {
263
+ super(
264
+ serializeAttrs({
265
+ message,
266
+ claim,
267
+ reason,
268
+ statusCode: statusCode.toString(),
269
+ })
270
+ );
271
+ this.claim = claim;
272
+ this.reason = reason;
273
+ this.statusCode = statusCode;
274
+ }
275
+ }
276
+
277
+ export class WalletInstanceRevokedError extends IoWalletError {
278
+ static get code(): "ERR_IO_WALLET_INSTANCE_REVOKED" {
279
+ return "ERR_IO_WALLET_INSTANCE_REVOKED";
280
+ }
281
+
282
+ code = "ERR_IO_WALLET_INSTANCE_REVOKED";
283
+
284
+ claim: string;
285
+ reason: string;
286
+
287
+ constructor(message: string, claim: string, reason: string = "unspecified") {
288
+ super(serializeAttrs({ message, claim, reason }));
289
+ this.reason = reason;
290
+ this.claim = claim;
291
+ }
292
+ }
293
+
294
+ export class WalletInstanceNotFoundError extends IoWalletError {
295
+ static get code(): "ERR_IO_WALLET_INSTANCE_NOT_FOUND" {
296
+ return "ERR_IO_WALLET_INSTANCE_NOT_FOUND";
297
+ }
298
+
299
+ code = "ERR_IO_WALLET_INSTANCE_NOT_FOUND";
300
+
301
+ claim: string;
302
+ reason: string;
303
+
304
+ constructor(message: string, claim: string, reason: string = "unspecified") {
305
+ super(serializeAttrs({ message, claim, reason }));
306
+ this.reason = reason;
307
+ this.claim = claim;
308
+ }
309
+ }
310
+
311
+ /**
312
+ * An error subclass thrown when an error occurs during the authorization process.
313
+ */
314
+ export class AuthorizationError extends IoWalletError {
315
+ static get code(): "ERR_IO_WALLET_AUTHORIZATION_ERROR" {
316
+ return "ERR_IO_WALLET_AUTHORIZATION_ERROR";
317
+ }
318
+
319
+ code = "ERR_IO_WALLET_AUTHORIZATION_ERROR";
320
+
321
+ constructor(message?: string) {
322
+ super(message);
323
+ }
324
+ }
325
+
326
+ /**
327
+ * An error subclass thrown when an error occurs during the authorization process with the IDP.
328
+ * It contains the error and error description returned by the IDP.
329
+ */
330
+ export class AuthorizationIdpError extends IoWalletError {
331
+ static get code(): "ERR_IO_WALLET_IDENTIFICATION_RESPONSE_ERROR" {
332
+ return "ERR_IO_WALLET_IDENTIFICATION_RESPONSE_ERROR";
333
+ }
334
+
335
+ code = "ERR_IO_WALLET_IDENTIFICATION_RESPONSE_PARSING_FAILED";
336
+
337
+ error: string;
338
+ errorDescription?: string;
339
+
340
+ constructor(error: string, errorDescription?: string) {
341
+ super(
342
+ serializeAttrs(errorDescription ? { error, errorDescription } : { error })
343
+ );
344
+ this.error = error;
345
+ this.errorDescription = errorDescription;
346
+ }
347
+ }
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Interface for the integrity context which provides the necessary functions to interact with the integrity service.
3
+ * The functions are platform specific and must be implemented in the platform specific code.
4
+ * getHardwareKeyTag: returns the hardware key tag in a url safe format (e.g. base64url).
5
+ * getAttestation: requests the attestation from the integrity service.
6
+ * getHardwareSignatureWithAuthData: signs the clientData and returns the signature with the authenticator data.
7
+ */
8
+ export interface IntegrityContext {
9
+ getHardwareKeyTag: () => string;
10
+ getAttestation: (nonce: string) => Promise<string>;
11
+ getHardwareSignatureWithAuthData: (
12
+ clientData: string
13
+ ) => Promise<HardwareSignatureWithAuthData>;
14
+ }
15
+
16
+ /**
17
+ * Type returned by the getHardwareSignatureWithAuthData function of {@link IntegrityContext}.
18
+ * It contains the signature and the authenticator data.
19
+ */
20
+ export type HardwareSignatureWithAuthData = {
21
+ signature: string;
22
+ authenticatorData: string;
23
+ };
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
+ });
@@ -0,0 +1,29 @@
1
+ import { getWalletProviderClient } from "../client";
2
+ import type { IntegrityContext } from "..";
3
+
4
+ export async function createWalletInstance(context: {
5
+ integrityContext: IntegrityContext;
6
+ walletProviderBaseUrl: string;
7
+ appFetch?: GlobalFetch["fetch"];
8
+ }) {
9
+ const { integrityContext } = context;
10
+
11
+ const api = getWalletProviderClient(context);
12
+
13
+ //1. Obtain nonce
14
+ const challenge = await api.get("/nonce").then((response) => response.nonce);
15
+
16
+ const keyAttestation = await integrityContext.getAttestation(challenge);
17
+ const hardwareKeyTag = integrityContext.getHardwareKeyTag();
18
+
19
+ //2. Create Wallet Instance
20
+ await api.post("/wallet-instances", {
21
+ body: {
22
+ challenge,
23
+ key_attestation: keyAttestation,
24
+ hardware_key_tag: hardwareKeyTag,
25
+ },
26
+ });
27
+
28
+ return hardwareKeyTag;
29
+ }