Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
quetool committed Aug 5, 2024
1 parent b1fd26d commit bd78944
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 50 deletions.
2 changes: 1 addition & 1 deletion example/wallet/lib/dependencies/chains/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class CommonMethods {
);
}
} catch (e) {
debugPrint('[WALLET] ${e.toString()}');
debugPrint('[SampleWallet] ${e.toString()}');
}
}

Expand Down
4 changes: 2 additions & 2 deletions example/wallet/lib/dependencies/chains/cosmos_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class CosmosService {
}

Future<void> cosmosSignDirect(String topic, dynamic parameters) async {
debugPrint('[WALLET] cosmosSignDirect request: $parameters');
debugPrint('[SampleWallet] cosmosSignDirect request: $parameters');
final pRequest = _web3Wallet.pendingRequests.getAll().last;
final response = JsonRpcResponse(
id: pRequest.id,
Expand All @@ -45,7 +45,7 @@ class CosmosService {
}

Future<void> cosmosSignAmino(String topic, dynamic parameters) async {
debugPrint('[WALLET] cosmosSignAmino request: $parameters');
debugPrint('[SampleWallet] cosmosSignAmino request: $parameters');
final pRequest = _web3Wallet.pendingRequests.getAll().last;
final response = JsonRpcResponse(
id: pRequest.id,
Expand Down
46 changes: 22 additions & 24 deletions example/wallet/lib/dependencies/chains/evm_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class EVMService {

// personal_sign is handled using onSessionRequest event for demo purposes
Future<void> personalSign(String topic, dynamic parameters) async {
debugPrint('[WALLET] personalSign request: $parameters');
debugPrint('[SampleWallet] personalSign request: $parameters');
final SessionRequest pRequest = _web3Wallet.pendingRequests.getAll().last;
final address = EthUtils.getAddressFromSessionRequest(pRequest);
final data = EthUtils.getDataFromSessionRequest(pRequest);
Expand Down Expand Up @@ -129,7 +129,7 @@ class EVMService {

response = response.copyWith(result: signedTx);
} catch (e) {
debugPrint('[WALLET] personalSign error $e');
debugPrint('[SampleWallet] personalSign error $e');
response = response.copyWith(
error: JsonRpcError(code: 0, message: e.toString()),
);
Expand All @@ -149,7 +149,7 @@ class EVMService {
}

Future<void> ethSign(String topic, dynamic parameters) async {
debugPrint('[WALLET] ethSign request: $parameters');
debugPrint('[SampleWallet] ethSign request: $parameters');
final pRequest = _web3Wallet.pendingRequests.getAll().last;
final data = EthUtils.getDataFromSessionRequest(pRequest);
final message = EthUtils.getUtf8Message(data.toString());
Expand All @@ -176,7 +176,7 @@ class EVMService {

response = response.copyWith(result: signedTx);
} catch (e) {
debugPrint('[WALLET] ethSign error $e');
debugPrint('[SampleWallet] ethSign error $e');
response = response.copyWith(
error: JsonRpcError(code: 0, message: e.toString()),
);
Expand All @@ -196,7 +196,7 @@ class EVMService {
}

Future<void> ethSignTypedData(String topic, dynamic parameters) async {
debugPrint('[WALLET] ethSignTypedData request: $parameters');
debugPrint('[SampleWallet] ethSignTypedData request: $parameters');
final pRequest = _web3Wallet.pendingRequests.getAll().last;
final data = EthUtils.getDataFromSessionRequest(pRequest);
var response = JsonRpcResponse(
Expand All @@ -218,7 +218,7 @@ class EVMService {

response = response.copyWith(result: signature);
} catch (e) {
debugPrint('[WALLET] ethSignTypedData error $e');
debugPrint('[SampleWallet] ethSignTypedData error $e');
response = response.copyWith(
error: JsonRpcError(code: 0, message: e.toString()),
);
Expand All @@ -238,7 +238,7 @@ class EVMService {
}

Future<void> ethSignTypedDataV4(String topic, dynamic parameters) async {
debugPrint('[WALLET] ethSignTypedDataV4 request: $parameters');
debugPrint('[SampleWallet] ethSignTypedDataV4 request: $parameters');
final pRequest = _web3Wallet.pendingRequests.getAll().last;
final data = EthUtils.getDataFromSessionRequest(pRequest);
var response = JsonRpcResponse(
Expand All @@ -260,7 +260,7 @@ class EVMService {

response = response.copyWith(result: signature);
} catch (e) {
debugPrint('[WALLET] ethSignTypedDataV4 error $e');
debugPrint('[SampleWallet] ethSignTypedDataV4 error $e');
response = response.copyWith(
error: JsonRpcError(code: 0, message: e.toString()),
);
Expand All @@ -280,7 +280,7 @@ class EVMService {
}

Future<void> ethSignTransaction(String topic, dynamic parameters) async {
debugPrint('[WALLET] ethSignTransaction request: $parameters');
debugPrint('[SampleWallet] ethSignTransaction request: $parameters');
final SessionRequest pRequest = _web3Wallet.pendingRequests.getAll().last;

final data = EthUtils.getTransactionFromSessionRequest(pRequest);
Expand Down Expand Up @@ -317,12 +317,12 @@ class EVMService {

response = response.copyWith(result: signedTx);
} on RPCError catch (e) {
debugPrint('[WALLET] ethSignTransaction error $e');
debugPrint('[SampleWallet] ethSignTransaction error $e');
response = response.copyWith(
error: JsonRpcError(code: e.errorCode, message: e.message),
);
} catch (e) {
debugPrint('[WALLET] ethSignTransaction error $e');
debugPrint('[SampleWallet] ethSignTransaction error $e');
response = response.copyWith(
error: JsonRpcError(code: 0, message: e.toString()),
);
Expand All @@ -340,7 +340,7 @@ class EVMService {
}

Future<void> ethSendTransaction(String topic, dynamic parameters) async {
debugPrint('[WALLET] ethSendTransaction request: $parameters');
debugPrint('[SampleWallet] ethSendTransaction request: $parameters');
final SessionRequest pRequest = _web3Wallet.pendingRequests.getAll().last;

final data = EthUtils.getTransactionFromSessionRequest(pRequest);
Expand Down Expand Up @@ -375,12 +375,12 @@ class EVMService {

response = response.copyWith(result: signedTx);
} on RPCError catch (e) {
debugPrint('[WALLET] ethSendTransaction error $e');
debugPrint('[SampleWallet] ethSendTransaction error $e');
response = response.copyWith(
error: JsonRpcError(code: e.errorCode, message: e.message),
);
} catch (e) {
debugPrint('[WALLET] ethSendTransaction error $e');
debugPrint('[SampleWallet] ethSendTransaction error $e');
response = response.copyWith(
error: JsonRpcError(code: 0, message: e.toString()),
);
Expand All @@ -398,7 +398,7 @@ class EVMService {
}

Future<void> switchChain(String topic, dynamic parameters) async {
debugPrint('[WALLET] switchChain request: $topic $parameters');
debugPrint('[SampleWallet] switchChain request: $topic $parameters');
final pRequest = _web3Wallet.pendingRequests.getAll().last;
var response = JsonRpcResponse(id: pRequest.id, jsonrpc: '2.0');
try {
Expand All @@ -415,12 +415,12 @@ class EVMService {
);
response = response.copyWith(result: true);
} on WalletConnectError catch (e) {
debugPrint('[WALLET] switchChain error $e');
debugPrint('[SampleWallet] switchChain error $e');
response = response.copyWith(
error: JsonRpcError(code: e.code, message: e.message),
);
} catch (e) {
debugPrint('[WALLET] switchChain error $e');
debugPrint('[SampleWallet] switchChain error $e');
response = response.copyWith(
error: JsonRpcError(code: 0, message: e.toString()),
);
Expand All @@ -435,7 +435,6 @@ class EVMService {
}

// Future<void> addChain(String topic, dynamic parameters) async {
// debugPrint('[WALLET] addChain request: $topic $parameters');
// final pRequest = _web3Wallet.pendingRequests.getAll().last;
// await _web3Wallet.respondSessionRequest(
// topic: topic,
Expand Down Expand Up @@ -537,7 +536,7 @@ class EVMService {

void _onSessionRequest(SessionRequestEvent? args) async {
if (args != null && args.chainId == chainSupported.chainId) {
debugPrint('[WALLET] _onSessionRequest ${args.toString()}');
debugPrint('[SampleWallet] _onSessionRequest ${args.toString()}');
final handler = sessionRequestHandlers[args.method];
if (handler != null) {
await handler(args.topic, args.params);
Expand All @@ -551,24 +550,23 @@ class EVMService {
String hexAddress,
) {
try {
debugPrint('isValidSignature(): $hexSignature, $message, $hexAddress');
debugPrint(
'[SampleWallet] isValidSignature: $hexSignature, $message, $hexAddress');
final recoveredAddress = EthSigUtil.recoverPersonalSignature(
signature: hexSignature,
message: utf8.encode(message),
);
debugPrint('recoveredAddress: $recoveredAddress');
debugPrint('[SampleWallet] recoveredAddress: $recoveredAddress');

final recoveredAddress2 = EthSigUtil.recoverSignature(
signature: hexSignature,
message: utf8.encode(message),
);
debugPrint('recoveredAddress2: $recoveredAddress2');
debugPrint('[SampleWallet] recoveredAddress2: $recoveredAddress2');

final isValid = recoveredAddress == hexAddress;
debugPrint('isValidSignature: $isValid');
return isValid;
} catch (e) {
debugPrint('isValidSignature() error, $e');
return false;
}
}
Expand Down
16 changes: 9 additions & 7 deletions example/wallet/lib/dependencies/chains/kadena_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class KadenaService {
}

Future<void> kadenaGetAccountsV1(String topic, dynamic parameters) async {
debugPrint('[WALLET] kadenaGetAccountsV1 request: $parameters');
debugPrint('[SampleWallet] kadenaGetAccountsV1 request: $parameters');
final pRequest = _web3Wallet.pendingRequests.getAll().last;
var response = JsonRpcResponse(
id: pRequest.id,
Expand Down Expand Up @@ -89,7 +89,7 @@ class KadenaService {
).toJson(),
);
} catch (e) {
debugPrint('[WALLET] kadenaGetAccountsV1 error: $e');
debugPrint('[SampleWallet] kadenaGetAccountsV1 error: $e');
response = response.copyWith(
error: JsonRpcError(code: 0, message: e.toString()),
);
Expand All @@ -104,7 +104,8 @@ class KadenaService {
}

Future<void> kadenaSignV1(String topic, dynamic parameters) async {
debugPrint('[WALLET] kadenaSignV1 request: ${jsonEncode(parameters)}');
debugPrint(
'[SampleWallet] kadenaSignV1 request: ${jsonEncode(parameters)}');
final pRequest = _web3Wallet.pendingRequests.getAll().last;
var response = JsonRpcResponse(
id: pRequest.id,
Expand Down Expand Up @@ -156,7 +157,7 @@ class KadenaService {
);
}
} catch (e) {
debugPrint('[WALLET] kadenaSignV1 error: $e');
debugPrint('[SampleWallet] kadenaSignV1 error: $e');
response = response.copyWith(
error: JsonRpcError(code: 0, message: e.toString()),
);
Expand All @@ -171,7 +172,8 @@ class KadenaService {
}

Future<void> kadenaQuicksignV1(String topic, dynamic parameters) async {
debugPrint('[WALLET] kadenaQuicksignV1 request: ${jsonEncode(parameters)}');
debugPrint(
'[SampleWallet] kadenaQuicksignV1 request: ${jsonEncode(parameters)}');
final pRequest = _web3Wallet.pendingRequests.getAll().last;
var response = JsonRpcResponse(
id: pRequest.id,
Expand Down Expand Up @@ -242,7 +244,7 @@ class KadenaService {
);
}
} catch (e) {
debugPrint('[WALLET] kadenaSignV1 error: $e');
debugPrint('[SampleWallet] kadenaSignV1 error: $e');
response = response.copyWith(
error: JsonRpcError(code: 0, message: e.toString()),
);
Expand All @@ -258,7 +260,7 @@ class KadenaService {

void _onSessionRequest(SessionRequestEvent? args) async {
if (args != null && args.chainId == chainSupported.chainId) {
debugPrint('[WALLET] _onSessionRequest ${args.toString()}');
debugPrint('[SampleWallet] _onSessionRequest ${args.toString()}');
final handler = kadenaRequestHandlers[args.method];
if (handler != null) {
await handler(args.topic, args.params);
Expand Down
13 changes: 7 additions & 6 deletions example/wallet/lib/dependencies/chains/polkadot_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class PolkadotService {
}

Future<void> polkadotSignMessage(String topic, dynamic parameters) async {
debugPrint('[WALLET] polkadotSignMessage: $parameters');
debugPrint('[SampleWallet] polkadotSignMessage: $parameters');
const method = 'polkadot_signMessage';
final pRequest = _web3Wallet.pendingRequests.getAll().last;
var response = JsonRpcResponse(
Expand All @@ -55,7 +55,7 @@ class PolkadotService {
try {
final params = parameters as Map<String, dynamic>;
final message = params['message'].toString();
debugPrint('[WALLET] polkadotSignMessage message: $message');
debugPrint('[SampleWallet] polkadotSignMessage message: $message');

// code
final keys = GetIt.I<IKeyService>().getKeysForChain(
Expand Down Expand Up @@ -86,7 +86,7 @@ class PolkadotService {
);
}
} catch (e) {
debugPrint('[WALLET] polkadotSignMessage error $e');
debugPrint('[SampleWallet] polkadotSignMessage error $e');
response = response.copyWith(
error: JsonRpcError(code: 0, message: e.toString()),
);
Expand All @@ -101,7 +101,8 @@ class PolkadotService {
}

Future<void> polkadotSignTransaction(String topic, dynamic parameters) async {
debugPrint('[WALLET] polkadotSignTransaction: ${jsonEncode(parameters)}');
debugPrint(
'[SampleWallet] polkadotSignTransaction: ${jsonEncode(parameters)}');
const method = 'polkadot_signTransaction';
final pRequest = _web3Wallet.pendingRequests.getAll().last;
var response = JsonRpcResponse(
Expand Down Expand Up @@ -144,7 +145,7 @@ class PolkadotService {
},
);
} catch (e) {
debugPrint('[WALLET] polkadotSignTransaction error $e');
debugPrint('[SampleWallet] polkadotSignTransaction error $e');
response = response.copyWith(
error: JsonRpcError(code: 0, message: e.toString()),
);
Expand All @@ -165,7 +166,7 @@ class PolkadotService {

void _onSessionRequest(SessionRequestEvent? args) async {
if (args != null && args.chainId == chainSupported.chainId) {
debugPrint('[WALLET] _onSessionRequest ${args.toString()}');
debugPrint('[SampleWallet] _onSessionRequest ${args.toString()}');
final handler = polkadotRequestHandlers[args.method];
if (handler != null) {
await handler(args.topic, args.params);
Expand Down
9 changes: 5 additions & 4 deletions example/wallet/lib/dependencies/chains/solana_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SolanaService {
}

Future<void> solanaSignMessage(String topic, dynamic parameters) async {
debugPrint('[WALLET] solanaSignMessage request: $parameters');
debugPrint('[SampleWallet] solanaSignMessage request: $parameters');
const method = 'solana_signMessage';
final pRequest = _web3Wallet.pendingRequests.getAll().last;
var response = JsonRpcResponse(id: pRequest.id, jsonrpc: '2.0');
Expand Down Expand Up @@ -71,7 +71,7 @@ class SolanaService {
}
//
} catch (e) {
debugPrint('[WALLET] polkadotSignMessage error $e');
debugPrint('[SampleWallet] polkadotSignMessage error $e');
response = response.copyWith(
error: JsonRpcError(code: 0, message: e.toString()),
);
Expand All @@ -86,7 +86,8 @@ class SolanaService {
}

Future<void> solanaSignTransaction(String topic, dynamic parameters) async {
debugPrint('[WALLET] solanaSignTransaction: ${jsonEncode(parameters)}');
debugPrint(
'[SampleWallet] solanaSignTransaction: ${jsonEncode(parameters)}');
const method = 'solana_signTransaction';
final pRequest = _web3Wallet.pendingRequests.getAll().last;
var response = JsonRpcResponse(id: pRequest.id, jsonrpc: '2.0');
Expand Down Expand Up @@ -137,7 +138,7 @@ class SolanaService {
);
}
} catch (e) {
debugPrint('[WALLET] solanaSignTransaction error $e');
debugPrint('[SampleWallet] solanaSignTransaction error $e');
response = response.copyWith(
error: JsonRpcError(code: 0, message: e.toString()),
);
Expand Down
9 changes: 5 additions & 4 deletions example/wallet/lib/dependencies/key_service/key_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class KeyService extends IKeyService {
publicKey: keyPair.publicKey,
address: address,
);
debugPrint('[WALLET] evmChainKey ${evmChainKey.toString()}');
debugPrint('[SampleWallet] evmChainKey ${evmChainKey.toString()}');
return evmChainKey;
}

Expand All @@ -129,11 +129,12 @@ class KeyService extends IKeyService {
Future<List<ChainKey>> _extraKeyPairs() async {
// HARDCODED VALUES
final kadenaChainKey = _kadenaKeyPair();
debugPrint('[WALLET] kadenaChainKey ${kadenaChainKey.toString()}');
debugPrint('[SampleWallet] kadenaChainKey ${kadenaChainKey.toString()}');
final polkadotChainKey = _polkadotKeyPair();
debugPrint('[WALLET] polkadotChainKey ${polkadotChainKey.toString()}');
debugPrint(
'[SampleWallet] polkadotChainKey ${polkadotChainKey.toString()}');
final solanaChainKeys = _solanaKeyPair();
debugPrint('[WALLET] solanaChainKey $solanaChainKeys');
debugPrint('[SampleWallet] solanaChainKey $solanaChainKeys');
//
return [
kadenaChainKey,
Expand Down
Loading

0 comments on commit bd78944

Please sign in to comment.