@@ -19,6 +19,7 @@ import {ChronoUnit} from 'js-joda';
1919import { keccak_256 , sha3_256 } from 'js-sha3' ;
2020import { Crypto } from '../../src/core/crypto' ;
2121import { Convert as convert } from '../../src/core/format' ;
22+ import { TransactionMapping } from '../../src/core/utils/TransactionMapping' ;
2223import { AccountHttp } from '../../src/infrastructure/AccountHttp' ;
2324import { NamespaceHttp } from '../../src/infrastructure/infrastructure' ;
2425import { Listener } from '../../src/infrastructure/Listener' ;
@@ -45,6 +46,7 @@ import { AccountRestrictionTransaction } from '../../src/model/transaction/Accou
4546import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction' ;
4647import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction' ;
4748import { CosignatureSignedTransaction } from '../../src/model/transaction/CosignatureSignedTransaction' ;
49+ import { CosignatureTransaction } from '../../src/model/transaction/CosignatureTransaction' ;
4850import { Deadline } from '../../src/model/transaction/Deadline' ;
4951import { HashLockTransaction } from '../../src/model/transaction/HashLockTransaction' ;
5052import { HashType } from '../../src/model/transaction/HashType' ;
@@ -1761,6 +1763,67 @@ describe('TransactionHttp', () => {
17611763 } ) ;
17621764 } ) ;
17631765
1766+ describe ( 'SignTransactionGivenSignatures' , ( ) => {
1767+ let listener : Listener ;
1768+ before ( ( ) => {
1769+ listener = new Listener ( config . apiUrl ) ;
1770+ return listener . open ( ) ;
1771+ } ) ;
1772+ after ( ( ) => {
1773+ return listener . close ( ) ;
1774+ } ) ;
1775+ it ( 'Announce cosign signatures given' , ( done ) => {
1776+
1777+ /**
1778+ * @see https://github.com/nemtech/nem2-sdk-typescript-javascript/issues/112
1779+ */
1780+ // AliceAccount: account
1781+ // BobAccount: account
1782+
1783+ const sendAmount = NetworkCurrencyMosaic . createRelative ( 1000 ) ;
1784+ const backAmount = NetworkCurrencyMosaic . createRelative ( 1 ) ;
1785+
1786+ const aliceTransferTransaction = TransferTransaction . create ( Deadline . create ( ) , account2 . address , [ sendAmount ] ,
1787+ PlainMessage . create ( 'payout' ) , NetworkType . MIJIN_TEST ) ;
1788+ const bobTransferTransaction = TransferTransaction . create ( Deadline . create ( ) , account . address , [ backAmount ] ,
1789+ PlainMessage . create ( 'payout' ) , NetworkType . MIJIN_TEST ) ;
1790+
1791+ // 01. Alice creates the aggregated tx and sign it. Then payload send to Bob
1792+ const aggregateTransaction = AggregateTransaction . createComplete (
1793+ Deadline . create ( ) ,
1794+ [
1795+ aliceTransferTransaction . toAggregate ( account . publicAccount ) ,
1796+ bobTransferTransaction . toAggregate ( account2 . publicAccount ) ,
1797+ ] ,
1798+ NetworkType . MIJIN_TEST ,
1799+ [ ] ,
1800+ ) ;
1801+
1802+ const aliceSignedTransaction = aggregateTransaction . signWith ( account , generationHash ) ;
1803+
1804+ // 02 Bob cosigns the tx and sends it back to Alice
1805+ const signedTxBob = CosignatureTransaction . signTransactionPayload ( account2 , aliceSignedTransaction . payload , generationHash ) ;
1806+
1807+ // 03. Alice collects the cosignatures, recreate, sign, and announces the transaction
1808+ const cosignatureSignedTransactions = [
1809+ new CosignatureSignedTransaction ( signedTxBob . parentHash , signedTxBob . signature , signedTxBob . signer ) ,
1810+ ] ;
1811+ const recreatedTx = TransactionMapping . createFromPayload ( aliceSignedTransaction . payload ) as AggregateTransaction ;
1812+
1813+ const signedTransaction = recreatedTx . signTransactionGivenSignatures ( account , cosignatureSignedTransactions , generationHash ) ;
1814+
1815+ listener . confirmed ( account . address ) . subscribe ( ( ) => {
1816+ done ( ) ;
1817+ } ) ;
1818+ listener . status ( account . address ) . subscribe ( ( error ) => {
1819+ console . log ( 'Error:' , error ) ;
1820+ assert ( false ) ;
1821+ done ( ) ;
1822+ } ) ;
1823+ transactionHttp . announce ( signedTransaction ) ;
1824+ } ) ;
1825+ } ) ;
1826+
17641827 describe ( 'transactions' , ( ) => {
17651828 it ( 'should call transactions successfully' , ( done ) => {
17661829 accountHttp . transactions ( account . publicAccount ) . subscribe ( ( transactions ) => {
0 commit comments