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

CLI command to dump libp2p keys #14169

Merged
merged 2 commits into from
Sep 21, 2023
Merged
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
32 changes: 31 additions & 1 deletion src/app/cli/src/init/client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1625,6 +1625,34 @@ let generate_libp2p_keypair =
let%map_open privkey_path = Cli_lib.Flag.privkey_write_path in
generate_libp2p_keypair_do privkey_path)

let dump_libp2p_keypair_do privkey_path =
Cli_lib.Exceptions.handle_nicely
@@ fun () ->
Deferred.ignore_m
(let open Deferred.Let_syntax in
let logger = Logger.null () in
(* Using the helper only for keypair generation requires no state. *)
File_system.with_temp_dir "mina-dump-libp2p-keypair" ~f:(fun tmpd ->
match%bind
Mina_net2.create ~logger ~conf_dir:tmpd ~all_peers_seen_metric:false
~pids:(Child_processes.Termination.create_pid_table ())
~on_peer_connected:ignore ~on_peer_disconnected:ignore ()
with
| Ok net ->
let%bind () = Mina_net2.shutdown net in
let%map me = Secrets.Libp2p_keypair.read_exn' privkey_path in
printf "libp2p keypair:\n%s\n" (Mina_net2.Keypair.to_string me)
| Error e ->
[%log fatal] "failed to dump libp2p keypair: $error"
~metadata:[ ("error", Error_json.error_to_yojson e) ] ;
exit 20 ))

let dump_libp2p_keypair =
Command.async ~summary:"Print an existing libp2p keypair"
(let open Command.Let_syntax in
let%map_open privkey_path = Cli_lib.Flag.privkey_read_path in
dump_libp2p_keypair_do privkey_path)

let trustlist_ip_flag =
Command.Param.(
flag "--ip-address" ~aliases:[ "ip-address" ]
Expand Down Expand Up @@ -2367,4 +2395,6 @@ let ledger =

let libp2p =
Command.group ~summary:"Libp2p commands"
[ ("generate-keypair", generate_libp2p_keypair) ]
[ ("generate-keypair", generate_libp2p_keypair)
; ("dump-keypair", dump_libp2p_keypair)
]