mirror of
https://github.com/LBRYFoundation/lbcwallet.git
synced 2025-08-23 17:47:29 +00:00
waddrmgr: fix botched merge
This commit is contained in:
parent
7770cac383
commit
ccb49eaf2a
1 changed files with 57 additions and 54 deletions
|
@ -1060,63 +1060,66 @@ func (m *Manager) Unlock(ns walletdb.ReadBucket, passphrase []byte) error {
|
||||||
|
|
||||||
// Use the crypto private key to decrypt all of the account private
|
// Use the crypto private key to decrypt all of the account private
|
||||||
// extended keys.
|
// extended keys.
|
||||||
for account, acctInfo := range m.acctInfo {
|
for _, manager := range m.scopedManagers {
|
||||||
decrypted, err := m.cryptoKeyPriv.Decrypt(acctInfo.acctKeyEncrypted)
|
for account, acctInfo := range manager.acctInfo {
|
||||||
if err != nil {
|
decrypted, err := m.cryptoKeyPriv.Decrypt(acctInfo.acctKeyEncrypted)
|
||||||
m.lock()
|
if err != nil {
|
||||||
str := fmt.Sprintf("failed to decrypt account %d "+
|
m.lock()
|
||||||
"private key", account)
|
str := fmt.Sprintf("failed to decrypt account %d "+
|
||||||
return managerError(ErrCrypto, str, err)
|
"private key", account)
|
||||||
|
return managerError(ErrCrypto, str, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
acctKeyPriv, err := hdkeychain.NewKeyFromString(string(decrypted))
|
||||||
|
zero.Bytes(decrypted)
|
||||||
|
if err != nil {
|
||||||
|
m.lock()
|
||||||
|
str := fmt.Sprintf("failed to regenerate account %d "+
|
||||||
|
"extended key", account)
|
||||||
|
return managerError(ErrKeyChain, str, err)
|
||||||
|
}
|
||||||
|
acctInfo.acctKeyPriv = acctKeyPriv
|
||||||
}
|
}
|
||||||
|
|
||||||
acctKeyPriv, err := hdkeychain.NewKeyFromString(string(decrypted))
|
// We'll also derive any private keys that are pending due to
|
||||||
zero.Bytes(decrypted)
|
// them being created while the address manager was locked.
|
||||||
if err != nil {
|
for _, info := range manager.deriveOnUnlock {
|
||||||
m.lock()
|
addressKey, err := manager.deriveKeyFromPath(
|
||||||
str := fmt.Sprintf("failed to regenerate account %d "+
|
ns, info.managedAddr.Account(), info.branch,
|
||||||
"extended key", account)
|
info.index, true,
|
||||||
return managerError(ErrKeyChain, str, err)
|
)
|
||||||
|
if err != nil {
|
||||||
|
m.lock()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// It's ok to ignore the error here since it can only
|
||||||
|
// fail if the extended key is not private, however it
|
||||||
|
// was just derived as a private key.
|
||||||
|
privKey, _ := addressKey.ECPrivKey()
|
||||||
|
addressKey.Zero()
|
||||||
|
|
||||||
|
privKeyBytes := privKey.Serialize()
|
||||||
|
privKeyEncrypted, err := m.cryptoKeyPriv.Encrypt(privKeyBytes)
|
||||||
|
zero.BigInt(privKey.D)
|
||||||
|
if err != nil {
|
||||||
|
m.lock()
|
||||||
|
str := fmt.Sprintf("failed to encrypt private key for "+
|
||||||
|
"address %s", info.managedAddr.Address())
|
||||||
|
return managerError(ErrCrypto, str, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
switch a := info.managedAddr.(type) {
|
||||||
|
case *managedAddress:
|
||||||
|
a.privKeyEncrypted = privKeyEncrypted
|
||||||
|
a.privKeyCT = privKeyBytes
|
||||||
|
case *scriptAddress:
|
||||||
|
}
|
||||||
|
|
||||||
|
// Avoid re-deriving this key on subsequent unlocks.
|
||||||
|
manager.deriveOnUnlock[0] = nil
|
||||||
|
manager.deriveOnUnlock = manager.deriveOnUnlock[1:]
|
||||||
}
|
}
|
||||||
acctInfo.acctKeyPriv = acctKeyPriv
|
|
||||||
}
|
|
||||||
|
|
||||||
// Derive any private keys that are pending due to them being created
|
|
||||||
// while the address manager was locked.
|
|
||||||
for _, info := range m.deriveOnUnlock {
|
|
||||||
addressKey, err := m.deriveKeyFromPath(ns, info.managedAddr.account,
|
|
||||||
info.branch, info.index, true)
|
|
||||||
if err != nil {
|
|
||||||
m.lock()
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// It's ok to ignore the error here since it can only fail if
|
|
||||||
// the extended key is not private, however it was just derived
|
|
||||||
// as a private key.
|
|
||||||
privKey, _ := addressKey.ECPrivKey()
|
|
||||||
addressKey.Zero()
|
|
||||||
|
|
||||||
privKeyBytes := privKey.Serialize()
|
|
||||||
privKeyEncrypted, err := m.cryptoKeyPriv.Encrypt(privKeyBytes)
|
|
||||||
zero.BigInt(privKey.D)
|
|
||||||
if err != nil {
|
|
||||||
m.lock()
|
|
||||||
str := fmt.Sprintf("failed to encrypt private key for "+
|
|
||||||
"address %s", info.managedAddr.Address())
|
|
||||||
return managerError(ErrCrypto, str, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(roasbeef): don't need to do anythign further?
|
|
||||||
switch a := info.managedAddr.(type) {
|
|
||||||
case *managedAddress:
|
|
||||||
a.privKeyEncrypted = privKeyEncrypted
|
|
||||||
a.privKeyCT = privKeyBytes
|
|
||||||
case *scriptAddress:
|
|
||||||
}
|
|
||||||
|
|
||||||
// Avoid re-deriving this key on subsequent unlocks.
|
|
||||||
m.deriveOnUnlock[0] = nil
|
|
||||||
m.deriveOnUnlock = m.deriveOnUnlock[1:]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m.locked = false
|
m.locked = false
|
||||||
|
|
Loading…
Add table
Reference in a new issue