@sphereon/ssi-sdk.vc-status-list 0.33.1-next.73 → 0.34.1-feature.SSISDK.17.bitstring.sl.2

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
@@ -61,7 +61,7 @@ var Status2021 = /* @__PURE__ */ function(Status20212) {
61
61
  }({});
62
62
 
63
63
  // src/functions.ts
64
- var import_ssi_types6 = require("@sphereon/ssi-types");
64
+ var import_ssi_types7 = require("@sphereon/ssi-types");
65
65
  var import_vc_status_list2 = require("@sphereon/vc-status-list");
66
66
 
67
67
  // src/utils.ts
@@ -108,8 +108,7 @@ var ValidProofTypeMap = /* @__PURE__ */ new Map([
108
108
  import_ssi_types.StatusListType.StatusList2021,
109
109
  [
110
110
  "jwt",
111
- "lds",
112
- "EthereumEip712Signature2021"
111
+ "lds"
113
112
  ]
114
113
  ],
115
114
  [
@@ -652,6 +651,9 @@ var OAuthStatusListImplementation = class {
652
651
  if (index < 0 || index >= statusList.statusList.length) {
653
652
  throw new Error("Status list index out of bounds");
654
653
  }
654
+ if (typeof value !== "number") {
655
+ throw new Error("Status list values should be of type number");
656
+ }
655
657
  statusList.setStatus(index, value);
656
658
  const { statusListCredential: signedCredential, encodedList } = await this.createSignedStatusList(proofFormat, context, statusList, issuer, id, expiresAt, keyRef);
657
659
  return {
@@ -708,7 +710,7 @@ var OAuthStatusListImplementation = class {
708
710
  const { statusList } = proofFormat === "jwt" ? decodeStatusListJWT(statusListCredential) : decodeStatusListCWT(statusListCredential);
709
711
  const index = typeof statusListIndex === "number" ? statusListIndex : parseInt(statusListIndex);
710
712
  if (index < 0 || index >= statusList.statusList.length) {
711
- throw new Error("Status list index out of bounds");
713
+ throw new Error(`Status list index out of bounds, has ${statusList.statusList.length} items, requested ${index}`);
712
714
  }
713
715
  return statusList.getStatus(index);
714
716
  }
@@ -755,7 +757,274 @@ var OAuthStatusListImplementation = class {
755
757
  };
756
758
 
757
759
  // src/impl/StatusListFactory.ts
760
+ var import_ssi_types6 = require("@sphereon/ssi-types");
761
+
762
+ // src/impl/BitstringStatusListImplementation.ts
758
763
  var import_ssi_types5 = require("@sphereon/ssi-types");
764
+ var import_vc_bitstring_status_list = require("@digitalbazaar/vc-bitstring-status-list");
765
+ var DEFAULT_LIST_LENGTH3 = 131072;
766
+ var DEFAULT_PROOF_FORMAT3 = "lds";
767
+ var DEFAULT_STATUS_SIZE = 1;
768
+ var DEFAULT_STATUS_PURPOSE = "revocation";
769
+ var BitstringStatusListImplementation = class {
770
+ static {
771
+ __name(this, "BitstringStatusListImplementation");
772
+ }
773
+ async createNewStatusList(args, context) {
774
+ if (!args.bitstringStatusList) {
775
+ throw new Error("BitstringStatusList options are required for type BitstringStatusList");
776
+ }
777
+ const length = args?.length ?? DEFAULT_LIST_LENGTH3;
778
+ const proofFormat = args?.proofFormat ?? DEFAULT_PROOF_FORMAT3;
779
+ assertValidProofType(import_ssi_types5.StatusListType.BitstringStatusList, proofFormat);
780
+ const veramoProofFormat = proofFormat;
781
+ const { issuer, id } = args;
782
+ const correlationId = getAssertedValue("correlationId", args.correlationId);
783
+ const { statusPurpose, statusSize, statusMessage, ttl } = args.bitstringStatusList;
784
+ const list = await (0, import_vc_bitstring_status_list.createList)({
785
+ length
786
+ });
787
+ const encodedList = await list.encode();
788
+ const statusListCredential = await this.createVerifiableCredential({
789
+ ...args,
790
+ encodedList,
791
+ proofFormat: veramoProofFormat,
792
+ statusPurpose: statusPurpose ?? DEFAULT_STATUS_PURPOSE,
793
+ statusSize: statusSize ?? DEFAULT_STATUS_SIZE,
794
+ statusMessage,
795
+ ttl
796
+ }, context);
797
+ return {
798
+ encodedList,
799
+ statusListCredential,
800
+ bitstringStatusList: {
801
+ statusPurpose: statusPurpose ?? DEFAULT_STATUS_PURPOSE,
802
+ ttl
803
+ },
804
+ length,
805
+ type: import_ssi_types5.StatusListType.BitstringStatusList,
806
+ proofFormat,
807
+ id,
808
+ correlationId,
809
+ issuer,
810
+ statuslistContentType: this.buildContentType(proofFormat)
811
+ };
812
+ }
813
+ async updateStatusListIndex(args, context) {
814
+ const credential = args.statusListCredential;
815
+ const uniform = import_ssi_types5.CredentialMapper.toUniformCredential(credential);
816
+ const { issuer, credentialSubject } = uniform;
817
+ const id = getAssertedValue("id", uniform.id);
818
+ const origEncodedList = getAssertedProperty("encodedList", credentialSubject);
819
+ const index = typeof args.statusListIndex === "number" ? args.statusListIndex : parseInt(args.statusListIndex);
820
+ const statusList = await (0, import_vc_bitstring_status_list.decodeList)({
821
+ encodedList: origEncodedList
822
+ });
823
+ statusList.setStatus(index, args.value != 0);
824
+ const encodedList = await statusList.encode();
825
+ const proofFormat = import_ssi_types5.CredentialMapper.detectDocumentType(credential) === import_ssi_types5.DocumentFormat.JWT ? "jwt" : "lds";
826
+ const credSubject = Array.isArray(credentialSubject) ? credentialSubject[0] : credentialSubject;
827
+ const statusPurpose = getAssertedProperty("statusPurpose", credSubject);
828
+ const validFrom = uniform.validFrom ? new Date(uniform.validFrom) : void 0;
829
+ const validUntil = uniform.validUntil ? new Date(uniform.validUntil) : void 0;
830
+ const ttl = credSubject.ttl;
831
+ const updatedCredential = await this.createVerifiableCredential({
832
+ ...args,
833
+ id,
834
+ issuer,
835
+ encodedList,
836
+ proofFormat,
837
+ statusPurpose,
838
+ ttl,
839
+ validFrom,
840
+ validUntil
841
+ }, context);
842
+ return {
843
+ statusListCredential: updatedCredential,
844
+ encodedList,
845
+ bitstringStatusList: {
846
+ statusPurpose,
847
+ validFrom,
848
+ validUntil,
849
+ ttl
850
+ },
851
+ length: statusList.length - 1,
852
+ type: import_ssi_types5.StatusListType.BitstringStatusList,
853
+ proofFormat,
854
+ id,
855
+ issuer,
856
+ statuslistContentType: this.buildContentType(proofFormat)
857
+ };
858
+ }
859
+ async updateStatusListFromEncodedList(args, context) {
860
+ if (!args.bitstringStatusList) {
861
+ throw new Error("bitstringStatusList options required for type BitstringStatusList");
862
+ }
863
+ const proofFormat = args?.proofFormat ?? DEFAULT_PROOF_FORMAT3;
864
+ assertValidProofType(import_ssi_types5.StatusListType.BitstringStatusList, proofFormat);
865
+ const veramoProofFormat = proofFormat;
866
+ const { issuer, id } = getAssertedValues(args);
867
+ const statusList = await (0, import_vc_bitstring_status_list.decodeList)({
868
+ encodedList: args.encodedList
869
+ });
870
+ const index = typeof args.statusListIndex === "number" ? args.statusListIndex : parseInt(args.statusListIndex);
871
+ statusList.setStatus(index, args.value);
872
+ const newEncodedList = await statusList.encode();
873
+ const { statusPurpose, statusSize, statusMessage, ttl, validFrom, validUntil } = args.bitstringStatusList;
874
+ const credential = await this.createVerifiableCredential({
875
+ id,
876
+ issuer,
877
+ encodedList: newEncodedList,
878
+ proofFormat: veramoProofFormat,
879
+ keyRef: args.keyRef,
880
+ statusPurpose,
881
+ statusSize,
882
+ statusMessage,
883
+ validFrom,
884
+ validUntil,
885
+ ttl
886
+ }, context);
887
+ return {
888
+ type: import_ssi_types5.StatusListType.BitstringStatusList,
889
+ statusListCredential: credential,
890
+ encodedList: newEncodedList,
891
+ bitstringStatusList: {
892
+ statusPurpose,
893
+ validFrom,
894
+ validUntil,
895
+ ttl
896
+ },
897
+ length: statusList.length,
898
+ proofFormat: args.proofFormat ?? "lds",
899
+ id,
900
+ issuer,
901
+ statuslistContentType: this.buildContentType(proofFormat)
902
+ };
903
+ }
904
+ async checkStatusIndex(args) {
905
+ const uniform = import_ssi_types5.CredentialMapper.toUniformCredential(args.statusListCredential);
906
+ const { credentialSubject } = uniform;
907
+ const encodedList = getAssertedProperty("encodedList", credentialSubject);
908
+ const subject = Array.isArray(credentialSubject) ? credentialSubject[0] : credentialSubject;
909
+ const messageList = subject.statusMessage;
910
+ const numIndex = typeof args.statusListIndex === "number" ? args.statusListIndex : parseInt(args.statusListIndex);
911
+ const hexIndex = `0x${numIndex.toString(16)}`;
912
+ const statusMessage = messageList.find((statMsg) => statMsg.status === hexIndex);
913
+ const statusList = await (0, import_vc_bitstring_status_list.decodeList)({
914
+ encodedList
915
+ });
916
+ if (statusList.length <= numIndex) {
917
+ throw new Error(`Status list index out of bounds, has ${messageList.length} messages, requested ${numIndex}`);
918
+ }
919
+ const value = statusList.getStatus(numIndex);
920
+ return {
921
+ index: numIndex,
922
+ status: hexIndex,
923
+ message: statusMessage?.message,
924
+ set: value
925
+ };
926
+ }
927
+ async toStatusListDetails(args) {
928
+ const { statusListPayload } = args;
929
+ const uniform = import_ssi_types5.CredentialMapper.toUniformCredential(statusListPayload);
930
+ const { issuer, credentialSubject } = uniform;
931
+ const id = getAssertedValue("id", uniform.id);
932
+ const encodedList = getAssertedProperty("encodedList", credentialSubject);
933
+ const proofFormat = import_ssi_types5.CredentialMapper.detectDocumentType(statusListPayload) === import_ssi_types5.DocumentFormat.JWT ? "jwt" : "lds";
934
+ const credSubject = Array.isArray(credentialSubject) ? credentialSubject[0] : credentialSubject;
935
+ const statusPurpose = getAssertedProperty("statusPurpose", credSubject);
936
+ const validFrom = uniform.validFrom ? new Date(uniform.validFrom) : void 0;
937
+ const validUntil = uniform.validUntil ? new Date(uniform.validUntil) : void 0;
938
+ const ttl = credSubject.ttl;
939
+ const list = await (0, import_vc_bitstring_status_list.decodeList)({
940
+ encodedList
941
+ });
942
+ return {
943
+ id,
944
+ encodedList,
945
+ issuer,
946
+ type: import_ssi_types5.StatusListType.BitstringStatusList,
947
+ proofFormat,
948
+ length: list.length,
949
+ statusListCredential: statusListPayload,
950
+ statuslistContentType: this.buildContentType(proofFormat),
951
+ bitstringStatusList: {
952
+ statusPurpose,
953
+ validFrom,
954
+ validUntil,
955
+ ttl
956
+ },
957
+ ...args.correlationId && {
958
+ correlationId: args.correlationId
959
+ },
960
+ ...args.driverType && {
961
+ driverType: args.driverType
962
+ }
963
+ };
964
+ }
965
+ async createVerifiableCredential(args, context) {
966
+ const identifier = await context.agent.identifierManagedGet({
967
+ identifier: typeof args.issuer === "string" ? args.issuer : args.issuer.id,
968
+ vmRelationship: "assertionMethod",
969
+ offlineWhenNoDIDRegistered: true
970
+ });
971
+ const credentialSubject = {
972
+ id: args.id,
973
+ type: "BitstringStatusList",
974
+ statusPurpose: args.statusPurpose,
975
+ encodedList: args.encodedList
976
+ };
977
+ if (args.statusSize && args.statusSize > 1) {
978
+ credentialSubject.statusSize = args.statusSize;
979
+ }
980
+ if (args.statusMessage) {
981
+ credentialSubject.statusMessage = args.statusMessage;
982
+ }
983
+ if (args.validFrom) {
984
+ credentialSubject.validFrom = args.validFrom;
985
+ }
986
+ if (args.validUntil) {
987
+ credentialSubject.validUntil = args.validUntil;
988
+ }
989
+ if (args.ttl) {
990
+ credentialSubject.ttl = args.ttl;
991
+ }
992
+ const credential = {
993
+ "@context": [
994
+ "https://www.w3.org/2018/credentials/v1",
995
+ "https://www.w3.org/ns/credentials/status/v1"
996
+ ],
997
+ id: args.id,
998
+ issuer: args.issuer,
999
+ type: [
1000
+ "VerifiableCredential",
1001
+ "BitstringStatusListCredential"
1002
+ ],
1003
+ credentialSubject
1004
+ };
1005
+ const verifiableCredential = await context.agent.createVerifiableCredential({
1006
+ credential,
1007
+ keyRef: args.keyRef ?? identifier.kmsKeyRef,
1008
+ proofFormat: args.proofFormat,
1009
+ fetchRemoteContexts: true
1010
+ });
1011
+ return import_ssi_types5.CredentialMapper.toWrappedVerifiableCredential(verifiableCredential).original;
1012
+ }
1013
+ buildContentType(proofFormat) {
1014
+ switch (proofFormat) {
1015
+ case "jwt":
1016
+ return `application/statuslist+jwt`;
1017
+ case "cbor":
1018
+ return `application/statuslist+cwt`;
1019
+ case "lds":
1020
+ return "application/statuslist+ld+json";
1021
+ default:
1022
+ throw Error(`Unsupported content type '${proofFormat}' for status lists`);
1023
+ }
1024
+ }
1025
+ };
1026
+
1027
+ // src/impl/StatusListFactory.ts
759
1028
  var StatusListFactory = class _StatusListFactory {
760
1029
  static {
761
1030
  __name(this, "StatusListFactory");
@@ -764,8 +1033,9 @@ var StatusListFactory = class _StatusListFactory {
764
1033
  implementations;
765
1034
  constructor() {
766
1035
  this.implementations = /* @__PURE__ */ new Map();
767
- this.implementations.set(import_ssi_types5.StatusListType.StatusList2021, new StatusList2021Implementation());
768
- this.implementations.set(import_ssi_types5.StatusListType.OAuthStatusList, new OAuthStatusListImplementation());
1036
+ this.implementations.set(import_ssi_types6.StatusListType.StatusList2021, new StatusList2021Implementation());
1037
+ this.implementations.set(import_ssi_types6.StatusListType.OAuthStatusList, new OAuthStatusListImplementation());
1038
+ this.implementations.set(import_ssi_types6.StatusListType.BitstringStatusList, new BitstringStatusListImplementation());
769
1039
  }
770
1040
  static getInstance() {
771
1041
  if (!_StatusListFactory.instance) {
@@ -838,7 +1108,7 @@ __name(vcLibCheckStatusFunction, "vcLibCheckStatusFunction");
838
1108
  async function checkStatusForCredential(args) {
839
1109
  const verifyStatusListCredential = args.verifyStatusListCredential ?? true;
840
1110
  const verifyMatchingIssuers = args.verifyMatchingIssuers ?? true;
841
- const uniform = import_ssi_types6.CredentialMapper.toUniformCredential(args.credential);
1111
+ const uniform = import_ssi_types7.CredentialMapper.toUniformCredential(args.credential);
842
1112
  if (!("credentialStatus" in uniform) || !uniform.credentialStatus) {
843
1113
  if (args.mandatoryCredentialStatus) {
844
1114
  const error = "No credential status object found in the Verifiable Credential and it is mandatory";
@@ -853,7 +1123,7 @@ async function checkStatusForCredential(args) {
853
1123
  };
854
1124
  }
855
1125
  if ("credentialStatus" in uniform && uniform.credentialStatus) {
856
- if (uniform.credentialStatus.type === "StatusList2021Entry") {
1126
+ if (uniform.credentialStatus.type === "StatusList2021Entry" || uniform.credentialStatus.type === "BitstringStatusListEntry") {
857
1127
  return (0, import_vc_status_list2.checkStatus)({
858
1128
  ...args,
859
1129
  verifyStatusListCredential,
@@ -904,19 +1174,19 @@ __name(updateStatusIndexFromStatusListCredential, "updateStatusIndexFromStatusLi
904
1174
  async function statusListCredentialToDetails(args) {
905
1175
  const credential = getAssertedValue("statusListCredential", args.statusListCredential);
906
1176
  let statusListType;
907
- const documentFormat = import_ssi_types6.CredentialMapper.detectDocumentType(credential);
908
- if (documentFormat === import_ssi_types6.DocumentFormat.JWT) {
1177
+ const documentFormat = import_ssi_types7.CredentialMapper.detectDocumentType(credential);
1178
+ if (documentFormat === import_ssi_types7.DocumentFormat.JWT) {
909
1179
  const [header] = credential.split(".");
910
1180
  const decodedHeader = JSON.parse(Buffer.from(header, "base64").toString());
911
1181
  if (decodedHeader.typ === "statuslist+jwt") {
912
- statusListType = import_ssi_types6.StatusListType.OAuthStatusList;
1182
+ statusListType = import_ssi_types7.StatusListType.OAuthStatusList;
913
1183
  }
914
- } else if (documentFormat === import_ssi_types6.DocumentFormat.MSO_MDOC) {
915
- statusListType = import_ssi_types6.StatusListType.OAuthStatusList;
1184
+ } else if (documentFormat === import_ssi_types7.DocumentFormat.MSO_MDOC) {
1185
+ statusListType = import_ssi_types7.StatusListType.OAuthStatusList;
916
1186
  }
917
1187
  if (!statusListType) {
918
- const uniform = import_ssi_types6.CredentialMapper.toUniformCredential(credential);
919
- const type = uniform.type.find((t) => t.includes("StatusList2021") || t.includes("OAuth2StatusList"));
1188
+ const uniform = import_ssi_types7.CredentialMapper.toUniformCredential(credential);
1189
+ const type = uniform.type.find((t) => t.includes("StatusList2021") || t.includes("OAuth2StatusList") || t.includes("BitstringStatusList"));
920
1190
  if (!type) {
921
1191
  throw new Error("Invalid status list credential type");
922
1192
  }
@@ -944,7 +1214,7 @@ async function statusList2021ToVerifiableCredential(args, context) {
944
1214
  offlineWhenNoDIDRegistered: true
945
1215
  });
946
1216
  const proofFormat = args?.proofFormat ?? "lds";
947
- assertValidProofType(import_ssi_types6.StatusListType.StatusList2021, proofFormat);
1217
+ assertValidProofType(import_ssi_types7.StatusListType.StatusList2021, proofFormat);
948
1218
  const veramoProofFormat = proofFormat;
949
1219
  const encodedList = getAssertedValue("encodedList", args.encodedList);
950
1220
  const statusPurpose = getAssertedValue("statusPurpose", args.statusPurpose);
@@ -973,7 +1243,7 @@ async function statusList2021ToVerifiableCredential(args, context) {
973
1243
  proofFormat: veramoProofFormat,
974
1244
  fetchRemoteContexts: true
975
1245
  });
976
- return import_ssi_types6.CredentialMapper.toWrappedVerifiableCredential(verifiableCredential).original;
1246
+ return import_ssi_types7.CredentialMapper.toWrappedVerifiableCredential(verifiableCredential).original;
977
1247
  }
978
1248
  __name(statusList2021ToVerifiableCredential, "statusList2021ToVerifiableCredential");
979
1249
  //# sourceMappingURL=index.cjs.map