@exodus/crypto

中文文档
1.0.0-rc.34发布于 2025/12/04MITTypeScriptES Module近 30 天下载 5.6万

Reusable cryptography primitives, for browser/Node.js/Electron/React Native

原始使用文档
文档目录6 节
  1. A note about React Native
  2. Regular API
  3. randomBytes(size)
  4. randomUUID()
  5. await hash(type, arg[, form])
  6. await hmac(type, secret, arg[, form])

@exodus/crypto

Reusable cryptography primitives, for browser/Node.js/Electron/React Native

For hashes not implemented by the platform, requires @noble/hashes dependency

A note about React Native

  • On React Native, methods that use randomness expect globalThis.crypto.getRandomValues to work. That can be polyfilled with require('react-native-get-random-values').

  • Buffer should be polyfilled (either globally or via a bundler).

Regular API

randomBytes(size)

import { randomBytes } from '@exodus/crypto/randomBytes'

Returns a Buffer instance of length size filled from CSPRNG.

On non-Node.js environments, requires polyfilled Buffer.

randomUUID()

import { randomUUID } from '@exodus/crypto/randomUUID'

Returns a random UUID (version 4, variant 1), filled from CSPRNG.

This contains 122 bits of randomness.

Compatible with Crypto.randomUUID().

await hash(type, arg[, form])

import { hash } from '@exodus/crypto/hash'

Hashes arg using the hash specified as type.

Returns the result as encoded as form (e.g. 'hex') or as a Buffer instance if form is not specified.

E.g.:

> await hash('sha256', 'abc', 'hex')
'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
> await hash('sha256', Buffer.from('abc'), 'hex')
'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
> await hash('sha256', new Uint8Array([97, 98, 99]), 'hex')
'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'
await hash('sha256', Buffer.from('abc'))
Buffer(32) [186, 120, 22, 191, 143, 1, 207, 234, 65, 65, 64, 222, 93, 174, 34, 35, 176, 3, 97, 163, 150, 23, 122, 156, 180, 16, 255, 97, 242, 0, 21, 173]

await hmac(type, secret, arg[, form])

import { hmac } from '@exodus/crypto/hmac'

HMAC implementation, usage similar to hash().

Empty secret values are not supported.

版本与发布记录

@exodus/crypto 共发布 35 个版本,首次发布于 2022/06/01;过去 12 个月发布了 3 个版本。

版本发布日期距今
1.0.0-rc.34latest2025/12/0411 个月前
1.0.0-rc.332025/11/2711 个月前
1.0.0-rc.322025/11/1711 个月前
1.0.0-rc.312025/10/171.1 年前
1.0.0-rc.302025/10/151.1 年前
1.0.0-rc.292025/09/291.1 年前

关于 @exodus/crypto 的常见问题

@exodus/crypto 是什么?

Reusable cryptography primitives, for browser/Node.js/Electron/React Native

如何安装 @exodus/crypto?

在项目目录运行 npm install @exodus/crypto,或使用 pnpm add / yarn add / bun add。

@exodus/crypto 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@exodus/crypto 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@exodus/crypto 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js ^20.19.0 || >=22.13.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@exodus/crypto 可以商用吗?

@exodus/crypto 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@exodus/crypto 的下载量有多少?

根据 npm 官方下载统计,@exodus/crypto 在 2026/10/14 – 2026/11/12 这 30 天内被下载 56,083 次,日均约 1,869 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@exodus/crypto 还在维护吗?

最新版本 1.0.0-rc.34 发布于 2025/12/04(11 个月前);至今共发布 35 个版本,其中过去 12 个月发布了 3 个;首次发布于 2022/06/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。