@sphereon/ssi-sdk.vc-status-list 0.34.1-feature.SSISDK.17.bitstring.sl.11 → 0.34.1-feature.SSISDK.17.bitstring.sl.13

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 CHANGED
@@ -123,7 +123,8 @@ var ValidProofTypeMap = /* @__PURE__ */ new Map([
123
123
  [
124
124
  import_ssi_types.StatusListType.BitstringStatusList,
125
125
  [
126
- "lds"
126
+ "lds",
127
+ "vc+jwt"
127
128
  ]
128
129
  ]
129
130
  ]);
@@ -845,6 +846,13 @@ var BitstringStatusListImplementation = class {
845
846
  static {
846
847
  __name(this, "BitstringStatusListImplementation");
847
848
  }
849
+ /**
850
+ * Creates a new bitstring status list with the specified configuration
851
+ *
852
+ * @param args - Configuration for the new status list including issuer, purpose, and size
853
+ * @param context - Veramo agent context for credential operations
854
+ * @returns Promise resolving to the created status list details
855
+ */
848
856
  async createNewStatusList(args, context) {
849
857
  if (!args.bitstringStatusList) {
850
858
  throw new Error("BitstringStatusList options are required for type BitstringStatusList");
@@ -852,28 +860,34 @@ var BitstringStatusListImplementation = class {
852
860
  const length = args?.length ?? DEFAULT_LIST_LENGTH3;
853
861
  const proofFormat = args?.proofFormat ?? DEFAULT_PROOF_FORMAT3;
854
862
  assertValidProofType(import_ssi_types5.StatusListType.BitstringStatusList, proofFormat);
855
- const veramoProofFormat = proofFormat;
856
863
  const { issuer, id } = args;
857
864
  const correlationId = getAssertedValue("correlationId", args.correlationId);
858
865
  const { statusPurpose, bitsPerStatus, validFrom, validUntil, ttl } = args.bitstringStatusList;
859
- const statusListCredential = await this.createVerifiableCredential({
860
- ...args,
861
- proofFormat: veramoProofFormat,
866
+ const unsignedCredential = await (0, import_vc_bitstring_status_lists.createStatusListCredential)({
867
+ id,
868
+ issuer,
862
869
  statusPurpose: statusPurpose ?? DEFAULT_STATUS_PURPOSE,
863
870
  validFrom: ensureDate(validFrom),
864
871
  validUntil: ensureDate(validUntil),
865
872
  ttl
873
+ });
874
+ const statusListCredential = await this.createVerifiableCredential({
875
+ unsignedCredential,
876
+ id,
877
+ issuer,
878
+ proofFormat,
879
+ keyRef: args.keyRef
866
880
  }, context);
867
881
  return {
868
- encodedList: statusListCredential.credentialSubject.encodedList,
882
+ encodedList: unsignedCredential.credentialSubject.encodedList,
869
883
  statusListCredential,
870
884
  bitstringStatusList: {
871
885
  statusPurpose: statusPurpose ?? DEFAULT_STATUS_PURPOSE,
872
- ...statusListCredential.validFrom && {
873
- validFrom: new Date(statusListCredential.validFrom)
886
+ ...unsignedCredential.validFrom && {
887
+ validFrom: new Date(unsignedCredential.validFrom)
874
888
  },
875
- ...statusListCredential.validUntil && {
876
- validUntil: new Date(statusListCredential.validUntil)
889
+ ...unsignedCredential.validUntil && {
890
+ validUntil: new Date(unsignedCredential.validUntil)
877
891
  },
878
892
  ttl,
879
893
  bitsPerStatus
@@ -887,9 +901,16 @@ var BitstringStatusListImplementation = class {
887
901
  statuslistContentType: this.buildContentType(proofFormat)
888
902
  };
889
903
  }
904
+ /**
905
+ * Updates the status of a specific credential in an existing status list
906
+ *
907
+ * @param args - Update parameters including the status list credential, index, and new value
908
+ * @param context - Veramo agent context for credential operations
909
+ * @returns Promise resolving to the updated status list details
910
+ */
890
911
  async updateStatusListIndex(args, context) {
891
912
  if (!args.bitsPerStatus || args.bitsPerStatus < 1) {
892
- return Promise.reject("bitsPerStatus must be set for bitstring status lists and must be 1 or higher. (updateStatusListIndex)");
913
+ return Promise.reject(Error("bitsPerStatus must be set for bitstring status lists and must be 1 or higher. (updateStatusListIndex)"));
893
914
  }
894
915
  const credential = args.statusListCredential;
895
916
  const uniform = import_ssi_types5.CredentialMapper.toUniformCredential(credential);
@@ -908,27 +929,32 @@ var BitstringStatusListImplementation = class {
908
929
  const validFrom = uniform.validFrom ? new Date(uniform.validFrom) : void 0;
909
930
  const validUntil = uniform.validUntil ? new Date(uniform.validUntil) : void 0;
910
931
  const ttl = credSubject.ttl;
911
- const updatedCredential = await this.createVerifiableCredential({
912
- ...args,
932
+ const unsignedCredential = await (0, import_vc_bitstring_status_lists.createStatusListCredential)({
913
933
  id,
914
934
  issuer,
915
935
  statusList,
936
+ statusPurpose: statusPurpose ?? DEFAULT_STATUS_PURPOSE,
937
+ validFrom: ensureDate(validFrom),
938
+ validUntil: ensureDate(validUntil),
939
+ ttl
940
+ });
941
+ const updatedCredential = await this.createVerifiableCredential({
942
+ unsignedCredential,
943
+ id,
944
+ issuer,
916
945
  proofFormat,
917
- statusPurpose,
918
- ttl,
919
- validFrom,
920
- validUntil
946
+ keyRef: args.keyRef
921
947
  }, context);
922
948
  return {
923
949
  statusListCredential: updatedCredential,
924
- encodedList: updatedCredential.credentialSubject.encodedList,
950
+ encodedList: unsignedCredential.credentialSubject.encodedList,
925
951
  bitstringStatusList: {
926
952
  statusPurpose,
927
- ...updatedCredential.validFrom && {
928
- validFrom: new Date(updatedCredential.validFrom)
953
+ ...unsignedCredential.validFrom && {
954
+ validFrom: new Date(unsignedCredential.validFrom)
929
955
  },
930
- ...updatedCredential.validUntil && {
931
- validUntil: new Date(updatedCredential.validUntil)
956
+ ...unsignedCredential.validUntil && {
957
+ validUntil: new Date(unsignedCredential.validUntil)
932
958
  },
933
959
  bitsPerStatus: args.bitsPerStatus,
934
960
  ttl
@@ -941,17 +967,23 @@ var BitstringStatusListImplementation = class {
941
967
  statuslistContentType: this.buildContentType(proofFormat)
942
968
  };
943
969
  }
970
+ /**
971
+ * Updates a status list by decoding an encoded list, modifying it, and re-encoding
972
+ *
973
+ * @param args - Update parameters including encoded list, index, and new value
974
+ * @param context - Veramo agent context for credential operations
975
+ * @returns Promise resolving to the updated status list details
976
+ */
944
977
  async updateStatusListFromEncodedList(args, context) {
945
978
  if (!args.bitstringStatusList) {
946
979
  throw new Error("bitstringStatusList options required for type BitstringStatusList");
947
980
  }
948
981
  if (args.bitstringStatusList.bitsPerStatus < 1) {
949
- return Promise.reject("bitsPerStatus must be set for bitstring status lists and must be 1 or higher. (updateStatusListFromEncodedList)");
982
+ return Promise.reject(Error("bitsPerStatus must be set for bitstring status lists and must be 1 or higher. (updateStatusListFromEncodedList)"));
950
983
  }
951
984
  const { statusPurpose, bitsPerStatus, ttl, validFrom, validUntil } = args.bitstringStatusList;
952
985
  const proofFormat = args?.proofFormat ?? DEFAULT_PROOF_FORMAT3;
953
986
  assertValidProofType(import_ssi_types5.StatusListType.BitstringStatusList, proofFormat);
954
- const veramoProofFormat = proofFormat;
955
987
  const { issuer, id } = getAssertedValues(args);
956
988
  const statusList = await import_vc_bitstring_status_lists.BitstreamStatusList.decode({
957
989
  encodedList: args.encodedList,
@@ -959,29 +991,34 @@ var BitstringStatusListImplementation = class {
959
991
  });
960
992
  const index = typeof args.statusListIndex === "number" ? args.statusListIndex : parseInt(args.statusListIndex);
961
993
  statusList.setStatus(index, args.value);
962
- const credential = await this.createVerifiableCredential({
994
+ const unsignedCredential = await (0, import_vc_bitstring_status_lists.createStatusListCredential)({
963
995
  id,
964
996
  issuer,
965
997
  statusList,
966
- proofFormat: veramoProofFormat,
967
- keyRef: args.keyRef,
968
- statusPurpose,
998
+ statusPurpose: statusPurpose ?? DEFAULT_STATUS_PURPOSE,
969
999
  validFrom: ensureDate(validFrom),
970
1000
  validUntil: ensureDate(validUntil),
971
1001
  ttl
1002
+ });
1003
+ const credential = await this.createVerifiableCredential({
1004
+ unsignedCredential,
1005
+ id,
1006
+ issuer,
1007
+ proofFormat,
1008
+ keyRef: args.keyRef
972
1009
  }, context);
973
1010
  return {
974
1011
  type: import_ssi_types5.StatusListType.BitstringStatusList,
975
1012
  statusListCredential: credential,
976
- encodedList: credential.credentialSubject.encodedList,
1013
+ encodedList: unsignedCredential.credentialSubject.encodedList,
977
1014
  bitstringStatusList: {
978
1015
  statusPurpose,
979
1016
  bitsPerStatus,
980
- ...credential.validFrom && {
981
- validFrom: new Date(credential.validFrom)
1017
+ ...unsignedCredential.validFrom && {
1018
+ validFrom: new Date(unsignedCredential.validFrom)
982
1019
  },
983
- ...credential.validUntil && {
984
- validUntil: new Date(credential.validUntil)
1020
+ ...unsignedCredential.validUntil && {
1021
+ validUntil: new Date(unsignedCredential.validUntil)
985
1022
  },
986
1023
  ttl
987
1024
  },
@@ -992,17 +1029,22 @@ var BitstringStatusListImplementation = class {
992
1029
  statuslistContentType: this.buildContentType(proofFormat)
993
1030
  };
994
1031
  }
1032
+ /**
1033
+ * Checks the status of a specific credential by its index in the status list
1034
+ *
1035
+ * @param args - Check parameters including the status list credential and index
1036
+ * @returns Promise resolving to the status value at the specified index
1037
+ */
995
1038
  async checkStatusIndex(args) {
996
1039
  if (!args.bitsPerStatus || args.bitsPerStatus < 1) {
997
- return Promise.reject("bitsPerStatus must be set for bitstring status lists and must be 1 or higher. (checkStatusIndex)");
1040
+ return Promise.reject(Error("bitsPerStatus must be set for bitstring status lists and must be 1 or higher. (checkStatusIndex)"));
998
1041
  }
999
1042
  const uniform = import_ssi_types5.CredentialMapper.toUniformCredential(args.statusListCredential);
1000
1043
  const { credentialSubject } = uniform;
1001
1044
  const encodedList = getAssertedProperty("encodedList", credentialSubject);
1002
- const statusSize = args.bitsPerStatus;
1003
1045
  const statusList = await import_vc_bitstring_status_lists.BitstreamStatusList.decode({
1004
1046
  encodedList,
1005
- statusSize
1047
+ statusSize: args.bitsPerStatus
1006
1048
  });
1007
1049
  const numIndex = typeof args.statusListIndex === "number" ? args.statusListIndex : parseInt(args.statusListIndex);
1008
1050
  if (statusList.getLength() <= numIndex) {
@@ -1010,16 +1052,22 @@ var BitstringStatusListImplementation = class {
1010
1052
  }
1011
1053
  return statusList.getStatus(numIndex);
1012
1054
  }
1055
+ /**
1056
+ * Converts a status list credential payload to detailed status list information
1057
+ *
1058
+ * @param args - Conversion parameters including the status list payload
1059
+ * @returns Promise resolving to detailed status list information
1060
+ */
1013
1061
  async toStatusListDetails(args) {
1014
1062
  const { statusListPayload, bitsPerStatus } = args;
1015
1063
  if (!bitsPerStatus || bitsPerStatus < 1) {
1016
- return Promise.reject("bitsPerStatus must be set for bitstring status lists and must be 1 or higher. (toStatusListDetails)");
1064
+ return Promise.reject(Error("bitsPerStatus must be set for bitstring status lists and must be 1 or higher. (toStatusListDetails)"));
1017
1065
  }
1018
1066
  const uniform = import_ssi_types5.CredentialMapper.toUniformCredential(statusListPayload);
1019
1067
  const { issuer, credentialSubject } = uniform;
1020
1068
  const id = getAssertedValue("id", uniform.id);
1021
1069
  const encodedList = getAssertedProperty("encodedList", credentialSubject);
1022
- const proofFormat = import_ssi_types5.CredentialMapper.detectDocumentType(statusListPayload) === import_ssi_types5.DocumentFormat.JWT ? "jwt" : "lds";
1070
+ const proofFormat = import_ssi_types5.CredentialMapper.detectDocumentType(statusListPayload) === import_ssi_types5.DocumentFormat.JWT ? "vc+jwt" : "lds";
1023
1071
  const credSubject = Array.isArray(credentialSubject) ? credentialSubject[0] : credentialSubject;
1024
1072
  const statusPurpose = getAssertedProperty("statusPurpose", credSubject);
1025
1073
  const validFrom = uniform.validFrom ? new Date(uniform.validFrom) : void 0;
@@ -1073,6 +1121,12 @@ var BitstringStatusListImplementation = class {
1073
1121
  }
1074
1122
  };
1075
1123
  }
1124
+ /**
1125
+ * Creates a credential status entry for a specific credential in a status list
1126
+ *
1127
+ * @param args - Parameters including the status list, entry details, and index
1128
+ * @returns Promise resolving to the credential status entry
1129
+ */
1076
1130
  async createCredentialStatus(args) {
1077
1131
  const { statusList, statusListEntry, statusListIndex } = args;
1078
1132
  const isBitstringEntry = /* @__PURE__ */ __name((entry) => {
@@ -1091,27 +1145,42 @@ var BitstringStatusListImplementation = class {
1091
1145
  bitsPerStatus: bitstringStatusList.bitsPerStatus
1092
1146
  };
1093
1147
  }
1148
+ /**
1149
+ * Creates a signed verifiable credential from an unsigned status list credential
1150
+ *
1151
+ * @param args - Parameters including the unsigned credential and signing details
1152
+ * @param context - Veramo agent context for credential operations
1153
+ * @returns Promise resolving to the signed credential
1154
+ */
1094
1155
  async createVerifiableCredential(args, context) {
1156
+ const { unsignedCredential, issuer, proofFormat, keyRef } = args;
1095
1157
  const identifier = await context.agent.identifierManagedGet({
1096
- identifier: typeof args.issuer === "string" ? args.issuer : args.issuer.id,
1158
+ identifier: typeof issuer === "string" ? issuer : issuer.id,
1097
1159
  vmRelationship: "assertionMethod",
1098
1160
  offlineWhenNoDIDRegistered: true
1099
1161
  });
1100
- const unsignedCredential = await (0, import_vc_bitstring_status_lists.createStatusListCredential)(args);
1101
1162
  const verifiableCredential = await context.agent.createVerifiableCredential({
1102
1163
  credential: unsignedCredential,
1103
- keyRef: args.keyRef ?? identifier.kmsKeyRef,
1104
- proofFormat: args.proofFormat,
1164
+ keyRef: keyRef ?? identifier.kmsKeyRef,
1165
+ proofFormat,
1105
1166
  fetchRemoteContexts: true
1106
1167
  });
1107
1168
  return import_ssi_types5.CredentialMapper.toWrappedVerifiableCredential(verifiableCredential).original;
1108
1169
  }
1170
+ /**
1171
+ * Builds the appropriate content type string for a given proof format
1172
+ *
1173
+ * @param proofFormat - The proof format to build content type for
1174
+ * @returns The corresponding content type string
1175
+ */
1109
1176
  buildContentType(proofFormat) {
1110
1177
  switch (proofFormat) {
1111
1178
  case "jwt":
1112
- return `application/statuslist+jwt`;
1179
+ return "application/statuslist+jwt";
1113
1180
  case "cbor":
1114
- return `application/statuslist+cwt`;
1181
+ return "application/statuslist+cwt";
1182
+ case "vc+jwt":
1183
+ return "application/statuslist+vc+jwt";
1115
1184
  case "lds":
1116
1185
  return "application/statuslist+ld+json";
1117
1186
  default:
@@ -1267,27 +1336,8 @@ async function updateStatusIndexFromStatusListCredential(args, context) {
1267
1336
  return implementation.updateStatusListIndex(args, context);
1268
1337
  }
1269
1338
  __name(updateStatusIndexFromStatusListCredential, "updateStatusIndexFromStatusListCredential");
1270
- async function statusListCredentialToDetails({ correlationId, driverType, statusListCredential, bitsPerStatus }) {
1339
+ async function statusListCredentialToDetails({ statusListType, correlationId, driverType, statusListCredential, bitsPerStatus }) {
1271
1340
  const credential = getAssertedValue("statusListCredential", statusListCredential);
1272
- let statusListType;
1273
- const documentFormat = import_ssi_types7.CredentialMapper.detectDocumentType(credential);
1274
- if (documentFormat === import_ssi_types7.DocumentFormat.JWT) {
1275
- const [header] = credential.split(".");
1276
- const decodedHeader = JSON.parse(Buffer.from(header, "base64").toString());
1277
- if (decodedHeader.typ === "statuslist+jwt") {
1278
- statusListType = import_ssi_types7.StatusListType.OAuthStatusList;
1279
- }
1280
- } else if (documentFormat === import_ssi_types7.DocumentFormat.MSO_MDOC) {
1281
- statusListType = import_ssi_types7.StatusListType.OAuthStatusList;
1282
- }
1283
- if (!statusListType) {
1284
- const uniform = import_ssi_types7.CredentialMapper.toUniformCredential(credential);
1285
- const type = uniform.type.find((t) => t.includes("StatusList2021") || t.includes("OAuth2StatusList") || t.includes("BitstringStatusList"));
1286
- if (!type) {
1287
- throw new Error("Invalid status list credential type");
1288
- }
1289
- statusListType = type.replace("Credential", "");
1290
- }
1291
1341
  const implementation = getStatusListImplementation(statusListType);
1292
1342
  const result = await implementation.toStatusListDetails({
1293
1343
  statusListPayload: credential,