# 클레이튼 계정으로 데이터 서명 및 검증하는 로직 질문

**URL:** <https://devforum.kaia.io/t/topic/6090>\
**Category:** Kaia\
**Tags:** klaytn\
**Created:** [10월 4, 2022, 7:01오전 UTC](https://devforum.kaia.io/t/topic/6090 "2022-10-04T07:01:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Woochi\_Jacob](https://yyz1.discourse-cdn.com/flex035/user_avatar/devforum.kaia.io/woochi_jacob/32/2916_2.png) [@Woochi\_Jacob](https://devforum.kaia.io/u/Woochi_Jacob)\
**Post date:** [10월 4, 2022, 7:01오전 UTC](https://devforum.kaia.io/t/topic/6090/1 "2022-10-04T07:01:29Z")

</div>

안녕하세요 개발 도중 질문이 있어서 글을 올립니다.

이더리움에서 제공하는 시그니쳐 검증하는 오픈소스를 가져와서 개발을 하였는데,  
클레이튼에서도 적용을 하려니 오류가 나서 질문드립니다.

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);
}

```

클레이튼에서도 이와 같은 소스를 제공하는 오픈소스가 있을까요! ㅠㅜㅠ

---

<div class="post-metadata">

**Author:** ![Jay](https://yyz1.discourse-cdn.com/flex035/user_avatar/devforum.kaia.io/jay/32/2655_2.png) [@Jay](https://devforum.kaia.io/u/Jay)\
**Post date:** [10월 6, 2022, 4:56오후 UTC](https://devforum.kaia.io/t/topic/6090/2 "2022-10-06T16:56:17Z")

</div>

클레이튼의 키 업데이트 기능으로 인해서 생기는 오류로 추측되는데요,

[validateSignedMessage](https://docs.klaytn.foundation/dapp/sdk/caver-js/api-references/caver.validator?q=validateSig#validatesignedmessage) 기능을 참조하시면 될 것 같습니다.

혹은 recoverPublicKey, getAccountKey API를 이용하셔도 됩니다.
