update pubkey method to use private key when available properly