@sphereon/ssi-sdk.credential-vcdm2-jose-provider 0.33.1-feature.jose.vcdm.67 → 0.33.1-feature.vcdm.verification.69
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 +88 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +82 -15
- package/dist/index.js.map +1 -1
- package/package.json +13 -13
- package/src/__tests__/issue-verify-flow-vcdm2-jose.test.ts +11 -2
- package/src/agent/CredentialProviderVcdm2Jose.ts +127 -41
package/dist/index.cjs
CHANGED
|
@@ -36,14 +36,15 @@ __export(index_exports, {
|
|
|
36
36
|
module.exports = __toCommonJS(index_exports);
|
|
37
37
|
|
|
38
38
|
// src/agent/CredentialProviderVcdm2Jose.ts
|
|
39
|
-
var import_ssi_sdk = require("@sphereon/ssi-sdk.credential-vcdm");
|
|
40
|
-
var import_did_jwt_vc = require("did-jwt-vc");
|
|
41
|
-
var import_did_jwt3 = require("did-jwt");
|
|
42
|
-
var import_debug = __toESM(require("debug"), 1);
|
|
43
|
-
var import_ssi_sdk2 = require("@sphereon/ssi-sdk.core");
|
|
44
|
-
var import_ssi_sdk3 = require("@sphereon/ssi-sdk.agent-config");
|
|
45
39
|
var import_ssi_sdk_ext = require("@sphereon/ssi-sdk-ext.identifier-resolution");
|
|
40
|
+
var import_ssi_sdk_ext2 = require("@sphereon/ssi-sdk-ext.key-utils");
|
|
41
|
+
var import_ssi_sdk = require("@sphereon/ssi-sdk.agent-config");
|
|
42
|
+
var import_ssi_sdk2 = require("@sphereon/ssi-sdk.core");
|
|
43
|
+
var import_ssi_sdk3 = require("@sphereon/ssi-sdk.credential-vcdm");
|
|
46
44
|
var import_ssi_types = require("@sphereon/ssi-types");
|
|
45
|
+
var import_debug = __toESM(require("debug"), 1);
|
|
46
|
+
var import_did_jwt3 = require("did-jwt");
|
|
47
|
+
var import_did_jwt_vc = require("did-jwt-vc");
|
|
47
48
|
|
|
48
49
|
// src/did-jwt/JWT.ts
|
|
49
50
|
var import_canonicalize = __toESM(require("canonicalize"), 1);
|
|
@@ -443,7 +444,6 @@ var SELF_ISSUED_V2_VC_INTEROP = "https://self-issued.me/v2/openid-vc";
|
|
|
443
444
|
var SELF_ISSUED_V0_1 = "https://self-issued.me";
|
|
444
445
|
|
|
445
446
|
// src/agent/CredentialProviderVcdm2Jose.ts
|
|
446
|
-
var import_ssi_sdk_ext2 = require("@sphereon/ssi-sdk-ext.key-utils");
|
|
447
447
|
var debug = (0, import_debug.default)("sphereon:ssi-sdk:credential-jwt");
|
|
448
448
|
var CredentialProviderVcdm2Jose = class {
|
|
449
449
|
static {
|
|
@@ -476,7 +476,7 @@ var CredentialProviderVcdm2Jose = class {
|
|
|
476
476
|
async createVerifiableCredential(args, context) {
|
|
477
477
|
const { keyRef } = args;
|
|
478
478
|
const agent = assertContext(context).agent;
|
|
479
|
-
const { credential, issuer } = (0,
|
|
479
|
+
const { credential, issuer } = (0, import_ssi_sdk3.preProcessCredentialPayload)(args);
|
|
480
480
|
if (!(0, import_ssi_types.isVcdm2Credential)(credential)) {
|
|
481
481
|
return Promise.reject(new Error("invalid_argument: credential must be a VCDM2 credential. Context: " + credential["@context"]));
|
|
482
482
|
}
|
|
@@ -492,7 +492,7 @@ var CredentialProviderVcdm2Jose = class {
|
|
|
492
492
|
identifier: identifier.did,
|
|
493
493
|
kmsKeyRef: keyRef
|
|
494
494
|
});
|
|
495
|
-
const key = await (0,
|
|
495
|
+
const key = await (0, import_ssi_sdk3.pickSigningKey)({
|
|
496
496
|
identifier,
|
|
497
497
|
kmsKeyRef: keyRef
|
|
498
498
|
}, context);
|
|
@@ -523,7 +523,7 @@ var CredentialProviderVcdm2Jose = class {
|
|
|
523
523
|
} = args;
|
|
524
524
|
const uniform = import_ssi_types.CredentialMapper.toUniformCredential(credential);
|
|
525
525
|
if (!(0, import_ssi_types.isVcdm2Credential)(uniform)) {
|
|
526
|
-
return Promise.reject(new Error("invalid_argument: credential must be a VCDM2 credential. Context: " +
|
|
526
|
+
return Promise.reject(new Error("invalid_argument: credential must be a VCDM2 credential. Context: " + uniform["@context"]));
|
|
527
527
|
}
|
|
528
528
|
let verificationResult = {
|
|
529
529
|
verified: false
|
|
@@ -539,7 +539,7 @@ var CredentialProviderVcdm2Jose = class {
|
|
|
539
539
|
}
|
|
540
540
|
/** {@inheritdoc @veramo/credential-w3c#AbstractCredentialProvider.createVerifiablePresentation} */
|
|
541
541
|
async createVerifiablePresentation(args, context) {
|
|
542
|
-
const { presentation, holder } = (0,
|
|
542
|
+
const { presentation, holder } = (0, import_ssi_sdk3.preProcessPresentation)(args);
|
|
543
543
|
let {
|
|
544
544
|
domain,
|
|
545
545
|
challenge,
|
|
@@ -552,7 +552,7 @@ var CredentialProviderVcdm2Jose = class {
|
|
|
552
552
|
kmsKeyRef: keyRef
|
|
553
553
|
});
|
|
554
554
|
const identifier = managedIdentifier.identifier;
|
|
555
|
-
const key = await (0,
|
|
555
|
+
const key = await (0, import_ssi_sdk3.pickSigningKey)({
|
|
556
556
|
identifier: managedIdentifier.identifier,
|
|
557
557
|
kmsKeyRef: managedIdentifier.kmsKeyRef
|
|
558
558
|
}, context);
|
|
@@ -633,7 +633,18 @@ var CredentialProviderVcdm2Jose = class {
|
|
|
633
633
|
if (result) {
|
|
634
634
|
return {
|
|
635
635
|
verified: true,
|
|
636
|
-
|
|
636
|
+
results: [
|
|
637
|
+
{
|
|
638
|
+
verified: true,
|
|
639
|
+
presentation: result.verifiablePresentation,
|
|
640
|
+
log: [
|
|
641
|
+
{
|
|
642
|
+
id: "valid_signature",
|
|
643
|
+
valid: true
|
|
644
|
+
}
|
|
645
|
+
]
|
|
646
|
+
}
|
|
647
|
+
]
|
|
637
648
|
};
|
|
638
649
|
}
|
|
639
650
|
} catch (e) {
|
|
@@ -721,9 +732,15 @@ async function verifierSignature({ jwt }, verifierContext) {
|
|
|
721
732
|
if (!credIssuer) {
|
|
722
733
|
throw new Error(`${import_did_jwt3.JWT_ERROR.INVALID_JWT}: No DID has been found in the JWT`);
|
|
723
734
|
}
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
735
|
+
let resolution = void 0;
|
|
736
|
+
try {
|
|
737
|
+
resolution = await agent.identifierExternalResolve({
|
|
738
|
+
identifier: credIssuer
|
|
739
|
+
});
|
|
740
|
+
} catch (e) {
|
|
741
|
+
}
|
|
742
|
+
const credential = import_ssi_types.CredentialMapper.toUniformCredential(jwt);
|
|
743
|
+
const expired = "validUntil" in credential && !!credential.validUntil && Date.parse(credential.validUntil) < (/* @__PURE__ */ new Date()).getTime() / 1e3;
|
|
727
744
|
const didOpts = {
|
|
728
745
|
method: "did",
|
|
729
746
|
identifier: credIssuer
|
|
@@ -731,27 +748,77 @@ async function verifierSignature({ jwt }, verifierContext) {
|
|
|
731
748
|
const jwtResult = await agent.jwtVerifyJwsSignature({
|
|
732
749
|
jws: jwt,
|
|
733
750
|
// @ts-ignore
|
|
734
|
-
jwk: resolution
|
|
751
|
+
jwk: resolution?.jwks[0].jwk,
|
|
735
752
|
opts: {
|
|
736
753
|
...(0, import_ssi_sdk_ext.isDidIdentifier)(credIssuer) && {
|
|
737
754
|
did: didOpts
|
|
738
755
|
}
|
|
739
756
|
}
|
|
740
757
|
});
|
|
741
|
-
|
|
758
|
+
const error = jwtResult.error || expired || !resolution;
|
|
759
|
+
const errorMessage = expired ? "Credential is expired" : !resolution ? `Issuer ${credIssuer} could not be resolved` : jwtResult.message;
|
|
760
|
+
if (error) {
|
|
761
|
+
const log2 = [
|
|
762
|
+
{
|
|
763
|
+
id: "valid_signature",
|
|
764
|
+
valid: false
|
|
765
|
+
},
|
|
766
|
+
{
|
|
767
|
+
id: "issuer_did_resolves",
|
|
768
|
+
valid: resolution != void 0
|
|
769
|
+
},
|
|
770
|
+
{
|
|
771
|
+
id: "expiration",
|
|
772
|
+
valid: !expired
|
|
773
|
+
}
|
|
774
|
+
];
|
|
742
775
|
return {
|
|
743
776
|
verified: false,
|
|
744
777
|
error: {
|
|
745
|
-
message:
|
|
778
|
+
message: errorMessage,
|
|
746
779
|
errorCode: jwtResult.name
|
|
747
780
|
},
|
|
781
|
+
log: log2,
|
|
782
|
+
results: [
|
|
783
|
+
{
|
|
784
|
+
verified: false,
|
|
785
|
+
credential: jwt,
|
|
786
|
+
log: log2,
|
|
787
|
+
error: {
|
|
788
|
+
message: errorMessage,
|
|
789
|
+
errorCode: jwtResult.name
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
],
|
|
748
793
|
payload,
|
|
749
794
|
didResolutionResult: resolution,
|
|
750
795
|
jwt
|
|
751
796
|
};
|
|
752
797
|
}
|
|
798
|
+
const log = [
|
|
799
|
+
{
|
|
800
|
+
id: "valid_signature",
|
|
801
|
+
valid: true
|
|
802
|
+
},
|
|
803
|
+
{
|
|
804
|
+
id: "issuer_did_resolves",
|
|
805
|
+
valid: true
|
|
806
|
+
},
|
|
807
|
+
{
|
|
808
|
+
id: "expiration",
|
|
809
|
+
valid: true
|
|
810
|
+
}
|
|
811
|
+
];
|
|
753
812
|
return {
|
|
754
813
|
verified: true,
|
|
814
|
+
log,
|
|
815
|
+
results: [
|
|
816
|
+
{
|
|
817
|
+
verified: true,
|
|
818
|
+
credential,
|
|
819
|
+
log
|
|
820
|
+
}
|
|
821
|
+
],
|
|
755
822
|
payload,
|
|
756
823
|
didResolutionResult: resolution,
|
|
757
824
|
jwt
|
|
@@ -759,9 +826,9 @@ async function verifierSignature({ jwt }, verifierContext) {
|
|
|
759
826
|
}
|
|
760
827
|
__name(verifierSignature, "verifierSignature");
|
|
761
828
|
function assertContext(context) {
|
|
762
|
-
if (!(0,
|
|
829
|
+
if (!(0, import_ssi_sdk.contextHasPlugin)(context, "jwtPrepareJws")) {
|
|
763
830
|
throw Error("JwtService plugin not found, which is required for JWT signing in the VCDM2 Jose credential provider. Please add the JwtService plugin to your agent configuration.");
|
|
764
|
-
} else if (!(0,
|
|
831
|
+
} else if (!(0, import_ssi_sdk.contextHasPlugin)(context, "identifierManagedGet")) {
|
|
765
832
|
throw Error("Identifier resolution plugin not found, which is required for JWT signing in the VCDM2 Jose credential provider. Please add the JwtService plugin to your agent configuration.");
|
|
766
833
|
}
|
|
767
834
|
return context;
|