Skip to content

Commit

Permalink
add chain id source to finding
Browse files Browse the repository at this point in the history
  • Loading branch information
aomerk committed Jul 27, 2023
1 parent 416d1da commit 4e073b1
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 16 deletions.
43 changes: 41 additions & 2 deletions cli/commands/run/server/alert.proto
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,43 @@ message Label {
repeated string metadata = 8;
}

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;
Expand All @@ -117,10 +154,12 @@ message Finding {
string alertId = 5;
string name = 6;
string description = 7;
string everestId = 8;
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;
}
41 changes: 27 additions & 14 deletions sdk/finding.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { EntityType, Label } from "./label"
import { assertIsFromEnum, assertIsNonEmptyString } from "./utils"
import {EntityType, Label} from "./label"
import {assertIsFromEnum, assertIsNonEmptyString} from "./utils"

export enum FindingSeverity {
Unknown,
Expand All @@ -19,31 +19,40 @@ export enum FindingType {
Scam
}

type FindingSourceChain = {
chainId: number
}
type FindingSources = {
chainSource: FindingSourceChain
}

type FindingInput = {
name: string,
description: string,
alertId: string,
protocol?: string,
severity: FindingSeverity,
type: FindingType,
metadata?: { [key: string]: string},
metadata?: { [key: string]: string },
addresses?: string[],
labels?: Label[],
uniqueKey?: string,
chainId?: number
}

export class Finding {
private constructor(
readonly name: string,
readonly description: string,
readonly alertId: string,
readonly protocol: string,
readonly severity: FindingSeverity,
readonly type: FindingType,
readonly metadata: { [key: string]: string},
readonly addresses: string[],
readonly labels: Label[],
readonly uniqueKey: string,
readonly name: string,
readonly description: string,
readonly alertId: string,
readonly protocol: string,
readonly severity: FindingSeverity,
readonly type: FindingType,
readonly metadata: { [key: string]: string },
readonly addresses: string[],
readonly labels: Label[],
readonly uniqueKey: string,
readonly sources: FindingSources,
) {}

toString() {
Expand Down Expand Up @@ -71,6 +80,7 @@ export class Finding {
addresses = [],
labels = [],
uniqueKey = '',
chainId = -1,
}: FindingInput) {
assertIsNonEmptyString(name, 'name')
assertIsNonEmptyString(description, 'description')
Expand All @@ -81,6 +91,9 @@ export class Finding {
// TODO assert metadata keys and values are strings

labels = labels.map(l => l instanceof Label ? l : Label.fromObject(l))
return new Finding(name, description, alertId, protocol, severity, type, metadata, addresses, labels, uniqueKey)
const sources = {chainSource: {chainId: chainId}}


return new Finding(name, description, alertId, protocol, severity, type, metadata, addresses, labels, uniqueKey, sources)
}
}

0 comments on commit 4e073b1

Please sign in to comment.