@pagopa/io-react-native-wallet 2.0.0-next.3 → 2.0.0-next.5
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/credential/issuance/04-complete-user-authorization.js +75 -57
- package/lib/commonjs/credential/issuance/04-complete-user-authorization.js.map +1 -1
- package/lib/commonjs/credential/issuance/06-obtain-credential.js.map +1 -1
- package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js +3 -3
- package/lib/commonjs/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
- package/lib/commonjs/credential/issuance/README.md +45 -34
- package/lib/commonjs/credential/issuance/types.js +1 -0
- package/lib/commonjs/credential/issuance/types.js.map +1 -1
- package/lib/commonjs/credential/presentation/07-evaluate-dcql-query.js +6 -13
- package/lib/commonjs/credential/presentation/07-evaluate-dcql-query.js.map +1 -1
- package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js +7 -8
- package/lib/commonjs/credential/presentation/07-evaluate-input-descriptor.js.map +1 -1
- package/lib/commonjs/credential/presentation/types.js +1 -1
- package/lib/commonjs/credential/presentation/types.js.map +1 -1
- package/lib/commonjs/credential/status/{02-status-attestation.js → 02-status-assertion.js} +28 -22
- package/lib/commonjs/credential/status/02-status-assertion.js.map +1 -0
- package/lib/commonjs/credential/status/03-verify-and-parse-status-assertion.js +85 -0
- package/lib/commonjs/credential/status/03-verify-and-parse-status-assertion.js.map +1 -0
- package/lib/commonjs/credential/status/README.md +22 -20
- package/lib/commonjs/credential/status/index.js +6 -6
- package/lib/commonjs/credential/status/index.js.map +1 -1
- package/lib/commonjs/credential/status/types.js +48 -15
- package/lib/commonjs/credential/status/types.js.map +1 -1
- package/lib/commonjs/sd-jwt/index.js +6 -1
- package/lib/commonjs/sd-jwt/index.js.map +1 -1
- package/lib/commonjs/sd-jwt/types.js +25 -9
- package/lib/commonjs/sd-jwt/types.js.map +1 -1
- package/lib/commonjs/utils/credentials.js +33 -0
- package/lib/commonjs/utils/credentials.js.map +1 -0
- package/lib/commonjs/utils/crypto.js +1 -7
- package/lib/commonjs/utils/crypto.js.map +1 -1
- package/lib/commonjs/utils/jwk.js +12 -0
- package/lib/commonjs/utils/jwk.js.map +1 -1
- package/lib/commonjs/wallet-instance-attestation/types.js +1 -2
- package/lib/commonjs/wallet-instance-attestation/types.js.map +1 -1
- package/lib/module/credential/issuance/04-complete-user-authorization.js +76 -58
- package/lib/module/credential/issuance/04-complete-user-authorization.js.map +1 -1
- package/lib/module/credential/issuance/06-obtain-credential.js.map +1 -1
- package/lib/module/credential/issuance/07-verify-and-parse-credential.js +4 -4
- package/lib/module/credential/issuance/07-verify-and-parse-credential.js.map +1 -1
- package/lib/module/credential/issuance/README.md +45 -34
- package/lib/module/credential/issuance/types.js +1 -0
- package/lib/module/credential/issuance/types.js.map +1 -1
- package/lib/module/credential/presentation/07-evaluate-dcql-query.js +6 -13
- package/lib/module/credential/presentation/07-evaluate-dcql-query.js.map +1 -1
- package/lib/module/credential/presentation/07-evaluate-input-descriptor.js +7 -8
- package/lib/module/credential/presentation/07-evaluate-input-descriptor.js.map +1 -1
- package/lib/module/credential/presentation/types.js +1 -1
- package/lib/module/credential/presentation/types.js.map +1 -1
- package/lib/module/credential/status/{02-status-attestation.js → 02-status-assertion.js} +28 -22
- package/lib/module/credential/status/02-status-assertion.js.map +1 -0
- package/lib/module/credential/status/03-verify-and-parse-status-assertion.js +78 -0
- package/lib/module/credential/status/03-verify-and-parse-status-assertion.js.map +1 -0
- package/lib/module/credential/status/README.md +22 -20
- package/lib/module/credential/status/index.js +3 -3
- package/lib/module/credential/status/index.js.map +1 -1
- package/lib/module/credential/status/types.js +43 -12
- package/lib/module/credential/status/types.js.map +1 -1
- package/lib/module/sd-jwt/index.js +6 -1
- package/lib/module/sd-jwt/index.js.map +1 -1
- package/lib/module/sd-jwt/types.js +25 -9
- package/lib/module/sd-jwt/types.js.map +1 -1
- package/lib/module/utils/credentials.js +26 -0
- package/lib/module/utils/credentials.js.map +1 -0
- package/lib/module/utils/crypto.js +2 -8
- package/lib/module/utils/crypto.js.map +1 -1
- package/lib/module/utils/jwk.js +11 -1
- package/lib/module/utils/jwk.js.map +1 -1
- package/lib/module/wallet-instance-attestation/types.js +1 -2
- package/lib/module/wallet-instance-attestation/types.js.map +1 -1
- package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts +7 -14
- package/lib/typescript/credential/issuance/04-complete-user-authorization.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/06-obtain-credential.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/07-verify-and-parse-credential.d.ts.map +1 -1
- package/lib/typescript/credential/issuance/types.d.ts +3 -0
- package/lib/typescript/credential/issuance/types.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/01-start-flow.d.ts +2 -2
- package/lib/typescript/credential/presentation/07-evaluate-dcql-query.d.ts +4 -3
- package/lib/typescript/credential/presentation/07-evaluate-dcql-query.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts +9 -5
- package/lib/typescript/credential/presentation/07-evaluate-input-descriptor.d.ts.map +1 -1
- package/lib/typescript/credential/presentation/types.d.ts +3 -4
- package/lib/typescript/credential/presentation/types.d.ts.map +1 -1
- package/lib/typescript/credential/status/02-status-assertion.d.ts +23 -0
- package/lib/typescript/credential/status/02-status-assertion.d.ts.map +1 -0
- package/lib/typescript/credential/status/03-verify-and-parse-status-assertion.d.ts +21 -0
- package/lib/typescript/credential/status/03-verify-and-parse-status-assertion.d.ts.map +1 -0
- package/lib/typescript/credential/status/index.d.ts +4 -4
- package/lib/typescript/credential/status/index.d.ts.map +1 -1
- package/lib/typescript/credential/status/types.d.ts +499 -22
- package/lib/typescript/credential/status/types.d.ts.map +1 -1
- package/lib/typescript/sd-jwt/index.d.ts +68 -40
- package/lib/typescript/sd-jwt/index.d.ts.map +1 -1
- package/lib/typescript/sd-jwt/types.d.ts +97 -46
- package/lib/typescript/sd-jwt/types.d.ts.map +1 -1
- package/lib/typescript/utils/credentials.d.ts +11 -0
- package/lib/typescript/utils/credentials.d.ts.map +1 -0
- package/lib/typescript/utils/crypto.d.ts.map +1 -1
- package/lib/typescript/utils/jwk.d.ts +7 -0
- package/lib/typescript/utils/jwk.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/credential/issuance/04-complete-user-authorization.ts +79 -85
- package/src/credential/issuance/06-obtain-credential.ts +4 -1
- package/src/credential/issuance/07-verify-and-parse-credential.ts +4 -6
- package/src/credential/issuance/README.md +45 -34
- package/src/credential/issuance/types.ts +1 -0
- package/src/credential/presentation/07-evaluate-dcql-query.ts +16 -17
- package/src/credential/presentation/07-evaluate-input-descriptor.ts +16 -13
- package/src/credential/presentation/types.ts +1 -2
- package/src/credential/status/{02-status-attestation.ts → 02-status-assertion.ts} +37 -28
- package/src/credential/status/03-verify-and-parse-status-assertion.ts +109 -0
- package/src/credential/status/README.md +22 -20
- package/src/credential/status/index.ts +7 -14
- package/src/credential/status/types.ts +62 -15
- package/src/sd-jwt/index.ts +5 -1
- package/src/sd-jwt/types.ts +24 -10
- package/src/utils/credentials.ts +29 -0
- package/src/utils/crypto.ts +12 -20
- package/src/utils/jwk.ts +15 -1
- package/src/wallet-instance-attestation/types.ts +1 -1
- package/lib/commonjs/credential/status/02-status-attestation.js.map +0 -1
- package/lib/commonjs/credential/status/03-verify-and-parse-status-attestation.js +0 -55
- package/lib/commonjs/credential/status/03-verify-and-parse-status-attestation.js.map +0 -1
- package/lib/module/credential/status/02-status-attestation.js.map +0 -1
- package/lib/module/credential/status/03-verify-and-parse-status-attestation.js +0 -49
- package/lib/module/credential/status/03-verify-and-parse-status-attestation.js.map +0 -1
- package/lib/typescript/credential/status/02-status-attestation.d.ts +0 -19
- package/lib/typescript/credential/status/02-status-attestation.d.ts.map +0 -1
- package/lib/typescript/credential/status/03-verify-and-parse-status-attestation.d.ts +0 -24
- package/lib/typescript/credential/status/03-verify-and-parse-status-attestation.d.ts.map +0 -1
- package/src/credential/status/03-verify-and-parse-status-attestation.ts +0 -70
@@ -72,8 +72,6 @@ The expected result from the authentication process is in `form_post.jwt` format
|
|
72
72
|
<summary>Credential issuance flow</summary>
|
73
73
|
|
74
74
|
```ts
|
75
|
-
// TODO: [SIW-2209] update documentation in PR #219
|
76
|
-
|
77
75
|
// Retrieve the integrity key tag from the store and create its context
|
78
76
|
const integrityKeyTag = "example"; // Let's assume this is the key tag used to create the wallet instance
|
79
77
|
const integrityContext = getIntegrityContext(integrityKeyTag);
|
@@ -98,17 +96,13 @@ const walletInstanceAttestation =
|
|
98
96
|
appFetch,
|
99
97
|
});
|
100
98
|
|
101
|
-
const
|
102
|
-
|
103
|
-
const eid = {
|
99
|
+
const pid = {
|
104
100
|
credential: "example",
|
105
101
|
parsedCredential: "example"
|
106
102
|
keyTag: "example";
|
107
|
-
credentialType: "
|
103
|
+
credentialType: "PersonIdentificationData";
|
108
104
|
};
|
109
105
|
|
110
|
-
const eidCryptoContext = createCryptoContextFor(eid.keyTag);
|
111
|
-
|
112
106
|
// Create credential crypto context
|
113
107
|
const credentialKeyTag = uuidv4().toString();
|
114
108
|
await generate(credentialKeyTag); // Let's assume this function generates a new hardware-backed key pair
|
@@ -117,22 +111,26 @@ const credentialCryptoContext = createCryptoContextFor(credentialKeyTag);
|
|
117
111
|
// Start the issuance flow
|
118
112
|
const startFlow: Credential.Issuance.StartFlow = () => ({
|
119
113
|
issuerUrl: WALLET_EAA_PROVIDER_BASE_URL,
|
120
|
-
|
114
|
+
credentialId: "someCredentialId",
|
121
115
|
});
|
122
116
|
|
123
|
-
const { issuerUrl } = startFlow();
|
117
|
+
const { issuerUrl, credentialId } = startFlow();
|
124
118
|
|
125
119
|
// Evaluate issuer trust
|
126
120
|
const { issuerConf } = await Credential.Issuance.evaluateIssuerTrust(issuerUrl);
|
127
121
|
|
128
122
|
// Start user authorization
|
129
|
-
const { issuerRequestUri, clientId, codeVerifier
|
130
|
-
await Credential.Issuance.startUserAuthorization(
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
123
|
+
const { issuerRequestUri, clientId, codeVerifier } =
|
124
|
+
await Credential.Issuance.startUserAuthorization(
|
125
|
+
issuerConf,
|
126
|
+
[credentialId],
|
127
|
+
{
|
128
|
+
walletInstanceAttestation,
|
129
|
+
redirectUri: REDIRECT_URI,
|
130
|
+
wiaCryptoContext,
|
131
|
+
appFetch,
|
132
|
+
}
|
133
|
+
);
|
136
134
|
|
137
135
|
const requestObject =
|
138
136
|
await Credential.Issuance.getRequestedCredentialToBePresented(
|
@@ -142,13 +140,12 @@ const requestObject =
|
|
142
140
|
appFetch
|
143
141
|
);
|
144
142
|
|
145
|
-
// The app here should ask the user to confirm the required data contained in the requestObject
|
146
|
-
|
147
143
|
// Complete the user authorization via form_post.jwt mode
|
148
144
|
const { code } =
|
149
145
|
await Credential.Issuance.completeUserAuthorizationWithFormPostJwtMode(
|
150
146
|
requestObject,
|
151
|
-
|
147
|
+
pid.credential,
|
148
|
+
{ wiaCryptoContext, pidCryptoContext: createCryptoContextFor(pid.keyTag) }
|
152
149
|
);
|
153
150
|
|
154
151
|
// Generate the DPoP context which will be used for the whole issuance flow
|
@@ -159,7 +156,7 @@ const { accessToken } = await Credential.Issuance.authorizeAccess(
|
|
159
156
|
issuerConf,
|
160
157
|
code,
|
161
158
|
clientId,
|
162
|
-
redirectUri,
|
159
|
+
redirectUri: REDIRECT_URI,
|
163
160
|
codeVerifier,
|
164
161
|
{
|
165
162
|
walletInstanceAttestation,
|
@@ -169,12 +166,19 @@ const { accessToken } = await Credential.Issuance.authorizeAccess(
|
|
169
166
|
}
|
170
167
|
);
|
171
168
|
|
172
|
-
//
|
173
|
-
const {
|
169
|
+
// For simplicity, in this example flow we work on a single credential.
|
170
|
+
const { credential_configuration_id, credential_identifiers } =
|
171
|
+
accessToken.authorization_details[0]!;
|
172
|
+
|
173
|
+
// Obtain the credential
|
174
|
+
const { credential } = await Credential.Issuance.obtainCredential(
|
174
175
|
issuerConf,
|
175
176
|
accessToken,
|
176
177
|
clientId,
|
177
|
-
|
178
|
+
{
|
179
|
+
credential_configuration_id,
|
180
|
+
credential_identifier: credential_identifiers[0],
|
181
|
+
},
|
178
182
|
{
|
179
183
|
credentialCryptoContext,
|
180
184
|
dPopCryptoContext,
|
@@ -186,22 +190,29 @@ const { credential, format } = await Credential.Issuance.obtainCredential(
|
|
186
190
|
* Parse and verify the credential. The ignoreMissingAttributes flag must be set to false or omitted in production.
|
187
191
|
* WARNING: includeUndefinedAttributes should not be set to true in production in order to get only claims explicitly declared by the issuer.
|
188
192
|
*/
|
189
|
-
const { parsedCredential } =
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
193
|
+
const { parsedCredential } =
|
194
|
+
await Credential.Issuance.verifyAndParseCredential(
|
195
|
+
issuerConf,
|
196
|
+
credential,
|
197
|
+
credential_configuration_id,
|
198
|
+
{
|
199
|
+
credentialCryptoContext,
|
200
|
+
ignoreMissingAttributes: true,
|
201
|
+
includeUndefinedAttributes: false
|
202
|
+
}
|
203
|
+
);
|
204
|
+
|
205
|
+
const credentialType =
|
206
|
+
issuerConf.openid_credential_issuer.credential_configurations_supported[
|
207
|
+
credential_configuration_id
|
208
|
+
].scope;
|
199
209
|
|
200
210
|
return {
|
201
211
|
parsedCredential,
|
202
212
|
credential,
|
203
213
|
keyTag: credentialKeyTag,
|
204
214
|
credentialType,
|
215
|
+
credentialConfigurationId: credential_configuration_id,
|
205
216
|
};
|
206
217
|
```
|
207
218
|
|
@@ -6,6 +6,7 @@ export const AuthorizationDetail = z.object({
|
|
6
6
|
});
|
7
7
|
export const TokenResponse = z.object({
|
8
8
|
access_token: z.string(),
|
9
|
+
refresh_token: z.string().optional(),
|
9
10
|
authorization_details: z.array(AuthorizationDetail),
|
10
11
|
expires_in: z.number(),
|
11
12
|
token_type: z.string()
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["z","AuthorizationDetail","object","type","literal","credential_configuration_id","string","credential_identifiers","array","TokenResponse","access_token","authorization_details","expires_in","number","token_type","CredentialResponse","credentials","credential","notification_id","
|
1
|
+
{"version":3,"names":["z","AuthorizationDetail","object","type","literal","credential_configuration_id","string","credential_identifiers","array","TokenResponse","access_token","refresh_token","optional","authorization_details","expires_in","number","token_type","CredentialResponse","credentials","credential","notification_id","ResponseUriResultShape","redirect_uri","NonceResponse","c_nonce"],"sourceRoot":"../../../../src","sources":["credential/issuance/types.ts"],"mappings":"AAAA,OAAO,KAAKA,CAAC,MAAM,KAAK;AAGxB,OAAO,MAAMC,mBAAmB,GAAGD,CAAC,CAACE,MAAM,CAAC;EAC1CC,IAAI,EAAEH,CAAC,CAACI,OAAO,CAAC,mBAAmB,CAAC;EACpCC,2BAA2B,EAAEL,CAAC,CAACM,MAAM,CAAC,CAAC;EACvCC,sBAAsB,EAAEP,CAAC,CAACQ,KAAK,CAACR,CAAC,CAACM,MAAM,CAAC,CAAC;AAC5C,CAAC,CAAC;AAIF,OAAO,MAAMG,aAAa,GAAGT,CAAC,CAACE,MAAM,CAAC;EACpCQ,YAAY,EAAEV,CAAC,CAACM,MAAM,CAAC,CAAC;EACxBK,aAAa,EAAEX,CAAC,CAACM,MAAM,CAAC,CAAC,CAACM,QAAQ,CAAC,CAAC;EACpCC,qBAAqB,EAAEb,CAAC,CAACQ,KAAK,CAACP,mBAAmB,CAAC;EACnDa,UAAU,EAAEd,CAAC,CAACe,MAAM,CAAC,CAAC;EACtBC,UAAU,EAAEhB,CAAC,CAACM,MAAM,CAAC;AACvB,CAAC,CAAC;AAIF,OAAO,MAAMW,kBAAkB,GAAGjB,CAAC,CAACE,MAAM,CAAC;EACzCgB,WAAW,EAAElB,CAAC,CAACQ,KAAK,CAClBR,CAAC,CAACE,MAAM,CAAC;IACPiB,UAAU,EAAEnB,CAAC,CAACM,MAAM,CAAC;EACvB,CAAC,CACH,CAAC;EACDc,eAAe,EAAEpB,CAAC,CAACM,MAAM,CAAC,CAAC,CAACM,QAAQ,CAAC;AACvC,CAAC,CAAC;;AAEF;AACA;AACA;AACA,OAAO,MAAMS,sBAAsB,GAAGrB,CAAC,CAACE,MAAM,CAAC;EAC7CoB,YAAY,EAAEtB,CAAC,CAACM,MAAM,CAAC;AACzB,CAAC,CAAC;AAKF,OAAO,MAAMiB,aAAa,GAAGvB,CAAC,CAACE,MAAM,CAAC;EACpCsB,OAAO,EAAExB,CAAC,CAACM,MAAM,CAAC;AACpB,CAAC,CAAC"}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import { DcqlQuery, DcqlError } from "dcql";
|
2
2
|
import { isValiError } from "valibot";
|
3
3
|
import { decode, prepareVpToken } from "../../sd-jwt";
|
4
|
-
import { createCryptoContextFor } from "../../utils/crypto";
|
5
4
|
import { CredentialsNotFoundError } from "./errors";
|
6
5
|
|
7
6
|
/**
|
@@ -18,11 +17,6 @@ const mapCredentialToObject = jwt => {
|
|
18
17
|
disclosures
|
19
18
|
} = decode(jwt);
|
20
19
|
const credentialFormat = sdJwt.header.typ;
|
21
|
-
|
22
|
-
// TODO [SIW-2082]: support MDOC credentials
|
23
|
-
if (credentialFormat !== "dc+sd-jwt") {
|
24
|
-
throw new Error(`Unsupported credential format: ${credentialFormat}`);
|
25
|
-
}
|
26
20
|
return {
|
27
21
|
vct: sdJwt.payload.vct,
|
28
22
|
credential_format: credentialFormat,
|
@@ -59,7 +53,7 @@ const extractMissingCredentials = (queryResult, originalQuery) => {
|
|
59
53
|
var _credential$meta;
|
60
54
|
let [id] = _ref3;
|
61
55
|
const credential = originalQuery.credentials.find(c => c.id === id);
|
62
|
-
if ((credential === null || credential === void 0 ? void 0 : credential.format) !== "dc+sd-jwt") {
|
56
|
+
if ((credential === null || credential === void 0 ? void 0 : credential.format) !== "dc+sd-jwt" && (credential === null || credential === void 0 ? void 0 : credential.format) !== "vc+sd-jwt") {
|
63
57
|
throw new Error("Unsupported format"); // TODO [SIW-2082]: support MDOC credentials
|
64
58
|
}
|
65
59
|
|
@@ -91,7 +85,7 @@ export const evaluateDcqlQuery = (credentialsSdJwt, query) => {
|
|
91
85
|
return getDcqlQueryMatches(queryResult).map(_ref5 => {
|
92
86
|
var _queryResult$credenti;
|
93
87
|
let [id, match] = _ref5;
|
94
|
-
if (match.output.credential_format !== "dc+sd-jwt") {
|
88
|
+
if (match.output.credential_format !== "dc+sd-jwt" && match.output.credential_format !== "vc+sd-jwt") {
|
95
89
|
throw new Error("Unsupported format"); // TODO [SIW-2082]: support MDOC credentials
|
96
90
|
}
|
97
91
|
|
@@ -109,12 +103,12 @@ export const evaluateDcqlQuery = (credentialsSdJwt, query) => {
|
|
109
103
|
required: Boolean(credentialSet.required)
|
110
104
|
};
|
111
105
|
});
|
112
|
-
const [
|
106
|
+
const [cryptoContext, credential] = credentialsSdJwtByVct[vct];
|
113
107
|
const requiredDisclosures = Object.values(claims);
|
114
108
|
return {
|
115
109
|
id,
|
116
110
|
vct,
|
117
|
-
|
111
|
+
cryptoContext,
|
118
112
|
credential,
|
119
113
|
requiredDisclosures,
|
120
114
|
// When it is a match but no credential_sets are found, the credential is required by default
|
@@ -142,12 +136,11 @@ export const prepareRemotePresentations = async (credentials, nonce, clientId) =
|
|
142
136
|
return Promise.all(credentials.map(async item => {
|
143
137
|
const {
|
144
138
|
vp_token
|
145
|
-
} = await prepareVpToken(nonce, clientId, [item.credential, item.requestedClaims,
|
139
|
+
} = await prepareVpToken(nonce, clientId, [item.credential, item.requestedClaims, item.cryptoContext]);
|
146
140
|
return {
|
147
141
|
credentialId: item.id,
|
148
142
|
requestedClaims: item.requestedClaims,
|
149
|
-
vpToken: vp_token
|
150
|
-
format: "dc+sd-jwt"
|
143
|
+
vpToken: vp_token
|
151
144
|
};
|
152
145
|
}));
|
153
146
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["DcqlQuery","DcqlError","isValiError","decode","prepareVpToken","
|
1
|
+
{"version":3,"names":["DcqlQuery","DcqlError","isValiError","decode","prepareVpToken","CredentialsNotFoundError","mapCredentialToObject","jwt","sdJwt","disclosures","credentialFormat","header","typ","vct","payload","credential_format","claims","reduce","acc","disclosure","decoded","getDcqlQueryMatches","result","Object","entries","credential_matches","filter","_ref","match","success","getDcqlQueryFailedMatches","_ref2","extractMissingCredentials","queryResult","originalQuery","map","_ref3","_credential$meta","id","credential","credentials","find","c","format","Error","vctValues","meta","vct_values","evaluateDcqlQuery","credentialsSdJwt","query","_ref4","parsedQuery","parse","validate","canBeSatisfied","credentialsSdJwtByVct","i","_ref5","_queryResult$credenti","output","purposes","credential_sets","set","_set$matching_options","matching_options","flat","includes","credentialSet","_credentialSet$purpos","description","purpose","toString","required","Boolean","cryptoContext","requiredDisclosures","values","error","message","code","cause","issues","prepareRemotePresentations","nonce","clientId","Promise","all","item","vp_token","requestedClaims","credentialId","vpToken"],"sourceRoot":"../../../../src","sources":["credential/presentation/07-evaluate-dcql-query.ts"],"mappings":"AAAA,SAASA,SAAS,EAAEC,SAAS,QAAyB,MAAM;AAC5D,SAASC,WAAW,QAAQ,SAAS;AACrC,SAASC,MAAM,EAAEC,cAAc,QAAQ,cAAc;AAGrD,SAASC,wBAAwB,QAA6B,UAAU;;AAGxE;AACA;AACA;;AAuCA;AACA;AACA;AACA;AACA,MAAMC,qBAAqB,GAAIC,GAAW,IAAK;EAC7C,MAAM;IAAEC,KAAK;IAAEC;EAAY,CAAC,GAAGN,MAAM,CAACI,GAAG,CAAC;EAC1C,MAAMG,gBAAgB,GAAGF,KAAK,CAACG,MAAM,CAACC,GAAG;EAEzC,OAAO;IACLC,GAAG,EAAEL,KAAK,CAACM,OAAO,CAACD,GAAG;IACtBE,iBAAiB,EAAEL,gBAAgB;IACnCM,MAAM,EAAEP,WAAW,CAACQ,MAAM,CACxB,CAACC,GAAG,EAAEC,UAAU,MAAM;MACpB,GAAGD,GAAG;MACN,CAACC,UAAU,CAACC,OAAO,CAAC,CAAC,CAAC,GAAGD,UAAU,CAACC;IACtC,CAAC,CAAC,EACF,CAAC,CACH;E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D,GAAG,MAAAA,CACpE3C,WAAW,EACX4C,KAAK,EACLC,QAAQ,KACL;EACH,OAAOC,OAAO,CAACC,GAAG,CAChB/C,WAAW,CAACL,GAAG,CAAC,MAAOqD,IAAI,IAAK;IAC9B,MAAM;MAAEC;IAAS,CAAC,GAAG,MAAMrF,cAAc,CAACgF,KAAK,EAAEC,QAAQ,EAAE,CACzDG,IAAI,CAACjD,UAAU,EACfiD,IAAI,CAACE,eAAe,EACpBF,IAAI,CAACb,aAAa,CACnB,CAAC;IAEF,OAAO;MACLgB,YAAY,EAAEH,IAAI,CAAClD,EAAE;MACrBoD,eAAe,EAAEF,IAAI,CAACE,eAAe;MACrCE,OAAO,EAAEH;IACX,CAAC;EACH,CAAC,CACH,CAAC;AACH,CAAC"}
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import { decode, prepareVpToken } from "../../sd-jwt";
|
2
|
-
import { createCryptoContextFor } from "../../utils/crypto";
|
3
2
|
import { JSONPath } from "jsonpath-plus";
|
4
3
|
import { CredentialsNotFoundError, MissingDataError } from "./errors";
|
5
4
|
import Ajv from "ajv";
|
@@ -177,7 +176,7 @@ export const evaluateInputDescriptorForSdJwt4VC = (inputDescriptor, payloadCrede
|
|
177
176
|
*/
|
178
177
|
export const findCredentialSdJwt = (inputDescriptor, decodedSdJwtCredentials) => {
|
179
178
|
for (const {
|
180
|
-
|
179
|
+
cryptoContext,
|
181
180
|
credential,
|
182
181
|
sdJwt,
|
183
182
|
disclosures
|
@@ -186,7 +185,7 @@ export const findCredentialSdJwt = (inputDescriptor, decodedSdJwtCredentials) =>
|
|
186
185
|
const evaluatedDisclosure = evaluateInputDescriptorForSdJwt4VC(inputDescriptor, sdJwt.payload, disclosures);
|
187
186
|
return {
|
188
187
|
matchedEvaluation: evaluatedDisclosure,
|
189
|
-
|
188
|
+
cryptoContext,
|
190
189
|
matchedCredential: credential
|
191
190
|
};
|
192
191
|
} catch {
|
@@ -217,13 +216,13 @@ export const findCredentialSdJwt = (inputDescriptor, decodedSdJwtCredentials) =>
|
|
217
216
|
export const evaluateInputDescriptors = async (inputDescriptors, credentialsSdJwt) => {
|
218
217
|
// We need decode SD-JWT credentials for evaluation
|
219
218
|
const decodedSdJwtCredentials = (credentialsSdJwt === null || credentialsSdJwt === void 0 ? void 0 : credentialsSdJwt.map(_ref2 => {
|
220
|
-
let [
|
219
|
+
let [cryptoContext, credential] = _ref2;
|
221
220
|
const {
|
222
221
|
sdJwt,
|
223
222
|
disclosures
|
224
223
|
} = decode(credential);
|
225
224
|
return {
|
226
|
-
|
225
|
+
cryptoContext,
|
227
226
|
credential,
|
228
227
|
sdJwt,
|
229
228
|
disclosures
|
@@ -240,14 +239,14 @@ export const evaluateInputDescriptors = async (inputDescriptors, credentialsSdJw
|
|
240
239
|
}
|
241
240
|
const {
|
242
241
|
matchedEvaluation,
|
243
|
-
|
242
|
+
cryptoContext,
|
244
243
|
matchedCredential
|
245
244
|
} = findCredentialSdJwt(descriptor, decodedSdJwtCredentials);
|
246
245
|
return {
|
247
246
|
evaluatedDisclosure: matchedEvaluation,
|
248
247
|
inputDescriptor: descriptor,
|
249
248
|
credential: matchedCredential,
|
250
|
-
|
249
|
+
cryptoContext
|
251
250
|
};
|
252
251
|
}
|
253
252
|
throw new CredentialsNotFoundError([{
|
@@ -280,7 +279,7 @@ export const prepareLegacyRemotePresentations = async (credentialAndDescriptors,
|
|
280
279
|
if ((_descriptor$format2 = descriptor.format) !== null && _descriptor$format2 !== void 0 && _descriptor$format2["dc+sd-jwt"]) {
|
281
280
|
const {
|
282
281
|
vp_token
|
283
|
-
} = await prepareVpToken(nonce, client_id, [item.credential, item.requestedClaims,
|
282
|
+
} = await prepareVpToken(nonce, client_id, [item.credential, item.requestedClaims, item.cryptoContext]);
|
284
283
|
return {
|
285
284
|
requestedClaims: item.requestedClaims,
|
286
285
|
inputDescriptor: descriptor,
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["decode","prepareVpToken","
|
1
|
+
{"version":3,"names":["decode","prepareVpToken","JSONPath","CredentialsNotFoundError","MissingDataError","Ajv","ajv","allErrors","INDEX_CLAIM_NAME","mapDisclosuresToObject","disclosures","reduce","obj","_ref","decoded","claimName","claimValue","findMatchedClaim","paths","payload","matchedPath","matchedValue","some","singlePath","result","path","json","length","error","extractClaimName","regex","match","Error","evaluateInputDescriptorForSdJwt4VC","inputDescriptor","payloadCredential","_inputDescriptor$cons","constraints","fields","requiredDisclosures","optionalDisclosures","unrequestedDisclosures","requiredClaimNames","optionalClaimNames","disclosuresAsPayload","allFieldsValid","every","field","optional","push","filter","validateSchema","compile","disclosure","includes","isNotLimitDisclosure","limit_disclosure","findCredentialSdJwt","decodedSdJwtCredentials","cryptoContext","credential","sdJwt","evaluatedDisclosure","matchedEvaluation","matchedCredential","id","reason","evaluateInputDescriptors","inputDescriptors","credentialsSdJwt","map","_ref2","Promise","all","descriptor","_descriptor$format","format","prepareLegacyRemotePresentations","credentialAndDescriptors","nonce","client_id","item","_descriptor$format2","vp_token","requestedClaims","vpToken"],"sourceRoot":"../../../../src","sources":["credential/presentation/07-evaluate-input-descriptor.ts"],"mappings":"AAEA,SAASA,MAAM,EAAEC,cAAc,QAAQ,cAAc;AACrD,SAASC,QAAQ,QAAQ,eAAe;AACxC,SAASC,wBAAwB,EAAEC,gBAAgB,QAAQ,UAAU;AACrE,OAAOC,GAAG,MAAM,KAAK;AAGrB,MAAMC,GAAG,GAAG,IAAID,GAAG,CAAC;EAAEE,SAAS,EAAE;AAAK,CAAC,CAAC;AACxC,MAAMC,gBAAgB,GAAG,CAAC;;AA6B1B;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;AACA,MAAMC,sBAAsB,GAC1BC,WAAoC,IACR;EAC5B,OAAOA,WAAW,CAACC,MAAM,CACvB,CAACC,GAAG,EAAAC,IAAA,KAAkB;IAAA,IAAhB;MAAEC;IAAQ,CAAC,GAAAD,IAAA;IACf,MAAM,GAAGE,SAAS,EAAEC,UAAU,CAAC,GAAGF,OAAO;IACzC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AE;MACV,CAAC;IACH;IAEA,MAAM,IAAIzE,wBAAwB,CAAC,CACjC;MACE8D,EAAE,EAAES,UAAU,CAACT,EAAE;MACjBC,MAAM,EAAG,GAAEQ,UAAU,CAACE,MAAO;IAC/B,CAAC,CACF,CAAC;EACJ,CAAC,CACH,CAAC;AACH,CAAC"}
|
@@ -86,7 +86,7 @@ export const RequestObject = z.object({
|
|
86
86
|
state: z.string().optional(),
|
87
87
|
nonce: z.string(),
|
88
88
|
response_uri: z.string(),
|
89
|
-
|
89
|
+
request_uri_method: z.string().optional(),
|
90
90
|
response_type: z.literal("vp_token"),
|
91
91
|
response_mode: z.literal("direct_post.jwt"),
|
92
92
|
client_id: z.string(),
|
@@ -1 +1 @@
|
|
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","
|
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","request_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","ErrorResponse","LegacyDirectAuthorizationBodyPayload","vp_token","union","presentation_submission","unknown","DirectAuthorizationBodyPayload","error","error_description"],"sourceRoot":"../../../../src","sources":["credential/presentation/types.ts"],"mappings":"AACA,SAASA,QAAQ,QAAQ,oBAAoB;AAC7C,OAAO,KAAKC,CAAC,MAAM,KA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AE1D,CAAC,CAAC2D,KAAK,CAAC,CAAC3D,CAAC,CAACK,MAAM,CAAC,CAAC,EAAEL,CAAC,CAACI,KAAK,CAACJ,CAAC,CAACK,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAACG,QAAQ,CAAC,CAAC;EAC/DoD,uBAAuB,EAAE5D,CAAC,CAACqB,MAAM,CAACrB,CAAC,CAACK,MAAM,CAAC,CAAC,EAAEL,CAAC,CAAC6D,OAAO,CAAC,CAAC;AAC3D,CAAC,CAAC;;AAEF;AACA;AACA;;AAIA,OAAO,MAAMC,8BAA8B,GAAG9D,CAAC,CAAC2D,KAAK,CAAC,CACpD3D,CAAC,CAACE,MAAM,CAAC;EACPwD,QAAQ,EAAE1D,CAAC,CAACqB,MAAM,CAACrB,CAAC,CAACK,MAAM,CAAC,CAAC,EAAEL,CAAC,CAACK,MAAM,CAAC,CAAC;AAC3C,CAAC,CAAC,EACFL,CAAC,CAACE,MAAM,CAAC;EAAE6D,KAAK,EAAEP,aAAa;EAAEQ,iBAAiB,EAAEhE,CAAC,CAACK,MAAM,CAAC;AAAE,CAAC,CAAC,EACjEoD,oCAAoC,CACrC,CAAC"}
|
@@ -1,36 +1,44 @@
|
|
1
1
|
import { getCredentialHashWithouDiscloures, hasStatusOrThrow } from "../../utils/misc";
|
2
2
|
import { SignJWT } from "@pagopa/io-react-native-jwt";
|
3
3
|
import { v4 as uuidv4 } from "uuid";
|
4
|
-
import {
|
4
|
+
import { StatusAssertionResponse } from "./types";
|
5
5
|
import { IssuerResponseError, IssuerResponseErrorCodes, ResponseErrorBuilder, UnexpectedStatusCodeError } from "../../utils/errors";
|
6
|
-
import {
|
6
|
+
import { Logger, LogLevel } from "../../utils/logging";
|
7
|
+
import { extractJwkFromCredential } from "../../utils/credentials";
|
7
8
|
/**
|
8
|
-
*
|
9
|
-
* Verify the status of the credential attestation.
|
9
|
+
* Get the status assertion of a digital credential.
|
10
10
|
* @param issuerConf - The issuer's configuration
|
11
11
|
* @param credential - The credential to be verified
|
12
|
-
* @param
|
12
|
+
* @param format - The format of the credential, e.g. "sd-jwt"
|
13
|
+
* @param context.credentialCryptoContext - The credential's crypto context
|
14
|
+
* @param context.wiaCryptoContext - The Wallet Attestation's crypto context
|
13
15
|
* @param context.appFetch (optional) fetch api implementation. Default: built-in fetch
|
14
16
|
* @throws {IssuerResponseError} with a specific code for more context
|
15
|
-
* @returns The credential status
|
17
|
+
* @returns The credential status assertion
|
16
18
|
*/
|
17
|
-
export const
|
18
|
-
|
19
|
-
|
19
|
+
export const statusAssertion = async (issuerConf, credential, format, ctx) => {
|
20
|
+
const {
|
21
|
+
credentialCryptoContext,
|
22
|
+
wiaCryptoContext,
|
23
|
+
appFetch = fetch
|
24
|
+
} = ctx;
|
25
|
+
const jwk = await extractJwkFromCredential(credential, format);
|
26
|
+
const issuerJwk = await wiaCryptoContext.getPublicKey();
|
20
27
|
const credentialHash = await getCredentialHashWithouDiscloures(credential);
|
21
28
|
const statusAttUrl = issuerConf.openid_credential_issuer.status_attestation_endpoint;
|
22
29
|
const credentialPop = await new SignJWT(credentialCryptoContext).setPayload({
|
30
|
+
iss: issuerJwk.kid,
|
23
31
|
aud: statusAttUrl,
|
24
32
|
jti: uuidv4().toString(),
|
25
33
|
credential_hash: credentialHash,
|
26
|
-
credential_hash_alg: "
|
34
|
+
credential_hash_alg: "sha-256"
|
27
35
|
}).setProtectedHeader({
|
28
36
|
alg: "ES256",
|
29
|
-
typ: "status-
|
37
|
+
typ: "status-assertion-request+jwt",
|
30
38
|
kid: jwk.kid
|
31
39
|
}).setIssuedAt().setExpirationTime("5m").sign();
|
32
40
|
const body = {
|
33
|
-
|
41
|
+
status_assertion_requests: [credentialPop]
|
34
42
|
};
|
35
43
|
Logger.log(LogLevel.DEBUG, `Credential pop: ${credentialPop}`);
|
36
44
|
const result = await appFetch(statusAttUrl, {
|
@@ -39,28 +47,26 @@ export const statusAttestation = async function (issuerConf, credential, credent
|
|
39
47
|
"Content-Type": "application/json"
|
40
48
|
},
|
41
49
|
body: JSON.stringify(body)
|
42
|
-
}).then(hasStatusOrThrow(
|
50
|
+
}).then(hasStatusOrThrow(200)).then(raw => raw.json()).then(json => StatusAssertionResponse.parse(json)).catch(handleStatusAssertionError);
|
51
|
+
const [statusAttestationJwt] = result.status_assertion_responses;
|
43
52
|
return {
|
44
|
-
|
53
|
+
statusAssertion: statusAttestationJwt
|
45
54
|
};
|
46
55
|
};
|
47
56
|
|
48
57
|
/**
|
49
|
-
* Handle the status
|
58
|
+
* Handle the status assertion error by mapping it to a custom exception.
|
50
59
|
* If the error is not an instance of {@link UnexpectedStatusCodeError}, it is thrown as is.
|
51
60
|
* @param e - The error to be handled
|
52
61
|
* @throws {IssuerResponseError} with a specific code for more context
|
53
62
|
*/
|
54
|
-
const
|
63
|
+
const handleStatusAssertionError = e => {
|
55
64
|
if (!(e instanceof UnexpectedStatusCodeError)) {
|
56
65
|
throw e;
|
57
66
|
}
|
58
|
-
throw new ResponseErrorBuilder(IssuerResponseError).handle(
|
59
|
-
code: IssuerResponseErrorCodes.CredentialInvalidStatus,
|
60
|
-
message: "Invalid status found for the given credential"
|
61
|
-
}).handle("*", {
|
67
|
+
throw new ResponseErrorBuilder(IssuerResponseError).handle("*", {
|
62
68
|
code: IssuerResponseErrorCodes.StatusAttestationRequestFailed,
|
63
|
-
message: `Unable to obtain the status
|
69
|
+
message: `Unable to obtain the status assertion for the given credential`
|
64
70
|
}).buildFrom(e);
|
65
71
|
};
|
66
|
-
//# sourceMappingURL=02-status-
|
72
|
+
//# sourceMappingURL=02-status-assertion.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["getCredentialHashWithouDiscloures","hasStatusOrThrow","SignJWT","v4","uuidv4","StatusAssertionResponse","IssuerResponseError","IssuerResponseErrorCodes","ResponseErrorBuilder","UnexpectedStatusCodeError","Logger","LogLevel","extractJwkFromCredential","statusAssertion","issuerConf","credential","format","ctx","credentialCryptoContext","wiaCryptoContext","appFetch","fetch","jwk","issuerJwk","getPublicKey","credentialHash","statusAttUrl","openid_credential_issuer","status_attestation_endpoint","credentialPop","setPayload","iss","kid","aud","jti","toString","credential_hash","credential_hash_alg","setProtectedHeader","alg","typ","setIssuedAt","setExpirationTime","sign","body","status_assertion_requests","log","DEBUG","result","method","headers","JSON","stringify","then","raw","json","parse","catch","handleStatusAssertionError","statusAttestationJwt","status_assertion_responses","e","handle","code","StatusAttestationRequestFailed","message","buildFrom"],"sourceRoot":"../../../../src","sources":["credential/status/02-status-assertion.ts"],"mappings":"AAAA,SACEA,iCAAiC,EACjCC,gBAAgB,QAEX,kBAAkB;AAEzB,SAA6BC,OAAO,QAAQ,6BAA6B;AACzE,SAASC,EAAE,IAAIC,MAAM,QAAQ,MAAM;AACnC,SAASC,uBAAuB,QAAQ,SAAS;AACjD,SACEC,mBAAmB,EACnBC,wBAAwB,EACxBC,oBAAoB,EACpBC,yBAAyB,QACpB,oBAAoB;AAC3B,SAASC,MAAM,EAAEC,QAAQ,QAAQ,qBAAqB;AACtD,SAASC,wBAAwB,QAAQ,yBAAyB;AAelE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,eAAgC,GAAG,MAAAA,CAC9CC,UAAU,EACVC,UAAU,EACVC,MAAM,EACNC,GAAG,KACA;EACH,MAAM;IAAEC,uBAAuB;IAAEC,gBAAgB;IAAEC,QAAQ,GAAGC;EAAM,CAAC,GAAGJ,GAAG;EAE3E,MAAMK,GAAG,GAAG,MAAMV,wBAAwB,CAACG,UAAU,EAAEC,MAAM,CAAC;EAC9D,MAAMO,SAAS,GAAG,MAAMJ,gBAAgB,CAACK,YAAY,CAAC,CAAC;EACvD,MAAMC,cAAc,GAAG,MAAMzB,iCAAiC,CAACe,UAAU,CAAC;EAC1E,MAAMW,YAAY,GAChBZ,UAAU,CAACa,wBAAwB,CAACC,2BAA2B;EAEjE,MAAMC,aAAa,GAAG,MAAM,IAAI3B,OAAO,CAACgB,uBAAuB,CAA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,EAAEA,CAAC,YAAYpD,yBAAyB,CAAC,EAAE;IAC7C,MAAMoD,CAAC;EACT;EAEA,MAAM,IAAIrD,oBAAoB,CAACF,mBAAmB,CAAC,CAChDwD,MAAM,CAAC,GAAG,EAAE;IACXC,IAAI,EAAExD,wBAAwB,CAACyD,8BAA8B;IAC7DC,OAAO,EAAG;EACZ,CAAC,CAAC,CACDC,SAAS,CAACL,CAAC,CAAC;AACjB,CAAC"}
|
@@ -0,0 +1,78 @@
|
|
1
|
+
import { IoWalletError, IssuerResponseError, IssuerResponseErrorCodes } from "../../utils/errors";
|
2
|
+
import { decode as decodeJwt, verify } from "@pagopa/io-react-native-jwt";
|
3
|
+
import { ParsedStatusAssertionResponse, StatusType } from "./types";
|
4
|
+
import { Logger, LogLevel } from "../../utils/logging";
|
5
|
+
import { extractJwkFromCredential } from "../../utils/credentials";
|
6
|
+
import { isSameThumbprint } from "../../utils/jwk";
|
7
|
+
/**
|
8
|
+
* Given a status assertion, verifies that:
|
9
|
+
* - It's in the supported format;
|
10
|
+
* - The assertion is correctly signed;
|
11
|
+
* - It's bound to the given key.
|
12
|
+
* @param issuerConf The Issuer configuration returned by {@link evaluateIssuerTrust}
|
13
|
+
* @param statusAssertion The encoded status assertion returned by {@link statusAssertion}
|
14
|
+
* @param context.credentialCryptoContext The crypto context used to obtain the credential in {@link obtainCredential}
|
15
|
+
* @returns A parsed status assertion
|
16
|
+
* @throws {IoWalletError} If the credential signature is not verified with the Issuer key set
|
17
|
+
* @throws {IssuerResponseError} If the status assertion contains an error or the credential status is invalid
|
18
|
+
*/
|
19
|
+
export const verifyAndParseStatusAssertion = async (issuerConf, rawStatusAssertion, credential, format) => {
|
20
|
+
const {
|
21
|
+
statusAssertion
|
22
|
+
} = rawStatusAssertion;
|
23
|
+
await verify(statusAssertion, issuerConf.openid_credential_issuer.jwks.keys);
|
24
|
+
const decodedJwt = decodeJwt(statusAssertion);
|
25
|
+
const parsedStatusAssertion = ParsedStatusAssertionResponse.parse({
|
26
|
+
header: decodedJwt.protectedHeader,
|
27
|
+
payload: decodedJwt.payload
|
28
|
+
});
|
29
|
+
Logger.log(LogLevel.DEBUG, `Parsed status assertion: ${JSON.stringify(parsedStatusAssertion)}`);
|
30
|
+
|
31
|
+
// Errors are transmitted in the JWT and use a 200 HTTP status code
|
32
|
+
if (isStatusAssertionError(parsedStatusAssertion)) {
|
33
|
+
throw new IssuerResponseError({
|
34
|
+
code: IssuerResponseErrorCodes.CredentialInvalidStatus,
|
35
|
+
message: "The status assertion contains an error",
|
36
|
+
statusCode: 200,
|
37
|
+
reason: buildErrorReason(parsedStatusAssertion)
|
38
|
+
});
|
39
|
+
}
|
40
|
+
const {
|
41
|
+
cnf,
|
42
|
+
credential_status_type
|
43
|
+
} = parsedStatusAssertion.payload;
|
44
|
+
const holderBindingKey = await extractJwkFromCredential(credential, format);
|
45
|
+
if (!(await isSameThumbprint(cnf.jwk, holderBindingKey))) {
|
46
|
+
const errorMessage = `Failed to verify holder binding for status assertion: the thumbprints of keys ${cnf.jwk.kid} and ${holderBindingKey.kid} do not match`;
|
47
|
+
Logger.log(LogLevel.ERROR, errorMessage);
|
48
|
+
throw new IoWalletError(errorMessage);
|
49
|
+
}
|
50
|
+
if (credential_status_type !== StatusType.VALID) {
|
51
|
+
throw new IssuerResponseError({
|
52
|
+
code: IssuerResponseErrorCodes.CredentialInvalidStatus,
|
53
|
+
message: "Invalid status found for the given credential",
|
54
|
+
statusCode: 200,
|
55
|
+
reason: buildErrorReason(parsedStatusAssertion)
|
56
|
+
});
|
57
|
+
}
|
58
|
+
return {
|
59
|
+
parsedStatusAssertion
|
60
|
+
};
|
61
|
+
};
|
62
|
+
const isStatusAssertionError = assertion => assertion.header.typ === "status-assertion-error+jwt";
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Build an object containing the details on the error to use as the IssuerResponseError's reason
|
66
|
+
* @param assertion The status assertion response, both success or failure
|
67
|
+
* @returns The error's reason object
|
68
|
+
*/
|
69
|
+
const buildErrorReason = _ref => {
|
70
|
+
let {
|
71
|
+
payload
|
72
|
+
} = _ref;
|
73
|
+
return "error" in payload ? payload : {
|
74
|
+
error: payload.credential_status_detail.state,
|
75
|
+
error_description: payload.credential_status_detail.description
|
76
|
+
};
|
77
|
+
};
|
78
|
+
//# sourceMappingURL=03-verify-and-parse-status-assertion.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["IoWalletError","IssuerResponseError","IssuerResponseErrorCodes","decode","decodeJwt","verify","ParsedStatusAssertionResponse","StatusType","Logger","LogLevel","extractJwkFromCredential","isSameThumbprint","verifyAndParseStatusAssertion","issuerConf","rawStatusAssertion","credential","format","statusAssertion","openid_credential_issuer","jwks","keys","decodedJwt","parsedStatusAssertion","parse","header","protectedHeader","payload","log","DEBUG","JSON","stringify","isStatusAssertionError","code","CredentialInvalidStatus","message","statusCode","reason","buildErrorReason","cnf","credential_status_type","holderBindingKey","jwk","errorMessage","kid","ERROR","VALID","assertion","typ","_ref","error","credential_status_detail","state","error_description","description"],"sourceRoot":"../../../../src","sources":["credential/status/03-verify-and-parse-status-assertion.ts"],"mappings":"AACA,SACEA,aAAa,EACbC,mBAAmB,EACnBC,wBAAwB,QACnB,oBAAoB;AAC3B,SAASC,MAAM,IAAIC,SAAS,EAAEC,MAAM,QAAQ,6BAA6B;AAEzE,SAIEC,6BAA6B,EAC7BC,UAAU,QACL,SAAS;AAChB,SAASC,MAAM,EAAEC,QAAQ,QAAQ,qBAAqB;AAEtD,SAASC,wBAAwB,QAAQ,yBAAyB;AAClE,SAASC,gBAAgB,QAAQ,iBAAiB;AASlD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,6BAA4D,GACvE,MAAAA,CAAOC,UAAU,EAAEC,kBAAkB,EAAEC,UAAU,EAAEC,MAAM,KAAK;EAC5D,MAAM;IAAEC;EAAgB,CAAC,GAAGH,kBAAkB;EAE9C,MAAMT,MAAM,CACVY,eAAe,EACfJ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