Skip to content

๐Ÿ” Isomorphic encrypted key store written in TypeScript.

License

Notifications You must be signed in to change notification settings

andywer/key-store

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

61 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

key-store

Build Status NPM Version JavaScript Style Guide

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

$ npm install --save key-store

Using yarn:

$ yarn add key-store

Example

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:

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.

License

MIT