Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Buffer and KeyObject as possible key types #98

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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