1515 */
1616
1717import { KeyPair } from '../../core/crypto' ;
18- import { Convert } from '../../core/format/Convert ' ;
19- import { Account } from '../account/Account ' ;
18+ import { Convert } from '../../core/format' ;
19+ import { Account } from '../account' ;
2020import { AggregateTransaction } from './AggregateTransaction' ;
2121import { CosignatureSignedTransaction } from './CosignatureSignedTransaction' ;
2222import { Transaction } from './Transaction' ;
@@ -53,14 +53,22 @@ export class CosignatureTransaction {
5353 * @returns {CosignatureSignedTransaction }
5454 */
5555 public static signTransactionPayload ( account : Account , payload : string , generationHash : string ) : CosignatureSignedTransaction {
56- /**
57- * For aggregated complete transaction, cosignatories are gathered off chain announced.
58- */
5956 const transactionHash = Transaction . createTransactionHash ( payload , Array . from ( Convert . hexToUint8 ( generationHash ) ) ) ;
57+ return this . signTransactionHash ( account , transactionHash ) ;
58+ }
59+
60+ /**
61+ * Co-sign transaction with transaction hash (off chain)
62+ * Creating a new CosignatureSignedTransaction
63+ * @param account - The signing account
64+ * @param transactionHash - The hash of the aggregate transaction to be cosigned
65+ * @returns {CosignatureSignedTransaction }
66+ */
67+ public static signTransactionHash ( account : Account , transactionHash : string ) : CosignatureSignedTransaction {
6068 const hashBytes = Convert . hexToUint8 ( transactionHash ) ;
6169 const keyPairEncoded = KeyPair . createKeyPairFromPrivateKeyString ( account . privateKey ) ;
6270 const signature = KeyPair . sign ( keyPairEncoded , new Uint8Array ( hashBytes ) ) ;
63- return new CosignatureSignedTransaction ( Convert . uint8ToHex ( hashBytes ) , Convert . uint8ToHex ( signature ) , account . publicKey ) ;
71+ return new CosignatureSignedTransaction ( transactionHash , Convert . uint8ToHex ( signature ) , account . publicKey ) ;
6472 }
6573
6674 /**
@@ -70,13 +78,10 @@ export class CosignatureTransaction {
7078 * @returns {CosignatureSignedTransaction }
7179 */
7280 public signWith ( account : Account , transactionHash ?: string ) : CosignatureSignedTransaction {
73- if ( ( ! this . transactionToCosign . transactionInfo || ! this . transactionToCosign . transactionInfo ! . hash ) && ! transactionHash ) {
81+ const hash = transactionHash || this . transactionToCosign . transactionInfo ?. hash ;
82+ if ( ! hash ) {
7483 throw new Error ( 'Transaction to cosign should be announced first' ) ;
7584 }
76- const hash = ! transactionHash ? this . transactionToCosign . transactionInfo ! . hash : transactionHash ;
77- const hashBytes = Convert . hexToUint8 ( hash ? hash : '' ) ;
78- const keyPairEncoded = KeyPair . createKeyPairFromPrivateKeyString ( account . privateKey ) ;
79- const signature = KeyPair . sign ( keyPairEncoded , new Uint8Array ( hashBytes ) ) ;
80- return new CosignatureSignedTransaction ( hash ? hash : '' , Convert . uint8ToHex ( signature ) , account . publicKey ) ;
85+ return CosignatureTransaction . signTransactionHash ( account , hash ) ;
8186 }
8287}
0 commit comments