:closed_lock_with_key: encrypt-down :closed_lock_with_key:
![NpmLicense](https://img.shields.io/npm/l/encrypt-down.svg)
An abstract-leveldown implementation that wraps another store to encrypt values.
Installation
npm install @adorsys/encrypt-down
Usage
Without any options encrypt-down
can be used but nothing is encrypted.
const memdown = require('memdown')
const encryptdown = require('@adorsys/encrypt-down')
const levleup = require('levelup')
const db = levelup(encryptdown(memdown()))
db.put('key', { awesome: true }, function (err) {
db.get('key', function (err, value) {
console.log(value)
})
})
Can we specify the encryption that shall be used? Yes!
const memdown = require('memdown')
const encryptdown = require('@adorsys/encrypt-down')
const levleup = require('levelup')
const codec = {
encrypt: value => Promise.resolve(value),
decrypt: value => Promise.resolve(value)
}
const db = levelup(encryptdown(memdown(), { codec }))
db.put('key', { awesome: true }, function (err) {
db.get('key', function (err, value) {
console.log(value)
})
})
Is there an example that actually encrypts the values? Yes!
We can use an existing encryption library like jwe-codec
.
const memdown = require('memdown')
const encryptdown = require('@adorsys/encrypt-down')
const levleup = require('levelup')
const jwe = require('@adorsys/jwe-codec')
const key = {
kty: 'oct',
alg: 'A256GCM',
use: 'enc',
k: '123456789abcdefghijklmnopqrstuvwxyz12345678'
}
jwe(key).then(function(codec) {
const db = levelup(encryptdown(memdown(), { codec }))
db.put('key', { awesome: true }, function (err) {
db.get('key', function (err, value) {
console.log(value)
})
})
})
API
const db = require('@adorsys/encrypt-down')(db[, options])
db
must be an abstract-leveldown
compliant storeoptions
:
codec
:
encrypt
: function returning promise of encrypted valuedecrypt
: function returning promise of decrypted value
encrypt
and decrypt
both default to identity function when not explicitly specified.
Credits
Made with :heart: by radzom and all these wonderful contributors (emoji key):
![](https://avatars.githubusercontent.com/u/3055345?v=3) Vincent Weevers :speech_balloon: | | | | | | |
---|
This project follows the all-contributors specification. Contributions of any kind are welcome!