VrfAlgorithm

Trait VrfAlgorithm 

Source
pub trait VrfAlgorithm:
    Clone
    + Send
    + Sync
    + 'static {
    type SecretKey;
    type VerificationKey;
    type Proof;
    type Output;

    const ALGORITHM_NAME: &'static str;
    const SEED_SIZE: usize;
    const SECRET_KEY_SIZE: usize;
    const VERIFICATION_KEY_SIZE: usize;
    const PROOF_SIZE: usize;
    const OUTPUT_SIZE: usize;

    // Required methods
    fn keypair_from_seed(
        seed: &[u8; 32],
    ) -> (Self::SecretKey, Self::VerificationKey);
    fn derive_verification_key(sk: &Self::SecretKey) -> Self::VerificationKey;
    fn prove(sk: &Self::SecretKey, message: &[u8]) -> CryptoResult<Self::Proof>;
    fn verify(
        vk: &Self::VerificationKey,
        proof: &Self::Proof,
        message: &[u8],
    ) -> CryptoResult<Self::Output>;
    fn proof_to_hash(proof: &Self::Proof) -> CryptoResult<Self::Output>;
    fn raw_serialize_verification_key(vk: &Self::VerificationKey) -> &[u8] ;
    fn raw_deserialize_verification_key(
        bytes: &[u8],
    ) -> Option<Self::VerificationKey>;
    fn raw_serialize_proof(proof: &Self::Proof) -> &[u8] ;
    fn raw_deserialize_proof(bytes: &[u8]) -> Option<Self::Proof>;

    // Provided method
    fn hash_verification_key<H: HashAlgorithm>(
        vk: &Self::VerificationKey,
    ) -> Vec<u8>  { ... }
}
Available on crate feature vrf only.
Expand description

Trait for VRF algorithms

This trait provides a unified interface for VRF implementations, matching the structure of Cardano’s VRFAlgorithm type class.

§Associated Types

  • SecretKey: VRF secret key type
  • VerificationKey: VRF public key type
  • Proof: VRF proof type
  • Output: VRF output type (hash)

§Example

use cardano_crypto::vrf::{VrfAlgorithm, VrfDraft03};
use cardano_crypto::hash::{Blake2b256, HashAlgorithm};

let seed = [42u8; 32];
let (sk, vk) = VrfDraft03::keypair_from_seed(&seed);

// Hash the verification key
let vk_hash = VrfDraft03::hash_verification_key::<Blake2b256>(&vk);
assert_eq!(vk_hash.len(), 32);

Required Associated Constants§

Source

const ALGORITHM_NAME: &'static str

Algorithm name

Source

const SEED_SIZE: usize

Seed size in bytes

Source

const SECRET_KEY_SIZE: usize

Secret key size in bytes

Source

const VERIFICATION_KEY_SIZE: usize

Verification key size in bytes

Source

const PROOF_SIZE: usize

Proof size in bytes

Source

const OUTPUT_SIZE: usize

Output size in bytes

Required Associated Types§

Source

type SecretKey

Secret key type

Source

type VerificationKey

Verification key type

Source

type Proof

Proof type

Source

type Output

Output type

Required Methods§

Source

fn keypair_from_seed( seed: &[u8; 32], ) -> (Self::SecretKey, Self::VerificationKey)

Generate keypair from seed

Source

fn derive_verification_key(sk: &Self::SecretKey) -> Self::VerificationKey

Derive verification key from secret key

Source

fn prove(sk: &Self::SecretKey, message: &[u8]) -> CryptoResult<Self::Proof>

Generate a VRF proof

Source

fn verify( vk: &Self::VerificationKey, proof: &Self::Proof, message: &[u8], ) -> CryptoResult<Self::Output>

Verify a VRF proof and return the output

Source

fn proof_to_hash(proof: &Self::Proof) -> CryptoResult<Self::Output>

Convert proof to output hash directly (without verification)

Source

fn raw_serialize_verification_key(vk: &Self::VerificationKey) -> &[u8]

Serialize verification key to raw bytes

Source

fn raw_deserialize_verification_key( bytes: &[u8], ) -> Option<Self::VerificationKey>

Deserialize verification key from raw bytes

Source

fn raw_serialize_proof(proof: &Self::Proof) -> &[u8]

Serialize proof to raw bytes

Source

fn raw_deserialize_proof(bytes: &[u8]) -> Option<Self::Proof>

Deserialize proof from raw bytes

Provided Methods§

Source

fn hash_verification_key<H: HashAlgorithm>( vk: &Self::VerificationKey, ) -> Vec<u8>

Available on crate feature alloc only.

Hash a verification key

This corresponds to hashVerKeyVRF in cardano-base.

§Type Parameters
  • H: The hash algorithm to use

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl VrfAlgorithm for VrfDraft03

Source§

const ALGORITHM_NAME: &'static str = "ECVRF-ED25519-SHA512-Elligator2-Draft03"

Source§

const SEED_SIZE: usize = 32usize

Source§

const SECRET_KEY_SIZE: usize = 64usize

Source§

const VERIFICATION_KEY_SIZE: usize = 32usize

Source§

const PROOF_SIZE: usize = 80usize

Source§

const OUTPUT_SIZE: usize = 64usize

Source§

type SecretKey = [u8; 64]

Source§

type VerificationKey = [u8; 32]

Source§

type Proof = [u8; 80]

Source§

type Output = [u8; 64]