status-go/account/address.go

24 lines
544 B
Go
Raw Permalink Normal View History

package account
import (
2019-12-19 16:03:00 +00:00
"github.com/status-im/status-go/eth-node/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
}