@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth 0.34.1-fix.171 → 0.34.1-fix.182

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.ts CHANGED
@@ -9,12 +9,13 @@ import { IIdentifierResolution, ManagedIdentifierOptsOrResult, ExternalIdentifie
9
9
  import { IJwtService } from '@sphereon/ssi-sdk-ext.jwt-service';
10
10
  import { ICredentialValidation, SchemaValidation } from '@sphereon/ssi-sdk.credential-validation';
11
11
  import { ImDLMdoc } from '@sphereon/ssi-sdk.mdl-mdoc';
12
- import { IPDManager, VersionControlMode } from '@sphereon/ssi-sdk.pd-manager';
12
+ import { IPDManager, ImportDcqlQueryItem, VersionControlMode } from '@sphereon/ssi-sdk.pd-manager';
13
13
  import { IPresentationExchange } from '@sphereon/ssi-sdk.presentation-exchange';
14
14
  import { ISDJwtPlugin } from '@sphereon/ssi-sdk.sd-jwt';
15
15
  import { AuthorizationRequestStateStatus } from '@sphereon/ssi-sdk.siopv2-oid4vp-common';
16
- import { DcqlQueryPayload, HasherSync } from '@sphereon/ssi-types';
16
+ import { HasherSync } from '@sphereon/ssi-types';
17
17
  import { VerifyCallback } from '@sphereon/wellknown-dids-client';
18
+ import { DcqlQuery } from 'dcql';
18
19
  import { Resolvable } from 'did-resolver';
19
20
  import { EventEmitter } from 'events';
20
21
 
@@ -435,9 +436,10 @@ interface IGetAuthResponseStateArgs {
435
436
  queryId?: string;
436
437
  errorOnNotFound?: boolean;
437
438
  progressRequestStateTo?: AuthorizationRequestStateStatus;
439
+ includeVerifiedData?: VerifiedDataMode;
438
440
  }
439
441
  interface IUpdateRequestStateArgs {
440
- queryId?: string;
442
+ queryId: string;
441
443
  correlationId: string;
442
444
  state: AuthorizationRequestStateStatus;
443
445
  error?: string;
@@ -451,14 +453,10 @@ interface IVerifyAuthResponseStateArgs {
451
453
  queryId?: string;
452
454
  correlationId: string;
453
455
  audience?: string;
454
- dcqlQueryPayload?: DcqlQueryPayload;
455
- }
456
- interface IDefinitionPair {
457
- definitionPayload?: IPresentationDefinition;
458
- dcqlPayload?: DcqlQueryPayload;
456
+ dcqlQuery?: DcqlQuery;
459
457
  }
460
458
  interface ImportDefinitionsArgs {
461
- queries: Array<IDefinitionPair>;
459
+ importItems: Array<ImportDcqlQueryItem>;
462
460
  tenantId?: string;
463
461
  version?: string;
464
462
  versionControlMode?: VersionControlMode;
@@ -897,4 +895,4 @@ declare class SIOPv2RP implements IAgentPlugin {
897
895
  private getDefaultOptions;
898
896
  }
899
897
 
900
- export { type CredentialOpts, type IAuthRequestDetails, type IAuthorizationRequestPayloads, type ICreateAuthRequestArgs, type IDefinitionPair, type IDeleteAuthStateArgs, type IGetAuthRequestStateArgs, type IGetAuthResponseStateArgs, type IGetRedirectUriArgs, type IPEXDefinitionPersistArgs, type IPEXInstanceOptions, type IPEXOptions, type IRPDefaultOpts, type IRPOptions, type IRequiredContext, type ISIOPIdentifierOptions, type ISIOPv2RP, type ISiopRPInstanceArgs, type ISiopv2RPOpts, type IUpdateRequestStateArgs, type IVerifyAuthResponseStateArgs, type ImportDefinitionsArgs, type PerDidResolver, SIOPv2RP, type VerificationPolicies, VerifiedDataMode, plugin_schema as schema };
898
+ export { type CredentialOpts, type IAuthRequestDetails, type IAuthorizationRequestPayloads, type ICreateAuthRequestArgs, type IDeleteAuthStateArgs, type IGetAuthRequestStateArgs, type IGetAuthResponseStateArgs, type IGetRedirectUriArgs, type IPEXDefinitionPersistArgs, type IPEXInstanceOptions, type IPEXOptions, type IRPDefaultOpts, type IRPOptions, type IRequiredContext, type ISIOPIdentifierOptions, type ISIOPv2RP, type ISiopRPInstanceArgs, type ISiopv2RPOpts, type IUpdateRequestStateArgs, type IVerifyAuthResponseStateArgs, type ImportDefinitionsArgs, type PerDidResolver, SIOPv2RP, type VerificationPolicies, VerifiedDataMode, plugin_schema as schema };
package/dist/index.js CHANGED
@@ -337,7 +337,7 @@ import { AuthorizationResponseStateStatus, decodeUriAsJson } from "@sphereon/did
337
337
  import { getAgentResolver as getAgentResolver2 } from "@sphereon/ssi-sdk-ext.did-utils";
338
338
  import { shaHasher as defaultHasher2 } from "@sphereon/ssi-sdk.core";
339
339
  import { CredentialMapper as CredentialMapper2 } from "@sphereon/ssi-types";
340
- import { DcqlPresentation, DcqlQuery } from "dcql";
340
+ import { DcqlQuery } from "dcql";
341
341
 
342
342
  // src/functions.ts
343
343
  import { ClientIdentifierPrefix, InMemoryRPSessionManager, PassBy, PropertyTarget, ResponseMode, ResponseType, RevocationVerification, RP, Scope, SubjectType, SupportedVersion } from "@sphereon/did-auth-siop";
@@ -413,7 +413,7 @@ async function createRPBuilder(args) {
413
413
  const presentationDefinitionItems = await context.agent.pdmGetDefinitions({
414
414
  filter: [
415
415
  {
416
- definitionId: pexOpts.queryId,
416
+ queryId: pexOpts.queryId,
417
417
  version: pexOpts.version,
418
418
  tenantId: pexOpts.tenantId
419
419
  }
@@ -759,26 +759,23 @@ var SIOPv2RP = class _SIOPv2RP {
759
759
  return void 0;
760
760
  }
761
761
  const responseState = authorizationResponseState;
762
- if (responseState.status === AuthorizationResponseStateStatus.VERIFIED) {
762
+ if (responseState.status === AuthorizationResponseStateStatus.VERIFIED && args.includeVerifiedData && args.includeVerifiedData !== VerifiedDataMode.NONE) {
763
763
  let hasher;
764
764
  if (CredentialMapper2.isSdJwtEncoded(responseState.response.payload.vp_token) && (!rpInstance.rpOptions.credentialOpts?.hasher || typeof rpInstance.rpOptions.credentialOpts?.hasher !== "function")) {
765
765
  hasher = defaultHasher2;
766
766
  }
767
- const vpToken = responseState.response.payload.vp_token && JSON.parse(responseState.response.payload.vp_token);
768
- const xx = DcqlPresentation.parse(vpToken);
769
- console.log(`IS DCQL PRESENTATION: ${JSON.stringify(xx)}`);
770
- const claims = [];
771
- for (const [key, value] of Object.entries(vpToken)) {
772
- const presentationDecoded = CredentialMapper2.decodeVerifiablePresentation(
773
- value,
774
- //todo: later we want to conditionally pass in options for mdl-mdoc here
775
- hasher
776
- );
777
- console.log(`presentationDecoded: ${JSON.stringify(presentationDecoded)}`);
778
- const allClaims = {};
779
- const presentationOrClaims = this.presentationOrClaimsFrom(presentationDecoded);
780
- if ("verifiableCredential" in presentationOrClaims) {
781
- for (const credential of presentationOrClaims.verifiableCredential) {
767
+ const presentationDecoded = CredentialMapper2.decodeVerifiablePresentation(
768
+ responseState.response.payload.vp_token,
769
+ //todo: later we want to conditionally pass in options for mdl-mdoc here
770
+ hasher
771
+ );
772
+ switch (args.includeVerifiedData) {
773
+ case VerifiedDataMode.VERIFIED_PRESENTATION:
774
+ responseState.response.payload.verifiedData = this.presentationOrClaimsFrom(presentationDecoded);
775
+ break;
776
+ case VerifiedDataMode.CREDENTIAL_SUBJECT_FLATTENED:
777
+ const allClaims = {};
778
+ for (const credential of this.presentationOrClaimsFrom(presentationDecoded).verifiableCredential || []) {
782
779
  const vc = credential;
783
780
  const schemaValidationResult = await context.agent.cvVerifySchema({
784
781
  credential,
@@ -794,41 +791,19 @@ var SIOPv2RP = class _SIOPv2RP {
794
791
  if (!("id" in allClaims)) {
795
792
  allClaims["id"] = credentialSubject.id;
796
793
  }
797
- Object.entries(credentialSubject).forEach(([key2, value2]) => {
798
- if (!(key2 in allClaims)) {
799
- allClaims[key2] = value2;
794
+ Object.entries(credentialSubject).forEach(([key, value]) => {
795
+ if (!(key in allClaims)) {
796
+ allClaims[key] = value;
800
797
  }
801
798
  });
802
- claims.push({
803
- id: key,
804
- type: vc.type[0],
805
- claims: allClaims
806
- });
807
799
  }
808
- } else {
809
- claims.push({
810
- id: key,
811
- type: presentationDecoded.decodedPayload.vct,
812
- claims: presentationOrClaims
813
- });
814
- }
800
+ responseState.verifiedData = allClaims;
801
+ break;
815
802
  }
816
- responseState.verifiedData = {
817
- ...responseState.response.payload.vp_token && {
818
- authorization_response: {
819
- vp_token: typeof responseState.response.payload.vp_token === "string" ? JSON.parse(responseState.response.payload.vp_token) : responseState.response.payload.vp_token
820
- }
821
- },
822
- ...claims.length > 0 && {
823
- credential_claims: claims
824
- }
825
- };
826
803
  }
827
804
  return responseState;
828
805
  }
829
- presentationOrClaimsFrom = /* @__PURE__ */ __name((presentationDecoded) => {
830
- return CredentialMapper2.isSdJwtDecodedCredential(presentationDecoded) ? presentationDecoded.decodedPayload : CredentialMapper2.toUniformPresentation(presentationDecoded);
831
- }, "presentationOrClaimsFrom");
806
+ presentationOrClaimsFrom = /* @__PURE__ */ __name((presentationDecoded) => CredentialMapper2.isSdJwtDecodedCredential(presentationDecoded) ? presentationDecoded.decodedPayload : CredentialMapper2.toUniformPresentation(presentationDecoded), "presentationOrClaimsFrom");
832
807
  async siopUpdateRequestState(args, context) {
833
808
  if (args.state !== "authorization_request_created") {
834
809
  throw Error(`Only 'authorization_request_created' status is supported for this method at this point`);
@@ -857,39 +832,23 @@ var SIOPv2RP = class _SIOPv2RP {
857
832
  queryId: args.queryId
858
833
  }, context).then((rp) => rp.get(context).then((rp2) => rp2.verifyAuthorizationResponse(authResponse, {
859
834
  correlationId: args.correlationId,
860
- ...args.dcqlQueryPayload ? {
861
- dcqlQuery: args.dcqlQueryPayload.dcqlQuery
835
+ ...args.dcqlQuery ? {
836
+ dcqlQuery: args.dcqlQuery
862
837
  } : {},
863
838
  audience: args.audience
864
839
  })));
865
840
  }
866
841
  async siopImportDefinitions(args, context) {
867
- const { queries, tenantId, version, versionControlMode } = args;
868
- await Promise.all(queries.map(async (definitionPair) => {
869
- const definitionPayload = definitionPair.definitionPayload;
870
- if (!definitionPayload && !definitionPair.dcqlPayload) {
871
- return Promise.reject(Error("Either dcqlPayload or definitionPayload must be suppplied"));
872
- }
873
- let definitionId;
874
- if (definitionPair.dcqlPayload) {
875
- DcqlQuery.validate(definitionPair.dcqlPayload.dcqlQuery);
876
- console.log(`persisting DCQL definition ${definitionPair.dcqlPayload.queryId} with versionControlMode ${versionControlMode}`);
877
- definitionId = definitionPair.dcqlPayload.queryId;
878
- }
879
- if (definitionPayload) {
880
- await context.agent.pexValidateDefinition({
881
- definition: definitionPayload
882
- });
883
- console.log(`persisting PEX definition ${definitionPayload.id} / ${definitionPayload.name} with versionControlMode ${versionControlMode}`);
884
- definitionId = definitionPayload.id;
885
- }
842
+ const { importItems, tenantId, version, versionControlMode } = args;
843
+ await Promise.all(importItems.map(async (importItem) => {
844
+ DcqlQuery.validate(importItem.query);
845
+ console.log(`persisting DCQL definition ${importItem.queryId} with versionControlMode ${versionControlMode}`);
886
846
  return context.agent.pdmPersistDefinition({
887
847
  definitionItem: {
888
- definitionId,
848
+ queryId: importItem.queryId,
889
849
  tenantId,
890
850
  version,
891
- definitionPayload,
892
- dcqlPayload: definitionPair.dcqlPayload
851
+ query: importItem.query
893
852
  },
894
853
  opts: {
895
854
  versionControlMode