@Override public byte[] getUnsignedBytes() { return zeroSignature(getBytes()); }
@Override public void sign(byte[] privateKey) { checkForSignature(); signature = Crypto.sign(getBytes(), privateKey); }
@Override public void sign(String secretPhrase) { checkForSignature(); signature = Crypto.signWithSecretPhrase(getBytes(), secretPhrase); }
@Override public long getId() { if (id == 0) { if (signature == null && type.isSigned()) { throw new IllegalStateException("Transaction is not signed yet"); } byte[] hash; if (useNQT()) { byte[] data = zeroSignature(getBytes()); byte[] signatureHash = Crypto.sha256().digest(signature != null ? signature : new byte[64]); MessageDigest digest = Crypto.sha256(); digest.update(data); hash = digest.digest(signatureHash); } else { hash = Crypto.sha256().digest(getBytes()); } BigInteger bigInteger = new BigInteger(1, new byte[] {hash[7], hash[6], hash[5], hash[4], hash[3], hash[2], hash[1], hash[0]}); id = bigInteger.longValue(); stringId = bigInteger.toString(); fullHash = Convert.toHexString(hash); } return id; }
@Test public void testNxtTransaction() throws WalletAccount.WalletAccountException, NxtException.ValidationException { NxtAddress destination = (NxtAddress) otherAccount.getReceiveAddress(); Value amount = NXT.value("1"); NxtSendRequest req = nxtAccount.sendCoinsOffline(destination, amount); nxtAccount.completeAndSignTx(req); Transaction nxtTx = req.nxtTxBuilder.build(); // nxtTx.sign(nxtSecret); byte[] txBytes = req.nxtTxBuilder.build().getBytes(); req.tx = new NxtTransaction(NXT, req.nxtTxBuilder.build()); Transaction parsedTx = TransactionImpl.parseTransaction(txBytes); assertEquals(Attachment.ORDINARY_PAYMENT, parsedTx.getAttachment()); assertEquals(NxtFamily.DEFAULT_DEADLINE, parsedTx.getDeadline()); assertEquals((req.tx.getRawTransaction()).getTimestamp(), parsedTx.getTimestamp()); assertEquals(nxtAccountId, parsedTx.getSenderId()); assertArrayEquals(nxtPublicKey, parsedTx.getSenderPublicKey()); assertEquals(amount.value, parsedTx.getAmountNQT()); assertEquals(req.fee.value, parsedTx.getFeeNQT()); assertEquals(destination.getAccountId(), parsedTx.getRecipientId()); // System.out.println(Convert.toHexString(nxtTx.getBytes())); // TODO check signature }