@sphereon/ssi-types 0.34.1-feature.FIDES.1.274 → 0.34.1-feature.IDK.11.48
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 +36 -81
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +111 -169
- package/dist/index.d.ts +111 -169
- package/dist/index.js +36 -81
- package/dist/index.js.map +1 -1
- package/package.json +3 -5
- package/src/index.ts +0 -1
- package/src/mapper/credential-mapper.ts +35 -46
- package/src/types/cose.ts +4 -5
- package/src/types/dcql.ts +39 -0
- package/src/types/index.ts +1 -2
- package/src/types/mso_mdoc.ts +9 -9
- package/src/types/sd-jwt-vc.ts +10 -19
- package/src/types/vc.ts +1 -42
- package/src/types/w3c-vc.ts +12 -30
- package/src/utils/mdoc.ts +9 -10
- package/src/utils/sd-jwt.ts +18 -32
- package/src/types/datastore.ts +0 -6
- package/src/types/vcdm2-sdjwt/index.ts +0 -2
- package/src/types/vcdm2-sdjwt/sd-jwt-vc-config.ts +0 -22
- package/src/types/vcdm2-sdjwt/sd-jwt-vc-payload.ts +0 -23
package/dist/index.cjs
CHANGED
|
@@ -34,7 +34,6 @@ __export(index_exports, {
|
|
|
34
34
|
ActionType: () => ActionType,
|
|
35
35
|
BasicEventEmitter: () => BasicEventEmitter,
|
|
36
36
|
CredentialMapper: () => CredentialMapper,
|
|
37
|
-
CredentialRole: () => CredentialRole,
|
|
38
37
|
DefaultActionSubType: () => DefaultActionSubType,
|
|
39
38
|
DocumentFormat: () => DocumentFormat,
|
|
40
39
|
EventManager: () => EventManager,
|
|
@@ -295,15 +294,6 @@ var SimpleRecordLogger = class extends SimpleLogger {
|
|
|
295
294
|
}
|
|
296
295
|
};
|
|
297
296
|
|
|
298
|
-
// src/types/datastore.ts
|
|
299
|
-
var CredentialRole = /* @__PURE__ */ (function(CredentialRole2) {
|
|
300
|
-
CredentialRole2["ISSUER"] = "ISSUER";
|
|
301
|
-
CredentialRole2["VERIFIER"] = "VERIFIER";
|
|
302
|
-
CredentialRole2["HOLDER"] = "HOLDER";
|
|
303
|
-
CredentialRole2["FEDERATION_TRUST_ANCHOR"] = "FEDERATION_TRUST_ANCHOR";
|
|
304
|
-
return CredentialRole2;
|
|
305
|
-
})({});
|
|
306
|
-
|
|
307
297
|
// src/events/index.ts
|
|
308
298
|
var import_events2 = require("events");
|
|
309
299
|
var System = /* @__PURE__ */ (function(System2) {
|
|
@@ -650,8 +640,7 @@ var parse = /* @__PURE__ */ __name((didUrl) => {
|
|
|
650
640
|
}, "parse");
|
|
651
641
|
|
|
652
642
|
// src/utils/mdoc.ts
|
|
653
|
-
var
|
|
654
|
-
var { com } = import_kmp_mdoc_core.default;
|
|
643
|
+
var mdoc = __toESM(require("@sphereon/kmp-mdoc-core"), 1);
|
|
655
644
|
function isWrappedMdocCredential(vc) {
|
|
656
645
|
return vc.format === "mso_mdoc";
|
|
657
646
|
}
|
|
@@ -660,12 +649,12 @@ function isWrappedMdocPresentation(vp) {
|
|
|
660
649
|
return vp.format === "mso_mdoc";
|
|
661
650
|
}
|
|
662
651
|
__name(isWrappedMdocPresentation, "isWrappedMdocPresentation");
|
|
663
|
-
function getMdocDecodedPayload(
|
|
664
|
-
const mdocJson =
|
|
652
|
+
function getMdocDecodedPayload(mdoc2) {
|
|
653
|
+
const mdocJson = mdoc2.toJson();
|
|
665
654
|
if (!mdocJson.issuerSigned.nameSpaces) {
|
|
666
655
|
throw Error(`Cannot access Issuer Signed items from the Mdoc`);
|
|
667
656
|
}
|
|
668
|
-
const issuerSignedJson =
|
|
657
|
+
const issuerSignedJson = mdoc2.issuerSigned.toJsonDTO();
|
|
669
658
|
const namespaces = issuerSignedJson.nameSpaces;
|
|
670
659
|
const decodedPayload = {};
|
|
671
660
|
for (const [namespace, items] of Object.entries(namespaces)) {
|
|
@@ -678,17 +667,17 @@ function getMdocDecodedPayload(mdoc) {
|
|
|
678
667
|
}
|
|
679
668
|
__name(getMdocDecodedPayload, "getMdocDecodedPayload");
|
|
680
669
|
function decodeMdocIssuerSigned(oid4vpIssuerSigned) {
|
|
681
|
-
const issuerSigned = com.sphereon.mdoc.data.device.IssuerSignedCbor.Static.cborDecode(com.sphereon.kmp.decodeFrom(oid4vpIssuerSigned, com.sphereon.kmp.Encoding.BASE64URL));
|
|
670
|
+
const issuerSigned = mdoc.com.sphereon.mdoc.data.device.IssuerSignedCbor.Static.cborDecode(mdoc.com.sphereon.kmp.decodeFrom(oid4vpIssuerSigned, mdoc.com.sphereon.kmp.Encoding.BASE64URL));
|
|
682
671
|
const holderMdoc = issuerSigned.toDocument();
|
|
683
672
|
return holderMdoc;
|
|
684
673
|
}
|
|
685
674
|
__name(decodeMdocIssuerSigned, "decodeMdocIssuerSigned");
|
|
686
675
|
function encodeMdocIssuerSigned(issuerSigned, encoding = "base64url") {
|
|
687
|
-
return com.sphereon.kmp.encodeTo(issuerSigned.cborEncode(), com.sphereon.kmp.Encoding.BASE64URL);
|
|
676
|
+
return mdoc.com.sphereon.kmp.encodeTo(issuerSigned.cborEncode(), mdoc.com.sphereon.kmp.Encoding.BASE64URL);
|
|
688
677
|
}
|
|
689
678
|
__name(encodeMdocIssuerSigned, "encodeMdocIssuerSigned");
|
|
690
679
|
function decodeMdocDeviceResponse(vpToken) {
|
|
691
|
-
const deviceResponse = com.sphereon.mdoc.data.device.DeviceResponseCbor.Static.cborDecode(com.sphereon.kmp.decodeFrom(vpToken, com.sphereon.kmp.Encoding.BASE64URL));
|
|
680
|
+
const deviceResponse = mdoc.com.sphereon.mdoc.data.device.DeviceResponseCbor.Static.cborDecode(mdoc.com.sphereon.kmp.decodeFrom(vpToken, mdoc.com.sphereon.kmp.Encoding.BASE64URL));
|
|
692
681
|
return deviceResponse;
|
|
693
682
|
}
|
|
694
683
|
__name(decodeMdocDeviceResponse, "decodeMdocDeviceResponse");
|
|
@@ -741,7 +730,7 @@ var mdocDecodedCredentialToUniformCredential = /* @__PURE__ */ __name((decoded,
|
|
|
741
730
|
created: issuanceDate,
|
|
742
731
|
proofPurpose: IProofPurpose.authentication,
|
|
743
732
|
verificationMethod: json.issuerSigned.issuerAuth.payload,
|
|
744
|
-
mso_mdoc: com.sphereon.kmp.encodeTo(decoded.cborEncode(), com.sphereon.kmp.Encoding.BASE64URL)
|
|
733
|
+
mso_mdoc: mdoc.com.sphereon.kmp.encodeTo(decoded.cborEncode(), mdoc.com.sphereon.kmp.Encoding.BASE64URL)
|
|
745
734
|
}
|
|
746
735
|
};
|
|
747
736
|
return credential;
|
|
@@ -754,10 +743,8 @@ function decodeSdJwtVc(compactSdJwtVc, hasher) {
|
|
|
754
743
|
const signedPayload = jwt.payload;
|
|
755
744
|
const decodedPayload = (0, import_decode.getClaimsSync)(signedPayload, disclosures, hasher);
|
|
756
745
|
const compactKeyBindingJwt = kbJwt ? compactSdJwtVc.split("~").pop() : void 0;
|
|
757
|
-
const type = decodedPayload.vct ? "dc+sd-jwt" : "vc+sd-jwt";
|
|
758
746
|
return {
|
|
759
747
|
compactSdJwtVc,
|
|
760
|
-
type,
|
|
761
748
|
decodedPayload,
|
|
762
749
|
disclosures: disclosures.map((d) => {
|
|
763
750
|
const decoded = d.key ? [
|
|
@@ -791,10 +778,8 @@ async function decodeSdJwtVcAsync(compactSdJwtVc, hasher) {
|
|
|
791
778
|
const signedPayload = jwt.payload;
|
|
792
779
|
const decodedPayload = await (0, import_decode.getClaims)(signedPayload, disclosures, hasher);
|
|
793
780
|
const compactKeyBindingJwt = kbJwt ? compactSdJwtVc.split("~").pop() : void 0;
|
|
794
|
-
const type = decodedPayload.vct ? "dc+sd-jwt" : "vc+sd-jwt";
|
|
795
781
|
return {
|
|
796
782
|
compactSdJwtVc,
|
|
797
|
-
type,
|
|
798
783
|
decodedPayload,
|
|
799
784
|
disclosures: disclosures.map((d) => {
|
|
800
785
|
const decoded = d.key ? [
|
|
@@ -825,19 +810,13 @@ async function decodeSdJwtVcAsync(compactSdJwtVc, hasher) {
|
|
|
825
810
|
__name(decodeSdJwtVcAsync, "decodeSdJwtVcAsync");
|
|
826
811
|
var sdJwtDecodedCredentialToUniformCredential = /* @__PURE__ */ __name((decoded, opts) => {
|
|
827
812
|
const { decodedPayload } = decoded;
|
|
828
|
-
const { exp, nbf, iss, iat, vct, cnf, status,
|
|
829
|
-
let credentialSubject = decodedPayload.credentialSubject;
|
|
830
|
-
let issuer = iss ?? decodedPayload.issuer;
|
|
831
|
-
if (typeof issuer === "object" && "id" in issuer && typeof issuer.id === "string") {
|
|
832
|
-
issuer = issuer.id;
|
|
833
|
-
}
|
|
834
|
-
const subId = decodedPayload.sub ?? (typeof credentialSubject == "object" && "id" in credentialSubject ? credentialSubject.id : void 0);
|
|
813
|
+
const { exp, nbf, iss, iat, vct, cnf, status, sub, jti } = decodedPayload;
|
|
835
814
|
const maxSkewInMS = opts?.maxTimeSkewInMS ?? 1500;
|
|
836
|
-
const expirationDate =
|
|
815
|
+
const expirationDate = jwtDateToISOString({
|
|
837
816
|
jwtClaim: exp,
|
|
838
817
|
claimName: "exp"
|
|
839
818
|
});
|
|
840
|
-
let issuanceDateStr =
|
|
819
|
+
let issuanceDateStr = jwtDateToISOString({
|
|
841
820
|
jwtClaim: iat,
|
|
842
821
|
claimName: "iat"
|
|
843
822
|
});
|
|
@@ -848,7 +827,7 @@ var sdJwtDecodedCredentialToUniformCredential = /* @__PURE__ */ __name((decoded,
|
|
|
848
827
|
claimName: "nbf"
|
|
849
828
|
});
|
|
850
829
|
if (issuanceDateStr && nbfDateAsStr && issuanceDateStr !== nbfDateAsStr) {
|
|
851
|
-
const diff = Math.abs(new Date(nbfDateAsStr).getTime() - new Date(
|
|
830
|
+
const diff = Math.abs(new Date(nbfDateAsStr).getTime() - new Date(iss).getTime());
|
|
852
831
|
if (!maxSkewInMS || diff > maxSkewInMS) {
|
|
853
832
|
throw Error(`Inconsistent issuance dates between JWT claim (${nbfDateAsStr}) and VC value (${iss})`);
|
|
854
833
|
}
|
|
@@ -869,39 +848,24 @@ var sdJwtDecodedCredentialToUniformCredential = /* @__PURE__ */ __name((decoded,
|
|
|
869
848
|
"jti",
|
|
870
849
|
"sub"
|
|
871
850
|
]);
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
}, {});
|
|
879
|
-
}
|
|
880
|
-
const sdJwtVc = decodedPayload.vct && !decodedPayload.type;
|
|
851
|
+
const credentialSubject = Object.entries(decodedPayload).reduce((acc, [key, value]) => {
|
|
852
|
+
if (!excludedFields.has(key) && value !== void 0 && value !== "" && !(typeof value === "object" && value !== null && Object.keys(value).length === 0)) {
|
|
853
|
+
acc[key] = value;
|
|
854
|
+
}
|
|
855
|
+
return acc;
|
|
856
|
+
}, {});
|
|
881
857
|
const credential = {
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
},
|
|
887
|
-
...{
|
|
888
|
-
"@context": sdJwtVc ? [] : decodedPayload["@context"]
|
|
889
|
-
},
|
|
858
|
+
type: [
|
|
859
|
+
vct
|
|
860
|
+
],
|
|
861
|
+
"@context": [],
|
|
890
862
|
credentialSubject: {
|
|
891
863
|
...credentialSubject,
|
|
892
|
-
id:
|
|
864
|
+
id: credentialSubject.id ?? sub ?? jti
|
|
893
865
|
},
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
validFrom: issuanceDateStr
|
|
898
|
-
}),
|
|
899
|
-
...expirationDate && (sdJwtVc ? {
|
|
900
|
-
expirationDate
|
|
901
|
-
} : {
|
|
902
|
-
validUntil: expirationDate
|
|
903
|
-
}),
|
|
904
|
-
issuer,
|
|
866
|
+
issuanceDate,
|
|
867
|
+
expirationDate,
|
|
868
|
+
issuer: iss,
|
|
905
869
|
...cnf && {
|
|
906
870
|
cnf
|
|
907
871
|
},
|
|
@@ -1101,7 +1065,6 @@ var CredentialMapper = class _CredentialMapper {
|
|
|
1101
1065
|
* an async hasher implementation, use the decodeSdJwtVcAsync method instead and you can provide the decoded payload to methods
|
|
1102
1066
|
* instead of the compact SD-JWT.
|
|
1103
1067
|
*
|
|
1104
|
-
* @param credential
|
|
1105
1068
|
* @param hasher Hasher implementation to use for SD-JWT decoding
|
|
1106
1069
|
*/
|
|
1107
1070
|
static decodeVerifiableCredential(credential, hasher) {
|
|
@@ -1138,8 +1101,7 @@ var CredentialMapper = class _CredentialMapper {
|
|
|
1138
1101
|
* an async hasher implementation, use the decodeSdJwtVcAsync method instead and you can provide the decoded payload to methods
|
|
1139
1102
|
* instead of the compact SD-JWT.
|
|
1140
1103
|
*
|
|
1141
|
-
* @param
|
|
1142
|
-
* @param opts
|
|
1104
|
+
* @param hasher Hasher implementation to use for SD-JWT decoding
|
|
1143
1105
|
*/
|
|
1144
1106
|
static toWrappedVerifiablePresentation(originalPresentation, opts) {
|
|
1145
1107
|
if (_CredentialMapper.isMsoMdocDecodedPresentation(originalPresentation) || _CredentialMapper.isMsoMdocOid4VPEncoded(originalPresentation)) {
|
|
@@ -1174,7 +1136,7 @@ var CredentialMapper = class _CredentialMapper {
|
|
|
1174
1136
|
}
|
|
1175
1137
|
return {
|
|
1176
1138
|
type: _CredentialMapper.isSdJwtDecodedCredential(originalPresentation) ? "sd-jwt-vc-decoded" : "sd-jwt-vc-encoded",
|
|
1177
|
-
format: "
|
|
1139
|
+
format: "vc+sd-jwt",
|
|
1178
1140
|
original: originalPresentation,
|
|
1179
1141
|
presentation: decodedPresentation,
|
|
1180
1142
|
decoded: decodedPresentation.decodedPayload,
|
|
@@ -1244,18 +1206,18 @@ var CredentialMapper = class _CredentialMapper {
|
|
|
1244
1206
|
*/
|
|
1245
1207
|
static toWrappedVerifiableCredential(verifiableCredential, opts) {
|
|
1246
1208
|
if (_CredentialMapper.isMsoMdocDecodedCredential(verifiableCredential) || _CredentialMapper.isMsoMdocOid4VPEncoded(verifiableCredential)) {
|
|
1247
|
-
let
|
|
1209
|
+
let mdoc2;
|
|
1248
1210
|
if (_CredentialMapper.isMsoMdocOid4VPEncoded(verifiableCredential)) {
|
|
1249
|
-
|
|
1211
|
+
mdoc2 = decodeMdocIssuerSigned(verifiableCredential);
|
|
1250
1212
|
} else {
|
|
1251
|
-
|
|
1213
|
+
mdoc2 = verifiableCredential;
|
|
1252
1214
|
}
|
|
1253
1215
|
return {
|
|
1254
1216
|
type: _CredentialMapper.isMsoMdocDecodedCredential(verifiableCredential) ? "mso_mdoc-decoded" : "mso_mdoc-encoded",
|
|
1255
1217
|
format: "mso_mdoc",
|
|
1256
1218
|
original: verifiableCredential,
|
|
1257
|
-
credential:
|
|
1258
|
-
decoded: getMdocDecodedPayload(
|
|
1219
|
+
credential: mdoc2,
|
|
1220
|
+
decoded: getMdocDecodedPayload(mdoc2)
|
|
1259
1221
|
};
|
|
1260
1222
|
}
|
|
1261
1223
|
if (_CredentialMapper.isSdJwtDecodedCredential(verifiableCredential) || _CredentialMapper.isSdJwtEncoded(verifiableCredential)) {
|
|
@@ -1268,7 +1230,7 @@ var CredentialMapper = class _CredentialMapper {
|
|
|
1268
1230
|
}
|
|
1269
1231
|
return {
|
|
1270
1232
|
type: _CredentialMapper.isSdJwtDecodedCredential(verifiableCredential) ? "sd-jwt-vc-decoded" : "sd-jwt-vc-encoded",
|
|
1271
|
-
format: "
|
|
1233
|
+
format: "vc+sd-jwt",
|
|
1272
1234
|
original: verifiableCredential,
|
|
1273
1235
|
credential: decodedCredential,
|
|
1274
1236
|
decoded: decodedCredential.decodedPayload
|
|
@@ -1390,13 +1352,6 @@ var CredentialMapper = class _CredentialMapper {
|
|
|
1390
1352
|
static isSdJwtDecodedCredential(original) {
|
|
1391
1353
|
return typeof original === "object" && (original.compactSdJwtVc !== void 0 || original.kbJwt !== void 0);
|
|
1392
1354
|
}
|
|
1393
|
-
static isSdJwtVcdm2DecodedCredential(original) {
|
|
1394
|
-
if (typeof original !== "object") {
|
|
1395
|
-
return false;
|
|
1396
|
-
}
|
|
1397
|
-
const decoded = original;
|
|
1398
|
-
return decoded.compactSdJwtVc !== void 0 && !decoded.decodedPayload.vct && !decoded.decodedPayload["@context"];
|
|
1399
|
-
}
|
|
1400
1355
|
static isMsoMdocDecodedCredential(original) {
|
|
1401
1356
|
return typeof original === "object" && "issuerSigned" in original && original.issuerSigned !== void 0;
|
|
1402
1357
|
}
|
|
@@ -1720,11 +1675,11 @@ var CredentialMapper = class _CredentialMapper {
|
|
|
1720
1675
|
}
|
|
1721
1676
|
};
|
|
1722
1677
|
function isWrappedSdJwtVerifiableCredential(vc) {
|
|
1723
|
-
return vc.format === "
|
|
1678
|
+
return vc.format === "vc+sd-jwt";
|
|
1724
1679
|
}
|
|
1725
1680
|
__name(isWrappedSdJwtVerifiableCredential, "isWrappedSdJwtVerifiableCredential");
|
|
1726
1681
|
function isWrappedSdJwtVerifiablePresentation(vp) {
|
|
1727
|
-
return vp.format === "
|
|
1682
|
+
return vp.format === "vc+sd-jwt";
|
|
1728
1683
|
}
|
|
1729
1684
|
__name(isWrappedSdJwtVerifiablePresentation, "isWrappedSdJwtVerifiablePresentation");
|
|
1730
1685
|
var OriginalType = /* @__PURE__ */ (function(OriginalType2) {
|