@pagopa/io-react-native-wallet 0.27.1 → 0.28.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 (153) hide show
  1. package/lib/commonjs/client/generated/wallet-provider.js +27 -19
  2. package/lib/commonjs/client/generated/wallet-provider.js.map +1 -1
  3. package/lib/commonjs/credential/issuance/03-start-user-authorization.js +3 -0
  4. package/lib/commonjs/credential/issuance/03-start-user-authorization.js.map +1 -1
  5. package/lib/commonjs/credential/presentation/01-start-flow.js +14 -24
  6. package/lib/commonjs/credential/presentation/01-start-flow.js.map +1 -1
  7. package/lib/commonjs/credential/presentation/03-get-request-object.js +30 -42
  8. package/lib/commonjs/credential/presentation/03-get-request-object.js.map +1 -1
  9. package/lib/commonjs/credential/presentation/04-retrieve-rp-jwks.js +32 -0
  10. package/lib/commonjs/credential/presentation/04-retrieve-rp-jwks.js.map +1 -0
  11. package/lib/commonjs/credential/presentation/05-verify-request-object.js +53 -0
  12. package/lib/commonjs/credential/presentation/05-verify-request-object.js.map +1 -0
  13. package/lib/commonjs/credential/presentation/06-fetch-presentation-definition.js +39 -0
  14. package/lib/commonjs/credential/presentation/06-fetch-presentation-definition.js.map +1 -0
  15. package/lib/commonjs/credential/presentation/07-evaluate-dcql-query.js +125 -0
  16. package/lib/commonjs/credential/presentation/07-evaluate-dcql-query.js.map +1 -0
  17. package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js +289 -0
  18. package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js.map +1 -0
  19. package/lib/commonjs/credential/presentation/08-send-authorization-response.js +170 -0
  20. package/lib/commonjs/credential/presentation/08-send-authorization-response.js.map +1 -0
  21. package/lib/commonjs/credential/presentation/errors.js +69 -1
  22. package/lib/commonjs/credential/presentation/errors.js.map +1 -1
  23. package/lib/commonjs/credential/presentation/index.js +29 -1
  24. package/lib/commonjs/credential/presentation/index.js.map +1 -1
  25. package/lib/commonjs/credential/presentation/types.js +124 -3
  26. package/lib/commonjs/credential/presentation/types.js.map +1 -1
  27. package/lib/commonjs/sd-jwt/index.js +41 -1
  28. package/lib/commonjs/sd-jwt/index.js.map +1 -1
  29. package/lib/commonjs/trust/chain.js +35 -50
  30. package/lib/commonjs/trust/chain.js.map +1 -1
  31. package/lib/commonjs/trust/index.js +139 -16
  32. package/lib/commonjs/trust/index.js.map +1 -1
  33. package/lib/commonjs/trust/types.js +36 -12
  34. package/lib/commonjs/trust/types.js.map +1 -1
  35. package/lib/commonjs/trust/utils.js +41 -0
  36. package/lib/commonjs/trust/utils.js.map +1 -0
  37. package/lib/commonjs/utils/jwk.js +5 -1
  38. package/lib/commonjs/utils/jwk.js.map +1 -1
  39. package/lib/commonjs/wallet-instance/index.js +10 -0
  40. package/lib/commonjs/wallet-instance/index.js.map +1 -1
  41. package/lib/module/client/generated/wallet-provider.js +22 -15
  42. package/lib/module/client/generated/wallet-provider.js.map +1 -1
  43. package/lib/module/credential/issuance/03-start-user-authorization.js +3 -0
  44. package/lib/module/credential/issuance/03-start-user-authorization.js.map +1 -1
  45. package/lib/module/credential/presentation/01-start-flow.js +14 -24
  46. package/lib/module/credential/presentation/01-start-flow.js.map +1 -1
  47. package/lib/module/credential/presentation/03-get-request-object.js +31 -43
  48. package/lib/module/credential/presentation/03-get-request-object.js.map +1 -1
  49. package/lib/module/credential/presentation/04-retrieve-rp-jwks.js +25 -0
  50. package/lib/module/credential/presentation/04-retrieve-rp-jwks.js.map +1 -0
  51. package/lib/module/credential/presentation/05-verify-request-object.js +46 -0
  52. package/lib/module/credential/presentation/05-verify-request-object.js.map +1 -0
  53. package/lib/module/credential/presentation/06-fetch-presentation-definition.js +32 -0
  54. package/lib/module/credential/presentation/06-fetch-presentation-definition.js.map +1 -0
  55. package/lib/module/credential/presentation/07-evaluate-dcql-query.js +117 -0
  56. package/lib/module/credential/presentation/07-evaluate-dcql-query.js.map +1 -0
  57. package/lib/module/credential/presentation/07-evaluate-input-descriptor.js +278 -0
  58. package/lib/module/credential/presentation/07-evaluate-input-descriptor.js.map +1 -0
  59. package/lib/module/credential/presentation/08-send-authorization-response.js +158 -0
  60. package/lib/module/credential/presentation/08-send-authorization-response.js.map +1 -0
  61. package/lib/module/credential/presentation/errors.js +64 -0
  62. package/lib/module/credential/presentation/errors.js.map +1 -1
  63. package/lib/module/credential/presentation/index.js +6 -2
  64. package/lib/module/credential/presentation/index.js.map +1 -1
  65. package/lib/module/credential/presentation/types.js +121 -2
  66. package/lib/module/credential/presentation/types.js.map +1 -1
  67. package/lib/module/sd-jwt/index.js +40 -1
  68. package/lib/module/sd-jwt/index.js.map +1 -1
  69. package/lib/module/trust/chain.js +32 -46
  70. package/lib/module/trust/chain.js.map +1 -1
  71. package/lib/module/trust/index.js +139 -18
  72. package/lib/module/trust/index.js.map +1 -1
  73. package/lib/module/trust/types.js +34 -11
  74. package/lib/module/trust/types.js.map +1 -1
  75. package/lib/module/trust/utils.js +33 -0
  76. package/lib/module/trust/utils.js.map +1 -0
  77. package/lib/module/utils/jwk.js +3 -0
  78. package/lib/module/utils/jwk.js.map +1 -1
  79. package/lib/module/wallet-instance/index.js +9 -0
  80. package/lib/module/wallet-instance/index.js.map +1 -1
  81. package/lib/typescript/client/generated/wallet-provider.d.ts +91 -54
  82. package/lib/typescript/client/generated/wallet-provider.d.ts.map +1 -1
  83. package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts.map +1 -1
  84. package/lib/typescript/credential/presentation/01-start-flow.d.ts +26 -5
  85. package/lib/typescript/credential/presentation/01-start-flow.d.ts.map +1 -1
  86. package/lib/typescript/credential/presentation/03-get-request-object.d.ts +7 -10
  87. package/lib/typescript/credential/presentation/03-get-request-object.d.ts.map +1 -1
  88. package/lib/typescript/credential/presentation/04-retrieve-rp-jwks.d.ts +23 -0
  89. package/lib/typescript/credential/presentation/04-retrieve-rp-jwks.d.ts.map +1 -0
  90. package/lib/typescript/credential/presentation/05-verify-request-object.d.ts +18 -0
  91. package/lib/typescript/credential/presentation/05-verify-request-object.d.ts.map +1 -0
  92. package/lib/typescript/credential/presentation/06-fetch-presentation-definition.d.ts +21 -0
  93. package/lib/typescript/credential/presentation/06-fetch-presentation-definition.d.ts.map +1 -0
  94. package/lib/typescript/credential/presentation/07-evaluate-dcql-query.d.ts +20 -0
  95. package/lib/typescript/credential/presentation/07-evaluate-dcql-query.d.ts.map +1 -0
  96. package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts +88 -0
  97. package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts.map +1 -0
  98. package/lib/typescript/credential/presentation/08-send-authorization-response.d.ts +70 -0
  99. package/lib/typescript/credential/presentation/08-send-authorization-response.d.ts.map +1 -0
  100. package/lib/typescript/credential/presentation/errors.d.ts +44 -0
  101. package/lib/typescript/credential/presentation/errors.d.ts.map +1 -1
  102. package/lib/typescript/credential/presentation/index.d.ts +7 -3
  103. package/lib/typescript/credential/presentation/index.d.ts.map +1 -1
  104. package/lib/typescript/credential/presentation/types.d.ts +747 -10
  105. package/lib/typescript/credential/presentation/types.d.ts.map +1 -1
  106. package/lib/typescript/credential/status/types.d.ts +6 -6
  107. package/lib/typescript/sd-jwt/index.d.ts +31 -12
  108. package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
  109. package/lib/typescript/sd-jwt/types.d.ts +6 -6
  110. package/lib/typescript/trust/chain.d.ts +4 -9
  111. package/lib/typescript/trust/chain.d.ts.map +1 -1
  112. package/lib/typescript/trust/index.d.ts +337 -61
  113. package/lib/typescript/trust/index.d.ts.map +1 -1
  114. package/lib/typescript/trust/types.d.ts +4074 -407
  115. package/lib/typescript/trust/types.d.ts.map +1 -1
  116. package/lib/typescript/trust/utils.d.ts +12 -0
  117. package/lib/typescript/trust/utils.d.ts.map +1 -0
  118. package/lib/typescript/utils/decoder.d.ts +1 -1
  119. package/lib/typescript/utils/decoder.d.ts.map +1 -1
  120. package/lib/typescript/utils/jwk.d.ts +137 -0
  121. package/lib/typescript/utils/jwk.d.ts.map +1 -1
  122. package/lib/typescript/wallet-instance/index.d.ts +8 -0
  123. package/lib/typescript/wallet-instance/index.d.ts.map +1 -1
  124. package/lib/typescript/wallet-instance-attestation/types.d.ts +36 -36
  125. package/package.json +5 -2
  126. package/src/client/generated/wallet-provider.ts +28 -19
  127. package/src/credential/issuance/03-start-user-authorization.ts +3 -0
  128. package/src/credential/presentation/01-start-flow.ts +19 -26
  129. package/src/credential/presentation/03-get-request-object.ts +35 -58
  130. package/src/credential/presentation/04-retrieve-rp-jwks.ts +34 -0
  131. package/src/credential/presentation/05-verify-request-object.ts +52 -0
  132. package/src/credential/presentation/06-fetch-presentation-definition.ts +48 -0
  133. package/src/credential/presentation/07-evaluate-dcql-query.ts +166 -0
  134. package/src/credential/presentation/07-evaluate-input-descriptor.ts +391 -0
  135. package/src/credential/presentation/08-send-authorization-response.ts +220 -0
  136. package/src/credential/presentation/errors.ts +64 -0
  137. package/src/credential/presentation/index.ts +22 -1
  138. package/src/credential/presentation/types.ts +133 -2
  139. package/src/sd-jwt/index.ts +49 -1
  140. package/src/trust/chain.ts +46 -66
  141. package/src/trust/index.ts +185 -20
  142. package/src/trust/types.ts +34 -10
  143. package/src/trust/utils.ts +35 -0
  144. package/src/utils/decoder.ts +1 -1
  145. package/src/utils/jwk.ts +8 -1
  146. package/src/wallet-instance/index.ts +13 -0
  147. package/lib/commonjs/credential/presentation/04-send-authorization-response.js +0 -138
  148. package/lib/commonjs/credential/presentation/04-send-authorization-response.js.map +0 -1
  149. package/lib/module/credential/presentation/04-send-authorization-response.js +0 -128
  150. package/lib/module/credential/presentation/04-send-authorization-response.js.map +0 -1
  151. package/lib/typescript/credential/presentation/04-send-authorization-response.d.ts +0 -34
  152. package/lib/typescript/credential/presentation/04-send-authorization-response.d.ts.map +0 -1
  153. package/src/credential/presentation/04-send-authorization-response.ts +0 -168
