use bip39 for lightning seeds

This commit is contained in:
Matthew Fosse 2024-05-31 09:29:37 -07:00
parent 779b5eef9e
commit 8f9b325e1a
2 changed files with 10 additions and 5 deletions

View file

@ -116,7 +116,7 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
unspentCoinsInfo: unspentCoinsInfo,
initialAddresses: initialAddresses,
initialBalance: initialBalance,
seedBytes: await mnemonicToSeedBytes(mnemonic),
seedBytes: await Mnemonic.toSeed(mnemonic),
initialRegularAddressIndex: initialRegularAddressIndex,
initialChangeAddressIndex: initialChangeAddressIndex,
addressPageType: addressPageType,
@ -142,7 +142,7 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
unconfirmed: snp.balance.unconfirmed,
frozen: snp.balance.frozen,
),
seedBytes: await mnemonicToSeedBytes(snp.mnemonic!),
seedBytes: await Mnemonic.toSeed(snp.mnemonic!),
initialRegularAddressIndex: snp.regularAddressIndex,
initialChangeAddressIndex: snp.changeAddressIndex,
addressPageType: snp.addressPageType,
@ -169,7 +169,7 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
Future<void> renameWalletFiles(String newWalletName) async {
await stopBreez(true);
await super.renameWalletFiles(newWalletName);
await setupBreez(await mnemonicToSeedBytes(mnemonic));
await setupBreez(await Mnemonic.toSeed(mnemonic));
}
Future<void> setupBreez(Uint8List seedBytes) async {
@ -183,6 +183,10 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
return;
}
// sdk.logStream.listen((LogEntry event) {
// print("Breez log: ${event.line}");
// });
Uint8List deviceKey = base64.decode(secrets.greenlightKey);
Uint8List deviceCert = base64.decode(secrets.greenlightCert);
GreenlightCredentials greenlightCredentials = GreenlightCredentials(
@ -203,7 +207,7 @@ abstract class LightningWalletBase extends ElectrumWallet with Store {
);
String workingDir = await pathForWalletDir(name: walletInfo.name, type: type);
workingDir = "$workingDir/breez";
workingDir = "$workingDir/breez/";
new Directory(workingDir).createSync(recursive: true);
breezConfig = breezConfig.copyWith(workingDir: workingDir);

View file

@ -12,6 +12,7 @@ import 'package:cw_core/wallet_type.dart';
import 'package:cw_lightning/lightning_wallet.dart';
import 'package:hive/hive.dart';
import 'package:collection/collection.dart';
import 'package:bip39/bip39.dart' as bip39;
class LightningWalletService extends WalletService<
BitcoinNewWalletCredentials,
@ -29,7 +30,7 @@ class LightningWalletService extends WalletService<
@override
Future<LightningWallet> create(BitcoinNewWalletCredentials credentials, {bool? isTestnet}) async {
final wallet = await LightningWalletBase.create(
mnemonic: await generateElectrumMnemonic(),
mnemonic: bip39.generateMnemonic(),
password: credentials.password!,
walletInfo: credentials.walletInfo!,
unspentCoinsInfo: unspentCoinsInfoSource,