# couchdb-calculate-session-id

> calculates valid CouchDB session IDs using username, salt, secret & timestamp

Latest version **1.1.3** (published 2018-05-15) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install couchdb-calculate-session-id
pnpm add couchdb-calculate-session-id
yarn add couchdb-calculate-session-id
bun add couchdb-calculate-session-id
```

## 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.1.3 |
| Published | 2018-05-15 |
| First published | 2015-12-15 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 17.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 9 |
| Author | The Hoodie Community |
| Maintainers | hoodie |
| Keywords | couchdb, session |

## Links

- npm: https://www.npmjs.com/package/couchdb-calculate-session-id
- Repository: https://github.com/hoodiehq/couchdb-calculate-session-id
- Homepage: https://github.com/hoodiehq/couchdb-calculate-session-id#readme
- Issues: https://github.com/hoodiehq/couchdb-calculate-session-id/issues
- npm.io page: https://npm.io/package/couchdb-calculate-session-id

## Dependencies (3)

- [aproba](https://npm.io/package/aproba.md) ^1.0.1
- [base64url](https://npm.io/package/base64url.md) ^3.0.0
- [crypto-lite](https://npm.io/package/crypto-lite.md) ^0.2.0

## Alternatives

- [@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
- [@luigi-project/plugin-auth-oauth2](https://npm.io/package/@luigi-project/plugin-auth-oauth2.md) — 2.3K weekly downloads
- [@nocobase/plugin-verification](https://npm.io/package/@nocobase/plugin-verification.md) — 2.0K weekly downloads
- [escher-request](https://npm.io/package/escher-request.md) — 545 weekly downloads

## Recent versions

- 1.1.3 (latest) — 2018-05-15
- 1.1.2 — 2017-02-08
- 1.1.1 — 2016-10-13
- 1.1.0 — 2015-12-25
- 1.0.1 — 2015-12-24
- 1.0.0 — 2015-12-15

## README

# couchdb-calculate-session-id

> calculates valid CouchDB session IDs using username, salt, secret & timestamp

[![Build Status](https://travis-ci.org/hoodiehq/couchdb-calculate-session-id.svg?branch=master)](https://travis-ci.org/hoodiehq/couchdb-calculate-session-id)
[![Coverage Status](https://coveralls.io/repos/hoodiehq/couchdb-calculate-session-id/badge.svg?branch=master)](https://coveralls.io/r/hoodiehq/couchdb-calculate-session-id?branch=master)
[![Dependency Status](https://david-dm.org/hoodiehq/couchdb-calculate-session-id.svg)](https://david-dm.org/hoodiehq/couchdb-calculate-session-id)
[![devDependency Status](https://david-dm.org/hoodiehq/couchdb-calculate-session-id/dev-status.svg)](https://david-dm.org/hoodiehq/couchdb-calculate-session-id#info=devDependencies)

## Example

```js
var calculateSessionId = require('couchdb-calculate-session-id')

var sessionId = calculateSessionId(
  'pat',
  '24eb90e9e1343977b8323857287ffca4',
  '78875068a1979fb910d5d8f37d316aa4',
  1449689785
)
```

## Arguments

<table>
  <thead>
    <tr>
      <th align="left">Argument</th>
      <th align="left">Type</th>
      <th align="left">Description</th>
    </tr>
  </thead>
  <tr>
    <th align="left"><strong>username</strong></th>
    <td>String</td>
    <td><code>name</code> property of <code>\_users</code> doc</td>
  </tr>
  <tr>
    <th align="left"><strong>usersalt</strong></th>
    <td>String</td>
    <td><code>salt</code> property of <code>\_users</code> doc</td>
  </tr>
  <tr>
    <th align="left"><strong>serversecret</strong></th>
    <td>String</td>
    <td><code>couch_httpd_auth.secret</code> of CouchDB configuration</td>
  </tr>
  <tr>
    <th align="left"><strong>timestamp</strong></th>
    <td>Number</td>
    <td>Number of seconds elapsed since 1 January 1970 00:00:00 UTC</td>
  </tr>
</table>

## How CouchDB does it using Erlang

```erlang
make_cookie_hash(UserName, Secret, TimeStamp) ->
    SessionData = UserName ++ ":" ++ erlang:integer_to_list(TimeStamp, 16),
    Hash = crypto:sha_mac(Secret, SessionData),
    couch_util:encodeBase64Url(SessionData ++ ":" ++ ?b2l(Hash)).
```

## Credits

All credits due to [@christophwitzko](https://twitter.com/christophwitzko),
[@indutny](https://twitter.com/indutny) & [@janl](https://twitter.com/janl):
https://gist.github.com/janl/4583f5eb4c0d8216cc5f

## License

[Apache-2.0](https://github.com/hoodiehq/hoodie/blob/master/LICENSE)

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