-
Notifications
You must be signed in to change notification settings - Fork 913
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
hsm_secret
generation from a seed-phrase
#3717
Comments
@mrostecki and I have been discussing the best way to implement this feature. By now our solution involves a plugin which should be executed before If there were no instances of c-lightning already running in the wild we would just need to generate 24 random words during the What do you think about it? |
We could to use BIP39 functions from libwally-core: https://wally.readthedocs.io/en/release_0.7.4/bip39/ libwally-core is already used in https://github.com/ElementsProject/lightning/blob/master/hsmd/hsmd.c#L53 Example project using BIP39 functionality from libwally: https://github.com/greenaddress/garecovery/blob/master/garecovery/mnemonic.py |
After reading more carefully the BIP39:
Which basically means that, to get the seed, we have to HMAC-SHA512 the derived data from the word list (seed-phrase). That makes it impossible for us to write an inverse function for the people who are already running c-lightning and used "random data" as the bip32 seed. |
Looking at this test can be helpful: https://github.com/ElementsProject/libwally-core/blob/master/src/ctest/test_clear.c |
Maybe we can generate the master with mnemonic like that? u8 bip39_seed[BIP39_SEED_LEN_512];
u8 entropy[BIP39_ENTROPY_LEN_256];
size_t bip39_seed_len;
struct words *words;
char *mnemonic;
randombytes_buf(entropy, sizeof(entropy));
bip39_get_wordlist("en", &words);
bip39_mnemonic_from_bytes(words, entropy, sizeof(entropy), &mnemonic);
status_debug("mnemonic: %s", mnemonic);
if (bip39_mnemonic_to_seed(mnemonic, passphrase, bip39_seed, sizeof(bip39_seed),
&bip39_seed_len) != WALLY_OK)
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Can't convert mnemonic to seed");
if (bip32_key_from_seed(bip39_seed, bip39_seed_len,
bip32_key_version.bip32_privkey_version,
0, &master_extkey) != WALLY_OK)
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Can't create bip32 master key"); What do you think? Now I will try to think about restoring from mnemonic. |
Hi, I may be a bit late but I think it's a good fit for |
Hi, @darosior we just had a call (@cdecker, @mrostecki and me). Let me summarize what we talked about so you have a bit more of context about the solution that we propose. To be on the same page, lets sketch the process for getting the master node for the HD wallet tree using BIP39 and BIP32. Generate X random words ------------> derive Y random bytes ------------> derive the master node for HD Wallets Right now c-lightning uses 32 (Y == 32) bytes to derive the master node. The bytes are stored in a file called Because that file contains 32 bytes generated at random it is safe to change directly the code in After that, we will add the The last step will be to "print" the mnemonic during the startup time when no seed is provided by the user and there is no Given that many other lightning implementations use c-lightning under the hood (easy to create bindings) it could be interesting to write this logic as a little program that reads from std input and writes the |
The following matrix shows cases we should handle in the new seed/masterkey generation logic. Thanks @positiveblue for it! To be precise, by seed we mean mnemonic (as an optional input from user). random is the current behavior of c-lightning - using BIP32 seed. no seed is the case when c-lightning will switch to BIP39 seeds and user will not provde mnemonic (so it will be generated and printed). |
This change uses mnemonic (list of 24 words) and an optional passphrase to generate the seed and the private master key, according to BIP39[0]. If mnemonic is not provided by user, it gets generated from the random list of bytes (entropy). [0] https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md Fixes: ElementsProject#3717 Co-authored-by: positiveblue <jomsdev@gmail.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change uses mnemonic (list of 24 words) and an optional passphrase to generate the seed and the private master key, according to BIP39[0]. If mnemonic is not provided by user, it gets generated from the random array of bytes (entropy). [0] https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md Fixes: ElementsProject#3717 Co-authored-by: positiveblue <jomsdev@gmail.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change uses mnemonic (list of 24 words) and an optional passphrase to generate the seed and the private master key, according to BIP39[0]. If mnemonic is not provided by user, it gets generated from the random array of bytes (entropy). [0] https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md Fixes: ElementsProject#3717 Co-authored-by: positiveblue <jomsdev@gmail.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change uses mnemonic (list of 24 words) and an optional passphrase to generate the seed and the private master key, according to BIP39[0]. If mnemonic is not provided by user, it gets generated from the random array of bytes (entropy). [0] https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md Fixes: ElementsProject#3717 Co-authored-by: positiveblue <jomsdev@gmail.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change adds the `--mnemonic-hsm-seed` flag to lightningd. If the flag is passed the node will derive the hsmd HD Wallet from a mnemonic (24 english words) and passphrase using BIP39 at start up time. Fixes: ElementsProject#3717 Co-authored-by: positiveblue <jomsdev@gmail.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change adds the `--mnemonic-hsm-seed` flag to lightningd. If the flag is passed the node will derive the hsmd HD Wallet from a mnemonic (24 english words) and passphrase using BIP39 at start up time. Fixes: ElementsProject#3717 Co-authored-by: positiveblue <jomsdev@gmail.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change adds the `--mnemonic-hsm-seed` flag to lightningd. If the flag is passed the node will derive the hsmd HD Wallet from a mnemonic (24 english words) and passphrase using BIP39 at start up time. Fixes: ElementsProject#3717 Co-authored-by: positiveblue <jomsdev@gmail.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change adds the `--mnemonic-hsm-seed` flag to lightningd. If the flag is passed the node will derive the hsmd HD Wallet from a mnemonic (24 english words) and passphrase using BIP39 at start up time. Fixes: ElementsProject#3717 Co-authored-by: positiveblue <jomsdev@gmail.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change adds the `--mnemonic-hsm-seed` flag to lightningd. If the flag is passed the node will derive the hsmd HD Wallet from a mnemonic (24 english words) and passphrase using BIP39 at start up time. Fixes: ElementsProject#3717 Co-authored-by: Michal Rostecki <mrostecki@mailfence.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change adds `mnemonic` and `passphrase` arguments of type *u8 to `hsm_init`, which will allow to pass BIP39 values from lightningd to HSMD. Fixes: ElementsProject#3717 Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
Previous changes added options in lightningd and arguments in `hsm_init` to spefify BIP39 mnemonic and passphrase. This change passes those values from lightningd config to `hsm_init`. Fixes: ElementsProject#3717 Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change uses mnemonic (list of 24 words) and an optional passphrase to generate the seed and the private master key, according to BIP39[0]. If mnemonic is not provided by user, it gets generated from the random array of bytes (entropy). [0] https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md Fixes: ElementsProject#3717 Co-authored-by: positiveblue <jomsdev@gmail.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change adds the `--mnemonic-hsm-seed` flag to lightningd. If the flag is passed the node will derive the hsmd HD Wallet from a mnemonic (24 english words) and passphrase using BIP39 at start up time. Fixes: ElementsProject#3717 Co-authored-by: Michal Rostecki <mrostecki@mailfence.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change adds `mnemonic` and `passphrase` arguments of type *u8 to `hsm_init`, which will allow to pass BIP39 values from lightningd to HSMD. Fixes: ElementsProject#3717 Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
Previous changes added options in lightningd and arguments in `hsm_init` to spefify BIP39 mnemonic and passphrase. This change passes those values from lightningd config to `hsm_init`. Fixes: ElementsProject#3717 Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change uses mnemonic (list of 24 words) and an optional passphrase to generate the seed and the private master key, according to BIP39[0]. If mnemonic is not provided by user, it gets generated from the random array of bytes (entropy). [0] https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md Fixes: ElementsProject#3717 Co-authored-by: positiveblue <jomsdev@gmail.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change adds the `--mnemonic-hsm-seed` flag to lightningd. If the flag is passed the node will derive the hsmd HD Wallet from a mnemonic (24 english words) and passphrase using BIP39 at start up time. Fixes: ElementsProject#3717 Co-authored-by: Michal Rostecki <mrostecki@mailfence.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change adds `mnemonic` and `passphrase` arguments of type *u8 to `hsm_init`, which will allow to pass BIP39 values from lightningd to HSMD. Fixes: ElementsProject#3717 Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
Previous changes added options in lightningd and arguments in `hsm_init` to spefify BIP39 mnemonic and passphrase. This change passes those values from lightningd config to `hsm_init`. Fixes: ElementsProject#3717 Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change uses mnemonic (list of 24 words) and an optional passphrase to generate the seed and the private master key, according to BIP39[0]. If mnemonic is not provided by user, it gets generated from the random array of bytes (entropy). [0] https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md Fixes: ElementsProject#3717 Co-authored-by: positiveblue <jomsdev@gmail.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change adds the `--mnemonic-hsm-seed` flag to lightningd. If the flag is passed the node will derive the hsmd HD Wallet from a mnemonic (24 english words) and passphrase using BIP39 at start up time. Fixes: ElementsProject#3717 Co-authored-by: Michal Rostecki <mrostecki@mailfence.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change adds `mnemonic` and `passphrase` arguments of type *u8 to `hsm_init`, which will allow to pass BIP39 values from lightningd to HSMD. Fixes: ElementsProject#3717 Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
Previous changes added options in lightningd and arguments in `hsm_init` to spefify BIP39 mnemonic and passphrase. This change passes those values from lightningd config to `hsm_init`. Fixes: ElementsProject#3717 Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change uses mnemonic (list of 24 words) and an optional passphrase to generate the seed and the private master key, according to BIP39[0]. If mnemonic is not provided by user, it gets generated from the random array of bytes (entropy). [0] https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md Fixes: ElementsProject#3717 Co-authored-by: positiveblue <jomsdev@gmail.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change adds the `--mnemonic-hsm-seed` flag to lightningd. If the flag is passed the node will derive the hsmd HD Wallet from a mnemonic (24 english words) and passphrase using BIP39 at start up time. Fixes: ElementsProject#3717 Co-authored-by: Michal Rostecki <mrostecki@mailfence.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change adds `mnemonic` and `passphrase` arguments of type *u8 to `hsm_init`, which will allow to pass BIP39 values from lightningd to HSMD. Fixes: ElementsProject#3717 Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
Previous changes added options in lightningd and arguments in `hsm_init` to spefify BIP39 mnemonic and passphrase. This change passes those values from lightningd config to `hsm_init`. Fixes: ElementsProject#3717 Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change uses mnemonic (list of 24 words) and an optional passphrase to generate the seed and the private master key, according to BIP39[0]. If mnemonic is not provided by user, it gets generated from the random array of bytes (entropy). [0] https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md Fixes: ElementsProject#3717 Co-authored-by: positiveblue <jomsdev@gmail.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change adds the `--mnemonic-hsm-seed` flag to lightningd. If the flag is passed the node will derive the hsmd HD Wallet from a mnemonic (24 english words) and passphrase using BIP39 at start up time. Fixes: ElementsProject#3717 Co-authored-by: Michal Rostecki <mrostecki@mailfence.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change adds `mnemonic` and `passphrase` arguments of type *u8 to `hsm_init`, which will allow to pass BIP39 values from lightningd to HSMD. Fixes: ElementsProject#3717 Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
Previous changes added options in lightningd and arguments in `hsm_init` to spefify BIP39 mnemonic and passphrase. This change passes those values from lightningd config to `hsm_init`. Fixes: ElementsProject#3717 Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change uses mnemonic (list of 24 words) and an optional passphrase to generate the seed and the private master key, according to BIP39[0]. If mnemonic is not provided by user, it gets generated from the random array of bytes (entropy). [0] https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md Fixes: ElementsProject#3717 Co-authored-by: positiveblue <jomsdev@gmail.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change adds the `--mnemonic-hsm-seed` flag to lightningd. If the flag is passed the node will derive the hsmd HD Wallet from a mnemonic (24 english words) and passphrase using BIP39 at start up time. Fixes: ElementsProject#3717 Co-authored-by: Michal Rostecki <mrostecki@mailfence.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change adds `mnemonic` and `passphrase` arguments of type *u8 to `hsm_init`, which will allow to pass BIP39 values from lightningd to HSMD. Fixes: ElementsProject#3717 Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
Previous changes added options in lightningd and arguments in `hsm_init` to spefify BIP39 mnemonic and passphrase. This change passes those values from lightningd config to `hsm_init`. Fixes: ElementsProject#3717 Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
This change uses mnemonic (list of 24 words) and an optional passphrase to generate the seed and the private master key, according to BIP39[0]. If mnemonic is not provided by user, it gets generated from the random array of bytes (entropy). [0] https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md Fixes: ElementsProject#3717 Co-authored-by: positiveblue <jomsdev@gmail.com> Signed-off-by: positiveblue <jomsdev@gmail.com> Signed-off-by: Michal Rostecki <mrostecki@mailfence.com>
Since |
If we are going this way, I'm happy to put up a PR for lightning_hsmtool .
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
Le mardi, juin 16, 2020 5:40 PM, ZmnSCPxj, ZmnSCPxj jxPCSmnZ <notifications@github.com> a écrit :
… Since hsm_secret is generated once, I agree with ***@***.***(https://github.com/darosior) that this feels more appropriate to add to hsmtool as a new method. We should probably install hsmtool in make install though, at least as lightning_hsmtool.
—
You are receiving this because you were mentioned.
Reply to this email directly, [view it on GitHub](#3717 (comment)), or [unsubscribe](https://github.com/notifications/unsubscribe-auth/AFLK3F3SXT5CVWWQONA7KSLRW6G6BANCNFSM4M4PVAHQ).
|
I think more of the |
Changelog-Added: We now install `lightning-hsmtool` for your `hsm_secret` needs. See: ElementsProject#3717 (comment) It seems reasonable to add this to the standard install, and to document it properly as well, hopefully we can fill in the documentation better later on.
Changelog-Added: We now install `lightning-hsmtool` for your `hsm_secret` needs. See: ElementsProject#3717 (comment) It seems reasonable to add this to the standard install, and to document it properly as well, hopefully we can fill in the documentation better later on.
Changelog-Added: We now install `lightning-hsmtool` for your `hsm_secret` needs. See: #3717 (comment) It seems reasonable to add this to the standard install, and to document it properly as well, hopefully we can fill in the documentation better later on.
Hello,
I saw that c-lightning was participating Lightning HackSprint May 2020 and I was interested in helping with one of the "challenges".
The goal of my contribution would be
the creation of a launcher or plugin that takes a seed-phrase and generates the associated hsm_secret file.
I am pretty new on the topic so I would like to summarize what I understood after doing a bit of research + reading part of the c-lightning code and try to move forward from there.
When a new lightning node starts up, it launches a daemon (hsmd.c) which creates/loads an
hms_secret file
. That file contains the 256 bits (32 bytes) used for creating the master private key of a HD Wallet as it is specified in the BIP32. During the creation of the key the bytes are randomly generated using libsodium's cryptographic randomness routine. By now there is no way to derivative those random bytes from a seed in order to backup the wallet.The idea is to implement some process that allow the node to derive those 32 bytes using a seed-phrase like input.
There are some widely approaches to this like using a 24 word list as specified in the BIP39. However, other lightning implementations like lnd use a similar approach (24 word list) but with another procedure called the aezeed cipher seed scheme.
The one based on aez comes with some sweet features like wallet timestamp and versioning in the seed but I am not sure if those are needed in this case, they are a nice have, or they are not needed at all.
My idea is to discuss which scheme is better for this use case and implement it as an external plugin (I did not investigate yet how plugins are loaded in the program).
Not sure if someone else is already taking care of this, there is no issue for it. I will add @cdecker who seems to be the coordinator for this.
The text was updated successfully, but these errors were encountered: