@pagopa/io-wallet-oauth2 1.3.0 → 1.4.0
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 +238 -52
- package/dist/index.d.ts +238 -52
- package/dist/index.js +280 -147
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +283 -149
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -854,28 +854,63 @@ import {
|
|
|
854
854
|
} from "@openid4vc/oauth2";
|
|
855
855
|
|
|
856
856
|
// src/client-attestation/client-attestation-pop.ts
|
|
857
|
+
import { verifyJwt as verifyJwt2 } from "@openid4vc/oauth2";
|
|
857
858
|
import {
|
|
858
|
-
|
|
859
|
-
} from "@openid4vc/oauth2";
|
|
860
|
-
import {
|
|
859
|
+
ItWalletSpecsVersion as ItWalletSpecsVersion2,
|
|
861
860
|
addSecondsToDate as addSecondsToDate2,
|
|
862
861
|
dateToSeconds as dateToSeconds3,
|
|
863
|
-
encodeToBase64Url as encodeToBase64Url3
|
|
862
|
+
encodeToBase64Url as encodeToBase64Url3,
|
|
863
|
+
parseWithErrorHandling as parseWithErrorHandling6
|
|
864
864
|
} from "@pagopa/io-wallet-utils";
|
|
865
|
+
|
|
866
|
+
// src/client-attestation/z-client-attestation-pop.ts
|
|
867
|
+
import z11 from "zod";
|
|
868
|
+
var IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES = [
|
|
869
|
+
"ES256",
|
|
870
|
+
"ES384",
|
|
871
|
+
"ES512"
|
|
872
|
+
];
|
|
873
|
+
var zItWalletClientAttestationPopJwtAlg = z11.enum(
|
|
874
|
+
IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES
|
|
875
|
+
);
|
|
876
|
+
var zItWalletClientAttestationPopJwtPayload = z11.looseObject({
|
|
877
|
+
...zJwtPayload.shape,
|
|
878
|
+
aud: z11.string(),
|
|
879
|
+
exp: z11.number().int().optional(),
|
|
880
|
+
iat: z11.number().int(),
|
|
881
|
+
iss: z11.string(),
|
|
882
|
+
jti: z11.string().max(MAX_JTI_LENGTH),
|
|
883
|
+
nonce: z11.string().optional()
|
|
884
|
+
});
|
|
885
|
+
var zItWalletClientAttestationPopJwtTyp = z11.literal(
|
|
886
|
+
"oauth-client-attestation-pop+jwt"
|
|
887
|
+
);
|
|
888
|
+
var zItWalletClientAttestationPopJwtHeader = z11.looseObject({
|
|
889
|
+
...zJwtHeader.shape,
|
|
890
|
+
typ: zItWalletClientAttestationPopJwtTyp
|
|
891
|
+
});
|
|
892
|
+
|
|
893
|
+
// src/client-attestation/client-attestation-pop.ts
|
|
894
|
+
function assertSupportedClientAttestationPopAlg(alg) {
|
|
895
|
+
if (!zItWalletClientAttestationPopJwtAlg.safeParse(alg).success) {
|
|
896
|
+
throw new Oauth2Error(
|
|
897
|
+
`Unsupported alg '${alg}' in client attestation PoP JWT: must be one of ${IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES.join(", ")}`
|
|
898
|
+
);
|
|
899
|
+
}
|
|
900
|
+
}
|
|
865
901
|
async function verifyClientAttestationPopJwt(options) {
|
|
866
902
|
try {
|
|
867
903
|
const { header, payload } = decodeJwt({
|
|
868
904
|
errorMessagePrefix: "Error decoding client attestation PoP JWT:",
|
|
869
|
-
|
|
905
|
+
headerSchema: zItWalletClientAttestationPopJwtHeader,
|
|
906
|
+
jwt: options.clientAttestationPopJwt,
|
|
907
|
+
payloadSchema: zItWalletClientAttestationPopJwtPayload
|
|
870
908
|
});
|
|
871
|
-
|
|
872
|
-
throw new Oauth2Error(
|
|
873
|
-
`Client Attestation Pop jwt contains 'aud' value '${payload.aud}', but expected authorization server identifier '${options.authorizationServer}'`
|
|
874
|
-
);
|
|
875
|
-
}
|
|
909
|
+
assertSupportedClientAttestationPopAlg(header.alg);
|
|
876
910
|
const { signer } = await verifyJwt2({
|
|
877
911
|
compact: options.clientAttestationPopJwt,
|
|
878
912
|
errorMessage: "client attestation pop jwt verification failed",
|
|
913
|
+
expectedAudience: options.authorizationServer,
|
|
879
914
|
expectedNonce: options.expectedNonce,
|
|
880
915
|
header,
|
|
881
916
|
now: options.now,
|
|
@@ -922,25 +957,32 @@ async function createClientAttestationPopJwt(options) {
|
|
|
922
957
|
method: "jwk",
|
|
923
958
|
publicJwk: jwk
|
|
924
959
|
};
|
|
960
|
+
assertSupportedClientAttestationPopAlg(signer.alg);
|
|
925
961
|
const header = {
|
|
926
962
|
alg: signer.alg,
|
|
927
|
-
typ:
|
|
963
|
+
typ: zItWalletClientAttestationPopJwtTyp.value
|
|
928
964
|
};
|
|
929
965
|
const issuedAt = options.issuedAt ?? /* @__PURE__ */ new Date();
|
|
930
|
-
const expiresAt = options.expiresAt ?? addSecondsToDate2(issuedAt, 1 * 60);
|
|
931
966
|
const jti = options.jti ?? (options.callbacks.generateRandom ? encodeToBase64Url3(await options.callbacks.generateRandom(32)) : void 0);
|
|
932
967
|
if (!jti) {
|
|
933
968
|
throw new Oauth2Error(
|
|
934
969
|
"Error: neither a default jti nor a generateRandom callback have been provided"
|
|
935
970
|
);
|
|
936
971
|
}
|
|
937
|
-
const payload =
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
972
|
+
const payload = parseWithErrorHandling6(
|
|
973
|
+
zItWalletClientAttestationPopJwtPayload,
|
|
974
|
+
{
|
|
975
|
+
aud: options.authorizationServer,
|
|
976
|
+
iat: dateToSeconds3(issuedAt),
|
|
977
|
+
iss: sub,
|
|
978
|
+
jti,
|
|
979
|
+
...options.config.itWalletSpecsVersion === ItWalletSpecsVersion2.V1_0 ? {
|
|
980
|
+
exp: dateToSeconds3(
|
|
981
|
+
"expiresAt" in options && options.expiresAt ? options.expiresAt : addSecondsToDate2(issuedAt, 1 * 60)
|
|
982
|
+
)
|
|
983
|
+
} : {}
|
|
984
|
+
}
|
|
985
|
+
);
|
|
944
986
|
const { jwt } = await options.callbacks.signJwt(signer, {
|
|
945
987
|
header,
|
|
946
988
|
payload
|
|
@@ -1214,40 +1256,52 @@ async function verifyAccessTokenRequest(options) {
|
|
|
1214
1256
|
|
|
1215
1257
|
// src/authorization-request/create-authorization-request.ts
|
|
1216
1258
|
import {
|
|
1259
|
+
ItWalletSpecsVersion as ItWalletSpecsVersion3,
|
|
1260
|
+
ItWalletSpecsVersionError as ItWalletSpecsVersionError2,
|
|
1217
1261
|
addSecondsToDate as addSecondsToDate3,
|
|
1218
1262
|
dateToSeconds as dateToSeconds4,
|
|
1219
|
-
encodeToBase64Url as encodeToBase64Url6
|
|
1263
|
+
encodeToBase64Url as encodeToBase64Url6,
|
|
1264
|
+
hasConfigVersion
|
|
1220
1265
|
} from "@pagopa/io-wallet-utils";
|
|
1221
1266
|
|
|
1222
1267
|
// src/authorization-request/z-authorization-request.ts
|
|
1223
|
-
import
|
|
1224
|
-
var zOpenidCredentialAuthorizationDetails =
|
|
1225
|
-
credential_configuration_id:
|
|
1226
|
-
type:
|
|
1268
|
+
import z12 from "zod";
|
|
1269
|
+
var zOpenidCredentialAuthorizationDetails = z12.object({
|
|
1270
|
+
credential_configuration_id: z12.string(),
|
|
1271
|
+
type: z12.literal("openid_credential")
|
|
1227
1272
|
});
|
|
1228
|
-
var zItL2DocumentProofAuthorizationDetails =
|
|
1229
|
-
challenge_method:
|
|
1230
|
-
challenge_redirect_uri:
|
|
1231
|
-
idphinting:
|
|
1232
|
-
type:
|
|
1273
|
+
var zItL2DocumentProofAuthorizationDetails = z12.object({
|
|
1274
|
+
challenge_method: z12.literal("mrtd+ias"),
|
|
1275
|
+
challenge_redirect_uri: z12.url(),
|
|
1276
|
+
idphinting: z12.url(),
|
|
1277
|
+
type: z12.literal("it_l2+document_proof")
|
|
1233
1278
|
});
|
|
1234
|
-
var
|
|
1235
|
-
authorization_details:
|
|
1236
|
-
|
|
1279
|
+
var zAuthorizationRequestBaseObject = z12.looseObject({
|
|
1280
|
+
authorization_details: z12.array(
|
|
1281
|
+
z12.discriminatedUnion("type", [
|
|
1237
1282
|
zOpenidCredentialAuthorizationDetails,
|
|
1238
1283
|
zItL2DocumentProofAuthorizationDetails
|
|
1239
1284
|
])
|
|
1240
1285
|
).optional(),
|
|
1241
|
-
client_id:
|
|
1242
|
-
code_challenge:
|
|
1243
|
-
code_challenge_method:
|
|
1244
|
-
issuer_state:
|
|
1245
|
-
jti:
|
|
1246
|
-
redirect_uri:
|
|
1247
|
-
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
|
|
1286
|
+
client_id: z12.string(),
|
|
1287
|
+
code_challenge: z12.string(),
|
|
1288
|
+
code_challenge_method: z12.string(),
|
|
1289
|
+
issuer_state: z12.optional(z12.string()),
|
|
1290
|
+
jti: z12.string().max(MAX_JTI_LENGTH),
|
|
1291
|
+
redirect_uri: z12.url(),
|
|
1292
|
+
response_type: z12.string(),
|
|
1293
|
+
scope: z12.string().optional(),
|
|
1294
|
+
state: z12.string()
|
|
1295
|
+
});
|
|
1296
|
+
var zAuthorizationRequestBase = zAuthorizationRequestBaseObject.refine(
|
|
1297
|
+
(data) => data.authorization_details !== void 0 || data.scope !== void 0,
|
|
1298
|
+
{
|
|
1299
|
+
message: "Either 'authorization_details' or 'scope' must be provided.",
|
|
1300
|
+
path: ["authorization_details"]
|
|
1301
|
+
}
|
|
1302
|
+
);
|
|
1303
|
+
var zAuthorizationRequestV1_0 = zAuthorizationRequestBaseObject.extend({
|
|
1304
|
+
response_mode: z12.string()
|
|
1251
1305
|
}).refine(
|
|
1252
1306
|
(data) => data.authorization_details !== void 0 || data.scope !== void 0,
|
|
1253
1307
|
{
|
|
@@ -1255,35 +1309,40 @@ var zAuthorizationRequest = z11.looseObject({
|
|
|
1255
1309
|
path: ["authorization_details"]
|
|
1256
1310
|
}
|
|
1257
1311
|
);
|
|
1258
|
-
var
|
|
1259
|
-
|
|
1312
|
+
var zAuthorizationRequestV1_3 = zAuthorizationRequestBase;
|
|
1313
|
+
var zPushedAuthorizationRequestSigned = z12.looseObject({
|
|
1314
|
+
client_id: z12.string().describe(
|
|
1260
1315
|
"MUST be set to the thumbprint of the jwk value in the cnf parameter inside the Wallet Attestation."
|
|
1261
1316
|
),
|
|
1262
|
-
pkceCodeVerifier:
|
|
1317
|
+
pkceCodeVerifier: z12.string().describe(
|
|
1263
1318
|
"Code verifier for PKCE. If not provided in CreatePushedAuthorizationRequestOptions, SDK will generate one."
|
|
1264
1319
|
),
|
|
1265
|
-
request:
|
|
1320
|
+
request: z12.string().describe(
|
|
1266
1321
|
"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."
|
|
1267
1322
|
)
|
|
1268
1323
|
});
|
|
1269
|
-
var
|
|
1270
|
-
authorizationRequest:
|
|
1324
|
+
var zPushedAuthorizationRequestUnsignedBase = (authorizationRequest) => z12.looseObject({
|
|
1325
|
+
authorizationRequest: authorizationRequest.describe(
|
|
1271
1326
|
"The authorization request parameters as a plain object. Used when require_signed_request_object is false."
|
|
1272
1327
|
),
|
|
1273
|
-
client_id:
|
|
1328
|
+
client_id: z12.string().describe(
|
|
1274
1329
|
"Thumbprint of the jwk value in the cnf parameter inside Wallet Attestation."
|
|
1275
1330
|
),
|
|
1276
|
-
pkceCodeVerifier:
|
|
1331
|
+
pkceCodeVerifier: z12.string().describe(
|
|
1332
|
+
"PKCE code verifier. Auto-generated if not provided in options."
|
|
1333
|
+
)
|
|
1277
1334
|
});
|
|
1335
|
+
var zPushedAuthorizationRequestUnsignedV1_0 = zPushedAuthorizationRequestUnsignedBase(zAuthorizationRequestV1_0);
|
|
1336
|
+
var zPushedAuthorizationRequestUnsignedV1_3 = zPushedAuthorizationRequestUnsignedBase(zAuthorizationRequestV1_3);
|
|
1278
1337
|
function isPushedAuthorizationRequestSigned(par) {
|
|
1279
1338
|
return "request" in par && typeof par.request === "string";
|
|
1280
1339
|
}
|
|
1281
1340
|
function isPushedAuthorizationRequestUnsigned(par) {
|
|
1282
1341
|
return "authorizationRequest" in par;
|
|
1283
1342
|
}
|
|
1284
|
-
var zPushedAuthorizationResponse =
|
|
1285
|
-
expires_in:
|
|
1286
|
-
request_uri:
|
|
1343
|
+
var zPushedAuthorizationResponse = z12.looseObject({
|
|
1344
|
+
expires_in: z12.number().int(),
|
|
1345
|
+
request_uri: z12.string()
|
|
1287
1346
|
});
|
|
1288
1347
|
|
|
1289
1348
|
// src/authorization-request/create-authorization-request.ts
|
|
@@ -1295,7 +1354,7 @@ async function createPushedAuthorizationRequest(options) {
|
|
|
1295
1354
|
callbacks: options.callbacks,
|
|
1296
1355
|
codeVerifier: options.pkceCodeVerifier
|
|
1297
1356
|
});
|
|
1298
|
-
const
|
|
1357
|
+
const baseAuthorizationRequest = {
|
|
1299
1358
|
authorization_details: options.authorization_details,
|
|
1300
1359
|
client_id: options.clientId,
|
|
1301
1360
|
code_challenge: pkce.codeChallenge,
|
|
@@ -1304,13 +1363,16 @@ async function createPushedAuthorizationRequest(options) {
|
|
|
1304
1363
|
await options.callbacks.generateRandom(RANDOM_BYTES_SIZE)
|
|
1305
1364
|
),
|
|
1306
1365
|
redirect_uri: options.redirectUri,
|
|
1307
|
-
response_mode: options.responseMode,
|
|
1308
1366
|
response_type: "code",
|
|
1309
1367
|
scope: options.scope,
|
|
1310
1368
|
state: options.state ?? encodeToBase64Url6(
|
|
1311
1369
|
await options.callbacks.generateRandom(RANDOM_BYTES_SIZE)
|
|
1312
1370
|
)
|
|
1313
|
-
}
|
|
1371
|
+
};
|
|
1372
|
+
const authorizationRequest = parseAuthorizationRequestByVersion(
|
|
1373
|
+
options,
|
|
1374
|
+
baseAuthorizationRequest
|
|
1375
|
+
);
|
|
1314
1376
|
const requireSigned = options.authorizationServerMetadata?.require_signed_request_object ?? false;
|
|
1315
1377
|
if (requireSigned) {
|
|
1316
1378
|
const { dpop } = options;
|
|
@@ -1340,13 +1402,31 @@ async function createPushedAuthorizationRequest(options) {
|
|
|
1340
1402
|
pkceCodeVerifier: pkce.codeVerifier,
|
|
1341
1403
|
request: requestJwt.jwt
|
|
1342
1404
|
};
|
|
1343
|
-
} else {
|
|
1344
|
-
return {
|
|
1345
|
-
authorizationRequest,
|
|
1346
|
-
client_id: options.clientId,
|
|
1347
|
-
pkceCodeVerifier: pkce.codeVerifier
|
|
1348
|
-
};
|
|
1349
1405
|
}
|
|
1406
|
+
return {
|
|
1407
|
+
authorizationRequest,
|
|
1408
|
+
client_id: options.clientId,
|
|
1409
|
+
pkceCodeVerifier: pkce.codeVerifier
|
|
1410
|
+
};
|
|
1411
|
+
}
|
|
1412
|
+
function parseAuthorizationRequestByVersion(options, baseAuthorizationRequest) {
|
|
1413
|
+
const version = options.config.itWalletSpecsVersion;
|
|
1414
|
+
if (hasConfigVersion(options, ItWalletSpecsVersion3.V1_0)) {
|
|
1415
|
+
return zAuthorizationRequestV1_0.parse({
|
|
1416
|
+
...baseAuthorizationRequest,
|
|
1417
|
+
response_mode: options.responseMode
|
|
1418
|
+
});
|
|
1419
|
+
}
|
|
1420
|
+
if (hasConfigVersion(options, ItWalletSpecsVersion3.V1_3)) {
|
|
1421
|
+
return zAuthorizationRequestV1_3.parse(
|
|
1422
|
+
baseAuthorizationRequest
|
|
1423
|
+
);
|
|
1424
|
+
}
|
|
1425
|
+
throw new ItWalletSpecsVersionError2(
|
|
1426
|
+
"createPushedAuthorizationRequest",
|
|
1427
|
+
version,
|
|
1428
|
+
[ItWalletSpecsVersion3.V1_0, ItWalletSpecsVersion3.V1_3]
|
|
1429
|
+
);
|
|
1350
1430
|
}
|
|
1351
1431
|
|
|
1352
1432
|
// src/authorization-request/fetch-authorization-response.ts
|
|
@@ -1439,10 +1519,12 @@ function parseAuthorizationRequest(options) {
|
|
|
1439
1519
|
|
|
1440
1520
|
// src/authorization-request/parse-pushed-authorization-request.ts
|
|
1441
1521
|
import {
|
|
1522
|
+
ItWalletSpecsVersion as ItWalletSpecsVersion4,
|
|
1523
|
+
ItWalletSpecsVersionError as ItWalletSpecsVersionError3,
|
|
1442
1524
|
formatZodError as formatZodError2,
|
|
1443
|
-
parseWithErrorHandling as
|
|
1525
|
+
parseWithErrorHandling as parseWithErrorHandling7
|
|
1444
1526
|
} from "@pagopa/io-wallet-utils";
|
|
1445
|
-
import
|
|
1527
|
+
import z14 from "zod";
|
|
1446
1528
|
|
|
1447
1529
|
// src/jar/fetch-jar-request-object.ts
|
|
1448
1530
|
import {
|
|
@@ -1508,31 +1590,34 @@ async function parseJarRequest(options) {
|
|
|
1508
1590
|
}
|
|
1509
1591
|
|
|
1510
1592
|
// src/jar/z-jar.ts
|
|
1511
|
-
import
|
|
1512
|
-
var zJarAuthorizationRequest =
|
|
1513
|
-
client_id:
|
|
1514
|
-
request:
|
|
1515
|
-
request_uri:
|
|
1593
|
+
import z13 from "zod";
|
|
1594
|
+
var zJarAuthorizationRequest = z13.looseObject({
|
|
1595
|
+
client_id: z13.optional(z13.string()),
|
|
1596
|
+
request: z13.optional(z13.string()),
|
|
1597
|
+
request_uri: z13.url().optional()
|
|
1516
1598
|
});
|
|
1517
|
-
var zJarRequestObjectPayload =
|
|
1599
|
+
var zJarRequestObjectPayload = z13.looseObject({
|
|
1518
1600
|
...zJwtPayload.shape,
|
|
1519
|
-
client_id:
|
|
1601
|
+
client_id: z13.string()
|
|
1520
1602
|
});
|
|
1521
|
-
var zSignedAuthorizationRequestJwtHeaderTyp =
|
|
1603
|
+
var zSignedAuthorizationRequestJwtHeaderTyp = z13.literal(
|
|
1522
1604
|
"oauth-authz-req+jwt"
|
|
1523
1605
|
);
|
|
1524
|
-
var zJarRequestObjectHeader =
|
|
1606
|
+
var zJarRequestObjectHeader = z13.looseObject({
|
|
1525
1607
|
...zJwtHeader.shape,
|
|
1526
1608
|
typ: zSignedAuthorizationRequestJwtHeaderTyp
|
|
1527
1609
|
});
|
|
1528
1610
|
var signedAuthorizationRequestJwtHeaderTyp = zSignedAuthorizationRequestJwtHeaderTyp.value;
|
|
1529
|
-
var zJwtAuthorizationRequestJwtHeaderTyp =
|
|
1611
|
+
var zJwtAuthorizationRequestJwtHeaderTyp = z13.literal("jwt");
|
|
1530
1612
|
var jwtAuthorizationRequestJwtHeaderTyp = zJwtAuthorizationRequestJwtHeaderTyp.value;
|
|
1531
1613
|
|
|
1532
1614
|
// src/authorization-request/parse-pushed-authorization-request.ts
|
|
1533
1615
|
async function parsePushedAuthorizationRequest(options) {
|
|
1534
|
-
const
|
|
1535
|
-
|
|
1616
|
+
const authorizationRequestSchema = getAuthorizationRequestSchema(
|
|
1617
|
+
options.config
|
|
1618
|
+
);
|
|
1619
|
+
const parsed = parseWithErrorHandling7(
|
|
1620
|
+
z14.union([authorizationRequestSchema, zJarAuthorizationRequest]),
|
|
1536
1621
|
options.authorizationRequest,
|
|
1537
1622
|
"Invalid authorization request. Could not parse authorization request or jar."
|
|
1538
1623
|
);
|
|
@@ -1547,7 +1632,9 @@ async function parsePushedAuthorizationRequest(options) {
|
|
|
1547
1632
|
errorMessagePrefix: "Error decoding pushed authorization request JWT:",
|
|
1548
1633
|
jwt: parsedJar.authorizationRequestJwt
|
|
1549
1634
|
});
|
|
1550
|
-
parsedAuthorizationRequest =
|
|
1635
|
+
parsedAuthorizationRequest = authorizationRequestSchema.safeParse(
|
|
1636
|
+
jwt.payload
|
|
1637
|
+
);
|
|
1551
1638
|
if (!parsedAuthorizationRequest.success) {
|
|
1552
1639
|
throw new Oauth2Error(
|
|
1553
1640
|
`Invalid authorization request. Could not parse jar request payload.
|
|
@@ -1556,7 +1643,7 @@ ${formatZodError2(parsedAuthorizationRequest.error)}`
|
|
|
1556
1643
|
}
|
|
1557
1644
|
authorizationRequestJwt = parsedJar.authorizationRequestJwt;
|
|
1558
1645
|
} else {
|
|
1559
|
-
parsedAuthorizationRequest =
|
|
1646
|
+
parsedAuthorizationRequest = authorizationRequestSchema.safeParse(
|
|
1560
1647
|
options.authorizationRequest
|
|
1561
1648
|
);
|
|
1562
1649
|
if (!parsedAuthorizationRequest.success) {
|
|
@@ -1577,6 +1664,19 @@ ${formatZodError2(parsedAuthorizationRequest.error)}`
|
|
|
1577
1664
|
dpop
|
|
1578
1665
|
};
|
|
1579
1666
|
}
|
|
1667
|
+
function getAuthorizationRequestSchema(config) {
|
|
1668
|
+
if (config.isVersion(ItWalletSpecsVersion4.V1_0)) {
|
|
1669
|
+
return zAuthorizationRequestV1_0;
|
|
1670
|
+
}
|
|
1671
|
+
if (config.isVersion(ItWalletSpecsVersion4.V1_3)) {
|
|
1672
|
+
return zAuthorizationRequestV1_3;
|
|
1673
|
+
}
|
|
1674
|
+
throw new ItWalletSpecsVersionError3(
|
|
1675
|
+
"parsePushedAuthorizationRequest",
|
|
1676
|
+
config.itWalletSpecsVersion,
|
|
1677
|
+
[ItWalletSpecsVersion4.V1_0, ItWalletSpecsVersion4.V1_3]
|
|
1678
|
+
);
|
|
1679
|
+
}
|
|
1580
1680
|
|
|
1581
1681
|
// src/authorization-request/verify-authorization-request.ts
|
|
1582
1682
|
async function verifyAuthorizationRequest(options) {
|
|
@@ -1628,7 +1728,7 @@ import {
|
|
|
1628
1728
|
zCompactJwe,
|
|
1629
1729
|
zCompactJwt as zCompactJwt4
|
|
1630
1730
|
} from "@openid4vc/oauth2";
|
|
1631
|
-
import { parseWithErrorHandling as
|
|
1731
|
+
import { parseWithErrorHandling as parseWithErrorHandling8 } from "@pagopa/io-wallet-utils";
|
|
1632
1732
|
async function verifyJarRequest(options) {
|
|
1633
1733
|
const { authorizationRequestJwt, callbacks, jarRequestParams, jwtSigner } = options;
|
|
1634
1734
|
const requestObjectIsEncrypted = zCompactJwe.safeParse(
|
|
@@ -1694,7 +1794,7 @@ async function verifyJarRequestObject(options) {
|
|
|
1694
1794
|
errorMessagePrefix: "Error decoding JAR authorization request JWT:",
|
|
1695
1795
|
jwt: authorizationRequestJwt
|
|
1696
1796
|
});
|
|
1697
|
-
const authorizationRequestPayload =
|
|
1797
|
+
const authorizationRequestPayload = parseWithErrorHandling8(
|
|
1698
1798
|
zJarRequestObjectPayload,
|
|
1699
1799
|
jwt.payload
|
|
1700
1800
|
);
|
|
@@ -1811,7 +1911,8 @@ function clientAuthenticationWalletAttestationJwt(options) {
|
|
|
1811
1911
|
const clientAttestationPop = await createClientAttestationPopJwt({
|
|
1812
1912
|
authorizationServer: authorizationServerMetadata.issuer,
|
|
1813
1913
|
callbacks: options.callbacks,
|
|
1814
|
-
clientAttestation: options.walletAttestationJwt
|
|
1914
|
+
clientAttestation: options.walletAttestationJwt,
|
|
1915
|
+
config: options.config
|
|
1815
1916
|
});
|
|
1816
1917
|
headers.set(oauthClientAttestationHeader, options.walletAttestationJwt);
|
|
1817
1918
|
headers.set(oauthClientAttestationPopHeader, clientAttestationPop);
|
|
@@ -1824,17 +1925,41 @@ import {
|
|
|
1824
1925
|
addSecondsToDate as addSecondsToDate4,
|
|
1825
1926
|
dateToSeconds as dateToSeconds5
|
|
1826
1927
|
} from "@pagopa/io-wallet-utils";
|
|
1928
|
+
|
|
1929
|
+
// src/client-attestation/jwk-thumbprint.ts
|
|
1930
|
+
import {
|
|
1931
|
+
HashAlgorithm as HashAlgorithm6,
|
|
1932
|
+
calculateJwkThumbprint as calculateJwkThumbprint4
|
|
1933
|
+
} from "@openid4vc/oauth2";
|
|
1934
|
+
var SUPPORTED_KTY = ["RSA", "EC"];
|
|
1935
|
+
var calculateDpopJwkThumbprint = (options) => {
|
|
1936
|
+
if (!SUPPORTED_KTY.includes(
|
|
1937
|
+
options.dpopJwkPublic.kty
|
|
1938
|
+
)) {
|
|
1939
|
+
throw new ClientAttestationError(
|
|
1940
|
+
`Unsupported JWK key type "${options.dpopJwkPublic.kty}" for thumbprint computation. Supported types: ${SUPPORTED_KTY.join(", ")}.`
|
|
1941
|
+
);
|
|
1942
|
+
}
|
|
1943
|
+
return calculateJwkThumbprint4({
|
|
1944
|
+
hashAlgorithm: HashAlgorithm6.Sha256,
|
|
1945
|
+
hashCallback: options.callbacks.hash,
|
|
1946
|
+
jwk: options.dpopJwkPublic
|
|
1947
|
+
});
|
|
1948
|
+
};
|
|
1949
|
+
|
|
1950
|
+
// src/client-attestation/v1.0/create-wallet-attestation-jwt.ts
|
|
1827
1951
|
var createWalletAttestationJwt = async (options) => {
|
|
1828
1952
|
try {
|
|
1829
1953
|
const { signJwt } = options.callbacks;
|
|
1830
1954
|
const iat = /* @__PURE__ */ new Date();
|
|
1831
1955
|
const exp = options.expiresAt ?? addSecondsToDate4(iat, 3600);
|
|
1956
|
+
const dpopJwkThumbprint = await calculateDpopJwkThumbprint(options);
|
|
1832
1957
|
const payload = {
|
|
1833
1958
|
cnf: { jwk: options.dpopJwkPublic },
|
|
1834
1959
|
exp: dateToSeconds5(exp),
|
|
1835
1960
|
iat: dateToSeconds5(iat),
|
|
1836
1961
|
iss: options.issuer,
|
|
1837
|
-
sub:
|
|
1962
|
+
sub: dpopJwkThumbprint,
|
|
1838
1963
|
...options.walletLink && { wallet_link: options.walletLink },
|
|
1839
1964
|
...options.walletName && { wallet_name: options.walletName },
|
|
1840
1965
|
aal: options.authenticatorAssuranceLevel
|
|
@@ -1880,12 +2005,13 @@ var createWalletAttestationJwt2 = async (options) => {
|
|
|
1880
2005
|
if (options.nbf && options.nbf >= exp) {
|
|
1881
2006
|
throw new ValidationError5("nbf must be before exp");
|
|
1882
2007
|
}
|
|
2008
|
+
const dpopJwkThumbprint = await calculateDpopJwkThumbprint(options);
|
|
1883
2009
|
const payload = {
|
|
1884
2010
|
cnf: { jwk: options.dpopJwkPublic },
|
|
1885
2011
|
exp: dateToSeconds6(exp),
|
|
1886
2012
|
iat: dateToSeconds6(iat),
|
|
1887
2013
|
iss: options.issuer,
|
|
1888
|
-
sub:
|
|
2014
|
+
sub: dpopJwkThumbprint,
|
|
1889
2015
|
...options.nbf && { nbf: dateToSeconds6(options.nbf) },
|
|
1890
2016
|
...options.status && { status: options.status },
|
|
1891
2017
|
...options.walletLink && { wallet_link: options.walletLink },
|
|
@@ -1936,13 +2062,14 @@ var createWalletAttestationJwt3 = async (options) => {
|
|
|
1936
2062
|
if (options.nbf && options.nbf >= exp) {
|
|
1937
2063
|
throw new ValidationError6("nbf must be before exp");
|
|
1938
2064
|
}
|
|
2065
|
+
const dpopJwkThumbprint = await calculateDpopJwkThumbprint(options);
|
|
1939
2066
|
const payload = {
|
|
1940
2067
|
cnf: { jwk: options.dpopJwkPublic },
|
|
1941
2068
|
exp: dateToSeconds7(exp),
|
|
1942
2069
|
iat: dateToSeconds7(iat),
|
|
1943
2070
|
iss: options.issuer,
|
|
1944
2071
|
status: options.status,
|
|
1945
|
-
sub:
|
|
2072
|
+
sub: dpopJwkThumbprint,
|
|
1946
2073
|
wallet_link: options.walletLink,
|
|
1947
2074
|
wallet_name: options.walletName,
|
|
1948
2075
|
...options.nbf && { nbf: dateToSeconds7(options.nbf) },
|
|
@@ -1981,8 +2108,8 @@ var createWalletAttestationJwt3 = async (options) => {
|
|
|
1981
2108
|
};
|
|
1982
2109
|
|
|
1983
2110
|
// src/common/jwt/z-jwe.ts
|
|
1984
|
-
import { z as
|
|
1985
|
-
var zCompactJwe2 =
|
|
2111
|
+
import { z as z15 } from "zod";
|
|
2112
|
+
var zCompactJwe2 = z15.string().regex(
|
|
1986
2113
|
/^[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+$/,
|
|
1987
2114
|
{
|
|
1988
2115
|
message: "Not a valid compact jwe"
|
|
@@ -2073,73 +2200,73 @@ var getJwtFromFormPost = async (options) => {
|
|
|
2073
2200
|
};
|
|
2074
2201
|
|
|
2075
2202
|
// src/mrtd-pop/create-mrtd-validation-jwt.ts
|
|
2076
|
-
import { dateToSeconds as dateToSeconds9, parseWithErrorHandling as
|
|
2203
|
+
import { dateToSeconds as dateToSeconds9, parseWithErrorHandling as parseWithErrorHandling9 } from "@pagopa/io-wallet-utils";
|
|
2077
2204
|
|
|
2078
2205
|
// src/mrtd-pop/z-mrtd-pop.ts
|
|
2079
|
-
import
|
|
2080
|
-
var zMrtdChallengeJwtHeader =
|
|
2081
|
-
alg:
|
|
2082
|
-
kid:
|
|
2083
|
-
typ:
|
|
2206
|
+
import z16 from "zod";
|
|
2207
|
+
var zMrtdChallengeJwtHeader = z16.looseObject({
|
|
2208
|
+
alg: z16.string(),
|
|
2209
|
+
kid: z16.string(),
|
|
2210
|
+
typ: z16.literal("mrtd-ias+jwt")
|
|
2084
2211
|
});
|
|
2085
|
-
var zMrtdChallengeJwtPayload =
|
|
2086
|
-
aud:
|
|
2087
|
-
exp:
|
|
2088
|
-
htm:
|
|
2089
|
-
htu:
|
|
2090
|
-
iat:
|
|
2091
|
-
iss:
|
|
2092
|
-
mrtd_auth_session:
|
|
2093
|
-
mrtd_pop_jwt_nonce:
|
|
2094
|
-
state:
|
|
2095
|
-
status:
|
|
2096
|
-
type:
|
|
2212
|
+
var zMrtdChallengeJwtPayload = z16.looseObject({
|
|
2213
|
+
aud: z16.string(),
|
|
2214
|
+
exp: z16.number(),
|
|
2215
|
+
htm: z16.literal("POST"),
|
|
2216
|
+
htu: z16.url(),
|
|
2217
|
+
iat: z16.number(),
|
|
2218
|
+
iss: z16.string(),
|
|
2219
|
+
mrtd_auth_session: z16.string(),
|
|
2220
|
+
mrtd_pop_jwt_nonce: z16.string(),
|
|
2221
|
+
state: z16.string(),
|
|
2222
|
+
status: z16.literal("require_interaction"),
|
|
2223
|
+
type: z16.literal("mrtd+ias")
|
|
2097
2224
|
});
|
|
2098
|
-
var zMrtdPopInitResponseJwtHeader =
|
|
2099
|
-
alg:
|
|
2100
|
-
kid:
|
|
2101
|
-
typ:
|
|
2225
|
+
var zMrtdPopInitResponseJwtHeader = z16.looseObject({
|
|
2226
|
+
alg: z16.string(),
|
|
2227
|
+
kid: z16.string(),
|
|
2228
|
+
typ: z16.literal("mrtd-ias-pop+jwt")
|
|
2102
2229
|
});
|
|
2103
|
-
var zMrtdPopInitResponseJwtPayload =
|
|
2104
|
-
aud:
|
|
2105
|
-
challenge:
|
|
2106
|
-
exp:
|
|
2107
|
-
htm:
|
|
2108
|
-
htu:
|
|
2109
|
-
iat:
|
|
2110
|
-
iss:
|
|
2111
|
-
mrtd_pop_nonce:
|
|
2112
|
-
mrz:
|
|
2230
|
+
var zMrtdPopInitResponseJwtPayload = z16.looseObject({
|
|
2231
|
+
aud: z16.string(),
|
|
2232
|
+
challenge: z16.string(),
|
|
2233
|
+
exp: z16.number(),
|
|
2234
|
+
htm: z16.literal("POST"),
|
|
2235
|
+
htu: z16.url(),
|
|
2236
|
+
iat: z16.number(),
|
|
2237
|
+
iss: z16.string(),
|
|
2238
|
+
mrtd_pop_nonce: z16.string(),
|
|
2239
|
+
mrz: z16.string().optional()
|
|
2113
2240
|
});
|
|
2114
|
-
var zMrtdData =
|
|
2115
|
-
dg1:
|
|
2116
|
-
dg11:
|
|
2117
|
-
sod_mrtd:
|
|
2241
|
+
var zMrtdData = z16.looseObject({
|
|
2242
|
+
dg1: z16.string(),
|
|
2243
|
+
dg11: z16.string(),
|
|
2244
|
+
sod_mrtd: z16.string()
|
|
2118
2245
|
});
|
|
2119
|
-
var zIasData =
|
|
2120
|
-
challenge_signed:
|
|
2121
|
-
ias_pk:
|
|
2122
|
-
sod_ias:
|
|
2246
|
+
var zIasData = z16.looseObject({
|
|
2247
|
+
challenge_signed: z16.string(),
|
|
2248
|
+
ias_pk: z16.string(),
|
|
2249
|
+
sod_ias: z16.string()
|
|
2123
2250
|
});
|
|
2124
|
-
var zMrtdValidationJwtHeader =
|
|
2125
|
-
alg:
|
|
2126
|
-
kid:
|
|
2127
|
-
typ:
|
|
2251
|
+
var zMrtdValidationJwtHeader = z16.looseObject({
|
|
2252
|
+
alg: z16.string(),
|
|
2253
|
+
kid: z16.string(),
|
|
2254
|
+
typ: z16.literal("mrtd-ias+jwt")
|
|
2128
2255
|
});
|
|
2129
|
-
var zMrtdValidationJwtPayload =
|
|
2130
|
-
aud:
|
|
2131
|
-
document_type:
|
|
2132
|
-
exp:
|
|
2256
|
+
var zMrtdValidationJwtPayload = z16.looseObject({
|
|
2257
|
+
aud: z16.string(),
|
|
2258
|
+
document_type: z16.literal("cie"),
|
|
2259
|
+
exp: z16.number(),
|
|
2133
2260
|
ias: zIasData,
|
|
2134
|
-
iat:
|
|
2135
|
-
iss:
|
|
2261
|
+
iat: z16.number(),
|
|
2262
|
+
iss: z16.string(),
|
|
2136
2263
|
mrtd: zMrtdData
|
|
2137
2264
|
});
|
|
2138
|
-
var zMrtdPopVerifyResponse =
|
|
2139
|
-
mrtd_val_pop_nonce:
|
|
2140
|
-
redirect_uri:
|
|
2141
|
-
status:
|
|
2142
|
-
type:
|
|
2265
|
+
var zMrtdPopVerifyResponse = z16.looseObject({
|
|
2266
|
+
mrtd_val_pop_nonce: z16.string(),
|
|
2267
|
+
redirect_uri: z16.url(),
|
|
2268
|
+
status: z16.literal("require_interaction"),
|
|
2269
|
+
type: z16.literal("redirect_to_web")
|
|
2143
2270
|
});
|
|
2144
2271
|
|
|
2145
2272
|
// src/mrtd-pop/create-mrtd-validation-jwt.ts
|
|
@@ -2151,12 +2278,12 @@ async function createMrtdValidationJwt(options) {
|
|
|
2151
2278
|
throw new MrtdPopError("Signer must have a publicJwk.kid property");
|
|
2152
2279
|
}
|
|
2153
2280
|
const iat = dateToSeconds9(options.issuedAt);
|
|
2154
|
-
const header =
|
|
2281
|
+
const header = parseWithErrorHandling9(zMrtdValidationJwtHeader, {
|
|
2155
2282
|
alg: options.signer.alg,
|
|
2156
2283
|
kid,
|
|
2157
2284
|
typ: "mrtd-ias+jwt"
|
|
2158
2285
|
});
|
|
2159
|
-
const payload =
|
|
2286
|
+
const payload = parseWithErrorHandling9(zMrtdValidationJwtPayload, {
|
|
2160
2287
|
aud: options.audience,
|
|
2161
2288
|
document_type: "cie",
|
|
2162
2289
|
exp: iat + JWT_EXPIRY_SECONDS2,
|
|
@@ -2257,7 +2384,7 @@ import {
|
|
|
2257
2384
|
ValidationError as ValidationError8,
|
|
2258
2385
|
createFetcher as createFetcher5,
|
|
2259
2386
|
hasStatusOrThrow as hasStatusOrThrow5,
|
|
2260
|
-
parseWithErrorHandling as
|
|
2387
|
+
parseWithErrorHandling as parseWithErrorHandling10
|
|
2261
2388
|
} from "@pagopa/io-wallet-utils";
|
|
2262
2389
|
async function fetchMrtdPopVerify(options) {
|
|
2263
2390
|
try {
|
|
@@ -2276,7 +2403,7 @@ async function fetchMrtdPopVerify(options) {
|
|
|
2276
2403
|
method: "POST"
|
|
2277
2404
|
});
|
|
2278
2405
|
await hasStatusOrThrow5(202, UnexpectedStatusCodeError5)(response);
|
|
2279
|
-
const parsed =
|
|
2406
|
+
const parsed = parseWithErrorHandling10(
|
|
2280
2407
|
zMrtdPopVerifyResponse,
|
|
2281
2408
|
await response.json(),
|
|
2282
2409
|
"Failed to parse MRTD PoP verify response"
|
|
@@ -2351,7 +2478,7 @@ async function verifyMrtdChallenge(options) {
|
|
|
2351
2478
|
|
|
2352
2479
|
// src/index.ts
|
|
2353
2480
|
import {
|
|
2354
|
-
HashAlgorithm as
|
|
2481
|
+
HashAlgorithm as HashAlgorithm7,
|
|
2355
2482
|
Oauth2JwtParseError as Oauth2JwtParseError3,
|
|
2356
2483
|
verifyJwt as verifyJwt7
|
|
2357
2484
|
} from "@openid4vc/oauth2";
|
|
@@ -2360,7 +2487,8 @@ export {
|
|
|
2360
2487
|
CreateTokenDPoPError,
|
|
2361
2488
|
CreateTokenResponseError,
|
|
2362
2489
|
FetchTokenResponseError,
|
|
2363
|
-
|
|
2490
|
+
HashAlgorithm7 as HashAlgorithm,
|
|
2491
|
+
IT_WALLET_CLIENT_ATTESTATION_POP_ALLOWED_ALG_VALUES,
|
|
2364
2492
|
MAX_JTI_LENGTH,
|
|
2365
2493
|
MrtdPopError,
|
|
2366
2494
|
Oauth2Error,
|
|
@@ -2428,12 +2556,17 @@ export {
|
|
|
2428
2556
|
zAccessTokenResponse,
|
|
2429
2557
|
zAlgValueNotNone,
|
|
2430
2558
|
zAuthorizationCodeGrantIdentifier,
|
|
2431
|
-
|
|
2559
|
+
zAuthorizationRequestV1_0,
|
|
2560
|
+
zAuthorizationRequestV1_3,
|
|
2432
2561
|
zCertificateChain,
|
|
2433
2562
|
zCompactJwe2 as zCompactJwe,
|
|
2434
2563
|
zCompactJwt,
|
|
2435
2564
|
zDpopJwtHeader,
|
|
2436
2565
|
zDpopJwtPayload,
|
|
2566
|
+
zItWalletClientAttestationPopJwtAlg,
|
|
2567
|
+
zItWalletClientAttestationPopJwtHeader,
|
|
2568
|
+
zItWalletClientAttestationPopJwtPayload,
|
|
2569
|
+
zItWalletClientAttestationPopJwtTyp,
|
|
2437
2570
|
zJarAuthorizationRequest,
|
|
2438
2571
|
zJarRequestObjectHeader,
|
|
2439
2572
|
zJarRequestObjectPayload,
|
|
@@ -2450,7 +2583,8 @@ export {
|
|
|
2450
2583
|
zMrtdValidationJwtHeader,
|
|
2451
2584
|
zMrtdValidationJwtPayload,
|
|
2452
2585
|
zPushedAuthorizationRequestSigned,
|
|
2453
|
-
|
|
2586
|
+
zPushedAuthorizationRequestUnsignedV1_0,
|
|
2587
|
+
zPushedAuthorizationRequestUnsignedV1_3,
|
|
2454
2588
|
zPushedAuthorizationResponse,
|
|
2455
2589
|
zRefreshTokenGrantIdentifier,
|
|
2456
2590
|
zSignedAuthorizationRequestJwtHeaderTyp,
|