@@ -4,7 +4,7 @@ import { join } from 'node:path'
44import test from 'ava'
55import { decode as nodeJwtDecode } from 'jsonwebtoken'
66
7- import { Algorithm , sign , signSync , verifySync , verify } from '../index.js'
7+ import { Algorithm , sign , signSync , verifySync , verify , decodeHeader } from '../index.js'
88
99const getUtcTimestamp = ( ) => Math . floor ( new Date ( ) . getTime ( ) / 1000 )
1010const oneDayInSeconds = 86400
@@ -30,6 +30,20 @@ test('signSync and sign (async) should produce the same result', async (t) => {
3030 t . truthy ( nodeJwtDecode ( resAsync ) )
3131} )
3232
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+
3347test ( 'verify should return the decoded claims' , async ( t ) => {
3448 const data = {
3549 id : 'f81d4fae-7dec-11d0-a765-00a0c91e6bf6' ,
0 commit comments