Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
hash() {
return '0x' + abi.soliditySHA3(
['bytes32', 'bytes32', 'bytes32', 'bytes32', 'bytes32'],
[
this.instructionStack.hash(),
this.dataStack.hash(),
this.callStack.hash(),
this.registerVal.hash(),
this.staticVal.hash()
]).toString('hex');
}
}
export async function createComment (id, comment, address) {
let res
let userHash = `0x${soliditySHA3(['string'], [address]).toString('hex')}`
let user = address === 'anonymous' ? address : userHash.substr(2, 7)
try {
res = await axios.post(`${utilityApiURL}/create/comment`, {
id: id,
comment: comment,
address: user
})
return res
} catch (error) {
console.error(error)
}
}
static generateHash(dataArgs) {
const types = [];
const args = [];
for (const value of dataArgs) {
types.push('uint256');
args.push(new BN(value, 16));
}
return Utilities.normalizeHex(abi.soliditySHA3(types, args).toString('hex').padStart(64, '0'));
}
export function tightlyPackedKeccak256(
inputTypes: string[],
...messages: any[]
) {
return '0x' + soliditySHA3(inputTypes, messages).toString('hex');
}
composeSHA3Message(types,values) {
var ethereumjsabi = require('ethereumjs-abi');
var sha3Message = ethereumjsabi.soliditySHA3(types, values);
var msg = "0x" + sha3Message.toString("hex");
return msg;
}
function hashCollect (instance, delegate, toId, fromPayIndex, toPayIndex, amount, fee, addr) {
let hash = abi.soliditySHA3(
['address', 'uint32', 'uint32', 'uint32', 'uint32', 'uint64', 'uint64', 'address'],
[instance, delegate, toId, fromPayIndex, toPayIndex, amount, fee, addr]).toString('hex')
return '0x' + hash
}
async paymentDigest (channelId: string, value: BigNumber): Promise {
const deployed = await this.contract
const digest = abi.soliditySHA3(['address', 'bytes32', 'uint256'],
[deployed.address, channelId, value.toString()])
return '0x' + digest.toString('hex')
}
async paymentDigest (channelId: string, value: BigNumber, tokenContract: string): Promise {
const deployed = await this.contract
const digest = abi.soliditySHA3(['address', 'bytes32', 'uint256', 'address'],
[deployed.address, channelId, value.toString(), tokenContract])
return '0x' + digest.toString('hex')
}