Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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]
)
))
}
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'))
}
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')}`;
}
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')}`;
}
Channel.getSignableStateRoot = function(channelId, balanceRoot) {
return Buffer.from(
keccak256.arrayBuffer(
abi.rawEncode(['bytes32', 'bytes32'], [ channelId, balanceRoot ])
)
)
}
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))
}