mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-10 12:54:38 +00:00
debatably better refactoring of derivationInfo, migration needed
This commit is contained in:
parent
d4c8a1d8f6
commit
ae97e50bf4
15 changed files with 127 additions and 106 deletions
|
@ -38,7 +38,6 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
|
||||||
initialBalance: initialBalance,
|
initialBalance: initialBalance,
|
||||||
seedBytes: seedBytes,
|
seedBytes: seedBytes,
|
||||||
currency: CryptoCurrency.btc) {
|
currency: CryptoCurrency.btc) {
|
||||||
|
|
||||||
// in a standard BIP44 wallet, mainHd derivation path = m/84'/0'/0'/0 (account 0, index unspecified here)
|
// in a standard BIP44 wallet, mainHd derivation path = m/84'/0'/0'/0 (account 0, index unspecified here)
|
||||||
// the sideHd derivation path = m/84'/0'/0'/1 (account 1, index unspecified here)
|
// the sideHd derivation path = m/84'/0'/0'/1 (account 1, index unspecified here)
|
||||||
walletAddresses = BitcoinWalletAddresses(walletInfo,
|
walletAddresses = BitcoinWalletAddresses(walletInfo,
|
||||||
|
@ -47,9 +46,11 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
|
||||||
initialRegularAddressIndex: initialRegularAddressIndex,
|
initialRegularAddressIndex: initialRegularAddressIndex,
|
||||||
initialChangeAddressIndex: initialChangeAddressIndex,
|
initialChangeAddressIndex: initialChangeAddressIndex,
|
||||||
mainHd: bitcoin.HDWallet.fromSeed(seedBytes, network: networkType)
|
mainHd: bitcoin.HDWallet.fromSeed(seedBytes, network: networkType)
|
||||||
.derivePath(walletInfo.derivationPath!),
|
.derivePath(walletInfo.derivationInfo!.derivationPath!),
|
||||||
sideHd: bitcoin.HDWallet.fromSeed(seedBytes, network: networkType).derivePath(
|
sideHd: bitcoin.HDWallet.fromSeed(seedBytes, network: networkType).derivePath(walletInfo
|
||||||
walletInfo.derivationPath!.substring(0, walletInfo.derivationPath!.length - 1) + "1"),
|
.derivationInfo!.derivationPath!
|
||||||
|
.substring(0, walletInfo.derivationInfo!.derivationPath!.length - 1) +
|
||||||
|
"1"),
|
||||||
networkType: networkType);
|
networkType: networkType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,14 +65,14 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
|
||||||
int initialChangeAddressIndex = 0}) async {
|
int initialChangeAddressIndex = 0}) async {
|
||||||
late Uint8List seedBytes;
|
late Uint8List seedBytes;
|
||||||
|
|
||||||
switch (walletInfo.derivationType) {
|
switch (walletInfo.derivationInfo?.derivationType) {
|
||||||
case DerivationType.electrum2:
|
|
||||||
seedBytes = await mnemonicToSeedBytes(mnemonic);
|
|
||||||
break;
|
|
||||||
case DerivationType.bip39:
|
case DerivationType.bip39:
|
||||||
default:
|
|
||||||
seedBytes = await bip39.mnemonicToSeed(mnemonic);
|
seedBytes = await bip39.mnemonicToSeed(mnemonic);
|
||||||
break;
|
break;
|
||||||
|
case DerivationType.electrum2:
|
||||||
|
default:
|
||||||
|
seedBytes = await mnemonicToSeedBytes(mnemonic);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return BitcoinWallet(
|
return BitcoinWallet(
|
||||||
|
@ -94,20 +95,17 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
|
||||||
}) async {
|
}) async {
|
||||||
final snp = await ElectrumWallletSnapshot.load(name, walletInfo.type, password);
|
final snp = await ElectrumWallletSnapshot.load(name, walletInfo.type, password);
|
||||||
|
|
||||||
walletInfo.derivationType = snp.derivationType;
|
walletInfo.derivationInfo ??= DerivationInfo(
|
||||||
walletInfo.derivationPath = snp.derivationPath;
|
derivationType: snp.derivationType ?? DerivationType.electrum2,
|
||||||
|
derivationPath: snp.derivationPath,
|
||||||
|
);
|
||||||
|
|
||||||
// set the default if not present:
|
// set the default if not present:
|
||||||
if (walletInfo.derivationPath == null) {
|
walletInfo.derivationInfo!.derivationPath = snp.derivationPath ?? "m/0'/1";
|
||||||
walletInfo.derivationPath = "m/0'/1";
|
|
||||||
}
|
|
||||||
if (walletInfo.derivationType == null) {
|
|
||||||
walletInfo.derivationType = DerivationType.electrum2;
|
|
||||||
}
|
|
||||||
|
|
||||||
late Uint8List seedBytes;
|
late Uint8List seedBytes;
|
||||||
|
|
||||||
switch (walletInfo.derivationType) {
|
switch (walletInfo.derivationInfo!.derivationType) {
|
||||||
case DerivationType.electrum2:
|
case DerivationType.electrum2:
|
||||||
seedBytes = await mnemonicToSeedBytes(snp.mnemonic);
|
seedBytes = await mnemonicToSeedBytes(snp.mnemonic);
|
||||||
break;
|
break;
|
||||||
|
@ -128,4 +126,4 @@ abstract class BitcoinWalletBase extends ElectrumWallet with Store {
|
||||||
initialRegularAddressIndex: snp.regularAddressIndex,
|
initialRegularAddressIndex: snp.regularAddressIndex,
|
||||||
initialChangeAddressIndex: snp.changeAddressIndex);
|
initialChangeAddressIndex: snp.changeAddressIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,11 @@ import 'package:cw_core/wallet_credentials.dart';
|
||||||
import 'package:cw_core/wallet_info.dart';
|
import 'package:cw_core/wallet_info.dart';
|
||||||
|
|
||||||
class BitcoinNewWalletCredentials extends WalletCredentials {
|
class BitcoinNewWalletCredentials extends WalletCredentials {
|
||||||
BitcoinNewWalletCredentials({required String name, WalletInfo? walletInfo})
|
BitcoinNewWalletCredentials(
|
||||||
|
{required String name, WalletInfo? walletInfo, this.derivationType, this.derivationPath})
|
||||||
: super(name: name, walletInfo: walletInfo);
|
: super(name: name, walletInfo: walletInfo);
|
||||||
|
DerivationType? derivationType;
|
||||||
|
String? derivationPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
class BitcoinRestoreWalletFromSeedCredentials extends WalletCredentials {
|
class BitcoinRestoreWalletFromSeedCredentials extends WalletCredentials {
|
||||||
|
@ -11,16 +14,17 @@ class BitcoinRestoreWalletFromSeedCredentials extends WalletCredentials {
|
||||||
required String name,
|
required String name,
|
||||||
required String password,
|
required String password,
|
||||||
required this.mnemonic,
|
required this.mnemonic,
|
||||||
|
WalletInfo? walletInfo,
|
||||||
DerivationType? derivationType,
|
DerivationType? derivationType,
|
||||||
String? derivationPath,
|
String? derivationPath,
|
||||||
WalletInfo? walletInfo,
|
|
||||||
}) : super(
|
}) : super(
|
||||||
name: name,
|
name: name,
|
||||||
password: password,
|
password: password,
|
||||||
walletInfo: walletInfo,
|
walletInfo: walletInfo,
|
||||||
derivationType: derivationType,
|
derivationInfo: DerivationInfo(
|
||||||
derivationPath: derivationPath,
|
derivationType: derivationType,
|
||||||
);
|
derivationPath: derivationPath,
|
||||||
|
));
|
||||||
|
|
||||||
final String mnemonic;
|
final String mnemonic;
|
||||||
}
|
}
|
||||||
|
@ -31,4 +35,4 @@ class BitcoinRestoreWalletFromWIFCredentials extends WalletCredentials {
|
||||||
: super(name: name, password: password, walletInfo: walletInfo);
|
: super(name: name, password: password, walletInfo: walletInfo);
|
||||||
|
|
||||||
final String wif;
|
final String wif;
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,13 +46,13 @@ class BitcoinWalletService extends WalletService<BitcoinNewWalletCredentials,
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<BitcoinWallet> create(BitcoinNewWalletCredentials credentials) async {
|
Future<BitcoinWallet> create(BitcoinNewWalletCredentials credentials) async {
|
||||||
// default derivation type/path for bitcoin wallets:
|
// set default if not present:
|
||||||
if (credentials.walletInfo!.derivationType == null) {
|
DerivationType derivationType = credentials.derivationType ?? DerivationType.electrum2;
|
||||||
credentials.walletInfo!.derivationType = DerivationType.electrum2;
|
String derivationPath = credentials.derivationPath ?? "m/0'/1";
|
||||||
}
|
// only set if not in the walletInfo already:
|
||||||
if (credentials.walletInfo!.derivationPath == null) {
|
credentials.walletInfo!.derivationInfo ??=
|
||||||
credentials.walletInfo!.derivationPath = "m/0'/1";
|
DerivationInfo(derivationType: derivationType, derivationPath: derivationPath);
|
||||||
}
|
|
||||||
final wallet = await BitcoinWalletBase.create(
|
final wallet = await BitcoinWalletBase.create(
|
||||||
mnemonic: await generateElectrumMnemonic(strength: 132),
|
mnemonic: await generateElectrumMnemonic(strength: 132),
|
||||||
password: credentials.password!,
|
password: credentials.password!,
|
||||||
|
|
|
@ -13,4 +13,5 @@ const ADDRESS_INFO_TYPE_ID = 11;
|
||||||
const ERC20_TOKEN_TYPE_ID = 12;
|
const ERC20_TOKEN_TYPE_ID = 12;
|
||||||
const NANO_ACCOUNT_TYPE_ID = 13;
|
const NANO_ACCOUNT_TYPE_ID = 13;
|
||||||
const POW_NODE_TYPE_ID = 14;
|
const POW_NODE_TYPE_ID = 14;
|
||||||
const DERIVATION_TYPE_TYPE_ID = 15;
|
const DERIVATION_TYPE_TYPE_ID = 15;
|
||||||
|
const DERIVATION_INFO_TYPE_ID = 16;
|
|
@ -6,14 +6,12 @@ abstract class WalletCredentials {
|
||||||
this.height,
|
this.height,
|
||||||
this.walletInfo,
|
this.walletInfo,
|
||||||
this.password,
|
this.password,
|
||||||
this.derivationType,
|
this.derivationInfo,
|
||||||
this.derivationPath,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
final String name;
|
final String name;
|
||||||
final int? height;
|
final int? height;
|
||||||
String? password;
|
String? password;
|
||||||
DerivationType? derivationType;
|
|
||||||
String? derivationPath;
|
|
||||||
WalletInfo? walletInfo;
|
WalletInfo? walletInfo;
|
||||||
|
DerivationInfo? derivationInfo;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,10 +21,10 @@ enum DerivationType {
|
||||||
@HiveField(5)
|
@HiveField(5)
|
||||||
electrum2,
|
electrum2,
|
||||||
}
|
}
|
||||||
|
@HiveType(typeId: DerivationInfo.typeId)
|
||||||
class DerivationInfo {
|
class DerivationInfo extends HiveObject {
|
||||||
DerivationInfo({
|
DerivationInfo({
|
||||||
required this.derivationType,
|
this.derivationType,
|
||||||
this.derivationPath,
|
this.derivationPath,
|
||||||
this.balance = "",
|
this.balance = "",
|
||||||
this.address = "",
|
this.address = "",
|
||||||
|
@ -33,10 +33,12 @@ class DerivationInfo {
|
||||||
this.description,
|
this.description,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
static const typeId = DERIVATION_INFO_TYPE_ID;
|
||||||
|
|
||||||
String balance;
|
String balance;
|
||||||
String address;
|
String address;
|
||||||
int height;
|
int height;
|
||||||
final DerivationType derivationType;
|
DerivationType? derivationType;
|
||||||
String? derivationPath;
|
String? derivationPath;
|
||||||
final String? script_type;
|
final String? script_type;
|
||||||
final String? description;
|
final String? description;
|
||||||
|
@ -57,8 +59,7 @@ class WalletInfo extends HiveObject {
|
||||||
this.yatEid,
|
this.yatEid,
|
||||||
this.yatLastUsedAddressRaw,
|
this.yatLastUsedAddressRaw,
|
||||||
this.showIntroCakePayCard,
|
this.showIntroCakePayCard,
|
||||||
this.derivationType,
|
this.derivationInfo)
|
||||||
this.derivationPath)
|
|
||||||
: _yatLastUsedAddressController = StreamController<String>.broadcast();
|
: _yatLastUsedAddressController = StreamController<String>.broadcast();
|
||||||
|
|
||||||
factory WalletInfo.external({
|
factory WalletInfo.external({
|
||||||
|
@ -74,8 +75,7 @@ class WalletInfo extends HiveObject {
|
||||||
bool? showIntroCakePayCard,
|
bool? showIntroCakePayCard,
|
||||||
String yatEid = '',
|
String yatEid = '',
|
||||||
String yatLastUsedAddressRaw = '',
|
String yatLastUsedAddressRaw = '',
|
||||||
DerivationType? derivationType,
|
DerivationInfo? derivationInfo,
|
||||||
String? derivationPath,
|
|
||||||
}) {
|
}) {
|
||||||
return WalletInfo(
|
return WalletInfo(
|
||||||
id,
|
id,
|
||||||
|
@ -90,8 +90,7 @@ class WalletInfo extends HiveObject {
|
||||||
yatEid,
|
yatEid,
|
||||||
yatLastUsedAddressRaw,
|
yatLastUsedAddressRaw,
|
||||||
showIntroCakePayCard,
|
showIntroCakePayCard,
|
||||||
derivationType,
|
derivationInfo);
|
||||||
derivationPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const typeId = WALLET_INFO_TYPE_ID;
|
static const typeId = WALLET_INFO_TYPE_ID;
|
||||||
|
@ -143,10 +142,7 @@ class WalletInfo extends HiveObject {
|
||||||
List<String>? usedAddresses;
|
List<String>? usedAddresses;
|
||||||
|
|
||||||
@HiveField(16)
|
@HiveField(16)
|
||||||
DerivationType? derivationType;
|
DerivationInfo? derivationInfo;
|
||||||
|
|
||||||
@HiveField(17)
|
|
||||||
String? derivationPath;
|
|
||||||
|
|
||||||
String get yatLastUsedAddress => yatLastUsedAddressRaw ?? '';
|
String get yatLastUsedAddress => yatLastUsedAddressRaw ?? '';
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ abstract class NanoWalletBase
|
||||||
}) : syncStatus = NotConnectedSyncStatus(),
|
}) : syncStatus = NotConnectedSyncStatus(),
|
||||||
_password = password,
|
_password = password,
|
||||||
_mnemonic = mnemonic,
|
_mnemonic = mnemonic,
|
||||||
_derivationType = walletInfo.derivationType!,
|
_derivationType = walletInfo.derivationInfo!.derivationType!,
|
||||||
_isTransactionUpdating = false,
|
_isTransactionUpdating = false,
|
||||||
_client = NanoClient(),
|
_client = NanoClient(),
|
||||||
walletAddresses = NanoWalletAddresses(walletInfo),
|
walletAddresses = NanoWalletAddresses(walletInfo),
|
||||||
|
@ -354,7 +354,7 @@ abstract class NanoWalletBase
|
||||||
derivationType = DerivationType.nano;
|
derivationType = DerivationType.nano;
|
||||||
}
|
}
|
||||||
|
|
||||||
walletInfo.derivationType = derivationType;
|
walletInfo.derivationInfo ??= DerivationInfo(derivationType: derivationType);
|
||||||
|
|
||||||
return NanoWallet(
|
return NanoWallet(
|
||||||
walletInfo: walletInfo,
|
walletInfo: walletInfo,
|
||||||
|
|
|
@ -2,8 +2,15 @@ import 'package:cw_core/wallet_credentials.dart';
|
||||||
import 'package:cw_core/wallet_info.dart';
|
import 'package:cw_core/wallet_info.dart';
|
||||||
|
|
||||||
class NanoNewWalletCredentials extends WalletCredentials {
|
class NanoNewWalletCredentials extends WalletCredentials {
|
||||||
NanoNewWalletCredentials({required String name, String? password})
|
NanoNewWalletCredentials({
|
||||||
: super(name: name, password: password);
|
required String name,
|
||||||
|
String? password,
|
||||||
|
DerivationType? derivationType,
|
||||||
|
}) : super(
|
||||||
|
name: name,
|
||||||
|
password: password,
|
||||||
|
derivationInfo: DerivationInfo(derivationType: derivationType),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
class NanoRestoreWalletFromSeedCredentials extends WalletCredentials {
|
class NanoRestoreWalletFromSeedCredentials extends WalletCredentials {
|
||||||
|
@ -14,11 +21,13 @@ class NanoRestoreWalletFromSeedCredentials extends WalletCredentials {
|
||||||
String? password,
|
String? password,
|
||||||
DerivationType? derivationType,
|
DerivationType? derivationType,
|
||||||
}) : super(
|
}) : super(
|
||||||
name: name,
|
name: name,
|
||||||
password: password,
|
password: password,
|
||||||
height: height,
|
height: height,
|
||||||
derivationType: derivationType,
|
derivationInfo: DerivationInfo(
|
||||||
);
|
derivationType: derivationType,
|
||||||
|
height: height,
|
||||||
|
));
|
||||||
|
|
||||||
final String mnemonic;
|
final String mnemonic;
|
||||||
}
|
}
|
||||||
|
@ -38,4 +47,4 @@ class NanoRestoreWalletFromKeysCredentials extends WalletCredentials {
|
||||||
|
|
||||||
final String seedKey;
|
final String seedKey;
|
||||||
final DerivationType? derivationType;
|
final DerivationType? derivationType;
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,11 +28,12 @@ class NanoWalletService extends WalletService<NanoNewWalletCredentials,
|
||||||
@override
|
@override
|
||||||
Future<WalletBase> create(NanoNewWalletCredentials credentials) async {
|
Future<WalletBase> create(NanoNewWalletCredentials credentials) async {
|
||||||
// nano standard:
|
// nano standard:
|
||||||
DerivationType derivationType = DerivationType.nano;
|
|
||||||
String seedKey = NanoSeeds.generateSeed();
|
String seedKey = NanoSeeds.generateSeed();
|
||||||
String mnemonic = NanoUtil.seedToMnemonic(seedKey);
|
String mnemonic = NanoUtil.seedToMnemonic(seedKey);
|
||||||
|
|
||||||
credentials.walletInfo!.derivationType = derivationType;
|
// set default if not present:
|
||||||
|
DerivationType derivationType = credentials.derivationInfo?.derivationType ?? DerivationType.nano;
|
||||||
|
credentials.walletInfo!.derivationInfo ??= DerivationInfo(derivationType: derivationType);
|
||||||
|
|
||||||
final wallet = NanoWallet(
|
final wallet = NanoWallet(
|
||||||
walletInfo: credentials.walletInfo!,
|
walletInfo: credentials.walletInfo!,
|
||||||
|
@ -88,7 +89,7 @@ class NanoWalletService extends WalletService<NanoNewWalletCredentials,
|
||||||
}
|
}
|
||||||
|
|
||||||
DerivationType derivationType = credentials.derivationType ?? DerivationType.nano;
|
DerivationType derivationType = credentials.derivationType ?? DerivationType.nano;
|
||||||
credentials.walletInfo!.derivationType = derivationType;
|
credentials.walletInfo!.derivationInfo ??= DerivationInfo(derivationType: derivationType);
|
||||||
|
|
||||||
String? mnemonic;
|
String? mnemonic;
|
||||||
|
|
||||||
|
@ -127,9 +128,10 @@ class NanoWalletService extends WalletService<NanoNewWalletCredentials,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DerivationType derivationType = credentials.derivationType ?? DerivationType.nano;
|
DerivationType derivationType =
|
||||||
|
credentials.walletInfo?.derivationInfo?.derivationType ?? DerivationType.nano;
|
||||||
|
|
||||||
credentials.walletInfo!.derivationType = derivationType;
|
credentials.walletInfo!.derivationInfo ??= DerivationInfo(derivationType: derivationType);
|
||||||
|
|
||||||
final wallet = await NanoWallet(
|
final wallet = await NanoWallet(
|
||||||
password: credentials.password!,
|
password: credentials.password!,
|
||||||
|
|
|
@ -100,6 +100,10 @@ Future<void> initializeAppConfigs() async {
|
||||||
if (!Hive.isAdapterRegistered(DERIVATION_TYPE_TYPE_ID)) {
|
if (!Hive.isAdapterRegistered(DERIVATION_TYPE_TYPE_ID)) {
|
||||||
CakeHive.registerAdapter(DerivationTypeAdapter());
|
CakeHive.registerAdapter(DerivationTypeAdapter());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!Hive.isAdapterRegistered(DERIVATION_INFO_TYPE_ID)) {
|
||||||
|
CakeHive.registerAdapter(DerivationInfoAdapter());
|
||||||
|
}
|
||||||
|
|
||||||
if (!CakeHive.isAdapterRegistered(WALLET_TYPE_TYPE_ID)) {
|
if (!CakeHive.isAdapterRegistered(WALLET_TYPE_TYPE_ID)) {
|
||||||
CakeHive.registerAdapter(WalletTypeAdapter());
|
CakeHive.registerAdapter(WalletTypeAdapter());
|
||||||
|
|
|
@ -96,6 +96,7 @@ class CWNano extends Nano {
|
||||||
NanoNewWalletCredentials(
|
NanoNewWalletCredentials(
|
||||||
name: name,
|
name: name,
|
||||||
password: password,
|
password: password,
|
||||||
|
derivationType: DerivationType.nano,
|
||||||
);
|
);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
|
@ -110,8 +110,9 @@ class WalletRestorePage extends BasePage {
|
||||||
final GlobalKey<WalletRestoreFromSeedFormState> walletRestoreFromSeedFormKey;
|
final GlobalKey<WalletRestoreFromSeedFormState> walletRestoreFromSeedFormKey;
|
||||||
final GlobalKey<WalletRestoreFromKeysFromState> walletRestoreFromKeysFormKey;
|
final GlobalKey<WalletRestoreFromKeysFromState> walletRestoreFromKeysFormKey;
|
||||||
final FocusNode _blockHeightFocusNode;
|
final FocusNode _blockHeightFocusNode;
|
||||||
DerivationType derivationType = DerivationType.unknown;
|
// DerivationType derivationType = DerivationType.unknown;
|
||||||
String? derivationPath = null;
|
// String? derivationPath = null;
|
||||||
|
DerivationInfo? derivationInfo;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget body(BuildContext context) {
|
Widget body(BuildContext context) {
|
||||||
|
@ -294,8 +295,7 @@ class WalletRestorePage extends BasePage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
credentials['derivationType'] = this.derivationType;
|
credentials['derivationInfo'] = this.derivationInfo;
|
||||||
credentials['derivationPath'] = this.derivationPath;
|
|
||||||
credentials['walletType'] = walletRestoreViewModel.type;
|
credentials['walletType'] = walletRestoreViewModel.type;
|
||||||
return credentials;
|
return credentials;
|
||||||
}
|
}
|
||||||
|
@ -330,10 +330,12 @@ class WalletRestorePage extends BasePage {
|
||||||
|
|
||||||
List<DerivationType> derivationTypes =
|
List<DerivationType> derivationTypes =
|
||||||
await walletRestoreViewModel.getDerivationTypes(_credentials());
|
await walletRestoreViewModel.getDerivationTypes(_credentials());
|
||||||
|
DerivationInfo? dInfo;
|
||||||
|
|
||||||
if (derivationTypes[0] == DerivationType.unknown || derivationTypes.length > 1) {
|
if (derivationTypes.length > 1) {
|
||||||
// push screen to choose the derivation type:
|
// push screen to choose the derivation type:
|
||||||
List<DerivationInfo> derivations = await walletRestoreViewModel.getDerivationInfo(_credentials());
|
List<DerivationInfo> derivations =
|
||||||
|
await walletRestoreViewModel.getDerivationInfo(_credentials());
|
||||||
|
|
||||||
int derivationsWithHistory = 0;
|
int derivationsWithHistory = 0;
|
||||||
int derivationWithHistoryIndex = 0;
|
int derivationWithHistoryIndex = 0;
|
||||||
|
@ -343,34 +345,25 @@ class WalletRestorePage extends BasePage {
|
||||||
derivationWithHistoryIndex = i;
|
derivationWithHistoryIndex = i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DerivationInfo? derivationInfo;
|
|
||||||
|
|
||||||
if (derivationsWithHistory > 1) {
|
if (derivationsWithHistory > 1) {
|
||||||
derivationInfo = await Navigator.of(context).pushNamed(Routes.restoreWalletChooseDerivation,
|
dInfo = await Navigator.of(context).pushNamed(Routes.restoreWalletChooseDerivation,
|
||||||
arguments: derivations) as DerivationInfo?;
|
arguments: derivations) as DerivationInfo?;
|
||||||
} else if (derivationsWithHistory == 1) {
|
} else if (derivationsWithHistory == 1) {
|
||||||
derivationInfo = derivations[derivationWithHistoryIndex];
|
dInfo = derivations[derivationWithHistoryIndex];
|
||||||
} else if (derivationsWithHistory == 0) {
|
|
||||||
// default derivation:
|
|
||||||
derivationInfo = DerivationInfo(
|
|
||||||
derivationType: derivationTypes[0],
|
|
||||||
derivationPath: "m/0'/1",
|
|
||||||
height: 0,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (derivationInfo == null) {
|
if (dInfo == null) {
|
||||||
walletRestoreViewModel.state = InitialExecutionState();
|
walletRestoreViewModel.state = InitialExecutionState();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.derivationType = derivationInfo.derivationType;
|
|
||||||
this.derivationPath = derivationInfo.derivationPath;
|
this.derivationInfo = dInfo;
|
||||||
} else {
|
}
|
||||||
// electrum derivation:
|
|
||||||
this.derivationType = derivationTypes[0];
|
// get the default derivation for this wallet type:
|
||||||
this.derivationPath = "m/0'/1";
|
if (this.derivationInfo == null) {
|
||||||
|
this.derivationInfo = walletRestoreViewModel.getDefaultDerivation();
|
||||||
}
|
}
|
||||||
|
|
||||||
walletRestoreViewModel.state = InitialExecutionState();
|
walletRestoreViewModel.state = InitialExecutionState();
|
||||||
|
|
|
@ -65,8 +65,7 @@ abstract class WalletCreationVMBase with Store {
|
||||||
dirPath: dirPath,
|
dirPath: dirPath,
|
||||||
address: '',
|
address: '',
|
||||||
showIntroCakePayCard: (!walletCreationService.typeExists(type)) && type != WalletType.haven,
|
showIntroCakePayCard: (!walletCreationService.typeExists(type)) && type != WalletType.haven,
|
||||||
derivationPath: credentials.derivationPath,
|
derivationInfo: credentials.derivationInfo,
|
||||||
derivationType: credentials.derivationType,
|
|
||||||
);
|
);
|
||||||
credentials.walletInfo = walletInfo;
|
credentials.walletInfo = walletInfo;
|
||||||
final wallet = restoreWallet != null
|
final wallet = restoreWallet != null
|
||||||
|
|
|
@ -35,21 +35,20 @@ abstract class WalletNewVMBase extends WalletCreationVM with Store {
|
||||||
WalletCredentials getCredentials(dynamic options) {
|
WalletCredentials getCredentials(dynamic options) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case WalletType.monero:
|
case WalletType.monero:
|
||||||
return monero!.createMoneroNewWalletCredentials(
|
return monero!.createMoneroNewWalletCredentials(name: name, language: options as String);
|
||||||
name: name, language: options as String);
|
|
||||||
case WalletType.bitcoin:
|
case WalletType.bitcoin:
|
||||||
return bitcoin!.createBitcoinNewWalletCredentials(name: name);
|
return bitcoin!.createBitcoinNewWalletCredentials(name: name);
|
||||||
case WalletType.litecoin:
|
case WalletType.litecoin:
|
||||||
return bitcoin!.createBitcoinNewWalletCredentials(name: name);
|
return bitcoin!.createBitcoinNewWalletCredentials(name: name);
|
||||||
case WalletType.haven:
|
case WalletType.haven:
|
||||||
return haven!.createHavenNewWalletCredentials(
|
return haven!.createHavenNewWalletCredentials(name: name, language: options as String);
|
||||||
name: name, language: options as String);
|
|
||||||
case WalletType.ethereum:
|
case WalletType.ethereum:
|
||||||
return ethereum!.createEthereumNewWalletCredentials(name: name);
|
return ethereum!.createEthereumNewWalletCredentials(name: name);
|
||||||
case WalletType.nano:
|
case WalletType.nano:
|
||||||
return nano!.createNanoNewWalletCredentials(name: name);
|
return nano!.createNanoNewWalletCredentials(name: name);
|
||||||
default:
|
default:
|
||||||
throw Exception('Unexpected type: ${type.toString()}');;
|
throw Exception('Unexpected type: ${type.toString()}');
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,8 +70,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
||||||
final password = generateWalletPassword();
|
final password = generateWalletPassword();
|
||||||
final height = options['height'] as int? ?? 0;
|
final height = options['height'] as int? ?? 0;
|
||||||
name = options['name'] as String;
|
name = options['name'] as String;
|
||||||
DerivationType? derivationType = options["derivationType"] as DerivationType?;
|
DerivationInfo? derivationInfo = options["derivationInfo"] as DerivationInfo?;
|
||||||
String? derivationPath = options["derivationPath"] as String?;
|
|
||||||
|
|
||||||
if (mode == WalletRestoreMode.seed) {
|
if (mode == WalletRestoreMode.seed) {
|
||||||
final seed = options['seed'] as String;
|
final seed = options['seed'] as String;
|
||||||
|
@ -84,8 +83,8 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
||||||
name: name,
|
name: name,
|
||||||
mnemonic: seed,
|
mnemonic: seed,
|
||||||
password: password,
|
password: password,
|
||||||
derivationType: derivationType,
|
derivationType: derivationInfo?.derivationType,
|
||||||
derivationPath: derivationPath,
|
derivationPath: derivationInfo?.derivationPath,
|
||||||
);
|
);
|
||||||
case WalletType.litecoin:
|
case WalletType.litecoin:
|
||||||
return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials(
|
return bitcoin!.createBitcoinRestoreWalletFromSeedCredentials(
|
||||||
|
@ -101,7 +100,7 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
||||||
name: name,
|
name: name,
|
||||||
mnemonic: seed,
|
mnemonic: seed,
|
||||||
password: password,
|
password: password,
|
||||||
derivationType: derivationType,
|
derivationType: derivationInfo?.derivationType,
|
||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -223,6 +222,8 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
||||||
privateKey: seedKey,
|
privateKey: seedKey,
|
||||||
node: node,
|
node: node,
|
||||||
);
|
);
|
||||||
|
case WalletType.litecoin:
|
||||||
|
return [DerivationType.electrum2];
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -231,6 +232,22 @@ abstract class WalletRestoreViewModelBase extends WalletCreationVM with Store {
|
||||||
return [DerivationType.def];
|
return [DerivationType.def];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DerivationInfo getDefaultDerivation() {
|
||||||
|
switch (type) {
|
||||||
|
case WalletType.nano:
|
||||||
|
return DerivationInfo(
|
||||||
|
derivationType: DerivationType.nano,
|
||||||
|
);
|
||||||
|
case WalletType.bitcoin:
|
||||||
|
case WalletType.litecoin:
|
||||||
|
default:
|
||||||
|
return DerivationInfo(
|
||||||
|
derivationType: DerivationType.electrum2,
|
||||||
|
derivationPath: "m/0'/1",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Future<WalletBase> process(WalletCredentials credentials) async {
|
Future<WalletBase> process(WalletCredentials credentials) async {
|
||||||
if (mode == WalletRestoreMode.keys) {
|
if (mode == WalletRestoreMode.keys) {
|
||||||
|
|
Loading…
Reference in a new issue