Search in sources :

Example 1 with Signer

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

the class AggregateTransaction method signTransactionWithCosigners.

/**
 * Sign transaction with cosignatories creating a new SignedTransaction.
 *
 * @param initiatorAccount Initiator account
 * @param cosignatories    The list of accounts that will cosign the transaction
 * @return {@link SignedTransaction}
 */
public SignedTransaction signTransactionWithCosigners(Account initiatorAccount, List<Account> cosignatories) {
    SignedTransaction signedTransaction = this.signWith(initiatorAccount);
    String payload = signedTransaction.getPayload();
    for (Account cosignatory : cosignatories) {
        Signer signer = new Signer(cosignatory.getKeyPair());
        byte[] bytes = Hex.decode(signedTransaction.getHash());
        byte[] signatureBytes = signer.sign(bytes).getBytes();
        payload += cosignatory.getPublicKey() + Hex.toHexString(signatureBytes);
    }
    byte[] payloadBytes = Hex.decode(payload);
    byte[] size = BigInteger.valueOf(payloadBytes.length).toByteArray();
    ArrayUtils.reverse(size);
    System.arraycopy(size, 0, payloadBytes, 0, size.length);
    return new SignedTransaction(Hex.toHexString(payloadBytes), signedTransaction.getHash(), getType());
}
Also used : Signer(io.nem.core.crypto.Signer) PublicAccount(io.nem.sdk.model.account.PublicAccount) Account(io.nem.sdk.model.account.Account)

Example 2 with Signer

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

the class CosignatureTransaction method signWith.

/**
 * Serialize and sign transaction creating a new SignedTransaction.
 *
 * @param account Account
 * @return {@link CosignatureSignedTransaction}
 */
public CosignatureSignedTransaction signWith(Account account) {
    Signer signer = new Signer(account.getKeyPair());
    byte[] bytes = Hex.decode(this.transactionToCosign.getTransactionInfo().get().getHash().get());
    byte[] signatureBytes = signer.sign(bytes).getBytes();
    return new CosignatureSignedTransaction(this.transactionToCosign.getTransactionInfo().get().getHash().get(), Hex.toHexString(signatureBytes), account.getPublicKey());
}
Also used : Signer(io.nem.core.crypto.Signer)

Example 3 with Signer

use of io.nem.core.crypto.Signer 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

Signer (io.nem.core.crypto.Signer)3 Signature (io.nem.core.crypto.Signature)1 Account (io.nem.sdk.model.account.Account)1 PublicAccount (io.nem.sdk.model.account.PublicAccount)1