kornrunner / ethereum-util
Pure PHP implementation of Ethereum Utils
Installs: 37 604
Dependents: 5
Suggesters: 0
Security: 0
Stars: 6
Watchers: 1
Forks: 2
Open Issues: 1
pkg:composer/kornrunner/ethereum-util
Requires
- php: ^8.1
- ext-gmp: *
- kornrunner/keccak: ^1.0
- kornrunner/secp256k1: ^0.3
Requires (Dev)
- phpunit/phpunit: ^9
README
Pure PHP implementation of Ethereum Utils
Usage
Hash Personal Message
use kornrunner\Eth; $hash = Eth::hashPersonalMessage('0xf20f20d357419f696f69e6ff05bc6566b1e6d38814ce4f489d35711e2fd2c481'); // 58a2db04c169254495a55b6dd5609a4902678ec29eac46df1e95994cdbeaebbb
Sign Personal Message
use kornrunner\Eth; $result = Eth::signPersonalMessage('Hello, Ethereum!', $privateKey);
Recover Public Key from Signature (ecRecover)
use kornrunner\Eth; $publicKey = Eth::ecRecover( '98d22cdb65bbf8a392180cd2ee892b0a971c47e7d29daf31a3286d006b9db4dc', 'f67118680df5993e8efca4d3ecc4172ca4ac5e3e007ea774293e373864809703', '47427f3633371c1a30abbb2b717dbd78ef63d5b19b5a951f9d681cccdd520320', 0 );
Verify Signature (ecVerify)
use kornrunner\Eth; $isValid = Eth::ecVerify( '98d22cdb65bbf8a392180cd2ee892b0a971c47e7d29daf31a3286d006b9db4dc', // message hash 'f67118680df5993e8efca4d3ecc4172ca4ac5e3e007ea774293e373864809703', // r component '47427f3633371c1a30abbb2b717dbd78ef63d5b19b5a951f9d681cccdd520320', // s component 0, // recovery id (v) '04cf60398ae73fd947ffe120fba68947ec741fe696438d68a2e52caca139613ff94f220cd0d3e886f95aa226f2ad2b86be1dd5cda2813fd505d1f6a8f552904864' // public key ); // true
All methods support both plain hex strings and 0x-prefixed hex strings.
0x9c7b7a00972121fb843af7af74526d7eb585b171