Skip to content

Commit 8ed95a2

Browse files
committed
Use more specific type constraints for stronger type checks
1 parent d69a290 commit 8ed95a2

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/JwtHandler.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export type PrivkeyData = { key: string, passphrase: string, alg: string } | und
1414
export type PubkeyResolver = (keyId: string) => PubkeyData | Promise<PubkeyData>
1515
export type PrivkeyResolver = (keyId: string) => PrivkeyData | Promise<PrivkeyData>
1616

17-
type JwtVerifyAsync = (token: string, publicKey: string, options?: jwt.VerifyOptions) => Promise<object | string>
18-
type JwtSignAsync = (payload: object, privateKey: {}, options?: jwt.SignOptions) => Promise<string>
17+
type JwtVerifyAsync = (token: string, publicKey: string | Buffer, options?: jwt.VerifyOptions) => Promise<object | string>
18+
type JwtSignAsync = (payload: string | Buffer | object, privateKey: {}, options?: jwt.SignOptions) => Promise<string>
1919

2020
shim() // util.promisify shim
2121

@@ -66,7 +66,7 @@ export class JwtHandler {
6666
* @param {Object} options Validation options (jsonwebtoken module options)
6767
* @return {Promise<Object, JsonWebTokenError>} Promise to the JWT body
6868
*/
69-
public async verify(jwtRaw: string, options?: jwt.VerifyOptions): Promise<string | object> {
69+
public async verify(jwtRaw: string, options?: jwt.VerifyOptions): Promise<string | { [key: string]: any }> {
7070
if (!jwtRaw) {
7171
throw new jwt.JsonWebTokenError("Empty JWT")
7272
}
@@ -90,7 +90,7 @@ export class JwtHandler {
9090
* @param {string} keyId The ID of the signing key
9191
* @return {Promise<Object, JsonWebTokenError>} Promise to the JWT body
9292
*/
93-
public async create(tokenBody: object, keyId: string): Promise<string> {
93+
public async create(tokenBody: string | Buffer | { [key: string]: any }, keyId: string): Promise<string> {
9494
debug("create, key id: " + keyId)
9595
if (this.privkeyResolver) {
9696
const signingKey = await this.privkeyResolver(keyId)

0 commit comments

Comments
 (0)