Skip to content

Commit 13671f6

Browse files
committed
增加btc 分叉币私钥导出
1 parent 6e98bd3 commit 13671f6

File tree

1 file changed

+11
-0
lines changed
  • src/main/java/org/consenlabs/tokencore/wallet

1 file changed

+11
-0
lines changed

Diff for: src/main/java/org/consenlabs/tokencore/wallet/Wallet.java

+11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
package org.consenlabs.tokencore.wallet;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
4+
import org.bitcoinj.crypto.ChildNumber;
5+
import org.bitcoinj.crypto.DeterministicKey;
6+
import org.bitcoinj.crypto.HDKeyDerivation;
7+
import org.consenlabs.tokencore.foundation.utils.MetaUtil;
48
import org.consenlabs.tokencore.foundation.utils.NumericUtil;
59
import org.consenlabs.tokencore.wallet.keystore.*;
610
import org.consenlabs.tokencore.wallet.model.*;
711

12+
import java.nio.charset.Charset;
813
import java.util.Collections;
914
import java.util.List;
1015

@@ -79,6 +84,12 @@ public String exportPrivateKey(String password) {
7984
} else {
8085
return NumericUtil.bytesToHex(decrypted);
8186
}
87+
}else if(keystore instanceof HDMnemonicKeystore){
88+
String xprv = new String(decryptMainKey(password), Charset.forName("UTF-8"));
89+
DeterministicKey xprvKey = DeterministicKey.deserializeB58(xprv, MetaUtil.getNetWork(keystore.getMetadata()));
90+
DeterministicKey accountKey = HDKeyDerivation.deriveChildKey(xprvKey, new ChildNumber(0, false));
91+
DeterministicKey externalChangeKey = HDKeyDerivation.deriveChildKey(accountKey, new ChildNumber(1, false));
92+
return NumericUtil.bigIntegerToHex(externalChangeKey.getPrivKey());
8293
}
8394
throw new TokenException(Messages.ILLEGAL_OPERATION);
8495
}

0 commit comments

Comments
 (0)