aiken/crypto

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:

Alias

DataHash = Hash<Blake2b_256, Data>

A Hash is nothing more than a ByteArray, but it carries extra information 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 {
  VerificationKey(ByteArray)
  Script(ByteArray)
}

with

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

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

Alias

Hash<alg, a> = ByteArray

A Keccak-256 hash algorithm.

Alias

Script = ByteArray

Alias

ScriptHash = Hash<Blake2b_224, Script>

A SHA2-256 hash algorithm.

A SHA3-256 hash algorithm.

Alias

Signature = ByteArray

Alias

VerificationKey = ByteArray

Alias

VerificationKeyHash = Hash<Blake2b_224, VerificationKey>

Functions

Hashing

blake2b_224(bytes: ByteArray) -> Hash<Blake2b_224, a>

Compute the blake2b-224 hash digest (28 bytes) of some data.

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

Compute the blake2b-256 hash digest (32 bytes) of some data.

keccak_256(bytes: ByteArray) -> Hash<Keccak_256, a>

Compute the keccak-256 hash digest (32 bytes) of some data.

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

Compute the sha2-256 hash digest (32 bytes) of some data.

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

Compute the sha3-256 hash digest (32 bytes) of some data.

Verifying signatures

verify_ecdsa_signature(
  key: VerificationKey,
  msg: ByteArray,
  sig: Signature,
) -> Bool

Verify an ECDCA signature (over secp256k1) using the given verification key. Returns True when the signature is valid.

verify_ed25519_signature(
  key: VerificationKey,
  msg: ByteArray,
  sig: Signature,
) -> Bool

Verify an Ed25519 signature using the given verification key. Returns True when the signature is valid.

verify_schnorr_signature(
  key: VerificationKey,
  msg: ByteArray,
  sig: Signature,
) -> Bool

Verify a Schnorr signature (over secp256k1) using the given verification key. Returns True when the signature is valid.

Search Document