Skip to content

Commit 9e573ce

Browse files
authored
Merge pull request #647 from openmina/feat/configure-keypair
Implement compatible with OCaml Mina way to configure keypair
2 parents 9527c86 + 8bd1b6c commit 9e573ce

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

Cargo.lock

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

cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ reqwest = { version = "0.11.24", features = ["blocking", "json"] }
3131
openmina-core = { path = "../core" }
3232
node = { path = "../node", features = ["replay"] }
3333
openmina-node-native = { path = "../node/native" }
34+
openmina-node-account = { path = "../node/account" }
3435
bytes = "1.4.0"
3536
tracing = "0.1.37"
3637
nix = { version = "0.26.2", features = ["signal"] }

cli/src/commands/node/mod.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ pub struct Node {
2323
#[arg(long, short = 's', env = "OPENMINA_P2P_SEC_KEY")]
2424
pub p2p_secret_key: Option<SecretKey>,
2525

26+
// warning, this overrides `OPENMINA_P2P_SEC_KEY`
27+
/// Compatibility with OCaml Mina node
28+
#[arg(long)]
29+
pub libp2p_keypair: Option<String>,
30+
2631
/// Http port to listen on
2732
#[arg(long, short, env, default_value = "3000")]
2833
pub port: u16,
@@ -124,6 +129,32 @@ impl Node {
124129
if let Some(sec_key) = self.p2p_secret_key {
125130
node_builder.p2p_sec_key(sec_key);
126131
}
132+
133+
// warning, this overrides `OPENMINA_P2P_SEC_KEY`
134+
if let Some(key_file) = self.libp2p_keypair {
135+
use openmina_node_account::AccountSecretKey;
136+
137+
match AccountSecretKey::from_encrypted_file(&key_file) {
138+
Ok(sk) => {
139+
node_builder.p2p_sec_key(SecretKey::from_bytes(sk.to_bytes()));
140+
node::core::info!(
141+
node::core::log::system_time();
142+
summary = "read sercret key from file",
143+
file_name = key_file,
144+
pk = sk.public_key().to_string(),
145+
)
146+
}
147+
Err(err) => {
148+
node::core::error!(
149+
node::core::log::system_time();
150+
summary = "failed to read secret key",
151+
file_name = key_file,
152+
err = err.to_string(),
153+
);
154+
}
155+
}
156+
}
157+
127158
node_builder.p2p_libp2p_port(self.libp2p_port);
128159

129160
self.seed.then(|| node_builder.p2p_seed_node());

0 commit comments

Comments
 (0)