@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.cjs CHANGED
@@ -679,29 +679,6 @@ function extractOriginalCredential(credential) {
679
679
  return credential;
680
680
  }
681
681
  __name(extractOriginalCredential, "extractOriginalCredential");
682
- function detectCredentialFormat(credential) {
683
- if (typeof credential === "string") {
684
- if (credential.includes("~")) {
685
- return "dc+sd-jwt";
686
- }
687
- const parts = credential.split(".");
688
- if (parts.length === 3) {
689
- return "jwt_vc_json";
690
- }
691
- } else if (typeof credential === "object") {
692
- if ("compactSdJwtVc" in credential) {
693
- return "dc+sd-jwt";
694
- }
695
- if ("@context" in credential || "proof" in credential) {
696
- return "ldp_vc";
697
- }
698
- if ("doctype" in credential || "namespaces" in credential) {
699
- return "mso_mdoc";
700
- }
701
- }
702
- return "jwt_vc_json";
703
- }
704
- __name(detectCredentialFormat, "detectCredentialFormat");
705
682
  function getIdentifierString(identifier) {
706
683
  if ("opts" in identifier && "method" in identifier) {
707
684
  if ((0, import_ssi_sdk_ext2.isManagedIdentifierDidResult)(identifier)) {
@@ -714,10 +691,10 @@ __name(getIdentifierString, "getIdentifierString");
714
691
  async function createVerifiablePresentationForFormat(credential, identifier, context) {
715
692
  const { nonce, audience, agent, clockSkew = CLOCK_SKEW } = context;
716
693
  const originalCredential = extractOriginalCredential(credential);
717
- const format = detectCredentialFormat(originalCredential);
718
- logger.debug(`Creating VP for format: ${format}`);
719
- switch (format) {
720
- case "dc+sd-jwt": {
694
+ const documentFormat = import_ssi_types.CredentialMapper.detectDocumentType(originalCredential);
695
+ logger.debug(`Creating VP for format: ${documentFormat}`);
696
+ switch (documentFormat) {
697
+ case import_ssi_types.DocumentFormat.SD_JWT_VC: {
721
698
  const decodedSdJwt = await import_ssi_types.CredentialMapper.decodeSdJwtVcAsync(typeof originalCredential === "string" ? originalCredential : originalCredential.compactSdJwtVc, import_ssi_sdk2.defaultGenerateDigest);
722
699
  const hashAlg = decodedSdJwt.signedPayload._sd_alg ?? "sha-256";
723
700
  const sdHash = (0, import_utils.calculateSdHash)(decodedSdJwt.compactSdJwtVc, hashAlg, import_ssi_sdk2.defaultGenerateDigest);
@@ -735,7 +712,32 @@ async function createVerifiablePresentationForFormat(credential, identifier, con
735
712
  });
736
713
  return presentationResult.presentation;
737
714
  }
738
- case "jwt_vc_json": {
715
+ case import_ssi_types.DocumentFormat.JSONLD: {
716
+ const vcObject = typeof originalCredential === "string" ? JSON.parse(originalCredential) : originalCredential;
717
+ const vpObject = {
718
+ "@context": [
719
+ "https://www.w3.org/2018/credentials/v1"
720
+ ],
721
+ type: [
722
+ "VerifiablePresentation"
723
+ ],
724
+ verifiableCredential: [
725
+ vcObject
726
+ ]
727
+ };
728
+ return await agent.createVerifiablePresentation({
729
+ presentation: vpObject,
730
+ proofFormat: "lds",
731
+ challenge: nonce,
732
+ domain: audience,
733
+ keyRef: identifier.kmsKeyRef || identifier.kid
734
+ });
735
+ }
736
+ case import_ssi_types.DocumentFormat.MSO_MDOC: {
737
+ logger.warning("mso_mdoc format has basic support - production use requires proper mdoc VP token implementation");
738
+ return originalCredential;
739
+ }
740
+ default: {
739
741
  const vcJwt = typeof originalCredential === "string" ? originalCredential : JSON.stringify(originalCredential);
740
742
  const identifierString = getIdentifierString(identifier);
741
743
  const vpPayload = {
@@ -755,7 +757,7 @@ async function createVerifiablePresentationForFormat(credential, identifier, con
755
757
  ]
756
758
  },
757
759
  iat: Math.floor(Date.now() / 1e3 - clockSkew),
758
- exp: Math.floor(Date.now() / 1e3 + 600)
760
+ exp: Math.floor(Date.now() / 1e3 + 600 + clockSkew)
759
761
  };
760
762
  const vpJwt = await agent.createVerifiablePresentation({
761
763
  presentation: vpPayload.vp,
@@ -766,33 +768,6 @@ async function createVerifiablePresentationForFormat(credential, identifier, con
766
768
  });
767
769
  return vpJwt.proof?.jwt || vpJwt;
768
770
  }
769
- case "ldp_vc": {
770
- const vcObject = typeof originalCredential === "string" ? JSON.parse(originalCredential) : originalCredential;
771
- const vpObject = {
772
- "@context": [
773
- "https://www.w3.org/2018/credentials/v1"
774
- ],
775
- type: [
776
- "VerifiablePresentation"
777
- ],
778
- verifiableCredential: [
779
- vcObject
780
- ]
781
- };
782
- return await agent.createVerifiablePresentation({
783
- presentation: vpObject,
784
- proofFormat: "lds",
785
- challenge: nonce,
786
- domain: audience,
787
- keyRef: identifier.kmsKeyRef || identifier.kid
788
- });
789
- }
790
- case "mso_mdoc": {
791
- logger.warning("mso_mdoc format has basic support - production use requires proper mdoc VP token implementation");
792
- return originalCredential;
793
- }
794
- default:
795
- return Promise.reject(Error(`Unsupported credential format: ${format}`));
796
771
  }
797
772
  }
798
773
  __name(createVerifiablePresentationForFormat, "createVerifiablePresentationForFormat");