Skip to content

A modern platform for visual, flexible, and extensible graph-based investigations. For cybersecurity analysts and investigators.

feat(types): type registry + type detection

dextmorgn136de4240bc1
diff --git a/flowsint-types/src/flowsint_types/__init__.py b/flowsint-types/src/flowsint_types/__init__.py
index 08614dc8..30e6600e 100644
--- a/flowsint-types/src/flowsint_types/__init__.py
+++ b/flowsint-types/src/flowsint_types/__init__.py
@@ -2,6 +2,9 @@
Flowsint Types - Pydantic models for flowsint
"""
+# Import registry first to ensure it's ready for auto-registration
+from .registry import TYPE_REGISTRY, flowsint_type, get_type
+
from .address import Location
from .affiliation import Affiliation
from .alias import Alias
@@ -40,6 +43,9 @@ from .web_tracker import WebTracker
from .website import Website
from .whois import Whois
+# Import base
+from .flowsint_base import FlowsintType
+
from typing import Dict, Type, Any, Optional
from pydantic import BaseModel
@@ -88,13 +94,18 @@ __all__ = [
"WebTracker",
"Website",
"Whois",
- # Type registry utilities
+ # Type registry utilities (legacy)
"TYPE_TO_MODEL",
"get_model_for_type",
"clean_neo4j_node_data",
"parse_node_to_pydantic",
"serialize_pydantic_for_transport",
"deserialize_pydantic_from_transport",
+ # New type registry
+ "TYPE_REGISTRY",
+ "flowsint_type",
+ "get_type",
+ "FlowsintType",
]
@@ -140,6 +151,7 @@ TYPE_TO_MODEL: Dict[str, Type[BaseModel]] = {
"webtracker": WebTracker,
"weapon": Weapon,
"whois": Whois,
+ "FlowsintType": FlowsintType,
}
@@ -182,11 +194,11 @@ def clean_neo4j_node_data(node_data: Dict[str, Any]) -> Dict[str, Any]:
cleaned = {}
for k, v in node_data.items():
# Skip Neo4j-specific fields (including 'type' which is the node type in Neo4j)
- if k in ['sketch_id', 'created_at', 'type', 'x', 'y', 'caption', 'color']:
+ if k in ["sketch_id", "created_at", "type", "x", "y", "caption", "color"]:
continue
# Skip empty values (empty strings, None, empty lists, etc.)
- if v in ('', None, [], {}):
+ if v in ("", None, [], {}):
continue
cleaned[k] = v
@@ -215,10 +227,10 @@ def parse_node_to_pydantic(node_data: Dict[str, Any]) -> Optional[BaseModel]:
>>> isinstance(result, Domain)
True
"""
- if not node_data or 'type' not in node_data:
+ if not node_data or "type" not in node_data:
return None
- node_type = node_data.get('type')
+ node_type = node_data.get("type")
model_class = get_model_for_type(node_type)
if not model_class:
@@ -246,10 +258,12 @@ def serialize_pydantic_for_transport(obj: BaseModel) -> Dict[str, Any]:
Returns:
Dictionary representation suitable for JSON serialization
"""
- return obj.model_dump(mode='json')
+ return obj.model_dump(mode="json")
-def deserialize_pydantic_from_transport(data: Dict[str, Any], type_name: str) -> Optional[BaseModel]:
+def deserialize_pydantic_from_transport(
+ data: Dict[str, Any], type_name: str
+) -> Optional[BaseModel]:
"""
Deserialize a dictionary back into a Pydantic model instance.
diff --git a/flowsint-types/src/flowsint_types/address.py b/flowsint-types/src/flowsint_types/address.py
index ec108b68..822c0d79 100644
--- a/flowsint-types/src/flowsint_types/address.py
+++ b/flowsint-types/src/flowsint_types/address.py
@@ -1,8 +1,10 @@
from pydantic import Field, model_validator
from typing import Optional, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Location(FlowsintType):
"""Represents a physical address with geographical coordinates."""
@@ -21,3 +23,8 @@ class Location(FlowsintType):
def compute_label(self) -> Self:
self.label = f"{self.address}, {self.city}, {self.country}"
return self
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Location cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/affiliation.py b/flowsint-types/src/flowsint_types/affiliation.py
index f2332bb3..9bcd8c4e 100644
--- a/flowsint-types/src/flowsint_types/affiliation.py
+++ b/flowsint-types/src/flowsint_types/affiliation.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Affiliation(FlowsintType):
"""Represents an organizational affiliation or employment relationship."""
@@ -63,3 +65,13 @@ class Affiliation(FlowsintType):
else:
self.label = self.organization
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse an affiliation from a raw string."""
+ return cls(organization=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Affiliation cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/alias.py b/flowsint-types/src/flowsint_types/alias.py
index 0572bfb6..5489400a 100644
--- a/flowsint-types/src/flowsint_types/alias.py
+++ b/flowsint-types/src/flowsint_types/alias.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Alias(FlowsintType):
"""Represents an alias or alternative name used by an entity."""
@@ -50,3 +52,13 @@ class Alias(FlowsintType):
def compute_label(self) -> Self:
self.label = self.alias
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse an alias from a raw string."""
+ return cls(alias=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Alias cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/asn.py b/flowsint-types/src/flowsint_types/asn.py
index 188f5b0e..8be0a856 100644
--- a/flowsint-types/src/flowsint_types/asn.py
+++ b/flowsint-types/src/flowsint_types/asn.py
@@ -2,16 +2,21 @@ from typing import List, Optional, Union, Self
from pydantic import Field, field_validator, model_validator
import re
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class ASN(FlowsintType):
"""Represents an Autonomous System Number with associated network information."""
- number: int = Field(
- ..., description="Autonomous System Number (e.g., 15169)", title="ASN Number"
+ asn_str: str = Field(
+ ...,
+ description="ASN in string format (e.g., 'AS15169')",
+ title="ASN String",
+ json_schema_extra={"primary": True},
)
- asn_str: Optional[str] = Field(
- None, description="ASN in string format (e.g., 'AS15169')", title="ASN String", json_schema_extra={"primary": True}
+ number: Optional[int] = Field(
+ None, description="Autonomous System Number (e.g., 15169)", title="ASN Number"
)
name: Optional[str] = Field(
None,
@@ -24,49 +29,51 @@ class ASN(FlowsintType):
description: Optional[str] = Field(
None, description="Additional information about the ASN", title="Description"
)
- cidrs: List['CIDR'] = Field(
+ cidrs: List["CIDR"] = Field(
default_factory=list,
description="List of announced CIDR blocks",
title="CIDR Blocks",
)
- @field_validator('number', mode='before')
+ @field_validator("asn_str")
@classmethod
- def validate_asn_number(cls, v: Union[int, str]) -> int:
- """Validate and normalize ASN number.
+ def validate_asn_str(cls, v: str) -> str:
+ """Validate and normalize ASN string.
Accepts:
- - Integer: 15169
- String with AS prefix: "AS15169"
- String without prefix: "15169"
- Returns the integer ASN number.
+ Returns the string in "AS{number}" format.
"""
- if isinstance(v, str):
- # Remove 'AS' prefix if present (case insensitive)
- v = re.sub(r"(?i)^AS", "", v.strip())
- try:
- v = int(v)
- except ValueError:
- raise ValueError(f"Invalid ASN format: {v}")
+ v = v.strip()
- if not isinstance(v, int):
- raise ValueError(f"ASN must be an integer or string, got {type(v)}")
+ # Remove 'AS' prefix if present (case insensitive)
+ number_str = re.sub(r"(?i)^AS", "", v)
+
+ try:
+ number = int(number_str)
+ except ValueError:
+ raise ValueError(f"Invalid ASN format: {v}")
# Validate ASN range (32-bit unsigned integer)
- if not (0 <= v <= 4294967295):
- raise ValueError(f"ASN number must be between 0 and 4294967295, got {v}")
+ if not (0 <= number <= 4294967295):
+ raise ValueError(
+ f"ASN number must be between 0 and 4294967295, got {number}"
+ )
- return v
+ return f"AS{number}"
- @model_validator(mode='after')
- def populate_asn_str(self) -> Self:
- """Automatically populate asn_str from number if not provided."""
- # Always set asn_str based on number to ensure consistency
- self.asn_str = f"AS{self.number}"
+ @model_validator(mode="after")
+ def populate_number(self) -> Self:
+ """Automatically populate number from asn_str if not provided."""
+ # Extract number from asn_str
+ if self.number is None:
+ number_str = re.sub(r"(?i)^AS", "", self.asn_str)
+ self.number = int(number_str)
return self
- @model_validator(mode='after')
+ @model_validator(mode="after")
def compute_label(self) -> Self:
# Use name and ASN string if available
if self.name:
@@ -75,6 +82,22 @@ class ASN(FlowsintType):
self.label = self.asn_str
return self
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse an ASN from a raw string."""
+ return cls(asn_str=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ line = line.strip()
+ if not line:
+ return False
+ m = re.match(r"(?i)^AS(\d+)$", line)
+ if m:
+ num = int(m.group(1))
+ return 1 <= num <= 4294967295 # ASN range
+ return False
+
# Import CIDR here to avoid circular import
from .cidr import CIDR
diff --git a/flowsint-types/src/flowsint_types/bank_account.py b/flowsint-types/src/flowsint_types/bank_account.py
index dcac4173..0aee2f43 100644
--- a/flowsint-types/src/flowsint_types/bank_account.py
+++ b/flowsint-types/src/flowsint_types/bank_account.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class BankAccount(FlowsintType):
"""Represents a bank account with financial and security information."""
@@ -72,3 +74,13 @@ class BankAccount(FlowsintType):
parts.append(f"****{self.account_number[-4:]}" if len(self.account_number) > 4 else self.account_number)
self.label = " - ".join(parts)
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a bank account from a raw string."""
+ return cls(account_number=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """BankAccount cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/breach.py b/flowsint-types/src/flowsint_types/breach.py
index f5ff9a4d..be2e4a94 100644
--- a/flowsint-types/src/flowsint_types/breach.py
+++ b/flowsint-types/src/flowsint_types/breach.py
@@ -1,8 +1,10 @@
from typing import List, Optional, Dict, Self
from pydantic import Field, model_validator
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Breach(FlowsintType):
"""Represents a data breach incident with affected accounts and details."""
@@ -76,3 +78,13 @@ class Breach(FlowsintType):
else:
self.label = self.name
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a breach from a raw string."""
+ return cls(name=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Breach cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/cidr.py b/flowsint-types/src/flowsint_types/cidr.py
index 48ea3247..bf991e78 100644
--- a/flowsint-types/src/flowsint_types/cidr.py
+++ b/flowsint-types/src/flowsint_types/cidr.py
@@ -1,8 +1,11 @@
from pydantic import IPvAnyNetwork, Field, model_validator
from typing import Self
+import ipaddress
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class CIDR(FlowsintType):
"""Represents a CIDR (Classless Inter-Domain Routing) network block."""
@@ -14,3 +17,21 @@ class CIDR(FlowsintType):
def compute_label(self) -> Self:
self.label = str(self.network)
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a CIDR from a raw string."""
+ return cls(network=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Detect if a line of text contains a CIDR block."""
+ line = line.strip()
+ if not line or '/' not in line:
+ return False
+
+ try:
+ ipaddress.ip_network(line, strict=False)
+ return True
+ except ValueError:
+ return False
diff --git a/flowsint-types/src/flowsint_types/credential.py b/flowsint-types/src/flowsint_types/credential.py
index 8f4c613b..019a8d2f 100644
--- a/flowsint-types/src/flowsint_types/credential.py
+++ b/flowsint-types/src/flowsint_types/credential.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Credential(FlowsintType):
"""Represents user credentials with compromise and usage information."""
@@ -72,3 +74,13 @@ class Credential(FlowsintType):
else:
self.label = self.username
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a credential from a raw string."""
+ return cls(username=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Credential cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/credit_card.py b/flowsint-types/src/flowsint_types/credit_card.py
index 4c83d7db..72f5541e 100644
--- a/flowsint-types/src/flowsint_types/credit_card.py
+++ b/flowsint-types/src/flowsint_types/credit_card.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class CreditCard(FlowsintType):
"""Represents a credit card with financial details and security status."""
@@ -67,3 +69,36 @@ class CreditCard(FlowsintType):
parts.append(f"****{self.card_number[-4:]}" if len(self.card_number) > 4 else self.card_number)
self.label = " ".join(parts)
return self
+
+ @classmethod
+ def _luhn_check(cls, card_number: str) -> bool:
+ """Validate a credit card number using the Luhn algorithm."""
+ def digits_of(n):
+ return [int(d) for d in str(n)]
+
+ digits = digits_of(card_number)
+ odd_digits = digits[-1::-2]
+ even_digits = digits[-2::-2]
+ checksum = sum(odd_digits)
+ for d in even_digits:
+ checksum += sum(digits_of(d * 2))
+ return checksum % 10 == 0
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a credit card from a raw string."""
+ return cls(card_number=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Detect if a line of text contains a credit card number."""
+ line = line.strip().replace(' ', '').replace('-', '')
+ if not line or not line.isdigit():
+ return False
+
+ # Credit card numbers are typically 13-19 digits
+ if len(line) < 13 or len(line) > 19:
+ return False
+
+ # Use Luhn algorithm to validate
+ return cls._luhn_check(line)
diff --git a/flowsint-types/src/flowsint_types/device.py b/flowsint-types/src/flowsint_types/device.py
index 2cf82f86..b2b3edab 100644
--- a/flowsint-types/src/flowsint_types/device.py
+++ b/flowsint-types/src/flowsint_types/device.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Device(FlowsintType):
"""Represents a device with hardware, software, and network information."""
@@ -77,3 +79,13 @@ class Device(FlowsintType):
parts.append(self.device_id)
self.label = " ".join(parts)
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a device from a raw string."""
+ return cls(device_id=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Device cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/dns_record.py b/flowsint-types/src/flowsint_types/dns_record.py
index 2927c966..a8970cac 100644
--- a/flowsint-types/src/flowsint_types/dns_record.py
+++ b/flowsint-types/src/flowsint_types/dns_record.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class DNSRecord(FlowsintType):
"""Represents a DNS record with type, value, and security information."""
@@ -59,3 +61,8 @@ class DNSRecord(FlowsintType):
def compute_label(self) -> Self:
self.label = self.value
return self
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """DNSRecord cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/document.py b/flowsint-types/src/flowsint_types/document.py
index e7bac541..d48a10a5 100644
--- a/flowsint-types/src/flowsint_types/document.py
+++ b/flowsint-types/src/flowsint_types/document.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Document(FlowsintType):
"""Represents a document with metadata, security, and content information."""
@@ -63,3 +65,13 @@ class Document(FlowsintType):
def compute_label(self) -> Self:
self.label = self.title
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a document from a raw string."""
+ return cls(title=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Document cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/domain.py b/flowsint-types/src/flowsint_types/domain.py
index a46037b5..7f7cdf5e 100644
--- a/flowsint-types/src/flowsint_types/domain.py
+++ b/flowsint-types/src/flowsint_types/domain.py
@@ -3,8 +3,10 @@ from pydantic import Field, field_validator, model_validator
from urllib.parse import urlparse
import re
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Domain(FlowsintType):
"""Represents a domain name and its properties."""
@@ -42,3 +44,26 @@ class Domain(FlowsintType):
def compute_label(self) -> Self:
self.label = self.domain
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a domain from a raw string."""
+ return cls(domain=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Detect if a line of text contains a domain."""
+ line = line.strip()
+ if not line or len(line) > 253: # Max domain length
+ return False
+
+ # Basic domain pattern: alphanumeric + hyphens, dots, and must have TLD
+ domain_pattern = r'^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\.)+[a-zA-Z]{2,}$'
+ if not re.match(domain_pattern, line):
+ return False
+
+ # Additional validation: not too many consecutive dots, no leading/trailing dots
+ if '..' in line or line.startswith('.') or line.endswith('.'):
+ return False
+
+ return True
diff --git a/flowsint-types/src/flowsint_types/email.py b/flowsint-types/src/flowsint_types/email.py
index 5ace24a0..713f8e14 100644
--- a/flowsint-types/src/flowsint_types/email.py
+++ b/flowsint-types/src/flowsint_types/email.py
@@ -1,8 +1,11 @@
from pydantic import Field, EmailStr, model_validator
from typing import Any, Self
+import re
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Email(FlowsintType):
"""Represents an email address."""
@@ -12,3 +15,19 @@ class Email(FlowsintType):
def compute_label(self) -> Self:
self.label = self.email
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse an email from a raw string."""
+ return cls(email=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Detect if a line of text contains an email address."""
+ line = line.strip()
+ if not line:
+ return False
+
+ # Email regex pattern (RFC 5322 simplified)
+ email_pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$'
+ return bool(re.match(email_pattern, line))
diff --git a/flowsint-types/src/flowsint_types/file.py b/flowsint-types/src/flowsint_types/file.py
index 9640b20b..fb0d9f17 100644
--- a/flowsint-types/src/flowsint_types/file.py
+++ b/flowsint-types/src/flowsint_types/file.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class File(FlowsintType):
"""Represents a file with metadata, type information, and security assessment."""
@@ -68,3 +70,13 @@ class File(FlowsintType):
def compute_label(self) -> Self:
self.label = self.filename
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a file from a raw string."""
+ return cls(filename=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """File cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/flowsint_base.py b/flowsint-types/src/flowsint_types/flowsint_base.py
index 9cc9312c..00e39244 100644
--- a/flowsint-types/src/flowsint_types/flowsint_base.py
+++ b/flowsint-types/src/flowsint_types/flowsint_base.py
@@ -1,10 +1,36 @@
from pydantic import BaseModel, Field
-from typing import Optional
+from pydantic._internal._model_construction import ModelMetaclass
+from typing import Optional, Type
-class FlowsintType(BaseModel):
+class FlowsintTypeMetaclass(ModelMetaclass):
+ """
+ Metaclass for FlowsintType that automatically registers types in the TYPE_REGISTRY.
+
+ This metaclass ensures that any class that inherits from FlowsintType
+ is automatically registered in the global type registry.
+ """
+
+ def __new__(mcs, name: str, bases: tuple, namespace: dict, **kwargs):
+ # Create the class using Pydantic's metaclass
+ cls = super().__new__(mcs, name, bases, namespace, **kwargs)
+
+ # Only register if this is a subclass of FlowsintType (not FlowsintType itself)
+ # and if it's not an abstract class
+ if name != 'FlowsintType' and bases:
+ # Import here to avoid circular dependency
+ from .registry import TYPE_REGISTRY
+ TYPE_REGISTRY.register(cls)
+
+ return cls
+
+
+class FlowsintType(BaseModel, metaclass=FlowsintTypeMetaclass):
"""Base class for all Flowsint entity types with label support.
Label is optional but computed at definition time.
+
+ All classes that inherit from FlowsintType are automatically registered
+ in the global TYPE_REGISTRY and can be accessed by their class name.
"""
label: Optional[str] = Field(
None, description="UI-readable label for this entity, the one used on the graph.", title="Label"
diff --git a/flowsint-types/src/flowsint_types/gravatar.py b/flowsint-types/src/flowsint_types/gravatar.py
index 8590f1cc..2373fd96 100644
--- a/flowsint-types/src/flowsint_types/gravatar.py
+++ b/flowsint-types/src/flowsint_types/gravatar.py
@@ -1,8 +1,10 @@
from pydantic import Field, HttpUrl, model_validator
from typing import Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Gravatar(FlowsintType):
"""Represents a Gravatar profile with image and user information."""
@@ -52,3 +54,8 @@ class Gravatar(FlowsintType):
else:
self.label = f"{self.hash}"
return self
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Gravatar cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/individual.py b/flowsint-types/src/flowsint_types/individual.py
index 02087f10..413a0615 100644
--- a/flowsint-types/src/flowsint_types/individual.py
+++ b/flowsint-types/src/flowsint_types/individual.py
@@ -5,8 +5,10 @@ from .email import Email
from .phone import Phone
from .ip import Ip
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Individual(FlowsintType):
"""Represents an individual person with comprehensive personal information."""
@@ -18,7 +20,10 @@ class Individual(FlowsintType):
..., description="Last name of the individual", title="Last Name"
)
full_name: Optional[str] = Field(
- None, description="Full name of the individual", title="Full Name", json_schema_extra={"primary": True}
+ None,
+ description="Full name of the individual",
+ title="Full Name",
+ json_schema_extra={"primary": True},
)
middle_name: Optional[str] = Field(
None, description="Middle name or initial", title="Middle Name"
@@ -311,9 +316,11 @@ class Individual(FlowsintType):
None, description="Last update timestamp", title="Last Updated"
)
- @field_validator('email_addresses', mode='before')
+ @field_validator("email_addresses", mode="before")
@classmethod
- def validate_email_addresses(cls, v: Optional[List[Union[str, Email]]]) -> Optional[List[Email]]:
+ def validate_email_addresses(
+ cls, v: Optional[List[Union[str, Email]]]
+ ) -> Optional[List[Email]]:
"""Validate that all email addresses in the list are valid and convert to Email objects."""
if v is None:
return None
@@ -338,9 +345,11 @@ class Individual(FlowsintType):
return validated_emails if validated_emails else None
- @field_validator('phone_numbers', mode='before')
+ @field_validator("phone_numbers", mode="before")
@classmethod
- def validate_phone_numbers(cls, v: Optional[List[Union[str, Phone]]]) -> Optional[List[Phone]]:
+ def validate_phone_numbers(
+ cls, v: Optional[List[Union[str, Phone]]]
+ ) -> Optional[List[Phone]]:
"""Validate phone numbers in the list and convert to Phone objects."""
if v is None:
return None
@@ -363,9 +372,11 @@ class Individual(FlowsintType):
continue
return validated_phones if validated_phones else None
- @field_validator('ip_addresses', mode='before')
+ @field_validator("ip_addresses", mode="before")
@classmethod
- def validate_ip_addresses(cls, v: Optional[List[Union[str, Ip]]]) -> Optional[List[Ip]]:
+ def validate_ip_addresses(
+ cls, v: Optional[List[Union[str, Ip]]]
+ ) -> Optional[List[Ip]]:
"""Validate that all IP addresses in the list are valid and convert to Ip objects."""
if v is None:
return None
@@ -389,7 +400,7 @@ class Individual(FlowsintType):
return validated_ips if validated_ips else None
- @model_validator(mode='after')
+ @model_validator(mode="after")
def compute_label(self) -> Self:
# Use full_name if available, otherwise concatenate first and last name
if self.full_name:
@@ -401,3 +412,35 @@ class Individual(FlowsintType):
elif self.last_name:
self.label = self.last_name
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse an individual from a raw string (full name).
+
+ Splits the string on space to extract first_name and last_name.
+ Example: "John Doe" -> first_name="John", last_name="Doe"
+ """
+ line = line.strip()
+ parts = line.split(maxsplit=1)
+
+ if len(parts) == 1:
+ # Only one name provided, use it as first_name
+ return cls(first_name=parts[0], last_name="")
+ elif len(parts) >= 2:
+ # At least two parts, first is first_name, rest is last_name
+ return cls(first_name=parts[0], last_name=parts[1])
+ else:
+ # Empty string
+ return cls(first_name="", last_name="")
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """We can detect an individual only if we can split value in exactly 2 string"""
+ line = line.strip()
+ if not line:
+ return False
+ fullname = " ".split(line)
+ if len(fullname) == 2:
+ return True
+
+ return False
diff --git a/flowsint-types/src/flowsint_types/ip.py b/flowsint-types/src/flowsint_types/ip.py
index d4fdb688..7630acc4 100644
--- a/flowsint-types/src/flowsint_types/ip.py
+++ b/flowsint-types/src/flowsint_types/ip.py
@@ -2,8 +2,10 @@ from pydantic import Field, field_validator, model_validator
from typing import Optional, Any, Self
import ipaddress
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Ip(FlowsintType):
"""Represents an IP address with geolocation and ISP information."""
@@ -43,3 +45,21 @@ class Ip(FlowsintType):
def compute_label(self) -> Self:
self.label = self.address
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse an IP address from a raw string."""
+ return cls(address=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Detect if a line of text contains an IP address."""
+ line = line.strip()
+ if not line:
+ return False
+
+ try:
+ ipaddress.ip_address(line)
+ return True
+ except ValueError:
+ return False
diff --git a/flowsint-types/src/flowsint_types/leak.py b/flowsint-types/src/flowsint_types/leak.py
index 770ef2cd..bd2c4921 100644
--- a/flowsint-types/src/flowsint_types/leak.py
+++ b/flowsint-types/src/flowsint_types/leak.py
@@ -2,8 +2,10 @@ from typing import List, Dict, Optional, Self
from pydantic import Field, model_validator
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Leak(FlowsintType):
"""Represents a data leak or breach with associated data."""
@@ -18,3 +20,13 @@ class Leak(FlowsintType):
def compute_label(self) -> Self:
self.label = self.name
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a leak from a raw string."""
+ return cls(name=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Leak cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/malware.py b/flowsint-types/src/flowsint_types/malware.py
index fb8aeaf7..f24854da 100644
--- a/flowsint-types/src/flowsint_types/malware.py
+++ b/flowsint-types/src/flowsint_types/malware.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Malware(FlowsintType):
"""Represents malware with family, capabilities, and threat intelligence."""
@@ -68,3 +70,13 @@ class Malware(FlowsintType):
else:
self.label = self.name
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a malware from a raw string."""
+ return cls(name=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Malware cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/message.py b/flowsint-types/src/flowsint_types/message.py
index 8f15cab4..50648e87 100644
--- a/flowsint-types/src/flowsint_types/message.py
+++ b/flowsint-types/src/flowsint_types/message.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Message(FlowsintType):
"""Represents a message with content, metadata, and security analysis."""
@@ -72,3 +74,8 @@ class Message(FlowsintType):
content_preview = self.content[:50] + "..." if len(self.content) > 50 else self.content
self.label = content_preview
return self
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Message cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/organization.py b/flowsint-types/src/flowsint_types/organization.py
index 49cab9dc..a008df9d 100644
--- a/flowsint-types/src/flowsint_types/organization.py
+++ b/flowsint-types/src/flowsint_types/organization.py
@@ -3,8 +3,10 @@ from typing import Any, Optional, List, Self
from .individual import Individual
from .address import Location
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Organization(FlowsintType):
"""Represents an organization with detailed business and administrative information."""
@@ -381,3 +383,13 @@ class Organization(FlowsintType):
elif self.name:
self.label = str(self.name)
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse an organization from a raw string."""
+ return cls(name=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Organization cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/phone.py b/flowsint-types/src/flowsint_types/phone.py
index ffb032df..4d0ac4ad 100644
--- a/flowsint-types/src/flowsint_types/phone.py
+++ b/flowsint-types/src/flowsint_types/phone.py
@@ -3,8 +3,11 @@ from typing import Optional, Any, Self
import phonenumbers
from phonenumbers import NumberParseException
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+import ipaddress
+@flowsint_type
class Phone(FlowsintType):
"""Represents a phone number with country and carrier information."""
@@ -60,3 +63,40 @@ class Phone(FlowsintType):
def compute_label(self) -> Self:
self.label = self.number
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a phone number from a raw string."""
+ return cls(number=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Detect if a line of text contains a phone number."""
+ line = line.strip()
+ if not line:
+ return False
+ # 1) Avoid IP v4 / v6
+ try:
+ ipaddress.ip_address(line)
+ return False
+ except ValueError:
+ pass
+ # Try international format first (starts with +)
+ if line.startswith('+'):
+ try:
+ parsed = phonenumbers.parse(line, None)
+ return phonenumbers.is_valid_number(parsed)
+ except NumberParseException:
+ pass
+
+ # Try parsing with common regions
+ common_regions = ['US', 'GB', 'FR', 'DE', 'ES', 'IT', 'CA', 'AU', 'JP', 'CN']
+ for region in common_regions:
+ try:
+ parsed = phonenumbers.parse(line, region)
+ if phonenumbers.is_valid_number(parsed):
+ return True
+ except NumberParseException:
+ continue
+
+ return False
diff --git a/flowsint-types/src/flowsint_types/phrase.py b/flowsint-types/src/flowsint_types/phrase.py
index 601a43cc..0839d400 100644
--- a/flowsint-types/src/flowsint_types/phrase.py
+++ b/flowsint-types/src/flowsint_types/phrase.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Any, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Phrase(FlowsintType):
"""Represents a phrase or text content."""
@@ -17,3 +19,13 @@ class Phrase(FlowsintType):
# Truncate to 100 characters for display
self.label = text_str[:100] + "..." if len(text_str) > 100 else text_str
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a phrase from a raw string."""
+ return cls(text=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Phrase is a fallback type and should not be auto-detected to avoid false positives."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/port.py b/flowsint-types/src/flowsint_types/port.py
index b77da7b6..88a836ae 100644
--- a/flowsint-types/src/flowsint_types/port.py
+++ b/flowsint-types/src/flowsint_types/port.py
@@ -1,8 +1,10 @@
from pydantic import Field, field_validator, model_validator
from typing import Optional, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Port(FlowsintType):
"""Represents an open network port related to an IP address."""
@@ -38,3 +40,21 @@ class Port(FlowsintType):
parts.append(f"({self.protocol})")
self.label = " ".join(parts)
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a port from a raw string."""
+ return cls(number=int(line.strip()))
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Detect if a line of text contains a port number."""
+ line = line.strip()
+ if not line or not line.isdigit():
+ return False
+
+ try:
+ port = int(line)
+ return 0 <= port <= 65535
+ except ValueError:
+ return False
diff --git a/flowsint-types/src/flowsint_types/registry.py b/flowsint-types/src/flowsint_types/registry.py
new file mode 100644
index 00000000..dfc6da76
--- /dev/null
+++ b/flowsint-types/src/flowsint_types/registry.py
@@ -0,0 +1,137 @@
+"""
+This module provides an automatic type registration system using decorators.
+All FlowsintType subclasses can be decorated with @flowsint_type to automatically
+register themselves in the global TYPE_REGISTRY.
+"""
+
+from typing import Dict, Type, TypeVar, Optional
+from pydantic import BaseModel
+
+
+T = TypeVar("T", bound=BaseModel)
+
+
+class TypeRegistry:
+ """
+ Global registry for Flowsint types.
+
+ Stores mappings:
+ - Class name (e.g., "Domain") -> Class
+ - Lowercase name (e.g., "domain") -> Class (for Neo4j compatibility)
+ """
+
+ def __init__(self):
+ self._types: Dict[str, Type[BaseModel]] = {}
+ self._lowercase_types: Dict[str, Type[BaseModel]] = {}
+
+ def register(self, cls: Type[T]) -> Type[T]:
+ """
+ Register a type in the registry.
+
+ Args:
+ cls: The class to register
+
+ Returns:
+ The same class (for use as a decorator)
+ """
+ class_name = cls.__name__
+
+ # Register with exact class name
+ self._types[class_name] = cls
+
+ # Register with lowercase name for Neo4j compatibility
+ lowercase_name = class_name.lower()
+ self._lowercase_types[lowercase_name] = cls
+
+ return cls
+
+ def get(self, type_name: str) -> Optional[Type[BaseModel]]:
+ """
+ Get a type by its name (case-sensitive).
+
+ Args:
+ type_name: The type name (e.g., "Domain", "Ip")
+
+ Returns:
+ The corresponding class, or None if not found
+ """
+ return self._types.get(type_name)
+
+ def get_lowercase(self, type_name: str) -> Optional[Type[BaseModel]]:
+ """
+ Get a type by its lowercase name (for Neo4j compatibility).
+
+ Args:
+ type_name: The type name in lowercase (e.g., "domain", "ip")
+
+ Returns:
+ The corresponding class, or None if not found
+ """
+ return self._lowercase_types.get(type_name.lower())
+
+ def all_types(self) -> Dict[str, Type[BaseModel]]:
+ """
+ Get all registered types.
+
+ Returns:
+ Dictionary mapping class names to classes
+ """
+ return self._types.copy()
+
+ def all_types_lowercase(self) -> Dict[str, Type[BaseModel]]:
+ """
+ Get all registered types with lowercase keys.
+
+ Returns:
+ Dictionary mapping lowercase names to classes
+ """
+ return self._lowercase_types.copy()
+
+ def clear(self):
+ """Clear all registered types (mainly for testing)."""
+ self._types.clear()
+ self._lowercase_types.clear()
+
+
+# Global type registry instance
+TYPE_REGISTRY = TypeRegistry()
+
+
+def flowsint_type(cls: Type[T]) -> Type[T]:
+ """
+ Decorator to automatically register a FlowsintType subclass.
+
+ Usage:
+ @flowsint_type
+ class Domain(FlowsintType):
+ domain: str
+ ...
+
+ This will automatically register the type in TYPE_REGISTRY with:
+ - Key "Domain" -> Domain class
+ - Key "domain" -> Domain class (lowercase for Neo4j)
+
+ Args:
+ cls: The class to register
+
+ Returns:
+ The same class (unmodified)
+ """
+ return TYPE_REGISTRY.register(cls)
+
+
+def get_type(type_name: str, case_sensitive: bool = False) -> Optional[Type[BaseModel]]:
+ """
+ Convenience function to get a type from the global registry.
+
+ Args:
+ type_name: The type name to look up
+ case_sensitive: If True, use exact case; if False, use lowercase lookup
+
+ Returns:
+ The corresponding class, or None if not found
+ """
+ if case_sensitive:
+ return TYPE_REGISTRY.get(type_name)
+ else:
+ return TYPE_REGISTRY.get_lowercase(type_name)
diff --git a/flowsint-types/src/flowsint_types/reputation_score.py b/flowsint-types/src/flowsint_types/reputation_score.py
index 54424f8a..dfa13ec1 100644
--- a/flowsint-types/src/flowsint_types/reputation_score.py
+++ b/flowsint-types/src/flowsint_types/reputation_score.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class ReputationScore(FlowsintType):
"""Represents a reputation score for an entity with historical data and trends."""
@@ -64,3 +66,13 @@ class ReputationScore(FlowsintType):
parts.append(f"Score: {self.score}")
self.label = " - ".join(parts)
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a reputation score from a raw string."""
+ return cls(entity_id=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """ReputationScore cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/risk_profile.py b/flowsint-types/src/flowsint_types/risk_profile.py
index 05f57edd..f8de1820 100644
--- a/flowsint-types/src/flowsint_types/risk_profile.py
+++ b/flowsint-types/src/flowsint_types/risk_profile.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class RiskProfile(FlowsintType):
"""Represents a comprehensive risk assessment profile for an entity."""
@@ -81,3 +83,13 @@ class RiskProfile(FlowsintType):
parts.append(f"Risk: {self.risk_level}")
self.label = " - ".join(parts)
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a risk profile from a raw string."""
+ return cls(entity_id=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """RiskProfile cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/script.py b/flowsint-types/src/flowsint_types/script.py
index 1e28642e..aa905c2a 100644
--- a/flowsint-types/src/flowsint_types/script.py
+++ b/flowsint-types/src/flowsint_types/script.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Script(FlowsintType):
"""Represents a script or code file with analysis and security information."""
@@ -73,3 +75,13 @@ class Script(FlowsintType):
else:
self.label = self.script_id
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a script from a raw string."""
+ return cls(script_id=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Script cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/session.py b/flowsint-types/src/flowsint_types/session.py
index cdc1c09b..15afa6bc 100644
--- a/flowsint-types/src/flowsint_types/session.py
+++ b/flowsint-types/src/flowsint_types/session.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Session(FlowsintType):
"""Represents a user session with device and activity information."""
@@ -63,3 +65,13 @@ class Session(FlowsintType):
parts.append(self.session_id)
self.label = " - ".join(parts)
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a session from a raw string."""
+ return cls(session_id=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Session cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/social_account.py b/flowsint-types/src/flowsint_types/social_account.py
index 507ed7cb..61540d4f 100644
--- a/flowsint-types/src/flowsint_types/social_account.py
+++ b/flowsint-types/src/flowsint_types/social_account.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Optional, List, Self
from .username import Username
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class SocialAccount(FlowsintType):
"""Represents a social media account (the 'home' of a username)."""
@@ -44,3 +46,8 @@ class SocialAccount(FlowsintType):
else:
self.label = f"@{self.username.value}"
return self
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """SocialAccount cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/ssl_certificate.py b/flowsint-types/src/flowsint_types/ssl_certificate.py
index 4812daf3..fb06cc45 100644
--- a/flowsint-types/src/flowsint_types/ssl_certificate.py
+++ b/flowsint-types/src/flowsint_types/ssl_certificate.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class SSLCertificate(FlowsintType):
"""Represents an SSL/TLS certificate with validation and security details."""
@@ -76,3 +78,13 @@ class SSLCertificate(FlowsintType):
def compute_label(self) -> Self:
self.label = self.subject
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse an SSL certificate from a raw string."""
+ return cls(subject=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """SSLCertificate cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/username.py b/flowsint-types/src/flowsint_types/username.py
index e7064eae..5c57415d 100644
--- a/flowsint-types/src/flowsint_types/username.py
+++ b/flowsint-types/src/flowsint_types/username.py
@@ -2,8 +2,10 @@ from pydantic import Field, field_validator, model_validator
from typing import Optional, Any, Self
import re
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Username(FlowsintType):
"""Represents a username or handle on any platform."""
@@ -39,3 +41,19 @@ class Username(FlowsintType):
def compute_label(self) -> Self:
self.label = f"{self.value}"
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a username from a raw string."""
+ return cls(value=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Detect if a line of text contains a username."""
+ line = line.strip()
+ if not line:
+ return False
+
+ # Username pattern: 3-80 characters, only letters, numbers, underscores, hyphens
+ # Note: This is intentionally restrictive to avoid false positives
+ return bool(re.match(r"^[a-zA-Z0-9_-]{3,80}$", line))
diff --git a/flowsint-types/src/flowsint_types/wallet.py b/flowsint-types/src/flowsint_types/wallet.py
index 7ad33596..43d1f559 100644
--- a/flowsint-types/src/flowsint_types/wallet.py
+++ b/flowsint-types/src/flowsint_types/wallet.py
@@ -2,8 +2,10 @@ from typing import Optional, Self
from pydantic import Field, HttpUrl, field_validator, model_validator
import re
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class CryptoWallet(FlowsintType):
"""Represents a cryptocurrency wallet."""
@@ -45,7 +47,37 @@ class CryptoWallet(FlowsintType):
self.label = self.address
return self
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a crypto wallet from a raw string."""
+ return cls(address=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Detect if a line of text contains a cryptocurrency wallet address."""
+ line = line.strip()
+ if not line or len(line) < 26:
+ return False
+
+ # Ethereum pattern: 0x followed by 40 hex characters
+ ethereum_pattern = r'^0x[a-fA-F0-9]{40}$'
+ if re.match(ethereum_pattern, line):
+ return True
+
+ # Bitcoin legacy pattern: starts with 1 or 3, 26-35 characters
+ bitcoin_legacy_pattern = r'^[13][a-km-zA-HJ-NP-Z1-9]{25,34}$'
+ if re.match(bitcoin_legacy_pattern, line):
+ return True
+
+ # Bitcoin SegWit pattern: starts with bc1, 39-59 characters
+ bitcoin_segwit_pattern = r'^bc1[a-z0-9]{39,59}$'
+ if re.match(bitcoin_segwit_pattern, line):
+ return True
+
+ return False
+
+@flowsint_type
class CryptoWalletTransaction(FlowsintType):
"""Represents a cryptocurrency transaction."""
@@ -145,6 +177,7 @@ class CryptoWalletTransaction(FlowsintType):
return self
+@flowsint_type
class CryptoNFT(FlowsintType):
"""Represents a Non-Fungible Token (NFT) held or minted by a wallet."""
diff --git a/flowsint-types/src/flowsint_types/weapon.py b/flowsint-types/src/flowsint_types/weapon.py
index 57aa444f..5367745d 100644
--- a/flowsint-types/src/flowsint_types/weapon.py
+++ b/flowsint-types/src/flowsint_types/weapon.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Literal, Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Weapon(FlowsintType):
"""Represents a weapon with detailed specifications and forensic information."""
@@ -122,3 +124,13 @@ class Weapon(FlowsintType):
parts.append(f"({self.type})")
self.label = " ".join(parts)
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a weapon from a raw string."""
+ return cls(name=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Weapon cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/web_tracker.py b/flowsint-types/src/flowsint_types/web_tracker.py
index 7434c927..43a2e00e 100644
--- a/flowsint-types/src/flowsint_types/web_tracker.py
+++ b/flowsint-types/src/flowsint_types/web_tracker.py
@@ -2,8 +2,10 @@ from pydantic import Field, model_validator
from typing import Optional, List, Self
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class WebTracker(FlowsintType):
"""Represents a web tracking technology with privacy and compliance information."""
@@ -67,3 +69,13 @@ class WebTracker(FlowsintType):
else:
self.label = self.tracker_id
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a web tracker from a raw string."""
+ return cls(tracker_id=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """WebTracker cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/src/flowsint_types/website.py b/flowsint-types/src/flowsint_types/website.py
index 6160eaef..52751134 100644
--- a/flowsint-types/src/flowsint_types/website.py
+++ b/flowsint-types/src/flowsint_types/website.py
@@ -1,9 +1,12 @@
from typing import List, Optional, Self
from pydantic import Field, HttpUrl, model_validator
+import re
from .domain import Domain
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Website(FlowsintType):
"""Represents a website with its URL, domain, and redirect information."""
@@ -24,3 +27,19 @@ class Website(FlowsintType):
def compute_label(self) -> Self:
self.label = str(self.url)
return self
+
+ @classmethod
+ def from_string(cls, line: str):
+ """Parse a website from a raw string."""
+ return cls(url=line.strip())
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Detect if a line of text contains a website URL."""
+ line = line.strip()
+ if not line:
+ return False
+
+ # URL pattern: must start with http:// or https://
+ url_pattern = r'^https?://[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}(/.*)?$'
+ return bool(re.match(url_pattern, line))
diff --git a/flowsint-types/src/flowsint_types/whois.py b/flowsint-types/src/flowsint_types/whois.py
index 659200f9..988e37ef 100644
--- a/flowsint-types/src/flowsint_types/whois.py
+++ b/flowsint-types/src/flowsint_types/whois.py
@@ -4,8 +4,10 @@ from .email import Email
from .domain import Domain
from .organization import Organization
from .flowsint_base import FlowsintType
+from .registry import flowsint_type
+@flowsint_type
class Whois(FlowsintType):
"""Represents WHOIS domain registration information."""
@@ -71,3 +73,8 @@ class Whois(FlowsintType):
else:
self.label = self.domain.domain
return self
+
+ @classmethod
+ def detect(cls, line: str) -> bool:
+ """Whois cannot be reliably detected from a single line of text."""
+ return False
diff --git a/flowsint-types/tests/test_labels.py b/flowsint-types/tests/test_labels.py
index 901eef43..9f5aad13 100644
--- a/flowsint-types/tests/test_labels.py
+++ b/flowsint-types/tests/test_labels.py
@@ -176,12 +176,12 @@ def test_cidr_label():
def test_asn_label_with_name():
- asn = ASN(number=15169, name="Google LLC")
+ asn = ASN(asn_str="AS15169", name="Google LLC")
assert asn.label == "AS15169 - Google LLC"
def test_asn_label_without_name():
- asn = ASN(number=15169)
+ asn = ASN(asn_str="AS15169")
assert asn.label == "AS15169"
diff --git a/flowsint-types/tests/test_parser.py b/flowsint-types/tests/test_parser.py
index eaef7f6d..29f3d68d 100644
--- a/flowsint-types/tests/test_parser.py
+++ b/flowsint-types/tests/test_parser.py
@@ -496,7 +496,7 @@ class TestAllTypes:
'organization': {'name': 'ACME Corp'},
'individual': {'first_name': 'John', 'last_name': 'Doe'},
'socialaccount': {'username': {'value': 'johndoe'}},
- 'asn': {'number': 15169},
+ 'asn': {'asn_str': 'AS15169'},
'cidr': {'network': '192.168.1.0/24'},
'cryptowallet': {'address': '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'},
'cryptowallettransaction': {'source': {'address': '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'}},
diff --git a/flowsint-types/tests/test_registry.py b/flowsint-types/tests/test_registry.py
new file mode 100644
index 00000000..4c968394
--- /dev/null
+++ b/flowsint-types/tests/test_registry.py
@@ -0,0 +1,40 @@
+from flowsint_types import Domain, Ip, get_type
+from flowsint_types.registry import TYPE_REGISTRY
+
+
+def test_get_all():
+ types = TYPE_REGISTRY.all_types()
+ assert isinstance(types, dict)
+ # test basic types
+ assert "Domain" in types
+ assert "Individual" in types
+
+
+def test_get_by_capital_key():
+ type = TYPE_REGISTRY.get("Domain")
+ assert type is Domain
+
+
+def test_get_by_lower_key():
+ type = TYPE_REGISTRY.get_lowercase("domain")
+ assert type is Domain
+
+
+def test_get_by_lower_key():
+ type = TYPE_REGISTRY.get_lowercase("domain")
+ assert type is Domain
+
+
+def get_type_function():
+ # Probably the main util function used here, as we can pass it either capital or lowercase types
+ type_lower = get_type("domain")
+ type_capital = get_type("Domain")
+ assert type_lower is type_capital is Domain
+
+
+def get_correct_parsing():
+ # Probably the main util function used here, as we can pass it either capital or lowercase types
+ raw_dict = {"address": "12.23.45.67", type: "ip"}
+ MyType = get_type(raw_dict.get("type"))
+ new_ip_obj = MyType(**raw_dict)
+ assert isinstance(new_ip_obj, Ip)