-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: #4318
forc-crypto
plugin exposing a CLI for common-use cryptog…
…raphic operations Supported algorithms: * [x] keccak256 * [x] sha256 * [ ] ecrecover * [x] bech32-to-hex * [x] hex-to-bech32
- Loading branch information
Showing
9 changed files
with
264 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" } | ||
fuel-crypto = { workspace = true } | ||
fuels-core = { workspace = true } | ||
forc-tx = { version = "0.46.0", path = "../forc-tx" } | ||
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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.clone()), 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.clone()), 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.to_string(), | ||
addr.to_string() | ||
) | ||
} |
Oops, something went wrong.