diff --git a/Cargo.toml b/Cargo.toml index 0719b478b..e798b9ed1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace.package] -version = "0.4.5" +version = "0.4.8" authors = ["Webb Technologies Inc."] edition = "2021" license = "Unlicense" diff --git a/standalone/node/src/cli.rs b/standalone/node/src/cli.rs index f65c238d3..bb246718c 100644 --- a/standalone/node/src/cli.rs +++ b/standalone/node/src/cli.rs @@ -92,4 +92,7 @@ pub enum Subcommand { /// Db meta columns information. FrontierDb(fc_cli::FrontierDbCmd), + + /// DKG signer + DKGSigner(crate::signer_cli::DKGSignerCmd), } diff --git a/standalone/node/src/command.rs b/standalone/node/src/command.rs index 8f986d6e7..552db668f 100644 --- a/standalone/node/src/command.rs +++ b/standalone/node/src/command.rs @@ -75,6 +75,7 @@ pub fn run() -> sc_cli::Result<()> { match &cli.subcommand { Some(Subcommand::Key(cmd)) => cmd.run(&cli), + Some(Subcommand::DKGSigner(cmd)) => cmd.run(&cli), Some(Subcommand::DKGKey(cmd)) => cmd.run(&cli), Some(Subcommand::BuildSpec(cmd)) => { let runner = cli.create_runner(cmd)?; diff --git a/standalone/node/src/lib.rs b/standalone/node/src/lib.rs index 1d44af52b..6632475c2 100644 --- a/standalone/node/src/lib.rs +++ b/standalone/node/src/lib.rs @@ -4,5 +4,6 @@ pub mod distributions; pub mod eth; pub mod rpc; pub mod service; +pub mod signer_cli; pub mod testnet_fixtures; pub mod utils; diff --git a/standalone/node/src/main.rs b/standalone/node/src/main.rs index 3e39eec41..50e79b8f2 100644 --- a/standalone/node/src/main.rs +++ b/standalone/node/src/main.rs @@ -10,6 +10,7 @@ mod command; mod distributions; mod eth; mod rpc; +mod signer_cli; mod testnet_fixtures; mod utils; diff --git a/standalone/node/src/signer_cli.rs b/standalone/node/src/signer_cli.rs new file mode 100644 index 000000000..08709a67a --- /dev/null +++ b/standalone/node/src/signer_cli.rs @@ -0,0 +1,76 @@ +#![allow(clippy::all)] +// Copyright 2023 Webb Technologies Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Signer module to sign data with wdkg keytype in keystore +use parity_scale_codec::{Decode, Encode}; +use sc_cli::{ + utils, with_crypto_scheme, CryptoScheme, Error, KeystoreParams, Result as CliResult, + SharedParams, SubstrateCli, +}; +use sc_keystore::LocalKeystore; +use sc_service::{config::KeystoreConfig, BasePath}; +use sp_keystore::KeystorePtr; +use sp_runtime::traits::{Block as BlockT, Header as HeaderT}; +use std::fmt::Debug; + +/// The `chain-info` subcommand used to output db meta columns information. +#[derive(Debug, Clone, clap::Parser)] +pub struct DKGSignerCmd { + /// Key type, examples: "gran", or "imon". + #[arg(long)] + data: String, + + #[allow(missing_docs)] + #[clap(flatten)] + pub shared_params: SharedParams, + + #[allow(missing_docs)] + #[clap(flatten)] + pub keystore_params: KeystoreParams, +} + +impl DKGSignerCmd { + /// Run the command + pub fn run(&self, cli: &C) -> Result<(), Error> { + let base_path = self + .shared_params + .base_path()? + .unwrap_or_else(|| BasePath::from_project("", "", &C::executable_name())); + let chain_id = self.shared_params.chain_id(self.shared_params.is_dev()); + let chain_spec = cli.load_spec(&chain_id)?; + let config_dir = base_path.config_dir(chain_spec.id()); + + let keystore = match self.keystore_params.keystore_config(&config_dir)? { + KeystoreConfig::Path { path, password } => { + let keystore: KeystorePtr = LocalKeystore::open(path, password)?.into(); + keystore + }, + _ => unreachable!("keystore_config always returns path and password; qed"), + }; + + let key_type = dkg_runtime_primitives::KEY_TYPE; + + let maybe_public = keystore.ecdsa_public_keys(key_type); + let public = maybe_public.first().unwrap(); + + let signature = keystore + .ecdsa_sign(key_type, &public, &self.data.as_bytes()) + .map_err(|_| Error::KeystoreOperation)?; + + println!("Signature : {:?}", signature); + + Ok(()) + } +}