fix importRawKey
This commit is contained in:
parent
79aafa21fa
commit
4fcb583f1f
36
src/Formatters/PrivateFormatter.php
Normal file
36
src/Formatters/PrivateFormatter.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* This file is part of web3.php package.
|
||||
*
|
||||
* (c) Kuan-Cheng,Lai <alk03073135@gmail.com>
|
||||
*
|
||||
* @author Peter Lai <alk03073135@gmail.com>
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
namespace Web3\Formatters;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Web3\Utils;
|
||||
use Web3\Formatters\IFormatter;
|
||||
|
||||
class PrivateFormatter implements IFormatter
|
||||
{
|
||||
/**
|
||||
* format
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return string
|
||||
*/
|
||||
public static function format($value)
|
||||
{
|
||||
$value = Utils::toString($value);
|
||||
$value = mb_strtolower($value);
|
||||
|
||||
if (Utils::isZeroPrefixed($value)) {
|
||||
$value = Utils::stripZero($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
}
|
@ -16,6 +16,7 @@ use Web3\Methods\EthMethod;
|
||||
use Web3\Validators\PrivateValidator;
|
||||
use Web3\Validators\StringValidator;
|
||||
use Web3\Formatters\StringFormatter;
|
||||
use Web3\Formatters\PrivateFormatter;
|
||||
|
||||
class ImportRawKey extends EthMethod
|
||||
{
|
||||
@ -34,7 +35,7 @@ class ImportRawKey extends EthMethod
|
||||
* @var array
|
||||
*/
|
||||
protected $inputFormatters = [
|
||||
PrivateValidator::class, StringFormatter::class
|
||||
PrivateFormatter::class, StringFormatter::class
|
||||
];
|
||||
|
||||
/**
|
||||
|
@ -26,6 +26,6 @@ class PrivateValidator
|
||||
if (!is_string($value)) {
|
||||
return false;
|
||||
}
|
||||
return (preg_match('/^[a-fA-F0-9]{64}$/', $value) >= 1);
|
||||
return (preg_match('/^(0x)?[a-fA-F0-9]{64}$/', $value) >= 1);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user