@sphereon/ssi-sdk.siopv2-oid4vp-op-auth 0.34.1-next.91 → 0.36.1-feat.SSISDK.83.11

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
@@ -367,8 +367,8 @@ var plugin_schema_default = {
367
367
 
368
368
  // src/agent/DidAuthSiopOpAuthenticator.ts
369
369
  import { decodeUriAsJson } from "@sphereon/did-auth-siop";
370
- import { ConnectionType as ConnectionType2, CorrelationIdentifierType, CredentialRole as CredentialRole2, IdentityOrigin } from "@sphereon/ssi-sdk.data-store";
371
- import { Loggers as Loggers4 } from "@sphereon/ssi-types";
370
+ import { ConnectionType as ConnectionType2, CorrelationIdentifierType, IdentityOrigin } from "@sphereon/ssi-sdk.data-store-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
@@ -394,10 +394,8 @@ __name(createOID4VPPresentationSignCallback, "createOID4VPPresentationSignCallba
394
394
  async function createOPBuilder({ opOptions, idOpts: idOpts1, context }) {
395
395
  const eventEmitter = opOptions.eventEmitter ?? new EventEmitter();
396
396
  const builder = OP.builder().withResponseMode(opOptions.responseMode ?? ResponseMode.DIRECT_POST).withSupportedVersions(opOptions.supportedVersions ?? [
397
- SupportedVersion.SIOPv2_ID1,
398
- SupportedVersion.JWT_VC_PRESENTATION_PROFILE_v1,
399
- SupportedVersion.SIOPv2_D11,
400
- SupportedVersion.SIOPv2_D12_OID4VP_D18
397
+ SupportedVersion.OID4VP_v1,
398
+ SupportedVersion.SIOPv2_OID4VP_D28
401
399
  ]).withExpiresIn(opOptions.expiresIn ?? 300).withEventEmitter(eventEmitter).withRegistration({
402
400
  passBy: PassBy.VALUE
403
401
  });
@@ -525,32 +523,205 @@ function getSigningAlgo(type) {
525
523
  __name(getSigningAlgo, "getSigningAlgo");
526
524
 
527
525
  // src/session/OID4VP.ts
528
- var OID4VP = class _OID4VP {
529
- static {
530
- __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;
531
618
  }
532
- //private readonly session: OpSession
533
- // private readonly allIdentifiers: string[]
534
- // private readonly hasher?: HasherSync
535
- constructor(args) {
619
+ if ("original" in credential) {
620
+ return credential.original;
536
621
  }
537
- static async init(session, allIdentifiers, hasher) {
538
- return new _OID4VP({
539
- session,
540
- allIdentifiers: allIdentifiers ?? await session.getSupportedDIDs(),
541
- hasher
542
- });
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
+ }
543
630
  }
544
- };
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");
545
717
 
546
718
  // src/session/OpSession.ts
547
719
  import { OP as OP2, URI } from "@sphereon/did-auth-siop";
548
720
  import { getAgentDIDMethods, getAgentResolver } from "@sphereon/ssi-sdk-ext.did-utils";
549
721
  import { encodeBase64url } from "@sphereon/ssi-sdk.core";
550
- import { parseDid } from "@sphereon/ssi-types";
722
+ import { Loggers as Loggers2, parseDid } from "@sphereon/ssi-types";
551
723
  import { v4 } from "uuid";
552
- import { Loggers } from "@sphereon/ssi-types";
553
- var logger = Loggers.DEFAULT.get("sphereon:oid4vp:OpSession");
724
+ var logger2 = Loggers2.DEFAULT.get("sphereon:oid4vp:OpSession");
554
725
  var OpSession = class _OpSession {
555
726
  static {
556
727
  __name(this, "OpSession");
@@ -614,9 +785,9 @@ var OpSession = class _OpSession {
614
785
  didPrefix,
615
786
  agentMethods
616
787
  });
617
- logger.debug(`RP supports subject syntax types: ${JSON.stringify(this.getSubjectSyntaxTypesSupported())}`);
788
+ logger2.debug(`RP supports subject syntax types: ${JSON.stringify(this.getSubjectSyntaxTypesSupported())}`);
618
789
  if (rpMethods.dids.length === 0) {
619
- 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())}`);
620
791
  return [];
621
792
  }
622
793
  let intersection;
@@ -634,7 +805,7 @@ var OpSession = class _OpSession {
634
805
  }
635
806
  getAgentDIDMethodsSupported(opts) {
636
807
  const agentMethods = this.options.supportedDIDMethods?.map((method) => convertDidMethod(method, opts.didPrefix));
637
- logger.debug(`agent methods: ${JSON.stringify(agentMethods)}`);
808
+ logger2.debug(`agent methods: ${JSON.stringify(agentMethods)}`);
638
809
  return agentMethods;
639
810
  }
640
811
  async getSubjectSyntaxTypesSupported() {
@@ -645,15 +816,15 @@ var OpSession = class _OpSession {
645
816
  async getRPDIDMethodsSupported(opts) {
646
817
  let keyType;
647
818
  const agentMethods = (opts.agentMethods ?? this.getAgentDIDMethodsSupported(opts))?.map((method) => convertDidMethod(method, opts.didPrefix)) ?? [];
648
- logger.debug(`agent methods supported: ${JSON.stringify(agentMethods)}`);
819
+ logger2.debug(`agent methods supported: ${JSON.stringify(agentMethods)}`);
649
820
  const authReq = await this.getAuthorizationRequest();
650
821
  const subjectSyntaxTypesSupported = authReq.registrationMetadataPayload?.subject_syntax_types_supported?.map((method) => convertDidMethod(method, opts.didPrefix)).filter((val) => !val.startsWith("did"));
651
- 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)}`);
652
823
  const aud = await authReq.authorizationRequest.getMergedProperty("aud");
653
824
  let rpMethods = [];
654
825
  if (aud && aud.startsWith("did:")) {
655
826
  const didMethod = convertDidMethod(parseDid(aud).method, opts.didPrefix);
656
- logger.debug(`aud did method: ${didMethod}`);
827
+ logger2.debug(`aud did method: ${didMethod}`);
657
828
  if (subjectSyntaxTypesSupported && subjectSyntaxTypesSupported.length > 0 && !subjectSyntaxTypesSupported.includes("did") && !subjectSyntaxTypesSupported.includes(didMethod)) {
658
829
  throw Error(`The aud DID method ${didMethod} is not in the supported types ${subjectSyntaxTypesSupported}`);
659
830
  }
@@ -668,7 +839,7 @@ var OpSession = class _OpSession {
668
839
  const isEBSI = rpMethods.length === 0 && (authReq.issuer?.includes(".ebsi.eu") || authReq.authorizationRequest.getMergedProperty("client_id")?.includes(".ebsi.eu"));
669
840
  let codecName = void 0;
670
841
  if (isEBSI && (!aud || !aud.startsWith("http"))) {
671
- 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`);
672
843
  const didKeyMethod = convertDidMethod("did:key", opts.didPrefix);
673
844
  if (!agentMethods?.includes(didKeyMethod)) {
674
845
  throw Error(`EBSI detected, but agent did not support did:key. Please reconfigure agent`);
@@ -687,13 +858,13 @@ var OpSession = class _OpSession {
687
858
  }
688
859
  async getSupportedIdentifiers(opts) {
689
860
  const methods = await this.getSupportedDIDMethods(true);
690
- logger.debug(`supported DID methods (did: prefix = true): ${JSON.stringify(methods)}`);
861
+ logger2.debug(`supported DID methods (did: prefix = true): ${JSON.stringify(methods)}`);
691
862
  if (methods.length === 0) {
692
863
  throw Error(`No DID methods are supported`);
693
864
  }
694
865
  const identifiers = await this.context.agent.didManagerFind().then((ids) => ids.filter((id) => methods.includes(id.provider)));
695
866
  if (identifiers.length === 0) {
696
- 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)}`);
697
868
  if (opts?.createInCaseNoDIDFound !== false) {
698
869
  const { codecName, keyType } = await this.getRPDIDMethodsSupported({
699
870
  didPrefix: true,
@@ -707,11 +878,11 @@ var OpSession = class _OpSession {
707
878
  type: keyType
708
879
  }
709
880
  });
710
- 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}`);
711
882
  identifiers.push(identifier);
712
883
  }
713
884
  }
714
- logger.debug(`supported identifiers: ${JSON.stringify(identifiers.map((id) => id.did))}`);
885
+ logger2.debug(`supported identifiers: ${JSON.stringify(identifiers.map((id) => id.did))}`);
715
886
  return identifiers;
716
887
  }
717
888
  async getSupportedDIDs() {
@@ -720,9 +891,6 @@ var OpSession = class _OpSession {
720
891
  async getRedirectUri() {
721
892
  return Promise.resolve(this.verifiedAuthorizationRequest.responseURI);
722
893
  }
723
- async getOID4VP(args) {
724
- return await OID4VP.init(this, args.allIdentifiers ?? [], args.hasher);
725
- }
726
894
  async createJarmResponseCallback({ responseOpts }) {
727
895
  const agent = this.context.agent;
728
896
  return /* @__PURE__ */ __name(async function jarmResponse(opts) {
@@ -802,80 +970,6 @@ function convertDidMethod(didMethod, didPrefix) {
802
970
  }
803
971
  __name(convertDidMethod, "convertDidMethod");
804
972
 
805
- // src/types/IDidAuthSiopOpAuthenticator.ts
806
- var LOGGER_NAMESPACE = "sphereon:siopv2-oid4vp:op-auth";
807
- var DEFAULT_JWT_PROOF_TYPE = "JwtProof2020";
808
-
809
- // src/types/siop-service/index.ts
810
- var Siopv2HolderEvent = /* @__PURE__ */ (function(Siopv2HolderEvent2) {
811
- Siopv2HolderEvent2["CONTACT_IDENTITY_CREATED"] = "contact_identity_created";
812
- Siopv2HolderEvent2["IDENTIFIER_CREATED"] = "identifier_created";
813
- return Siopv2HolderEvent2;
814
- })({});
815
- var SupportedLanguage = /* @__PURE__ */ (function(SupportedLanguage2) {
816
- SupportedLanguage2["ENGLISH"] = "en";
817
- SupportedLanguage2["DUTCH"] = "nl";
818
- return SupportedLanguage2;
819
- })({});
820
-
821
- // src/types/machine/index.ts
822
- var Siopv2MachineStates = /* @__PURE__ */ (function(Siopv2MachineStates2) {
823
- Siopv2MachineStates2["createConfig"] = "createConfig";
824
- Siopv2MachineStates2["getSiopRequest"] = "getSiopRequest";
825
- Siopv2MachineStates2["getSelectableCredentials"] = "getSelectableCredentials";
826
- Siopv2MachineStates2["retrieveContact"] = "retrieveContact";
827
- Siopv2MachineStates2["transitionFromSetup"] = "transitionFromSetup";
828
- Siopv2MachineStates2["addContact"] = "addContact";
829
- Siopv2MachineStates2["addContactIdentity"] = "addContactIdentity";
830
- Siopv2MachineStates2["selectCredentials"] = "selectCredentials";
831
- Siopv2MachineStates2["sendResponse"] = "sendResponse";
832
- Siopv2MachineStates2["handleError"] = "handleError";
833
- Siopv2MachineStates2["aborted"] = "aborted";
834
- Siopv2MachineStates2["declined"] = "declined";
835
- Siopv2MachineStates2["error"] = "error";
836
- Siopv2MachineStates2["done"] = "done";
837
- return Siopv2MachineStates2;
838
- })({});
839
- var Siopv2MachineAddContactStates = /* @__PURE__ */ (function(Siopv2MachineAddContactStates2) {
840
- Siopv2MachineAddContactStates2["idle"] = "idle";
841
- Siopv2MachineAddContactStates2["executing"] = "executing";
842
- Siopv2MachineAddContactStates2["next"] = "next";
843
- return Siopv2MachineAddContactStates2;
844
- })({});
845
- var Siopv2MachineEvents = /* @__PURE__ */ (function(Siopv2MachineEvents2) {
846
- Siopv2MachineEvents2["NEXT"] = "NEXT";
847
- Siopv2MachineEvents2["PREVIOUS"] = "PREVIOUS";
848
- Siopv2MachineEvents2["DECLINE"] = "DECLINE";
849
- Siopv2MachineEvents2["SET_CONTACT_ALIAS"] = "SET_CONTACT_ALIAS";
850
- Siopv2MachineEvents2["SET_CONTACT_CONSENT"] = "SET_CONTACT_CONSENT";
851
- Siopv2MachineEvents2["CREATE_CONTACT"] = "CREATE_CONTACT";
852
- Siopv2MachineEvents2["SET_SELECTED_CREDENTIALS"] = "SET_SELECTED_CREDENTIALS";
853
- return Siopv2MachineEvents2;
854
- })({});
855
- var Siopv2MachineGuards = /* @__PURE__ */ (function(Siopv2MachineGuards2) {
856
- Siopv2MachineGuards2["hasNoContactGuard"] = "Siopv2HasNoContactGuard";
857
- Siopv2MachineGuards2["createContactGuard"] = "Siopv2CreateContactGuard";
858
- Siopv2MachineGuards2["hasContactGuard"] = "Siopv2HasContactGuard";
859
- Siopv2MachineGuards2["hasAuthorizationRequestGuard"] = "Siopv2HasAuthorizationRequestGuard";
860
- Siopv2MachineGuards2["hasSelectableCredentialsAndContactGuard"] = "Siopv2HasSelectableCredentialsAndContactGuard";
861
- Siopv2MachineGuards2["hasSelectedRequiredCredentialsGuard"] = "Siopv2HasSelectedRequiredCredentialsGuard";
862
- Siopv2MachineGuards2["siopOnlyGuard"] = "Siopv2IsSiopOnlyGuard";
863
- Siopv2MachineGuards2["siopWithOID4VPGuard"] = "Siopv2IsSiopWithOID4VPGuard";
864
- return Siopv2MachineGuards2;
865
- })({});
866
- var Siopv2MachineServices = /* @__PURE__ */ (function(Siopv2MachineServices2) {
867
- Siopv2MachineServices2["getSiopRequest"] = "getSiopRequest";
868
- Siopv2MachineServices2["getSelectableCredentials"] = "getSelectableCredentials";
869
- Siopv2MachineServices2["retrieveContact"] = "retrieveContact";
870
- Siopv2MachineServices2["addContactIdentity"] = "addContactIdentity";
871
- Siopv2MachineServices2["sendResponse"] = "sendResponse";
872
- Siopv2MachineServices2["createConfig"] = "createConfig";
873
- return Siopv2MachineServices2;
874
- })({});
875
-
876
- // src/types/identifier/index.ts
877
- var DID_PREFIX = "did";
878
-
879
973
  // src/machine/Siopv2Machine.ts
880
974
  import { assign, createMachine, interpret } from "xstate";
881
975
 
@@ -921,8 +1015,8 @@ var Localization = class Localization2 {
921
1015
  var translate = Localization.translate;
922
1016
 
923
1017
  // src/machine/Siopv2Machine.ts
924
- import { Loggers as Loggers2 } from "@sphereon/ssi-types";
925
- var logger2 = Loggers2.DEFAULT.get(LOGGER_NAMESPACE);
1018
+ import { Loggers as Loggers3 } from "@sphereon/ssi-types";
1019
+ var logger3 = Loggers3.DEFAULT.get(LOGGER_NAMESPACE);
926
1020
  var Siopv2HasNoContactGuard = /* @__PURE__ */ __name((_ctx, _event) => {
927
1021
  const { contact } = _ctx;
928
1022
  return contact === void 0;
@@ -1252,7 +1346,7 @@ var Siopv2Machine = class {
1252
1346
  __name(this, "Siopv2Machine");
1253
1347
  }
1254
1348
  static newInstance(opts) {
1255
- logger2.info("New Siopv2Machine instance");
1349
+ logger3.info("New Siopv2Machine instance");
1256
1350
  const interpreter = interpret(createSiopv2Machine(opts).withConfig({
1257
1351
  services: {
1258
1352
  ...opts?.services
@@ -1280,7 +1374,7 @@ var Siopv2Machine = class {
1280
1374
  });
1281
1375
  }
1282
1376
  interpreter.onTransition((snapshot) => {
1283
- logger2.info("onTransition to new state", snapshot.value);
1377
+ logger3.info("onTransition to new state", snapshot.value);
1284
1378
  });
1285
1379
  return {
1286
1380
  interpreter
@@ -1289,20 +1383,20 @@ var Siopv2Machine = class {
1289
1383
  };
1290
1384
 
1291
1385
  // src/services/Siopv2MachineService.ts
1292
- import { SupportedVersion as SupportedVersion2 } from "@sphereon/did-auth-siop";
1386
+ import { getOrCreatePrimaryIdentifier, SupportedDidMethodEnum } from "@sphereon/ssi-sdk-ext.did-utils";
1293
1387
  import { isOID4VCIssuerIdentifier } from "@sphereon/ssi-sdk-ext.identifier-resolution";
1294
- import { verifiableCredentialForRoleFilter } from "@sphereon/ssi-sdk.credential-store";
1295
- import { ConnectionType, CredentialRole } from "@sphereon/ssi-sdk.data-store";
1296
- import { CredentialMapper as CredentialMapper3, Loggers as Loggers3 } from "@sphereon/ssi-types";
1297
1388
  import { encodeJoseBlob } from "@sphereon/ssi-sdk.core";
1389
+ import { verifiableCredentialForRoleFilter } from "@sphereon/ssi-sdk.credential-store";
1390
+ import { ConnectionType } from "@sphereon/ssi-sdk.data-store-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
- import { getOrCreatePrimaryIdentifier, SupportedDidMethodEnum } from "@sphereon/ssi-sdk-ext.did-utils";
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));
1353
- const domain = await request.authorizationRequest.getMergedProperty("client_id") ?? request.issuer ?? (request.versions.includes(SupportedVersion2.JWT_VC_PRESENTATION_PROFILE_v1) ? "https://self-issued.me/v2/openid-vc" : "https://self-issued.me/v2");
1354
- logger3.debug(`NONCE: ${session.nonce}, domain: ${domain}`);
1445
+ logger4.debug(`AUD: ${aud}`);
1446
+ logger4.debug(JSON.stringify(request.authorizationRequest));
1447
+ const domain = await request.authorizationRequest.getMergedProperty("client_id") ?? request.issuer ?? "https://self-issued.me/v2";
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,12 +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
- if (originalVc) {
1420
- presentation[key] = originalVc;
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;
1421
1524
  }
1422
1525
  }
1423
1526
  }
@@ -1428,12 +1531,9 @@ var siopSendAuthorizationResponse = /* @__PURE__ */ __name(async (connectionType
1428
1531
  dcqlPresentation
1429
1532
  }
1430
1533
  });
1431
- logger3.debug(`Response: `, response);
1534
+ logger4.debug(`Response: `, response);
1432
1535
  return response;
1433
1536
  }, "siopSendAuthorizationResponse");
1434
- var retrieveEncodedCredential = /* @__PURE__ */ __name((credential) => {
1435
- return credential.originalVerifiableCredential !== void 0 && credential.originalVerifiableCredential !== null && credential?.originalVerifiableCredential?.compactSdJwtVc !== void 0 && credential?.originalVerifiableCredential?.compactSdJwtVc !== null ? credential.originalVerifiableCredential.compactSdJwtVc : credential.originalVerifiableCredential;
1436
- }, "retrieveEncodedCredential");
1437
1537
  var getSelectableCredentials = /* @__PURE__ */ __name(async (dcqlQuery, context) => {
1438
1538
  const agentContext = {
1439
1539
  ...context,
@@ -1512,7 +1612,7 @@ var translateCorrelationIdToName = /* @__PURE__ */ __name(async (correlationId,
1512
1612
  }, "translateCorrelationIdToName");
1513
1613
 
1514
1614
  // src/agent/DidAuthSiopOpAuthenticator.ts
1515
- var logger4 = Loggers4.DEFAULT.options(LOGGER_NAMESPACE, {}).get(LOGGER_NAMESPACE);
1615
+ var logger5 = Loggers5.DEFAULT.options(LOGGER_NAMESPACE, {}).get(LOGGER_NAMESPACE);
1516
1616
  var didAuthSiopOpAuthenticatorMethods = [
1517
1617
  "cmGetContacts",
1518
1618
  "cmGetContact",
@@ -1666,11 +1766,11 @@ var DidAuthSiopOpAuthenticator = class {
1666
1766
  hasher: this.hasher
1667
1767
  }
1668
1768
  }));
1669
- logger4.debug(`session: ${JSON.stringify(session.id, null, 2)}`);
1769
+ logger5.debug(`session: ${JSON.stringify(session.id, null, 2)}`);
1670
1770
  const verifiedAuthorizationRequest = await session.getAuthorizationRequest();
1671
1771
  const clientName = verifiedAuthorizationRequest.registrationMetadataPayload?.client_name;
1672
1772
  const url = verifiedAuthorizationRequest.responseURI ?? (args.url.includes("request_uri") ? decodeURIComponent(args.url.split("?request_uri=")[1].trim()) : verifiedAuthorizationRequest.issuer ?? verifiedAuthorizationRequest.registrationMetadataPayload?.client_id);
1673
- const uri = url.includes("://") ? new URL(url) : void 0;
1773
+ const uri = url?.includes("://") ? new URL(url) : void 0;
1674
1774
  const correlationId = uri?.hostname ?? await this.determineCorrelationId(uri, verifiedAuthorizationRequest, clientName, context);
1675
1775
  const clientId = verifiedAuthorizationRequest.authorizationRequest.getMergedProperty("client_id");
1676
1776
  return {
@@ -1745,7 +1845,7 @@ var DidAuthSiopOpAuthenticator = class {
1745
1845
  contactId: contact.id,
1746
1846
  identity: addedIdentity
1747
1847
  });
1748
- logger4.info(`Contact identity created: ${JSON.stringify(addedIdentity)}`);
1848
+ logger5.info(`Contact identity created: ${JSON.stringify(addedIdentity)}`);
1749
1849
  }
1750
1850
  }
1751
1851
  async siopSendResponse(args, context) {
@@ -1787,8 +1887,8 @@ var DidAuthSiopOpAuthenticator = class {
1787
1887
  };
1788
1888
 
1789
1889
  // src/machine/CallbackStateListener.ts
1790
- import { Loggers as Loggers5, LogLevel, LogMethod } from "@sphereon/ssi-types";
1791
- 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", {
1792
1892
  defaultLogLevel: LogLevel.DEBUG,
1793
1893
  methods: [
1794
1894
  LogMethod.CONSOLE
@@ -1797,21 +1897,21 @@ var logger5 = Loggers5.DEFAULT.options("sphereon:siopv2-oid4vp:op-auth", {
1797
1897
  var OID4VPCallbackStateListener = /* @__PURE__ */ __name((callbacks) => {
1798
1898
  return async (oid4vciMachine, state) => {
1799
1899
  if (state._event.type === "internal") {
1800
- logger5.debug("oid4vpCallbackStateListener: internal event");
1900
+ logger6.debug("oid4vpCallbackStateListener: internal event");
1801
1901
  return;
1802
1902
  }
1803
- logger5.info(`VP state listener state: ${JSON.stringify(state.value)}`);
1903
+ logger6.info(`VP state listener state: ${JSON.stringify(state.value)}`);
1804
1904
  if (!callbacks || callbacks.size === 0) {
1805
- 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)}`);
1806
1906
  return;
1807
1907
  }
1808
1908
  for (const [stateKey, callback] of callbacks) {
1809
1909
  if (state.matches(stateKey)) {
1810
- logger5.log(`VP state callback for state: ${JSON.stringify(state.value)}, will execute...`);
1811
- await callback(oid4vciMachine, state).then(() => logger5.log(`VP state callback executed for state: ${JSON.stringify(state.value)}`)).catch((error) => {
1812
- 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)}`);
1813
1913
  if (error.stack) {
1814
- logger5.error(error.stack);
1914
+ logger6.error(error.stack);
1815
1915
  }
1816
1916
  });
1817
1917
  break;
@@ -1824,8 +1924,8 @@ var OID4VPCallbackStateListener = /* @__PURE__ */ __name((callbacks) => {
1824
1924
  import { contextHasPlugin } from "@sphereon/ssi-sdk.agent-config";
1825
1925
  import { LinkHandlerAdapter } from "@sphereon/ssi-sdk.core";
1826
1926
  import { interpreterStartOrResume } from "@sphereon/ssi-sdk.xstate-machine-persistence";
1827
- import { Loggers as Loggers6 } from "@sphereon/ssi-types";
1828
- 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);
1829
1929
  var Siopv2OID4VPLinkHandler = class extends LinkHandlerAdapter {
1830
1930
  static {
1831
1931
  __name(this, "Siopv2OID4VPLinkHandler");
@@ -1845,7 +1945,7 @@ var Siopv2OID4VPLinkHandler = class extends LinkHandlerAdapter {
1845
1945
  this.idOpts = args.idOpts;
1846
1946
  }
1847
1947
  async handle(url, opts) {
1848
- logger6.debug(`handling SIOP link: ${url}`);
1948
+ logger7.debug(`handling SIOP link: ${url}`);
1849
1949
  const siopv2Machine = await this.context.agent.siopGetMachineInterpreter({
1850
1950
  url,
1851
1951
  idOpts: opts?.idOpts ?? this.idOpts,
@@ -1861,10 +1961,10 @@ var Siopv2OID4VPLinkHandler = class extends LinkHandlerAdapter {
1861
1961
  singletonCheck: true,
1862
1962
  noRegistration: this.noStateMachinePersistence
1863
1963
  });
1864
- logger6.debug(`SIOP machine started for link: ${url}`, init);
1964
+ logger7.debug(`SIOP machine started for link: ${url}`, init);
1865
1965
  } else {
1866
1966
  interpreter.start(opts?.machineState);
1867
- logger6.debug(`SIOP machine started for link: ${url}`);
1967
+ logger7.debug(`SIOP machine started for link: ${url}`);
1868
1968
  }
1869
1969
  }
1870
1970
  };
@@ -1873,7 +1973,6 @@ export {
1873
1973
  DID_PREFIX,
1874
1974
  DidAuthSiopOpAuthenticator,
1875
1975
  LOGGER_NAMESPACE,
1876
- OID4VP,
1877
1976
  OID4VPCallbackStateListener,
1878
1977
  OpSession,
1879
1978
  Siopv2HolderEvent,
@@ -1891,6 +1990,7 @@ export {
1891
1990
  createOID4VPPresentationSignCallback,
1892
1991
  createOP,
1893
1992
  createOPBuilder,
1993
+ createVerifiablePresentationForFormat,
1894
1994
  didAuthSiopOpAuthenticatorMethods,
1895
1995
  getSigningAlgo,
1896
1996
  plugin_schema_default as schema