status-go/account/address.go

24 lines
536 B
Go
Raw Normal View History

package account
import (
"github.com/ethereum/go-ethereum/crypto"
"github.com/status-im/status-go/eth-node/types"
)
func CreateAddress() (address, pubKey, privKey string, err error) {
key, err := crypto.GenerateKey()
if err != nil {
return "", "", "", err
}
privKeyBytes := crypto.FromECDSA(key)
pubKeyBytes := crypto.FromECDSAPub(&key.PublicKey)
addressBytes := crypto.PubkeyToAddress(key.PublicKey)
privKey = types.EncodeHex(privKeyBytes)
pubKey = types.EncodeHex(pubKeyBytes)
address = addressBytes.Hex()
return
}