# keystore-idb

> In-browser key management with IndexedDB and the Web Crypto API

Latest version **0.15.5** (published 2022-03-30) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install keystore-idb
pnpm add keystore-idb
yarn add keystore-idb
bun add keystore-idb
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.15.5 |
| Published | 2022-03-30 |
| First published | 2020-02-24 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10.21.0 |
| Dependencies | 3 |
| Unpacked size | 389.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 61 |
| Author | Daniel Holmgren |
| Maintainers | appcypher, icidasset, quinnwilton, bgins-fission, expede, walkah, philipp-fission, dholms |

## Links

- npm: https://www.npmjs.com/package/keystore-idb
- Repository: https://github.com/fission-suite/keystore-idb
- Homepage: https://github.com/fission-suite/keystore-idb#readme
- Issues: https://github.com/fission-suite/keystore-idb/issues
- npm.io page: https://npm.io/package/keystore-idb

## Dependencies (3)

- [localforage](https://npm.io/package/localforage.md) ^1.10.0
- [uint8arrays](https://npm.io/package/uint8arrays.md) ^3.0.0
- [one-webcrypto](https://npm.io/package/one-webcrypto.md) ^1.0.3

## Recent versions

- 0.15.5 (latest) — 2022-03-30
- 0.15.3-alpha1 (alpha) — 2021-10-20
- 0.15.4 — 2021-11-02
- 0.15.3 — 2021-10-21
- 0.15.2 — 2021-10-06
- 0.15.1 — 2021-09-28
- 0.15.1-alpha — 2021-09-27
- 0.15.0 — 2021-09-14
- 0.15.0-alpha-6 — 2021-09-13
- 0.15.0-alpha-5 — 2021-09-13
- 0.15.0-alpha-4 — 2021-09-13
- 0.15.0-alpha-3 — 2021-09-13
- 0.15.0-alpha-2 — 2021-09-13
- 0.15.0-alpha — 2021-09-08
- 0.14.2 — 2021-06-14
- … 45 more at https://npm.io/package/keystore-idb/versions

## README

# IndexedDB KeyStore

[![NPM](https://img.shields.io/npm/v/keystore-idb)](https://www.npmjs.com/package/keystore-idb)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://github.com/fission-suite/blob/master/LICENSE)
[![Maintainability](https://api.codeclimate.com/v1/badges/b0fabd7e80c6bd2c0c7b/maintainability)](https://codeclimate.com/github/fission-suite/keystore-idb/maintainability)
[![Built by FISSION](https://img.shields.io/badge/⌘-Built_by_FISSION-purple.svg)](https://fission.codes)
[![Discord](https://img.shields.io/discord/478735028319158273.svg)](https://discord.gg/zAQBDEq)
[![Discourse](https://img.shields.io/discourse/https/talk.fission.codes/topics)](https://talk.fission.codes)

In-browser key management with IndexedDB and the Web Crypto API.

Securely store and use keys for encryption, decryption, and signatures. IndexedDB and Web Crypto keep keys safe from malicious javascript.

Supports both RSA (RSASSA-PKCS1-v1_5 & RSA-OAEP) and Elliptic Curves (P-256, P-381 & P-521).

ECC (Elliptic Curve Cryptography) is only available on Chrome. Firefox and Safari do not support ECC and must use RSA.
_Specifically, this is an issue with storing ECC keys in IndexedDB_



## Config

Below is the default config and all possible values
_Note: these are given as primitives, but in Typescript you can use the included enums_

```typescript
const defaultConfig = {
  type: 'ecc', // 'ecc' | 'rsa'
  curve: 'P-256', // 'P-256' | 'P-384' | 'P-521'
  rsaSize: 2048, // 1024 | 2048 | 4096
  symmAlg: 'AES-CTR', // 'AES-CTR' | 'AES-GCM' | 'AES-CBC'
  symmLen: 128, // 128 | 192 | 256
  hashAlg: 'SHA-256', // 'SHA-1' | 'SHA-256' | 'SHA-384' | 'SHA-512'
  charSize: 16, // 8 | 16
  storeName: 'keystore', // any string
  exchangeKeyName: 'exchange-key', // any string
  writeKeyName: 'write-key', // any string
}
```
_Note: if you don't include a crypto "type" (`'ecc' | 'rsa'`), the library will check if your browser supports ECC. If so (Chrome), it will use ECC, if not (Firefox, Safari) it will fall back to RSA._



## Example Usage

```typescript
import keystore from 'keystore-idb'

async function run() {
  await keystore.clear()

  const ks1 = await keystore.init({ storeName: 'keystore' })
  const ks2 = await keystore.init({ storeName: 'keystore2' })

  const msg = "Incididunt id ullamco et do."

  // exchange keys and write keys are separate because of the Web Crypto API
  const exchangeKey1 = await ks1.publicExchangeKey()
  const writeKey1 = await ks1.publicWriteKey()
  const exchangeKey2 = await ks2.publicExchangeKey()

  // these keys get exported as strings
  console.log('exchangeKey1: ', exchangeKey1)
  console.log('writeKey1: ', writeKey1)
  console.log('exchangeKey2: ', exchangeKey2)

  const sig = await ks1.sign(msg)
  const valid = await ks2.verify(msg, sig, writeKey1)
  console.log('sig: ', sig)
  console.log('valid: ', valid)

  const cipher = await ks1.encrypt(msg, exchangeKey2)
  const decipher = await ks2.decrypt(cipher, exchangeKey1)
  console.log('cipher: ', cipher)
  console.log('decipher: ', decipher)
}

run()
```



## Development

```shell
# install dependencies
yarn

# run development server
yarn start

# build
yarn build

# test
yarn test

# test w/ reloading
yarn test:watch

# publish (run this script instead of npm publish!)
./publish.sh
```

---
_Source: https://npm.io/package/keystore-idb · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
