@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth 0.34.1-feature.SSISDK.57.uni.client.169 → 0.34.1-feature.SSISDK.57.uni.client.173

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
@@ -336,6 +336,7 @@ var plugin_schema_default = {
336
336
  import { AuthorizationResponseStateStatus, decodeUriAsJson } from "@sphereon/did-auth-siop";
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
+ import { validate as isValidUUID } from "uuid";
339
340
  import { CredentialMapper as CredentialMapper2 } from "@sphereon/ssi-types";
340
341
  import { DcqlQuery } from "dcql";
341
342
 
@@ -366,6 +367,29 @@ function getWellKnownDIDVerifyCallback(siopIdentifierOpts, context) {
366
367
  };
367
368
  }
368
369
  __name(getWellKnownDIDVerifyCallback, "getWellKnownDIDVerifyCallback");
370
+ function getDcqlQueryLookupCallback(context) {
371
+ async function dcqlQueryLookup(queryId, version, tenantId) {
372
+ const result = await context.agent.pdmGetDefinitions({
373
+ filter: [
374
+ {
375
+ queryId,
376
+ version,
377
+ tenantId
378
+ },
379
+ {
380
+ id: queryId
381
+ }
382
+ ]
383
+ });
384
+ if (result && result.length > 0) {
385
+ return result[0].dcqlQuery;
386
+ }
387
+ return Promise.reject(Error(`No dcql query found for queryId ${queryId}`));
388
+ }
389
+ __name(dcqlQueryLookup, "dcqlQueryLookup");
390
+ return dcqlQueryLookup;
391
+ }
392
+ __name(getDcqlQueryLookupCallback, "getDcqlQueryLookupCallback");
369
393
  function getPresentationVerificationCallback(idOpts, context) {
370
394
  async function presentationVerificationCallback(args, presentationSubmission) {
371
395
  if (CredentialMapper.isSdJwtEncoded(args)) {
@@ -405,27 +429,8 @@ function getPresentationVerificationCallback(idOpts, context) {
405
429
  }
406
430
  __name(getPresentationVerificationCallback, "getPresentationVerificationCallback");
407
431
  async function createRPBuilder(args) {
408
- const { rpOpts, pexOpts, context } = args;
432
+ const { rpOpts, context } = args;
409
433
  const { identifierOpts } = rpOpts;
410
- let definition = args.definition;
411
- let dcqlQuery = args.dcql;
412
- if (!definition && pexOpts && pexOpts.queryId) {
413
- const presentationDefinitionItems = await context.agent.pdmGetDefinitions({
414
- filter: [
415
- {
416
- queryId: pexOpts.queryId,
417
- version: pexOpts.version,
418
- tenantId: pexOpts.tenantId
419
- }
420
- ]
421
- });
422
- if (presentationDefinitionItems.length > 0) {
423
- const presentationDefinitionItem = presentationDefinitionItems[0];
424
- if (!dcqlQuery) {
425
- dcqlQuery = presentationDefinitionItem.dcqlQuery;
426
- }
427
- }
428
- }
429
434
  const didMethods = identifierOpts.supportedDIDMethods ?? await getAgentDIDMethods(context);
430
435
  const eventEmitter = rpOpts.eventEmitter ?? new EventEmitter();
431
436
  const defaultClientMetadata = {
@@ -489,7 +494,7 @@ async function createRPBuilder(args) {
489
494
  wellknownDIDVerifyCallback: getWellKnownDIDVerifyCallback(rpOpts.identifierOpts, context),
490
495
  checkLinkedDomain: "if_present"
491
496
  }
492
- }, context)).withRevocationVerification(RevocationVerification.NEVER).withPresentationVerification(getPresentationVerificationCallback(identifierOpts.idOpts, context));
497
+ }, context)).withDcqlQueryLookup(getDcqlQueryLookupCallback(context)).withRevocationVerification(RevocationVerification.NEVER).withPresentationVerification(getPresentationVerificationCallback(identifierOpts.idOpts, context));
493
498
  const oidfOpts = identifierOpts.oidfOpts;
