aiken/hash

This module defines Hash, a self-documenting type-alias with a phantom-type for readability.

On-chain, any hash digest value is represented as a plain ‘ByteArray’. Though in practice, hashes come from different sources and have different semantics.

Hence, while this type-alias doesn’t provide any strong type-guarantees, it helps writing functions signatures with more meaningful types than mere ‘ByteArray’.

Compare for example:

pub type Credential {
  VerificationKeyCredential(ByteArray)
  ScriptCredential(ByteArray)
}

with

pub type Credential {
  VerificationKeyCredential(Hash<Blake2b_224, VerificationKey>)
  ScriptCredential(Hash<Blake2b_224, Script>)
}

Both are strictly equivalent, but the second reads much better.

Types

A blake2b-224 hash algorithm.

Typically used for:

Note: there’s no function to calculate blake2b-224 hash digests on-chain.

A blake2b-256 hash algorithm.

Typically used for:

A Hash is nothing more than a ByteArray, but it carries extra information for readability.

Alias

Hash<alg, a> = ByteArray

A SHA2-256 hash algorithm.

A SHA3-256 hash algorithm.

Functions

blake2b_256(bytes: ByteArray) -> Hash<Blake2b_256, a>

Compute the blake2b-256 hash digest of some data.

sha2_256(bytes: ByteArray) -> Hash<Sha2_256, a>

Compute the sha2-256 hash digest of some data.

sha3_256(bytes: ByteArray) -> Hash<Sha3_256, a>

Compute the sha3-256 hash digest of some data.

Search Document