mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2024-12-23 03:59:23 +00:00
handle bip39 and electrum mnemonics
This commit is contained in:
parent
5e129ec6d2
commit
7f629f9f1b
1 changed files with 13 additions and 2 deletions
|
@ -27,6 +27,7 @@ import 'package:cw_bitcoin/bitcoin_wallet_addresses.dart';
|
||||||
import 'package:path_provider/path_provider.dart';
|
import 'package:path_provider/path_provider.dart';
|
||||||
import 'package:cw_lightning/.secrets.g.dart' as secrets;
|
import 'package:cw_lightning/.secrets.g.dart' as secrets;
|
||||||
import 'package:cw_bitcoin/electrum_wallet.dart';
|
import 'package:cw_bitcoin/electrum_wallet.dart';
|
||||||
|
import 'package:bip39/bip39.dart' as bip39;
|
||||||
|
|
||||||
part 'lightning_wallet.g.dart';
|
part 'lightning_wallet.g.dart';
|
||||||
|
|
||||||
|
@ -109,6 +110,16 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
|
||||||
LightningBalance? initialBalance,
|
LightningBalance? initialBalance,
|
||||||
Map<String, int>? initialRegularAddressIndex,
|
Map<String, int>? initialRegularAddressIndex,
|
||||||
Map<String, int>? initialChangeAddressIndex}) async {
|
Map<String, int>? initialChangeAddressIndex}) async {
|
||||||
|
late final Uint8List seedBytes;
|
||||||
|
// electrum:
|
||||||
|
if (validateMnemonic(mnemonic)) {
|
||||||
|
seedBytes = await bip39.mnemonicToSeed(mnemonic);
|
||||||
|
// bip39:
|
||||||
|
} else if (bip39.validateMnemonic(mnemonic)) {
|
||||||
|
seedBytes = await mnemonicToSeedBytes(mnemonic);
|
||||||
|
} else {
|
||||||
|
throw Exception("Invalid mnemonic!");
|
||||||
|
}
|
||||||
return LightningWallet(
|
return LightningWallet(
|
||||||
mnemonic: mnemonic,
|
mnemonic: mnemonic,
|
||||||
password: password,
|
password: password,
|
||||||
|
@ -116,7 +127,7 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
|
||||||
unspentCoinsInfo: unspentCoinsInfo,
|
unspentCoinsInfo: unspentCoinsInfo,
|
||||||
initialAddresses: initialAddresses,
|
initialAddresses: initialAddresses,
|
||||||
initialBalance: initialBalance,
|
initialBalance: initialBalance,
|
||||||
seedBytes: await Mnemonic.toSeed(mnemonic),
|
seedBytes: seedBytes,
|
||||||
initialRegularAddressIndex: initialRegularAddressIndex,
|
initialRegularAddressIndex: initialRegularAddressIndex,
|
||||||
initialChangeAddressIndex: initialChangeAddressIndex,
|
initialChangeAddressIndex: initialChangeAddressIndex,
|
||||||
addressPageType: addressPageType,
|
addressPageType: addressPageType,
|
||||||
|
|
Loading…
Reference in a new issue