Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
mocketh.prototype.TransactionReceipt = function(spec) {
return {
transactionHash: web3.sha3(JSON.stringify(spec)),
blockNumber: spec.reception[this.chainId]
};
}
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);
}
mocketh.prototype.Transaction = function(spec) {
return {
hash: web3.sha3(JSON.stringify(spec)),
nonce: spec.nonce,
from: this.getAddress(spec.from || 0)
};
}
mocketh.prototype.blockHash = function (chainId, number) {
return web3.sha3(this.chainHash + ':' + chainId + ':' + number);
}
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]);
}
function getHash(tx) {
return web3.sha3(JSON.stringify(tx));
}
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')
}
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