How to use the ethereumjs-util.keccak256 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 leapdao / leap-node / src / utils / claimRewards.js View on Github external
.map(event => {
      const { owner, blocksRoot } = event.returnValues;
      slotId = event.returnValues.slotId; // eslint-disable-line prefer-destructuring

      const consenusBuf = Buffer.alloc(64, 0);
      toBuffer(blocksRoot).copy(consenusBuf);
      const consensusRoot = bufferToHex(keccak256(consenusBuf));

      const validatorBuf = Buffer.alloc(32, 0);
      validatorBuf.writeUInt8(slotId, 11);
      toBuffer(owner).copy(validatorBuf, 12);
      const validatorData = bufferToHex(validatorBuf);

      const empty = bufferToHex(Buffer.alloc(32, 0));

      return {
        consensusRoot,
        cas: empty,
        validatorData,
        rest: empty,
      };
    })
    .reduce(
github floating / frame / main / crypt / typedDataUtils.js View on Github external
const encValues = []

  // Add typehash
  encTypes.push('bytes32')
  encValues.push(typeHash(primaryType, types))

  // Add field contents
  for (const field of types[primaryType]) {
    const value = data[field.name]
    if (value === undefined) {
      throw Error(`Invalid typed data! Data for ${field.name} not found!`)
    }

    if (field.type === 'string' || field.type === 'bytes') {
      encTypes.push('bytes32')
      const valueHash = ethUtil.keccak256(value)
      encValues.push(valueHash)
    } else if (types[field.type] !== undefined) {
      encTypes.push('bytes32')
      const valueHash = ethUtil.keccak256(encodeData(field.type, types, value))
      encValues.push(valueHash)
    } else if (field.type.lastIndexOf(']') === field.type.length - 1) {
      throw new Error('Arrays currently not implemented!')
    } else {
      if (!isPrimitiveType(field.type)) {
        throw Error(`Invalid primitive type ${field.type}`)
      }

      encTypes.push(field.type)
      encValues.push(value)
    }
  }
github maticnetwork / contracts / test / helpers / deployer.js View on Github external
async deployWithdrawManager() {
    this.withdrawManager = await contracts.WithdrawManager.new()
    this.withdrawManagerProxy = await contracts.WithdrawManagerProxy.new(
      this.withdrawManager.address,
      this.registry.address,
      this.rootChain.address
    )
    await this.registry.updateContractMap(
      ethUtils.keccak256('withdrawManager'),
      this.withdrawManagerProxy.address
    )
    const w = await contracts.WithdrawManager.at(
      this.withdrawManagerProxy.address
    )
    await w.setExitNFTContract(this.exitNFT.address)
    return w
  }
github maticnetwork / contracts / scripts / eventSignatures.js View on Github external
const ethUtils = require('ethereumjs-util')

console.log(
  ethUtils.keccak256('Deposit(address,address,uint256,uint256,uint256)').toString('hex'),
  ethUtils.keccak256('Withdraw(address,address,uint256,uint256,uint256)').toString('hex'),
  ethUtils.keccak256('LogTransfer(address,address,address,uint256,uint256,uint256,uint256,uint256)').toString('hex'),
  ethUtils.keccak256('LogFeeTransfer(address,address,address,uint256,uint256,uint256,uint256,uint256)').toString('hex'),
  ethUtils.keccak256('mintWithTokenURI(address,uint256,string)').slice(0, 4).toString('hex'),
  ethUtils.keccak256('mint(address,uint256)').slice(0, 4).toString('hex')
)
github leapdao / leap-node / src / utils / claimRewards.js View on Github external
function getPeriodRoot(consensus, cas, data, rest) {
  let buf = Buffer.alloc(64, 0);
  toBuffer(data).copy(buf);
  toBuffer(rest).copy(buf, 32);
  const dataBuf = keccak256(buf);

  buf = Buffer.alloc(64, 0);
  toBuffer(cas).copy(buf);
  dataBuf.copy(buf, 32);
  const casBuf = keccak256(buf);

  buf = Buffer.alloc(64, 0);
  toBuffer(consensus).copy(buf);
  casBuf.copy(buf, 32);
  return bufferToHex(keccak256(buf));
}
github airswap / AirSwap.js / src / utils / orderUtils.js View on Github external
function hashParty(party) {
  return ethUtil.keccak256(
    abi.rawEncode(
      ['bytes32', 'address', 'address', 'uint256'],
      [PARTY_TYPEHASH, party.wallet, party.token, party.param],
    ),
  )
}
github ConsenSys / stow-js / src / record.js View on Github external
verifyData(plaintext) {
    return eutil.bufferToHex(eutil.keccak256(plaintext)) === this.dataHash;
  }
github merklejerk / flex-contract / src / index.js View on Github external
async function getCodeDigest(inst, opts={}) {
	opts = _.defaults({}, opts, {
		address: inst._address
	});
	const address = await inst._eth.resolve(opts.address || opts.to);
	if (!address)
		throw new Error('Cannot determine contract adress and it was not provided.');
	const code = await inst._eth.getCode(address, opts.block);
	return util.toHex(ethjs.keccak256(
		Buffer.from(util.stripHexPrefix(code), 'hex')));
}
github celo-org / celo-monorepo / packages / contractkit / src / wrappers / TransactionBuilder.ts View on Github external
get hash(): Buffer {
    const encoded = this.encoded
    return keccak256(
      this.kit.web3.eth.abi.encodeParameters(
        ['uint256[]', 'address[]', 'bytes', 'uint256[]'],
        [encoded.values, encoded.destinations, encoded.data, encoded.dataLengths]
      )
    ) as Buffer
  }