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());
}
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());
}
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);
}
Aggregations