|
@@ -242,6 +242,21 @@ class Utils
|
|
return '0x' . $hash;
|
|
return '0x' . $hash;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static function hashPersonalMessage($message) {
|
|
|
|
+ if (stripos($message, '0x') === 0) {
|
|
|
|
+ $message = substr($message, 2);
|
|
|
|
+ }
|
|
|
|
+ if (!ctype_xdigit($message)) {
|
|
|
|
+ throw new InvalidArgumentException('Message should be a hexadecimal');
|
|
|
|
+ }
|
|
|
|
+ if (strlen($message) % 2) {
|
|
|
|
+ throw new InvalidArgumentException('Message size cannot be odd');
|
|
|
|
+ }
|
|
|
|
+ $buffer = unpack('C*', hex2bin($message));
|
|
|
|
+ $prefix = bin2hex("\u{0019}Ethereum Signed Message:\n" . sizeof($buffer));
|
|
|
|
+ return Keccak::hash(hex2bin($prefix . $message), 256);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* toString
|
|
* toString
|
|
*
|
|
*
|
|
@@ -366,6 +381,11 @@ class Utils
|
|
return $bn->divide($bnt);
|
|
return $bn->divide($bnt);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static function strToHex($str) {
|
|
|
|
+ $hex = unpack('H*', $str);
|
|
|
|
+ return '0x' . array_shift($hex);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* jsonMethodToString
|
|
* jsonMethodToString
|
|
*
|
|
*
|