# swa-token

> The "SWA" token is similar to JWT token but it just shorter.

Latest version **2.0.2** (published 2022-07-25) · MPL license · 0 weekly downloads

## Install

```sh
npm install swa-token
pnpm add swa-token
yarn add swa-token
bun add swa-token
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2022-07-25 |
| First published | 2022-04-17 |
| Weekly downloads | 0 |
| License | MPL |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 26.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | alexzvn |
| Maintainers | alexzvn |
| Keywords | web token, token, short token, short web app token, swa-token |

## Links

- npm: https://www.npmjs.com/package/swa-token
- Homepage: https://github.com/alexzvn/swa-token#readme
- Issues: https://github.com/alexzvn/swa-token/issues
- npm.io page: https://npm.io/package/swa-token

## Recent versions

- 2.0.2 (latest) — 2022-07-25
- 2.0.1 — 2022-04-20
- 2.0.0 — 2022-04-19
- 1.0.1 — 2022-04-17
- 1.0.0 — 2022-04-17

## README

# Short web application token
The "SWA" token is similar to JWT token but it just shorter.

<img width="1083" alt="image" src="https://user-images.githubusercontent.com/41188285/164160359-cbdb789d-2f31-497e-95e6-83385a772c83.png">


## Install

```bash
# npm users
npm i swa-token

# yarn users
yarn add swa-token
```
## How to use

1. Create SWAT instance

```ts
import SWAT from 'swa-token'

const swat = createSWAT('Your-secret-key')
```

2. Issue new token

```ts
swat.create('1', 'user')
```

3. Verify a token

```ts
swat.verify(token)
```

4. Get token info

```ts
swat.parse(token)
```

5. Change to difference signature provider

```ts
// By default SWAT use HS256 to create signature
// Bellow is example to change HS512 algo
swat.use('HS512')
```

6. Custom signature provider

```ts
swat.use('YourAlgo', {
  sign: (data: string) => 'signature',
  verify: (data: string, signature: string) => true || false
})
```

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