Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

User can participate in DKG #395

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions crypto/server/src/user/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub async fn new_user(
encoded_data: Bytes,
) -> Result<StatusCode, UserErr> {
let data = OcwMessage::decode(&mut encoded_data.as_ref())?;
if data.sig_request_accounts.is_empty() {
if data.registering_users.is_empty() {
return Ok(StatusCode::NO_CONTENT);
}

Expand All @@ -185,8 +185,9 @@ pub async fn new_user(
let my_subgroup = subgroup.ok_or_else(|| UserErr::SubgroupError("Subgroup Error"))?;
let mut addresses_in_subgroup = return_all_addresses_of_subgroup(&api, my_subgroup).await?;

for sig_request_account in data.sig_request_accounts {
let address_slice: &[u8; 32] = &sig_request_account
for registering_user in data.registering_users {
let address_slice: &[u8; 32] = &registering_user
.sig_request_account
.clone()
.try_into()
.map_err(|_| UserErr::AddressConversionError("Invalid Length".to_string()))?;
Expand Down Expand Up @@ -414,7 +415,7 @@ pub async fn validate_new_user(
}

let mut hasher_chain_data = Blake2s256::new();
hasher_chain_data.update(chain_data.sig_request_accounts.encode());
hasher_chain_data.update(chain_data.registering_users.encode());
let chain_data_hash = hasher_chain_data.finalize();
let mut hasher_verifying_data = Blake2s256::new();

Expand Down
12 changes: 9 additions & 3 deletions crypto/server/src/user/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{env, fs, net::SocketAddrV4, path::PathBuf, str::FromStr, sync::Arc, ti
use axum::http::StatusCode;
use bip39::{Language, Mnemonic, MnemonicType};
use entropy_constraints::{Architecture, Evm, Parse};
use entropy_shared::{Acl, KeyVisibility, OcwMessage};
use entropy_shared::{Acl, KeyVisibility, OcwMessage, RegisteringUser};
use ethers_core::types::{Address, TransactionRequest};
use futures::{
future::{self, join_all},
Expand Down Expand Up @@ -475,8 +475,14 @@ async fn test_store_share() {
tss_account: TSS_ACCOUNTS[1].clone().encode(),
},
];
let mut onchain_user_request =
OcwMessage { sig_request_accounts: vec![alice.encode()], block_number, validators_info };
let mut onchain_user_request = OcwMessage {
registering_users: vec![RegisteringUser {
sig_request_account: alice.encode(),
key_visibility: KeyVisibility::Permissioned,
}],
block_number,
validators_info,
};
let client = reqwest::Client::new();

put_register_request_on_chain(&api, &alice, alice_constraint.to_account_id().into()).await;
Expand Down
9 changes: 8 additions & 1 deletion crypto/shared/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,17 @@ pub struct ValidatorInfo {
pub tss_account: codec::alloc::vec::Vec<u8>,
}

#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, TypeInfo)]
pub struct RegisteringUser {
pub sig_request_account: codec::alloc::vec::Vec<u8>,
pub key_visibility: KeyVisibility,
}

#[cfg_attr(feature = "std", derive(Serialize, Deserialize))]
#[derive(Clone, Encode, Decode, Debug, Eq, PartialEq, TypeInfo)]
pub struct OcwMessage {
pub block_number: BlockNumber,
pub sig_request_accounts: Vec<codec::alloc::vec::Vec<u8>>,
pub registering_users: Vec<RegisteringUser>,
pub validators_info: Vec<ValidatorInfo>,
}
2 changes: 1 addition & 1 deletion pallets/propagation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub mod pallet {
let req_body = OcwMessage {
// subtract 1 from blocknumber since the request is from the last block
block_number: converted_block_number.saturating_sub(1),
sig_request_accounts: messages,
registering_users: messages,
validators_info,
};

Expand Down
8 changes: 4 additions & 4 deletions pallets/propagation/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ fn knows_how_to_mock_several_http_calls() {
sent: true,
response: Some([].to_vec()),
body: [
3, 0, 0, 0, 8, 32, 1, 0, 0, 0, 0, 0, 0, 0, 32, 2, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0,
3, 0, 0, 0, 8, 32, 1, 0, 0, 0, 0, 0, 0, 0, 0, 32, 2, 0, 0, 0, 0, 0, 0, 0, 0, 8, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 4, 20, 32, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 40, 32, 8, 0, 0, 0, 0, 0, 0,
0,
0, 0, 0, 4, 20, 32, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 40, 32, 8, 0, 0, 0, 0,
0, 0, 0,
]
.to_vec(),
..Default::default()
Expand Down
8 changes: 5 additions & 3 deletions pallets/relayer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub mod weights;

#[frame_support::pallet]
pub mod pallet {
use entropy_shared::{Constraints, KeyVisibility, SIGNING_PARTY_SIZE};
use entropy_shared::{Constraints, KeyVisibility, RegisteringUser, SIGNING_PARTY_SIZE};
use frame_support::{
dispatch::{DispatchResult, DispatchResultWithPostInfo, Pays},
inherent::Vec,
Expand Down Expand Up @@ -115,7 +115,7 @@ pub mod pallet {
#[pallet::storage]
#[pallet::getter(fn dkg)]
pub type Dkg<T: Config> =
StorageMap<_, Blake2_128Concat, T::BlockNumber, Vec<Vec<u8>>, ValueQuery>;
StorageMap<_, Blake2_128Concat, T::BlockNumber, Vec<RegisteringUser>, ValueQuery>;

#[pallet::storage]
#[pallet::getter(fn registered)]
Expand Down Expand Up @@ -186,8 +186,10 @@ pub mod pallet {
ConstraintsPallet::<T>::validate_constraints(constraints)?;
}
let block_number = <frame_system::Pallet<T>>::block_number();
let registering_user =
RegisteringUser { sig_request_account: sig_req_account.encode(), key_visibility };
Dkg::<T>::try_mutate(block_number, |messages| -> Result<_, DispatchError> {
messages.push(sig_req_account.clone().encode());
messages.push(registering_user);
Ok(())
})?;
// put account into a registering state
Expand Down
10 changes: 8 additions & 2 deletions pallets/relayer/src/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use codec::Encode;
use entropy_shared::{Constraints, KeyVisibility};
use entropy_shared::{Constraints, KeyVisibility, RegisteringUser};
use frame_support::{
assert_noop, assert_ok,
dispatch::{GetDispatchInfo, Pays},
Expand Down Expand Up @@ -59,7 +59,13 @@ fn it_registers_a_user() {
));

assert!(Relayer::registering(1).unwrap().is_registering);
assert_eq!(Relayer::dkg(0), vec![1u64.encode()]);
assert_eq!(
Relayer::dkg(0),
vec![RegisteringUser {
sig_request_account: 1u64.encode(),
key_visibility: KeyVisibility::Public
}]
);
});
}

Expand Down