def authenticate(device, data, facet, check_only=False):
if isinstance(data, string_types):<EOL><INDENT>data = json.loads(data)<EOL><DEDENT>if data['<STR_LIT:version>'] != VERSION:<EOL><INDENT>raise ValueError('<STR_LIT>' % data['<STR_LIT:version>'])<EOL><DEDENT>app_id = data.get('<STR_LIT>', facet)<EOL>verify_facet(app_id, facet)<EOL>app_param = sha256(app_id.encode('<STR_LIT:utf8>')).digest()<EOL>key_handle = websafe_decode(data['<STR_LIT>'])<EOL>client_data = {<EOL>'<STR_LIT>': '<STR_LIT>',<EOL>'<STR_LIT>': data['<STR_LIT>'],<EOL>'<STR_LIT>': facet<EOL>}<EOL>client_data = json.dumps(client_data)<EOL>client_param = sha256(client_data.encode('<STR_LIT:utf8>')).digest()<EOL>request = client_param + app_param + int2byte(<EOL>len(key_handle)) + key_handle<EOL>p1 = <NUM_LIT> if check_only else <NUM_LIT><EOL>p2 = <NUM_LIT:0><EOL>response = device.send_apdu(INS_SIGN, p1, p2, request)<EOL>return {<EOL>'<STR_LIT>': websafe_encode(client_data),<EOL>'<STR_LIT>': websafe_encode(response),<EOL>'<STR_LIT>': data['<STR_LIT>']<EOL>}<EOL>
Signs an authentication challenge

data = {
    'version': "U2F_V2",
    'challenge': websafe_encode(self.challenge),
    'appId': self.binding.app_id,
    'keyHandle': websafe_encode(self.binding.key_handle)
}