@sphereon/ssi-sdk.siopv2-oid4vp-op-auth 0.34.1-feature.SSISDK.58.host.nonce.endpoint.194 → 0.34.1-feature.SSISDK.62.219

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.d.cts CHANGED
@@ -533,7 +533,7 @@ type OnContactIdentityCreatedArgs = {
533
533
  type OnIdentifierCreatedArgs = {
534
534
  identifier: IIdentifier;
535
535
  };
536
- type RequiredContext = IAgentContext<IContactManager & IDidAuthSiopOpAuthenticator & IDIDManager & IResolver & IIdentifierResolution & ICredentialStore & IIssuanceBranding>;
536
+ type RequiredContext = IAgentContext<IContactManager & IDidAuthSiopOpAuthenticator & IDIDManager & IResolver & IIdentifierResolution & ICredentialStore & IIssuanceBranding & ISDJwtPlugin>;
537
537
 
538
538
  type Siopv2MachineContext = {
539
539
  url: string;
package/dist/index.d.ts CHANGED
@@ -533,7 +533,7 @@ type OnContactIdentityCreatedArgs = {
533
533
  type OnIdentifierCreatedArgs = {
534
534
  identifier: IIdentifier;
535
535
  };
536
- type RequiredContext = IAgentContext<IContactManager & IDidAuthSiopOpAuthenticator & IDIDManager & IResolver & IIdentifierResolution & ICredentialStore & IIssuanceBranding>;
536
+ type RequiredContext = IAgentContext<IContactManager & IDidAuthSiopOpAuthenticator & IDIDManager & IResolver & IIdentifierResolution & ICredentialStore & IIssuanceBranding & ISDJwtPlugin>;
537
537
 
538
538
  type Siopv2MachineContext = {
539
539
  url: string;
package/dist/index.js CHANGED
@@ -1287,13 +1287,14 @@ var Siopv2Machine = class {
1287
1287
  };
1288
1288
 
1289
1289
  // src/services/Siopv2MachineService.ts
1290
- import { SupportedVersion as SupportedVersion2 } from "@sphereon/did-auth-siop";
1290
+ import { calculateSdHash } from "@sphereon/pex/dist/main/lib/utils";
1291
+ import { getOrCreatePrimaryIdentifier, SupportedDidMethodEnum } from "@sphereon/ssi-sdk-ext.did-utils";
1291
1292
  import { isOID4VCIssuerIdentifier } from "@sphereon/ssi-sdk-ext.identifier-resolution";
1293
+ import { encodeJoseBlob } from "@sphereon/ssi-sdk.core";
1292
1294
  import { verifiableCredentialForRoleFilter } from "@sphereon/ssi-sdk.credential-store";
1293
1295
  import { ConnectionType } from "@sphereon/ssi-sdk.data-store";
1294
- import { CredentialRole } from "@sphereon/ssi-types";
1295
- import { CredentialMapper as CredentialMapper3, Loggers as Loggers3 } from "@sphereon/ssi-types";
1296
- import { encodeJoseBlob } from "@sphereon/ssi-sdk.core";
1296
+ import { defaultGenerateDigest } from "@sphereon/ssi-sdk.sd-jwt";
1297
+ import { CredentialMapper as CredentialMapper3, CredentialRole, Loggers as Loggers3 } from "@sphereon/ssi-types";
1297
1298
  import { DcqlPresentation, DcqlQuery } from "dcql";
1298
1299
 
1299
1300
  // src/utils/dcql.ts
@@ -1334,7 +1335,7 @@ function convertToDcqlCredentials(credential, hasher) {
1334
1335
  __name(convertToDcqlCredentials, "convertToDcqlCredentials");
1335
1336
 
1336
1337
  // src/services/Siopv2MachineService.ts
1337
- import { getOrCreatePrimaryIdentifier, SupportedDidMethodEnum } from "@sphereon/ssi-sdk-ext.did-utils";
1338
+ var CLOCK_SKEW = 120;
1338
1339
  var logger3 = Loggers3.DEFAULT.get(LOGGER_NAMESPACE);
1339
1340
  var siopSendAuthorizationResponse = /* @__PURE__ */ __name(async (connectionType, args, context) => {
1340
1341
  const { agent } = context;
@@ -1349,7 +1350,7 @@ var siopSendAuthorizationResponse = /* @__PURE__ */ __name(async (connectionType
1349
1350
  const aud = request.authorizationRequest.getMergedProperty("aud");
1350
1351
  logger3.debug(`AUD: ${aud}`);
1351
1352
  logger3.debug(JSON.stringify(request.authorizationRequest));
1352
- 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");
1353
+ const domain = await request.authorizationRequest.getMergedProperty("client_id") ?? request.issuer ?? "https://self-issued.me/v2";
1353
1354
  logger3.debug(`NONCE: ${session.nonce}, domain: ${domain}`);
1354
1355
  const firstUniqueDC = credentials[0];
1355
1356
  if (typeof firstUniqueDC !== "object" || !("digitalCredential" in firstUniqueDC)) {
@@ -1415,8 +1416,23 @@ var siopSendAuthorizationResponse = /* @__PURE__ */ __name(async (connectionType
1415
1416
  if (!originalVc) {
1416
1417
  continue;
1417
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
+ });
1418
1434
  if (originalVc) {
1419
- presentation[key] = originalVc;
1435
+ presentation[key] = presentationResult.presentation;
1420
1436
  }
1421
1437
  }
1422
1438
  }
@@ -1509,6 +1525,31 @@ var translateCorrelationIdToName = /* @__PURE__ */ __name(async (correlationId,
1509
1525
  }
1510
1526
  return contacts[0].contact.displayName;
1511
1527
  }, "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");
1512
1553
 
1513
1554
  // src/agent/DidAuthSiopOpAuthenticator.ts
1514
1555
  var logger4 = Loggers4.DEFAULT.options(LOGGER_NAMESPACE, {}).get(LOGGER_NAMESPACE);