Skip to content

Commit 45b14ea

Browse files
committed
修复filecoin生成地址bug
1 parent 6ed4283 commit 45b14ea

File tree

6 files changed

+36
-11
lines changed

6 files changed

+36
-11
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
# tokencore介绍
3939

40-
##### 区块链钱包后台核心组件,支持BTC,OMNI,ETH,ERC20,TRX,TRC20,BCH,BSV,DOGE,DASH,LTC
40+
##### 区块链钱包后台核心组件,支持BTC,OMNI,ETH,ERC20,TRX,TRC20,BCH,BSV,DOGE,DASH,LTC,FILECOIN
4141

4242
# tokencore使用方式
4343

README_en.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ If you need the [java-wallet](https://github.com/paipaipaipai/java-wallet) walle
3838

3939
# tokencore introduction
4040

41-
##### The core components of the blockchain wallet backend, support BTC, OMNI, ETH, ERC20, TRX, TRC20, BCH, BSV, DOGE, DASH, LTC
41+
##### The core components of the blockchain wallet backend, support BTC, OMNI, ETH, ERC20, TRX, TRC20, BCH, BSV, DOGE, DASH, LTC,FILECOIN
4242

4343
# tokencore usage
4444

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@ dependencies {
3737
// compile group: 'com.google.protobuf', name: 'protobuf-lite', version: '3.0.1'
3838
// compile 'com.google.protobuf:protobuf-java:3.5.1'
3939
compile 'org.json:json:20170516'
40-
annotationProcessor 'org.projectlombok:lombok:1.18.2'
41-
compileOnly 'org.projectlombok:lombok:1.18.2'
40+
compile 'org.slf4j:slf4j-simple:1.6.6'
4241

4342
compile 'com.github.paipaipaipai:FilecoinJ:0.0.1'
4443
compile 'com.google.protobuf:protobuf-java:3.11.0'
@@ -48,6 +47,8 @@ dependencies {
4847

4948
compile 'com.google.guava:guava:28.0-jre'
5049

50+
// compile 'com.madgag.spongycastle:core:1.58.0.0'
51+
5152
compile 'io.grpc:grpc-stub:1.36.0'
5253
}
5354

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public List<Wallet> deriveWalletsByMnemonics(List<String> chainTypes, String pas
195195
wallet = deriveTronWallet(mnemonics, password);
196196
break;
197197
case ChainType.FILECOIN:
198-
wallet = deriveTronWallet(mnemonics, password);
198+
wallet = deriveFilecoinWallet(mnemonics, password);
199199
break;
200200
default:
201201
throw new TokenException(String.format("Doesn't support deriving %s wallet", chainType));

src/main/java/org/consenlabs/tokencore/wallet/address/FilecoinAddressCreator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import cn.hutool.core.codec.Base32;
44
import cn.hutool.core.util.HexUtil;
5-
import org.bitcoinj.core.ECKey;
5+
import com.filecoinj.crypto.ECKey;
66
import org.consenlabs.tokencore.foundation.utils.NumericUtil;
77
import ove.crypto.digest.Blake2b;
88

@@ -29,13 +29,13 @@ private String fromECKey(ECKey key) {
2929

3030
@Override
3131
public String fromPrivateKey(String prvKeyHex) {
32-
ECKey key = ECKey.fromPrivate(NumericUtil.hexToBytes(prvKeyHex), false);
32+
ECKey key = ECKey.fromPrivate(NumericUtil.hexToBytes(prvKeyHex));
3333
return fromECKey(key);
3434
}
3535

3636
@Override
3737
public String fromPrivateKey(byte[] prvKeyBytes) {
38-
ECKey key = ECKey.fromPrivate(prvKeyBytes, false);
38+
ECKey key = ECKey.fromPrivate(prvKeyBytes);
3939
return fromECKey(key);
4040
}
4141
}

src/test/java/org/consenlabs/tokencore/Test.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@
2121

2222
public class Test implements KeystoreStorage {
2323

24-
static String path = "/temp";
24+
static String path = "/tmp";
2525

2626
@Override
2727
public File getKeystoreDir() {
2828
return new File(path);
2929
}
3030

31-
static {
31+
static public void init() {
3232
try {
3333
Files.createDirectories(Paths.get(path + "/wallets"));
3434
} catch (Throwable ignored) {
@@ -50,7 +50,8 @@ public File getKeystoreDir() {
5050
}
5151

5252

53-
static public void genWallet() {
53+
static public void genBitcoinWallet() {
54+
init();
5455
Identity identity = Identity.getCurrentIdentity();
5556
String password = "123456";
5657
Wallet wallet = identity.deriveWalletByMnemonics(
@@ -61,7 +62,22 @@ static public void genWallet() {
6162
System.out.println(wallet.getAddress());
6263
}
6364

65+
static public void genFilecoinWallet() {
66+
init();
67+
Identity identity = Identity.getCurrentIdentity();
68+
String password = "123456";
69+
Wallet wallet = identity.deriveWalletByMnemonics(
70+
ChainType.FILECOIN,
71+
password,
72+
MnemonicUtil.randomMnemonicCodes()
73+
);
74+
System.out.println(wallet.getAddress());
75+
String privateKey=wallet.exportPrivateKey("123456");
76+
System.out.println(privateKey);
77+
}
78+
6479
static public void signBitcoinTx() {
80+
init();
6581
String password = "123456";
6682
String toAddress = "33sXfhCBPyHqeVsVthmyYonCBshw5XJZn9";
6783
int changeIdx = 0;
@@ -86,6 +102,7 @@ static public void signBitcoinTx() {
86102
}
87103

88104
static public void signTrxTx() {
105+
init();
89106
String from = "TJRabPrwbZy45sbavfcjinPJC18kjpRTv8";
90107
String to = "TF17BgPaZYbz8oxbjhriubPDsA7ArKoLX3";
91108
long amount = 1;
@@ -99,4 +116,11 @@ static public void signTrxTx() {
99116
}
100117

101118

119+
120+
public static void main(String[] args) {
121+
genFilecoinWallet();
122+
}
123+
124+
125+
102126
}

0 commit comments

Comments
 (0)