Adding logic to obtain signatures

This commit is contained in:
Richard Ramos 2018-09-01 00:45:28 -04:00
parent 3f56fd4676
commit 69e8167499
2 changed files with 45 additions and 29 deletions

View File

@ -70,7 +70,7 @@ class CallGasRelayed extends Component {
}); });
}; };
sign = (event) => { sign = async (event) => {
if(event) event.preventDefault(); if(event) event.preventDefault();
this.setState({ this.setState({
@ -78,25 +78,15 @@ class CallGasRelayed extends Component {
transactionError: '' transactionError: ''
}); });
IdentityGasRelay.options.address = this.props.identityAddress;
try { try {
IdentityGasRelay.methods.callGasRelayHash(
this.state.to, const s = new StatusGasRelayer.Identity(this.props.identityAddress, web3.eth.defaultAccount)
this.state.value, .setTransaction(this.state.to, this.state.value, this.state.data)
web3.utils.soliditySha3({t: 'bytes', v: this.state.data}), .setGas(this.state.gasToken, this.state.gasPrice, this.state.gasLimit);
this.props.nonce,
this.state.gasPrice, const signature = await s.sign(web3);
this.state.gasLimit,
this.state.gasToken
)
.call()
.then(message => {
return web3.eth.sign(message, web3.eth.defaultAccount);
})
.then(signature => {
this.setState({signature}); this.setState({signature});
});
} catch(error){ } catch(error){
this.setState({transactionError: error.message}); this.setState({transactionError: error.message});
} }

View File

@ -8,12 +8,12 @@ export const Functions = {
'call': 'callGasRelayed', 'call': 'callGasRelayed',
'approveAndCall': 'approveAndCallGasRelayed' 'approveAndCall': 'approveAndCallGasRelayed'
} }
} };
export const Actions = { export const Actions = {
'Availability': 'availability', 'Availability': 'availability',
'Transaction': 'transaction' 'Transaction': 'transaction'
} };
const relayerSymmmetricKeyID = "0xd0d905c1c62b810b787141430417caf2b3f54cffadb395b7bb39fdeb8f17266b"; const relayerSymmmetricKeyID = "0xd0d905c1c62b810b787141430417caf2b3f54cffadb395b7bb39fdeb8f17266b";
@ -65,16 +65,23 @@ class StatusGasRelayer {
payload: this.web3.utils.toHex(this.message) payload: this.web3.utils.toHex(this.message)
}; };
return await web3.shh.post(sendOptions); const msgId = await this.web3.shh.post(sendOptions);
return msgId;
} }
validateBuild = (build) => { validateBuild = (build) => {
return (String(build.constructor) === String(StatusGasRelayer.AvailableRelayers)); return (String(build.constructor) === String(StatusGasRelayer.AvailableRelayers) ||
String(build.constructor) === String(StatusGasRelayer.Identity)
);
} }
static get AvailableRelayers() { static get AvailableRelayers() {
return AvailableRelayersAction; return AvailableRelayersAction;
} }
static get Identity() {
return IdentityGasRelayedAction;
}
} }
class Action { class Action {
@ -120,14 +127,35 @@ class IdentityGasRelayedAction extends Action {
return this; return this;
} }
getNonce = async (web3) => { _nonce = async(contract) => {
const contract = web3.eth.contract(identityGasRelayABI, this.contractAddress);
const nonce = await contract.methods.nonce().call(); const nonce = await contract.methods.nonce().call();
return nonce; return nonce;
} }
sign = (web3) => { getNonce = async (web3) => {
const contract = new web3.eth.Contract(identityGasRelayABI, this.contractAddress);
const nonce = await this._nonce(contract);
return nonce;
}
sign = async (web3) => {
const contract = new web3.eth.Contract(identityGasRelayABI, this.contractAddress);
const nonce = await this._nonce(contract);
// TODO: this depends of the operation to execute
const hashedMessage = await contract.methods.callGasRelayHash(
this.to,
this.value,
web3.utils.soliditySha3({t: 'bytes', v: this.data}),
nonce,
this.gasPrice,
this.gasLimit,
this.gasToken
).call();
const signature = await web3.eth.sign(hashedMessage, this.accountAddress);
return signature;
} }
_getMessage = async web3 => { _getMessage = async web3 => {
@ -166,8 +194,6 @@ class AvailableRelayersAction extends Action {
} }
} }
const identityGasRelayABI = [ const identityGasRelayABI = [
{ {
"constant": true, "constant": true,