mirror of
https://github.com/Such-Software/hash-wallet.git
synced 2026-11-24 10:54:13 +01:00
CW-1157-Use-correct-derivation-paths-for-other-address-types (#2825)
* feat: use bitcoin standard derivation paths per address type * add support for Electrum derivation type in wallet * fix merge conflict * Use segwit HD for key export and simplify _hdFor * skip derivation chooser for standard scan paths * add legacy and P2SH derivation paths
This commit is contained in:
@@ -182,7 +182,8 @@ class CWBitcoin extends Bitcoin {
|
||||
address: addr.address,
|
||||
txCount: addr.txCount,
|
||||
balance: addr.balance,
|
||||
isChange: addr.isHidden))
|
||||
isChange: addr.isHidden,
|
||||
isLegacyDerivation: addr.isLegacyDerivation))
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
||||
@@ -278,14 +278,31 @@ class WalletRestorePage extends BasePage {
|
||||
|
||||
int derivationsWithHistory = 0;
|
||||
int derivationWithHistoryIndex = 0;
|
||||
final List<String> derivationPathsWithHistory = [];
|
||||
|
||||
for (int i = 0; i < derivations.length; i++) {
|
||||
if (derivations[i].transactionsCount > 0) {
|
||||
derivationsWithHistory++;
|
||||
derivationWithHistoryIndex = i;
|
||||
final derivationPath = derivations[i].derivationPath;
|
||||
if (derivationPath != null && derivationPath.isNotEmpty) {
|
||||
derivationPathsWithHistory.add(derivationPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (derivationsWithHistory > 1) {
|
||||
final scanDerivationPaths = {
|
||||
"m/84'/0'/0'",
|
||||
"m/86'/0'/0'",
|
||||
"m/44'/0'/0'",
|
||||
"m/49'/0'/0'",
|
||||
};
|
||||
|
||||
final shouldSkipChooseDerivationScreen =
|
||||
derivationPathsWithHistory.isNotEmpty &&
|
||||
derivationPathsWithHistory.every(scanDerivationPaths.contains);
|
||||
|
||||
if (derivationsWithHistory > 1 && !shouldSkipChooseDerivationScreen) {
|
||||
dInfo = await Navigator.of(context).pushNamed(
|
||||
Routes.restoreWalletChooseDerivation,
|
||||
arguments: derivations,
|
||||
|
||||
@@ -13,6 +13,7 @@ class WalletAddressListItem extends ListItem {
|
||||
this.isOneTimeReceiveAddress = false,
|
||||
this.isHidden = false,
|
||||
this.isManual = false,
|
||||
this.isLegacyDerivation = false,
|
||||
}) : super();
|
||||
|
||||
final int? id;
|
||||
@@ -24,6 +25,7 @@ class WalletAddressListItem extends ListItem {
|
||||
final bool isChange;
|
||||
bool isHidden;
|
||||
bool isManual;
|
||||
bool isLegacyDerivation;
|
||||
final bool? isOneTimeReceiveAddress;
|
||||
|
||||
@override
|
||||
|
||||
@@ -290,7 +290,8 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
|
||||
txCount: subaddress.txCount,
|
||||
balance: _appStore.amountParsingProxy
|
||||
.getDisplayCryptoString(subaddress.balance, walletTypeToCryptoCurrency(type)),
|
||||
isChange: subaddress.isChange);
|
||||
isChange: subaddress.isChange,
|
||||
isLegacyDerivation: subaddress.isLegacyDerivation);
|
||||
});
|
||||
|
||||
// don't show all 1000+ mweb addresses:
|
||||
@@ -352,8 +353,9 @@ abstract class WalletAddressListViewModelBase extends WalletChangeListenerViewMo
|
||||
|
||||
for (var i = 0; i < addressList.length; i++) {
|
||||
if (!(addressList[i] is WalletAddressListItem)) continue;
|
||||
(addressList[i] as WalletAddressListItem).isHidden = wallet.walletAddresses.hiddenAddresses
|
||||
.contains((addressList[i] as WalletAddressListItem).address);
|
||||
final item = addressList[i] as WalletAddressListItem;
|
||||
item.isHidden = wallet.walletAddresses.hiddenAddresses.contains(item.address) ||
|
||||
(isElectrumWallet && item.isLegacyDerivation);
|
||||
}
|
||||
|
||||
for (var i = 0; i < addressList.length; i++) {
|
||||
|
||||
Reference in New Issue
Block a user