PHP Validation
(PHP)
Validate signature belongs to the signing address
To validate the signature belongs to the signing address, we can create a class Signature that will call the method personalEcRecover from Ethereum\EcRecover:
<?php
namespace Signature;
use Ethereum\EcRecover;
use Ethereum\DataType\EthD;
/**
* Class that validates sender signature
*
*/
class Signature
{
/**
* @dataProvider ecRecover
*
* @param $address
* @param $transaction
* @param $signature
*
* @returns bool
*
* @throws \Exception
*/
public function checkMatch($address, $transaction, $signature)
{
$recoveredAddr = Ethereum::personalEcRecover($transaction, new EthD($signature) );
$isEqual = $address == $recoveredAddr;
return $isEqual;
}
}
?>
Updated about 5 years ago