public void signTransaction(NxtSendRequest request) { checkArgument(request.isCompleted(), "Send request is not completed"); checkArgument(request.tx != null, "No transaction found in send request"); Transaction tx = request.tx.getRawTransaction(); byte[] privateKey; if (rootKey.isEncrypted()) { checkArgument(request.aesKey != null, "Wallet is encrypted but no decryption key provided"); privateKey = rootKey.toDecrypted(request.aesKey).getPrivateKey(); } else { privateKey = rootKey.getPrivateKey(); } tx.sign(privateKey); Arrays.fill(privateKey, (byte) 0); // clear private key }
@Test public void testHDAccountNxt() throws MnemonicException { byte[] privateKey = nxtAccount.rootKey.getPrivateKey(); byte[] publicKey = nxtAccount.getPublicKey(); assertArrayEquals(nxtPrivateKey, privateKey); assertEquals(nxtRsAddress, nxtAccount.getPublicKeyMnemonic()); assertArrayEquals(nxtPublicKey, publicKey); NxtAddress address = (NxtAddress) nxtAccount.getReceiveAddress(); assertEquals(nxtRsAddress, address.toString()); assertEquals(nxtAccountId, address.getAccountId()); }
@Test public void testHDAccountNxt() throws MnemonicException, UnreadableWalletException { DeterministicSeed seed = new DeterministicSeed(recoveryPhrase, null, "", 0); DeterministicKey masterKey = HDKeyDerivation.createMasterPrivateKey(seed.getSeedBytes()); DeterministicHierarchy hierarchy = new DeterministicHierarchy(masterKey); DeterministicKey entropy = hierarchy.get(NxtMain.get().getBip44Path(0), false, true); NxtFamilyKey nxtKey = new NxtFamilyKey(entropy, null, null); byte[] privateKey = nxtKey.getPrivateKey(); byte[] publicKey = nxtKey.getPublicKey(); NxtAddress address = new NxtAddress(NxtMain.get(), publicKey); assertArrayEquals(nxtPrivateKey, privateKey); assertArrayEquals(nxtPublicKey, publicKey); assertEquals(nxtRsAddress, address.toString()); assertEquals(nxtAccountId, address.getAccountId()); }