mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-01-22 10:45:08 +00:00
Implement Verify Message for Monero
This commit is contained in:
parent
34631092a4
commit
04fccb8e7b
8 changed files with 45 additions and 2 deletions
|
@ -1022,13 +1022,18 @@ extern "C"
|
||||||
m_coins->thaw(index);
|
m_coins->thaw(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sign Messages //
|
// Sign & Verify Messages //
|
||||||
|
|
||||||
char *sign_message(char *message, char *address = "")
|
char *sign_message(char *message, char *address = "")
|
||||||
{
|
{
|
||||||
return strdup(get_current_wallet()->signMessage(std::string(message), std::string(address)).c_str());
|
return strdup(get_current_wallet()->signMessage(std::string(message), std::string(address)).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool verify_message(char *message, char *address, char *signature)
|
||||||
|
{
|
||||||
|
return get_current_wallet()->verifySignedMessage(std::string(message), std::string(address), std::string(signature));
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,7 +32,9 @@ void store(char *path);
|
||||||
|
|
||||||
void set_trusted_daemon(bool arg);
|
void set_trusted_daemon(bool arg);
|
||||||
bool trusted_daemon();
|
bool trusted_daemon();
|
||||||
|
|
||||||
char *sign_message(char *message, char *address);
|
char *sign_message(char *message, char *address);
|
||||||
|
bool verify_message(char *message, char *address, char *signature);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -151,3 +151,5 @@ typedef freeze_coin = Void Function(Int32 index);
|
||||||
typedef thaw_coin = Void Function(Int32 index);
|
typedef thaw_coin = Void Function(Int32 index);
|
||||||
|
|
||||||
typedef sign_message = Pointer<Utf8> Function(Pointer<Utf8> message, Pointer<Utf8> address);
|
typedef sign_message = Pointer<Utf8> Function(Pointer<Utf8> message, Pointer<Utf8> address);
|
||||||
|
|
||||||
|
typedef verify_message = Int8 Function(Pointer<Utf8> message, Pointer<Utf8> address, Pointer<Utf8> signature);
|
||||||
|
|
|
@ -151,3 +151,5 @@ typedef FreezeCoin = void Function(int);
|
||||||
typedef ThawCoin = void Function(int);
|
typedef ThawCoin = void Function(int);
|
||||||
|
|
||||||
typedef SignMessage = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Utf8>);
|
typedef SignMessage = Pointer<Utf8> Function(Pointer<Utf8>, Pointer<Utf8>);
|
||||||
|
|
||||||
|
typedef VerifyMessage = int Function(Pointer<Utf8>, Pointer<Utf8>, Pointer<Utf8>);
|
||||||
|
|
|
@ -131,6 +131,10 @@ final signMessageNative = moneroApi
|
||||||
.lookup<NativeFunction<sign_message>>('sign_message')
|
.lookup<NativeFunction<sign_message>>('sign_message')
|
||||||
.asFunction<SignMessage>();
|
.asFunction<SignMessage>();
|
||||||
|
|
||||||
|
final verifyMessageNative = moneroApi
|
||||||
|
.lookup<NativeFunction<verify_message>>('verify_message')
|
||||||
|
.asFunction<VerifyMessage>();
|
||||||
|
|
||||||
int getSyncingHeight() => getSyncingHeightNative();
|
int getSyncingHeight() => getSyncingHeightNative();
|
||||||
|
|
||||||
bool isNeededToRefresh() => isNeededToRefreshNative() != 0;
|
bool isNeededToRefresh() => isNeededToRefreshNative() != 0;
|
||||||
|
@ -397,3 +401,16 @@ String signMessage(String message, {String address = ""}) {
|
||||||
|
|
||||||
return signature;
|
return signature;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool verifyMessage(String message, String address, String signature) {
|
||||||
|
final messagePointer = message.toNativeUtf8();
|
||||||
|
final addressPointer = address.toNativeUtf8();
|
||||||
|
final signaturePointer = address.toNativeUtf8();
|
||||||
|
|
||||||
|
final isVerified = verifyMessageNative(messagePointer, addressPointer, signaturePointer);
|
||||||
|
calloc.free(messagePointer);
|
||||||
|
calloc.free(addressPointer);
|
||||||
|
calloc.free(signaturePointer);
|
||||||
|
|
||||||
|
return isVerified != 0;
|
||||||
|
}
|
||||||
|
|
|
@ -690,4 +690,12 @@ abstract class MoneroWalletBase
|
||||||
final useAddress = address ?? "";
|
final useAddress = address ?? "";
|
||||||
return monero_wallet.signMessage(message, address: useAddress);
|
return monero_wallet.signMessage(message, address: useAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<bool> verifyMessage(String message, String signature, {String? address = null}) async {
|
||||||
|
if (address == null) return false;
|
||||||
|
|
||||||
|
return monero_wallet.verifyMessage(message, address, signature);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1020,13 +1020,18 @@ extern "C"
|
||||||
m_coins->thaw(index);
|
m_coins->thaw(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sign Messages //
|
// Sign & Verify Messages //
|
||||||
|
|
||||||
char *sign_message(char *message, char *address = "")
|
char *sign_message(char *message, char *address = "")
|
||||||
{
|
{
|
||||||
return strdup(get_current_wallet()->signMessage(std::string(message), std::string(address)).c_str());
|
return strdup(get_current_wallet()->signMessage(std::string(message), std::string(address)).c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool verify_message(char *message, char *address, char *signature)
|
||||||
|
{
|
||||||
|
return get_current_wallet()->verifySignedMessage(std::string(message), std::string(address), std::string(verifySignedMessage));
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -32,7 +32,9 @@ void store(char *path);
|
||||||
|
|
||||||
void set_trusted_daemon(bool arg);
|
void set_trusted_daemon(bool arg);
|
||||||
bool trusted_daemon();
|
bool trusted_daemon();
|
||||||
|
|
||||||
char *sign_message(char *message, char *address);
|
char *sign_message(char *message, char *address);
|
||||||
|
bool verify_message(char *message, char *address, char *signature);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue