syntax = "proto3";

package network.forta;

option go_package = "./;protocol";

message TrackingTimestamps {
  string block = 1;
  string feed = 2;
  string botRequest = 3;
  string botResponse = 4;
  string sourceAlert = 5;
}

enum AlertType {
  UNKNOWN_ALERT_TYPE = 0;
  TRANSACTION = 1;
  BLOCK = 2;
  PRIVATE = 3;
  COMBINATION = 4;
  API = 5;
}

message AgentInfo {
  string image = 1;
  string imageHash = 2;
  string id = 3;
  bool isTest = 4;
  string manifest = 5;
}

message ScannerInfo {
  string address = 1;
}

message AlertResponse {
  repeated SignedAlert alerts = 1;
  string nextPageToken = 2;
}

message Signature {
  string signature = 1;
  string algorithm = 2;
  string signer = 3;
}

message BloomFilter {
  string k = 1;
  string m = 2;
  string bitset = 3;
  uint32 itemCount = 4;
}

message Alert {
  string id = 1;
  AlertType type = 2;
  Finding finding = 3;
  string timestamp = 4;
  map<string, string> metadata = 5;
  AgentInfo agent = 6;
  map<string, string> tags = 7;
  ScannerInfo scanner = 8;
  TrackingTimestamps timestamps = 9;
  bool truncated = 10;
  BloomFilter addressBloomFilter = 11;
}

message SignedAlert {
  Alert alert = 1;
  Signature signature = 2;
  string chainId = 3;
  string blockNumber = 4;
  string publishedWithTx = 5;
}

message Label {
  enum EntityType {
    UNKNOWN_ENTITY_TYPE = 0;
    ADDRESS = 1;
    TRANSACTION = 2;
    BLOCK = 3;
    URL = 4;
  }

  EntityType entityType = 1;
  string entity = 2;
  reserved 3;
  float confidence = 4;
  reserved 5;
  bool remove = 6;
  string label = 7;
  repeated string metadata = 8;
  string uniqueKey = 9;
  repeated float embedding = 10;
}

message Source {
  message TransactionSource {
    uint64 chainId = 1;
    string hash = 2;
  }

  message BlockSource {
    uint64 chainId = 1;
    string hash = 2;
    uint64 number = 3;
  }

  message URLSource {
    string url = 1;
  }

  message ChainSource {
    uint64 chainId = 1;
  }

  message AlertSource {
    string id = 1;
  }

  message CustomSource {
    string name = 1;
    string value = 2;
  }

  repeated TransactionSource transactions = 1;
  repeated BlockSource blocks = 2;
  repeated URLSource urls = 3;
  repeated ChainSource chains = 4;
  repeated AlertSource alerts = 5;
  repeated CustomSource customSources = 6;
}

message Finding {
  enum Severity {
    UNKNOWN = 0;
    INFO = 1;
    LOW = 2;
    MEDIUM = 3;
    HIGH = 4;
    CRITICAL = 5;
  }

  enum FindingType {
    UNKNOWN_TYPE = 0;
    EXPLOIT = 1;
    SUSPICIOUS = 2;
    DEGRADED = 3;
    INFORMATION = 4;
    SCAM = 5;
  }

  string protocol = 1;
  Severity severity = 2;
  map<string, string> metadata = 3;
  FindingType type = 4;
  string alertId = 5;
  string name = 6;
  string description = 7;
  reserved 8;
  bool private = 9;
  repeated string addresses = 10;
  map<string, double> indicators = 11;
  repeated Label labels = 12;
  repeated string relatedAlerts = 13;
  string uniqueKey = 14;
  Source source = 15;
  string timestamp = 16;
}

message APIAlert {
  message APIAlertAgent {
    string id = 1;
  }
  string id = 1;
  AlertType type = 2;
  Finding finding = 3;
  APIAlertAgent agent = 4;
  string timestamp = 5;
}