diff --git a/Cargo.lock b/Cargo.lock index 2e9df452af..d1f0ee3e15 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1317,7 +1317,7 @@ dependencies = [ "console-subscriber 0.3.0", "dashmap", "derivative", - "jf-signature", + "jf-signature 0.1.0", "lazy_static", "local-ip-address", "parking_lot", @@ -1338,7 +1338,7 @@ dependencies = [ "async-std", "cdn-proto", "clap", - "jf-signature", + "jf-signature 0.1.0", "parking_lot", "rand 0.8.5", "tokio", @@ -1354,7 +1354,7 @@ dependencies = [ "async-std", "cdn-proto", "clap", - "jf-signature", + "jf-signature 0.1.0", "tokio", "tracing", "tracing-subscriber 0.3.18", @@ -1371,7 +1371,7 @@ dependencies = [ "capnp", "capnpc", "derivative", - "jf-signature", + "jf-signature 0.1.0", "kanal", "lazy_static", "mnemonic", @@ -3105,7 +3105,7 @@ dependencies = [ "hotshot-task", "hotshot-task-impls", "hotshot-types", - "jf-signature", + "jf-signature 0.2.0", "libp2p-identity", "libp2p-networking", "lru 0.12.5", @@ -3299,7 +3299,7 @@ dependencies = [ "hotshot-types", "jf-crhf", "jf-rescue", - "jf-signature", + "jf-signature 0.2.0", "jf-utils", "rand_chacha 0.3.1", "serde", @@ -3341,7 +3341,7 @@ dependencies = [ "hotshot-builder-api", "hotshot-task", "hotshot-types", - "jf-signature", + "jf-signature 0.2.0", "jf-vid", "lru 0.12.5", "rand 0.8.5", @@ -3385,7 +3385,7 @@ dependencies = [ "hotshot-task-impls", "hotshot-types", "itertools 0.13.0", - "jf-signature", + "jf-signature 0.2.0", "jf-vid", "lru 0.12.5", "portpicker", @@ -3435,7 +3435,7 @@ dependencies = [ "ethereum-types", "futures", "jf-pcs", - "jf-signature", + "jf-signature 0.2.0", "jf-utils", "jf-vid", "lazy_static", @@ -4250,6 +4250,35 @@ dependencies = [ "zeroize", ] +[[package]] +name = "jf-signature" +version = "0.2.0" +source = "git+https://github.com/EspressoSystems/jellyfish?tag=jf-signature-v0.2.0#ca160ce3452b560cad512b750a742a87c48c5881" +dependencies = [ + "ark-bls12-381", + "ark-bn254", + "ark-ec", + "ark-ff", + "ark-serialize", + "ark-std", + "blst", + "derivative", + "digest 0.10.7", + "displaydoc", + "hashbrown 0.14.5", + "itertools 0.12.1", + "jf-crhf", + "jf-relation", + "jf-rescue", + "jf-utils", + "num-bigint", + "num-traits", + "serde", + "sha3", + "tagged-base64", + "zeroize", +] + [[package]] name = "jf-utils" version = "0.4.4" diff --git a/Cargo.toml b/Cargo.toml index 8d9a9ca841..854fc46fd4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -61,7 +61,7 @@ derive_more = { version = "1.0", features = ["from"] } futures = { version = "0.3", default-features = false } jf-crhf = { version = "0.1.0", git = "https://github.com/EspressoSystems/jellyfish", tag = "0.4.5" } jf-vid = { version = "0.1.0", git = "https://github.com/EspressoSystems/jellyfish", tag = "0.4.5" } -jf-signature = { version = "0.1.0", git = "https://github.com/EspressoSystems/jellyfish", tag = "0.4.5" } +jf-signature = { git = "https://github.com/EspressoSystems/jellyfish", tag = "jf-signature-v0.2.0" } jf-rescue = { version = "0.1.0", git = "https://github.com/EspressoSystems/jellyfish", tag = "0.4.5" } jf-pcs = { version = "0.1.0", git = "https://github.com/EspressoSystems/jellyfish", tag = "0.4.5" } jf-utils = { version = "0.4.4", git = "https://github.com/espressosystems/jellyfish", tag = "0.4.5" } diff --git a/crates/examples/infra/mod.rs b/crates/examples/infra/mod.rs index 8d8bf4d3b7..7fbae5db22 100755 --- a/crates/examples/infra/mod.rs +++ b/crates/examples/infra/mod.rs @@ -258,9 +258,6 @@ pub fn read_orchestrator_init_config() -> (NetworkConfig( config_file: &str, @@ -273,11 +270,6 @@ pub fn load_config_from_file( let mut config: NetworkConfig = config_toml.into(); - // my_own_validator_config would be best to load from file, - // but its type is too complex to load so we'll generate it from seed now. - // Also this function is only used for orchestrator initialization now, so this value doesn't matter - config.config.my_own_validator_config = - ValidatorConfig::generated_from_seed_indexed(config.seed, config.node_index, 1, true); // initialize it with size for better assignment of peers' config config.config.known_nodes_with_stake = vec![PeerConfig::default(); config.config.num_nodes_with_stake.get() as usize]; @@ -357,6 +349,7 @@ pub trait RunDa< /// Initializes networking, returns self async fn initialize_networking( config: NetworkConfig, + validator_config: ValidatorConfig, libp2p_advertise_address: Option, ) -> Self; @@ -371,10 +364,11 @@ pub trait RunDa< .expect("Couldn't generate genesis block"); let config = self.config(); + let validator_config = self.validator_config(); // Get KeyPair for certificate Aggregation - let pk = config.config.my_own_validator_config.public_key.clone(); - let sk = config.config.my_own_validator_config.private_key.clone(); + let pk = validator_config.public_key.clone(); + let sk = validator_config.private_key.clone(); let network = self.network(); @@ -600,6 +594,9 @@ pub trait RunDa< /// Returns the config for this run fn config(&self) -> NetworkConfig; + + /// Returns the validator config with private signature keys for this run. + fn validator_config(&self) -> ValidatorConfig; } // Push CDN @@ -608,6 +605,8 @@ pub trait RunDa< pub struct PushCdnDaRun { /// The underlying configuration config: NetworkConfig, + /// The private validator config + validator_config: ValidatorConfig, /// The underlying network network: PushCdnNetwork, } @@ -636,20 +635,18 @@ where { async fn initialize_networking( config: NetworkConfig, + validator_config: ValidatorConfig, _libp2p_advertise_address: Option, ) -> PushCdnDaRun { - // Get our own key - let key = config.config.my_own_validator_config.clone(); - // Convert to the Push-CDN-compatible type let keypair = KeyPair { - public_key: WrappedSignatureKey(key.public_key), - private_key: key.private_key, + public_key: WrappedSignatureKey(validator_config.public_key.clone()), + private_key: validator_config.private_key.clone(), }; // See if we should be DA, subscribe to the DA topic if so let mut topics = vec![CdnTopic::Global]; - if config.config.my_own_validator_config.is_da { + if validator_config.is_da { topics.push(CdnTopic::Da); } @@ -668,7 +665,11 @@ where // Wait for the network to be ready network.wait_for_ready().await; - PushCdnDaRun { config, network } + PushCdnDaRun { + config, + validator_config, + network, + } } fn network(&self) -> PushCdnNetwork { @@ -678,6 +679,10 @@ where fn config(&self) -> NetworkConfig { self.config.clone() } + + fn validator_config(&self) -> ValidatorConfig { + self.validator_config.clone() + } } // Libp2p @@ -686,6 +691,8 @@ where pub struct Libp2pDaRun { /// The underlying network configuration config: NetworkConfig, + /// The private validator config + validator_config: ValidatorConfig, /// The underlying network network: Libp2pNetwork, } @@ -714,12 +721,12 @@ where { async fn initialize_networking( config: NetworkConfig, + validator_config: ValidatorConfig, libp2p_advertise_address: Option, ) -> Libp2pDaRun { // Extrapolate keys for ease of use - let keys = config.clone().config.my_own_validator_config; - let public_key = keys.public_key; - let private_key = keys.private_key; + let public_key = &validator_config.public_key; + let private_key = &validator_config.private_key; // In an example, we can calculate the libp2p bind address as a function // of the advertise address. @@ -759,8 +766,8 @@ where GossipConfig::default(), RequestResponseConfig::default(), bind_address, - &public_key, - &private_key, + public_key, + private_key, Libp2pMetricsValue::default(), ) .await @@ -771,6 +778,7 @@ where Libp2pDaRun { config, + validator_config, network: libp2p_network, } } @@ -782,6 +790,10 @@ where fn config(&self) -> NetworkConfig { self.config.clone() } + + fn validator_config(&self) -> ValidatorConfig { + self.validator_config.clone() + } } // Combined network @@ -790,6 +802,8 @@ where pub struct CombinedDaRun { /// The underlying network configuration config: NetworkConfig, + /// The private validator config + validator_config: ValidatorConfig, /// The underlying network network: CombinedNetworks, } @@ -818,6 +832,7 @@ where { async fn initialize_networking( config: NetworkConfig, + validator_config: ValidatorConfig, libp2p_advertise_address: Option, ) -> CombinedDaRun { // Initialize our Libp2p network @@ -827,19 +842,24 @@ where Libp2pImpl, V, >>::initialize_networking( - config.clone(), libp2p_advertise_address.clone() + config.clone(), + validator_config.clone(), + libp2p_advertise_address.clone(), ) .await; // Initialize our CDN network - let cdn_network: PushCdnDaRun = - as RunDa< - TYPES, - PushCdnNetwork, - PushCdnImpl, - V, - >>::initialize_networking(config.clone(), libp2p_advertise_address) - .await; + let cdn_network: PushCdnDaRun = as RunDa< + TYPES, + PushCdnNetwork, + PushCdnImpl, + V, + >>::initialize_networking( + config.clone(), + validator_config.clone(), + libp2p_advertise_address, + ) + .await; // Create our combined network config let delay_duration = config @@ -852,7 +872,11 @@ where CombinedNetworks::new(cdn_network.network, libp2p_network.network, delay_duration); // Return the run configuration - CombinedDaRun { config, network } + CombinedDaRun { + config, + validator_config, + network, + } } fn network(&self) -> CombinedNetworks { @@ -862,6 +886,10 @@ where fn config(&self) -> NetworkConfig { self.config.clone() } + + fn validator_config(&self) -> ValidatorConfig { + self.validator_config.clone() + } } /// Main entry point for validators @@ -897,24 +925,22 @@ pub async fn main_entry_point< let orchestrator_client: OrchestratorClient = OrchestratorClient::new(args.url.clone()); // We assume one node will not call this twice to generate two validator_config-s with same identity. - let my_own_validator_config = - NetworkConfig::::generate_init_validator_config( - orchestrator_client - .get_node_index_for_init_validator_config() - .await, - // we assign nodes to the DA committee by default - true, - ); + let validator_config = NetworkConfig::::generate_init_validator_config( + orchestrator_client + .get_node_index_for_init_validator_config() + .await, + // we assign nodes to the DA committee by default + true, + ); // Derives our Libp2p private key from our private key, and then returns the public key of that key let libp2p_public_key = - derive_libp2p_peer_id::(&my_own_validator_config.private_key) + derive_libp2p_peer_id::(&validator_config.private_key) .expect("failed to derive Libp2p keypair"); // We need this to be able to register our node let peer_config = - PeerConfig::::to_bytes(&my_own_validator_config.public_config()) - .clone(); + PeerConfig::::to_bytes(&validator_config.public_config()).clone(); // Derive the advertise multiaddress from the supplied string let advertise_multiaddress = args.advertise_address.clone().map(|advertise_address| { @@ -928,16 +954,22 @@ pub async fn main_entry_point< // This function will be taken solely by sequencer right after OrchestratorClient::new, // which means the previous `generate_validator_config_when_init` will not be taken by sequencer, it's only for key pair generation for testing in hotshot. - let (mut run_config, source) = get_complete_config( + let (mut run_config, validator_config, source) = get_complete_config( &orchestrator_client, - my_own_validator_config, + validator_config, advertise_multiaddress, Some(libp2p_public_key), ) .await .expect("failed to get config"); - let builder_task = initialize_builder(&mut run_config, &args, &orchestrator_client).await; + let builder_task = initialize_builder( + &mut run_config, + &validator_config, + &args, + &orchestrator_client, + ) + .await; run_config.config.builder_urls = orchestrator_client .get_builder_addresses() @@ -957,7 +989,9 @@ pub async fn main_entry_point< ); info!("Initializing networking"); - let run = RUNDA::initialize_networking(run_config.clone(), args.advertise_address).await; + let run = + RUNDA::initialize_networking(run_config.clone(), validator_config, args.advertise_address) + .await; let hotshot = run.initialize_state_and_hotshot().await; if let Some(task) = builder_task { @@ -1018,6 +1052,7 @@ async fn initialize_builder< >, >( run_config: &mut NetworkConfig<::SignatureKey>, + validator_config: &ValidatorConfig<::SignatureKey>, args: &ValidatorArgs, orchestrator_client: &OrchestratorClient, ) -> Option>> @@ -1026,7 +1061,7 @@ where ::BlockPayload: TestableBlock, Leaf: TestableLeaf, { - if !run_config.config.my_own_validator_config.is_da { + if !validator_config.is_da { return None; } diff --git a/crates/hotshot/src/traits/networking/libp2p_network.rs b/crates/hotshot/src/traits/networking/libp2p_network.rs index f5cbac9f50..a8bc4ff6e4 100644 --- a/crates/hotshot/src/traits/networking/libp2p_network.rs +++ b/crates/hotshot/src/traits/networking/libp2p_network.rs @@ -51,7 +51,7 @@ use hotshot_types::{ metrics::{Counter, Gauge, Metrics, NoMetrics}, network::{ConnectedNetwork, NetworkError, Topic}, node_implementation::{ConsensusTime, NodeType}, - signature_key::SignatureKey, + signature_key::{PrivateSignatureKey, SignatureKey}, }, BoxSyncFuture, }; @@ -310,7 +310,7 @@ pub fn derive_libp2p_keypair( private_key: &K::PrivateKey, ) -> anyhow::Result { // Derive a secondary key from our primary private key - let derived_key = blake3::derive_key("libp2p key", &(bincode::serialize(&private_key)?)); + let derived_key = blake3::derive_key("libp2p key", &private_key.to_bytes()); let derived_key = SecretKey::try_from_bytes(derived_key)?; // Create an `ed25519` keypair from the derived key diff --git a/crates/orchestrator/src/client.rs b/crates/orchestrator/src/client.rs index bac62ecdd7..19799f8e7b 100644 --- a/crates/orchestrator/src/client.rs +++ b/crates/orchestrator/src/client.rs @@ -168,14 +168,14 @@ pub struct MultiValidatorArgs { /// If we are unable to get the configuration from the orchestrator pub async fn get_complete_config( client: &OrchestratorClient, - my_own_validator_config: ValidatorConfig, + mut validator_config: ValidatorConfig, libp2p_advertise_address: Option, libp2p_public_key: Option, -) -> anyhow::Result<(NetworkConfig, NetworkConfigSource)> { +) -> anyhow::Result<(NetworkConfig, ValidatorConfig, NetworkConfigSource)> { // get the configuration from the orchestrator let run_config: NetworkConfig = client .post_and_wait_all_public_keys::( - my_own_validator_config, + &mut validator_config, libp2p_advertise_address, libp2p_public_key, ) @@ -183,9 +183,13 @@ pub async fn get_complete_config( info!( "Retrieved config; our node index is {}. DA committee member: {}", - run_config.node_index, run_config.config.my_own_validator_config.is_da + run_config.node_index, validator_config.is_da ); - Ok((run_config, NetworkConfigSource::Orchestrator)) + Ok(( + run_config, + validator_config, + NetworkConfigSource::Orchestrator, + )) } impl ValidatorArgs { @@ -393,7 +397,7 @@ impl OrchestratorClient { #[instrument(skip(self), name = "orchestrator public keys")] pub async fn post_and_wait_all_public_keys( &self, - mut validator_config: ValidatorConfig, + validator_config: &mut ValidatorConfig, libp2p_advertise_address: Option, libp2p_public_key: Option, ) -> NetworkConfig { @@ -445,7 +449,6 @@ impl OrchestratorClient { let mut network_config = self.get_config_after_collection().await; network_config.node_index = node_index; - network_config.config.my_own_validator_config = validator_config; network_config } diff --git a/crates/testing/src/helpers.rs b/crates/testing/src/helpers.rs index 842ef3e538..40760372c6 100644 --- a/crates/testing/src/helpers.rs +++ b/crates/testing/src/helpers.rs @@ -92,7 +92,7 @@ pub async fn build_system_handle_from_launcher< let network = (launcher.resource_generator.channel_generator)(node_id).await; let storage = (launcher.resource_generator.storage)(node_id); let marketplace_config = (launcher.resource_generator.marketplace_config)(node_id); - let mut config = launcher.resource_generator.config.clone(); + let config = launcher.resource_generator.config.clone(); let initializer = HotShotInitializer::::from_genesis::(TestInstanceState::new( launcher.metadata.async_delay_config.clone(), @@ -104,11 +104,10 @@ pub async fn build_system_handle_from_launcher< let is_da = node_id < config.da_staked_committee_size as u64; // We assign node's public key and stake value rather than read from config file since it's a test - let validator_config = + let validator_config: ValidatorConfig = ValidatorConfig::generated_from_seed_indexed([0u8; 32], node_id, 1, is_da); - config.my_own_validator_config = validator_config; - let private_key = config.my_own_validator_config.private_key.clone(); - let public_key = config.my_own_validator_config.public_key.clone(); + let private_key = validator_config.private_key.clone(); + let public_key = validator_config.public_key.clone(); let all_nodes = config.known_nodes_with_stake.clone(); let da_nodes = config.known_da_nodes.clone(); diff --git a/crates/testing/src/test_builder.rs b/crates/testing/src/test_builder.rs index f86acd9d31..4773e597e0 100644 --- a/crates/testing/src/test_builder.rs +++ b/crates/testing/src/test_builder.rs @@ -481,7 +481,7 @@ where }) .collect(); // But now to test validator's config, we input the info of my_own_validator from config file when node_id == 0. - let my_own_validator_config = ValidatorConfig::generated_from_seed_indexed( + let validator_config = ValidatorConfig::::generated_from_seed_indexed( [0u8; 32], node_id, 1, @@ -496,7 +496,6 @@ where known_da_nodes, num_bootstrap: num_bootstrap_nodes, known_nodes_with_stake, - my_own_validator_config, da_staked_committee_size, fixed_leader_for_gpuvid: 1, next_view_timeout: 500, @@ -548,6 +547,7 @@ where storage }), config, + validator_config, marketplace_config: Box::new(|_| MarketplaceConfig:: { auction_results_provider: TestAuctionResultsProvider::::default().into(), fallback_builder_url: Url::parse("http://localhost:9999").unwrap(), diff --git a/crates/testing/src/test_launcher.rs b/crates/testing/src/test_launcher.rs index a6c5730e1c..8edffa33a8 100644 --- a/crates/testing/src/test_launcher.rs +++ b/crates/testing/src/test_launcher.rs @@ -16,7 +16,7 @@ use hotshot_types::{ network::{AsyncGenerator, ConnectedNetwork}, node_implementation::{NodeType, Versions}, }, - HotShotConfig, + HotShotConfig, ValidatorConfig, }; use super::{test_builder::TestDescription, test_runner::TestRunner}; @@ -36,6 +36,8 @@ pub struct ResourceGenerators>, /// configuration used to generate each hotshot node pub config: HotShotConfig, + /// config that contains the signature keys + pub validator_config: ValidatorConfig, /// generate a new marketplace config for each node pub marketplace_config: Generator>, } diff --git a/crates/testing/tests/tests_1/network_task.rs b/crates/testing/tests/tests_1/network_task.rs index 2771d6993a..26367ab7b4 100644 --- a/crates/testing/tests/tests_1/network_task.rs +++ b/crates/testing/tests/tests_1/network_task.rs @@ -55,7 +55,8 @@ async fn test_network_task() { let storage = Arc::new(RwLock::new((launcher.resource_generator.storage)(node_id))); let consensus = handle.hotshot.consensus(); let config = launcher.resource_generator.config.clone(); - let public_key = config.my_own_validator_config.public_key; + let validator_config = launcher.resource_generator.validator_config.clone(); + let public_key = validator_config.public_key; let all_nodes = config.known_nodes_with_stake.clone(); @@ -239,7 +240,8 @@ async fn test_network_storage_fail() { let storage = Arc::new(RwLock::new((launcher.resource_generator.storage)(node_id))); storage.write().await.should_return_err = true; let config = launcher.resource_generator.config.clone(); - let public_key = config.my_own_validator_config.public_key; + let validator_config = launcher.resource_generator.validator_config.clone(); + let public_key = validator_config.public_key; let all_nodes = config.known_nodes_with_stake.clone(); let upgrade_lock = UpgradeLock::::new(); diff --git a/crates/types/Cargo.toml b/crates/types/Cargo.toml index 9575be6b33..f2f161c33c 100644 --- a/crates/types/Cargo.toml +++ b/crates/types/Cargo.toml @@ -40,7 +40,7 @@ typenum = { workspace = true } derivative = "2" jf-vid = { workspace = true } jf-pcs = { workspace = true } -jf-signature = { workspace = true, features = ["schnorr"] } +jf-signature = { workspace = true, features = ["bls", "schnorr"] } jf-utils = { workspace = true } rand_chacha = { workspace = true } serde = { workspace = true } diff --git a/crates/types/src/hotshot_config_file.rs b/crates/types/src/hotshot_config_file.rs index 93f37ca022..9a285ae6fc 100644 --- a/crates/types/src/hotshot_config_file.rs +++ b/crates/types/src/hotshot_config_file.rs @@ -29,9 +29,6 @@ pub struct HotShotConfigFile { /// Total number of staked nodes in the network pub num_nodes_with_stake: NonZeroUsize, #[serde(skip)] - /// My own public key, secret key, stake value - pub my_own_validator_config: ValidatorConfig, - #[serde(skip)] /// The known nodes' public key and stake value pub known_nodes_with_stake: Vec>, #[serde(skip)] @@ -67,7 +64,6 @@ impl From> for HotShotConfig { num_nodes_with_stake: val.num_nodes_with_stake, known_da_nodes: val.known_da_nodes, known_nodes_with_stake: val.known_nodes_with_stake, - my_own_validator_config: val.my_own_validator_config, da_staked_committee_size: val.staked_da_nodes, fixed_leader_for_gpuvid: val.fixed_leader_for_gpuvid, next_view_timeout: val.next_view_timeout, @@ -120,7 +116,6 @@ impl HotShotConfigFile { Self { num_nodes_with_stake: NonZeroUsize::new(10).unwrap(), start_threshold: (1, 1), - my_own_validator_config: ValidatorConfig::default(), known_nodes_with_stake: gen_known_nodes_with_stake, staked_da_nodes, known_da_nodes, diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs index 44c81e4e68..f158fcf3ae 100644 --- a/crates/types/src/lib.rs +++ b/crates/types/src/lib.rs @@ -8,7 +8,6 @@ use std::{fmt::Debug, future::Future, num::NonZeroUsize, pin::Pin, time::Duration}; use bincode::Options; -use derivative::Derivative; use displaydoc::Display; use light_client::StateVerKey; use tracing::error; @@ -64,15 +63,12 @@ where assert_future::(Box::pin(fut)) } -#[derive(serde::Serialize, serde::Deserialize, Clone, Derivative, Display)] -#[serde(bound(deserialize = ""))] -#[derivative(Debug(bound = ""))] +#[derive(Clone, Debug, Display)] /// config for validator, including public key, private key, stake value pub struct ValidatorConfig { /// The validator's public key and stake value pub public_key: KEY, /// The validator's private key, should be in the mempool, not public - #[derivative(Debug = "ignore")] pub private_key: KEY::PrivateKey, /// The validator's stake pub stake_value: u64, @@ -176,8 +172,6 @@ pub struct HotShotConfig { pub known_nodes_with_stake: Vec>, /// All public keys known to be DA nodes pub known_da_nodes: Vec>, - /// My own validator config, including my public key, private key, stake value, serving as private parameter - pub my_own_validator_config: ValidatorConfig, /// List of DA committee (staking)nodes for static DA committee pub da_staked_committee_size: usize, /// Number of fixed leaders for GPU VID, normally it will be 0, it's only used when running GPU VID diff --git a/crates/types/src/light_client.rs b/crates/types/src/light_client.rs index 1fac6614e4..07644df0ef 100644 --- a/crates/types/src/light_client.rs +++ b/crates/types/src/light_client.rs @@ -36,7 +36,7 @@ pub type StateSignKey = schnorr::SignKey; /// Concrete for circuit's public input pub type PublicInput = GenericPublicInput; /// Key pairs for signing/verifying a light client state -#[derive(Debug, Default, Clone, serde::Serialize, serde::Deserialize)] +#[derive(Debug, Default, Clone)] pub struct StateKeyPair(pub schnorr::KeyPair); /// Request body to send to the state relay server diff --git a/crates/types/src/signature_key.rs b/crates/types/src/signature_key.rs index 2741912f14..43110ed8b2 100644 --- a/crates/types/src/signature_key.rs +++ b/crates/types/src/signature_key.rs @@ -23,7 +23,7 @@ use crate::{ stake_table::StakeTableEntry, traits::{ qc::QuorumCertificateScheme, - signature_key::{BuilderSignatureKey, SignatureKey}, + signature_key::{BuilderSignatureKey, PrivateSignatureKey, SignatureKey}, }, }; @@ -34,6 +34,20 @@ pub type BLSPubKey = VerKey; /// Public parameters for BLS signature scheme pub type BLSPublicParam = (); +impl PrivateSignatureKey for BLSPrivKey { + fn to_bytes(&self) -> Vec { + self.to_bytes() + } + + fn from_bytes(bytes: &[u8]) -> anyhow::Result { + Ok(Self::from_bytes(bytes)) + } + + fn to_tagged_base64(&self) -> Result { + self.to_tagged_base64() + } +} + impl SignatureKey for BLSPubKey { type PrivateKey = BLSPrivKey; type StakeTableEntry = StakeTableEntry; diff --git a/crates/types/src/traits/signature_key.rs b/crates/types/src/traits/signature_key.rs index 52503c0cd5..93edb4e1ba 100644 --- a/crates/types/src/traits/signature_key.rs +++ b/crates/types/src/traits/signature_key.rs @@ -20,7 +20,7 @@ use committable::Committable; use ethereum_types::U256; use jf_vid::VidScheme; use serde::{de::DeserializeOwned, Deserialize, Serialize}; -use tagged_base64::TaggedBase64; +use tagged_base64::{TaggedBase64, Tb64Error}; use super::EncodeBytes; use crate::{ @@ -36,6 +36,24 @@ pub trait StakeTableEntryType { fn public_key(&self) -> K; } +/// Trait for abstracting private signature key +pub trait PrivateSignatureKey: + Send + Sync + Sized + Clone + Debug + Eq + Hash + for<'a> TryFrom<&'a TaggedBase64> +{ + /// Serialize the private key into bytes + fn to_bytes(&self) -> Vec; + + /// Deserialize the private key from bytes + /// # Errors + /// If deserialization fails. + fn from_bytes(bytes: &[u8]) -> anyhow::Result; + + /// Serialize the private key into TaggedBase64 blob. + /// # Errors + /// If serialization fails. + fn to_tagged_base64(&self) -> Result; +} + /// Trait for abstracting public key signatures /// Self is the public key type pub trait SignatureKey: @@ -56,15 +74,7 @@ pub trait SignatureKey: + Into { /// The private key type for this signature algorithm - type PrivateKey: Send - + Sync - + Sized - + Clone - + Debug - + Eq - + Serialize - + for<'a> Deserialize<'a> - + Hash; + type PrivateKey: PrivateSignatureKey; /// The type of the entry that contain both public key and stake value type StakeTableEntry: StakeTableEntryType + Send @@ -179,15 +189,7 @@ pub trait BuilderSignatureKey: + Display { /// The type of the keys builder would use to sign its messages - type BuilderPrivateKey: Send - + Sync - + Sized - + Clone - + Debug - + Eq - + Serialize - + for<'a> Deserialize<'a> - + Hash; + type BuilderPrivateKey: PrivateSignatureKey; /// The type of the signature builder would use to sign its messages type BuilderSignature: Send