Sanity Checking on Public Keys

- Abstracted away sanity check
- Placed check in CLI and API.