Skip to content

Commit

Permalink
增加btc 分叉币私钥导出
Browse files Browse the repository at this point in the history
  • Loading branch information
GalaxySciTech committed Sep 16, 2020
1 parent 6e98bd3 commit 13671f6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/org/consenlabs/tokencore/wallet/Wallet.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package org.consenlabs.tokencore.wallet;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.bitcoinj.crypto.ChildNumber;
import org.bitcoinj.crypto.DeterministicKey;
import org.bitcoinj.crypto.HDKeyDerivation;
import org.consenlabs.tokencore.foundation.utils.MetaUtil;
import org.consenlabs.tokencore.foundation.utils.NumericUtil;
import org.consenlabs.tokencore.wallet.keystore.*;
import org.consenlabs.tokencore.wallet.model.*;

import java.nio.charset.Charset;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -79,6 +84,12 @@ public String exportPrivateKey(String password) {
} else {
return NumericUtil.bytesToHex(decrypted);
}
}else if(keystore instanceof HDMnemonicKeystore){
String xprv = new String(decryptMainKey(password), Charset.forName("UTF-8"));
DeterministicKey xprvKey = DeterministicKey.deserializeB58(xprv, MetaUtil.getNetWork(keystore.getMetadata()));
DeterministicKey accountKey = HDKeyDerivation.deriveChildKey(xprvKey, new ChildNumber(0, false));
DeterministicKey externalChangeKey = HDKeyDerivation.deriveChildKey(accountKey, new ChildNumber(1, false));
return NumericUtil.bigIntegerToHex(externalChangeKey.getPrivKey());
}
throw new TokenException(Messages.ILLEGAL_OPERATION);
}
Expand Down

0 comments on commit 13671f6

Please sign in to comment.