@tevm/voltaire / primitives/PublicKey
primitives/PublicKey
Type Aliases
PublicKeyType
PublicKeyType =Defined in: src/primitives/PublicKey/PublicKeyType.ts:7 PublicKey type - 64 byte uncompressed public key Distinguishes from generic Hex/Uint8ArrayUint8Array&object
Type Declaration
[brand]
readonly[brand]:"PublicKey"
length
readonlylength:64
Variables
_verify()
Defined in: src/primitives/PublicKey/index.ts:25const_verify: (publicKey,hash,signature) =>boolean
Parameters
publicKey
PublicKeyType
hash
HashType
signature
Secp256k1SignatureType
Returns
boolean
PublicKey
Defined in: src/primitives/PublicKey/index.ts:122constPublicKey:object
Type Declaration
compress()
compress: (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.publicKey) =>Uint8Array
Parameters
publicKey
Public key (hex string or 64 bytes)string | Uint8Array<ArrayBufferLike>
Returns
Uint8Array
Compressed public key (33 bytes)
Example
decompress()
decompress: (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.compressed) =>PublicKeyType
Parameters
compressed
Uint8Array
Compressed public key (33 bytes with 0x02/0x03 prefix)
Returns
PublicKeyType
Uncompressed public key (64 bytes)
Throws
If compressed format is invalidExample
from()
from: (Create PublicKey from hex stringhex) =>PublicKeyType
Parameters
hex
string
Hex string (64 bytes uncompressed)
Returns
PublicKeyType
Public key
Throws
If hex string format is invalidThrows
If hex is not 64 bytesExample
fromPrivateKey()
fromPrivateKey: (Derive public key from private keyprivateKey) =>PublicKeyType
Parameters
privateKey
PrivateKeyType
Private key
Returns
PublicKeyType
Public key (64 bytes uncompressed)
Example
isCompressed()
isCompressed: (Check if a public key is in compressed format Returns true for 33 bytes with 0x02/0x03 prefix, false otherwisebytes) =>boolean
Parameters
bytes
Uint8Array
Public key bytes
Returns
boolean
True if compressed format
Example
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(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 oddpublicKey):Uint8Array<ArrayBufferLike>
Parameters
publicKey
PublicKeyType
Uncompressed public key (64 bytes)
Returns
Uint8Array<ArrayBufferLike>
Compressed public key (33 bytes)
Example
_decompress()
_decompress(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 paritycompressed):PublicKeyType
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 invalidExample
_isCompressed()
_isCompressed(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 otherwisebytes):boolean
Parameters
bytes
Uint8Array<ArrayBufferLike>
Public key bytes
Returns
boolean
True if compressed format
Example
_toAddress()
_toAddress(Defined in: src/primitives/PublicKey/toAddress.ts:16 Derive Ethereum address from public keythis):AddressType
Parameters
this
PublicKeyType
Public key
Returns
AddressType
Ethereum address (20 bytes)
Example
_toHex()
_toHex(Defined in: src/primitives/PublicKey/toHex.ts:14 Convert PublicKey to hex stringthis):string
Parameters
this
PublicKeyType
Public key
Returns
string
Hex string
Example
compress()
compress(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.publicKey):Uint8Array
Parameters
publicKey
Public key (hex string or 64 bytes)string | Uint8Array<ArrayBufferLike>
Returns
Uint8Array
Compressed public key (33 bytes)
Example
decompress()
decompress(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.compressed):PublicKeyType
Parameters
compressed
Uint8Array
Compressed public key (33 bytes with 0x02/0x03 prefix)
Returns
PublicKeyType
Uncompressed public key (64 bytes)
Throws
If compressed format is invalidExample
from()
from(Defined in: src/primitives/PublicKey/from.ts:22 Create PublicKey from hex stringhex):PublicKeyType
Parameters
hex
string
Hex string (64 bytes uncompressed)
Returns
PublicKeyType
Public key
Throws
If hex string format is invalidThrows
If hex is not 64 bytesExample
fromPrivateKey()
fromPrivateKey(Defined in: src/primitives/PublicKey/fromPrivateKey.ts:16 Derive public key from private keyprivateKey):PublicKeyType
Parameters
privateKey
PrivateKeyType
Private key
Returns
PublicKeyType
Public key (64 bytes uncompressed)
Example
isCompressed()
isCompressed(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 otherwisebytes):boolean
Parameters
bytes
Uint8Array
Public key bytes
Returns
boolean
True if compressed format
Example
toAddress()
toAddress(Defined in: src/primitives/PublicKey/index.ts:32publicKey):AddressType
Parameters
publicKey
string
Returns
AddressType
toHex()
toHex(Defined in: src/primitives/PublicKey/index.ts:28publicKey):string
Parameters
publicKey
string
Returns
string
verify()
verify(Defined in: src/primitives/PublicKey/index.ts:36publicKey,hash,signature):boolean
Parameters
publicKey
string
hash
HashType
signature
SignatureType
Returns
boolean
Verify()
Verify(Defined in: src/primitives/PublicKey/verify.js:7 Factory: Verify signature against public keydeps): (publicKey,hash,signature) =>boolean
Parameters
deps
Crypto dependenciessecp256k1Verify
(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
