@sphereon/ssi-sdk.siopv2-oid4vp-rp-auth 0.34.1-feature.SSISDK.57.uni.client.168 → 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.cjs +77 -53
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -14
- package/dist/index.d.ts +10 -14
- package/dist/index.js +77 -53
- package/dist/index.js.map +1 -1
- package/package.json +17 -17
- package/src/RPInstance.ts +7 -26
- package/src/agent/SIOPv2RP.ts +50 -18
- package/src/functions.ts +29 -29
- package/src/types/ISIOPv2RP.ts +4 -6
package/dist/index.cjs
CHANGED
|
@@ -362,6 +362,7 @@ var plugin_schema_default = {
|
|
|
362
362
|
var import_did_auth_siop2 = require("@sphereon/did-auth-siop");
|
|
363
363
|
var import_ssi_sdk_ext4 = require("@sphereon/ssi-sdk-ext.did-utils");
|
|
364
364
|
var import_ssi_sdk2 = require("@sphereon/ssi-sdk.core");
|
|
365
|
+
var import_uuid2 = require("uuid");
|
|
365
366
|
var import_ssi_types2 = require("@sphereon/ssi-types");
|
|
366
367
|
var import_dcql = require("dcql");
|
|
367
368
|
|
|
@@ -392,6 +393,29 @@ function getWellKnownDIDVerifyCallback(siopIdentifierOpts, context) {
|
|
|
392
393
|
};
|
|
393
394
|
}
|
|
394
395
|
__name(getWellKnownDIDVerifyCallback, "getWellKnownDIDVerifyCallback");
|
|
396
|
+
function getDcqlQueryLookupCallback(context) {
|
|
397
|
+
async function dcqlQueryLookup(queryId, version, tenantId) {
|
|
398
|
+
const result = await context.agent.pdmGetDefinitions({
|
|
399
|
+
filter: [
|
|
400
|
+
{
|
|
401
|
+
queryId,
|
|
402
|
+
version,
|
|
403
|
+
tenantId
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
id: queryId
|
|
407
|
+
}
|
|
408
|
+
]
|
|
409
|
+
});
|
|
410
|
+
if (result && result.length > 0) {
|
|
411
|
+
return result[0].dcqlQuery;
|
|
412
|
+
}
|
|
413
|
+
return Promise.reject(Error(`No dcql query found for queryId ${queryId}`));
|
|
414
|
+
}
|
|
415
|
+
__name(dcqlQueryLookup, "dcqlQueryLookup");
|
|
416
|
+
return dcqlQueryLookup;
|
|
417
|
+
}
|
|
418
|
+
__name(getDcqlQueryLookupCallback, "getDcqlQueryLookupCallback");
|
|
395
419
|
function getPresentationVerificationCallback(idOpts, context) {
|
|
396
420
|
async function presentationVerificationCallback(args, presentationSubmission) {
|
|
397
421
|
if (import_ssi_types.CredentialMapper.isSdJwtEncoded(args)) {
|
|
@@ -431,27 +455,8 @@ function getPresentationVerificationCallback(idOpts, context) {
|
|
|
431
455
|
}
|
|
432
456
|
__name(getPresentationVerificationCallback, "getPresentationVerificationCallback");
|
|
433
457
|
async function createRPBuilder(args) {
|
|
434
|
-
const { rpOpts,
|
|
458
|
+
const { rpOpts, context } = args;
|
|
435
459
|
const { identifierOpts } = rpOpts;
|
|
436
|
-
let definition = args.definition;
|
|
437
|
-
let dcqlQuery = args.dcql;
|
|
438
|
-
if (!definition && pexOpts && pexOpts.queryId) {
|
|
439
|
-
const presentationDefinitionItems = await context.agent.pdmGetDefinitions({
|
|
440
|
-
filter: [
|
|
441
|
-
{
|
|
442
|
-
queryId: pexOpts.queryId,
|
|
443
|
-
version: pexOpts.version,
|
|
444
|
-
tenantId: pexOpts.tenantId
|
|
445
|
-
}
|
|
446
|
-
]
|
|
447
|
-
});
|
|
448
|
-
if (presentationDefinitionItems.length > 0) {
|
|
449
|
-
const presentationDefinitionItem = presentationDefinitionItems[0];
|
|
450
|
-
if (!dcqlQuery) {
|
|
451
|
-
dcqlQuery = presentationDefinitionItem.dcqlQuery;
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
460
|
const didMethods = identifierOpts.supportedDIDMethods ?? await (0, import_ssi_sdk_ext.getAgentDIDMethods)(context);
|
|
456
461
|
const eventEmitter = rpOpts.eventEmitter ?? new import_events.EventEmitter();
|
|
457
462
|
const defaultClientMetadata = {
|
|
@@ -515,7 +520,7 @@ async function createRPBuilder(args) {
|
|
|
515
520
|
wellknownDIDVerifyCallback: getWellKnownDIDVerifyCallback(rpOpts.identifierOpts, context),
|
|
516
521
|
checkLinkedDomain: "if_present"
|
|
517
522
|
}
|
|
518
|
-
}, context)).withRevocationVerification(import_did_auth_siop.RevocationVerification.NEVER).withPresentationVerification(getPresentationVerificationCallback(identifierOpts.idOpts, context));
|
|
523
|
+
}, context)).withDcqlQueryLookup(getDcqlQueryLookupCallback(context)).withRevocationVerification(import_did_auth_siop.RevocationVerification.NEVER).withPresentationVerification(getPresentationVerificationCallback(identifierOpts.idOpts, context));
|
|
519
524
|
const oidfOpts = identifierOpts.oidfOpts;
|
|
520
525
|
if (oidfOpts && (0, import_ssi_sdk_ext2.isExternalIdentifierOIDFEntityIdOpts)(oidfOpts)) {
|
|
521
526
|
builder.withEntityId(oidfOpts.identifier, import_did_auth_siop.PropertyTarget.REQUEST_OBJECT);
|
|
@@ -526,9 +531,6 @@ async function createRPBuilder(args) {
|
|
|
526
531
|
if (hasher) {
|
|
527
532
|
builder.withHasher(hasher);
|
|
528
533
|
}
|
|
529
|
-
if (dcqlQuery) {
|
|
530
|
-
builder.withDcqlQuery(dcqlQuery);
|
|
531
|
-
}
|
|
532
534
|
if (rpOpts.responseRedirectUri) {
|
|
533
535
|
builder.withResponseRedirectUri(rpOpts.responseRedirectUri);
|
|
534
536
|
}
|
|
@@ -594,17 +596,16 @@ var RPInstance = class {
|
|
|
594
596
|
__name(this, "RPInstance");
|
|
595
597
|
}
|
|
596
598
|
_rp;
|
|
597
|
-
|
|
599
|
+
_presentationOptions;
|
|
598
600
|
_rpOptions;
|
|
599
601
|
constructor({ rpOpts, pexOpts }) {
|
|
600
602
|
this._rpOptions = rpOpts;
|
|
601
|
-
this.
|
|
603
|
+
this._presentationOptions = pexOpts;
|
|
602
604
|
}
|
|
603
605
|
async get(context) {
|
|
604
606
|
if (!this._rp) {
|
|
605
607
|
const builder = await createRPBuilder({
|
|
606
608
|
rpOpts: this._rpOptions,
|
|
607
|
-
pexOpts: this._pexOptions,
|
|
608
609
|
context
|
|
609
610
|
});
|
|
610
611
|
this._rp = builder.build();
|
|
@@ -614,20 +615,8 @@ var RPInstance = class {
|
|
|
614
615
|
get rpOptions() {
|
|
615
616
|
return this._rpOptions;
|
|
616
617
|
}
|
|
617
|
-
get
|
|
618
|
-
return this.
|
|
619
|
-
}
|
|
620
|
-
hasDefinition() {
|
|
621
|
-
return this.definitionId !== void 0;
|
|
622
|
-
}
|
|
623
|
-
get definitionId() {
|
|
624
|
-
return this.pexOptions?.queryId;
|
|
625
|
-
}
|
|
626
|
-
async getPresentationDefinition(context) {
|
|
627
|
-
return this.definitionId ? await context.agent.pexStoreGetDefinition({
|
|
628
|
-
definitionId: this.definitionId,
|
|
629
|
-
tenantId: this.pexOptions?.tenantId
|
|
630
|
-
}) : void 0;
|
|
618
|
+
get presentationOptions() {
|
|
619
|
+
return this._presentationOptions;
|
|
631
620
|
}
|
|
632
621
|
async createAuthorizationRequestURI(createArgs, context) {
|
|
633
622
|
const { correlationId, queryId, claims, requestByReferenceURI, responseURI, responseURIType, callback } = createArgs;
|
|
@@ -744,6 +733,7 @@ var SIOPv2RP = class _SIOPv2RP {
|
|
|
744
733
|
}
|
|
745
734
|
async createAuthorizationRequestURI(createArgs, context) {
|
|
746
735
|
return await this.getRPInstance({
|
|
736
|
+
createWhenNotPresent: true,
|
|
747
737
|
responseRedirectURI: createArgs.responseRedirectURI,
|
|
748
738
|
...createArgs.useQueryIdInstance === true && {
|
|
749
739
|
queryId: createArgs.queryId
|
|
@@ -752,6 +742,7 @@ var SIOPv2RP = class _SIOPv2RP {
|
|
|
752
742
|
}
|
|
753
743
|
async createAuthorizationRequestPayloads(createArgs, context) {
|
|
754
744
|
return await this.getRPInstance({
|
|
745
|
+
createWhenNotPresent: true,
|
|
755
746
|
queryId: createArgs.queryId
|
|
756
747
|
}, context).then((rp) => rp.createAuthorizationRequest(createArgs, context)).then(async (request) => {
|
|
757
748
|
const authRequest = {
|
|
@@ -764,11 +755,13 @@ var SIOPv2RP = class _SIOPv2RP {
|
|
|
764
755
|
}
|
|
765
756
|
async siopGetRequestState(args, context) {
|
|
766
757
|
return await this.getRPInstance({
|
|
758
|
+
createWhenNotPresent: false,
|
|
767
759
|
queryId: args.queryId
|
|
768
760
|
}, context).then((rp) => rp.get(context).then((rp2) => rp2.sessionManager.getRequestStateByCorrelationId(args.correlationId, args.errorOnNotFound)));
|
|
769
761
|
}
|
|
770
762
|
async siopGetResponseState(args, context) {
|
|
771
763
|
const rpInstance = await this.getRPInstance({
|
|
764
|
+
createWhenNotPresent: false,
|
|
772
765
|
queryId: args.queryId
|
|
773
766
|
}, context);
|
|
774
767
|
const authorizationResponseState = await rpInstance.get(context).then((rp) => rp.sessionManager.getResponseStateByCorrelationId(args.correlationId, args.errorOnNotFound));
|
|
@@ -826,6 +819,7 @@ var SIOPv2RP = class _SIOPv2RP {
|
|
|
826
819
|
throw Error(`Only 'authorization_request_created' status is supported for this method at this point`);
|
|
827
820
|
}
|
|
828
821
|
return await this.getRPInstance({
|
|
822
|
+
createWhenNotPresent: false,
|
|
829
823
|
queryId: args.queryId
|
|
830
824
|
}, context).then((rp) => rp.get(context).then(async (rp2) => {
|
|
831
825
|
await rp2.signalAuthRequestRetrieved({
|
|
@@ -837,6 +831,7 @@ var SIOPv2RP = class _SIOPv2RP {
|
|
|
837
831
|
}
|
|
838
832
|
async siopDeleteState(args, context) {
|
|
839
833
|
return await this.getRPInstance({
|
|
834
|
+
createWhenNotPresent: false,
|
|
840
835
|
queryId: args.queryId
|
|
841
836
|
}, context).then((rp) => rp.get(context).then((rp2) => rp2.sessionManager.deleteStateForCorrelationId(args.correlationId))).then(() => true);
|
|
842
837
|
}
|
|
@@ -846,6 +841,7 @@ var SIOPv2RP = class _SIOPv2RP {
|
|
|
846
841
|
}
|
|
847
842
|
const authResponse = typeof args.authorizationResponse === "string" ? (0, import_did_auth_siop2.decodeUriAsJson)(args.authorizationResponse) : args.authorizationResponse;
|
|
848
843
|
return await this.getRPInstance({
|
|
844
|
+
createWhenNotPresent: false,
|
|
849
845
|
queryId: args.queryId
|
|
850
846
|
}, context).then((rp) => rp.get(context).then((rp2) => rp2.verifyAuthorizationResponse(authResponse, {
|
|
851
847
|
correlationId: args.correlationId,
|
|
@@ -890,9 +886,37 @@ var SIOPv2RP = class _SIOPv2RP {
|
|
|
890
886
|
}
|
|
891
887
|
return void 0;
|
|
892
888
|
}
|
|
893
|
-
async getRPInstance({ queryId, responseRedirectURI }, context) {
|
|
894
|
-
|
|
895
|
-
|
|
889
|
+
async getRPInstance({ createWhenNotPresent, queryId, responseRedirectURI }, context) {
|
|
890
|
+
let rpInstanceId = _SIOPv2RP._DEFAULT_OPTS_KEY;
|
|
891
|
+
let rpInstance;
|
|
892
|
+
if (queryId) {
|
|
893
|
+
if (this.instances.has(queryId)) {
|
|
894
|
+
rpInstanceId = queryId;
|
|
895
|
+
rpInstance = this.instances.get(rpInstanceId);
|
|
896
|
+
} else if ((0, import_uuid2.validate)(queryId)) {
|
|
897
|
+
try {
|
|
898
|
+
const pd = await context.agent.pdmGetDefinition({
|
|
899
|
+
itemId: queryId
|
|
900
|
+
});
|
|
901
|
+
if (this.instances.has(pd.queryId)) {
|
|
902
|
+
rpInstanceId = pd.queryId;
|
|
903
|
+
rpInstance = this.instances.get(rpInstanceId);
|
|
904
|
+
}
|
|
905
|
+
} catch (ignore) {
|
|
906
|
+
}
|
|
907
|
+
}
|
|
908
|
+
if (createWhenNotPresent) {
|
|
909
|
+
rpInstanceId = queryId;
|
|
910
|
+
} else {
|
|
911
|
+
rpInstance = this.instances.get(rpInstanceId);
|
|
912
|
+
}
|
|
913
|
+
} else {
|
|
914
|
+
rpInstance = this.instances.get(rpInstanceId);
|
|
915
|
+
}
|
|
916
|
+
if (!rpInstance) {
|
|
917
|
+
if (!createWhenNotPresent) {
|
|
918
|
+
return Promise.reject(`No RP instance found for key ${rpInstanceId}`);
|
|
919
|
+
}
|
|
896
920
|
const instanceOpts = this.getInstanceOpts(queryId);
|
|
897
921
|
const rpOpts = await this.getRPOptions(context, {
|
|
898
922
|
queryId,
|
|
@@ -914,12 +938,12 @@ var SIOPv2RP = class _SIOPv2RP {
|
|
|
914
938
|
resolverResolution: true
|
|
915
939
|
});
|
|
916
940
|
}
|
|
917
|
-
|
|
941
|
+
rpInstance = new RPInstance({
|
|
918
942
|
rpOpts,
|
|
919
943
|
pexOpts: instanceOpts
|
|
920
|
-
})
|
|
944
|
+
});
|
|
945
|
+
this.instances.set(rpInstanceId, rpInstance);
|
|
921
946
|
}
|
|
922
|
-
const rpInstance = this.instances.get(instanceId);
|
|
923
947
|
if (responseRedirectURI) {
|
|
924
948
|
rpInstance.rpOptions.responseRedirectUri = responseRedirectURI;
|
|
925
949
|
}
|
|
@@ -961,20 +985,20 @@ var SIOPv2RP = class _SIOPv2RP {
|
|
|
961
985
|
}
|
|
962
986
|
return options;
|
|
963
987
|
}
|
|
964
|
-
getInstanceOpts(
|
|
988
|
+
getInstanceOpts(queryId) {
|
|
965
989
|
if (!this.opts.instanceOpts) return void 0;
|
|
966
|
-
const instanceOpt =
|
|
967
|
-
return instanceOpt ?? this.getDefaultOptions(
|
|
990
|
+
const instanceOpt = queryId ? this.opts.instanceOpts.find((i) => i.queryId === queryId) : void 0;
|
|
991
|
+
return instanceOpt ?? this.getDefaultOptions(queryId);
|
|
968
992
|
}
|
|
969
|
-
getDefaultOptions(
|
|
993
|
+
getDefaultOptions(queryId) {
|
|
970
994
|
if (!this.opts.instanceOpts) return void 0;
|
|
971
995
|
const defaultOptions = this.opts.instanceOpts.find((i) => i.queryId === "default");
|
|
972
996
|
if (defaultOptions) {
|
|
973
997
|
const clonedOptions = {
|
|
974
998
|
...defaultOptions
|
|
975
999
|
};
|
|
976
|
-
if (
|
|
977
|
-
clonedOptions.queryId =
|
|
1000
|
+
if (queryId !== void 0) {
|
|
1001
|
+
clonedOptions.queryId = queryId;
|
|
978
1002
|
}
|
|
979
1003
|
return clonedOptions;
|
|
980
1004
|
}
|