@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.
- package/lib/commonjs/credential/presentation/01-start-flow.js +7 -5
- package/lib/commonjs/credential/presentation/01-start-flow.js.map +1 -1
- package/lib/commonjs/credential/presentation/03-get-request-object.js +47 -0
- package/lib/commonjs/credential/presentation/03-get-request-object.js.map +1 -0
- package/lib/commonjs/credential/presentation/04-retrieve-rp-jwks.js +82 -0
- package/lib/commonjs/credential/presentation/04-retrieve-rp-jwks.js.map +1 -0
- package/lib/commonjs/credential/presentation/05-verify-request-object.js +35 -0
- package/lib/commonjs/credential/presentation/05-verify-request-object.js.map +1 -0
- package/lib/commonjs/credential/presentation/06-fetch-presentation-definition.js +63 -0
- package/lib/commonjs/credential/presentation/06-fetch-presentation-definition.js.map +1 -0
- package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js +169 -0
- package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js.map +1 -0
- package/lib/commonjs/credential/presentation/08-send-authorization-response.js +202 -0
- package/lib/commonjs/credential/presentation/08-send-authorization-response.js.map +1 -0
- package/lib/commonjs/credential/presentation/README.md +43 -4
- package/lib/commonjs/credential/presentation/errors.js +52 -1
- package/lib/commonjs/credential/presentation/errors.js.map +1 -1
- package/lib/commonjs/credential/presentation/index.js +27 -6
- package/lib/commonjs/credential/presentation/index.js.map +1 -1
- package/lib/commonjs/credential/presentation/types.js +69 -4
- package/lib/commonjs/credential/presentation/types.js.map +1 -1
- package/lib/commonjs/entity/trust/types.js +4 -1
- package/lib/commonjs/entity/trust/types.js.map +1 -1
- package/lib/module/credential/presentation/01-start-flow.js +8 -6
- package/lib/module/credential/presentation/01-start-flow.js.map +1 -1
- package/lib/module/credential/presentation/03-get-request-object.js +39 -0
- package/lib/module/credential/presentation/03-get-request-object.js.map +1 -0
- package/lib/module/credential/presentation/04-retrieve-rp-jwks.js +75 -0
- package/lib/module/credential/presentation/04-retrieve-rp-jwks.js.map +1 -0
- package/lib/module/credential/presentation/05-verify-request-object.js +28 -0
- package/lib/module/credential/presentation/05-verify-request-object.js.map +1 -0
- package/lib/module/credential/presentation/06-fetch-presentation-definition.js +56 -0
- package/lib/module/credential/presentation/06-fetch-presentation-definition.js.map +1 -0
- package/lib/module/credential/presentation/07-evaluate-input-descriptor.js +161 -0
- package/lib/module/credential/presentation/07-evaluate-input-descriptor.js.map +1 -0
- package/lib/module/credential/presentation/08-send-authorization-response.js +188 -0
- package/lib/module/credential/presentation/08-send-authorization-response.js.map +1 -0
- package/lib/module/credential/presentation/README.md +43 -4
- package/lib/module/credential/presentation/errors.js +48 -0
- package/lib/module/credential/presentation/errors.js.map +1 -1
- package/lib/module/credential/presentation/index.js +7 -4
- package/lib/module/credential/presentation/index.js.map +1 -1
- package/lib/module/credential/presentation/types.js +67 -3
- package/lib/module/credential/presentation/types.js.map +1 -1
- package/lib/module/entity/trust/types.js +4 -1
- package/lib/module/entity/trust/types.js.map +1 -1
- package/lib/typescript/credential/presentation/01-start-flow.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/{04-get-request-object.d.ts → 03-get-request-object.d.ts} +3 -5
- package/lib/typescript/credential/presentation/03-get-request-object.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/{03-retrieve-jwks.d.ts → 04-retrieve-rp-jwks.d.ts} +6 -5
- package/lib/typescript/credential/presentation/04-retrieve-rp-jwks.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/05-verify-request-object.d.ts +8 -0
- package/lib/typescript/credential/presentation/05-verify-request-object.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/06-fetch-presentation-definition.d.ts +26 -0
- package/lib/typescript/credential/presentation/06-fetch-presentation-definition.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts +27 -0
- package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/08-send-authorization-response.d.ts +99 -0
- package/lib/typescript/credential/presentation/08-send-authorization-response.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/errors.d.ts +33 -0
- package/lib/typescript/credential/presentation/errors.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/index.d.ts +8 -5
- package/lib/typescript/credential/presentation/index.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/types.d.ts +612 -9
- package/lib/typescript/credential/presentation/types.d.ts.map +1 -1
- package/lib/typescript/entity/trust/index.d.ts +152 -0
- package/lib/typescript/entity/trust/index.d.ts.map +1 -1
- package/lib/typescript/entity/trust/types.d.ts +2088 -0
- package/lib/typescript/entity/trust/types.d.ts.map +1 -1
- package/package.json +5 -1
- package/src/credential/presentation/01-start-flow.ts +10 -6
- package/src/credential/presentation/{04-get-request-object.ts → 03-get-request-object.ts} +6 -51
- package/src/credential/presentation/04-retrieve-rp-jwks.ts +88 -0
- package/src/credential/presentation/05-verify-request-object.ts +35 -0
- package/src/credential/presentation/06-fetch-presentation-definition.ts +78 -0
- package/src/credential/presentation/07-evaluate-input-descriptor.ts +204 -0
- package/src/credential/presentation/08-send-authorization-response.ts +251 -0
- package/src/credential/presentation/README.md +43 -4
- package/src/credential/presentation/errors.ts +48 -0
- package/src/credential/presentation/index.ts +27 -9
- package/src/credential/presentation/types.ts +59 -3
- package/src/entity/trust/types.ts +3 -0
- package/lib/commonjs/credential/presentation/03-retrieve-jwks.js +0 -68
- package/lib/commonjs/credential/presentation/03-retrieve-jwks.js.map +0 -1
- package/lib/commonjs/credential/presentation/04-get-request-object.js +0 -82
- package/lib/commonjs/credential/presentation/04-get-request-object.js.map +0 -1
- package/lib/commonjs/credential/presentation/05-send-authorization-response.js +0 -139
- package/lib/commonjs/credential/presentation/05-send-authorization-response.js.map +0 -1
- package/lib/module/credential/presentation/03-retrieve-jwks.js +0 -61
- package/lib/module/credential/presentation/03-retrieve-jwks.js.map +0 -1
- package/lib/module/credential/presentation/04-get-request-object.js +0 -74
- package/lib/module/credential/presentation/04-get-request-object.js.map +0 -1
- package/lib/module/credential/presentation/05-send-authorization-response.js +0 -128
- package/lib/module/credential/presentation/05-send-authorization-response.js.map +0 -1
- package/lib/typescript/credential/presentation/03-retrieve-jwks.d.ts.map +0 -1
- package/lib/typescript/credential/presentation/04-get-request-object.d.ts.map +0 -1
- package/lib/typescript/credential/presentation/05-send-authorization-response.d.ts +0 -34
- package/lib/typescript/credential/presentation/05-send-authorization-response.d.ts.map +0 -1
- package/src/credential/presentation/03-retrieve-jwks.ts +0 -73
- 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
|
-
};
|