# @libp2p/keychain

> Key management and cryptographically protected messages

Latest version **6.1.10** (published 2026-10-18) · Apache-2.0 OR MIT license · 0 weekly downloads

## Install

```sh
npm install @libp2p/keychain
pnpm add @libp2p/keychain
yarn add @libp2p/keychain
bun add @libp2p/keychain
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 6.1.10 |
| Published | 2026-10-18 |
| First published | 2023-01-26 |
| Weekly downloads | 0 |
| License | Apache-2.0 OR MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 8 |
| Unpacked size | 1.3 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 2581 |
| Maintainers | daviddias, alanshaw, achingbrain, vascosantos, npm-service-account-libp2p, jacobheun |
| Keywords | IPFS, crypto, encryption, keys, libp2p, secure |

## Links

- npm: https://www.npmjs.com/package/@libp2p/keychain
- Repository: https://github.com/libp2p/js-libp2p
- Homepage: https://github.com/libp2p/js-libp2p/tree/main/packages/keychain#readme
- Issues: https://github.com/libp2p/js-libp2p/issues
- npm.io page: https://npm.io/package/@libp2p/keychain

## Dependencies (8)

- [asn1js](https://npm.io/package/asn1js.md) ^3.0.6
- [uint8arrays](https://npm.io/package/uint8arrays.md) ^6.1.1
- [multiformats](https://npm.io/package/multiformats.md) ^14.0.0
- [@noble/hashes](https://npm.io/package/@noble/hashes.md) ^2.0.1
- [@libp2p/crypto](https://npm.io/package/@libp2p/crypto.md) ^5.2.0
- [@libp2p/interface](https://npm.io/package/@libp2p/interface.md) ^3.4.0
- [sanitize-filename](https://npm.io/package/sanitize-filename.md) ^1.6.3
- [interface-datastore](https://npm.io/package/interface-datastore.md) ^10.0.1

## Alternatives

- [@gemini-wallet/core](https://npm.io/package/@gemini-wallet/core.md) — 515.6K weekly downloads
- [utility](https://npm.io/package/utility.md) — 416.6K weekly downloads
- [@primno/dpapi](https://npm.io/package/@primno/dpapi.md) — 7.2K weekly downloads
- [pi-readseek](https://npm.io/package/pi-readseek.md) — 3.7K weekly downloads
- [@emilia-protocol/verify](https://npm.io/package/@emilia-protocol/verify.md) — 1.1K weekly downloads

## Recent versions

- 6.1.10 (latest) — 2026-10-18
- 6.1.10-c57bf6228 (next) — 2026-10-19
- 6.1.10-3da8bab7c — 2026-10-19
- 6.1.10-b927d5921 — 2026-10-18
- 6.1.10-aa5ba42d0 — 2026-10-18
- 6.1.9-2d4c93ed6 — 2026-10-17
- 6.1.9-d1ce8bdbe — 2026-10-17
- 6.1.9-95392efdf — 2026-10-17
- 6.1.9-f0e64b9b8 — 2026-10-17
- 6.1.9-57c4b4456 — 2026-10-17
- 6.1.9-6d888970e — 2026-10-17
- 6.1.9 — 2026-10-17
- 6.1.8-be63a4416 — 2026-10-16
- 6.1.8-e48eabf67 — 2026-10-16
- 6.1.8-e073d373d — 2026-10-15
- … 902 more at https://npm.io/package/@libp2p/keychain/versions

## README

# @libp2p/keychain

[![libp2p.io](https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square)](http://libp2p.io/)
[![Discuss](https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square)](https://discuss.libp2p.io)
[![codecov](https://img.shields.io/codecov/c/github/libp2p/js-libp2p.svg?style=flat-square)](https://codecov.io/gh/libp2p/js-libp2p)
[![CI](https://img.shields.io/github/actions/workflow/status/libp2p/js-libp2p/main.yml?branch=main\&style=flat-square)](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amain)

> Key management and cryptographically protected messages

# About

<!--

!IMPORTANT!

Everything in this README between "# About" and "# Install" is automatically
generated and will be overwritten the next time the doc generator is run.

To make changes to this section, please update the @packageDocumentation section
of src/index.js or src/index.ts

To experiment with formatting, please run "npm run docs" from the root of this
repo and examine the changes made.

-->

- Manages the life cycle of a key
- Keys are encrypted at rest
- Enforces the use of safe key names
- Uses encrypted PKCS 8 for key storage
- Uses PBKDF2 for a "stretched" key encryption key
- Enforces NIST SP 800-131A and NIST SP 800-132
- Delays reporting errors to slow down brute force attacks

## KeyInfo

The key management and naming service API all return a `KeyInfo` object.  The `id` is a universally unique identifier for the key.  The `name` is local to the key chain.

```JSON
{
  "name": "rsa-key",
  "id": "QmYWYSUZ4PV6MRFYpdtEDJBiGs4UrmE6g8wmAWSePekXVW"
}
```

The **key id** is the SHA-256 [multihash](https://github.com/multiformats/multihash) of its public key.

The *public key* is a [protobuf encoding](https://github.com/libp2p/js-libp2p/blob/main/packages/crypto/src/keys/keys.proto) containing a type and the [DER encoding](https://en.wikipedia.org/wiki/X.690) of the PKCS [SubjectPublicKeyInfo](https://www.ietf.org/rfc/rfc3279.txt).

## Private key storage

A private key is stored as an encrypted PKCS 8 structure in the PEM format. It is protected by a key generated from the key chain's *pass phrase* using **PBKDF2**.

The default options for generating the derived encryption key are in the `dek` object.  This, along with the pass phrase, is the input to a `PBKDF2` function.

```TypeScript
const defaultOptions = {
  // See https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#pbkdf2
  dek: {
    keyLength: 512 / 8,
    iterationCount: 1000,
    salt: 'at least 16 characters long',
    hash: 'sha2-512'
  }
}
```

## Physical storage

The actual physical storage of an encrypted key is left to implementations of [interface-datastore](https://github.com/ipfs/interface-datastore/).

A key benefit is that now the key chain can be used in browser with the [js-datastore-level](https://github.com/ipfs/js-datastore-level) implementation.

# Install

```console
$ npm i @libp2p/keychain
```

## Browser `<script>` tag

Loading this module through a script tag will make its exports available as `Libp2pKeychain` in the global namespace.

```html
<script src="https://unpkg.com/@libp2p/keychain/dist/index.min.js"></script>
```

# API Docs

- <https://libp2p.github.io/js-libp2p/modules/_libp2p_keychain.html>

# License

Licensed under either of

- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/keychain/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/keychain/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)

# Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

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