15
15
*/
16
16
17
17
import { 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' ;
20
20
import { AggregateTransaction } from './AggregateTransaction' ;
21
21
import { CosignatureSignedTransaction } from './CosignatureSignedTransaction' ;
22
22
import { Transaction } from './Transaction' ;
@@ -53,14 +53,22 @@ export class CosignatureTransaction {
53
53
* @returns {CosignatureSignedTransaction }
54
54
*/
55
55
public static signTransactionPayload ( account : Account , payload : string , generationHash : string ) : CosignatureSignedTransaction {
56
- /**
57
- * For aggregated complete transaction, cosignatories are gathered off chain announced.
58
- */
59
56
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 {
60
68
const hashBytes = Convert . hexToUint8 ( transactionHash ) ;
61
69
const keyPairEncoded = KeyPair . createKeyPairFromPrivateKeyString ( account . privateKey ) ;
62
70
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 ) ;
64
72
}
65
73
66
74
/**
@@ -70,13 +78,10 @@ export class CosignatureTransaction {
70
78
* @returns {CosignatureSignedTransaction }
71
79
*/
72
80
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 ) {
74
83
throw new Error ( 'Transaction to cosign should be announced first' ) ;
75
84
}
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 ) ;
81
86
}
82
87
}
0 commit comments