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

primitives/PrivateKey

Type Aliases

PrivateKeyType

PrivateKeyType = Uint8Array & object
Defined in: src/primitives/PrivateKey/PrivateKeyType.ts:7 Branded PrivateKey type - 32 byte private key for cryptographic operations Prevents accidental exposure or misuse of sensitive key material

Type Declaration

[brand]
readonly [brand]: "PrivateKey"
length
readonly length: 32

Variables

_sign()

const _sign: (privateKey, hash) => Secp256k1SignatureType
Defined in: src/primitives/PrivateKey/index.ts:25

Parameters

privateKey
PrivateKeyType
hash
HashType

Returns

Secp256k1SignatureType

PrivateKey

const PrivateKey: object
Defined in: src/primitives/PrivateKey/index.ts:51

Type Declaration

from()
from: (hex) => PrivateKeyType
Create PrivateKey from hex string
Parameters
hex
string Hex string (32 bytes)
Returns
PrivateKeyType Private key
Throws
If hex string format is invalid
Throws
If hex is not 32 bytes
Example
const pk = PrivateKey.from("0x1234...");
fromBytes()
fromBytes: (bytes) => PrivateKeyType
Create PrivateKey from raw bytes
Parameters
bytes
Uint8Array<ArrayBufferLike> Raw bytes (must be 32 bytes)
Returns
PrivateKeyType Private key
Throws
If bytes is not 32 bytes
Example
import * as PrivateKey from './primitives/PrivateKey/index.js';
const bytes = new Uint8Array(32);
const privateKey = PrivateKey.fromBytes(bytes);
sign()
sign: (privateKey, hash) => Secp256k1SignatureType
Parameters
privateKey
string
hash
HashType
Returns
Secp256k1SignatureType
toAddress()
toAddress: (privateKey) => AddressType
Parameters
privateKey
string
Returns
AddressType
toHex()
toHex: (privateKey) => string
Parameters
privateKey
string
Returns
string
toPublicKey()
toPublicKey: (privateKey) => PublicKeyType
Parameters
privateKey
string
Returns
PublicKeyType

Functions

_toAddress()

_toAddress(this): AddressType
Defined in: src/primitives/PrivateKey/toAddress.ts:17 Derive Ethereum address from private key

Parameters

this
PrivateKeyType Private key

Returns

AddressType Ethereum address (20 bytes)

Example

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

_toHex()

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

Parameters

this
PrivateKeyType Private key

Returns

string Hex string

Example

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

_toPublicKey()

_toPublicKey(this): PublicKeyType
Defined in: src/primitives/PrivateKey/toPublicKey.ts:16 Derive public key from private key

Parameters

this
PrivateKeyType Private key

Returns

PublicKeyType Public key (uncompressed 64 bytes)

Example

const publicKey = PrivateKey._toPublicKey.call(pk);

from()

from(hex): PrivateKeyType
Defined in: src/primitives/PrivateKey/from.ts:22 Create PrivateKey from hex string

Parameters

hex
string Hex string (32 bytes)

Returns

PrivateKeyType Private key

Throws

If hex string format is invalid

Throws

If hex is not 32 bytes

Example

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

fromBytes()

fromBytes(bytes): PrivateKeyType
Defined in: src/primitives/PrivateKey/fromBytes.js:17 Create PrivateKey from raw bytes

Parameters

bytes
Uint8Array<ArrayBufferLike> Raw bytes (must be 32 bytes)

Returns

PrivateKeyType Private key

Throws

If bytes is not 32 bytes

Example

import * as PrivateKey from './primitives/PrivateKey/index.js';
const bytes = new Uint8Array(32);
const privateKey = PrivateKey.fromBytes(bytes);

sign()

sign(privateKey, hash): Secp256k1SignatureType
Defined in: src/primitives/PrivateKey/index.ts:40

Parameters

privateKey
string
hash
HashType

Returns

Secp256k1SignatureType

Sign()

Sign(deps): (privateKey, hash) => Secp256k1SignatureType
Defined in: src/primitives/PrivateKey/sign.js:7 Factory: Sign a message hash with private key

Parameters

deps
Crypto dependencies
secp256k1Sign
(messageHash, privateKey) => Secp256k1SignatureType Secp256k1 signing function

Returns

Function that creates ECDSA signature
(privateKey, hash): Secp256k1SignatureType
Parameters
privateKey
PrivateKeyType
hash
HashType
Returns
Secp256k1SignatureType

toAddress()

toAddress(privateKey): AddressType
Defined in: src/primitives/PrivateKey/index.ts:36

Parameters

privateKey
string

Returns

AddressType

toHex()

toHex(privateKey): string
Defined in: src/primitives/PrivateKey/index.ts:28

Parameters

privateKey
string

Returns

string

toPublicKey()

toPublicKey(privateKey): PublicKeyType
Defined in: src/primitives/PrivateKey/index.ts:32

Parameters

privateKey
string

Returns

PublicKeyType

References

BrandedPrivateKey

Renames and re-exports PrivateKeyType

default

Renames and re-exports PrivateKey