Skip to content

Commit

Permalink
minor change
Browse files Browse the repository at this point in the history
  • Loading branch information
quetool committed Mar 4, 2024
1 parent 86ddbc9 commit 57e27f8
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 25 deletions.
10 changes: 9 additions & 1 deletion example/dapp/lib/utils/crypto/eip155.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import 'dart:convert';
// ignore: depend_on_referenced_packages
import 'package:convert/convert.dart';

import 'package:flutter/foundation.dart';

import 'package:intl/intl.dart';
import 'package:walletconnect_flutter_v2/walletconnect_flutter_v2.dart';
Expand Down Expand Up @@ -161,12 +165,16 @@ class EIP155 {
required String address,
required String message,
}) async {
final bytes = utf8.encode(message);
final encoded = '0x${hex.encode(bytes)}';
debugPrint('personalSign $encoded');

return await web3App.request(
topic: topic,
chainId: chainId,
request: SessionRequestParams(
method: methods[EIP155Methods.personalSign]!,
params: [message, address],
params: [encoded, address],
),
);
}
Expand Down
6 changes: 4 additions & 2 deletions example/wallet/lib/dependencies/bip39/bip39_base.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@ Uint8List _randomBytes(int size) {
return bytes;
}

String generateMnemonic(
{int strength = 128, RandomBytes randomBytes = _randomBytes}) {
String generateMnemonic({
int strength = 128,
RandomBytes randomBytes = _randomBytes,
}) {
assert(strength % 32 == 0);
final entropy = randomBytes(strength ~/ 8);
return entropyToMnemonic(hex.encode(entropy));
Expand Down
21 changes: 8 additions & 13 deletions example/wallet/lib/dependencies/chains/evm_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'dart:convert';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
// ignore: depend_on_referenced_packages
import 'package:http/http.dart' as http;
Expand Down Expand Up @@ -93,15 +92,13 @@ class EVMService {
final keys = GetIt.I<IKeyService>().getKeysForChain(
chainSupported.chainId,
);
final credentials = EthPrivateKey.fromHex(keys[0].privateKey);

final signature = hex.encode(
credentials.signPersonalMessageToUint8List(
Uint8List.fromList(utf8.encode(message)),
),
final signature = EthSigUtil.signPersonalMessage(
privateKey: keys[0].privateKey,
message: utf8.encode(message),
);

response = response.copyWith(result: '0x$signature');
response = response.copyWith(result: signature);
} catch (e) {
debugPrint('[$runtimeType] personalSign error $e');
response = response.copyWith(
Expand Down Expand Up @@ -138,15 +135,13 @@ class EVMService {
final keys = GetIt.I<IKeyService>().getKeysForChain(
chainSupported.chainId,
);
final credentials = EthPrivateKey.fromHex(keys[0].privateKey);

final signature = hex.encode(
credentials.signPersonalMessageToUint8List(
Uint8List.fromList(utf8.encode(message)),
),
final signature = EthSigUtil.signPersonalMessage(
privateKey: keys[0].privateKey,
message: utf8.encode(message),
);

response = response.copyWith(result: '0x$signature');
response = response.copyWith(result: signature);
} catch (e) {
debugPrint('[$runtimeType] ethSign error $e');
response = response.copyWith(
Expand Down
12 changes: 3 additions & 9 deletions lib/apis/auth_api/utils/auth_signature.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ class AuthSignature {
// Get the sig bytes
// print(sig);
final sigBytes = Uint8List.fromList(
hex.decode(
sig.substring(2),
),
hex.decode(sig.substring(2)),
);

// If the sig bytes aren't 65 bytes long, throw an error
Expand All @@ -60,15 +58,11 @@ class AuthSignature {

// Get the r and s values from the sig bytes
final r = BigInt.parse(
hex.encode(
sigBytes.sublist(0, 32),
),
hex.encode(sigBytes.sublist(0, 32)),
radix: 16,
);
final s = BigInt.parse(
hex.encode(
sigBytes.sublist(32, 64),
),
hex.encode(sigBytes.sublist(32, 64)),
radix: 16,
);
// print(sigBytes[64]);
Expand Down

0 comments on commit 57e27f8

Please sign in to comment.