@@ -4,7 +4,7 @@ import { join } from 'node:path'
4
4
import test from 'ava'
5
5
import { decode as nodeJwtDecode } from 'jsonwebtoken'
6
6
7
- import { Algorithm , sign , signSync , verifySync , verify } from '../index.js'
7
+ import { Algorithm , sign , signSync , verifySync , verify , decodeHeader } from '../index.js'
8
8
9
9
const getUtcTimestamp = ( ) => Math . floor ( new Date ( ) . getTime ( ) / 1000 )
10
10
const oneDayInSeconds = 86400
@@ -30,6 +30,20 @@ test('signSync and sign (async) should produce the same result', async (t) => {
30
30
t . truthy ( nodeJwtDecode ( resAsync ) )
31
31
} )
32
32
33
+ test ( 'should decode header' , async ( t ) => {
34
+ const data = {
35
+ id : 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6' ,
36
+ }
37
+ const claims = { data, exp : getUtcTimestamp ( ) + oneDayInSeconds }
38
+ const secretKey = 'secret'
39
+ const headers = { algorithm : Algorithm . HS384 }
40
+
41
+ const token = await sign ( claims , secretKey , headers )
42
+
43
+ const header = decodeHeader ( token )
44
+ t . is ( header . algorithm , Algorithm . HS384 )
45
+ } )
46
+
33
47
test ( 'verify should return the decoded claims' , async ( t ) => {
34
48
const data = {
35
49
id : 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6' ,
0 commit comments