@@ -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' ;
@@ -44,6 +45,7 @@ import { AccountRestrictionTransaction } from '../../src/model/transaction/Accou
4445import { AddressAliasTransaction } from '../../src/model/transaction/AddressAliasTransaction' ;
4546import { AggregateTransaction } from '../../src/model/transaction/AggregateTransaction' ;
4647import { CosignatureSignedTransaction } from '../../src/model/transaction/CosignatureSignedTransaction' ;
48+ import { CosignatureTransaction } from '../../src/model/transaction/CosignatureTransaction' ;
4749import { Deadline } from '../../src/model/transaction/Deadline' ;
4850import { HashLockTransaction } from '../../src/model/transaction/HashLockTransaction' ;
4951import { HashType } from '../../src/model/transaction/HashType' ;
@@ -1641,6 +1643,67 @@ describe('TransactionHttp', () => {
16411643 } ) ;
16421644 } ) ;
16431645
1646+ describe ( 'SignTransactionGivenSignatures' , ( ) => {
1647+ let listener : Listener ;
1648+ before ( ( ) => {
1649+ listener = new Listener ( config . apiUrl ) ;
1650+ return listener . open ( ) ;
1651+ } ) ;
1652+ after ( ( ) => {
1653+ return listener . close ( ) ;
1654+ } ) ;
1655+ it ( 'Announce cosign signatures given' , ( done ) => {
1656+
1657+ /**
1658+ * @see https://github.com/nemtech/nem2-sdk-typescript-javascript/issues/112
1659+ */
1660+ // AliceAccount: account
1661+ // BobAccount: account
1662+
1663+ const sendAmount = NetworkCurrencyMosaic . createRelative ( 1000 ) ;
1664+ const backAmount = NetworkCurrencyMosaic . createRelative ( 1 ) ;
1665+
1666+ const aliceTransferTransaction = TransferTransaction . create ( Deadline . create ( ) , account2 . address , [ sendAmount ] ,
1667+ PlainMessage . create ( 'payout' ) , NetworkType . MIJIN_TEST ) ;
1668+ const bobTransferTransaction = TransferTransaction . create ( Deadline . create ( ) , account . address , [ backAmount ] ,
1669+ PlainMessage . create ( 'payout' ) , NetworkType . MIJIN_TEST ) ;
1670+
1671+ // 01. Alice creates the aggregated tx and sign it. Then payload send to Bob
1672+ const aggregateTransaction = AggregateTransaction . createComplete (
1673+ Deadline . create ( ) ,
1674+ [
1675+ aliceTransferTransaction . toAggregate ( account . publicAccount ) ,
1676+ bobTransferTransaction . toAggregate ( account2 . publicAccount ) ,
1677+ ] ,
1678+ NetworkType . MIJIN_TEST ,
1679+ [ ] ,
1680+ ) ;
1681+
1682+ const aliceSignedTransaction = aggregateTransaction . signWith ( account , generationHash ) ;
1683+
1684+ // 02 Bob cosigns the tx and sends it back to Alice
1685+ const signedTxBob = CosignatureTransaction . signTransactionPayload ( account2 , aliceSignedTransaction . payload , generationHash ) ;
1686+
1687+ // 03. Alice collects the cosignatures, recreate, sign, and announces the transaction
1688+ const cosignatureSignedTransactions = [
1689+ new CosignatureSignedTransaction ( signedTxBob . parentHash , signedTxBob . signature , signedTxBob . signer ) ,
1690+ ] ;
1691+ const recreatedTx = TransactionMapping . createFromPayload ( aliceSignedTransaction . payload ) as AggregateTransaction ;
1692+
1693+ const signedTransaction = recreatedTx . signTransactionGivenSignatures ( account , cosignatureSignedTransactions , generationHash ) ;
1694+
1695+ listener . confirmed ( account . address ) . subscribe ( ( ) => {
1696+ done ( ) ;
1697+ } ) ;
1698+ listener . status ( account . address ) . subscribe ( ( error ) => {
1699+ console . log ( 'Error:' , error ) ;
1700+ assert ( false ) ;
1701+ done ( ) ;
1702+ } ) ;
1703+ transactionHttp . announce ( signedTransaction ) ;
1704+ } ) ;
1705+ } ) ;
1706+
16441707 describe ( 'transactions' , ( ) => {
16451708 it ( 'should call transactions successfully' , ( done ) => {
16461709 accountHttp . transactions ( account . publicAccount ) . subscribe ( ( transactions ) => {
0 commit comments