@sphereon/ssi-sdk.siopv2-oid4vp-op-auth 0.34.1-feature.SSISDK.44.finish.dcql.314 → 0.34.1-feature.SSISDK.44.finish.dcql.317

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.js CHANGED
@@ -526,7 +526,7 @@ __name(getSigningAlgo, "getSigningAlgo");
526
526
  import { calculateSdHash } from "@sphereon/pex/dist/main/lib/utils/index.js";
527
527
  import { isManagedIdentifierDidResult } from "@sphereon/ssi-sdk-ext.identifier-resolution";
528
528
  import { defaultGenerateDigest } from "@sphereon/ssi-sdk.sd-jwt";
529
- import { CredentialMapper, Loggers } from "@sphereon/ssi-types";
529
+ import { CredentialMapper, DocumentFormat, Loggers } from "@sphereon/ssi-types";
530
530
 
531
531
  // src/types/IDidAuthSiopOpAuthenticator.ts
532
532
  var LOGGER_NAMESPACE = "sphereon:siopv2-oid4vp:op-auth";
@@ -622,29 +622,6 @@ function extractOriginalCredential(credential) {
622
622
  return credential;
623
623
  }
624
624
  __name(extractOriginalCredential, "extractOriginalCredential");
625
- function detectCredentialFormat(credential) {
626
- if (typeof credential === "string") {
627
- if (credential.includes("~")) {
628
- return "dc+sd-jwt";
629
- }
630
- const parts = credential.split(".");
631
- if (parts.length === 3) {
632
- return "jwt_vc_json";
633
- }
634
- } else if (typeof credential === "object") {
635
- if ("compactSdJwtVc" in credential) {
636
- return "dc+sd-jwt";
637
- }
638
- if ("@context" in credential || "proof" in credential) {
639
- return "ldp_vc";
640
- }
641
- if ("doctype" in credential || "namespaces" in credential) {
642
- return "mso_mdoc";
643
- }
644
- }
645
- return "jwt_vc_json";
646
- }
647
- __name(detectCredentialFormat, "detectCredentialFormat");
648
625
  function getIdentifierString(identifier) {
649
626
  if ("opts" in identifier && "method" in identifier) {
650
627
  if (isManagedIdentifierDidResult(identifier)) {
@@ -657,10 +634,10 @@ __name(getIdentifierString, "getIdentifierString");
657
634
  async function createVerifiablePresentationForFormat(credential, identifier, context) {
658
635
  const { nonce, audience, agent, clockSkew = CLOCK_SKEW } = context;
659
636
  const originalCredential = extractOriginalCredential(credential);
660
- const format = detectCredentialFormat(originalCredential);
661
- logger.debug(`Creating VP for format: ${format}`);
662
- switch (format) {
663
- case "dc+sd-jwt": {
637
+ const documentFormat = CredentialMapper.detectDocumentType(originalCredential);
638
+ logger.debug(`Creating VP for format: ${documentFormat}`);
639
+ switch (documentFormat) {
640
+ case DocumentFormat.SD_JWT_VC: {
664
641
  const decodedSdJwt = await CredentialMapper.decodeSdJwtVcAsync(typeof originalCredential === "string" ? originalCredential : originalCredential.compactSdJwtVc, defaultGenerateDigest);
665
642
  const hashAlg = decodedSdJwt.signedPayload._sd_alg ?? "sha-256";
666
643
  const sdHash = calculateSdHash(decodedSdJwt.compactSdJwtVc, hashAlg, defaultGenerateDigest);
@@ -678,7 +655,32 @@ async function createVerifiablePresentationForFormat(credential, identifier, con
678
655
  });
679
656
  return presentationResult.presentation;
680
657
  }
681
- case "jwt_vc_json": {
658
+ case DocumentFormat.JSONLD: {
659
+ const vcObject = typeof originalCredential === "string" ? JSON.parse(originalCredential) : originalCredential;
660
+ const vpObject = {
661
+ "@context": [
662
+ "https://www.w3.org/2018/credentials/v1"
663
+ ],
664
+ type: [
665
+ "VerifiablePresentation"
666
+ ],
667
+ verifiableCredential: [
668
+ vcObject
669
+ ]
670
+ };
671
+ return await agent.createVerifiablePresentation({
672
+ presentation: vpObject,
673
+ proofFormat: "lds",
674
+ challenge: nonce,
675
+ domain: audience,
676
+ keyRef: identifier.kmsKeyRef || identifier.kid
677
+ });
678
+ }
679
+ case DocumentFormat.MSO_MDOC: {
680
+ logger.warning("mso_mdoc format has basic support - production use requires proper mdoc VP token implementation");
681
+ return originalCredential;
682
+ }
683
+ default: {
682
684
  const vcJwt = typeof originalCredential === "string" ? originalCredential : JSON.stringify(originalCredential);
683
685
  const identifierString = getIdentifierString(identifier);
684
686
  const vpPayload = {
@@ -698,7 +700,7 @@ async function createVerifiablePresentationForFormat(credential, identifier, con
698
700
  ]
699
701
  },
700
702
  iat: Math.floor(Date.now() / 1e3 - clockSkew),
701
- exp: Math.floor(Date.now() / 1e3 + 600)
703
+ exp: Math.floor(Date.now() / 1e3 + 600 + clockSkew)
702
704
  };
703
705
  const vpJwt = await agent.createVerifiablePresentation({
704
706
  presentation: vpPayload.vp,
@@ -709,33 +711,6 @@ async function createVerifiablePresentationForFormat(credential, identifier, con
709
711
  });
710
712
  return vpJwt.proof?.jwt || vpJwt;
711
713
  }
712
- case "ldp_vc": {
713
- const vcObject = typeof originalCredential === "string" ? JSON.parse(originalCredential) : originalCredential;
714
- const vpObject = {
715
- "@context": [
716
- "https://www.w3.org/2018/credentials/v1"
717
- ],
718
- type: [
719
- "VerifiablePresentation"
720
- ],
721
- verifiableCredential: [
722
- vcObject
723
- ]
724
- };
725
- return await agent.createVerifiablePresentation({
726
- presentation: vpObject,
727
- proofFormat: "lds",
728
- challenge: nonce,
729
- domain: audience,
730
- keyRef: identifier.kmsKeyRef || identifier.kid
731
- });
732
- }
733
- case "mso_mdoc": {
734
- logger.warning("mso_mdoc format has basic support - production use requires proper mdoc VP token implementation");
735
- return originalCredential;
736
- }
737
- default:
738
- return Promise.reject(Error(`Unsupported credential format: ${format}`));
739
714
  }
740
715
  }
741
716
  __name(createVerifiablePresentationForFormat, "createVerifiablePresentationForFormat");