electrum updates (#1449)

* hotfixes

* copy over the rest of the fixes

* use hardened derivation path everywhere

* correct balance path for electrum

* revert index nullability and correct balance path for all cases

* only save wallet info if we changed it
This commit is contained in:
Matthew Fosse 2024-06-18 07:08:03 +02:00 committed by GitHub
parent fc2c9a2bcc
commit 591342ec6a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 66 additions and 46 deletions

View file

@ -5,58 +5,64 @@ import 'package:bitcoin_flutter/bitcoin_flutter.dart' as bitcoin;
import 'package:bitcoin_flutter/src/payments/index.dart' show PaymentData;
import 'package:hex/hex.dart';
bitcoin.PaymentData generatePaymentData({required bitcoin.HDWallet hd, int? index}) {
final pubKey = index != null ? hd.derive(index).pubKey! : hd.pubKey!;
bitcoin.PaymentData generatePaymentData({
required bitcoin.HDWallet hd,
required int index,
}) {
final pubKey = hd.derive(index).pubKey!;
return PaymentData(pubkey: Uint8List.fromList(HEX.decode(pubKey)));
}
ECPrivate generateECPrivate(
{required bitcoin.HDWallet hd, required BasedUtxoNetwork network, int? index}) {
final wif = index != null ? hd.derive(index).wif! : hd.wif!;
ECPrivate generateECPrivate({
required bitcoin.HDWallet hd,
required BasedUtxoNetwork network,
required int index,
}) {
final wif = hd.derive(index).wif!;
return ECPrivate.fromWif(wif, netVersion: network.wifNetVer);
}
String generateP2WPKHAddress({
required bitcoin.HDWallet hd,
required BasedUtxoNetwork network,
int? index,
required int index,
}) {
final pubKey = index != null ? hd.derive(index).pubKey! : hd.pubKey!;
final pubKey = hd.derive(index).pubKey!;
return ECPublic.fromHex(pubKey).toP2wpkhAddress().toAddress(network);
}
String generateP2SHAddress({
required bitcoin.HDWallet hd,
required BasedUtxoNetwork network,
int? index,
required int index,
}) {
final pubKey = index != null ? hd.derive(index).pubKey! : hd.pubKey!;
final pubKey = hd.derive(index).pubKey!;
return ECPublic.fromHex(pubKey).toP2wpkhInP2sh().toAddress(network);
}
String generateP2WSHAddress({
required bitcoin.HDWallet hd,
required BasedUtxoNetwork network,
int? index,
required int index,
}) {
final pubKey = index != null ? hd.derive(index).pubKey! : hd.pubKey!;
final pubKey = hd.derive(index).pubKey!;
return ECPublic.fromHex(pubKey).toP2wshAddress().toAddress(network);
}
String generateP2PKHAddress({
required bitcoin.HDWallet hd,
required BasedUtxoNetwork network,
int? index,
required int index,
}) {
final pubKey = index != null ? hd.derive(index).pubKey! : hd.pubKey!;
final pubKey = hd.derive(index).pubKey!;
return ECPublic.fromHex(pubKey).toP2pkhAddress().toAddress(network);
}
String generateP2TRAddress({
required bitcoin.HDWallet hd,
required BasedUtxoNetwork network,
int? index,
required int index,
}) {
final pubKey = index != null ? hd.derive(index).pubKey! : hd.pubKey!;
final pubKey = hd.derive(index).pubKey!;
return ECPublic.fromHex(pubKey).toTaprootAddress().toAddress(network);
}