diff --git a/src/app/cli/src/init/client.ml b/src/app/cli/src/init/client.ml index b53076a7aa9..ae3141d37b9 100644 --- a/src/app/cli/src/init/client.ml +++ b/src/app/cli/src/init/client.ml @@ -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" ] @@ -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) + ]