Skip to content
Merged
Show file tree
Hide file tree
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
3 changes: 1 addition & 2 deletions examples/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ async function main() {
'403697de87af64611c1d32a05dab0fe1fcb715a86ab435f1ec99192d79569388',
'hex'
)
},
expectCwtTag: true
}
});
const base64encoded = await generator.generate(
{
Expand Down
2 changes: 1 addition & 1 deletion src/cat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
),
kid: 'Symmetric256'
};
await cat.mac(key, 'HS256', { addCwtTag: true });
await cat.mac(key, 'HS256');
expect(cat.raw).toBeDefined();
const macHex = cat.raw?.toString('hex');
const token = Buffer.from(macHex!, 'hex');

Check warning on line 38 in src/cat.test.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion
const newCat = new CommonAccessToken({});
await newCat.parse(token, key, { expectCwtTag: true });
expect(newCat.claims).toEqual(claims);
Expand All @@ -61,7 +61,7 @@
};
await cat.sign(signKey, 'ES256');
const signedHex = cat.raw?.toString('hex');
const token = Buffer.from(signedHex!, 'hex');

Check warning on line 64 in src/cat.test.ts

View workflow job for this annotation

GitHub Actions / lint

Forbidden non-null assertion
const verifyKey = {
x: Buffer.from(
'143329cce7868e416927599cf65a34f3ce2ffda55a7eca69ed8919a394d42f0f',
Expand Down
4 changes: 2 additions & 2 deletions src/cat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,16 +147,16 @@
* Common Access Token Claims
*/
export type CommonAccessTokenClaims = {
[key: string]: string | number | Map<number | string, any>;

Check warning on line 150 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 153 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 159 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 @@ -208,14 +208,14 @@
for (const param in dict) {
const key = claimsToLabels[param] ? claimsToLabels[param] : parseInt(param);
if (key === claimsToLabels['catu'] && !(dict[param] instanceof Map)) {
map.set(key, CommonAccessTokenUri.fromDict(dict[param] as any).payload);

Check warning on line 211 in src/cat.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
} else if (
key === claimsToLabels['catr'] &&
!(dict[param] instanceof Map)
) {
map.set(
key,
CommonAccessTokenRenewal.fromDict(dict[param] as any).payload

Check warning on line 218 in src/cat.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
);
} else if (
key === claimsToLabels['cath'] &&
Expand All @@ -223,7 +223,7 @@
) {
map.set(
key,
CommonAccessTokenHeader.fromDict(dict[param] as any).payload

Check warning on line 226 in src/cat.ts

View workflow job for this annotation

GitHub Actions / lint

Unexpected any. Specify a different type
);
} else if (
key === claimsToLabels['catif'] &&
Expand Down Expand Up @@ -310,7 +310,7 @@
* Options
*/
opts?: {
addCwtTag: boolean;
noCwtTag: boolean;
}
): Promise<void> {
const headers = {
Expand All @@ -320,7 +320,7 @@
const recipient = {
key: key.k
};
if (opts?.addCwtTag) {
if (!opts?.noCwtTag) {
const plaintext = cbor.encode(this.payload);
const coseMessage = await cose.mac.create(
headers,
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class CAT {
throw new Error('Key not found');
}
await cat.mac({ k: key, kid: opts.kid }, opts.alg, {
addCwtTag: this.expectCwtTag
noCwtTag: !this.expectCwtTag
});
if (!cat.raw) {
throw new Error('Failed to MAC token');
Expand Down Expand Up @@ -290,7 +290,7 @@ export class CAT {
throw new Error('Key not found');
}
await cat.mac({ k: key, kid: opts.kid }, opts.alg, {
addCwtTag: this.expectCwtTag
noCwtTag: !this.expectCwtTag
});
if (!cat.raw) {
throw new Error('Failed to MAC token');
Expand Down Expand Up @@ -324,7 +324,7 @@ export class CAT {
throw new KeyNotFoundError();
}
await newCat.mac({ k: key, kid: opts.kid }, opts.alg, {
addCwtTag: this.expectCwtTag
noCwtTag: !this.expectCwtTag
});
if (!newCat.raw) {
throw new Error('Failed to MAC token');
Expand Down
3 changes: 1 addition & 2 deletions src/validators/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,8 +386,7 @@ export class HttpValidator {
}
await newCat.mac(
{ kid: keyid, k: this.keys[keyid] },
this.opts.alg || 'HS256',
{ addCwtTag: true }
this.opts.alg || 'HS256'
);
const newToken = toBase64NoPadding(newCat.raw!);
const encodedToken = encodeURIComponent(newToken!);
Expand Down
Loading