안녕하세요 개발 도중 질문이 있어서 글을 올립니다.
이더리움에서 제공하는 시그니쳐 검증하는 오픈소스를 가져와서 개발을 하였는데,
클레이튼에서도 적용을 하려니 오류가 나서 질문드립니다.
public function ecRecover($hex, $signed)
{
$rHex = substr($signed, 2, 64);
$sHex = substr($signed, 66, 64);
$vValue = hexdec(substr($signed, 130, 2));
$messageHex = substr($hex, 2);
$messageByteArray = unpack(‘C*’, hex2bin($messageHex));
$messageGmp = gmp_init(“0x” . $messageHex);
$r = $rHex; //hex string without 0x
$s = $sHex; //hex string without 0x
$v = $vValue; //27 or 28
//with hex2bin it gives the same byte array as the javascript
$rByteArray = unpack('C*', hex2bin($r));
$sByteArray = unpack('C*', hex2bin($s));
$rGmp = gmp_init("0x" . $r);
$sGmp = gmp_init("0x" . $s);
if($vValue == 1 || $vValue == 0) {
$recovery = $v;
} else {
$recovery = $v - 27;
}
if ($recovery !== 0 && $recovery !== 1) {
throw new Exception('Invalid signature v value');
}
$publicKey = Signature::recoverPublicKey($rGmp, $sGmp, $messageGmp, $recovery);
$publicKeyString = $publicKey["x"] . $publicKey["y"];
return '0x'. substr($this->keccak256(hex2bin($publicKeyString)), -40);
}
클레이튼에서도 이와 같은 소스를 제공하는 오픈소스가 있을까요! ㅠㅜㅠ