Skip to content

Add Buffer and KeyObject as possible key types#98

Open
davidje13 wants to merge 1 commit intohokaccha:masterfrom
davidje13:patch-1
Open

Add Buffer and KeyObject as possible key types#98
davidje13 wants to merge 1 commit intohokaccha:masterfrom
davidje13:patch-1

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

Comments