keyPrivateKey

32-byte secp256k1 private key

32-byte secp256k1 private key used for transaction signing and ECDH key derivation.

Definition

class PrivateKey(Bytes32):
    @staticmethod
    def from_hex_str(hex_string: str) -> PrivateKey:
        ...

Construction

Parameter
Type
Required
Description

val

bytes | str | int

Yes

Hex string, raw bytes, or integer

Raises ValueError if length is not exactly 32 bytes.

Methods

from_hex_str()

Create a PrivateKey from a hex string, with or without 0x prefix. Shorthand for PrivateKey(hex_to_bytes(hex_string)).

@staticmethod
def from_hex_str(hex_string: str) -> PrivateKey

Example

Notes

  • Subclass of Bytes32 — inherits immutability, hashability, .to_0x_hex()

  • Compatible with eth_keys.PrivateKey via eth_keys.PrivateKey(bytes(pk))

  • No validation on mathematical validity (i.e., no check that 0 < key < n)

See Also

Last updated