Skip to content

Commit

Permalink
Merge pull request #1539 from bitmark-inc/fix_irl_sign_message
Browse files Browse the repository at this point in the history
fix: irl sign message: encode message
  • Loading branch information
phuocbitmark authored Feb 23, 2024
2 parents d4bcd50 + db1e3af commit 11d37f7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
18 changes: 12 additions & 6 deletions lib/screen/irl_screen/sign_message_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -146,12 +147,17 @@ class _IRLSignMessageScreenState extends State<IRLSignMessageScreen> {

@override
Widget build(BuildContext context) {
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;
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);

Expand Down
8 changes: 8 additions & 0 deletions lib/util/string_ext.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 11d37f7

Please sign in to comment.