@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.js
CHANGED
|
@@ -36,15 +36,16 @@ __export(src_exports, {
|
|
|
36
36
|
createOpenid4vpAuthorizationResponse: () => createOpenid4vpAuthorizationResponse,
|
|
37
37
|
isJarmResponseMode: () => isJarmResponseMode,
|
|
38
38
|
isOpenid4vpAuthorizationRequestDcApi: () => isOpenid4vpAuthorizationRequestDcApi,
|
|
39
|
+
parseDcqlVpToken: () => parseDcqlVpToken,
|
|
39
40
|
parseJarmAuthorizationResponse: () => parseJarmAuthorizationResponse,
|
|
40
41
|
parseOpenid4vpAuthorizationRequestPayload: () => parseOpenid4vpAuthorizationRequestPayload,
|
|
41
42
|
parseOpenid4vpAuthorizationResponse: () => parseOpenid4vpAuthorizationResponse,
|
|
42
|
-
|
|
43
|
+
parsePexVpToken: () => parsePexVpToken,
|
|
43
44
|
parseTransactionData: () => parseTransactionData,
|
|
44
45
|
resolveOpenid4vpAuthorizationRequest: () => resolveOpenid4vpAuthorizationRequest,
|
|
45
46
|
submitOpenid4vpAuthorizationResponse: () => submitOpenid4vpAuthorizationResponse,
|
|
46
47
|
validateOpenid4vpAuthorizationRequestPayload: () => validateOpenid4vpAuthorizationRequestPayload,
|
|
47
|
-
|
|
48
|
+
validateOpenid4vpAuthorizationResponsePayload: () => validateOpenid4vpAuthorizationResponsePayload,
|
|
48
49
|
verifyJarmAuthorizationResponse: () => verifyJarmAuthorizationResponse,
|
|
49
50
|
zClientIdScheme: () => zClientIdScheme,
|
|
50
51
|
zClientMetadata: () => zClientMetadata,
|
|
@@ -80,6 +81,7 @@ var import_utils = require("@openid4vc/utils");
|
|
|
80
81
|
// src/jarm/jarm-auth-response/z-jarm-auth-response.ts
|
|
81
82
|
var import_oauth2 = require("@openid4vc/oauth2");
|
|
82
83
|
var import_zod2 = require("zod");
|
|
84
|
+
var zJarmHeader = import_zod2.z.object({ ...import_oauth2.zJwtHeader.shape, apu: import_zod2.z.string().optional(), apv: import_zod2.z.string().optional() });
|
|
83
85
|
var zJarmAuthResponse = import_zod2.z.object({
|
|
84
86
|
/**
|
|
85
87
|
* iss: The issuer URL of the authorization server that created the response
|
|
@@ -1238,8 +1240,10 @@ function extractJwksFromClientMetadata(clientMetadata) {
|
|
|
1238
1240
|
const parsed = zJarmClientMetadataParsed.parse(clientMetadata);
|
|
1239
1241
|
const encryptionAlg = parsed.client_metadata.authorization_encrypted_response_enc;
|
|
1240
1242
|
const signingAlg = parsed.client_metadata.authorization_signed_response_alg;
|
|
1241
|
-
const encJwk = clientMetadata.jwks.keys.find((key) => key.use === "enc" && key.alg === encryptionAlg) ?? clientMetadata.jwks.keys.find((key) => key.use === "enc")
|
|
1242
|
-
|
|
1243
|
+
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
|
|
1244
|
+
clientMetadata.jwks.keys?.[0];
|
|
1245
|
+
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
|
|
1246
|
+
clientMetadata.jwks.keys?.[0];
|
|
1243
1247
|
return { encJwk, sigJwk };
|
|
1244
1248
|
}
|
|
1245
1249
|
|
|
@@ -1445,190 +1449,90 @@ async function submitOpenid4vpAuthorizationResponse(options) {
|
|
|
1445
1449
|
}
|
|
1446
1450
|
|
|
1447
1451
|
// src/authorization-response/validate-authorization-response.ts
|
|
1448
|
-
var import_oauth227 = require("@openid4vc/oauth2");
|
|
1449
|
-
|
|
1450
|
-
// src/vp-token/parse-presentations-from-vp-token.ts
|
|
1451
1452
|
var import_oauth225 = require("@openid4vc/oauth2");
|
|
1452
|
-
|
|
1453
|
+
|
|
1454
|
+
// src/vp-token/parse-vp-token.ts
|
|
1453
1455
|
var import_utils18 = require("@openid4vc/utils");
|
|
1456
|
+
|
|
1457
|
+
// src/vp-token/z-vp-token.ts
|
|
1454
1458
|
var import_zod17 = require("zod");
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
return vpToken.map((token, idx) => parseSinglePresentationFromVpToken({ vpToken: token, path: `$[${idx}]` }));
|
|
1463
|
-
}
|
|
1464
|
-
if (typeof vpToken === "string" || typeof vpToken === "object") {
|
|
1465
|
-
return [parseSinglePresentationFromVpToken({ vpToken, path: "$" })];
|
|
1459
|
+
var zVpTokenPexEntry = import_zod17.z.union([import_zod17.z.string(), import_zod17.z.record(import_zod17.z.any())], {
|
|
1460
|
+
message: "pex vp_token entry must be a string or object"
|
|
1461
|
+
});
|
|
1462
|
+
var zVpTokenPex = import_zod17.z.union(
|
|
1463
|
+
[zVpTokenPexEntry, import_zod17.z.array(zVpTokenPexEntry).nonempty("Must have at least entry in vp_token array")],
|
|
1464
|
+
{
|
|
1465
|
+
message: "pex vp_token must be a string, object or array of strings and objects"
|
|
1466
1466
|
}
|
|
1467
|
-
|
|
1468
|
-
|
|
1467
|
+
);
|
|
1468
|
+
var zVpTokenDcql = import_zod17.z.record(import_zod17.z.union([import_zod17.z.string(), import_zod17.z.record(import_zod17.z.any())]), {
|
|
1469
|
+
message: "dcql vp_token must be an object with keys referencing the dcql credential query id, and values the encoded (string or object) presentation"
|
|
1470
|
+
});
|
|
1471
|
+
var zVpToken = zVpTokenDcql.or(zVpTokenPex);
|
|
1472
|
+
|
|
1473
|
+
// src/vp-token/parse-vp-token.ts
|
|
1474
|
+
function parsePexVpToken(vpToken) {
|
|
1475
|
+
const parsedVpToken = (0, import_utils18.parseWithErrorHandling)(
|
|
1476
|
+
zVpTokenPex,
|
|
1477
|
+
(0, import_utils18.parseIfJson)(vpToken),
|
|
1478
|
+
"Could not parse presentation exchange vp_token. Expected a string or an array of strings"
|
|
1469
1479
|
);
|
|
1480
|
+
return Array.isArray(parsedVpToken) ? parsedVpToken : [parsedVpToken];
|
|
1470
1481
|
}
|
|
1471
|
-
function
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
Object.entries(parsed).map(([key, value]) => {
|
|
1477
|
-
return [key, parseSinglePresentationFromVpToken({ vpToken: value })];
|
|
1478
|
-
})
|
|
1482
|
+
function parseDcqlVpToken(vpToken) {
|
|
1483
|
+
return (0, import_utils18.parseWithErrorHandling)(
|
|
1484
|
+
zVpTokenDcql,
|
|
1485
|
+
(0, import_utils18.parseIfJson)(vpToken),
|
|
1486
|
+
"Could not parse dcql vp_token. Expected an object where the values are encoded presentations"
|
|
1479
1487
|
);
|
|
1480
|
-
return dcqlPresentationRecord;
|
|
1481
|
-
}
|
|
1482
|
-
function parseSinglePresentationFromVpToken(options) {
|
|
1483
|
-
const { vpToken: _vpToken, path } = options;
|
|
1484
|
-
const vpToken = (0, import_utils18.parseIfJson)(_vpToken);
|
|
1485
|
-
const zLdpVpProof = import_zod17.z.object({ challenge: import_zod17.z.string().optional() }).passthrough();
|
|
1486
|
-
const ldpVpParseResult = import_zod17.z.object({
|
|
1487
|
-
"@context": import_zod17.z.string().optional(),
|
|
1488
|
-
verifiableCredential: import_zod17.z.string().optional(),
|
|
1489
|
-
proof: import_zod17.z.union([zLdpVpProof, import_zod17.z.array(zLdpVpProof)]).optional()
|
|
1490
|
-
}).passthrough().safeParse(vpToken);
|
|
1491
|
-
if (ldpVpParseResult.success && (ldpVpParseResult.data["@context"] || ldpVpParseResult.data.verifiableCredential)) {
|
|
1492
|
-
const challenge = Array.isArray(ldpVpParseResult.data.proof) ? ldpVpParseResult.data.proof.map((proof) => proof.challenge) : ldpVpParseResult.data.proof?.challenge;
|
|
1493
|
-
if (Array.isArray(challenge)) {
|
|
1494
|
-
const allNoncesAreTheSame = challenge.every((nonce) => nonce === challenge[0]);
|
|
1495
|
-
if (!allNoncesAreTheSame) {
|
|
1496
|
-
throw new import_oauth225.Oauth2Error(
|
|
1497
|
-
"Failed to parse presentation from vp_token. LDP presentation is missing the proof.challenge parameter."
|
|
1498
|
-
);
|
|
1499
|
-
}
|
|
1500
|
-
}
|
|
1501
|
-
if (!challenge) {
|
|
1502
|
-
throw new import_oauth225.Oauth2Error(
|
|
1503
|
-
"Failed to parse presentation from vp_token. LDP presentation is missing the proof.challenge parameter."
|
|
1504
|
-
);
|
|
1505
|
-
}
|
|
1506
|
-
return {
|
|
1507
|
-
format: "ldp_vp",
|
|
1508
|
-
presentation: ldpVpParseResult,
|
|
1509
|
-
path,
|
|
1510
|
-
nonce: Array.isArray(challenge) ? challenge[0] : challenge
|
|
1511
|
-
};
|
|
1512
|
-
}
|
|
1513
|
-
if ((0, import_utils18.isObject)(vpToken) && (vpToken.schema_id || vpToken.cred_def_id)) {
|
|
1514
|
-
return {
|
|
1515
|
-
format: "ac_vp",
|
|
1516
|
-
presentation: vpToken,
|
|
1517
|
-
path: options.path
|
|
1518
|
-
};
|
|
1519
|
-
}
|
|
1520
|
-
if (typeof vpToken !== "string") {
|
|
1521
|
-
throw new import_oauth225.Oauth2Error(
|
|
1522
|
-
`Could not parse vp_token. Expected a string since the vp_token is neither a ldp_vp nor an ac_vp. Received: ${typeof vpToken}`
|
|
1523
|
-
);
|
|
1524
|
-
}
|
|
1525
|
-
if (vpToken.includes("~")) {
|
|
1526
|
-
const split = vpToken.split("~");
|
|
1527
|
-
const keyBindingJwt = split[split.length - 1];
|
|
1528
|
-
let nonce;
|
|
1529
|
-
try {
|
|
1530
|
-
const decoded = (0, import_oauth225.decodeJwt)({ jwt: keyBindingJwt });
|
|
1531
|
-
nonce = decoded.payload.nonce;
|
|
1532
|
-
} catch (error) {
|
|
1533
|
-
nonce = void 0;
|
|
1534
|
-
}
|
|
1535
|
-
return {
|
|
1536
|
-
format: "dc+sd-jwt",
|
|
1537
|
-
presentation: vpToken,
|
|
1538
|
-
path: options.path
|
|
1539
|
-
};
|
|
1540
|
-
}
|
|
1541
|
-
const result = import_oauth226.zCompactJwt.safeParse(vpToken);
|
|
1542
|
-
if (result.success) {
|
|
1543
|
-
let nonce;
|
|
1544
|
-
try {
|
|
1545
|
-
const decoded = (0, import_oauth225.decodeJwt)({ jwt: vpToken });
|
|
1546
|
-
nonce = decoded.payload.nonce;
|
|
1547
|
-
} catch (error) {
|
|
1548
|
-
nonce = void 0;
|
|
1549
|
-
}
|
|
1550
|
-
return {
|
|
1551
|
-
format: "jwt_vp_json",
|
|
1552
|
-
presentation: vpToken,
|
|
1553
|
-
path: options.path,
|
|
1554
|
-
nonce
|
|
1555
|
-
};
|
|
1556
|
-
}
|
|
1557
|
-
return {
|
|
1558
|
-
format: "mso_mdoc",
|
|
1559
|
-
presentation: vpToken,
|
|
1560
|
-
path: options.path
|
|
1561
|
-
};
|
|
1562
1488
|
}
|
|
1563
1489
|
|
|
1564
1490
|
// src/authorization-response/validate-authorization-response.ts
|
|
1565
|
-
function
|
|
1491
|
+
function validateOpenid4vpAuthorizationResponsePayload(options) {
|
|
1566
1492
|
const { requestPayload, responsePayload } = options;
|
|
1567
|
-
if (!responsePayload.vp_token) {
|
|
1568
|
-
throw new import_oauth227.Oauth2Error("Failed to verify OpenId4Vp Authorization Response. vp_token is missing.");
|
|
1569
|
-
}
|
|
1570
1493
|
if ("state" in requestPayload && requestPayload.state !== responsePayload.state) {
|
|
1571
|
-
throw new
|
|
1494
|
+
throw new import_oauth225.Oauth2Error("OpenId4Vp Authorization Response state mismatch.");
|
|
1572
1495
|
}
|
|
1573
1496
|
if (responsePayload.id_token) {
|
|
1574
|
-
throw new
|
|
1497
|
+
throw new import_oauth225.Oauth2Error("OpenId4Vp Authorization Response id_token is not supported.");
|
|
1575
1498
|
}
|
|
1576
1499
|
if (responsePayload.presentation_submission) {
|
|
1577
1500
|
if (!requestPayload.presentation_definition) {
|
|
1578
|
-
throw new
|
|
1579
|
-
}
|
|
1580
|
-
const presentations = parsePresentationsFromVpToken({ vpToken: responsePayload.vp_token });
|
|
1581
|
-
if (presentations.every((p) => p.nonce) && !presentations.every((p) => p.nonce === requestPayload.nonce)) {
|
|
1582
|
-
throw new import_oauth227.Oauth2Error(
|
|
1583
|
-
"Presentation nonce mismatch. The nonce of some presentations does not match the nonce of the request."
|
|
1584
|
-
);
|
|
1501
|
+
throw new import_oauth225.Oauth2Error("OpenId4Vp Authorization Request is missing the required presentation_definition.");
|
|
1585
1502
|
}
|
|
1586
1503
|
return {
|
|
1587
1504
|
type: "pex",
|
|
1588
1505
|
pex: "scope" in requestPayload && requestPayload.scope ? {
|
|
1589
1506
|
scope: requestPayload.scope,
|
|
1590
1507
|
presentationSubmission: responsePayload.presentation_submission,
|
|
1591
|
-
presentations
|
|
1508
|
+
presentations: parsePexVpToken(responsePayload.vp_token)
|
|
1592
1509
|
} : {
|
|
1593
1510
|
presentationDefinition: requestPayload.presentation_definition,
|
|
1594
1511
|
presentationSubmission: responsePayload.presentation_submission,
|
|
1595
|
-
presentations
|
|
1512
|
+
presentations: parsePexVpToken(responsePayload.vp_token)
|
|
1596
1513
|
}
|
|
1597
1514
|
};
|
|
1598
1515
|
}
|
|
1599
1516
|
if (requestPayload.dcql_query) {
|
|
1600
|
-
|
|
1601
|
-
throw new import_oauth227.Oauth2Error(
|
|
1602
|
-
"The OpenId4Vp Authorization Response contains multiple vp_token values. In combination with dcql this is not possible."
|
|
1603
|
-
);
|
|
1604
|
-
}
|
|
1605
|
-
if (typeof responsePayload.vp_token !== "string" && typeof responsePayload.vp_token !== "object") {
|
|
1606
|
-
throw new import_oauth227.Oauth2Error("With DCQL the vp_token must be a JSON-encoded object.");
|
|
1607
|
-
}
|
|
1608
|
-
const presentation = parseDcqlPresentationFromVpToken({ vpToken: responsePayload.vp_token });
|
|
1609
|
-
if (Object.values(presentation).every((p) => p.nonce) && !Object.values(presentation).every((p) => p.nonce === requestPayload.nonce)) {
|
|
1610
|
-
throw new import_oauth227.Oauth2Error(
|
|
1611
|
-
"Presentation nonce mismatch. The nonce of some presentations does not match the nonce of the request."
|
|
1612
|
-
);
|
|
1613
|
-
}
|
|
1517
|
+
const presentations = parseDcqlVpToken(responsePayload.vp_token);
|
|
1614
1518
|
return {
|
|
1615
1519
|
type: "dcql",
|
|
1616
1520
|
dcql: "scope" in requestPayload && requestPayload.scope ? {
|
|
1617
1521
|
scope: requestPayload.scope,
|
|
1618
|
-
|
|
1522
|
+
presentations
|
|
1619
1523
|
} : {
|
|
1620
1524
|
query: requestPayload.dcql_query,
|
|
1621
|
-
|
|
1525
|
+
presentations
|
|
1622
1526
|
}
|
|
1623
1527
|
};
|
|
1624
1528
|
}
|
|
1625
|
-
throw new
|
|
1626
|
-
"Invalid OpenId4Vp Authorization Response. Response neither contains a presentation_submission nor a dcql_query."
|
|
1529
|
+
throw new import_oauth225.Oauth2Error(
|
|
1530
|
+
"Invalid OpenId4Vp Authorization Response. Response neither contains a presentation_submission nor request contains a dcql_query."
|
|
1627
1531
|
);
|
|
1628
1532
|
}
|
|
1629
1533
|
|
|
1630
1534
|
// src/authorization-response/parse-authorization-response.ts
|
|
1631
|
-
var
|
|
1535
|
+
var import_oauth227 = require("@openid4vc/oauth2");
|
|
1632
1536
|
|
|
1633
1537
|
// src/authorization-response/parse-authorization-response-payload.ts
|
|
1634
1538
|
var import_utils19 = require("@openid4vc/utils");
|
|
@@ -1636,16 +1540,17 @@ var import_utils19 = require("@openid4vc/utils");
|
|
|
1636
1540
|
// src/authorization-response/z-authorization-response.ts
|
|
1637
1541
|
var import_zod19 = require("zod");
|
|
1638
1542
|
|
|
1639
|
-
// src/
|
|
1543
|
+
// src/models/z-pex.ts
|
|
1640
1544
|
var import_zod18 = require("zod");
|
|
1641
|
-
var
|
|
1545
|
+
var zPexPresentationDefinition = import_zod18.z.record(import_zod18.z.any());
|
|
1546
|
+
var zPexPresentationSubmission = import_zod18.z.record(import_zod18.z.any());
|
|
1642
1547
|
|
|
1643
1548
|
// src/authorization-response/z-authorization-response.ts
|
|
1644
1549
|
var zOpenid4vpAuthorizationResponse = import_zod19.z.object({
|
|
1645
1550
|
state: import_zod19.z.string().optional(),
|
|
1646
1551
|
id_token: import_zod19.z.string().optional(),
|
|
1647
1552
|
vp_token: zVpToken,
|
|
1648
|
-
presentation_submission:
|
|
1553
|
+
presentation_submission: zPexPresentationSubmission.optional(),
|
|
1649
1554
|
refresh_token: import_zod19.z.string().optional(),
|
|
1650
1555
|
token_type: import_zod19.z.string().optional(),
|
|
1651
1556
|
access_token: import_zod19.z.string().optional(),
|
|
@@ -1662,19 +1567,18 @@ function parseOpenid4VpAuthorizationResponsePayload(payload) {
|
|
|
1662
1567
|
}
|
|
1663
1568
|
|
|
1664
1569
|
// src/authorization-response/parse-jarm-authorization-response.ts
|
|
1665
|
-
var
|
|
1570
|
+
var import_oauth226 = require("@openid4vc/oauth2");
|
|
1666
1571
|
var import_utils20 = require("@openid4vc/utils");
|
|
1667
1572
|
var import_zod20 = __toESM(require("zod"));
|
|
1668
1573
|
async function parseJarmAuthorizationResponse(options) {
|
|
1669
1574
|
const { jarmResponseJwt, callbacks } = options;
|
|
1670
1575
|
const jarmAuthorizationResponseJwt = (0, import_utils20.parseWithErrorHandling)(
|
|
1671
|
-
import_zod20.default.union([
|
|
1576
|
+
import_zod20.default.union([import_oauth226.zCompactJwt, import_oauth226.zCompactJwe]),
|
|
1672
1577
|
jarmResponseJwt,
|
|
1673
1578
|
"Invalid jarm authorization response jwt."
|
|
1674
1579
|
);
|
|
1675
1580
|
const verifiedJarmResponse = await verifyJarmAuthorizationResponse({ jarmAuthorizationResponseJwt, callbacks });
|
|
1676
|
-
const
|
|
1677
|
-
const { header: jarmHeader } = (0, import_oauth228.decodeJwtHeader)({
|
|
1581
|
+
const { header: jarmHeader } = (0, import_oauth226.decodeJwtHeader)({
|
|
1678
1582
|
jwt: jarmAuthorizationResponseJwt,
|
|
1679
1583
|
headerSchema: zJarmHeader
|
|
1680
1584
|
});
|
|
@@ -1682,17 +1586,17 @@ async function parseJarmAuthorizationResponse(options) {
|
|
|
1682
1586
|
authorizationRequest: verifiedJarmResponse.authorizationRequest
|
|
1683
1587
|
});
|
|
1684
1588
|
if (parsedAuthorizationRequest.type !== "openid4vp" && parsedAuthorizationRequest.type !== "openid4vp_dc_api") {
|
|
1685
|
-
throw new
|
|
1589
|
+
throw new import_oauth226.Oauth2Error("Invalid authorization request. Could not parse openid4vp authorization request.");
|
|
1686
1590
|
}
|
|
1687
|
-
const
|
|
1688
|
-
const validateOpenId4vpResponse =
|
|
1591
|
+
const authorizationResponsePayload = parseOpenid4VpAuthorizationResponsePayload(verifiedJarmResponse.jarmAuthResponse);
|
|
1592
|
+
const validateOpenId4vpResponse = validateOpenid4vpAuthorizationResponsePayload({
|
|
1689
1593
|
requestPayload: parsedAuthorizationRequest.params,
|
|
1690
|
-
responsePayload:
|
|
1594
|
+
responsePayload: authorizationResponsePayload
|
|
1691
1595
|
});
|
|
1692
|
-
const
|
|
1693
|
-
if (!
|
|
1694
|
-
throw new
|
|
1695
|
-
`Invalid response mode for jarm response. Response mode: '${
|
|
1596
|
+
const authorizationRequestPayload = parsedAuthorizationRequest.params;
|
|
1597
|
+
if (!authorizationRequestPayload.response_mode || !isJarmResponseMode(authorizationRequestPayload.response_mode)) {
|
|
1598
|
+
throw new import_oauth226.Oauth2Error(
|
|
1599
|
+
`Invalid response mode for jarm response. Response mode: '${authorizationRequestPayload.response_mode ?? "fragment"}'`
|
|
1696
1600
|
);
|
|
1697
1601
|
}
|
|
1698
1602
|
let mdocGeneratedNonce = void 0;
|
|
@@ -1701,15 +1605,16 @@ async function parseJarmAuthorizationResponse(options) {
|
|
|
1701
1605
|
}
|
|
1702
1606
|
if (jarmHeader?.apv) {
|
|
1703
1607
|
const jarmRequestNonce = (0, import_utils20.encodeToUtf8String)((0, import_utils20.decodeBase64)(jarmHeader.apv));
|
|
1704
|
-
if (jarmRequestNonce !==
|
|
1705
|
-
throw new
|
|
1608
|
+
if (jarmRequestNonce !== authorizationRequestPayload.nonce) {
|
|
1609
|
+
throw new import_oauth226.Oauth2Error("The nonce in the jarm header does not match the nonce in the request.");
|
|
1706
1610
|
}
|
|
1707
1611
|
}
|
|
1708
1612
|
return {
|
|
1709
1613
|
...validateOpenId4vpResponse,
|
|
1710
1614
|
jarm: { ...verifiedJarmResponse, jarmHeader, mdocGeneratedNonce },
|
|
1711
|
-
|
|
1712
|
-
|
|
1615
|
+
expectedNonce: authorizationRequestPayload.nonce,
|
|
1616
|
+
authorizationResponsePayload,
|
|
1617
|
+
authorizationRequestPayload
|
|
1713
1618
|
};
|
|
1714
1619
|
}
|
|
1715
1620
|
|
|
@@ -1719,19 +1624,19 @@ async function parseOpenid4vpAuthorizationResponse(options) {
|
|
|
1719
1624
|
if (responsePayload.response) {
|
|
1720
1625
|
return parseJarmAuthorizationResponse({ jarmResponseJwt: responsePayload.response, callbacks });
|
|
1721
1626
|
}
|
|
1722
|
-
const
|
|
1723
|
-
const { authorizationRequest } = await callbacks.getOpenid4vpAuthorizationRequest(
|
|
1627
|
+
const authorizationResponsePayload = parseOpenid4VpAuthorizationResponsePayload(responsePayload);
|
|
1628
|
+
const { authorizationRequest } = await callbacks.getOpenid4vpAuthorizationRequest(authorizationResponsePayload);
|
|
1724
1629
|
const parsedAuthRequest = parseOpenid4vpAuthorizationRequestPayload({ authorizationRequest });
|
|
1725
1630
|
if (parsedAuthRequest.type !== "openid4vp" && parsedAuthRequest.type !== "openid4vp_dc_api") {
|
|
1726
|
-
throw new
|
|
1631
|
+
throw new import_oauth227.Oauth2Error("Invalid authorization request. Could not parse openid4vp authorization request.");
|
|
1727
1632
|
}
|
|
1728
|
-
const
|
|
1729
|
-
const validateOpenId4vpResponse =
|
|
1730
|
-
requestPayload:
|
|
1731
|
-
responsePayload:
|
|
1633
|
+
const authorizationRequestPayload = parsedAuthRequest.params;
|
|
1634
|
+
const validateOpenId4vpResponse = validateOpenid4vpAuthorizationResponsePayload({
|
|
1635
|
+
requestPayload: authorizationRequestPayload,
|
|
1636
|
+
responsePayload: authorizationResponsePayload
|
|
1732
1637
|
});
|
|
1733
|
-
if (
|
|
1734
|
-
throw new
|
|
1638
|
+
if (authorizationRequestPayload.response_mode && isJarmResponseMode(authorizationRequestPayload.response_mode)) {
|
|
1639
|
+
throw new import_oauth227.Oauth2ServerErrorResponseError(
|
|
1735
1640
|
{
|
|
1736
1641
|
error: "invalid_request",
|
|
1737
1642
|
error_description: "Invalid response mode for openid4vp response. Expected jarm response."
|
|
@@ -1743,8 +1648,9 @@ async function parseOpenid4vpAuthorizationResponse(options) {
|
|
|
1743
1648
|
}
|
|
1744
1649
|
return {
|
|
1745
1650
|
...validateOpenId4vpResponse,
|
|
1746
|
-
|
|
1747
|
-
|
|
1651
|
+
expectedNonce: authorizationRequestPayload.nonce,
|
|
1652
|
+
authorizationResponsePayload,
|
|
1653
|
+
authorizationRequestPayload,
|
|
1748
1654
|
jarm: void 0
|
|
1749
1655
|
};
|
|
1750
1656
|
}
|
|
@@ -1782,11 +1688,14 @@ var Openid4vpVerifier = class {
|
|
|
1782
1688
|
parseOpenid4vpAuthorizationResponse(options) {
|
|
1783
1689
|
return parseOpenid4vpAuthorizationResponse(options);
|
|
1784
1690
|
}
|
|
1785
|
-
|
|
1786
|
-
return
|
|
1691
|
+
validateOpenid4vpAuthorizationResponsePayload(options) {
|
|
1692
|
+
return validateOpenid4vpAuthorizationResponsePayload(options);
|
|
1693
|
+
}
|
|
1694
|
+
parsePexVpToken(vpToken) {
|
|
1695
|
+
return parsePexVpToken(vpToken);
|
|
1787
1696
|
}
|
|
1788
|
-
|
|
1789
|
-
return
|
|
1697
|
+
parseDcqlVpToken(vpToken) {
|
|
1698
|
+
return parseDcqlVpToken(vpToken);
|
|
1790
1699
|
}
|
|
1791
1700
|
parseTransactionData(options) {
|
|
1792
1701
|
return parseTransactionData(options);
|
|
@@ -1808,15 +1717,16 @@ var zProofFormat = import_zod22.z.enum(["jwt_vp_json", "ldc_vp", "ac_vp", "dc+sd
|
|
|
1808
1717
|
createOpenid4vpAuthorizationResponse,
|
|
1809
1718
|
isJarmResponseMode,
|
|
1810
1719
|
isOpenid4vpAuthorizationRequestDcApi,
|
|
1720
|
+
parseDcqlVpToken,
|
|
1811
1721
|
parseJarmAuthorizationResponse,
|
|
1812
1722
|
parseOpenid4vpAuthorizationRequestPayload,
|
|
1813
1723
|
parseOpenid4vpAuthorizationResponse,
|
|
1814
|
-
|
|
1724
|
+
parsePexVpToken,
|
|
1815
1725
|
parseTransactionData,
|
|
1816
1726
|
resolveOpenid4vpAuthorizationRequest,
|
|
1817
1727
|
submitOpenid4vpAuthorizationResponse,
|
|
1818
1728
|
validateOpenid4vpAuthorizationRequestPayload,
|
|
1819
|
-
|
|
1729
|
+
validateOpenid4vpAuthorizationResponsePayload,
|
|
1820
1730
|
verifyJarmAuthorizationResponse,
|
|
1821
1731
|
zClientIdScheme,
|
|
1822
1732
|
zClientMetadata,
|