diff --git a/cw_zano/lib/zano_wallet.dart b/cw_zano/lib/zano_wallet.dart index c5534f6c8..da253e3ae 100644 --- a/cw_zano/lib/zano_wallet.dart +++ b/cw_zano/lib/zano_wallet.dart @@ -59,9 +59,8 @@ abstract class ZanoWalletBase String get password => _password; @override - Future signMessage(String message, {String? address = null}) { - throw UnimplementedError(); - } + Future signMessage(String message, {String? address = null}) => + super.signMessage(message, address: address); @override Future verifyMessage(String message, String signature, {String? address = null}) { diff --git a/cw_zano/lib/zano_wallet_api.dart b/cw_zano/lib/zano_wallet_api.dart index f10e0b2d6..197690c08 100644 --- a/cw_zano/lib/zano_wallet_api.dart +++ b/cw_zano/lib/zano_wallet_api.dart @@ -401,6 +401,35 @@ mixin ZanoWalletApi { throw TransferException('Transfer error, empty result'); } + Future signMessage(String message, {String? address = null}) async { + try { + final messageBase64 = convert.base64.encode(convert.utf8.encode(message)); + final response = await invokeMethod('sign_message', {'buff': messageBase64}); + final responseData = convert.jsonDecode(response) as Map; + + if (responseData['error'] != null) { + printV('ZANO sign_message error: ${responseData['error']}'); + throw Exception('Zano sign_message failed: ${responseData['error']}'); + } + + final result = responseData['result'] as Map?; + if (result == null) { + throw Exception('Invalid response from sign_message'); + } + + final signature = result['sig'] as String?; + + if (signature == null) { + throw Exception('No signature in response'); + } + + return signature; + } catch (e) { + printV('ZANO signMessage error: $e'); + rethrow; + } + } + void _checkForErrors(Map? map) { if (map == null) { throw ZanoWalletException('Empty response'); @@ -510,4 +539,4 @@ Future _closeWallet(int hWallet) async { return str; } -Map> debugCallLength() => zano.debugCallLength; \ No newline at end of file +Map> debugCallLength() => zano.debugCallLength; diff --git a/lib/buy/dfx/dfx_buy_provider.dart b/lib/buy/dfx/dfx_buy_provider.dart index bef250f05..4dd6f1c68 100644 --- a/lib/buy/dfx/dfx_buy_provider.dart +++ b/lib/buy/dfx/dfx_buy_provider.dart @@ -62,9 +62,9 @@ class DFXBuyProvider extends BuyProvider { String get blockchain { switch (wallet.type) { case WalletType.bitcoin: - case WalletType.bitcoinCash: - case WalletType.litecoin: return 'Bitcoin'; + case WalletType.zano: + return 'Zano'; default: return walletTypeToString(wallet.type); } @@ -131,6 +131,7 @@ class DFXBuyProvider extends BuyProvider { case WalletType.litecoin: case WalletType.bitcoin: case WalletType.bitcoinCash: + case WalletType.zano: return await wallet.signMessage(message, address: walletAddress); default: throw Exception("WalletType is not available for DFX ${wallet.type}"); @@ -345,7 +346,7 @@ class DFXBuyProvider extends BuyProvider { 'asset-out': isBuyAction ? quote.cryptoCurrency.toString() : quote.fiatCurrency.toString(), 'blockchain': blockchain, 'asset-in': isBuyAction ? quote.fiatCurrency.toString() : quote.cryptoCurrency.toString(), - 'amount': amount.toString() //TODO: Amount does not work + 'amount-in': amount.toString() }); if (await canLaunchUrl(uri)) {