How to use the js-sha3.keccak256.arrayBuffer function in js-sha3

To help you get started, we’ve selected a few js-sha3 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 AdExNetwork / adex-protocol-eth / js / Channel.js View on Github external
Channel.prototype.hash = function(contractAddr) {
	// contains contractAddr, so that it's not replayable
	if (!contractAddr) throw 'contractAddr required'
	return new Buffer(keccak256.arrayBuffer(
		abi.rawEncode(
			['address', 'address', 'address', 'uint256', 'uint256', 'address[]', 'bytes32'],
			[contractAddr, this.creator, this.tokenAddr, this.tokenAmount, this.validUntil, this.validators, this.spec]
		)
	))
}
github AdExNetwork / adex-protocol-eth / js / IdentityDeploy.js View on Github external
function getContractAddrWithZeroNonce(deployAddr) {
	// Calculate the id.address in advance
	// really, we need to concat 0xd694{address}00
	// same as require('rlp').encode([relayerAddr, 0x00]) or ethers.utils.RPL.encode([relayerAddr, ... (dunno what)])
	// @TODO: move this out into js/Identity
	const rlpEncodedInput = Buffer.concat([
		// rpl encoding values
		Buffer.from(new Uint8Array([0xd6, 0x94])),
		// sender
		Buffer.from(deployAddr.slice(2), 'hex'),
		// nonce (0x80 is equivalent to nonce 0)
		Buffer.from(new Uint8Array([0x80])),
	])
	const digest = new Buffer(keccak256.arrayBuffer(rlpEncodedInput))
	return utils.getAddress('0x'+digest.slice(-20).toString('hex'))
}
github dogethereum / dogethereum-contracts / test / utils.js View on Github external
function calcSuperblockHash(merkleRoot, accumulatedWork, timestamp, prevTimestamp, lastHash, lastBits, parentId) {
  return `0x${Buffer.from(keccak256.arrayBuffer(
    Buffer.concat([
      module.exports.fromHex(merkleRoot),
      module.exports.fromHex(toUint256(accumulatedWork)),
      module.exports.fromHex(toUint256(timestamp)),
      module.exports.fromHex(toUint256(prevTimestamp)),
      module.exports.fromHex(lastHash),
      module.exports.fromHex(toUint32(lastBits)),
      module.exports.fromHex(parentId)
    ])
  )).toString('hex')}`;
}
github dogethereum / dogethereum-contracts / test / utils.js View on Github external
function ethAddressFromKeyPair(keyPair) {
  const uncompressedPublicKey = bitcoin.ECPair.fromPublicKey(keyPair.publicKey, { compressed: false });
  return `0x${Buffer.from(keccak256.arrayBuffer(uncompressedPublicKey.publicKey.slice(1))).slice(12).toString('hex')}`;
}
github AdExNetwork / adex-protocol-eth / js / Channel.js View on Github external
Channel.getSignableStateRoot = function(channelId, balanceRoot) {
	return Buffer.from(
		keccak256.arrayBuffer(
			abi.rawEncode(['bytes32', 'bytes32'], [ channelId, balanceRoot ])
		)
	)
}
github AdExNetwork / adex-protocol-eth / js / Identity.js View on Github external
Transaction.prototype.hash = function() {
	const buf = abi.rawEncode(
		['address', 'uint256', 'address', 'uint256', 'address', 'uint256', 'bytes'],
		[
			this.identityContract,
			this.nonce,
			this.feeTokenAddr,
			this.feeAmount,
			this.to,
			this.value,
			this.data
		]
	)
	return Buffer.from(keccak256.arrayBuffer(buf))
}