@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 +16 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -16
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as pako from 'pako';
|
|
2
2
|
import { SignJWT, jwtVerify } from 'jose';
|
|
3
|
-
import
|
|
3
|
+
import { encode, Tag, decode } from 'cbor-x';
|
|
4
4
|
import { createSign, createVerify } from 'crypto';
|
|
5
5
|
|
|
6
6
|
// lib/types/errors.ts
|
|
@@ -701,8 +701,8 @@ var ALGORITHM_MAP = {
|
|
|
701
701
|
// EdDSA (Ed25519)
|
|
702
702
|
};
|
|
703
703
|
function signCOSE(payload, protectedHeader, privateKey) {
|
|
704
|
-
const protectedHeaderEncoded =
|
|
705
|
-
const sigStructure =
|
|
704
|
+
const protectedHeaderEncoded = encode(protectedHeader);
|
|
705
|
+
const sigStructure = encode([
|
|
706
706
|
"Signature1",
|
|
707
707
|
// Context
|
|
708
708
|
protectedHeaderEncoded,
|
|
@@ -725,22 +725,22 @@ function signCOSE(payload, protectedHeader, privateKey) {
|
|
|
725
725
|
signature
|
|
726
726
|
// Signature
|
|
727
727
|
];
|
|
728
|
-
const tagged = new
|
|
729
|
-
return
|
|
728
|
+
const tagged = new Tag(coseSign1, COSE_SIGN1_TAG);
|
|
729
|
+
return encode(tagged);
|
|
730
730
|
}
|
|
731
731
|
function verifyCOSE(coseSign1, publicKey) {
|
|
732
732
|
try {
|
|
733
|
-
const decoded =
|
|
734
|
-
if (!(decoded instanceof
|
|
733
|
+
const decoded = decode(coseSign1);
|
|
734
|
+
if (!(decoded instanceof Tag) || decoded.tag !== COSE_SIGN1_TAG) {
|
|
735
735
|
throw new InvalidTokenFormatError("Invalid COSE Sign1 structure: missing tag 18");
|
|
736
736
|
}
|
|
737
737
|
const [protectedHeaderEncoded, , payload, signature] = decoded.value;
|
|
738
|
-
const protectedHeader =
|
|
738
|
+
const protectedHeader = decode(protectedHeaderEncoded);
|
|
739
739
|
const alg = protectedHeader.get(1);
|
|
740
740
|
if (!alg) {
|
|
741
741
|
throw new InvalidTokenFormatError("Missing algorithm in protected header");
|
|
742
742
|
}
|
|
743
|
-
const sigStructure =
|
|
743
|
+
const sigStructure = encode([
|
|
744
744
|
"Signature1",
|
|
745
745
|
protectedHeaderEncoded,
|
|
746
746
|
new Uint8Array(0),
|
|
@@ -912,11 +912,11 @@ function createCWTStatusListPayload(options) {
|
|
|
912
912
|
return payload;
|
|
913
913
|
}
|
|
914
914
|
function encodeCWTPayload(payload) {
|
|
915
|
-
return
|
|
915
|
+
return encode(payload);
|
|
916
916
|
}
|
|
917
917
|
function parseCWTStatusList(cwtBytes) {
|
|
918
918
|
try {
|
|
919
|
-
const payload =
|
|
919
|
+
const payload = decode(cwtBytes);
|
|
920
920
|
validateCWTPayload(payload);
|
|
921
921
|
const typedPayload = payload;
|
|
922
922
|
const statusListClaim = typedPayload[CWT_CLAIMS.STATUS_LIST];
|
|
@@ -938,14 +938,14 @@ function parseCWTStatusList(cwtBytes) {
|
|
|
938
938
|
function parseCWTStatusListSigned(cwtBytes, publicKey) {
|
|
939
939
|
try {
|
|
940
940
|
const payloadBytes = verifyCOSE(cwtBytes, publicKey);
|
|
941
|
-
const payload =
|
|
941
|
+
const payload = decode(payloadBytes);
|
|
942
942
|
validateCWTPayload(payload);
|
|
943
943
|
const typedPayload = payload;
|
|
944
944
|
const statusListClaim = typedPayload[CWT_CLAIMS.STATUS_LIST];
|
|
945
945
|
const statusList = StatusList.decompressFromBytes(statusListClaim.lst, statusListClaim.bits);
|
|
946
|
-
const decoded =
|
|
946
|
+
const decoded = decode(cwtBytes);
|
|
947
947
|
const [protectedHeaderEncoded] = decoded.value;
|
|
948
|
-
const protectedHeader =
|
|
948
|
+
const protectedHeader = decode(protectedHeaderEncoded);
|
|
949
949
|
return {
|
|
950
950
|
protectedHeader,
|
|
951
951
|
unprotectedHeader: /* @__PURE__ */ new Map(),
|
|
@@ -970,12 +970,12 @@ function signCWTStatusList(payload, privateKey, options) {
|
|
|
970
970
|
if (kid) {
|
|
971
971
|
protectedHeader.set(COSE_HEADERS.KID, kid);
|
|
972
972
|
}
|
|
973
|
-
const payloadBytes =
|
|
973
|
+
const payloadBytes = encode(payload);
|
|
974
974
|
return signCOSE(payloadBytes, protectedHeader, privateKey);
|
|
975
975
|
}
|
|
976
976
|
function extractStatusListReferenceCBOR(credentialCBOR) {
|
|
977
977
|
try {
|
|
978
|
-
const credential =
|
|
978
|
+
const credential = decode(credentialCBOR);
|
|
979
979
|
const status = credential.status || credential["status"];
|
|
980
980
|
if (!status || typeof status !== "object") {
|
|
981
981
|
throw new InvalidTokenFormatError("Missing status claim in credential");
|