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

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,11 +336,12 @@ 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
 
342
343
  // src/functions.ts
343
- import { InMemoryRPSessionManager, PassBy, PropertyTarget, ResponseMode, ResponseType, RevocationVerification, RP, Scope, SubjectType, SupportedVersion } from "@sphereon/did-auth-siop";
344
+ import { ClientIdentifierPrefix, InMemoryRPSessionManager, PassBy, PropertyTarget, ResponseMode, ResponseType, RevocationVerification, RP, Scope, SubjectType, SupportedVersion } from "@sphereon/did-auth-siop";
344
345
  import { SigningAlgo } from "@sphereon/oid4vc-common";
345
346
  import { getAgentDIDMethods, getAgentResolver } from "@sphereon/ssi-sdk-ext.did-utils";
346
347
  import { isExternalIdentifierOIDFEntityIdOpts, isManagedIdentifierDidOpts, isManagedIdentifierDidResult, isManagedIdentifierX5cOpts } from "@sphereon/ssi-sdk-ext.identifier-resolution";
@@ -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) {
425
- dcqlQuery = presentationDefinitionItem.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,29 +489,27 @@ 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);
496
504
  } else {
497
505
  const resolution = await context.agent.identifierManagedGet(identifierOpts.idOpts);
498
- builder.withClientId(resolution.issuer ?? (isManagedIdentifierDidResult(resolution) ? resolution.did : resolution.jwkThumbprint), PropertyTarget.REQUEST_OBJECT);
506
+ const clientId = rpOpts.clientMetadataOpts?.client_id ?? resolution.issuer ?? (isManagedIdentifierDidResult(resolution) ? resolution.did : resolution.jwkThumbprint);
507
+ const clientIdPrefixed = prefixClientId(clientId);
508
+ builder.withClientId(clientIdPrefixed, PropertyTarget.REQUEST_OBJECT);
499
509
  }
500
510
  if (hasher) {
501
511
  builder.withHasher(hasher);
502
512
  }
503
- if (dcqlQuery) {
504
- builder.withDcqlQuery(dcqlQuery);
505
- }
506
513
  if (rpOpts.responseRedirectUri) {
507
514
  builder.withResponseRedirectUri(rpOpts.responseRedirectUri);
508
515
  }
@@ -559,6 +566,13 @@ function getSigningAlgo(type) {
559
566
  }
560
567
  }
561
568
  __name(getSigningAlgo, "getSigningAlgo");
569
+ function prefixClientId(clientId) {
570
+ if (clientId.startsWith("did:")) {
571
+ return `${ClientIdentifierPrefix.DECENTRALIZED_IDENTIFIER}:${clientId}`;
572
+ }
573
+ return clientId;
574
+ }
575
+ __name(prefixClientId, "prefixClientId");
562
576
 
563
577
  // src/RPInstance.ts
564
578
  import { v4 as uuidv4 } from "uuid";
@@ -568,17 +582,16 @@ var RPInstance = class {
568
582
  __name(this, "RPInstance");
569
583
  }
570
584
  _rp;
571
- _pexOptions;
585
+ _presentationOptions;
572
586
  _rpOptions;
573
587
  constructor({ rpOpts, pexOpts }) {
574
588
  this._rpOptions = rpOpts;
575
- this._pexOptions = pexOpts;
589
+ this._presentationOptions = pexOpts;
576
590
  }
