How to use the ethereumjs-util.fromRpcSig 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 dydxprotocol / protocol_v1 / test / helpers / ZeroExV2Helper.js View on Github external
async function signV2Order(order) {
  const signature = await promisify(web3Instance.eth.sign)(
    getV2OrderHash(order), order.makerAddress
  );

  const { v, r, s } = ethUtil.fromRpcSig(signature);

  // 0x00 Illegal
  // 0x01 Invalid
  // 0x02 EIP712 (no prepended string)
  // 0x03 EthSign (prepended "\x19Ethereum Signed Message:\n32")
  // 0x04 Wallet
  // 0x05 Validator
  // 0x06 PreSigned
  // 0x07 NSignatureTypes
  const sigType = 3;

  return ethUtil.bufferToHex(
    Buffer.concat([
      ethUtil.toBuffer(v),
      r,
      s,
github eolszewski / simple-payment-channel / test / utils.js View on Github external
async function recoverSigner(message, signature) {
  let split = util.fromRpcSig(signature);
  let publicKey = util.ecrecover(message, split.v, split.r, split.s);
  let signer = util.pubToAddress(publicKey).toString("hex");
  return signer;
}
github James-Sangalli / xcontract / public / javascripts / Web3Handler.js View on Github external
verify: (web3, message, signature, cb) =>
    {
        try
        {
            message = web3.sha3(message);
            const {v, r, s} = utils.fromRpcSig(signature);
            let m = utils.toBuffer(message);
            let pub = utils.ecrecover(m, v, r, s);
            let adr = '0x' + utils.pubToAddress(pub).toString('hex');
            cb(adr);
        }
        catch(e)
        {
            console.log("verify error: " + e);
        }
    },
github ProjectOpenSea / opensea-js / src / utils.ts View on Github external
function _parseSignatureHexAsRSV(signatureHex: string) {
    const { v, r, s } = ethUtil.fromRpcSig(signatureHex)
    const ecSignature = {
        v,
        r: ethUtil.bufferToHex(r),
        s: ethUtil.bufferToHex(s),
    }
    return ecSignature
  }
}
github poetapp / frost-api / src / helpers / ethereum.ts View on Github external
export function signatureIsValid(address: string, message: string, signature: string): boolean {
  if (!address || !signature)
    return false

  try {
    const msgHash = hashPersonalMessage(Buffer.from(message))

    const signatureParams = fromRpcSig(signature)
    const publicKey = ecrecover(
      msgHash,
      signatureParams.v,
      signatureParams.r,
      signatureParams.s,
    )
    const addressBuffer = publicToAddress(publicKey)
    const addressVerified = bufferToHex(addressBuffer)

    return addressVerified.toLowerCase() === address.toLowerCase()
  } catch (exception) {
    if (exception.message === 'Invalid signature length')
      return false
    else if (exception.message === 'couldn\'t recover public key from signature')
      return false
    else
github ProjectOpenSea / opensea-js / lib / wyvern.js View on Github external
function _parseSignatureHexAsRSV(signatureHex) {
        var _a = ethUtil.fromRpcSig(signatureHex), v = _a.v, r = _a.r, s = _a.s;
        var ecSignature = {
            v: v,
            r: ethUtil.bufferToHex(r),
            s: ethUtil.bufferToHex(s),
        };
        return ecSignature;
    }
}
github WalletConnect / walletconnect-example-dapp / src / helpers / utilities.ts View on Github external
export function recoverPublicKey(sig: string, hash: string): string {
  const sigParams = ethUtil.fromRpcSig(sig);
  const hashBuffer = ethUtil.toBuffer(hash);
  const result = ethUtil.ecrecover(
    hashBuffer,
    sigParams.v,
    sigParams.r,
    sigParams.s
  );
  const signer = ethUtil.bufferToHex(ethUtil.publicToAddress(result));
  return signer;
}
github zachd / ethereum-identity-research / app / javascripts / app.js View on Github external
function verifyAttribute(attribute, RPCsig) {
  var hash = ethUtils.sha3(attribute);
  var sig = ethUtils.fromRpcSig(RPCsig);
  var pubkey = ethUtils.ecrecover(hash, sig.v, sig.r, sig.s);
  return '0x' + ethUtils.publicToAddress(pubkey).toString('hex');
}
github eolszewski / ipfs-pubsub-chatroom / src / utils.js View on Github external
async function recoverSigner(message, signature) {
  let split = util.fromRpcSig(signature);
  let publicKey = util.ecrecover(message, split.v, split.r, split.s);
  let signer = util.pubToAddress(publicKey).toString("hex");
  return signer;
}
github kangarang / tcr-ui / src / utils / signing_utils.js View on Github external
parseSignatureHexAsRSV(signatureHex) {
    const { v, r, s } = ethUtil.fromRpcSig(signatureHex)
    const ecSignature = {
      v,
      r: ethUtil.bufferToHex(r),
      s: ethUtil.bufferToHex(s),
    }
    return ecSignature
  },
}