dragu / siwe
Ethereum Authentication for PHP
dev-master
2025-04-12 08:02 UTC
Requires
- ext-ctype: *
- kornrunner/keccak: ^1.0
- simplito/elliptic-php: ^1.0
Requires (Dev)
- phpunit/phpunit: 11
This package is auto-updated.
Last update: 2025-04-12 08:02:58 UTC
README
This package provides a PHP implementation of EIP-4361: Sign In With Ethereum.
Installation
composer require zbkm/siwe
Usage
- The wallet is connected to the client, then the wallet address is sent to the server
- On the server we generate SIWE messages.
$params = new SiweMessageParams( address: $address, chainId: 1, domain: "example.com", uri: "https://example.com/path" );
or with params builder:
$params = SiweMessageParamsBuilder::create() ->withAddress($address) ->withChainId(1) ->withDomain("example.com") ->withUri("https://example.com/path")->build();
And we generate the message text:
$message = SiweMessage::create($params);
- On the client side, we sign the SIWE message via personal_sign. We send the received signature to the server.
- All that remains is to check the signature.
if (SiweMessage::verify($params, $signature)) { // authorization success } else { // authorization failed (signature invalid) }
You can also look at a fully working example of authorization using the library.