Skip to content

Commit

Permalink
fix: add type to support ES256 with passphrase in TypeScript (#247)
Browse files Browse the repository at this point in the history
* test: add test for ES256 with passphrase

* fix: add new type to support ES256 with passphrase
  • Loading branch information
yaoandy107 authored Jul 13, 2022
1 parent e047fef commit 6fad154
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion jwt.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export type UserType = FastifyJWT extends { user: infer T }

export type TokenOrHeader = JwtHeader | { header: JwtHeader; payload: any }

export type Secret = string | Buffer | KeyFetcher
export type Secret = string | Buffer | KeyFetcher | { key: Secret; passphrase: string }
| ((request: fastify.FastifyRequest, tokenOrHeader: TokenOrHeader, cb: (e: Error | null, secret: string | Buffer | undefined) => void) => void)
| ((request: fastify.FastifyRequest, tokenOrHeader: TokenOrHeader) => Promise<string | Buffer>)

Expand Down
11 changes: 11 additions & 0 deletions test/types/jwt.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ Object.values(secretOptions).forEach((value) => {

app.register(fastifyJwt, {...jwtOptions, trusted: () => Promise.resolve(false || '' || Buffer.from('foo')) })

app.register(fastifyJwt, {
secret: {
private: {
key: 'privateKey',
passphrase: 'super secret passphrase',
},
public: 'publicKey',
},
sign: { algorithm: 'ES256' },
})

// expect jwt and its subsequent methods have merged with the fastify instance
expectAssignable<object>(app.jwt)
expectAssignable<Function>(app.jwt.sign)
Expand Down

0 comments on commit 6fad154

Please sign in to comment.