https://github.com/andywer/key-store
🔐 Isomorphic encrypted key store written in TypeScript.
https://github.com/andywer/key-store
aes-256 key nodejs password store typescript
Last synced: 10 months ago
JSON representation
🔐 Isomorphic encrypted key store written in TypeScript.
- Host: GitHub
- URL: https://github.com/andywer/key-store
- Owner: andywer
- License: mit
- Created: 2017-10-27T11:44:49.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-02-11T17:17:29.000Z (about 3 years ago)
- Last Synced: 2025-04-15T11:14:08.014Z (about 1 year ago)
- Topics: aes-256, key, nodejs, password, store, typescript
- Language: TypeScript
- Homepage:
- Size: 223 KB
- Stars: 19
- Watchers: 2
- Forks: 4
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# key-store
[](https://travis-ci.org/andywer/key-store)
[](https://www.npmjs.com/package/key-store)
[](http://standardjs.com/)
Isomorphic encrypted key store. Works in node and in the browser.
#### Features
🔒 Strong encryption to securily store sensible data
🔑 Supports distinct passwords for each key
🔍 Can store unencrypted data alongside each key
**Attention: The data is stored in a truly secure way. If you lose your password you will not be able to recover the wallet data! So please make sure to store a backup of the private data in a safe place.**
## Installation
```sh
$ npm install --save key-store
```
Using yarn:
```sh
$ yarn add key-store
```
## Example
```js
import { createStore } from 'key-store'
const store = createStore(saveFile, initialData)
await store.saveKey('test-key', 'arbitrary password', { privateKey: 'super secret private key' })
const { privateKey } = store.getPrivateKeyData('test-key', 'arbitrary password')
console.log(`Stored private key: ${privateKey}`)
console.log(`All stored keys' IDs: ${store.getKeyIDs().join(', ')}`)
```
Writing and reading keys to a file in node is easy:
```js
import * as fs from 'fs'
import * as util from 'util'
import { createStore } from 'key-store'
const readFile = util.promisify(fs.readFile)
const writeFile = util.promisify(fs.writeFile)
async function createFileStore (filePath) {
const saveKeys = data => writeFile(filePath, JSON.stringify(data), 'utf8')
const readKeys = async () => JSON.parse(await readFile(filePath, 'utf8'))
return createStore(saveKeys, await readKeys())
}
```
## Encryption details
All data private data is encrypted using tweetnacl's `xsalsa20-poly1305` implementation. The encryption key is derived from the password using PBKDF2/SHA256. The iteration count for the PBKDF2 invocation is configurable and defaults to 10,000 rounds.
## API
Check out the [declaration file](./lib/index.d.ts).
## License
MIT