Documentation

Key
in package

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.

Tags
author

DubbaThony

Table of Contents

Properties

$addr  : Address|null
$key  : KeyPair
$keyHex  : string

Methods

fromBin()  : static
Initializes from binary of the key.
fromHex()  : static
Initializes from a hexadecimal string.
generate()  : static
Generates new random key using openssl for random bytes. Triggers E_USER_WARNING if weak entropy was used.
getPublicBin()  : string
Returns binary blob of public key associated with this private key
getPublicHex()  : string
Returns hex-encoded public key associated with this private key. Does not contain initial "04" prefix.
sign()  : Signature
Signs arbitrary hash using the private key.
toAddress()  : Address
Generates an Ethereum Address based on the key. Internally caches the address to avoid wasting time on hashing.
toBin()  : string
Returns the binary of the key.
toHex()  : string
Returns the hexadecimal representation of the key, prefixed with '0x'.
__construct()  : mixed

Properties

$key

private KeyPair $key

$keyHex

private string $keyHex
Attributes
#[SensitiveParameter]

Methods

fromBin()

Initializes from binary of the key.

public static fromBin(string $bin) : static
Parameters
$bin : string

Binary string of the key.

Return values
static

fromHex()

Initializes from a hexadecimal string.

public static fromHex(string $keyHex) : static
Parameters
$keyHex : string

Hexadecimal string of the private key.

Return values
static —

Instance of Key class.

generate()

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

public static generate() : static
Return values
static

getPublicBin()

Returns binary blob of public key associated with this private key

public getPublicBin() : string
Tags
throws
InvalidHexException
Return values
string

getPublicHex()

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

public getPublicHex([bool $with0x = true ]) : string
Parameters
$with0x : bool = true
Return values
string

sign()

Signs arbitrary hash using the private key.

public sign(Hash $hash) : Signature
Parameters
$hash : Hash

Hash to be signed.

Return values
Signature —

The resulting Ethereum signature.

toAddress()

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

public toAddress() : Address
Tags
throws
EthBinderLogicException
Return values
Address —

The Ethereum address.

toBin()

Returns the binary of the key.

public toBin() : string
Return values
string —

Binary string of the key.

toHex()

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

public toHex() : string
Return values
string —

Hexadecimal string of the key.

__construct()

protected __construct(string $keyHex) : mixed
Parameters
$keyHex : string

Hexadecimal string of the private key.


        
On this page

Search results