Skip to content

Commit

Permalink
Define AccountId key type primitives for keystore logic
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrylavrenov committed Apr 22, 2022
1 parent d1533dd commit 765109f
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 64 deletions.
20 changes: 11 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions crates/bioauth-id/Cargo.toml

This file was deleted.

10 changes: 0 additions & 10 deletions crates/bioauth-id/src/lib.rs

This file was deleted.

1 change: 1 addition & 0 deletions crates/humanode-peer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ bioauth-consensus = { version = "0.1", path = "../bioauth-consensus", features =
bioauth-flow = { version = "0.1", path = "../bioauth-flow" }
humanode-rpc = { version = "0.1", path = "../humanode-rpc" }
humanode-runtime = { version = "0.1", path = "../humanode-runtime" }
keystore-account-id = { version = "0.1", path = "../keystore-account-id" }
ngrok-api = { version = "0.1", path = "../ngrok-api" }
pallet-bioauth = { version = "0.1", path = "../pallet-bioauth" }
robonode-client = { version = "0.1", path = "../robonode-client" }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Bioauth key generate subcommand logic.

use super::BioauthConsensusPair;
use super::BioauthPair;
use bip39::{Language, Mnemonic, MnemonicType};
use sc_cli::{utils, OutputTypeFlag};
use structopt::StructOpt;
Expand Down Expand Up @@ -40,7 +40,7 @@ impl GenerateKeyCmd {
// Password is None as we don't use it for keystore at the current moment.
// Network_override is None as we don't allow to override network type as
// the subcommand is used for Bioauth network explicitly.
utils::print_from_uri::<BioauthConsensusPair>(mnemonic.phrase(), None, None, output);
utils::print_from_uri::<BioauthPair>(mnemonic.phrase(), None, None, output);

Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions crates/humanode-peer/src/cli/subcommand/bioauth/key/insert.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Bioauth key insert subcommand logic.

use super::BioauthConsensusId;
use super::BioauthId;
use sc_cli::{utils, CliConfiguration, KeystoreParams, SharedParams};
use sc_service::KeystoreContainer;
use sp_application_crypto::{AppKey, AppPublic};
Expand Down Expand Up @@ -72,11 +72,11 @@ impl InsertKeyCmd {
pub async fn run(&self, keystore_container: KeystoreContainer) -> sc_cli::Result<()> {
let keystore = keystore_container.keystore();

ensure_bioauth_key_absent::<BioauthConsensusId>(Arc::clone(&keystore))
ensure_bioauth_key_absent::<BioauthId>(Arc::clone(&keystore))
.await
.map_err(|err| sc_cli::Error::Service(sc_service::Error::Other(err.to_string())))?;

insert_bioauth_key::<BioauthConsensusId>(self.suri.as_ref(), keystore).await?;
insert_bioauth_key::<BioauthId>(self.suri.as_ref(), keystore).await?;
Ok(())
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Bioauth key inspect subcommand logic.

use super::BioauthConsensusPair;
use super::BioauthPair;
use bip39::{Language, Mnemonic};
use sc_cli::{utils, OutputTypeFlag};
use structopt::StructOpt;
Expand All @@ -27,7 +27,7 @@ impl InspectKeyCmd {
// Password is None as we don't use it for keystore at the current moment.
// Network_override is None as we don't allow to override network type as
// the subcommand is used for Bioauth network explicitly.
utils::print_from_uri::<BioauthConsensusPair>(mnemonic.phrase(), None, None, output);
utils::print_from_uri::<BioauthPair>(mnemonic.phrase(), None, None, output);

Ok(())
}
Expand Down
9 changes: 4 additions & 5 deletions crates/humanode-peer/src/cli/subcommand/bioauth/key/list.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Bioauth key list subcommand logic.

use super::BioauthConsensusId;
use super::BioauthId;
use sc_cli::{CliConfiguration, KeystoreParams, SharedParams};
use sc_service::KeystoreContainer;
use structopt::StructOpt;
Expand All @@ -23,10 +23,9 @@ impl ListKeysCmd {
/// Run the list command.
pub async fn run(&self, keystore_container: KeystoreContainer) -> sc_cli::Result<()> {
let keystore = keystore_container.keystore();
let keys =
crate::validator_key::AppCryptoPublic::<BioauthConsensusId>::list(keystore.as_ref())
.await
.map_err(|err| sc_cli::Error::Service(sc_service::Error::Other(err.to_string())))?;
let keys = crate::validator_key::AppCryptoPublic::<BioauthId>::list(keystore.as_ref())
.await
.map_err(|err| sc_cli::Error::Service(sc_service::Error::Other(err.to_string())))?;
for key in keys {
println!("{}", &key);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/humanode-peer/src/cli/subcommand/bioauth/key/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ pub mod inspect;
pub mod list;

/// Bioauth identifier used at the keystore.
pub type BioauthConsensusId = humanode_runtime::BioauthConsensusId;
pub type BioauthId = keystore_account_id::KeystoreAccountId;
/// Bioauth key pair scheme type used at the keystore.
pub type BioauthConsensusPair = <<BioauthConsensusId as sp_application_crypto::CryptoType>::Pair as sp_application_crypto::AppPair>::Generic;
pub type BioauthPair = <<BioauthId as sp_application_crypto::CryptoType>::Pair as sp_application_crypto::AppPair>::Generic;

/// Subcommands for the `bioauth key` command.
#[derive(Debug, StructOpt)]
Expand Down
17 changes: 10 additions & 7 deletions crates/humanode-peer/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use fc_mapping_sync::{MappingSyncWorker, SyncStrategy};
use fc_rpc::EthTask;
use fc_rpc_core::types::{FeeHistoryCache, FilterPool};
use futures::StreamExt;
use humanode_runtime::{self, opaque::Block, BioauthConsensusId, RuntimeApi};
use humanode_runtime::{self, opaque::Block, RuntimeApi};
use sc_client_api::{BlockchainEvents, ExecutorProvider};
use sc_consensus_babe::SlotProportion;
pub use sc_executor::NativeElseWasmExecutor;
Expand All @@ -22,7 +22,7 @@ use std::{
};
use tracing::*;

use crate::configuration::Configuration;
use crate::{cli::bioauth::key::BioauthId, configuration::Configuration};

pub mod frontier;
pub mod inherents;
Expand Down Expand Up @@ -334,8 +334,11 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
let pool = Arc::clone(&transaction_pool);
let robonode_client = Arc::clone(&robonode_client);
let bioauth_flow_rpc_slot = Arc::new(bioauth_flow_rpc_slot);
let validator_key_extractor = Arc::clone(&validator_key_extractor);
let validator_signer_factory = {
let bioauth_validator_key_extractor =
Arc::new(bioauth_consensus::keystore::ValidatorKeyExtractor::<
BioauthId,
>::new(keystore_container.sync_keystore()));
let bioauth_validator_signer_factory = {
let keystore = keystore_container.keystore();
Arc::new(move |key| {
crate::validator_key::AppCryptoSigner::new(
Expand Down Expand Up @@ -388,8 +391,8 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
bioauth: humanode_rpc::BioauthDeps {
robonode_client: Arc::clone(&robonode_client),
bioauth_flow_slot: Arc::clone(&bioauth_flow_rpc_slot),
validator_signer_factory: Arc::clone(&validator_signer_factory),
validator_key_extractor: Arc::clone(&validator_key_extractor),
bioauth_validator_signer_factory: Arc::clone(&bioauth_validator_signer_factory),
bioauth_validator_key_extractor: Arc::clone(&bioauth_validator_key_extractor),
},
babe: humanode_rpc::BabeDeps {
babe_config: babe_config.clone(),
Expand Down Expand Up @@ -561,7 +564,7 @@ pub async fn new_full(config: Configuration) -> Result<TaskManager, ServiceError
let transaction_pool = Arc::clone(&transaction_pool);
Box::pin(async move {
let validator_public_key =
crate::validator_key::AppCryptoPublic::<BioauthConsensusId>::from_keystore(
crate::validator_key::AppCryptoPublic::<BioauthId>::from_keystore(
keystore.as_ref(),
)
.await;
Expand Down
16 changes: 8 additions & 8 deletions crates/humanode-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ pub struct BioauthDeps<VKE, VSF> {
pub robonode_client: Arc<robonode_client::Client>,
/// The liveness data tx slot to use in the bioauth flow RPC.
pub bioauth_flow_slot: Arc<LivenessDataTxSlot>,
/// Extracts the currently used validator key.
pub validator_key_extractor: VKE,
/// A factory for making signers by the validator public keys.
pub validator_signer_factory: VSF,
/// Extracts the currently used bioauth validator key.
pub bioauth_validator_key_extractor: VKE,
/// A factory for making signers by the bioauth validator public keys.
pub bioauth_validator_signer_factory: VSF,
}

/// Extra dependencies for BABE.
Expand Down Expand Up @@ -206,8 +206,8 @@ where
let BioauthDeps {
robonode_client,
bioauth_flow_slot,
validator_key_extractor,
validator_signer_factory,
bioauth_validator_key_extractor,
bioauth_validator_signer_factory,
} = bioauth;

let BabeDeps {
Expand Down Expand Up @@ -268,8 +268,8 @@ where
io.extend_with(BioauthApi::to_delegate(Bioauth::new(
robonode_client,
bioauth_flow_slot,
validator_key_extractor,
validator_signer_factory,
bioauth_validator_key_extractor,
bioauth_validator_signer_factory,
Arc::clone(&client),
Arc::clone(&pool),
)));
Expand Down
2 changes: 2 additions & 0 deletions crates/humanode-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ substrate-wasm-builder = { git = "https://github.com/humanode-network/substrate"
bioauth-consensus-api = { version = "0.1", path = "../bioauth-consensus-api", default-features = false }
bioauth-flow-api = { version = "0.1", path = "../bioauth-flow-api", default-features = false }
frontier-api = { version = "0.1", path = "../frontier-api", default-features = false }
keystore-account-id = { version = "0.1", path = "../keystore-account-id", default-features = false }
pallet-bioauth = { version = "0.1", path = "../pallet-bioauth", default-features = false }
pallet-bioauth-session = { version = "0.1", path = "../pallet-bioauth-session", default-features = false }
pallet-ethereum-chain-id = { version = "0.1", path = "../pallet-ethereum-chain-id", default-features = false }
Expand Down Expand Up @@ -91,6 +92,7 @@ std = [
"frame-support/std",
"frame-system/std",
"frame-system-rpc-runtime-api/std",
"keystore-account-id/std",
"pallet-babe/std",
"pallet-bioauth/std",
"pallet-bioauth-session/std",
Expand Down
10 changes: 4 additions & 6 deletions crates/humanode-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs"));

use fp_rpc::TransactionStatus;
use keystore_account_id::KeystoreAccountId;
use pallet_bioauth::AuthTicket;
use pallet_ethereum::{Call::transact, Transaction as EthereumTransaction};
use pallet_evm::FeeCalculator;
Expand Down Expand Up @@ -765,12 +766,9 @@ impl_runtime_apis! {
}
}

impl bioauth_flow_api::BioauthFlowApi<Block, BioauthConsensusId, UnixMilliseconds> for Runtime {
fn bioauth_status(id: &BioauthConsensusId) -> bioauth_flow_api::BioauthStatus<UnixMilliseconds> {
let id = match Session::key_owner(BioauthConsensusId::ID, id.as_slice()) {
Some(account_id) => account_id,
None => return bioauth_flow_api::BioauthStatus::Inactive,
};
impl bioauth_flow_api::BioauthFlowApi<Block, KeystoreAccountId, UnixMilliseconds> for Runtime {
fn bioauth_status(id: &KeystoreAccountId) -> bioauth_flow_api::BioauthStatus<UnixMilliseconds> {
let id = AccountId::try_from(id.as_slice()).unwrap();
let active_authentications = Bioauth::active_authentications().into_inner();
let maybe_active_authentication = active_authentications
.iter()
Expand Down
14 changes: 14 additions & 0 deletions crates/keystore-account-id/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "keystore-account-id"
version = "0.1.0"
edition = "2021"
publish = false

[dependencies]
codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] }
scale-info = { version = "1.0", default-features = false, features = ["derive"] }
sp-application-crypto = { default-features = false, git = "https://github.com/humanode-network/substrate", branch = "master" }

[features]
default = ["std"]
std = ["codec/std", "scale-info/std", "sp-application-crypto/std"]
13 changes: 13 additions & 0 deletions crates/keystore-account-id/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Crypto primitives for AccountId key type.

// Either generate code at stadard mode, or `no_std`, based on the `std` feature presence.
#![cfg_attr(not(feature = "std"), no_std)]

/// AccountId key type definition.
mod app {
use sp_application_crypto::{app_crypto, key_types::ACCOUNT, sr25519};
app_crypto!(sr25519, ACCOUNT);
}

/// AccountId key type identifier.
pub type KeystoreAccountId = app::Public;

0 comments on commit 765109f

Please sign in to comment.