2018-05-07 15:41:02 +00:00
|
|
|
package crypto
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ethereum/go-ethereum/crypto"
|
2018-11-21 15:30:00 +00:00
|
|
|
"github.com/ethereum/go-ethereum/p2p/discv5"
|
2018-05-07 15:41:02 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type PublicKeyParser interface {
|
|
|
|
ParsePublicKey(privateKey string) (string, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type EthPublicKeyParser struct{}
|
|
|
|
|
|
|
|
func (EthPublicKeyParser) ParsePublicKey(privateKey string) (string, error) {
|
|
|
|
np, err := crypto.HexToECDSA(privateKey)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
2018-11-21 15:30:00 +00:00
|
|
|
pubKey := discv5.PubkeyID(&np.PublicKey)
|
2018-05-07 15:41:02 +00:00
|
|
|
return pubKey.String(), nil
|
|
|
|
}
|