Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
} catch (err) {
end(err);
}
return;
case 'eth_accounts':
try {
const accounts = await this._web3Wrapper.getAvailableAddressesAsync();
end(null, accounts);
} catch (err) {
end(err);
}
return;
case 'eth_sendTransaction':
const [txParams] = payload.params;
try {
const txData = marshaller.unmarshalTxData(txParams);
const txHash = await this._web3Wrapper.sendTransactionAsync(txData);
end(null, txHash);
} catch (err) {
end(err);
}
return;
case 'eth_sign':
[address, message] = payload.params;
try {
// Metamask incorrectly implements eth_sign and does not prefix the message as per the spec
// Source: https://github.com/MetaMask/metamask-extension/commit/a9d36860bec424dcee8db043d3e7da6a5ff5672e
const msgBuff = ethUtil.toBuffer(message);
const prefixedMsgBuff = ethUtil.hashPersonalMessage(msgBuff);
const prefixedMsgHex = ethUtil.bufferToHex(prefixedMsgBuff);
const signature = await this._web3Wrapper.signMessageAsync(address, prefixedMsgHex);
signature ? end(null, signature) : end(new Error('Error performing eth_sign'), null);
} catch (err) {
end(err);
}
return;
case 'eth_accounts':
try {
const accounts = await this._web3Wrapper.getAvailableAddressesAsync();
end(null, accounts);
} catch (err) {
end(err);
}
return;
case 'eth_sendTransaction':
const [txParams] = payload.params;
try {
const txData = marshaller.unmarshalTxData(txParams);
const txHash = await this._web3Wrapper.sendTransactionAsync(txData);
end(null, txHash);
} catch (err) {
end(err);
}
return;
case 'eth_sign':
[address, message] = payload.params;
try {
const signature = await this._web3Wrapper.signMessageAsync(address, message);
end(null, signature);
} catch (err) {
end(err);
}
return;
case 'eth_signTypedData':