Skip to content

sovrin/jted

Repository files navigation

jted

npm version types size coverage vulnerabilities dependencies devDependencies License

just JWT en-/decoding

Installation

$ npm i jted

Usage

import {encode} from 'jted';

const payload = {
    foo: 'bar';
    user: 'John Doe',
    role: 'moderator'
};

const key = 'change me to a very secure key';

// create token with payload and key
const token = encode(payload, key);

API

encode(payload: Payload, key: string, algorithm: Algorithm = 'sha512', options?: Options): string

Create a JWT via the payload, key, algorithm and optional options.


decode(token: string, key: string, algorithm: Algorithm = null, validate: boolean = true): Payload

Retrieve the payload by decoding token with key and algorithm.


verify(input: string, key: string, algorithm: Algorithm, signature: string): boolean

Verify if provided token is legit.


Supported algorithms

  • sha256
  • sha384
  • sha512
  • RSA-SHA256

Todo

  • check nodejs support for other algorithms

Licence

Apache-2.0 License, see LICENSE