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
Table of Contents
Properties
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
$addr
private
Address|null
$addr
$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
staticfromHex()
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
staticgetPublicBin()
Returns binary blob of public key associated with this private key
public
getPublicBin() : string
Tags
Return values
stringgetPublicHex()
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
stringsign()
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
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.