How to use the web3.sha3 function in web3

To help you get started, we’ve selected a few web3 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 ConsenSys / reflux-tx / test / utils / mocketh.js View on Github external
var mocketh = function(chainName, blockTime) {
	this.chainId = 0;
	this.blockNumber = 0;

	try {
		this.chain = chains[chainName];
	} catch (e) {
		throw new Error('Could not find chain ' + chainName + ' in chain.json spec file');
	}

	this.chainHash = web3.sha3(JSON.stringify(this.chain));
	this.blockTime = blockTime;
	if (!blockTime) this.blockTime = 500;

	this.running = true;
	this.block = this.Block(this.chainId, this.blockNumber);
	this.blockHashMap = {};
	this.blockCallbacks = [];
	this.blocks = {};
	this.blocks[this.block.hash] = this.block;
	this.filterCallback = null;

	this.getTransactionReceipt.request = this.request('getTransactionReceipt');
	this.getTransaction.request = this.request('getTransaction');

	// Fake the chain here
	this.blockInterval = setInterval(this.incChain.bind(this), this.blockTime);
github ConsenSys / reflux-tx / test / utils / mocketh.js View on Github external
mocketh.prototype.TransactionReceipt = function(spec) {
	return {
		transactionHash: web3.sha3(JSON.stringify(spec)),
		blockNumber: spec.reception[this.chainId]
	};
}
github ConsenSys / reflux-tx / test / utils / mocketh.js View on Github external
mocketh.prototype.getAddress = function(index) {
	var hash = web3.sha3(index.toString());
	if (hash.slice(0, 2) === '0x')
		return hash.slice(0, 42);
	else
		return hash.slice(0, 40);
}
github ConsenSys / reflux-tx / test / utils / mocketh.js View on Github external
mocketh.prototype.Transaction = function(spec) {
	return {
		hash: web3.sha3(JSON.stringify(spec)),
		nonce: spec.nonce,
		from: this.getAddress(spec.from || 0)
	};
}
github ConsenSys / reflux-tx / test / utils / mocketh.js View on Github external
mocketh.prototype.blockHash = function (chainId, number) {
	return web3.sha3(this.chainHash + ':' + chainId + ':' +  number);
}
github ConsenSys / reflux-tx / test / utils / test_helper.js View on Github external
function validateTxReceipt(err, receipt, tx) {
    assert.isNull(err);
    assert.equal(receipt.transactionHash, web3.sha3(JSON.stringify(tx)));
    assert.equal(receipt.blockNumber, tx.reception[web3.eth.chainId]);
}
github ConsenSys / reflux-tx / test / utils / test_helper.js View on Github external
function getHash(tx) {
  return web3.sha3(JSON.stringify(tx));
}
github validitylabs / hopr / src / utils.js View on Github external
module.exports.hash = function (buf) {
    if (!Buffer.isBuffer(buf))
        throw Error('Invalid input. Please use a Buffer')

    return Buffer.from(sha3(buf).slice(2), 'hex')
}
github James-Sangalli / metamask-passport-client / index.js View on Github external
function signChallengeResponse(challengeMessage)
    {
        let messageHashed = web3.sha3(challengeMessage);
        let abi = getAbiEncoding(type);
        let contract = web3.eth.contract(abi).at(contractAddress);
        contract.balanceOf.call(account, (err, bal) => {
            if(bal == 0)
            {
                alert("you do not hold a valid token to enter, please try again");
                window.location.reload(false);
                return;
            }
            web3.eth.sign(account, messageHashed, (err, signature) => {
                request.post(serverUrl + messageHashed + "/" + signature, (err, callback) => {
                    if (err) {
                        alert(err);
                        return;
                    }
                    //handle redirect to service