How to use the algosdk.mergeMultisigTransactions function in algosdk

To help you get started, we’ve selected a few algosdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github BitGo / BitGoJS / modules / core / src / v2 / coins / algo.ts View on Github external
const initialDecodedTx = Encoding.decode(txToHex);

      // we need to scrub the txn of sigs for half-signed
      const decodedTx = isHalfSigned ? initialDecodedTx.txn : initialDecodedTx;

      transaction = Multisig.MultiSigTransaction.from_obj_for_encoding(decodedTx);
    } catch (e) {
      throw new Error('transaction needs to be a valid tx encoded as base64 string');
    }

    // sign our tx
    let signed = transaction.partialSignTxn({ version: addressVersion, threshold: 2, pks: encodedPublicKeys }, sk);

    // if we have already signed it, we'll have to merge that with our previous tx
    if (isHalfSigned) {
      signed = mergeMultisigTransactions([Buffer.from(signed), txToHex]);
    }

    const signedBase64 = Buffer.from(signed).toString('base64');

    if (isHalfSigned) {
      return { txHex: signedBase64 };
    } else {
      return { halfSigned: { txHex: signedBase64 } };
    }
  }