@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
@@ -0,0 +1,158 @@
|
|
1
|
+
import { EncryptJwe } from "@pagopa/io-react-native-jwt";
|
2
|
+
import uuid from "react-native-uuid";
|
3
|
+
import { getJwksFromConfig } from "./04-retrieve-rp-jwks";
|
4
|
+
import { NoSuitableKeysFoundInEntityConfiguration } from "./errors";
|
5
|
+
import { hasStatusOrThrow } from "../../utils/misc";
|
6
|
+
import * as z from "zod";
|
7
|
+
export const AuthorizationResponse = z.object({
|
8
|
+
status: z.string().optional(),
|
9
|
+
response_code: z.string() /**
|
10
|
+
FIXME: [SIW-627] we expect this value from every RP implementation
|
11
|
+
Actually some RP does not return the value
|
12
|
+
We make it optional to not break the flow.
|
13
|
+
*/.optional(),
|
14
|
+
redirect_uri: z.string().optional()
|
15
|
+
});
|
16
|
+
|
17
|
+
/**
|
18
|
+
* Selects a public key (with `use = enc`) from the set of JWK keys
|
19
|
+
* offered by the Relying Party (RP) for encryption.
|
20
|
+
*
|
21
|
+
* @param rpJwkKeys - The array of JWKs retrieved from the RP entity configuration.
|
22
|
+
* @returns The first suitable public key found in the list.
|
23
|
+
* @throws {NoSuitableKeysFoundInEntityConfiguration} If no suitable encryption key is found.
|
24
|
+
*/
|
25
|
+
export const choosePublicKeyToEncrypt = rpJwkKeys => {
|
26
|
+
const encKey = rpJwkKeys.find(jwk => jwk.use === "enc");
|
27
|
+
if (encKey) {
|
28
|
+
return encKey;
|
29
|
+
}
|
30
|
+
|
31
|
+
// No suitable key found
|
32
|
+
throw new NoSuitableKeysFoundInEntityConfiguration("No suitable public key found for encryption.");
|
33
|
+
};
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Builds a URL-encoded form body for a direct POST response using JWT encryption.
|
37
|
+
*
|
38
|
+
* @param jwkKeys - Array of JWKs from the Relying Party for encryption.
|
39
|
+
* @param requestObject - Contains state, nonce, and other relevant info.
|
40
|
+
* @param payload - Object that contains the VP token to encrypt and the mapping of the credential disclosures
|
41
|
+
* @returns A URL-encoded string for an `application/x-www-form-urlencoded` POST body, where `response` contains the encrypted JWE.
|
42
|
+
*/
|
43
|
+
export const buildDirectPostJwtBody = async (requestObject, rpConf, payload) => {
|
44
|
+
// Prepare the authorization response payload to be encrypted
|
45
|
+
const authzResponsePayload = JSON.stringify({
|
46
|
+
state: requestObject.state,
|
47
|
+
...payload
|
48
|
+
});
|
49
|
+
|
50
|
+
// Choose a suitable public key for encryption
|
51
|
+
const {
|
52
|
+
keys
|
53
|
+
} = getJwksFromConfig(rpConf.metadata);
|
54
|
+
const encPublicJwk = choosePublicKeyToEncrypt(keys);
|
55
|
+
|
56
|
+
// Encrypt the authorization payload
|
57
|
+
const {
|
58
|
+
authorization_encrypted_response_alg,
|
59
|
+
authorization_encrypted_response_enc
|
60
|
+
} = rpConf.metadata.openid_credential_verifier;
|
61
|
+
const encryptedResponse = await new EncryptJwe(authzResponsePayload, {
|
62
|
+
alg: authorization_encrypted_response_alg || "RSA-OAEP-256",
|
63
|
+
enc: authorization_encrypted_response_enc || "A256CBC-HS512",
|
64
|
+
kid: encPublicJwk.kid
|
65
|
+
}).encrypt(encPublicJwk);
|
66
|
+
|
67
|
+
// Build the x-www-form-urlencoded form body
|
68
|
+
const formBody = new URLSearchParams({
|
69
|
+
response: encryptedResponse,
|
70
|
+
...(requestObject.state ? {
|
71
|
+
state: requestObject.state
|
72
|
+
} : {})
|
73
|
+
});
|
74
|
+
return formBody.toString();
|
75
|
+
};
|
76
|
+
|
77
|
+
/**
|
78
|
+
* Type definition for the function that sends the authorization response
|
79
|
+
* to the Relying Party, completing the presentation flow.
|
80
|
+
* Use with `presentation_definition`.
|
81
|
+
* @deprecated Use `sendAuthorizationResponse`
|
82
|
+
*/
|
83
|
+
|
84
|
+
/**
|
85
|
+
* Sends the authorization response to the Relying Party (RP) using the specified `response_mode`.
|
86
|
+
* This function completes the presentation flow in an OpenID 4 Verifiable Presentations scenario.
|
87
|
+
*
|
88
|
+
* @param requestObject - The request details, including presentation requirements.
|
89
|
+
* @param presentationDefinition - The definition of the expected presentation.
|
90
|
+
* @param jwkKeys - Array of JWKs from the Relying Party for optional encryption.
|
91
|
+
* @param presentation - Tuple with verifiable credential, claims, and crypto context.
|
92
|
+
* @param context - Contains optional custom fetch implementation.
|
93
|
+
* @returns Parsed and validated authorization response from the Relying Party.
|
94
|
+
*/
|
95
|
+
export const sendLegacyAuthorizationResponse = async function (requestObject, presentationDefinitionId, remotePresentations, rpConf) {
|
96
|
+
var _remotePresentations$;
|
97
|
+
let {
|
98
|
+
appFetch = fetch
|
99
|
+
} = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : {};
|
100
|
+
/**
|
101
|
+
* 1. Prepare the VP token and presentation submission
|
102
|
+
* If there is only one credential, `vpToken` is a single string.
|
103
|
+
* If there are multiple credential, `vpToken` is an array of string.
|
104
|
+
**/
|
105
|
+
const vp_token = (remotePresentations === null || remotePresentations === void 0 ? void 0 : remotePresentations.length) === 1 ? (_remotePresentations$ = remotePresentations[0]) === null || _remotePresentations$ === void 0 ? void 0 : _remotePresentations$.vpToken : remotePresentations.map(remotePresentation => remotePresentation.vpToken);
|
106
|
+
const descriptor_map = remotePresentations.map((remotePresentation, index) => ({
|
107
|
+
id: remotePresentation.inputDescriptor.id,
|
108
|
+
path: remotePresentations.length === 1 ? `$` : `$[${index}]`,
|
109
|
+
format: remotePresentation.format
|
110
|
+
}));
|
111
|
+
const presentation_submission = {
|
112
|
+
id: uuid.v4(),
|
113
|
+
definition_id: presentationDefinitionId,
|
114
|
+
descriptor_map
|
115
|
+
};
|
116
|
+
const requestBody = await buildDirectPostJwtBody(requestObject, rpConf, {
|
117
|
+
vp_token,
|
118
|
+
presentation_submission
|
119
|
+
});
|
120
|
+
|
121
|
+
// 3. Send the authorization response via HTTP POST and validate the response
|
122
|
+
return await appFetch(requestObject.response_uri, {
|
123
|
+
method: "POST",
|
124
|
+
headers: {
|
125
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
126
|
+
},
|
127
|
+
body: requestBody
|
128
|
+
}).then(hasStatusOrThrow(200)).then(res => res.json()).then(AuthorizationResponse.parse);
|
129
|
+
};
|
130
|
+
|
131
|
+
/**
|
132
|
+
* Type definition for the function that sends the authorization response
|
133
|
+
* to the Relying Party, completing the presentation flow.
|
134
|
+
* Use with DCQL queries.
|
135
|
+
*/
|
136
|
+
|
137
|
+
export const sendAuthorizationResponse = async function (requestObject, remotePresentations, rpConf) {
|
138
|
+
let {
|
139
|
+
appFetch = fetch
|
140
|
+
} = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
141
|
+
// 1. Prepare the VP token as a JSON object with keys corresponding to the DCQL query credential IDs
|
142
|
+
const requestBody = await buildDirectPostJwtBody(requestObject, rpConf, {
|
143
|
+
vp_token: remotePresentations.reduce((acc, presentation) => ({
|
144
|
+
...acc,
|
145
|
+
[presentation.credentialId]: presentation.vpToken
|
146
|
+
}), {})
|
147
|
+
});
|
148
|
+
|
149
|
+
// 2. Send the authorization response via HTTP POST and validate the response
|
150
|
+
return await appFetch(requestObject.response_uri, {
|
151
|
+
method: "POST",
|
152
|
+
headers: {
|
153
|
+
"Content-Type": "application/x-www-form-urlencoded"
|
154
|
+
},
|
155
|
+
body: requestBody
|
156
|
+
}).then(hasStatusOrThrow(200)).then(res => res.json()).then(AuthorizationResponse.parse);
|
157
|
+
};
|
158
|
+
//# sourceMappingURL=08-send-authorization-response.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["EncryptJwe","uuid","getJwksFromConfig","NoSuitableKeysFoundInEntityConfiguration","hasStatusOrThrow","z","AuthorizationResponse","object","status","string","optional","response_code","redirect_uri","choosePublicKeyToEncrypt","rpJwkKeys","encKey","find","jwk","use","buildDirectPostJwtBody","requestObject","rpConf","payload","authzResponsePayload","JSON","stringify","state","keys","metadata","encPublicJwk","authorization_encrypted_response_alg","authorization_encrypted_response_enc","openid_credential_verifier","encryptedResponse","alg","enc","kid","encrypt","formBody","URLSearchParams","response","toString","sendLegacyAuthorizationResponse","presentationDefinitionId","remotePresentations","_remotePresentations$","appFetch","fetch","arguments","length","undefined","vp_token","vpToken","map","remotePresentation","descriptor_map","index","id","inputDescriptor","path","format","presentation_submission","v4","definition_id","requestBody","response_uri","method","headers","body","then","res","json","parse","sendAuthorizationResponse","reduce","acc","presentation","credentialId"],"sourceRoot":"../../../../src","sources":["credential/presentation/08-send-authorization-response.ts"],"mappings":"AAAA,SAASA,UAAU,QAAQ,6BAA6B;AACxD,OAAOC,IAAI,MAAM,mBAAmB;AACpC,SAASC,iBAAiB,QAAwB,uBAAuB;AAEzE,SAASC,wCAAwC,QAAQ,UAAU;AACnE,SAASC,gBAAgB,QAAkB,kBAAkB;AAO7D,OAAO,KAAKC,CAAC,MAAM,KAAK;AAKxB,OAAO,MAAMC,qBAAqB,GAAGD,CAAC,CAACE,M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,aAAa,CAAC6C,YAAY,EAAE;IAChDC,MAAM,EAAE,MAAM;IACdC,OAAO,EAAE;MACP,cAAc,EAAE;IAClB,CAAC;IACDC,IAAI,EAAEJ;EACR,CAAC,CAAC,CACCK,IAAI,CAACjE,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAC3BiE,IAAI,CAAEC,GAAG,IAAKA,GAAG,CAACC,IAAI,CAAC,CAAC,CAAC,CACzBF,IAAI,CAAC/D,qBAAqB,CAACkE,KAAK,CAAC;AACtC,CAAC"}
|
@@ -39,4 +39,68 @@ export class NoSuitableKeysFoundInEntityConfiguration extends IoWalletError {
|
|
39
39
|
super(message);
|
40
40
|
}
|
41
41
|
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* When a QR code is not valid.
|
45
|
+
*
|
46
|
+
*/
|
47
|
+
export class InvalidQRCodeError extends IoWalletError {
|
48
|
+
code = "ERR_INVALID_QR_CODE";
|
49
|
+
|
50
|
+
/**
|
51
|
+
* @param detail A description of why the QR code is considered invalid.
|
52
|
+
*/
|
53
|
+
constructor(detail) {
|
54
|
+
const message = `QR code is not valid: ${detail}.`;
|
55
|
+
super(message);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
/**
|
60
|
+
* When the entity is unverified because the Relying Party is not trusted.
|
61
|
+
*
|
62
|
+
*/
|
63
|
+
export class UnverifiedEntityError extends IoWalletError {
|
64
|
+
code = "ERR_UNVERIFIED_RP_ENTITY";
|
65
|
+
|
66
|
+
/**
|
67
|
+
* @param reason A description of why the entity cannot be verified.
|
68
|
+
*/
|
69
|
+
constructor(reason) {
|
70
|
+
const message = `Unverified entity: ${reason}.`;
|
71
|
+
super(message);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
/**
|
76
|
+
* When some required data is missing to continue because certain attributes are not contained inside the wallet.
|
77
|
+
*
|
78
|
+
*/
|
79
|
+
export class MissingDataError extends IoWalletError {
|
80
|
+
code = "ERR_MISSING_DATA";
|
81
|
+
|
82
|
+
/**
|
83
|
+
* @param missingAttributes An array or description of the attributes that are missing.
|
84
|
+
*/
|
85
|
+
constructor(missingAttributes) {
|
86
|
+
const message = `Some required data is missing: ${missingAttributes}.`;
|
87
|
+
super(message);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
/**
|
92
|
+
* When a credential is not found in the wallet.
|
93
|
+
*
|
94
|
+
*/
|
95
|
+
export class CredentialNotFoundError extends IoWalletError {
|
96
|
+
code = "ERR_CREDENTIAL_NOT_FOUND";
|
97
|
+
|
98
|
+
/**
|
99
|
+
* @param credentialId The ID of the credential that was not found.
|
100
|
+
*/
|
101
|
+
constructor(credentialId) {
|
102
|
+
const message = `Credential not found: ${credentialId}.`;
|
103
|
+
super(message);
|
104
|
+
}
|
105
|
+
}
|
42
106
|
//# sourceMappingURL=errors.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["IoWalletError","serializeAttrs","AuthRequestDecodeError","code","constructor","message","claim","arguments","length","undefined","reason","NoSuitableKeysFoundInEntityConfiguration","scenario"],"sourceRoot":"../../../../src","sources":["credential/presentation/errors.ts"],"mappings":"AAAA,SAASA,aAAa,EAAEC,cAAc,QAAQ,oBAAoB;;AAElE;AACA;AACA;AACA;AACA,OAAO,MAAMC,sBAAsB,SAASF,aAAa,CAAC;EACxDG,IAAI,GAAG,oDAAoD;;EAE3D;;EAGA;;EAGAC,WAAWA,CACTC,OAAe,EAGf;IAAA,IAFAC,KAAa,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,aAAa;IAAA,IAC7BG,MAAc,GAAAH,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,aAAa;IAE9B,KAAK,CAACN,cAAc,CAAC;MAAEI,OAAO;MAAEC,KAAK;MAAEI;IAAO,CAAC,CAAC,CAAC;IACjD,IAAI,CAACJ,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACI,MAAM,GAAGA,MAAM;EACtB;AACF;;AAEA;AACA;AACA;AACA;AACA,OAAO,MAAMC,wCAAwC,SAASX,aAAa,CAAC;EAC1EG,IAAI,GAAG,gCAAgC;;EAEvC;AACF;AACA;EACEC,WAAWA,CAACQ,QAAgB,EAAE;IAC5B,MAAMP,OAAO,GAAI,0DAAyDO,QAAS,IAAG;IACtF,KAAK,CAACP,OAAO,CAAC;EAChB;AACF"}
|
1
|
+
{"version":3,"names":["IoWalletError","serializeAttrs","AuthRequestDecodeError","code","constructor","message","claim","arguments","length","undefined","reason","NoSuitableKeysFoundInEntityConfiguration","scenario","InvalidQRCodeError","detail","UnverifiedEntityError","MissingDataError","missingAttributes","CredentialNotFoundError","credentialId"],"sourceRoot":"../../../../src","sources":["credential/presentation/errors.ts"],"mappings":"AAAA,SAASA,aAAa,EAAEC,cAAc,QAAQ,oBAAoB;;AAElE;AACA;AACA;AACA;AACA,OAAO,MAAMC,sBAAsB,SAASF,aAAa,CAAC;EACxDG,IAAI,GAAG,oDAAoD;;EAE3D;;EAGA;;EAGAC,WAAWA,CACTC,OAAe,EAGf;IAAA,IAFAC,KAAa,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,aAAa;IAAA,IAC7BG,MAAc,GAAAH,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,aAAa;IAE9B,KAAK,CAACN,cAAc,CAAC;MAAEI,OAAO;MAAEC,KAAK;MAAEI;IAAO,CAAC,CAAC,CAAC;IACjD,IAAI,CAACJ,KAAK,GAAGA,KAAK;IAClB,IAAI,CAACI,MAAM,GAAGA,MAAM;EACtB;AACF;;AAEA;AACA;AACA;AACA;AACA,OAAO,MAAMC,wCAAwC,SAASX,aAAa,CAAC;EAC1EG,IAAI,GAAG,gCAAgC;;EAEvC;AACF;AACA;EACEC,WAAWA,CAACQ,QAAgB,EAAE;IAC5B,MAAMP,OAAO,GAAI,0DAAyDO,QAAS,IAAG;IACtF,KAAK,CAACP,OAAO,CAAC;EAChB;AACF;;AAEA;AACA;AACA;AACA;AACA,OAAO,MAAMQ,kBAAkB,SAASb,aAAa,CAAC;EACpDG,IAAI,GAAG,qBAAqB;;EAE5B;AACF;AACA;EACEC,WAAWA,CAACU,MAAc,EAAE;IAC1B,MAAMT,OAAO,GAAI,yBAAwBS,MAAO,GAAE;IAClD,KAAK,CAACT,OAAO,CAAC;EAChB;AACF;;AAEA;AACA;AACA;AACA;AACA,OAAO,MAAMU,qBAAqB,SAASf,aAAa,CAAC;EACvDG,IAAI,GAAG,0BAA0B;;EAEjC;AACF;AACA;EACEC,WAAWA,CAACM,MAAc,EAAE;IAC1B,MAAML,OAAO,GAAI,sBAAqBK,MAAO,GAAE;IAC/C,KAAK,CAACL,OAAO,CAAC;EAChB;AACF;;AAEA;AACA;AACA;AACA;AACA,OAAO,MAAMW,gBAAgB,SAAShB,aAAa,CAAC;EAClDG,IAAI,GAAG,kBAAkB;;EAEzB;AACF;AACA;EACEC,WAAWA,CAACa,iBAAyB,EAAE;IACrC,MAAMZ,OAAO,GAAI,kCAAiCY,iBAAkB,GAAE;IACtE,KAAK,CAACZ,OAAO,CAAC;EAChB;AACF;;AAEA;AACA;AACA;AACA;AACA,OAAO,MAAMa,uBAAuB,SAASlB,aAAa,CAAC;EACzDG,IAAI,GAAG,0BAA0B;;EAEjC;AACF;AACA;EACEC,WAAWA,CAACe,YAAoB,EAAE;IAChC,MAAMd,OAAO,GAAI,yBAAwBc,YAAa,GAAE;IACxD,KAAK,CAACd,OAAO,CAAC;EAChB;AACF"}
|
@@ -1,7 +1,11 @@
|
|
1
1
|
import { startFlowFromQR } from "./01-start-flow";
|
2
2
|
import { evaluateRelyingPartyTrust } from "./02-evaluate-rp-trust";
|
3
3
|
import { getRequestObject } from "./03-get-request-object";
|
4
|
-
import {
|
4
|
+
import { getJwksFromConfig } from "./04-retrieve-rp-jwks";
|
5
|
+
import { verifyRequestObject } from "./05-verify-request-object";
|
6
|
+
import { fetchPresentDefinition } from "./06-fetch-presentation-definition";
|
7
|
+
import { evaluateInputDescriptorForSdJwt4VC } from "./07-evaluate-input-descriptor";
|
8
|
+
import { sendAuthorizationResponse } from "./08-send-authorization-response";
|
5
9
|
import * as Errors from "./errors";
|
6
|
-
export { startFlowFromQR, evaluateRelyingPartyTrust, getRequestObject, sendAuthorizationResponse, Errors };
|
10
|
+
export { startFlowFromQR, evaluateRelyingPartyTrust, getRequestObject, getJwksFromConfig, verifyRequestObject, fetchPresentDefinition, evaluateInputDescriptorForSdJwt4VC, sendAuthorizationResponse, Errors };
|
7
11
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["startFlowFromQR","evaluateRelyingPartyTrust","getRequestObject","sendAuthorizationResponse","Errors"],"sourceRoot":"../../../../src","sources":["credential/presentation/index.ts"],"mappings":"AAAA,SAASA,eAAe,QAAwB,iBAAiB;AACjE,SACEC,yBAAyB,QAEpB,wBAAwB;AAC/B,SACEC,gBAAgB,QAEX,yBAAyB;AAChC,SACEC,yBAAyB,QAEpB,kCAAkC;AACzC,OAAO,KAAKC,MAAM,MAAM,UAAU;AAElC,
|
1
|
+
{"version":3,"names":["startFlowFromQR","evaluateRelyingPartyTrust","getRequestObject","getJwksFromConfig","verifyRequestObject","fetchPresentDefinition","evaluateInputDescriptorForSdJwt4VC","sendAuthorizationResponse","Errors"],"sourceRoot":"../../../../src","sources":["credential/presentation/index.ts"],"mappings":"AAAA,SAASA,eAAe,QAAwB,iBAAiB;AACjE,SACEC,yBAAyB,QAEpB,wBAAwB;AAC/B,SACEC,gBAAgB,QAEX,yBAAyB;AAChC,SAASC,iBAAiB,QAAwB,uBAAuB;AACzE,SACEC,mBAAmB,QAEd,4BAA4B;AACnC,SACEC,sBAAsB,QAEjB,oCAAoC;AAC3C,SACEC,kCAAkC,QAE7B,gCAAgC;AACvC,SACEC,yBAAyB,QAEpB,kCAAkC;AACzC,OAAO,KAAKC,MAAM,MAAM,UAAU;AAElC,SACER,eAAe,EACfC,yBAAyB,EACzBC,gBAAgB,EAChBC,iBAAiB,EACjBC,mBAAmB,EACnBC,sBAAsB,EACtBC,kCAAkC,EAClCC,yBAAyB,EACzBC,MAAM"}
|
@@ -5,6 +5,80 @@ import * as z from "zod";
|
|
5
5
|
* A pair that associate a tokenized Verified Credential with the claims presented or requested to present.
|
6
6
|
*/
|
7
7
|
|
8
|
+
/**
|
9
|
+
* A object that associate the information needed to multiple remote presentation
|
10
|
+
* Used with `presentation_definition`
|
11
|
+
* @deprecated Use `RemotePresentation`
|
12
|
+
*/
|
13
|
+
|
14
|
+
/**
|
15
|
+
* A object that associate the information needed to multiple remote presentation
|
16
|
+
* Used with DCQL queries
|
17
|
+
*/
|
18
|
+
|
19
|
+
const Fields = z.object({
|
20
|
+
path: z.array(z.string().min(1)),
|
21
|
+
// Array of JSONPath string expressions
|
22
|
+
id: z.string().optional(),
|
23
|
+
// Unique string ID
|
24
|
+
purpose: z.string().optional(),
|
25
|
+
// Purpose of the field
|
26
|
+
name: z.string().optional(),
|
27
|
+
// Human-friendly name
|
28
|
+
filter: z.any().optional(),
|
29
|
+
// JSON Schema descriptor for filtering
|
30
|
+
optional: z.boolean().optional(),
|
31
|
+
// Boolean indicating if the field is optional
|
32
|
+
intent_to_retain: z.boolean().optional() // Boolean indicating that the Verifier intends to retain the Claim's data being requested
|
33
|
+
});
|
34
|
+
|
35
|
+
// Define the Constraints Object Schema
|
36
|
+
const Constraints = z.object({
|
37
|
+
fields: z.array(Fields).optional(),
|
38
|
+
// Array of Field Objects
|
39
|
+
limit_disclosure: z.enum(["required", "preferred"]).optional() // Limit disclosure property
|
40
|
+
});
|
41
|
+
|
42
|
+
// Define the Input Descriptor Object Schema
|
43
|
+
|
44
|
+
export const InputDescriptor = z.object({
|
45
|
+
id: z.string().min(1),
|
46
|
+
// Mandatory unique string ID
|
47
|
+
name: z.string().optional(),
|
48
|
+
// Human-friendly name
|
49
|
+
purpose: z.string().optional(),
|
50
|
+
// Purpose of the schema
|
51
|
+
format: z.record(z.string(), z.any()).optional(),
|
52
|
+
// Object with Claim Format Designations
|
53
|
+
constraints: Constraints,
|
54
|
+
// Constraints Object (mandatory)
|
55
|
+
group: z.string().optional() // Match one of the grouping strings listed in the "from" values of a Submission Requirement Rule
|
56
|
+
});
|
57
|
+
|
58
|
+
const SubmissionRequirement = z.object({
|
59
|
+
name: z.string().optional(),
|
60
|
+
purpose: z.string().optional(),
|
61
|
+
rule: z.string(),
|
62
|
+
// "all": all group's rules must be present, or "pick": at least group's "count" rules must be present
|
63
|
+
from: z.string().optional(),
|
64
|
+
// MUST contain either a "from" or "from_nested" property
|
65
|
+
from_nested: z.array(z.object({
|
66
|
+
name: z.string().optional(),
|
67
|
+
purpose: z.string().optional(),
|
68
|
+
rule: z.string(),
|
69
|
+
from: z.string()
|
70
|
+
})).optional(),
|
71
|
+
count: z.number().optional()
|
72
|
+
//"count", "min", and "max" may be present with a "pick" rule
|
73
|
+
});
|
74
|
+
|
75
|
+
export const PresentationDefinition = z.object({
|
76
|
+
id: z.string(),
|
77
|
+
name: z.string().optional(),
|
78
|
+
purpose: z.string().optional(),
|
79
|
+
input_descriptors: z.array(InputDescriptor),
|
80
|
+
submission_requirements: z.array(SubmissionRequirement).optional()
|
81
|
+
});
|
8
82
|
export const RequestObject = z.object({
|
9
83
|
iss: z.string(),
|
10
84
|
iat: UnixTime,
|
@@ -12,10 +86,55 @@ export const RequestObject = z.object({
|
|
12
86
|
state: z.string(),
|
13
87
|
nonce: z.string(),
|
14
88
|
response_uri: z.string(),
|
89
|
+
response_uri_method: z.string().optional(),
|
15
90
|
response_type: z.literal("vp_token"),
|
16
91
|
response_mode: z.literal("direct_post.jwt"),
|
17
92
|
client_id: z.string(),
|
18
|
-
|
19
|
-
|
93
|
+
dcql_query: z.record(z.string(), z.any()).optional(),
|
94
|
+
// Validation happens within the `dcql` library, no need to duplicate it here
|
95
|
+
scope: z.string().optional(),
|
96
|
+
presentation_definition: PresentationDefinition.optional()
|
97
|
+
});
|
98
|
+
export const WalletMetadata = z.object({
|
99
|
+
presentation_definition_uri_supported: z.boolean().optional(),
|
100
|
+
client_id_schemes_supported: z.array(z.string()).optional(),
|
101
|
+
request_object_signing_alg_values_supported: z.array(z.string()).optional(),
|
102
|
+
vp_formats_supported: z.record(z.string(),
|
103
|
+
// TODO [SIW-2110]: use explicit credential format?
|
104
|
+
z.object({
|
105
|
+
"sd-jwt_alg_values": z.array(z.string()).optional() // alg_values_supported?
|
106
|
+
}))
|
107
|
+
// TODO [SIW-2110]: include other metadata?
|
108
|
+
});
|
109
|
+
|
110
|
+
/**
|
111
|
+
* Wallet capabilities that must be submitted to get the Request Object
|
112
|
+
* via POST request when the `request_uri_method` is `post`.
|
113
|
+
*/
|
114
|
+
|
115
|
+
export const RequestObjectWalletCapabilities = z.object({
|
116
|
+
wallet_metadata: WalletMetadata,
|
117
|
+
wallet_nonce: z.string().optional()
|
118
|
+
});
|
119
|
+
|
120
|
+
/**
|
121
|
+
* Authorization Response payload when using `presentation_definition`.
|
122
|
+
* @deprecated Use `DirectAuthorizationBodyPayload`
|
123
|
+
*/
|
124
|
+
|
125
|
+
/**
|
126
|
+
* @deprecated Use `DirectAuthorizationBodyPayload`
|
127
|
+
*/
|
128
|
+
export const LegacyDirectAuthorizationBodyPayload = z.object({
|
129
|
+
vp_token: z.union([z.string(), z.array(z.string())]).optional(),
|
130
|
+
presentation_submission: z.record(z.string(), z.unknown())
|
131
|
+
});
|
132
|
+
|
133
|
+
/**
|
134
|
+
* Authorization Response payload when using DCQL queries.
|
135
|
+
*/
|
136
|
+
|
137
|
+
export const DirectAuthorizationBodyPayload = z.object({
|
138
|
+
vp_token: z.record(z.string(), z.string())
|
20
139
|
});
|
21
140
|
//# sourceMappingURL=types.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["UnixTime","z","
|
1
|
+
{"version":3,"names":["UnixTime","z","Fields","object","path","array","string","min","id","optional","purpose","name","filter","any","boolean","intent_to_retain","Constraints","fields","limit_disclosure","enum","InputDescriptor","format","record","constraints","group","SubmissionRequirement","rule","from","from_nested","count","number","PresentationDefinition","input_descriptors","submission_requirements","RequestObject","iss","iat","exp","state","nonce","response_uri","response_uri_method","response_type","literal","response_mode","client_id","dcql_query","scope","presentation_definition","WalletMetadata","presentation_definition_uri_supported","client_id_schemes_supported","request_object_signing_alg_values_supported","vp_formats_supported","RequestObjectWalletCapabilities","wallet_metadata","wallet_nonce","LegacyDirectAuthorizationBodyPayload","vp_token","union","presentation_submission","unknown","DirectAuthorizationBodyPayload"],"sourceRoot":"../../../../src","sources":["credential/presentation/types.ts"],"mappings":"AACA,SAASA,QAAQ,QAAQ,oBAAoB;AAC7C,OAAO,KAAKC,CAAC,MAAM,KAAK;;AAExB;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;;AAQA;AACA;AACA;AACA;;AAQA,MAAMC,MAAM,GAAGD,CAAC,CAACE,MAAM,CAAC;EACtBC,IAAI,EAAEH,CAAC,CAACI,KAAK,CAACJ,CAAC,CAACK,MAAM,CAAC,CAAC,CAACC,GAAG,CAAC,CAAC,CAAC,CAAC;EAAE;EAClCC,EAAE,EAAEP,CAAC,CAACK,MAAM,CAAC,CAAC,CAACG,QAAQ,CAAC,CAAC;EAAE;EAC3BC,OAAO,EAAET,CAAC,CAACK,MAAM,CAAC,CAAC,CAACG,QAAQ,CAAC,CAAC;EAAE;EAChCE,IAAI,EAAEV,CAAC,CAACK,MAAM,CAAC,CAAC,CAACG,QAAQ,CAAC,CAAC;EAAE;EAC7BG,MAAM,EAAEX,CAAC,CAACY,GAAG,CAAC,CAAC,CAACJ,QAAQ,CAAC,CAAC;EAAE;EAC5BA,QAAQ,EAAER,CAAC,CAACa,OAAO,CAAC,CAAC,CAACL,QAAQ,CAAC,CAAC;EAAE;EAClCM,gBAAgB,EAAEd,CAAC,CAACa,OAAO,CAAC,CAAC,CAACL,QAAQ,CAAC,CAAC,CAAE;AA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;AACA;AACA;AACA;;AAIA,OAAO,MAAM6C,+BAA+B,GAAGrD,CAAC,CAACE,MAAM,CAAC;EACtDoD,eAAe,EAAEN,cAAc;EAC/BO,YAAY,EAAEvD,CAAC,CAACK,MAAM,CAAC,CAAC,CAACG,QAAQ,CAAC;AACpC,CAAC,CAAC;;AAEF;AACA;AACA;AACA;;AAIA;AACA;AACA;AACA,OAAO,MAAMgD,oCAAoC,GAAGxD,CAAC,CAACE,MAAM,CAAC;EAC3DuD,QAAQ,EAAEzD,CAAC,CAAC0D,KAAK,CAAC,CAAC1D,CAAC,CAACK,MAAM,CAAC,CAAC,EAAEL,CAAC,CAACI,KAAK,CAACJ,CAAC,CAACK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAACG,QAAQ,CAAC,CAAC;EAC/DmD,uBAAuB,EAAE3D,CAAC,CAACqB,MAAM,CAACrB,CAAC,CAACK,MAAM,CAAC,CAAC,EAAEL,CAAC,CAAC4D,OAAO,CAAC,CAAC;AAC3D,CAAC,CAAC;;AAEF;AACA;AACA;;AAIA,OAAO,MAAMC,8BAA8B,GAAG7D,CAAC,CAACE,MAAM,CAAC;EACrDuD,QAAQ,EAAEzD,CAAC,CAACqB,MAAM,CAACrB,CAAC,CAACK,MAAM,CAAC,CAAC,EAAEL,CAAC,CAACK,MAAM,CAAC,CAAC;AAC3C,CAAC,CAAC"}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { decode as decodeJwt } from "@pagopa/io-react-native-jwt";
|
2
2
|
import { verify as verifyJwt } from "@pagopa/io-react-native-jwt";
|
3
|
-
import { sha256ToBase64 } from "@pagopa/io-react-native-jwt";
|
3
|
+
import { SignJWT, sha256ToBase64 } from "@pagopa/io-react-native-jwt";
|
4
4
|
import { Disclosure, SdJwt4VC } from "./types";
|
5
5
|
import { verifyDisclosure } from "./verifier";
|
6
6
|
import * as Errors from "./errors";
|
@@ -149,5 +149,44 @@ export const verify = async (token, publicKey, customSchema) => {
|
|
149
149
|
disclosures: decoded.disclosures.map(d => d.decoded)
|
150
150
|
};
|
151
151
|
};
|
152
|
+
|
153
|
+
/**
|
154
|
+
* Prepares a Verified Presentation (VP) token to be sent as part of an
|
155
|
+
* authorization response in an OpenID 4 Verifiable Presentations flow.
|
156
|
+
*
|
157
|
+
* @param nonce - The nonce provided by the relying party.
|
158
|
+
* @param client_id - The client identifier of the relying party.
|
159
|
+
* @param presentation - An object containing the verifiable credential, the claims to disclose,
|
160
|
+
* and the cryptographic context for signing.
|
161
|
+
* @returns An object containing the signed VP token (`vp_token`).
|
162
|
+
*
|
163
|
+
* @remarks
|
164
|
+
* 1. The `disclose()` function is used to produce a token with only the requested claims.
|
165
|
+
* 2. A KB-JWT is then signed, including sd_hash and `nonce`.
|
166
|
+
* 3. The `vp_token` is composed of the disclosed VP and the KB-JWT.
|
167
|
+
*/
|
168
|
+
export const prepareVpToken = async (nonce, client_id, _ref2) => {
|
169
|
+
let [verifiableCredential, requestedClaims, cryptoContext] = _ref2;
|
170
|
+
// Produce a VP token with only requested claims from the verifiable credential
|
171
|
+
const {
|
172
|
+
token: vp
|
173
|
+
} = await disclose(verifiableCredential, requestedClaims);
|
174
|
+
|
175
|
+
// <Issuer-signed JWT>~<Disclosure 1>~<Disclosure N>~
|
176
|
+
const sd_hash = await sha256ToBase64(`${vp}~`);
|
177
|
+
const kbJwt = await new SignJWT(cryptoContext).setProtectedHeader({
|
178
|
+
typ: "kb+jwt",
|
179
|
+
alg: "ES256"
|
180
|
+
}).setPayload({
|
181
|
+
sd_hash,
|
182
|
+
nonce: nonce
|
183
|
+
}).setAudience(client_id).setIssuedAt().sign();
|
184
|
+
|
185
|
+
// <Issuer-signed JWT>~<Disclosure 1>~...~<Disclosure N>~<KB-JWT>
|
186
|
+
const vp_token = [vp, kbJwt].join("~");
|
187
|
+
return {
|
188
|
+
vp_token
|
189
|
+
};
|
190
|
+
};
|
152
191
|
export { SdJwt4VC, Errors };
|
153
192
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["decode","decodeJwt","verify","verifyJwt","sha256ToBase64","Disclosure","SdJwt4VC","verifyDisclosure","Errors","Base64","decodeDisclosure","encoded","utf8String","decoded","parse","JSON","token","customSchema","slice","rawSdJwt","rawDisclosures","split","decodedJwt","parser","sdJwt","header","protectedHeader","payload","disclosures","map","disclose","claims","paths","Promise","all","claim","disclosure","find","_ref","name","ClaimsNotFoundBetweenDisclosures","hash","_sd","includes","index","indexOf","path","ClaimsNotFoundInToken","filteredDisclosures","filter","d","disclosedToken","join","publicKey"],"sourceRoot":"../../../src","sources":["sd-jwt/index.ts"],"mappings":"AAEA,SAASA,MAAM,IAAIC,SAAS,QAAQ,6BAA6B;AACjE,SAASC,MAAM,IAAIC,SAAS,QAAQ,6BAA6B;AACjE,SAASC,cAAc,QAAQ,6BAA6B;
|
1
|
+
{"version":3,"names":["decode","decodeJwt","verify","verifyJwt","SignJWT","sha256ToBase64","Disclosure","SdJwt4VC","verifyDisclosure","Errors","Base64","decodeDisclosure","encoded","utf8String","decoded","parse","JSON","token","customSchema","slice","rawSdJwt","rawDisclosures","split","decodedJwt","parser","sdJwt","header","protectedHeader","payload","disclosures","map","disclose","claims","paths","Promise","all","claim","disclosure","find","_ref","name","ClaimsNotFoundBetweenDisclosures","hash","_sd","includes","index","indexOf","path","ClaimsNotFoundInToken","filteredDisclosures","filter","d","disclosedToken","join","publicKey","prepareVpToken","nonce","client_id","_ref2","verifiableCredential","requestedClaims","cryptoContext","vp","sd_hash","kbJwt","setProtectedHeader","typ","alg","setPayload","setAudience","setIssuedAt","sign","vp_token"],"sourceRoot":"../../../src","sources":["sd-jwt/index.ts"],"mappings":"AAEA,SAASA,MAAM,IAAIC,SAAS,QAAQ,6BAA6B;AACjE,SAASC,MAAM,IAAIC,SAAS,QAAQ,6BAA6B;AACjE,SAASC,OAAO,EAAEC,cAAc,QAAQ,6BAA6B;AACrE,SAASC,UAAU,EAAEC,QAAQ,QAAoC,SAAS;AAC1E,SA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BAAoB,EAAEC,eAAe,EAAEC,aAAa,CAAe,GAAAH,KAAA;EAIpE;EACA,MAAM;IAAEzC,KAAK,EAAE6C;EAAG,CAAC,GAAG,MAAM/B,QAAQ,CAAC4B,oBAAoB,EAAEC,eAAe,CAAC;;EAE3E;EACA,MAAMG,OAAO,GAAG,MAAM1D,cAAc,CAAE,GAAEyD,EAAG,GAAE,CAAC;EAE9C,MAAME,KAAK,GAAG,MAAM,IAAI5D,OAAO,CAACyD,aAAa,CAAC,CAC3CI,kBAAkB,CAAC;IAClBC,GAAG,EAAE,QAAQ;IACbC,GAAG,EAAE;EACP,CAAC,CAAC,CACDC,UAAU,CAAC;IACVL,OAAO;IACPP,KAAK,EAAEA;EACT,CAAC,CAAC,CACDa,WAAW,CAACZ,SAAS,CAAC,CACtBa,WAAW,CAAC,CAAC,CACbC,IAAI,CAAC,CAAC;;EAET;EACA,MAAMC,QAAQ,GAAG,CAACV,EAAE,EAAEE,KAAK,CAAC,CAACX,IAAI,CAAC,GAAG,CAAC;EAEtC,OAAO;IAAEmB;EAAS,CAAC;AACrB,CAAC;AAED,SAASjE,QAAQ,EAAEE,MAAM"}
|
@@ -1,34 +1,8 @@
|
|
1
|
-
import { decode as decodeJwt, verify as verifyJwt } from "@pagopa/io-react-native-jwt";
|
2
1
|
import { EntityConfiguration, EntityStatement, TrustAnchorEntityConfiguration } from "./types";
|
3
2
|
import { IoWalletError } from "../utils/errors";
|
4
3
|
import * as z from "zod";
|
5
4
|
import { getSignedEntityConfiguration, getSignedEntityStatement } from ".";
|
6
|
-
|
7
|
-
// The kid is extracted from the token header
|
8
|
-
const verify = async (token, kid, jwks) => {
|
9
|
-
const jwk = jwks.find(k => k.kid === kid);
|
10
|
-
if (!jwk) {
|
11
|
-
throw new Error(`Invalid kid: ${kid}, token: ${token}`);
|
12
|
-
}
|
13
|
-
const {
|
14
|
-
protectedHeader: header,
|
15
|
-
payload
|
16
|
-
} = await verifyJwt(token, jwk);
|
17
|
-
return {
|
18
|
-
header,
|
19
|
-
payload
|
20
|
-
};
|
21
|
-
};
|
22
|
-
const decode = token => {
|
23
|
-
const {
|
24
|
-
protectedHeader: header,
|
25
|
-
payload
|
26
|
-
} = decodeJwt(token);
|
27
|
-
return {
|
28
|
-
header,
|
29
|
-
payload
|
30
|
-
};
|
31
|
-
};
|
5
|
+
import { decode, verify } from "./utils";
|
32
6
|
|
33
7
|
// The first element of the chain is supposed to be the Entity Configuration for the document issuer
|
34
8
|
const FirstElementShape = EntityConfiguration;
|
@@ -42,7 +16,7 @@ const LastElementShape = z.union([EntityStatement, TrustAnchorEntityConfiguratio
|
|
42
16
|
* Validates a provided trust chain against a known trust
|
43
17
|
*
|
44
18
|
* @param trustAnchorEntity The entity configuration of the known trust anchor
|
45
|
-
* @param chain The chain of statements to be
|
19
|
+
* @param chain The chain of statements to be validated
|
46
20
|
* @returns The list of parsed token representing the chain
|
47
21
|
* @throws {IoWalletError} If the chain is not valid
|
48
22
|
*/
|
@@ -66,7 +40,7 @@ export async function validateTrustChain(trustAnchorEntity, chain) {
|
|
66
40
|
};
|
67
41
|
|
68
42
|
// select keys from the next token
|
69
|
-
// if the current token is the last, keys
|
43
|
+
// if the current token is the last, keys from trust anchor will be used
|
70
44
|
const selectKeys = currentIndex => {
|
71
45
|
if (currentIndex === chain.length - 1) {
|
72
46
|
return trustAnchorEntity.payload.jwks.keys;
|
@@ -81,7 +55,7 @@ export async function validateTrustChain(trustAnchorEntity, chain) {
|
|
81
55
|
};
|
82
56
|
|
83
57
|
// Iterate the chain and validate each element's signature against the public keys of its next
|
84
|
-
// If there is no next, hence it's the end of the chain and it must be verified by the Trust Anchor
|
58
|
+
// If there is no next, hence it's the end of the chain, and it must be verified by the Trust Anchor
|
85
59
|
return Promise.all(chain.map((token, i) => [token, selectKid(i), selectKeys(i)]).map(args => verify(...args)));
|
86
60
|
}
|
87
61
|
|
@@ -90,24 +64,36 @@ export async function validateTrustChain(trustAnchorEntity, chain) {
|
|
90
64
|
*
|
91
65
|
* @param chain The original chain
|
92
66
|
* @param appFetch (optional) fetch api implementation
|
93
|
-
* @returns A list of signed token that
|
94
|
-
* @throws When an element of the chain fails to parse
|
67
|
+
* @returns A list of signed token that represent the trust chain, in the same order of the provided chain
|
68
|
+
* @throws IoWalletError When an element of the chain fails to parse
|
95
69
|
*/
|
96
|
-
export function renewTrustChain(chain) {
|
70
|
+
export async function renewTrustChain(chain) {
|
97
71
|
let appFetch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : fetch;
|
98
|
-
return Promise.all(chain
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
}
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
72
|
+
return Promise.all(chain.map(async (token, index) => {
|
73
|
+
const decoded = decode(token);
|
74
|
+
const entityStatementResult = EntityStatement.safeParse(decoded);
|
75
|
+
const entityConfigurationResult = EntityConfiguration.safeParse(decoded);
|
76
|
+
if (entityConfigurationResult.success) {
|
77
|
+
return getSignedEntityConfiguration(entityConfigurationResult.data.payload.iss, {
|
78
|
+
appFetch
|
79
|
+
});
|
80
|
+
}
|
81
|
+
if (entityStatementResult.success) {
|
82
|
+
const entityStatement = entityStatementResult.data;
|
83
|
+
const parentBaseUrl = entityStatement.payload.iss;
|
84
|
+
const parentECJwt = await getSignedEntityConfiguration(parentBaseUrl, {
|
85
|
+
appFetch
|
86
|
+
});
|
87
|
+
const parentEC = EntityConfiguration.parse(decode(parentECJwt));
|
88
|
+
const federationFetchEndpoint = parentEC.payload.metadata.federation_entity.federation_fetch_endpoint;
|
89
|
+
if (!federationFetchEndpoint) {
|
90
|
+
throw new IoWalletError(`Parent EC at ${parentBaseUrl} is missing federation_fetch_endpoint`);
|
91
|
+
}
|
92
|
+
return getSignedEntityStatement(federationFetchEndpoint, entityStatement.payload.sub, {
|
93
|
+
appFetch
|
94
|
+
});
|
95
|
+
}
|
96
|
+
throw new IoWalletError(`Cannot renew trust chain because element #${index} failed to parse.`);
|
111
97
|
}));
|
112
98
|
}
|
113
99
|
//# sourceMappingURL=chain.js.map
|