@pagopa/io-react-native-wallet 1.1.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. package/lib/commonjs/credential/presentation/01-start-flow.js +7 -5
  2. package/lib/commonjs/credential/presentation/01-start-flow.js.map +1 -1
  3. package/lib/commonjs/credential/presentation/03-get-request-object.js +47 -0
  4. package/lib/commonjs/credential/presentation/03-get-request-object.js.map +1 -0
  5. package/lib/commonjs/credential/presentation/04-retrieve-rp-jwks.js +82 -0
  6. package/lib/commonjs/credential/presentation/04-retrieve-rp-jwks.js.map +1 -0
  7. package/lib/commonjs/credential/presentation/05-verify-request-object.js +35 -0
  8. package/lib/commonjs/credential/presentation/05-verify-request-object.js.map +1 -0
  9. package/lib/commonjs/credential/presentation/06-fetch-presentation-definition.js +63 -0
  10. package/lib/commonjs/credential/presentation/06-fetch-presentation-definition.js.map +1 -0
  11. package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js +169 -0
  12. package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js.map +1 -0
  13. package/lib/commonjs/credential/presentation/08-send-authorization-response.js +202 -0
  14. package/lib/commonjs/credential/presentation/08-send-authorization-response.js.map +1 -0
  15. package/lib/commonjs/credential/presentation/README.md +43 -4
  16. package/lib/commonjs/credential/presentation/errors.js +52 -1
  17. package/lib/commonjs/credential/presentation/errors.js.map +1 -1
  18. package/lib/commonjs/credential/presentation/index.js +27 -6
  19. package/lib/commonjs/credential/presentation/index.js.map +1 -1
  20. package/lib/commonjs/credential/presentation/types.js +69 -4
  21. package/lib/commonjs/credential/presentation/types.js.map +1 -1
  22. package/lib/commonjs/entity/trust/types.js +4 -1
  23. package/lib/commonjs/entity/trust/types.js.map +1 -1
  24. package/lib/module/credential/presentation/01-start-flow.js +8 -6
  25. package/lib/module/credential/presentation/01-start-flow.js.map +1 -1
  26. package/lib/module/credential/presentation/03-get-request-object.js +39 -0
  27. package/lib/module/credential/presentation/03-get-request-object.js.map +1 -0
  28. package/lib/module/credential/presentation/04-retrieve-rp-jwks.js +75 -0
  29. package/lib/module/credential/presentation/04-retrieve-rp-jwks.js.map +1 -0
  30. package/lib/module/credential/presentation/05-verify-request-object.js +28 -0
  31. package/lib/module/credential/presentation/05-verify-request-object.js.map +1 -0
  32. package/lib/module/credential/presentation/06-fetch-presentation-definition.js +56 -0
  33. package/lib/module/credential/presentation/06-fetch-presentation-definition.js.map +1 -0
  34. package/lib/module/credential/presentation/07-evaluate-input-descriptor.js +161 -0
  35. package/lib/module/credential/presentation/07-evaluate-input-descriptor.js.map +1 -0
  36. package/lib/module/credential/presentation/08-send-authorization-response.js +188 -0
  37. package/lib/module/credential/presentation/08-send-authorization-response.js.map +1 -0
  38. package/lib/module/credential/presentation/README.md +43 -4
  39. package/lib/module/credential/presentation/errors.js +48 -0
  40. package/lib/module/credential/presentation/errors.js.map +1 -1
  41. package/lib/module/credential/presentation/index.js +7 -4
  42. package/lib/module/credential/presentation/index.js.map +1 -1
  43. package/lib/module/credential/presentation/types.js +67 -3
  44. package/lib/module/credential/presentation/types.js.map +1 -1
  45. package/lib/module/entity/trust/types.js +4 -1
  46. package/lib/module/entity/trust/types.js.map +1 -1
  47. package/lib/typescript/credential/presentation/01-start-flow.d.ts.map +1 -1
  48. package/lib/typescript/credential/presentation/{04-get-request-object.d.ts → 03-get-request-object.d.ts} +3 -5
  49. package/lib/typescript/credential/presentation/03-get-request-object.d.ts.map +1 -0
  50. package/lib/typescript/credential/presentation/{03-retrieve-jwks.d.ts → 04-retrieve-rp-jwks.d.ts} +6 -5
  51. package/lib/typescript/credential/presentation/04-retrieve-rp-jwks.d.ts.map +1 -0
  52. package/lib/typescript/credential/presentation/05-verify-request-object.d.ts +8 -0
  53. package/lib/typescript/credential/presentation/05-verify-request-object.d.ts.map +1 -0
  54. package/lib/typescript/credential/presentation/06-fetch-presentation-definition.d.ts +26 -0
  55. package/lib/typescript/credential/presentation/06-fetch-presentation-definition.d.ts.map +1 -0
  56. package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts +27 -0
  57. package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts.map +1 -0
  58. package/lib/typescript/credential/presentation/08-send-authorization-response.d.ts +99 -0
  59. package/lib/typescript/credential/presentation/08-send-authorization-response.d.ts.map +1 -0
  60. package/lib/typescript/credential/presentation/errors.d.ts +33 -0
  61. package/lib/typescript/credential/presentation/errors.d.ts.map +1 -1
  62. package/lib/typescript/credential/presentation/index.d.ts +8 -5
  63. package/lib/typescript/credential/presentation/index.d.ts.map +1 -1
  64. package/lib/typescript/credential/presentation/types.d.ts +612 -9
  65. package/lib/typescript/credential/presentation/types.d.ts.map +1 -1
  66. package/lib/typescript/entity/trust/index.d.ts +152 -0
  67. package/lib/typescript/entity/trust/index.d.ts.map +1 -1
  68. package/lib/typescript/entity/trust/types.d.ts +2088 -0
  69. package/lib/typescript/entity/trust/types.d.ts.map +1 -1
  70. package/package.json +5 -1
  71. package/src/credential/presentation/01-start-flow.ts +10 -6
  72. package/src/credential/presentation/{04-get-request-object.ts → 03-get-request-object.ts} +6 -51
  73. package/src/credential/presentation/04-retrieve-rp-jwks.ts +88 -0
  74. package/src/credential/presentation/05-verify-request-object.ts +35 -0
  75. package/src/credential/presentation/06-fetch-presentation-definition.ts +78 -0
  76. package/src/credential/presentation/07-evaluate-input-descriptor.ts +204 -0
  77. package/src/credential/presentation/08-send-authorization-response.ts +251 -0
  78. package/src/credential/presentation/README.md +43 -4
  79. package/src/credential/presentation/errors.ts +48 -0
  80. package/src/credential/presentation/index.ts +27 -9
  81. package/src/credential/presentation/types.ts +59 -3
  82. package/src/entity/trust/types.ts +3 -0
  83. package/lib/commonjs/credential/presentation/03-retrieve-jwks.js +0 -68
  84. package/lib/commonjs/credential/presentation/03-retrieve-jwks.js.map +0 -1
  85. package/lib/commonjs/credential/presentation/04-get-request-object.js +0 -82
  86. package/lib/commonjs/credential/presentation/04-get-request-object.js.map +0 -1
  87. package/lib/commonjs/credential/presentation/05-send-authorization-response.js +0 -139
  88. package/lib/commonjs/credential/presentation/05-send-authorization-response.js.map +0 -1
  89. package/lib/module/credential/presentation/03-retrieve-jwks.js +0 -61
  90. package/lib/module/credential/presentation/03-retrieve-jwks.js.map +0 -1
  91. package/lib/module/credential/presentation/04-get-request-object.js +0 -74
  92. package/lib/module/credential/presentation/04-get-request-object.js.map +0 -1
  93. package/lib/module/credential/presentation/05-send-authorization-response.js +0 -128
  94. package/lib/module/credential/presentation/05-send-authorization-response.js.map +0 -1
  95. package/lib/typescript/credential/presentation/03-retrieve-jwks.d.ts.map +0 -1
  96. package/lib/typescript/credential/presentation/04-get-request-object.d.ts.map +0 -1
  97. package/lib/typescript/credential/presentation/05-send-authorization-response.d.ts +0 -34
  98. package/lib/typescript/credential/presentation/05-send-authorization-response.d.ts.map +0 -1
  99. package/src/credential/presentation/03-retrieve-jwks.ts +0 -73
  100. package/src/credential/presentation/05-send-authorization-response.ts +0 -168
@@ -1,168 +0,0 @@
1
- import { EncryptJwe, SignJWT } from "@pagopa/io-react-native-jwt";
2
- import uuid from "react-native-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 "./04-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: `${uuid.v4()}`,
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: `${uuid.v4()}`,
94
- id: `${uuid.v4()}`,
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
- };