lightningnetwork / lnd

Lightning Network Daemon ⚡️
MIT License
7.65k stars 2.07k forks source link

[bug]: lncli create is not honoring its documentation #8897

Closed JaviLib closed 3 weeks ago

JaviLib commented 3 months ago

Background

lncli create is not honoring its documentation which says the following:

 embed/lnd/lncli --lnddir=lnd/ create --help
NAME:
   lncli create - Initialize a wallet when starting lnd for the first time.

USAGE:
   lncli create [command options] [arguments...]

CATEGORY:
   Startup

DESCRIPTION:

  The create command is used to initialize an lnd wallet from scratch for
  the very first time. This is interactive command with one required
  argument (the password), and one optional argument (the mnemonic
  passphrase).

  The first argument (the password) is required and MUST be greater than
  8 characters. This will be used to encrypt the wallet within lnd. This
  MUST be remembered as it will be required to fully start up the daemon.

  The second argument is an optional 24-word mnemonic derived from BIP
  39. If provided, then the internal wallet will use the seed derived
  from this mnemonic to generate all keys.

  This command returns a 24-word seed in the scenario that NO mnemonic
  was provided by the user. This should be written down as it can be used
  to potentially recover all on-chain funds, and most off-chain funds as
  well.

  If the --stateless_init flag is set, no macaroon files are created by
  the daemon. Instead, the binary serialized admin macaroon is returned
  in the answer. This answer MUST be stored somewhere, otherwise all
  access to the RPC server will be lost and the wallet must be recreated
  to re-gain access.
  If the --save_to parameter is set, the macaroon is saved to this file,
  otherwise it is printed to standard out.

  Finally, it's also possible to use this command and a set of static
  channel backups to trigger a recover attempt for the provided Static
  Channel Backups. Only one of the three parameters will be accepted. See
  the restorechanbackup command for further details w.r.t the format
  accepted.

OPTIONS:
   --single_backup value  a hex encoded single channel backup obtained from exportchanbackup
   --multi_backup value   a hex encoded multi-channel backup obtained from exportchanbackup
   --multi_file value     the path to a multi-channel back up file
   --stateless_init       do not create any macaroon files in the file system of the daemon
   --save_to value        save returned admin macaroon to this file

When I do the following command I obtain the following:

embed/lnd/lncli --lnddir=lnd/ create 34423423jjjjjkasdfsa
Input wallet password:
Confirm password:

Do you have an existing cipher seed mnemonic or extended master root key you want to use?
Enter 'y' to use an existing cipher seed mnemonic, 'x' to use an extended master root key
or 'n' to create a new seed (Enter y/x/n): n

Your cipher seed can optionally be encrypted.
Input your passphrase if you wish to encrypt it (or press enter to proceed without a cipher seed passphrase):

Generating fresh cipher seed...

[lncli] unable to generate seed: rpc error: code = Unavailable desc = connection error: desc = "transport: authentication handshake failed: tls: failed to verify certificate: x509: certificate signed by unknown authority (possibly because of \"x509: ECDSA verification failure\" while trying to verify candidate authority certificate \"mac-2.local\")"

Now, if you read carefully, it says that the fist argument is the password, and the second argument is optional. But what I get is an interactive form asking for a password, that I already provided in the first argument, and it is also asking for a seed, which is optional according to the documentation. And not only I am not obtaining the 24 words, but in fact I am returned an error.

This makes programatically configurations imposible. I have to attach a stdin and gess what lncliis going to ask, which is not optimal. I truly want the process to be fully automatic and be gifted with the 24 words, as the documentation promises.

Your environment

guggero commented 3 months ago

Yeah, I see how the documentation is a bit weird here. So the [arguments...] part comes from the CLI library that generates the help text and is there for every command. But there are no command line arguments for the create command, only interactive queries. So the text should say something like:

... This is interactive command with one required
  input prompt (the password), and one optional input (the mnemonic
  passphrase).

If you want to create a wallet programmatically, I suggest looking into lndinit which was created for that exact purpose.

rhg4d9ow35 commented 1 month ago

I would like to work on this issue! Can I take it?