lib/transaction.js
function signTx(_txObj, i, privKey) {
  var compressPubKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  var hashcode = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : zconstants.SIGHASH_ALL;

  // Make a copy
  var txObj = JSON.parse(JSON.stringify(_txObj));

  // Prepare our signature
  // Get script from the current tx input
  var script = txObj.ins[i].prevScriptPubKey;

  // Populate current tx in with the prevScriptPubKey
  var signingTx = signatureForm(txObj, i, script, hashcode);

  // Get script signature
  var scriptSig = getScriptSignature(privKey, signingTx, hashcode);

  // Chuck it back into txObj and add pubkey
  // Protocol:
  // PUSHDATA
  // signature data and SIGHASH_ALL
  // PUSHDATA
  // public key data
  var pubKey = zaddress.privKeyToPubKey(privKey, compressPubKey);

  txObj.ins[i].script = zbufferutils.getPushDataLength(scriptSig) + scriptSig + zbufferutils.getPushDataLength(pubKey) + pubKey;

  return txObj;
}
function signTx(_txObj, i, privKey) {
  var compressPubKey = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
  var hashcode = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : zconstants.SIGHASH_ALL;

  // Make a copy
  var txObj = JSON.parse(JSON.stringify(_txObj));

  // Prepare our signature
  // Get script from the current tx input
  var script = txObj.ins[i].prevScriptPubKey;

  // Populate current tx in with the prevScriptPubKey
  var signingTx = signatureForm(txObj, i, script, hashcode);

  // Get script signature
  var scriptSig = getScriptSignature(privKey, signingTx, hashcode);

  // Chuck it back into txObj and add pubkey
  // Protocol:
  // PUSHDATA
  // signature data and SIGHASH_ALL
  // PUSHDATA
  // public key data
  var pubKey = zaddress.privKeyToPubKey(privKey, compressPubKey);

  txObj.ins[i].script = zbufferutils.getPushDataLength(scriptSig) + scriptSig + zbufferutils.getPushDataLength(pubKey) + pubKey;

  return txObj;
}
function signTx ( _txObj , i , privKey ) { var compressPubKey = arguments . length > 3 && arguments [ 3 ] !== undefined ? arguments [ 3 ] : false ; var hashcode = arguments . length > 4 && arguments [ 4 ] !== undefined ? arguments [ 4 ] : zconstants . SIGHASH_ALL ; // Make a copy var txObj = JSON . parse ( JSON . stringify ( _txObj ) ) ; // Prepare our signature // Get script from the current tx input var script = txObj . ins [ i ] . prevScriptPubKey ; // Populate current tx in with the prevScriptPubKey var signingTx = signatureForm ( txObj , i , script , hashcode ) ; // Get script signature var scriptSig = getScriptSignature ( privKey , signingTx , hashcode ) ; // Chuck it back into txObj and add pubkey // Protocol: // PUSHDATA // signature data and SIGHASH_ALL // PUSHDATA // public key data var pubKey = zaddress . privKeyToPubKey ( privKey , compressPubKey ) ; txObj . ins [ i ] . script = zbufferutils . getPushDataLength ( scriptSig ) + scriptSig + zbufferutils . getPushDataLength ( pubKey ) + pubKey ; return txObj ; }
/*
Signs the raw transaction
@param {String} rawTx raw transaction
@param {Int} i
@param {privKey} privKey (not WIF format)
@param {compressPubKey} compress public key before appending to scriptSig? (default false)
@param {hashcode} hashcode (default SIGHASH_ALL)
return {String} signed transaction
/ * Signs the raw transaction