@pagopa/io-wallet-oauth2 1.5.8 → 2.0.0-launchpad
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/dist/index.d.mts +962 -1340
- package/dist/index.d.ts +962 -1340
- package/dist/index.js +407 -670
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +361 -571
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -6
package/dist/index.mjs
CHANGED
|
@@ -10,180 +10,20 @@ var createTokenRequest = async (options) => ({
|
|
|
10
10
|
// src/access-token/create-token-response.ts
|
|
11
11
|
import {
|
|
12
12
|
HashAlgorithm,
|
|
13
|
-
calculateJwkThumbprint
|
|
14
|
-
} from "@openid4vc/oauth2";
|
|
15
|
-
import {
|
|
16
13
|
addSecondsToDate,
|
|
14
|
+
calculateJwkThumbprint,
|
|
17
15
|
dateToSeconds,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// src/common/jwt/decode-jwt-header.ts
|
|
22
|
-
import { Oauth2JwtParseError } from "@openid4vc/oauth2";
|
|
23
|
-
import {
|
|
24
|
-
decodeBase64,
|
|
25
|
-
encodeToUtf8String,
|
|
26
|
-
formatError,
|
|
27
|
-
parseWithErrorHandling,
|
|
28
|
-
stringToJsonWithErrorHandling
|
|
16
|
+
jwtHeaderFromJwtSigner,
|
|
17
|
+
parseWithErrorHandling
|
|
29
18
|
} from "@pagopa/io-wallet-utils";
|
|
30
19
|
|
|
31
|
-
// src/common/jwt/z-jwt.ts
|
|
32
|
-
import z3 from "zod";
|
|
33
|
-
|
|
34
|
-
// src/common/jwk/z-jwk.ts
|
|
35
|
-
import z2 from "zod";
|
|
36
|
-
|
|
37
|
-
// src/common/z-common.ts
|
|
38
|
-
import z from "zod";
|
|
39
|
-
var zTrustChain = z.tuple([z.string()], z.string());
|
|
40
|
-
var zCertificateChain = z.array(z.string()).nonempty();
|
|
41
|
-
var zAlgValueNotNone = z.string().refine((alg) => alg !== "none", { message: `alg value may not be 'none'` });
|
|
42
|
-
|
|
43
|
-
// src/common/jwk/z-jwk.ts
|
|
44
|
-
var zJwk = z2.looseObject({
|
|
45
|
-
alg: z2.optional(z2.string()),
|
|
46
|
-
crv: z2.optional(z2.string()),
|
|
47
|
-
d: z2.optional(z2.string()),
|
|
48
|
-
dp: z2.optional(z2.string()),
|
|
49
|
-
dq: z2.optional(z2.string()),
|
|
50
|
-
e: z2.optional(z2.string()),
|
|
51
|
-
ext: z2.optional(z2.boolean()),
|
|
52
|
-
k: z2.optional(z2.string()),
|
|
53
|
-
key_ops: z2.optional(z2.array(z2.string())),
|
|
54
|
-
kid: z2.optional(z2.string()),
|
|
55
|
-
kty: z2.string(),
|
|
56
|
-
n: z2.optional(z2.string()),
|
|
57
|
-
oth: z2.optional(
|
|
58
|
-
z2.array(
|
|
59
|
-
z2.looseObject({
|
|
60
|
-
d: z2.optional(z2.string()),
|
|
61
|
-
r: z2.optional(z2.string()),
|
|
62
|
-
t: z2.optional(z2.string())
|
|
63
|
-
})
|
|
64
|
-
)
|
|
65
|
-
),
|
|
66
|
-
p: z2.optional(z2.string()),
|
|
67
|
-
q: z2.optional(z2.string()),
|
|
68
|
-
qi: z2.optional(z2.string()),
|
|
69
|
-
use: z2.optional(z2.string()),
|
|
70
|
-
x: z2.optional(z2.string()),
|
|
71
|
-
x5c: z2.optional(zCertificateChain),
|
|
72
|
-
x5t: z2.optional(z2.string()),
|
|
73
|
-
"x5t#S256": z2.optional(z2.string()),
|
|
74
|
-
x5u: z2.optional(z2.string()),
|
|
75
|
-
y: z2.optional(z2.string())
|
|
76
|
-
});
|
|
77
|
-
var zJwkSet = z2.looseObject({ keys: z2.array(zJwk) });
|
|
78
|
-
|
|
79
|
-
// src/common/jwt/z-jwt.ts
|
|
80
|
-
var MAX_JTI_LENGTH = 256;
|
|
81
|
-
var zCompactJwt = z3.string().regex(/^([a-zA-Z0-9-_]+)\.([a-zA-Z0-9-_]+)\.([a-zA-Z0-9-_]+)$/, {
|
|
82
|
-
message: "Not a valid compact jwt"
|
|
83
|
-
});
|
|
84
|
-
var zJwtConfirmationPayload = z3.looseObject({
|
|
85
|
-
// RFC9449. jwk thumbprint of the dpop public key to which the access token is bound
|
|
86
|
-
jkt: z3.string().optional(),
|
|
87
|
-
jwk: zJwk.optional()
|
|
88
|
-
});
|
|
89
|
-
var zJwtPayload = z3.looseObject({
|
|
90
|
-
aud: z3.string().optional(),
|
|
91
|
-
cnf: zJwtConfirmationPayload.optional(),
|
|
92
|
-
exp: z3.number().int().optional(),
|
|
93
|
-
iat: z3.number().int().optional(),
|
|
94
|
-
iss: z3.string().optional(),
|
|
95
|
-
jti: z3.string().max(MAX_JTI_LENGTH).optional(),
|
|
96
|
-
nbf: z3.number().int().optional(),
|
|
97
|
-
nonce: z3.string().optional(),
|
|
98
|
-
// Reserved for status parameters
|
|
99
|
-
status: z3.record(z3.string(), z3.any()).optional(),
|
|
100
|
-
// Reserved for OpenID Federation
|
|
101
|
-
trust_chain: zTrustChain.optional()
|
|
102
|
-
});
|
|
103
|
-
var zJwtHeader = z3.looseObject({
|
|
104
|
-
alg: zAlgValueNotNone,
|
|
105
|
-
jwk: zJwk.optional(),
|
|
106
|
-
kid: z3.string().optional(),
|
|
107
|
-
// Reserved for OpenID Federation
|
|
108
|
-
trust_chain: zTrustChain.optional(),
|
|
109
|
-
typ: z3.string().optional(),
|
|
110
|
-
x5c: zCertificateChain.optional()
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
// src/common/jwt/decode-jwt-header.ts
|
|
114
|
-
function decodeJwtHeader(options) {
|
|
115
|
-
const jwtParts = options.jwt.split(".");
|
|
116
|
-
if (jwtParts.length <= 2) {
|
|
117
|
-
throw new Oauth2JwtParseError(
|
|
118
|
-
formatError(
|
|
119
|
-
"Unable to decode because Jwt is not a valid!",
|
|
120
|
-
options.errorMessagePrefix
|
|
121
|
-
)
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
const [headerPart] = jwtParts;
|
|
125
|
-
let headerJson;
|
|
126
|
-
try {
|
|
127
|
-
headerJson = stringToJsonWithErrorHandling(
|
|
128
|
-
encodeToUtf8String(decodeBase64(headerPart)),
|
|
129
|
-
formatError(
|
|
130
|
-
"Unable to parse jwt header to JSON",
|
|
131
|
-
options.errorMessagePrefix
|
|
132
|
-
)
|
|
133
|
-
);
|
|
134
|
-
} catch (error) {
|
|
135
|
-
throw new Oauth2JwtParseError(
|
|
136
|
-
formatError(
|
|
137
|
-
`Error parsing JWT. ${error instanceof Error ? error.message : ""}`,
|
|
138
|
-
options.errorMessagePrefix
|
|
139
|
-
)
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
const header = parseWithErrorHandling(
|
|
143
|
-
options.headerSchema ?? zJwtHeader,
|
|
144
|
-
headerJson,
|
|
145
|
-
formatError("Invalid JWT header", options.errorMessagePrefix)
|
|
146
|
-
);
|
|
147
|
-
return {
|
|
148
|
-
header
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
function jwtHeaderFromJwtSigner(signer) {
|
|
152
|
-
if (signer.method === "did") {
|
|
153
|
-
return {
|
|
154
|
-
alg: signer.alg,
|
|
155
|
-
kid: signer.didUrl
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
if (signer.method === "federation") {
|
|
159
|
-
return {
|
|
160
|
-
alg: signer.alg,
|
|
161
|
-
kid: signer.kid,
|
|
162
|
-
trust_chain: signer.trustChain
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
if (signer.method === "jwk") {
|
|
166
|
-
return {
|
|
167
|
-
alg: signer.alg,
|
|
168
|
-
jwk: signer.publicJwk
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
if (signer.method === "x5c") {
|
|
172
|
-
return {
|
|
173
|
-
alg: signer.alg,
|
|
174
|
-
kid: signer.kid,
|
|
175
|
-
trust_chain: signer.trustChain,
|
|
176
|
-
x5c: signer.x5c
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
return { alg: signer.alg };
|
|
180
|
-
}
|
|
181
|
-
|
|
182
20
|
// src/errors.ts
|
|
183
21
|
var Oauth2Error = class extends Error {
|
|
184
22
|
statusCode;
|
|
185
23
|
constructor(message, options) {
|
|
186
|
-
|
|
24
|
+
const errorMessage = message ?? "Unknown error occurred.";
|
|
25
|
+
const causeMessage = options?.cause instanceof Error ? ` ${options.cause.message}` : options?.cause ? ` ${String(options.cause)}` : "";
|
|
26
|
+
super(`${errorMessage}${causeMessage}`, options);
|
|
187
27
|
this.name = "Oauth2Error";
|
|
188
28
|
this.statusCode = options?.statusCode;
|
|
189
29
|
}
|
|
@@ -234,70 +74,75 @@ var ClientAttestationError = class extends Oauth2Error {
|
|
|
234
74
|
};
|
|
235
75
|
|
|
236
76
|
// src/access-token/z-token.ts
|
|
237
|
-
import {
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
77
|
+
import {
|
|
78
|
+
MAX_JTI_LENGTH,
|
|
79
|
+
zJwtHeader,
|
|
80
|
+
zJwtPayload
|
|
81
|
+
} from "@pagopa/io-wallet-utils";
|
|
82
|
+
import { z } from "zod";
|
|
83
|
+
var zAccessTokenRequest = z.discriminatedUnion("grant_type", [
|
|
84
|
+
z.object({
|
|
85
|
+
code: z.string().nonempty(),
|
|
86
|
+
code_verifier: z.string().nonempty(),
|
|
87
|
+
grant_type: z.literal("authorization_code"),
|
|
88
|
+
redirect_uri: z.string().nonempty()
|
|
244
89
|
}),
|
|
245
|
-
|
|
246
|
-
grant_type:
|
|
247
|
-
refresh_token:
|
|
248
|
-
scope:
|
|
90
|
+
z.object({
|
|
91
|
+
grant_type: z.literal("refresh_token"),
|
|
92
|
+
refresh_token: z.string().nonempty(),
|
|
93
|
+
scope: z.string().optional()
|
|
249
94
|
})
|
|
250
95
|
]);
|
|
251
|
-
var zAccessTokenResponse =
|
|
252
|
-
access_token:
|
|
253
|
-
authorization_details:
|
|
254
|
-
|
|
255
|
-
credential_configuration_id:
|
|
256
|
-
credential_identifiers:
|
|
257
|
-
type:
|
|
96
|
+
var zAccessTokenResponse = z.looseObject({
|
|
97
|
+
access_token: z.string(),
|
|
98
|
+
authorization_details: z.array(
|
|
99
|
+
z.looseObject({
|
|
100
|
+
credential_configuration_id: z.optional(z.string()),
|
|
101
|
+
credential_identifiers: z.optional(z.array(z.string())),
|
|
102
|
+
type: z.literal("openid_credential")
|
|
258
103
|
})
|
|
259
104
|
).optional(),
|
|
260
|
-
expires_in:
|
|
261
|
-
refresh_token:
|
|
262
|
-
token_type:
|
|
105
|
+
expires_in: z.optional(z.number().int()),
|
|
106
|
+
refresh_token: z.optional(z.string()),
|
|
107
|
+
token_type: z.union([z.literal("Bearer"), z.literal("DPoP")])
|
|
263
108
|
});
|
|
264
|
-
var zAccessTokenProfileJwtHeader =
|
|
109
|
+
var zAccessTokenProfileJwtHeader = z.looseObject({
|
|
265
110
|
...zJwtHeader.shape,
|
|
266
|
-
typ:
|
|
111
|
+
typ: z.enum(["application/at+jwt", "at+jwt"])
|
|
267
112
|
});
|
|
268
|
-
var zAccessTokenProfileJwtPayload =
|
|
113
|
+
var zAccessTokenProfileJwtPayload = z.looseObject({
|
|
269
114
|
...zJwtPayload.shape,
|
|
270
|
-
aud:
|
|
271
|
-
client_id:
|
|
272
|
-
cnf:
|
|
273
|
-
jkt:
|
|
115
|
+
aud: z.string(),
|
|
116
|
+
client_id: z.string(),
|
|
117
|
+
cnf: z.object({
|
|
118
|
+
jkt: z.string()
|
|
274
119
|
}).optional(),
|
|
275
|
-
exp:
|
|
276
|
-
iat:
|
|
277
|
-
iss:
|
|
278
|
-
jti:
|
|
279
|
-
nbf:
|
|
280
|
-
scope:
|
|
281
|
-
sub:
|
|
120
|
+
exp: z.number(),
|
|
121
|
+
iat: z.number(),
|
|
122
|
+
iss: z.string(),
|
|
123
|
+
jti: z.string().max(MAX_JTI_LENGTH),
|
|
124
|
+
nbf: z.number().optional(),
|
|
125
|
+
scope: z.string().optional(),
|
|
126
|
+
sub: z.string()
|
|
282
127
|
});
|
|
283
|
-
var zRefreshTokenProfileJwtHeader =
|
|
128
|
+
var zRefreshTokenProfileJwtHeader = z.looseObject({
|
|
284
129
|
...zJwtHeader.shape,
|
|
285
|
-
kid:
|
|
286
|
-
typ:
|
|
130
|
+
kid: z.string(),
|
|
131
|
+
typ: z.literal("rt+jwt")
|
|
287
132
|
});
|
|
288
|
-
var zRefreshTokenProfileJwtPayload =
|
|
133
|
+
var zRefreshTokenProfileJwtPayload = z.looseObject({
|
|
289
134
|
...zJwtPayload.shape,
|
|
290
|
-
aud:
|
|
291
|
-
client_id:
|
|
292
|
-
cnf:
|
|
293
|
-
jkt:
|
|
135
|
+
aud: z.string(),
|
|
136
|
+
client_id: z.string(),
|
|
137
|
+
cnf: z.object({
|
|
138
|
+
jkt: z.string()
|
|
294
139
|
}),
|
|
295
|
-
exp:
|
|
296
|
-
iat:
|
|
297
|
-
iss:
|
|
298
|
-
jti:
|
|
299
|
-
nbf:
|
|
300
|
-
sub:
|
|
140
|
+
exp: z.number().int(),
|
|
141
|
+
iat: z.number().int(),
|
|
142
|
+
iss: z.string(),
|
|
143
|
+
jti: z.string().max(MAX_JTI_LENGTH),
|
|
144
|
+
nbf: z.number().int(),
|
|
145
|
+
sub: z.string()
|
|
301
146
|
});
|
|
302
147
|
|
|
303
148
|
// src/access-token/create-token-response.ts
|
|
@@ -353,11 +198,11 @@ async function createAccessTokenResponse(options) {
|
|
|
353
198
|
now,
|
|
354
199
|
options.expiresInSeconds
|
|
355
200
|
);
|
|
356
|
-
const header =
|
|
201
|
+
const header = parseWithErrorHandling(zAccessTokenProfileJwtHeader, {
|
|
357
202
|
...jwtHeaderFromJwtSigner(options.signer),
|
|
358
203
|
typ: "at+jwt"
|
|
359
204
|
});
|
|
360
|
-
const payload =
|
|
205
|
+
const payload = parseWithErrorHandling(zAccessTokenProfileJwtPayload, {
|
|
361
206
|
...options.additionalPayload,
|
|
362
207
|
aud: options.audience,
|
|
363
208
|
client_id: options.clientId,
|
|
@@ -382,7 +227,7 @@ async function createAccessTokenResponse(options) {
|
|
|
382
227
|
"Unable to resolve a kid for the Refresh Token JOSE header. Provide signer.kid or a publicJwk.kid."
|
|
383
228
|
);
|
|
384
229
|
}
|
|
385
|
-
const refreshTokenHeader =
|
|
230
|
+
const refreshTokenHeader = parseWithErrorHandling(
|
|
386
231
|
zRefreshTokenProfileJwtHeader,
|
|
387
232
|
{
|
|
388
233
|
alg: options.signer.alg,
|
|
@@ -390,7 +235,7 @@ async function createAccessTokenResponse(options) {
|
|
|
390
235
|
typ: "rt+jwt"
|
|
391
236
|
}
|
|
392
237
|
);
|
|
393
|
-
const refreshTokenPayload =
|
|
238
|
+
const refreshTokenPayload = parseWithErrorHandling(
|
|
394
239
|
zRefreshTokenProfileJwtPayload,
|
|
395
240
|
{
|
|
396
241
|
aud: options.authorizationServer,
|
|
@@ -415,7 +260,7 @@ async function createAccessTokenResponse(options) {
|
|
|
415
260
|
);
|
|
416
261
|
refreshToken = refreshTokenSignResult.jwt;
|
|
417
262
|
}
|
|
418
|
-
const accessTokenResponse =
|
|
263
|
+
const accessTokenResponse = parseWithErrorHandling(zAccessTokenResponse, {
|
|
419
264
|
...options.additionalPayload,
|
|
420
265
|
access_token: jwt,
|
|
421
266
|
expires_in: options.expiresInSeconds,
|
|
@@ -441,7 +286,7 @@ import {
|
|
|
441
286
|
ValidationError,
|
|
442
287
|
createFetcher,
|
|
443
288
|
hasStatusOrThrow,
|
|
444
|
-
parseWithErrorHandling as
|
|
289
|
+
parseWithErrorHandling as parseWithErrorHandling2
|
|
445
290
|
} from "@pagopa/io-wallet-utils";
|
|
446
291
|
async function fetchTokenResponse(options) {
|
|
447
292
|
try {
|
|
@@ -457,7 +302,7 @@ async function fetchTokenResponse(options) {
|
|
|
457
302
|
method: "POST"
|
|
458
303
|
});
|
|
459
304
|
await hasStatusOrThrow(200, UnexpectedStatusCodeError)(tokenResponse);
|
|
460
|
-
return
|
|
305
|
+
return parseWithErrorHandling2(
|
|
461
306
|
zAccessTokenResponse,
|
|
462
307
|
await tokenResponse.json(),
|
|
463
308
|
"Failed to parse token response"
|
|
@@ -489,98 +334,29 @@ import {
|
|
|
489
334
|
} from "@pagopa/io-wallet-utils";
|
|
490
335
|
|
|
491
336
|
// src/client-attestation/wallet-attestation.ts
|
|
492
|
-
import { zCompactJwt as zCompactJwt2 } from "@openid4vc/oauth2";
|
|
493
337
|
import {
|
|
494
338
|
ItWalletSpecsVersion,
|
|
495
|
-
createVersionDispatcher
|
|
339
|
+
createVersionDispatcher,
|
|
340
|
+
zCompactJwt
|
|
496
341
|
} from "@pagopa/io-wallet-utils";
|
|
497
342
|
|
|
498
343
|
// src/client-attestation/types.ts
|
|
499
|
-
import
|
|
500
|
-
var zOauthClientAttestationHeader =
|
|
344
|
+
import z2 from "zod";
|
|
345
|
+
var zOauthClientAttestationHeader = z2.literal(
|
|
501
346
|
"OAuth-Client-Attestation"
|
|
502
347
|
);
|
|
503
348
|
var oauthClientAttestationHeader = zOauthClientAttestationHeader.value;
|
|
504
|
-
var zOauthClientAttestationPopHeader =
|
|
349
|
+
var zOauthClientAttestationPopHeader = z2.literal(
|
|
505
350
|
"OAuth-Client-Attestation-PoP"
|
|
506
351
|
);
|
|
507
352
|
var oauthClientAttestationPopHeader = zOauthClientAttestationPopHeader.value;
|
|
508
353
|
|
|
509
354
|
// src/client-attestation/verify-wallet-attestation-jwt-base.ts
|
|
510
|
-
import { jwtSignerFromJwt, verifyJwt } from "@openid4vc/oauth2";
|
|
511
|
-
|
|
512
|
-
// src/common/jwt/decode-jwt.ts
|
|
513
|
-
import { Oauth2JwtParseError as Oauth2JwtParseError2 } from "@openid4vc/oauth2";
|
|
514
355
|
import {
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
parseWithErrorHandling as parseWithErrorHandling4,
|
|
519
|
-
stringToJsonWithErrorHandling as stringToJsonWithErrorHandling2
|
|
356
|
+
decodeJwt,
|
|
357
|
+
jwtSignerFromJwt,
|
|
358
|
+
verifyJwt
|
|
520
359
|
} from "@pagopa/io-wallet-utils";
|
|
521
|
-
function decodeJwt(options) {
|
|
522
|
-
const jwtParts = options.jwt.split(".");
|
|
523
|
-
if (jwtParts.length !== 3) {
|
|
524
|
-
throw new Oauth2JwtParseError2(
|
|
525
|
-
formatError2(
|
|
526
|
-
"Unable to decode because Jwt is not a valid!",
|
|
527
|
-
options.errorMessagePrefix
|
|
528
|
-
)
|
|
529
|
-
);
|
|
530
|
-
}
|
|
531
|
-
let payloadJson;
|
|
532
|
-
try {
|
|
533
|
-
const payloadPart = jwtParts[1];
|
|
534
|
-
if (payloadPart === void 0) {
|
|
535
|
-
throw new Oauth2JwtParseError2(
|
|
536
|
-
formatError2(
|
|
537
|
-
"Unable to decode because Jwt is not a valid!",
|
|
538
|
-
options.errorMessagePrefix
|
|
539
|
-
)
|
|
540
|
-
);
|
|
541
|
-
}
|
|
542
|
-
payloadJson = stringToJsonWithErrorHandling2(
|
|
543
|
-
encodeToUtf8String2(decodeBase642(payloadPart)),
|
|
544
|
-
formatError2(
|
|
545
|
-
"Unable to parse jwt payload to JSON",
|
|
546
|
-
options.errorMessagePrefix
|
|
547
|
-
)
|
|
548
|
-
);
|
|
549
|
-
} catch (error) {
|
|
550
|
-
throw new Oauth2JwtParseError2(
|
|
551
|
-
formatError2(
|
|
552
|
-
`Error parsing JWT. ${error instanceof Error ? error.message : ""}`,
|
|
553
|
-
options.errorMessagePrefix
|
|
554
|
-
)
|
|
555
|
-
);
|
|
556
|
-
}
|
|
557
|
-
const signaturePart = jwtParts[2];
|
|
558
|
-
if (signaturePart === void 0) {
|
|
559
|
-
throw new Oauth2JwtParseError2(
|
|
560
|
-
formatError2(
|
|
561
|
-
"Unable to decode because Jwt is not a valid!",
|
|
562
|
-
options.errorMessagePrefix
|
|
563
|
-
)
|
|
564
|
-
);
|
|
565
|
-
}
|
|
566
|
-
const { header } = decodeJwtHeader({
|
|
567
|
-
errorMessagePrefix: options.errorMessagePrefix,
|
|
568
|
-
headerSchema: options.headerSchema,
|
|
569
|
-
jwt: options.jwt
|
|
570
|
-
});
|
|
571
|
-
const payload = parseWithErrorHandling4(
|
|
572
|
-
options.payloadSchema ?? zJwtPayload,
|
|
573
|
-
payloadJson,
|
|
574
|
-
formatError2("Invalid JWT payload", options.errorMessagePrefix)
|
|
575
|
-
);
|
|
576
|
-
return {
|
|
577
|
-
header,
|
|
578
|
-
payload,
|
|
579
|
-
signature: signaturePart
|
|
580
|
-
};
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
// src/client-attestation/verify-wallet-attestation-jwt-base.ts
|
|
584
360
|
async function verifyWalletAttestationBase(options, headerSchema, payloadSchema) {
|
|
585
361
|
const { header, payload } = decodeJwt({
|
|
586
362
|
errorMessagePrefix: "Error decoding wallet attestation JWT:",
|
|
@@ -601,27 +377,33 @@ async function verifyWalletAttestationBase(options, headerSchema, payloadSchema)
|
|
|
601
377
|
}
|
|
602
378
|
|
|
603
379
|
// src/client-attestation/v1.0/z-wallet-attestation.ts
|
|
604
|
-
import {
|
|
605
|
-
|
|
606
|
-
|
|
380
|
+
import {
|
|
381
|
+
zJwk,
|
|
382
|
+
zJwtHeader as zJwtHeader2,
|
|
383
|
+
zJwtPayload as zJwtPayload2,
|
|
384
|
+
zTrustChain
|
|
385
|
+
} from "@pagopa/io-wallet-utils";
|
|
386
|
+
import { z as z3 } from "zod";
|
|
387
|
+
var zWalletAttestationJwtHeaderV1_0 = z3.looseObject({
|
|
388
|
+
...zJwtHeader2.shape,
|
|
607
389
|
trust_chain: zTrustChain,
|
|
608
390
|
// REQUIRED in v1.0
|
|
609
|
-
typ:
|
|
391
|
+
typ: z3.literal("oauth-client-attestation+jwt")
|
|
610
392
|
});
|
|
611
|
-
var zWalletAttestationJwtPayloadV1_0 =
|
|
612
|
-
...
|
|
613
|
-
aal:
|
|
614
|
-
cnf:
|
|
393
|
+
var zWalletAttestationJwtPayloadV1_0 = z3.looseObject({
|
|
394
|
+
...zJwtPayload2.shape,
|
|
395
|
+
aal: z3.string(),
|
|
396
|
+
cnf: z3.object({
|
|
615
397
|
jwk: zJwk
|
|
616
398
|
}),
|
|
617
|
-
exp:
|
|
618
|
-
iat:
|
|
619
|
-
iss:
|
|
620
|
-
sub:
|
|
621
|
-
wallet_link:
|
|
622
|
-
wallet_name:
|
|
399
|
+
exp: z3.number(),
|
|
400
|
+
iat: z3.number(),
|
|
401
|
+
iss: z3.string(),
|
|
402
|
+
sub: z3.string(),
|
|
403
|
+
wallet_link: z3.url().optional(),
|
|
404
|
+
wallet_name: z3.string().optional()
|
|
623
405
|
});
|
|
624
|
-
var zWalletAttestationJwtV1_0 =
|
|
406
|
+
var zWalletAttestationJwtV1_0 = z3.string().min(1);
|
|
625
407
|
|
|
626
408
|
// src/client-attestation/v1.0/verify-wallet-attestation-jwt.ts
|
|
627
409
|
async function verifyWalletAttestationJwt(options) {
|
|
@@ -633,37 +415,44 @@ async function verifyWalletAttestationJwt(options) {
|
|
|
633
415
|
}
|
|
634
416
|
|
|
635
417
|
// src/client-attestation/v1.3/z-wallet-attestation.ts
|
|
636
|
-
import {
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
418
|
+
import {
|
|
419
|
+
zCertificateChain,
|
|
420
|
+
zJwk as zJwk2,
|
|
421
|
+
zJwtHeader as zJwtHeader3,
|
|
422
|
+
zJwtPayload as zJwtPayload3,
|
|
423
|
+
zTrustChain as zTrustChain2
|
|
424
|
+
} from "@pagopa/io-wallet-utils";
|
|
425
|
+
import { z as z4 } from "zod";
|
|
426
|
+
var zWalletAttestationJwtHeaderV1_3 = z4.looseObject({
|
|
427
|
+
...zJwtHeader3.shape,
|
|
428
|
+
trust_chain: zTrustChain2.optional(),
|
|
640
429
|
// OPTIONAL in v1.3
|
|
641
|
-
typ:
|
|
430
|
+
typ: z4.literal("oauth-client-attestation+jwt"),
|
|
642
431
|
x5c: zCertificateChain
|
|
643
432
|
// REQUIRED in v1.3
|
|
644
433
|
});
|
|
645
|
-
var zWalletAttestationJwtPayloadV1_3 =
|
|
646
|
-
...
|
|
647
|
-
cnf:
|
|
648
|
-
jwk:
|
|
434
|
+
var zWalletAttestationJwtPayloadV1_3 = z4.looseObject({
|
|
435
|
+
...zJwtPayload3.shape,
|
|
436
|
+
cnf: z4.object({
|
|
437
|
+
jwk: zJwk2
|
|
649
438
|
}),
|
|
650
|
-
exp:
|
|
651
|
-
iat:
|
|
652
|
-
iss:
|
|
653
|
-
nbf:
|
|
439
|
+
exp: z4.number(),
|
|
440
|
+
iat: z4.number(),
|
|
441
|
+
iss: z4.string(),
|
|
442
|
+
nbf: z4.number().optional(),
|
|
654
443
|
// NEW in v1.3
|
|
655
|
-
status:
|
|
656
|
-
status_list:
|
|
657
|
-
idx:
|
|
658
|
-
uri:
|
|
444
|
+
status: z4.object({
|
|
445
|
+
status_list: z4.object({
|
|
446
|
+
idx: z4.number().int(),
|
|
447
|
+
uri: z4.string()
|
|
659
448
|
})
|
|
660
449
|
}).optional(),
|
|
661
450
|
// NEW in v1.3 - status object for revocation
|
|
662
|
-
sub:
|
|
663
|
-
wallet_link:
|
|
664
|
-
wallet_name:
|
|
451
|
+
sub: z4.string(),
|
|
452
|
+
wallet_link: z4.url().optional(),
|
|
453
|
+
wallet_name: z4.string().optional()
|
|
665
454
|
});
|
|
666
|
-
var zWalletAttestationJwtV1_3 =
|
|
455
|
+
var zWalletAttestationJwtV1_3 = z4.string().min(1);
|
|
667
456
|
|
|
668
457
|
// src/client-attestation/v1.3/verify-wallet-attestation-jwt.ts
|
|
669
458
|
async function verifyWalletAttestationJwt2(options) {
|
|
@@ -675,28 +464,35 @@ async function verifyWalletAttestationJwt2(options) {
|
|
|
675
464
|
}
|
|
676
465
|
|
|
677
466
|
// src/client-attestation/v1.4/z-wallet-attestation.ts
|
|
678
|
-
import {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
467
|
+
import {
|
|
468
|
+
zCertificateChain as zCertificateChain2,
|
|
469
|
+
zJwk as zJwk3,
|
|
470
|
+
zJwtHeader as zJwtHeader4,
|
|
471
|
+
zJwtPayload as zJwtPayload4,
|
|
472
|
+
zTrustChain as zTrustChain3
|
|
473
|
+
} from "@pagopa/io-wallet-utils";
|
|
474
|
+
import { z as z5 } from "zod";
|
|
475
|
+
var zWalletAttestationJwtHeaderV1_4 = z5.looseObject({
|
|
476
|
+
...zJwtHeader4.shape,
|
|
477
|
+
kid: z5.string(),
|
|
478
|
+
trust_chain: zTrustChain3.optional(),
|
|
479
|
+
typ: z5.literal("oauth-client-attestation+jwt"),
|
|
480
|
+
x5c: zCertificateChain2
|
|
685
481
|
});
|
|
686
|
-
var zWalletAttestationJwtPayloadV1_4 =
|
|
687
|
-
...
|
|
688
|
-
cnf:
|
|
689
|
-
jwk:
|
|
482
|
+
var zWalletAttestationJwtPayloadV1_4 = z5.looseObject({
|
|
483
|
+
...zJwtPayload4.shape,
|
|
484
|
+
cnf: z5.object({
|
|
485
|
+
jwk: zJwk3
|
|
690
486
|
}),
|
|
691
|
-
exp:
|
|
692
|
-
iat:
|
|
693
|
-
iss:
|
|
694
|
-
nbf:
|
|
695
|
-
sub:
|
|
696
|
-
wallet_link:
|
|
697
|
-
wallet_name:
|
|
487
|
+
exp: z5.number().int(),
|
|
488
|
+
iat: z5.number().int(),
|
|
489
|
+
iss: z5.string(),
|
|
490
|
+
nbf: z5.number().optional(),
|
|
491
|
+
sub: z5.string(),
|
|
492
|
+
wallet_link: z5.url(),
|
|
493
|
+
wallet_name: z5.string()
|
|
698
494
|
});
|
|
699
|
-
var zWalletAttestationJwtV1_4 =
|
|
495
|
+
var zWalletAttestationJwtV1_4 = z5.string().min(1);
|
|
700
496
|
|
|
701
497
|
// src/client-attestation/v1.4/verify-wallet-attestation-jwt.ts
|
|
702
498
|
async function verifyWalletAttestationJwt3(options) {
|
|
@@ -727,7 +523,7 @@ function extractClientAttestationJwtsFromHeaders(headers) {
|
|
|
727
523
|
if (!walletAttestationHeader || !clientAttestationPopHeader) {
|
|
728
524
|
return { valid: false };
|
|
729
525
|
}
|
|
730
|
-
if (!
|
|
526
|
+
if (!zCompactJwt.safeParse(walletAttestationHeader).success || !zCompactJwt.safeParse(clientAttestationPopHeader).success) {
|
|
731
527
|
return { valid: false };
|
|
732
528
|
}
|
|
733
529
|
return {
|
|
@@ -740,14 +536,12 @@ function extractClientAttestationJwtsFromHeaders(headers) {
|
|
|
740
536
|
// src/token-dpop/create-token-dpop.ts
|
|
741
537
|
import {
|
|
742
538
|
HashAlgorithm as HashAlgorithm2,
|
|
743
|
-
zCompactJwt as zCompactJwt3
|
|
744
|
-
} from "@openid4vc/oauth2";
|
|
745
|
-
import {
|
|
746
539
|
ValidationError as ValidationError2,
|
|
747
540
|
dateToSeconds as dateToSeconds2,
|
|
748
541
|
decodeUtf8String,
|
|
749
542
|
encodeToBase64Url,
|
|
750
|
-
parseWithErrorHandling as
|
|
543
|
+
parseWithErrorHandling as parseWithErrorHandling3,
|
|
544
|
+
zCompactJwt as zCompactJwt2
|
|
751
545
|
} from "@pagopa/io-wallet-utils";
|
|
752
546
|
import { Base64 } from "js-base64";
|
|
753
547
|
|
|
@@ -760,20 +554,26 @@ var htuFromRequestUrl = (requestUrl) => {
|
|
|
760
554
|
};
|
|
761
555
|
|
|
762
556
|
// src/token-dpop/z-dpop.ts
|
|
763
|
-
import {
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
557
|
+
import {
|
|
558
|
+
MAX_JTI_LENGTH as MAX_JTI_LENGTH2,
|
|
559
|
+
zHttpMethod,
|
|
560
|
+
zJwk as zJwk4,
|
|
561
|
+
zJwtHeader as zJwtHeader5,
|
|
562
|
+
zJwtPayload as zJwtPayload5
|
|
563
|
+
} from "@pagopa/io-wallet-utils";
|
|
564
|
+
import z6 from "zod";
|
|
565
|
+
var zDpopJwtPayload = z6.looseObject({
|
|
566
|
+
...zJwtPayload5.shape,
|
|
567
|
+
ath: z6.optional(z6.string()),
|
|
768
568
|
htm: zHttpMethod,
|
|
769
|
-
htu:
|
|
770
|
-
iat:
|
|
771
|
-
jti:
|
|
569
|
+
htu: z6.url(),
|
|
570
|
+
iat: z6.number().int().nonnegative(),
|
|
571
|
+
jti: z6.string().max(MAX_JTI_LENGTH2)
|
|
772
572
|
});
|
|
773
|
-
var zDpopJwtHeader =
|
|
774
|
-
...
|
|
775
|
-
jwk:
|
|
776
|
-
typ:
|
|
573
|
+
var zDpopJwtHeader = z6.looseObject({
|
|
574
|
+
...zJwtHeader5.shape,
|
|
575
|
+
jwk: zJwk4,
|
|
576
|
+
typ: z6.literal("dpop+jwt")
|
|
777
577
|
});
|
|
778
578
|
|
|
779
579
|
// src/token-dpop/create-token-dpop.ts
|
|
@@ -794,12 +594,12 @@ async function createTokenDPoP(options) {
|
|
|
794
594
|
"Error: neither a default jti nor a generateRandom callback have been provided"
|
|
795
595
|
);
|
|
796
596
|
}
|
|
797
|
-
const header =
|
|
597
|
+
const header = parseWithErrorHandling3(zDpopJwtHeader, {
|
|
798
598
|
alg: options.signer.alg,
|
|
799
599
|
jwk: options.signer.publicJwk,
|
|
800
600
|
typ: "dpop+jwt"
|
|
801
601
|
});
|
|
802
|
-
const payload =
|
|
602
|
+
const payload = parseWithErrorHandling3(zDpopJwtPayload, {
|
|
803
603
|
ath,
|
|
804
604
|
htm: options.tokenRequest.method,
|
|
805
605
|
htu: htuFromRequestUrl(options.tokenRequest.url),
|
|
@@ -824,17 +624,17 @@ function extractDpopJwtFromHeaders(headers) {
|
|
|
824
624
|
if (!dpopJwt) {
|
|
825
625
|
return { valid: true };
|
|
826
626
|
}
|
|
827
|
-
if (!
|
|
627
|
+
if (!zCompactJwt2.safeParse(dpopJwt).success) {
|
|
828
628
|
return { valid: false };
|
|
829
629
|
}
|
|
830
630
|
return { dpopJwt, valid: true };
|
|
831
631
|
}
|
|
832
632
|
|
|
833
633
|
// src/access-token/z-grant-type.ts
|
|
834
|
-
import { z as
|
|
835
|
-
var zAuthorizationCodeGrantIdentifier =
|
|
634
|
+
import { z as z7 } from "zod";
|
|
635
|
+
var zAuthorizationCodeGrantIdentifier = z7.literal("authorization_code");
|
|
836
636
|
var authorizationCodeGrantIdentifier = zAuthorizationCodeGrantIdentifier.value;
|
|
837
|
-
var zRefreshTokenGrantIdentifier =
|
|
637
|
+
var zRefreshTokenGrantIdentifier = z7.literal("refresh_token");
|
|
838
638
|
var refreshTokenGrantIdentifier = zRefreshTokenGrantIdentifier.value;
|
|
839
639
|
|
|
840
640
|
// src/access-token/parse-token-request.ts
|
|
@@ -915,42 +715,48 @@ function parseSecurityHeaders(headers) {
|
|
|
915
715
|
import {
|
|
916
716
|
HashAlgorithm as HashAlgorithm3,
|
|
917
717
|
calculateJwkThumbprint as calculateJwkThumbprint2
|
|
918
|
-
} from "@
|
|
718
|
+
} from "@pagopa/io-wallet-utils";
|
|
919
719
|
|
|
920
720
|
// src/client-attestation/client-attestation-pop.ts
|
|
921
|
-
import { verifyJwt as verifyJwt2 } from "@openid4vc/oauth2";
|
|
922
721
|
import {
|
|
923
722
|
ItWalletSpecsVersion as ItWalletSpecsVersion2,
|
|
924
723
|
addSecondsToDate as addSecondsToDate2,
|
|
925
724
|
dateToSeconds as dateToSeconds3,
|
|
725
|
+
decodeJwt as decodeJwt2,
|
|
926
726
|
encodeToBase64Url as encodeToBase64Url2,
|
|
927
|
-
parseWithErrorHandling as
|
|
727
|
+
parseWithErrorHandling as parseWithErrorHandling4,
|
|
728
|
+
verifyJwt as verifyJwt2
|
|
928
729
|
} from "@pagopa/io-wallet-utils";
|
|
929
730
|
|
|
930
731
|
// src/client-attestation/z-client-attestation-pop.ts
|
|
931
|
-
import
|
|
732
|
+
import {
|
|
733
|
+
MAX_JTI_LENGTH as MAX_JTI_LENGTH3,
|
|
734
|
+
zJwtHeader as zJwtHeader6,
|
|
735
|
+
zJwtPayload as zJwtPayload6
|
|
736
|
+
} from "@pagopa/io-wallet-utils";
|
|
737
|
+
import z8 from "zod";
|
|
932
738
|
var IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES = [
|
|
933
739
|
"ES256",
|
|
934
740
|
"ES384",
|
|
935
741
|
"ES512"
|
|
936
742
|
];
|
|
937
|
-
var zItWalletClientAttestationPopJwtAlg =
|
|
743
|
+
var zItWalletClientAttestationPopJwtAlg = z8.enum(
|
|
938
744
|
IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES
|
|
939
745
|
);
|
|
940
|
-
var zItWalletClientAttestationPopJwtPayload =
|
|
941
|
-
...
|
|
942
|
-
aud:
|
|
943
|
-
exp:
|
|
944
|
-
iat:
|
|
945
|
-
iss:
|
|
946
|
-
jti:
|
|
947
|
-
nonce:
|
|
746
|
+
var zItWalletClientAttestationPopJwtPayload = z8.looseObject({
|
|
747
|
+
...zJwtPayload6.shape,
|
|
748
|
+
aud: z8.string(),
|
|
749
|
+
exp: z8.number().int().optional(),
|
|
750
|
+
iat: z8.number().int(),
|
|
751
|
+
iss: z8.string(),
|
|
752
|
+
jti: z8.string().max(MAX_JTI_LENGTH3),
|
|
753
|
+
nonce: z8.string().optional()
|
|
948
754
|
});
|
|
949
|
-
var zItWalletClientAttestationPopJwtTyp =
|
|
755
|
+
var zItWalletClientAttestationPopJwtTyp = z8.literal(
|
|
950
756
|
"oauth-client-attestation-pop+jwt"
|
|
951
757
|
);
|
|
952
|
-
var zItWalletClientAttestationPopJwtHeader =
|
|
953
|
-
...
|
|
758
|
+
var zItWalletClientAttestationPopJwtHeader = z8.looseObject({
|
|
759
|
+
...zJwtHeader6.shape,
|
|
954
760
|
typ: zItWalletClientAttestationPopJwtTyp
|
|
955
761
|
});
|
|
956
762
|
|
|
@@ -964,7 +770,7 @@ function assertSupportedClientAttestationPopAlg(alg) {
|
|
|
964
770
|
}
|
|
965
771
|
async function verifyClientAttestationPopJwt(options) {
|
|
966
772
|
try {
|
|
967
|
-
const { header, payload } =
|
|
773
|
+
const { header, payload } = decodeJwt2({
|
|
968
774
|
errorMessagePrefix: "Error decoding client attestation PoP JWT:",
|
|
969
775
|
headerSchema: zItWalletClientAttestationPopJwtHeader,
|
|
970
776
|
jwt: options.clientAttestationPopJwt,
|
|
@@ -1000,7 +806,7 @@ async function verifyClientAttestationPopJwt(options) {
|
|
|
1000
806
|
}
|
|
1001
807
|
async function createClientAttestationPopJwt(options) {
|
|
1002
808
|
try {
|
|
1003
|
-
const clientAttestation =
|
|
809
|
+
const clientAttestation = decodeJwt2({
|
|
1004
810
|
errorMessagePrefix: "Error decoding client attestation JWT:",
|
|
1005
811
|
jwt: options.clientAttestation
|
|
1006
812
|
});
|
|
@@ -1033,7 +839,7 @@ async function createClientAttestationPopJwt(options) {
|
|
|
1033
839
|
"Error: neither a default jti nor a generateRandom callback have been provided"
|
|
1034
840
|
);
|
|
1035
841
|
}
|
|
1036
|
-
const payload =
|
|
842
|
+
const payload = parseWithErrorHandling4(
|
|
1037
843
|
zItWalletClientAttestationPopJwtPayload,
|
|
1038
844
|
{
|
|
1039
845
|
aud: options.authorizationServer,
|
|
@@ -1106,9 +912,10 @@ async function verifyClientAttestation(options) {
|
|
|
1106
912
|
|
|
1107
913
|
// src/pkce.ts
|
|
1108
914
|
import {
|
|
1109
|
-
HashAlgorithm as HashAlgorithm4
|
|
1110
|
-
|
|
1111
|
-
|
|
915
|
+
HashAlgorithm as HashAlgorithm4,
|
|
916
|
+
decodeUtf8String as decodeUtf8String2,
|
|
917
|
+
encodeToBase64Url as encodeToBase64Url3
|
|
918
|
+
} from "@pagopa/io-wallet-utils";
|
|
1112
919
|
var PkceCodeChallengeMethod = {
|
|
1113
920
|
Plain: "plain",
|
|
1114
921
|
S256: "S256"
|
|
@@ -1170,15 +977,14 @@ async function calculateCodeChallenge(options) {
|
|
|
1170
977
|
import {
|
|
1171
978
|
HashAlgorithm as HashAlgorithm5,
|
|
1172
979
|
calculateJwkThumbprint as calculateJwkThumbprint3,
|
|
1173
|
-
|
|
1174
|
-
} from "@openid4vc/oauth2";
|
|
1175
|
-
import {
|
|
980
|
+
decodeJwt as decodeJwt3,
|
|
1176
981
|
decodeUtf8String as decodeUtf8String3,
|
|
1177
982
|
encodeToBase64Url as encodeToBase64Url4,
|
|
983
|
+
verifyJwt as verifyJwt3,
|
|
1178
984
|
verifyJwtIatOrThrow
|
|
1179
985
|
} from "@pagopa/io-wallet-utils";
|
|
1180
986
|
async function verifyTokenDPoP(options) {
|
|
1181
|
-
const { header, payload } =
|
|
987
|
+
const { header, payload } = decodeJwt3({
|
|
1182
988
|
errorMessagePrefix: "Error decoding access token DPoP JWT:",
|
|
1183
989
|
headerSchema: zDpopJwtHeader,
|
|
1184
990
|
jwt: options.dpopJwt,
|
|
@@ -1328,33 +1134,34 @@ import {
|
|
|
1328
1134
|
} from "@pagopa/io-wallet-utils";
|
|
1329
1135
|
|
|
1330
1136
|
// src/authorization-request/z-authorization-request.ts
|
|
1331
|
-
import
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1137
|
+
import { MAX_JTI_LENGTH as MAX_JTI_LENGTH4 } from "@pagopa/io-wallet-utils";
|
|
1138
|
+
import z9 from "zod";
|
|
1139
|
+
var zOpenidCredentialAuthorizationDetails = z9.object({
|
|
1140
|
+
credential_configuration_id: z9.string(),
|
|
1141
|
+
type: z9.literal("openid_credential")
|
|
1335
1142
|
});
|
|
1336
|
-
var zItL2DocumentProofAuthorizationDetails =
|
|
1337
|
-
challenge_method:
|
|
1338
|
-
challenge_redirect_uri:
|
|
1339
|
-
idphinting:
|
|
1340
|
-
type:
|
|
1143
|
+
var zItL2DocumentProofAuthorizationDetails = z9.object({
|
|
1144
|
+
challenge_method: z9.literal("mrtd+ias"),
|
|
1145
|
+
challenge_redirect_uri: z9.url(),
|
|
1146
|
+
idphinting: z9.url(),
|
|
1147
|
+
type: z9.literal("it_l2+document_proof")
|
|
1341
1148
|
});
|
|
1342
|
-
var zAuthorizationRequestBaseObject =
|
|
1343
|
-
authorization_details:
|
|
1344
|
-
|
|
1149
|
+
var zAuthorizationRequestBaseObject = z9.looseObject({
|
|
1150
|
+
authorization_details: z9.array(
|
|
1151
|
+
z9.discriminatedUnion("type", [
|
|
1345
1152
|
zOpenidCredentialAuthorizationDetails,
|
|
1346
1153
|
zItL2DocumentProofAuthorizationDetails
|
|
1347
1154
|
])
|
|
1348
1155
|
).optional(),
|
|
1349
|
-
client_id:
|
|
1350
|
-
code_challenge:
|
|
1351
|
-
code_challenge_method:
|
|
1352
|
-
issuer_state:
|
|
1353
|
-
jti:
|
|
1354
|
-
redirect_uri:
|
|
1355
|
-
response_type:
|
|
1356
|
-
scope:
|
|
1357
|
-
state:
|
|
1156
|
+
client_id: z9.string(),
|
|
1157
|
+
code_challenge: z9.string(),
|
|
1158
|
+
code_challenge_method: z9.string(),
|
|
1159
|
+
issuer_state: z9.optional(z9.string()),
|
|
1160
|
+
jti: z9.string().max(MAX_JTI_LENGTH4),
|
|
1161
|
+
redirect_uri: z9.url(),
|
|
1162
|
+
response_type: z9.string(),
|
|
1163
|
+
scope: z9.string().optional(),
|
|
1164
|
+
state: z9.string()
|
|
1358
1165
|
});
|
|
1359
1166
|
var zAuthorizationRequestBase = zAuthorizationRequestBaseObject.refine(
|
|
1360
1167
|
(data) => data.authorization_details !== void 0 || data.scope !== void 0,
|
|
@@ -1364,7 +1171,7 @@ var zAuthorizationRequestBase = zAuthorizationRequestBaseObject.refine(
|
|
|
1364
1171
|
}
|
|
1365
1172
|
);
|
|
1366
1173
|
var zAuthorizationRequestV1_0 = zAuthorizationRequestBaseObject.extend({
|
|
1367
|
-
response_mode:
|
|
1174
|
+
response_mode: z9.string()
|
|
1368
1175
|
}).refine(
|
|
1369
1176
|
(data) => data.authorization_details !== void 0 || data.scope !== void 0,
|
|
1370
1177
|
{
|
|
@@ -1373,25 +1180,25 @@ var zAuthorizationRequestV1_0 = zAuthorizationRequestBaseObject.extend({
|
|
|
1373
1180
|
}
|
|
1374
1181
|
);
|
|
1375
1182
|
var zAuthorizationRequestV1_3 = zAuthorizationRequestBase;
|
|
1376
|
-
var zPushedAuthorizationRequestSigned =
|
|
1377
|
-
client_id:
|
|
1183
|
+
var zPushedAuthorizationRequestSigned = z9.looseObject({
|
|
1184
|
+
client_id: z9.string().describe(
|
|
1378
1185
|
"MUST be set to the thumbprint of the jwk value in the cnf parameter inside the Wallet Attestation."
|
|
1379
1186
|
),
|
|
1380
|
-
pkceCodeVerifier:
|
|
1187
|
+
pkceCodeVerifier: z9.string().describe(
|
|
1381
1188
|
"Code verifier for PKCE. If not provided in CreatePushedAuthorizationRequestOptions, SDK will generate one."
|
|
1382
1189
|
),
|
|
1383
|
-
request:
|
|
1190
|
+
request: z9.string().describe(
|
|
1384
1191
|
"It MUST be a signed JWT. The private key corresponding to the public one in the cnf parameter inside the Wallet Attestation MUST be used for signing the Request Object."
|
|
1385
1192
|
)
|
|
1386
1193
|
});
|
|
1387
|
-
var zPushedAuthorizationRequestUnsignedBase = (authorizationRequest) =>
|
|
1194
|
+
var zPushedAuthorizationRequestUnsignedBase = (authorizationRequest) => z9.looseObject({
|
|
1388
1195
|
authorizationRequest: authorizationRequest.describe(
|
|
1389
1196
|
"The authorization request parameters as a plain object. Used when require_signed_request_object is false."
|
|
1390
1197
|
),
|
|
1391
|
-
client_id:
|
|
1198
|
+
client_id: z9.string().describe(
|
|
1392
1199
|
"Thumbprint of the jwk value in the cnf parameter inside Wallet Attestation."
|
|
1393
1200
|
),
|
|
1394
|
-
pkceCodeVerifier:
|
|
1201
|
+
pkceCodeVerifier: z9.string().describe(
|
|
1395
1202
|
"PKCE code verifier. Auto-generated if not provided in options."
|
|
1396
1203
|
)
|
|
1397
1204
|
});
|
|
@@ -1403,9 +1210,9 @@ function isPushedAuthorizationRequestSigned(par) {
|
|
|
1403
1210
|
function isPushedAuthorizationRequestUnsigned(par) {
|
|
1404
1211
|
return "authorizationRequest" in par;
|
|
1405
1212
|
}
|
|
1406
|
-
var zPushedAuthorizationResponse =
|
|
1407
|
-
expires_in:
|
|
1408
|
-
request_uri:
|
|
1213
|
+
var zPushedAuthorizationResponse = z9.looseObject({
|
|
1214
|
+
expires_in: z9.number().int(),
|
|
1215
|
+
request_uri: z9.string()
|
|
1409
1216
|
});
|
|
1410
1217
|
|
|
1411
1218
|
// src/authorization-request/create-authorization-request.ts
|
|
@@ -1581,11 +1388,12 @@ function parseAuthorizationRequest(options) {
|
|
|
1581
1388
|
// src/authorization-request/parse-pushed-authorization-request.ts
|
|
1582
1389
|
import {
|
|
1583
1390
|
ItWalletSpecsVersion as ItWalletSpecsVersion4,
|
|
1391
|
+
decodeJwt as decodeJwt4,
|
|
1584
1392
|
dispatchByVersion as dispatchByVersion2,
|
|
1585
1393
|
formatZodError as formatZodError2,
|
|
1586
|
-
parseWithErrorHandling as
|
|
1394
|
+
parseWithErrorHandling as parseWithErrorHandling5
|
|
1587
1395
|
} from "@pagopa/io-wallet-utils";
|
|
1588
|
-
import
|
|
1396
|
+
import z11 from "zod";
|
|
1589
1397
|
|
|
1590
1398
|
// src/jar/fetch-jar-request-object.ts
|
|
1591
1399
|
import {
|
|
@@ -1651,25 +1459,26 @@ async function parseJarRequest(options) {
|
|
|
1651
1459
|
}
|
|
1652
1460
|
|
|
1653
1461
|
// src/jar/z-jar.ts
|
|
1654
|
-
import
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1462
|
+
import { zJwtHeader as zJwtHeader7, zJwtPayload as zJwtPayload7 } from "@pagopa/io-wallet-utils";
|
|
1463
|
+
import z10 from "zod";
|
|
1464
|
+
var zJarAuthorizationRequest = z10.looseObject({
|
|
1465
|
+
client_id: z10.optional(z10.string()),
|
|
1466
|
+
request: z10.optional(z10.string()),
|
|
1467
|
+
request_uri: z10.url().optional()
|
|
1659
1468
|
});
|
|
1660
|
-
var zJarRequestObjectPayload =
|
|
1661
|
-
...
|
|
1662
|
-
client_id:
|
|
1469
|
+
var zJarRequestObjectPayload = z10.looseObject({
|
|
1470
|
+
...zJwtPayload7.shape,
|
|
1471
|
+
client_id: z10.string()
|
|
1663
1472
|
});
|
|
1664
|
-
var zSignedAuthorizationRequestJwtHeaderTyp =
|
|
1473
|
+
var zSignedAuthorizationRequestJwtHeaderTyp = z10.literal(
|
|
1665
1474
|
"oauth-authz-req+jwt"
|
|
1666
1475
|
);
|
|
1667
|
-
var zJarRequestObjectHeader =
|
|
1668
|
-
...
|
|
1476
|
+
var zJarRequestObjectHeader = z10.looseObject({
|
|
1477
|
+
...zJwtHeader7.shape,
|
|
1669
1478
|
typ: zSignedAuthorizationRequestJwtHeaderTyp
|
|
1670
1479
|
});
|
|
1671
1480
|
var signedAuthorizationRequestJwtHeaderTyp = zSignedAuthorizationRequestJwtHeaderTyp.value;
|
|
1672
|
-
var zJwtAuthorizationRequestJwtHeaderTyp =
|
|
1481
|
+
var zJwtAuthorizationRequestJwtHeaderTyp = z10.literal("jwt");
|
|
1673
1482
|
var jwtAuthorizationRequestJwtHeaderTyp = zJwtAuthorizationRequestJwtHeaderTyp.value;
|
|
1674
1483
|
|
|
1675
1484
|
// src/authorization-request/parse-pushed-authorization-request.ts
|
|
@@ -1677,8 +1486,8 @@ async function parsePushedAuthorizationRequest(options) {
|
|
|
1677
1486
|
const authorizationRequestSchema = getAuthorizationRequestSchema(
|
|
1678
1487
|
options.config
|
|
1679
1488
|
);
|
|
1680
|
-
const parsed =
|
|
1681
|
-
|
|
1489
|
+
const parsed = parseWithErrorHandling5(
|
|
1490
|
+
z11.union([authorizationRequestSchema, zJarAuthorizationRequest]),
|
|
1682
1491
|
options.authorizationRequest,
|
|
1683
1492
|
"Invalid authorization request. Could not parse authorization request or jar."
|
|
1684
1493
|
);
|
|
@@ -1689,7 +1498,7 @@ async function parsePushedAuthorizationRequest(options) {
|
|
|
1689
1498
|
callbacks: options.callbacks,
|
|
1690
1499
|
jarRequestParams: parsed
|
|
1691
1500
|
});
|
|
1692
|
-
const jwt =
|
|
1501
|
+
const jwt = decodeJwt4({
|
|
1693
1502
|
errorMessagePrefix: "Error decoding pushed authorization request JWT:",
|
|
1694
1503
|
jwt: parsedJar.authorizationRequestJwt
|
|
1695
1504
|
});
|
|
@@ -1779,13 +1588,17 @@ async function verifyAuthorizationRequestDpop(options, request, callbacks, now)
|
|
|
1779
1588
|
};
|
|
1780
1589
|
}
|
|
1781
1590
|
|
|
1591
|
+
// src/authorization-request/verify-pushed-authorization-request.ts
|
|
1592
|
+
import { decodeJwt as decodeJwt6 } from "@pagopa/io-wallet-utils";
|
|
1593
|
+
|
|
1782
1594
|
// src/jar/verify-jar-request.ts
|
|
1783
1595
|
import {
|
|
1596
|
+
decodeJwt as decodeJwt5,
|
|
1597
|
+
parseWithErrorHandling as parseWithErrorHandling6,
|
|
1784
1598
|
verifyJwt as verifyJwt4,
|
|
1785
1599
|
zCompactJwe,
|
|
1786
|
-
zCompactJwt as
|
|
1787
|
-
} from "@
|
|
1788
|
-
import { parseWithErrorHandling as parseWithErrorHandling8 } from "@pagopa/io-wallet-utils";
|
|
1600
|
+
zCompactJwt as zCompactJwt3
|
|
1601
|
+
} from "@pagopa/io-wallet-utils";
|
|
1789
1602
|
async function verifyJarRequest(options) {
|
|
1790
1603
|
const { authorizationRequestJwt, callbacks, jarRequestParams, jwtSigner } = options;
|
|
1791
1604
|
const requestObjectIsEncrypted = zCompactJwe.safeParse(
|
|
@@ -1794,7 +1607,7 @@ async function verifyJarRequest(options) {
|
|
|
1794
1607
|
if (requestObjectIsEncrypted) {
|
|
1795
1608
|
throw new Oauth2Error("Encrypted JWE request objects are not supported.");
|
|
1796
1609
|
}
|
|
1797
|
-
const requestIsSigned =
|
|
1610
|
+
const requestIsSigned = zCompactJwt3.safeParse(
|
|
1798
1611
|
authorizationRequestJwt
|
|
1799
1612
|
).success;
|
|
1800
1613
|
if (!requestIsSigned) {
|
|
@@ -1847,11 +1660,11 @@ async function verifyJarRequest(options) {
|
|
|
1847
1660
|
}
|
|
1848
1661
|
async function verifyJarRequestObject(options) {
|
|
1849
1662
|
const { authorizationRequestJwt, callbacks, jwtSigner } = options;
|
|
1850
|
-
const jwt =
|
|
1663
|
+
const jwt = decodeJwt5({
|
|
1851
1664
|
errorMessagePrefix: "Error decoding JAR authorization request JWT:",
|
|
1852
1665
|
jwt: authorizationRequestJwt
|
|
1853
1666
|
});
|
|
1854
|
-
const authorizationRequestPayload =
|
|
1667
|
+
const authorizationRequestPayload = parseWithErrorHandling6(
|
|
1855
1668
|
zJarRequestObjectPayload,
|
|
1856
1669
|
jwt.payload
|
|
1857
1670
|
);
|
|
@@ -1888,7 +1701,7 @@ async function verifyPushedAuthorizationRequest(options) {
|
|
|
1888
1701
|
let jar;
|
|
1889
1702
|
if (options.authorizationRequestJwt) {
|
|
1890
1703
|
if (requireSigned) {
|
|
1891
|
-
const decoded =
|
|
1704
|
+
const decoded = decodeJwt6({
|
|
1892
1705
|
errorMessagePrefix: "Error decoding pushed authorization request JWT:",
|
|
1893
1706
|
jwt: options.authorizationRequestJwt.jwt
|
|
1894
1707
|
});
|
|
@@ -1980,14 +1793,15 @@ function clientAuthenticationWalletAttestationJwt(options) {
|
|
|
1980
1793
|
import {
|
|
1981
1794
|
ValidationError as ValidationError4,
|
|
1982
1795
|
addSecondsToDate as addSecondsToDate4,
|
|
1983
|
-
dateToSeconds as dateToSeconds5
|
|
1796
|
+
dateToSeconds as dateToSeconds5,
|
|
1797
|
+
decodeJwt as decodeJwt7
|
|
1984
1798
|
} from "@pagopa/io-wallet-utils";
|
|
1985
1799
|
|
|
1986
1800
|
// src/client-attestation/jwk-thumbprint.ts
|
|
1987
1801
|
import {
|
|
1988
1802
|
HashAlgorithm as HashAlgorithm6,
|
|
1989
1803
|
calculateJwkThumbprint as calculateJwkThumbprint4
|
|
1990
|
-
} from "@
|
|
1804
|
+
} from "@pagopa/io-wallet-utils";
|
|
1991
1805
|
var SUPPORTED_KTY = ["RSA", "EC"];
|
|
1992
1806
|
var calculateDpopJwkThumbprint = (options) => {
|
|
1993
1807
|
if (!SUPPORTED_KTY.includes(
|
|
@@ -2031,7 +1845,7 @@ var createWalletAttestationJwt = async (options) => {
|
|
|
2031
1845
|
header,
|
|
2032
1846
|
payload
|
|
2033
1847
|
});
|
|
2034
|
-
|
|
1848
|
+
decodeJwt7({
|
|
2035
1849
|
errorMessagePrefix: "Error decoding wallet attestation JWT:",
|
|
2036
1850
|
headerSchema: zWalletAttestationJwtHeaderV1_0,
|
|
2037
1851
|
jwt: result.jwt,
|
|
@@ -2052,7 +1866,8 @@ var createWalletAttestationJwt = async (options) => {
|
|
|
2052
1866
|
import {
|
|
2053
1867
|
ValidationError as ValidationError5,
|
|
2054
1868
|
addSecondsToDate as addSecondsToDate5,
|
|
2055
|
-
dateToSeconds as dateToSeconds6
|
|
1869
|
+
dateToSeconds as dateToSeconds6,
|
|
1870
|
+
decodeJwt as decodeJwt8
|
|
2056
1871
|
} from "@pagopa/io-wallet-utils";
|
|
2057
1872
|
var createWalletAttestationJwt2 = async (options) => {
|
|
2058
1873
|
try {
|
|
@@ -2088,7 +1903,7 @@ var createWalletAttestationJwt2 = async (options) => {
|
|
|
2088
1903
|
header,
|
|
2089
1904
|
payload
|
|
2090
1905
|
});
|
|
2091
|
-
|
|
1906
|
+
decodeJwt8({
|
|
2092
1907
|
errorMessagePrefix: "Error decoding wallet attestation JWT:",
|
|
2093
1908
|
headerSchema: zWalletAttestationJwtHeaderV1_3,
|
|
2094
1909
|
jwt: result.jwt,
|
|
@@ -2109,7 +1924,8 @@ var createWalletAttestationJwt2 = async (options) => {
|
|
|
2109
1924
|
import {
|
|
2110
1925
|
ValidationError as ValidationError6,
|
|
2111
1926
|
addSecondsToDate as addSecondsToDate6,
|
|
2112
|
-
dateToSeconds as dateToSeconds7
|
|
1927
|
+
dateToSeconds as dateToSeconds7,
|
|
1928
|
+
decodeJwt as decodeJwt9
|
|
2113
1929
|
} from "@pagopa/io-wallet-utils";
|
|
2114
1930
|
var DEFAULT_EXPIRATION_SECONDS = 3600;
|
|
2115
1931
|
var MAX_EXPIRATION_SECONDS = 86400;
|
|
@@ -2151,7 +1967,7 @@ var createWalletAttestationJwt3 = async (options) => {
|
|
|
2151
1967
|
header,
|
|
2152
1968
|
payload
|
|
2153
1969
|
});
|
|
2154
|
-
|
|
1970
|
+
decodeJwt9({
|
|
2155
1971
|
errorMessagePrefix: "Error decoding wallet attestation JWT:",
|
|
2156
1972
|
headerSchema: zWalletAttestationJwtHeaderV1_4,
|
|
2157
1973
|
jwt: result.jwt,
|
|
@@ -2168,17 +1984,11 @@ var createWalletAttestationJwt3 = async (options) => {
|
|
|
2168
1984
|
}
|
|
2169
1985
|
};
|
|
2170
1986
|
|
|
2171
|
-
// src/common/jwt/z-jwe.ts
|
|
2172
|
-
import { z as z15 } from "zod";
|
|
2173
|
-
var zCompactJwe2 = z15.string().regex(
|
|
2174
|
-
/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/,
|
|
2175
|
-
{
|
|
2176
|
-
message: "Not a valid compact jwe"
|
|
2177
|
-
}
|
|
2178
|
-
);
|
|
2179
|
-
|
|
2180
1987
|
// src/jar/create-jar-request.ts
|
|
2181
|
-
import {
|
|
1988
|
+
import {
|
|
1989
|
+
addSecondsToDate as addSecondsToDate7,
|
|
1990
|
+
dateToSeconds as dateToSeconds8
|
|
1991
|
+
} from "@pagopa/io-wallet-utils";
|
|
2182
1992
|
async function createJarRequest(options) {
|
|
2183
1993
|
const {
|
|
2184
1994
|
authorizationRequestHeader,
|
|
@@ -2225,6 +2035,7 @@ async function createJarRequest(options) {
|
|
|
2225
2035
|
}
|
|
2226
2036
|
|
|
2227
2037
|
// src/jarm-form-post-jwt.ts
|
|
2038
|
+
import { decodeJwt as decodeJwt10 } from "@pagopa/io-wallet-utils";
|
|
2228
2039
|
var getJwtFromFormPost = async (options) => {
|
|
2229
2040
|
const inputRegex = /<input[^<>]*>/gi;
|
|
2230
2041
|
const nameRegex = /name="response"/gi;
|
|
@@ -2239,7 +2050,7 @@ var getJwtFromFormPost = async (options) => {
|
|
|
2239
2050
|
const responseJwt = matchValue[1];
|
|
2240
2051
|
if (responseJwt) {
|
|
2241
2052
|
const jwt = responseJwt.replace(lineExpressionRegex, "");
|
|
2242
|
-
const decodedJwt =
|
|
2053
|
+
const decodedJwt = decodeJwt10({
|
|
2243
2054
|
errorMessagePrefix: "Error decoding JARM form post JWT:",
|
|
2244
2055
|
jwt,
|
|
2245
2056
|
payloadSchema: options.schema
|
|
@@ -2261,73 +2072,76 @@ var getJwtFromFormPost = async (options) => {
|
|
|
2261
2072
|
};
|
|
2262
2073
|
|
|
2263
2074
|
// src/mrtd-pop/create-mrtd-validation-jwt.ts
|
|
2264
|
-
import {
|
|
2075
|
+
import {
|
|
2076
|
+
dateToSeconds as dateToSeconds9,
|
|
2077
|
+
parseWithErrorHandling as parseWithErrorHandling7
|
|
2078
|
+
} from "@pagopa/io-wallet-utils";
|
|
2265
2079
|
|
|
2266
2080
|
// src/mrtd-pop/z-mrtd-pop.ts
|
|
2267
|
-
import
|
|
2268
|
-
var zMrtdChallengeJwtHeader =
|
|
2269
|
-
alg:
|
|
2270
|
-
kid:
|
|
2271
|
-
typ:
|
|
2081
|
+
import z12 from "zod";
|
|
2082
|
+
var zMrtdChallengeJwtHeader = z12.looseObject({
|
|
2083
|
+
alg: z12.string(),
|
|
2084
|
+
kid: z12.string(),
|
|
2085
|
+
typ: z12.literal("mrtd-ias+jwt")
|
|
2272
2086
|
});
|
|
2273
|
-
var zMrtdChallengeJwtPayload =
|
|
2274
|
-
aud:
|
|
2275
|
-
exp:
|
|
2276
|
-
htm:
|
|
2277
|
-
htu:
|
|
2278
|
-
iat:
|
|
2279
|
-
iss:
|
|
2280
|
-
mrtd_auth_session:
|
|
2281
|
-
mrtd_pop_jwt_nonce:
|
|
2282
|
-
state:
|
|
2283
|
-
status:
|
|
2284
|
-
type:
|
|
2087
|
+
var zMrtdChallengeJwtPayload = z12.looseObject({
|
|
2088
|
+
aud: z12.string(),
|
|
2089
|
+
exp: z12.number(),
|
|
2090
|
+
htm: z12.literal("POST"),
|
|
2091
|
+
htu: z12.url(),
|
|
2092
|
+
iat: z12.number(),
|
|
2093
|
+
iss: z12.string(),
|
|
2094
|
+
mrtd_auth_session: z12.string(),
|
|
2095
|
+
mrtd_pop_jwt_nonce: z12.string(),
|
|
2096
|
+
state: z12.string(),
|
|
2097
|
+
status: z12.literal("require_interaction"),
|
|
2098
|
+
type: z12.literal("mrtd+ias")
|
|
2285
2099
|
});
|
|
2286
|
-
var zMrtdPopInitResponseJwtHeader =
|
|
2287
|
-
alg:
|
|
2288
|
-
kid:
|
|
2289
|
-
typ:
|
|
2100
|
+
var zMrtdPopInitResponseJwtHeader = z12.looseObject({
|
|
2101
|
+
alg: z12.string(),
|
|
2102
|
+
kid: z12.string(),
|
|
2103
|
+
typ: z12.literal("mrtd-ias-pop+jwt")
|
|
2290
2104
|
});
|
|
2291
|
-
var zMrtdPopInitResponseJwtPayload =
|
|
2292
|
-
aud:
|
|
2293
|
-
challenge:
|
|
2294
|
-
exp:
|
|
2295
|
-
htm:
|
|
2296
|
-
htu:
|
|
2297
|
-
iat:
|
|
2298
|
-
iss:
|
|
2299
|
-
mrtd_pop_nonce:
|
|
2300
|
-
mrz:
|
|
2105
|
+
var zMrtdPopInitResponseJwtPayload = z12.looseObject({
|
|
2106
|
+
aud: z12.string(),
|
|
2107
|
+
challenge: z12.string(),
|
|
2108
|
+
exp: z12.number(),
|
|
2109
|
+
htm: z12.literal("POST"),
|
|
2110
|
+
htu: z12.url(),
|
|
2111
|
+
iat: z12.number(),
|
|
2112
|
+
iss: z12.string(),
|
|
2113
|
+
mrtd_pop_nonce: z12.string(),
|
|
2114
|
+
mrz: z12.string().optional()
|
|
2301
2115
|
});
|
|
2302
|
-
var zMrtdData =
|
|
2303
|
-
dg1:
|
|
2304
|
-
dg11:
|
|
2305
|
-
sod_mrtd:
|
|
2116
|
+
var zMrtdData = z12.looseObject({
|
|
2117
|
+
dg1: z12.string(),
|
|
2118
|
+
dg11: z12.string(),
|
|
2119
|
+
sod_mrtd: z12.string()
|
|
2306
2120
|
});
|
|
2307
|
-
var zIasData =
|
|
2308
|
-
challenge_signed:
|
|
2309
|
-
ias_pk:
|
|
2310
|
-
sod_ias:
|
|
2121
|
+
var zIasData = z12.looseObject({
|
|
2122
|
+
challenge_signed: z12.string(),
|
|
2123
|
+
ias_pk: z12.string(),
|
|
2124
|
+
sod_ias: z12.string()
|
|
2311
2125
|
});
|
|
2312
|
-
var zMrtdValidationJwtHeader =
|
|
2313
|
-
alg:
|
|
2314
|
-
kid:
|
|
2315
|
-
typ:
|
|
2126
|
+
var zMrtdValidationJwtHeader = z12.looseObject({
|
|
2127
|
+
alg: z12.string(),
|
|
2128
|
+
kid: z12.string(),
|
|
2129
|
+
typ: z12.literal("mrtd-ias+jwt")
|
|
2316
2130
|
});
|
|
2317
|
-
var zMrtdValidationJwtPayload =
|
|
2318
|
-
aud:
|
|
2319
|
-
document_type:
|
|
2320
|
-
exp:
|
|
2131
|
+
var zMrtdValidationJwtPayload = z12.looseObject({
|
|
2132
|
+
aud: z12.string(),
|
|
2133
|
+
document_type: z12.literal("cie"),
|
|
2134
|
+
exp: z12.number(),
|
|
2321
2135
|
ias: zIasData,
|
|
2322
|
-
iat:
|
|
2323
|
-
iss:
|
|
2136
|
+
iat: z12.number(),
|
|
2137
|
+
iss: z12.string(),
|
|
2324
2138
|
mrtd: zMrtdData
|
|
2325
2139
|
});
|
|
2326
|
-
var zMrtdPopVerifyResponse =
|
|
2327
|
-
mrtd_val_pop_nonce:
|
|
2328
|
-
redirect_uri:
|
|
2329
|
-
status:
|
|
2330
|
-
type:
|
|
2140
|
+
var zMrtdPopVerifyResponse = z12.looseObject({
|
|
2141
|
+
mrtd_val_pop_nonce: z12.string(),
|
|
2142
|
+
redirect_uri: z12.url(),
|
|
2143
|
+
status: z12.literal("require_interaction"),
|
|
2144
|
+
type: z12.literal("redirect_to_web")
|
|
2331
2145
|
});
|
|
2332
2146
|
|
|
2333
2147
|
// src/mrtd-pop/create-mrtd-validation-jwt.ts
|
|
@@ -2339,12 +2153,12 @@ async function createMrtdValidationJwt(options) {
|
|
|
2339
2153
|
throw new MrtdPopError("Signer must have a publicJwk.kid property");
|
|
2340
2154
|
}
|
|
2341
2155
|
const iat = dateToSeconds9(options.issuedAt);
|
|
2342
|
-
const header =
|
|
2156
|
+
const header = parseWithErrorHandling7(zMrtdValidationJwtHeader, {
|
|
2343
2157
|
alg: options.signer.alg,
|
|
2344
2158
|
kid,
|
|
2345
2159
|
typ: "mrtd-ias+jwt"
|
|
2346
2160
|
});
|
|
2347
|
-
const payload =
|
|
2161
|
+
const payload = parseWithErrorHandling7(zMrtdValidationJwtPayload, {
|
|
2348
2162
|
aud: options.audience,
|
|
2349
2163
|
document_type: "cie",
|
|
2350
2164
|
exp: iat + JWT_EXPIRY_SECONDS2,
|
|
@@ -2377,17 +2191,16 @@ async function createMrtdValidationJwt(options) {
|
|
|
2377
2191
|
}
|
|
2378
2192
|
|
|
2379
2193
|
// src/mrtd-pop/fetch-mrtd-pop-init.ts
|
|
2380
|
-
import {
|
|
2381
|
-
jwtSignerFromJwt as jwtSignerFromJwt2,
|
|
2382
|
-
verifyJwt as verifyJwt5
|
|
2383
|
-
} from "@openid4vc/oauth2";
|
|
2384
2194
|
import {
|
|
2385
2195
|
CONTENT_TYPES as CONTENT_TYPES3,
|
|
2386
2196
|
HEADERS as HEADERS3,
|
|
2387
2197
|
UnexpectedStatusCodeError as UnexpectedStatusCodeError4,
|
|
2388
2198
|
ValidationError as ValidationError7,
|
|
2389
2199
|
createFetcher as createFetcher4,
|
|
2390
|
-
|
|
2200
|
+
decodeJwt as decodeJwt11,
|
|
2201
|
+
hasStatusOrThrow as hasStatusOrThrow4,
|
|
2202
|
+
jwtSignerFromJwt as jwtSignerFromJwt2,
|
|
2203
|
+
verifyJwt as verifyJwt5
|
|
2391
2204
|
} from "@pagopa/io-wallet-utils";
|
|
2392
2205
|
async function fetchMrtdPopInit(options) {
|
|
2393
2206
|
try {
|
|
@@ -2406,7 +2219,7 @@ async function fetchMrtdPopInit(options) {
|
|
|
2406
2219
|
});
|
|
2407
2220
|
await hasStatusOrThrow4(202, UnexpectedStatusCodeError4)(response);
|
|
2408
2221
|
const responseJwt = await response.text();
|
|
2409
|
-
const jwt =
|
|
2222
|
+
const jwt = decodeJwt11({
|
|
2410
2223
|
errorMessagePrefix: "Error decoding MRTD PoP init response JWT:",
|
|
2411
2224
|
headerSchema: zMrtdPopInitResponseJwtHeader,
|
|
2412
2225
|
jwt: responseJwt,
|
|
@@ -2445,7 +2258,7 @@ import {
|
|
|
2445
2258
|
ValidationError as ValidationError8,
|
|
2446
2259
|
createFetcher as createFetcher5,
|
|
2447
2260
|
hasStatusOrThrow as hasStatusOrThrow5,
|
|
2448
|
-
parseWithErrorHandling as
|
|
2261
|
+
parseWithErrorHandling as parseWithErrorHandling8
|
|
2449
2262
|
} from "@pagopa/io-wallet-utils";
|
|
2450
2263
|
async function fetchMrtdPopVerify(options) {
|
|
2451
2264
|
try {
|
|
@@ -2464,7 +2277,7 @@ async function fetchMrtdPopVerify(options) {
|
|
|
2464
2277
|
method: "POST"
|
|
2465
2278
|
});
|
|
2466
2279
|
await hasStatusOrThrow5(202, UnexpectedStatusCodeError5)(response);
|
|
2467
|
-
const parsed =
|
|
2280
|
+
const parsed = parseWithErrorHandling8(
|
|
2468
2281
|
zMrtdPopVerifyResponse,
|
|
2469
2282
|
await response.json(),
|
|
2470
2283
|
"Failed to parse MRTD PoP verify response"
|
|
@@ -2484,7 +2297,7 @@ async function fetchMrtdPopVerify(options) {
|
|
|
2484
2297
|
}
|
|
2485
2298
|
|
|
2486
2299
|
// src/mrtd-pop/parse-mrtd-challenge.ts
|
|
2487
|
-
import { zCompactJwt as
|
|
2300
|
+
import { decodeJwt as decodeJwt12, zCompactJwt as zCompactJwt4 } from "@pagopa/io-wallet-utils";
|
|
2488
2301
|
function parseMrtdChallenge(options) {
|
|
2489
2302
|
const url = new URL(options.redirectUrl);
|
|
2490
2303
|
const challengeJwt = url.searchParams.get("challenge_info");
|
|
@@ -2493,12 +2306,12 @@ function parseMrtdChallenge(options) {
|
|
|
2493
2306
|
"Missing 'challenge_info' query parameter in redirect URL"
|
|
2494
2307
|
);
|
|
2495
2308
|
}
|
|
2496
|
-
if (!
|
|
2309
|
+
if (!zCompactJwt4.safeParse(challengeJwt).success) {
|
|
2497
2310
|
throw new MrtdPopError(
|
|
2498
2311
|
"Invalid JWT format in 'challenge_info' query parameter"
|
|
2499
2312
|
);
|
|
2500
2313
|
}
|
|
2501
|
-
const { header, payload } =
|
|
2314
|
+
const { header, payload } = decodeJwt12({
|
|
2502
2315
|
errorMessagePrefix: "Error decoding MRTD challenge JWT:",
|
|
2503
2316
|
headerSchema: zMrtdChallengeJwtHeader,
|
|
2504
2317
|
jwt: challengeJwt,
|
|
@@ -2509,12 +2322,13 @@ function parseMrtdChallenge(options) {
|
|
|
2509
2322
|
|
|
2510
2323
|
// src/mrtd-pop/verify-mrtd-challenge.ts
|
|
2511
2324
|
import {
|
|
2325
|
+
decodeJwt as decodeJwt13,
|
|
2512
2326
|
jwtSignerFromJwt as jwtSignerFromJwt3,
|
|
2513
2327
|
verifyJwt as verifyJwt6
|
|
2514
|
-
} from "@
|
|
2328
|
+
} from "@pagopa/io-wallet-utils";
|
|
2515
2329
|
async function verifyMrtdChallenge(options) {
|
|
2516
2330
|
const { callbacks, challengeJwt, clientId } = options;
|
|
2517
|
-
const jwt =
|
|
2331
|
+
const jwt = decodeJwt13({
|
|
2518
2332
|
errorMessagePrefix: "Error decoding MRTD challenge JWT:",
|
|
2519
2333
|
headerSchema: zMrtdChallengeJwtHeader,
|
|
2520
2334
|
jwt: challengeJwt,
|
|
@@ -2536,24 +2350,14 @@ async function verifyMrtdChallenge(options) {
|
|
|
2536
2350
|
});
|
|
2537
2351
|
return { header: jwt.header, payload: jwt.payload, signer };
|
|
2538
2352
|
}
|
|
2539
|
-
|
|
2540
|
-
// src/index.ts
|
|
2541
|
-
import {
|
|
2542
|
-
HashAlgorithm as HashAlgorithm7,
|
|
2543
|
-
Oauth2JwtParseError as Oauth2JwtParseError3,
|
|
2544
|
-
verifyJwt as verifyJwt7
|
|
2545
|
-
} from "@openid4vc/oauth2";
|
|
2546
2353
|
export {
|
|
2547
2354
|
ClientAttestationError,
|
|
2548
2355
|
CreateTokenDPoPError,
|
|
2549
2356
|
CreateTokenResponseError,
|
|
2550
2357
|
FetchTokenResponseError,
|
|
2551
|
-
HashAlgorithm7 as HashAlgorithm,
|
|
2552
2358
|
IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES,
|
|
2553
|
-
MAX_JTI_LENGTH,
|
|
2554
2359
|
MrtdPopError,
|
|
2555
2360
|
Oauth2Error,
|
|
2556
|
-
Oauth2JwtParseError3 as Oauth2JwtParseError,
|
|
2557
2361
|
PkceCodeChallengeMethod,
|
|
2558
2362
|
PushedAuthorizationRequestError,
|
|
2559
2363
|
SupportedClientAuthenticationMethod,
|
|
@@ -2571,8 +2375,6 @@ export {
|
|
|
2571
2375
|
createWalletAttestationJwt as createWalletAttestationJwtV1_0,
|
|
2572
2376
|
createWalletAttestationJwt2 as createWalletAttestationJwtV1_3,
|
|
2573
2377
|
createWalletAttestationJwt3 as createWalletAttestationJwtV1_4,
|
|
2574
|
-
decodeJwt,
|
|
2575
|
-
decodeJwtHeader,
|
|
2576
2378
|
extractClientAttestationJwtsFromHeaders,
|
|
2577
2379
|
extractDpopJwtFromHeaders,
|
|
2578
2380
|
fetchJarRequestObject,
|
|
@@ -2587,7 +2389,6 @@ export {
|
|
|
2587
2389
|
isPushedAuthorizationRequestSigned,
|
|
2588
2390
|
isPushedAuthorizationRequestUnsigned,
|
|
2589
2391
|
jwtAuthorizationRequestJwtHeaderTyp,
|
|
2590
|
-
jwtHeaderFromJwtSigner,
|
|
2591
2392
|
parseAccessTokenRequest,
|
|
2592
2393
|
parseAuthorizationRequest,
|
|
2593
2394
|
parseJarRequest,
|
|
@@ -2602,7 +2403,6 @@ export {
|
|
|
2602
2403
|
verifyClientAttestation,
|
|
2603
2404
|
verifyClientAttestationPopJwt,
|
|
2604
2405
|
verifyJarRequest,
|
|
2605
|
-
verifyJwt7 as verifyJwt,
|
|
2606
2406
|
verifyMrtdChallenge,
|
|
2607
2407
|
verifyPkce,
|
|
2608
2408
|
verifyPushedAuthorizationRequest,
|
|
@@ -2615,13 +2415,9 @@ export {
|
|
|
2615
2415
|
zAccessTokenProfileJwtPayload,
|
|
2616
2416
|
zAccessTokenRequest,
|
|
2617
2417
|
zAccessTokenResponse,
|
|
2618
|
-
zAlgValueNotNone,
|
|
2619
2418
|
zAuthorizationCodeGrantIdentifier,
|
|
2620
2419
|
zAuthorizationRequestV1_0,
|
|
2621
2420
|
zAuthorizationRequestV1_3,
|
|
2622
|
-
zCertificateChain,
|
|
2623
|
-
zCompactJwe2 as zCompactJwe,
|
|
2624
|
-
zCompactJwt,
|
|
2625
2421
|
zDpopJwtHeader,
|
|
2626
2422
|
zDpopJwtPayload,
|
|
2627
2423
|
zItWalletClientAttestationPopJwtAlg,
|
|
@@ -2631,11 +2427,6 @@ export {
|
|
|
2631
2427
|
zJarAuthorizationRequest,
|
|
2632
2428
|
zJarRequestObjectHeader,
|
|
2633
2429
|
zJarRequestObjectPayload,
|
|
2634
|
-
zJwk,
|
|
2635
|
-
zJwkSet,
|
|
2636
|
-
zJwtConfirmationPayload,
|
|
2637
|
-
zJwtHeader,
|
|
2638
|
-
zJwtPayload,
|
|
2639
2430
|
zMrtdChallengeJwtHeader,
|
|
2640
2431
|
zMrtdChallengeJwtPayload,
|
|
2641
2432
|
zMrtdPopInitResponseJwtHeader,
|
|
@@ -2651,7 +2442,6 @@ export {
|
|
|
2651
2442
|
zRefreshTokenProfileJwtHeader,
|
|
2652
2443
|
zRefreshTokenProfileJwtPayload,
|
|
2653
2444
|
zSignedAuthorizationRequestJwtHeaderTyp,
|
|
2654
|
-
zTrustChain,
|
|
2655
2445
|
zWalletAttestationJwtHeaderV1_0,
|
|
2656
2446
|
zWalletAttestationJwtHeaderV1_3,
|
|
2657
2447
|
zWalletAttestationJwtHeaderV1_4,
|