How to use the ethereumjs-util.ecsign function in ethereumjs-util

To help you get started, we’ve selected a few ethereumjs-util 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 SpankChain / chainsaw / tests / auctionPairWiseIntegration.js View on Github external
const sign = (msgHash, privKey) => {
  if (typeof msgHash === 'string' && msgHash.slice(0, 2) === '0x') {
    msgHash = Buffer.alloc(32, msgHash.slice(2), 'hex')
  }
  const sig = ecsign(msgHash, privKey)
  return `0x${sig.r.toString('hex')}${sig.s.toString('hex')}${sig.v.toString(16)}`
}
github LayerXcom / plasma-mvp-vyper / test / helpers / transaction.js View on Github external
confirmSig(root, privateKey) {
        const vrs = utils.ecsign(
            utils.sha3(Buffer.concat([this.hash(false), root])),
            privateKey
        )
        return utils.toBuffer(utils.toRpcSig(vrs.v, vrs.r, vrs.s))
    }
github opporty-com / Plasma-Cash / client / routing / txTestController.js View on Github external
let blockNumber = parseInt(i.split('_')[1]);

            try {
                let txData = {
                    prev_hash: utxo.getHash().toString('hex'),
                    prev_block: blockNumber,
                    token_id: utxo.token_id.toString(),
                    new_owner: this.nextAddressGen.next(utxo.new_owner).value
                };
                let txDataForRlp = [ethUtil.addHexPrefix(txData.prev_hash), txData.prev_block, ethUtil.toBuffer(txData.token_id), txData.new_owner];
                let txRlpEncoded = ethUtil.hashPersonalMessage(ethUtil.sha3(RLP.encode(txDataForRlp)));

                if (utxo.new_owner instanceof Buffer)
                    utxo.new_owner = ethUtil.addHexPrefix(utxo.new_owner.toString('hex')).toLowerCase();

                let signature = ethUtil.ecsign(txRlpEncoded, prkeys[utxo.new_owner]);

                txData.signature = ethUtil.toRpcSig(signature.v, signature.r, signature.s).toString("hex");
                let createdTx = createSignedTransaction(txData);
                this.alltransactions.push(createdTx);
            } catch (e) {
                console.log(e);
            }
        }

        console.log('TXcount - ', this.alltransactions.length);
    }
github JoinColony / colonyNetwork / helpers / task-review-signing.js View on Github external
accountsJson = JSON.parse(fs.readFileSync("./ganache-accounts.json", "utf8"));
  }

  for (let i = 0; i < signers.length; i += 1) {
    let user = signers[i].toString();
    user = user.toLowerCase();

    let privKey;
    if (privKeys[i]) {
      privKey = privKeys[i];
    } else {
      privKey = accountsJson.private_keys[user];
    }

    const prefixedMessageHash = soliditySha3("\x19Ethereum Signed Message:\n\x20", msgHash);
    const sig = ecsign(Buffer.from(prefixedMessageHash.slice(2), "hex"), Buffer.from(privKey, "hex"));
    sigV.push(sig.v);
    sigR.push(`0x${sig.r.toString("hex")}`);
    sigS.push(`0x${sig.s.toString("hex")}`);
  }

  return { sigV, sigR, sigS };
}
github MyCryptoHQ / MyCrypto / common / libs / signing.ts View on Github external
export function signMessageWithPrivKeyV2(privKey: Buffer, msg: string): string {
  const hash = hashPersonalMessage(toBuffer(msg));
  const signed = ecsign(hash, privKey);
  const combined = Buffer.concat([
    Buffer.from(signed.r),
    Buffer.from(signed.s),
    Buffer.from([signed.v])
  ]);
  const combinedHex = combined.toString('hex');

  return addHexPrefix(combinedHex);
}
github LoopringSecondary / circulr / src / common / loopringjs / src / ethereum / account.js View on Github external
sign (hash)
    {
        hash = toBuffer(hash);
        const signature = ecsign(hash, this.privateKey);
        const v = toNumber(signature.v);
        const r = toHex(signature.r);
        const s = toHex(signature.s);
        return {r, s, v};
    }
github pillarwallet / pillarwallet / src / utils / common.js View on Github external
export const ethSign = (msgHex: String, privateKeyHex: string): string => {
  const message = ethUtil.toBuffer(msgHex);
  const privateKey = ethUtil.toBuffer(privateKeyHex);
  const sigParams = ethUtil.ecsign(message, privateKey);
  const result = concatSig(sigParams);

  return result;
};
github DigixGlobal / truffle-lightwallet-provider / node_modules / eth-sig-util / index.js View on Github external
personalSign: function (privateKey, msgParams) {
    var message = ethUtil.toBuffer(msgParams.data)
    var msgHash = ethUtil.hashPersonalMessage(message)
    var sig = ethUtil.ecsign(msgHash, privateKey)
    var serialized = ethUtil.bufferToHex(this.concatSig(sig.v, sig.r, sig.s))
    return serialized
  },