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

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
 
@@ -351,7 +352,7 @@ function getRequestVersion(rpOptions) {
351
352
  if (Array.isArray(rpOptions.supportedVersions) && rpOptions.supportedVersions.length > 0) {
352
353
  return rpOptions.supportedVersions[0];
353
354
  }
354
- return SupportedVersion.JWT_VC_PRESENTATION_PROFILE_v1;
355
+ return SupportedVersion.OID4VP_v1;
355
356
  }
356
357
  __name(getRequestVersion, "getRequestVersion");
357
358
  function getWellKnownDIDVerifyCallback(siopIdentifierOpts, context) {
@@ -366,6 +367,33 @@ 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
+ ...tenantId && {
377
+ tenantId
378
+ },
379
+ ...version && {
380
+ version
381
+ }
382
+ },
383
+ {
384
+ id: queryId
385
+ }
386
+ ]
387
+ });
388
+ if (result && result.length > 0) {
389
+ return result[0].query;
390
+ }
391
+ return Promise.reject(Error(`No dcql query found for queryId ${queryId}`));
392
+ }
393
+ __name(dcqlQueryLookup, "dcqlQueryLookup");
394
+ return dcqlQueryLookup;
395
+ }
396
+ __name(getDcqlQueryLookupCallback, "getDcqlQueryLookupCallback");
369
397
  function getPresentationVerificationCallback(idOpts, context) {
370
398
  async function presentationVerificationCallback(args, presentationSubmission) {
371
399
  if (CredentialMapper.isSdJwtEncoded(args)) {
@@ -405,27 +433,8 @@ function getPresentationVerificationCallback(idOpts, context) {
405
433
  }
406
434
  __name(getPresentationVerificationCallback, "getPresentationVerificationCallback");
407
435
  async function createRPBuilder(args) {
408
- const { rpOpts, pexOpts, context } = args;
436
+ const { rpOpts, context } = args;
409
437
  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 && presentationDefinitionItem.dcqlPayload) {
425
- dcqlQuery = presentationDefinitionItem.dcqlPayload.dcqlQuery;
426
- }
427
- }
428
- }
429
438
  const didMethods = identifierOpts.supportedDIDMethods ?? await getAgentDIDMethods(context);
430
439
  const eventEmitter = rpOpts.eventEmitter ?? new EventEmitter();
431
440
  const defaultClientMetadata = {
@@ -480,16 +489,15 @@ async function createRPBuilder(args) {
480
489
  const builder = RP.builder({
481
490
  requestVersion: getRequestVersion(rpOpts)
482
491
  }).withScope("openid", PropertyTarget.REQUEST_OBJECT).withResponseMode(rpOpts.responseMode ?? ResponseMode.POST).withResponseType(ResponseType.VP_TOKEN, PropertyTarget.REQUEST_OBJECT).withSupportedVersions(rpOpts.supportedVersions ?? [
483
- SupportedVersion.JWT_VC_PRESENTATION_PROFILE_v1,
484
- SupportedVersion.SIOPv2_ID1,
485
- SupportedVersion.SIOPv2_D11
492
+ SupportedVersion.OID4VP_v1,
493
+ SupportedVersion.SIOPv2_OID4VP_D28
486
494
  ]).withEventEmitter(eventEmitter).withSessionManager(rpOpts.sessionManager ?? new InMemoryRPSessionManager(eventEmitter)).withClientMetadata(rpOpts.clientMetadataOpts ?? defaultClientMetadata, PropertyTarget.REQUEST_OBJECT).withVerifyJwtCallback(rpOpts.verifyJwtCallback ? rpOpts.verifyJwtCallback : getVerifyJwtCallback({
487
495
  resolver,
488
496
  verifyOpts: {
489
497
  wellknownDIDVerifyCallback: getWellKnownDIDVerifyCallback(rpOpts.identifierOpts, context),
490
498
  checkLinkedDomain: "if_present"
491
499
  }
492
- }, context)).withRevocationVerification(RevocationVerification.NEVER).withPresentationVerification(getPresentationVerificationCallback(identifierOpts.idOpts, context));
500
+ }, context)).withDcqlQueryLookup(getDcqlQueryLookupCallback(context)).withRevocationVerification(RevocationVerification.NEVER).withPresentationVerification(getPresentationVerificationCallback(identifierOpts.idOpts, context));
493
501
  const oidfOpts = identifierOpts.oidfOpts;
