Skip to content

Commit

Permalink
Merge pull request #78 from cspr-rad/feature/crypto-wasm-compatibility
Browse files Browse the repository at this point in the history
Hide filesystem functions in `kairos-crypto` behind feature flag.
  • Loading branch information
koxu1996 authored Apr 29, 2024
2 parents 366391c + d7d67a6 commit 06cfb1c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion kairos-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +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" }
kairos-crypto = { path = "../kairos-crypto", features = ["fs"] }

[dev-dependencies]
assert_cmd = "2"
Expand Down
3 changes: 2 additions & 1 deletion kairos-crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ license.workspace = true
[features]
default = ["crypto-casper"]
crypto-casper = ["casper-types"]
fs = ["casper-types/std"] # TODO: Change `std` -> `std-fs-io` in the future version.

[lib]

Expand All @@ -15,4 +16,4 @@ 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.
casper-types = { version = "4", optional = true }
3 changes: 3 additions & 0 deletions kairos-crypto/src/implementations/casper.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use casper_types::bytesrepr::{FromBytes, ToBytes};
use casper_types::{crypto, PublicKey, SecretKey, Signature};

#[cfg(feature = "fs")]
use std::path::Path;

use crate::CryptoError;
Expand All @@ -11,6 +13,7 @@ pub struct Signer {
}

impl CryptoSigner for Signer {
#[cfg(feature = "fs")]
fn from_private_key_file<P: AsRef<Path>>(file: P) -> Result<Self, CryptoError>
where
Self: Sized,
Expand Down
2 changes: 2 additions & 0 deletions kairos-crypto/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
pub mod error;
pub mod implementations;

#[cfg(feature = "fs")]
use std::path::Path;

use error::CryptoError;

pub trait CryptoSigner {
#[cfg(feature = "fs")]
fn from_private_key_file<P: AsRef<Path>>(file: P) -> Result<Self, CryptoError>
where
Self: Sized;
Expand Down

0 comments on commit 06cfb1c

Please sign in to comment.