Skip to content

Commit 6c59fa4

Browse files
committed
Split keygen into a create and a binary (#1426)
Split so it can be inherited from other binaries https://github.com/FuelLabs/sway/issues/5170
1 parent 0d9e252 commit 6c59fa4

File tree

9 files changed

+106
-14
lines changed

9 files changed

+106
-14
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,13 @@ jobs:
478478
- name: Build fuel-core and fuel-core-keygen
479479
run: |
480480
cross build --profile=release --target ${{ matrix.job.target }} --no-default-features --features "production" -p fuel-core-bin
481-
cross build --profile=release --target ${{ matrix.job.target }} -p fuel-core-keygen
481+
cross build --profile=release --target ${{ matrix.job.target }} -p fuel-core-keygen-bin
482482
483483
- name: Strip release binary linux x86_64
484484
if: matrix.job.platform == 'linux'
485485
run: |
486486
strip "target/${{ matrix.job.target }}/release/fuel-core"
487-
strip "target/${{ matrix.job.target }}/release/fuel-core-keygen"
487+
strip "target/${{ matrix.job.target }}/release/fuel-core-keygen-bin"
488488
489489
- name: Strip release binary aarch64-linux-gnu
490490
if: matrix.job.target == 'aarch64-unknown-linux-gnu'
@@ -498,13 +498,13 @@ jobs:
498498
"$PWD/target:/target:Z" \
499499
aarch64-linux-gnu:latest \
500500
aarch64-linux-gnu-strip \
501-
/target/aarch64-unknown-linux-gnu/release/fuel-core-keygen
501+
/target/aarch64-unknown-linux-gnu/release/fuel-core-keygen-bin
502502
503503
- name: Strip release binary mac
504504
if: matrix.job.os == 'macos-latest'
505505
run: |
506506
strip -x "target/${{ matrix.job.target }}/release/fuel-core"
507-
strip -x "target/${{ matrix.job.target }}/release/fuel-core-keygen"
507+
strip -x "target/${{ matrix.job.target }}/release/fuel-core-keygen-bin"
508508
509509
- name: Prepare Binary Artifact
510510
env:
@@ -523,7 +523,7 @@ jobs:
523523
# create zip file
524524
mkdir -pv "$ARTIFACT"
525525
cp "target/${{ matrix.job.target }}/release/fuel-core" "$ARTIFACT"
526-
cp "target/${{ matrix.job.target }}/release/fuel-core-keygen" "$ARTIFACT"
526+
cp "target/${{ matrix.job.target }}/release/fuel-core-keygen-bin" "$ARTIFACT"
527527
tar -czvf "$ZIP_FILE_NAME" "$ARTIFACT"
528528
529529
- name: Upload Binary Artifact
@@ -604,4 +604,4 @@ jobs:
604604
- uses: actions/checkout@v3
605605
- uses: actions-rs/audit-check@v1
606606
with:
607-
token: ${{ secrets.GITHUB_TOKEN }}
607+
token: ${{ secrets.GITHUB_TOKEN }}

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Description of the upcoming release here.
1313
- [#1436](https://github.com/FuelLabs/fuel-core/pull/1436): Add a github action to continuously test beta-4.
1414
- [#1430](https://github.com/FuelLabs/fuel-core/pull/1430): Add "sanity" benchmarks for crypto opcodes.
1515
- [#1432](https://github.com/FuelLabs/fuel-core/pull/1432): Add a new `--api-request-timeout` argument to control TTL for GraphQL requests.
16+
- [#1426](https://github.com/FuelLabs/fuel-core/pull/1426) Split keygen into a create and a binary
1617
- [#1419](https://github.com/FuelLabs/fuel-core/pull/1419): Add additional "sanity" benchmarks for arithmetic op code instructions.
1718
- [#1411](https://github.com/FuelLabs/fuel-core/pull/1411): Added WASM and `no_std` compatibility.
1819
- [#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.

Cargo.lock

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010
"crates/client",
1111
"crates/database",
1212
"crates/fuel-core",
13+
"crates/keygen",
1314
"crates/metrics",
1415
"crates/services",
1516
"crates/services/consensus_module",
@@ -52,7 +53,8 @@ version = "0.20.4"
5253
fuel-core = { version = "0.20.4", path = "./crates/fuel-core", default-features = false }
5354
fuel-core-client-bin = { version = "0.20.4", path = "./bin/client" }
5455
fuel-core-bin = { version = "0.20.4", path = "./bin/fuel-core" }
55-
fuel-core-keygen = { version = "0.20.4", path = "./bin/keygen" }
56+
fuel-core-keygen = { version = "0.20.4", path = "./crates/keygen" }
57+
fuel-core-keygen-bin = { version = "0.20.4", path = "./bin/keygen" }
5658
fuel-core-chain-config = { version = "0.20.4", path = "./crates/chain-config" }
5759
fuel-core-client = { version = "0.20.4", path = "./crates/client" }
5860
fuel-core-database = { version = "0.20.4", path = "./crates/database" }

bin/keygen/Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
2-
name = "fuel-core-keygen"
2+
name = "fuel-core-keygen-bin"
33
version = { workspace = true }
44
edition = { workspace = true }
55
homepage = { workspace = true }
@@ -12,6 +12,4 @@ description = "Command line utilities for fuel-core key management"
1212
[dependencies]
1313
anyhow = { workspace = true }
1414
clap = { workspace = true, features = ["derive", "env"] }
15-
fuel-core-types = { workspace = true, features = ["serde", "random"] }
16-
libp2p-identity = { version = "0.2.4", features = ["secp256k1", "peerid"] }
17-
serde_json = { workspace = true, features = ["raw_value"] }
15+
fuel-core-keygen = { workspace = true }

crates/keygen/Cargo.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[package]
2+
name = "fuel-core-keygen"
3+
authors = { workspace = true }
4+
categories = { workspace = true }
5+
version = { workspace = true }
6+
edition = { workspace = true }
7+
homepage = { workspace = true }
8+
keywords = { workspace = true }
9+
license = { workspace = true }
10+
repository = { workspace = true }
11+
description = "Create to create command line utilities for fuel-core key management"
12+
13+
[dependencies]
14+
anyhow = { workspace = true }
15+
atty = "0.2.14"
16+
clap = { workspace = true, features = ["derive", "env"] }
17+
fuel-core-types = { workspace = true, features = ["serde", "random"] }
18+
libp2p-identity = { version = "0.2.4", features = ["secp256k1", "peerid"] }
19+
serde_json = { workspace = true, features = ["raw_value"] }
20+
termion = "2.0.1"
Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::{
22
BLOCK_PRODUCTION,
33
P2P,
44
};
5+
use atty::Stream;
56
use clap::ValueEnum;
67
use fuel_core_types::{
78
fuel_crypto::{
@@ -20,9 +21,16 @@ use libp2p_identity::{
2021
};
2122
use serde_json::json;
2223
use std::{
24+
io::{
25+
stdin,
26+
stdout,
27+
Read,
28+
Write,
29+
},
2330
ops::Deref,
2431
str::FromStr,
2532
};
33+
use termion::screen::IntoAlternateScreen;
2634

2735
/// Generate a random new secret & public key in the format expected by fuel-core
2836
#[derive(Debug, clap::Args)]
@@ -126,13 +134,38 @@ impl ParseSecret {
126134
}
127135
}
128136

137+
fn wait_for_keypress() {
138+
let mut single_key = [0u8];
139+
stdin().read_exact(&mut single_key).unwrap();
140+
}
141+
142+
fn display_string_discreetly(
143+
discreet_string: &str,
144+
continue_message: &str,
145+
) -> anyhow::Result<()> {
146+
if atty::is(Stream::Stdout) {
147+
let mut screen = stdout().into_alternate_screen()?;
148+
writeln!(screen, "{discreet_string}")?;
149+
screen.flush()?;
150+
println!("{continue_message}");
151+
wait_for_keypress();
152+
} else {
153+
println!("{discreet_string}");
154+
}
155+
Ok(())
156+
}
157+
129158
fn print_value(output: serde_json::Value, pretty: bool) -> anyhow::Result<()> {
130159
let output = if pretty {
131160
serde_json::to_string_pretty(&output)
132161
} else {
133162
serde_json::to_string(&output)
134163
}
135164
.map_err(anyhow::Error::msg);
136-
println!("{}", output?);
165+
166+
let _ = display_string_discreetly(
167+
&output?,
168+
"### Do not share or lose this private key! Press any key to complete. ###",
169+
);
137170
Ok(())
138171
}

docs/developers/debugging.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ Using environment variables for CLI arguments allows these values to be reused a
5050

5151
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.
5252

53-
A key pair can be generated by running the utility binary `fuel-core-keygen`:
53+
A key pair can be generated by running the utility binary `fuel-core-keygen-bin`:
5454

5555
```bash
56-
cargo run --bin fuel-core-keygen new
56+
cargo run --bin fuel-core-keygen-bin new
5757
```
5858

5959
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.

0 commit comments

Comments
 (0)