@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.
- package/lib/commonjs/client/generated/wallet-provider.js +27 -19
- package/lib/commonjs/client/generated/wallet-provider.js.map +1 -1
- package/lib/commonjs/credential/issuance/03-start-user-authorization.js +3 -0
- package/lib/commonjs/credential/issuance/03-start-user-authorization.js.map +1 -1
- package/lib/commonjs/credential/presentation/01-start-flow.js +14 -24
- package/lib/commonjs/credential/presentation/01-start-flow.js.map +1 -1
- package/lib/commonjs/credential/presentation/03-get-request-object.js +30 -42
- package/lib/commonjs/credential/presentation/03-get-request-object.js.map +1 -1
- package/lib/commonjs/credential/presentation/04-retrieve-rp-jwks.js +32 -0
- package/lib/commonjs/credential/presentation/04-retrieve-rp-jwks.js.map +1 -0
- package/lib/commonjs/credential/presentation/05-verify-request-object.js +53 -0
- package/lib/commonjs/credential/presentation/05-verify-request-object.js.map +1 -0
- package/lib/commonjs/credential/presentation/06-fetch-presentation-definition.js +39 -0
- package/lib/commonjs/credential/presentation/06-fetch-presentation-definition.js.map +1 -0
- package/lib/commonjs/credential/presentation/07-evaluate-dcql-query.js +125 -0
- package/lib/commonjs/credential/presentation/07-evaluate-dcql-query.js.map +1 -0
- package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js +289 -0
- package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js.map +1 -0
- package/lib/commonjs/credential/presentation/08-send-authorization-response.js +170 -0
- package/lib/commonjs/credential/presentation/08-send-authorization-response.js.map +1 -0
- package/lib/commonjs/credential/presentation/errors.js +69 -1
- package/lib/commonjs/credential/presentation/errors.js.map +1 -1
- package/lib/commonjs/credential/presentation/index.js +29 -1
- package/lib/commonjs/credential/presentation/index.js.map +1 -1
- package/lib/commonjs/credential/presentation/types.js +124 -3
- package/lib/commonjs/credential/presentation/types.js.map +1 -1
- package/lib/commonjs/sd-jwt/index.js +41 -1
- package/lib/commonjs/sd-jwt/index.js.map +1 -1
- package/lib/commonjs/trust/chain.js +35 -50
- package/lib/commonjs/trust/chain.js.map +1 -1
- package/lib/commonjs/trust/index.js +139 -16
- package/lib/commonjs/trust/index.js.map +1 -1
- package/lib/commonjs/trust/types.js +36 -12
- package/lib/commonjs/trust/types.js.map +1 -1
- package/lib/commonjs/trust/utils.js +41 -0
- package/lib/commonjs/trust/utils.js.map +1 -0
- package/lib/commonjs/utils/jwk.js +5 -1
- package/lib/commonjs/utils/jwk.js.map +1 -1
- package/lib/commonjs/wallet-instance/index.js +10 -0
- package/lib/commonjs/wallet-instance/index.js.map +1 -1
- package/lib/module/client/generated/wallet-provider.js +22 -15
- package/lib/module/client/generated/wallet-provider.js.map +1 -1
- package/lib/module/credential/issuance/03-start-user-authorization.js +3 -0
- package/lib/module/credential/issuance/03-start-user-authorization.js.map +1 -1
- package/lib/module/credential/presentation/01-start-flow.js +14 -24
- package/lib/module/credential/presentation/01-start-flow.js.map +1 -1
- package/lib/module/credential/presentation/03-get-request-object.js +31 -43
- package/lib/module/credential/presentation/03-get-request-object.js.map +1 -1
- package/lib/module/credential/presentation/04-retrieve-rp-jwks.js +25 -0
- package/lib/module/credential/presentation/04-retrieve-rp-jwks.js.map +1 -0
- package/lib/module/credential/presentation/05-verify-request-object.js +46 -0
- package/lib/module/credential/presentation/05-verify-request-object.js.map +1 -0
- package/lib/module/credential/presentation/06-fetch-presentation-definition.js +32 -0
- package/lib/module/credential/presentation/06-fetch-presentation-definition.js.map +1 -0
- package/lib/module/credential/presentation/07-evaluate-dcql-query.js +117 -0
- package/lib/module/credential/presentation/07-evaluate-dcql-query.js.map +1 -0
- package/lib/module/credential/presentation/07-evaluate-input-descriptor.js +278 -0
- package/lib/module/credential/presentation/07-evaluate-input-descriptor.js.map +1 -0
- package/lib/module/credential/presentation/08-send-authorization-response.js +158 -0
- package/lib/module/credential/presentation/08-send-authorization-response.js.map +1 -0
- package/lib/module/credential/presentation/errors.js +64 -0
- package/lib/module/credential/presentation/errors.js.map +1 -1
- package/lib/module/credential/presentation/index.js +6 -2
- package/lib/module/credential/presentation/index.js.map +1 -1
- package/lib/module/credential/presentation/types.js +121 -2
- package/lib/module/credential/presentation/types.js.map +1 -1
- package/lib/module/sd-jwt/index.js +40 -1
- package/lib/module/sd-jwt/index.js.map +1 -1
- package/lib/module/trust/chain.js +32 -46
- package/lib/module/trust/chain.js.map +1 -1
- package/lib/module/trust/index.js +139 -18
- package/lib/module/trust/index.js.map +1 -1
- package/lib/module/trust/types.js +34 -11
- package/lib/module/trust/types.js.map +1 -1
- package/lib/module/trust/utils.js +33 -0
- package/lib/module/trust/utils.js.map +1 -0
- package/lib/module/utils/jwk.js +3 -0
- package/lib/module/utils/jwk.js.map +1 -1
- package/lib/module/wallet-instance/index.js +9 -0
- package/lib/module/wallet-instance/index.js.map +1 -1
- package/lib/typescript/client/generated/wallet-provider.d.ts +91 -54
- package/lib/typescript/client/generated/wallet-provider.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/03-start-user-authorization.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/01-start-flow.d.ts +26 -5
- package/lib/typescript/credential/presentation/01-start-flow.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/03-get-request-object.d.ts +7 -10
- package/lib/typescript/credential/presentation/03-get-request-object.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/04-retrieve-rp-jwks.d.ts +23 -0
- 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 +18 -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 +21 -0
- package/lib/typescript/credential/presentation/06-fetch-presentation-definition.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/07-evaluate-dcql-query.d.ts +20 -0
- package/lib/typescript/credential/presentation/07-evaluate-dcql-query.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts +88 -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 +70 -0
- package/lib/typescript/credential/presentation/08-send-authorization-response.d.ts.map +1 -0
- package/lib/typescript/credential/presentation/errors.d.ts +44 -0
- package/lib/typescript/credential/presentation/errors.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/index.d.ts +7 -3
- package/lib/typescript/credential/presentation/index.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/types.d.ts +747 -10
- package/lib/typescript/credential/presentation/types.d.ts.map +1 -1
- package/lib/typescript/credential/status/types.d.ts +6 -6
- package/lib/typescript/sd-jwt/index.d.ts +31 -12
- package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
- package/lib/typescript/sd-jwt/types.d.ts +6 -6
- package/lib/typescript/trust/chain.d.ts +4 -9
- package/lib/typescript/trust/chain.d.ts.map +1 -1
- package/lib/typescript/trust/index.d.ts +337 -61
- package/lib/typescript/trust/index.d.ts.map +1 -1
- package/lib/typescript/trust/types.d.ts +4074 -407
- package/lib/typescript/trust/types.d.ts.map +1 -1
- package/lib/typescript/trust/utils.d.ts +12 -0
- package/lib/typescript/trust/utils.d.ts.map +1 -0
- package/lib/typescript/utils/decoder.d.ts +1 -1
- package/lib/typescript/utils/decoder.d.ts.map +1 -1
- package/lib/typescript/utils/jwk.d.ts +137 -0
- package/lib/typescript/utils/jwk.d.ts.map +1 -1
- package/lib/typescript/wallet-instance/index.d.ts +8 -0
- package/lib/typescript/wallet-instance/index.d.ts.map +1 -1
- package/lib/typescript/wallet-instance-attestation/types.d.ts +36 -36
- package/package.json +5 -2
- package/src/client/generated/wallet-provider.ts +28 -19
- package/src/credential/issuance/03-start-user-authorization.ts +3 -0
- package/src/credential/presentation/01-start-flow.ts +19 -26
- package/src/credential/presentation/03-get-request-object.ts +35 -58
- package/src/credential/presentation/04-retrieve-rp-jwks.ts +34 -0
- package/src/credential/presentation/05-verify-request-object.ts +52 -0
- package/src/credential/presentation/06-fetch-presentation-definition.ts +48 -0
- package/src/credential/presentation/07-evaluate-dcql-query.ts +166 -0
- package/src/credential/presentation/07-evaluate-input-descriptor.ts +391 -0
- package/src/credential/presentation/08-send-authorization-response.ts +220 -0
- package/src/credential/presentation/errors.ts +64 -0
- package/src/credential/presentation/index.ts +22 -1
- package/src/credential/presentation/types.ts +133 -2
- package/src/sd-jwt/index.ts +49 -1
- package/src/trust/chain.ts +46 -66
- package/src/trust/index.ts +185 -20
- package/src/trust/types.ts +34 -10
- package/src/trust/utils.ts +35 -0
- package/src/utils/decoder.ts +1 -1
- package/src/utils/jwk.ts +8 -1
- package/src/wallet-instance/index.ts +13 -0
- package/lib/commonjs/credential/presentation/04-send-authorization-response.js +0 -138
- package/lib/commonjs/credential/presentation/04-send-authorization-response.js.map +0 -1
- package/lib/module/credential/presentation/04-send-authorization-response.js +0 -128
- package/lib/module/credential/presentation/04-send-authorization-response.js.map +0 -1
- package/lib/typescript/credential/presentation/04-send-authorization-response.d.ts +0 -34
- package/lib/typescript/credential/presentation/04-send-authorization-response.d.ts.map +0 -1
- 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
|
-
};
|