updates & verification for electrum currencies

This commit is contained in:
Matthew Fosse 2024-04-09 12:06:03 -07:00
parent 82dc036a18
commit ff0bdf8c7f
5 changed files with 35 additions and 2 deletions

View file

@ -1229,6 +1229,15 @@ abstract class ElectrumWalletBase
return base64Encode(HD.signMessage(message));
}
@override
Future<bool> verifyMessage(String message, String signature, {String? address = null}) async {
final index = address != null
? walletAddresses.allAddresses.firstWhere((element) => element.address == address).index
: null;
final HD = index == null ? hd : hd.derive(index);
return HD.verify(message: message, signature: base64Decode(signature));
}
static BasedUtxoNetwork _getNetwork(bitcoin.NetworkType networkType, CryptoCurrency? currency) {
if (networkType == bitcoin.bitcoin && currency == CryptoCurrency.bch) {
return BitcoinCashNetwork.mainnet;

View file

@ -175,4 +175,15 @@ abstract class BitcoinCashWalletBase extends ElectrumWallet with Store {
final HD = index == null ? hd : hd.derive(index);
return base64Encode(HD.signMessage(message));
}
@override
Future<bool> verifyMessage(String message, String signature, {String? address = null}) async {
final index = address != null
? walletAddresses.allAddresses
.firstWhere((element) => element.address == AddressUtils.toLegacyAddress(address))
.index
: null;
final HD = index == null ? hd : hd.derive(index);
return HD.verify(message: message, signature: base64Decode(signature));
}
}

View file

@ -67,7 +67,6 @@ abstract class WalletBase<BalanceType extends Balance, HistoryType extends Trans
int calculateEstimatedFee(TransactionPriority priority, int? amount);
// void fetchTransactionsAsync(
// void Function(TransactionType transaction) onTransactionLoaded,
// {void Function() onFinished});
@ -88,7 +87,11 @@ abstract class WalletBase<BalanceType extends Balance, HistoryType extends Trans
Future<void> renameWalletFiles(String newWalletName);
Future<String> signMessage(String message, {String? address = null}) => throw UnimplementedError();
Future<String> signMessage(String message, {String? address = null}) =>
throw UnimplementedError();
Future<bool> verifyMessage(String message, String signature, {String? address = null}) =>
throw UnimplementedError();
bool? isTestnet;
}

View file

@ -119,6 +119,11 @@ class EthereumWallet extends EVMChainWallet {
return EthereumTransactionHistory(walletInfo: walletInfo, password: password);
}
@override
Future<String> signMessage(String message, {String? address}) async {
throw UnimplementedError();
}
static Future<EthereumWallet> open(
{required String name, required String password, required WalletInfo walletInfo}) async {
final path = await pathForWallet(name: name, type: walletInfo.type);

View file

@ -527,5 +527,10 @@ abstract class SolanaWalletBase
return signSolanaMessage(message);
}
@override
Future<String> verifyMessage(String message, String signature, {String? address}) async {
throw UnimplementedError();
}
SolanaClient? get solanaClient => _client.getSolanaClient;
}