Skip to content

Commit

Permalink
use stored ecash key when using credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
simonwicky committed Oct 31, 2023
1 parent 1b45b2a commit 9df28c4
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
3 changes: 3 additions & 0 deletions common/bandwidth-controller/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,7 @@ pub enum BandwidthControllerError {

#[error("Threshold not set yet")]
NoThreshold,

#[error("Ecash key is not set yet")]
NoEcashKey,
}
17 changes: 14 additions & 3 deletions common/bandwidth-controller/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use crate::error::BandwidthControllerError;
use nym_compact_ecash::scheme::keygen::KeyPairUser;
use nym_compact_ecash::scheme::{EcashCredential, Wallet};
use nym_compact_ecash::setup::setup;
use nym_compact_ecash::{Base58, PayInfo, SecretKeyUser};
Expand All @@ -18,11 +19,16 @@ pub mod error;
pub struct BandwidthController<C, St> {
storage: St,
client: C,
ecash_keypair: Option<KeyPairUser>,
}

impl<C, St: Storage> BandwidthController<C, St> {
pub fn new(storage: St, client: C) -> Self {
BandwidthController { storage, client }
pub fn new(storage: St, client: C, ecash_keypair: Option<KeyPairUser>) -> Self {
BandwidthController {
storage,
client,
ecash_keypair,
}
}

pub fn storage(&self) -> &St {
Expand Down Expand Up @@ -53,7 +59,11 @@ impl<C, St: Storage> BandwidthController<C, St> {

let some_l_i_guess = 100; //SW: TEMPORARY VALUE
let params = setup(some_l_i_guess);
let sk_user = SecretKeyUser::try_from_bs58(ecash_credential.secret_key)?;
let sk_user = self
.ecash_keypair
.clone()
.ok_or(BandwidthControllerError::NoEcashKey)?
.secret_key();
let pay_info = PayInfo::generate_payinfo(provider_pk);
let nb_tickets = 1u64; //SW: TEMPORARY VALUE, what should we put there?

Expand Down Expand Up @@ -99,6 +109,7 @@ where
BandwidthController {
storage: self.storage.clone(),
client: self.client.clone(),
ecash_keypair: self.ecash_keypair.clone(),
}
}
}
11 changes: 8 additions & 3 deletions common/client-core/src/client/base_client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use nym_topology::provider_trait::TopologyProvider;
use nym_topology::HardcodedTopologyProvider;
use nym_validator_client::nyxd::contract_traits::DkgQueryClient;
use std::fmt::Debug;
use std::ops::Deref;
use std::path::Path;
use std::sync::Arc;
use url::Url;
Expand Down Expand Up @@ -612,9 +613,13 @@ where

// the components are started in very specific order. Unless you know what you are doing,
// do not change that.
let bandwidth_controller = self
.dkg_query_client
.map(|client| BandwidthController::new(credential_store, client));
let bandwidth_controller = self.dkg_query_client.map(|client| {
BandwidthController::new(
credential_store,
client,
Some(init_res.managed_keys.ecash_keypair().deref().clone()),
)
});

let topology_provider = Self::setup_topology_provider(
self.custom_topology_provider.take(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub fn create_bandwidth_controller_with_urls<St: CredentialStorage>(
) -> BandwidthController<QueryHttpRpcNyxdClient, St> {
let client = default_query_dkg_client(nyxd_url);

BandwidthController::new(storage, client)
BandwidthController::new(storage, client, None)
}

pub fn default_query_dkg_client_from_config(config: &Config) -> QueryHttpRpcNyxdClient {
Expand Down
1 change: 1 addition & 0 deletions nym-api/src/network_monitor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl<'a> NetworkMonitorBuilder<'a> {
)
.await,
self.nyxd_client.clone(),
None,
)
};

Expand Down

0 comments on commit 9df28c4

Please sign in to comment.