diff --git a/src/Methods/Personal/ImportRawKey.php b/src/Methods/Personal/ImportRawKey.php new file mode 100644 index 0000000..f2c6722 --- /dev/null +++ b/src/Methods/Personal/ImportRawKey.php @@ -0,0 +1,65 @@ + + * + * @author Peter Lai + * @license MIT + */ + +namespace Web3\Methods\Personal; + +use InvalidArgumentException; +use Web3\Methods\EthMethod; +use Web3\Validators\PrivateValidator; +use Web3\Validators\StringValidator; +use Web3\Formatters\StringFormatter; + +class ImportRawKey extends EthMethod +{ + /** + * validators + * + * @var array + */ + protected $validators = [ + PrivateValidator::class, StringValidator::class + ]; + + /** + * inputFormatters + * + * @var array + */ + protected $inputFormatters = [ + PrivateValidator::class, StringFormatter::class + ]; + + /** + * outputFormatters + * + * @var array + */ + protected $outputFormatters = []; + + /** + * defaultValues + * + * @var array + */ + protected $defaultValues = []; + + /** + * construct + * + * @param string $method + * @param array $arguments + * @return void + */ + // public function __construct($method='', $arguments=[]) + // { + // parent::__construct($method, $arguments); + // } +} diff --git a/src/Personal.php b/src/Personal.php index 66db560..770004d 100644 --- a/src/Personal.php +++ b/src/Personal.php @@ -2,9 +2,9 @@ /** * This file is part of web3.php package. - * + * * (c) Kuan-Cheng,Lai - * + * * @author Peter Lai * @license MIT */ @@ -27,18 +27,18 @@ class Personal /** * methods - * + * * @var array */ private $methods = []; /** * allowedMethods - * + * * @var array */ private $allowedMethods = [ - 'personal_listAccounts', 'personal_newAccount', 'personal_unlockAccount', 'personal_lockAccount', 'personal_sendTransaction' + 'personal_listAccounts', 'personal_newAccount', 'personal_unlockAccount', 'personal_lockAccount', 'personal_sendTransaction', 'personal_importRawKey' ]; /** @@ -63,7 +63,7 @@ class Personal /** * call - * + * * @param string $name * @param array $arguments * @return void @@ -109,7 +109,7 @@ class Personal /** * get - * + * * @param string $name * @return mixed */ @@ -125,7 +125,7 @@ class Personal /** * set - * + * * @param string $name * @param mixed $value * @return mixed @@ -142,7 +142,7 @@ class Personal /** * getProvider - * + * * @return \Web3\Providers\Provider */ public function getProvider() @@ -152,7 +152,7 @@ class Personal /** * setProvider - * + * * @param \Web3\Providers\Provider $provider * @return bool */ @@ -167,7 +167,7 @@ class Personal /** * batch - * + * * @param bool $status * @return void */ diff --git a/src/Validators/PrivateValidator.php b/src/Validators/PrivateValidator.php new file mode 100644 index 0000000..57bfe8d --- /dev/null +++ b/src/Validators/PrivateValidator.php @@ -0,0 +1,31 @@ + + * + * @author Peter Lai + * @license MIT + */ + +namespace Web3\Validators; + +use Web3\Validators\IValidator; + +class PrivateValidator +{ + /** + * validate + * + * @param string $value + * @return bool + */ + public static function validate($value) + { + if (!is_string($value)) { + return false; + } + return (preg_match('/^[a-fA-F0-9]{64}$/', $value) >= 1); + } +}