# siws

> ## Install

Latest version **1.0.7** (published 2022-03-08) · ISC license · 0 weekly downloads

## Install

```sh
npm install siws
pnpm add siws
yarn add siws
bun add siws
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.7 |
| Published | 2022-03-08 |
| First published | 2022-02-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 3.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | pbtripletree |

## Links

- npm: https://www.npmjs.com/package/siws
- Repository: https://github.com/pbtripletree/siws
- Homepage: https://github.com/pbtripletree/siws#readme
- Issues: https://github.com/pbtripletree/siws/issues
- npm.io page: https://npm.io/package/siws

## Dependencies (2)

- [bs58](https://npm.io/package/bs58.md) ^5.0.0
- [tweetnacl](https://npm.io/package/tweetnacl.md) ^1.0.3

## Recent versions

- 1.0.7 (latest) — 2022-03-08
- 1.0.6 — 2022-02-28
- 1.0.5 — 2022-02-23
- 1.0.4 — 2022-02-23
- 1.0.3 — 2022-02-18
- 1.0.2 — 2022-02-18
- 1.0.1 — 2022-02-18
- 1.0.0 — 2022-02-18

## README

# Usage

## Install

```
npm i siws
```

## Client

#### 1. Import

```
import { SiwsMessage } from "siws";
```

#### 2. Create message

```
const message = new SiwsMessage({
  domain: window.location.host,
  address: walletAddress,
  statement: "Use SIWS to authenticate",
});
```

#### 3. Prepare message for signing

```
const preparedMessage = message.prepare()
```

#### 4. Sign message with solana

```
const signedMessage = await solana.signMessage(preparedMessage);
```

#### 5. Create API token with signed message signature

```
const token = message.token(signedMessage.signature);
```

#### 6. Add this as your 'Authorization' header for an API request!

<br>

## Server

#### 1. Import

```
const { SiwsMessage } = require("siws");
```

#### 2a. Decode 'Authorization' token sent in header

```
const token = request.header("Authorization");
const siwsMessage = new SiwsMessage({}).decode(token);
```

#### 2b. If successful, your decoded message should look like the following

```
{
  domain: 'localhost:3000',
  address: '<address>',
  statement: 'Use SIWS to authenticate',
  message: 'localhost:3000 wants you to sign in with your Solana account:\n' +
    '<address>\n' +
    '\n' +
    'Use SIWS to authenticate.\n' +
    '\n' +
    'Nonce: <nonce>\n' +
    'Issued At: Fri Feb 18 2022 4:20:00 GMT-0700 (Mountain Standard Time)',
  signature: '<signature>'
}
```

#### 3. Validate the decoded token (will return a boolean)

```
const validated = siwsMessage.validate();
```

#### 4. If `validated === true`, you can trust that the address in the decoded message was the message signer

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