# @walletconnect/crypto

> Isomorphic Cryptography Library for AES, HMAC and SHA2

Latest version **1.1.0** (published 2025-01-24) · MIT license · 0 weekly downloads

## Install

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

## Health

**Score 50/100 (C)** — status: stable.

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

Warnings: low downloads; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2025-01-24 |
| First published | 2021-07-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 238.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 132 |
| Author | WalletConnect, Inc. |
| Maintainers | pedrouid, magiziz, bkrem, nachosan, devceline, gancho_walletconnect, cyberdrk, zoruka, lukaisailovic, enesozturk, chris13524, huxwell |
| Keywords | crypto, cryptography, isomorphic, aes, hmac, sha2 |

## Links

- npm: https://www.npmjs.com/package/@walletconnect/crypto
- Repository: https://github.com/walletconnect/walletconnect-utils
- Issues: https://github.com/walletconnect/walletconnect-utils/issues
- npm.io page: https://npm.io/package/@walletconnect/crypto

## Dependencies (6)

- [tslib](https://npm.io/package/tslib.md) 1.14.1
- [@noble/hashes](https://npm.io/package/@noble/hashes.md) 1.7.0
- [@noble/ciphers](https://npm.io/package/@noble/ciphers.md) 1.2.0
- [@walletconnect/encoding](https://npm.io/package/@walletconnect/encoding.md) ^1.0.2
- [@walletconnect/environment](https://npm.io/package/@walletconnect/environment.md) ^1.0.1
- [@walletconnect/randombytes](https://npm.io/package/@walletconnect/randombytes.md) ^1.0.3

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

- 1.1.0 (latest) — 2025-01-24
- 1.0.3-canary-bnl-1 (canary) — 2025-01-07
- 1.0.0-beta.1 (beta) — 2021-07-26
- 1.0.3 — 2022-11-25
- 1.0.2 — 2022-03-14
- 1.0.1 — 2021-07-29
- 1.0.0 — 2021-07-28

## README

# iso-crypto [![npm version](https://badge.fury.io/js/%40pedrouid%2Fiso-crypto.svg)](https://badge.fury.io/js/%40pedrouid%2Fiso-crypto)

Isomorphic Cryptography Library for AES, HMAC and SHA2

## Description

This library supports AES, HMAC and SHA2 methods through native NodeJS and Browser APIs when available and fallbacks to vanilla javascript are already provided.

## Usage

### RandomBytes

```typescript
import * as isoCrypto from "iso-crypto";

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

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

### AES

```typescript
import * as isoCrypto from "iso-crypto";
import * as encoding from "@walletconnect/encoding";

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

const str = "test message to encrypt";
const msg = encoding.utf8ToArray(str);

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

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

// decrypted === str
```

### HMAC

```typescript
import * as isoCrypto from "iso-crypto";
import * as encoding from "@walletconnect/encoding";

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

const macKey = encoding.concatArrays(iv, key);
const dataToMac = encoding.concatArrays(iv, key, msg);

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

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

// result will return true if match
```

### SHA2

```typescript
import * as isoCrypto from "iso-crypto";
import * as encoding from "@walletconnect/encoding";

// SHA256
const str = "test message to hash";
const msg = encoding.utf8ToArray(str);
const hash = await isoCrypto.sha256(str);

// SHA512
const str = "test message to hash";
const msg = encoding.utf8ToArray(str);
const hash = await isoCrypto.sha512(str);
```

## 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/@walletconnect/crypto · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
