Search in sources :

Example 1 with Signature

use of io.nem.core.crypto.Signature in project nem2-sdk-java by nemtech.

the class Transaction method signWith.

/**
 * Serialize and sign transaction creating a new SignedTransaction.
 *
 * @param account The account to sign the transaction.
 * @return {@link SignedTransaction}
 */
public SignedTransaction signWith(Account account) {
    Signer signer = new Signer(account.getKeyPair());
    byte[] bytes = this.generateBytes();
    byte[] signingBytes = new byte[bytes.length - 100];
    System.arraycopy(bytes, 100, signingBytes, 0, bytes.length - 100);
    Signature signature = signer.sign(signingBytes);
    byte[] payload = new byte[bytes.length];
    // Size
    System.arraycopy(bytes, 0, payload, 0, 4);
    // Signature
    System.arraycopy(signature.getBytes(), 0, payload, 4, signature.getBytes().length);
    // Signer
    System.arraycopy(account.getKeyPair().getPublicKey().getRaw(), 0, payload, 64 + 4, account.getKeyPair().getPublicKey().getRaw().length);
    System.arraycopy(bytes, 100, payload, 100, bytes.length - 100);
    String hash = Transaction.createTransactionHash(Hex.toHexString(payload));
    return new SignedTransaction(Hex.toHexString(payload).toUpperCase(), hash, type);
}
Also used : Signer(io.nem.core.crypto.Signer) Signature(io.nem.core.crypto.Signature)

Aggregations

Signature (io.nem.core.crypto.Signature)1 Signer (io.nem.core.crypto.Signer)1