# @travetto/jwt

> JSON Web Token implementation

Latest version **5.1.0** (published 2025-01-26) · MIT license · 23 weekly downloads

## Install

```sh
npm install @travetto/jwt
pnpm add @travetto/jwt
yarn add @travetto/jwt
bun add @travetto/jwt
```

## Health

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

Positive: no vulnerabilities; high maintenance score.

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

Negative: stale; declining downloads.

## Facts

| | |
|---|---|
| Version | 5.1.0 |
| Published | 2025-01-26 |
| First published | 2018-10-20 |
| Weekly downloads | 23 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 13.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 23 |
| Author | Travetto Framework |
| Maintainers | arcsine |
| Keywords | jwt, travetto, typescript |

## Links

- npm: https://www.npmjs.com/package/@travetto/jwt
- Repository: https://github.com/travetto/travetto
- Homepage: https://travetto.io
- Issues: https://github.com/travetto/travetto/issues
- npm.io page: https://npm.io/package/@travetto/jwt

## Dependencies (3)

- [jws](https://npm.io/package/jws.md) ^4.0.0
- [@types/jws](https://npm.io/package/@types/jws.md) ^3.2.10
- [@travetto/runtime](https://npm.io/package/@travetto/runtime.md) ^5.1.0

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 5.1.0 (latest) — 2025-01-26
- 6.0.0-rc.0 (rc) — 2025-01-31
- 2.0.0-alpha.11 (alpha) — 2021-05-05
- 1.1.0-rc.0 (next) — 2020-09-20
- 1.0.0-beta.1 (beta) — 2019-08-16
- 5.0.16 — 2025-01-16
- 5.0.15 — 2025-01-16
- 5.0.14 — 2025-01-01
- 5.0.13 — 2024-11-16
- 5.0.12 — 2024-10-26
- 5.0.11 — 2024-10-20
- 5.0.10 — 2024-10-06
- 5.0.9 — 2024-10-06
- 5.0.8 — 2024-10-06
- 5.0.7 — 2024-09-30
- … 205 more at https://npm.io/package/@travetto/jwt/versions

## README

<!-- This file was generated by @travetto/doc and should not be modified directly -->
<!-- Please modify https://github.com/travetto/travetto/tree/main/module/jwt/DOC.tsx and execute "npx trv doc" to rebuild -->
# JWT

## JSON Web Token implementation

**Install: @travetto/jwt**
```bash
npm install @travetto/jwt

# or

yarn add @travetto/jwt
```

This module is a simple component to support [JWT](https://jwt.io/) signing and verification.  The framework provides a port of [node-jsonwebtoken](https://github.com/auth0/node-jsonwebtoken). The API has been streamlined, and is intended as a lower level component as a basis for other modules. 

The API exposes:

**Code: Signing Options**
```typescript
export interface SignOptions {
  /**
   * Key to use
   */
  key?: OrProm<KeyItem>;
  /**
   * Ignore issued
   */
  iatExclude?: boolean;
  /**
   * Algorithm
   */
  alg?: AlgType;
  /**
   * Header type
   */
  header?: {
    typ?: 'JWT';
  } & {
    [key: string]: string;
  };
  /**
   * Encoding for key
   */
  encoding?: string;
}
```

**Code: Verify Options**
```typescript
export type VerifyOptions = {
  /**
   * Clock starting point
   */
  clock?: {
    /**
     * Time to check against
     */
    timestamp?: number | Date;
    /**
     * Time tolerance
     */
    tolerance?: number;
  };
  /**
   * Ignore various checks
   */
  ignore?: {
    /**
     * Ignore expiration time
     */
    exp?: boolean;
    /**
     * Ignore not before timestamp
     */
    nbf?: boolean;
  };
  /**
   * Max age in seconds
   */
  maxAgeSec?: number;
  /**
   * Header
   */
  header?: Record<string, string>;
  /**
   * Encryption key
   */
  key?: OrProm<KeyItem | KeyItem[]>;
  /**
   * Encoding
   */
  encoding?: string;
  /**
   * Algorithms to use
   */
  alg?: AlgType | AlgType[];

  /**
   * Payload audience to check
   */
  payload?: {
    aud?: string | RegExp | (string | RegExp)[];
  } & PayloadCore;
};
```

**Code: API**
```typescript
export class JWTUtil {
  /**
   * Sign the payload and return a token
   */
  static async create<T extends Payload>(payload: T, options: SignOptions = {}): Promise<string>;
  /**
   * Read and return full object with signatures
   */
  static read<T extends Payload = Payload>(jwt: string): TypedSig<T>;
  /**
   * Rewrite a token with a simple transformation
   */
  static async rewrite<T extends Payload>(jwt: string, transformer: (o: T) => T, options: SignOptions = {}): Promise<string>;
  /**
   * Verify the token
   */
  static async verify<T>(jwt: string, options: VerifyOptions = {}): Promise<Payload & T>;
}
```

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