lotus/lib/sigs/delegated/eth.go
raulk e7aa7cb04f
add a basic FEVM integration test. (#9922)
* add a basic FEVM integration test.

Exercises f4 addresses, placeholder transitions, Ethereum Account.

* remove unused parameter from newEthTxFromFilecoinMessageLookup.

* break when found in newEthTxFromFilecoinMessageLookup.

* fixup test.

* lint and gen.

* move test to itests root package.

Co-authored-by: Shrenuj Bansal <shrenuj.bansal@protocol.ai>
2022-12-21 15:12:07 -05:00

27 lines
766 B
Go

package delegated
import (
"fmt"
"golang.org/x/crypto/sha3"
)
// EthAddressFromPubKey returns the Ethereum address corresponding to an
// uncompressed secp256k1 public key.
//
// TODO move somewhere else, this likely doesn't belong here.
func EthAddressFromPubKey(pubk []byte) ([]byte, error) {
// if we get an uncompressed public key (that's what we get from the library,
// but putting this check here for defensiveness), strip the prefix
if pubk[0] != 0x04 {
return nil, fmt.Errorf("expected first byte of secp256k1 to be 0x04 (uncompressed)")
}
pubk = pubk[1:]
// Calculate the Ethereum address based on the keccak hash of the pubkey.
hasher := sha3.NewLegacyKeccak256()
hasher.Write(pubk)
ethAddr := hasher.Sum(nil)[12:]
return ethAddr, nil
}