# @coboxcoop/crypto

> crypto library for generating keys using libsodium

Latest version **1.0.2-alpha.1** (published 2020-07-29) · AGPL-3.0-or-later license · 0 weekly downloads

## Install

```sh
npm install @coboxcoop/crypto
pnpm add @coboxcoop/crypto
yarn add @coboxcoop/crypto
bun add @coboxcoop/crypto
```

## 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-alpha.1 |
| Published | 2020-07-29 |
| First published | 2020-07-29 |
| Weekly downloads | 0 |
| License | AGPL-3.0-or-later |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 53 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | magma collective |
| Maintainers | ameba23, kyphae |

## Links

- npm: https://www.npmjs.com/package/@coboxcoop/crypto
- Repository: https://gitlab.com/coboxcoop/cobox-crypto
- Homepage: https://cobox.cloud
- Issues: https://gitlab.com/coboxcoop/cobox-crypto/issues
- npm.io page: https://npm.io/package/@coboxcoop/crypto

## Dependencies (5)

- [bip39](https://npm.io/package/bip39.md) ^3.0.2
- [assert](https://npm.io/package/assert.md) ^2.0.0
- [sodium-native](https://npm.io/package/sodium-native.md) ^2.4.2
- [hypercore-crypto](https://npm.io/package/hypercore-crypto.md) ^1.0.0
- [@coboxcoop/crypto-encoder](https://npm.io/package/@coboxcoop/crypto-encoder.md) ^1.0.0-alpha.1

## Recent versions

- 1.0.2-alpha.1 (latest) — 2020-07-29
- 1.0.1-alpha.1 — 2020-07-29
- 1.0.0-alpha.1 — 2020-07-29

## README

# crypto

<div align="center">
  <img src="https://cobox.cloud/src/svg/logo.svg">
</div>

[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)

## Table of Contents

  - [About](#about)
  - [Install](#install)
  - [Usage](#usage)
  - [API](#api)
  - [Contributing](#contributing)
  - [License](#license)

## About
**CoBox** is an encrypted p2p file system and distributed back-up tool. [README](https://gitlab.com/coboxcoop/readme) provides a map of the project.

`crypto` provides the crypto primitives used in CoBox

## Install

```
npm i -g @coboxcoop/crypto
```

## Usage

```
const crypto = require('@coboxcoop/crypto')
```

## API

```js
const address = crypto.address()
```

Returns a `ed25519` random 32 byte buffer

```js
const keyPair = crypto.keyPair()
```

Returns an `ed25519` keypair that can used for tree signing.

```js
const encKey = crypto.encryptionKey()
```

Returns an `ed25519` symmetric key used for shared secret encryption

```js
const accessKey = crypto.accessKey()

// OR

const accessKey = crypto.pack(address, encKey)
```

Returns an access key, which consists of an `ed25519` address, packed together with an `ed25519` symmetric key

```js
const keys = crypto.unpack(key)
```

Returns an object containing an address, and a shared secret if accessible. Address alone is used for blind replication. The shared secret can then be used for decryption.

```js
const { publicKey, secretKey } = crypto.boxKeyPair(seed)
```

Returns an `ed25519` private box keypair used for identification, message signing and encryption

```js
const boxed = box(publicKey, message, [context])
```

Encrypts a message to a given public key and returns it as a buffer
- `publicKey` buffer or hex encoded string
- `message` buffer or hex encoded string of any length
- `context`, if passed, will be hashed in to the shared secret. Should be a buffer or hex encoded string.

```js
const unboxed = unbox(cipherText, keypair, [context])
```

Decrypts a message using the given keypair.
- `cipherText` the encrypted message given as a buffer.
- `keypair` an object of the form `{ publicKey, secretKey }` both of which should be buffers or hex encoded strings.
- `context`, if given, will be hashed into the shared secret. Should be a buffer or hex encoded string.

## Contributing

PRs accepted.

Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.

# License

[`AGPL-3.0-or-later`](./LICENSE)

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