Files
Zach Kelling 055a2576ce chore: update copyright years to 2025 and Go version
- Update copyright headers to 2025
- Standardize Go version to 1.25.1
- Remove toolchain directive
2025-09-26 02:20:31 +00:00

23 lines
636 B
Go

// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package secp256k1
import (
"crypto/ecdsa"
"github.com/luxfi/crypto/common"
)
// PubkeyToAddress returns the Ethereum address for the given public key
func PubkeyToAddress(p ecdsa.PublicKey) common.Address {
pubBytes := make([]byte, 65)
pubBytes[0] = 0x04 // uncompressed point
copy(pubBytes[1:33], p.X.Bytes())
copy(pubBytes[33:65], p.Y.Bytes())
// Ethereum address is last 20 bytes of Keccak256 hash of public key (excluding prefix)
hash := Keccak256(pubBytes[1:])
return common.BytesToAddress(hash[12:])
}