WalletToolsETH implements IWalletTools { @Override public String getWalletAddressFromAccountPUB(String accountPUB, String cryptoCurrency, int chainIndex, int index) { if (!accountPUB.startsWith("xpub")) { return null; } byte[] serializedKey = Base58.decodeChecked(accountPUB); ByteBuffer buffer = ByteBuffer.wrap(serializedKey); int header = buffer.getInt(); int standard = -1; boolean isPub = true; switch (header) { case XPUB: standard = STANDARD_BIP44; isPub = true; break; case XPRV: standard = STANDARD_BIP44; isPub = false; break; } if(standard == -1) { throw new IllegalArgumentException("Unknown header bytes in pub: " + accountPUB); } else { if (isPub) { int depth = buffer.get() & 255; DeterministicKey accountKey = deserializePub(accountPUB, standard); DeterministicKey walletKey = accountKey; if (depth != 2) { final DeterministicKey chainKey = HDKeyDerivation.deriveChildKey(accountKey, new ChildNumber(chainIndex, false)); walletKey = HDKeyDerivation.deriveChildKey(chainKey, new ChildNumber(index, false)); } if (standard == STANDARD_BIP44) { return Address.fromKey(MainNetParams.get(), walletKey, Script.ScriptType.P2PKH).toString(); }else if (standard == STANDARD_BIP84) { return null; } }else { return null; } } return null; }  @Override String generateSeedMnemonicSeparatedBySpaces(); MasterPrivateKeyETH getMasterPrivateKey(String seedMnemonicSeparatedBySpaces, String password, String cryptoCurrency, int standard); @Override MasterPrivateKeyETH getMasterPrivateKey(String prv, String cryptoCurrency, int standard); @Override String getWalletAddress(IMasterPrivateKey master, String cryptoCurrency, int accountIndex, int chainIndex, int index); @Override String getWalletAddressFromAccountPUB(String accountPUB, String cryptoCurrency, int chainIndex, int index); @Override String getWalletPrivateKey(IMasterPrivateKey master, String cryptoCurrency, int accountIndex, int chainIndex, int index); @Override String getAccountPUB(IMasterPrivateKey master, String cryptoCurrency, int accountIndex); @Override String getWalletAddressFromPrivateKey(String privateKey, String cryptoCurrency); @Override ISignature sign(String privateKey, byte[] hashToSign, String cryptoCurrency); boolean isAddressValid(String address, String cryptoCurrency); @Override Classification classify(String input, String cryptoCurrencyHint); @Override Classification classify(String input); @Override Set<String> supportedCryptoCurrencies(); static byte[] sha3(byte[] message); static String encodeAddressToIBAN(byte[] addrBytes); String generateWalletPrivateKeyWithPrefix(String prefix, String cryptoCurrency); static final int XPUB; static final int XPRV; }
@Test public void getWalletAddressFromAccountPUB() { String walletAddressFromPub = walletToolsETH.getWalletAddressFromAccountPUB(masterPrivateKey.getPUB(), "ETH", 2, 3); Assert.assertEquals("1ALZ3ojSmz3632LG7j3xbHeJpuy4ZXbPn9", walletAddressFromPub); }