Is signWithCosignatories
you mention should be signTransactionWithCosignatories
? But that is internal function, which is not expose by typescript?
Okay, this is what I do, but still giving me TypeError: Cannot read property 'hash' of undefined
:
const nodeUrl = 'http://localhost:3000';
const transactionHttp = new TransactionHttp(nodeUrl);
//multisig
const multisigPrivateKey = '...';
const multisigAccount = Account.createFromPrivateKey(multisigPrivateKey, NetworkType.MIJIN_TEST);
//alice
const alicePrivateKey = '...';
const aliceAccount = Account.createFromPrivateKey(alicePrivateKey, NetworkType.MIJIN_TEST);
//bob
const bobPrivateKey = '...';
const bobAccount = Account.createFromPrivateKey(bobPrivateKey, NetworkType.MIJIN_TEST);
//MultisigAccountModificationTransaction
const convertIntoMultisigTransaction = MultisigAccountModificationTransaction.create(
Deadline.create(),
1,
1,
[
new MultisigCosignatoryModification(
CosignatoryModificationAction.Add,
aliceAccount.publicAccount,
),
new MultisigCosignatoryModification(
CosignatoryModificationAction.Add,
bobAccount.publicAccount,
)],
NetworkType.MIJIN_TEST,
UInt64.fromUint(0))
//AggregateBondedTransaction
const aggregateTransaction = AggregateTransaction.createComplete(
Deadline.create(),
[convertIntoMultisigTransaction.toAggregate(multisigAccount.publicAccount)],
NetworkType.MIJIN_TEST,
[],
UInt64.fromUint(0))
//Sign tx with the multisig account
const networkGenerationHash = '...';
const signedTransaction = multisigAccount.sign(aggregateTransaction, networkGenerationHash);
// const signedTransaction = aggregateTransaction.signTransactionWithCosignatories(multisigAccount, [], networkGenerationHash);
const cosignAggregateBondedTransaction = (transaction: AggregateTransaction, account: Account): CosignatureSignedTransaction => {
const cosignatureSignedTransaction = CosignatureTransaction.create(transaction);
return account.signCosignatureTransaction(cosignatureSignedTransaction);
}
const txPayload = signedTransaction.payload;
const txHash = signedTransaction.hash;
const AB = TransactionMapping.createFromPayload(txPayload) as AggregateTransaction;
const signedTxAlice = cosignAggregateBondedTransaction(AB, aliceAccount);
const signedTxBob = cosignAggregateBondedTransaction(AB, bobAccount);
const fullySigned = multisigAccount.signTransactionGivenSignatures(AB, [signedTxAlice, signedTxBob], networkGenerationHash);
console.log(fullySigned);
transactionHttp.announce(fullySigned).subscribe(
x => console.log(x),
err => {
console.error(err);
},
);