Fixes related to the use of accounts and signatures

This commit is contained in:
Richard Ramos 2018-10-08 14:14:19 -04:00
parent 73f2ea6b85
commit e197a66384
4 changed files with 16 additions and 18 deletions

View File

@ -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){

View File

@ -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:

View File

@ -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)

View File

@ -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,