494
502
  if (oidfOpts && isExternalIdentifierOIDFEntityIdOpts(oidfOpts)) {
495
503
  builder.withEntityId(oidfOpts.identifier, PropertyTarget.REQUEST_OBJECT);
@@ -502,9 +510,6 @@ async function createRPBuilder(args) {
502
510
  if (hasher) {
503
511
  builder.withHasher(hasher);
504
512
  }
505
- if (dcqlQuery) {
506
- builder.withDcqlQuery(dcqlQuery);
507
- }
508
513
  if (rpOpts.responseRedirectUri) {
509
514
  builder.withResponseRedirectUri(rpOpts.responseRedirectUri);
510
515
  }
@@ -577,17 +582,16 @@ var RPInstance = class {
577
582
  __name(this, "RPInstance");
578
583
  }
579
584
  _rp;
580
- _pexOptions;
585
+ _presentationOptions;
581
586
  _rpOptions;
582
587
  constructor({ rpOpts, pexOpts }) {
583
588
  this._rpOptions = rpOpts;
584
- this._pexOptions = pexOpts;
589
+ this._presentationOptions = pexOpts;
585
590
  }
586
591
  async get(context) {
587
592
  if (!this._rp) {
588
593
  const builder = await createRPBuilder({
589
594
  rpOpts: this._rpOptions,
590
- pexOpts: this._pexOptions,
591
595
  context
592
596
  });
593
597
  this._rp = builder.build();
@@ -597,20 +601,8 @@ var RPInstance = class {
597
601
  get rpOptions() {
598
602
  return this._rpOptions;
599
603
  }
600
- get pexOptions() {
601
- return this._pexOptions;
602
- }
603
- hasDefinition() {
604
- return this.definitionId !== void 0;
605
- }
606
- get definitionId() {
607
- return this.pexOptions?.queryId;
608
- }
609
- async getPresentationDefinition(context) {
610
- return this.definitionId ? await context.agent.pexStoreGetDefinition({
611
- definitionId: this.definitionId,
612
- tenantId: this.pexOptions?.tenantId
613
- }) : void 0;
604
+ get presentationOptions() {
605
+ return this._presentationOptions;
614
606
  }
615
607
  async createAuthorizationRequestURI(createArgs, context) {
616
608
  const { correlationId, queryId, claims, requestByReferenceURI, responseURI, responseURIType, callback } = createArgs;
@@ -727,6 +719,7 @@ var SIOPv2RP = class _SIOPv2RP {
727
719
  }
728
720
  async createAuthorizationRequestURI(createArgs, context) {
729
721
  return await this.getRPInstance({
722
+ createWhenNotPresent: true,
730
723
  responseRedirectURI: createArgs.responseRedirectURI,
731
724
  ...createArgs.useQueryIdInstance === true && {
732
725
  queryId: createArgs.queryId
@@ -735,6 +728,7 @@ var SIOPv2RP = class _SIOPv2RP {
735
728
  }
736
729
  async createAuthorizationRequestPayloads(createArgs, context) {
737
730
  return await this.getRPInstance({
731
+ createWhenNotPresent: true,
738
732
  queryId: createArgs.queryId
739
733
  }, context).then((rp) => rp.createAuthorizationRequest(createArgs, context)).then(async (request) => {
740
734
  const authRequest = {
@@ -747,11 +741,13 @@ var SIOPv2RP = class _SIOPv2RP {
747
741
  }
748
742
  async siopGetRequestState(args, context) {
749
743
  return await this.getRPInstance({
744
+ createWhenNotPresent: false,
750
745
  queryId: args.queryId
751
746
  }, context).then((rp) => rp.get(context).then((rp2) => rp2.sessionManager.getRequestStateByCorrelationId(args.correlationId, args.errorOnNotFound)));
752
747
  }
753
748
  async siopGetResponseState(args, context) {
754
749
  const rpInstance = await this.getRPInstance({
750
+ createWhenNotPresent: false,
755
751
  queryId: args.queryId
756
752
  }, context);
757
753
  const authorizationResponseState = await rpInstance.get(context).then((rp) => rp.sessionManager.getResponseStateByCorrelationId(args.correlationId, args.errorOnNotFound));
@@ -809,6 +805,7 @@ var SIOPv2RP = class _SIOPv2RP {
809
805
  throw Error(`Only 'authorization_request_created' status is supported for this method at this point`);
810
806
  }
811
807
  return await this.getRPInstance({
808
+ createWhenNotPresent: false,
812
809
  queryId: args.queryId
813
810
  }, context).then((rp) => rp.get(context).then(async (rp2) => {
814
811
  await rp2.signalAuthRequestRetrieved({
@@ -820,6 +817,7 @@ var SIOPv2RP = class _SIOPv2RP {
820
817
  }
821
818
  async siopDeleteState(args, context) {
822
819
  return await this.getRPInstance({
820
+ createWhenNotPresent: false,
823
821
  queryId: args.queryId
824
822
  }, context).then((rp) => rp.get(context).then((rp2) => rp2.sessionManager.deleteStateForCorrelationId(args.correlationId))).then(() => true);
825
823
  }
@@ -829,6 +827,7 @@ var SIOPv2RP = class _SIOPv2RP {
829
827
  }
830
828
  const authResponse = typeof args.authorizationResponse === "string" ? decodeUriAsJson(args.authorizationResponse) : args.authorizationResponse;
831
829
  return await this.getRPInstance({
830
+ createWhenNotPresent: false,
832
831
  queryId: args.queryId
833
832
  }, context).then((rp) => rp.get(context).then((rp2) => rp2.verifyAuthorizationResponse(authResponse, {
834
833
  correlationId: args.correlationId,
@@ -873,9 +872,37 @@ var SIOPv2RP = class _SIOPv2RP {
873
872
  }
874
873
  return void 0;
875
874
  }
876
- async getRPInstance({ queryId, responseRedirectURI }, context) {
877
- const instanceId = queryId ?? _SIOPv2RP._DEFAULT_OPTS_KEY;
878
- if (!this.instances.has(instanceId)) {
875
+ async getRPInstance({ createWhenNotPresent, queryId, responseRedirectURI }, context) {
876
+ let rpInstanceId = _SIOPv2RP._DEFAULT_OPTS_KEY;
877
+ let rpInstance;
878
+ if (queryId) {
879
+ if (this.instances.has(queryId)) {
880
+ rpInstanceId = queryId;
881
+ rpInstance = this.instances.get(rpInstanceId);
882
+ } else if (isValidUUID(queryId)) {
883
+ try {
884
+ const pd = await context.agent.pdmGetDefinition({
885
+ itemId: queryId
886
+ });
887
+ if (this.instances.has(pd.queryId)) {
888
+ rpInstanceId = pd.queryId;
889
+ rpInstance = this.instances.get(rpInstanceId);
890
+ }
891
+ } catch (ignore) {
892
+ }
893
+ }
894
+ if (createWhenNotPresent) {
895
+ rpInstanceId = queryId;
896
+ } else {
897
+ rpInstance = this.instances.get(rpInstanceId);
898
+ }
899
+ } else {
900
+ rpInstance = this.instances.get(rpInstanceId);
901
+ }
902
+ if (!rpInstance) {
903
+ if (!createWhenNotPresent) {
904
+ return Promise.reject(`No RP instance found for key ${rpInstanceId}`);
905
+ }
879
906
  const instanceOpts = this.getInstanceOpts(queryId);
880
907
  const rpOpts = await this.getRPOptions(context, {
881
908
  queryId,
@@ -897,12 +924,12 @@ var SIOPv2RP = class _SIOPv2RP {
897
924
  resolverResolution: true
898
925
  });
899
926
  }
900
- this.instances.set(instanceId, new RPInstance({
927
+ rpInstance = new RPInstance({
901
928
  rpOpts,
902
929
  pexOpts: instanceOpts
903
- }));
930
+ });
931
+ this.instances.set(rpInstanceId, rpInstance);
904
932
  }
905
- const rpInstance = this.instances.get(instanceId);
906
933
  if (responseRedirectURI) {
907
934
  rpInstance.rpOptions.responseRedirectUri = responseRedirectURI;
908
935
  }
@@ -944,20 +971,20 @@ var SIOPv2RP = class _SIOPv2RP {
944
971
  }
945
972
  return options;
946
973
  }
947
- getInstanceOpts(definitionId) {
974
+ getInstanceOpts(queryId) {
948
975
  if (!this.opts.instanceOpts) return void 0;
949
- const instanceOpt = definitionId ? this.opts.instanceOpts.find((i) => i.queryId === definitionId) : void 0;
950
- return instanceOpt ?? this.getDefaultOptions(definitionId);
976
+ const instanceOpt = queryId ? this.opts.instanceOpts.find((i) => i.queryId === queryId) : void 0;
977
+ return instanceOpt ?? this.getDefaultOptions(queryId);
951
978
  }
952
- getDefaultOptions(definitionId) {
979
+ getDefaultOptions(queryId) {
953
980
  if (!this.opts.instanceOpts) return void 0;
954
981
  const defaultOptions = this.opts.instanceOpts.find((i) => i.queryId === "default");
955
982
  if (defaultOptions) {
956
983
  const clonedOptions = {
957
984
  ...defaultOptions
958
985
  };
959
- if (definitionId !== void 0) {
960
- clonedOptions.queryId = definitionId;
986
+ if (queryId !== void 0) {
987
+ clonedOptions.queryId = queryId;
961
988
  }
962
989
  return clonedOptions;
963
990
  }