@sphereon/ssi-sdk.siopv2-oid4vp-op-auth 0.34.1-feature.SSISDK.78.306 → 0.34.1-feature.SSISDK.82.and.SSISDK.70.346

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