Skip to main content
@tevm/voltaire
@tevm/voltaire / primitives/PublicKey

primitives/PublicKey

Type Aliases

PublicKeyType

PublicKeyType = Uint8Array & object
Defined in: src/primitives/PublicKey/PublicKeyType.ts:7 PublicKey type - 64 byte uncompressed public key Distinguishes from generic Hex/Uint8Array

Type Declaration

[brand]
readonly [brand]: "PublicKey"
length
readonly length: 64

Variables

_verify()

const _verify: (publicKey, hash, signature) => boolean
Defined in: src/primitives/PublicKey/index.ts:25

Parameters

publicKey
PublicKeyType
hash
HashType
signature
Secp256k1SignatureType

Returns

boolean

PublicKey

const PublicKey: object
Defined in: src/primitives/PublicKey/index.ts:122

Type Declaration

compress()
compress: (publicKey) => Uint8Array
Compress a public key from 64 bytes (uncompressed) to 33 bytes (compressed) Compressed format: prefix (1 byte) + x-coordinate (32 bytes) Prefix is 0x02 if y is even, 0x03 if y is odd Compressed keys are preferred for storage and transmission due to smaller size. Uncompressed keys are needed by some legacy systems.
Parameters
publicKey
Public key (hex string or 64 bytes) string | Uint8Array<ArrayBufferLike>
Returns
Uint8Array Compressed public key (33 bytes)
Example
import * as PublicKey from './primitives/PublicKey/index.js';

const compressed = PublicKey.compress("0x1234...");
console.log(compressed.length); // 33
decompress()
decompress: (compressed) => PublicKeyType
Decompress a public key from 33 bytes (compressed) to 64 bytes (uncompressed) Solves the curve equation y² = x³ + 7 mod p and chooses y based on prefix parity.
Parameters
compressed
Uint8Array Compressed public key (33 bytes with 0x02/0x03 prefix)
Returns
PublicKeyType Uncompressed public key (64 bytes)
Throws
If compressed format is invalid
Example
import * as PublicKey from './primitives/PublicKey/index.js';

const uncompressed = PublicKey.decompress(compressed);
console.log(uncompressed.length); // 64
from()
from: (hex) => PublicKeyType
Create PublicKey from hex string
Parameters
hex
string Hex string (64 bytes uncompressed)
Returns
PublicKeyType Public key
Throws
If hex string format is invalid
Throws
If hex is not 64 bytes
Example
const pk = PublicKey.from("0x1234...");
fromPrivateKey()
fromPrivateKey: (privateKey) => PublicKeyType
Derive public key from private key
Parameters
privateKey
PrivateKeyType Private key
Returns
PublicKeyType Public key (64 bytes uncompressed)
Example
const publicKey = PublicKey.fromPrivateKey(pk);
isCompressed()
isCompressed: (bytes) => boolean
Check if a public key is in compressed format Returns true for 33 bytes with 0x02/0x03 prefix, false otherwise
Parameters
bytes
Uint8Array Public key bytes
Returns
boolean True if compressed format
Example
import * as PublicKey from './primitives/PublicKey/index.js';

const isComp = PublicKey.isCompressed(bytes);
toAddress()
toAddress: (publicKey) => AddressType
Parameters
publicKey
string
Returns
AddressType
toHex()
toHex: (publicKey) => string
Parameters
publicKey
string
Returns
string
verify()
verify: (publicKey, hash, signature) => boolean
Parameters
publicKey
string
hash
HashType
signature
SignatureType
Returns
boolean

Functions

_compress()

_compress(publicKey): Uint8Array<ArrayBufferLike>
Defined in: src/primitives/PublicKey/compress.js:16 Compress a public key from 64 bytes (uncompressed) to 33 bytes (compressed) Compressed format: prefix (1 byte) + x-coordinate (32 bytes) Prefix is 0x02 if y is even, 0x03 if y is odd

Parameters

publicKey
PublicKeyType Uncompressed public key (64 bytes)

Returns

Uint8Array<ArrayBufferLike> Compressed public key (33 bytes)

Example

import * as PublicKey from './primitives/PublicKey/index.js';
const compressed = PublicKey._compress(publicKey);

_decompress()

_decompress(compressed): PublicKeyType
Defined in: src/primitives/PublicKey/decompress.js:16 Decompress a public key from 33 bytes (compressed) to 64 bytes (uncompressed) Solves y² = x³ + 7 mod p and chooses y based on prefix parity

Parameters

compressed
Uint8Array<ArrayBufferLike> Compressed public key (33 bytes with 0x02/0x03 prefix)

Returns

PublicKeyType Uncompressed public key (64 bytes)

Throws

If compressed format is invalid

Example

import * as PublicKey from './primitives/PublicKey/index.js';
const uncompressed = PublicKey._decompress(compressed);

