Skip to main content
Blake2b with variable output length. Used in various protocols and the EVM BLAKE2F precompile.
import { Blake2Service, Blake2Live } from 'voltaire-effect/crypto'
import { Effect } from 'effect'

const result = await Effect.runPromise(
  Effect.gen(function* () {
    const blake2 = yield* Blake2Service
    const hash64 = yield* blake2.hash(data)           // 64 bytes default
    const hash32 = yield* blake2.hash(data, 32)       // 32 bytes
    return { hash64, hash32 }
  }).pipe(Effect.provide(Blake2Live))
)

Testing

import { Blake2Test } from 'voltaire-effect/crypto'
myProgram.pipe(Effect.provide(Blake2Test))
// Returns zero-filled array of requested length

Interface

interface Blake2ServiceShape {
  readonly hash: (data: Uint8Array, outputLength?: number) => Effect.Effect<Blake2Hash>
}