diff --git a/minode/shared.py b/minode/shared.py index d49786c..8c6a7d6 100644 --- a/minode/shared.py +++ b/minode/shared.py @@ -16,6 +16,8 @@ ip_enabled = True log_level = logging.INFO +curve = 714 # secp256k1 +key_length = 32 magic_bytes = b'\xe9\xbe\xb4\xd9' protocol_version = 3 services = 3 # NODE_NETWORK, NODE_SSL diff --git a/minode/structure.py b/minode/structure.py index d2352fa..88ee6bc 100644 --- a/minode/structure.py +++ b/minode/structure.py @@ -132,6 +132,31 @@ class Object(): return False return True + def is_junk(self): + """ + Returns True if an object with encrypted payload has + curve number or key length different from those defined in shared. + """ + if self.object_type not in (1, 2, 3): + return False + if self.object_type == 2: + sp = 0 + elif self.object_type == 1 and self.version != 4: + return False + else: + sp = 32 + sp += 16 + curve = struct.unpack('!H', self.object_payload[sp:sp + 2])[0] + if curve != shared.curve: + return True + length = struct.unpack('!H', self.object_payload[sp + 2:sp + 4])[0] + if length > shared.key_length: + return True + length = struct.unpack('!H', self.object_payload[sp + 36:sp + 38])[0] + if length > shared.key_length: + return True + return False + def pow_target(self): """Compute PoW target""" data = self.to_bytes()[8:]