use alloc::vec::Vec;
use dusk_bls12_381::BlsScalar;
use dusk_bls12_381_sign::PublicKey;
use dusk_bytes::Serializable;
use dusk_pki::StealthAddress;
const ALLOW_MESSAGE_SIZE: usize = u64::SIZE + PublicKey::SIZE;
const STAKE_MESSAGE_SIZE: usize = u64::SIZE + u64::SIZE;
const WITHDRAW_MESSAGE_SIZE: usize =
u64::SIZE + StealthAddress::SIZE + BlsScalar::SIZE;
#[must_use]
pub fn allow_signature_message(
counter: u64,
staker: &PublicKey,
) -> [u8; ALLOW_MESSAGE_SIZE] {
let mut bytes = [0u8; ALLOW_MESSAGE_SIZE];
bytes[..u64::SIZE].copy_from_slice(&counter.to_bytes());
bytes[u64::SIZE..].copy_from_slice(&staker.to_bytes());
bytes
}
#[must_use]
pub fn stake_signature_message(
counter: u64,
value: u64,
) -> [u8; STAKE_MESSAGE_SIZE] {
let mut bytes = [0u8; STAKE_MESSAGE_SIZE];
bytes[..u64::SIZE].copy_from_slice(&counter.to_bytes());
bytes[u64::SIZE..].copy_from_slice(&value.to_bytes());
bytes
}
pub fn unstake_signature_message<T>(counter: u64, note: T) -> Vec<u8>
where
T: AsRef<[u8]>,
{
let mut vec = Vec::new();
vec.extend_from_slice(&counter.to_bytes());
vec.extend_from_slice(note.as_ref());
vec
}
#[must_use]
pub fn withdraw_signature_message(
counter: u64,
address: StealthAddress,
nonce: BlsScalar,
) -> [u8; WITHDRAW_MESSAGE_SIZE] {
let mut bytes = [0u8; WITHDRAW_MESSAGE_SIZE];
bytes[..u64::SIZE].copy_from_slice(&counter.to_bytes());
bytes[u64::SIZE..u64::SIZE + StealthAddress::SIZE]
.copy_from_slice(&address.to_bytes());
bytes[u64::SIZE + StealthAddress::SIZE..]
.copy_from_slice(&nonce.to_bytes());
bytes
}