fix: validate EVM restore mnemonic checksum (#3498)

* fix: validate EVM restore mnemonics

* chore: drop test changes from this PR

Removes the test additions/modifications introduced by this branch so the
test design is left to the maintainers. Production code is unchanged.
This commit is contained in:
Seth For Privacy
2026-08-16 10:57:47 +02:00
committed by GitHub
parent 8f38ba6b17
commit 8a366129f8
3 changed files with 34 additions and 16 deletions
+6
View File
@@ -1,5 +1,11 @@
import 'package:cw_core/crypto_currency.dart';
class EVMChainMnemonicIsIncorrectException implements Exception {
@override
String toString() =>
'EVM mnemonic has incorrect format. Mnemonic should contain 12 or 24 words separated by space.';
}
class EVMChainTransactionCreationException implements Exception {
final String exceptionMessage;
+5
View File
@@ -11,6 +11,7 @@ import 'package:cw_core/wallet_type.dart';
import 'package:path/path.dart' as p;
import 'package:cw_evm/clients/evm_chain_client.dart';
import 'package:cw_evm/evm_chain_client_factory.dart';
import 'package:cw_evm/evm_chain_exceptions.dart';
import 'package:cw_evm/evm_chain_registry.dart';
import 'package:cw_evm/evm_chain_wallet.dart';
import 'package:cw_evm/evm_chain_wallet_creation_credentials.dart';
@@ -199,6 +200,10 @@ class EVMChainWalletService extends WalletService<
EVMChainRestoreWalletFromSeedCredentials credentials, {
bool? isTestnet,
}) async {
if (!bip39.validateMnemonic(credentials.mnemonic)) {
throw EVMChainMnemonicIsIncorrectException();
}
final walletInfo = credentials.walletInfo!;
// Get chainId from wallet type