Skip to content

Commit

Permalink
add keyshare store and test
Browse files Browse the repository at this point in the history
  • Loading branch information
JesseAbram committed Jul 29, 2024
1 parent 4e30876 commit 2e2cfeb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
11 changes: 9 additions & 2 deletions crates/threshold-signature-server/src/validator/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,16 @@ pub async fn new_reshare(
.map_err(|_| ValidatorErr::ProtocolError("Error executing protocol".to_string()))?
.0
.ok_or(ValidatorErr::NoOutputFromReshareProtocol)?;
let _serialized_key_share = key_serialize(&new_key_share)
let serialized_key_share = key_serialize(&new_key_share)
.map_err(|_| ProtocolErr::KvSerialize("Kv Serialize Error".to_string()))?;
// TODO: do reshare call confirm_reshare (delete key when done) see #941
let network_parent_key = hex::encode(NETWORK_PARENT_KEY);
// TODO: should this be a two step process? see # https://github.com/entropyxyz/entropy-core/issues/968
if app_state.kv_store.kv().exists(&network_parent_key).await? {
app_state.kv_store.kv().delete(&network_parent_key).await?
};

let reservation = app_state.kv_store.kv().reserve_key(network_parent_key).await?;
app_state.kv_store.kv().put(reservation, serialized_key_share.clone()).await?;

// TODO: Error handling really complex needs to be thought about.
confirm_key_reshare(&api, &rpc, &signer).await?;
Expand Down
12 changes: 7 additions & 5 deletions crates/threshold-signature-server/src/validator/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@ use crate::{
helpers::{
launch::{development_mnemonic, ValidatorName, FORBIDDEN_KEYS},
substrate::submit_transaction,
tests::initialize_test_logger,
tests::{initialize_test_logger, spawn_testing_validators, unsafe_get},
validator::get_signer_and_x25519_secret_from_mnemonic,
},
validator::errors::ValidatorErr,
};
use entropy_kvdb::clean_tests;
use entropy_shared::{OcwMessageReshare, EVE_VERIFYING_KEY, MIN_BALANCE};
use entropy_shared::{OcwMessageReshare, EVE_VERIFYING_KEY, MIN_BALANCE, NETWORK_PARENT_KEY};
use entropy_testing_utils::{
constants::{ALICE_STASH_ADDRESS, RANDOM_ACCOUNT},
spawn_testing_validators,
substrate_context::{testing_context, test_node_process_testing_state},
test_context_stationary,
substrate_context::{test_node_process_testing_state, testing_context},
};
use futures::future::join_all;
use parity_scale_codec::Encode;
Expand All @@ -57,6 +55,7 @@ async fn test_reshare() {

let client = reqwest::Client::new();
let block_number = rpc.chain_get_header(None).await.unwrap().unwrap().number + 1;
let key_share_before = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), 3001).await;

let onchain_reshare_request =
OcwMessageReshare { new_signer: alice.public().encode(), block_number };
Expand All @@ -77,6 +76,9 @@ async fn test_reshare() {
for response_result in response_results {
assert_eq!(response_result.unwrap().text().await.unwrap(), "");
}
let key_share_after = unsafe_get(&client, hex::encode(NETWORK_PARENT_KEY), 3001).await;
assert_ne!(key_share_before, key_share_after);

clean_tests();
}

Expand Down

0 comments on commit 2e2cfeb

Please sign in to comment.