How to use the ethereumjs-util.hashPersonalMessage 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 BANKEX / PlasmaETHexchange / lib / Block / blockHeader.js View on Github external
hash (includeSignature) {
    if (includeSignature === undefined) includeSignature = true

    // EIP155 spec:
    // when computing the hash of a transaction for purposes of signing or recovering,
    // instead of hashing only the first six elements (ie. nonce, gasprice, startgas, to, value, data),
    // hash nine elements, with v replaced by CHAIN_ID, r = 0 and s = 0

    let items = this.clearRaw(includeSignature);
    // return ethUtil.sha3(Buffer.concat(items));
    return ethUtil.hashPersonalMessage(Buffer.concat(items));

  }
github MyEtherWallet / MyEtherWallet / tests / unit / specs / HDWalletInterface.mnemonic.spec.js View on Github external
return new Promise(resolve => {
          const msgHash = hashPersonalMessage(toBuffer(msg));
          const signed = ecsign(
            msgHash,
            hdk.derive(ETH_PATH + '/' + i).privateKey
          );
          resolve(
            Buffer.concat([
              Buffer.from(signed.r),
              Buffer.from(signed.s),
              Buffer.from([signed.v])
            ])
          );
        });
      },
github RequestNetwork / Request_SmartContracts / test / synchrone / ethereum / requestEthereumBroadcastSignedRequestAsPayer.js View on Github external
var signHashRequest = function(hash,privateKey) {
	return ethUtil.ecsign(ethUtil.hashPersonalMessage(hash), privateKey);
}
github WalletConnect / walletconnect-demo-app / src / helpers / ethSigUtil.js View on Github external
export const personalSign = (privateKey, msgParams) => {
  const message = ethUtil.toBuffer(msgParams.data);
  const msgHash = ethUtil.hashPersonalMessage(message);
  const sig = ethUtil.ecsign(msgHash, privateKey);
  const serialized = ethUtil.bufferToHex(concatSig(sig.v, sig.r, sig.s));
  return serialized;
};
github blockmason / lndr-mobile / legacy-src / credit-protocol-client / src / credit-record.js View on Github external
sign(privateKeyBuffer) {
    const { r, s, v } = ethUtil.ecsign(
      ethUtil.hashPersonalMessage(this.creditRecord),
      privateKeyBuffer
    )

    return bufferToHex(
      Buffer.concat(
        [ r, s, Buffer.from([ v ]) ]
      )
    )
  }
}
github opporty-com / Plasma-Cash / plasma-core / src / child-chain / models / Block.js View on Github external
async function sign(block) {
  if (block.signature)
    return block;

  const _signHash = await getSignHash(block);

  let msgHash = ethUtil.hashPersonalMessage(_signHash);
  let key = Buffer.from(config.plasmaNodeKey, 'hex');
  let sig = ethUtil.ecsign(msgHash, key);
  block.signature = ethUtil.toBuffer(ethUtil.toRpcSig(sig.v, sig.r, sig.s));

  return block.signature;
}
github inblocks / precedence / common / src / signature.js View on Github external
const sign = (data, privateKey) => {
  const vrs = ecsign(hashPersonalMessage(data), Buffer.from(privateKey, 'hex'))
  return toRpcSig(vrs.v, vrs.r, vrs.s)
}
github MyEtherWallet / MyEtherWallet / src / wallets / WalletInterface.js View on Github external
return new Promise((resolve, reject) => {
      if (!this.isPubOnly) {
        const msgHash = hashPersonalMessage(Misc.toBuffer(msg));
        const signed = ecsign(msgHash, this.privateKey);
        resolve(
          Buffer.concat([
            Buffer.from(signed.r),
            Buffer.from(signed.s),
            Buffer.from([signed.v])
          ])
        );
      } else {
        signer(msg)
          .then(resolve)
          .catch(reject);
      }
    });
  }
github opporty-com / Plasma-Cash / plasma-core / cli / index.js View on Github external
function createSignTransaction(transaction) {
  let txHash = (transaction.getHash(true))
  let signature = ethUtil.ecsign(ethUtil.hashPersonalMessage(txHash),
    Buffer.from(config.privateKey, 'hex'))
  let rpcSig = ethUtil.toRpcSig(signature.v, signature.r, signature.s)
  transaction.signature = rpcSig
  return transaction
}
github MyEtherWallet / MyEtherWallet / src / wallets / software / mnemonic / mnemonicWallet.js View on Github external
async signMessageMnemonic (stringMessage) {
    try {
      if (!this.wallet) throw new Error('no wallet present. wallet may not have been decrypted')

      let msg = ethUtil.hashPersonalMessage(ethUtil.toBuffer(stringMessage))
      let signed = ethUtil.ecsign(msg, this.wallet.privKey)
      let combined = Buffer.concat([Buffer.from(signed.r), Buffer.from(signed.s), Buffer.from([signed.v])])
      let combinedHex = combined.toString('hex')
      return '0x' + combinedHex
    } catch (e) {
      return e
    }
  }