Skip to content

Commit 7f22bbe

Browse files
authored
fix: use CWT tag per default (#28)
1 parent eae9cda commit 7f22bbe

File tree

5 files changed

+8
-10
lines changed

5 files changed

+8
-10
lines changed

examples/generate.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ async function main() {
77
'403697de87af64611c1d32a05dab0fe1fcb715a86ab435f1ec99192d79569388',
88
'hex'
99
)
10-
},
11-
expectCwtTag: true
10+
}
1211
});
1312
const base64encoded = await generator.generate(
1413
{

src/cat.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ describe('CAT', () => {
3232
),
3333
kid: 'Symmetric256'
3434
};
35-
await cat.mac(key, 'HS256', { addCwtTag: true });
35+
await cat.mac(key, 'HS256');
3636
expect(cat.raw).toBeDefined();
3737
const macHex = cat.raw?.toString('hex');
3838
const token = Buffer.from(macHex!, 'hex');

src/cat.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ export class CommonAccessToken {
310310
* Options
311311
*/
312312
opts?: {
313-
addCwtTag: boolean;
313+
noCwtTag: boolean;
314314
}
315315
): Promise<void> {
316316
const headers = {
@@ -320,7 +320,7 @@ export class CommonAccessToken {
320320
const recipient = {
321321
key: key.k
322322
};
323-
if (opts?.addCwtTag) {
323+
if (!opts?.noCwtTag) {
324324
const plaintext = cbor.encode(this.payload);
325325
const coseMessage = await cose.mac.create(
326326
headers,

src/index.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ export class CAT {
234234
throw new Error('Key not found');
235235
}
236236
await cat.mac({ k: key, kid: opts.kid }, opts.alg, {
237-
addCwtTag: this.expectCwtTag
237+
noCwtTag: !this.expectCwtTag
238238
});
239239
if (!cat.raw) {
240240
throw new Error('Failed to MAC token');
@@ -290,7 +290,7 @@ export class CAT {
290290
throw new Error('Key not found');
291291
}
292292
await cat.mac({ k: key, kid: opts.kid }, opts.alg, {
293-
addCwtTag: this.expectCwtTag
293+
noCwtTag: !this.expectCwtTag
294294
});
295295
if (!cat.raw) {
296296
throw new Error('Failed to MAC token');
@@ -324,7 +324,7 @@ export class CAT {
324324
throw new KeyNotFoundError();
325325
}
326326
await newCat.mac({ k: key, kid: opts.kid }, opts.alg, {
327-
addCwtTag: this.expectCwtTag
327+
noCwtTag: !this.expectCwtTag
328328
});
329329
if (!newCat.raw) {
330330
throw new Error('Failed to MAC token');

src/validators/http.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,7 @@ export class HttpValidator {
386386
}
387387
await newCat.mac(
388388
{ kid: keyid, k: this.keys[keyid] },
389-
this.opts.alg || 'HS256',
390-
{ addCwtTag: true }
389+
this.opts.alg || 'HS256'
391390
);
392391
const newToken = toBase64NoPadding(newCat.raw!);
393392
const encodedToken = encodeURIComponent(newToken!);

0 commit comments

Comments
 (0)