unlockCompressedPublicKey

33-byte compressed secp256k1 public key

33-byte compressed secp256k1 public key with validated prefix byte.

Overview

CompressedPublicKey is a fixed-size byte type representing a compressed secp256k1 public key. It validates both the length (33 bytes) and the prefix byte (0x02 or 0x03) at construction time.

Definition

class CompressedPublicKey(HexBytes):
    """33-byte compressed secp256k1 public key (0x02 / 0x03 prefix)."""
    _size = 33

Inheritance

  • Inherits from HexBytes (from the hexbytes package)

  • HexBytes itself inherits from Python's bytes type

  • Fully compatible with any API expecting bytes

Construction

CompressedPublicKey can be constructed from:

  • Hex strings (with or without "0x" prefix)

  • Raw bytes objects

  • Integer values

Parameters

Parameter
Type
Required
Description

val

bytes | str | int

Yes

The value to convert to a 33-byte compressed public key

Raises

  • ValueError - If the length is not exactly 33 bytes

  • ValueError - If the prefix byte is not 0x02 or 0x03

Examples

From Hex String

From Raw Bytes

Derive from Private Key

Use in ECDH

Validation Errors

Methods

to_0x_hex()

Returns the hex string representation with "0x" prefix.

Properties

  • Immutable - Cannot be modified after construction

  • Hashable - Can be used as dictionary keys or in sets

  • 33 bytes - Always exactly 33 bytes

  • Valid prefix - Always starts with 0x02 or 0x03

  • Compatible with bytes - Passes isinstance(x, bytes) checks

Compressed vs Uncompressed

Seismic uses compressed public keys exclusively:

  • Compressed: 33 bytes (1-byte prefix + 32-byte x-coordinate)

  • Uncompressed: 65 bytes (1-byte prefix + 32-byte x-coordinate + 32-byte y-coordinate)

The prefix byte indicates the y-coordinate's parity:

  • 0x02 - y-coordinate is even

  • 0x03 - y-coordinate is odd

Notes

  • Used in SeismicElements for encryption_pubkey

  • Required for ECDH key derivation in precompiles

  • Obtained from w3.seismic.get_tee_public_key() for transaction encryption

  • Prefix validation ensures only valid compressed keys are accepted

See Also

Last updated