This page is a placeholder. All examples on this page are currently AI-generated and are not correct. This documentation will be completed in the future with accurate, tested examples.
For tree-shakeable, crypto-agnostic implementation, use the factory function:
Copy
Ask AI
import { FromPrivateKey } from '@tevm/voltaire/Address/AddressType'import { hash as keccak256 } from '@tevm/voltaire/Keccak256'import { derivePublicKey } from '@tevm/voltaire/Secp256k1'import * as PrivateKey from '@tevm/voltaire/primitives/PrivateKey'// Create factory instance with both crypto dependenciesconst fromPrivateKey = FromPrivateKey({ keccak256, derivePublicKey })// Use the factoryconst privateKey = PrivateKey('0x...')const address = fromPrivateKey(privateKey)
Note: This method requires TWO crypto dependencies:
keccak256 - For hashing the public key
derivePublicKey - For deriving public key from private key
This allows complete control over which crypto implementations to use (native, WASM, or custom).
The C API does not currently expose fromPrivateKey directly. To derive addresses from private keys in C, use the crypto library’s secp256k1 functions to derive the public key first, then use primitives_address_from_public_key.Example workflow:
Copy
Ask AI
#include "tevm.h"// 1. Derive public key from private key (using secp256k1)uint8_t private_key[32] = { /* your private key */ };uint8_t public_key[64]; // x, y coordinates// Use secp256k1_pubkey_create or similar (not shown - requires crypto lib)// secp256k1_derive_public_key(private_key, public_key);// 2. Convert public key coordinates to address// Note: This function may not exist yet in C API// If not available, compute manually:// - Hash public key with keccak256// - Take last 20 bytes for address// Future API (when available):// PrimitivesAddress addr;// int result = primitives_address_from_public_key(public_key, 64, &addr);
Note: For production use with C, consider:
Using the crypto library directly for secp256k1 operations
Computing keccak256 hash of the derived public key
Extracting the last 20 bytes for the address
Alternative: Use Zig or TypeScript APIs for key derivation, then pass addresses to C code as hex strings or byte arrays.Defined in:src/primitives.h
Never hardcode or log private keys. Store securely and transmit only over encrypted channels. Compromised private keys allow complete control of associated addresses.
Best practices:
Generate from cryptographically secure random source