From 5405584475b99a4cb1f99db1b898cd52d3ebeaa0 Mon Sep 17 00:00:00 2001 From: Cesar <142530682+cr-fuel@users.noreply.github.com> Date: Tue, 17 Oct 2023 21:56:26 -0300 Subject: [PATCH 1/7] Split keygen into a create and a binary Split so it can be inherited from other binaries https://github.com/FuelLabs/sway/issues/5170 --- CHANGELOG.md | 1 + Cargo.lock | 9 +++++++++ Cargo.toml | 4 +++- bin/keygen/Cargo.toml | 6 ++---- crates/keygen/Cargo.toml | 19 +++++++++++++++++++ {bin => crates}/keygen/src/keygen.rs | 0 {bin => crates}/keygen/src/lib.rs | 0 7 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 crates/keygen/Cargo.toml rename {bin => crates}/keygen/src/keygen.rs (100%) rename {bin => crates}/keygen/src/lib.rs (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 85a31d08256..97bc23673dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ Description of the upcoming release here. ### Added - [#1432](https://github.com/FuelLabs/fuel-core/pull/1432): Add a new `--api-request-timeout` argument to control TTL for GraphQL requests. +- [#1426](https://github.com/FuelLabs/fuel-core/pull/1426) Split keygen into a create and a binary - [#1419](https://github.com/FuelLabs/fuel-core/pull/1419): Add additional "sanity" benchmarks for arithmetic op code instructions. - [#1411](https://github.com/FuelLabs/fuel-core/pull/1411): Added WASM and `no_std` compatibility - [#1371](https://github.com/FuelLabs/fuel-core/pull/1371): Add new client function for querying the `MessageStatus` for a specific message (by `Nonce`) diff --git a/Cargo.lock b/Cargo.lock index 700302fe7aa..25fc29a79ec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2950,6 +2950,15 @@ dependencies = [ "serde_json", ] +[[package]] +name = "fuel-core-keygen-bin" +version = "0.20.4" +dependencies = [ + "anyhow", + "clap 4.4.6", + "fuel-core-keygen", +] + [[package]] name = "fuel-core-metrics" version = "0.20.4" diff --git a/Cargo.toml b/Cargo.toml index d7f9bdc939a..4bbc97a3e14 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ members = [ "crates/client", "crates/database", "crates/fuel-core", + "crates/keygen", "crates/metrics", "crates/services", "crates/services/consensus_module", @@ -52,7 +53,8 @@ version = "0.20.4" fuel-core = { version = "0.20.4", path = "./crates/fuel-core", default-features = false } fuel-core-client-bin = { version = "0.20.4", path = "./bin/client" } fuel-core-bin = { version = "0.20.4", path = "./bin/fuel-core" } -fuel-core-keygen = { version = "0.20.4", path = "./bin/keygen" } +fuel-core-keygen = { version = "0.20.4", path = "./crates/keygen" } +fuel-core-keygen-bin = { version = "0.20.4", path = "./bin/keygen" } fuel-core-chain-config = { version = "0.20.4", path = "./crates/chain-config" } fuel-core-client = { version = "0.20.4", path = "./crates/client" } fuel-core-database = { version = "0.20.4", path = "./crates/database" } diff --git a/bin/keygen/Cargo.toml b/bin/keygen/Cargo.toml index b74b70fb958..71735bcc491 100644 --- a/bin/keygen/Cargo.toml +++ b/bin/keygen/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "fuel-core-keygen" +name = "fuel-core-keygen-bin" version = { workspace = true } edition = { workspace = true } homepage = { workspace = true } @@ -12,6 +12,4 @@ description = "Command line utilities for fuel-core key management" [dependencies] anyhow = { workspace = true } clap = { workspace = true, features = ["derive", "env"] } -fuel-core-types = { workspace = true, features = ["serde", "random"] } -libp2p-identity = { version = "0.2.4", features = ["secp256k1", "peerid"] } -serde_json = { workspace = true, features = ["raw_value"] } +fuel-core-keygen = { workspace = true } diff --git a/crates/keygen/Cargo.toml b/crates/keygen/Cargo.toml new file mode 100644 index 00000000000..dc975bec090 --- /dev/null +++ b/crates/keygen/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "fuel-core-keygen" +authors = { workspace = true } +categories = { workspace = true } +version = { workspace = true } +edition = { workspace = true } +homepage = { workspace = true } +keywords = { workspace = true } +license = { workspace = true } +repository = { workspace = true } +description = "Create to create command line utilities for fuel-core key management" +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +anyhow = { workspace = true } +clap = { workspace = true, features = ["derive", "env"] } +fuel-core-types = { workspace = true, features = ["serde", "random"] } +libp2p-identity = { version = "0.2.4", features = ["secp256k1", "peerid"] } +serde_json = { workspace = true, features = ["raw_value"] } diff --git a/bin/keygen/src/keygen.rs b/crates/keygen/src/keygen.rs similarity index 100% rename from bin/keygen/src/keygen.rs rename to crates/keygen/src/keygen.rs diff --git a/bin/keygen/src/lib.rs b/crates/keygen/src/lib.rs similarity index 100% rename from bin/keygen/src/lib.rs rename to crates/keygen/src/lib.rs From b3493a9922ca5ace99bae05b079426ef97e1ad26 Mon Sep 17 00:00:00 2001 From: Cesar <142530682+cr-fuel@users.noreply.github.com> Date: Wed, 18 Oct 2023 00:43:18 -0300 Subject: [PATCH 2/7] Remove comment from Cargo.toml --- crates/keygen/Cargo.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/keygen/Cargo.toml b/crates/keygen/Cargo.toml index dc975bec090..b470d770d7f 100644 --- a/crates/keygen/Cargo.toml +++ b/crates/keygen/Cargo.toml @@ -9,7 +9,6 @@ keywords = { workspace = true } license = { workspace = true } repository = { workspace = true } description = "Create to create command line utilities for fuel-core key management" -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] anyhow = { workspace = true } From 328b1b8ffb589782ed3d1cefd1bce5984768396c Mon Sep 17 00:00:00 2001 From: Cesar <142530682+cr-fuel@users.noreply.github.com> Date: Wed, 18 Oct 2023 01:20:43 -0300 Subject: [PATCH 3/7] Add secret display --- Cargo.lock | 28 ++++++++++++++++++++++++++++ crates/keygen/Cargo.toml | 1 + crates/keygen/src/keygen.rs | 28 +++++++++++++++++++++++++++- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 25fc29a79ec..1f6b0c1d3db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2948,6 +2948,7 @@ dependencies = [ "fuel-core-types", "libp2p-identity 0.2.5", "serde_json", + "termion", ] [[package]] @@ -5413,6 +5414,12 @@ dependencies = [ "syn 2.0.38", ] +[[package]] +name = "numtoa" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" + [[package]] name = "object" version = "0.32.1" @@ -6493,6 +6500,15 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_termios" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" +dependencies = [ + "redox_syscall 0.2.16", +] + [[package]] name = "redox_users" version = "0.4.3" @@ -7809,6 +7825,18 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "termion" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "659c1f379f3408c7e5e84c7d0da6d93404e3800b6b9d063ba24436419302ec90" +dependencies = [ + "libc", + "numtoa", + "redox_syscall 0.2.16", + "redox_termios", +] + [[package]] name = "termtree" version = "0.4.1" diff --git a/crates/keygen/Cargo.toml b/crates/keygen/Cargo.toml index b470d770d7f..d81b7d21055 100644 --- a/crates/keygen/Cargo.toml +++ b/crates/keygen/Cargo.toml @@ -16,3 +16,4 @@ clap = { workspace = true, features = ["derive", "env"] } fuel-core-types = { workspace = true, features = ["serde", "random"] } libp2p-identity = { version = "0.2.4", features = ["secp256k1", "peerid"] } serde_json = { workspace = true, features = ["raw_value"] } +termion = "2.0.1" diff --git a/crates/keygen/src/keygen.rs b/crates/keygen/src/keygen.rs index 151461c16f7..89536a93562 100644 --- a/crates/keygen/src/keygen.rs +++ b/crates/keygen/src/keygen.rs @@ -20,6 +20,10 @@ use libp2p_identity::{ }; use serde_json::json; use std::{ + io::{ + Read, + Write, + }, ops::Deref, str::FromStr, }; @@ -126,6 +130,24 @@ impl ParseSecret { } } +fn wait_for_keypress() { + let mut single_key = [0u8]; + std::io::stdin().read_exact(&mut single_key).unwrap(); +} + +fn display_string_discreetly( + discreet_string: &str, + continue_message: &str, +) -> anyhow::Result<()> { + use termion::screen::IntoAlternateScreen; + let mut screen = std::io::stdout().into_alternate_screen()?; + writeln!(screen, "{discreet_string}")?; + screen.flush()?; + println!("{continue_message}"); + wait_for_keypress(); + Ok(()) +} + fn print_value(output: serde_json::Value, pretty: bool) -> anyhow::Result<()> { let output = if pretty { serde_json::to_string_pretty(&output) @@ -133,6 +155,10 @@ fn print_value(output: serde_json::Value, pretty: bool) -> anyhow::Result<()> { serde_json::to_string(&output) } .map_err(anyhow::Error::msg); - println!("{}", output?); + + let _ = display_string_discreetly( + &output?, + "### Do not share or lose this private key! Press any key to complete. ###", + ); Ok(()) } From 2800e4a950570f3c87438c9f188410afef4451fd Mon Sep 17 00:00:00 2001 From: Cesar <142530682+cr-fuel@users.noreply.github.com> Date: Wed, 18 Oct 2023 20:31:45 -0300 Subject: [PATCH 4/7] Print secret message to tty If stdout is not a tty (i.e it is a pipe to another process or it writes to another file) a normal message will be printed. --- Cargo.lock | 1 + crates/keygen/Cargo.toml | 1 + crates/keygen/src/keygen.rs | 21 ++++++++++++++------- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1f6b0c1d3db..ecc1fdac1f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2944,6 +2944,7 @@ name = "fuel-core-keygen" version = "0.20.4" dependencies = [ "anyhow", + "atty", "clap 4.4.6", "fuel-core-types", "libp2p-identity 0.2.5", diff --git a/crates/keygen/Cargo.toml b/crates/keygen/Cargo.toml index d81b7d21055..53569f0123e 100644 --- a/crates/keygen/Cargo.toml +++ b/crates/keygen/Cargo.toml @@ -12,6 +12,7 @@ description = "Create to create command line utilities for fuel-core key managem [dependencies] anyhow = { workspace = true } +atty = "0.2.14" clap = { workspace = true, features = ["derive", "env"] } fuel-core-types = { workspace = true, features = ["serde", "random"] } libp2p-identity = { version = "0.2.4", features = ["secp256k1", "peerid"] } diff --git a/crates/keygen/src/keygen.rs b/crates/keygen/src/keygen.rs index 89536a93562..ba817f7040a 100644 --- a/crates/keygen/src/keygen.rs +++ b/crates/keygen/src/keygen.rs @@ -2,6 +2,7 @@ use crate::{ BLOCK_PRODUCTION, P2P, }; +use atty::Stream; use clap::ValueEnum; use fuel_core_types::{ fuel_crypto::{ @@ -21,12 +22,15 @@ use libp2p_identity::{ use serde_json::json; use std::{ io::{ + stdin, + stdout, Read, Write, }, ops::Deref, str::FromStr, }; +use termion::screen::IntoAlternateScreen; /// Generate a random new secret & public key in the format expected by fuel-core #[derive(Debug, clap::Args)] @@ -132,19 +136,22 @@ impl ParseSecret { fn wait_for_keypress() { let mut single_key = [0u8]; - std::io::stdin().read_exact(&mut single_key).unwrap(); + stdin().read_exact(&mut single_key).unwrap(); } fn display_string_discreetly( discreet_string: &str, continue_message: &str, ) -> anyhow::Result<()> { - use termion::screen::IntoAlternateScreen; - let mut screen = std::io::stdout().into_alternate_screen()?; - writeln!(screen, "{discreet_string}")?; - screen.flush()?; - println!("{continue_message}"); - wait_for_keypress(); + if atty::is(Stream::Stdout) { + let mut screen = stdout().into_alternate_screen()?; + writeln!(screen, "{discreet_string}")?; + screen.flush()?; + println!("{continue_message}"); + wait_for_keypress(); + } else { + println!("{discreet_string}"); + } Ok(()) } From fe30bc87d0c48c3be2b4ce09f64d1671daa806bd Mon Sep 17 00:00:00 2001 From: Cesar <142530682+cr-fuel@users.noreply.github.com> Date: Mon, 23 Oct 2023 02:05:09 -0300 Subject: [PATCH 5/7] Update fuel-core-keygen reference to fuel-core-keygen-bin in ci --- .github/workflows/ci.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d6e2700a769..ba27ab235e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -478,13 +478,13 @@ jobs: - name: Build fuel-core and fuel-core-keygen run: | cross build --profile=release --target ${{ matrix.job.target }} --no-default-features --features "production" -p fuel-core-bin - cross build --profile=release --target ${{ matrix.job.target }} -p fuel-core-keygen + cross build --profile=release --target ${{ matrix.job.target }} -p fuel-core-keygen-bin - name: Strip release binary linux x86_64 if: matrix.job.platform == 'linux' run: | strip "target/${{ matrix.job.target }}/release/fuel-core" - strip "target/${{ matrix.job.target }}/release/fuel-core-keygen" + strip "target/${{ matrix.job.target }}/release/fuel-core-keygen-bin" - name: Strip release binary aarch64-linux-gnu if: matrix.job.target == 'aarch64-unknown-linux-gnu' @@ -498,13 +498,13 @@ jobs: "$PWD/target:/target:Z" \ aarch64-linux-gnu:latest \ aarch64-linux-gnu-strip \ - /target/aarch64-unknown-linux-gnu/release/fuel-core-keygen + /target/aarch64-unknown-linux-gnu/release/fuel-core-keygen-bin - name: Strip release binary mac if: matrix.job.os == 'macos-latest' run: | strip -x "target/${{ matrix.job.target }}/release/fuel-core" - strip -x "target/${{ matrix.job.target }}/release/fuel-core-keygen" + strip -x "target/${{ matrix.job.target }}/release/fuel-core-keygen-bin" - name: Prepare Binary Artifact env: @@ -523,7 +523,7 @@ jobs: # create zip file mkdir -pv "$ARTIFACT" cp "target/${{ matrix.job.target }}/release/fuel-core" "$ARTIFACT" - cp "target/${{ matrix.job.target }}/release/fuel-core-keygen" "$ARTIFACT" + cp "target/${{ matrix.job.target }}/release/fuel-core-keygen-bin" "$ARTIFACT" tar -czvf "$ZIP_FILE_NAME" "$ARTIFACT" - name: Upload Binary Artifact @@ -604,4 +604,4 @@ jobs: - uses: actions/checkout@v3 - uses: actions-rs/audit-check@v1 with: - token: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + token: ${{ secrets.GITHUB_TOKEN }} From 60a8cde80c2f345eee6a35531c9418dce3a74917 Mon Sep 17 00:00:00 2001 From: xgreenx Date: Mon, 23 Oct 2023 11:59:36 +0200 Subject: [PATCH 6/7] Update debugging documentation --- docs/developers/debugging.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/developers/debugging.md b/docs/developers/debugging.md index 08b2ab2b81c..06b41322d5d 100644 --- a/docs/developers/debugging.md +++ b/docs/developers/debugging.md @@ -50,10 +50,10 @@ Using environment variables for CLI arguments allows these values to be reused a When running the client with the P2P service enabled, i.e., building the binary with the `p2p` feature and supplying the runtime argument `--enable-p2p`, the client will connect to a Fuel network. This requires additional CLI arguments, including the `--keypair` and `--network` arguments. -A key pair can be generated by running the utility binary `fuel-core-keygen`: +A key pair can be generated by running the utility binary `fuel-core-keygen-bin`: ```bash -cargo run --bin fuel-core-keygen new +cargo run --bin fuel-core-keygen-bin new ``` The resulting key pair printed to the console contains an address and secret. The `secret` can be provided to the `--keypair` argument when running the node. From 4480fe93fbafd02883454a4213dc51327123e632 Mon Sep 17 00:00:00 2001 From: xgreenx Date: Mon, 23 Oct 2023 16:11:33 +0200 Subject: [PATCH 7/7] Fixed Cargo conflicts --- Cargo.lock | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 6dbe38188ab..a389f07cc47 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2947,10 +2947,21 @@ name = "fuel-core-keygen" version = "0.20.4" dependencies = [ "anyhow", + "atty", "clap 4.4.6", "fuel-core-types", "libp2p-identity 0.2.7", "serde_json", + "termion", +] + +[[package]] +name = "fuel-core-keygen-bin" +version = "0.20.4" +dependencies = [ + "anyhow", + "clap 4.4.6", + "fuel-core-keygen", ] [[package]] @@ -5406,6 +5417,12 @@ dependencies = [ "syn 2.0.38", ] +[[package]] +name = "numtoa" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" + [[package]] name = "object" version = "0.32.1" @@ -6501,6 +6518,15 @@ dependencies = [ "bitflags 1.3.2", ] +[[package]] +name = "redox_termios" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8440d8acb4fd3d277125b4bd01a6f38aee8d814b3b5fc09b3f2b825d37d3fe8f" +dependencies = [ + "redox_syscall 0.2.16", +] + [[package]] name = "redox_users" version = "0.4.3" @@ -7817,6 +7843,18 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "termion" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "659c1f379f3408c7e5e84c7d0da6d93404e3800b6b9d063ba24436419302ec90" +dependencies = [ + "libc", + "numtoa", + "redox_syscall 0.2.16", + "redox_termios", +] + [[package]] name = "termtree" version = "0.4.1"