diff --git a/Cargo.lock b/Cargo.lock index 35f4734c6..f6f4241ab 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -525,15 +525,6 @@ dependencies = [ "sp-std", ] -[[package]] -name = "bioauth-id" -version = "0.1.0" -dependencies = [ - "parity-scale-codec", - "scale-info", - "sp-application-crypto", -] - [[package]] name = "bitflags" version = "1.3.2" @@ -2736,6 +2727,7 @@ dependencies = [ "humanode-rpc", "humanode-runtime", "indoc", + "keystore-account-id", "ngrok-api", "pallet-bioauth", "pallet-dynamic-fee", @@ -2836,6 +2828,7 @@ dependencies = [ "frame-system-rpc-runtime-api", "frontier-api", "hex-literal", + "keystore-account-id", "pallet-babe", "pallet-balances", "pallet-base-fee", @@ -3316,6 +3309,15 @@ dependencies = [ "winapi-build", ] +[[package]] +name = "keystore-account-id" +version = "0.1.0" +dependencies = [ + "parity-scale-codec", + "scale-info", + "sp-application-crypto", +] + [[package]] name = "kv-log-macro" version = "1.0.7" diff --git a/crates/bioauth-id/Cargo.toml b/crates/bioauth-id/Cargo.toml deleted file mode 100644 index c3a0e75ab..000000000 --- a/crates/bioauth-id/Cargo.toml +++ /dev/null @@ -1,10 +0,0 @@ -[package] -name = "bioauth-id" -version = "0.1.0" -edition = "2021" -publish = false - -[dependencies] -codec = { package = "parity-scale-codec", version = "2.0.0" } -scale-info = { version = "1.0", default-features = false, features = ["derive"] } -sp-application-crypto = { git = "https://github.com/humanode-network/substrate", branch = "master" } diff --git a/crates/bioauth-id/src/lib.rs b/crates/bioauth-id/src/lib.rs deleted file mode 100644 index 4d15f535f..000000000 --- a/crates/bioauth-id/src/lib.rs +++ /dev/null @@ -1,10 +0,0 @@ -//! Crypto primitives for bioauth account. - -/// Bioauth crypto keys definition. -mod app { - use sp_application_crypto::{app_crypto, key_types::ACCOUNT, sr25519}; - app_crypto!(sr25519, ACCOUNT); -} - -/// A Bioauth authority identifier. -pub type AuthorityId = app::Public; diff --git a/crates/humanode-peer/Cargo.toml b/crates/humanode-peer/Cargo.toml index 627e3a7e5..61eef7674 100644 --- a/crates/humanode-peer/Cargo.toml +++ b/crates/humanode-peer/Cargo.toml @@ -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" } diff --git a/crates/humanode-peer/src/cli/subcommand/bioauth/key/generate.rs b/crates/humanode-peer/src/cli/subcommand/bioauth/key/generate.rs index 502252cc3..b71c5f6de 100644 --- a/crates/humanode-peer/src/cli/subcommand/bioauth/key/generate.rs +++ b/crates/humanode-peer/src/cli/subcommand/bioauth/key/generate.rs @@ -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; @@ -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::(mnemonic.phrase(), None, None, output); + utils::print_from_uri::(mnemonic.phrase(), None, None, output); Ok(()) } diff --git a/crates/humanode-peer/src/cli/subcommand/bioauth/key/insert.rs b/crates/humanode-peer/src/cli/subcommand/bioauth/key/insert.rs index 3d3c50e9b..ad88674fe 100644 --- a/crates/humanode-peer/src/cli/subcommand/bioauth/key/insert.rs +++ b/crates/humanode-peer/src/cli/subcommand/bioauth/key/insert.rs @@ -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}; @@ -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::(Arc::clone(&keystore)) + ensure_bioauth_key_absent::(Arc::clone(&keystore)) .await .map_err(|err| sc_cli::Error::Service(sc_service::Error::Other(err.to_string())))?; - insert_bioauth_key::(self.suri.as_ref(), keystore).await?; + insert_bioauth_key::(self.suri.as_ref(), keystore).await?; Ok(()) } } diff --git a/crates/humanode-peer/src/cli/subcommand/bioauth/key/inspect.rs b/crates/humanode-peer/src/cli/subcommand/bioauth/key/inspect.rs index e3ecc0dac..d3aa106cc 100644 --- a/crates/humanode-peer/src/cli/subcommand/bioauth/key/inspect.rs +++ b/crates/humanode-peer/src/cli/subcommand/bioauth/key/inspect.rs @@ -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; @@ -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::(mnemonic.phrase(), None, None, output); + utils::print_from_uri::(mnemonic.phrase(), None, None, output); Ok(()) } diff --git a/crates/humanode-peer/src/cli/subcommand/bioauth/key/list.rs b/crates/humanode-peer/src/cli/subcommand/bioauth/key/list.rs index c4336931a..93a997bf1 100644 --- a/crates/humanode-peer/src/cli/subcommand/bioauth/key/list.rs +++ b/crates/humanode-peer/src/cli/subcommand/bioauth/key/list.rs @@ -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; @@ -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::::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::::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); } diff --git a/crates/humanode-peer/src/cli/subcommand/bioauth/key/mod.rs b/crates/humanode-peer/src/cli/subcommand/bioauth/key/mod.rs index e90184d29..6771c4a21 100644 --- a/crates/humanode-peer/src/cli/subcommand/bioauth/key/mod.rs +++ b/crates/humanode-peer/src/cli/subcommand/bioauth/key/mod.rs @@ -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 = <::Pair as sp_application_crypto::AppPair>::Generic; +pub type BioauthPair = <::Pair as sp_application_crypto::AppPair>::Generic; /// Subcommands for the `bioauth key` command. #[derive(Debug, StructOpt)] diff --git a/crates/humanode-peer/src/service/mod.rs b/crates/humanode-peer/src/service/mod.rs index 7abd9e96e..51751e8b4 100644 --- a/crates/humanode-peer/src/service/mod.rs +++ b/crates/humanode-peer/src/service/mod.rs @@ -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; @@ -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; @@ -334,8 +334,11 @@ pub async fn new_full(config: Configuration) -> Result::new(keystore_container.sync_keystore())); + let bioauth_validator_signer_factory = { let keystore = keystore_container.keystore(); Arc::new(move |key| { crate::validator_key::AppCryptoSigner::new( @@ -388,8 +391,8 @@ pub async fn new_full(config: Configuration) -> Result Result::from_keystore( + crate::validator_key::AppCryptoPublic::::from_keystore( keystore.as_ref(), ) .await; diff --git a/crates/humanode-rpc/src/lib.rs b/crates/humanode-rpc/src/lib.rs index f1d7754d7..adb836cac 100644 --- a/crates/humanode-rpc/src/lib.rs +++ b/crates/humanode-rpc/src/lib.rs @@ -50,10 +50,10 @@ pub struct BioauthDeps { pub robonode_client: Arc, /// The liveness data tx slot to use in the bioauth flow RPC. pub bioauth_flow_slot: Arc, - /// 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. @@ -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 { @@ -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), ))); diff --git a/crates/humanode-runtime/Cargo.toml b/crates/humanode-runtime/Cargo.toml index c7a1580a9..de4c886e9 100644 --- a/crates/humanode-runtime/Cargo.toml +++ b/crates/humanode-runtime/Cargo.toml @@ -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 } @@ -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", diff --git a/crates/humanode-runtime/src/lib.rs b/crates/humanode-runtime/src/lib.rs index d2a8d537b..da775f3b5 100644 --- a/crates/humanode-runtime/src/lib.rs +++ b/crates/humanode-runtime/src/lib.rs @@ -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; @@ -765,12 +766,9 @@ impl_runtime_apis! { } } - impl bioauth_flow_api::BioauthFlowApi for Runtime { - fn bioauth_status(id: &BioauthConsensusId) -> bioauth_flow_api::BioauthStatus { - 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 for Runtime { + fn bioauth_status(id: &KeystoreAccountId) -> bioauth_flow_api::BioauthStatus { + let id = AccountId::try_from(id.as_slice()).unwrap(); let active_authentications = Bioauth::active_authentications().into_inner(); let maybe_active_authentication = active_authentications .iter() diff --git a/crates/keystore-account-id/Cargo.toml b/crates/keystore-account-id/Cargo.toml new file mode 100644 index 000000000..d03e1651d --- /dev/null +++ b/crates/keystore-account-id/Cargo.toml @@ -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"] diff --git a/crates/keystore-account-id/src/lib.rs b/crates/keystore-account-id/src/lib.rs new file mode 100644 index 000000000..793f56477 --- /dev/null +++ b/crates/keystore-account-id/src/lib.rs @@ -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;