-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
walletunlocker: Allow wallet to be created from extended master root key (xprv) #4717
Conversation
b8f0a3f
to
db42b6f
Compare
Rebased this as there seems to be some interest in the wallet community to get this in. Two questions occurred to me during the rebase:
|
How would non-aezeed wallets determine what that value should be? We're able to have such a birthday param only because we actually encode that data in the seed.
Seems to be the case for "double importing" into a wallet independent of this use case right? From my PoV, I think I'm missing ab it of a motivating use case for this PR:
|
The birthday param would be optional and fall back to the hard coded value that is in the PR now. Users that know exactly when the seed was created (perhaps because they wrote it down) can set it and speed up the process. Users that don't know the date leave it blank.
I added the two main use cases to the main PR description. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did a very high level pass, nicely broken up PR! Will give this a more thorough look once it's been rebased.
lnd.go
Outdated
// When importing a wallet from its extended private key | ||
// we don't know the birthday as that information is not |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Decided against an optional birthday param for extended key (as discussed in the PR body)? I think it could be useful, eg in the case of an existing on-chain wallet, they probably know the date when the wallet was created so could have a birthday hint?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, you're right, it might be useful to have the birthday field. Added it.
da0f2fe
to
a6ed0a4
Compare
Rebased this PR and its dependency. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Definitely worthy of an addition given its use cases.
The |
2d4ff89
to
96b1b34
Compare
Rebased after dependent PR was merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏅
// No seed was given, we're importing a wallet from its | ||
// extended private key. | ||
birthday = initMsg.ExtendedKeyBirthday | ||
newWallet, err = loader.CreateNewWalletExtendedKey( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Assuming that this will fail if len(extendedKey)==0
, but could be a bit clearer to switch on cipherSeed != nil
/len(extendedKey)!=0
/default
so that the case where we're init-ing the wallet with no seed/key is a bit more obvious?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it could be a bit more obvious. Added a switch
block instead.
In addition to creating a new wallet from an aezeed, we allow specifying an exteded master root key as the main wallet key directly. Because an exteded key (xprv) doesn't contain any information about the creation time of the wallet, we must assume a birthday to start scanning the chain from (if the user doesn't provide an explicit value). Since lnd only uses SegWit addresses, it makes sense to choose the date that corresponds to the first mainnet block that contained SegWit transactions. Restoring a wallet from an extended master root key will result in a significantly longer initial wallet rescan time if the default value is used.
To allow users to restore a wallet from an existing extended master root key, we accept one of three answers when asking for an existing seed.
To allow testing restoring a node from an extended master root key, we add an extra argument to the RestoreNodeWithSeed function.
We add an additional test case to the on-chain fund recovery test that tries restoring the same wallet from the extended master root key instead of the seed.
96b1b34
to
8632fc9
Compare
Depends on btcsuite/btcwallet#720.
In addition to creating a new wallet from an aezeed, we allow specifying
an exteded master root key as the main wallet key directly.
Motivation:
This PR is useful to some users for two reasons:
wallet.db
to which the seed was lost or never known (because of incorrect use of the--noseedbackup
). This feature gives those nodes the ability to recover from data loss in combination with thechantools walletinfo
command that extracts thexprv
from awallet.db
(assuming the wallet password is still known).lnd
for the off-chain stuff. They possibly don't want to give the user another seed to back up. With BIP85 they could derive a new master root key from their existing seed and give it tolnd
. It's still important to make sure thexprv
given tolnd
is used bylnd
exclusively!Wallet birthday:
Because an exteded key (
xprv...
) doesn't contain any information about thecreation time of the wallet, we must assume a birthday to start scanning
the chain from. Since lnd only uses SegWit addresses, it makes sense to
choose the date that corresponds to the first mainnet block that
contained SegWit transactions.
Restoring a wallet from an extended master root key will result in a
significantly longer initial wallet rescan time.