@bitgo/blake2b

中文文档
3.2.4发布于 2023/08/05ISCCommonJS近 30 天下载 40.3万

Blake2b (64-bit version) in pure JavaScript

原始使用文档
文档目录9 节
  1. Usage
  2. API
  3. var hash = blake2b(outLength, [key], [salt], [personal], [n…
  4. var hash = hash.update(input)
  5. var out = hash.digest(out)
  6. Constants
  7. Install
  8. Test vectors
  9. License

@bitgo/blake2b

Build Status

Blake2b (64-bit version) in pure JavaScript

This module is based on @dcposch implementation of BLAKE2b, with some changes:

  • This module requires you to pass in a out buffer, saving an allocation
  • This module allows you to set the salt and personal parameters
  • This module exports constants for the parameters in libsodium style
  • Uses a WASM version (where it is supported) for massive performance boosts

All credit goes to @dcposch for doing the hard work of porting the implementation from C to JavaScript.

Usage

var blake2b = require('@bitgo/blake2b');

var output = new Uint8Array(64);
var input = Buffer.from('hello world');

console.log('hash:', blake2b(output.length).update(input).digest('hex'));

API

var hash = blake2b(outLength, [key], [salt], [personal], [noAssert = false])

Create a new hash instance, optionally with key, salt and personal. Bypass input assertions by setting noAssert to true.

All parameters must be Uint8Array, Buffer or another object with a compatible API. All parameters must also fulfill the following constraints, or an AssertionError will be thrown (unless noAssert = true):

  • outLength must within the byte ranges defined by the constants below.
  • key is optional, but must within the byte ranges defined by the constants below, if given. This value must be kept secret, and can be used to create prefix-MACs.
  • salt is optional, but must be exactly SALTBYTES, if given. You can use this parameter as a kind of per user id, or local versioning scheme. This value is not required to be secret.
  • personal is optional, but must be exactly PERSONALBYTES, if given. You can use this parameter as a kind of app id, or global versioning scheme. This value is not required to be secret.

var hash = hash.update(input)

Update the hash with new input. Calling this method after .digest will throw an error.

var out = hash.digest(out)

Finalise the the hash and write the digest to out. out must be exactly equal to outLength given in the blake2b method.

Optionally you can pass hex to get the hash as a hex string or no arguments to have the hash return a new Uint8Array with the hash.

Constants

  • blake2b.BYTES_MIN Minimum length of out
  • blake2b.BYTES_MAX Maximum length of out
  • blake2b.BYTES Recommended default length of out
  • blake2b.KEYBYTES_MIN Minimum length of key
  • blake2b.KEYBYTES_MAX Maximum length of key
  • blake2b.KEYBYTES Recommended default length of key
  • blake2b.SALTBYTES Required length of salt
  • blake2b.PERSONALBYTES Required length of personal

Install

npm install @bitgo/blake2b

Test vectors

This repository includes test vectors with {outlen, out, input, key, salt, personal} objects for testing conformance against the spec and other implementations:

License

ISC

版本与发布记录

@bitgo/blake2b 共发布 17 个版本,首次发布于 2021/04/13;过去 12 个月发布了 0 个版本。

版本发布日期距今
3.2.4latest2023/08/053 年前
3.2.32023/07/293 年前
3.2.22023/07/193 年前
3.2.12022/11/303 年前
3.2.02022/10/194 年前
3.0.42022/10/014 年前

其他发布通道:dev → 3.1.0-dev.0,rc → 3.0.4-rc.0。

关于 @bitgo/blake2b 的常见问题

@bitgo/blake2b 是什么?

Blake2b (64-bit version) in pure JavaScript

如何安装 @bitgo/blake2b?

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

@bitgo/blake2b 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/bitgo__blake2b 是否存在。

@bitgo/blake2b 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@bitgo/blake2b 可以商用吗?

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

@bitgo/blake2b 的下载量有多少?

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

@bitgo/blake2b 还在维护吗?

最新版本 3.2.4 发布于 2023/08/05(3 年前);至今共发布 17 个版本,其中过去 12 个月发布了 0 个;首次发布于 2021/04/13。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。