check return for pubkey generation

avoids using a wrong pubkey when something goes wrong