Created
February 20, 2023 05:58
-
-
Save smallyunet/f62c540fba2311a2c4d25e350ef666fb to your computer and use it in GitHub Desktop.
Eth private key to address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/hex" | |
"fmt" | |
"github.com/ethereum/go-ethereum/common/hexutil" | |
"github.com/ethereum/go-ethereum/crypto/secp256k1" | |
"github.com/wealdtech/go-merkletree/keccak256" | |
) | |
func main() { | |
privateKeyStr := "0x0000000000000000000000000000000000000000000000000000000000000001" | |
privateKey, err := hexutil.Decode(privateKeyStr) | |
if err != nil { | |
panic(err) | |
} | |
cv := secp256k1.S256() | |
puKeyX, puKeyY := cv.ScalarBaseMult(privateKey) | |
var x [32]byte | |
var y [32]byte | |
copy(x[:], puKeyX.Bytes()) | |
copy(y[:], puKeyY.Bytes()) | |
concatXY := append(x[:], y[:]...) | |
k := keccak256.New() | |
ethAddr := k.Hash(concatXY[:]) | |
ethAddrHex := "0x" + hex.EncodeToString(ethAddr[:])[24:] | |
fmt.Println(privateKeyStr, ethAddrHex) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment