@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.js
CHANGED
|
@@ -34,12 +34,9 @@ __export(index_exports, {
|
|
|
34
34
|
CreateTokenDPoPError: () => CreateTokenDPoPError,
|
|
35
35
|
CreateTokenResponseError: () => CreateTokenResponseError,
|
|
36
36
|
FetchTokenResponseError: () => FetchTokenResponseError,
|
|
37
|
-
HashAlgorithm: () => import_oauth216.HashAlgorithm,
|
|
38
37
|
IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES: () => IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES,
|
|
39
|
-
MAX_JTI_LENGTH: () => MAX_JTI_LENGTH,
|
|
40
38
|
MrtdPopError: () => MrtdPopError,
|
|
41
39
|
Oauth2Error: () => Oauth2Error,
|
|
42
|
-
Oauth2JwtParseError: () => import_oauth216.Oauth2JwtParseError,
|
|
43
40
|
PkceCodeChallengeMethod: () => PkceCodeChallengeMethod,
|
|
44
41
|
PushedAuthorizationRequestError: () => PushedAuthorizationRequestError,
|
|
45
42
|
SupportedClientAuthenticationMethod: () => SupportedClientAuthenticationMethod,
|
|
@@ -57,8 +54,6 @@ __export(index_exports, {
|
|
|
57
54
|
createWalletAttestationJwtV1_0: () => createWalletAttestationJwt,
|
|
58
55
|
createWalletAttestationJwtV1_3: () => createWalletAttestationJwt2,
|
|
59
56
|
createWalletAttestationJwtV1_4: () => createWalletAttestationJwt3,
|
|
60
|
-
decodeJwt: () => decodeJwt,
|
|
61
|
-
decodeJwtHeader: () => decodeJwtHeader,
|
|
62
57
|
extractClientAttestationJwtsFromHeaders: () => extractClientAttestationJwtsFromHeaders,
|
|
63
58
|
extractDpopJwtFromHeaders: () => extractDpopJwtFromHeaders,
|
|
64
59
|
fetchJarRequestObject: () => fetchJarRequestObject,
|
|
@@ -73,7 +68,6 @@ __export(index_exports, {
|
|
|
73
68
|
isPushedAuthorizationRequestSigned: () => isPushedAuthorizationRequestSigned,
|
|
74
69
|
isPushedAuthorizationRequestUnsigned: () => isPushedAuthorizationRequestUnsigned,
|
|
75
70
|
jwtAuthorizationRequestJwtHeaderTyp: () => jwtAuthorizationRequestJwtHeaderTyp,
|
|
76
|
-
jwtHeaderFromJwtSigner: () => jwtHeaderFromJwtSigner,
|
|
77
71
|
parseAccessTokenRequest: () => parseAccessTokenRequest,
|
|
78
72
|
parseAuthorizationRequest: () => parseAuthorizationRequest,
|
|
79
73
|
parseJarRequest: () => parseJarRequest,
|
|
@@ -88,7 +82,6 @@ __export(index_exports, {
|
|
|
88
82
|
verifyClientAttestation: () => verifyClientAttestation,
|
|
89
83
|
verifyClientAttestationPopJwt: () => verifyClientAttestationPopJwt,
|
|
90
84
|
verifyJarRequest: () => verifyJarRequest,
|
|
91
|
-
verifyJwt: () => import_oauth216.verifyJwt,
|
|
92
85
|
verifyMrtdChallenge: () => verifyMrtdChallenge,
|
|
93
86
|
verifyPkce: () => verifyPkce,
|
|
94
87
|
verifyPushedAuthorizationRequest: () => verifyPushedAuthorizationRequest,
|
|
@@ -101,13 +94,9 @@ __export(index_exports, {
|
|
|
101
94
|
zAccessTokenProfileJwtPayload: () => zAccessTokenProfileJwtPayload,
|
|
102
95
|
zAccessTokenRequest: () => zAccessTokenRequest,
|
|
103
96
|
zAccessTokenResponse: () => zAccessTokenResponse,
|
|
104
|
-
zAlgValueNotNone: () => zAlgValueNotNone,
|
|
105
97
|
zAuthorizationCodeGrantIdentifier: () => zAuthorizationCodeGrantIdentifier,
|
|
106
98
|
zAuthorizationRequestV1_0: () => zAuthorizationRequestV1_0,
|
|
107
99
|
zAuthorizationRequestV1_3: () => zAuthorizationRequestV1_3,
|
|
108
|
-
zCertificateChain: () => zCertificateChain,
|
|
109
|
-
zCompactJwe: () => zCompactJwe2,
|
|
110
|
-
zCompactJwt: () => zCompactJwt,
|
|
111
100
|
zDpopJwtHeader: () => zDpopJwtHeader,
|
|
112
101
|
zDpopJwtPayload: () => zDpopJwtPayload,
|
|
113
102
|
zItWalletClientAttestationPopJwtAlg: () => zItWalletClientAttestationPopJwtAlg,
|
|
@@ -117,11 +106,6 @@ __export(index_exports, {
|
|
|
117
106
|
zJarAuthorizationRequest: () => zJarAuthorizationRequest,
|
|
118
107
|
zJarRequestObjectHeader: () => zJarRequestObjectHeader,
|
|
119
108
|
zJarRequestObjectPayload: () => zJarRequestObjectPayload,
|
|
120
|
-
zJwk: () => zJwk,
|
|
121
|
-
zJwkSet: () => zJwkSet,
|
|
122
|
-
zJwtConfirmationPayload: () => zJwtConfirmationPayload,
|
|
123
|
-
zJwtHeader: () => zJwtHeader,
|
|
124
|
-
zJwtPayload: () => zJwtPayload,
|
|
125
109
|
zMrtdChallengeJwtHeader: () => zMrtdChallengeJwtHeader,
|
|
126
110
|
zMrtdChallengeJwtPayload: () => zMrtdChallengeJwtPayload,
|
|
127
111
|
zMrtdPopInitResponseJwtHeader: () => zMrtdPopInitResponseJwtHeader,
|
|
@@ -137,7 +121,6 @@ __export(index_exports, {
|
|
|
137
121
|
zRefreshTokenProfileJwtHeader: () => zRefreshTokenProfileJwtHeader,
|
|
138
122
|
zRefreshTokenProfileJwtPayload: () => zRefreshTokenProfileJwtPayload,
|
|
139
123
|
zSignedAuthorizationRequestJwtHeaderTyp: () => zSignedAuthorizationRequestJwtHeaderTyp,
|
|
140
|
-
zTrustChain: () => zTrustChain,
|
|
141
124
|
zWalletAttestationJwtHeaderV1_0: () => zWalletAttestationJwtHeaderV1_0,
|
|
142
125
|
zWalletAttestationJwtHeaderV1_3: () => zWalletAttestationJwtHeaderV1_3,
|
|
143
126
|
zWalletAttestationJwtHeaderV1_4: () => zWalletAttestationJwtHeaderV1_4,
|
|
@@ -160,169 +143,15 @@ var createTokenRequest = async (options) => ({
|
|
|
160
143
|
});
|
|
161
144
|
|
|
162
145
|
// src/access-token/create-token-response.ts
|
|
163
|
-
var import_oauth22 = require("@openid4vc/oauth2");
|
|
164
146
|
var import_io_wallet_utils2 = require("@pagopa/io-wallet-utils");
|
|
165
147
|
|
|
166
|
-
// src/common/jwt/decode-jwt-header.ts
|
|
167
|
-
var import_oauth2 = require("@openid4vc/oauth2");
|
|
168
|
-
var import_io_wallet_utils = require("@pagopa/io-wallet-utils");
|
|
169
|
-
|
|
170
|
-
// src/common/jwt/z-jwt.ts
|
|
171
|
-
var import_zod3 = __toESM(require("zod"));
|
|
172
|
-
|
|
173
|
-
// src/common/jwk/z-jwk.ts
|
|
174
|
-
var import_zod2 = __toESM(require("zod"));
|
|
175
|
-
|
|
176
|
-
// src/common/z-common.ts
|
|
177
|
-
var import_zod = __toESM(require("zod"));
|
|
178
|
-
var zTrustChain = import_zod.default.tuple([import_zod.default.string()], import_zod.default.string());
|
|
179
|
-
var zCertificateChain = import_zod.default.array(import_zod.default.string()).nonempty();
|
|
180
|
-
var zAlgValueNotNone = import_zod.default.string().refine((alg) => alg !== "none", { message: `alg value may not be 'none'` });
|
|
181
|
-
|
|
182
|
-
// src/common/jwk/z-jwk.ts
|
|
183
|
-
var zJwk = import_zod2.default.looseObject({
|
|
184
|
-
alg: import_zod2.default.optional(import_zod2.default.string()),
|
|
185
|
-
crv: import_zod2.default.optional(import_zod2.default.string()),
|
|
186
|
-
d: import_zod2.default.optional(import_zod2.default.string()),
|
|
187
|
-
dp: import_zod2.default.optional(import_zod2.default.string()),
|
|
188
|
-
dq: import_zod2.default.optional(import_zod2.default.string()),
|
|
189
|
-
e: import_zod2.default.optional(import_zod2.default.string()),
|
|
190
|
-
ext: import_zod2.default.optional(import_zod2.default.boolean()),
|
|
191
|
-
k: import_zod2.default.optional(import_zod2.default.string()),
|
|
192
|
-
key_ops: import_zod2.default.optional(import_zod2.default.array(import_zod2.default.string())),
|
|
193
|
-
kid: import_zod2.default.optional(import_zod2.default.string()),
|
|
194
|
-
kty: import_zod2.default.string(),
|
|
195
|
-
n: import_zod2.default.optional(import_zod2.default.string()),
|
|
196
|
-
oth: import_zod2.default.optional(
|
|
197
|
-
import_zod2.default.array(
|
|
198
|
-
import_zod2.default.looseObject({
|
|
199
|
-
d: import_zod2.default.optional(import_zod2.default.string()),
|
|
200
|
-
r: import_zod2.default.optional(import_zod2.default.string()),
|
|
201
|
-
t: import_zod2.default.optional(import_zod2.default.string())
|
|
202
|
-
})
|
|
203
|
-
)
|
|
204
|
-
),
|
|
205
|
-
p: import_zod2.default.optional(import_zod2.default.string()),
|
|
206
|
-
q: import_zod2.default.optional(import_zod2.default.string()),
|
|
207
|
-
qi: import_zod2.default.optional(import_zod2.default.string()),
|
|
208
|
-
use: import_zod2.default.optional(import_zod2.default.string()),
|
|
209
|
-
x: import_zod2.default.optional(import_zod2.default.string()),
|
|
210
|
-
x5c: import_zod2.default.optional(zCertificateChain),
|
|
211
|
-
x5t: import_zod2.default.optional(import_zod2.default.string()),
|
|
212
|
-
"x5t#S256": import_zod2.default.optional(import_zod2.default.string()),
|
|
213
|
-
x5u: import_zod2.default.optional(import_zod2.default.string()),
|
|
214
|
-
y: import_zod2.default.optional(import_zod2.default.string())
|
|
215
|
-
});
|
|
216
|
-
var zJwkSet = import_zod2.default.looseObject({ keys: import_zod2.default.array(zJwk) });
|
|
217
|
-
|
|
218
|
-
// src/common/jwt/z-jwt.ts
|
|
219
|
-
var MAX_JTI_LENGTH = 256;
|
|
220
|
-
var zCompactJwt = import_zod3.default.string().regex(/^([a-zA-Z0-9-_]+)\.([a-zA-Z0-9-_]+)\.([a-zA-Z0-9-_]+)$/, {
|
|
221
|
-
message: "Not a valid compact jwt"
|
|
222
|
-
});
|
|
223
|
-
var zJwtConfirmationPayload = import_zod3.default.looseObject({
|
|
224
|
-
// RFC9449. jwk thumbprint of the dpop public key to which the access token is bound
|
|
225
|
-
jkt: import_zod3.default.string().optional(),
|
|
226
|
-
jwk: zJwk.optional()
|
|
227
|
-
});
|
|
228
|
-
var zJwtPayload = import_zod3.default.looseObject({
|
|
229
|
-
aud: import_zod3.default.string().optional(),
|
|
230
|
-
cnf: zJwtConfirmationPayload.optional(),
|
|
231
|
-
exp: import_zod3.default.number().int().optional(),
|
|
232
|
-
iat: import_zod3.default.number().int().optional(),
|
|
233
|
-
iss: import_zod3.default.string().optional(),
|
|
234
|
-
jti: import_zod3.default.string().max(MAX_JTI_LENGTH).optional(),
|
|
235
|
-
nbf: import_zod3.default.number().int().optional(),
|
|
236
|
-
nonce: import_zod3.default.string().optional(),
|
|
237
|
-
// Reserved for status parameters
|
|
238
|
-
status: import_zod3.default.record(import_zod3.default.string(), import_zod3.default.any()).optional(),
|
|
239
|
-
// Reserved for OpenID Federation
|
|
240
|
-
trust_chain: zTrustChain.optional()
|
|
241
|
-
});
|
|
242
|
-
var zJwtHeader = import_zod3.default.looseObject({
|
|
243
|
-
alg: zAlgValueNotNone,
|
|
244
|
-
jwk: zJwk.optional(),
|
|
245
|
-
kid: import_zod3.default.string().optional(),
|
|
246
|
-
// Reserved for OpenID Federation
|
|
247
|
-
trust_chain: zTrustChain.optional(),
|
|
248
|
-
typ: import_zod3.default.string().optional(),
|
|
249
|
-
x5c: zCertificateChain.optional()
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
// src/common/jwt/decode-jwt-header.ts
|
|
253
|
-
function decodeJwtHeader(options) {
|
|
254
|
-
const jwtParts = options.jwt.split(".");
|
|
255
|
-
if (jwtParts.length <= 2) {
|
|
256
|
-
throw new import_oauth2.Oauth2JwtParseError(
|
|
257
|
-
(0, import_io_wallet_utils.formatError)(
|
|
258
|
-
"Unable to decode because Jwt is not a valid!",
|
|
259
|
-
options.errorMessagePrefix
|
|
260
|
-
)
|
|
261
|
-
);
|
|
262
|
-
}
|
|
263
|
-
const [headerPart] = jwtParts;
|
|
264
|
-
let headerJson;
|
|
265
|
-
try {
|
|
266
|
-
headerJson = (0, import_io_wallet_utils.stringToJsonWithErrorHandling)(
|
|
267
|
-
(0, import_io_wallet_utils.encodeToUtf8String)((0, import_io_wallet_utils.decodeBase64)(headerPart)),
|
|
268
|
-
(0, import_io_wallet_utils.formatError)(
|
|
269
|
-
"Unable to parse jwt header to JSON",
|
|
270
|
-
options.errorMessagePrefix
|
|
271
|
-
)
|
|
272
|
-
);
|
|
273
|
-
} catch (error) {
|
|
274
|
-
throw new import_oauth2.Oauth2JwtParseError(
|
|
275
|
-
(0, import_io_wallet_utils.formatError)(
|
|
276
|
-
`Error parsing JWT. ${error instanceof Error ? error.message : ""}`,
|
|
277
|
-
options.errorMessagePrefix
|
|
278
|
-
)
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
const header = (0, import_io_wallet_utils.parseWithErrorHandling)(
|
|
282
|
-
options.headerSchema ?? zJwtHeader,
|
|
283
|
-
headerJson,
|
|
284
|
-
(0, import_io_wallet_utils.formatError)("Invalid JWT header", options.errorMessagePrefix)
|
|
285
|
-
);
|
|
286
|
-
return {
|
|
287
|
-
header
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
function jwtHeaderFromJwtSigner(signer) {
|
|
291
|
-
if (signer.method === "did") {
|
|
292
|
-
return {
|
|
293
|
-
alg: signer.alg,
|
|
294
|
-
kid: signer.didUrl
|
|
295
|
-
};
|
|
296
|
-
}
|
|
297
|
-
if (signer.method === "federation") {
|
|
298
|
-
return {
|
|
299
|
-
alg: signer.alg,
|
|
300
|
-
kid: signer.kid,
|
|
301
|
-
trust_chain: signer.trustChain
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
if (signer.method === "jwk") {
|
|
305
|
-
return {
|
|
306
|
-
alg: signer.alg,
|
|
307
|
-
jwk: signer.publicJwk
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
if (signer.method === "x5c") {
|
|
311
|
-
return {
|
|
312
|
-
alg: signer.alg,
|
|
313
|
-
kid: signer.kid,
|
|
314
|
-
trust_chain: signer.trustChain,
|
|
315
|
-
x5c: signer.x5c
|
|
316
|
-
};
|
|
317
|
-
}
|
|
318
|
-
return { alg: signer.alg };
|
|
319
|
-
}
|
|
320
|
-
|
|
321
148
|
// src/errors.ts
|
|
322
149
|
var Oauth2Error = class extends Error {
|
|
323
150
|
statusCode;
|
|
324
151
|
constructor(message, options) {
|
|
325
|
-
|
|
152
|
+
const errorMessage = message ?? "Unknown error occurred.";
|
|
153
|
+
const causeMessage = options?.cause instanceof Error ? ` ${options.cause.message}` : options?.cause ? ` ${String(options.cause)}` : "";
|
|
154
|
+
super(`${errorMessage}${causeMessage}`, options);
|
|
326
155
|
this.name = "Oauth2Error";
|
|
327
156
|
this.statusCode = options?.statusCode;
|
|
328
157
|
}
|
|
@@ -373,70 +202,71 @@ var ClientAttestationError = class extends Oauth2Error {
|
|
|
373
202
|
};
|
|
374
203
|
|
|
375
204
|
// src/access-token/z-token.ts
|
|
376
|
-
var
|
|
377
|
-
var
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
205
|
+
var import_io_wallet_utils = require("@pagopa/io-wallet-utils");
|
|
206
|
+
var import_zod = require("zod");
|
|
207
|
+
var zAccessTokenRequest = import_zod.z.discriminatedUnion("grant_type", [
|
|
208
|
+
import_zod.z.object({
|
|
209
|
+
code: import_zod.z.string().nonempty(),
|
|
210
|
+
code_verifier: import_zod.z.string().nonempty(),
|
|
211
|
+
grant_type: import_zod.z.literal("authorization_code"),
|
|
212
|
+
redirect_uri: import_zod.z.string().nonempty()
|
|
383
213
|
}),
|
|
384
|
-
|
|
385
|
-
grant_type:
|
|
386
|
-
refresh_token:
|
|
387
|
-
scope:
|
|
214
|
+
import_zod.z.object({
|
|
215
|
+
grant_type: import_zod.z.literal("refresh_token"),
|
|
216
|
+
refresh_token: import_zod.z.string().nonempty(),
|
|
217
|
+
scope: import_zod.z.string().optional()
|
|
388
218
|
})
|
|
389
219
|
]);
|
|
390
|
-
var zAccessTokenResponse =
|
|
391
|
-
access_token:
|
|
392
|
-
authorization_details:
|
|
393
|
-
|
|
394
|
-
credential_configuration_id:
|
|
395
|
-
credential_identifiers:
|
|
396
|
-
type:
|
|
220
|
+
var zAccessTokenResponse = import_zod.z.looseObject({
|
|
221
|
+
access_token: import_zod.z.string(),
|
|
222
|
+
authorization_details: import_zod.z.array(
|
|
223
|
+
import_zod.z.looseObject({
|
|
224
|
+
credential_configuration_id: import_zod.z.optional(import_zod.z.string()),
|
|
225
|
+
credential_identifiers: import_zod.z.optional(import_zod.z.array(import_zod.z.string())),
|
|
226
|
+
type: import_zod.z.literal("openid_credential")
|
|
397
227
|
})
|
|
398
228
|
).optional(),
|
|
399
|
-
expires_in:
|
|
400
|
-
refresh_token:
|
|
401
|
-
token_type:
|
|
229
|
+
expires_in: import_zod.z.optional(import_zod.z.number().int()),
|
|
230
|
+
refresh_token: import_zod.z.optional(import_zod.z.string()),
|
|
231
|
+
token_type: import_zod.z.union([import_zod.z.literal("Bearer"), import_zod.z.literal("DPoP")])
|
|
402
232
|
});
|
|
403
|
-
var zAccessTokenProfileJwtHeader =
|
|
404
|
-
...zJwtHeader.shape,
|
|
405
|
-
typ:
|
|
233
|
+
var zAccessTokenProfileJwtHeader = import_zod.z.looseObject({
|
|
234
|
+
...import_io_wallet_utils.zJwtHeader.shape,
|
|
235
|
+
typ: import_zod.z.enum(["application/at+jwt", "at+jwt"])
|
|
406
236
|
});
|
|
407
|
-
var zAccessTokenProfileJwtPayload =
|
|
408
|
-
...zJwtPayload.shape,
|
|
409
|
-
aud:
|
|
410
|
-
client_id:
|
|
411
|
-
cnf:
|
|
412
|
-
jkt:
|
|
237
|
+
var zAccessTokenProfileJwtPayload = import_zod.z.looseObject({
|
|
238
|
+
...import_io_wallet_utils.zJwtPayload.shape,
|
|
239
|
+
aud: import_zod.z.string(),
|
|
240
|
+
client_id: import_zod.z.string(),
|
|
241
|
+
cnf: import_zod.z.object({
|
|
242
|
+
jkt: import_zod.z.string()
|
|
413
243
|
}).optional(),
|
|
414
|
-
exp:
|
|
415
|
-
iat:
|
|
416
|
-
iss:
|
|
417
|
-
jti:
|
|
418
|
-
nbf:
|
|
419
|
-
scope:
|
|
420
|
-
sub:
|
|
244
|
+
exp: import_zod.z.number(),
|
|
245
|
+
iat: import_zod.z.number(),
|
|
246
|
+
iss: import_zod.z.string(),
|
|
247
|
+
jti: import_zod.z.string().max(import_io_wallet_utils.MAX_JTI_LENGTH),
|
|
248
|
+
nbf: import_zod.z.number().optional(),
|
|
249
|
+
scope: import_zod.z.string().optional(),
|
|
250
|
+
sub: import_zod.z.string()
|
|
421
251
|
});
|
|
422
|
-
var zRefreshTokenProfileJwtHeader =
|
|
423
|
-
...zJwtHeader.shape,
|
|
424
|
-
kid:
|
|
425
|
-
typ:
|
|
252
|
+
var zRefreshTokenProfileJwtHeader = import_zod.z.looseObject({
|
|
253
|
+
...import_io_wallet_utils.zJwtHeader.shape,
|
|
254
|
+
kid: import_zod.z.string(),
|
|
255
|
+
typ: import_zod.z.literal("rt+jwt")
|
|
426
256
|
});
|
|
427
|
-
var zRefreshTokenProfileJwtPayload =
|
|
428
|
-
...zJwtPayload.shape,
|
|
429
|
-
aud:
|
|
430
|
-
client_id:
|
|
431
|
-
cnf:
|
|
432
|
-
jkt:
|
|
257
|
+
var zRefreshTokenProfileJwtPayload = import_zod.z.looseObject({
|
|
258
|
+
...import_io_wallet_utils.zJwtPayload.shape,
|
|
259
|
+
aud: import_zod.z.string(),
|
|
260
|
+
client_id: import_zod.z.string(),
|
|
261
|
+
cnf: import_zod.z.object({
|
|
262
|
+
jkt: import_zod.z.string()
|
|
433
263
|
}),
|
|
434
|
-
exp:
|
|
435
|
-
iat:
|
|
436
|
-
iss:
|
|
437
|
-
jti:
|
|
438
|
-
nbf:
|
|
439
|
-
sub:
|
|
264
|
+
exp: import_zod.z.number().int(),
|
|
265
|
+
iat: import_zod.z.number().int(),
|
|
266
|
+
iss: import_zod.z.string(),
|
|
267
|
+
jti: import_zod.z.string().max(import_io_wallet_utils.MAX_JTI_LENGTH),
|
|
268
|
+
nbf: import_zod.z.number().int(),
|
|
269
|
+
sub: import_zod.z.string()
|
|
440
270
|
});
|
|
441
271
|
|
|
442
272
|
// src/access-token/create-token-response.ts
|
|
@@ -483,8 +313,8 @@ async function createAccessTokenResponse(options) {
|
|
|
483
313
|
`refreshTokenExpiresInSeconds (${options.refreshTokenExpiresInSeconds}) must be greater than expiresInSeconds (${options.expiresInSeconds}) so the Refresh Token remains usable after the Access Token expires.`
|
|
484
314
|
);
|
|
485
315
|
}
|
|
486
|
-
const dpopJkt = options.dpop ? await (0,
|
|
487
|
-
hashAlgorithm:
|
|
316
|
+
const dpopJkt = options.dpop ? await (0, import_io_wallet_utils2.calculateJwkThumbprint)({
|
|
317
|
+
hashAlgorithm: import_io_wallet_utils2.HashAlgorithm.Sha256,
|
|
488
318
|
hashCallback: options.callbacks.hash,
|
|
489
319
|
jwk: options.dpop.jwk
|
|
490
320
|
}) : void 0;
|
|
@@ -493,7 +323,7 @@ async function createAccessTokenResponse(options) {
|
|
|
493
323
|
options.expiresInSeconds
|
|
494
324
|
);
|
|
495
325
|
const header = (0, import_io_wallet_utils2.parseWithErrorHandling)(zAccessTokenProfileJwtHeader, {
|
|
496
|
-
...jwtHeaderFromJwtSigner(options.signer),
|
|
326
|
+
...(0, import_io_wallet_utils2.jwtHeaderFromJwtSigner)(options.signer),
|
|
497
327
|
typ: "at+jwt"
|
|
498
328
|
});
|
|
499
329
|
const payload = (0, import_io_wallet_utils2.parseWithErrorHandling)(zAccessTokenProfileJwtPayload, {
|
|
@@ -615,133 +445,66 @@ function toURLSearchParams(data) {
|
|
|
615
445
|
}
|
|
616
446
|
|
|
617
447
|
// src/access-token/parse-token-request.ts
|
|
618
|
-
var
|
|
448
|
+
var import_io_wallet_utils11 = require("@pagopa/io-wallet-utils");
|
|
619
449
|
|
|
620
450
|
// src/client-attestation/wallet-attestation.ts
|
|
621
|
-
var
|
|
622
|
-
var import_io_wallet_utils5 = require("@pagopa/io-wallet-utils");
|
|
451
|
+
var import_io_wallet_utils8 = require("@pagopa/io-wallet-utils");
|
|
623
452
|
|
|
624
453
|
// src/client-attestation/types.ts
|
|
625
|
-
var
|
|
626
|
-
var zOauthClientAttestationHeader =
|
|
454
|
+
var import_zod2 = __toESM(require("zod"));
|
|
455
|
+
var zOauthClientAttestationHeader = import_zod2.default.literal(
|
|
627
456
|
"OAuth-Client-Attestation"
|
|
628
457
|
);
|
|
629
458
|
var oauthClientAttestationHeader = zOauthClientAttestationHeader.value;
|
|
630
|
-
var zOauthClientAttestationPopHeader =
|
|
459
|
+
var zOauthClientAttestationPopHeader = import_zod2.default.literal(
|
|
631
460
|
"OAuth-Client-Attestation-PoP"
|
|
632
461
|
);
|
|
633
462
|
var oauthClientAttestationPopHeader = zOauthClientAttestationPopHeader.value;
|
|
634
463
|
|
|
635
464
|
// src/client-attestation/verify-wallet-attestation-jwt-base.ts
|
|
636
|
-
var import_oauth24 = require("@openid4vc/oauth2");
|
|
637
|
-
|
|
638
|
-
// src/common/jwt/decode-jwt.ts
|
|
639
|
-
var import_oauth23 = require("@openid4vc/oauth2");
|
|
640
465
|
var import_io_wallet_utils4 = require("@pagopa/io-wallet-utils");
|
|
641
|
-
function decodeJwt(options) {
|
|
642
|
-
const jwtParts = options.jwt.split(".");
|
|
643
|
-
if (jwtParts.length !== 3) {
|
|
644
|
-
throw new import_oauth23.Oauth2JwtParseError(
|
|
645
|
-
(0, import_io_wallet_utils4.formatError)(
|
|
646
|
-
"Unable to decode because Jwt is not a valid!",
|
|
647
|
-
options.errorMessagePrefix
|
|
648
|
-
)
|
|
649
|
-
);
|
|
650
|
-
}
|
|
651
|
-
let payloadJson;
|
|
652
|
-
try {
|
|
653
|
-
const payloadPart = jwtParts[1];
|
|
654
|
-
if (payloadPart === void 0) {
|
|
655
|
-
throw new import_oauth23.Oauth2JwtParseError(
|
|
656
|
-
(0, import_io_wallet_utils4.formatError)(
|
|
657
|
-
"Unable to decode because Jwt is not a valid!",
|
|
658
|
-
options.errorMessagePrefix
|
|
659
|
-
)
|
|
660
|
-
);
|
|
661
|
-
}
|
|
662
|
-
payloadJson = (0, import_io_wallet_utils4.stringToJsonWithErrorHandling)(
|
|
663
|
-
(0, import_io_wallet_utils4.encodeToUtf8String)((0, import_io_wallet_utils4.decodeBase64)(payloadPart)),
|
|
664
|
-
(0, import_io_wallet_utils4.formatError)(
|
|
665
|
-
"Unable to parse jwt payload to JSON",
|
|
666
|
-
options.errorMessagePrefix
|
|
667
|
-
)
|
|
668
|
-
);
|
|
669
|
-
} catch (error) {
|
|
670
|
-
throw new import_oauth23.Oauth2JwtParseError(
|
|
671
|
-
(0, import_io_wallet_utils4.formatError)(
|
|
672
|
-
`Error parsing JWT. ${error instanceof Error ? error.message : ""}`,
|
|
673
|
-
options.errorMessagePrefix
|
|
674
|
-
)
|
|
675
|
-
);
|
|
676
|
-
}
|
|
677
|
-
const signaturePart = jwtParts[2];
|
|
678
|
-
if (signaturePart === void 0) {
|
|
679
|
-
throw new import_oauth23.Oauth2JwtParseError(
|
|
680
|
-
(0, import_io_wallet_utils4.formatError)(
|
|
681
|
-
"Unable to decode because Jwt is not a valid!",
|
|
682
|
-
options.errorMessagePrefix
|
|
683
|
-
)
|
|
684
|
-
);
|
|
685
|
-
}
|
|
686
|
-
const { header } = decodeJwtHeader({
|
|
687
|
-
errorMessagePrefix: options.errorMessagePrefix,
|
|
688
|
-
headerSchema: options.headerSchema,
|
|
689
|
-
jwt: options.jwt
|
|
690
|
-
});
|
|
691
|
-
const payload = (0, import_io_wallet_utils4.parseWithErrorHandling)(
|
|
692
|
-
options.payloadSchema ?? zJwtPayload,
|
|
693
|
-
payloadJson,
|
|
694
|
-
(0, import_io_wallet_utils4.formatError)("Invalid JWT payload", options.errorMessagePrefix)
|
|
695
|
-
);
|
|
696
|
-
return {
|
|
697
|
-
header,
|
|
698
|
-
payload,
|
|
699
|
-
signature: signaturePart
|
|
700
|
-
};
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
// src/client-attestation/verify-wallet-attestation-jwt-base.ts
|
|
704
466
|
async function verifyWalletAttestationBase(options, headerSchema, payloadSchema) {
|
|
705
|
-
const { header, payload } = decodeJwt({
|
|
467
|
+
const { header, payload } = (0, import_io_wallet_utils4.decodeJwt)({
|
|
706
468
|
errorMessagePrefix: "Error decoding wallet attestation JWT:",
|
|
707
469
|
headerSchema,
|
|
708
470
|
jwt: options.walletAttestationJwt,
|
|
709
471
|
payloadSchema
|
|
710
472
|
});
|
|
711
|
-
const { signer } = await (0,
|
|
473
|
+
const { signer } = await (0, import_io_wallet_utils4.verifyJwt)({
|
|
712
474
|
compact: options.walletAttestationJwt,
|
|
713
475
|
errorMessage: "wallet attestation verification failed.",
|
|
714
476
|
header,
|
|
715
477
|
now: options.now,
|
|
716
478
|
payload,
|
|
717
|
-
signer: (0,
|
|
479
|
+
signer: (0, import_io_wallet_utils4.jwtSignerFromJwt)({ header, payload }),
|
|
718
480
|
verifyJwtCallback: options.callbacks.verifyJwt
|
|
719
481
|
});
|
|
720
482
|
return { header, payload, signer };
|
|
721
483
|
}
|
|
722
484
|
|
|
723
485
|
// src/client-attestation/v1.0/z-wallet-attestation.ts
|
|
724
|
-
var
|
|
725
|
-
var
|
|
726
|
-
|
|
727
|
-
|
|
486
|
+
var import_io_wallet_utils5 = require("@pagopa/io-wallet-utils");
|
|
487
|
+
var import_zod3 = require("zod");
|
|
488
|
+
var zWalletAttestationJwtHeaderV1_0 = import_zod3.z.looseObject({
|
|
489
|
+
...import_io_wallet_utils5.zJwtHeader.shape,
|
|
490
|
+
trust_chain: import_io_wallet_utils5.zTrustChain,
|
|
728
491
|
// REQUIRED in v1.0
|
|
729
|
-
typ:
|
|
492
|
+
typ: import_zod3.z.literal("oauth-client-attestation+jwt")
|
|
730
493
|
});
|
|
731
|
-
var zWalletAttestationJwtPayloadV1_0 =
|
|
732
|
-
...zJwtPayload.shape,
|
|
733
|
-
aal:
|
|
734
|
-
cnf:
|
|
735
|
-
jwk: zJwk
|
|
494
|
+
var zWalletAttestationJwtPayloadV1_0 = import_zod3.z.looseObject({
|
|
495
|
+
...import_io_wallet_utils5.zJwtPayload.shape,
|
|
496
|
+
aal: import_zod3.z.string(),
|
|
497
|
+
cnf: import_zod3.z.object({
|
|
498
|
+
jwk: import_io_wallet_utils5.zJwk
|
|
736
499
|
}),
|
|
737
|
-
exp:
|
|
738
|
-
iat:
|
|
739
|
-
iss:
|
|
740
|
-
sub:
|
|
741
|
-
wallet_link:
|
|
742
|
-
wallet_name:
|
|
500
|
+
exp: import_zod3.z.number(),
|
|
501
|
+
iat: import_zod3.z.number(),
|
|
502
|
+
iss: import_zod3.z.string(),
|
|
503
|
+
sub: import_zod3.z.string(),
|
|
504
|
+
wallet_link: import_zod3.z.url().optional(),
|
|
505
|
+
wallet_name: import_zod3.z.string().optional()
|
|
743
506
|
});
|
|
744
|
-
var zWalletAttestationJwtV1_0 =
|
|
507
|
+
var zWalletAttestationJwtV1_0 = import_zod3.z.string().min(1);
|
|
745
508
|
|
|
746
509
|
// src/client-attestation/v1.0/verify-wallet-attestation-jwt.ts
|
|
747
510
|
async function verifyWalletAttestationJwt(options) {
|
|
@@ -753,37 +516,38 @@ async function verifyWalletAttestationJwt(options) {
|
|
|
753
516
|
}
|
|
754
517
|
|
|
755
518
|
// src/client-attestation/v1.3/z-wallet-attestation.ts
|
|
756
|
-
var
|
|
757
|
-
var
|
|
758
|
-
|
|
759
|
-
|
|
519
|
+
var import_io_wallet_utils6 = require("@pagopa/io-wallet-utils");
|
|
520
|
+
var import_zod4 = require("zod");
|
|
521
|
+
var zWalletAttestationJwtHeaderV1_3 = import_zod4.z.looseObject({
|
|
522
|
+
...import_io_wallet_utils6.zJwtHeader.shape,
|
|
523
|
+
trust_chain: import_io_wallet_utils6.zTrustChain.optional(),
|
|
760
524
|
// OPTIONAL in v1.3
|
|
761
|
-
typ:
|
|
762
|
-
x5c: zCertificateChain
|
|
525
|
+
typ: import_zod4.z.literal("oauth-client-attestation+jwt"),
|
|
526
|
+
x5c: import_io_wallet_utils6.zCertificateChain
|
|
763
527
|
// REQUIRED in v1.3
|
|
764
528
|
});
|
|
765
|
-
var zWalletAttestationJwtPayloadV1_3 =
|
|
766
|
-
...zJwtPayload.shape,
|
|
767
|
-
cnf:
|
|
768
|
-
jwk: zJwk
|
|
529
|
+
var zWalletAttestationJwtPayloadV1_3 = import_zod4.z.looseObject({
|
|
530
|
+
...import_io_wallet_utils6.zJwtPayload.shape,
|
|
531
|
+
cnf: import_zod4.z.object({
|
|
532
|
+
jwk: import_io_wallet_utils6.zJwk
|
|
769
533
|
}),
|
|
770
|
-
exp:
|
|
771
|
-
iat:
|
|
772
|
-
iss:
|
|
773
|
-
nbf:
|
|
534
|
+
exp: import_zod4.z.number(),
|
|
535
|
+
iat: import_zod4.z.number(),
|
|
536
|
+
iss: import_zod4.z.string(),
|
|
537
|
+
nbf: import_zod4.z.number().optional(),
|
|
774
538
|
// NEW in v1.3
|
|
775
|
-
status:
|
|
776
|
-
status_list:
|
|
777
|
-
idx:
|
|
778
|
-
uri:
|
|
539
|
+
status: import_zod4.z.object({
|
|
540
|
+
status_list: import_zod4.z.object({
|
|
541
|
+
idx: import_zod4.z.number().int(),
|
|
542
|
+
uri: import_zod4.z.string()
|
|
779
543
|
})
|
|
780
544
|
}).optional(),
|
|
781
545
|
// NEW in v1.3 - status object for revocation
|
|
782
|
-
sub:
|
|
783
|
-
wallet_link:
|
|
784
|
-
wallet_name:
|
|
546
|
+
sub: import_zod4.z.string(),
|
|
547
|
+
wallet_link: import_zod4.z.url().optional(),
|
|
548
|
+
wallet_name: import_zod4.z.string().optional()
|
|
785
549
|
});
|
|
786
|
-
var zWalletAttestationJwtV1_3 =
|
|
550
|
+
var zWalletAttestationJwtV1_3 = import_zod4.z.string().min(1);
|
|
787
551
|
|
|
788
552
|
// src/client-attestation/v1.3/verify-wallet-attestation-jwt.ts
|
|
789
553
|
async function verifyWalletAttestationJwt2(options) {
|
|
@@ -795,28 +559,29 @@ async function verifyWalletAttestationJwt2(options) {
|
|
|
795
559
|
}
|
|
796
560
|
|
|
797
561
|
// src/client-attestation/v1.4/z-wallet-attestation.ts
|
|
798
|
-
var
|
|
799
|
-
var
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
562
|
+
var import_io_wallet_utils7 = require("@pagopa/io-wallet-utils");
|
|
563
|
+
var import_zod5 = require("zod");
|
|
564
|
+
var zWalletAttestationJwtHeaderV1_4 = import_zod5.z.looseObject({
|
|
565
|
+
...import_io_wallet_utils7.zJwtHeader.shape,
|
|
566
|
+
kid: import_zod5.z.string(),
|
|
567
|
+
trust_chain: import_io_wallet_utils7.zTrustChain.optional(),
|
|
568
|
+
typ: import_zod5.z.literal("oauth-client-attestation+jwt"),
|
|
569
|
+
x5c: import_io_wallet_utils7.zCertificateChain
|
|
805
570
|
});
|
|
806
|
-
var zWalletAttestationJwtPayloadV1_4 =
|
|
807
|
-
...zJwtPayload.shape,
|
|
808
|
-
cnf:
|
|
809
|
-
jwk: zJwk
|
|
571
|
+
var zWalletAttestationJwtPayloadV1_4 = import_zod5.z.looseObject({
|
|
572
|
+
...import_io_wallet_utils7.zJwtPayload.shape,
|
|
573
|
+
cnf: import_zod5.z.object({
|
|
574
|
+
jwk: import_io_wallet_utils7.zJwk
|
|
810
575
|
}),
|
|
811
|
-
exp:
|
|
812
|
-
iat:
|
|
813
|
-
iss:
|
|
814
|
-
nbf:
|
|
815
|
-
sub:
|
|
816
|
-
wallet_link:
|
|
817
|
-
wallet_name:
|
|
576
|
+
exp: import_zod5.z.number().int(),
|
|
577
|
+
iat: import_zod5.z.number().int(),
|
|
578
|
+
iss: import_zod5.z.string(),
|
|
579
|
+
nbf: import_zod5.z.number().optional(),
|
|
580
|
+
sub: import_zod5.z.string(),
|
|
581
|
+
wallet_link: import_zod5.z.url(),
|
|
582
|
+
wallet_name: import_zod5.z.string()
|
|
818
583
|
});
|
|
819
|
-
var zWalletAttestationJwtV1_4 =
|
|
584
|
+
var zWalletAttestationJwtV1_4 = import_zod5.z.string().min(1);
|
|
820
585
|
|
|
821
586
|
// src/client-attestation/v1.4/verify-wallet-attestation-jwt.ts
|
|
822
587
|
async function verifyWalletAttestationJwt3(options) {
|
|
@@ -828,10 +593,10 @@ async function verifyWalletAttestationJwt3(options) {
|
|
|
828
593
|
}
|
|
829
594
|
|
|
830
595
|
// src/client-attestation/wallet-attestation.ts
|
|
831
|
-
var dispatchVerifyWalletAttestationJwt = (0,
|
|
832
|
-
[
|
|
833
|
-
[
|
|
834
|
-
[
|
|
596
|
+
var dispatchVerifyWalletAttestationJwt = (0, import_io_wallet_utils8.createVersionDispatcher)({
|
|
597
|
+
[import_io_wallet_utils8.ItWalletSpecsVersion.V1_0]: (o) => verifyWalletAttestationJwt(o),
|
|
598
|
+
[import_io_wallet_utils8.ItWalletSpecsVersion.V1_3]: (o) => verifyWalletAttestationJwt2(o),
|
|
599
|
+
[import_io_wallet_utils8.ItWalletSpecsVersion.V1_4]: (o) => verifyWalletAttestationJwt3(o)
|
|
835
600
|
});
|
|
836
601
|
async function verifyWalletAttestationJwt4(options) {
|
|
837
602
|
return dispatchVerifyWalletAttestationJwt(options);
|
|
@@ -847,7 +612,7 @@ function extractClientAttestationJwtsFromHeaders(headers) {
|
|
|
847
612
|
if (!walletAttestationHeader || !clientAttestationPopHeader) {
|
|
848
613
|
return { valid: false };
|
|
849
614
|
}
|
|
850
|
-
if (!
|
|
615
|
+
if (!import_io_wallet_utils8.zCompactJwt.safeParse(walletAttestationHeader).success || !import_io_wallet_utils8.zCompactJwt.safeParse(clientAttestationPopHeader).success) {
|
|
851
616
|
return { valid: false };
|
|
852
617
|
}
|
|
853
618
|
return {
|
|
@@ -858,8 +623,7 @@ function extractClientAttestationJwtsFromHeaders(headers) {
|
|
|
858
623
|
}
|
|
859
624
|
|
|
860
625
|
// src/token-dpop/create-token-dpop.ts
|
|
861
|
-
var
|
|
862
|
-
var import_io_wallet_utils7 = require("@pagopa/io-wallet-utils");
|
|
626
|
+
var import_io_wallet_utils10 = require("@pagopa/io-wallet-utils");
|
|
863
627
|
var import_js_base64 = require("js-base64");
|
|
864
628
|
|
|
865
629
|
// src/token-dpop/dpop-utils.ts
|
|
@@ -871,29 +635,29 @@ var htuFromRequestUrl = (requestUrl) => {
|
|
|
871
635
|
};
|
|
872
636
|
|
|
873
637
|
// src/token-dpop/z-dpop.ts
|
|
874
|
-
var
|
|
875
|
-
var
|
|
876
|
-
var zDpopJwtPayload =
|
|
877
|
-
...zJwtPayload.shape,
|
|
878
|
-
ath:
|
|
879
|
-
htm:
|
|
880
|
-
htu:
|
|
881
|
-
iat:
|
|
882
|
-
jti:
|
|
638
|
+
var import_io_wallet_utils9 = require("@pagopa/io-wallet-utils");
|
|
639
|
+
var import_zod6 = __toESM(require("zod"));
|
|
640
|
+
var zDpopJwtPayload = import_zod6.default.looseObject({
|
|
641
|
+
...import_io_wallet_utils9.zJwtPayload.shape,
|
|
642
|
+
ath: import_zod6.default.optional(import_zod6.default.string()),
|
|
643
|
+
htm: import_io_wallet_utils9.zHttpMethod,
|
|
644
|
+
htu: import_zod6.default.url(),
|
|
645
|
+
iat: import_zod6.default.number().int().nonnegative(),
|
|
646
|
+
jti: import_zod6.default.string().max(import_io_wallet_utils9.MAX_JTI_LENGTH)
|
|
883
647
|
});
|
|
884
|
-
var zDpopJwtHeader =
|
|
885
|
-
...zJwtHeader.shape,
|
|
886
|
-
jwk: zJwk,
|
|
887
|
-
typ:
|
|
648
|
+
var zDpopJwtHeader = import_zod6.default.looseObject({
|
|
649
|
+
...import_io_wallet_utils9.zJwtHeader.shape,
|
|
650
|
+
jwk: import_io_wallet_utils9.zJwk,
|
|
651
|
+
typ: import_zod6.default.literal("dpop+jwt")
|
|
888
652
|
});
|
|
889
653
|
|
|
890
654
|
// src/token-dpop/create-token-dpop.ts
|
|
891
655
|
async function createTokenDPoP(options) {
|
|
892
656
|
try {
|
|
893
|
-
const ath = options.accessToken ? (0,
|
|
657
|
+
const ath = options.accessToken ? (0, import_io_wallet_utils10.encodeToBase64Url)(
|
|
894
658
|
await options.callbacks.hash(
|
|
895
|
-
(0,
|
|
896
|
-
|
|
659
|
+
(0, import_io_wallet_utils10.decodeUtf8String)(options.accessToken),
|
|
660
|
+
import_io_wallet_utils10.HashAlgorithm.Sha256
|
|
897
661
|
)
|
|
898
662
|
) : void 0;
|
|
899
663
|
const jti = options.jti ?? (options.callbacks.generateRandom ? import_js_base64.Base64.fromUint8Array(
|
|
@@ -905,16 +669,16 @@ async function createTokenDPoP(options) {
|
|
|
905
669
|
"Error: neither a default jti nor a generateRandom callback have been provided"
|
|
906
670
|
);
|
|
907
671
|
}
|
|
908
|
-
const header = (0,
|
|
672
|
+
const header = (0, import_io_wallet_utils10.parseWithErrorHandling)(zDpopJwtHeader, {
|
|
909
673
|
alg: options.signer.alg,
|
|
910
674
|
jwk: options.signer.publicJwk,
|
|
911
675
|
typ: "dpop+jwt"
|
|
912
676
|
});
|
|
913
|
-
const payload = (0,
|
|
677
|
+
const payload = (0, import_io_wallet_utils10.parseWithErrorHandling)(zDpopJwtPayload, {
|
|
914
678
|
ath,
|
|
915
679
|
htm: options.tokenRequest.method,
|
|
916
680
|
htu: htuFromRequestUrl(options.tokenRequest.url),
|
|
917
|
-
iat: (0,
|
|
681
|
+
iat: (0, import_io_wallet_utils10.dateToSeconds)(options.issuedAt),
|
|
918
682
|
jti
|
|
919
683
|
});
|
|
920
684
|
return options.callbacks.signJwt(options.signer, {
|
|
@@ -922,7 +686,7 @@ async function createTokenDPoP(options) {
|
|
|
922
686
|
payload
|
|
923
687
|
});
|
|
924
688
|
} catch (error) {
|
|
925
|
-
if (error instanceof CreateTokenDPoPError || error instanceof
|
|
689
|
+
if (error instanceof CreateTokenDPoPError || error instanceof import_io_wallet_utils10.ValidationError) {
|
|
926
690
|
throw error;
|
|
927
691
|
}
|
|
928
692
|
throw new CreateTokenDPoPError(
|
|
@@ -935,17 +699,17 @@ function extractDpopJwtFromHeaders(headers) {
|
|
|
935
699
|
if (!dpopJwt) {
|
|
936
700
|
return { valid: true };
|
|
937
701
|
}
|
|
938
|
-
if (!
|
|
702
|
+
if (!import_io_wallet_utils10.zCompactJwt.safeParse(dpopJwt).success) {
|
|
939
703
|
return { valid: false };
|
|
940
704
|
}
|
|
941
705
|
return { dpopJwt, valid: true };
|
|
942
706
|
}
|
|
943
707
|
|
|
944
708
|
// src/access-token/z-grant-type.ts
|
|
945
|
-
var
|
|
946
|
-
var zAuthorizationCodeGrantIdentifier =
|
|
709
|
+
var import_zod7 = require("zod");
|
|
710
|
+
var zAuthorizationCodeGrantIdentifier = import_zod7.z.literal("authorization_code");
|
|
947
711
|
var authorizationCodeGrantIdentifier = zAuthorizationCodeGrantIdentifier.value;
|
|
948
|
-
var zRefreshTokenGrantIdentifier =
|
|
712
|
+
var zRefreshTokenGrantIdentifier = import_zod7.z.literal("refresh_token");
|
|
949
713
|
var refreshTokenGrantIdentifier = zRefreshTokenGrantIdentifier.value;
|
|
950
714
|
|
|
951
715
|
// src/access-token/parse-token-request.ts
|
|
@@ -956,7 +720,7 @@ function parseAccessTokenRequest(options) {
|
|
|
956
720
|
if (!validationResult.success) {
|
|
957
721
|
throw new Oauth2Error(
|
|
958
722
|
`Access token request validation failed:
|
|
959
|
-
${(0,
|
|
723
|
+
${(0, import_io_wallet_utils11.formatZodError)(validationResult.error)}`
|
|
960
724
|
);
|
|
961
725
|
}
|
|
962
726
|
const accessTokenRequest = validationResult.data;
|
|
@@ -1023,36 +787,36 @@ function parseSecurityHeaders(headers) {
|
|
|
1023
787
|
}
|
|
1024
788
|
|
|
1025
789
|
// src/client-attestation/verify-client-attestation.ts
|
|
1026
|
-
var
|
|
790
|
+
var import_io_wallet_utils14 = require("@pagopa/io-wallet-utils");
|
|
1027
791
|
|
|
1028
792
|
// src/client-attestation/client-attestation-pop.ts
|
|
1029
|
-
var
|
|
1030
|
-
var import_io_wallet_utils9 = require("@pagopa/io-wallet-utils");
|
|
793
|
+
var import_io_wallet_utils13 = require("@pagopa/io-wallet-utils");
|
|
1031
794
|
|
|
1032
795
|
// src/client-attestation/z-client-attestation-pop.ts
|
|
1033
|
-
var
|
|
796
|
+
var import_io_wallet_utils12 = require("@pagopa/io-wallet-utils");
|
|
797
|
+
var import_zod8 = __toESM(require("zod"));
|
|
1034
798
|
var IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES = [
|
|
1035
799
|
"ES256",
|
|
1036
800
|
"ES384",
|
|
1037
801
|
"ES512"
|
|
1038
802
|
];
|
|
1039
|
-
var zItWalletClientAttestationPopJwtAlg =
|
|
803
|
+
var zItWalletClientAttestationPopJwtAlg = import_zod8.default.enum(
|
|
1040
804
|
IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES
|
|
1041
805
|
);
|
|
1042
|
-
var zItWalletClientAttestationPopJwtPayload =
|
|
1043
|
-
...zJwtPayload.shape,
|
|
1044
|
-
aud:
|
|
1045
|
-
exp:
|
|
1046
|
-
iat:
|
|
1047
|
-
iss:
|
|
1048
|
-
jti:
|
|
1049
|
-
nonce:
|
|
806
|
+
var zItWalletClientAttestationPopJwtPayload = import_zod8.default.looseObject({
|
|
807
|
+
...import_io_wallet_utils12.zJwtPayload.shape,
|
|
808
|
+
aud: import_zod8.default.string(),
|
|
809
|
+
exp: import_zod8.default.number().int().optional(),
|
|
810
|
+
iat: import_zod8.default.number().int(),
|
|
811
|
+
iss: import_zod8.default.string(),
|
|
812
|
+
jti: import_zod8.default.string().max(import_io_wallet_utils12.MAX_JTI_LENGTH),
|
|
813
|
+
nonce: import_zod8.default.string().optional()
|
|
1050
814
|
});
|
|
1051
|
-
var zItWalletClientAttestationPopJwtTyp =
|
|
815
|
+
var zItWalletClientAttestationPopJwtTyp = import_zod8.default.literal(
|
|
1052
816
|
"oauth-client-attestation-pop+jwt"
|
|
1053
817
|
);
|
|
1054
|
-
var zItWalletClientAttestationPopJwtHeader =
|
|
1055
|
-
...zJwtHeader.shape,
|
|
818
|
+
var zItWalletClientAttestationPopJwtHeader = import_zod8.default.looseObject({
|
|
819
|
+
...import_io_wallet_utils12.zJwtHeader.shape,
|
|
1056
820
|
typ: zItWalletClientAttestationPopJwtTyp
|
|
1057
821
|
});
|
|
1058
822
|
|
|
@@ -1066,14 +830,14 @@ function assertSupportedClientAttestationPopAlg(alg) {
|
|
|
1066
830
|
}
|
|
1067
831
|
async function verifyClientAttestationPopJwt(options) {
|
|
1068
832
|
try {
|
|
1069
|
-
const { header, payload } = decodeJwt({
|
|
833
|
+
const { header, payload } = (0, import_io_wallet_utils13.decodeJwt)({
|
|
1070
834
|
errorMessagePrefix: "Error decoding client attestation PoP JWT:",
|
|
1071
835
|
headerSchema: zItWalletClientAttestationPopJwtHeader,
|
|
1072
836
|
jwt: options.clientAttestationPopJwt,
|
|
1073
837
|
payloadSchema: zItWalletClientAttestationPopJwtPayload
|
|
1074
838
|
});
|
|
1075
839
|
assertSupportedClientAttestationPopAlg(header.alg);
|
|
1076
|
-
const { signer } = await (0,
|
|
840
|
+
const { signer } = await (0, import_io_wallet_utils13.verifyJwt)({
|
|
1077
841
|
compact: options.clientAttestationPopJwt,
|
|
1078
842
|
errorMessage: "client attestation pop jwt verification failed",
|
|
1079
843
|
expectedAudience: options.authorizationServer,
|
|
@@ -1102,7 +866,7 @@ async function verifyClientAttestationPopJwt(options) {
|
|
|
1102
866
|
}
|
|
1103
867
|
async function createClientAttestationPopJwt(options) {
|
|
1104
868
|
try {
|
|
1105
|
-
const clientAttestation = decodeJwt({
|
|
869
|
+
const clientAttestation = (0, import_io_wallet_utils13.decodeJwt)({
|
|
1106
870
|
errorMessagePrefix: "Error decoding client attestation JWT:",
|
|
1107
871
|
jwt: options.clientAttestation
|
|
1108
872
|
});
|
|
@@ -1129,22 +893,22 @@ async function createClientAttestationPopJwt(options) {
|
|
|
1129
893
|
typ: zItWalletClientAttestationPopJwtTyp.value
|
|
1130
894
|
};
|
|
1131
895
|
const issuedAt = options.issuedAt ?? /* @__PURE__ */ new Date();
|
|
1132
|
-
const jti = options.jti ?? (options.callbacks.generateRandom ? (0,
|
|
896
|
+
const jti = options.jti ?? (options.callbacks.generateRandom ? (0, import_io_wallet_utils13.encodeToBase64Url)(await options.callbacks.generateRandom(32)) : void 0);
|
|
1133
897
|
if (!jti) {
|
|
1134
898
|
throw new Oauth2Error(
|
|
1135
899
|
"Error: neither a default jti nor a generateRandom callback have been provided"
|
|
1136
900
|
);
|
|
1137
901
|
}
|
|
1138
|
-
const payload = (0,
|
|
902
|
+
const payload = (0, import_io_wallet_utils13.parseWithErrorHandling)(
|
|
1139
903
|
zItWalletClientAttestationPopJwtPayload,
|
|
1140
904
|
{
|
|
1141
905
|
aud: options.authorizationServer,
|
|
1142
|
-
iat: (0,
|
|
906
|
+
iat: (0, import_io_wallet_utils13.dateToSeconds)(issuedAt),
|
|
1143
907
|
iss: sub,
|
|
1144
908
|
jti,
|
|
1145
|
-
...options.config.itWalletSpecsVersion ===
|
|
1146
|
-
exp: (0,
|
|
1147
|
-
"expiresAt" in options && options.expiresAt ? options.expiresAt : (0,
|
|
909
|
+
...options.config.itWalletSpecsVersion === import_io_wallet_utils13.ItWalletSpecsVersion.V1_0 ? {
|
|
910
|
+
exp: (0, import_io_wallet_utils13.dateToSeconds)(
|
|
911
|
+
"expiresAt" in options && options.expiresAt ? options.expiresAt : (0, import_io_wallet_utils13.addSecondsToDate)(issuedAt, 1 * 60)
|
|
1148
912
|
)
|
|
1149
913
|
} : {}
|
|
1150
914
|
}
|
|
@@ -1189,8 +953,8 @@ async function verifyClientAttestation(options) {
|
|
|
1189
953
|
);
|
|
1190
954
|
}
|
|
1191
955
|
if (options.clientAttestation.ensureConfirmationKeyMatchesDpopKey && options.dpopJwkThumbprint) {
|
|
1192
|
-
const clientAttestationJkt = await (0,
|
|
1193
|
-
hashAlgorithm:
|
|
956
|
+
const clientAttestationJkt = await (0, import_io_wallet_utils14.calculateJwkThumbprint)({
|
|
957
|
+
hashAlgorithm: import_io_wallet_utils14.HashAlgorithm.Sha256,
|
|
1194
958
|
hashCallback: options.callbacks.hash,
|
|
1195
959
|
jwk: clientAttestation.payload.cnf.jwk
|
|
1196
960
|
});
|
|
@@ -1207,8 +971,7 @@ async function verifyClientAttestation(options) {
|
|
|
1207
971
|
}
|
|
1208
972
|
|
|
1209
973
|
// src/pkce.ts
|
|
1210
|
-
var
|
|
1211
|
-
var import_io_wallet_utils10 = require("@pagopa/io-wallet-utils");
|
|
974
|
+
var import_io_wallet_utils15 = require("@pagopa/io-wallet-utils");
|
|
1212
975
|
var PkceCodeChallengeMethod = {
|
|
1213
976
|
Plain: "plain",
|
|
1214
977
|
S256: "S256"
|
|
@@ -1226,7 +989,7 @@ async function createPkce(options) {
|
|
|
1226
989
|
const codeChallengeMethod = allowedCodeChallengeMethods.includes(
|
|
1227
990
|
PkceCodeChallengeMethod.S256
|
|
1228
991
|
) ? PkceCodeChallengeMethod.S256 : PkceCodeChallengeMethod.Plain;
|
|
1229
|
-
const codeVerifier = options.codeVerifier ?? (0,
|
|
992
|
+
const codeVerifier = options.codeVerifier ?? (0, import_io_wallet_utils15.encodeToBase64Url)(await options.callbacks.generateRandom(64));
|
|
1230
993
|
return {
|
|
1231
994
|
codeChallenge: await calculateCodeChallenge({
|
|
1232
995
|
codeChallengeMethod,
|
|
@@ -1254,10 +1017,10 @@ async function calculateCodeChallenge(options) {
|
|
|
1254
1017
|
return options.codeVerifier;
|
|
1255
1018
|
}
|
|
1256
1019
|
if (options.codeChallengeMethod === PkceCodeChallengeMethod.S256) {
|
|
1257
|
-
return (0,
|
|
1020
|
+
return (0, import_io_wallet_utils15.encodeToBase64Url)(
|
|
1258
1021
|
await options.hashCallback(
|
|
1259
|
-
(0,
|
|
1260
|
-
|
|
1022
|
+
(0, import_io_wallet_utils15.decodeUtf8String)(options.codeVerifier),
|
|
1023
|
+
import_io_wallet_utils15.HashAlgorithm.Sha256
|
|
1261
1024
|
)
|
|
1262
1025
|
);
|
|
1263
1026
|
}
|
|
@@ -1267,10 +1030,9 @@ async function calculateCodeChallenge(options) {
|
|
|
1267
1030
|
}
|
|
1268
1031
|
|
|
1269
1032
|
// src/token-dpop/verify-token-dpop.ts
|
|
1270
|
-
var
|
|
1271
|
-
var import_io_wallet_utils11 = require("@pagopa/io-wallet-utils");
|
|
1033
|
+
var import_io_wallet_utils16 = require("@pagopa/io-wallet-utils");
|
|
1272
1034
|
async function verifyTokenDPoP(options) {
|
|
1273
|
-
const { header, payload } = decodeJwt({
|
|
1035
|
+
const { header, payload } = (0, import_io_wallet_utils16.decodeJwt)({
|
|
1274
1036
|
errorMessagePrefix: "Error decoding access token DPoP JWT:",
|
|
1275
1037
|
headerSchema: zDpopJwtHeader,
|
|
1276
1038
|
jwt: options.dpopJwt,
|
|
@@ -1308,10 +1070,10 @@ async function verifyTokenDPoP(options) {
|
|
|
1308
1070
|
);
|
|
1309
1071
|
}
|
|
1310
1072
|
if (options.accessToken) {
|
|
1311
|
-
const expectedAth = (0,
|
|
1073
|
+
const expectedAth = (0, import_io_wallet_utils16.encodeToBase64Url)(
|
|
1312
1074
|
await options.callbacks.hash(
|
|
1313
|
-
(0,
|
|
1314
|
-
|
|
1075
|
+
(0, import_io_wallet_utils16.decodeUtf8String)(options.accessToken),
|
|
1076
|
+
import_io_wallet_utils16.HashAlgorithm.Sha256
|
|
1315
1077
|
)
|
|
1316
1078
|
);
|
|
1317
1079
|
if (!payload.ath) {
|
|
@@ -1325,8 +1087,8 @@ async function verifyTokenDPoP(options) {
|
|
|
1325
1087
|
);
|
|
1326
1088
|
}
|
|
1327
1089
|
}
|
|
1328
|
-
const jwkThumbprint = await (0,
|
|
1329
|
-
hashAlgorithm:
|
|
1090
|
+
const jwkThumbprint = await (0, import_io_wallet_utils16.calculateJwkThumbprint)({
|
|
1091
|
+
hashAlgorithm: import_io_wallet_utils16.HashAlgorithm.Sha256,
|
|
1330
1092
|
hashCallback: options.callbacks.hash,
|
|
1331
1093
|
jwk: header.jwk
|
|
1332
1094
|
});
|
|
@@ -1336,7 +1098,7 @@ async function verifyTokenDPoP(options) {
|
|
|
1336
1098
|
);
|
|
1337
1099
|
}
|
|
1338
1100
|
try {
|
|
1339
|
-
(0,
|
|
1101
|
+
(0, import_io_wallet_utils16.verifyJwtIatOrThrow)({
|
|
1340
1102
|
iat: payload.iat,
|
|
1341
1103
|
now: options.now
|
|
1342
1104
|
});
|
|
@@ -1345,7 +1107,7 @@ async function verifyTokenDPoP(options) {
|
|
|
1345
1107
|
throw new Oauth2Error(`Invalid iat claim in dpop JWT: ${error.message}`);
|
|
1346
1108
|
}
|
|
1347
1109
|
}
|
|
1348
|
-
await (0,
|
|
1110
|
+
await (0, import_io_wallet_utils16.verifyJwt)({
|
|
1349
1111
|
compact: options.dpopJwt,
|
|
1350
1112
|
errorMessage: "dpop jwt verification failed",
|
|
1351
1113
|
header,
|
|
@@ -1411,36 +1173,37 @@ async function verifyAccessTokenRequest(options) {
|
|
|
1411
1173
|
}
|
|
1412
1174
|
|
|
1413
1175
|
// src/authorization-request/create-authorization-request.ts
|
|
1414
|
-
var
|
|
1176
|
+
var import_io_wallet_utils18 = require("@pagopa/io-wallet-utils");
|
|
1415
1177
|
|
|
1416
1178
|
// src/authorization-request/z-authorization-request.ts
|
|
1417
|
-
var
|
|
1418
|
-
var
|
|
1419
|
-
|
|
1420
|
-
|
|
1179
|
+
var import_io_wallet_utils17 = require("@pagopa/io-wallet-utils");
|
|
1180
|
+
var import_zod9 = __toESM(require("zod"));
|
|
1181
|
+
var zOpenidCredentialAuthorizationDetails = import_zod9.default.object({
|
|
1182
|
+
credential_configuration_id: import_zod9.default.string(),
|
|
1183
|
+
type: import_zod9.default.literal("openid_credential")
|
|
1421
1184
|
});
|
|
1422
|
-
var zItL2DocumentProofAuthorizationDetails =
|
|
1423
|
-
challenge_method:
|
|
1424
|
-
challenge_redirect_uri:
|
|
1425
|
-
idphinting:
|
|
1426
|
-
type:
|
|
1185
|
+
var zItL2DocumentProofAuthorizationDetails = import_zod9.default.object({
|
|
1186
|
+
challenge_method: import_zod9.default.literal("mrtd+ias"),
|
|
1187
|
+
challenge_redirect_uri: import_zod9.default.url(),
|
|
1188
|
+
idphinting: import_zod9.default.url(),
|
|
1189
|
+
type: import_zod9.default.literal("it_l2+document_proof")
|
|
1427
1190
|
});
|
|
1428
|
-
var zAuthorizationRequestBaseObject =
|
|
1429
|
-
authorization_details:
|
|
1430
|
-
|
|
1191
|
+
var zAuthorizationRequestBaseObject = import_zod9.default.looseObject({
|
|
1192
|
+
authorization_details: import_zod9.default.array(
|
|
1193
|
+
import_zod9.default.discriminatedUnion("type", [
|
|
1431
1194
|
zOpenidCredentialAuthorizationDetails,
|
|
1432
1195
|
zItL2DocumentProofAuthorizationDetails
|
|
1433
1196
|
])
|
|
1434
1197
|
).optional(),
|
|
1435
|
-
client_id:
|
|
1436
|
-
code_challenge:
|
|
1437
|
-
code_challenge_method:
|
|
1438
|
-
issuer_state:
|
|
1439
|
-
jti:
|
|
1440
|
-
redirect_uri:
|
|
1441
|
-
response_type:
|
|
1442
|
-
scope:
|
|
1443
|
-
state:
|
|
1198
|
+
client_id: import_zod9.default.string(),
|
|
1199
|
+
code_challenge: import_zod9.default.string(),
|
|
1200
|
+
code_challenge_method: import_zod9.default.string(),
|
|
1201
|
+
issuer_state: import_zod9.default.optional(import_zod9.default.string()),
|
|
1202
|
+
jti: import_zod9.default.string().max(import_io_wallet_utils17.MAX_JTI_LENGTH),
|
|
1203
|
+
redirect_uri: import_zod9.default.url(),
|
|
1204
|
+
response_type: import_zod9.default.string(),
|
|
1205
|
+
scope: import_zod9.default.string().optional(),
|
|
1206
|
+
state: import_zod9.default.string()
|
|
1444
1207
|
});
|
|
1445
1208
|
var zAuthorizationRequestBase = zAuthorizationRequestBaseObject.refine(
|
|
1446
1209
|
(data) => data.authorization_details !== void 0 || data.scope !== void 0,
|
|
@@ -1450,7 +1213,7 @@ var zAuthorizationRequestBase = zAuthorizationRequestBaseObject.refine(
|
|
|
1450
1213
|
}
|
|
1451
1214
|
);
|
|
1452
1215
|
var zAuthorizationRequestV1_0 = zAuthorizationRequestBaseObject.extend({
|
|
1453
|
-
response_mode:
|
|
1216
|
+
response_mode: import_zod9.default.string()
|
|
1454
1217
|
}).refine(
|
|
1455
1218
|
(data) => data.authorization_details !== void 0 || data.scope !== void 0,
|
|
1456
1219
|
{
|
|
@@ -1459,25 +1222,25 @@ var zAuthorizationRequestV1_0 = zAuthorizationRequestBaseObject.extend({
|
|
|
1459
1222
|
}
|
|
1460
1223
|
);
|
|
1461
1224
|
var zAuthorizationRequestV1_3 = zAuthorizationRequestBase;
|
|
1462
|
-
var zPushedAuthorizationRequestSigned =
|
|
1463
|
-
client_id:
|
|
1225
|
+
var zPushedAuthorizationRequestSigned = import_zod9.default.looseObject({
|
|
1226
|
+
client_id: import_zod9.default.string().describe(
|
|
1464
1227
|
"MUST be set to the thumbprint of the jwk value in the cnf parameter inside the Wallet Attestation."
|
|
1465
1228
|
),
|
|
1466
|
-
pkceCodeVerifier:
|
|
1229
|
+
pkceCodeVerifier: import_zod9.default.string().describe(
|
|
1467
1230
|
"Code verifier for PKCE. If not provided in CreatePushedAuthorizationRequestOptions, SDK will generate one."
|
|
1468
1231
|
),
|
|
1469
|
-
request:
|
|
1232
|
+
request: import_zod9.default.string().describe(
|
|
1470
1233
|
"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."
|
|
1471
1234
|
)
|
|
1472
1235
|
});
|
|
1473
|
-
var zPushedAuthorizationRequestUnsignedBase = (authorizationRequest) =>
|
|
1236
|
+
var zPushedAuthorizationRequestUnsignedBase = (authorizationRequest) => import_zod9.default.looseObject({
|
|
1474
1237
|
authorizationRequest: authorizationRequest.describe(
|
|
1475
1238
|
"The authorization request parameters as a plain object. Used when require_signed_request_object is false."
|
|
1476
1239
|
),
|
|
1477
|
-
client_id:
|
|
1240
|
+
client_id: import_zod9.default.string().describe(
|
|
1478
1241
|
"Thumbprint of the jwk value in the cnf parameter inside Wallet Attestation."
|
|
1479
1242
|
),
|
|
1480
|
-
pkceCodeVerifier:
|
|
1243
|
+
pkceCodeVerifier: import_zod9.default.string().describe(
|
|
1481
1244
|
"PKCE code verifier. Auto-generated if not provided in options."
|
|
1482
1245
|
)
|
|
1483
1246
|
});
|
|
@@ -1489,9 +1252,9 @@ function isPushedAuthorizationRequestSigned(par) {
|
|
|
1489
1252
|
function isPushedAuthorizationRequestUnsigned(par) {
|
|
1490
1253
|
return "authorizationRequest" in par;
|
|
1491
1254
|
}
|
|
1492
|
-
var zPushedAuthorizationResponse =
|
|
1493
|
-
expires_in:
|
|
1494
|
-
request_uri:
|
|
1255
|
+
var zPushedAuthorizationResponse = import_zod9.default.looseObject({
|
|
1256
|
+
expires_in: import_zod9.default.number().int(),
|
|
1257
|
+
request_uri: import_zod9.default.string()
|
|
1495
1258
|
});
|
|
1496
1259
|
|
|
1497
1260
|
// src/authorization-request/create-authorization-request.ts
|
|
@@ -1509,13 +1272,13 @@ async function createPushedAuthorizationRequest(options) {
|
|
|
1509
1272
|
code_challenge: pkce.codeChallenge,
|
|
1510
1273
|
code_challenge_method: pkce.codeChallengeMethod,
|
|
1511
1274
|
...options.issuerState !== void 0 ? { issuer_state: options.issuerState } : {},
|
|
1512
|
-
jti: options.jti ?? (0,
|
|
1275
|
+
jti: options.jti ?? (0, import_io_wallet_utils18.encodeToBase64Url)(
|
|
1513
1276
|
await options.callbacks.generateRandom(RANDOM_BYTES_SIZE)
|
|
1514
1277
|
),
|
|
1515
1278
|
redirect_uri: options.redirectUri,
|
|
1516
1279
|
response_type: "code",
|
|
1517
1280
|
scope: options.scope,
|
|
1518
|
-
state: options.state ?? (0,
|
|
1281
|
+
state: options.state ?? (0, import_io_wallet_utils18.encodeToBase64Url)(
|
|
1519
1282
|
await options.callbacks.generateRandom(RANDOM_BYTES_SIZE)
|
|
1520
1283
|
)
|
|
1521
1284
|
};
|
|
@@ -1532,7 +1295,7 @@ async function createPushedAuthorizationRequest(options) {
|
|
|
1532
1295
|
);
|
|
1533
1296
|
}
|
|
1534
1297
|
const iat = options.issuedAt ?? /* @__PURE__ */ new Date();
|
|
1535
|
-
const exp = options.expiresAt ?? (0,
|
|
1298
|
+
const exp = options.expiresAt ?? (0, import_io_wallet_utils18.addSecondsToDate)(iat, JWT_EXPIRY_SECONDS);
|
|
1536
1299
|
const requestJwt = await options.callbacks.signJwt(dpop.signer, {
|
|
1537
1300
|
header: {
|
|
1538
1301
|
alg: dpop.signer.alg,
|
|
@@ -1541,8 +1304,8 @@ async function createPushedAuthorizationRequest(options) {
|
|
|
1541
1304
|
},
|
|
1542
1305
|
payload: {
|
|
1543
1306
|
aud: options.audience,
|
|
1544
|
-
exp: (0,
|
|
1545
|
-
iat: (0,
|
|
1307
|
+
exp: (0, import_io_wallet_utils18.dateToSeconds)(exp),
|
|
1308
|
+
iat: (0, import_io_wallet_utils18.dateToSeconds)(iat),
|
|
1546
1309
|
iss: dpop.signer.publicJwk.kid,
|
|
1547
1310
|
...authorizationRequest
|
|
1548
1311
|
}
|
|
@@ -1560,27 +1323,27 @@ async function createPushedAuthorizationRequest(options) {
|
|
|
1560
1323
|
};
|
|
1561
1324
|
}
|
|
1562
1325
|
function parseAuthorizationRequestByVersion(options, baseAuthorizationRequest) {
|
|
1563
|
-
return (0,
|
|
1564
|
-
[
|
|
1326
|
+
return (0, import_io_wallet_utils18.dispatchByVersion)(options.config.itWalletSpecsVersion, {
|
|
1327
|
+
[import_io_wallet_utils18.ItWalletSpecsVersion.V1_0]: () => zAuthorizationRequestV1_0.parse({
|
|
1565
1328
|
...baseAuthorizationRequest,
|
|
1566
1329
|
response_mode: options.responseMode
|
|
1567
1330
|
}),
|
|
1568
|
-
[
|
|
1331
|
+
[import_io_wallet_utils18.ItWalletSpecsVersion.V1_3]: () => zAuthorizationRequestV1_3.parse(
|
|
1569
1332
|
baseAuthorizationRequest
|
|
1570
1333
|
),
|
|
1571
1334
|
// V1_4 reuses V1_3 authorization request schema — no breaking changes between versions.
|
|
1572
1335
|
// Verified against compare/1.3.3...1.4.1: authorization request parameters identical.
|
|
1573
|
-
[
|
|
1336
|
+
[import_io_wallet_utils18.ItWalletSpecsVersion.V1_4]: () => zAuthorizationRequestV1_3.parse(
|
|
1574
1337
|
baseAuthorizationRequest
|
|
1575
1338
|
)
|
|
1576
1339
|
});
|
|
1577
1340
|
}
|
|
1578
1341
|
|
|
1579
1342
|
// src/authorization-request/fetch-authorization-response.ts
|
|
1580
|
-
var
|
|
1343
|
+
var import_io_wallet_utils19 = require("@pagopa/io-wallet-utils");
|
|
1581
1344
|
async function fetchPushedAuthorizationResponse(options) {
|
|
1582
1345
|
try {
|
|
1583
|
-
const fetch = (0,
|
|
1346
|
+
const fetch = (0, import_io_wallet_utils19.createFetcher)(options.callbacks.fetch);
|
|
1584
1347
|
const body = isPushedAuthorizationRequestSigned(
|
|
1585
1348
|
options.pushedAuthorizationRequest
|
|
1586
1349
|
) ? new URLSearchParams({
|
|
@@ -1594,25 +1357,25 @@ async function fetchPushedAuthorizationResponse(options) {
|
|
|
1594
1357
|
{
|
|
1595
1358
|
body,
|
|
1596
1359
|
headers: {
|
|
1597
|
-
[
|
|
1598
|
-
[
|
|
1599
|
-
[
|
|
1360
|
+
[import_io_wallet_utils19.HEADERS.CONTENT_TYPE]: import_io_wallet_utils19.CONTENT_TYPES.FORM_URLENCODED,
|
|
1361
|
+
[import_io_wallet_utils19.HEADERS.OAUTH_CLIENT_ATTESTATION]: options.walletAttestation,
|
|
1362
|
+
[import_io_wallet_utils19.HEADERS.OAUTH_CLIENT_ATTESTATION_POP]: options.clientAttestationDPoP
|
|
1600
1363
|
},
|
|
1601
1364
|
method: "POST"
|
|
1602
1365
|
}
|
|
1603
1366
|
);
|
|
1604
|
-
await (0,
|
|
1367
|
+
await (0, import_io_wallet_utils19.hasStatusOrThrow)(201, import_io_wallet_utils19.UnexpectedStatusCodeError)(parResponse);
|
|
1605
1368
|
const parResponseJson = await parResponse.json();
|
|
1606
1369
|
const parsedParResponse = zPushedAuthorizationResponse.safeParse(parResponseJson);
|
|
1607
1370
|
if (!parsedParResponse.success) {
|
|
1608
|
-
throw new
|
|
1371
|
+
throw new import_io_wallet_utils19.ValidationError(
|
|
1609
1372
|
`Failed to parse pushed authorization response`,
|
|
1610
1373
|
parsedParResponse.error
|
|
1611
1374
|
);
|
|
1612
1375
|
}
|
|
1613
1376
|
return parsedParResponse.data;
|
|
1614
1377
|
} catch (error) {
|
|
1615
|
-
if (error instanceof
|
|
1378
|
+
if (error instanceof import_io_wallet_utils19.UnexpectedStatusCodeError || error instanceof import_io_wallet_utils19.ValidationError) {
|
|
1616
1379
|
throw error;
|
|
1617
1380
|
}
|
|
1618
1381
|
throw new PushedAuthorizationRequestError(
|
|
@@ -1658,22 +1421,22 @@ function parseAuthorizationRequest(options) {
|
|
|
1658
1421
|
}
|
|
1659
1422
|
|
|
1660
1423
|
// src/authorization-request/parse-pushed-authorization-request.ts
|
|
1661
|
-
var
|
|
1662
|
-
var
|
|
1424
|
+
var import_io_wallet_utils22 = require("@pagopa/io-wallet-utils");
|
|
1425
|
+
var import_zod11 = __toESM(require("zod"));
|
|
1663
1426
|
|
|
1664
1427
|
// src/jar/fetch-jar-request-object.ts
|
|
1665
|
-
var
|
|
1428
|
+
var import_io_wallet_utils20 = require("@pagopa/io-wallet-utils");
|
|
1666
1429
|
async function fetchJarRequestObject(options) {
|
|
1667
1430
|
const { fetch, requestUri } = options;
|
|
1668
1431
|
const JAR_ACCEPT_HEADER = [
|
|
1669
|
-
|
|
1432
|
+
import_io_wallet_utils20.ContentType.OAuthAuthorizationRequestJwt,
|
|
1670
1433
|
// Preferred: application/oauth-authz-req+jwt
|
|
1671
|
-
`${
|
|
1434
|
+
`${import_io_wallet_utils20.ContentType.Jwt};q=0.9`,
|
|
1672
1435
|
// Fallback: application/jwt
|
|
1673
1436
|
"text/plain"
|
|
1674
1437
|
// Final fallback: text/plain
|
|
1675
1438
|
].join(", ");
|
|
1676
|
-
const response = await (0,
|
|
1439
|
+
const response = await (0, import_io_wallet_utils20.createFetcher)(fetch)(requestUri, {
|
|
1677
1440
|
headers: {
|
|
1678
1441
|
Accept: JAR_ACCEPT_HEADER
|
|
1679
1442
|
},
|
|
@@ -1683,7 +1446,7 @@ async function fetchJarRequestObject(options) {
|
|
|
1683
1446
|
`Fetching request_object from request_uri '${requestUri}' failed`
|
|
1684
1447
|
);
|
|
1685
1448
|
});
|
|
1686
|
-
await (0,
|
|
1449
|
+
await (0, import_io_wallet_utils20.hasStatusOrThrow)(200, import_io_wallet_utils20.UnexpectedStatusCodeError)(response);
|
|
1687
1450
|
return await response.text();
|
|
1688
1451
|
}
|
|
1689
1452
|
|
|
@@ -1720,25 +1483,26 @@ async function parseJarRequest(options) {
|
|
|
1720
1483
|
}
|
|
1721
1484
|
|
|
1722
1485
|
// src/jar/z-jar.ts
|
|
1723
|
-
var
|
|
1724
|
-
var
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1486
|
+
var import_io_wallet_utils21 = require("@pagopa/io-wallet-utils");
|
|
1487
|
+
var import_zod10 = __toESM(require("zod"));
|
|
1488
|
+
var zJarAuthorizationRequest = import_zod10.default.looseObject({
|
|
1489
|
+
client_id: import_zod10.default.optional(import_zod10.default.string()),
|
|
1490
|
+
request: import_zod10.default.optional(import_zod10.default.string()),
|
|
1491
|
+
request_uri: import_zod10.default.url().optional()
|
|
1728
1492
|
});
|
|
1729
|
-
var zJarRequestObjectPayload =
|
|
1730
|
-
...zJwtPayload.shape,
|
|
1731
|
-
client_id:
|
|
1493
|
+
var zJarRequestObjectPayload = import_zod10.default.looseObject({
|
|
1494
|
+
...import_io_wallet_utils21.zJwtPayload.shape,
|
|
1495
|
+
client_id: import_zod10.default.string()
|
|
1732
1496
|
});
|
|
1733
|
-
var zSignedAuthorizationRequestJwtHeaderTyp =
|
|
1497
|
+
var zSignedAuthorizationRequestJwtHeaderTyp = import_zod10.default.literal(
|
|
1734
1498
|
"oauth-authz-req+jwt"
|
|
1735
1499
|
);
|
|
1736
|
-
var zJarRequestObjectHeader =
|
|
1737
|
-
...zJwtHeader.shape,
|
|
1500
|
+
var zJarRequestObjectHeader = import_zod10.default.looseObject({
|
|
1501
|
+
...import_io_wallet_utils21.zJwtHeader.shape,
|
|
1738
1502
|
typ: zSignedAuthorizationRequestJwtHeaderTyp
|
|
1739
1503
|
});
|
|
1740
1504
|
var signedAuthorizationRequestJwtHeaderTyp = zSignedAuthorizationRequestJwtHeaderTyp.value;
|
|
1741
|
-
var zJwtAuthorizationRequestJwtHeaderTyp =
|
|
1505
|
+
var zJwtAuthorizationRequestJwtHeaderTyp = import_zod10.default.literal("jwt");
|
|
1742
1506
|
var jwtAuthorizationRequestJwtHeaderTyp = zJwtAuthorizationRequestJwtHeaderTyp.value;
|
|
1743
1507
|
|
|
1744
1508
|
// src/authorization-request/parse-pushed-authorization-request.ts
|
|
@@ -1746,8 +1510,8 @@ async function parsePushedAuthorizationRequest(options) {
|
|
|
1746
1510
|
const authorizationRequestSchema = getAuthorizationRequestSchema(
|
|
1747
1511
|
options.config
|
|
1748
1512
|
);
|
|
1749
|
-
const parsed = (0,
|
|
1750
|
-
|
|
1513
|
+
const parsed = (0, import_io_wallet_utils22.parseWithErrorHandling)(
|
|
1514
|
+
import_zod11.default.union([authorizationRequestSchema, zJarAuthorizationRequest]),
|
|
1751
1515
|
options.authorizationRequest,
|
|
1752
1516
|
"Invalid authorization request. Could not parse authorization request or jar."
|
|
1753
1517
|
);
|
|
@@ -1758,7 +1522,7 @@ async function parsePushedAuthorizationRequest(options) {
|
|
|
1758
1522
|
callbacks: options.callbacks,
|
|
1759
1523
|
jarRequestParams: parsed
|
|
1760
1524
|
});
|
|
1761
|
-
const jwt = decodeJwt({
|
|
1525
|
+
const jwt = (0, import_io_wallet_utils22.decodeJwt)({
|
|
1762
1526
|
errorMessagePrefix: "Error decoding pushed authorization request JWT:",
|
|
1763
1527
|
jwt: parsedJar.authorizationRequestJwt
|
|
1764
1528
|
});
|
|
@@ -1768,7 +1532,7 @@ async function parsePushedAuthorizationRequest(options) {
|
|
|
1768
1532
|
if (!parsedAuthorizationRequest.success) {
|
|
1769
1533
|
throw new Oauth2Error(
|
|
1770
1534
|
`Invalid authorization request. Could not parse jar request payload.
|
|
1771
|
-
${(0,
|
|
1535
|
+
${(0, import_io_wallet_utils22.formatZodError)(parsedAuthorizationRequest.error)}`
|
|
1772
1536
|
);
|
|
1773
1537
|
}
|
|
1774
1538
|
authorizationRequestJwt = parsedJar.authorizationRequestJwt;
|
|
@@ -1779,7 +1543,7 @@ ${(0, import_io_wallet_utils15.formatZodError)(parsedAuthorizationRequest.error)
|
|
|
1779
1543
|
if (!parsedAuthorizationRequest.success) {
|
|
1780
1544
|
throw new Oauth2Error(
|
|
1781
1545
|
`Error occurred during validation of pushed authorization request.
|
|
1782
|
-
${(0,
|
|
1546
|
+
${(0, import_io_wallet_utils22.formatZodError)(parsedAuthorizationRequest.error)}`
|
|
1783
1547
|
);
|
|
1784
1548
|
}
|
|
1785
1549
|
}
|
|
@@ -1795,12 +1559,12 @@ ${(0, import_io_wallet_utils15.formatZodError)(parsedAuthorizationRequest.error)
|
|
|
1795
1559
|
};
|
|
1796
1560
|
}
|
|
1797
1561
|
function getAuthorizationRequestSchema(config) {
|
|
1798
|
-
return (0,
|
|
1799
|
-
[
|
|
1800
|
-
[
|
|
1562
|
+
return (0, import_io_wallet_utils22.dispatchByVersion)(config.itWalletSpecsVersion, {
|
|
1563
|
+
[import_io_wallet_utils22.ItWalletSpecsVersion.V1_0]: () => zAuthorizationRequestV1_0,
|
|
1564
|
+
[import_io_wallet_utils22.ItWalletSpecsVersion.V1_3]: () => zAuthorizationRequestV1_3,
|
|
1801
1565
|
// V1_4 reuses V1_3 PAR schema — no breaking changes between versions.
|
|
1802
1566
|
// Verified against compare/1.3.3...1.4.1: authorization request parameters identical.
|
|
1803
|
-
[
|
|
1567
|
+
[import_io_wallet_utils22.ItWalletSpecsVersion.V1_4]: () => zAuthorizationRequestV1_3
|
|
1804
1568
|
});
|
|
1805
1569
|
}
|
|
1806
1570
|
|
|
@@ -1848,18 +1612,20 @@ async function verifyAuthorizationRequestDpop(options, request, callbacks, now)
|
|
|
1848
1612
|
};
|
|
1849
1613
|
}
|
|
1850
1614
|
|
|
1615
|
+
// src/authorization-request/verify-pushed-authorization-request.ts
|
|
1616
|
+
var import_io_wallet_utils24 = require("@pagopa/io-wallet-utils");
|
|
1617
|
+
|
|
1851
1618
|
// src/jar/verify-jar-request.ts
|
|
1852
|
-
var
|
|
1853
|
-
var import_io_wallet_utils16 = require("@pagopa/io-wallet-utils");
|
|
1619
|
+
var import_io_wallet_utils23 = require("@pagopa/io-wallet-utils");
|
|
1854
1620
|
async function verifyJarRequest(options) {
|
|
1855
1621
|
const { authorizationRequestJwt, callbacks, jarRequestParams, jwtSigner } = options;
|
|
1856
|
-
const requestObjectIsEncrypted =
|
|
1622
|
+
const requestObjectIsEncrypted = import_io_wallet_utils23.zCompactJwe.safeParse(
|
|
1857
1623
|
authorizationRequestJwt
|
|
1858
1624
|
).success;
|
|
1859
1625
|
if (requestObjectIsEncrypted) {
|
|
1860
1626
|
throw new Oauth2Error("Encrypted JWE request objects are not supported.");
|
|
1861
1627
|
}
|
|
1862
|
-
const requestIsSigned =
|
|
1628
|
+
const requestIsSigned = import_io_wallet_utils23.zCompactJwt.safeParse(
|
|
1863
1629
|
authorizationRequestJwt
|
|
1864
1630
|
).success;
|
|
1865
1631
|
if (!requestIsSigned) {
|
|
@@ -1912,15 +1678,15 @@ async function verifyJarRequest(options) {
|
|
|
1912
1678
|
}
|
|
1913
1679
|
async function verifyJarRequestObject(options) {
|
|
1914
1680
|
const { authorizationRequestJwt, callbacks, jwtSigner } = options;
|
|
1915
|
-
const jwt = decodeJwt({
|
|
1681
|
+
const jwt = (0, import_io_wallet_utils23.decodeJwt)({
|
|
1916
1682
|
errorMessagePrefix: "Error decoding JAR authorization request JWT:",
|
|
1917
1683
|
jwt: authorizationRequestJwt
|
|
1918
1684
|
});
|
|
1919
|
-
const authorizationRequestPayload = (0,
|
|
1685
|
+
const authorizationRequestPayload = (0, import_io_wallet_utils23.parseWithErrorHandling)(
|
|
1920
1686
|
zJarRequestObjectPayload,
|
|
1921
1687
|
jwt.payload
|
|
1922
1688
|
);
|
|
1923
|
-
const { signer } = await (0,
|
|
1689
|
+
const { signer } = await (0, import_io_wallet_utils23.verifyJwt)({
|
|
1924
1690
|
compact: authorizationRequestJwt,
|
|
1925
1691
|
header: jwt.header,
|
|
1926
1692
|
payload: authorizationRequestPayload,
|
|
@@ -1953,7 +1719,7 @@ async function verifyPushedAuthorizationRequest(options) {
|
|
|
1953
1719
|
let jar;
|
|
1954
1720
|
if (options.authorizationRequestJwt) {
|
|
1955
1721
|
if (requireSigned) {
|
|
1956
|
-
const decoded = decodeJwt({
|
|
1722
|
+
const decoded = (0, import_io_wallet_utils24.decodeJwt)({
|
|
1957
1723
|
errorMessagePrefix: "Error decoding pushed authorization request JWT:",
|
|
1958
1724
|
jwt: options.authorizationRequestJwt.jwt
|
|
1959
1725
|
});
|
|
@@ -2042,10 +1808,10 @@ function clientAuthenticationWalletAttestationJwt(options) {
|
|
|
2042
1808
|
}
|
|
2043
1809
|
|
|
2044
1810
|
// src/client-attestation/v1.0/create-wallet-attestation-jwt.ts
|
|
2045
|
-
var
|
|
1811
|
+
var import_io_wallet_utils26 = require("@pagopa/io-wallet-utils");
|
|
2046
1812
|
|
|
2047
1813
|
// src/client-attestation/jwk-thumbprint.ts
|
|
2048
|
-
var
|
|
1814
|
+
var import_io_wallet_utils25 = require("@pagopa/io-wallet-utils");
|
|
2049
1815
|
var SUPPORTED_KTY = ["RSA", "EC"];
|
|
2050
1816
|
var calculateDpopJwkThumbprint = (options) => {
|
|
2051
1817
|
if (!SUPPORTED_KTY.includes(
|
|
@@ -2055,8 +1821,8 @@ var calculateDpopJwkThumbprint = (options) => {
|
|
|
2055
1821
|
`Unsupported JWK key type "${options.dpopJwkPublic.kty}" for thumbprint computation. Supported types: ${SUPPORTED_KTY.join(", ")}.`
|
|
2056
1822
|
);
|
|
2057
1823
|
}
|
|
2058
|
-
return (0,
|
|
2059
|
-
hashAlgorithm:
|
|
1824
|
+
return (0, import_io_wallet_utils25.calculateJwkThumbprint)({
|
|
1825
|
+
hashAlgorithm: import_io_wallet_utils25.HashAlgorithm.Sha256,
|
|
2060
1826
|
hashCallback: options.callbacks.hash,
|
|
2061
1827
|
jwk: options.dpopJwkPublic
|
|
2062
1828
|
});
|
|
@@ -2067,12 +1833,12 @@ var createWalletAttestationJwt = async (options) => {
|
|
|
2067
1833
|
try {
|
|
2068
1834
|
const { signJwt } = options.callbacks;
|
|
2069
1835
|
const iat = /* @__PURE__ */ new Date();
|
|
2070
|
-
const exp = options.expiresAt ?? (0,
|
|
1836
|
+
const exp = options.expiresAt ?? (0, import_io_wallet_utils26.addSecondsToDate)(iat, 3600);
|
|
2071
1837
|
const dpopJwkThumbprint = await calculateDpopJwkThumbprint(options);
|
|
2072
1838
|
const payload = {
|
|
2073
1839
|
cnf: { jwk: options.dpopJwkPublic },
|
|
2074
|
-
exp: (0,
|
|
2075
|
-
iat: (0,
|
|
1840
|
+
exp: (0, import_io_wallet_utils26.dateToSeconds)(exp),
|
|
1841
|
+
iat: (0, import_io_wallet_utils26.dateToSeconds)(iat),
|
|
2076
1842
|
iss: options.issuer,
|
|
2077
1843
|
sub: dpopJwkThumbprint,
|
|
2078
1844
|
...options.walletLink && { wallet_link: options.walletLink },
|
|
@@ -2089,7 +1855,7 @@ var createWalletAttestationJwt = async (options) => {
|
|
|
2089
1855
|
header,
|
|
2090
1856
|
payload
|
|
2091
1857
|
});
|
|
2092
|
-
decodeJwt({
|
|
1858
|
+
(0, import_io_wallet_utils26.decodeJwt)({
|
|
2093
1859
|
errorMessagePrefix: "Error decoding wallet attestation JWT:",
|
|
2094
1860
|
headerSchema: zWalletAttestationJwtHeaderV1_0,
|
|
2095
1861
|
jwt: result.jwt,
|
|
@@ -2097,7 +1863,7 @@ var createWalletAttestationJwt = async (options) => {
|
|
|
2097
1863
|
});
|
|
2098
1864
|
return result.jwt;
|
|
2099
1865
|
} catch (error) {
|
|
2100
|
-
if (error instanceof
|
|
1866
|
+
if (error instanceof import_io_wallet_utils26.ValidationError) {
|
|
2101
1867
|
throw error;
|
|
2102
1868
|
}
|
|
2103
1869
|
throw new ClientAttestationError(
|
|
@@ -2107,23 +1873,23 @@ var createWalletAttestationJwt = async (options) => {
|
|
|
2107
1873
|
};
|
|
2108
1874
|
|
|
2109
1875
|
// src/client-attestation/v1.3/create-wallet-attestation-jwt.ts
|
|
2110
|
-
var
|
|
1876
|
+
var import_io_wallet_utils27 = require("@pagopa/io-wallet-utils");
|
|
2111
1877
|
var createWalletAttestationJwt2 = async (options) => {
|
|
2112
1878
|
try {
|
|
2113
1879
|
const { signJwt } = options.callbacks;
|
|
2114
1880
|
const iat = /* @__PURE__ */ new Date();
|
|
2115
|
-
const exp = options.expiresAt ?? (0,
|
|
1881
|
+
const exp = options.expiresAt ?? (0, import_io_wallet_utils27.addSecondsToDate)(iat, 3600);
|
|
2116
1882
|
if (options.nbf && options.nbf >= exp) {
|
|
2117
|
-
throw new
|
|
1883
|
+
throw new import_io_wallet_utils27.ValidationError("nbf must be before exp");
|
|
2118
1884
|
}
|
|
2119
1885
|
const dpopJwkThumbprint = await calculateDpopJwkThumbprint(options);
|
|
2120
1886
|
const payload = {
|
|
2121
1887
|
cnf: { jwk: options.dpopJwkPublic },
|
|
2122
|
-
exp: (0,
|
|
2123
|
-
iat: (0,
|
|
1888
|
+
exp: (0, import_io_wallet_utils27.dateToSeconds)(exp),
|
|
1889
|
+
iat: (0, import_io_wallet_utils27.dateToSeconds)(iat),
|
|
2124
1890
|
iss: options.issuer,
|
|
2125
1891
|
sub: dpopJwkThumbprint,
|
|
2126
|
-
...options.nbf && { nbf: (0,
|
|
1892
|
+
...options.nbf && { nbf: (0, import_io_wallet_utils27.dateToSeconds)(options.nbf) },
|
|
2127
1893
|
...options.status && { status: options.status },
|
|
2128
1894
|
...options.walletLink && { wallet_link: options.walletLink },
|
|
2129
1895
|
...options.walletName && { wallet_name: options.walletName }
|
|
@@ -2142,7 +1908,7 @@ var createWalletAttestationJwt2 = async (options) => {
|
|
|
2142
1908
|
header,
|
|
2143
1909
|
payload
|
|
2144
1910
|
});
|
|
2145
|
-
decodeJwt({
|
|
1911
|
+
(0, import_io_wallet_utils27.decodeJwt)({
|
|
2146
1912
|
errorMessagePrefix: "Error decoding wallet attestation JWT:",
|
|
2147
1913
|
headerSchema: zWalletAttestationJwtHeaderV1_3,
|
|
2148
1914
|
jwt: result.jwt,
|
|
@@ -2150,7 +1916,7 @@ var createWalletAttestationJwt2 = async (options) => {
|
|
|
2150
1916
|
});
|
|
2151
1917
|
return result.jwt;
|
|
2152
1918
|
} catch (error) {
|
|
2153
|
-
if (error instanceof
|
|
1919
|
+
if (error instanceof import_io_wallet_utils27.ValidationError) {
|
|
2154
1920
|
throw error;
|
|
2155
1921
|
}
|
|
2156
1922
|
throw new ClientAttestationError(
|
|
@@ -2160,33 +1926,33 @@ var createWalletAttestationJwt2 = async (options) => {
|
|
|
2160
1926
|
};
|
|
2161
1927
|
|
|
2162
1928
|
// src/client-attestation/v1.4/create-wallet-attestation-jwt.ts
|
|
2163
|
-
var
|
|
1929
|
+
var import_io_wallet_utils28 = require("@pagopa/io-wallet-utils");
|
|
2164
1930
|
var DEFAULT_EXPIRATION_SECONDS = 3600;
|
|
2165
1931
|
var MAX_EXPIRATION_SECONDS = 86400;
|
|
2166
1932
|
var createWalletAttestationJwt3 = async (options) => {
|
|
2167
1933
|
try {
|
|
2168
1934
|
const { signJwt } = options.callbacks;
|
|
2169
1935
|
const iat = /* @__PURE__ */ new Date();
|
|
2170
|
-
const exp = options.expiresAt ?? (0,
|
|
1936
|
+
const exp = options.expiresAt ?? (0, import_io_wallet_utils28.addSecondsToDate)(iat, DEFAULT_EXPIRATION_SECONDS);
|
|
2171
1937
|
if (exp <= iat) {
|
|
2172
|
-
throw new
|
|
1938
|
+
throw new import_io_wallet_utils28.ValidationError("exp must be after iat");
|
|
2173
1939
|
}
|
|
2174
|
-
if (exp > (0,
|
|
2175
|
-
throw new
|
|
1940
|
+
if (exp > (0, import_io_wallet_utils28.addSecondsToDate)(iat, MAX_EXPIRATION_SECONDS)) {
|
|
1941
|
+
throw new import_io_wallet_utils28.ValidationError("exp must not be more than 24 hours after iat");
|
|
2176
1942
|
}
|
|
2177
1943
|
if (options.nbf && options.nbf >= exp) {
|
|
2178
|
-
throw new
|
|
1944
|
+
throw new import_io_wallet_utils28.ValidationError("nbf must be before exp");
|
|
2179
1945
|
}
|
|
2180
1946
|
const dpopJwkThumbprint = await calculateDpopJwkThumbprint(options);
|
|
2181
1947
|
const payload = {
|
|
2182
1948
|
cnf: { jwk: options.dpopJwkPublic },
|
|
2183
|
-
exp: (0,
|
|
2184
|
-
iat: (0,
|
|
1949
|
+
exp: (0, import_io_wallet_utils28.dateToSeconds)(exp),
|
|
1950
|
+
iat: (0, import_io_wallet_utils28.dateToSeconds)(iat),
|
|
2185
1951
|
iss: options.issuer,
|
|
2186
1952
|
sub: dpopJwkThumbprint,
|
|
2187
1953
|
wallet_link: options.walletLink,
|
|
2188
1954
|
wallet_name: options.walletName,
|
|
2189
|
-
...options.nbf && { nbf: (0,
|
|
1955
|
+
...options.nbf && { nbf: (0, import_io_wallet_utils28.dateToSeconds)(options.nbf) }
|
|
2190
1956
|
};
|
|
2191
1957
|
const header = {
|
|
2192
1958
|
alg: options.signer.alg,
|
|
@@ -2201,7 +1967,7 @@ var createWalletAttestationJwt3 = async (options) => {
|
|
|
2201
1967
|
header,
|
|
2202
1968
|
payload
|
|
2203
1969
|
});
|
|
2204
|
-
decodeJwt({
|
|
1970
|
+
(0, import_io_wallet_utils28.decodeJwt)({
|
|
2205
1971
|
errorMessagePrefix: "Error decoding wallet attestation JWT:",
|
|
2206
1972
|
headerSchema: zWalletAttestationJwtHeaderV1_4,
|
|
2207
1973
|
jwt: result.jwt,
|
|
@@ -2209,7 +1975,7 @@ var createWalletAttestationJwt3 = async (options) => {
|
|
|
2209
1975
|
});
|
|
2210
1976
|
return result.jwt;
|
|
2211
1977
|
} catch (error) {
|
|
2212
|
-
if (error instanceof
|
|
1978
|
+
if (error instanceof import_io_wallet_utils28.ValidationError) {
|
|
2213
1979
|
throw error;
|
|
2214
1980
|
}
|
|
2215
1981
|
throw new ClientAttestationError(
|
|
@@ -2218,17 +1984,8 @@ var createWalletAttestationJwt3 = async (options) => {
|
|
|
2218
1984
|
}
|
|
2219
1985
|
};
|
|
2220
1986
|
|
|
2221
|
-
// src/common/jwt/z-jwe.ts
|
|
2222
|
-
var import_zod15 = require("zod");
|
|
2223
|
-
var zCompactJwe2 = import_zod15.z.string().regex(
|
|
2224
|
-
/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/,
|
|
2225
|
-
{
|
|
2226
|
-
message: "Not a valid compact jwe"
|
|
2227
|
-
}
|
|
2228
|
-
);
|
|
2229
|
-
|
|
2230
1987
|
// src/jar/create-jar-request.ts
|
|
2231
|
-
var
|
|
1988
|
+
var import_io_wallet_utils29 = require("@pagopa/io-wallet-utils");
|
|
2232
1989
|
async function createJarRequest(options) {
|
|
2233
1990
|
const {
|
|
2234
1991
|
authorizationRequestHeader,
|
|
@@ -2246,8 +2003,8 @@ async function createJarRequest(options) {
|
|
|
2246
2003
|
payload: {
|
|
2247
2004
|
...options.additionalJwtPayload,
|
|
2248
2005
|
...authorizationRequestPayload,
|
|
2249
|
-
exp: (0,
|
|
2250
|
-
iat: (0,
|
|
2006
|
+
exp: (0, import_io_wallet_utils29.dateToSeconds)((0, import_io_wallet_utils29.addSecondsToDate)(now, options.expiresInSeconds)),
|
|
2007
|
+
iat: (0, import_io_wallet_utils29.dateToSeconds)(now)
|
|
2251
2008
|
}
|
|
2252
2009
|
});
|
|
2253
2010
|
authorizationRequestJwt = jwt;
|
|
@@ -2275,6 +2032,7 @@ async function createJarRequest(options) {
|
|
|
2275
2032
|
}
|
|
2276
2033
|
|
|
2277
2034
|
// src/jarm-form-post-jwt.ts
|
|
2035
|
+
var import_io_wallet_utils30 = require("@pagopa/io-wallet-utils");
|
|
2278
2036
|
var getJwtFromFormPost = async (options) => {
|
|
2279
2037
|
const inputRegex = /<input[^<>]*>/gi;
|
|
2280
2038
|
const nameRegex = /name="response"/gi;
|
|
@@ -2289,7 +2047,7 @@ var getJwtFromFormPost = async (options) => {
|
|
|
2289
2047
|
const responseJwt = matchValue[1];
|
|
2290
2048
|
if (responseJwt) {
|
|
2291
2049
|
const jwt = responseJwt.replace(lineExpressionRegex, "");
|
|
2292
|
-
const decodedJwt = decodeJwt({
|
|
2050
|
+
const decodedJwt = (0, import_io_wallet_utils30.decodeJwt)({
|
|
2293
2051
|
errorMessagePrefix: "Error decoding JARM form post JWT:",
|
|
2294
2052
|
jwt,
|
|
2295
2053
|
payloadSchema: options.schema
|
|
@@ -2311,73 +2069,73 @@ var getJwtFromFormPost = async (options) => {
|
|
|
2311
2069
|
};
|
|
2312
2070
|
|
|
2313
2071
|
// src/mrtd-pop/create-mrtd-validation-jwt.ts
|
|
2314
|
-
var
|
|
2072
|
+
var import_io_wallet_utils31 = require("@pagopa/io-wallet-utils");
|
|
2315
2073
|
|
|
2316
2074
|
// src/mrtd-pop/z-mrtd-pop.ts
|
|
2317
|
-
var
|
|
2318
|
-
var zMrtdChallengeJwtHeader =
|
|
2319
|
-
alg:
|
|
2320
|
-
kid:
|
|
2321
|
-
typ:
|
|
2075
|
+
var import_zod12 = __toESM(require("zod"));
|
|
2076
|
+
var zMrtdChallengeJwtHeader = import_zod12.default.looseObject({
|
|
2077
|
+
alg: import_zod12.default.string(),
|
|
2078
|
+
kid: import_zod12.default.string(),
|
|
2079
|
+
typ: import_zod12.default.literal("mrtd-ias+jwt")
|
|
2322
2080
|
});
|
|
2323
|
-
var zMrtdChallengeJwtPayload =
|
|
2324
|
-
aud:
|
|
2325
|
-
exp:
|
|
2326
|
-
htm:
|
|
2327
|
-
htu:
|
|
2328
|
-
iat:
|
|
2329
|
-
iss:
|
|
2330
|
-
mrtd_auth_session:
|
|
2331
|
-
mrtd_pop_jwt_nonce:
|
|
2332
|
-
state:
|
|
2333
|
-
status:
|
|
2334
|
-
type:
|
|
2081
|
+
var zMrtdChallengeJwtPayload = import_zod12.default.looseObject({
|
|
2082
|
+
aud: import_zod12.default.string(),
|
|
2083
|
+
exp: import_zod12.default.number(),
|
|
2084
|
+
htm: import_zod12.default.literal("POST"),
|
|
2085
|
+
htu: import_zod12.default.url(),
|
|
2086
|
+
iat: import_zod12.default.number(),
|
|
2087
|
+
iss: import_zod12.default.string(),
|
|
2088
|
+
mrtd_auth_session: import_zod12.default.string(),
|
|
2089
|
+
mrtd_pop_jwt_nonce: import_zod12.default.string(),
|
|
2090
|
+
state: import_zod12.default.string(),
|
|
2091
|
+
status: import_zod12.default.literal("require_interaction"),
|
|
2092
|
+
type: import_zod12.default.literal("mrtd+ias")
|
|
2335
2093
|
});
|
|
2336
|
-
var zMrtdPopInitResponseJwtHeader =
|
|
2337
|
-
alg:
|
|
2338
|
-
kid:
|
|
2339
|
-
typ:
|
|
2094
|
+
var zMrtdPopInitResponseJwtHeader = import_zod12.default.looseObject({
|
|
2095
|
+
alg: import_zod12.default.string(),
|
|
2096
|
+
kid: import_zod12.default.string(),
|
|
2097
|
+
typ: import_zod12.default.literal("mrtd-ias-pop+jwt")
|
|
2340
2098
|
});
|
|
2341
|
-
var zMrtdPopInitResponseJwtPayload =
|
|
2342
|
-
aud:
|
|
2343
|
-
challenge:
|
|
2344
|
-
exp:
|
|
2345
|
-
htm:
|
|
2346
|
-
htu:
|
|
2347
|
-
iat:
|
|
2348
|
-
iss:
|
|
2349
|
-
mrtd_pop_nonce:
|
|
2350
|
-
mrz:
|
|
2099
|
+
var zMrtdPopInitResponseJwtPayload = import_zod12.default.looseObject({
|
|
2100
|
+
aud: import_zod12.default.string(),
|
|
2101
|
+
challenge: import_zod12.default.string(),
|
|
2102
|
+
exp: import_zod12.default.number(),
|
|
2103
|
+
htm: import_zod12.default.literal("POST"),
|
|
2104
|
+
htu: import_zod12.default.url(),
|
|
2105
|
+
iat: import_zod12.default.number(),
|
|
2106
|
+
iss: import_zod12.default.string(),
|
|
2107
|
+
mrtd_pop_nonce: import_zod12.default.string(),
|
|
2108
|
+
mrz: import_zod12.default.string().optional()
|
|
2351
2109
|
});
|
|
2352
|
-
var zMrtdData =
|
|
2353
|
-
dg1:
|
|
2354
|
-
dg11:
|
|
2355
|
-
sod_mrtd:
|
|
2110
|
+
var zMrtdData = import_zod12.default.looseObject({
|
|
2111
|
+
dg1: import_zod12.default.string(),
|
|
2112
|
+
dg11: import_zod12.default.string(),
|
|
2113
|
+
sod_mrtd: import_zod12.default.string()
|
|
2356
2114
|
});
|
|
2357
|
-
var zIasData =
|
|
2358
|
-
challenge_signed:
|
|
2359
|
-
ias_pk:
|
|
2360
|
-
sod_ias:
|
|
2115
|
+
var zIasData = import_zod12.default.looseObject({
|
|
2116
|
+
challenge_signed: import_zod12.default.string(),
|
|
2117
|
+
ias_pk: import_zod12.default.string(),
|
|
2118
|
+
sod_ias: import_zod12.default.string()
|
|
2361
2119
|
});
|
|
2362
|
-
var zMrtdValidationJwtHeader =
|
|
2363
|
-
alg:
|
|
2364
|
-
kid:
|
|
2365
|
-
typ:
|
|
2120
|
+
var zMrtdValidationJwtHeader = import_zod12.default.looseObject({
|
|
2121
|
+
alg: import_zod12.default.string(),
|
|
2122
|
+
kid: import_zod12.default.string(),
|
|
2123
|
+
typ: import_zod12.default.literal("mrtd-ias+jwt")
|
|
2366
2124
|
});
|
|
2367
|
-
var zMrtdValidationJwtPayload =
|
|
2368
|
-
aud:
|
|
2369
|
-
document_type:
|
|
2370
|
-
exp:
|
|
2125
|
+
var zMrtdValidationJwtPayload = import_zod12.default.looseObject({
|
|
2126
|
+
aud: import_zod12.default.string(),
|
|
2127
|
+
document_type: import_zod12.default.literal("cie"),
|
|
2128
|
+
exp: import_zod12.default.number(),
|
|
2371
2129
|
ias: zIasData,
|
|
2372
|
-
iat:
|
|
2373
|
-
iss:
|
|
2130
|
+
iat: import_zod12.default.number(),
|
|
2131
|
+
iss: import_zod12.default.string(),
|
|
2374
2132
|
mrtd: zMrtdData
|
|
2375
2133
|
});
|
|
2376
|
-
var zMrtdPopVerifyResponse =
|
|
2377
|
-
mrtd_val_pop_nonce:
|
|
2378
|
-
redirect_uri:
|
|
2379
|
-
status:
|
|
2380
|
-
type:
|
|
2134
|
+
var zMrtdPopVerifyResponse = import_zod12.default.looseObject({
|
|
2135
|
+
mrtd_val_pop_nonce: import_zod12.default.string(),
|
|
2136
|
+
redirect_uri: import_zod12.default.url(),
|
|
2137
|
+
status: import_zod12.default.literal("require_interaction"),
|
|
2138
|
+
type: import_zod12.default.literal("redirect_to_web")
|
|
2381
2139
|
});
|
|
2382
2140
|
|
|
2383
2141
|
// src/mrtd-pop/create-mrtd-validation-jwt.ts
|
|
@@ -2388,13 +2146,13 @@ async function createMrtdValidationJwt(options) {
|
|
|
2388
2146
|
if (!kid) {
|
|
2389
2147
|
throw new MrtdPopError("Signer must have a publicJwk.kid property");
|
|
2390
2148
|
}
|
|
2391
|
-
const iat = (0,
|
|
2392
|
-
const header = (0,
|
|
2149
|
+
const iat = (0, import_io_wallet_utils31.dateToSeconds)(options.issuedAt);
|
|
2150
|
+
const header = (0, import_io_wallet_utils31.parseWithErrorHandling)(zMrtdValidationJwtHeader, {
|
|
2393
2151
|
alg: options.signer.alg,
|
|
2394
2152
|
kid,
|
|
2395
2153
|
typ: "mrtd-ias+jwt"
|
|
2396
2154
|
});
|
|
2397
|
-
const payload = (0,
|
|
2155
|
+
const payload = (0, import_io_wallet_utils31.parseWithErrorHandling)(zMrtdValidationJwtPayload, {
|
|
2398
2156
|
aud: options.audience,
|
|
2399
2157
|
document_type: "cie",
|
|
2400
2158
|
exp: iat + JWT_EXPIRY_SECONDS2,
|
|
@@ -2427,37 +2185,36 @@ async function createMrtdValidationJwt(options) {
|
|
|
2427
2185
|
}
|
|
2428
2186
|
|
|
2429
2187
|
// src/mrtd-pop/fetch-mrtd-pop-init.ts
|
|
2430
|
-
var
|
|
2431
|
-
var import_io_wallet_utils22 = require("@pagopa/io-wallet-utils");
|
|
2188
|
+
var import_io_wallet_utils32 = require("@pagopa/io-wallet-utils");
|
|
2432
2189
|
async function fetchMrtdPopInit(options) {
|
|
2433
2190
|
try {
|
|
2434
|
-
const fetch = (0,
|
|
2191
|
+
const fetch = (0, import_io_wallet_utils32.createFetcher)(options.callbacks.fetch);
|
|
2435
2192
|
const response = await fetch(options.popInitEndpoint, {
|
|
2436
2193
|
body: JSON.stringify({
|
|
2437
2194
|
mrtd_auth_session: options.mrtdAuthSession,
|
|
2438
2195
|
mrtd_pop_jwt_nonce: options.mrtdPopJwtNonce
|
|
2439
2196
|
}),
|
|
2440
2197
|
headers: {
|
|
2441
|
-
[
|
|
2442
|
-
[
|
|
2443
|
-
[
|
|
2198
|
+
[import_io_wallet_utils32.HEADERS.CONTENT_TYPE]: import_io_wallet_utils32.CONTENT_TYPES.JSON,
|
|
2199
|
+
[import_io_wallet_utils32.HEADERS.OAUTH_CLIENT_ATTESTATION]: options.walletAttestation,
|
|
2200
|
+
[import_io_wallet_utils32.HEADERS.OAUTH_CLIENT_ATTESTATION_POP]: options.clientAttestationDPoP
|
|
2444
2201
|
},
|
|
2445
2202
|
method: "POST"
|
|
2446
2203
|
});
|
|
2447
|
-
await (0,
|
|
2204
|
+
await (0, import_io_wallet_utils32.hasStatusOrThrow)(202, import_io_wallet_utils32.UnexpectedStatusCodeError)(response);
|
|
2448
2205
|
const responseJwt = await response.text();
|
|
2449
|
-
const jwt = decodeJwt({
|
|
2206
|
+
const jwt = (0, import_io_wallet_utils32.decodeJwt)({
|
|
2450
2207
|
errorMessagePrefix: "Error decoding MRTD PoP init response JWT:",
|
|
2451
2208
|
headerSchema: zMrtdPopInitResponseJwtHeader,
|
|
2452
2209
|
jwt: responseJwt,
|
|
2453
2210
|
payloadSchema: zMrtdPopInitResponseJwtPayload
|
|
2454
2211
|
});
|
|
2455
|
-
const { signer } = await (0,
|
|
2212
|
+
const { signer } = await (0, import_io_wallet_utils32.verifyJwt)({
|
|
2456
2213
|
compact: responseJwt,
|
|
2457
2214
|
errorMessage: "Error verifying MRTD PoP init response JWT",
|
|
2458
2215
|
header: jwt.header,
|
|
2459
2216
|
payload: jwt.payload,
|
|
2460
|
-
signer: options.signer ?? (0,
|
|
2217
|
+
signer: options.signer ?? (0, import_io_wallet_utils32.jwtSignerFromJwt)({ header: jwt.header, payload: jwt.payload }),
|
|
2461
2218
|
verifyJwtCallback: options.callbacks.verifyJwt
|
|
2462
2219
|
});
|
|
2463
2220
|
return {
|
|
@@ -2468,7 +2225,7 @@ async function fetchMrtdPopInit(options) {
|
|
|
2468
2225
|
signer
|
|
2469
2226
|
};
|
|
2470
2227
|
} catch (error) {
|
|
2471
|
-
if (error instanceof
|
|
2228
|
+
if (error instanceof import_io_wallet_utils32.UnexpectedStatusCodeError || error instanceof import_io_wallet_utils32.ValidationError) {
|
|
2472
2229
|
throw error;
|
|
2473
2230
|
}
|
|
2474
2231
|
throw new MrtdPopError(
|
|
@@ -2478,10 +2235,10 @@ async function fetchMrtdPopInit(options) {
|
|
|
2478
2235
|
}
|
|
2479
2236
|
|
|
2480
2237
|
// src/mrtd-pop/fetch-mrtd-pop-verify.ts
|
|
2481
|
-
var
|
|
2238
|
+
var import_io_wallet_utils33 = require("@pagopa/io-wallet-utils");
|
|
2482
2239
|
async function fetchMrtdPopVerify(options) {
|
|
2483
2240
|
try {
|
|
2484
|
-
const fetch = (0,
|
|
2241
|
+
const fetch = (0, import_io_wallet_utils33.createFetcher)(options.callbacks.fetch);
|
|
2485
2242
|
const response = await fetch(options.popVerifyEndpoint, {
|
|
2486
2243
|
body: JSON.stringify({
|
|
2487
2244
|
mrtd_auth_session: options.mrtdAuthSession,
|
|
@@ -2489,14 +2246,14 @@ async function fetchMrtdPopVerify(options) {
|
|
|
2489
2246
|
mrtd_validation_jwt: options.mrtdValidationJwt
|
|
2490
2247
|
}),
|
|
2491
2248
|
headers: {
|
|
2492
|
-
[
|
|
2493
|
-
[
|
|
2494
|
-
[
|
|
2249
|
+
[import_io_wallet_utils33.HEADERS.CONTENT_TYPE]: import_io_wallet_utils33.CONTENT_TYPES.JSON,
|
|
2250
|
+
[import_io_wallet_utils33.HEADERS.OAUTH_CLIENT_ATTESTATION]: options.walletAttestation,
|
|
2251
|
+
[import_io_wallet_utils33.HEADERS.OAUTH_CLIENT_ATTESTATION_POP]: options.clientAttestationDPoP
|
|
2495
2252
|
},
|
|
2496
2253
|
method: "POST"
|
|
2497
2254
|
});
|
|
2498
|
-
await (0,
|
|
2499
|
-
const parsed = (0,
|
|
2255
|
+
await (0, import_io_wallet_utils33.hasStatusOrThrow)(202, import_io_wallet_utils33.UnexpectedStatusCodeError)(response);
|
|
2256
|
+
const parsed = (0, import_io_wallet_utils33.parseWithErrorHandling)(
|
|
2500
2257
|
zMrtdPopVerifyResponse,
|
|
2501
2258
|
await response.json(),
|
|
2502
2259
|
"Failed to parse MRTD PoP verify response"
|
|
@@ -2506,7 +2263,7 @@ async function fetchMrtdPopVerify(options) {
|
|
|
2506
2263
|
redirectUri: parsed.redirect_uri
|
|
2507
2264
|
};
|
|
2508
2265
|
} catch (error) {
|
|
2509
|
-
if (error instanceof
|
|
2266
|
+
if (error instanceof import_io_wallet_utils33.UnexpectedStatusCodeError || error instanceof import_io_wallet_utils33.ValidationError) {
|
|
2510
2267
|
throw error;
|
|
2511
2268
|
}
|
|
2512
2269
|
throw new MrtdPopError(
|
|
@@ -2516,7 +2273,7 @@ async function fetchMrtdPopVerify(options) {
|
|
|
2516
2273
|
}
|
|
2517
2274
|
|
|
2518
2275
|
// src/mrtd-pop/parse-mrtd-challenge.ts
|
|
2519
|
-
var
|
|
2276
|
+
var import_io_wallet_utils34 = require("@pagopa/io-wallet-utils");
|
|
2520
2277
|
function parseMrtdChallenge(options) {
|
|
2521
2278
|
const url = new URL(options.redirectUrl);
|
|
2522
2279
|
const challengeJwt = url.searchParams.get("challenge_info");
|
|
@@ -2525,12 +2282,12 @@ function parseMrtdChallenge(options) {
|
|
|
2525
2282
|
"Missing 'challenge_info' query parameter in redirect URL"
|
|
2526
2283
|
);
|
|
2527
2284
|
}
|
|
2528
|
-
if (!
|
|
2285
|
+
if (!import_io_wallet_utils34.zCompactJwt.safeParse(challengeJwt).success) {
|
|
2529
2286
|
throw new MrtdPopError(
|
|
2530
2287
|
"Invalid JWT format in 'challenge_info' query parameter"
|
|
2531
2288
|
);
|
|
2532
2289
|
}
|
|
2533
|
-
const { header, payload } = decodeJwt({
|
|
2290
|
+
const { header, payload } = (0, import_io_wallet_utils34.decodeJwt)({
|
|
2534
2291
|
errorMessagePrefix: "Error decoding MRTD challenge JWT:",
|
|
2535
2292
|
headerSchema: zMrtdChallengeJwtHeader,
|
|
2536
2293
|
jwt: challengeJwt,
|
|
@@ -2540,10 +2297,10 @@ function parseMrtdChallenge(options) {
|
|
|
2540
2297
|
}
|
|
2541
2298
|
|
|
2542
2299
|
// src/mrtd-pop/verify-mrtd-challenge.ts
|
|
2543
|
-
var
|
|
2300
|
+
var import_io_wallet_utils35 = require("@pagopa/io-wallet-utils");
|
|
2544
2301
|
async function verifyMrtdChallenge(options) {
|
|
2545
2302
|
const { callbacks, challengeJwt, clientId } = options;
|
|
2546
|
-
const jwt = decodeJwt({
|
|
2303
|
+
const jwt = (0, import_io_wallet_utils35.decodeJwt)({
|
|
2547
2304
|
errorMessagePrefix: "Error decoding MRTD challenge JWT:",
|
|
2548
2305
|
headerSchema: zMrtdChallengeJwtHeader,
|
|
2549
2306
|
jwt: challengeJwt,
|
|
@@ -2555,31 +2312,25 @@ async function verifyMrtdChallenge(options) {
|
|
|
2555
2312
|
);
|
|
2556
2313
|
}
|
|
2557
2314
|
const payload = jwt.payload;
|
|
2558
|
-
const { signer } = await (0,
|
|
2315
|
+
const { signer } = await (0, import_io_wallet_utils35.verifyJwt)({
|
|
2559
2316
|
compact: challengeJwt,
|
|
2560
2317
|
errorMessage: "Error verifying MRTD challenge JWT",
|
|
2561
2318
|
header: jwt.header,
|
|
2562
2319
|
payload,
|
|
2563
|
-
signer: options.signer ?? (0,
|
|
2320
|
+
signer: options.signer ?? (0, import_io_wallet_utils35.jwtSignerFromJwt)({ header: jwt.header, payload }),
|
|
2564
2321
|
verifyJwtCallback: callbacks.verifyJwt
|
|
2565
2322
|
});
|
|
2566
2323
|
return { header: jwt.header, payload: jwt.payload, signer };
|
|
2567
2324
|
}
|
|
2568
|
-
|
|
2569
|
-
// src/index.ts
|
|
2570
|
-
var import_oauth216 = require("@openid4vc/oauth2");
|
|
2571
2325
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2572
2326
|
0 && (module.exports = {
|
|
2573
2327
|
ClientAttestationError,
|
|
2574
2328
|
CreateTokenDPoPError,
|
|
2575
2329
|
CreateTokenResponseError,
|
|
2576
2330
|
FetchTokenResponseError,
|
|
2577
|
-
HashAlgorithm,
|
|
2578
2331
|
IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES,
|
|
2579
|
-
MAX_JTI_LENGTH,
|
|
2580
2332
|
MrtdPopError,
|
|
2581
2333
|
Oauth2Error,
|
|
2582
|
-
Oauth2JwtParseError,
|
|
2583
2334
|
PkceCodeChallengeMethod,
|
|
2584
2335
|
PushedAuthorizationRequestError,
|
|
2585
2336
|
SupportedClientAuthenticationMethod,
|
|
@@ -2597,8 +2348,6 @@ var import_oauth216 = require("@openid4vc/oauth2");
|
|
|
2597
2348
|
createWalletAttestationJwtV1_0,
|
|
2598
2349
|
createWalletAttestationJwtV1_3,
|
|
2599
2350
|
createWalletAttestationJwtV1_4,
|
|
2600
|
-
decodeJwt,
|
|
2601
|
-
decodeJwtHeader,
|
|
2602
2351
|
extractClientAttestationJwtsFromHeaders,
|
|
2603
2352
|
extractDpopJwtFromHeaders,
|
|
2604
2353
|
fetchJarRequestObject,
|
|
@@ -2613,7 +2362,6 @@ var import_oauth216 = require("@openid4vc/oauth2");
|
|
|
2613
2362
|
isPushedAuthorizationRequestSigned,
|
|
2614
2363
|
isPushedAuthorizationRequestUnsigned,
|
|
2615
2364
|
jwtAuthorizationRequestJwtHeaderTyp,
|
|
2616
|
-
jwtHeaderFromJwtSigner,
|
|
2617
2365
|
parseAccessTokenRequest,
|
|
2618
2366
|
parseAuthorizationRequest,
|
|
2619
2367
|
parseJarRequest,
|
|
@@ -2628,7 +2376,6 @@ var import_oauth216 = require("@openid4vc/oauth2");
|
|
|
2628
2376
|
verifyClientAttestation,
|
|
2629
2377
|
verifyClientAttestationPopJwt,
|
|
2630
2378
|
verifyJarRequest,
|
|
2631
|
-
verifyJwt,
|
|
2632
2379
|
verifyMrtdChallenge,
|
|
2633
2380
|
verifyPkce,
|
|
2634
2381
|
verifyPushedAuthorizationRequest,
|
|
@@ -2641,13 +2388,9 @@ var import_oauth216 = require("@openid4vc/oauth2");
|
|
|
2641
2388
|
zAccessTokenProfileJwtPayload,
|
|
2642
2389
|
zAccessTokenRequest,
|
|
2643
2390
|
zAccessTokenResponse,
|
|
2644
|
-
zAlgValueNotNone,
|
|
2645
2391
|
zAuthorizationCodeGrantIdentifier,
|
|
2646
2392
|
zAuthorizationRequestV1_0,
|
|
2647
2393
|
zAuthorizationRequestV1_3,
|
|
2648
|
-
zCertificateChain,
|
|
2649
|
-
zCompactJwe,
|
|
2650
|
-
zCompactJwt,
|
|
2651
2394
|
zDpopJwtHeader,
|
|
2652
2395
|
zDpopJwtPayload,
|
|
2653
2396
|
zItWalletClientAttestationPopJwtAlg,
|
|
@@ -2657,11 +2400,6 @@ var import_oauth216 = require("@openid4vc/oauth2");
|
|
|
2657
2400
|
zJarAuthorizationRequest,
|
|
2658
2401
|
zJarRequestObjectHeader,
|
|
2659
2402
|
zJarRequestObjectPayload,
|
|
2660
|
-
zJwk,
|
|
2661
|
-
zJwkSet,
|
|
2662
|
-
zJwtConfirmationPayload,
|
|
2663
|
-
zJwtHeader,
|
|
2664
|
-
zJwtPayload,
|
|
2665
2403
|
zMrtdChallengeJwtHeader,
|
|
2666
2404
|
zMrtdChallengeJwtPayload,
|
|
2667
2405
|
zMrtdPopInitResponseJwtHeader,
|
|
@@ -2677,7 +2415,6 @@ var import_oauth216 = require("@openid4vc/oauth2");
|
|
|
2677
2415
|
zRefreshTokenProfileJwtHeader,
|
|
2678
2416
|
zRefreshTokenProfileJwtPayload,
|
|
2679
2417
|
zSignedAuthorizationRequestJwtHeaderTyp,
|
|
2680
|
-
zTrustChain,
|
|
2681
2418
|
zWalletAttestationJwtHeaderV1_0,
|
|
2682
2419
|
zWalletAttestationJwtHeaderV1_3,
|
|
2683
2420
|
zWalletAttestationJwtHeaderV1_4,
|