dragu/siwe

Ethereum Authentication for PHP

dev-master 2025-04-12 08:02 UTC

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

  1. The wallet is connected to the client, then the wallet address is sent to the server
  2. 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);
  1. On the client side, we sign the SIWE message via personal_sign. We send the received signature to the server.
  2. 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.

Links