2019-11-20
2019-11-20 本文已影响0人
YANG_ad29
eos 支持bip44 与助记词管理
jar包
<dependency>
<groupId>org.bitcoinj</groupId>
<artifactId>bitcoinj-core</artifactId>
<version>0.14.7</version>
</dependency>
还有 eos4j (可以去github找)
public static final ChildNumber EOS_HARDENED = new ChildNumber(194, true);//eos是194
//助记词生成私钥
public String getBip44pk(List<String> mnemonicWords, String passPhrase, int number) {
String words = Joiner.on(" ").join(mnemonicWords);
byte[] seed = MnemonicUtils.generateSeed(words, passPhrase);
// ChildNumber ethindex = checkNetStatus() ? EOS_HARDENED : ONE_HARDENED;
DeterministicKey rootPrivateKey = HDKeyDerivation.createMasterPrivateKey(seed);
DeterministicHierarchy deterministicHierarchy = new DeterministicHierarchy(rootPrivateKey);
ImmutableList<ChildNumber> path = ImmutableList.of(new ChildNumber(44, true), EOS_HARDENED,
ChildNumber.ZERO_HARDENED);
DeterministicKey fourpath = deterministicHierarchy.get(path, true, true);
DeterministicKey fourpathhd = HDKeyDerivation.deriveChildKey(fourpath, 0);
DeterministicKey fivepathhd = HDKeyDerivation.deriveChildKey(fourpathhd, number);//默认number为0 取第一个 主流钱包一般是第一个
byte[] privateKeyByte = fivepathhd.getPrivKeyBytes();
byte[] a = { (byte) 0x80 };
byte[] b = new BigInteger(privateKeyByte).toByteArray();
byte[] private_key = ByteUtils.concat(a, b);
byte[] checksum = Sha.SHA256(private_key);
checksum = Sha.SHA256(checksum);
byte[] check = ByteUtils.copy(checksum, 0, 4);
byte[] pk = ByteUtils.concat(private_key, check);
String encode = Base58.encode(pk);
return encode;
// 私钥生成地址 String address = Ecc.privateToPublic(encode);//地址就可以拿去注册eos账户了
}