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\Crypto\Key Class Reference

Public Member Functions

 toHex ()
 
 getPublicHex (bool $with0x=true)
 
 getPublicBin ()
 
 toAddress ()
 
 toBin ()
 
 sign (Hash $hash)
 

Static Public Member Functions

static fromHex (#[SensitiveParameter] string $keyHex)
 
static fromBin (string $bin)
 
static generate ()
 

Protected Member Functions

 __construct (#[SensitiveParameter] private string $keyHex)
 

Detailed Description

Key is a representation for raw Ethereum private key. It contains essential utilities for its usage and is used in EthBinder as raw private key.

Author
DubbaThony

Constructor & Destructor Documentation

◆ __construct()

M8B\EtherBinder\Crypto\Key::__construct ( # private string $keyHex[SensitiveParameter])
protected
Parameters
string$keyHexHexadecimal string of the private key.

Member Function Documentation

◆ fromBin()

static M8B\EtherBinder\Crypto\Key::fromBin ( string $bin)
static

Initializes from binary of the key.

Parameters
string$binBinary string of the key.

◆ fromHex()

static M8B\EtherBinder\Crypto\Key::fromHex ( # string $keyHex[SensitiveParameter])
static

Initializes from a hexadecimal string.

Parameters
string$keyHexHexadecimal string of the private key.
Returns
static Instance of Key class.

◆ generate()

static M8B\EtherBinder\Crypto\Key::generate ( )
static

Generates new random key using openssl for random bytes. Triggers E_USER_WARNING if weak entropy was used.

Returns
static

◆ getPublicBin()

M8B\EtherBinder\Crypto\Key::getPublicBin ( )

Returns binary blob of public key associated with this private key

Returns
string
Exceptions
InvalidHexException

◆ getPublicHex()

M8B\EtherBinder\Crypto\Key::getPublicHex ( bool $with0x = true)

Returns hex-encoded public key associated with this private key. Does not contain initial "04" prefix.

Parameters
bool$with0x
Returns
string

◆ sign()

M8B\EtherBinder\Crypto\Key::sign ( Hash $hash)

Signs arbitrary hash using the private key.

Parameters
Hash$hashHash to be signed.
Returns
Signature The resulting Ethereum signature.

◆ toAddress()

M8B\EtherBinder\Crypto\Key::toAddress ( )

Generates an Ethereum Address based on the key. Internally caches the address to avoid wasting time on hashing.

Returns
Address The Ethereum address.
Exceptions
EthBinderLogicException

◆ toBin()

M8B\EtherBinder\Crypto\Key::toBin ( )

Returns the binary of the key.

Returns
string Binary string of the key.

◆ toHex()

M8B\EtherBinder\Crypto\Key::toHex ( )

Returns the hexadecimal representation of the key, prefixed with '0x'.

Returns
string Hexadecimal string of the key.

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