From 81bc25b6d8a4be3c802534fdd23f469a0078e8a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andrzej=20Bro=C5=84ski?= Date: Sun, 17 Mar 2024 17:25:27 +0100 Subject: [PATCH] Use `kairos-crypto` in CLI parsing. --- Cargo.lock | 1 + kairos-cli/Cargo.toml | 1 + kairos-cli/src/commands/deposit.rs | 8 +++++--- kairos-cli/src/commands/transfer.rs | 11 ++++++----- kairos-cli/src/commands/withdraw.rs | 8 +++++--- kairos-cli/src/error.rs | 2 +- 6 files changed, 19 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 40986fbf..2d2a37e5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1050,6 +1050,7 @@ dependencies = [ "casper-types", "clap", "hex", + "kairos-crypto", "predicates", "thiserror", ] diff --git a/kairos-cli/Cargo.toml b/kairos-cli/Cargo.toml index abf507c8..7fcd037c 100644 --- a/kairos-cli/Cargo.toml +++ b/kairos-cli/Cargo.toml @@ -17,6 +17,7 @@ casper-types = { version = "4.0.1", features = ["std"] } # TODO: Change `std` -> clap = { version = "4.4.18", features = ["derive"] } hex = "0.4.3" thiserror = "1.0.56" +kairos-crypto = { path = "../kairos-crypto" } [dev-dependencies] assert_cmd = "2.0.13" diff --git a/kairos-cli/src/commands/deposit.rs b/kairos-cli/src/commands/deposit.rs index a90650ff..b4b95c99 100644 --- a/kairos-cli/src/commands/deposit.rs +++ b/kairos-cli/src/commands/deposit.rs @@ -1,8 +1,10 @@ use crate::common::args::{AmountArg, PrivateKeyPathArg}; -use crate::crypto::error::CryptoError; -use crate::crypto::signer::CasperSigner; use crate::error::CliError; +use kairos_crypto::error::CryptoError; +use kairos_crypto::implementations::Signer; +use kairos_crypto::CryptoSigner; + use clap::Parser; #[derive(Parser, Debug)] @@ -16,7 +18,7 @@ pub struct Args { pub fn run(args: Args) -> Result { let _amount: u64 = args.amount.field; let _signer = - CasperSigner::from_file(args.private_key_path.field).map_err(CryptoError::from)?; + Signer::from_private_key_file(args.private_key_path.field).map_err(CryptoError::from)?; // TODO: Create transaction and sign it with `signer`. diff --git a/kairos-cli/src/commands/transfer.rs b/kairos-cli/src/commands/transfer.rs index 508057eb..605d3821 100644 --- a/kairos-cli/src/commands/transfer.rs +++ b/kairos-cli/src/commands/transfer.rs @@ -1,10 +1,11 @@ use crate::common::args::{AmountArg, PrivateKeyPathArg}; -use crate::crypto::error::CryptoError; -use crate::crypto::public_key::CasperPublicKey; -use crate::crypto::signer::CasperSigner; use crate::error::CliError; use crate::utils::parse_hex_string; +use kairos_crypto::error::CryptoError; +use kairos_crypto::implementations::Signer; +use kairos_crypto::CryptoSigner; + use clap::Parser; #[derive(Parser)] @@ -18,10 +19,10 @@ pub struct Args { } pub fn run(args: Args) -> Result { - let _recipient = CasperPublicKey::from_bytes(args.recipient.as_ref())?; + let _recipient = Signer::from_public_key(args.recipient.as_ref())?.to_public_key()?; let _amount: u64 = args.amount.field; let _signer = - CasperSigner::from_file(args.private_key_path.field).map_err(CryptoError::from)?; + Signer::from_private_key_file(args.private_key_path.field).map_err(CryptoError::from)?; // TODO: Create transaction and sign it with `signer`. diff --git a/kairos-cli/src/commands/withdraw.rs b/kairos-cli/src/commands/withdraw.rs index 45a6b130..13490eb2 100644 --- a/kairos-cli/src/commands/withdraw.rs +++ b/kairos-cli/src/commands/withdraw.rs @@ -1,8 +1,10 @@ use crate::common::args::{AmountArg, PrivateKeyPathArg}; -use crate::crypto::error::CryptoError; -use crate::crypto::signer::CasperSigner; use crate::error::CliError; +use kairos_crypto::error::CryptoError; +use kairos_crypto::implementations::Signer; +use kairos_crypto::CryptoSigner; + use clap::Parser; #[derive(Parser)] @@ -16,7 +18,7 @@ pub struct Args { pub fn run(args: Args) -> Result { let _amount: u64 = args.amount.field; let _signer = - CasperSigner::from_file(args.private_key_path.field).map_err(CryptoError::from)?; + Signer::from_private_key_file(args.private_key_path.field).map_err(CryptoError::from)?; // TODO: Create transaction and sign it with `signer`. diff --git a/kairos-cli/src/error.rs b/kairos-cli/src/error.rs index 9338ee2b..19558e20 100644 --- a/kairos-cli/src/error.rs +++ b/kairos-cli/src/error.rs @@ -1,7 +1,7 @@ use hex::FromHexError; use thiserror::Error; -use crate::crypto::error::CryptoError; +use kairos_crypto::error::CryptoError; #[derive(Error, Debug)] pub enum CliError {