clockhash256_with_domain

Function clockhash256_with_domain 

Source
pub fn clockhash256_with_domain(domain: DomainTag, data: &[u8]) -> [u8; 32]
Expand description

Compute ClockHash-256 with a typed domain tag.

This function provides type-safe domain separation using the DomainTag enum. It automatically converts the enum variant to the appropriate domain bytes and performs domain-separated hashing.

§Arguments

  • domain - The domain tag enum variant specifying the use case
  • data - The data to hash

§Returns

A 32-byte array containing the domain-separated ClockHash-256 hash

§Examples

Type-safe domain hashing:

use clock_hash::{clockhash256_with_domain, DomainTag};

let data = b"important data";

// Type-safe domain specification
let block_hash = clockhash256_with_domain(DomainTag::Block, data);
let merkle_hash = clockhash256_with_domain(DomainTag::Merkle, data);

assert_ne!(block_hash, merkle_hash);

All domain types:

let block_hash = clockhash256_with_domain(DomainTag::Block, data);
let tx_hash = clockhash256_with_domain(DomainTag::Transaction, data);
let merkle_hash = clockhash256_with_domain(DomainTag::Merkle, data);
let nonce_hash = clockhash256_with_domain(DomainTag::Nonce, data);
let rng_hash = clockhash256_with_domain(DomainTag::Rng, data);

// All hashes are guaranteed to be different
let hashes = vec![block_hash, tx_hash, merkle_hash, nonce_hash, rng_hash];
for i in 0..hashes.len() {
    for j in (i+1)..hashes.len() {
        assert_ne!(hashes[i], hashes[j]);
    }
}

§Performance

This function has the same performance characteristics as clockhash256_domain() since it simply delegates to that function after converting the enum to bytes.