• Stars
    star
    242
  • Rank 167,048 (Top 4 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created about 10 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

plugin for encrypted pouchdb/couchdb databases

Crypto-Pouch

CI NPM Version JS Standard Style

Plugin to encrypt a PouchDB database.

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, an audited 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).

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 instead.

Usage

This plugin is hosted on npm. To install it in your project:

$ npm install crypto-pouch

Using Typescript? Install the type definitions:

$ 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:

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; see that library for more details.

Development

First, get the source:

$ git clone [email protected]:calvinmetcalf/crypto-pouch.git
$ cd crypto-pouch
$ npm i

Use the test suite:

$ npm test

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

License

See LICENSE.

More Repositories

1

lie

A basic but performant promise implementation.
JavaScript
741
star
2

shapefile-js

Convert a Shapefile to GeoJSON. Not many caveats.
JavaScript
651
star
3

catiline

JavaScript library to take the pain out of web workers.
JavaScript
579
star
4

copyfiles

copy files on the command line
JavaScript
386
star
5

leaflet-ajax

plugin for leaflet for ajax
JavaScript
353
star
6

leaflet.shapefile

Shapefile in Leaflet
JavaScript
242
star
7

tap-nyan

tap -> nyan
JavaScript
146
star
8

immediate

cross browser microtask
JavaScript
146
star
9

rollup-plugin-node-builtins

JavaScript
138
star
10

topojson.py

Topojson ported to python
Python
92
star
11

rollup-plugin-node-globals

JavaScript
89
star
12

SQLdown

sql backend for levelup
JavaScript
72
star
13

fileGDB.js

parse a file GDB
JavaScript
67
star
14

derequire

remove require statements without breaking scope
JavaScript
65
star
15

leaflet.filegdb

use an ESRI file geodatabase in leaflet
JavaScript
49
star
16

leaflet.pouch

PouchDB layer for leaflet
JavaScript
38
star
17

chacha20poly1305

chacha20/poly1305 with the node api
JavaScript
38
star
18

esri2geo

Converts ESRI json to geojson
JavaScript
38
star
19

leaflet.d3

leaflet + d3
JavaScript
34
star
20

leaflet.demos

Some demos for leaflet
JavaScript
32
star
21

native-crypto

crypto that should work in both the browser and in node using native modules where available
JavaScript
31
star
22

process-nextick-args

process.nextTick always accepts args, always
JavaScript
31
star
23

pouch-dat

replicate from pouch to dat
JavaScript
23
star
24

PouchStream

use some streams with your pouches
JavaScript
20
star
25

node-lfu-cache

JavaScript
19
star
26

leaflet.workspace

a quick and dirty workspace for you.
JavaScript
19
star
27

level-tree

R-tree spatial index for GeoJSON in LevelDB
JavaScript
18
star
28

minimalistic-assert

JavaScript
18
star
29

mbliberator

liberate your mbtiles from the tyranny of sqlite
JavaScript
17
star
30

simplify-rs

Rust
15
star
31

set.up

functional tools for es6 sets
JavaScript
13
star
32

esri2topo

Python
12
star
33

buffer-shims

JavaScript
12
star
34

medium

Like Big but less so
JavaScript
11
star
35

CodeForBoston-Census

Repo for the census group.
JavaScript
11
star
36

noms

easily make noms for your other streams to consume
JavaScript
10
star
37

ltcdr

like commander, but accepting pull requests
JavaScript
10
star
38

deckpad

presentations made easier
JavaScript
10
star
39

MassGIS

MassGIS -> Open
10
star
40

coshp

Cloud Optimized Shapefiles
JavaScript
9
star
41

async-iter-stream

streams as asyncIterators
JavaScript
9
star
42

leaf-couch

leaflet in the front, couchdb in the back
JavaScript
9
star
43

es6-stream

streams, but with generators
JavaScript
9
star
44

parseDBF

JavaScript
9
star
45

macrotask

A cross browser macrotask library
JavaScript
9
star
46

streams-a-love-story

Node Interactive talk entitled Streams and You: A Love Story
HTML
8
star
47

rollup-config-cjs

JavaScript
8
star
48

esri2gist

Make Gists inside Arcmap
Python
8
star
49

buffer-es6

es6 port of browserify buffer
JavaScript
7
star
50

async-rtree

An async rtree
JavaScript
6
star
51

web-worker

make web workers from strings in many browsers
JavaScript
6
star
52

cabs

Content Addressable Blob Store
JavaScript
6
star
53

chacha-native

node bindings for chacha20 in c
C++
6
star
54

proj4geojson

JavaScript
6
star
55

liar

A modular collection of tools for asynchronous programing via promises
JavaScript
6
star
56

jsgeo

Calvin's js.geo presentation
JavaScript
5
star
57

rollup-plugin-auto-transform

JavaScript
5
star
58

cw.ajax

ajax plugin
JavaScript
5
star
59

name-me

come up with a name for your npm package
JavaScript
5
star
60

salsa20

JavaScript
5
star
61

inline-process-browser

inline references to 'process.browser' to 'true'
JavaScript
5
star
62

es6-translate

Yo dawg I heard you liked modules, so I made a module to translate your modules into modules.
JavaScript
5
star
63

spider-stream

recursively get files in a directory and sub directories, as a stream
JavaScript
4
star
64

nontree

geohashes, but turned up to 102 in ternary
JavaScript
4
star
65

vector-layers

vector layers in leaflet
JavaScript
4
star
66

flaming-wight

pouch demo from my blog
JavaScript
4
star
67

node-process-es6

JavaScript
4
star
68

geojson-assert

assert stuff about geojson (well just one thing)
JavaScript
4
star
69

shp-write-stream

stream write shapefiles, sorta
JavaScript
4
star
70

SBS

Sync Buffer Stream: A stream that synchronously buffers and then drains on the next tick
JavaScript
4
star
71

leaflet.css

moved
JavaScript
3
star
72

io-stream

iojs-core streams for userland
JavaScript
3
star
73

cloud-pubsub

JavaScript
3
star
74

crypto-stream

streaming authenticated encryption stream
JavaScript
3
star
75

pem2jwk

JavaScript
3
star
76

leaflet.sprite

moved
CoffeeScript
3
star
77

sublevel-migrate

migrate v5 sublevels to v6
JavaScript
3
star
78

create-cipher

the node ciphers you always wanted
JavaScript
3
star
79

kublai

express + tilelive + cats
JavaScript
3
star
80

projections-in-web-browsers-are-terrible-and-you-should-be-ashamed-of-yourself

I have opinions
JavaScript
3
star
81

kubernetes-scripts

JavaScript
2
star
82

csr

JavaScript
2
star
83

lie-parallel

JavaScript
2
star
84

express-simple-auth-token

JSON web token middleware for express designed to work with Ember Simple Auth Token
JavaScript
2
star
85

pouchdb-topromise

JavaScript
2
star
86

leaflet-workshop

workshop at avidgeo
JavaScript
2
star
87

maptime-git

JavaScript
2
star
88

k3

JavaScript
2
star
89

deckdemo

JavaScript
2
star
90

parcel-map

JavaScript
2
star
91

FieldMapping

tools for dealing with arcpy field mapping
Python
2
star
92

intercal

TODO port to JS
C
2
star
93

service-account

sugar for easier access to google service account keys
JavaScript
2
star
94

cartodb-console

JavaScript
2
star
95

cw.mapReduce

JavaScript
2
star
96

hmac-stream

streaming HMACs
JavaScript
2
star
97

ppp

2
star
98

offline-talk

HTML
1
star
99

pouchdb-promise

JavaScript
1
star
100

cwm

JavaScript
1
star