Skip to content

Commit

Permalink
Merge branch 'main' into add-coverage-report
Browse files Browse the repository at this point in the history
  • Loading branch information
marijanp authored Mar 28, 2024
2 parents 4f79d17 + b9fdf2c commit 95ca340
Show file tree
Hide file tree
Showing 27 changed files with 442 additions and 222 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"

members = [
"kairos-cli",
"kairos-crypto",
"kairos-server",
"kairos-tx",
"kairos-test-utils",
Expand Down
1 change: 1 addition & 0 deletions kairos-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ casper-types = { version = "4.0.1", features = ["std"] } # TODO: Change `std` ->
clap = { version = "4.5", features = ["derive", "deprecated"] }
hex = "0.4"
thiserror = "1"
kairos-crypto = { path = "../kairos-crypto" }

[dev-dependencies]
assert_cmd = "2"
Expand Down
8 changes: 5 additions & 3 deletions kairos-cli/src/commands/deposit.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -16,7 +18,7 @@ pub struct Args {
pub fn run(args: Args) -> Result<String, CliError> {
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`.

Expand Down
11 changes: 6 additions & 5 deletions kairos-cli/src/commands/transfer.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -18,10 +19,10 @@ pub struct Args {
}

pub fn run(args: Args) -> Result<String, CliError> {
let _recipient = CasperPublicKey::from_bytes(args.recipient.as_ref())?;
let _recipient = Signer::from_public_key(args.recipient)?.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`.

Expand Down
8 changes: 5 additions & 3 deletions kairos-cli/src/commands/withdraw.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -16,7 +18,7 @@ pub struct Args {
pub fn run(args: Args) -> Result<String, CliError> {
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`.

Expand Down
15 changes: 0 additions & 15 deletions kairos-cli/src/crypto/error.rs

This file was deleted.

4 changes: 0 additions & 4 deletions kairos-cli/src/crypto/mod.rs

This file was deleted.

11 changes: 0 additions & 11 deletions kairos-cli/src/crypto/private_key.rs

This file was deleted.

68 changes: 0 additions & 68 deletions kairos-cli/src/crypto/public_key.rs

This file was deleted.

38 changes: 0 additions & 38 deletions kairos-cli/src/crypto/signer.rs

This file was deleted.

2 changes: 1 addition & 1 deletion kairos-cli/src/error.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
1 change: 0 additions & 1 deletion kairos-cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
pub mod commands;
pub mod common;
pub mod crypto;
pub mod error;
pub mod utils;
17 changes: 17 additions & 0 deletions kairos-crypto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[package]
name = "kairos-crypto"
version.workspace = true
edition.workspace = true

[features]
default = ["crypto-casper"]
crypto-casper = ["casper-types"]

[lib]

[dependencies]
hex = "0.4"
thiserror = "1"

# Casper signer implementation.
casper-types = { version = "4", optional = true, features = ["std"] } # TODO: Change `std` -> `std-fs-io` in the future version.
20 changes: 20 additions & 0 deletions kairos-crypto/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
use thiserror::Error;

#[derive(Error, Debug)]
pub enum CryptoError {
/// Failed to parse a public key from a raw data.
#[error("failed to parse private key: {error}")]
FailedToParseKey { error: String },
/// Encoding related error.
#[error("failed to serialize '{context}'")]
Serialization { context: &'static str },
/// Invalid public key (hexdigest) or other decoding related error.
#[error("failed to deserialize '{context}'")]
Deserialization { context: &'static str },
/// Signature verification failure.
#[error("signature verification failed")]
InvalidSignature,
/// Private key is not provided.
#[error("private key is not provided")]
MissingPrivateKey,
}
Loading

0 comments on commit 95ca340

Please sign in to comment.