This commit is contained in:
sc0Vu 2017-12-20 15:09:52 +08:00
parent 02b30ee2d5
commit 11ffbf93d6

View File

@ -62,9 +62,11 @@ class Utils
if (!is_string($value)) { if (!is_string($value)) {
throw new InvalidArgumentException('The value to toHex function must be string.'); throw new InvalidArgumentException('The value to toHex function must be string.');
} }
$hexString = str_replace('0x', '', $value); if (strpos($value, '0x') === 0) {
$count = 1;
return pack('H*', $hexString); $value = str_replace('0x', '', $value, $count);
}
return pack('H*', $value);
} }
/** /**
@ -74,12 +76,12 @@ class Utils
* @param string $value * @param string $value
* @return string * @return string
*/ */
public function sha3($value) public static function sha3($value)
{ {
if (!is_string($value)) { if (!is_string($value)) {
throw new InvalidArgumentException('The value to sha3 function must be string.'); throw new InvalidArgumentException('The value to sha3 function must be string.');
} }
if (preg_match('/^0x/', $value) > 0) { if (strpos($value, '0x') === 0) {
$value = self::hexToBin($value); $value = self::hexToBin($value);
} }
$hash = Keccak::hash($value, 256); $hash = Keccak::hash($value, 256);