From c4c679e55ec26d0e75aa19d80bcdced4ef8ebecf Mon Sep 17 00:00:00 2001 From: phuoc Date: Thu, 22 Feb 2024 17:38:54 +0700 Subject: [PATCH 1/2] fix: irl sign message: encode message Signed-off-by: phuoc --- lib/screen/irl_screen/sign_message_screen.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/screen/irl_screen/sign_message_screen.dart b/lib/screen/irl_screen/sign_message_screen.dart index d1cd92eac..66285a8ca 100644 --- a/lib/screen/irl_screen/sign_message_screen.dart +++ b/lib/screen/irl_screen/sign_message_screen.dart @@ -146,7 +146,7 @@ class _IRLSignMessageScreenState extends State { @override Widget build(BuildContext context) { - final message = hexToBytes(widget.payload.payload); + final message = Uint8List.fromList(utf8.encode(widget.payload.payload)); final Uint8List viewMessage = message.length > 6 && message.sublist(0, 2).equals(Uint8List.fromList([5, 1])) ? message.sublist(6) From db1e3afb48a294a1f07a7f34e82208b14551c9c6 Mon Sep 17 00:00:00 2001 From: phuoc Date: Fri, 23 Feb 2024 09:54:19 +0700 Subject: [PATCH 2/2] fix: handle both text and hex string Signed-off-by: phuoc --- lib/screen/irl_screen/sign_message_screen.dart | 18 ++++++++++++------ lib/util/string_ext.dart | 8 ++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/lib/screen/irl_screen/sign_message_screen.dart b/lib/screen/irl_screen/sign_message_screen.dart index 66285a8ca..9f2a6ae7d 100644 --- a/lib/screen/irl_screen/sign_message_screen.dart +++ b/lib/screen/irl_screen/sign_message_screen.dart @@ -8,6 +8,7 @@ import 'package:autonomy_flutter/service/configuration_service.dart'; import 'package:autonomy_flutter/service/local_auth_service.dart'; import 'package:autonomy_flutter/util/debouce_util.dart'; import 'package:autonomy_flutter/util/inapp_notifications.dart'; +import 'package:autonomy_flutter/util/string_ext.dart'; import 'package:autonomy_flutter/util/style.dart'; import 'package:autonomy_flutter/util/wallet_storage_ext.dart'; import 'package:autonomy_flutter/view/back_appbar.dart'; @@ -146,12 +147,17 @@ class _IRLSignMessageScreenState extends State { @override Widget build(BuildContext context) { - final message = Uint8List.fromList(utf8.encode(widget.payload.payload)); - final Uint8List viewMessage = message.length > 6 && - message.sublist(0, 2).equals(Uint8List.fromList([5, 1])) - ? message.sublist(6) - : message; - final messageInUtf8 = utf8.decode(viewMessage, allowMalformed: true); + late String messageInUtf8; + if (widget.payload.payload.isHex) { + final message = hexToBytes(widget.payload.payload); + final Uint8List viewMessage = message.length > 6 && + message.sublist(0, 2).equals(Uint8List.fromList([5, 1])) + ? message.sublist(6) + : message; + messageInUtf8 = utf8.decode(viewMessage, allowMalformed: true); + } else { + messageInUtf8 = widget.payload.payload; + } final theme = Theme.of(context); diff --git a/lib/util/string_ext.dart b/lib/util/string_ext.dart index dc32892b1..9a9a9b263 100644 --- a/lib/util/string_ext.dart +++ b/lib/util/string_ext.dart @@ -148,4 +148,12 @@ extension StringExtension on String { } String get hexToDecimal => BigInt.parse(this, radix: 16).toString(); + + bool get isHex { + String hexString = this; + if (hexString.startsWith('0x')) { + hexString = hexString.substring(2); + } + return RegExp(r'^[0-9a-fA-F]+$').hasMatch(hexString); + } }