Create Address from secp256k1 public key coordinates using factory pattern. Enables tree-shakeable imports without bundling unnecessary crypto.Parameters:
deps.keccak256: (data: Uint8Array) => Uint8Array - Keccak256 hash function
Returns:(x: bigint, y: bigint) => AddressType - Function that creates Address from public keyExample:
import { FromPublicKey } from 'tevm/Address/AddressType'import { hash as keccak256 } from 'tevm/crypto/Keccak256'// Create factory with injected cryptoconst fromPublicKey = FromPublicKey({ keccak256 })// Use it to derive addressesconst x = 0x79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798nconst y = 0x483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8nconst addr = fromPublicKey(x, y)console.log(addr.length) // 20
Bundle Size: Tree-shakeable. Only includes keccak256 if used.Use Case: Optimal for libraries that need to avoid bundling crypto dependencies by default.
Derive address from secp256k1 public key using C API. Requires manual concatenation of coordinates and keccak256 hashing.Parameters:
x_bytes: uint8_t[32] - X coordinate (32 bytes, big-endian)
y_bytes: uint8_t[32] - Y coordinate (32 bytes, big-endian)
out_address: PrimitivesAddress* - Output address
Returns:int - PRIMITIVES_SUCCESS or error codeExample:
#include "primitives.h"#include <string.h>// Public key coordinates (32 bytes each, big-endian)uint8_t x[32] = { /* x coordinate bytes */ };uint8_t y[32] = { /* y coordinate bytes */ };// Concatenate coordinatesuint8_t pubkey[64];memcpy(pubkey, x, 32);memcpy(pubkey + 32, y, 32);// Hash with keccak256PrimitivesHash hash;int result = primitives_keccak256(pubkey, 64, &hash);if (result != PRIMITIVES_SUCCESS) { // Handle error}// Extract last 20 bytes as addressPrimitivesAddress addr;memcpy(addr.bytes, hash.bytes + 12, 20);
Note: C API does not provide a dedicated fromPublicKey function. Derive manually using primitives_keccak256 and extract last 20 bytes.Defined in:primitives.h:139
Cryptographic dependency: Uses keccak256 hash function internally.Bundle size impact:
Factory API (FromPublicKey): Tree-shakeable, only includes keccak256 if used
Namespace API (Address.fromPublicKey): Always includes keccak256 (~5-10 KB)
Recommendation: Use Factory API for libraries, Namespace API for applications.Alternative: For performance-critical code, consider using fromPrivateKey() directly if you have the private key, as it combines key derivation and address generation.