Skip to content

Commit

Permalink
WIP: #4318 forc-crypto plugin exposing a CLI for common-use cryptog…
Browse files Browse the repository at this point in the history
…raphic operations

Supported algorithms:
* [x] keccak256
* [x] sha256
* [ ] ecrecover
* [x] bech32-to-hex
* [x] hex-to-bech32
  • Loading branch information
cr-fuel committed Sep 28, 2023
1 parent d37f706 commit 799fe49
Show file tree
Hide file tree
Showing 9 changed files with 261 additions and 31 deletions.
94 changes: 69 additions & 25 deletions Cargo.lock

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

8 changes: 2 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ members = [
"forc",
"forc-pkg",
"forc-plugins/forc-client",
"forc-plugins/forc-crypto",
"forc-plugins/forc-doc",
"forc-plugins/forc-fmt",
"forc-plugins/forc-lsp",
Expand All @@ -24,11 +25,7 @@ members = [
"swayfmt",
"test",
]
exclude = [
"examples/*",
"swayfmt/test_macros",
"forc-test/test_data"
]
exclude = ["examples/*", "swayfmt/test_macros", "forc-test/test_data"]

[workspace.dependencies]
# Dependencies from the `fuel-core` repository:
Expand All @@ -54,4 +51,3 @@ authors = ["Fuel Labs <contact@fuel.sh>"]
homepage = "https://fuel.network/"
license = "Apache-2.0"
repository = "https://github.com/FuelLabs/sway"

32 changes: 32 additions & 0 deletions forc-plugins/forc-crypto/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[package]
name = "forc-crypto"
version = "0.46.0"
description = "A `forc` plugin for interacting with a fuel's crypto library."
authors.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
repository.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
anyhow = "1.0.75"
async-trait = "0.1.58"
clap = { version = "3", features = ["derive", "env"] }
forc-tracing = { version = "0.46.0", path = "../../forc-tracing" }
forc-tx = { version = "0.46.0", path = "../forc-tx" }
fuel-crypto = { workspace = true }
fuels-core = { workspace = true }
futures = "0.3"
hex = "0.4.3"
rand = "0.8"
rpassword = "7.2"
serde = "1.0"
serde_json = "1"
sha2 = "0.10.8"
sha3 = "0.10.8"
strum = "0.25.0"
strum_macros = "0.25.2"
tokio = { version = "1.8", features = ["macros", "rt-multi-thread", "process"] }
tracing = "0.1"
24 changes: 24 additions & 0 deletions forc-plugins/forc-crypto/src/address.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use std::str::FromStr;

use fuel_crypto::fuel_types::Address;
use fuels_core::types::bech32::Bech32Address;

pub fn dump_address<T: AsRef<[u8]>>(data: T) -> String {
let bytes_32: Result<[u8; 32], _> = data.as_ref().try_into();
let (bech32, addr) = if let Ok(bytes) = bytes_32 {
let addr = Address::from(bytes);
(Bech32Address::from(addr), addr)
} else if let Ok(string) = String::from_utf8(data.as_ref().to_owned()) {
if let Ok(bech32) = Bech32Address::from_str(&string) {
(bech32.clone(), Address::from(bech32))
} else if let Ok(addr) = Address::from_str(&string) {
(Bech32Address::from(addr), addr)
} else {
panic!("{} cannot be parsed to a valid address", string);
}
} else {
panic!("{} cannot be parsed to a valid address", hex::encode(data));
};

format!("Bench32: {}\nAddress: 0x{}\n", bech32, addr,)
}
Loading

0 comments on commit 799fe49

Please sign in to comment.