digitaldonkey / ecverify Goto Github PK
View Code? Open in Web Editor NEWPHP based Ethereum web3 personal recover
Home Page: https://github.com/digitaldonkey/ethereum-php
License: MIT License
PHP based Ethereum web3 personal recover
Home Page: https://github.com/digitaldonkey/ethereum-php
License: MIT License
Hi All,
i have {
"message": {
"domain": "localhost:3000",
"address": "0x5F901aF6E1Bc15889c11aBe2C1c03B31544FBc98",
"statement": "hello world",
"uri": "http://localhost:3000",
"version": "1",
"chainId": 56,
"nonce": "3407d937dc17082a457a",
"issuedAt": "2022-12-28T23:10:14.286Z"
},
"signature": "0x3017e592092433ae903eb9eda9e62afc333403555b93b8fe063e8d56d374fc106fc186d4fc856c35423c37ff4befc5851984585600b868230698379e1df434931c",
}
SIWE::verifyAddress($a->statement, $json->signature)
after multiple attempts the address still shows -> 0x26fea7722af194204c33502ae483c4af2add5ec2, 0x7f9cc389193346ace2b25f6436b1d6d47e465f6a, 0x204235a7552cb6994f7533015eeb3f9a3944c723.
random addresses like that, i want it to recover 0x5F901aF6E1Bc15889c11aBe2C1c03B31544FBc98
Thanks
@digitaldonkey digitaldonkey
If I run the sample code in Readme.md it causes the following error if the server/platform running the code does not have the php-gmp extension installed, but does have php-bcmath installed.
The dependency simplito/elliptic-php
requires either gmp or bcmath to be installed as you can see in BigInteger.php.
First it tries to do the operation using gmp but if gmp is not installed it uses bcmath as a fallback.
This problem can be fixed (within this repo) by removing the '0x'
that is prefixed to the $message_hash
in EcRecover.php on line 20.
So this line
$message_hash = '0x' . Keccak::hash(self::personalSignAddHeader($message), 256);
changes to this
$message_hash = Keccak::hash(self::personalSignAddHeader($message), 256);
Once that change has been implemented the sample code in Readme.md runs fine using both the gmp and bcmath methods.
I'm not sure if the proper solution here is for this repo to be modified as described above or if simplito/elliptic-php
should somehow be modified instead. However if you look at the the README.md for simplito/elliptic-php
under "Verifying Ethereum Signature" you can see that the example does not prefix the hash with '0x'
.
For reference here is the exact code I am running that causes an error. This is the same code from Readme.md, just with a couple typo fixes.
use Ethereum\EcRecover;
$address = '0xbe93f9bacbcffc8ee6663f2647917ed7a20a57bb';
$message = 'hello world';
$signature = '0xce909e8ea6851bc36c007a0072d0524b07a3ff8d4e623aca4c71ca8e57250c4d0a3fc38fa8fbaaa81ead4b9f6bd03356b6f8bf18bccad167d78891636e1d69561b';
// Verify known address
$valid = EcRecover::personalVerifyEcRecover($message, $signature, $address);
// Recover unknown address
$recoveredAddress = EcRecover::personalEcRecover($message, $signature);
if ($recoveredAddress === $address) {
echo 'Jay! it was a long way here. ';
}
This is the error I am getting:
Exception
Invalid characters
vendor/simplito/bigint-wrapper-php/lib/BigInteger.php:328
If a signature happens to end in 00, $recid
will be negative and the function will fail.
Line 70 in fe873f7
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.