32 if (self::isValidFunction($input)) {
34 return self::ensureHexPrefix(substr(self::sha3($input), 0, 10));
37 throw new \InvalidArgumentException(
"No valid (solidity) signature string provided.");
63 return self::ensureHexPrefix(Keccak::hash($string, 256));
80 public static function sha3($string)
82 return self::phpKeccak256($string);
109 $regex =
'/^[a-zA-Z]+[a-zA-Z0-9]*[\(]{1}(([\w\d\[\]*){1}(\,[\w\d\[\]]*[\w\d\[\]]*)*)[\)]{1}$/';
110 if (is_string($input) && preg_match($regex, $input) === 1) {
126 $schema_path = __DIR__ .
'/../resources/ethjs-schema.json';
127 return json_decode(file_get_contents($schema_path),
true);
158 if (!EthereumStatic::hasHexPrefix($str)) {
163 if (strlen($str) < 3) {
167 return ctype_xdigit(self::removeHexPrefix($str));
186 if (!EthereumStatic::hasHexPrefix($str)) {
190 if (strlen($str) <= 3) {
195 if ((strlen($str) % 2 != 0)) {
199 return ctype_xdigit(self::removeHexPrefix($str));
219 if (!self::hasHexPrefix(
$address)) {
226 $return = ctype_xdigit(self::removeHexPrefix(
$address));
241 return substr($str, 0, 2) ===
'0x';
255 if (!self::hasHexPrefix($str)) {
259 return substr($str, 2);
273 if (self::hasHexPrefix($str)) {
291 public static function convertCurrency(
float $amount,
string $from =
'wei',
string $to =
'ether') {
295 'wei' => 1000000000000000000,
297 'kwei' => 1000000000000000,
299 'mwei' => 1000000000000,
301 'gwei' => 1000000000,
310 'mether' => 0.000001,
311 'gether' => 0.000000001,
312 'thether' => 0.000000000001,
314 if (!isset($convertTabe[$from])) {
315 throw new \Exception(
'Inknown currency to convert from "' . $from .
'"');
317 if (!isset($convertTabe[$to])) {
318 throw new \Exception(
'Inknown currency to convert to "' . $to .
'"');
320 return $convertTabe[$to] * $amount / $convertTabe[$from];
static phpKeccak256($string)
static isValidAddress($address, $throw=false)
static ensureHexPrefix($str)
static getMethodSignature($input)
static isValidFunction($input)
static isValidHexData($str)
static convertCurrency(float $amount, string $from='wei', string $to='ether')
static hasHexPrefix($str)
static isValidHexQuantity($str)
static removeHexPrefix($str)