web3 test init samples
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
45
verify.php
Normal file
45
verify.php
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
require_once 'path/to/web3.php/src/Web3/Providers/HttpProvider.php';
|
||||
require_once 'path/to/web3.php/src/Web3/RequestManagers/RequestManager.php';
|
||||
require_once 'path/to/web3.php/src/Web3/Web3.php';
|
||||
require_once 'path/to/web3.php/src/Web3/Eth.php';
|
||||
require_once 'path/to/web3.php/src/Web3/Utils.php';
|
||||
|
||||
// https://github.com/sc0Vu/web3.php
|
||||
// https://github.com/kornrunner/php-keccak
|
||||
// https://github.com/web3p/ethereum-util
|
||||
|
||||
// Include the necessary files
|
||||
require_once 'path/to/Keccak.php'; // Adjust the path
|
||||
require_once 'path/to/Util.php'; // Adjust the path
|
||||
|
||||
use kornrunner\Keccak;
|
||||
use Web3p\EthereumUtil\Util;
|
||||
|
||||
function verifySignature($address, $signature, $message) {
|
||||
$util = new Util();
|
||||
|
||||
// Hash the message
|
||||
$msgHash = Keccak::hash("\x19Ethereum Signed Message:\n" . strlen($message) . $message, 256);
|
||||
|
||||
// Recover the public key from the signature
|
||||
$pubKey = $util->recoverPublicKey($msgHash, $signature);
|
||||
|
||||
// Convert the public key to an Ethereum address
|
||||
$derivedAddress = $util->publicKeyToAddress($pubKey);
|
||||
|
||||
// Compare the derived address with the given address
|
||||
return strtolower($address) === strtolower($derivedAddress);
|
||||
}
|
||||
|
||||
// Fetch and decode the JSON POST request
|
||||
$data = json_decode(file_get_contents('php://input'), true);
|
||||
$account = $data['account'];
|
||||
$signature = $data['signature'];
|
||||
$message = $data['message'];
|
||||
|
||||
$verified = verifySignature($account, $signature, $message);
|
||||
|
||||
echo json_encode(['verified' => $verified]);
|
||||
|
Reference in New Issue
Block a user