# crypto-pouch

> encrypted pouchdb/couchdb database

Latest version **4.0.2** (published 2024-11-07) · MIT license · 0 weekly downloads

## Install

```sh
npm install crypto-pouch
pnpm add crypto-pouch
yarn add crypto-pouch
bun add crypto-pouch
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.0.2 |
| Published | 2024-11-07 |
| First published | 2014-11-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/crypto-pouch) |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 15.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 245 |
| Author | Calvin Metcalf |
| Maintainers | cwmma, garbados |
| Keywords | pouchdb, couchdb, encrypted |

## Links

- npm: https://www.npmjs.com/package/crypto-pouch
- Repository: https://github.com/calvinmetcalf/crypto-pouch
- Issues: https://github.com/calvinmetcalf/crypto-pouch/issues
- npm.io page: https://npm.io/package/crypto-pouch

## Dependencies (2)

- [garbados-crypt](https://npm.io/package/garbados-crypt.md) ^3.0.0-beta
- [transform-pouch](https://npm.io/package/transform-pouch.md) ^2.0.0

## Recent versions

- 4.0.2 (latest) — 2024-11-07
- 4.0.1 — 2021-08-10
- 4.0.0 — 2021-08-06
- 3.1.3 — 2017-08-01
- 3.1.2 — 2017-05-09
- 3.1.1 — 2016-12-21
- 3.1.0 — 2016-11-01
- 3.0.0 — 2016-06-09
- 2.0.0 — 2016-05-03
- 1.2.1 — 2016-02-05
- 1.2.0 — 2016-02-02
- 1.1.3 — 2015-08-25
- 1.1.2 — 2015-05-04
- 1.1.1 — 2014-11-26
- 1.1.0 — 2014-11-26
- … 1 more at https://npm.io/package/crypto-pouch/versions

## README

# Crypto-Pouch

[![CI](https://github.com/calvinmetcalf/crypto-pouch/actions/workflows/ci.yaml/badge.svg)](https://github.com/calvinmetcalf/crypto-pouch/actions/workflows/ci.yaml)
[![NPM Version](https://img.shields.io/npm/v/crypto-pouch.svg?style=flat-square)](https://www.npmjs.com/package/crypto-pouch)
[![JS Standard Style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)

Plugin to encrypt a PouchDB database.

```js
const PouchDB = require('pouchdb')
PouchDB.plugin(require('crypto-pouch'))

const db = new PouchDB('my_db')

// init; after this, docs will be transparently en/decrypted
db.crypto(password).then(() => {
  // db will now transparently encrypt writes and decrypt reads
  await db.put({ ... })
  // you can disable transparent en/decryption,
  // though encrypted docs remain encrypted
  db.removeCrypto()
})
```

Crypto-Pouch encrypts documents using [TweetNaCl.js](https://github.com/dchest/tweetnacl-js), an [audited](https://cure53.de/tweetnacl.pdf) encryption library. It uses the *xsalsa20-poly1305* algorithm.

**Note**: Attachments cannot be encrypted at this point. Use `{ignore: '_attachments'}` to leave attachments unencrypted. Also note that `db.putAttachment` / `db.getAttachment` are not supported. Use `db.put` and `db.get({binary: true, attachment: true})` instead. ([#18](https://github.com/calvinmetcalf/crypto-pouch/issues/13)).

This only encrypts the contents of documents, **not the \_id or \_rev, nor view keys and values**. This means that `_id` values always remain unencrypted, and any keys or values emitted by views are stored unencrypted as well. If you need total encryption at rest, consider using the PouchDB plugin [ComDB](https://github.com/garbados/comdb) instead.

## Usage

This plugin is hosted on [npm](http://npmjs.com/). To install it in your project:

```bash
$ npm install crypto-pouch
```
Using Typescript? Install the type definitions:

```bash
$ npm install --save-dev @types/crypto-pouch
```

## Usage

### async db.crypto(password [, options])

Set up encryption on the database.

- `password`: A string password, used to encrypt documents. Make sure it's good!
- `options.ignore`: Array of strings of properties that will not be encrypted.

You may also pass an options object as the first parameter, like so:

```javascript
db.crypto({ password, ignore: [...] }).then(() => {
  // database will now encrypt writes and decrypt reads
})
```

### db.removeCrypto()

Disables encryption on the database and forgets your password.

## Details

If you replicate to another database, Crypto-Pouch will decrypt documents before
sending them to the target database. Documents received through replication will
be encrypted before being saved to disk.

If you change the ID of a document, Crypto-Pouch will throw an error when you try
to decrypt it. If you manually move a document from one database to another,
it will not decrypt correctly.

Encrypted documents have only one custom property, `payload`, which contains the
encrypted contents of the unencrypted document. So, `{ hello: 'world' }` becomes
`{ payload: '...' }`. This `payload` value is produced by [garbados-crypt](https://github.com/garbados/crypt#garbados-crypt); see that library for more details.

## Development

First, get the source:

```bash
$ git clone git@github.com:calvinmetcalf/crypto-pouch.git
$ cd crypto-pouch
$ npm i
```

Use the test suite:

```bash
$ npm test
```

*When contributing patches, be a good neighbor and include tests!*

## License

See [LICENSE](./LICENSE).

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