@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth 0.34.1-feature.SSISDK.45.93 → 0.34.1-feature.SSISDK.46.151

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
@@ -13,7 +13,7 @@ import { IPDManager, 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 { AdditionalClaims, DcqlQueryREST, HasherSync } from '@sphereon/ssi-types';
16
+ import { AdditionalClaims, DcqlQueryPayload, HasherSync } from '@sphereon/ssi-types';
17
17
  import { VerifyCallback } from '@sphereon/wellknown-dids-client';
18
18
  import { Resolvable } from 'did-resolver';
19
19
  import { EventEmitter } from 'events';
@@ -41,8 +41,9 @@ interface ISiopv2RPOpts {
41
41
  interface IRPDefaultOpts extends IRPOptions {
42
42
  }
43
43
  interface ICreateAuthRequestArgs {
44
- definitionId: string;
44
+ queryId: string;
45
45
  correlationId: string;
46
+ useQueryIdInstance?: boolean;
46
47
  responseURIType: ResponseURIType;
47
48
  responseURI: string;
48
49
  responseRedirectURI?: string;
@@ -54,46 +55,46 @@ interface ICreateAuthRequestArgs {
54
55
  }
55
56
  interface IGetAuthRequestStateArgs {
56
57
  correlationId: string;
57
- definitionId: string;
58
+ queryId?: string;
58
59
  errorOnNotFound?: boolean;
59
60
  }
60
61
  interface IGetAuthResponseStateArgs {
61
62
  correlationId: string;
62
- definitionId: string;
63
+ queryId?: string;
63
64
  errorOnNotFound?: boolean;
64
65
  progressRequestStateTo?: AuthorizationRequestStateStatus;
65
66
  includeVerifiedData?: VerifiedDataMode;
66
67
  }
67
68
  interface IUpdateRequestStateArgs {
68
- definitionId: string;
69
+ queryId: string;
69
70
  correlationId: string;
70
71
  state: AuthorizationRequestStateStatus;
71
72
  error?: string;
72
73
  }
73
74
  interface IDeleteAuthStateArgs {
74
75
  correlationId: string;
75
- definitionId: string;
76
+ queryId?: string;
76
77
  }
77
78
  interface IVerifyAuthResponseStateArgs {
78
79
  authorizationResponse: string | AuthorizationResponsePayload;
79
- definitionId?: string;
80
+ queryId?: string;
80
81
  correlationId: string;
81
82
  audience?: string;
82
- dcqlQuery?: DcqlQueryREST;
83
+ dcqlQueryPayload?: DcqlQueryPayload;
83
84
  }
84
85
  interface IDefinitionPair {
85
- definitionPayload: IPresentationDefinition;
86
- dcqlPayload?: DcqlQueryREST;
86
+ definitionPayload?: IPresentationDefinition;
87
+ dcqlPayload?: DcqlQueryPayload;
87
88
  }
88
89
  interface ImportDefinitionsArgs {
89
- definitions: Array<IDefinitionPair>;
90
+ queries: Array<IDefinitionPair>;
90
91
  tenantId?: string;
91
92
  version?: string;
92
93
  versionControlMode?: VersionControlMode;
93
94
  }
94
95
  interface IGetRedirectUriArgs {
95
96
  correlationId: string;
96
- definitionId?: string;
97
+ queryId?: string;
97
98
  state?: string;
98
99
  }
99
100
  interface IAuthorizationRequestPayloads {
@@ -106,7 +107,7 @@ interface IPEXDefinitionPersistArgs extends IPEXInstanceOptions {
106
107
  ttl?: number;
107
108
  }
108
109
  interface ISiopRPInstanceArgs {
109
- definitionId?: string;
110
+ queryId?: string;
110
111
  responseRedirectURI?: string;
111
112
  }
112
113
  interface IPEXInstanceOptions extends IPEXOptions {
@@ -127,7 +128,7 @@ interface IRPOptions {
127
128
  }
128
129
  interface IPEXOptions {
129
130
  presentationVerifyCallback?: PresentationVerificationCallback;
130
- definitionId: string;
131
+ queryId: string;
131
132
  version?: string;
132
133
  tenantId?: string;
133
134
  }
@@ -171,8 +172,8 @@ declare class RPInstance {
171
172
  hasDefinition(): boolean;
172
173
  get definitionId(): string | undefined;
173
174
  getPresentationDefinition(context: IRequiredContext): Promise<IPresentationDefinition | undefined>;
174
- createAuthorizationRequestURI(createArgs: Omit<ICreateAuthRequestArgs, 'definitionId'>, context: IRequiredContext): Promise<URI>;
175
- createAuthorizationRequest(createArgs: Omit<ICreateAuthRequestArgs, 'definitionId'>, context: IRequiredContext): Promise<AuthorizationRequest>;
175
+ createAuthorizationRequestURI(createArgs: ICreateAuthRequestArgs, context: IRequiredContext): Promise<URI>;
176
+ createAuthorizationRequest(createArgs: Omit<ICreateAuthRequestArgs, 'queryId'>, context: IRequiredContext): Promise<AuthorizationRequest>;
176
177
  }
177
178
 
178
179
  declare class SIOPv2RP implements IAgentPlugin {
@@ -193,9 +194,9 @@ declare class SIOPv2RP implements IAgentPlugin {
193
194
  private siopVerifyAuthResponse;
194
195
  private siopImportDefinitions;
195
196
  private siopGetRedirectURI;
196
- getRPInstance({ definitionId, responseRedirectURI }: ISiopRPInstanceArgs, context: IRequiredContext): Promise<RPInstance>;
197
+ getRPInstance({ queryId, responseRedirectURI }: ISiopRPInstanceArgs, context: IRequiredContext): Promise<RPInstance>;
197
198
  getRPOptions(context: IRequiredContext, opts: {
198
- definitionId?: string;
199
+ queryId?: string;
199
200
  responseRedirectURI?: string;
200
201
  }): Promise<IRPOptions>;
201
202
  getInstanceOpts(definitionId?: string): IPEXInstanceOptions | undefined;
package/dist/index.js CHANGED
@@ -344,6 +344,7 @@ var require_plugin_schema = __commonJS({
344
344
  import { AuthorizationResponseStateStatus, decodeUriAsJson } from "@sphereon/did-auth-siop";
345
345
  import { getAgentResolver as getAgentResolver2 } from "@sphereon/ssi-sdk-ext.did-utils";
346
346
  import { CredentialMapper as CredentialMapper2 } from "@sphereon/ssi-types";
347
+ import { DcqlQuery } from "dcql";
347
348
 
348
349
  // src/functions.ts
349
350
  import { InMemoryRPSessionManager, PassBy, PropertyTarget, ResponseMode, ResponseType, RevocationVerification, RP, Scope, SubjectType, SupportedVersion } from "@sphereon/did-auth-siop";
@@ -376,8 +377,7 @@ function getPresentationVerificationCallback(idOpts, context) {
376
377
  async function presentationVerificationCallback(args, presentationSubmission) {
377
378
  if (CredentialMapper.isSdJwtEncoded(args)) {
378
379
  const result2 = await context.agent.verifySdJwtPresentation({
379
- presentation: args,
380
- kb: true
380
+ presentation: args
381
381
  });
382
382
  return {
383
383
  verified: !!result2.payload
@@ -416,11 +416,11 @@ async function createRPBuilder(args) {
416
416
  const { identifierOpts } = rpOpts;
417
417
  let definition = args.definition;
418
418
  let dcqlQuery = args.dcql;
419
- if (!definition && pexOpts && pexOpts.definitionId) {
419
+ if (!definition && pexOpts && pexOpts.queryId) {
420
420
  const presentationDefinitionItems = await context.agent.pdmGetDefinitions({
421
421
  filter: [
422
422
  {
423
- definitionId: pexOpts.definitionId,
423
+ definitionId: pexOpts.queryId,
424
424
  version: pexOpts.version,
425
425
  tenantId: pexOpts.tenantId
426
426
  }
@@ -428,9 +428,8 @@ async function createRPBuilder(args) {
428
428
  });
429
429
  if (presentationDefinitionItems.length > 0) {
430
430
  const presentationDefinitionItem = presentationDefinitionItems[0];
431
- definition = presentationDefinitionItem.definitionPayload;
432
431
  if (!dcqlQuery && presentationDefinitionItem.dcqlPayload) {
433
- dcqlQuery = presentationDefinitionItem.dcqlPayload;
432
+ dcqlQuery = presentationDefinitionItem.dcqlPayload.dcqlQuery;
434
433
  }
435
434
  }
436
435
  }
@@ -500,19 +499,14 @@ async function createRPBuilder(args) {
500
499
  }, context)).withRevocationVerification(RevocationVerification.NEVER).withPresentationVerification(getPresentationVerificationCallback(identifierOpts.idOpts, context));
501
500
  const oidfOpts = identifierOpts.oidfOpts;
502
501
  if (oidfOpts && isExternalIdentifierOIDFEntityIdOpts(oidfOpts)) {
503
- builder.withEntityId(oidfOpts.identifier, PropertyTarget.REQUEST_OBJECT).withClientIdScheme("entity_id", PropertyTarget.REQUEST_OBJECT);
502
+ builder.withEntityId(oidfOpts.identifier, PropertyTarget.REQUEST_OBJECT);
504
503
  } else {
505
504
  const resolution = await context.agent.identifierManagedGet(identifierOpts.idOpts);
506
- builder.withClientId(resolution.issuer ?? (isManagedIdentifierDidResult(resolution) ? resolution.did : resolution.jwkThumbprint), PropertyTarget.REQUEST_OBJECT).withClientIdScheme(resolution.clientIdScheme ?? identifierOpts.idOpts.clientIdScheme, PropertyTarget.REQUEST_OBJECT);
505
+ builder.withClientId(resolution.issuer ?? (isManagedIdentifierDidResult(resolution) ? resolution.did : resolution.jwkThumbprint), PropertyTarget.REQUEST_OBJECT);
507
506
  }
508
507
  if (hasher) {
509
508
  builder.withHasher(hasher);
510
509
  }
511
- if (definition) {
512
- builder.withPresentationDefinition({
513
- definition
514
- }, PropertyTarget.REQUEST_OBJECT);
515
- }
516
510
  if (dcqlQuery) {
517
511
  builder.withDcqlQuery(dcqlQuery);
518
512
  }
@@ -608,7 +602,7 @@ var RPInstance = class {
608
602
  return this.definitionId !== void 0;
609
603
  }
610
604
  get definitionId() {
611
- return this.pexOptions?.definitionId;
605
+ return this.pexOptions?.queryId;
612
606
  }
613
607
  async getPresentationDefinition(context) {
614
608
  return this.definitionId ? await context.agent.pexStoreGetDefinition({
@@ -617,7 +611,7 @@ var RPInstance = class {
617
611
  }) : void 0;
618
612
  }
619
613
  async createAuthorizationRequestURI(createArgs, context) {
620
- const { correlationId, claims, requestByReferenceURI, responseURI, responseURIType } = createArgs;
614
+ const { correlationId, queryId, claims, requestByReferenceURI, responseURI, responseURIType } = createArgs;
621
615
  const nonce = createArgs.nonce ?? uuidv4();
622
616
  const state = createArgs.state ?? correlationId;
623
617
  let jwtIssuer;
@@ -645,6 +639,7 @@ var RPInstance = class {
645
639
  return await this.get(context).then((rp) => rp.createAuthorizationRequestURI({
646
640
  version: getRequestVersion(this.rpOptions),
647
641
  correlationId,
642
+ queryId,
648
643
  nonce,
649
644
  state,
650
645
  claims,
@@ -730,30 +725,32 @@ var SIOPv2RP = class _SIOPv2RP {
730
725
  }
731
726
  async createAuthorizationRequestURI(createArgs, context) {
732
727
  return await this.getRPInstance({
733
- definitionId: createArgs.definitionId,
734
- responseRedirectURI: createArgs.responseRedirectURI
728
+ responseRedirectURI: createArgs.responseRedirectURI,
729
+ ...createArgs.useQueryIdInstance === true && {
730
+ queryId: createArgs.queryId
731
+ }
735
732
  }, context).then((rp) => rp.createAuthorizationRequestURI(createArgs, context)).then((URI) => URI.encodedUri);
736
733
  }
737
734
  async createAuthorizationRequestPayloads(createArgs, context) {
738
735
  return await this.getRPInstance({
739
- definitionId: createArgs.definitionId
736
+ queryId: createArgs.queryId
740
737
  }, context).then((rp) => rp.createAuthorizationRequest(createArgs, context)).then(async (request) => {
741
738
  const authRequest = {
742
739
  authorizationRequest: request.payload,
743
740
  requestObject: await request.requestObjectJwt(),
744
- requestObjectDecoded: await request.requestObject?.getPayload()
741
+ requestObjectDecoded: request.requestObject?.getPayload()
745
742
  };
746
743
  return authRequest;
747
744
  });
748
745
  }
749
746
  async siopGetRequestState(args, context) {
750
747
  return await this.getRPInstance({
751
- definitionId: args.definitionId
748
+ queryId: args.queryId
752
749
  }, context).then((rp) => rp.get(context).then((rp2) => rp2.sessionManager.getRequestStateByCorrelationId(args.correlationId, args.errorOnNotFound)));
753
750
  }
754
751
  async siopGetResponseState(args, context) {
755
752
  const rpInstance = await this.getRPInstance({
756
- definitionId: args.definitionId
753
+ queryId: args.queryId
757
754
  }, context);
758
755
  const authorizationResponseState = await rpInstance.get(context).then((rp) => rp.sessionManager.getResponseStateByCorrelationId(args.correlationId, args.errorOnNotFound));
759
756
  if (authorizationResponseState === void 0) {
@@ -806,11 +803,11 @@ var SIOPv2RP = class _SIOPv2RP {
806
803
  }
807
804
  presentationOrClaimsFrom = /* @__PURE__ */ __name((presentationDecoded) => CredentialMapper2.isSdJwtDecodedCredential(presentationDecoded) ? presentationDecoded.decodedPayload : CredentialMapper2.toUniformPresentation(presentationDecoded), "presentationOrClaimsFrom");
808
805
  async siopUpdateRequestState(args, context) {
809
- if (args.state !== "sent") {
810
- throw Error(`Only 'sent' status is supported for this method at this point`);
806
+ if (args.state !== "authorization_request_created") {
807
+ throw Error(`Only 'authorization_request_created' status is supported for this method at this point`);
811
808
  }
812
809
  return await this.getRPInstance({
813
- definitionId: args.definitionId
810
+ queryId: args.queryId
814
811
  }, context).then((rp) => rp.get(context).then(async (rp2) => {
815
812
  await rp2.signalAuthRequestRetrieved({
816
813
  correlationId: args.correlationId,
@@ -821,7 +818,7 @@ var SIOPv2RP = class _SIOPv2RP {
821
818
  }
822
819
  async siopDeleteState(args, context) {
823
820
  return await this.getRPInstance({
824
- definitionId: args.definitionId
821
+ queryId: args.queryId
825
822
  }, context).then((rp) => rp.get(context).then((rp2) => rp2.sessionManager.deleteStateForCorrelationId(args.correlationId))).then(() => true);
826
823
  }
827
824
  async siopVerifyAuthResponse(args, context) {
@@ -830,25 +827,38 @@ var SIOPv2RP = class _SIOPv2RP {
830
827
  }
831
828
  const authResponse = typeof args.authorizationResponse === "string" ? decodeUriAsJson(args.authorizationResponse) : args.authorizationResponse;
832
829
  return await this.getRPInstance({
833
- definitionId: args.definitionId
830
+ queryId: args.queryId
834
831
  }, context).then((rp) => rp.get(context).then((rp2) => rp2.verifyAuthorizationResponse(authResponse, {
835
832
  correlationId: args.correlationId,
836
- ...args.dcqlQuery ? {
837
- dcqlQuery: args.dcqlQuery
833
+ ...args.dcqlQueryPayload ? {
834
+ dcqlQuery: args.dcqlQueryPayload.dcqlQuery
838
835
  } : {},
839
836
  audience: args.audience
840
837
  })));
841
838
  }
842
839
  async siopImportDefinitions(args, context) {
843
- const { definitions, tenantId, version, versionControlMode } = args;
844
- await Promise.all(definitions.map(async (definitionPair) => {
840
+ const { queries, tenantId, version, versionControlMode } = args;
841
+ await Promise.all(queries.map(async (definitionPair) => {
845
842
  const definitionPayload = definitionPair.definitionPayload;
846
- await context.agent.pexValidateDefinition({
847
- definition: definitionPayload
848
- });
849
- console.log(`persisting definition ${definitionPayload.id} / ${definitionPayload.name} with versionControlMode ${versionControlMode}`);
843
+ if (!definitionPayload && !definitionPair.dcqlPayload) {
844
+ return Promise.reject(Error("Either dcqlPayload or definitionPayload must be suppplied"));
845
+ }
846
+ let definitionId;
847
+ if (definitionPair.dcqlPayload) {
848
+ DcqlQuery.validate(definitionPair.dcqlPayload.dcqlQuery);
849
+ console.log(`persisting DCQL definition ${definitionPair.dcqlPayload.queryId} with versionControlMode ${versionControlMode}`);
850
+ definitionId = definitionPair.dcqlPayload.queryId;
851
+ }
852
+ if (definitionPayload) {
853
+ await context.agent.pexValidateDefinition({
854
+ definition: definitionPayload
855
+ });
856
+ console.log(`persisting PEX definition ${definitionPayload.id} / ${definitionPayload.name} with versionControlMode ${versionControlMode}`);
857
+ definitionId = definitionPayload.id;
858
+ }
850
859
  return context.agent.pdmPersistDefinition({
851
860
  definitionItem: {
861
+ definitionId,
852
862
  tenantId,
853
863
  version,
854
864
  definitionPayload,
@@ -861,7 +871,7 @@ var SIOPv2RP = class _SIOPv2RP {
861
871
  }));
862
872
  }
863
873
  async siopGetRedirectURI(args, context) {
864
- const instanceId = args.definitionId ?? _SIOPv2RP._DEFAULT_OPTS_KEY;
874
+ const instanceId = args.queryId ?? _SIOPv2RP._DEFAULT_OPTS_KEY;
865
875
  if (this.instances.has(instanceId)) {
866
876
  const rpInstance = this.instances.get(instanceId);
867
877
  if (rpInstance !== void 0) {
@@ -877,12 +887,12 @@ var SIOPv2RP = class _SIOPv2RP {
877
887
  }
878
888
  return void 0;
879
889
  }
880
- async getRPInstance({ definitionId, responseRedirectURI }, context) {
881
- const instanceId = definitionId ?? _SIOPv2RP._DEFAULT_OPTS_KEY;
890
+ async getRPInstance({ queryId, responseRedirectURI }, context) {
891
+ const instanceId = queryId ?? _SIOPv2RP._DEFAULT_OPTS_KEY;
882
892
  if (!this.instances.has(instanceId)) {
883
- const instanceOpts = this.getInstanceOpts(definitionId);
893
+ const instanceOpts = this.getInstanceOpts(queryId);
884
894
  const rpOpts = await this.getRPOptions(context, {
885
- definitionId,
895
+ queryId,
886
896
  responseRedirectURI
887
897
  });
888
898
  if (!rpOpts.identifierOpts.resolveOpts?.resolver || typeof rpOpts.identifierOpts.resolveOpts.resolver.resolve !== "function") {
@@ -894,7 +904,7 @@ var SIOPv2RP = class _SIOPv2RP {
894
904
  ...rpOpts.identifierOpts.resolveOpts
895
905
  };
896
906
  }
897
- console.log("Using agent DID resolver for RP instance with definition id " + definitionId);
907
+ console.log("Using agent DID resolver for RP instance with definition id " + queryId);
898
908
  rpOpts.identifierOpts.resolveOpts.resolver = getAgentResolver2(context, {
899
909
  uniresolverResolution: true,
900
910
  localResolution: true,
@@ -913,10 +923,10 @@ var SIOPv2RP = class _SIOPv2RP {
913
923
  return rpInstance;
914
924
  }
915
925
  async getRPOptions(context, opts) {
916
- const { definitionId, responseRedirectURI } = opts;
917
- const options = this.getInstanceOpts(definitionId)?.rpOpts ?? this.opts.defaultOpts;
926
+ const { queryId, responseRedirectURI } = opts;
927
+ const options = this.getInstanceOpts(queryId)?.rpOpts ?? this.opts.defaultOpts;
918
928
  if (!options) {
919
- throw Error(`Could not get specific nor default options for definition ${definitionId}`);
929
+ throw Error(`Could not get specific nor default options for definition ${queryId}`);
920
930
  }
921
931
  if (this.opts.defaultOpts) {
922
932
  if (!options.identifierOpts) {
@@ -950,18 +960,18 @@ var SIOPv2RP = class _SIOPv2RP {
950
960
  }
951
961
  getInstanceOpts(definitionId) {
952
962
  if (!this.opts.instanceOpts) return void 0;
953
- const instanceOpt = definitionId ? this.opts.instanceOpts.find((i) => i.definitionId === definitionId) : void 0;
963
+ const instanceOpt = definitionId ? this.opts.instanceOpts.find((i) => i.queryId === definitionId) : void 0;
954
964
  return instanceOpt ?? this.getDefaultOptions(definitionId);
955
965
  }
956
966
  getDefaultOptions(definitionId) {
957
967
  if (!this.opts.instanceOpts) return void 0;
958
- const defaultOptions = this.opts.instanceOpts.find((i) => i.definitionId === "default");
968
+ const defaultOptions = this.opts.instanceOpts.find((i) => i.queryId === "default");
959
969
  if (defaultOptions) {
960
970
  const clonedOptions = {
961
971
  ...defaultOptions
962
972
  };
963
973
  if (definitionId !== void 0) {
964
- clonedOptions.definitionId = definitionId;
974
+ clonedOptions.queryId = definitionId;
965
975
  }
966
976
  return clonedOptions;
967
977
  }
@@ -970,12 +980,12 @@ var SIOPv2RP = class _SIOPv2RP {
970
980
  };
971
981
 
972
982
  // src/types/ISIOPv2RP.ts
973
- var VerifiedDataMode = /* @__PURE__ */ function(VerifiedDataMode2) {
983
+ var VerifiedDataMode = /* @__PURE__ */ (function(VerifiedDataMode2) {
974
984
  VerifiedDataMode2["NONE"] = "none";
975
985
  VerifiedDataMode2["VERIFIED_PRESENTATION"] = "vp";
976
986
  VerifiedDataMode2["CREDENTIAL_SUBJECT_FLATTENED"] = "cs-flat";
977
987
  return VerifiedDataMode2;
978
- }({});
988
+ })({});
979
989
 
980
990
  // src/index.ts
981
991
  var schema = require_plugin_schema();