# @o.mhadhbi/jsonwebtoken

> This version supports jwt signed using ES256K algorithm and ethereum keys or sjcl keys.

Latest version **8.4.0** (published 2021-10-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @o.mhadhbi/jsonwebtoken
pnpm add @o.mhadhbi/jsonwebtoken
yarn add @o.mhadhbi/jsonwebtoken
bun add @o.mhadhbi/jsonwebtoken
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: no vulnerabilities; popular repo.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 8.4.0 |
| Published | 2021-10-01 |
| First published | 2021-10-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=4 |
| Dependencies | 11 |
| Unpacked size | 67.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 18195 |
| Author | auth0 |
| Maintainers | o.mhadhbi |
| Keywords | jwt |

## Links

- npm: https://www.npmjs.com/package/@o.mhadhbi/jsonwebtoken
- Repository: https://github.com/auth0/node-jsonwebtoken
- Homepage: https://github.com/auth0/node-jsonwebtoken#readme
- Issues: https://github.com/auth0/node-jsonwebtoken/issues
- npm.io page: https://npm.io/package/@o.mhadhbi/jsonwebtoken

## Dependencies (11)

- [ms](https://npm.io/package/ms.md) ^2.1.1
- [jws](https://npm.io/package/jws.md) ^3.2.2
- [semver](https://npm.io/package/semver.md) ^5.6.0
- [base64-url](https://npm.io/package/base64-url.md) ^2.2.0
- [lodash.once](https://npm.io/package/lodash.once.md) ^4.0.0
- [lodash.includes](https://npm.io/package/lodash.includes.md) ^4.3.0
- [lodash.isnumber](https://npm.io/package/lodash.isnumber.md) ^3.0.3
- [lodash.isstring](https://npm.io/package/lodash.isstring.md) ^4.0.1
- [lodash.isboolean](https://npm.io/package/lodash.isboolean.md) ^3.0.3
- [lodash.isinteger](https://npm.io/package/lodash.isinteger.md) ^4.0.4
- [lodash.isplainobject](https://npm.io/package/lodash.isplainobject.md) ^4.0.6

## Alternatives

- [@clerk/clerk-expo](https://npm.io/package/@clerk/clerk-expo.md) — 133.6K weekly downloads
- [@pothos/plugin-authz](https://npm.io/package/@pothos/plugin-authz.md) — 12.4K weekly downloads
- [@bounded-sh/client](https://npm.io/package/@bounded-sh/client.md) — 3.2K weekly downloads
- [@oxyhq/services](https://npm.io/package/@oxyhq/services.md) — 2.3K weekly downloads
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads

## Recent versions

- 8.4.0 (latest) — 2021-10-01

## README

# jsonwebtoken

This is a fork of [node-jsonwebtoken](https://github.com/civicteam/node-jsonwebtoken) branch f9ba002 (version: 8.4.0).This version supports jwt signed using ES256K algorithm and ethereum keys or sjcl keys.

# Install

```bash
$ npm install  jsonwebtoken@npm:@o.mhadhbi/jsonwebtoken
```

To override the original jsonwebtoken package but preserve all names.

# Usage

If you are going to use ES256K algorithm, you have to provide an implementation of sign and verify functions.

Note: If you just want to sign and verify jwt using ES256K algorithm and ethereum keys, you can directly use [jsontokens](https://www.npmjs.com/package/jsontokens).

Example 1 with Ethereum public key:

```
//import { TokenVerifier } from 'jsontokens';

{
      jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
      secretOrKey: config.ethereumPublicKey`,
      jsonWebTokenOptions: {
        cryptoManager: {
          verify: (jwt: string, ethereumPublicKey: string, algorithm: string) => {
            return new TokenVerifier(algorithm, ethereumPublicKey).verify(jwt);
          },
        },
        keyName: 'Ethereum', //must be 'Ethereum'
      },
    }
```

Example 2 with sjcl keys:

```
//sjcl = require('sjcl')

let cryptoManager;
cryptoManager.keys['keyname'] = sjcl.ecc.ecdsa.generateKeys(sjcl.ecc.curves.k256);
cryptoManager.verify = (keyname, hash, signature) =>  {
  if(!cryptoManager.keys['keyname']) {
    throw new Error('Key not found');
  }
  const pair = cryptoManager.keys[keyname];
  return pair.pub.verify(sjcl.codec.hex.toBits(hash), sjcl.codec.hex.toBits(signature));
}
```

## Algorithms supported

Array of supported algorithms. The following algorithms are currently supported.

| alg Parameter Value | Digital Signature or MAC Algorithm                                     |
| ------------------- | ---------------------------------------------------------------------- |
| HS256               | HMAC using SHA-256 hash algorithm                                      |
| HS384               | HMAC using SHA-384 hash algorithm                                      |
| HS512               | HMAC using SHA-512 hash algorithm                                      |
| RS256               | RSASSA-PKCS1-v1_5 using SHA-256 hash algorithm                         |
| RS384               | RSASSA-PKCS1-v1_5 using SHA-384 hash algorithm                         |
| RS512               | RSASSA-PKCS1-v1_5 using SHA-512 hash algorithm                         |
| PS256               | RSASSA-PSS using SHA-256 hash algorithm (only node ^6.12.0 OR >=8.0.0) |
| PS384               | RSASSA-PSS using SHA-384 hash algorithm (only node ^6.12.0 OR >=8.0.0) |
| PS512               | RSASSA-PSS using SHA-512 hash algorithm (only node ^6.12.0 OR >=8.0.0) |
| ES256               | ECDSA using P-256 curve and SHA-256 hash algorithm                     |
| ES256k              | ECDSA using SECP256K1 curve (\*)                                       |
| ES384               | ECDSA using P-384 curve and SHA-384 hash algorithm                     |
| ES512               | ECDSA using P-521 curve and SHA-512 hash algorithm                     |
| none                | No digital signature or MAC value included                             |

---
_Source: https://npm.io/package/@o.mhadhbi/jsonwebtoken · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
