@vess-id/status-list 0.2.0 → 0.3.0

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
@@ -2,7 +2,7 @@
2
2
 
3
3
  var pako = require('pako');
4
4
  var jose = require('jose');
5
- var cbor = require('cbor');
5
+ var cborX = require('cbor-x');
6
6
  var crypto = require('crypto');
7
7
 
8
8
  function _interopNamespace(e) {
@@ -24,7 +24,6 @@ function _interopNamespace(e) {
24
24
  }
25
25
 
26
26
  var pako__namespace = /*#__PURE__*/_interopNamespace(pako);
27
- var cbor__namespace = /*#__PURE__*/_interopNamespace(cbor);
28
27
 
29
28
  // lib/types/errors.ts
30
29
  var StatusListError = class extends Error {
@@ -724,8 +723,8 @@ var ALGORITHM_MAP = {
724
723
  // EdDSA (Ed25519)
725
724
  };
726
725
  function signCOSE(payload, protectedHeader, privateKey) {
727
- const protectedHeaderEncoded = cbor__namespace.encode(protectedHeader);
728
- const sigStructure = cbor__namespace.encode([
726
+ const protectedHeaderEncoded = cborX.encode(protectedHeader);
727
+ const sigStructure = cborX.encode([
729
728
  "Signature1",
730
729
  // Context
731
730
  protectedHeaderEncoded,
@@ -748,22 +747,22 @@ function signCOSE(payload, protectedHeader, privateKey) {
748
747
  signature
749
748
  // Signature
750
749
  ];
751
- const tagged = new cbor__namespace.Tagged(COSE_SIGN1_TAG, coseSign1);
752
- return cbor__namespace.encode(tagged);
750
+ const tagged = new cborX.Tag(coseSign1, COSE_SIGN1_TAG);
751
+ return cborX.encode(tagged);
753
752
  }
754
753
  function verifyCOSE(coseSign1, publicKey) {
755
754
  try {
756
- const decoded = cbor__namespace.decode(coseSign1);
757
- if (!(decoded instanceof cbor__namespace.Tagged) || decoded.tag !== COSE_SIGN1_TAG) {
755
+ const decoded = cborX.decode(coseSign1);
756
+ if (!(decoded instanceof cborX.Tag) || decoded.tag !== COSE_SIGN1_TAG) {
758
757
  throw new InvalidTokenFormatError("Invalid COSE Sign1 structure: missing tag 18");
759
758
  }
760
759
  const [protectedHeaderEncoded, , payload, signature] = decoded.value;
761
- const protectedHeader = cbor__namespace.decode(protectedHeaderEncoded);
760
+ const protectedHeader = cborX.decode(protectedHeaderEncoded);
762
761
  const alg = protectedHeader.get(1);
763
762
  if (!alg) {
764
763
  throw new InvalidTokenFormatError("Missing algorithm in protected header");
765
764
  }
766
- const sigStructure = cbor__namespace.encode([
765
+ const sigStructure = cborX.encode([
767
766
  "Signature1",
768
767
  protectedHeaderEncoded,
769
768
  new Uint8Array(0),
@@ -935,11 +934,11 @@ function createCWTStatusListPayload(options) {
935
934
  return payload;
936
935
  }
937
936
  function encodeCWTPayload(payload) {
938
- return cbor__namespace.encode(payload);
937
+ return cborX.encode(payload);
939
938
  }
940
939
  function parseCWTStatusList(cwtBytes) {
941
940
  try {
942
- const payload = cbor__namespace.decode(cwtBytes);
941
+ const payload = cborX.decode(cwtBytes);
943
942
  validateCWTPayload(payload);
944
943
  const typedPayload = payload;
945
944
  const statusListClaim = typedPayload[CWT_CLAIMS.STATUS_LIST];
@@ -961,14 +960,14 @@ function parseCWTStatusList(cwtBytes) {
961
960
  function parseCWTStatusListSigned(cwtBytes, publicKey) {
962
961
  try {
963
962
  const payloadBytes = verifyCOSE(cwtBytes, publicKey);
964
- const payload = cbor__namespace.decode(payloadBytes);
963
+ const payload = cborX.decode(payloadBytes);
965
964
  validateCWTPayload(payload);
966
965
  const typedPayload = payload;
967
966
  const statusListClaim = typedPayload[CWT_CLAIMS.STATUS_LIST];
968
967
  const statusList = StatusList.decompressFromBytes(statusListClaim.lst, statusListClaim.bits);
969
- const decoded = cbor__namespace.decode(cwtBytes);
968
+ const decoded = cborX.decode(cwtBytes);
970
969
  const [protectedHeaderEncoded] = decoded.value;
971
- const protectedHeader = cbor__namespace.decode(protectedHeaderEncoded);
970
+ const protectedHeader = cborX.decode(protectedHeaderEncoded);
972
971
  return {
973
972
  protectedHeader,
974
973
  unprotectedHeader: /* @__PURE__ */ new Map(),
@@ -993,12 +992,12 @@ function signCWTStatusList(payload, privateKey, options) {
993
992
  if (kid) {
994
993
  protectedHeader.set(COSE_HEADERS.KID, kid);
995
994
  }
996
- const payloadBytes = cbor__namespace.encode(payload);
995
+ const payloadBytes = cborX.encode(payload);
997
996
  return signCOSE(payloadBytes, protectedHeader, privateKey);
998
997
  }
999
998
  function extractStatusListReferenceCBOR(credentialCBOR) {
1000
999
  try {
1001
- const credential = cbor__namespace.decode(credentialCBOR);
1000
+ const credential = cborX.decode(credentialCBOR);
1002
1001
  const status = credential.status || credential["status"];
1003
1002
  if (!status || typeof status !== "object") {
1004
1003
  throw new InvalidTokenFormatError("Missing status claim in credential");