# eccrypto-js

> Elliptic curve cryptography library (NodeJS, Browser and Pure JS)

Latest version **5.4.0** (published 2021-01-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install eccrypto-js
pnpm add eccrypto-js
yarn add eccrypto-js
bun add eccrypto-js
```

## Health

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

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.4.0 |
| Published | 2021-01-08 |
| First published | 2020-02-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 7 |
| Unpacked size | 643.9 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 32 |
| Author | Pedro Gomes |
| Maintainers | pedrouid |
| Keywords | ecc, ecdsa, ecdh, ecies, crypto, cryptography, secp256k1, K-256, elliptic, curve |

## Links

- npm: https://www.npmjs.com/package/eccrypto-js
- Repository: https://github.com/pedrouid/eccrypto-js
- Issues: https://github.com/pedrouid/eccrypto-js/issues
- npm.io page: https://npm.io/package/eccrypto-js

## Dependencies (7)

- [aes-js](https://npm.io/package/aes-js.md) 3.1.2
- [pbkdf2](https://npm.io/package/pbkdf2.md) ^3.0.17
- [hash.js](https://npm.io/package/hash.js.md) 1.1.7
- [js-sha3](https://npm.io/package/js-sha3.md) 0.8.0
- [enc-utils](https://npm.io/package/enc-utils.md) 2.1.0
- [secp256k1](https://npm.io/package/secp256k1.md) 3.8.0
- [randombytes](https://npm.io/package/randombytes.md) 2.1.0

## 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

- 5.4.0 (latest) — 2021-01-08
- 5.0.0-beta.14 (beta) — 2020-05-05
- 5.0.0-beta.10 (next) — 2020-04-17
- 5.3.0 — 2020-05-25
- 5.2.0 — 2020-05-06
- 5.1.1 — 2020-05-06
- 5.1.0 — 2020-05-06
- 5.0.0 — 2020-05-05
- 5.0.0-beta.13 — 2020-04-20
- 4.5.4 — 2020-04-20
- 5.0.0-beta.12 — 2020-04-20
- 5.0.0-beta.11 — 2020-04-17
- 5.0.0-beta.8 — 2020-04-16
- 5.0.0-beta.7 — 2020-04-16
- 5.0.0-beta.6 — 2020-04-16
- … 54 more at https://npm.io/package/eccrypto-js/versions

## README

# eccrypto-js [![npm version](https://badge.fury.io/js/eccrypto-js.svg)](https://badge.fury.io/js/eccrypto-js)

Elliptic curve cryptography library (NodeJS, Browser and Pure JS)

## Description

This library is a port from [eccrypto](https://github.com/bitchan/eccrypto) it makes use of native libraries on NodeJS and Browser enviroments with pure javascript fallbacks.

## Usage

### RandomBytes

```typescript
import * as eccryptoJS from 'eccrypto-js';

const length = 32;
const key = eccryptoJS.randomBytes(length);

// key.length === length
```

### AES

```typescript
import * as eccryptoJS from 'eccrypto-js';

const key = eccryptoJS.randomBytes(32);
const iv = eccryptoJS.randomBytes(16);

const str = 'test message to encrypt';
const msg = eccryptoJS.utf8ToBuffer(str);

const ciphertext = await eccryptoJS.aesCbcEncrypt(iv, key, msg);

const decrypted = await eccryptoJS.aesCbcDecrypt(iv, key, ciphertext);

// decrypted.toString() === str
```

### HMAC

```typescript
import * as eccryptoJS from 'eccrypto-js';

const key = eccryptoJS.randomBytes(32);
const iv = eccryptoJS.randomBytes(16);

const macKey = eccryptoJS.concatBuffers(iv, key);
const dataToMac = eccryptoJS.concatBuffers(iv, key, msg);

const mac = await eccryptoJS.hmacSha256Sign(macKey, dataToMac);

const result = await eccryptoJS.hmacSha256Verify(macKey, dataToMac, mac);

// result will return true if match
```

### SHA2

```typescript
import * as eccryptoJS from 'eccrypto-js';

// SHA256
const str = 'test message to hash';
const msg = eccryptoJS.utf8ToBuffer(str);
const hash = await eccryptoJS.sha256(str);

// SHA512
const str = 'test message to hash';
const msg = eccryptoJS.utf8ToBuffer(str);
const hash = await eccryptoJS.sha512(str);
```

### SHA3

```typescript
import * as eccryptoJS from 'eccrypto-js';

// SHA3
const str = 'test message to hash';
const msg = eccryptoJS.utf8ToBuffer(str);
const hash = await eccryptoJS.sha3(str);

// KECCAK256
const str = 'test message to hash';
const msg = eccryptoJS.utf8ToBuffer(str);
const hash = await eccryptoJS.keccak256(str);
```

### ECDSA

```typescript
import * as eccryptoJS from 'eccrypto-js';

const keyPair = eccryptoJS.generateKeyPair();

const str = 'test message to hash';
const msg = eccryptoJS.utf8ToBuffer(str);
const hash = await eccryptoJS.sha256(str);

const sig = await eccryptoJS.sign(keyPair.privateKey, hash);

await eccryptoJS.verify(keyPair.publicKey, msg, sig);

// verify will throw if signature is BAD
```

### ECDH

```typescript
import * as eccryptoJS from 'eccrypto-js';

const keyPairA = eccryptoJS.generateKeyPair();
const keyPairB = eccryptoJS.generateKeyPair();

const sharedKey1 = await eccryptoJS.derive(
  keyPairA.privateKey,
  keyPairB.publicKey
);

const sharedKey2 = await eccryptoJS.derive(
  keyPairB.privateKey,
  keyPairA.publicKey
);

// sharedKey1.toString('hex') === sharedKey2.toString('hex')
```

### ECIES

```typescript
import * as eccryptoJS from 'eccrypto-js';

const keyPair = eccryptoJS.generateKeyPair();

const str = 'test message to encrypt';
const msg = eccryptoJS.utf8ToBuffer(str);

const encrypted = await eccryptoJS.encrypt(keyPairB.publicKey, msg);

const decrypted = await eccryptoJS.decrypt(keyPairB.privateKey, encrypted);

// decrypted.toString() === str
```

### PBKDF2

```typescript
import * as eccryptoJS from 'eccrypto-js';

const password = 'password';
const buffer = eccryptoJS.utf8ToBuffer(str);

const key = await eccryptoJS.pbkdf2(buffer);

// key.length === 32
```

## React-Native Support

This library is intended for use in a Browser or NodeJS environment, however it is possible to use in a React-Native environment if NodeJS modules are polyfilled with `react-native-crypto`, read more [here](https://github.com/tradle/react-native-crypto).

## License

[MIT License](LICENSE.md)

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