瀏覽代碼

调整签名方式

solupro 5 年之前
父節點
當前提交
22d98c71d8
共有 2 個文件被更改,包括 8 次插入3 次删除
  1. 6 1
      protected/extensions/Utils.php
  2. 2 2
      protected/models/Account.php

+ 6 - 1
protected/extensions/Utils.php

@@ -254,7 +254,7 @@ class Utils
         }
         $buffer = unpack('C*', hex2bin($message));
         $prefix = bin2hex("\u{0019}Ethereum Signed Message:\n" . sizeof($buffer));
-        return Keccak::hash(hex2bin($prefix . $message), self::HASH_SIZE);
+        return Keccak::hash(hex2bin($prefix . $message), 256);
     }
 
     /**
@@ -381,6 +381,11 @@ class Utils
         return $bn->divide($bnt);
     }
 
+    public static function strToHex($str) {
+        $hex = unpack('H*', $str);
+        return '0x' . array_shift($hex);
+    }
+
     /**
      * jsonMethodToString
      * 

+ 2 - 2
protected/models/Account.php

@@ -280,9 +280,9 @@ class Account extends Model {
      * @throws Exception
      */
     public static function verifyEth($account, $data, $signed) {
-        $hash = Utils::hashPersonalMessage($data);
+        $hash = Utils::hashPersonalMessage(Utils::strToHex($data));
 
-        $messageGmp       = gmp_init($hash);
+        $messageGmp       = gmp_init("0x" . $hash);
         $rHex   = substr($signed, 2, 64);
         $sHex   = substr($signed, 66, 64);
         $vValue = hexdec(substr($signed, 130, 2));