@sphereon/oid4vci-common 0.20.2-next.2 → 0.20.2-next.21

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.cjs CHANGED
@@ -150,7 +150,9 @@ __export(index_exports, {
150
150
  convertJsonToURI: () => convertJsonToURI,
151
151
  convertURIToJsonObject: () => convertURIToJsonObject,
152
152
  createCodeChallenge: () => createCodeChallenge,
153
+ createCwtProofOfPossession: () => createCwtProofOfPossession,
153
154
  createProofOfPossession: () => createProofOfPossession,
155
+ credentialIssuerMetadataFieldNamesV1_0: () => credentialIssuerMetadataFieldNamesV1_0,
154
156
  credentialIssuerMetadataFieldNamesV1_0_15: () => credentialIssuerMetadataFieldNamesV1_0_15,
155
157
  decodeJsonProperties: () => decodeJsonProperties,
156
158
  determineFlowType: () => determineFlowType,
@@ -193,6 +195,7 @@ __export(index_exports, {
193
195
  isW3cCredentialSupported: () => isW3cCredentialSupported,
194
196
  normalizeOfferInput: () => normalizeOfferInput,
195
197
  post: () => post,
198
+ processSignedMetadata: () => processSignedMetadata,
196
199
  resolveCredentialOfferURI: () => resolveCredentialOfferURI,
197
200
  supportedOID4VCICredentialFormat: () => supportedOID4VCICredentialFormat,
198
201
  toAuthorizationResponsePayload: () => toAuthorizationResponsePayload,
@@ -342,6 +345,27 @@ var credentialIssuerMetadataFieldNamesV1_0_15 = [
342
345
  "authorization_challenge_endpoint"
343
346
  ];
344
347
 
348
+ // lib/types/v1_0.types.ts
349
+ init_cjs_shims();
350
+ var credentialIssuerMetadataFieldNamesV1_0 = [
351
+ "credential_issuer",
352
+ "credential_configurations_supported",
353
+ "credential_endpoint",
354
+ "nonce_endpoint",
355
+ "deferred_credential_endpoint",
356
+ "notification_endpoint",
357
+ "credential_response_encryption",
358
+ "batch_credential_issuance_supported",
359
+ "credential_issuer_public_key",
360
+ "authorization_servers",
361
+ "token_endpoint",
362
+ "display",
363
+ "credential_supplier_config",
364
+ "credential_identifiers_supported",
365
+ "signed_metadata",
366
+ "authorization_challenge_endpoint"
367
+ ];
368
+
345
369
  // lib/types/ServerMetadata.ts
346
370
  init_cjs_shims();
347
371
  var authorizationServerMetadataFieldNames = [
@@ -420,6 +444,7 @@ var WRONG_METADATA_FORMAT = "Wrong metadata format";
420
444
  init_cjs_shims();
421
445
  var OpenId4VCIVersion = /* @__PURE__ */ (function(OpenId4VCIVersion2) {
422
446
  OpenId4VCIVersion2[OpenId4VCIVersion2["VER_1_0_15"] = 1015] = "VER_1_0_15";
447
+ OpenId4VCIVersion2[OpenId4VCIVersion2["VER_1_0"] = 1100] = "VER_1_0";
423
448
  OpenId4VCIVersion2[OpenId4VCIVersion2["VER_UNKNOWN"] = Number.MAX_VALUE] = "VER_UNKNOWN";
424
449
  return OpenId4VCIVersion2;
425
450
  })({});
@@ -604,7 +629,8 @@ var adjustUrl = /* @__PURE__ */ __name((urlOrPath, opts) => {
604
629
  // lib/functions/CredentialResponseUtil.ts
605
630
  function isDeferredCredentialResponse(credentialResponse) {
606
631
  const orig = credentialResponse.successBody;
607
- return credentialResponse.origResponse.status % 200 <= 2 && !!orig && !orig.credentials && (!!orig.acceptance_token || !!orig.transaction_id);
632
+ const hasNoCredential = !orig?.credentials && !orig?.credential;
633
+ return credentialResponse.origResponse.status % 200 <= 2 && !!orig && hasNoCredential && (!!orig.acceptance_token || !!orig.transaction_id);
608
634
  }
609
635
  __name(isDeferredCredentialResponse, "isDeferredCredentialResponse");
610
636
  function assertNonFatalError(credentialResponse) {
@@ -642,7 +668,7 @@ async function acquireDeferredCredential({ bearerToken, transactionId, deferredC
642
668
  deferredCredentialEndpoint
643
669
  });
644
670
  const DEFAULT_SLEEP_IN_MS = 5e3;
645
- while (!credentialResponse.successBody?.credentials && deferredCredentialAwait) {
671
+ while (!credentialResponse.successBody?.credentials && !credentialResponse.successBody?.credential && deferredCredentialAwait) {
646
672
  assertNonFatalError(credentialResponse);
647
673
  const pending = isDeferredCredentialIssuancePending(credentialResponse);
648
674
  console.log(`Issuance still pending?: ${pending}`);
@@ -683,7 +709,7 @@ var logger2 = import_ssi_types2.Loggers.DEFAULT.get("sphereon:oid4vci:offer");
683
709
  function determineSpecVersionFromURI(uri) {
684
710
  let version = determineSpecVersionFromScheme(uri, OpenId4VCIVersion.VER_UNKNOWN) ?? OpenId4VCIVersion.VER_UNKNOWN;
685
711
  if (version === OpenId4VCIVersion.VER_UNKNOWN) {
686
- version = OpenId4VCIVersion.VER_1_0_15;
712
+ version = OpenId4VCIVersion.VER_1_0;
687
713
  }
688
714
  return version;
689
715
  }
@@ -815,7 +841,7 @@ var getStateFromCredentialOfferPayload = /* @__PURE__ */ __name((credentialOffer
815
841
  }, "getStateFromCredentialOfferPayload");
816
842
  function determineSpecVersionFromOffer(offer) {
817
843
  if (isCredentialOfferV1_0_15(offer)) {
818
- return OpenId4VCIVersion.VER_1_0_15;
844
+ return OpenId4VCIVersion.VER_1_0;
819
845
  }
820
846
  return OpenId4VCIVersion.VER_UNKNOWN;
821
847
  }
@@ -1197,19 +1223,22 @@ function getTypesFromAuthorizationDetails(authDetails, opts) {
1197
1223
  __name(getTypesFromAuthorizationDetails, "getTypesFromAuthorizationDetails");
1198
1224
  function getTypesFromCredentialSupported(credentialSupported, opts) {
1199
1225
  let types = [];
1200
- if (credentialSupported.format === "jwt_vc_json" || credentialSupported.format === "jwt_vc" || credentialSupported.format === "jwt_vc_json-ld" || credentialSupported.format === "ldp_vc") {
1226
+ const format = credentialSupported.format;
1227
+ if (format === "jwt_vc_json" || format === "jwt_vc" || format === "jwt_vc_json-ld" || format === "ldp_vc") {
1201
1228
  types = getTypesFromObject(credentialSupported) ?? [];
1202
- } else if (credentialSupported.format === "dc+sd-jwt" || credentialSupported.format === "vc+sd-jwt") {
1229
+ } else if (format === "dc+sd-jwt" || format === "vc+sd-jwt") {
1203
1230
  types = [
1204
1231
  credentialSupported.vct
1205
1232
  ];
1206
- } else if (credentialSupported.format === "mso_mdoc") {
1233
+ } else if (format === "mso_mdoc") {
1207
1234
  types = [
1208
1235
  credentialSupported.doctype
1209
1236
  ];
1237
+ } else {
1238
+ throw Error(`Unsupported credential format '${format}'`);
1210
1239
  }
1211
1240
  if (!types || types.length === 0) {
1212
- throw Error("Could not deduce types from credential supported");
1241
+ throw Error(`Could not deduce types from credential supported (format '${format}')`);
1213
1242
  }
1214
1243
  if (opts?.filterVerifiableCredential) {
1215
1244
  return types.filter((type) => type !== "VerifiableCredential");
@@ -1243,7 +1272,37 @@ __name(getSupportedCredentials, "getSupportedCredentials");
1243
1272
  function determineVersionsFromIssuerMetadata(issuerMetadata) {
1244
1273
  const versions = /* @__PURE__ */ new Set();
1245
1274
  if ("credential_configurations_supported" in issuerMetadata) {
1246
- versions.add(OpenId4VCIVersion.VER_1_0_15);
1275
+ let is1_0Final = false;
1276
+ if ("batch_credential_issuance_supported" in issuerMetadata && typeof issuerMetadata.batch_credential_issuance_supported === "boolean") {
1277
+ is1_0Final = true;
1278
+ }
1279
+ if ("credential_issuer_public_key" in issuerMetadata) {
1280
+ is1_0Final = true;
1281
+ }
1282
+ if (!is1_0Final) {
1283
+ const configs = issuerMetadata.credential_configurations_supported;
1284
+ if (configs) {
1285
+ for (const config of Object.values(configs)) {
1286
+ if ("cryptographic_suites_supported" in config) {
1287
+ is1_0Final = true;
1288
+ break;
1289
+ }
1290
+ if (config.proof_types_supported && "di_vp" in config.proof_types_supported) {
1291
+ is1_0Final = true;
1292
+ break;
1293
+ }
1294
+ }
1295
+ }
1296
+ }
1297
+ if (is1_0Final) {
1298
+ versions.add(OpenId4VCIVersion.VER_1_0);
1299
+ } else {
1300
+ if ("batch_credential_issuance" in issuerMetadata && typeof issuerMetadata.batch_credential_issuance === "object") {
1301
+ versions.add(OpenId4VCIVersion.VER_1_0_15);
1302
+ } else {
1303
+ versions.add(OpenId4VCIVersion.VER_1_0);
1304
+ }
1305
+ }
1247
1306
  }
1248
1307
  if (versions.size === 0) {
1249
1308
  versions.add(OpenId4VCIVersion.VER_UNKNOWN);
@@ -1402,6 +1461,16 @@ var createProofOfPossession = /* @__PURE__ */ __name(async (popMode, callbacks,
1402
1461
  ${jwt}`);
1403
1462
  return proof;
1404
1463
  }, "createProofOfPossession");
1464
+ var createCwtProofOfPossession = /* @__PURE__ */ __name(async (callbacks, opts) => {
1465
+ if (!callbacks.cwtSignCallback) {
1466
+ throw new Error("No CWT signer callback supplied");
1467
+ }
1468
+ const cwt = await callbacks.cwtSignCallback(opts);
1469
+ return {
1470
+ proof_type: "cwt",
1471
+ cwt
1472
+ };
1473
+ }, "createCwtProofOfPossession");
1405
1474
  var partiallyValidateJWS = /* @__PURE__ */ __name((jws) => {
1406
1475
  if (jws.split(".").length !== 3 || !jws.startsWith("ey")) {
1407
1476
  throw new Error(JWS_NOT_VALID);
@@ -1570,6 +1639,33 @@ var assertValidCodeVerifier = /* @__PURE__ */ __name((codeVerifier) => {
1570
1639
  }
1571
1640
  }, "assertValidCodeVerifier");
1572
1641
 
1642
+ // lib/functions/SignedMetadataUtils.ts
1643
+ init_cjs_shims();
1644
+ async function processSignedMetadata(opts) {
1645
+ const { metadata, issuer, signedMetadataVerifyCallback } = opts;
1646
+ if (!metadata.signed_metadata) {
1647
+ return metadata;
1648
+ }
1649
+ if (!signedMetadataVerifyCallback) {
1650
+ VCI_LOG_COMMON.warning(`Issuer ${issuer} provides signed_metadata but no signedMetadataVerifyCallback was provided. Signed metadata will not be verified or applied.`);
1651
+ return metadata;
1652
+ }
1653
+ const result = await signedMetadataVerifyCallback({
1654
+ signedMetadata: metadata.signed_metadata,
1655
+ issuer
1656
+ });
1657
+ if (!result.verified) {
1658
+ throw Error(`Signed metadata verification failed for issuer ${issuer}`);
1659
+ }
1660
+ VCI_LOG_COMMON.info(`Signed metadata verified for issuer ${issuer}, applying signed claims`);
1661
+ const { iss: _iss, iat: _iat, exp: _exp, nbf: _nbf, jti: _jti, aud: _aud, sub: _sub, ...metadataClaims } = result.metadata;
1662
+ return {
1663
+ ...metadata,
1664
+ ...metadataClaims
1665
+ };
1666
+ }
1667
+ __name(processSignedMetadata, "processSignedMetadata");
1668
+
1573
1669
  // lib/experimental/holder-vci.ts
1574
1670
  init_cjs_shims();
1575
1671
  var EXPERIMENTAL_SUBJECT_PROOF_MODE_ENABLED = process.env.EXPERIMENTAL_SUBJECT_PROOF_MODE?.trim().toLowerCase() === "true";