@sphereon/ssi-sdk.siopv2-oid4vp-op-auth 0.34.1-fix.80 → 0.34.1-next.278

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -423,8 +423,8 @@ var plugin_schema_default = {
423
423
  };
424
424
 
425
425
  // src/agent/DidAuthSiopOpAuthenticator.ts
426
- var import_did_auth_siop5 = require("@sphereon/did-auth-siop");
427
- var import_ssi_sdk6 = require("@sphereon/ssi-sdk.data-store");
426
+ var import_did_auth_siop4 = require("@sphereon/did-auth-siop");
427
+ var import_ssi_sdk7 = require("@sphereon/ssi-sdk.data-store-types");
428
428
  var import_ssi_types7 = require("@sphereon/ssi-types");
429
429
  var import_uuid2 = require("uuid");
430
430
 
@@ -451,10 +451,8 @@ __name(createOID4VPPresentationSignCallback, "createOID4VPPresentationSignCallba
451
451
  async function createOPBuilder({ opOptions, idOpts: idOpts1, context }) {
452
452
  const eventEmitter = opOptions.eventEmitter ?? new import_events.EventEmitter();
453
453
  const builder = import_did_auth_siop.OP.builder().withResponseMode(opOptions.responseMode ?? import_did_auth_siop.ResponseMode.DIRECT_POST).withSupportedVersions(opOptions.supportedVersions ?? [
454
- import_did_auth_siop.SupportedVersion.SIOPv2_ID1,
455
- import_did_auth_siop.SupportedVersion.JWT_VC_PRESENTATION_PROFILE_v1,
456
- import_did_auth_siop.SupportedVersion.SIOPv2_D11,
457
- import_did_auth_siop.SupportedVersion.SIOPv2_D12_OID4VP_D18
454
+ import_did_auth_siop.SupportedVersion.OID4VP_v1,
455
+ import_did_auth_siop.SupportedVersion.SIOPv2_OID4VP_D28
458
456
  ]).withExpiresIn(opOptions.expiresIn ?? 300).withEventEmitter(eventEmitter).withRegistration({
459
457
  passBy: import_did_auth_siop.PassBy.VALUE
460
458
  });
@@ -864,19 +862,19 @@ var LOGGER_NAMESPACE = "sphereon:siopv2-oid4vp:op-auth";
864
862
  var DEFAULT_JWT_PROOF_TYPE = "JwtProof2020";
865
863
 
866
864
  // src/types/siop-service/index.ts
867
- var Siopv2HolderEvent = /* @__PURE__ */ function(Siopv2HolderEvent2) {
865
+ var Siopv2HolderEvent = /* @__PURE__ */ (function(Siopv2HolderEvent2) {
868
866
  Siopv2HolderEvent2["CONTACT_IDENTITY_CREATED"] = "contact_identity_created";
869
867
  Siopv2HolderEvent2["IDENTIFIER_CREATED"] = "identifier_created";
870
868
  return Siopv2HolderEvent2;
871
- }({});
872
- var SupportedLanguage = /* @__PURE__ */ function(SupportedLanguage2) {
869
+ })({});
870
+ var SupportedLanguage = /* @__PURE__ */ (function(SupportedLanguage2) {
873
871
  SupportedLanguage2["ENGLISH"] = "en";
874
872
  SupportedLanguage2["DUTCH"] = "nl";
875
873
  return SupportedLanguage2;
876
- }({});
874
+ })({});
877
875
 
878
876
  // src/types/machine/index.ts
879
- var Siopv2MachineStates = /* @__PURE__ */ function(Siopv2MachineStates2) {
877
+ var Siopv2MachineStates = /* @__PURE__ */ (function(Siopv2MachineStates2) {
880
878
  Siopv2MachineStates2["createConfig"] = "createConfig";
881
879
  Siopv2MachineStates2["getSiopRequest"] = "getSiopRequest";
882
880
  Siopv2MachineStates2["getSelectableCredentials"] = "getSelectableCredentials";
@@ -892,14 +890,14 @@ var Siopv2MachineStates = /* @__PURE__ */ function(Siopv2MachineStates2) {
892
890
  Siopv2MachineStates2["error"] = "error";
893
891
  Siopv2MachineStates2["done"] = "done";
894
892
  return Siopv2MachineStates2;
895
- }({});
896
- var Siopv2MachineAddContactStates = /* @__PURE__ */ function(Siopv2MachineAddContactStates2) {
893
+ })({});
894
+ var Siopv2MachineAddContactStates = /* @__PURE__ */ (function(Siopv2MachineAddContactStates2) {
897
895
  Siopv2MachineAddContactStates2["idle"] = "idle";
898
896
  Siopv2MachineAddContactStates2["executing"] = "executing";
899
897
  Siopv2MachineAddContactStates2["next"] = "next";
900
898
  return Siopv2MachineAddContactStates2;
901
- }({});
902
- var Siopv2MachineEvents = /* @__PURE__ */ function(Siopv2MachineEvents2) {
899
+ })({});
900
+ var Siopv2MachineEvents = /* @__PURE__ */ (function(Siopv2MachineEvents2) {
903
901
  Siopv2MachineEvents2["NEXT"] = "NEXT";
904
902
  Siopv2MachineEvents2["PREVIOUS"] = "PREVIOUS";
905
903
  Siopv2MachineEvents2["DECLINE"] = "DECLINE";
@@ -908,8 +906,8 @@ var Siopv2MachineEvents = /* @__PURE__ */ function(Siopv2MachineEvents2) {
908
906
  Siopv2MachineEvents2["CREATE_CONTACT"] = "CREATE_CONTACT";
909
907
  Siopv2MachineEvents2["SET_SELECTED_CREDENTIALS"] = "SET_SELECTED_CREDENTIALS";
910
908
  return Siopv2MachineEvents2;
911
- }({});
912
- var Siopv2MachineGuards = /* @__PURE__ */ function(Siopv2MachineGuards2) {
909
+ })({});
910
+ var Siopv2MachineGuards = /* @__PURE__ */ (function(Siopv2MachineGuards2) {
913
911
  Siopv2MachineGuards2["hasNoContactGuard"] = "Siopv2HasNoContactGuard";
914
912
  Siopv2MachineGuards2["createContactGuard"] = "Siopv2CreateContactGuard";
915
913
  Siopv2MachineGuards2["hasContactGuard"] = "Siopv2HasContactGuard";
@@ -919,8 +917,8 @@ var Siopv2MachineGuards = /* @__PURE__ */ function(Siopv2MachineGuards2) {
919
917
  Siopv2MachineGuards2["siopOnlyGuard"] = "Siopv2IsSiopOnlyGuard";
920
918
  Siopv2MachineGuards2["siopWithOID4VPGuard"] = "Siopv2IsSiopWithOID4VPGuard";
921
919
  return Siopv2MachineGuards2;
922
- }({});
923
- var Siopv2MachineServices = /* @__PURE__ */ function(Siopv2MachineServices2) {
920
+ })({});
921
+ var Siopv2MachineServices = /* @__PURE__ */ (function(Siopv2MachineServices2) {
924
922
  Siopv2MachineServices2["getSiopRequest"] = "getSiopRequest";
925
923
  Siopv2MachineServices2["getSelectableCredentials"] = "getSelectableCredentials";
926
924
  Siopv2MachineServices2["retrieveContact"] = "retrieveContact";
@@ -928,7 +926,7 @@ var Siopv2MachineServices = /* @__PURE__ */ function(Siopv2MachineServices2) {
928
926
  Siopv2MachineServices2["sendResponse"] = "sendResponse";
929
927
  Siopv2MachineServices2["createConfig"] = "createConfig";
930
928
  return Siopv2MachineServices2;
931
- }({});
929
+ })({});
932
930
 
933
931
  // src/types/identifier/index.ts
934
932
  var DID_PREFIX = "did";
@@ -1346,12 +1344,14 @@ var Siopv2Machine = class {
1346
1344
  };
1347
1345
 
1348
1346
  // src/services/Siopv2MachineService.ts
1349
- var import_did_auth_siop4 = require("@sphereon/did-auth-siop");
1350
- var import_ssi_sdk_ext3 = require("@sphereon/ssi-sdk-ext.identifier-resolution");
1351
- var import_ssi_sdk3 = require("@sphereon/ssi-sdk.credential-store");
1352
- var import_ssi_sdk4 = require("@sphereon/ssi-sdk.data-store");
1347
+ var import_utils = require("@sphereon/pex/dist/main/lib/utils/index.js");
1348
+ var import_ssi_sdk_ext3 = require("@sphereon/ssi-sdk-ext.did-utils");
1349
+ var import_ssi_sdk_ext4 = require("@sphereon/ssi-sdk-ext.identifier-resolution");
1350
+ var import_ssi_sdk3 = require("@sphereon/ssi-sdk.core");
1351
+ var import_ssi_sdk4 = require("@sphereon/ssi-sdk.credential-store");
1352
+ var import_ssi_sdk5 = require("@sphereon/ssi-sdk.data-store-types");
1353
+ var import_ssi_sdk6 = require("@sphereon/ssi-sdk.sd-jwt");
1353
1354
  var import_ssi_types6 = require("@sphereon/ssi-types");
1354
- var import_ssi_sdk5 = require("@sphereon/ssi-sdk.core");
1355
1355
  var import_dcql = require("dcql");
1356
1356
 
1357
1357
  // src/utils/dcql.ts
@@ -1392,12 +1392,12 @@ function convertToDcqlCredentials(credential, hasher) {
1392
1392
  __name(convertToDcqlCredentials, "convertToDcqlCredentials");
1393
1393
 
1394
1394
  // src/services/Siopv2MachineService.ts
1395
- var import_ssi_sdk_ext4 = require("@sphereon/ssi-sdk-ext.did-utils");
1395
+ var CLOCK_SKEW = 120;
1396
1396
  var logger3 = import_ssi_types6.Loggers.DEFAULT.get(LOGGER_NAMESPACE);
1397
1397
  var siopSendAuthorizationResponse = /* @__PURE__ */ __name(async (connectionType, args, context) => {
1398
1398
  const { agent } = context;
1399
1399
  const { credentials } = args;
1400
- if (connectionType !== import_ssi_sdk4.ConnectionType.SIOPv2_OpenID4VP) {
1400
+ if (connectionType !== import_ssi_sdk5.ConnectionType.SIOPv2_OpenID4VP) {
1401
1401
  return Promise.reject(Error(`No supported authentication provider for type: ${connectionType}`));
1402
1402
  }
1403
1403
  const session = await agent.siopGetOPSession({
@@ -1407,7 +1407,7 @@ var siopSendAuthorizationResponse = /* @__PURE__ */ __name(async (connectionType
1407
1407
  const aud = request.authorizationRequest.getMergedProperty("aud");
1408
1408
  logger3.debug(`AUD: ${aud}`);
1409
1409
  logger3.debug(JSON.stringify(request.authorizationRequest));
1410
- const domain = await request.authorizationRequest.getMergedProperty("client_id") ?? request.issuer ?? (request.versions.includes(import_did_auth_siop4.SupportedVersion.JWT_VC_PRESENTATION_PROFILE_v1) ? "https://self-issued.me/v2/openid-vc" : "https://self-issued.me/v2");
1410
+ const domain = await request.authorizationRequest.getMergedProperty("client_id") ?? request.issuer ?? "https://self-issued.me/v2";
1411
1411
  logger3.debug(`NONCE: ${session.nonce}, domain: ${domain}`);
1412
1412
  const firstUniqueDC = credentials[0];
1413
1413
  if (typeof firstUniqueDC !== "object" || !("digitalCredential" in firstUniqueDC)) {
@@ -1418,7 +1418,7 @@ var siopSendAuthorizationResponse = /* @__PURE__ */ __name(async (connectionType
1418
1418
  const firstVC = firstUniqueDC.uniformVerifiableCredential;
1419
1419
  const holder = import_ssi_types6.CredentialMapper.isSdJwtDecodedCredential(firstVC) ? firstVC.decodedPayload.cnf?.jwk ? (
1420
1420
  //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
1421
- `did:jwk:${(0, import_ssi_sdk5.encodeJoseBlob)(firstVC.decodedPayload.cnf?.jwk)}#0`
1421
+ `did:jwk:${(0, import_ssi_sdk3.encodeJoseBlob)(firstVC.decodedPayload.cnf?.jwk)}#0`
1422
1422
  ) : firstVC.decodedPayload.sub : Array.isArray(firstVC.credentialSubject) ? firstVC.credentialSubject[0].id : firstVC.credentialSubject.id;
1423
1423
  if (!digitalCredential.kmsKeyRef) {
1424
1424
  if (!holder) {
@@ -1432,7 +1432,7 @@ var siopSendAuthorizationResponse = /* @__PURE__ */ __name(async (connectionType
1432
1432
  logger3.debug(`Holder DID not found: ${holder}`);
1433
1433
  throw e;
1434
1434
  }
1435
- } else if ((0, import_ssi_sdk_ext3.isOID4VCIssuerIdentifier)(digitalCredential.kmsKeyRef)) {
1435
+ } else if ((0, import_ssi_sdk_ext4.isOID4VCIssuerIdentifier)(digitalCredential.kmsKeyRef)) {
1436
1436
  identifier = await session.context.agent.identifierManagedGetByOID4VCIssuer({
1437
1437
  identifier: firstUniqueDC.digitalCredential.kmsKeyRef
1438
1438
  });
@@ -1473,8 +1473,23 @@ var siopSendAuthorizationResponse = /* @__PURE__ */ __name(async (connectionType
1473
1473
  if (!originalVc) {
1474
1474
  continue;
1475
1475
  }
1476
+ const decodedSdJwt = await import_ssi_types6.CredentialMapper.decodeSdJwtVcAsync(originalVc, import_ssi_sdk6.defaultGenerateDigest);
1477
+ const updatedSdJwt = updateSdJwtCredential(decodedSdJwt, request.requestObject?.getPayload()?.nonce, domain);
1478
+ const presentationResult = await context.agent.createSdJwtPresentation({
1479
+ presentation: updatedSdJwt.compactSdJwtVc,
1480
+ kb: {
1481
+ payload: {
1482
+ ...updatedSdJwt.kbJwt?.payload,
1483
+ // FIXME SSISDK-44
1484
+ nonce: updatedSdJwt.kbJwt?.payload.nonce ?? request.requestObject.getPayload().nonce,
1485
+ // FIXME SSISDK-44
1486
+ aud: updatedSdJwt.kbJwt?.payload.aud ?? domain,
1487
+ iat: updatedSdJwt.kbJwt?.payload?.iat ?? Math.floor(Date.now() / 1e3 - CLOCK_SKEW)
1488
+ }
1489
+ }
1490
+ });
1476
1491
  if (originalVc) {
1477
- presentation[key] = originalVc;
1492
+ presentation[key] = presentationResult.presentation;
1478
1493
  }
1479
1494
  }
1480
1495
  }
@@ -1498,7 +1513,7 @@ var getSelectableCredentials = /* @__PURE__ */ __name(async (dcqlQuery, context)
1498
1513
  };
1499
1514
  const { agent } = agentContext;
1500
1515
  const uniqueVerifiableCredentials = await agent.crsGetUniqueCredentials({
1501
- filter: (0, import_ssi_sdk3.verifiableCredentialForRoleFilter)(import_ssi_sdk4.CredentialRole.HOLDER)
1516
+ filter: (0, import_ssi_sdk4.verifiableCredentialForRoleFilter)(import_ssi_types6.CredentialRole.HOLDER)
1502
1517
  });
1503
1518
  const branding = await agent.ibGetCredentialBranding();
1504
1519
  const dcqlCredentialsWithCredentials = new Map(uniqueVerifiableCredentials.map((vc) => [
@@ -1567,6 +1582,31 @@ var translateCorrelationIdToName = /* @__PURE__ */ __name(async (correlationId,
1567
1582
  }
1568
1583
  return contacts[0].contact.displayName;
1569
1584
  }, "translateCorrelationIdToName");
1585
+ var updateSdJwtCredential = /* @__PURE__ */ __name((credential, nonce, aud) => {
1586
+ const sdJwtCredential = credential;
1587
+ const hashAlg = sdJwtCredential.signedPayload._sd_alg ?? "sha-256";
1588
+ const sdHash = (0, import_utils.calculateSdHash)(sdJwtCredential.compactSdJwtVc, hashAlg, import_ssi_sdk6.defaultGenerateDigest);
1589
+ const kbJwt = {
1590
+ // alg MUST be set by the signer
1591
+ header: {
1592
+ typ: "kb+jwt"
1593
+ },
1594
+ payload: {
1595
+ iat: Math.floor((/* @__PURE__ */ new Date()).getTime() / 1e3),
1596
+ sd_hash: sdHash,
1597
+ ...nonce && {
1598
+ nonce
1599
+ },
1600
+ ...aud && {
1601
+ aud
1602
+ }
1603
+ }
1604
+ };
1605
+ return {
1606
+ ...sdJwtCredential,
1607
+ kbJwt
1608
+ };
1609
+ }, "updateSdJwtCredential");
1570
1610
 
1571
1611
  // src/agent/DidAuthSiopOpAuthenticator.ts
1572
1612
  var logger4 = import_ssi_types7.Loggers.DEFAULT.options(LOGGER_NAMESPACE, {}).get(LOGGER_NAMESPACE);
@@ -1727,7 +1767,7 @@ var DidAuthSiopOpAuthenticator = class {
1727
1767
  const verifiedAuthorizationRequest = await session.getAuthorizationRequest();
1728
1768
  const clientName = verifiedAuthorizationRequest.registrationMetadataPayload?.client_name;
1729
1769
  const url = verifiedAuthorizationRequest.responseURI ?? (args.url.includes("request_uri") ? decodeURIComponent(args.url.split("?request_uri=")[1].trim()) : verifiedAuthorizationRequest.issuer ?? verifiedAuthorizationRequest.registrationMetadataPayload?.client_id);
1730
- const uri = url.includes("://") ? new URL(url) : void 0;
1770
+ const uri = url?.includes("://") ? new URL(url) : void 0;
1731
1771
  const correlationId = uri?.hostname ?? await this.determineCorrelationId(uri, verifiedAuthorizationRequest, clientName, context);
1732
1772
  const clientId = verifiedAuthorizationRequest.authorizationRequest.getMergedProperty("client_id");
1733
1773
  return {
@@ -1785,12 +1825,12 @@ var DidAuthSiopOpAuthenticator = class {
1785
1825
  if (correlationId) {
1786
1826
  const identity = {
1787
1827
  alias: correlationId,
1788
- origin: import_ssi_sdk6.IdentityOrigin.EXTERNAL,
1828
+ origin: import_ssi_sdk7.IdentityOrigin.EXTERNAL,
1789
1829
  roles: [
1790
- import_ssi_sdk6.CredentialRole.ISSUER
1830
+ import_ssi_types7.CredentialRole.ISSUER
1791
1831
  ],
1792
1832
  identifier: {
1793
- type: correlationId.startsWith("did:") ? import_ssi_sdk6.CorrelationIdentifierType.DID : import_ssi_sdk6.CorrelationIdentifierType.URL,
1833
+ type: correlationId.startsWith("did:") ? import_ssi_sdk7.CorrelationIdentifierType.DID : import_ssi_sdk7.CorrelationIdentifierType.URL,
1794
1834
  correlationId
1795
1835
  }
1796
1836
  };
@@ -1813,7 +1853,7 @@ var DidAuthSiopOpAuthenticator = class {
1813
1853
  if (authorizationRequestData === void 0) {
1814
1854
  return Promise.reject(Error("Missing authorization request data in context"));
1815
1855
  }
1816
- const response = await siopSendAuthorizationResponse(import_ssi_sdk6.ConnectionType.SIOPv2_OpenID4VP, {
1856
+ const response = await siopSendAuthorizationResponse(import_ssi_sdk7.ConnectionType.SIOPv2_OpenID4VP, {
1817
1857
  sessionId: didAuthConfig.sessionId,
1818
1858
  ...args.idOpts && {
1819
1859
  idOpts: args.idOpts
@@ -1831,7 +1871,7 @@ var DidAuthSiopOpAuthenticator = class {
1831
1871
  return {
1832
1872
  body: responseBody,
1833
1873
  url: response?.url,
1834
- queryParams: (0, import_did_auth_siop5.decodeUriAsJson)(response?.url)
1874
+ queryParams: (0, import_did_auth_siop4.decodeUriAsJson)(response?.url)
1835
1875
  };
1836
1876
  }
1837
1877
  async siopGetSelectableCredentials(args, context) {
@@ -1878,12 +1918,12 @@ var OID4VPCallbackStateListener = /* @__PURE__ */ __name((callbacks) => {
1878
1918
  }, "OID4VPCallbackStateListener");
1879
1919
 
1880
1920
  // src/link-handler/index.ts
1881
- var import_ssi_sdk7 = require("@sphereon/ssi-sdk.agent-config");
1882
- var import_ssi_sdk8 = require("@sphereon/ssi-sdk.core");
1883
- var import_ssi_sdk9 = require("@sphereon/ssi-sdk.xstate-machine-persistence");
1921
+ var import_ssi_sdk8 = require("@sphereon/ssi-sdk.agent-config");
1922
+ var import_ssi_sdk9 = require("@sphereon/ssi-sdk.core");
1923
+ var import_ssi_sdk10 = require("@sphereon/ssi-sdk.xstate-machine-persistence");
1884
1924
  var import_ssi_types9 = require("@sphereon/ssi-types");
1885
1925
  var logger6 = import_ssi_types9.Loggers.DEFAULT.options(LOGGER_NAMESPACE, {}).get(LOGGER_NAMESPACE);
1886
- var Siopv2OID4VPLinkHandler = class extends import_ssi_sdk8.LinkHandlerAdapter {
1926
+ var Siopv2OID4VPLinkHandler = class extends import_ssi_sdk9.LinkHandlerAdapter {
1887
1927
  static {
1888
1928
  __name(this, "Siopv2OID4VPLinkHandler");
1889
1929
  }
@@ -1909,8 +1949,8 @@ var Siopv2OID4VPLinkHandler = class extends import_ssi_sdk8.LinkHandlerAdapter {
1909
1949
  stateNavigationListener: this.stateNavigationListener
1910
1950
  });
1911
1951
  const interpreter = siopv2Machine.interpreter;
1912
- if (!this.noStateMachinePersistence && !opts?.machineState && (0, import_ssi_sdk7.contextHasPlugin)(this.context, "machineStatesFindActive")) {
1913
- const init = await (0, import_ssi_sdk9.interpreterStartOrResume)({
1952
+ if (!this.noStateMachinePersistence && !opts?.machineState && (0, import_ssi_sdk8.contextHasPlugin)(this.context, "machineStatesFindActive")) {
1953
+ const init = await (0, import_ssi_sdk10.interpreterStartOrResume)({
1914
1954
  interpreter,
1915
1955
  context: this.context,
1916
1956
  cleanupAllOtherInstances: true,