use super::{Randomness, TicketBody, TicketId};
use crate::consensus::slots::Slot;
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use codec::Encode;
pub use crate::core::bandersnatch::{
ring_vrf::{RingProver, RingVerifier, RingVerifierKey, RingVrfSignature},
vrf::{VrfInput, VrfPreOutput, VrfSignData, VrfSignature},
};
pub const RING_SIZE: usize = 1024;
pub type RingContext = crate::core::bandersnatch::ring_vrf::RingContext<RING_SIZE>;
pub fn slot_claim_input(randomness: &Randomness, slot: Slot, epoch: u64) -> VrfInput {
let v = [b"sassafras-ticket", randomness.as_slice(), &slot.to_le_bytes(), &epoch.to_le_bytes()]
.concat();
VrfInput::new(&v[..])
}
pub fn slot_claim_sign_data(randomness: &Randomness, slot: Slot, epoch: u64) -> VrfSignData {
let v = [b"sassafras-ticket", randomness.as_slice(), &slot.to_le_bytes(), &epoch.to_le_bytes()]
.concat();
VrfSignData::new(&v[..], &[])
}
pub fn ticket_id_input(randomness: &Randomness, attempt: u32, epoch: u64) -> VrfInput {
let v =
[b"sassafras-ticket", randomness.as_slice(), &attempt.to_le_bytes(), &epoch.to_le_bytes()]
.concat();
VrfInput::new(&v[..])
}
pub fn ticket_body_sign_data(ticket_body: &TicketBody, ticket_id_input: VrfInput) -> VrfSignData {
VrfSignData { vrf_input: ticket_id_input, aux_data: ticket_body.encode() }
}
pub fn make_ticket_id(preout: &VrfPreOutput) -> TicketId {
let bytes: [u8; 16] = preout.make_bytes()[..16].try_into().unwrap();
u128::from_le_bytes(bytes)
}