Secure key-value store built on secure-container
.
npm install seco-keyval
import SecoKeyval from 'seco-keyval'
const kv = new SecoKeyval('db.seco', { appName: 'exodus', appVersion: '1.0.0' })
await kv.open('1-very-secure-password', { a: 1 })
await kv.set('key', 'myValue')
const value1 = kv.get('a')
console.log(value1) // -> 1
const value2 = kv.get('key')
console.log(value2) // -> 'myValue'
file
(String) Filenameheader
(Object)appName
(String) App NameappVersion
(String) App Version
Loads the key-value store. Creates it if it doesn't exist.
passphrase
(String | Buffer)initialData
(any JSON-serializable data) Will be written if the store doesn't exist.
Returns a Promise resolving when the filesystem operations are complete. You cannot call set()
or get()
until this is done.
Sets key
to value
. Returns a promise resolving when the data has been written to disk.
Gets key
and returns the value of key
. Returns undefined
if the key is not set.
Deletes key
. Returns a promise resolving when the data has been written to disk.
Accepts an Array of operations
where each item is an Object, with the structure:
type
The String"set"
or"delete"
key
Key to perform the operation onvalue
forset
operation, the value to be set tokey
Returns a promise resolving when the data has been written to disk.
Changes the passphrase to newPassphrase
. Returns a promise resolving when the data has been written to disk.
Schedule for the passphrase to change to newPassphrase
on the next file write. There is no guarantee that the passphrase will get changed when using this method (i.e. if set()
is never called afterwards). Returns undefined
.
Returns an object containing all the key-value pairs in the kv.
DANGER: Don't use this method unless you know what you're doing!
This completely replaces and overwrites the key-value store with data
and writes the data to disk, with no backups of the old data.
MIT