Skip to content

Conversation

@davidje13
Copy link

Fixes #97

This adds Buffer and KeyObject as possible parameter types for key.

decode gets multiple overloads to detect when the branch

if (!algorithm && /BEGIN( RSA)? PUBLIC KEY/.test(key.toString())) {
is triggered (if it is triggered, the key must be a string or Buffer; otherwise it can also be a KeyObject)

If that check were updated to be KeyObject-aware (see KeyObject.asymmetricKeyType), the decode types could be simplified to a single declaration:

export function decode(token: string, key: KeyLike, noVerify?: boolean, algorithm?: TAlgorithm): any;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update types to allow Buffer as key argument

1 participant