store.go
func (ks *Keystore) PublicKey() (crypto.PublicKey, bool) {
	ks.rw.RLock()
	key, pub := ks.Key, ks.PubKey
	ks.rw.RUnlock()
	if pub != nil {
		return pub, true
	}

	// generate the public key
	if key != nil {
		ks.rw.Lock()
		defer ks.rw.Unlock()

		if x, ok := key.(interface {
			Public() crypto.PublicKey
		}); ok {
			ks.PubKey = x.Public()
		}

		return ks.PubKey, ks.PubKey != nil
	}

	return nil, false
}
func (ks *Keystore) PublicKey() (crypto.PublicKey, bool) {
	ks.rw.RLock()
	key, pub := ks.Key, ks.PubKey
	ks.rw.RUnlock()
	if pub != nil {
		return pub, true
	}

	// generate the public key
	if key != nil {
		ks.rw.Lock()
		defer ks.rw.Unlock()

		if x, ok := key.(interface {
			Public() crypto.PublicKey
		}); ok {
			ks.PubKey = x.Public()
		}

		return ks.PubKey, ks.PubKey != nil
	}

	return nil, false
}
// PublicKey returns the stored public key for the keystore, alternately
// generating the public key from the private key if the public key was not
// supplied and the private key was.