Skip to content

Commit

Permalink
fix: Eth sign message not work for normal messages (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
ciripel authored Nov 3, 2022
1 parent 332a771 commit 7244fa7
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 1.1.8
* Fix Eth sign normal messages (not converted already to hex by the Dapp)
## 1.1.7
* Add supported network check
## 1.1.6
Expand Down
16 changes: 16 additions & 0 deletions example/integration_tests/on_emulator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,14 @@ void main() {
),
equals(
'0xce929bf4483308f0e23752d43cb45def3bfafefdaba1b328d8121969ac303fd955acc4dd5520f585ee3691e04e0917f99360fa24a8280805ff25aa879fb83ae81c'));
expect(
EthSign.message(
wallet: wallet,
networkId: TWCoinType.TWCoinTypeEthereum,
message: 'We are Simplio!',
),
equals(
'0xc925dc32a276bb6e4089bc161022f6a25819c29a31cf36fdcbcb489dba6f0e5105d77f17a021322f7cfa224a1f962929ff626396d886dd7d0af0bee946d1278d1b'));
});
test('Test personalMessage return correct signature', () {
expect(
Expand All @@ -1628,6 +1636,14 @@ void main() {
),
equals(
'0x2913768a701ea3bea19b5d61d4b70758bf6b805869dea9425edc18e2efa2aa5c61add9bef273d29b4633972a1f35cc5efec23d7c8aeab358efedc2024d555bb01b'));
expect(
EthSign.personalMessage(
wallet: wallet,
networkId: TWCoinType.TWCoinTypeEthereum,
message: 'We are Simplio!',
),
equals(
'0x6ac9dd87d1c807a5f69c7fb4b72992a25cf2eafcd2063ceda8b273950e43a95533219e419a0a9201691da1fc128716d282e83c6e9c1bcf3a453805ce628215701b'));
});
});
}
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ packages:
path: ".."
relative: true
source: path
version: "1.1.7"
version: "1.1.8"
sky_engine:
dependency: transitive
description: flutter
Expand Down
13 changes: 11 additions & 2 deletions lib/src/signing.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:typed_data';

import 'package:convert/convert.dart';
Expand Down Expand Up @@ -35,10 +36,14 @@ class EthSign {
required int networkId,
required String message,
}) {
String hexMessage = message;
if (message.substring(0, 2) != '0x') {
hexMessage = '0x${hex.encode(utf8.encode(message))}';
}
return EthSigUtil.signMessage(
privateKeyInBytes: wallet.getKeyForCoin(networkId).data(),
message: Uint8List.fromList(hex.decode(
message.substring(2, message.length),
hexMessage.substring(2),
)),
);
}
Expand All @@ -48,10 +53,14 @@ class EthSign {
required int networkId,
required String message,
}) {
String hexMessage = message;
if (message.substring(0, 2) != '0x') {
hexMessage = '0x${hex.encode(utf8.encode(message))}';
}
return EthSigUtil.signPersonalMessage(
privateKeyInBytes: wallet.getKeyForCoin(networkId).data(),
message: Uint8List.fromList(hex.decode(
message.substring(2, message.length),
hexMessage.substring(2),
)),
);
}
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: sio_core_light
description: Simplio wallet core library for building blockchain transactions, developed in Dart, can be used in Flutter framework.
version: 1.1.7
version: 1.1.8
repository: https://github.com/SimplioOfficial/sio_core_light

environment:
Expand Down

0 comments on commit 7244fa7

Please sign in to comment.