@openid4vc/openid4vp 0.3.0-alpha-20250227094616 → 0.3.0-alpha-20250304095426
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 +441 -18999
- package/dist/index.d.ts +441 -18999
- package/dist/index.js +91 -181
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +90 -187
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
jwtSignerFromJwt,
|
|
20
20
|
zCompactJwe,
|
|
21
21
|
zCompactJwt,
|
|
22
|
-
zJwtHeader
|
|
22
|
+
zJwtHeader as zJwtHeader2
|
|
23
23
|
} from "@openid4vc/oauth2";
|
|
24
24
|
import z3 from "zod";
|
|
25
25
|
|
|
@@ -28,8 +28,9 @@ import { Oauth2Error } from "@openid4vc/oauth2";
|
|
|
28
28
|
import { dateToSeconds } from "@openid4vc/utils";
|
|
29
29
|
|
|
30
30
|
// src/jarm/jarm-auth-response/z-jarm-auth-response.ts
|
|
31
|
-
import { zJwtPayload } from "@openid4vc/oauth2";
|
|
31
|
+
import { zJwtHeader, zJwtPayload } from "@openid4vc/oauth2";
|
|
32
32
|
import { z as z2 } from "zod";
|
|
33
|
+
var zJarmHeader = z2.object({ ...zJwtHeader.shape, apu: z2.string().optional(), apv: z2.string().optional() });
|
|
33
34
|
var zJarmAuthResponse = z2.object({
|
|
34
35
|
/**
|
|
35
36
|
* iss: The issuer URL of the authorization server that created the response
|
|
@@ -86,7 +87,7 @@ async function verifyJarmAuthorizationResponse(options) {
|
|
|
86
87
|
if (responseIsSigned) {
|
|
87
88
|
const { header: jwsProtectedHeader, payload: jwsPayload } = decodeJwt({
|
|
88
89
|
jwt: decryptedRequestData,
|
|
89
|
-
headerSchema: z3.object({ ...
|
|
90
|
+
headerSchema: z3.object({ ...zJwtHeader2.shape, kid: z3.string() })
|
|
90
91
|
});
|
|
91
92
|
const response = zJarmAuthResponse.parse(jwsPayload);
|
|
92
93
|
const jwtSigner = jwtSignerFromJwt({ header: jwsProtectedHeader, payload: jwsPayload });
|
|
@@ -1205,8 +1206,10 @@ function extractJwksFromClientMetadata(clientMetadata) {
|
|
|
1205
1206
|
const parsed = zJarmClientMetadataParsed.parse(clientMetadata);
|
|
1206
1207
|
const encryptionAlg = parsed.client_metadata.authorization_encrypted_response_enc;
|
|
1207
1208
|
const signingAlg = parsed.client_metadata.authorization_signed_response_alg;
|
|
1208
|
-
const encJwk = clientMetadata.jwks.keys.find((key) => key.use === "enc" && key.alg === encryptionAlg) ?? clientMetadata.jwks.keys.find((key) => key.use === "enc")
|
|
1209
|
-
|
|
1209
|
+
const encJwk = clientMetadata.jwks.keys.find((key) => key.use === "enc" && key.alg === encryptionAlg) ?? clientMetadata.jwks.keys.find((key) => key.use === "enc") ?? // fallback, take first key. HAIP does not specify requirement on enc
|
|
1210
|
+
clientMetadata.jwks.keys?.[0];
|
|
1211
|
+
const sigJwk = clientMetadata.jwks.keys.find((key) => key.use === "sig" && key.alg === signingAlg) ?? clientMetadata.jwks.keys.find((key) => key.use === "sig") ?? // falback, take first key
|
|
1212
|
+
clientMetadata.jwks.keys?.[0];
|
|
1210
1213
|
return { encJwk, sigJwk };
|
|
1211
1214
|
}
|
|
1212
1215
|
|
|
@@ -1412,190 +1415,90 @@ async function submitOpenid4vpAuthorizationResponse(options) {
|
|
|
1412
1415
|
}
|
|
1413
1416
|
|
|
1414
1417
|
// src/authorization-response/validate-authorization-response.ts
|
|
1415
|
-
import { Oauth2Error as
|
|
1418
|
+
import { Oauth2Error as Oauth2Error10 } from "@openid4vc/oauth2";
|
|
1419
|
+
|
|
1420
|
+
// src/vp-token/parse-vp-token.ts
|
|
1421
|
+
import { parseIfJson as parseIfJson2, parseWithErrorHandling as parseWithErrorHandling5 } from "@openid4vc/utils";
|
|
1416
1422
|
|
|
1417
|
-
// src/vp-token/
|
|
1418
|
-
import { Oauth2Error as Oauth2Error10, decodeJwt as decodeJwt4 } from "@openid4vc/oauth2";
|
|
1419
|
-
import { zCompactJwt as zCompactJwt3 } from "@openid4vc/oauth2";
|
|
1420
|
-
import { isObject, parseIfJson as parseIfJson2, parseWithErrorHandling as parseWithErrorHandling5 } from "@openid4vc/utils";
|
|
1423
|
+
// src/vp-token/z-vp-token.ts
|
|
1421
1424
|
import { z as z17 } from "zod";
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
return vpToken.map((token, idx) => parseSinglePresentationFromVpToken({ vpToken: token, path: `$[${idx}]` }));
|
|
1430
|
-
}
|
|
1431
|
-
if (typeof vpToken === "string" || typeof vpToken === "object") {
|
|
1432
|
-
return [parseSinglePresentationFromVpToken({ vpToken, path: "$" })];
|
|
1425
|
+
var zVpTokenPexEntry = z17.union([z17.string(), z17.record(z17.any())], {
|
|
1426
|
+
message: "pex vp_token entry must be a string or object"
|
|
1427
|
+
});
|
|
1428
|
+
var zVpTokenPex = z17.union(
|
|
1429
|
+
[zVpTokenPexEntry, z17.array(zVpTokenPexEntry).nonempty("Must have at least entry in vp_token array")],
|
|
1430
|
+
{
|
|
1431
|
+
message: "pex vp_token must be a string, object or array of strings and objects"
|
|
1433
1432
|
}
|
|
1434
|
-
|
|
1435
|
-
|
|
1433
|
+
);
|
|
1434
|
+
var zVpTokenDcql = z17.record(z17.union([z17.string(), z17.record(z17.any())]), {
|
|
1435
|
+
message: "dcql vp_token must be an object with keys referencing the dcql credential query id, and values the encoded (string or object) presentation"
|
|
1436
|
+
});
|
|
1437
|
+
var zVpToken = zVpTokenDcql.or(zVpTokenPex);
|
|
1438
|
+
|
|
1439
|
+
// src/vp-token/parse-vp-token.ts
|
|
1440
|
+
function parsePexVpToken(vpToken) {
|
|
1441
|
+
const parsedVpToken = parseWithErrorHandling5(
|
|
1442
|
+
zVpTokenPex,
|
|
1443
|
+
parseIfJson2(vpToken),
|
|
1444
|
+
"Could not parse presentation exchange vp_token. Expected a string or an array of strings"
|
|
1436
1445
|
);
|
|
1446
|
+
return Array.isArray(parsedVpToken) ? parsedVpToken : [parsedVpToken];
|
|
1437
1447
|
}
|
|
1438
|
-
function
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
Object.entries(parsed).map(([key, value]) => {
|
|
1444
|
-
return [key, parseSinglePresentationFromVpToken({ vpToken: value })];
|
|
1445
|
-
})
|
|
1448
|
+
function parseDcqlVpToken(vpToken) {
|
|
1449
|
+
return parseWithErrorHandling5(
|
|
1450
|
+
zVpTokenDcql,
|
|
1451
|
+
parseIfJson2(vpToken),
|
|
1452
|
+
"Could not parse dcql vp_token. Expected an object where the values are encoded presentations"
|
|
1446
1453
|
);
|
|
1447
|
-
return dcqlPresentationRecord;
|
|
1448
|
-
}
|
|
1449
|
-
function parseSinglePresentationFromVpToken(options) {
|
|
1450
|
-
const { vpToken: _vpToken, path } = options;
|
|
1451
|
-
const vpToken = parseIfJson2(_vpToken);
|
|
1452
|
-
const zLdpVpProof = z17.object({ challenge: z17.string().optional() }).passthrough();
|
|
1453
|
-
const ldpVpParseResult = z17.object({
|
|
1454
|
-
"@context": z17.string().optional(),
|
|
1455
|
-
verifiableCredential: z17.string().optional(),
|
|
1456
|
-
proof: z17.union([zLdpVpProof, z17.array(zLdpVpProof)]).optional()
|
|
1457
|
-
}).passthrough().safeParse(vpToken);
|
|
1458
|
-
if (ldpVpParseResult.success && (ldpVpParseResult.data["@context"] || ldpVpParseResult.data.verifiableCredential)) {
|
|
1459
|
-
const challenge = Array.isArray(ldpVpParseResult.data.proof) ? ldpVpParseResult.data.proof.map((proof) => proof.challenge) : ldpVpParseResult.data.proof?.challenge;
|
|
1460
|
-
if (Array.isArray(challenge)) {
|
|
1461
|
-
const allNoncesAreTheSame = challenge.every((nonce) => nonce === challenge[0]);
|
|
1462
|
-
if (!allNoncesAreTheSame) {
|
|
1463
|
-
throw new Oauth2Error10(
|
|
1464
|
-
"Failed to parse presentation from vp_token. LDP presentation is missing the proof.challenge parameter."
|
|
1465
|
-
);
|
|
1466
|
-
}
|
|
1467
|
-
}
|
|
1468
|
-
if (!challenge) {
|
|
1469
|
-
throw new Oauth2Error10(
|
|
1470
|
-
"Failed to parse presentation from vp_token. LDP presentation is missing the proof.challenge parameter."
|
|
1471
|
-
);
|
|
1472
|
-
}
|
|
1473
|
-
return {
|
|
1474
|
-
format: "ldp_vp",
|
|
1475
|
-
presentation: ldpVpParseResult,
|
|
1476
|
-
path,
|
|
1477
|
-
nonce: Array.isArray(challenge) ? challenge[0] : challenge
|
|
1478
|
-
};
|
|
1479
|
-
}
|
|
1480
|
-
if (isObject(vpToken) && (vpToken.schema_id || vpToken.cred_def_id)) {
|
|
1481
|
-
return {
|
|
1482
|
-
format: "ac_vp",
|
|
1483
|
-
presentation: vpToken,
|
|
1484
|
-
path: options.path
|
|
1485
|
-
};
|
|
1486
|
-
}
|
|
1487
|
-
if (typeof vpToken !== "string") {
|
|
1488
|
-
throw new Oauth2Error10(
|
|
1489
|
-
`Could not parse vp_token. Expected a string since the vp_token is neither a ldp_vp nor an ac_vp. Received: ${typeof vpToken}`
|
|
1490
|
-
);
|
|
1491
|
-
}
|
|
1492
|
-
if (vpToken.includes("~")) {
|
|
1493
|
-
const split = vpToken.split("~");
|
|
1494
|
-
const keyBindingJwt = split[split.length - 1];
|
|
1495
|
-
let nonce;
|
|
1496
|
-
try {
|
|
1497
|
-
const decoded = decodeJwt4({ jwt: keyBindingJwt });
|
|
1498
|
-
nonce = decoded.payload.nonce;
|
|
1499
|
-
} catch (error) {
|
|
1500
|
-
nonce = void 0;
|
|
1501
|
-
}
|
|
1502
|
-
return {
|
|
1503
|
-
format: "dc+sd-jwt",
|
|
1504
|
-
presentation: vpToken,
|
|
1505
|
-
path: options.path
|
|
1506
|
-
};
|
|
1507
|
-
}
|
|
1508
|
-
const result = zCompactJwt3.safeParse(vpToken);
|
|
1509
|
-
if (result.success) {
|
|
1510
|
-
let nonce;
|
|
1511
|
-
try {
|
|
1512
|
-
const decoded = decodeJwt4({ jwt: vpToken });
|
|
1513
|
-
nonce = decoded.payload.nonce;
|
|
1514
|
-
} catch (error) {
|
|
1515
|
-
nonce = void 0;
|
|
1516
|
-
}
|
|
1517
|
-
return {
|
|
1518
|
-
format: "jwt_vp_json",
|
|
1519
|
-
presentation: vpToken,
|
|
1520
|
-
path: options.path,
|
|
1521
|
-
nonce
|
|
1522
|
-
};
|
|
1523
|
-
}
|
|
1524
|
-
return {
|
|
1525
|
-
format: "mso_mdoc",
|
|
1526
|
-
presentation: vpToken,
|
|
1527
|
-
path: options.path
|
|
1528
|
-
};
|
|
1529
1454
|
}
|
|
1530
1455
|
|
|
1531
1456
|
// src/authorization-response/validate-authorization-response.ts
|
|
1532
|
-
function
|
|
1457
|
+
function validateOpenid4vpAuthorizationResponsePayload(options) {
|
|
1533
1458
|
const { requestPayload, responsePayload } = options;
|
|
1534
|
-
if (!responsePayload.vp_token) {
|
|
1535
|
-
throw new Oauth2Error11("Failed to verify OpenId4Vp Authorization Response. vp_token is missing.");
|
|
1536
|
-
}
|
|
1537
1459
|
if ("state" in requestPayload && requestPayload.state !== responsePayload.state) {
|
|
1538
|
-
throw new
|
|
1460
|
+
throw new Oauth2Error10("OpenId4Vp Authorization Response state mismatch.");
|
|
1539
1461
|
}
|
|
1540
1462
|
if (responsePayload.id_token) {
|
|
1541
|
-
throw new
|
|
1463
|
+
throw new Oauth2Error10("OpenId4Vp Authorization Response id_token is not supported.");
|
|
1542
1464
|
}
|
|
1543
1465
|
if (responsePayload.presentation_submission) {
|
|
1544
1466
|
if (!requestPayload.presentation_definition) {
|
|
1545
|
-
throw new
|
|
1546
|
-
}
|
|
1547
|
-
const presentations = parsePresentationsFromVpToken({ vpToken: responsePayload.vp_token });
|
|
1548
|
-
if (presentations.every((p) => p.nonce) && !presentations.every((p) => p.nonce === requestPayload.nonce)) {
|
|
1549
|
-
throw new Oauth2Error11(
|
|
1550
|
-
"Presentation nonce mismatch. The nonce of some presentations does not match the nonce of the request."
|
|
1551
|
-
);
|
|
1467
|
+
throw new Oauth2Error10("OpenId4Vp Authorization Request is missing the required presentation_definition.");
|
|
1552
1468
|
}
|
|
1553
1469
|
return {
|
|
1554
1470
|
type: "pex",
|
|
1555
1471
|
pex: "scope" in requestPayload && requestPayload.scope ? {
|
|
1556
1472
|
scope: requestPayload.scope,
|
|
1557
1473
|
presentationSubmission: responsePayload.presentation_submission,
|
|
1558
|
-
presentations
|
|
1474
|
+
presentations: parsePexVpToken(responsePayload.vp_token)
|
|
1559
1475
|
} : {
|
|
1560
1476
|
presentationDefinition: requestPayload.presentation_definition,
|
|
1561
1477
|
presentationSubmission: responsePayload.presentation_submission,
|
|
1562
|
-
presentations
|
|
1478
|
+
presentations: parsePexVpToken(responsePayload.vp_token)
|
|
1563
1479
|
}
|
|
1564
1480
|
};
|
|
1565
1481
|
}
|
|
1566
1482
|
if (requestPayload.dcql_query) {
|
|
1567
|
-
|
|
1568
|
-
throw new Oauth2Error11(
|
|
1569
|
-
"The OpenId4Vp Authorization Response contains multiple vp_token values. In combination with dcql this is not possible."
|
|
1570
|
-
);
|
|
1571
|
-
}
|
|
1572
|
-
if (typeof responsePayload.vp_token !== "string" && typeof responsePayload.vp_token !== "object") {
|
|
1573
|
-
throw new Oauth2Error11("With DCQL the vp_token must be a JSON-encoded object.");
|
|
1574
|
-
}
|
|
1575
|
-
const presentation = parseDcqlPresentationFromVpToken({ vpToken: responsePayload.vp_token });
|
|
1576
|
-
if (Object.values(presentation).every((p) => p.nonce) && !Object.values(presentation).every((p) => p.nonce === requestPayload.nonce)) {
|
|
1577
|
-
throw new Oauth2Error11(
|
|
1578
|
-
"Presentation nonce mismatch. The nonce of some presentations does not match the nonce of the request."
|
|
1579
|
-
);
|
|
1580
|
-
}
|
|
1483
|
+
const presentations = parseDcqlVpToken(responsePayload.vp_token);
|
|
1581
1484
|
return {
|
|
1582
1485
|
type: "dcql",
|
|
1583
1486
|
dcql: "scope" in requestPayload && requestPayload.scope ? {
|
|
1584
1487
|
scope: requestPayload.scope,
|
|
1585
|
-
|
|
1488
|
+
presentations
|
|
1586
1489
|
} : {
|
|
1587
1490
|
query: requestPayload.dcql_query,
|
|
1588
|
-
|
|
1491
|
+
presentations
|
|
1589
1492
|
}
|
|
1590
1493
|
};
|
|
1591
1494
|
}
|
|
1592
|
-
throw new
|
|
1593
|
-
"Invalid OpenId4Vp Authorization Response. Response neither contains a presentation_submission nor a dcql_query."
|
|
1495
|
+
throw new Oauth2Error10(
|
|
1496
|
+
"Invalid OpenId4Vp Authorization Response. Response neither contains a presentation_submission nor request contains a dcql_query."
|
|
1594
1497
|
);
|
|
1595
1498
|
}
|
|
1596
1499
|
|
|
1597
1500
|
// src/authorization-response/parse-authorization-response.ts
|
|
1598
|
-
import { Oauth2Error as
|
|
1501
|
+
import { Oauth2Error as Oauth2Error12, Oauth2ServerErrorResponseError as Oauth2ServerErrorResponseError12 } from "@openid4vc/oauth2";
|
|
1599
1502
|
|
|
1600
1503
|
// src/authorization-response/parse-authorization-response-payload.ts
|
|
1601
1504
|
import { parseWithErrorHandling as parseWithErrorHandling6 } from "@openid4vc/utils";
|
|
@@ -1603,16 +1506,17 @@ import { parseWithErrorHandling as parseWithErrorHandling6 } from "@openid4vc/ut
|
|
|
1603
1506
|
// src/authorization-response/z-authorization-response.ts
|
|
1604
1507
|
import { z as z19 } from "zod";
|
|
1605
1508
|
|
|
1606
|
-
// src/
|
|
1509
|
+
// src/models/z-pex.ts
|
|
1607
1510
|
import { z as z18 } from "zod";
|
|
1608
|
-
var
|
|
1511
|
+
var zPexPresentationDefinition = z18.record(z18.any());
|
|
1512
|
+
var zPexPresentationSubmission = z18.record(z18.any());
|
|
1609
1513
|
|
|
1610
1514
|
// src/authorization-response/z-authorization-response.ts
|
|
1611
1515
|
var zOpenid4vpAuthorizationResponse = z19.object({
|
|
1612
1516
|
state: z19.string().optional(),
|
|
1613
1517
|
id_token: z19.string().optional(),
|
|
1614
1518
|
vp_token: zVpToken,
|
|
1615
|
-
presentation_submission:
|
|
1519
|
+
presentation_submission: zPexPresentationSubmission.optional(),
|
|
1616
1520
|
refresh_token: z19.string().optional(),
|
|
1617
1521
|
token_type: z19.string().optional(),
|
|
1618
1522
|
access_token: z19.string().optional(),
|
|
@@ -1629,24 +1533,17 @@ function parseOpenid4VpAuthorizationResponsePayload(payload) {
|
|
|
1629
1533
|
}
|
|
1630
1534
|
|
|
1631
1535
|
// src/authorization-response/parse-jarm-authorization-response.ts
|
|
1632
|
-
import {
|
|
1633
|
-
Oauth2Error as Oauth2Error12,
|
|
1634
|
-
decodeJwtHeader as decodeJwtHeader2,
|
|
1635
|
-
zCompactJwe as zCompactJwe3,
|
|
1636
|
-
zCompactJwt as zCompactJwt4,
|
|
1637
|
-
zJwtHeader as zJwtHeader2
|
|
1638
|
-
} from "@openid4vc/oauth2";
|
|
1536
|
+
import { Oauth2Error as Oauth2Error11, decodeJwtHeader as decodeJwtHeader2, zCompactJwe as zCompactJwe3, zCompactJwt as zCompactJwt3 } from "@openid4vc/oauth2";
|
|
1639
1537
|
import { decodeBase64 as decodeBase642, encodeToUtf8String as encodeToUtf8String2, parseWithErrorHandling as parseWithErrorHandling7 } from "@openid4vc/utils";
|
|
1640
1538
|
import z20 from "zod";
|
|
1641
1539
|
async function parseJarmAuthorizationResponse(options) {
|
|
1642
1540
|
const { jarmResponseJwt, callbacks } = options;
|
|
1643
1541
|
const jarmAuthorizationResponseJwt = parseWithErrorHandling7(
|
|
1644
|
-
z20.union([
|
|
1542
|
+
z20.union([zCompactJwt3, zCompactJwe3]),
|
|
1645
1543
|
jarmResponseJwt,
|
|
1646
1544
|
"Invalid jarm authorization response jwt."
|
|
1647
1545
|
);
|
|
1648
1546
|
const verifiedJarmResponse = await verifyJarmAuthorizationResponse({ jarmAuthorizationResponseJwt, callbacks });
|
|
1649
|
-
const zJarmHeader = z20.object({ ...zJwtHeader2.shape, apu: z20.string().optional(), apv: z20.string().optional() });
|
|
1650
1547
|
const { header: jarmHeader } = decodeJwtHeader2({
|
|
1651
1548
|
jwt: jarmAuthorizationResponseJwt,
|
|
1652
1549
|
headerSchema: zJarmHeader
|
|
@@ -1655,17 +1552,17 @@ async function parseJarmAuthorizationResponse(options) {
|
|
|
1655
1552
|
authorizationRequest: verifiedJarmResponse.authorizationRequest
|
|
1656
1553
|
});
|
|
1657
1554
|
if (parsedAuthorizationRequest.type !== "openid4vp" && parsedAuthorizationRequest.type !== "openid4vp_dc_api") {
|
|
1658
|
-
throw new
|
|
1555
|
+
throw new Oauth2Error11("Invalid authorization request. Could not parse openid4vp authorization request.");
|
|
1659
1556
|
}
|
|
1660
|
-
const
|
|
1661
|
-
const validateOpenId4vpResponse =
|
|
1557
|
+
const authorizationResponsePayload = parseOpenid4VpAuthorizationResponsePayload(verifiedJarmResponse.jarmAuthResponse);
|
|
1558
|
+
const validateOpenId4vpResponse = validateOpenid4vpAuthorizationResponsePayload({
|
|
1662
1559
|
requestPayload: parsedAuthorizationRequest.params,
|
|
1663
|
-
responsePayload:
|
|
1560
|
+
responsePayload: authorizationResponsePayload
|
|
1664
1561
|
});
|
|
1665
|
-
const
|
|
1666
|
-
if (!
|
|
1667
|
-
throw new
|
|
1668
|
-
`Invalid response mode for jarm response. Response mode: '${
|
|
1562
|
+
const authorizationRequestPayload = parsedAuthorizationRequest.params;
|
|
1563
|
+
if (!authorizationRequestPayload.response_mode || !isJarmResponseMode(authorizationRequestPayload.response_mode)) {
|
|
1564
|
+
throw new Oauth2Error11(
|
|
1565
|
+
`Invalid response mode for jarm response. Response mode: '${authorizationRequestPayload.response_mode ?? "fragment"}'`
|
|
1669
1566
|
);
|
|
1670
1567
|
}
|
|
1671
1568
|
let mdocGeneratedNonce = void 0;
|
|
@@ -1674,15 +1571,16 @@ async function parseJarmAuthorizationResponse(options) {
|
|
|
1674
1571
|
}
|
|
1675
1572
|
if (jarmHeader?.apv) {
|
|
1676
1573
|
const jarmRequestNonce = encodeToUtf8String2(decodeBase642(jarmHeader.apv));
|
|
1677
|
-
if (jarmRequestNonce !==
|
|
1678
|
-
throw new
|
|
1574
|
+
if (jarmRequestNonce !== authorizationRequestPayload.nonce) {
|
|
1575
|
+
throw new Oauth2Error11("The nonce in the jarm header does not match the nonce in the request.");
|
|
1679
1576
|
}
|
|
1680
1577
|
}
|
|
1681
1578
|
return {
|
|
1682
1579
|
...validateOpenId4vpResponse,
|
|
1683
1580
|
jarm: { ...verifiedJarmResponse, jarmHeader, mdocGeneratedNonce },
|
|
1684
|
-
|
|
1685
|
-
|
|
1581
|
+
expectedNonce: authorizationRequestPayload.nonce,
|
|
1582
|
+
authorizationResponsePayload,
|
|
1583
|
+
authorizationRequestPayload
|
|
1686
1584
|
};
|
|
1687
1585
|
}
|
|
1688
1586
|
|
|
@@ -1692,18 +1590,18 @@ async function parseOpenid4vpAuthorizationResponse(options) {
|
|
|
1692
1590
|
if (responsePayload.response) {
|
|
1693
1591
|
return parseJarmAuthorizationResponse({ jarmResponseJwt: responsePayload.response, callbacks });
|
|
1694
1592
|
}
|
|
1695
|
-
const
|
|
1696
|
-
const { authorizationRequest } = await callbacks.getOpenid4vpAuthorizationRequest(
|
|
1593
|
+
const authorizationResponsePayload = parseOpenid4VpAuthorizationResponsePayload(responsePayload);
|
|
1594
|
+
const { authorizationRequest } = await callbacks.getOpenid4vpAuthorizationRequest(authorizationResponsePayload);
|
|
1697
1595
|
const parsedAuthRequest = parseOpenid4vpAuthorizationRequestPayload({ authorizationRequest });
|
|
1698
1596
|
if (parsedAuthRequest.type !== "openid4vp" && parsedAuthRequest.type !== "openid4vp_dc_api") {
|
|
1699
|
-
throw new
|
|
1597
|
+
throw new Oauth2Error12("Invalid authorization request. Could not parse openid4vp authorization request.");
|
|
1700
1598
|
}
|
|
1701
|
-
const
|
|
1702
|
-
const validateOpenId4vpResponse =
|
|
1703
|
-
requestPayload:
|
|
1704
|
-
responsePayload:
|
|
1599
|
+
const authorizationRequestPayload = parsedAuthRequest.params;
|
|
1600
|
+
const validateOpenId4vpResponse = validateOpenid4vpAuthorizationResponsePayload({
|
|
1601
|
+
requestPayload: authorizationRequestPayload,
|
|
1602
|
+
responsePayload: authorizationResponsePayload
|
|
1705
1603
|
});
|
|
1706
|
-
if (
|
|
1604
|
+
if (authorizationRequestPayload.response_mode && isJarmResponseMode(authorizationRequestPayload.response_mode)) {
|
|
1707
1605
|
throw new Oauth2ServerErrorResponseError12(
|
|
1708
1606
|
{
|
|
1709
1607
|
error: "invalid_request",
|
|
@@ -1716,8 +1614,9 @@ async function parseOpenid4vpAuthorizationResponse(options) {
|
|
|
1716
1614
|
}
|
|
1717
1615
|
return {
|
|
1718
1616
|
...validateOpenId4vpResponse,
|
|
1719
|
-
|
|
1720
|
-
|
|
1617
|
+
expectedNonce: authorizationRequestPayload.nonce,
|
|
1618
|
+
authorizationResponsePayload,
|
|
1619
|
+
authorizationRequestPayload,
|
|
1721
1620
|
jarm: void 0
|
|
1722
1621
|
};
|
|
1723
1622
|
}
|
|
@@ -1755,11 +1654,14 @@ var Openid4vpVerifier = class {
|
|
|
1755
1654
|
parseOpenid4vpAuthorizationResponse(options) {
|
|
1756
1655
|
return parseOpenid4vpAuthorizationResponse(options);
|
|
1757
1656
|
}
|
|
1758
|
-
|
|
1759
|
-
return
|
|
1657
|
+
validateOpenid4vpAuthorizationResponsePayload(options) {
|
|
1658
|
+
return validateOpenid4vpAuthorizationResponsePayload(options);
|
|
1659
|
+
}
|
|
1660
|
+
parsePexVpToken(vpToken) {
|
|
1661
|
+
return parsePexVpToken(vpToken);
|
|
1760
1662
|
}
|
|
1761
|
-
|
|
1762
|
-
return
|
|
1663
|
+
parseDcqlVpToken(vpToken) {
|
|
1664
|
+
return parseDcqlVpToken(vpToken);
|
|
1763
1665
|
}
|
|
1764
1666
|
parseTransactionData(options) {
|
|
1765
1667
|
return parseTransactionData(options);
|
|
@@ -1780,15 +1682,16 @@ export {
|
|
|
1780
1682
|
createOpenid4vpAuthorizationResponse,
|
|
1781
1683
|
isJarmResponseMode,
|
|
1782
1684
|
isOpenid4vpAuthorizationRequestDcApi,
|
|
1685
|
+
parseDcqlVpToken,
|
|
1783
1686
|
parseJarmAuthorizationResponse,
|
|
1784
1687
|
parseOpenid4vpAuthorizationRequestPayload,
|
|
1785
1688
|
parseOpenid4vpAuthorizationResponse,
|
|
1786
|
-
|
|
1689
|
+
parsePexVpToken,
|
|
1787
1690
|
parseTransactionData,
|
|
1788
1691
|
resolveOpenid4vpAuthorizationRequest,
|
|
1789
1692
|
submitOpenid4vpAuthorizationResponse,
|
|
1790
1693
|
validateOpenid4vpAuthorizationRequestPayload,
|
|
1791
|
-
|
|
1694
|
+
validateOpenid4vpAuthorizationResponsePayload,
|
|
1792
1695
|
verifyJarmAuthorizationResponse,
|
|
1793
1696
|
zClientIdScheme,
|
|
1794
1697
|
zClientMetadata,
|