diff --git a/src/Validators/ShhFilterValidator.php b/src/Validators/ShhFilterValidator.php new file mode 100644 index 0000000..48f7faf --- /dev/null +++ b/src/Validators/ShhFilterValidator.php @@ -0,0 +1,55 @@ + + * + * @author Peter Lai + * @license MIT + */ + +namespace Web3\Validators; + +use Web3\Validators\IValidator; +use Web3\Validators\QuantityValidator; +use Web3\Validators\HexValidator; +use Web3\Validators\IdentityValidator; + +class ShhFilterValidator +{ + /** + * validate + * + * @param array $value + * @return bool + */ + public static function validate($value) + { + if (!is_array($value)) { + return false; + } + if (isset($value['to']) && IdentityValidator::validate($value['to']) === false) { + return false; + } + if (!isset($value['topics']) || !is_array($value['topics'])) { + return false; + } + foreach ($value['topics'] as $topic) { + if (is_array($topic)) { + foreach ($topic as $subTopic) { + if (HexValidator::validate($subTopic) === false) { + return false; + } + } + continue; + } + if (HexValidator::validate($topic) === false) { + if (!is_null($topic)) { + return false; + } + } + } + return true; + } +} \ No newline at end of file