# @harmony-js/crypto

> crypto libraries for harmony

Latest version **0.1.56** (published 2020-11-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install @harmony-js/crypto
pnpm add @harmony-js/crypto
yarn add @harmony-js/crypto
bun add @harmony-js/crypto
```

## Health

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

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

Warnings: low downloads; pre 1.0.

Negative: insecure dependencies; abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.56 |
| Published | 2020-11-22 |
| First published | 2019-05-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 11 |
| Unpacked size | 462.1 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| Author | neeboo@firestack.one |
| Maintainers | gupadhyaya, jhwon0820, ghostcorn |

## Links

- npm: https://www.npmjs.com/package/@harmony-js/crypto
- npm.io page: https://npm.io/package/@harmony-js/crypto

## Dependencies (11)

- [uuid](https://npm.io/package/uuid.md) ^3.3.2
- [bip39](https://npm.io/package/bip39.md) ^2.5.0
- [bn.js](https://npm.io/package/bn.js.md) ^4.11.8
- [hdkey](https://npm.io/package/hdkey.md) ^1.1.1
- [aes-js](https://npm.io/package/aes-js.md) ^3.1.2
- [pbkdf2](https://npm.io/package/pbkdf2.md) ^3.0.17
- [js-sha3](https://npm.io/package/js-sha3.md) ^0.8.0
- [elliptic](https://npm.io/package/elliptic.md) ^6.4.1
- [hmac-drbg](https://npm.io/package/hmac-drbg.md) ^1.0.1
- [scrypt-shim](https://npm.io/package/scrypt-shim.md) github:web3-js/scrypt-shim
- [@harmony-js/utils](https://npm.io/package/@harmony-js/utils.md) 0.1.56

## Recent versions

- 0.1.56 (latest) — 2020-11-22
- 0.1.58 (next) — 2022-07-06
- 0.1.41-alpha.1 (canary) — 2020-05-04
- 0.1.55 — 2020-09-29
- 0.1.54 — 2020-09-07
- 0.1.48 — 2020-07-13
- 0.1.45 — 2020-06-06
- 0.1.43 — 2020-05-04
- 0.1.35 — 2019-11-27
- 0.1.34 — 2019-11-18
- 0.1.32 — 2019-10-31
- 0.1.28 — 2019-10-10
- 0.1.27 — 2019-10-10
- 0.1.23 — 2019-09-24
- 0.1.14 — 2019-09-04
- … 49 more at https://npm.io/package/@harmony-js/crypto/versions

## README

# @harmony-js/crypto

This package provides a collection of apis related to address management, kestore, encoding, and encrypt/decrypt.

## Installation

```
npm install @harmony-js/crypto
```

## Usage

```javascript
const {
  encode,
  decode,
  randomBytes,
  toBech32,
  fromBech32,
  HarmonyAddress,
  generatePrivateKey,
  getPubkeyFromPrivateKey,
  getAddressFromPublicKey,
  getAddressFromPrivateKey,
  encryptPhrase,
  decryptPhrase
} = require('@harmony-js/crypto');
const { isPrivateKey, isAddress, isPublicKey } = require('@harmony-js/utils');
```

Address apis
```javascript
const bytes = randomBytes(20);
const addr = new HarmonyAddress(bytes);

console.log(addr.checksum);
console.log(addr.bech32);

console.log(HarmonyAddress.isValidBech32(addr.bech32));
```

RLP apis
```javascript
const encoded = '0x89010101010101010101';
const decoded = '0x010101010101010101';
console.log(encode(decoded));
console.log(decode(encoded));
```

Keystore apis
```javascript
const prv = generatePrivateKey();
const pub = getPubkeyFromPrivateKey(prv);
const addr = getAddressFromPublicKey(pub);
const addrPrv = getAddressFromPrivateKey(prv);
console.log(isPrivateKey(prv));
console.log(isPublicKey(pub));
console.log(isAddress(addr));
console.log(isAddress(addrPrv));
```

Encrypt/decrypt apis
```javascript
const { Wallet } = require('@harmony-js/account');

const myPhrase = new Wallet().newMnemonic();
console.log(myPhrase);
const pwd = '1234';
encryptPhrase(myPhrase, pwd).then((value) => {
  console.log(value);
  decryptPhrase(JSON.parse(value), pwd).then(value => {
    console.log(value);
  });
});
```

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