compressPublicKey

fun compressPublicKey(publicKeyBytes: ByteArray): ByteArray

Compresses a public key represented by its X and Y coordinates concatenated in a single byte array.

Assumes the input starts with a leading 0x04 byte, which is commonly used to denote an uncompressed public key in some elliptic curve representations.

Return

The compressed public key as a byte array.

Parameters

publicKeyBytes

A byte array representing the public key, expected to be 65 bytes with the first byte being 0x04. The following 32 bytes are for the X coordinate, and the last 32 for the Y coordinate.

Throws

if the input byte array is not of expected length or doesn't start with 0x04.