diff --git a/src/Utils.php b/src/Utils.php index 22e4157..ebfa200 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -83,6 +83,21 @@ class Utils return (strpos($value, '0x') === 0); } + /** + * stripZero + * + * @param string $value + * @return string + */ + public static function stripZero($value) + { + if (self::isZeroPrefixed($value)) { + $count = 1; + return str_replace('0x', '', $value, $count); + } + return $value; + } + /** * sha3 * keccak256 diff --git a/test/unit/UtilsTest.php b/test/unit/UtilsTest.php index a95d1be..96761ca 100644 --- a/test/unit/UtilsTest.php +++ b/test/unit/UtilsTest.php @@ -79,6 +79,22 @@ class UtilsTest extends TestCase $this->assertEquals($isPrefixed, true); } + /** + * testStripZero + * + * @return void + */ + public function testStripZero() + { + $str = Utils::stripZero($this->testHex); + + $this->assertEquals($str, $this->testHex); + + $str = Utils::stripZero('0x' . $this->testHex); + + $this->assertEquals($str, $this->testHex); + } + /** * testSha3 *