494
499
  if (oidfOpts && isExternalIdentifierOIDFEntityIdOpts(oidfOpts)) {
495
500
  builder.withEntityId(oidfOpts.identifier, PropertyTarget.REQUEST_OBJECT);
@@ -500,9 +505,6 @@ async function createRPBuilder(args) {
500
505
  if (hasher) {
501
506
  builder.withHasher(hasher);
502
507
  }
503
- if (dcqlQuery) {
504
- builder.withDcqlQuery(dcqlQuery);
505
- }
506
508
  if (rpOpts.responseRedirectUri) {
507
509
  builder.withResponseRedirectUri(rpOpts.responseRedirectUri);
508
510
  }
@@ -568,17 +570,16 @@ var RPInstance = class {
568
570
  __name(this, "RPInstance");
569
571
  }
570
572
  _rp;
571
- _pexOptions;
573
+ _presentationOptions;
572
574
  _rpOptions;
573
575
  constructor({ rpOpts, pexOpts }) {
574
576
  this._rpOptions = rpOpts;
575
- this._pexOptions = pexOpts;
577
+ this._presentationOptions = pexOpts;
576
578
  }
577
579
  async get(context) {
578
580
  if (!this._rp) {
579
581
  const builder = await createRPBuilder({
580
582
  rpOpts: this._rpOptions,
581
- pexOpts: this._pexOptions,
582
583
  context
583
584
  });
584
585
  this._rp = builder.build();
@@ -588,20 +589,8 @@ var RPInstance = class {
588
589
  get rpOptions() {
589
590
  return this._rpOptions;
590
591
  }
591
- get pexOptions() {
592
- return this._pexOptions;
593
- }
594
- hasDefinition() {
595
- return this.definitionId !== void 0;
596
- }
597
- get definitionId() {
598
- return this.pexOptions?.queryId;
599
- }
600
- async getPresentationDefinition(context) {
601
- return this.definitionId ? await context.agent.pexStoreGetDefinition({
602
- definitionId: this.definitionId,
603
- tenantId: this.pexOptions?.tenantId
604
- }) : void 0;
592
+ get presentationOptions() {
593
+ return this._presentationOptions;
605
594
  }
606
595
  async createAuthorizationRequestURI(createArgs, context) {
607
596
  const { correlationId, queryId, claims, requestByReferenceURI, responseURI, responseURIType, callback } = createArgs;
@@ -718,6 +707,7 @@ var SIOPv2RP = class _SIOPv2RP {
718
707
  }
719
708
  async createAuthorizationRequestURI(createArgs, context) {
720
709
  return await this.getRPInstance({
710
+ createWhenNotPresent: true,
721
711
  responseRedirectURI: createArgs.responseRedirectURI,
722
712
  ...createArgs.useQueryIdInstance === true && {
723
713
  queryId: createArgs.queryId
@@ -726,6 +716,7 @@ var SIOPv2RP = class _SIOPv2RP {
726
716
  }
727
717
  async createAuthorizationRequestPayloads(createArgs, context) {
728
718
  return await this.getRPInstance({
719
+ createWhenNotPresent: true,
729
720
  queryId: createArgs.queryId
730
721
  }, context).then((rp) => rp.createAuthorizationRequest(createArgs, context)).then(async (request) => {
731
722
  const authRequest = {
@@ -738,11 +729,13 @@ var SIOPv2RP = class _SIOPv2RP {
738
729
  }
739
730
  async siopGetRequestState(args, context) {
740
731
  return await this.getRPInstance({
732
+ createWhenNotPresent: false,
741
733
  queryId: args.queryId
742
734
  }, context).then((rp) => rp.get(context).then((rp2) => rp2.sessionManager.getRequestStateByCorrelationId(args.correlationId, args.errorOnNotFound)));
743
735
  }
744
736
  async siopGetResponseState(args, context) {
745
737
  const rpInstance = await this.getRPInstance({
738
+ createWhenNotPresent: false,
746
739
  queryId: args.queryId
747
740
  }, context);
748
741
  const authorizationResponseState = await rpInstance.get(context).then((rp) => rp.sessionManager.getResponseStateByCorrelationId(args.correlationId, args.errorOnNotFound));
@@ -800,6 +793,7 @@ var SIOPv2RP = class _SIOPv2RP {
800
793
  throw Error(`Only 'authorization_request_created' status is supported for this method at this point`);
801
794
  }
802
795
  return await this.getRPInstance({
796
+ createWhenNotPresent: false,
803
797
  queryId: args.queryId
804
798
  }, context).then((rp) => rp.get(context).then(async (rp2) => {
805
799
  await rp2.signalAuthRequestRetrieved({
@@ -811,6 +805,7 @@ var SIOPv2RP = class _SIOPv2RP {
811
805
  }
812
806
  async siopDeleteState(args, context) {
813
807
  return await this.getRPInstance({
808
+ createWhenNotPresent: false,
814
809
  queryId: args.queryId
815
810
  }, context).then((rp) => rp.get(context).then((rp2) => rp2.sessionManager.deleteStateForCorrelationId(args.correlationId))).then(() => true);
816
811
  }
@@ -820,6 +815,7 @@ var SIOPv2RP = class _SIOPv2RP {
820
815
  }
821
816
  const authResponse = typeof args.authorizationResponse === "string" ? decodeUriAsJson(args.authorizationResponse) : args.authorizationResponse;
822
817
  return await this.getRPInstance({
818
+ createWhenNotPresent: false,
823
819
  queryId: args.queryId
824
820
  }, context).then((rp) => rp.get(context).then((rp2) => rp2.verifyAuthorizationResponse(authResponse, {
825
821
  correlationId: args.correlationId,
@@ -864,9 +860,37 @@ var SIOPv2RP = class _SIOPv2RP {
864
860
  }
865
861
  return void 0;
866
862
  }
867
- async getRPInstance({ queryId, responseRedirectURI }, context) {
868
- const instanceId = queryId ?? _SIOPv2RP._DEFAULT_OPTS_KEY;
869
- if (!this.instances.has(instanceId)) {
863
+ async getRPInstance({ createWhenNotPresent, queryId, responseRedirectURI }, context) {
864
+ let rpInstanceId = _SIOPv2RP._DEFAULT_OPTS_KEY;
865
+ let rpInstance;
866
+ if (queryId) {
867
+ if (this.instances.has(queryId)) {
868
+ rpInstanceId = queryId;
869
+ rpInstance = this.instances.get(rpInstanceId);
870
+ } else if (isValidUUID(queryId)) {
871
+ try {
872
+ const pd = await context.agent.pdmGetDefinition({
873
+ itemId: queryId
874
+ });
875
+ if (this.instances.has(pd.queryId)) {
876
+ rpInstanceId = pd.queryId;
877
+ rpInstance = this.instances.get(rpInstanceId);
878
+ }
879
+ } catch (ignore) {
880
+ }
881
+ }
882
+ if (createWhenNotPresent) {
883
+ rpInstanceId = queryId;
884
+ } else {
885
+ rpInstance = this.instances.get(rpInstanceId);
886
+ }
887
+ } else {
888
+ rpInstance = this.instances.get(rpInstanceId);
889
+ }
890
+ if (!rpInstance) {
891
+ if (!createWhenNotPresent) {
892
+ return Promise.reject(`No RP instance found for key ${rpInstanceId}`);
893
+ }
870
894
  const instanceOpts = this.getInstanceOpts(queryId);
871
895
  const rpOpts = await this.getRPOptions(context, {
872
896
  queryId,
@@ -888,12 +912,12 @@ var SIOPv2RP = class _SIOPv2RP {
888
912
  resolverResolution: true
889
913
  });
890
914
  }
891
- this.instances.set(instanceId, new RPInstance({
915
+ rpInstance = new RPInstance({
892
916
  rpOpts,
893
917
  pexOpts: instanceOpts
894
- }));
918
+ });
919
+ this.instances.set(rpInstanceId, rpInstance);
895
920
  }
896
- const rpInstance = this.instances.get(instanceId);
897
921
  if (responseRedirectURI) {
898
922
  rpInstance.rpOptions.responseRedirectUri = responseRedirectURI;
899
923
  }