# crypto-encoder

> A simple crypto encoder compatible with hypercore

Latest version **1.0.2** (published 2020-07-15) · AGPL-3.0-or-later license · 0 weekly downloads

## Install

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

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2020-07-15 |
| First published | 2019-12-12 |
| Weekly downloads | 0 |
| License | AGPL-3.0-or-later |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 77.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Magma Collective |
| Maintainers | ameba23 |
| Keywords | crypto, encoder, hypercore |

## Links

- npm: https://www.npmjs.com/package/crypto-encoder
- Repository: https://github.com/ameba23/crypto-encoder
- Homepage: https://github.com/ameba23/crypto-encoder#readme
- Issues: https://github.com/ameba23/crypto-encoder/issues
- npm.io page: https://npm.io/package/crypto-encoder

## Dependencies (3)

- [assert](https://npm.io/package/assert.md) ^2.0.0
- [codecs](https://npm.io/package/codecs.md) ^2.1.0
- [sodium-native](https://npm.io/package/sodium-native.md) ^2.4.2

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2020-07-15
- 1.0.1 — 2019-12-12
- 1.0.0 — 2019-12-12

## README

# crypto-encoder

A simple hypercore-compatible crypto encoder.

## Example

```js
const hypercore = require('hypercore')
const Encoder = require('.')

const encryptionKey = Encoder.encryptionKey()
const valueEncoding = Encoder(encrytionKey, { valueEncoding: 'utf-8' })

const feed = hypercore(storage, { valueEncoding })
```

## API

```js
const Encoder = require('.')
```

```js
const encryptionKey = Encoder.encryptionKey()
```
Generate a random 32 byte key to be used to encrypt.

```js
const valueEncoding = Encoder(encryptionKey, opts)
```
Returns a message encoder used for encrypting messages in hypercore. 
- `encryptionKey` must be a buffer of length `Encoder.KEYBYTES`.
- `opts` is an optional object which may contain:
  - `opts.valueEncoder`, an additional encoder to be used before encryption. May be one of:
    - The string 'utf-8' - utf-8 encoded strings will be assumed.
    - The string 'JSON' - JSON encoding will be assumed.
    - A custom encoder of the form `{ encode: [function] decode: [function] }`

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