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> ⓘ { ... }
}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 typeVerificationKey: VRF public key typeProof: VRF proof typeOutput: 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§
Sourceconst ALGORITHM_NAME: &'static str
const ALGORITHM_NAME: &'static str
Algorithm name
Sourceconst SECRET_KEY_SIZE: usize
const SECRET_KEY_SIZE: usize
Secret key size in bytes
Sourceconst VERIFICATION_KEY_SIZE: usize
const VERIFICATION_KEY_SIZE: usize
Verification key size in bytes
Sourceconst PROOF_SIZE: usize
const PROOF_SIZE: usize
Proof size in bytes
Sourceconst OUTPUT_SIZE: usize
const OUTPUT_SIZE: usize
Output size in bytes
Required Associated Types§
Sourcetype VerificationKey
type VerificationKey
Verification key type
Required Methods§
Sourcefn keypair_from_seed(
seed: &[u8; 32],
) -> (Self::SecretKey, Self::VerificationKey)
fn keypair_from_seed( seed: &[u8; 32], ) -> (Self::SecretKey, Self::VerificationKey)
Generate keypair from seed
Sourcefn derive_verification_key(sk: &Self::SecretKey) -> Self::VerificationKey
fn derive_verification_key(sk: &Self::SecretKey) -> Self::VerificationKey
Derive verification key from secret key
Sourcefn prove(sk: &Self::SecretKey, message: &[u8]) -> CryptoResult<Self::Proof>
fn prove(sk: &Self::SecretKey, message: &[u8]) -> CryptoResult<Self::Proof>
Generate a VRF proof
Sourcefn verify(
vk: &Self::VerificationKey,
proof: &Self::Proof,
message: &[u8],
) -> CryptoResult<Self::Output>
fn verify( vk: &Self::VerificationKey, proof: &Self::Proof, message: &[u8], ) -> CryptoResult<Self::Output>
Verify a VRF proof and return the output
Sourcefn proof_to_hash(proof: &Self::Proof) -> CryptoResult<Self::Output>
fn proof_to_hash(proof: &Self::Proof) -> CryptoResult<Self::Output>
Convert proof to output hash directly (without verification)
Sourcefn raw_serialize_verification_key(vk: &Self::VerificationKey) -> &[u8] ⓘ
fn raw_serialize_verification_key(vk: &Self::VerificationKey) -> &[u8] ⓘ
Serialize verification key to raw bytes
Sourcefn raw_deserialize_verification_key(
bytes: &[u8],
) -> Option<Self::VerificationKey>
fn raw_deserialize_verification_key( bytes: &[u8], ) -> Option<Self::VerificationKey>
Deserialize verification key from raw bytes
Sourcefn raw_serialize_proof(proof: &Self::Proof) -> &[u8] ⓘ
fn raw_serialize_proof(proof: &Self::Proof) -> &[u8] ⓘ
Serialize proof to raw bytes
Sourcefn raw_deserialize_proof(bytes: &[u8]) -> Option<Self::Proof>
fn raw_deserialize_proof(bytes: &[u8]) -> Option<Self::Proof>
Deserialize proof from raw bytes
Provided Methods§
Sourcefn hash_verification_key<H: HashAlgorithm>(
vk: &Self::VerificationKey,
) -> Vec<u8> ⓘ
Available on crate feature alloc only.
fn hash_verification_key<H: HashAlgorithm>( vk: &Self::VerificationKey, ) -> Vec<u8> ⓘ
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.