Skip to content

Commit 7053091

Browse files
fix: improve chain support and error handling
- WalletManager.importWalletFromMnemonic: add support for TRON, FILECOIN, DASH, DOGECOIN, BCH, BSV (previously only ETH, BTC, LTC, EOS) - WalletManager.importWalletFromMnemonic: throw on unsupported chain instead of silently returning null → NPE - V3Keystore: add Filecoin support via FilecoinAddressCreator - V3Keystore: improve error message for unsupported chain types - Update .gitignore with more comprehensive patterns Co-authored-by: Galaxy <GalaxySciTech@users.noreply.github.com>
1 parent 53ea401 commit 7053091

3 files changed

Lines changed: 39 additions & 14 deletions

File tree

.gitignore

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
1+
# Gradle
12
.gradle/
23
build/
4+
/build
5+
/*/build/
6+
7+
# IDE
38
.settings/
49
.project
510
.classpath
6-
*.class
7-
.idea
11+
.idea/
812
*.iml
9-
/local.properties
10-
.DS_Store
11-
/build
13+
*.ipr
14+
*.iws
15+
.vscode/
16+
17+
# Compiled
18+
*.class
1219
/*/out/
13-
out
20+
out/
21+
22+
# OS
23+
.DS_Store
24+
Thumbs.db
25+
26+
# Properties
27+
/local.properties
28+
29+
# Test output
30+
bin/

src/main/java/org/consenlabs/tokencore/wallet/WalletManager.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,16 +167,23 @@ public static Wallet importWalletFromMnemonic(Metadata metadata, @Nullable Strin
167167
MnemonicUtil.validateMnemonics(mnemonicCodes);
168168
switch (metadata.getChainType()) {
169169
case ChainType.ETHEREUM:
170+
case ChainType.TRON:
171+
case ChainType.FILECOIN:
170172
keystore = V3MnemonicKeystore.create(metadata, password, mnemonicCodes, path);
171173
break;
172174
case ChainType.BITCOIN:
173-
keystore = HDMnemonicKeystore.create(metadata, password, mnemonicCodes, path);
174-
break;
175175
case ChainType.LITECOIN:
176+
case ChainType.DASH:
177+
case ChainType.DOGECOIN:
178+
case ChainType.BITCOINCASH:
179+
case ChainType.BITCOINSV:
176180
keystore = HDMnemonicKeystore.create(metadata, password, mnemonicCodes, path);
177181
break;
178182
case ChainType.EOS:
179183
keystore = EOSKeystore.create(metadata, password, accountName, mnemonicCodes, path, permissions);
184+
break;
185+
default:
186+
throw new TokenException(String.format("Mnemonic import not supported for chain: %s", metadata.getChainType()));
180187
}
181188

182189
return persistWallet(keystore, overwrite);

src/main/java/org/consenlabs/tokencore/wallet/keystore/V3Keystore.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
import org.consenlabs.tokencore.foundation.crypto.Crypto;
66
import org.consenlabs.tokencore.foundation.utils.MetaUtil;
77
import org.consenlabs.tokencore.foundation.utils.NumericUtil;
8-
import org.consenlabs.tokencore.wallet.address.BitcoinAddressCreator;
9-
import org.consenlabs.tokencore.wallet.address.EthereumAddressCreator;
10-
import org.consenlabs.tokencore.wallet.address.SegWitBitcoinAddressCreator;
11-
import org.consenlabs.tokencore.wallet.address.TronAddressCreator;
8+
import org.consenlabs.tokencore.wallet.address.*;
129
import org.consenlabs.tokencore.wallet.model.ChainType;
1310
import org.consenlabs.tokencore.wallet.model.Metadata;
1411
import org.consenlabs.tokencore.wallet.model.TokenException;
@@ -55,8 +52,12 @@ public V3Keystore(Metadata metadata, String password, String prvKeyHex, String i
5552
prvKeyBytes = NumericUtil.hexToBytes(prvKeyHex);
5653
new PrivateKeyValidator(prvKeyHex).validate();
5754
this.address = new TronAddressCreator().fromPrivateKey(prvKeyBytes);
58-
}else {
59-
throw new TokenException("Can't init eos keystore in this constructor");
55+
} else if (metadata.getChainType().equals(ChainType.FILECOIN)) {
56+
prvKeyBytes = NumericUtil.hexToBytes(prvKeyHex);
57+
new PrivateKeyValidator(prvKeyHex).validate();
58+
this.address = new FilecoinAddressCreator().fromPrivateKey(prvKeyBytes);
59+
} else {
60+
throw new TokenException(String.format("Unsupported chain type for V3Keystore: %s", metadata.getChainType()));
6061
}
6162
this.crypto = Crypto.createPBKDF2Crypto(password, prvKeyBytes);
6263
metadata.setWalletType(Metadata.V3);

0 commit comments

Comments
 (0)