Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split keygen into a create and a binary #1426

Merged
merged 8 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -604,4 +604,4 @@ jobs:
- uses: actions/checkout@v3
- uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Description of the upcoming release here.
- [#1436](https://github.com/FuelLabs/fuel-core/pull/1436): Add a github action to continuously test beta-4.
- [#1430](https://github.com/FuelLabs/fuel-core/pull/1430): Add "sanity" benchmarks for crypto opcodes.
- [#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
Voxelot marked this conversation as resolved.
Show resolved Hide resolved
- [#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.
- [#1400](https://github.com/FuelLabs/fuel-core/pull/1400): Add releasy beta to fuel-core so that new commits to fuel-core master triggers fuels-rs.
Expand Down
38 changes: 38 additions & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"crates/client",
"crates/database",
"crates/fuel-core",
"crates/keygen",
"crates/metrics",
"crates/services",
"crates/services/consensus_module",
Expand Down Expand Up @@ -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" }
Expand Down
6 changes: 2 additions & 4 deletions bin/keygen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "fuel-core-keygen"
name = "fuel-core-keygen-bin"
version = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
Expand All @@ -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 }
20 changes: 20 additions & 0 deletions crates/keygen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[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"

[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"] }
serde_json = { workspace = true, features = ["raw_value"] }
termion = "2.0.1"
35 changes: 34 additions & 1 deletion bin/keygen/src/keygen.rs → crates/keygen/src/keygen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{
BLOCK_PRODUCTION,
P2P,
};
use atty::Stream;
use clap::ValueEnum;
use fuel_core_types::{
fuel_crypto::{
Expand All @@ -20,9 +21,16 @@ 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)]
Expand Down Expand Up @@ -126,13 +134,38 @@ impl ParseSecret {
}
}

fn wait_for_keypress() {
let mut single_key = [0u8];
stdin().read_exact(&mut single_key).unwrap();
}

fn display_string_discreetly(
discreet_string: &str,
continue_message: &str,
) -> anyhow::Result<()> {
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(())
}

fn print_value(output: serde_json::Value, pretty: bool) -> anyhow::Result<()> {
let output = if pretty {
serde_json::to_string_pretty(&output)
} else {
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(())
}
File renamed without changes.
4 changes: 2 additions & 2 deletions docs/developers/debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading