mirror of
https://github.com/cake-tech/cake_wallet.git
synced 2025-06-28 12:29:51 +00:00
Cw 565 sign messages (#1378)
* version bump to 3.13.9, auth working on mac * bump flutter version in workflow file * workflow fix * test fix * downgrade flutter version * test fix * test fix * update gradle version * start working on ui for message signing * updates * sign working for a few wallet types * updates & verification for electrum currencies * nano support * sign/verify working on eth, bitcoin broken * update translations * Implement Verify Message for Monero * save [skip ci] * pub key extraction working * fixes for electrum signing * verify working for solana! * electrum still not working :( [skip ci] * electrum messages working! * fixes for updated dart version, localization file updates * remove accidental inclusion * missed some unimplemented throws * Update res/values/strings_de.arb Co-authored-by: Konstantin Ullrich <konstantinullrich12@gmail.com> * Apply suggestions from code review Co-authored-by: Konstantin Ullrich <konstantinullrich12@gmail.com> * review suggestions and updates [skip ci] * [skip ci] add polygon * [skip ci] merge mac-auth/update version * fix litecoin * bio auth mac fix * remove comment and change duration from 2 to 0 * cherry pick previous changes * litecoin fixes, sign form fixes, use new walletAddressPicker * support accounts * verify messages working for monero * working sign and verify messages for nano * electrum signing working [skip ci] * additional nano fixes * update translations * attempt to decode signatures with base64 * workaround for secure storage bug on mac * bump version to 3.19.5 (because breez will need this version anyways) * some code cleanup * some changess didn't get saved * just documenting the issue [skip ci] * undo accidental removal + minor code cleanup * merge conflicts * merge fixes [skip ci] * add tron support * [wip] fixing * remove duplicate references to electrum path for maintainability * fixes * minor fix * fixes * undo debug comment * update migration for all electrum based wallets * hotfixes * copy over the rest of the fixes * minor code cleanup [skip ci] * updates * electrum signing workinggit statusgit statusgit statusgit status! * copy same fixes for litecoin * litecoin fixes * add v to litecoin signatures * fix dependencies * fix bitcoin_base version * merge fix * dep override * fix conflicts with main * trial fix for android build * fixes * fix * dep fix, should build * fix signing for bitcoin cash * [skip ci] minor code cleanup * [skip ci] minor code cleanup 2 * forgot wonero, various other fixes * more fixes * fix solana (untested) --------- Co-authored-by: Konstantin Ullrich <konstantinullrich12@gmail.com> Co-authored-by: Omar Hatem <omarh.ismail1@gmail.com>
This commit is contained in:
parent
eef319658a
commit
83ef61e928
65 changed files with 1479 additions and 271 deletions
|
@ -32,6 +32,8 @@ import 'package:shared_preferences/shared_preferences.dart';
|
|||
import 'package:solana/base58.dart';
|
||||
import 'package:solana/metaplex.dart' as metaplex;
|
||||
import 'package:solana/solana.dart';
|
||||
import 'package:solana/src/crypto/ed25519_hd_keypair.dart';
|
||||
import 'package:cryptography/cryptography.dart';
|
||||
|
||||
part 'solana_wallet.g.dart';
|
||||
|
||||
|
@ -571,17 +573,59 @@ abstract class SolanaWalletBase
|
|||
});
|
||||
}
|
||||
|
||||
Future<String> signSolanaMessage(String message) async {
|
||||
@override
|
||||
Future<String> signMessage(String message, {String? address}) async {
|
||||
// Convert the message to bytes
|
||||
final messageBytes = utf8.encode(message);
|
||||
|
||||
// Sign the message bytes with the wallet's private key
|
||||
final signature = await _walletKeyPair!.sign(messageBytes);
|
||||
final signature = (await _walletKeyPair!.sign(messageBytes)).toString();
|
||||
|
||||
// Convert the signature to a hexadecimal string
|
||||
final hex = HEX.encode(signature.bytes);
|
||||
return HEX.encode(utf8.encode(signature)).toUpperCase();
|
||||
}
|
||||
|
||||
return hex;
|
||||
List<List<int>> bytesFromSigString(String signatureString) {
|
||||
final regex = RegExp(r'Signature\(\[(.+)\], publicKey: (.+)\)');
|
||||
final match = regex.firstMatch(signatureString);
|
||||
|
||||
if (match != null) {
|
||||
final bytesString = match.group(1)!;
|
||||
final base58EncodedPublicKeyString = match.group(2)!;
|
||||
final sigBytes = bytesString.split(', ').map(int.parse).toList();
|
||||
|
||||
List<int> pubKeyBytes = base58decode(base58EncodedPublicKeyString);
|
||||
|
||||
return [sigBytes, pubKeyBytes];
|
||||
} else {
|
||||
throw const FormatException('Invalid Signature string format');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> verifyMessage(String message, String signature, {String? address}) async {
|
||||
String signatureString = utf8.decode(HEX.decode(signature));
|
||||
|
||||
List<List<int>> bytes = bytesFromSigString(signatureString);
|
||||
|
||||
final messageBytes = utf8.encode(message);
|
||||
final sigBytes = bytes[0];
|
||||
final pubKeyBytes = bytes[1];
|
||||
|
||||
if (address == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// make sure the address derived from the public key provided matches the one we expect
|
||||
final pub = Ed25519HDPublicKey(pubKeyBytes);
|
||||
if (address != pub.toBase58()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return await verifySignature(
|
||||
message: messageBytes,
|
||||
signature: sigBytes,
|
||||
publicKey: Ed25519HDPublicKey(pubKeyBytes),
|
||||
);
|
||||
}
|
||||
|
||||
SolanaClient? get solanaClient => _client.getSolanaClient;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue