single DerivePathType enum declaration

This commit is contained in:
julian 2023-01-25 12:08:48 -06:00
parent 1965501bf8
commit 6b08acf225
7 changed files with 32 additions and 19 deletions

View file

@ -33,6 +33,7 @@ import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/default_nodes.dart'; import 'package:stackwallet/utilities/default_nodes.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart';
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
import 'package:stackwallet/utilities/format.dart'; import 'package:stackwallet/utilities/format.dart';
@ -50,8 +51,6 @@ const String GENESIS_HASH_MAINNET =
const String GENESIS_HASH_TESTNET = const String GENESIS_HASH_TESTNET =
"000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"; "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943";
enum DerivePathType { bip44, bip49, bip84 }
bip32.BIP32 getBip32Node( bip32.BIP32 getBip32Node(
int chain, int chain,
int index, int index,

View file

@ -34,6 +34,7 @@ import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/default_nodes.dart'; import 'package:stackwallet/utilities/default_nodes.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart';
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
import 'package:stackwallet/utilities/format.dart'; import 'package:stackwallet/utilities/format.dart';
@ -50,8 +51,6 @@ const String GENESIS_HASH_MAINNET =
const String GENESIS_HASH_TESTNET = const String GENESIS_HASH_TESTNET =
"000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943"; "000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943";
enum DerivePathType { bip44, bip49 }
bip32.BIP32 getBip32Node(int chain, int index, String mnemonic, bip32.BIP32 getBip32Node(int chain, int index, String mnemonic,
NetworkType network, DerivePathType derivePathType) { NetworkType network, DerivePathType derivePathType) {
final root = getBip32Root(mnemonic, network); final root = getBip32Root(mnemonic, network);
@ -1421,9 +1420,8 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
.address!; .address!;
addrType = isar_models.AddressType.p2sh; addrType = isar_models.AddressType.p2sh;
break; break;
// default: case DerivePathType.bip84:
// // should never hit this due to all enum cases handled throw UnsupportedError("bip84 not supported by BCH");
// return null;
} }
// add generated address & info to derivations // add generated address & info to derivations
@ -1466,6 +1464,8 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
case DerivePathType.bip49: case DerivePathType.bip49:
type = isar_models.AddressType.p2sh; type = isar_models.AddressType.p2sh;
break; break;
case DerivePathType.bip84:
throw UnsupportedError("bip84 not supported by BCH");
} }
final address = await db final address = await db
@ -1491,6 +1491,8 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
case DerivePathType.bip49: case DerivePathType.bip49:
key = "${walletId}_${chainId}DerivationsP2SH"; key = "${walletId}_${chainId}DerivationsP2SH";
break; break;
case DerivePathType.bip84:
throw UnsupportedError("bip84 not supported by BCH");
} }
return key; return key;
} }
@ -2611,6 +2613,8 @@ class BitcoinCashWallet extends CoinServiceAPI with WalletCache, WalletDB {
case DerivePathType.bip49: case DerivePathType.bip49:
addressesP2SH.add(address); addressesP2SH.add(address);
break; break;
case DerivePathType.bip84:
throw UnsupportedError("bip84 not supported by BCH");
} }
} }
} }

View file

@ -34,6 +34,7 @@ import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/default_nodes.dart'; import 'package:stackwallet/utilities/default_nodes.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart';
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
import 'package:stackwallet/utilities/format.dart'; import 'package:stackwallet/utilities/format.dart';
@ -50,8 +51,6 @@ const String GENESIS_HASH_MAINNET =
const String GENESIS_HASH_TESTNET = const String GENESIS_HASH_TESTNET =
"bb0a78264637406b6360aad926284d544d7049f45189db5664f3c4d07350559e"; "bb0a78264637406b6360aad926284d544d7049f45189db5664f3c4d07350559e";
enum DerivePathType { bip44 }
bip32.BIP32 getBip32Node(int chain, int index, String mnemonic, bip32.BIP32 getBip32Node(int chain, int index, String mnemonic,
NetworkType network, DerivePathType derivePathType) { NetworkType network, DerivePathType derivePathType) {
final root = getBip32Root(mnemonic, network); final root = getBip32Root(mnemonic, network);
@ -90,7 +89,7 @@ bip32.BIP32 getBip32NodeFromRoot(
case DerivePathType.bip44: case DerivePathType.bip44:
return root.derivePath("m/44'/$coinType'/0'/$chain/$index"); return root.derivePath("m/44'/$coinType'/0'/$chain/$index");
default: default:
throw Exception("DerivePathType must not be null."); throw Exception("Unsupported DerivePathType");
} }
} }
@ -1273,9 +1272,8 @@ class DogecoinWallet extends CoinServiceAPI
case DerivePathType.bip44: case DerivePathType.bip44:
address = P2PKH(data: data, network: network).data.address!; address = P2PKH(data: data, network: network).data.address!;
break; break;
// default: default:
// // should never hit this due to all enum cases handled throw Exception("Unsupported DerivePathType");
// return null;
} }
// add generated address & info to derivations // add generated address & info to derivations
@ -1320,6 +1318,8 @@ class DogecoinWallet extends CoinServiceAPI
.sortByDerivationIndexDesc() .sortByDerivationIndexDesc()
.findFirst(); .findFirst();
break; break;
default:
throw Exception("Unsupported DerivePathType");
} }
return address!.value; return address!.value;
} }
@ -1332,6 +1332,8 @@ class DogecoinWallet extends CoinServiceAPI
case DerivePathType.bip44: case DerivePathType.bip44:
key = "${walletId}_${chainId}DerivationsP2PKH"; key = "${walletId}_${chainId}DerivationsP2PKH";
break; break;
default:
throw Exception("Unsupported DerivePathType");
} }
return key; return key;
} }
@ -2339,6 +2341,8 @@ class DogecoinWallet extends CoinServiceAPI
case DerivePathType.bip44: case DerivePathType.bip44:
addressesP2PKH.add(address); addressesP2PKH.add(address);
break; break;
default:
throw Exception("Unsupported DerivePathType");
} }
} }
} }

