Skip to main content

Try it Live

Run Address examples in the interactive playground
View the complete executable example at playground/src/examples/primitives/address/from-public-key.ts.

FromPublicKey({ keccak256 })

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:
Bundle Size: Tree-shakeable. Only includes keccak256 if used.Use Case: Optimal for libraries that need to avoid bundling crypto dependencies by default.

Algorithm

The address derivation follows Ethereum’s standard process:
  1. Concatenate coordinates - Combine x and y into 64-byte uncompressed public key
  2. Hash with keccak256 - Compute keccak256 hash (32 bytes output)
  3. Extract address - Take last 20 bytes of hash
Pseudocode:

Public Key Format

Ethereum uses uncompressed secp256k1 public keys:
  • Curve: secp256k1 (same as Bitcoin)
  • Coordinates: x and y, each 256 bits (32 bytes)
  • Total size: 64 bytes (no 0x04 prefix in Ethereum)
The x and y coordinates must be valid points on the secp256k1 curve.

Complete Example

Use Cases

Verifying Signatures

After recovering a public key from an ECDSA signature:

Deterministic Address Generation

Generate addresses from known public keys:

Performance

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.

See Also