# @bitgo/blake2b

> Blake2b (64-bit version) in pure JavaScript

Latest version **3.2.4** (published 2023-08-04) · ISC license · 0 weekly downloads

## Install

```sh
npm install @bitgo/blake2b
pnpm add @bitgo/blake2b
yarn add @bitgo/blake2b
bun add @bitgo/blake2b
```

## Health

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

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 3.2.4 |
| Published | 2023-08-04 |
| First published | 2021-04-12 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 299.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 395 |
| Author | Emil Bay |
| Maintainers | mohammadalfaiyaz_bitgo, alebusse, zahin-mohammad, mkottaichamy, margueriteblair, islamaminbitgo, pranavjain, joshdk, johntzanakakisbitgo, mmcshinsky-bitgo, bitgoaaron, ericcrosson-bitgo, dhoffmann |

## Links

- npm: https://www.npmjs.com/package/@bitgo/blake2b
- Repository: https://github.com/BitGo/BitGoJS
- Homepage: https://github.com/emilbayes/blake2b#readme
- Issues: https://github.com/emilbayes/blake2b/issues
- npm.io page: https://npm.io/package/@bitgo/blake2b

## Dependencies (2)

- [nanoassert](https://npm.io/package/nanoassert.md) ^2.0.0
- [@bitgo/blake2b-wasm](https://npm.io/package/@bitgo/blake2b-wasm.md) ^3.2.3

## Recent versions

- 3.2.4 (latest) — 2023-08-04
- 3.0.4-rc.0 (rc) — 2022-07-26
- 3.1.0-dev.0 (dev) — 2022-06-18
- 3.2.3 — 2023-07-28
- 3.2.2 — 2023-07-18
- 3.2.1 — 2022-11-29
- 3.2.0 — 2022-10-18
- 3.0.4 — 2022-09-30
- 3.0.3 — 2022-07-19
- 3.0.3-rc.0 — 2022-06-07
- 3.0.2 — 2022-02-08
- 3.0.2-rc.0 — 2021-12-23
- 3.0.1 — 2021-08-10
- 3.0.1-rc.0 — 2021-08-06
- 3.0.0 — 2021-04-22
- … 2 more at https://npm.io/package/@bitgo/blake2b/versions

## README

# `@bitgo/blake2b`

[![Build Status](https://travis-ci.org/emilbayes/blake2b.svg?branch=master)](https://travis-ci.org/emilbayes/blake2b)

> Blake2b (64-bit version) in pure JavaScript

This module is based on @dcposch
[implementation of BLAKE2b](https://github.com/dcposch/blakejs), 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

```js
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

```sh
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:

- Lines [2 - 257](test-vectors.json#L2-L257) are tests for hashing with no key, taken from [BLAKE2 test vectors](https://github.com/BLAKE2/BLAKE2/blob/5cbb39c9ef8007f0b63723e3aea06cd0887e36ad/testvectors/blake2-kat.json)
- Lines [258 - 513](test-vectors.json#L258-L513) are tests for hashing with keys, taken from [BLAKE2 test vectors](https://github.com/BLAKE2/BLAKE2/blob/5cbb39c9ef8007f0b63723e3aea06cd0887e36ad/testvectors/blake2-kat.json)
- Lines [514- 577](test-vectors.json#L514-L577) are tests for hashing with key, salt and personalisation, derived from the [libsodium tests](https://github.com/jedisct1/libsodium/blob/3a9c4c38f7dbe671d91dcfa267c919734b4923df/test/default/generichash3.c)

## License

[ISC](LICENSE)

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