Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/cat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,16 @@
* Common Access Token Claims
*/
export type CommonAccessTokenClaims = {
[key: string]: string | number | Map<number | string, any>;

Check warning on line 154 in src/cat.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
};
export type CommonAccessTokenDict = {
[key: string]: string | number | { [key: string]: any };

Check warning on line 157 in src/cat.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
};
export type CommonAccessTokenValue =
| string
| number
| Buffer
| Map<number | string, any>;

Check warning on line 163 in src/cat.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type

/**
* CWT Encryption Key
Expand Down Expand Up @@ -214,7 +214,7 @@
if (key === claimsToLabels['catu'] && !(dict[param] instanceof Map)) {
map.set(
key,
CommonAccessTokenUri.fromDictTags(dict[param] as any).payload

Check warning on line 217 in src/cat.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
);
} else if (
key === claimsToLabels['catr'] &&
Expand Down Expand Up @@ -331,8 +331,8 @@
const recipient = {
key: key.k
};
const encoder = new cbor.Encoder({ mapsAsObjects: false });
if (!opts?.noCwtTag) {
const encoder = new cbor.Encoder({ mapsAsObjects: false });
const plaintext = encoder.encode(this.payload);
const coseMessage = await cose.mac.create(
headers,
Expand All @@ -346,7 +346,7 @@
Log(cwtTag, { depth: null });
this.data = encoder.encode(cwtTag);
} else {
const plaintext = cbor.encode(this.payload).toString('hex');
const plaintext = encoder.encode(this.payload).toString('hex');
this.data = await cose.mac.create(headers, plaintext, recipient);
}
this.kid = key.kid;
Expand All @@ -369,7 +369,8 @@
throw new Error('Expected CWT tag');
}
if (coseMessage.tag === CWT_TAG) {
const cborCoseMessage = cbor.encode(coseMessage.value);
const encoder = new cbor.Encoder({ mapsAsObjects: false });
const cborCoseMessage = encoder.encode(coseMessage.value);
Log({
kid: key.kid,
key: key.k.toString('hex')
Expand All @@ -387,7 +388,8 @@
}

public async sign(key: CWTSigningKey, alg: string): Promise<void> {
const plaintext = cbor.encode(this.payload).toString('hex');
const encoder = new cbor.Encoder({ mapsAsObjects: false });
const plaintext = encoder.encode(this.payload).toString('hex');
const headers = {
p: { alg: alg },
u: { kid: key.kid }
Expand All @@ -403,7 +405,10 @@
key: CWTVerifierKey
): Promise<CommonAccessToken> {
const buf = await cose.sign.verify(token, { key: key });
this.payload = await cbor.decode(Buffer.from(buf.toString('hex'), 'hex'));
const decoder = new cbor.Decoder({ mapsAsObjects: false });
this.payload = await decoder.decode(
Buffer.from(buf.toString('hex'), 'hex')
);
return this;
}

Expand Down
Loading