Define all coordinator transaction types

This commit is contained in:
Luke Parker
2023-04-11 19:04:53 -04:00
parent 90f67b5e54
commit 2cfee536f6
10 changed files with 372 additions and 0 deletions

View File

@@ -10,9 +10,17 @@ edition = "2021"
[dependencies]
thiserror = "1"
rand_core = { version = "0.6", optional = true }
blake2 = "0.10"
ciphersuite = { package = "ciphersuite", path = "../../crypto/ciphersuite", features = ["ristretto"] }
schnorr = { package = "schnorr-signatures", path = "../../crypto/schnorr" }
tendermint = { package = "tendermint-machine", path = "./tendermint" }
[dev-dependencies]
rand_core = "0.6"
[features]
tests = ["rand_core"]

View File

@@ -9,6 +9,9 @@ pub use transaction::*;
mod block;
pub use block::*;
#[cfg(any(test, feature = "tests"))]
pub mod tests;
/// An item which can be read and written.
pub trait ReadWrite: Sized {
fn read<R: io::Read>(reader: &mut R) -> io::Result<Self>;

View File

@@ -0,0 +1,2 @@
mod transaction;
pub use transaction::*;

View File

@@ -0,0 +1,27 @@
use rand_core::RngCore;
use ciphersuite::{
group::{ff::Field, Group},
Ciphersuite, Ristretto,
};
use schnorr::SchnorrSignature;
use crate::Signed;
pub fn random_signed<R: RngCore>(rng: &mut R) -> Signed {
Signed {
signer: <Ristretto as Ciphersuite>::G::random(&mut *rng),
nonce: u32::try_from(rng.next_u64() >> 32).unwrap(),
signature: SchnorrSignature::<Ristretto> {
R: <Ristretto as Ciphersuite>::G::random(&mut *rng),
s: <Ristretto as Ciphersuite>::F::random(rng),
},
}
}
#[test]
fn serialize_signed() {
use crate::ReadWrite;
let signed = signed(&mut rand_core::OsRng);
assert_eq!(Signed::read::<&[u8]>(&mut signed.serialize().as_ref()).unwrap(), signed);
}