@sphereon/ssi-sdk.siopv2-oid4vp-op-auth 0.34.1-next.299 → 0.34.1-next.322

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
@@ -368,7 +368,7 @@ var plugin_schema_default = {
368
368
  // src/agent/DidAuthSiopOpAuthenticator.ts
369
369
  import { decodeUriAsJson } from "@sphereon/did-auth-siop";
370
370
  import { ConnectionType as ConnectionType2, CorrelationIdentifierType, IdentityOrigin } from "@sphereon/ssi-sdk.data-store-types";
371
- import { Loggers as Loggers4, CredentialRole as CredentialRole2 } from "@sphereon/ssi-types";
371
+ import { Loggers as Loggers5, CredentialRole as CredentialRole2 } from "@sphereon/ssi-types";
372
372
  import { v4 as uuidv4 } from "uuid";
373
373
 
374
374
  // src/session/functions.ts
@@ -523,32 +523,205 @@ function getSigningAlgo(type) {
523
523
  __name(getSigningAlgo, "getSigningAlgo");
524
524
 
525
525
  // src/session/OID4VP.ts
526
- var OID4VP = class _OID4VP {
527
- static {
528
- __name(this, "OID4VP");
526
+ import { calculateSdHash } from "@sphereon/pex/dist/main/lib/utils/index.js";
527
+ import { isManagedIdentifierDidResult } from "@sphereon/ssi-sdk-ext.identifier-resolution";
528
+ import { defaultGenerateDigest } from "@sphereon/ssi-sdk.sd-jwt";
529
+ import { CredentialMapper, DocumentFormat, Loggers } from "@sphereon/ssi-types";
530
+
531
+ // src/types/IDidAuthSiopOpAuthenticator.ts
532
+ var LOGGER_NAMESPACE = "sphereon:siopv2-oid4vp:op-auth";
533
+ var DEFAULT_JWT_PROOF_TYPE = "JwtProof2020";
534
+
535
+ // src/types/siop-service/index.ts
536
+ var Siopv2HolderEvent = /* @__PURE__ */ (function(Siopv2HolderEvent2) {
537
+ Siopv2HolderEvent2["CONTACT_IDENTITY_CREATED"] = "contact_identity_created";
538
+ Siopv2HolderEvent2["IDENTIFIER_CREATED"] = "identifier_created";
539
+ return Siopv2HolderEvent2;
540
+ })({});
541
+ var SupportedLanguage = /* @__PURE__ */ (function(SupportedLanguage2) {
542
+ SupportedLanguage2["ENGLISH"] = "en";
543
+ SupportedLanguage2["DUTCH"] = "nl";
544
+ return SupportedLanguage2;
545
+ })({});
546
+
547
+ // src/types/machine/index.ts
548
+ var Siopv2MachineStates = /* @__PURE__ */ (function(Siopv2MachineStates2) {
549
+ Siopv2MachineStates2["createConfig"] = "createConfig";
550
+ Siopv2MachineStates2["getSiopRequest"] = "getSiopRequest";
551
+ Siopv2MachineStates2["getSelectableCredentials"] = "getSelectableCredentials";
552
+ Siopv2MachineStates2["retrieveContact"] = "retrieveContact";
553
+ Siopv2MachineStates2["transitionFromSetup"] = "transitionFromSetup";
554
+ Siopv2MachineStates2["addContact"] = "addContact";
555
+ Siopv2MachineStates2["addContactIdentity"] = "addContactIdentity";
556
+ Siopv2MachineStates2["selectCredentials"] = "selectCredentials";
557
+ Siopv2MachineStates2["sendResponse"] = "sendResponse";
558
+ Siopv2MachineStates2["handleError"] = "handleError";
559
+ Siopv2MachineStates2["aborted"] = "aborted";
560
+ Siopv2MachineStates2["declined"] = "declined";
561
+ Siopv2MachineStates2["error"] = "error";
562
+ Siopv2MachineStates2["done"] = "done";
563
+ return Siopv2MachineStates2;
564
+ })({});
565
+ var Siopv2MachineAddContactStates = /* @__PURE__ */ (function(Siopv2MachineAddContactStates2) {
566
+ Siopv2MachineAddContactStates2["idle"] = "idle";
567
+ Siopv2MachineAddContactStates2["executing"] = "executing";
568
+ Siopv2MachineAddContactStates2["next"] = "next";
569
+ return Siopv2MachineAddContactStates2;
570
+ })({});
571
+ var Siopv2MachineEvents = /* @__PURE__ */ (function(Siopv2MachineEvents2) {
572
+ Siopv2MachineEvents2["NEXT"] = "NEXT";
573
+ Siopv2MachineEvents2["PREVIOUS"] = "PREVIOUS";
574
+ Siopv2MachineEvents2["DECLINE"] = "DECLINE";
575
+ Siopv2MachineEvents2["SET_CONTACT_ALIAS"] = "SET_CONTACT_ALIAS";
576
+ Siopv2MachineEvents2["SET_CONTACT_CONSENT"] = "SET_CONTACT_CONSENT";
577
+ Siopv2MachineEvents2["CREATE_CONTACT"] = "CREATE_CONTACT";
578
+ Siopv2MachineEvents2["SET_SELECTED_CREDENTIALS"] = "SET_SELECTED_CREDENTIALS";
579
+ return Siopv2MachineEvents2;
580
+ })({});
581
+ var Siopv2MachineGuards = /* @__PURE__ */ (function(Siopv2MachineGuards2) {
582
+ Siopv2MachineGuards2["hasNoContactGuard"] = "Siopv2HasNoContactGuard";
583
+ Siopv2MachineGuards2["createContactGuard"] = "Siopv2CreateContactGuard";
584
+ Siopv2MachineGuards2["hasContactGuard"] = "Siopv2HasContactGuard";
585
+ Siopv2MachineGuards2["hasAuthorizationRequestGuard"] = "Siopv2HasAuthorizationRequestGuard";
586
+ Siopv2MachineGuards2["hasSelectableCredentialsAndContactGuard"] = "Siopv2HasSelectableCredentialsAndContactGuard";
587
+ Siopv2MachineGuards2["hasSelectedRequiredCredentialsGuard"] = "Siopv2HasSelectedRequiredCredentialsGuard";
588
+ Siopv2MachineGuards2["siopOnlyGuard"] = "Siopv2IsSiopOnlyGuard";
589
+ Siopv2MachineGuards2["siopWithOID4VPGuard"] = "Siopv2IsSiopWithOID4VPGuard";
590
+ return Siopv2MachineGuards2;
591
+ })({});
592
+ var Siopv2MachineServices = /* @__PURE__ */ (function(Siopv2MachineServices2) {
593
+ Siopv2MachineServices2["getSiopRequest"] = "getSiopRequest";
594
+ Siopv2MachineServices2["getSelectableCredentials"] = "getSelectableCredentials";
595
+ Siopv2MachineServices2["retrieveContact"] = "retrieveContact";
596
+ Siopv2MachineServices2["addContactIdentity"] = "addContactIdentity";
597
+ Siopv2MachineServices2["sendResponse"] = "sendResponse";
598
+ Siopv2MachineServices2["createConfig"] = "createConfig";
599
+ return Siopv2MachineServices2;
600
+ })({});
601
+
602
+ // src/types/identifier/index.ts
603
+ var DID_PREFIX = "did";
604
+
605
+ // src/session/OID4VP.ts
606
+ var CLOCK_SKEW = 120;
607
+ var logger = Loggers.DEFAULT.get(LOGGER_NAMESPACE);
608
+ function extractOriginalCredential(credential) {
609
+ if (typeof credential === "string") {
610
+ return credential;
611
+ }
612
+ if ("digitalCredential" in credential) {
613
+ const udc = credential;
614
+ if (udc.originalVerifiableCredential) {
615
+ return udc.originalVerifiableCredential;
616
+ }
617
+ return udc.uniformVerifiableCredential;
529
618
  }
530
- //private readonly session: OpSession
531
- // private readonly allIdentifiers: string[]
532
- // private readonly hasher?: HasherSync
533
- constructor(args) {
619
+ if ("original" in credential) {
620
+ return credential.original;
534
621
  }
535
- static async init(session, allIdentifiers, hasher) {
536
- return new _OID4VP({
537
- session,
538
- allIdentifiers: allIdentifiers ?? await session.getSupportedDIDs(),
539
- hasher
540
- });
622
+ return credential;
623
+ }
624
+ __name(extractOriginalCredential, "extractOriginalCredential");
625
+ function getIdentifierString(identifier) {
626
+ if ("opts" in identifier && "method" in identifier) {
627
+ if (isManagedIdentifierDidResult(identifier)) {
628
+ return identifier.did;
629
+ }
541
630
  }
542
- };
631
+ return identifier.issuer ?? identifier.kid ?? "";
632
+ }
633
+ __name(getIdentifierString, "getIdentifierString");
634
+ async function createVerifiablePresentationForFormat(credential, identifier, context) {
635
+ const { nonce, audience, agent, clockSkew = CLOCK_SKEW } = context;
636
+ const originalCredential = extractOriginalCredential(credential);
637
+ const documentFormat = CredentialMapper.detectDocumentType(originalCredential);
638
+ logger.debug(`Creating VP for format: ${documentFormat}`);
639
+ switch (documentFormat) {
640
+ case DocumentFormat.SD_JWT_VC: {
641
+ const decodedSdJwt = await CredentialMapper.decodeSdJwtVcAsync(typeof originalCredential === "string" ? originalCredential : originalCredential.compactSdJwtVc, defaultGenerateDigest);
642
+ const hashAlg = decodedSdJwt.signedPayload._sd_alg ?? "sha-256";
643
+ const sdHash = calculateSdHash(decodedSdJwt.compactSdJwtVc, hashAlg, defaultGenerateDigest);
644
+ const kbJwtPayload = {
645
+ iat: Math.floor(Date.now() / 1e3 - clockSkew),
646
+ sd_hash: sdHash,
647
+ nonce,
648
+ aud: audience
649
+ };
650
+ const presentationResult = await agent.createSdJwtPresentation({
651
+ presentation: decodedSdJwt.compactSdJwtVc,
652
+ kb: {
653
+ payload: kbJwtPayload
654
+ }
655
+ });
656
+ return presentationResult.presentation;
657
+ }
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: {
684
+ const vcJwt = typeof originalCredential === "string" ? originalCredential : JSON.stringify(originalCredential);
685
+ const identifierString = getIdentifierString(identifier);
686
+ const vpPayload = {
687
+ iss: identifierString,
688
+ aud: audience,
689
+ nonce,
690
+ vp: {
691
+ "@context": [
692
+ "https://www.w3.org/2018/credentials/v1"
693
+ ],
694
+ type: [
695
+ "VerifiablePresentation"
696
+ ],
697
+ holder: identifierString,
698
+ verifiableCredential: [
699
+ vcJwt
700
+ ]
701
+ },
702
+ iat: Math.floor(Date.now() / 1e3 - clockSkew),
703
+ exp: Math.floor(Date.now() / 1e3 + 600 + clockSkew)
704
+ };
705
+ const vpJwt = await agent.createVerifiablePresentation({
706
+ presentation: vpPayload.vp,
707
+ proofFormat: "jwt",
708
+ domain: audience,
709
+ challenge: nonce,
710
+ keyRef: identifier.kmsKeyRef || identifier.kid
711
+ });
712
+ return vpJwt.proof?.jwt || vpJwt;
713
+ }
714
+ }
715
+ }
716
+ __name(createVerifiablePresentationForFormat, "createVerifiablePresentationForFormat");
543
717
 
544
718
  // src/session/OpSession.ts
545
719
  import { OP as OP2, URI } from "@sphereon/did-auth-siop";
546
720
  import { getAgentDIDMethods, getAgentResolver } from "@sphereon/ssi-sdk-ext.did-utils";
547
721
  import { encodeBase64url } from "@sphereon/ssi-sdk.core";
548
- import { parseDid } from "@sphereon/ssi-types";
722
+ import { Loggers as Loggers2, parseDid } from "@sphereon/ssi-types";
549
723
  import { v4 } from "uuid";
550
- import { Loggers } from "@sphereon/ssi-types";
551
- var logger = Loggers.DEFAULT.get("sphereon:oid4vp:OpSession");
724
+ var logger2 = Loggers2.DEFAULT.get("sphereon:oid4vp:OpSession");
552
725
  var OpSession = class _OpSession {
553
726
  static {
554
727
  __name(this, "OpSession");
@@ -612,9 +785,9 @@ var OpSession = class _OpSession {
612
785
  didPrefix,
613
786
  agentMethods
614
787
  });
615
- logger.debug(`RP supports subject syntax types: ${JSON.stringify(this.getSubjectSyntaxTypesSupported())}`);
788
+ logger2.debug(`RP supports subject syntax types: ${JSON.stringify(this.getSubjectSyntaxTypesSupported())}`);
616
789
  if (rpMethods.dids.length === 0) {
617
- logger.debug(`RP does not support DIDs. Supported: ${JSON.stringify(this.getSubjectSyntaxTypesSupported())}`);
790
+ logger2.debug(`RP does not support DIDs. Supported: ${JSON.stringify(this.getSubjectSyntaxTypesSupported())}`);
618
791
  return [];
619
792
  }
620
793
  let intersection;
@@ -632,7 +805,7 @@ var OpSession = class _OpSession {
632
805
  }
633
806
  getAgentDIDMethodsSupported(opts) {
634
807
  const agentMethods = this.options.supportedDIDMethods?.map((method) => convertDidMethod(method, opts.didPrefix));
635
- logger.debug(`agent methods: ${JSON.stringify(agentMethods)}`);
808
+ logger2.debug(`agent methods: ${JSON.stringify(agentMethods)}`);
636
809
  return agentMethods;
637
810
  }
638
811
  async getSubjectSyntaxTypesSupported() {
@@ -643,15 +816,15 @@ var OpSession = class _OpSession {
643
816
  async getRPDIDMethodsSupported(opts) {
644
817
  let keyType;
645
818
  const agentMethods = (opts.agentMethods ?? this.getAgentDIDMethodsSupported(opts))?.map((method) => convertDidMethod(method, opts.didPrefix)) ?? [];
646
- logger.debug(`agent methods supported: ${JSON.stringify(agentMethods)}`);
819
+ logger2.debug(`agent methods supported: ${JSON.stringify(agentMethods)}`);
647
820
  const authReq = await this.getAuthorizationRequest();
648
821
  const subjectSyntaxTypesSupported = authReq.registrationMetadataPayload?.subject_syntax_types_supported?.map((method) => convertDidMethod(method, opts.didPrefix)).filter((val) => !val.startsWith("did"));
649
- logger.debug(`subject syntax types supported in rp method supported: ${JSON.stringify(subjectSyntaxTypesSupported)}`);
822
+ logger2.debug(`subject syntax types supported in rp method supported: ${JSON.stringify(subjectSyntaxTypesSupported)}`);
650
823
  const aud = await authReq.authorizationRequest.getMergedProperty("aud");
651
824
  let rpMethods = [];
652
825
  if (aud && aud.startsWith("did:")) {
653
826
  const didMethod = convertDidMethod(parseDid(aud).method, opts.didPrefix);
654
- logger.debug(`aud did method: ${didMethod}`);
827
+ logger2.debug(`aud did method: ${didMethod}`);
655
828
  if (subjectSyntaxTypesSupported && subjectSyntaxTypesSupported.length > 0 && !subjectSyntaxTypesSupported.includes("did") && !subjectSyntaxTypesSupported.includes(didMethod)) {
656
829
  throw Error(`The aud DID method ${didMethod} is not in the supported types ${subjectSyntaxTypesSupported}`);
657
830
  }
@@ -666,7 +839,7 @@ var OpSession = class _OpSession {
666
839
  const isEBSI = rpMethods.length === 0 && (authReq.issuer?.includes(".ebsi.eu") || authReq.authorizationRequest.getMergedProperty("client_id")?.includes(".ebsi.eu"));
667
840
  let codecName = void 0;
668
841
  if (isEBSI && (!aud || !aud.startsWith("http"))) {
669
- logger.debug(`EBSI detected, adding did:key to supported DID methods for RP`);
842
+ logger2.debug(`EBSI detected, adding did:key to supported DID methods for RP`);
670
843
  const didKeyMethod = convertDidMethod("did:key", opts.didPrefix);
671
844
  if (!agentMethods?.includes(didKeyMethod)) {
672
845
  throw Error(`EBSI detected, but agent did not support did:key. Please reconfigure agent`);
@@ -685,13 +858,13 @@ var OpSession = class _OpSession {
685
858
  }
686
859
  async getSupportedIdentifiers(opts) {
687
860
  const methods = await this.getSupportedDIDMethods(true);
688
- logger.debug(`supported DID methods (did: prefix = true): ${JSON.stringify(methods)}`);
861
+ logger2.debug(`supported DID methods (did: prefix = true): ${JSON.stringify(methods)}`);
689
862
  if (methods.length === 0) {
690
863
  throw Error(`No DID methods are supported`);
691
864
  }
692
865
  const identifiers = await this.context.agent.didManagerFind().then((ids) => ids.filter((id) => methods.includes(id.provider)));
693
866
  if (identifiers.length === 0) {
694
- logger.debug(`No identifiers available in agent supporting methods ${JSON.stringify(methods)}`);
867
+ logger2.debug(`No identifiers available in agent supporting methods ${JSON.stringify(methods)}`);
695
868
  if (opts?.createInCaseNoDIDFound !== false) {
696
869
  const { codecName, keyType } = await this.getRPDIDMethodsSupported({
697
870
  didPrefix: true,
@@ -705,11 +878,11 @@ var OpSession = class _OpSession {
705
878
  type: keyType
706
879
  }
707
880
  });
708
- logger.debug(`Created a new identifier for the SIOP interaction: ${identifier.did}`);
881
+ logger2.debug(`Created a new identifier for the SIOP interaction: ${identifier.did}`);
709
882
  identifiers.push(identifier);
710
883
  }
711
884
  }
712
- logger.debug(`supported identifiers: ${JSON.stringify(identifiers.map((id) => id.did))}`);
885
+ logger2.debug(`supported identifiers: ${JSON.stringify(identifiers.map((id) => id.did))}`);
713
886
  return identifiers;
714
887
  }
715
888
  async getSupportedDIDs() {
@@ -718,9 +891,6 @@ var OpSession = class _OpSession {
718
891
  async getRedirectUri() {
719
892
  return Promise.resolve(this.verifiedAuthorizationRequest.responseURI);
720
893
  }
721
- async getOID4VP(args) {
722
- return await OID4VP.init(this, args.allIdentifiers ?? [], args.hasher);
723
- }
724
894
  async createJarmResponseCallback({ responseOpts }) {
725
895
  const agent = this.context.agent;
726
896
  return /* @__PURE__ */ __name(async function jarmResponse(opts) {
@@ -800,80 +970,6 @@ function convertDidMethod(didMethod, didPrefix) {
800
970
  }
801
971
  __name(convertDidMethod, "convertDidMethod");
802
972
 
803
- // src/types/IDidAuthSiopOpAuthenticator.ts
804
- var LOGGER_NAMESPACE = "sphereon:siopv2-oid4vp:op-auth";
805
- var DEFAULT_JWT_PROOF_TYPE = "JwtProof2020";
806
-
807
- // src/types/siop-service/index.ts
808
- var Siopv2HolderEvent = /* @__PURE__ */ (function(Siopv2HolderEvent2) {
809
- Siopv2HolderEvent2["CONTACT_IDENTITY_CREATED"] = "contact_identity_created";
810
- Siopv2HolderEvent2["IDENTIFIER_CREATED"] = "identifier_created";
811
- return Siopv2HolderEvent2;
812
- })({});
813
- var SupportedLanguage = /* @__PURE__ */ (function(SupportedLanguage2) {
814
- SupportedLanguage2["ENGLISH"] = "en";
815
- SupportedLanguage2["DUTCH"] = "nl";
816
- return SupportedLanguage2;
817
- })({});
818
-
819
- // src/types/machine/index.ts
820
- var Siopv2MachineStates = /* @__PURE__ */ (function(Siopv2MachineStates2) {
821
- Siopv2MachineStates2["createConfig"] = "createConfig";
822
- Siopv2MachineStates2["getSiopRequest"] = "getSiopRequest";
823
- Siopv2MachineStates2["getSelectableCredentials"] = "getSelectableCredentials";
824
- Siopv2MachineStates2["retrieveContact"] = "retrieveContact";
825
- Siopv2MachineStates2["transitionFromSetup"] = "transitionFromSetup";
826
- Siopv2MachineStates2["addContact"] = "addContact";
827
- Siopv2MachineStates2["addContactIdentity"] = "addContactIdentity";
828
- Siopv2MachineStates2["selectCredentials"] = "selectCredentials";
829
- Siopv2MachineStates2["sendResponse"] = "sendResponse";
830
- Siopv2MachineStates2["handleError"] = "handleError";
831
- Siopv2MachineStates2["aborted"] = "aborted";
832
- Siopv2MachineStates2["declined"] = "declined";
833
- Siopv2MachineStates2["error"] = "error";
834
- Siopv2MachineStates2["done"] = "done";
835
- return Siopv2MachineStates2;
836
- })({});
837
- var Siopv2MachineAddContactStates = /* @__PURE__ */ (function(Siopv2MachineAddContactStates2) {
838
- Siopv2MachineAddContactStates2["idle"] = "idle";
839
- Siopv2MachineAddContactStates2["executing"] = "executing";
840
- Siopv2MachineAddContactStates2["next"] = "next";
841
- return Siopv2MachineAddContactStates2;
842
- })({});
843
- var Siopv2MachineEvents = /* @__PURE__ */ (function(Siopv2MachineEvents2) {
844
- Siopv2MachineEvents2["NEXT"] = "NEXT";
845
- Siopv2MachineEvents2["PREVIOUS"] = "PREVIOUS";
846
- Siopv2MachineEvents2["DECLINE"] = "DECLINE";
847
- Siopv2MachineEvents2["SET_CONTACT_ALIAS"] = "SET_CONTACT_ALIAS";
848
- Siopv2MachineEvents2["SET_CONTACT_CONSENT"] = "SET_CONTACT_CONSENT";
849
- Siopv2MachineEvents2["CREATE_CONTACT"] = "CREATE_CONTACT";
850
- Siopv2MachineEvents2["SET_SELECTED_CREDENTIALS"] = "SET_SELECTED_CREDENTIALS";
851
- return Siopv2MachineEvents2;
852
- })({});
853
- var Siopv2MachineGuards = /* @__PURE__ */ (function(Siopv2MachineGuards2) {
854
- Siopv2MachineGuards2["hasNoContactGuard"] = "Siopv2HasNoContactGuard";
855
- Siopv2MachineGuards2["createContactGuard"] = "Siopv2CreateContactGuard";
856
- Siopv2MachineGuards2["hasContactGuard"] = "Siopv2HasContactGuard";
857
- Siopv2MachineGuards2["hasAuthorizationRequestGuard"] = "Siopv2HasAuthorizationRequestGuard";
858
- Siopv2MachineGuards2["hasSelectableCredentialsAndContactGuard"] = "Siopv2HasSelectableCredentialsAndContactGuard";
859
- Siopv2MachineGuards2["hasSelectedRequiredCredentialsGuard"] = "Siopv2HasSelectedRequiredCredentialsGuard";
860
- Siopv2MachineGuards2["siopOnlyGuard"] = "Siopv2IsSiopOnlyGuard";
861
- Siopv2MachineGuards2["siopWithOID4VPGuard"] = "Siopv2IsSiopWithOID4VPGuard";
862
- return Siopv2MachineGuards2;
863
- })({});
864
- var Siopv2MachineServices = /* @__PURE__ */ (function(Siopv2MachineServices2) {
865
- Siopv2MachineServices2["getSiopRequest"] = "getSiopRequest";
866
- Siopv2MachineServices2["getSelectableCredentials"] = "getSelectableCredentials";
867
- Siopv2MachineServices2["retrieveContact"] = "retrieveContact";
868
- Siopv2MachineServices2["addContactIdentity"] = "addContactIdentity";
869
- Siopv2MachineServices2["sendResponse"] = "sendResponse";
870
- Siopv2MachineServices2["createConfig"] = "createConfig";
871
- return Siopv2MachineServices2;
872
- })({});
873
-
874
- // src/types/identifier/index.ts
875
- var DID_PREFIX = "did";
876
-
877
973
  // src/machine/Siopv2Machine.ts
878
974
  import { assign, createMachine, interpret } from "xstate";
879
975
 
@@ -919,8 +1015,8 @@ var Localization = class Localization2 {
919
1015
  var translate = Localization.translate;
920
1016
 
921
1017
  // src/machine/Siopv2Machine.ts
922
- import { Loggers as Loggers2 } from "@sphereon/ssi-types";
923
- var logger2 = Loggers2.DEFAULT.get(LOGGER_NAMESPACE);
1018
+ import { Loggers as Loggers3 } from "@sphereon/ssi-types";
1019
+ var logger3 = Loggers3.DEFAULT.get(LOGGER_NAMESPACE);
924
1020
  var Siopv2HasNoContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
925
1021
  const { contact } = _ctx;
926
1022
  return contact === void 0;
@@ -1250,7 +1346,7 @@ var Siopv2Machine = class {
1250
1346
  __name(this, "Siopv2Machine");
1251
1347
  }
1252
1348
  static newInstance(opts) {
1253
- logger2.info("New Siopv2Machine instance");
1349
+ logger3.info("New Siopv2Machine instance");
1254
1350
  const interpreter = interpret(createSiopv2Machine(opts).withConfig({
1255
1351
  services: {
1256
1352
  ...opts?.services
@@ -1278,7 +1374,7 @@ var Siopv2Machine = class {
1278
1374
  });
1279
1375
  }
1280
1376
  interpreter.onTransition((snapshot) => {
1281
- logger2.info("onTransition to new state", snapshot.value);
1377
+ logger3.info("onTransition to new state", snapshot.value);
1282
1378
  });
1283
1379
  return {
1284
1380
  interpreter
@@ -1287,22 +1383,20 @@ var Siopv2Machine = class {
1287
1383
  };
1288
1384
 
1289
1385
  // src/services/Siopv2MachineService.ts
1290
- import { calculateSdHash } from "@sphereon/pex/dist/main/lib/utils/index.js";
1291
1386
  import { getOrCreatePrimaryIdentifier, SupportedDidMethodEnum } from "@sphereon/ssi-sdk-ext.did-utils";
1292
1387
  import { isOID4VCIssuerIdentifier } from "@sphereon/ssi-sdk-ext.identifier-resolution";
1293
1388
  import { encodeJoseBlob } from "@sphereon/ssi-sdk.core";
1294
1389
  import { verifiableCredentialForRoleFilter } from "@sphereon/ssi-sdk.credential-store";
1295
1390
  import { ConnectionType } from "@sphereon/ssi-sdk.data-store-types";
1296
- import { defaultGenerateDigest } from "@sphereon/ssi-sdk.sd-jwt";
1297
- import { CredentialMapper as CredentialMapper3, CredentialRole, Loggers as Loggers3 } from "@sphereon/ssi-types";
1391
+ import { CredentialMapper as CredentialMapper4, CredentialRole, Loggers as Loggers4 } from "@sphereon/ssi-types";
1298
1392
  import { DcqlPresentation, DcqlQuery } from "dcql";
1299
1393
 
1300
1394
  // src/utils/dcql.ts
1301
- import { CredentialMapper as CredentialMapper2 } from "@sphereon/ssi-types";
1395
+ import { CredentialMapper as CredentialMapper3 } from "@sphereon/ssi-types";
1302
1396
  import { Dcql } from "@sphereon/did-auth-siop";
1303
1397
 
1304
1398
  // src/utils/CredentialUtils.ts
1305
- import { CredentialMapper } from "@sphereon/ssi-types";
1399
+ import { CredentialMapper as CredentialMapper2 } from "@sphereon/ssi-types";
1306
1400
  var isUniqueDigitalCredential = /* @__PURE__ */ __name((credential) => {
1307
1401
  return credential.digitalCredential !== void 0;
1308
1402
  }, "isUniqueDigitalCredential");
@@ -1314,29 +1408,29 @@ function convertToDcqlCredentials(credential, hasher) {
1314
1408
  if (!credential.originalVerifiableCredential) {
1315
1409
  throw new Error("originalVerifiableCredential is not defined in UniqueDigitalCredential");
1316
1410
  }
1317
- originalVerifiableCredential = CredentialMapper2.decodeVerifiableCredential(credential.originalVerifiableCredential, hasher);
1411
+ originalVerifiableCredential = CredentialMapper3.decodeVerifiableCredential(credential.originalVerifiableCredential, hasher);
1318
1412
  } else {
1319
- originalVerifiableCredential = CredentialMapper2.decodeVerifiableCredential(credential, hasher);
1413
+ originalVerifiableCredential = CredentialMapper3.decodeVerifiableCredential(credential, hasher);
1320
1414
  }
1321
1415
  if (!originalVerifiableCredential) {
1322
1416
  throw new Error("No payload found");
1323
1417
  }
1324
- if (CredentialMapper2.isJwtDecodedCredential(originalVerifiableCredential)) {
1325
- return Dcql.toDcqlJwtCredential(CredentialMapper2.toWrappedVerifiableCredential(originalVerifiableCredential));
1326
- } else if (CredentialMapper2.isSdJwtDecodedCredential(originalVerifiableCredential)) {
1327
- return Dcql.toDcqlSdJwtCredential(CredentialMapper2.toWrappedVerifiableCredential(originalVerifiableCredential));
1328
- } else if (CredentialMapper2.isMsoMdocDecodedCredential(originalVerifiableCredential)) {
1329
- return Dcql.toDcqlMdocCredential(CredentialMapper2.toWrappedVerifiableCredential(originalVerifiableCredential));
1330
- } else if (CredentialMapper2.isW3cCredential(originalVerifiableCredential)) {
1331
- return Dcql.toDcqlJsonLdCredential(CredentialMapper2.toWrappedVerifiableCredential(originalVerifiableCredential));
1418
+ if (CredentialMapper3.isJwtDecodedCredential(originalVerifiableCredential)) {
1419
+ return Dcql.toDcqlJwtCredential(CredentialMapper3.toWrappedVerifiableCredential(originalVerifiableCredential));
1420
+ } else if (CredentialMapper3.isSdJwtDecodedCredential(originalVerifiableCredential)) {
1421
+ return Dcql.toDcqlSdJwtCredential(CredentialMapper3.toWrappedVerifiableCredential(originalVerifiableCredential));
1422
+ } else if (CredentialMapper3.isMsoMdocDecodedCredential(originalVerifiableCredential)) {
1423
+ return Dcql.toDcqlMdocCredential(CredentialMapper3.toWrappedVerifiableCredential(originalVerifiableCredential));
1424
+ } else if (CredentialMapper3.isW3cCredential(originalVerifiableCredential)) {
1425
+ return Dcql.toDcqlJsonLdCredential(CredentialMapper3.toWrappedVerifiableCredential(originalVerifiableCredential));
1332
1426
  }
1333
1427
  throw Error(`Unable to map credential to DCQL credential. Credential: ${JSON.stringify(originalVerifiableCredential)}`);
1334
1428
  }
1335
1429
  __name(convertToDcqlCredentials, "convertToDcqlCredentials");
1336
1430
 
1337
1431
  // src/services/Siopv2MachineService.ts
1338
- var CLOCK_SKEW = 120;
1339
- var logger3 = Loggers3.DEFAULT.get(LOGGER_NAMESPACE);
1432
+ var CLOCK_SKEW2 = 120;
1433
+ var logger4 = Loggers4.DEFAULT.get(LOGGER_NAMESPACE);
1340
1434
  var siopSendAuthorizationResponse = /* @__PURE__ */ __name(async (connectionType, args, context) => {
1341
1435
  const { agent } = context;
1342
1436
  const { credentials } = args;
@@ -1348,10 +1442,10 @@ var siopSendAuthorizationResponse = /* @__PURE__ */ __name(async (connectionType
1348
1442
  });
1349
1443
  const request = await session.getAuthorizationRequest();
1350
1444
  const aud = request.authorizationRequest.getMergedProperty("aud");
1351
- logger3.debug(`AUD: ${aud}`);
1352
- logger3.debug(JSON.stringify(request.authorizationRequest));
1445
+ logger4.debug(`AUD: ${aud}`);
1446
+ logger4.debug(JSON.stringify(request.authorizationRequest));
1353
1447
  const domain = await request.authorizationRequest.getMergedProperty("client_id") ?? request.issuer ?? "https://self-issued.me/v2";
1354
- logger3.debug(`NONCE: ${session.nonce}, domain: ${domain}`);
1448
+ logger4.debug(`NONCE: ${session.nonce}, domain: ${domain}`);
1355
1449
  const firstUniqueDC = credentials[0];
1356
1450
  if (typeof firstUniqueDC !== "object" || !("digitalCredential" in firstUniqueDC)) {
1357
1451
  return Promise.reject(Error("SiopMachine only supports UniqueDigitalCredentials for now"));
@@ -1359,10 +1453,12 @@ var siopSendAuthorizationResponse = /* @__PURE__ */ __name(async (connectionType
1359
1453
  let identifier;
1360
1454
  const digitalCredential = firstUniqueDC.digitalCredential;
1361
1455
  const firstVC = firstUniqueDC.uniformVerifiableCredential;
1362
- const holder = CredentialMapper3.isSdJwtDecodedCredential(firstVC) ? firstVC.decodedPayload.cnf?.jwk ? (
1363
- //doesn't apply to did:jwk only, as you can represent any DID key as a JWK. So whenever you encounter a JWK it doesn't mean it had to come from a did:jwk in the system. It just can always be represented as a did:jwk
1364
- `did:jwk:${encodeJoseBlob(firstVC.decodedPayload.cnf?.jwk)}#0`
1365
- ) : firstVC.decodedPayload.sub : Array.isArray(firstVC.credentialSubject) ? firstVC.credentialSubject[0].id : firstVC.credentialSubject.id;
1456
+ let holder;
1457
+ if (CredentialMapper4.isSdJwtDecodedCredential(firstVC)) {
1458
+ holder = firstVC.decodedPayload.cnf?.jwk ? `did:jwk:${encodeJoseBlob(firstVC.decodedPayload.cnf?.jwk)}#0` : firstVC.decodedPayload.sub;
1459
+ } else {
1460
+ holder = Array.isArray(firstVC.credentialSubject) ? firstVC.credentialSubject[0].id : firstVC.credentialSubject.id;
1461
+ }
1366
1462
  if (!digitalCredential.kmsKeyRef) {
1367
1463
  if (!holder) {
1368
1464
  return Promise.reject(`No holder found and no kmsKeyRef in DB. Cannot determine identifier to use`);
@@ -1372,7 +1468,7 @@ var siopSendAuthorizationResponse = /* @__PURE__ */ __name(async (connectionType
1372
1468
  identifier: holder
1373
1469
  });
1374
1470
  } catch (e) {
1375
- logger3.debug(`Holder DID not found: ${holder}`);
1471
+ logger4.debug(`Holder DID not found: ${holder}`);
1376
1472
  throw e;
1377
1473
  }
1378
1474
  } else if (isOID4VCIssuerIdentifier(digitalCredential.kmsKeyRef)) {
@@ -1403,6 +1499,13 @@ var siopSendAuthorizationResponse = /* @__PURE__ */ __name(async (connectionType
1403
1499
  if (!queryResult.can_be_satisfied) {
1404
1500
  return Promise.reject(Error("Credentials do not match required query request"));
1405
1501
  }
1502
+ const presentationContext = {
1503
+ nonce: request.requestObject?.getPayload()?.nonce ?? session.nonce,
1504
+ audience: domain,
1505
+ agent: context.agent,
1506
+ clockSkew: CLOCK_SKEW2,
1507
+ hasher: args.hasher
1508
+ };
1406
1509
  const presentation = {};
1407
1510
  const uniqueCredentials = Array.from(dcqlCredentialsWithCredentials.values());
1408
1511
  for (const [key, value] of Object.entries(queryResult.credential_matches)) {
@@ -1412,27 +1515,12 @@ var siopSendAuthorizationResponse = /* @__PURE__ */ __name(async (connectionType
1412
1515
  if (!vc) {
1413
1516
  continue;
1414
1517
  }
1415
- const originalVc = retrieveEncodedCredential(vc);
1416
- if (!originalVc) {
1417
- continue;
1418
- }
1419
- const decodedSdJwt = await CredentialMapper3.decodeSdJwtVcAsync(originalVc, defaultGenerateDigest);
1420
- const updatedSdJwt = updateSdJwtCredential(decodedSdJwt, request.requestObject?.getPayload()?.nonce, domain);
1421
- const presentationResult = await context.agent.createSdJwtPresentation({
1422
- presentation: updatedSdJwt.compactSdJwtVc,
1423
- kb: {
1424
- payload: {
1425
- ...updatedSdJwt.kbJwt?.payload,
1426
- // FIXME SSISDK-44
1427
- nonce: updatedSdJwt.kbJwt?.payload.nonce ?? request.requestObject.getPayload().nonce,
1428
- // FIXME SSISDK-44
1429
- aud: updatedSdJwt.kbJwt?.payload.aud ?? domain,
1430
- iat: updatedSdJwt.kbJwt?.payload?.iat ?? Math.floor(Date.now() / 1e3 - CLOCK_SKEW)
1431
- }
1432
- }
1433
- });
1434
- if (originalVc) {
1435
- presentation[key] = presentationResult.presentation;
1518
+ try {
1519
+ const vp = await createVerifiablePresentationForFormat(vc, identifier, presentationContext);
1520
+ presentation[key] = vp;
1521
+ } catch (error) {
1522
+ logger4.error(`Failed to create VP for credential ${key}:`, error);
1523
+ throw error;
1436
1524
  }
1437
1525
  }
1438
1526
  }
@@ -1443,12 +1531,9 @@ var siopSendAuthorizationResponse = /* @__PURE__ */ __name(async (connectionType
1443
1531
  dcqlPresentation
1444
1532
  }
1445
1533
  });
1446
- logger3.debug(`Response: `, response);
1534
+ logger4.debug(`Response: `, response);
1447
1535
  return response;
1448
1536
  }, "siopSendAuthorizationResponse");
1449
- var retrieveEncodedCredential = /* @__PURE__ */ __name((credential) => {
1450
- return credential.originalVerifiableCredential !== void 0 && credential.originalVerifiableCredential !== null && credential?.originalVerifiableCredential?.compactSdJwtVc !== void 0 && credential?.originalVerifiableCredential?.compactSdJwtVc !== null ? credential.originalVerifiableCredential.compactSdJwtVc : credential.originalVerifiableCredential;
1451
- }, "retrieveEncodedCredential");
1452
1537
  var getSelectableCredentials = /* @__PURE__ */ __name(async (dcqlQuery, context) => {
1453
1538
  const agentContext = {
1454
1539
  ...context,
@@ -1525,34 +1610,9 @@ var translateCorrelationIdToName = /* @__PURE__ */ __name(async (correlationId,
1525
1610
  }
1526
1611
  return contacts[0].contact.displayName;
1527
1612
  }, "translateCorrelationIdToName");
1528
- var updateSdJwtCredential = /* @__PURE__ */ __name((credential, nonce, aud) => {
1529
- const sdJwtCredential = credential;
1530
- const hashAlg = sdJwtCredential.signedPayload._sd_alg ?? "sha-256";
1531
- const sdHash = calculateSdHash(sdJwtCredential.compactSdJwtVc, hashAlg, defaultGenerateDigest);
1532
- const kbJwt = {
1533
- // alg MUST be set by the signer
1534
- header: {
1535
- typ: "kb+jwt"
1536
- },
1537
- payload: {
1538
- iat: Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3),
1539
- sd_hash: sdHash,
1540
- ...nonce && {
1541
- nonce
1542
- },
1543
- ...aud && {
1544
- aud
1545
- }
1546
- }
1547
- };
1548
- return {
1549
- ...sdJwtCredential,
1550
- kbJwt
1551
- };
1552
- }, "updateSdJwtCredential");
1553
1613
 
1554
1614
  // src/agent/DidAuthSiopOpAuthenticator.ts
1555
- var logger4 = Loggers4.DEFAULT.options(LOGGER_NAMESPACE, {}).get(LOGGER_NAMESPACE);
1615
+ var logger5 = Loggers5.DEFAULT.options(LOGGER_NAMESPACE, {}).get(LOGGER_NAMESPACE);
1556
1616
  var didAuthSiopOpAuthenticatorMethods = [
1557
1617
  "cmGetContacts",
1558
1618
  "cmGetContact",
@@ -1706,7 +1766,7 @@ var DidAuthSiopOpAuthenticator = class {
1706
1766
  hasher: this.hasher
1707
1767
  }
1708
1768
  }));
1709
- logger4.debug(`session: ${JSON.stringify(session.id, null, 2)}`);
1769
+ logger5.debug(`session: ${JSON.stringify(session.id, null, 2)}`);
1710
1770
  const verifiedAuthorizationRequest = await session.getAuthorizationRequest();
1711
1771
  const clientName = verifiedAuthorizationRequest.registrationMetadataPayload?.client_name;
1712
1772
  const url = verifiedAuthorizationRequest.responseURI ?? (args.url.includes("request_uri") ? decodeURIComponent(args.url.split("?request_uri=")[1].trim()) : verifiedAuthorizationRequest.issuer ?? verifiedAuthorizationRequest.registrationMetadataPayload?.client_id);
@@ -1785,7 +1845,7 @@ var DidAuthSiopOpAuthenticator = class {
1785
1845
  contactId: contact.id,
1786
1846
  identity: addedIdentity
1787
1847
  });
1788
- logger4.info(`Contact identity created: ${JSON.stringify(addedIdentity)}`);
1848
+ logger5.info(`Contact identity created: ${JSON.stringify(addedIdentity)}`);
1789
1849
  }
1790
1850
  }
1791
1851
  async siopSendResponse(args, context) {
@@ -1827,8 +1887,8 @@ var DidAuthSiopOpAuthenticator = class {
1827
1887
  };
1828
1888
 
1829
1889
  // src/machine/CallbackStateListener.ts
1830
- import { Loggers as Loggers5, LogLevel, LogMethod } from "@sphereon/ssi-types";
1831
- var logger5 = Loggers5.DEFAULT.options("sphereon:siopv2-oid4vp:op-auth", {
1890
+ import { Loggers as Loggers6, LogLevel, LogMethod } from "@sphereon/ssi-types";
1891
+ var logger6 = Loggers6.DEFAULT.options("sphereon:siopv2-oid4vp:op-auth", {
1832
1892
  defaultLogLevel: LogLevel.DEBUG,
1833
1893
  methods: [
1834
1894
  LogMethod.CONSOLE
@@ -1837,21 +1897,21 @@ var logger5 = Loggers5.DEFAULT.options("sphereon:siopv2-oid4vp:op-auth", {
1837
1897
  var OID4VPCallbackStateListener = /* @__PURE__ */ __name((callbacks) => {
1838
1898
  return async (oid4vciMachine, state) => {
1839
1899
  if (state._event.type === "internal") {
1840
- logger5.debug("oid4vpCallbackStateListener: internal event");
1900
+ logger6.debug("oid4vpCallbackStateListener: internal event");
1841
1901
  return;
1842
1902
  }
1843
- logger5.info(`VP state listener state: ${JSON.stringify(state.value)}`);
1903
+ logger6.info(`VP state listener state: ${JSON.stringify(state.value)}`);
1844
1904
  if (!callbacks || callbacks.size === 0) {
1845
- logger5.info(`VP no callbacks registered for state: ${JSON.stringify(state.value)}`);
1905
+ logger6.info(`VP no callbacks registered for state: ${JSON.stringify(state.value)}`);
1846
1906
  return;
1847
1907
  }
1848
1908
  for (const [stateKey, callback] of callbacks) {
1849
1909
  if (state.matches(stateKey)) {
1850
- logger5.log(`VP state callback for state: ${JSON.stringify(state.value)}, will execute...`);
1851
- await callback(oid4vciMachine, state).then(() => logger5.log(`VP state callback executed for state: ${JSON.stringify(state.value)}`)).catch((error) => {
1852
- logger5.error(`VP state callback failed for state: ${JSON.stringify(state.value)}, error: ${JSON.stringify(error?.message)}, ${JSON.stringify(state.event)}`);
1910
+ logger6.log(`VP state callback for state: ${JSON.stringify(state.value)}, will execute...`);
1911
+ await callback(oid4vciMachine, state).then(() => logger6.log(`VP state callback executed for state: ${JSON.stringify(state.value)}`)).catch((error) => {
1912
+ logger6.error(`VP state callback failed for state: ${JSON.stringify(state.value)}, error: ${JSON.stringify(error?.message)}, ${JSON.stringify(state.event)}`);
1853
1913
  if (error.stack) {
1854
- logger5.error(error.stack);
1914
+ logger6.error(error.stack);
1855
1915
  }
1856
1916
  });
1857
1917
  break;
@@ -1864,8 +1924,8 @@ var OID4VPCallbackStateListener = /* @__PURE__ */ __name((callbacks) => {
1864
1924
  import { contextHasPlugin } from "@sphereon/ssi-sdk.agent-config";
1865
1925
  import { LinkHandlerAdapter } from "@sphereon/ssi-sdk.core";
1866
1926
  import { interpreterStartOrResume } from "@sphereon/ssi-sdk.xstate-machine-persistence";
1867
- import { Loggers as Loggers6 } from "@sphereon/ssi-types";
1868
- var logger6 = Loggers6.DEFAULT.options(LOGGER_NAMESPACE, {}).get(LOGGER_NAMESPACE);
1927
+ import { Loggers as Loggers7 } from "@sphereon/ssi-types";
1928
+ var logger7 = Loggers7.DEFAULT.options(LOGGER_NAMESPACE, {}).get(LOGGER_NAMESPACE);
1869
1929
  var Siopv2OID4VPLinkHandler = class extends LinkHandlerAdapter {
1870
1930
  static {
1871
1931
  __name(this, "Siopv2OID4VPLinkHandler");
@@ -1885,7 +1945,7 @@ var Siopv2OID4VPLinkHandler = class extends LinkHandlerAdapter {
1885
1945
  this.idOpts = args.idOpts;
1886
1946
  }
1887
1947
  async handle(url, opts) {
1888
- logger6.debug(`handling SIOP link: ${url}`);
1948
+ logger7.debug(`handling SIOP link: ${url}`);
1889
1949
  const siopv2Machine = await this.context.agent.siopGetMachineInterpreter({
1890
1950
  url,
1891
1951
  idOpts: opts?.idOpts ?? this.idOpts,
@@ -1901,10 +1961,10 @@ var Siopv2OID4VPLinkHandler = class extends LinkHandlerAdapter {
1901
1961
  singletonCheck: true,
1902
1962
  noRegistration: this.noStateMachinePersistence
1903
1963
  });
1904
- logger6.debug(`SIOP machine started for link: ${url}`, init);
1964
+ logger7.debug(`SIOP machine started for link: ${url}`, init);
1905
1965
  } else {
1906
1966
  interpreter.start(opts?.machineState);
1907
- logger6.debug(`SIOP machine started for link: ${url}`);
1967
+ logger7.debug(`SIOP machine started for link: ${url}`);
1908
1968
  }
1909
1969
  }
1910
1970
  };
@@ -1913,7 +1973,6 @@ export {
1913
1973
  DID_PREFIX,
1914
1974
  DidAuthSiopOpAuthenticator,
1915
1975
  LOGGER_NAMESPACE,
1916
- OID4VP,
1917
1976
  OID4VPCallbackStateListener,
1918
1977
  OpSession,
1919
1978
  Siopv2HolderEvent,
@@ -1931,6 +1990,7 @@ export {
1931
1990
  createOID4VPPresentationSignCallback,
1932
1991
  createOP,
1933
1992
  createOPBuilder,
1993
+ createVerifiablePresentationForFormat,
1934
1994
  didAuthSiopOpAuthenticatorMethods,
1935
1995
  getSigningAlgo,
1936
1996
  plugin_schema_default as schema