@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth 0.34.1-feature.SSISDK.57.uni.client.206 → 0.34.1-feature.SSISDK.58.host.nonce.endpoint.194
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.cjs +57 -84
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +14 -10
- package/dist/index.d.ts +14 -10
- package/dist/index.js +57 -84
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
- package/src/RPInstance.ts +26 -7
- package/src/agent/SIOPv2RP.ts +24 -55
- package/src/functions.ts +41 -40
- package/src/types/ISIOPv2RP.ts +6 -5
package/dist/index.js
CHANGED
|
@@ -336,7 +336,6 @@ 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";
|
|
340
339
|
import { CredentialMapper as CredentialMapper2 } from "@sphereon/ssi-types";
|
|
341
340
|
import { DcqlQuery } from "dcql";
|
|
342
341
|
|
|
@@ -352,7 +351,7 @@ function getRequestVersion(rpOptions) {
|
|
|
352
351
|
if (Array.isArray(rpOptions.supportedVersions) && rpOptions.supportedVersions.length > 0) {
|
|
353
352
|
return rpOptions.supportedVersions[0];
|
|
354
353
|
}
|
|
355
|
-
return SupportedVersion.
|
|
354
|
+
return SupportedVersion.JWT_VC_PRESENTATION_PROFILE_v1;
|
|
356
355
|
}
|
|
357
356
|
__name(getRequestVersion, "getRequestVersion");
|
|
358
357
|
function getWellKnownDIDVerifyCallback(siopIdentifierOpts, context) {
|
|
@@ -367,33 +366,6 @@ function getWellKnownDIDVerifyCallback(siopIdentifierOpts, context) {
|
|
|
367
366
|
};
|
|
368
367
|
}
|
|
369
368
|
__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");
|
|
397
369
|
function getPresentationVerificationCallback(idOpts, context) {
|
|
398
370
|
async function presentationVerificationCallback(args, presentationSubmission) {
|
|
399
371
|
if (CredentialMapper.isSdJwtEncoded(args)) {
|
|
@@ -433,8 +405,27 @@ function getPresentationVerificationCallback(idOpts, context) {
|
|
|
433
405
|
}
|
|
434
406
|
__name(getPresentationVerificationCallback, "getPresentationVerificationCallback");
|
|
435
407
|
async function createRPBuilder(args) {
|
|
436
|
-
const { rpOpts, context } = args;
|
|
408
|
+
const { rpOpts, pexOpts, context } = args;
|
|
437
409
|
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
|
+
}
|
|
438
429
|
const didMethods = identifierOpts.supportedDIDMethods ?? await getAgentDIDMethods(context);
|
|
439
430
|
const eventEmitter = rpOpts.eventEmitter ?? new EventEmitter();
|
|
440
431
|
const defaultClientMetadata = {
|
|
@@ -489,15 +480,16 @@ async function createRPBuilder(args) {
|
|
|
489
480
|
const builder = RP.builder({
|
|
490
481
|
requestVersion: getRequestVersion(rpOpts)
|
|
491
482
|
}).withScope("openid", PropertyTarget.REQUEST_OBJECT).withResponseMode(rpOpts.responseMode ?? ResponseMode.POST).withResponseType(ResponseType.VP_TOKEN, PropertyTarget.REQUEST_OBJECT).withSupportedVersions(rpOpts.supportedVersions ?? [
|
|
492
|
-
SupportedVersion.
|
|
493
|
-
SupportedVersion.
|
|
483
|
+
SupportedVersion.JWT_VC_PRESENTATION_PROFILE_v1,
|
|
484
|
+
SupportedVersion.SIOPv2_ID1,
|
|
485
|
+
SupportedVersion.SIOPv2_D11
|
|
494
486
|
]).withEventEmitter(eventEmitter).withSessionManager(rpOpts.sessionManager ?? new InMemoryRPSessionManager(eventEmitter)).withClientMetadata(rpOpts.clientMetadataOpts ?? defaultClientMetadata, PropertyTarget.REQUEST_OBJECT).withVerifyJwtCallback(rpOpts.verifyJwtCallback ? rpOpts.verifyJwtCallback : getVerifyJwtCallback({
|
|
495
487
|
resolver,
|
|
496
488
|
verifyOpts: {
|
|
497
489
|
wellknownDIDVerifyCallback: getWellKnownDIDVerifyCallback(rpOpts.identifierOpts, context),
|
|
498
490
|
checkLinkedDomain: "if_present"
|
|
499
491
|
}
|
|
500
|
-
}, context)).
|
|
492
|
+
}, context)).withRevocationVerification(RevocationVerification.NEVER).withPresentationVerification(getPresentationVerificationCallback(identifierOpts.idOpts, context));
|
|
501
493
|
const oidfOpts = identifierOpts.oidfOpts;
|
|
502
494
|
if (oidfOpts && isExternalIdentifierOIDFEntityIdOpts(oidfOpts)) {
|
|
503
495
|
builder.withEntityId(oidfOpts.identifier, PropertyTarget.REQUEST_OBJECT);
|
|
@@ -510,6 +502,9 @@ async function createRPBuilder(args) {
|
|
|
510
502
|
if (hasher) {
|
|
511
503
|
builder.withHasher(hasher);
|
|
512
504
|
}
|
|
505
|
+
if (dcqlQuery) {
|
|
506
|
+
builder.withDcqlQuery(dcqlQuery);
|
|
507
|
+
}
|
|
513
508
|
if (rpOpts.responseRedirectUri) {
|
|
514
509
|
builder.withResponseRedirectUri(rpOpts.responseRedirectUri);
|
|
515
510
|
}
|
|
@@ -582,16 +577,17 @@ var RPInstance = class {
|
|
|
582
577
|
__name(this, "RPInstance");
|
|
583
578
|
}
|
|
584
579
|
_rp;
|
|
585
|
-
|
|
580
|
+
_pexOptions;
|
|
586
581
|
_rpOptions;
|
|
587
582
|
constructor({ rpOpts, pexOpts }) {
|
|
588
583
|
this._rpOptions = rpOpts;
|
|
589
|
-
this.
|
|
584
|
+
this._pexOptions = pexOpts;
|
|
590
585
|
}
|
|
591
586
|
async get(context) {
|
|
592
587
|
if (!this._rp) {
|
|
593
588
|
const builder = await createRPBuilder({
|
|
594
589
|
rpOpts: this._rpOptions,
|
|
590
|
+
pexOpts: this._pexOptions,
|
|
595
591
|
context
|
|
596
592
|
});
|
|
597
593
|
this._rp = builder.build();
|
|
@@ -601,8 +597,20 @@ var RPInstance = class {
|
|
|
601
597
|
get rpOptions() {
|
|
602
598
|
return this._rpOptions;
|
|
603
599
|
}
|
|
604
|
-
get
|
|
605
|
-
return this.
|
|
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;
|
|
606
614
|
}
|
|
607
615
|
async createAuthorizationRequestURI(createArgs, context) {
|
|
608
616
|
const { correlationId, queryId, claims, requestByReferenceURI, responseURI, responseURIType, callback } = createArgs;
|
|
@@ -719,7 +727,6 @@ var SIOPv2RP = class _SIOPv2RP {
|
|
|
719
727
|
}
|
|
720
728
|
async createAuthorizationRequestURI(createArgs, context) {
|
|
721
729
|
return await this.getRPInstance({
|
|
722
|
-
createWhenNotPresent: true,
|
|
723
730
|
responseRedirectURI: createArgs.responseRedirectURI,
|
|
724
731
|
...createArgs.useQueryIdInstance === true && {
|
|
725
732
|
queryId: createArgs.queryId
|
|
@@ -728,7 +735,6 @@ var SIOPv2RP = class _SIOPv2RP {
|
|
|
728
735
|
}
|
|
729
736
|
async createAuthorizationRequestPayloads(createArgs, context) {
|
|
730
737
|
return await this.getRPInstance({
|
|
731
|
-
createWhenNotPresent: true,
|
|
732
738
|
queryId: createArgs.queryId
|
|
733
739
|
}, context).then((rp) => rp.createAuthorizationRequest(createArgs, context)).then(async (request) => {
|
|
734
740
|
const authRequest = {
|
|
@@ -741,13 +747,11 @@ var SIOPv2RP = class _SIOPv2RP {
|
|
|
741
747
|
}
|
|
742
748
|
async siopGetRequestState(args, context) {
|
|
743
749
|
return await this.getRPInstance({
|
|
744
|
-
createWhenNotPresent: false,
|
|
745
750
|
queryId: args.queryId
|
|
746
751
|
}, context).then((rp) => rp.get(context).then((rp2) => rp2.sessionManager.getRequestStateByCorrelationId(args.correlationId, args.errorOnNotFound)));
|
|
747
752
|
}
|
|
748
753
|
async siopGetResponseState(args, context) {
|
|
749
754
|
const rpInstance = await this.getRPInstance({
|
|
750
|
-
createWhenNotPresent: false,
|
|
751
755
|
queryId: args.queryId
|
|
752
756
|
}, context);
|
|
753
757
|
const authorizationResponseState = await rpInstance.get(context).then((rp) => rp.sessionManager.getResponseStateByCorrelationId(args.correlationId, args.errorOnNotFound));
|
|
@@ -805,7 +809,6 @@ var SIOPv2RP = class _SIOPv2RP {
|
|
|
805
809
|
throw Error(`Only 'authorization_request_created' status is supported for this method at this point`);
|
|
806
810
|
}
|
|
807
811
|
return await this.getRPInstance({
|
|
808
|
-
createWhenNotPresent: false,
|
|
809
812
|
queryId: args.queryId
|
|
810
813
|
}, context).then((rp) => rp.get(context).then(async (rp2) => {
|
|
811
814
|
await rp2.signalAuthRequestRetrieved({
|
|
@@ -817,7 +820,6 @@ var SIOPv2RP = class _SIOPv2RP {
|
|
|
817
820
|
}
|
|
818
821
|
async siopDeleteState(args, context) {
|
|
819
822
|
return await this.getRPInstance({
|
|
820
|
-
createWhenNotPresent: false,
|
|
821
823
|
queryId: args.queryId
|
|
822
824
|
}, context).then((rp) => rp.get(context).then((rp2) => rp2.sessionManager.deleteStateForCorrelationId(args.correlationId))).then(() => true);
|
|
823
825
|
}
|
|
@@ -827,7 +829,6 @@ var SIOPv2RP = class _SIOPv2RP {
|
|
|
827
829
|
}
|
|
828
830
|
const authResponse = typeof args.authorizationResponse === "string" ? decodeUriAsJson(args.authorizationResponse) : args.authorizationResponse;
|
|
829
831
|
return await this.getRPInstance({
|
|
830
|
-
createWhenNotPresent: false,
|
|
831
832
|
queryId: args.queryId
|
|
832
833
|
}, context).then((rp) => rp.get(context).then((rp2) => rp2.verifyAuthorizationResponse(authResponse, {
|
|
833
834
|
correlationId: args.correlationId,
|
|
@@ -872,37 +873,9 @@ var SIOPv2RP = class _SIOPv2RP {
|
|
|
872
873
|
}
|
|
873
874
|
return void 0;
|
|
874
875
|
}
|
|
875
|
-
async getRPInstance({
|
|
876
|
-
|
|
877
|
-
|
|
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
|
-
}
|
|
876
|
+
async getRPInstance({ queryId, responseRedirectURI }, context) {
|
|
877
|
+
const instanceId = queryId ?? _SIOPv2RP._DEFAULT_OPTS_KEY;
|
|
878
|
+
if (!this.instances.has(instanceId)) {
|
|
906
879
|
const instanceOpts = this.getInstanceOpts(queryId);
|
|
907
880
|
const rpOpts = await this.getRPOptions(context, {
|
|
908
881
|
queryId,
|
|
@@ -924,12 +897,12 @@ var SIOPv2RP = class _SIOPv2RP {
|
|
|
924
897
|
resolverResolution: true
|
|
925
898
|
});
|
|
926
899
|
}
|
|
927
|
-
|
|
900
|
+
this.instances.set(instanceId, new RPInstance({
|
|
928
901
|
rpOpts,
|
|
929
902
|
pexOpts: instanceOpts
|
|
930
|
-
});
|
|
931
|
-
this.instances.set(rpInstanceId, rpInstance);
|
|
903
|
+
}));
|
|
932
904
|
}
|
|
905
|
+
const rpInstance = this.instances.get(instanceId);
|
|
933
906
|
if (responseRedirectURI) {
|
|
934
907
|
rpInstance.rpOptions.responseRedirectUri = responseRedirectURI;
|
|
935
908
|
}
|
|
@@ -971,20 +944,20 @@ var SIOPv2RP = class _SIOPv2RP {
|
|
|
971
944
|
}
|
|
972
945
|
return options;
|
|
973
946
|
}
|
|
974
|
-
getInstanceOpts(
|
|
947
|
+
getInstanceOpts(definitionId) {
|
|
975
948
|
if (!this.opts.instanceOpts) return void 0;
|
|
976
|
-
const instanceOpt =
|
|
977
|
-
return instanceOpt ?? this.getDefaultOptions(
|
|
949
|
+
const instanceOpt = definitionId ? this.opts.instanceOpts.find((i) => i.queryId === definitionId) : void 0;
|
|
950
|
+
return instanceOpt ?? this.getDefaultOptions(definitionId);
|
|
978
951
|
}
|
|
979
|
-
getDefaultOptions(
|
|
952
|
+
getDefaultOptions(definitionId) {
|
|
980
953
|
if (!this.opts.instanceOpts) return void 0;
|
|
981
954
|
const defaultOptions = this.opts.instanceOpts.find((i) => i.queryId === "default");
|
|
982
955
|
if (defaultOptions) {
|
|
983
956
|
const clonedOptions = {
|
|
984
957
|
...defaultOptions
|
|
985
958
|
};
|
|
986
|
-
if (
|
|
987
|
-
clonedOptions.queryId =
|
|
959
|
+
if (definitionId !== void 0) {
|
|
960
|
+
clonedOptions.queryId = definitionId;
|
|
988
961
|
}
|
|
989
962
|
return clonedOptions;
|
|
990
963
|
}
|