0

我正在尝试为以太坊混合BitcoinJWeb3j. 确定性密钥是使用生成BitcoinJ的,而以太坊凭证使用Web3j. 但是使用凭证生成的地址Web3j并不像预期的那样。

String seedCode = "yard impulse luxury drive today throw farm pepper survey wreck glass federal";

// BitcoinJ
DeterministicSeed seed = new DeterministicSeed(seedCode, null, "", 1409478661L);
DeterministicKeyChain chain = DeterministicKeyChain.builder().seed(seed).build();
DeterministicKey key = chain.getKey(KeyPurpose.RECEIVE_FUNDS);
BigInteger privKey = key.getPrivKey();

// Web3j
Credentials credentials = Credentials.create(privKey.toString(16));
System.out.println("Address: " + credentials.getAddress());

输出0x2c4186d0422d0462a48c92cd559cbc30f528855b

预期0x72445fcFdEB1Fff79496D7Ce66089d663Ff90E26

代码中的误解在哪里?

4

1 回答 1

6

默认情况下,bitcoinj使用键链的路径m/0'/0大多数以太坊解决方案都使用m/44'/60'/0'/0BIP44规范。这就是为什么与其他以太坊工具相比结果不如预期的原因。

下面的代码解决了“问题”:

String seedCode = "yard impulse luxury drive today throw farm pepper survey wreck glass federal";

// BitcoinJ
DeterministicSeed seed = new DeterministicSeed(seedCode, null, "", 1409478661L);
DeterministicKeyChain chain = DeterministicKeyChain.builder().seed(seed).build();
List<ChildNumber> keyPath = HDUtils.parsePath("M/44H/60H/0H/0/0");
DeterministicKey key = chain.getKeyByPath(keyPath, true);
BigInteger privKey = key.getPrivKey();

// Web3j
Credentials credentials = Credentials.create(privKey.toString(16));
System.out.println(credentials.getAddress());
于 2018-03-09T20:26:32.103 回答