def decode(cls, data): packed = messages.wrap(data) if packed is None: return None # signature must be at the end message_type = type(packed) signature = message_type.fields_spec[-1] assert signature.name == 'signature', 'signature is not the last field' message_data = data[:-signature.size_bytes] message_signature = data[-signature.size_bytes:] message_hash = sha3(message_data) data_that_was_signed = pack_signing_data( message_type.get_bytes_from(data, 'nonce'), message_type.get_bytes_from(data, 'transferred_amount'), message_type.get_bytes_from(data, 'channel'), message_type.get_bytes_from(data, 'locksroot'), message_hash, ) publickey = recover_publickey_safe(data_that_was_signed, message_signature) if publickey is None: return None message = cls.unpack(packed) # pylint: disable=no-member message.sender = publickey_to_address(publickey) return message
def decode(cls, data): packed = messages.wrap(data) if packed is None: return None return cls.unpack(packed)
def decode(cls, data): packed = messages.wrap(data) if packed is None: return # signature must be at the end message_type = type(packed) signature = message_type.fields_spec[-1] assert signature.name == 'signature', 'signature is not the last field' data_that_was_signed = data[:-signature.size_bytes] message_signature = data[-signature.size_bytes:] try: publickey = recover_publickey(data_that_was_signed, message_signature) except ValueError: # raised if the signature has the wrong length log.error('invalid signature') return except TypeError as e: # raised if the PublicKey instantiation failed log.error('invalid key data: {}'.format(e.message)) return except Exception as e: # pylint: disable=broad-except # secp256k1 is using bare Exception classes: raised if the recovery failed log.error('error while recovering pubkey: {}'.format(e.message)) return message = cls.unpack(packed) # pylint: disable=no-member message.sender = publickey_to_address(publickey) return message
def decode(cls, data): packed = messages.wrap(data) if packed is None: return None # signature must be at the end message_type = type(packed) signature = message_type.fields_spec[-1] assert signature.name == 'signature', 'signature is not the last field' message_data = data[:-signature.size_bytes] message_signature = data[-signature.size_bytes:] message_hash = sha3(message_data) data_that_was_signed = pack_signing_data( message_type.get_bytes_from(data, 'nonce'), message_type.get_bytes_from(data, 'transferred_amount'), # Locked amount should get signed when smart contracts change to include it # message_type.get_bytes_from(data, 'locked_amount'), message_type.get_bytes_from(data, 'channel'), message_type.get_bytes_from(data, 'locksroot'), message_hash, ) address = signing.recover_address(data_that_was_signed, message_signature) if address is None: return None message = cls.unpack(packed) # pylint: disable=no-member message.sender = address return message
def decode(cls, data): packed = messages.wrap(data) if packed is None: return # signature must be at the end message_type = type(packed) signature = message_type.fields_spec[-1] assert signature.name == 'signature', 'signature is not the last field' data_that_was_signed = data[:-signature.size_bytes] message_signature = data[-signature.size_bytes:] publickey = recover_publickey_safe(data_that_was_signed, message_signature) message = cls.unpack(packed) # pylint: disable=no-member message.sender = publickey_to_address(publickey) return message
def decode(cls, data): packed = messages.wrap(data) if packed is None: return None # signature must be at the end message_type = type(packed) signature = message_type.fields_spec[-1] assert signature.name == 'signature', 'signature is not the last field' data_that_was_signed = data[:-signature.size_bytes] message_signature = data[-signature.size_bytes:] address = signing.recover_address(data_that_was_signed, message_signature) if address is None: return None message = cls.unpack(packed) # pylint: disable=no-member message.sender = address return message
def decode(cls, data): packed = messages.wrap(data) return cls.unpack(packed)
def decode(cls, packed): packed = messages.wrap(packed) return cls.unpack(packed)