From a83afef8c7876d35baa88e5366684457939b4bff Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Fri, 4 Sep 2020 19:48:33 +0200 Subject: [PATCH 1/4] accounts/usbwallet, signer/core: un-hide accounts from ledger legacy derivation paths --- accounts/usbwallet/wallet.go | 14 +++++++++----- signer/core/api.go | 33 +++++++++++++++++++++------------ 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/accounts/usbwallet/wallet.go b/accounts/usbwallet/wallet.go index ee539d96535d..24a87f44717f 100644 --- a/accounts/usbwallet/wallet.go +++ b/accounts/usbwallet/wallet.go @@ -368,18 +368,22 @@ func (w *wallet) selfDerive() { w.log.Warn("USB wallet nonce retrieval failed", "err", err) break } - // If the next account is empty, stop self-derivation, but add for the last base path + // We've just self-derived a new account, start tracking it locally + // unless the account was empty. + path := make(accounts.DerivationPath, len(nextPaths[i])) + copy(path[:], nextPaths[i][:]) if balance.Sign() == 0 && nonce == 0 { empty = true + // If it indeed was empty, make a log output for it anyway. In the case + // of legacy-ledger, the first account on the legacy-path will + // be shown to the user, even if we don't actively track it if i < len(nextAddrs)-1 { + w.log.Info("Skipping acc, use personal.deriveAccount(,, false) to track", + "path", path, "address", nextAddrs[i]) break } } - // We've just self-derived a new account, start tracking it locally - path := make(accounts.DerivationPath, len(nextPaths[i])) - copy(path[:], nextPaths[i][:]) paths = append(paths, path) - account := accounts.Account{ Address: nextAddrs[i], URL: accounts.URL{Scheme: w.url.Scheme, Path: fmt.Sprintf("%s/%s", w.url.Path, path)}, diff --git a/signer/core/api.go b/signer/core/api.go index 7e6ece997f29..7817a08cb41f 100644 --- a/signer/core/api.go +++ b/signer/core/api.go @@ -346,19 +346,28 @@ func (api *SignerAPI) startUSBListener() { case accounts.WalletOpened: status, _ := event.Wallet.Status() log.Info("New wallet appeared", "url", event.Wallet.URL(), "status", status) - - // Derive first N accounts, hardcoded for now - var nextPath = make(accounts.DerivationPath, len(accounts.DefaultBaseDerivationPath)) - copy(nextPath[:], accounts.DefaultBaseDerivationPath[:]) - - for i := 0; i < numberOfAccountsToDerive; i++ { - acc, err := event.Wallet.Derive(nextPath, true) - if err != nil { - log.Warn("account derivation failed", "error", err) - } else { - log.Info("derived account", "address", acc.Address) + var derive = func(numToDerive int, base accounts.DerivationPath) { + // Derive first N accounts, hardcoded for now + var nextPath = make(accounts.DerivationPath, len(base)) + copy(nextPath[:], base[:]) + + for i := 0; i < numToDerive; i++ { + acc, err := event.Wallet.Derive(nextPath, true) + if err != nil { + log.Warn("account derivation failed", "error", err) + } else { + log.Info("derived account", "address", acc.Address, "path", nextPath) + } + nextPath[len(nextPath)-1]++ } - nextPath[len(nextPath)-1]++ + } + if event.Wallet.URL().Scheme == "ledger" { + log.Info("Deriving ledger default paths") + derive(numberOfAccountsToDerive/2, accounts.DefaultBaseDerivationPath) + log.Info("Deriving ledger legacy paths") + derive(numberOfAccountsToDerive/2, accounts.LegacyLedgerBaseDerivationPath) + } else { + derive(numberOfAccountsToDerive, accounts.DefaultBaseDerivationPath) } case accounts.WalletDropped: log.Info("Old wallet dropped", "url", event.Wallet.URL()) From 10b35fd78b7725f02e7cc2bc5d74a8412d00cdfa Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Tue, 8 Sep 2020 11:18:59 +0200 Subject: [PATCH 2/4] Update accounts/usbwallet/wallet.go --- accounts/usbwallet/wallet.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/accounts/usbwallet/wallet.go b/accounts/usbwallet/wallet.go index 24a87f44717f..993c599346a0 100644 --- a/accounts/usbwallet/wallet.go +++ b/accounts/usbwallet/wallet.go @@ -378,7 +378,7 @@ func (w *wallet) selfDerive() { // of legacy-ledger, the first account on the legacy-path will // be shown to the user, even if we don't actively track it if i < len(nextAddrs)-1 { - w.log.Info("Skipping acc, use personal.deriveAccount(,, false) to track", + w.log.Info("Skipping trakcking first account on legacy path, use personal.deriveAccount(,, false) to track", "path", path, "address", nextAddrs[i]) break } From 3bfe1a8aee7b22532a6ceff33b42b5b5670fc811 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Tue, 8 Sep 2020 11:19:48 +0200 Subject: [PATCH 3/4] Update signer/core/api.go --- signer/core/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/signer/core/api.go b/signer/core/api.go index 7817a08cb41f..d64dfe5234cf 100644 --- a/signer/core/api.go +++ b/signer/core/api.go @@ -354,7 +354,7 @@ func (api *SignerAPI) startUSBListener() { for i := 0; i < numToDerive; i++ { acc, err := event.Wallet.Derive(nextPath, true) if err != nil { - log.Warn("account derivation failed", "error", err) + log.Warn("Account derivation failed", "error", err) } else { log.Info("derived account", "address", acc.Address, "path", nextPath) } From a713d66a51806d724e17cc504471bfc0333ce3fe Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Tue, 8 Sep 2020 11:19:55 +0200 Subject: [PATCH 4/4] Update signer/core/api.go --- signer/core/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/signer/core/api.go b/signer/core/api.go index d64dfe5234cf..3817345c8f1a 100644 --- a/signer/core/api.go +++ b/signer/core/api.go @@ -356,7 +356,7 @@ func (api *SignerAPI) startUSBListener() { if err != nil { log.Warn("Account derivation failed", "error", err) } else { - log.Info("derived account", "address", acc.Address, "path", nextPath) + log.Info("Derived account", "address", acc.Address, "path", nextPath) } nextPath[len(nextPath)-1]++ }