Fix behavior when calling get_master_public_key from an external context

Fix #842 #854