_isCompressed()

_isCompressed(bytes): boolean
Defined in: src/primitives/PublicKey/isCompressed.js:15 Check if a public key is in compressed format Returns true for 33 bytes with 0x02/0x03 prefix, false otherwise

Parameters

bytes
Uint8Array<ArrayBufferLike> Public key bytes

Returns

boolean True if compressed format

Example

import * as PublicKey from './primitives/PublicKey/index.js';
const isCompressed = PublicKey._isCompressed(bytes);

_toAddress()

_toAddress(this): AddressType
Defined in: src/primitives/PublicKey/toAddress.ts:16 Derive Ethereum address from public key

Parameters

this
PublicKeyType Public key

Returns

AddressType Ethereum address (20 bytes)

Example

const address = PublicKey._toAddress.call(pk);

_toHex()

_toHex(this): string
Defined in: src/primitives/PublicKey/toHex.ts:14 Convert PublicKey to hex string

Parameters

this
PublicKeyType Public key

Returns

string Hex string

Example

const hex = PublicKey._toHex.call(pk);

compress()

compress(publicKey): Uint8Array
Defined in: src/primitives/PublicKey/index.ts:68 Compress a public key from 64 bytes (uncompressed) to 33 bytes (compressed) Compressed format: prefix (1 byte) + x-coordinate (32 bytes) Prefix is 0x02 if y is even, 0x03 if y is odd Compressed keys are preferred for storage and transmission due to smaller size. Uncompressed keys are needed by some legacy systems.

Parameters

publicKey
Public key (hex string or 64 bytes) string | Uint8Array<ArrayBufferLike>

Returns

Uint8Array Compressed public key (33 bytes)

Example

import * as PublicKey from './primitives/PublicKey/index.js';

const compressed = PublicKey.compress("0x1234...");
console.log(compressed.length); // 33

decompress()

decompress(compressed): PublicKeyType
Defined in: src/primitives/PublicKey/index.ts:93 Decompress a public key from 33 bytes (compressed) to 64 bytes (uncompressed) Solves the curve equation y² = x³ + 7 mod p and chooses y based on prefix parity.

Parameters

compressed
Uint8Array Compressed public key (33 bytes with 0x02/0x03 prefix)

Returns

PublicKeyType Uncompressed public key (64 bytes)

Throws

If compressed format is invalid

Example

import * as PublicKey from './primitives/PublicKey/index.js';

const uncompressed = PublicKey.decompress(compressed);
console.log(uncompressed.length); // 64

from()

from(hex): PublicKeyType
Defined in: src/primitives/PublicKey/from.ts:22 Create PublicKey from hex string

Parameters

hex
string Hex string (64 bytes uncompressed)

Returns

PublicKeyType Public key

Throws

If hex string format is invalid

Throws

If hex is not 64 bytes

Example

const pk = PublicKey.from("0x1234...");

fromPrivateKey()

fromPrivateKey(privateKey): PublicKeyType
Defined in: src/primitives/PublicKey/fromPrivateKey.ts:16 Derive public key from private key

Parameters

privateKey
PrivateKeyType Private key

Returns

PublicKeyType Public key (64 bytes uncompressed)

Example

const publicKey = PublicKey.fromPrivateKey(pk);

isCompressed()

isCompressed(bytes): boolean
Defined in: src/primitives/PublicKey/index.ts:114 Check if a public key is in compressed format Returns true for 33 bytes with 0x02/0x03 prefix, false otherwise

Parameters

bytes
Uint8Array Public key bytes

Returns

boolean True if compressed format

Example

import * as PublicKey from './primitives/PublicKey/index.js';

const isComp = PublicKey.isCompressed(bytes);

toAddress()

toAddress(publicKey): AddressType
Defined in: src/primitives/PublicKey/index.ts:32

Parameters

publicKey
string

Returns

AddressType

toHex()

toHex(publicKey): string
Defined in: src/primitives/PublicKey/index.ts:28

Parameters

publicKey
string

Returns

string

verify()

verify(publicKey, hash, signature): boolean
Defined in: src/primitives/PublicKey/index.ts:36

Parameters

publicKey
string
hash
HashType
signature
SignatureType

Returns

boolean

Verify()

Verify(deps): (publicKey, hash, signature) => boolean
Defined in: src/primitives/PublicKey/verify.js:7 Factory: Verify signature against public key

Parameters

deps
Crypto dependencies
secp256k1Verify
(signature, hash, publicKey) => boolean Secp256k1 signature verification function (expects 64-byte public key)

Returns

Function that verifies ECDSA signature
(publicKey, hash, signature): boolean
Parameters
publicKey
PublicKeyType
hash
HashType
signature
Secp256k1SignatureType
Returns
boolean