diff --git a/nym-api/src/coconut/client.rs b/nym-api/src/coconut/client.rs index f4c34e04d2..bfab9034d6 100644 --- a/nym-api/src/coconut/client.rs +++ b/nym-api/src/coconut/client.rs @@ -11,6 +11,7 @@ use nym_coconut_dkg_common::types::{ PartialContractDealing, State, }; use nym_coconut_dkg_common::verification_key::{ContractVKShare, VerificationKeyShare}; +use nym_contracts_common::IdentityKey; use nym_dkg::Threshold; use nym_validator_client::nyxd::cosmwasm_client::types::ExecuteResult; use nym_validator_client::nyxd::{AccountId, Fee, Hash, TxResponse}; @@ -52,6 +53,7 @@ pub trait Client { async fn register_dealer( &self, bte_key: EncodedBTEPublicKeyWithProof, + identity_key: IdentityKey, announce_address: String, resharing: bool, ) -> Result; diff --git a/nym-api/src/coconut/dkg/client.rs b/nym-api/src/coconut/dkg/client.rs index 984e26440f..dc6cd83d47 100644 --- a/nym-api/src/coconut/dkg/client.rs +++ b/nym-api/src/coconut/dkg/client.rs @@ -11,6 +11,7 @@ use nym_coconut_dkg_common::types::{ PartialContractDealing, State as ContractState, }; use nym_coconut_dkg_common::verification_key::{ContractVKShare, VerificationKeyShare}; +use nym_contracts_common::IdentityKey; use nym_dkg::Threshold; use nym_validator_client::nyxd::cosmwasm_client::logs::{find_attribute, NODE_INDEX}; use nym_validator_client::nyxd::cosmwasm_client::types::ExecuteResult; @@ -152,12 +153,13 @@ impl DkgClient { pub(crate) async fn register_dealer( &self, bte_key: EncodedBTEPublicKeyWithProof, + identity_key: IdentityKey, announce_address: String, resharing: bool, ) -> Result { let res = self .inner - .register_dealer(bte_key, announce_address, resharing) + .register_dealer(bte_key, identity_key, announce_address, resharing) .await?; let node_index = find_attribute(&res.logs, "wasm", NODE_INDEX) .ok_or(CoconutError::NodeIndexRecoveryError { diff --git a/nym-api/src/coconut/dkg/controller.rs b/nym-api/src/coconut/dkg/controller.rs index 506655f6d8..31c676de3e 100644 --- a/nym-api/src/coconut/dkg/controller.rs +++ b/nym-api/src/coconut/dkg/controller.rs @@ -15,6 +15,7 @@ use crate::nyxd; use crate::support::config; use anyhow::{bail, Result}; use nym_coconut_dkg_common::types::EpochState; +use nym_crypto::asymmetric::identity; use nym_dkg::bte::keys::KeyPair as DkgKeyPair; use nym_task::{TaskClient, TaskManager}; use rand::rngs::OsRng; @@ -51,6 +52,7 @@ impl DkgController { config: &config::CoconutSigner, nyxd_client: nyxd::Client, coconut_keypair: CoconutKeyPair, + identity_key: identity::PublicKey, rng: R, ) -> Result { let Some(announce_address) = &config.announce_address else { @@ -82,6 +84,7 @@ impl DkgController { persistent_state, announce_address.clone(), dkg_keypair, + identity_key, coconut_keypair, ), rng, @@ -208,6 +211,7 @@ impl DkgController { config: &config::CoconutSigner, nyxd_client: nyxd::Client, coconut_keypair: CoconutKeyPair, + identity_key: identity::PublicKey, rng: R, shutdown: &TaskManager, ) -> Result<()> @@ -215,7 +219,8 @@ impl DkgController { R: Sync + Send + 'static, { let shutdown_listener = shutdown.subscribe(); - let dkg_controller = DkgController::new(config, nyxd_client, coconut_keypair, rng).await?; + let dkg_controller = + DkgController::new(config, nyxd_client, coconut_keypair, identity_key, rng).await?; tokio::spawn(async move { dkg_controller.run(shutdown_listener).await }); Ok(()) } diff --git a/nym-api/src/coconut/dkg/public_key.rs b/nym-api/src/coconut/dkg/public_key.rs index 74f3d5c9f3..a03e6c6bb9 100644 --- a/nym-api/src/coconut/dkg/public_key.rs +++ b/nym-api/src/coconut/dkg/public_key.rs @@ -38,7 +38,12 @@ pub(crate) async fn public_key_submission( // If it was a dealer in a previous epoch, re-register it for this epoch debug!("Registering for the current DKG round, with keys from a previous epoch"); dkg_client - .register_dealer(bte_key, state.announce_address().to_string(), resharing) + .register_dealer( + bte_key, + state.identity_key().to_base58_string(), + state.announce_address().to_string(), + resharing, + ) .await?; } details.assigned_index @@ -46,7 +51,12 @@ pub(crate) async fn public_key_submission( debug!("Registering for the first time to be a dealer"); // First time registration dkg_client - .register_dealer(bte_key, state.announce_address().to_string(), resharing) + .register_dealer( + bte_key, + state.identity_key().to_base58_string(), + state.announce_address().to_string(), + resharing, + ) .await? }; state.set_node_index(Some(index)); @@ -61,9 +71,11 @@ pub(crate) mod tests { use crate::coconut::dkg::state::PersistentState; use crate::coconut::tests::DummyClient; use crate::coconut::KeyPair; + use nym_crypto::asymmetric::identity; use nym_dkg::bte::keys::KeyPair as DkgKeyPair; use nym_validator_client::nyxd::AccountId; use rand::rngs::OsRng; + use rand_07::thread_rng; use std::path::PathBuf; use std::str::FromStr; use url::Url; @@ -76,11 +88,13 @@ pub(crate) mod tests { let dkg_client = DkgClient::new(DummyClient::new( AccountId::from_str(TEST_VALIDATOR_ADDRESS).unwrap(), )); + let identity_keypair = identity::KeyPair::new(&mut thread_rng()); let mut state = State::new( PathBuf::default(), PersistentState::default(), Url::parse("localhost:8000").unwrap(), DkgKeyPair::new(&nym_dkg::bte::setup(), OsRng), + *identity_keypair.public_key(), KeyPair::new(), ); diff --git a/nym-api/src/coconut/dkg/state.rs b/nym-api/src/coconut/dkg/state.rs index f0afb86f90..829f1f5eb3 100644 --- a/nym-api/src/coconut/dkg/state.rs +++ b/nym-api/src/coconut/dkg/state.rs @@ -8,6 +8,7 @@ use cosmwasm_std::Addr; use log::debug; use nym_coconut_dkg_common::dealer::DealerDetails; use nym_coconut_dkg_common::types::{DealingIndex, EpochId, EpochState}; +use nym_crypto::asymmetric::identity; use nym_dkg::bte::{keys::KeyPair as DkgKeyPair, PublicKey, PublicKeyWithProof}; use nym_dkg::{Dealing, NodeIndex, RecoveredVerificationKeys, Threshold}; use serde::de::Error; @@ -249,6 +250,7 @@ impl PersistentState { pub(crate) struct State { persistent_state_path: PathBuf, announce_address: Url, + identity_key: identity::PublicKey, dkg_keypair: DkgKeyPair, coconut_keypair: CoconutKeyPair, node_index: Option, @@ -269,11 +271,13 @@ impl State { persistent_state: PersistentState, announce_address: Url, dkg_keypair: DkgKeyPair, + identity_key: identity::PublicKey, coconut_keypair: CoconutKeyPair, ) -> Self { State { persistent_state_path, announce_address, + identity_key, dkg_keypair, coconut_keypair, node_index: persistent_state.node_index, @@ -312,6 +316,10 @@ impl State { &self.announce_address } + pub fn identity_key(&self) -> identity::PublicKey { + self.identity_key + } + pub fn dkg_keypair(&self) -> &DkgKeyPair { &self.dkg_keypair } diff --git a/nym-api/src/main.rs b/nym-api/src/main.rs index e28d0ad37e..032eba869b 100644 --- a/nym-api/src/main.rs +++ b/nym-api/src/main.rs @@ -70,6 +70,7 @@ async fn start_nym_api_tasks(config: Config) -> anyhow::Result let coconut_keypair = coconut::keypair::KeyPair::new(); let identity_keypair = config.base.storage_paths.load_identity()?; + let identity_public_key = *identity_keypair.public_key(); // let's build our rocket! let rocket = http::setup_rocket( @@ -137,6 +138,7 @@ async fn start_nym_api_tasks(config: Config) -> anyhow::Result &config.coconut_signer, nyxd_client.clone(), coconut_keypair, + identity_public_key, OsRng, &shutdown, ) diff --git a/nym-api/src/support/nyxd/mod.rs b/nym-api/src/support/nyxd/mod.rs index c350c3d252..78efde83f1 100644 --- a/nym-api/src/support/nyxd/mod.rs +++ b/nym-api/src/support/nyxd/mod.rs @@ -467,12 +467,13 @@ impl crate::coconut::client::Client for Client { async fn register_dealer( &self, bte_key: EncodedBTEPublicKeyWithProof, + identity_key: IdentityKey, announce_address: String, resharing: bool, ) -> Result { Ok(nyxd_signing!( self, - register_dealer(bte_key, announce_address, resharing, None).await? + register_dealer(bte_key, announce_address, identity_key, resharing, None).await? )) }