Ether Binder
Set of utilities for interacting with Ethereum and it's smart contracts with PHP, with generating ABI bindings and Ethereum-related types
Loading...
Searching...
No Matches
M8B\EtherBinder\Misc\AbstractSigningMessage Class Reference
Inheritance diagram for M8B\EtherBinder\Misc\AbstractSigningMessage:
M8B\EtherBinder\Misc\GethLikeMessage M8B\EtherBinder\Misc\InnerHashedMessage M8B\EtherBinder\Misc\UnFormattedSigningMessage

Public Member Functions

 __construct (protected string $message, protected ?Address $from=null, protected ?Signature $sig=null)
 
 setMessage (string $message)
 
 getMessage ()
 
 sign (Key $key)
 
 isSigned ()
 
 toJson (bool $pretty)
 
 __toString ()
 
 getSignature ()
 
 validateSignature ()
 

Static Public Member Functions

static fromJSON (string $json)
 

Protected Member Functions

 preProcessMessage ()
 

Detailed Description

AbstractSigningMessage is class for handling Ethereum signed messages, regardless of specific formatting which is offloaded to class extending AbstractSigningMessage. This allows for easy implementation of multiple signing formats offered by different wallets, usually small variations of "\x19Ethereum Signed Message:\n(len)(message)"

Author
DubbaThony

Constructor & Destructor Documentation

◆ __construct()

M8B\EtherBinder\Misc\AbstractSigningMessage::__construct ( protected string $message,
protected ?Address $from = null,
protected ?Signature $sig = null )

Initializes the object with the message, from address and signature.

Parameters
string$messageThe message to be signed.
Address | null$fromEthereum address sending the message. Optional.
Signature | null$sigExisting signature. Optional.

Member Function Documentation

◆ __toString()

M8B\EtherBinder\Misc\AbstractSigningMessage::__toString ( )

Default to string behaviour is pretty printed JSON.

Returns
string Pretty printed JSON
Exceptions
EthBinderLogicException
See also
self::toJson

◆ fromJSON()

static M8B\EtherBinder\Misc\AbstractSigningMessage::fromJSON ( string $json)
static

Creates signed message from JSON string. Does not on its own validate the message, just parses it into object.

Parameters
string$jsonJSON object of message
Returns
static parsed message object
Exceptions
BadAddressChecksumException
EthBinderLogicException
InvalidHexException
InvalidHexLengthException
JsonException

◆ getMessage()

M8B\EtherBinder\Misc\AbstractSigningMessage::getMessage ( )

Get the current message.

Returns
string The current message.

◆ getSignature()

M8B\EtherBinder\Misc\AbstractSigningMessage::getSignature ( )

Retrieve the signature object.

Returns
Signature The clone of existing signature.

◆ isSigned()

M8B\EtherBinder\Misc\AbstractSigningMessage::isSigned ( )

Check if message is signed.

Returns
bool True if message has been signed, false otherwise.

◆ preProcessMessage()

M8B\EtherBinder\Misc\AbstractSigningMessage::preProcessMessage ( )
abstractprotected

Preprocess the message before hashing, for example adding signing "magic bytes" such as "\x19Ethereum Signed Message" etc. This allows for multiple formats support

Returns
string The pre-processed message.

Reimplemented in M8B\EtherBinder\Misc\GethLikeMessage, M8B\EtherBinder\Misc\InnerHashedMessage, and M8B\EtherBinder\Misc\UnFormattedSigningMessage.

◆ setMessage()

M8B\EtherBinder\Misc\AbstractSigningMessage::setMessage ( string $message)

Set the message. This will invalidate and remove the current signature if message is different from currently set and if signature is present

Parameters
string$messageThe new message.

◆ sign()

M8B\EtherBinder\Misc\AbstractSigningMessage::sign ( Key $key)

Sign the message.

Parameters
Key$keyPrivate key for signing.
Returns
Signature Clone of generated signature.
Exceptions
EthBinderLogicException

◆ toJson()

M8B\EtherBinder\Misc\AbstractSigningMessage::toJson ( bool $pretty)

Convert object state to JSON string, producing JSON object similar to MEW and other wallets that support signing

Parameters
bool$prettyUse JSON pretty print option if true.
Returns
string The object state as a JSON string.
Exceptions
EthBinderLogicException

◆ validateSignature()

M8B\EtherBinder\Misc\AbstractSigningMessage::validateSignature ( )

Validate if the existing signature matches address it claims to be from.

Returns
bool True if signature is valid, false otherwise.
Exceptions
EthBinderLogicException
EthBinderRuntimeException

The documentation for this class was generated from the following file: