Skip to content

Commit 9303995

Browse files
committed
Changed to sign cosign transaction to use payload instead of hash
1 parent e5bc363 commit 9303995

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

src/model/transaction/CosignatureTransaction.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,17 @@ export class CosignatureTransaction {
4646
}
4747

4848
/**
49-
* Co-sign transaction with transaction hash (off chain)
49+
* Co-sign transaction with transaction payload (off chain)
5050
* Creating a new CosignatureSignedTransaction
5151
* @param account - The signing account
52-
* @param transactionHash - off transaction hash (aggregated transaction is unannounced)
52+
* @param payload - off transaction payload (aggregated transaction is unannounced)
5353
* @returns {CosignatureSignedTransaction}
5454
*/
55-
public static signTransactionHashWith(account: Account, transactionHash: string): CosignatureSignedTransaction {
55+
public static signTransactionPayload(account: Account, payload: string): CosignatureSignedTransaction {
5656
/**
5757
* For aggregated complete transaction, cosignatories are gathered off chain announced.
5858
*/
59+
const transactionHash = VerifiableTransaction.createTransactionHash(payload);
5960
const aggregateSignatureTransaction = new CosignaturetransactionLibrary(transactionHash);
6061
const signedTransactionRaw = aggregateSignatureTransaction.signCosignatoriesTransaction(account);
6162
return new CosignatureSignedTransaction(signedTransactionRaw.parentHash,

test/model/transaction/AggregateTransaction.spec.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ describe('AggregateTransaction', () => {
411411
PlainMessage.create('c to a'),
412412
NetworkType.MIJIN_TEST);
413413

414-
// 01. Alice creates the aggregated tx and serialize it, and generate the hash. Then send to Bob & Carol
414+
// 01. Alice creates the aggregated tx and serialize it, Then payload send to Bob & Carol
415415
const aggregateTransactionPayload = AggregateTransaction.createComplete(
416416
Deadline.create(),
417417
[
@@ -422,13 +422,11 @@ describe('AggregateTransaction', () => {
422422
[],
423423
).serialize();
424424

425-
const txHash = VerifiableTransaction.createTransactionHash(aggregateTransactionPayload);
426-
427425
// 02.1 Bob cosigns the tx and sends it back to Alice
428-
const signedTxBob = CosignatureTransaction.signTransactionHashWith(accountBob, txHash);
426+
const signedTxBob = CosignatureTransaction.signTransactionPayload(accountBob, aggregateTransactionPayload);
429427

430428
// 02.2 Carol cosigns the tx and sends it back to Alice
431-
const signedTxCarol = CosignatureTransaction.signTransactionHashWith(accountCarol, txHash);
429+
const signedTxCarol = CosignatureTransaction.signTransactionPayload(accountCarol, aggregateTransactionPayload);
432430

433431
// 03. Alice collects the cosignatures, recreate, sign, and announces the transaction
434432

test/model/transaction/CosignatureTransaction.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,15 @@ describe('CosignatureTransaction', () => {
118118
expect(cosignatureSignedTransaction.signer).to.be.equal(account.publicKey);
119119
});
120120

121-
it('should sign a transaction with transaction hash', () => {
121+
it('should sign a transaction with transaction payload', () => {
122122
const txPayload = TransferTransaction.create(Deadline.create(),
123123
account.address,
124124
[],
125125
PlainMessage.create('a to b'),
126126
NetworkType.MIJIN_TEST).serialize();
127127

128-
const txHash = VerifiableTransaction.createTransactionHash(txPayload);
128+
const signedTx = CosignatureTransaction.signTransactionPayload(account, txPayload);
129129

130-
const signedTx = CosignatureTransaction.signTransactionHashWith(account, txHash);
131-
132-
expect(signedTx.parentHash).to.be.equal(txHash);
133130
expect(signedTx.signer).to.be.equal('C2F93346E27CE6AD1A9F8F5E3066F8326593A406BDF357ACB041E2F9AB402EFE');
134131
expect(signedTx.signer).to.be.equal(account.publicKey);
135132
});

0 commit comments

Comments
 (0)