Ether Binder
Set of utilities for interacting with Ethereum and it's smart contracts with PHP, with generating ABI bindings and Ethereum-related types
|
Ether Binder has simple utility to sign message, with support for few formats. Unfortunately, the signed message is not normalized and seemingly every second implementation of it defines its own. Most of the implementations if not all of them, in the end boil down to taking the message, processing it, hashing it and signing that hash. The processing usually involves adding \x19Ethereum Signed Message:
prefix.
Right now there are 3 formats supported:
message = \x19Ethereum Signed Message:\n{len(message)}{message}
message = \x19Ethereum Signed Message:\n32{keccak256(message)}
message = message
You can also define your own message type by extending AbstractSigningMessage
and implementing single method:
Signed messages support bidirectional JSON en/de-coding (note that re-encoding with Ether Binder will lose original signer and version). Usage on can be also fully done on Ether Binder's types.
To sign message, select format by choosing implementation (like GethLike in example below), supply the message to constructor, and use sign()
with private key.
To validate message, it needs to get instantiated, and then validateSignature()
method can be called. It returns bool if message is matching declared address.
One way of instantiating the message object is using ::fromJSON
static method:
Alternatively, Ether Binder types can be utilized