Skip to content

Commit e378449

Browse files
committed
docs: update README.md
1 parent f508199 commit e378449

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

README.md

+20-12
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ $ npm install jsonwebtoken
3333
3434
> If `payload` is not a buffer or a string, it will be coerced into a string using `JSON.stringify`.
3535
36-
`secretOrPrivateKey` is a string (utf-8 encoded), buffer, object, or KeyObject containing either the secret for HMAC algorithms or the PEM
37-
encoded private key for RSA and ECDSA. In case of a private key with passphrase an object `{ key, passphrase }` can be used (based on [crypto documentation](https://nodejs.org/api/crypto.html#crypto_sign_sign_private_key_output_format)), in this case be sure you pass the `algorithm` option.
36+
`secretOrPrivateKey` is a [KeyObject] (preferred), string (utf-8 encoded), buffer, object, or any valid input to [crypto.createPrivateKey] or [crypto.createSecretKey] containing either the secret for HMAC algorithms or the private key for RSA, ECDSA, or EdDSA.
37+
3838
When signing with RSA algorithms the minimum modulus length is 2048 except when the allowInsecureKeySizes option is set to true. Private keys below this size will be rejected with an error.
3939

4040
`options`:
@@ -52,8 +52,8 @@ When signing with RSA algorithms the minimum modulus length is 2048 except when
5252
* `header`
5353
* `keyid`
5454
* `mutatePayload`: if true, the sign function will modify the payload object directly. This is useful if you need a raw reference to the payload after claims have been applied to it but before it has been encoded into a token.
55-
* `allowInsecureKeySizes`: if true allows private keys with a modulus below 2048 to be used for RSA
56-
* `allowInvalidAsymmetricKeyTypes`: if true, allows asymmetric keys which do not match the specified algorithm. This option is intended only for backwards compatability and should be avoided.
55+
* `allowInsecureKeySizes`: if true allows private keys with a modulus below 2048 to be used for RSA. This option is intended only for backwards compatibility and should be avoided.
56+
* `allowInvalidAsymmetricKeyTypes`: if true, allows asymmetric keys which do not match the specified algorithm. This option is intended only for backwards compatibility and should be avoided.
5757

5858

5959

@@ -133,8 +133,8 @@ jwt.sign({
133133
134134
`token` is the JsonWebToken string
135135

136-
`secretOrPublicKey` is a string (utf-8 encoded), buffer, or KeyObject containing either the secret for HMAC algorithms, or the PEM
137-
encoded public key for RSA and ECDSA.
136+
`secretOrPublicKey` is a [KeyObject] (preferred), string (utf-8 encoded), buffer, object, or any valid input to [crypto.createPublicKey] or [crypto.createSecretKey] containing either the secret for HMAC algorithms or the private key for RSA, ECDSA, or EdDSA.
137+
138138
If `jwt.verify` is called asynchronous, `secretOrPublicKey` can be a function that should fetch the secret or public key. See below for a detailed example
139139

140140
As mentioned in [this comment](https://github.com/auth0/node-jsonwebtoken/issues/208#issuecomment-231861138), there are other libraries that expect base64 encoded secrets (random bytes encoded using base64), if that is your case you can pass `Buffer.from(secret, 'base64')`, by doing this the secret will be decoded using base64 and the token verification will use the original random bytes.
@@ -144,9 +144,10 @@ As mentioned in [this comment](https://github.com/auth0/node-jsonwebtoken/issues
144144
* `algorithms`: List of strings with the names of the allowed algorithms. For instance, `["HS256", "HS384"]`.
145145
> If not specified a defaults will be used based on the type of key provided
146146
> * secret - ['HS256', 'HS384', 'HS512']
147-
> * rsa - ['RS256', 'RS384', 'RS512']
148-
> * ec - ['ES256', 'ES384', 'ES512']
149-
> * default - ['RS256', 'RS384', 'RS512']
147+
> * rsa - ['RS256', 'RS384', 'RS512', 'PS256', 'PS384', 'PS512']
148+
> * rsa-pss - ['PS256', 'PS384', 'PS512']
149+
> * ec - ['ES256', 'ES256K', 'ES384', 'ES512']
150+
> * ed25519, ed448 - ['EdDSA']
150151
* `audience`: if you want to check audience (`aud`), provide a value here. The audience can be checked against a string, a regular expression or a list of strings and/or regular expressions.
151152
> Eg: `"urn:foo"`, `/urn:f[o]{2}/`, `[/urn:f[o]{2}/, "urn:bar"]`
152153
* `complete`: return an object with the decoded `{ payload, header, signature }` instead of only the usual content of the payload.
@@ -160,7 +161,7 @@ As mentioned in [this comment](https://github.com/auth0/node-jsonwebtoken/issues
160161
> Eg: `1000`, `"2 days"`, `"10h"`, `"7d"`. A numeric value is interpreted as a seconds count. If you use a string be sure you provide the time units (days, hours, etc), otherwise milliseconds unit is used by default (`"120"` is equal to `"120ms"`).
161162
* `clockTimestamp`: the time in seconds that should be used as the current time for all necessary comparisons.
162163
* `nonce`: if you want to check `nonce` claim, provide a string value here. It is used on Open ID for the ID Tokens. ([Open ID implementation notes](https://openid.net/specs/openid-connect-core-1_0.html#NonceNotes))
163-
* `allowInvalidAsymmetricKeyTypes`: if true, allows asymmetric keys which do not match the specified algorithm. This option is intended only for backwards compatability and should be avoided.
164+
* `allowInvalidAsymmetricKeyTypes`: if true, allows asymmetric keys which do not match the specified algorithm. This option is intended only for backwards compatibility and should be avoided.
164165

165166
```js
166167
// verify a token symmetric - synchronous
@@ -352,9 +353,9 @@ jwt.verify(token, 'shhhhh', function(err, decoded) {
352353
```
353354

354355

355-
## Algorithms supported
356+
## Supported algorithms
356357

357-
Array of supported algorithms. The following algorithms are currently supported.
358+
The following algorithms from the [IANA registry](https://www.iana.org/assignments/jose/jose.xhtml#web-signature-encryption-algorithms) are supported.
358359

359360
| alg Parameter Value | Digital Signature or MAC Algorithm |
360361
|---------------------|------------------------------------------------------------------------|
@@ -368,8 +369,10 @@ Array of supported algorithms. The following algorithms are currently supported.
368369
| PS384 | RSASSA-PSS using SHA-384 hash algorithm (only node ^6.12.0 OR >=8.0.0) |
369370
| PS512 | RSASSA-PSS using SHA-512 hash algorithm (only node ^6.12.0 OR >=8.0.0) |
370371
| ES256 | ECDSA using P-256 curve and SHA-256 hash algorithm |
372+
| ES256K | ECDSA using secp256k1 curve and SHA-256 hash algorithm |
371373
| ES384 | ECDSA using P-384 curve and SHA-384 hash algorithm |
372374
| ES512 | ECDSA using P-521 curve and SHA-512 hash algorithm |
375+
| EdDSA | EdDSA using Ed25519 or Ed448 |
373376
| none | No digital signature or MAC value included |
374377

375378
## Refreshing JWTs
@@ -394,3 +397,8 @@ If you have found a bug or if you have a feature request, please report them at
394397
## License
395398

396399
This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info.
400+
401+
[crypto.createPublicKey]: https://nodejs.org/api/crypto.html#cryptocreatepublickeykey
402+
[crypto.createPrivateKey]: https://nodejs.org/api/crypto.html#cryptocreateprivatekeykey
403+
[crypto.createSecretKey]: https://nodejs.org/api/crypto.html#cryptocreatesecretkeykey-encoding
404+
[KeyObject]: https://nodejs.org/api/crypto.html#class-keyobject

0 commit comments

Comments
 (0)