WalletToolsBCH 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(); if (isPub(accountPUB, header)) { int depth = buffer.get() & 255; DeterministicKey accountKey = DeterministicKey.deserializeB58(accountPUB, MainNetParams.get()); DeterministicKey walletKey = accountKey; if (depth != 2) { final DeterministicKey chainKey = HDKeyDerivation.deriveChildKey(accountKey, new ChildNumber(chainIndex, false)); walletKey = HDKeyDerivation.deriveChildKey(chainKey, new ChildNumber(index, false)); } return getAddress(walletKey); } return null; }  @Override String generateSeedMnemonicSeparatedBySpaces(); MasterPrivateKeyBCH getMasterPrivateKey(String seedMnemonicSeparatedBySpaces, String password, String cryptoCurrency, int standard); @Override MasterPrivateKeyBCH 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); boolean isAddressValid(String address, String cryptoCurrency); @Override ISignature sign(String privateKey, byte[] hashToSign, String cryptoCurrency); @Override Classification classify(String input, String cryptoCurrencyHint); @Override Classification classify(String input); @Override Set<String> supportedCryptoCurrencies(); String generateWalletPrivateKeyWithPrefix(String prefix, String cryptoCurrency); static final int XPUB; static final int XPRV; static final String BITCOINCASH_PREFIX; }
@Test public void getWalletAddressFromAccountPUB() { String walletAddressFromPub = walletToolsBCH.getWalletAddressFromAccountPUB(masterPrivateKey.getPUB(), "BCH", 2, 3); Assert.assertEquals("qq85rv80tn99qhzf2dzl5c6rcleavlnz7yay4yxumv", walletAddressFromPub); }