@@ -1,168 +0,0 @@
1
- import { EncryptJwe, SignJWT } from "@pagopa/io-react-native-jwt";
2
- import { v4 as uuidv4 } from "uuid";
3
- import * as WalletInstanceAttestation from "../../wallet-instance-attestation";
4
- import type { JWK } from "@pagopa/io-react-native-jwt/lib/typescript/types";
5
- import { NoSuitableKeysFoundInEntityConfiguration } from "./errors";
6
- import { hasStatusOrThrow, type Out } from "../../utils/misc";
7
- import type { GetRequestObject } from "./03-get-request-object";
8
- import { disclose } from "../../sd-jwt";
9
- import type { EvaluateRelyingPartyTrust } from "./02-evaluate-rp-trust";
10
- import { type Presentation } from "./types";
11
- import * as z from "zod";
12
-
13
- export type AuthorizationResponse = z.infer<typeof AuthorizationResponse>;
14
- export const AuthorizationResponse = z.object({
15
- status: z.string(),
16
- response_code: z
17
- .string() /**
18
- FIXME: [SIW-627] we expect this value from every RP implementation
19
- Actually some RP does not return the value
20
- We make it optional to not break the flow.
21
- */
22
- .optional(),
23
- });
24
-
25
- /**
26
- * Choose an RSA public key from those offered by the RP for encryption.
27
- *
28
- * @param entity The RP entity configuration
29
- * @returns A suitable public key with its compatible encryption algorithm
30
- * @throws {NoSuitableKeysFoundInEntityConfiguration} If entity do not contain any public key suitable for encrypting
31
- */
32
- const chooseRSAPublicKeyToEncrypt = (
33
- entity: Out<EvaluateRelyingPartyTrust>["rpConf"]
34
- ): JWK => {
35
- const [usingRsa256] = entity.wallet_relying_party.jwks.keys.filter(
36
- (jwk) => jwk.use === "enc" && jwk.kty === "RSA"
37
- );
38
-
39
- if (usingRsa256) {
40
- return usingRsa256;
41
- }
42
-
43
- // No suitable key has been found
44
- throw new NoSuitableKeysFoundInEntityConfiguration(
45
- "Encrypt with RP public key"
46
- );
47
- };
48
-
49
- /**
50
- * Generate a Verified Presentation token for a received request object within the context of an authorization request flow.
51
- * The presentation is created by revealing data from the provided credentials based on the requested claims.
52
- * Each Verified Credential is accompanied by the claims that the user consents to disclose from it.
53
- *
54
- * @todo: Allow for handling more than one Verified Credential.
55
- */
56
- const prepareVpToken = async (
57
- requestObject: Out<GetRequestObject>["requestObject"],
58
- walletInstanceAttestation: string,
59
- [vc, claims, cryptoCtx]: Presentation // TODO: [SIW-353] support multiple presentations,
60
- ): Promise<{
61
- vp_token: string;
62
- presentation_submission: Record<string, unknown>;
63
- }> => {
64
- // this throws if vc cannot satisfy all the requested claims
65
- const { token: vp, paths } = await disclose(vc, claims);
66
-
67
- // obtain issuer from Wallet Instance
68
- const {
69
- payload: { iss },
70
- } = WalletInstanceAttestation.decode(walletInstanceAttestation);
71
-
72
- const pidKid = await cryptoCtx.getPublicKey().then((_) => _.kid);
73
-
74
- // TODO: [SIW-359] check all requeste claims of the requestedObj are satisfied
75
- const vp_token = await new SignJWT(cryptoCtx)
76
- .setProtectedHeader({
77
- typ: "JWT",
78
- kid: pidKid,
79
- })
80
- .setPayload({
81
- vp: vp,
82
- jti: `${uuidv4()}`,
83
- iss,
84
- nonce: requestObject.nonce,
85
- })
86
- .setAudience(requestObject.response_uri)
87
- .setIssuedAt()
88
- .setExpirationTime("1h")
89
- .sign();
90
-
91
- const vc_scope = requestObject.scope;
92
- const presentation_submission = {
93
- definition_id: `${uuidv4()}`,
94
- id: `${uuidv4()}`,
95
- descriptor_map: paths.map((p) => ({
96
- id: vc_scope,
97
- path: `$.vp_token.${p.path}`,
98
- format: "vc+sd-jwt",
99
- })),
100
- };
101
-
102
- return { vp_token, presentation_submission };
103
- };
104
-
105
- export type SendAuthorizationResponse = (
106
- requestObject: Out<GetRequestObject>["requestObject"],
107
- rpConf: Out<EvaluateRelyingPartyTrust>["rpConf"],
108
- presentation: Presentation, // TODO: [SIW-353] support multiple presentations
109
- context: {
110
- walletInstanceAttestation: string;
111
- appFetch?: GlobalFetch["fetch"];
112
- }
113
- ) => Promise<AuthorizationResponse>;
114
-
115
- /**
116
- * Complete the presentation flow by sending the authorization response to the Relying Party
117
- *
118
- * @param requestObject The Request Object that describes the presentation
119
- * @param rpConf The Relying Party's configuration
120
- * @param presentation The presentation tuple consisting in the signed credential,
121
- * the list of claims to be disclosed, and the context to access the key that proves the holder binding
122
- * @param context.walletInstanceAttestation The Wallet Instance Attestation token
123
- * @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
124
- * @returns The result of the presentation flow
125
- */
126
- export const sendAuthorizationResponse: SendAuthorizationResponse = async (
127
- requestObject,
128
- rpConf,
129
- presentation,
130
- { appFetch = fetch, walletInstanceAttestation }
131
- ): Promise<AuthorizationResponse> => {
132
- // the request is an unsigned jws without iss, aud, exp
133
- // https://openid.net/specs/openid-4-verifiable-presentations-1_0.html#name-signed-and-encrypted-respon
134
- const rsaPublicJwk = chooseRSAPublicKeyToEncrypt(rpConf);
135
-
136
- const { vp_token, presentation_submission } = await prepareVpToken(
137
- requestObject,
138
- walletInstanceAttestation,
139
- presentation
140
- );
141
-
142
- const authzResponsePayload = JSON.stringify({
143
- state: requestObject.state,
144
- presentation_submission,
145
- nonce: requestObject.nonce,
146
- vp_token,
147
- });
148
-
149
- const encrypted = await new EncryptJwe(authzResponsePayload, {
150
- alg: "RSA-OAEP-256",
151
- enc: "A256CBC-HS512",
152
- kid: rsaPublicJwk.kid,
153
- }).encrypt(rsaPublicJwk);
154
-
155
- const formBody = new URLSearchParams({ response: encrypted });
156
- const body = formBody.toString();
157
-
158
- return appFetch(requestObject.response_uri, {
159
- method: "POST",
160
- headers: {
161
- "Content-Type": "application/x-www-form-urlencoded",
162
- },
163
- body,
164
- })
165
- .then(hasStatusOrThrow(200))
166
- .then((res) => res.json())
167
- .then(AuthorizationResponse.parse);
168
- };