# hypercore-crypto

> The crypto primitives used in hypercore, extracted into a separate module

Latest version **3.7.0** (published 2026-05-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install hypercore-crypto
pnpm add hypercore-crypto
yarn add hypercore-crypto
bun add hypercore-crypto
```

## Health

**Score 45/100 (D)** — status: active.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

## Facts

| | |
|---|---|
| Version | 3.7.0 |
| Published | 2026-05-05 |
| First published | 2018-06-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 8.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 37 |
| Author | Mathias Buus |
| Maintainers | mafintosh, andrewosh |

## Links

- npm: https://www.npmjs.com/package/hypercore-crypto
- Repository: https://github.com/mafintosh/hypercore-crypto
- Issues: https://github.com/mafintosh/hypercore-crypto/issues
- npm.io page: https://npm.io/package/hypercore-crypto

## Dependencies (3)

- [b4a](https://npm.io/package/b4a.md) ^1.6.6
- [compact-encoding](https://npm.io/package/compact-encoding.md) ^3.0.0
- [sodium-universal](https://npm.io/package/sodium-universal.md) ^5.0.0

## Recent versions

- 3.7.0 (latest) — 2026-05-05
- 3.6.1 — 2025-05-22
- 3.6.0 — 2025-04-12
- 3.5.0 — 2025-02-13
- 3.4.2 — 2024-05-28
- 3.4.1 — 2024-04-28
- 3.4.0 — 2023-07-26
- 3.3.1 — 2023-01-10
- 3.3.0 — 2022-06-12
- 3.2.1 — 2022-03-11
- 3.2.0 — 2022-03-01
- 3.1.1 — 2021-11-23
- 3.1.0 — 2021-11-09
- 3.0.0 — 2021-11-08
- 2.3.2 — 2021-11-08
- … 10 more at https://npm.io/package/hypercore-crypto/versions

## README

# hypercore-crypto

The crypto primitives used in hypercore, extracted into a separate module

```
npm install hypercore-crypto
```

## Usage

```js
const crypto = require('hypercore-crypto')

const keyPair = crypto.keyPair()
console.log(keyPair) // prints a ed25519 keypair
```

## API

#### `keyPair = crypto.keyPair()`

Returns an `ED25519` keypair that can be used for tree signing.

#### `signature = crypto.sign(message, secretKey)`

Signs a message (buffer).

#### `verified = crypto.verify(message, signature, publicKey)`

Verifies a signature for a message.

#### `hash = crypto.data(data)`

Hashes a leaf node in a merkle tree.

#### `hash = crypto.parent(left, right)`

Hash a parent node in a merkle tree. `left` and `right` should look like this:

```js
{
  index: treeIndex,
  hash: hashOfThisNode,
  size: byteSizeOfThisTree
}
```

#### `hash = crypto.tree(peaks)`

Hashes the merkle root of the tree. `peaks` should be an array of the peaks of the tree and should look like above.

#### `buffer = crypto.randomBytes(size)`

Returns a buffer containing random bytes of size `size`.

#### `hash = crypto.discoveryKey(publicKey)`

Return a hash derived from a `publicKey` that can used for discovery
without disclosing the public key.

#### `list = crypto.namespace(name, count)`

Make a list of namespaces from a specific publicly known name.
Use this to namespace capabilities or hashes / signatures across algorithms.

## License

MIT

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