use of io.nem.sdk.model.account.Account 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.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class AggregateTransactionTest method shouldCreateAggregateTransactionAndSignWithMultipleCosignatories.
@Test
void shouldCreateAggregateTransactionAndSignWithMultipleCosignatories() {
TransferTransaction transferTx = TransferTransaction.create(new FakeDeadline(), new Address("SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC", NetworkType.MIJIN_TEST), Arrays.asList(), new PlainMessage("test-message"), NetworkType.MIJIN_TEST);
AggregateTransaction aggregateTx = AggregateTransaction.createComplete(new FakeDeadline(), Collections.singletonList(transferTx.toAggregate(new PublicAccount("B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D", NetworkType.MIJIN_TEST))), NetworkType.MIJIN_TEST);
Account cosignatoryAccount = new Account("2a2b1f5d366a5dd5dc56c3c757cf4fe6c66e2787087692cf329d7a49a594658b", NetworkType.MIJIN_TEST);
// TODO bug with private key
Account cosignatoryAccount2 = new Account("b8afae6f4ad13a1b8aad047b488e0738a437c7389d4ff30c359ac068910c1d59", NetworkType.MIJIN_TEST);
SignedTransaction signedTransaction = cosignatoryAccount.signTransactionWithCosignatories(aggregateTx, Arrays.asList(cosignatoryAccount2));
assertEquals("2d010000", signedTransaction.getPayload().substring(0, 8));
assertEquals("5100000051000000", signedTransaction.getPayload().substring(240, 256));
// assertEquals("039054419050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E1420D000000746573742D6D65737361676568B3FBB18729C1FDE225C57F8CE080FA828F0067E451A3FD81FA628842B0B763", signedTransaction.getPayload().substring(320, 474));
}
use of io.nem.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class E2ETest method setup.
@BeforeAll
void setup() throws ExecutionException, InterruptedException, IOException {
transactionHttp = new TransactionHttp(this.getNodeUrl());
account = new Account("787225aaff3d2c71f4ffa32d4f19ec4922f3cd869747f267378f81f8e3fcb12d", NetworkType.MIJIN_TEST);
multisigAccount = new Account("5edebfdbeb32e9146d05ffd232c8af2cf9f396caf9954289daa0362d097fff3b", NetworkType.MIJIN_TEST);
cosignatoryAccount = new Account("2a2b1f5d366a5dd5dc56c3c757cf4fe6c66e2787087692cf329d7a49a594658b", NetworkType.MIJIN_TEST);
cosignatoryAccount2 = new Account("b8afae6f4ad13a1b8aad047b488e0738a437c7389d4ff30c359ac068910c1d59", NetworkType.MIJIN_TEST);
listener = new Listener(this.getNodeUrl());
listener.open().get();
}
use of io.nem.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class ListenerTest method setup.
@BeforeAll
void setup() throws IOException {
transactionHttp = new TransactionHttp(this.getNodeUrl());
accountHttp = new AccountHttp(this.getNodeUrl());
account = new Account("787225aaff3d2c71f4ffa32d4f19ec4922f3cd869747f267378f81f8e3fcb12d", NetworkType.MIJIN_TEST);
multisigAccount = new Account("5edebfdbeb32e9146d05ffd232c8af2cf9f396caf9954289daa0362d097fff3b", NetworkType.MIJIN_TEST);
cosignatoryAccount = new Account("2a2b1f5d366a5dd5dc56c3c757cf4fe6c66e2787087692cf329d7a49a594658b", NetworkType.MIJIN_TEST);
cosignatoryAccount2 = new Account("b8afae6f4ad13a1b8aad047b488e0738a437c7389d4ff30c359ac068910c1d59", NetworkType.MIJIN);
}