@openid4vc/openid4vp 0.3.0-alpha-20250321221213 → 0.3.0-alpha-20250322155633

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.mjs CHANGED
@@ -92,6 +92,8 @@ var zVpFormatsSupported = z2.record(
92
92
 
93
93
  // src/models/z-client-metadata.ts
94
94
  var zClientMetadata = z3.object({
95
+ // Up until draft 22
96
+ jwks_uri: z3.string().url().optional(),
95
97
  jwks: z3.optional(zJwkSet),
96
98
  vp_formats: z3.optional(zVpFormatsSupported),
97
99
  ...zJarmClientMetadata.shape,
@@ -938,15 +940,15 @@ function parseAuthorizationRequestVersion(request) {
938
940
 
939
941
  // src/jar/jar-request-object/fetch-jar-request-object.ts
940
942
  import { Oauth2ErrorCodes as Oauth2ErrorCodes6, Oauth2ServerErrorResponseError as Oauth2ServerErrorResponseError7 } from "@openid4vc/oauth2";
941
- import { ContentType as ContentType2, defaultFetcher, objectToQueryParams as objectToQueryParams2 } from "@openid4vc/utils";
943
+ import { ContentType as ContentType2, createFetcher, objectToQueryParams as objectToQueryParams2 } from "@openid4vc/utils";
942
944
  async function fetchJarRequestObject(options) {
943
- const { requestUri, clientIdentifierScheme, method, wallet, fetch = defaultFetcher } = options;
945
+ const { requestUri, clientIdentifierScheme, method, wallet, fetch } = options;
944
946
  let requestBody = wallet.metadata ? { wallet_metadata: wallet.metadata, wallet_nonce: wallet.nonce } : void 0;
945
947
  if (requestBody?.wallet_metadata?.request_object_signing_alg_values_supported && clientIdentifierScheme === "redirect_uri") {
946
948
  const { request_object_signing_alg_values_supported, ...rest } = requestBody.wallet_metadata;
947
949
  requestBody = { ...requestBody, wallet_metadata: { ...rest } };
948
950
  }
949
- const response = await fetch(requestUri, {
951
+ const response = await createFetcher(fetch)(requestUri, {
950
952
  method,
951
953
  body: method === "POST" ? objectToQueryParams2(wallet.metadata ?? {}) : void 0,
952
954
  headers: {
@@ -1204,7 +1206,8 @@ function validateOpenId4vpAuthorizationRequestPayload(options) {
1204
1206
  import {
1205
1207
  Oauth2Error as Oauth2Error7,
1206
1208
  Oauth2ErrorCodes as Oauth2ErrorCodes10,
1207
- Oauth2ServerErrorResponseError as Oauth2ServerErrorResponseError11
1209
+ Oauth2ServerErrorResponseError as Oauth2ServerErrorResponseError11,
1210
+ fetchJwks
1208
1211
  } from "@openid4vc/oauth2";
1209
1212
  import { dateToSeconds as dateToSeconds3 } from "@openid4vc/utils";
1210
1213
 
@@ -1316,10 +1319,15 @@ async function createOpenid4vpAuthorizationResponse(options) {
1316
1319
  if (!authorizationRequestPayload.client_metadata) {
1317
1320
  throw new Oauth2Error7("Missing client metadata in the request params to assert Jarm metadata support.");
1318
1321
  }
1319
- if (!authorizationRequestPayload.client_metadata.jwks) {
1322
+ let jwks;
1323
+ if (authorizationRequestPayload.client_metadata.jwks) {
1324
+ jwks = authorizationRequestPayload.client_metadata.jwks;
1325
+ } else if (authorizationRequestPayload.client_metadata.jwks_uri) {
1326
+ jwks = await fetchJwks(authorizationRequestPayload.client_metadata.jwks_uri, options.callbacks.fetch);
1327
+ } else {
1320
1328
  throw new Oauth2ServerErrorResponseError11({
1321
1329
  error: Oauth2ErrorCodes10.InvalidRequest,
1322
- error_description: "Missing JWKS in client metadata. Cannot extract encryption JWK."
1330
+ error_description: `Missing 'jwks' or 'jwks_uri' in client metadata. Cannot extract encryption JWK.`
1323
1331
  });
1324
1332
  }
1325
1333
  const supportedJarmMetadata = jarmAssertMetadataSupported({
@@ -1328,7 +1336,7 @@ async function createOpenid4vpAuthorizationResponse(options) {
1328
1336
  });
1329
1337
  const clientMetaJwks = extractJwksFromClientMetadata({
1330
1338
  ...authorizationRequestPayload.client_metadata,
1331
- jwks: authorizationRequestPayload.client_metadata.jwks
1339
+ jwks
1332
1340
  });
1333
1341
  if (!clientMetaJwks?.encJwk) {
1334
1342
  throw new Oauth2ServerErrorResponseError11({
@@ -1385,12 +1393,12 @@ async function createOpenid4vpAuthorizationResponse(options) {
1385
1393
 
1386
1394
  // src/authorization-response/submit-authorization-response.ts
1387
1395
  import { Oauth2Error as Oauth2Error9 } from "@openid4vc/oauth2";
1388
- import { ContentType as ContentType4, defaultFetcher as defaultFetcher3 } from "@openid4vc/utils";
1396
+ import { ContentType as ContentType4, createFetcher as createFetcher3 } from "@openid4vc/utils";
1389
1397
  import { objectToQueryParams as objectToQueryParams3 } from "@openid4vc/utils";
1390
1398
 
1391
1399
  // src/jarm/jarm-authorizatino-response-send.ts
1392
1400
  import { Oauth2Error as Oauth2Error8 } from "@openid4vc/oauth2";
1393
- import { ContentType as ContentType3, URL as URL4, defaultFetcher as defaultFetcher2 } from "@openid4vc/utils";
1401
+ import { ContentType as ContentType3, URL as URL4, createFetcher as createFetcher2 } from "@openid4vc/utils";
1394
1402
  var jarmAuthorizationResponseSend = (options) => {
1395
1403
  const { authorizationRequestPayload, jarmAuthorizationResponseJwt, callbacks } = options;
1396
1404
  const responseEndpoint = authorizationRequestPayload.response_uri ?? authorizationRequestPayload.redirect_uri;
@@ -1401,7 +1409,7 @@ var jarmAuthorizationResponseSend = (options) => {
1401
1409
  return handleDirectPostJwt(responseEndpointUrl, jarmAuthorizationResponseJwt, callbacks);
1402
1410
  };
1403
1411
  async function handleDirectPostJwt(responseEndpoint, responseJwt, callbacks) {
1404
- const response = await (callbacks.fetch ?? defaultFetcher2)(responseEndpoint, {
1412
+ const response = await createFetcher2(callbacks.fetch)(responseEndpoint, {
1405
1413
  method: "POST",
1406
1414
  headers: { "Content-Type": ContentType3.XWwwFormUrlencoded },
1407
1415
  body: `response=${responseJwt}`
@@ -1428,11 +1436,11 @@ async function submitOpenid4vpAuthorizationResponse(options) {
1428
1436
  "Failed to submit OpenId4Vp Authorization Response. No redirect_uri or response_uri provided."
1429
1437
  );
1430
1438
  }
1431
- const fetch = callbacks.fetch ?? defaultFetcher3;
1439
+ const fetch = createFetcher3(callbacks.fetch);
1432
1440
  const encodedResponse = objectToQueryParams3(authorizationResponsePayload);
1433
1441
  const submissionResponse = await fetch(url, {
1434
1442
  method: "POST",
1435
- body: encodedResponse,
1443
+ body: encodedResponse.toString(),
1436
1444
  headers: {
1437
1445
  "Content-Type": ContentType4.XWwwFormUrlencoded
1438
1446
  }