Skip to content

Commit

Permalink
Fix hyperledger-web3j#919. Gen consistent privateKey with other eth l…
Browse files Browse the repository at this point in the history
…ibs (hyperledger-web3j#1259)

* Fix hyperledger-web3j#919. Gen consistent privateKey with others.

* Fix format issues.

* Fix format issues with spotlessJavaApply

Co-authored-by: mawenpeng <wp.ma@muheda.com>
  • Loading branch information
2 people authored and rach-id committed Apr 12, 2021
1 parent d1b1b5c commit 0fff0d1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/org/web3j/crypto/Bip44WalletUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ public static Bip32ECKeyPair generateBip44KeyPair(Bip32ECKeyPair master, boolean
final int[] path = {44 | HARDENED_BIT, 0 | HARDENED_BIT, 0 | HARDENED_BIT, 0};
return Bip32ECKeyPair.deriveKeyPair(master, path);
} else {
// m/44'/60'/0'/0
final int[] path = {44 | HARDENED_BIT, 60 | HARDENED_BIT, 0 | HARDENED_BIT, 0};
// m/44'/60'/0'/0/0
final int[] path = {44 | HARDENED_BIT, 60 | HARDENED_BIT, 0 | HARDENED_BIT, 0, 0};
return Bip32ECKeyPair.deriveKeyPair(master, path);
}
}
Expand Down
11 changes: 9 additions & 2 deletions core/src/test/java/org/web3j/crypto/Bip44WalletUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,18 @@ public void generateBip44KeyPair() {
Bip32ECKeyPair bip44Keypair = Bip44WalletUtils.generateBip44KeyPair(masterKeypair);

assertEquals(
"xprv9zvpunws9gusoXVkmqAXWQm5z5hjR5kY3ifRGL7M8Kpjn8kRhavkGnFLjnFWPGGS2gAUw8rP33Lmj6SwZUpwy2mn2fXRYWzGa9WRTnE8DPz",
"xprvA3p5nTrBJcdEvUQAK64rZ4oJTwsTiMg7JQrqNh6JNWe3VUW2tcLb7GW1wj1fNDAoymUTSFERZ2LxPxJNmqoMZPs9y3TMNMuBN8MS9eigoWq",
Base58.encode(addChecksum(serializePrivate(bip44Keypair))));
assertEquals(
"xpub6DvBKJUkz4UB21aDsrhXsYhpY7YDpYUPQwb24iWxgfMiew5aF8EzpaZpb567bYYbMfUnPwFNuRYvVpMGQUcaGPMoXUEUZKFvx7LaU5b7zBD",
"xpub6GoSByP58zBY8xUdR7brvCk31yhx7pPxfdnSB5VuvrB2NGqBS9eqf4pVo1xev4GEmip5Wuky9KUtJVxq4fvYfFchS6SA6C4cCRyQkLqNNjq",
Base58.encode(addChecksum(serializePublic(bip44Keypair))));

Credentials credentials =
Bip44WalletUtils.loadBip44Credentials(
"", mnemonic); // Verify address according to https://iancoleman.io/bip39/
assertEquals(
"0xece62451ca8fba33746d6dafd0d0ebdef84778b7",
credentials.getAddress().toLowerCase());
}

@Test
Expand Down

0 comments on commit 0fff0d1

Please # to comment.