# @thirdweb-dev/crypto

> thirdweb crypto

Latest version **0.2.6** (published 2024-05-10) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @thirdweb-dev/crypto
pnpm add @thirdweb-dev/crypto
yarn add @thirdweb-dev/crypto
bun add @thirdweb-dev/crypto
```

## Health

**Score 45/100 (D)** — status: abandoned.

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

Warnings: low downloads; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.2.6 |
| Published | 2024-05-10 |
| First published | 2023-11-15 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=18 |
| Dependencies | 2 |
| Unpacked size | 105.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 639 |
| Author | thirdweb eng |
| Maintainers | furqantw, yash90, krishang, jakeloo, joaquim-verges, jnsdls |

## Links

- npm: https://www.npmjs.com/package/@thirdweb-dev/crypto
- Repository: https://github.com/thirdweb-dev/js.git#main
- Homepage: https://github.com/thirdweb-dev/js/tree/main#readme
- Issues: https://github.com/thirdweb-dev/js/issues
- npm.io page: https://npm.io/package/@thirdweb-dev/crypto

## Dependencies (2)

- [js-sha3](https://npm.io/package/js-sha3.md) ^0.9.3
- [@noble/hashes](https://npm.io/package/@noble/hashes.md) ^1.4.0

## Recent versions

- 0.2.6 (latest) — 2024-05-10
- 0.2.7-nightly-d974db533a5a2e241df7743b201d730c90cda0d7-20240627000603 (nightly) — 2024-06-27
- 0.0.0-dev-f95024147f012f9b752b6cd2215199dca870c39d-20240511003159 (dev) — 2024-05-11
- 0.2.7-nightly-7be7b6ff84b83ee587d369f4e8da5a2d9f80b8c2-20240626221701 — 2024-06-26
- 0.2.7-nightly-3979ff0238ae9b3a0a216e6c2d562eb7206a9fe8-20240626085813 — 2024-06-26
- 0.2.7-nightly-e7434891354f351d2a399daebdddae9cf1fc817b-20240623000619 — 2024-06-23
- 0.2.7-nightly-fe775166d40fdd50faaa8d6da3fcd624f9a450ed-20240622000610 — 2024-06-22
- 0.2.7-nightly-d320777eea5404f596aa39b2b49b5165d3e1959a-20240621000551 — 2024-06-21
- 0.2.7-nightly-fab5cd43bed972b0a3f70f0f39a790349672ba72-20240620192731 — 2024-06-20
- 0.0.0-dev-bd03ffef9e57f12d9ceb57fa26c4c56781f381db-20240510221023 — 2024-05-10
- 0.2.6-nightly-ad24d83b5123f76b30268a755ff739a79f29f4af-20240510215849 — 2024-05-10
- 0.2.6-nightly-9d410c6a5409848fa6c7cc4f1c0fc6ec3a6fa6e8-20240510213648 — 2024-05-10
- 0.2.6-nightly-02c03196ad38de888ff86311c68fa010018bda60-20240510212518 — 2024-05-10
- 0.2.5 — 2024-04-07
- 0.2.5-nightly-ebdfb571c957386fd0fb97647f364bba3c82769c-20240407210240 — 2024-04-07
- … 38 more at https://npm.io/package/@thirdweb-dev/crypto/versions

## README

<p align="center">
<br />
<a href="https://thirdweb.com"><img src="https://github.com/thirdweb-dev/js/blob/main/legacy_packages/sdk/logo.svg?raw=true" width="200" alt=""/></a>
<br />
</p>
<h1 align="center">thirdweb crypto</h1>
<p align="center">
<a href="https://www.npmjs.com/package/@thirdweb-dev/crypto"><img src="https://img.shields.io/npm/v/@thirdweb-dev/crypto?color=red&label=npm&logo=npm" alt="npm version"/></a>
<a href="https://github.com/thirdweb-dev/js/actions/workflows/build-test-lint.yml"><img alt="Build Status" src="https://github.com/thirdweb-dev/js/actions/workflows/build-test-lint.yml/badge.svg"/></a>
<a href="https://discord.gg/thirdweb"><img alt="Join our Discord!" src="https://img.shields.io/discord/834227967404146718.svg?color=7289da&label=discord&logo=discord&style=flat"/></a>

</p>
<p align="center"><strong>Secure, performant and cross-platform cryptography methods commonly used across other thirdweb packages.</strong></p>
<br />

## Installation

```bash
npm install @thirdweb-dev/crypto
```

## Available methods

### Encryption

| method                                       | use case                                                                                              | return type       | underlying technology |
| -------------------------------------------- | ----------------------------------------------------------------------------------------------------- | ----------------- | --------------------- |
| `aesEncrypt(<plaintext>, <password>)`        | Encrypts a string/Uint8Array with AES-GCM                                                             | `Promise<string>` | `WebCrypto` (AES-GCM) |
| `aesDecrypt(<ciphertext>, <password>)`       | Decrypts a value encrypted via `aesEncrypt`                                                           | `Promise<string>` | `WebCrypto` (AES-GCM) |
| `aesDecryptCompat(<ciphertext>, <password>)` | Same as `aesDecrypt` but also supports values encrypted via `crypto-js` (for backwards compatibility) | `Promise<string>` | `WebCrypto` (AES-GCM) |

### Hashing

| method                              | use case                                                        | return type           | underlying technology |
| ----------------------------------- | --------------------------------------------------------------- | --------------------- | --------------------- |
| `sha256(<value>)`                   | Hashes a string/Uint8Array with SHA256                          | `Promise<Uint8Array>` | `WebCrypto`           |
| `sha256Hex(<value>)`                | Same as `sha256` but reruns as hex string                       | `Promise<string>`     | `WebCrypto`           |
| `sha256Sync(<value>)`               | Same as `sha256` but synchronous                                | `Uint8Array`          | `@noble/hashes`       |
| `sha256SyncHex(<value>)`            | Same as `sha256Sync` but reruns as hex string                   | `string`              | `@noble/hashes`       |
| `keccak256Sync(<value>)`            | Hashes a string/Uint8Array with Keccak256                       | `Uint8Array`          | `js-sha3`             |
| `keccak256SyncHex(<value>)`         | Same as `keccak256Sync` but returns as hex string               | `string`              | `js-sha3`             |
| `keccak256SyncHexPrefixed(<value>)` | Same as `keccak256Sync` but returns as `0x` prefixed hex string | `0x${string}`         | `js-sha3`             |

## Initial Benchmarks

#### sha256 -> Uint8Array

```bash
┌──────────────────────────────┬─────────┬────────────────────┬────────┬─────────┐
│          Task Name           │ ops/sec │ Average Time (ns)  │ Margin │ Samples │
├──────────────────────────────┼─────────┼────────────────────┼────────┼─────────┤
│ @thirdweb-dev/crypto (async) │ 112,929 │ 8855.08539999982   │ ±1.37% │ 100000  │
│ @thirdweb-dev/crypto (sync)  │ 55,004  │ 18180.482820000594 │ ±1.02% │ 100000  │
│ crypto-js (sync)             │ 19,213  │ 52047.35353999857  │ ±0.25% │ 100000  │
└──────────────────────────────┴─────────┴────────────────────┴────────┴─────────┘
```

#### sha256 -> hex

```bash
┌──────────────────────────────┬─────────┬────────────────────┬────────┬─────────┐
│          Task Name           │ ops/sec │ Average Time (ns)  │ Margin │ Samples │
├──────────────────────────────┼─────────┼────────────────────┼────────┼─────────┤
│ @thirdweb-dev/crypto (async) │ 100,845 │ 9916.125730001713  │ ±1.24% │ 100000  │
│ @thirdweb-dev/crypto (sync)  │ 53,751  │ 18604.047449997142 │ ±0.92% │ 100000  │
│ crypto-js (sync)             │ 19,077  │ 52419.03465000334  │ ±0.24% │ 100000  │
└──────────────────────────────┴─────────┴────────────────────┴────────┴─────────┘
```

#### keccack256 -> Uint8Array

```bash
┌──────────────────────┬─────────┬────────────────────┬────────┬─────────┐
│      Task Name       │ ops/sec │ Average Time (ns)  │ Margin │ Samples │
├──────────────────────┼─────────┼────────────────────┼────────┼─────────┤
│ @thirdweb-dev/crypto │ 72,533  │ 13786.719900000808 │ ±0.31% │ 100000  │
│ ethers@v5            │ 71,891  │ 13909.94663000107  │ ±0.33% │ 100000  │
│ @noble/hashes        │ 27,244  │ 36704.73226000136  │ ±0.19% │ 100000  │
│ viem                 │ 27,115  │ 36879.07953999698  │ ±0.26% │ 100000  │
└──────────────────────┴─────────┴────────────────────┴────────┴─────────┘
```

#### keccack256 -> hex

```bash
┌──────────────────────┬─────────┬───────────────────┬────────┬─────────┐
│      Task Name       │ ops/sec │ Average Time (ns) │ Margin │ Samples │
├──────────────────────┼─────────┼───────────────────┼────────┼─────────┤
│ @thirdweb-dev/crypto │ 42,947  │ 23284.22780000266 │ ±0.23% │ 100000  │
│ ethers@5             │ 35,568  │ 28114.98005000045 │ ±0.42% │ 100000  │
│ @noble/hashes        │ 15,149  │ 66009.80448000187 │ ±0.26% │ 100000  │
│ viem                 │ 15,217  │ 65714.15843999518 │ ±0.25% │ 100000  │
└──────────────────────┴─────────┴───────────────────┴────────┴─────────┘
```

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