From e197a66384759934e37e6f7be07ffe2512431598 Mon Sep 17 00:00:00 2001 From: Richard Ramos Date: Mon, 8 Oct 2018 14:14:19 -0400 Subject: [PATCH] Fixes related to the use of accounts and signatures --- gas-relayer/src/message-processor.js | 3 +-- gas-relayer/src/service.js | 7 ++++--- test-dapp/app/components/transfersnt.js | 17 +++++++---------- test-dapp/app/status-gas-relayer.js | 7 ++++--- 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/gas-relayer/src/message-processor.js b/gas-relayer/src/message-processor.js index 9a58976..be2a663 100644 --- a/gas-relayer/src/message-processor.js +++ b/gas-relayer/src/message-processor.js @@ -66,8 +66,7 @@ class MessageProcessor { const inputValidation = await this._validateInput(contract, input); if(!inputValidation.success){ // TODO Log? - reply(inputValidation); - return; + return inputValidation; } if(strategy || contract.strategy){ diff --git a/gas-relayer/src/service.js b/gas-relayer/src/service.js index 73764ab..0284413 100644 --- a/gas-relayer/src/service.js +++ b/gas-relayer/src/service.js @@ -159,10 +159,10 @@ events.on('server:listen', (shhOptions, settings) => { const input = extractInput(message); const inputCheckSum = JSum.digest({input}, 'SHA256', 'hex'); - + const reply = replyFunction(message, inputCheckSum); - if(cache.get(inputCheckSum)){ + if(cache.get(inputCheckSum) && input.action != 'availability'){ reply("Duplicated message received"); } else { let validationResult; @@ -180,8 +180,9 @@ events.on('server:listen', (shhOptions, settings) => { ); if(validationResult.success && validationResult.message) { cache.put(inputCheckSum, (new Date().getTime()), 86400000); - reply(validationResult.message); } + reply(validationResult.message); + break; default: diff --git a/test-dapp/app/components/transfersnt.js b/test-dapp/app/components/transfersnt.js index ed8dca4..f3d6cbe 100644 --- a/test-dapp/app/components/transfersnt.js +++ b/test-dapp/app/components/transfersnt.js @@ -35,6 +35,7 @@ class TransferSNT extends Component { super(props); this.state = { topic: '0x534e5443', + account: '', to: '0x0000000000000000000000000000000000000000', amount: 0, gasPrice: 0, @@ -80,9 +81,9 @@ class TransferSNT extends Component { try { - const accounts = await web3.eth.getAccounts(); - - const s = new StatusGasRelayer.SNTController(SNTController.options.address, accounts[0]) + this.setState({account: web3.eth.defaultAccount}); + + const s = new StatusGasRelayer.SNTController(SNTController.options.address, web3.eth.defaultAccount) .transferSNT(this.state.to, this.state.amount) .setGas(this.state.gasPrice); @@ -95,7 +96,7 @@ class TransferSNT extends Component { } } - obtainRelayers = async event => { + obtainRelayers = async (event) => { event.preventDefault(); const {web3, kid, skid} = this.props; @@ -108,9 +109,7 @@ class TransferSNT extends Component { try { - const accounts = await web3.eth.getAccounts(); - - const s = new StatusGasRelayer.AvailableRelayers(Contracts.SNT, SNTController.options.address, accounts[0]) + const s = new StatusGasRelayer.AvailableRelayers(Contracts.SNT, SNTController.options.address, this.state.account) .setRelayersSymKeyID(skid) .setAsymmetricKeyID(kid) .setGas(STT.options.address, this.state.gasPrice); @@ -148,9 +147,7 @@ class TransferSNT extends Component { this.props.clearMessages(); try { - const accounts = await web3.eth.getAccounts(); - - const s = new StatusGasRelayer.SNTController(SNTController.options.address, accounts[0]) + const s = new StatusGasRelayer.SNTController(SNTController.options.address, this.state.account) .transferSNT(this.state.to, this.state.amount) .setGas(this.state.gasPrice) .setRelayer(relayer) diff --git a/test-dapp/app/status-gas-relayer.js b/test-dapp/app/status-gas-relayer.js index 386e8bf..9421cfb 100644 --- a/test-dapp/app/status-gas-relayer.js +++ b/test-dapp/app/status-gas-relayer.js @@ -25,6 +25,7 @@ export const Messages = { const relayerSymmmetricKeyID = "0xd0d905c1c62b810b787141430417caf2b3f54cffadb395b7bb39fdeb8f17266b"; const emptyBytesSha = "0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"; + class StatusGasRelayer { constructor(build, web3) { if (arguments.length !== 2 || !this.validateBuild(build)) throw new Error("Invalid build"); @@ -246,7 +247,7 @@ class IdentityGasRelayedAction extends Action { throw new Error("Function not allowed"); } - const signedMessage = await web3.eth.sign(hashedMessage, this.accountAddress); + const signedMessage = await web3.eth.personal.sign(hashedMessage, this.accountAddress); return signedMessage; } @@ -371,7 +372,7 @@ class SNTControllerAction extends Action { throw new Error("Function not allowed"); } - const signedMessage = await web3.eth.sign(hashedMessage, this.accountAddress); + const signedMessage = await web3.eth.personal.sign(hashedMessage, this.accountAddress); return signedMessage; } @@ -410,7 +411,7 @@ class SNTControllerAction extends Action { default: throw new Error("Function not allowed"); } - + return { 'contract': this.contractAddress, 'address': this.accountAddress,