577
591
  async get(context) {
578
592
  if (!this._rp) {
579
593
  const builder = await createRPBuilder({
580
594
  rpOpts: this._rpOptions,
581
- pexOpts: this._pexOptions,
582
595
  context
583
596
  });
584
597
  this._rp = builder.build();
@@ -588,20 +601,8 @@ var RPInstance = class {
588
601
  get rpOptions() {
589
602
  return this._rpOptions;
590
603
  }
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;
604
+ get presentationOptions() {
605
+ return this._presentationOptions;
605
606
  }
606
607
  async createAuthorizationRequestURI(createArgs, context) {
607
608
  const { correlationId, queryId, claims, requestByReferenceURI, responseURI, responseURIType, callback } = createArgs;
@@ -718,6 +719,7 @@ var SIOPv2RP = class _SIOPv2RP {
718
719
  }
719
720
  async createAuthorizationRequestURI(createArgs, context) {
720
721
  return await this.getRPInstance({
722
+ createWhenNotPresent: true,
721
723
  responseRedirectURI: createArgs.responseRedirectURI,
722
724
  ...createArgs.useQueryIdInstance === true && {
723
725
  queryId: createArgs.queryId
@@ -726,6 +728,7 @@ var SIOPv2RP = class _SIOPv2RP {
726
728
  }
727
729
  async createAuthorizationRequestPayloads(createArgs, context) {
728
730
  return await this.getRPInstance({
731
+ createWhenNotPresent: true,
729
732
  queryId: createArgs.queryId
730
733
  }, context).then((rp) => rp.createAuthorizationRequest(createArgs, context)).then(async (request) => {
731
734
  const authRequest = {
@@ -738,11 +741,13 @@ var SIOPv2RP = class _SIOPv2RP {
738
741
  }
739
742
  async siopGetRequestState(args, context) {
740
743
  return await this.getRPInstance({
744
+ createWhenNotPresent: false,
741
745
  queryId: args.queryId
742
746
  }, context).then((rp) => rp.get(context).then((rp2) => rp2.sessionManager.getRequestStateByCorrelationId(args.correlationId, args.errorOnNotFound)));
743
747
  }
744
748
  async siopGetResponseState(args, context) {
745
749
  const rpInstance = await this.getRPInstance({
750
+ createWhenNotPresent: false,
746
751
  queryId: args.queryId
747
752
  }, context);
748
753
  const authorizationResponseState = await rpInstance.get(context).then((rp) => rp.sessionManager.getResponseStateByCorrelationId(args.correlationId, args.errorOnNotFound));
@@ -800,6 +805,7 @@ var SIOPv2RP = class _SIOPv2RP {
800
805
  throw Error(`Only 'authorization_request_created' status is supported for this method at this point`);
801
806
  }
802
807
  return await this.getRPInstance({
808
+ createWhenNotPresent: false,
803
809
  queryId: args.queryId
804
810
  }, context).then((rp) => rp.get(context).then(async (rp2) => {
805
811
  await rp2.signalAuthRequestRetrieved({
@@ -811,6 +817,7 @@ var SIOPv2RP = class _SIOPv2RP {
811
817
  }
812
818
  async siopDeleteState(args, context) {
813
819
  return await this.getRPInstance({
820
+ createWhenNotPresent: false,
814
821
  queryId: args.queryId
815
822
  }, context).then((rp) => rp.get(context).then((rp2) => rp2.sessionManager.deleteStateForCorrelationId(args.correlationId))).then(() => true);
816
823
  }
@@ -820,6 +827,7 @@ var SIOPv2RP = class _SIOPv2RP {
820
827
  }
821
828
  const authResponse = typeof args.authorizationResponse === "string" ? decodeUriAsJson(args.authorizationResponse) : args.authorizationResponse;
822
829
  return await this.getRPInstance({
830
+ createWhenNotPresent: false,
823
831
  queryId: args.queryId
824
832
  }, context).then((rp) => rp.get(context).then((rp2) => rp2.verifyAuthorizationResponse(authResponse, {
825
833
  correlationId: args.correlationId,
@@ -832,14 +840,14 @@ var SIOPv2RP = class _SIOPv2RP {
832
840
  async siopImportDefinitions(args, context) {
833
841
  const { importItems, tenantId, version, versionControlMode } = args;
834
842
  await Promise.all(importItems.map(async (importItem) => {
835
- DcqlQuery.validate(importItem.dcqlQuery);
843
+ DcqlQuery.validate(importItem.query);
836
844
  console.log(`persisting DCQL definition ${importItem.queryId} with versionControlMode ${versionControlMode}`);
837
845
  return context.agent.pdmPersistDefinition({
838
846
  definitionItem: {
839
847
  queryId: importItem.queryId,
840
848
  tenantId,
841
849
  version,
842
- dcqlQuery: importItem.dcqlQuery
850
+ query: importItem.query
843
851
  },
844
852
  opts: {
845
853
  versionControlMode
@@ -864,9 +872,37 @@ var SIOPv2RP = class _SIOPv2RP {
864
872
  }
865
873
  return void 0;
866
874
  }
867
- async getRPInstance({ queryId, responseRedirectURI }, context) {
868
- const instanceId = queryId ?? _SIOPv2RP._DEFAULT_OPTS_KEY;
869
- 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
+ }
870
906
  const instanceOpts = this.getInstanceOpts(queryId);
871
907
  const rpOpts = await this.getRPOptions(context, {
872
908
  queryId,
@@ -888,12 +924,12 @@ var SIOPv2RP = class _SIOPv2RP {
888
924
  resolverResolution: true
889
925
  });
890
926
  }
891
- this.instances.set(instanceId, new RPInstance({
927
+ rpInstance = new RPInstance({
892
928
  rpOpts,
893
929
  pexOpts: instanceOpts
894
- }));
930
+ });
931
+ this.instances.set(rpInstanceId, rpInstance);
895
932
  }
896
- const rpInstance = this.instances.get(instanceId);
897
933
  if (responseRedirectURI) {
898
934
  rpInstance.rpOptions.responseRedirectUri = responseRedirectURI;
899
935
  }