Skip to main content
@tevm/voltaire
@tevm/voltaire / crypto/Blake2

crypto/Blake2

Variables

Blake2

const Blake2: (input, outputLength?) => Blake2Hash & object = Blake2Hash
Defined in: src/crypto/Blake2/Blake2.js:51

Type Declaration

from()
from: (input, outputLength?) => Blake2Hash
Hash input with BLAKE2b (constructor pattern) Auto-detects input type and hashes accordingly:
  • Uint8Array: hash directly
  • string: UTF-8 encode then hash
Parameters
input
Data to hash string | Uint8Array<ArrayBufferLike>
outputLength?
number = 64 Output length in bytes (1-64, default 64)
Returns
Blake2Hash BLAKE2b hash
See
https://voltaire.tevm.sh/crypto/blake2 for crypto documentation
Since
0.0.0
Throws
If outputLength is invalid
Example
import { Blake2Hash } from './crypto/Blake2/index.js';

const hash1 = Blake2Hash.from("hello");              // String, 64 bytes
const hash2 = Blake2Hash.from("hello", 32);          // String, 32 bytes
const hash3 = Blake2Hash.from(uint8array);           // Bytes, 64 bytes
const hash4 = Blake2Hash.from(uint8array, 48);       // Bytes, 48 bytes
fromString()
fromString: (str, outputLength?) => Blake2Hash = hashString
Hash string with BLAKE2b (convenience function)
Parameters
str
string Input string to hash
outputLength?
number = 64 Output length in bytes (1-64, default 64)
Returns
Blake2Hash BLAKE2b hash
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If outputLength is invalid
Example
import * as Blake2 from './crypto/Blake2/index.js';
const hash = Blake2.hashString("hello world");
const hash48 = Blake2.hashString("hello world", 48);
hash()
hash: (data, outputLength?) => Blake2Hash
Hash data with BLAKE2b
Parameters
data
Input data to hash (Uint8Array or string) string | Uint8Array<ArrayBufferLike>
outputLength?
number = 64 Output length in bytes (1-64, default 64)
Returns
Blake2Hash BLAKE2b hash
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If outputLength is invalid
Example
import * as Blake2 from './crypto/Blake2/index.js';
const hash = Blake2.hash(new Uint8Array([1, 2, 3]));
const hash32 = Blake2.hash("hello", 32);
hashString()
hashString: (str, outputLength?) => Blake2Hash
Hash string with BLAKE2b (convenience function)
Parameters
str
string Input string to hash
outputLength?
number = 64 Output length in bytes (1-64, default 64)
Returns
Blake2Hash BLAKE2b hash
See
https://voltaire.tevm.sh/crypto for crypto documentation
Since
0.0.0
Throws
If outputLength is invalid
Example
import * as Blake2 from './crypto/Blake2/index.js';
const hash = Blake2.hashString("hello world");
const hash48 = Blake2.hashString("hello world", 48);
SIZE
SIZE: number

Deprecated

Use Blake2Hash instead Blake2 alias maintained for backward compatibility

SIZE

const SIZE: 64 = 64
Defined in: src/crypto/Blake2/Blake2HashType.ts:23

Functions

compress()

compress(input): Uint8Array<ArrayBufferLike>
Defined in: src/crypto/Blake2/compress.js:41 BLAKE2b F compression function (EIP-152 format)

Parameters

input
Uint8Array<ArrayBufferLike> 213-byte input in EIP-152 format

Returns

Uint8Array<ArrayBufferLike> 64-byte output (updated state)

Throws

If input length is not 213 bytes

Example

import { compress } from './crypto/Blake2/compress.js';

const input = new Uint8Array(213);
// ... fill input with rounds, h, m, t, f
const output = compress(input);

from()

from(input, outputLength?): Blake2Hash
Defined in: src/crypto/Blake2/from.js:27 Hash input with BLAKE2b (constructor pattern) Auto-detects input type and hashes accordingly:
  • Uint8Array: hash directly
  • string: UTF-8 encode then hash

Parameters

input
Data to hash string | Uint8Array<ArrayBufferLike>
outputLength?
number = 64 Output length in bytes (1-64, default 64)

Returns

Blake2Hash BLAKE2b hash

See

https://voltaire.tevm.sh/crypto/blake2 for crypto documentation

Since

0.0.0

Throws

If outputLength is invalid

Example

import { Blake2Hash } from './crypto/Blake2/index.js';

const hash1 = Blake2Hash.from("hello");              // String, 64 bytes
const hash2 = Blake2Hash.from("hello", 32);          // String, 32 bytes
const hash3 = Blake2Hash.from(uint8array);           // Bytes, 64 bytes
const hash4 = Blake2Hash.from(uint8array, 48);       // Bytes, 48 bytes

hash()

hash(data, outputLength?): Blake2Hash
Defined in: src/crypto/Blake2/hash.js:19 Hash data with BLAKE2b

Parameters

data
Input data to hash (Uint8Array or string) string | Uint8Array<ArrayBufferLike>
outputLength?
number = 64 Output length in bytes (1-64, default 64)

Returns

Blake2Hash BLAKE2b hash

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

If outputLength is invalid

Example

import * as Blake2 from './crypto/Blake2/index.js';
const hash = Blake2.hash(new Uint8Array([1, 2, 3]));
const hash32 = Blake2.hash("hello", 32);

hashString()

hashString(str, outputLength?): Blake2Hash
Defined in: src/crypto/Blake2/hashString.js:19 Hash string with BLAKE2b (convenience function)

Parameters

str
string Input string to hash
outputLength?
number = 64 Output length in bytes (1-64, default 64)

Returns

Blake2Hash BLAKE2b hash

See

https://voltaire.tevm.sh/crypto for crypto documentation

Since

0.0.0

Throws

If outputLength is invalid

Example

import * as Blake2 from './crypto/Blake2/index.js';
const hash = Blake2.hashString("hello world");
const hash48 = Blake2.hashString("hello world", 48);

References

Blake2Hash

Re-exports Blake2Hash