Skip to content

Commit

Permalink
修复filecoin生成地址bug
Browse files Browse the repository at this point in the history
  • Loading branch information
GalaxySciTech committed Apr 8, 2021
1 parent 6ed4283 commit 45b14ea
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

# tokencore介绍

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

# tokencore使用方式

Expand Down
2 changes: 1 addition & 1 deletion README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ If you need the [java-wallet](https://github.com/paipaipaipai/java-wallet) walle

# tokencore introduction

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

# tokencore usage

Expand Down
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ dependencies {
// compile group: 'com.google.protobuf', name: 'protobuf-lite', version: '3.0.1'
// compile 'com.google.protobuf:protobuf-java:3.5.1'
compile 'org.json:json:20170516'
annotationProcessor 'org.projectlombok:lombok:1.18.2'
compileOnly 'org.projectlombok:lombok:1.18.2'
compile 'org.slf4j:slf4j-simple:1.6.6'

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

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

// compile 'com.madgag.spongycastle:core:1.58.0.0'

compile 'io.grpc:grpc-stub:1.36.0'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public List<Wallet> deriveWalletsByMnemonics(List<String> chainTypes, String pas
wallet = deriveTronWallet(mnemonics, password);
break;
case ChainType.FILECOIN:
wallet = deriveTronWallet(mnemonics, password);
wallet = deriveFilecoinWallet(mnemonics, password);
break;
default:
throw new TokenException(String.format("Doesn't support deriving %s wallet", chainType));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import cn.hutool.core.codec.Base32;
import cn.hutool.core.util.HexUtil;
import org.bitcoinj.core.ECKey;
import com.filecoinj.crypto.ECKey;
import org.consenlabs.tokencore.foundation.utils.NumericUtil;
import ove.crypto.digest.Blake2b;

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

@Override
public String fromPrivateKey(String prvKeyHex) {
ECKey key = ECKey.fromPrivate(NumericUtil.hexToBytes(prvKeyHex), false);
ECKey key = ECKey.fromPrivate(NumericUtil.hexToBytes(prvKeyHex));
return fromECKey(key);
}

@Override
public String fromPrivateKey(byte[] prvKeyBytes) {
ECKey key = ECKey.fromPrivate(prvKeyBytes, false);
ECKey key = ECKey.fromPrivate(prvKeyBytes);
return fromECKey(key);
}
}
30 changes: 27 additions & 3 deletions src/test/java/org/consenlabs/tokencore/Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@

public class Test implements KeystoreStorage {

static String path = "/temp";
static String path = "/tmp";

@Override
public File getKeystoreDir() {
return new File(path);
}

static {
static public void init() {
try {
Files.createDirectories(Paths.get(path + "/wallets"));
} catch (Throwable ignored) {
Expand All @@ -50,7 +50,8 @@ public File getKeystoreDir() {
}


static public void genWallet() {
static public void genBitcoinWallet() {
init();
Identity identity = Identity.getCurrentIdentity();
String password = "123456";
Wallet wallet = identity.deriveWalletByMnemonics(
Expand All @@ -61,7 +62,22 @@ static public void genWallet() {
System.out.println(wallet.getAddress());
}

static public void genFilecoinWallet() {
init();
Identity identity = Identity.getCurrentIdentity();
String password = "123456";
Wallet wallet = identity.deriveWalletByMnemonics(
ChainType.FILECOIN,
password,
MnemonicUtil.randomMnemonicCodes()
);
System.out.println(wallet.getAddress());
String privateKey=wallet.exportPrivateKey("123456");
System.out.println(privateKey);
}

static public void signBitcoinTx() {
init();
String password = "123456";
String toAddress = "33sXfhCBPyHqeVsVthmyYonCBshw5XJZn9";
int changeIdx = 0;
Expand All @@ -86,6 +102,7 @@ static public void signBitcoinTx() {
}

static public void signTrxTx() {
init();
String from = "TJRabPrwbZy45sbavfcjinPJC18kjpRTv8";
String to = "TF17BgPaZYbz8oxbjhriubPDsA7ArKoLX3";
long amount = 1;
Expand All @@ -99,4 +116,11 @@ static public void signTrxTx() {
}



public static void main(String[] args) {
genFilecoinWallet();
}



}

0 comments on commit 45b14ea

Please sign in to comment.