Additional verification for availability strategy to check instances
This commit is contained in:
parent
a94f810382
commit
0683317821
|
@ -9,6 +9,8 @@ const winston = require('winston');
|
||||||
const cache = require('memory-cache');
|
const cache = require('memory-cache');
|
||||||
const accountParser = require('./account-parser');
|
const accountParser = require('./account-parser');
|
||||||
|
|
||||||
|
var pubKey;
|
||||||
|
|
||||||
// Setting up logging
|
// Setting up logging
|
||||||
const wLogger = winston.createLogger({
|
const wLogger = winston.createLogger({
|
||||||
level: 'info',
|
level: 'info',
|
||||||
|
@ -92,7 +94,7 @@ events.on('setup:complete', async (settings) => {
|
||||||
shhOptions.kId = await web3.shh.newKeyPair();
|
shhOptions.kId = await web3.shh.newKeyPair();
|
||||||
|
|
||||||
const symKeyID = await web3.shh.addSymKey(config.node.whisper.symKey);
|
const symKeyID = await web3.shh.addSymKey(config.node.whisper.symKey);
|
||||||
const pubKey = await web3.shh.getPublicKey(shhOptions.kId);
|
pubKey = await web3.shh.getPublicKey(shhOptions.kId);
|
||||||
|
|
||||||
// Listening to whisper
|
// Listening to whisper
|
||||||
// Individual subscriptions due to https://github.com/ethereum/web3.js/issues/1361
|
// Individual subscriptions due to https://github.com/ethereum/web3.js/issues/1361
|
||||||
|
@ -183,14 +185,16 @@ events.on('server:listen', (shhOptions, settings) => {
|
||||||
let validationResult;
|
let validationResult;
|
||||||
switch(input.action){
|
switch(input.action){
|
||||||
case 'transaction':
|
case 'transaction':
|
||||||
processor.processTransaction(settings.getContractByTopic(message.topic),
|
if(message.recipientPublicKey === pubKey){
|
||||||
input,
|
processor.processTransaction(settings.getContractByTopic(message.topic),
|
||||||
reply,
|
input,
|
||||||
account,
|
reply,
|
||||||
() => {
|
account,
|
||||||
cache.put(inputCheckSum, (new Date().getTime()), 3600000);
|
() => {
|
||||||
}
|
cache.put(inputCheckSum, (new Date().getTime()), 3600000);
|
||||||
);
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'availability':
|
case 'availability':
|
||||||
validationResult = await processor.processStrategy(settings.getContractByTopic(message.topic),
|
validationResult = await processor.processStrategy(settings.getContractByTopic(message.topic),
|
||||||
|
|
|
@ -12,6 +12,14 @@ class AvailabilityStrategy extends Strategy {
|
||||||
* @returns {object} Status of validation, and minimum price
|
* @returns {object} Status of validation, and minimum price
|
||||||
*/
|
*/
|
||||||
async execute(input, cache){
|
async execute(input, cache){
|
||||||
|
|
||||||
|
if(this.contract.isIdentity){
|
||||||
|
let validInstance = await this._validateInstance(input);
|
||||||
|
if(!validInstance){
|
||||||
|
return {success: false, message: "Invalid identity instance"};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Verifying if token is allowed
|
// Verifying if token is allowed
|
||||||
const token = this.settings.getToken(input.gasToken);
|
const token = this.settings.getToken(input.gasToken);
|
||||||
if(token == undefined) return {success: false, message: "Token not allowed"};
|
if(token == undefined) return {success: false, message: "Token not allowed"};
|
||||||
|
|
|
@ -7,6 +7,25 @@ const erc20ABI = require('../../abi/ERC20Token.json');
|
||||||
*/
|
*/
|
||||||
class BaseStrategy {
|
class BaseStrategy {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates if the contract being invoked represents an instance created via factory
|
||||||
|
* @param {object} input - Object obtained from a `transaction` request.
|
||||||
|
* @returns {bool} Valid instance or not
|
||||||
|
*/
|
||||||
|
async _validateInstance(input){
|
||||||
|
const instanceCodeHash = this.web3.utils.soliditySha3(await this.web3.eth.getCode(input.contract));
|
||||||
|
const kernelVerifSignature = this.web3.utils.soliditySha3(this.contract.kernelVerification).slice(0, 10);
|
||||||
|
|
||||||
|
if(instanceCodeHash === null) return false;
|
||||||
|
|
||||||
|
let verificationResult = await this.web3.eth.call({
|
||||||
|
to: this.contract.factoryAddress,
|
||||||
|
data: kernelVerifSignature + instanceCodeHash.slice(2)});
|
||||||
|
|
||||||
|
return this.web3.eth.abi.decodeParameter('bool', verificationResult);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {object} web3 - Web3 object already configured
|
* @param {object} web3 - Web3 object already configured
|
||||||
* @param {object} config - Configuration object obtained from `./config/config.js`
|
* @param {object} config - Configuration object obtained from `./config/config.js`
|
||||||
|
|
|
@ -10,23 +10,6 @@ const ApproveAndCallGasRelayed = "0x59f4ac61";
|
||||||
*/
|
*/
|
||||||
class IdentityStrategy extends Strategy {
|
class IdentityStrategy extends Strategy {
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates if the contract being invoked represents an Identity instance
|
|
||||||
* @param {object} input - Object obtained from a `transaction` request.
|
|
||||||
* @returns {bool} Valid instance or not
|
|
||||||
*/
|
|
||||||
async _validateInstance(input){
|
|
||||||
const instanceCodeHash = this.web3.utils.soliditySha3(await this.web3.eth.getCode(input.contract));
|
|
||||||
const kernelVerifSignature = this.web3.utils.soliditySha3(this.contract.kernelVerification).slice(0, 10);
|
|
||||||
|
|
||||||
if(instanceCodeHash === null) return false;
|
|
||||||
|
|
||||||
let verificationResult = await this.web3.eth.call({
|
|
||||||
to: this.contract.factoryAddress,
|
|
||||||
data: kernelVerifSignature + instanceCodeHash.slice(2)});
|
|
||||||
|
|
||||||
return this.web3.eth.abi.decodeParameter('bool', verificationResult);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Process Identity strategy
|
* Process Identity strategy
|
||||||
|
|
|
@ -52,6 +52,7 @@ contract IdentityFactory is Factory {
|
||||||
{
|
{
|
||||||
IdentityKernel instance = IdentityKernel(new DelayedUpdatableInstance(address(latestKernel)));
|
IdentityKernel instance = IdentityKernel(new DelayedUpdatableInstance(address(latestKernel)));
|
||||||
|
|
||||||
|
// Saving hash for version in case it does not exist
|
||||||
bytes32 codeHash = getCodeHash(address(instance));
|
bytes32 codeHash = getCodeHash(address(instance));
|
||||||
if(hashToVersion[codeHash] == 0){
|
if(hashToVersion[codeHash] == 0){
|
||||||
hashToVersion[codeHash] = versionLog.length;
|
hashToVersion[codeHash] = versionLog.length;
|
||||||
|
|
Loading…
Reference in New Issue