View file

@ -33,6 +33,7 @@ import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/default_nodes.dart'; import 'package:stackwallet/utilities/default_nodes.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart';
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
import 'package:stackwallet/utilities/format.dart'; import 'package:stackwallet/utilities/format.dart';
@ -50,8 +51,6 @@ const String GENESIS_HASH_MAINNET =
const String GENESIS_HASH_TESTNET = const String GENESIS_HASH_TESTNET =
"4966625a4b2851d9fdee139e56211a0d88575f59ed816ff5e6a63deb4e3e29a0"; "4966625a4b2851d9fdee139e56211a0d88575f59ed816ff5e6a63deb4e3e29a0";
enum DerivePathType { bip44, bip49, bip84 }
bip32.BIP32 getBip32Node( bip32.BIP32 getBip32Node(
int chain, int chain,
int index, int index,

View file

@ -33,6 +33,7 @@ import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/default_nodes.dart'; import 'package:stackwallet/utilities/default_nodes.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart';
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
import 'package:stackwallet/utilities/format.dart'; import 'package:stackwallet/utilities/format.dart';
@ -50,8 +51,6 @@ const String GENESIS_HASH_MAINNET =
const String GENESIS_HASH_TESTNET = const String GENESIS_HASH_TESTNET =
"00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008"; "00000007199508e34a9ff81e6ec0c477a4cccff2a4767a8eee39c11db367b008";
enum DerivePathType { bip44, bip49, bip84 }
bip32.BIP32 getBip32Node( bip32.BIP32 getBip32Node(
int chain, int chain,
int index, int index,

View file

@ -32,6 +32,7 @@ import 'package:stackwallet/utilities/assets.dart';
import 'package:stackwallet/utilities/constants.dart'; import 'package:stackwallet/utilities/constants.dart';
import 'package:stackwallet/utilities/default_nodes.dart'; import 'package:stackwallet/utilities/default_nodes.dart';
import 'package:stackwallet/utilities/enums/coin_enum.dart'; import 'package:stackwallet/utilities/enums/coin_enum.dart';
import 'package:stackwallet/utilities/enums/derive_path_type_enum.dart';
import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart'; import 'package:stackwallet/utilities/enums/fee_rate_type_enum.dart';
import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart'; import 'package:stackwallet/utilities/flutter_secure_storage_interface.dart';
import 'package:stackwallet/utilities/format.dart'; import 'package:stackwallet/utilities/format.dart';
@ -48,8 +49,6 @@ const String GENESIS_HASH_MAINNET =
const String GENESIS_HASH_TESTNET = const String GENESIS_HASH_TESTNET =
"0000594ada5310b367443ee0afd4fa3d0bbd5850ea4e33cdc7d6a904a7ec7c90"; "0000594ada5310b367443ee0afd4fa3d0bbd5850ea4e33cdc7d6a904a7ec7c90";
enum DerivePathType { bip44, bip84 }
bip32.BIP32 getBip32Node( bip32.BIP32 getBip32Node(
int chain, int chain,
int index, int index,
@ -1407,6 +1406,8 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
address = P2WPKH(network: _network, data: data).data.address!; address = P2WPKH(network: _network, data: data).data.address!;
addrType = isar_models.AddressType.p2wpkh; addrType = isar_models.AddressType.p2wpkh;
break; break;
default:
throw Exception("Unsupported DerivePathType");
} }
// add generated address & info to derivations // add generated address & info to derivations
@ -1450,6 +1451,8 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
case DerivePathType.bip84: case DerivePathType.bip84:
type = isar_models.AddressType.p2wpkh; type = isar_models.AddressType.p2wpkh;
break; break;
default:
throw Exception("Unsupported DerivePathType");
} }
address = await db address = await db
.getAddresses(walletId) .getAddresses(walletId)
@ -1475,6 +1478,8 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
case DerivePathType.bip84: case DerivePathType.bip84:
key = "${walletId}_${chainId}DerivationsP2WPKH"; key = "${walletId}_${chainId}DerivationsP2WPKH";
break; break;
default:
throw Exception("Unsupported DerivePathType");
} }
return key; return key;
} }
@ -2743,6 +2748,8 @@ class ParticlWallet extends CoinServiceAPI with WalletCache, WalletDB {
case DerivePathType.bip84: case DerivePathType.bip84:
addressesP2WPKH.add(address); addressesP2WPKH.add(address);
break; break;
default:
throw Exception("Unsupported DerivePathType");
} }
} }
} }

View file

@ -0,0 +1 @@
enum DerivePathType { bip44, bip49, bip84 }