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

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -1,77 +1,68 @@
1
- import {
2
- type CryptoContext,
3
- decode as decodeJwt,
4
- } from "@pagopa/io-react-native-jwt";
5
- import { verify as verifyJwt } from "@pagopa/io-react-native-jwt";
1
+ import { type CryptoContext } from "@pagopa/io-react-native-jwt";
6
2
  import { SignJWT, thumbprint } from "@pagopa/io-react-native-jwt";
3
+ import { z } from "zod";
7
4
  import { JWK, fixBase64EncodingOnKey } from "../utils/jwk";
8
- import { WalletInstanceAttestationRequestJwt } from "./types";
9
- import uuid from "react-native-uuid";
10
- import { WalletInstanceAttestationIssuingError } from "../utils/errors";
11
- import type { WalletProviderEntityConfiguration } from "../trust/types";
5
+ import { getWalletProviderClient } from "../client";
6
+ import type { IntegrityContext } from "..";
7
+ import {
8
+ WalletProviderResponseError,
9
+ WalletInstanceRevokedError,
10
+ WalletInstanceNotFoundError,
11
+ WalletInstanceAttestationIssuingError,
12
+ } from "../utils/errors";
12
13
 
13
- async function getAttestationRequest(
14
+ /**
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.
16
+ *
17
+ * @param challenge - The nonce received from the Wallet Provider which is part of the signed clientData
18
+ * @param wiaCryptoContext - The key pair associated with the WIA. Will be use to prove the ownership of the attestation
19
+ * @param integrityContext - The integrity context which exposes a set of functions to interact with the device integrity service
20
+ * @param walletProviderBaseUrl - Base url for the Wallet Provider
21
+ * @returns A JWT containing the attestation request
22
+ */
23
+ export async function getAttestationRequest(
24
+ challenge: string,
14
25
  wiaCryptoContext: CryptoContext,
15
- walletProviderEntityConfiguration: WalletProviderEntityConfiguration
26
+ integrityContext: IntegrityContext,
27
+ walletProviderBaseUrl: string
16
28
  ): Promise<string> {
17
29
  const jwk = await wiaCryptoContext.getPublicKey();
18
30
  const parsedJwk = JWK.parse(jwk);
19
31
  const keyThumbprint = await thumbprint(parsedJwk);
20
32
  const publicKey = { ...parsedJwk, kid: keyThumbprint };
21
33
 
34
+ const clientData = {
35
+ challenge,
36
+ jwk_thumbprint: keyThumbprint,
37
+ };
38
+
39
+ const hardwareKeyTag = integrityContext.getHardwareKeyTag();
40
+ const { signature, authenticatorData } =
41
+ await integrityContext.getHardwareSignatureWithAuthData(
42
+ JSON.stringify(clientData)
43
+ );
44
+
22
45
  return new SignJWT(wiaCryptoContext)
23
46
  .setPayload({
24
47
  iss: keyThumbprint,
25
- aud: walletProviderEntityConfiguration.payload.iss,
26
- jti: `${uuid.v4()}`,
27
- nonce: `${uuid.v4()}`,
48
+ sub: walletProviderBaseUrl,
49
+ challenge,
50
+ hardware_signature: signature,
51
+ integrity_assertion: authenticatorData,
52
+ hardware_key_tag: hardwareKeyTag,
28
53
  cnf: {
29
54
  jwk: fixBase64EncodingOnKey(publicKey),
30
55
  },
31
56
  })
32
57
  .setProtectedHeader({
33
58
  kid: publicKey.kid,
34
- typ: "wiar+jwt",
59
+ typ: "war+jwt",
35
60
  })
36
61
  .setIssuedAt()
37
62
  .setExpirationTime("1h")
38
63
  .sign();
39
64
  }
40
65
 
41
- /**
42
- * Validate a Wallet Instance Attestation token.
43
- * Either return true or throw an exception.
44
- *
45
- * @param wia Signed Wallet Instance Attestation token
46
- * @param walletProviderEntityConfiguration Entity Configuration object for the issuing Wallet Provider
47
- * @returns The token is valid
48
- * @throws {WalletInstanceAttestationIssuingError} When the received token fails to validate. This can happen due to invalid signature, expired token or malformed JWT token.
49
- */
50
- async function verifyWalletInstanceAttestation(
51
- wia: string,
52
- walletProviderEntityConfiguration: WalletProviderEntityConfiguration
53
- ): Promise<true> {
54
- const {
55
- payload: {
56
- sub,
57
- metadata: {
58
- wallet_provider: {
59
- jwks: { keys },
60
- },
61
- },
62
- },
63
- } = walletProviderEntityConfiguration;
64
- return verifyJwt(wia, keys, { issuer: sub })
65
- .then((_) => true as const)
66
- .catch((ex) => {
67
- const reason = ex && ex instanceof Error ? ex.message : "unknown reason";
68
- throw new WalletInstanceAttestationIssuingError(
69
- "Unable to validate received wallet instance attestation",
70
- reason
71
- );
72
- });
73
- }
74
-
75
66
  /**
76
67
  * Request a Wallet Instance Attestation (WIA) to the Wallet provider
77
68
  *
@@ -79,61 +70,74 @@ async function verifyWalletInstanceAttestation(
79
70
  * @param params.appFetch (optional) Http client
80
71
  * @param walletProviderBaseUrl Base url for the Wallet Provider
81
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
82
75
  */
83
- export const getAttestation =
84
- ({
85
- wiaCryptoContext,
86
- appFetch = fetch,
87
- }: {
88
- wiaCryptoContext: CryptoContext;
89
- appFetch?: GlobalFetch["fetch"];
90
- }) =>
91
- async (
92
- walletProviderEntityConfiguration: WalletProviderEntityConfiguration
93
- ): Promise<string> => {
94
- const signedAttestationRequest = await getAttestationRequest(
95
- wiaCryptoContext,
96
- walletProviderEntityConfiguration
97
- );
76
+ export const getAttestation = async ({
77
+ wiaCryptoContext,
78
+ integrityContext,
79
+ walletProviderBaseUrl,
80
+ appFetch = fetch,
81
+ }: {
82
+ wiaCryptoContext: CryptoContext;
83
+ integrityContext: IntegrityContext;
84
+ walletProviderBaseUrl: string;
85
+ appFetch?: GlobalFetch["fetch"];
86
+ }): Promise<string> => {
87
+ const api = getWalletProviderClient({
88
+ walletProviderBaseUrl,
89
+ appFetch,
90
+ });
98
91
 
99
- const decodedRequest = decodeJwt(signedAttestationRequest);
100
- const parsedRequest = WalletInstanceAttestationRequestJwt.parse({
101
- payload: decodedRequest.payload,
102
- header: decodedRequest.protectedHeader,
103
- });
104
- const publicKey = parsedRequest.payload.cnf.jwk;
92
+ // 1. Get nonce from backend
93
+ const challenge = await api.get("/nonce").then((response) => response.nonce);
105
94
 
106
- await verifyJwt(signedAttestationRequest, publicKey);
95
+ // 2. Get a signed attestation request
96
+ const signedAttestationRequest = await getAttestationRequest(
97
+ challenge,
98
+ wiaCryptoContext,
99
+ integrityContext,
100
+ walletProviderBaseUrl
101
+ );
107
102
 
108
- const tokenUrl =
109
- walletProviderEntityConfiguration.payload.metadata.wallet_provider
110
- .token_endpoint;
111
- const requestBody = {
112
- grant_type:
113
- "urn:ietf:params:oauth:client-assertion-type:jwt-client-attestation",
114
- assertion: signedAttestationRequest,
115
- };
116
- const response = await appFetch(tokenUrl, {
117
- method: "POST",
118
- headers: {
119
- "Content-Type": "application/json",
103
+ // 3. Request WIA
104
+ const wia = await api
105
+ .post("/token", {
106
+ body: {
107
+ grant_type: "urn:ietf:params:oauth:grant-type:jwt-bearer",
108
+ assertion: signedAttestationRequest,
120
109
  },
121
- body: JSON.stringify(requestBody),
122
- });
110
+ })
111
+ .then((result) => z.string().parse(result))
112
+ .catch(handleAttestationCreationError);
123
113
 
124
- if (response.status !== 201) {
125
- throw new WalletInstanceAttestationIssuingError(
126
- "Unable to obtain wallet instance attestation from wallet provider",
127
- `Response code: ${response.status}`
128
- );
129
- }
114
+ return wia;
115
+ };
130
116
 
131
- const wia = await response.text();
117
+ const handleAttestationCreationError = (e: unknown) => {
118
+ if (!(e instanceof WalletProviderResponseError)) {
119
+ throw e;
120
+ }
132
121
 
133
- await verifyWalletInstanceAttestation(
134
- wia,
135
- walletProviderEntityConfiguration
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
136
127
  );
128
+ }
137
129
 
138
- return wia;
139
- };
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
+ };
@@ -33,7 +33,7 @@ export const WalletInstanceAttestationRequestJwt = z.object({
33
33
  header: z.intersection(
34
34
  Jwt.shape.header,
35
35
  z.object({
36
- typ: z.literal("wiar+jwt"),
36
+ typ: z.literal("war+jwt"),
37
37
  })
38
38
  ),
39
39
  payload: z.intersection(
@@ -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>;