GethLikeMessage
extends AbstractSigningMessage
in package
GethLikeMessage is a subclass of AbstractSigningMessage that pre-processes messages in a way that Geth does.
The message gets prepended with "\x19Ethereum Signed Message:\n" followed by the message length, to align with Geth's signing method.
Tags
Table of Contents
Properties
Methods
- __construct() : mixed
- Initializes the object with the message, from address and signature.
- __toString() : string
- Default to string behaviour is pretty printed JSON.
- fromJSON() : static
- Creates signed message from JSON string. Does not on its own validate the message, just parses it into object.
- getMessage() : string
- Get the current message.
- getSignature() : Signature
- Retrieve the signature object.
- isSigned() : bool
- Check if message is signed.
- setMessage() : void
- Set the message. This will invalidate and remove the current signature if message is different from currently set and if signature is present
- sign() : Signature
- Sign the message.
- toJson() : string
- Convert object state to JSON string, producing JSON object similar to MEW and other wallets that support signing
- validateSignature() : bool
- Validate if the existing signature matches address it claims to be from.
- preProcessMessage() : string
- Preprocess the message before hashing, for example adding signing "magic bytes" such as "\x19Ethereum Signed Message" etc.
- getMessageHash() : Hash
Properties
$from
protected
Address|null
$from
= null
$message
protected
string
$message
$sig
protected
Signature|null
$sig
= null
Methods
__construct()
Initializes the object with the message, from address and signature.
public
__construct(string $message[, Address|null $from = null ][, Signature|null $sig = null ]) : mixed
Parameters
__toString()
Default to string behaviour is pretty printed JSON.
public
__toString() : string
Tags
Return values
string —Pretty printed JSON
fromJSON()
Creates signed message from JSON string. Does not on its own validate the message, just parses it into object.
public
static fromJSON(string $json) : static
Parameters
- $json : string
-
JSON object of message
Tags
Return values
static —parsed message object
getMessage()
Get the current message.
public
getMessage() : string
Return values
string —The current message.
getSignature()
Retrieve the signature object.
public
getSignature() : Signature
Return values
Signature —The clone of existing signature.
isSigned()
Check if message is signed.
public
isSigned() : bool
Return values
bool —True if message has been signed, false otherwise.
setMessage()
Set the message. This will invalidate and remove the current signature if message is different from currently set and if signature is present
public
setMessage(string $message) : void
Parameters
- $message : string
-
The new message.
sign()
Sign the message.
public
sign(Key $key) : Signature
Parameters
- $key : Key
-
Private key for signing.
Tags
Return values
Signature —Clone of generated signature.
toJson()
Convert object state to JSON string, producing JSON object similar to MEW and other wallets that support signing
public
toJson(bool $pretty) : string
Parameters
- $pretty : bool
-
Use JSON pretty print option if true.
Tags
Return values
string —The object state as a JSON string.
validateSignature()
Validate if the existing signature matches address it claims to be from.
public
validateSignature() : bool
Tags
Return values
bool —True if signature is valid, false otherwise.
preProcessMessage()
Preprocess the message before hashing, for example adding signing "magic bytes" such as "\x19Ethereum Signed Message" etc.
protected
preProcessMessage() : string
This allows for multiple formats support
Return values
string —The pre-processed message.
getMessageHash()
private
getMessageHash() : Hash