@chainpatrol/sdk 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # `@chainpatrol/sdk`
2
+
3
+ Typescript SDK for ChainPatrol.
4
+
5
+ [Documentation](https://chainpatrol.io/docs/sdk/overview)
@@ -0,0 +1,225 @@
1
+ declare const ContinueAtOwnRisk = "CHAINPATROL_CONTINUE_AT_OWN_RISK";
2
+ declare const Events: {
3
+ readonly ContinueAtOwnRisk: "CHAINPATROL_CONTINUE_AT_OWN_RISK";
4
+ };
5
+ type EventData = {
6
+ [ContinueAtOwnRisk]: {
7
+ domain: string;
8
+ };
9
+ };
10
+
11
+ type Handle = {
12
+ addListener: (callback: (message: any) => void) => void;
13
+ removeListener: (callback: (message: any) => void) => void;
14
+ postMessage: (message: any) => void;
15
+ };
16
+ /**
17
+ * Relay contains methods for implementing an event relay. It is used to
18
+ * forward events between Javascript contexts:
19
+ *
20
+ * `<window>` <-> `<content script>` <-> `<background script>`
21
+ *
22
+ * Call `Relay.send` to send an event from one context to another. Call
23
+ * `Relay.on` to listen for events in the current context. Call `Relay.run`
24
+ * to start listening for events in the current context and forward them
25
+ * to all other contexts.
26
+ */
27
+ declare class Relay {
28
+ protected static handles: Handle[];
29
+ private static readonly logger;
30
+ static send<EventType extends keyof EventData>(type: EventType, data: EventData[EventType]): void;
31
+ static run(events: (keyof EventData)[]): () => void;
32
+ private static handleMessage;
33
+ static on<EventType extends keyof EventData>(targetEvent: EventType, callback: (data: EventData[EventType]) => void): () => void;
34
+ }
35
+
36
+ type ChainPatrolClientOptions = {
37
+ apiKey: string;
38
+ baseUrl?: string;
39
+ };
40
+ type AssetType = "URL" | "PAGE" | "ADDRESS";
41
+ type AssetStatus = "ALLOWED" | "BLOCKED" | "UNKNOWN";
42
+ declare class ChainPatrolClient {
43
+ readonly baseUrl: string;
44
+ private readonly apiKey;
45
+ private readonly logger;
46
+ constructor(options: ChainPatrolClientOptions);
47
+ private fetch;
48
+ get asset(): {
49
+ check: (req: {
50
+ type: AssetType;
51
+ content: string;
52
+ }) => Promise<{
53
+ /**
54
+ * "ALLOWED" - the asset is on the allowlist
55
+ * "BLOCKED" - the asset is on the blocklist
56
+ * "UNKNOWN" - the asset's status is not known
57
+ */
58
+ status: AssetStatus;
59
+ /**
60
+ * If the asset is allowed or blocked, this will be the reason why.
61
+ * ChainPatrol aggregates data from multiple sources, so this will
62
+ * tell you which source blocked or allowed the asset.
63
+ *
64
+ * ex. 'eth-phishing-detect' - the asset is on MetaMask's blocklist
65
+ * 'reported' - the asset is on ChainPatrol's blocklist because
66
+ * it was reported by a user
67
+ */
68
+ reason?: string;
69
+ }>;
70
+ list: (req: {
71
+ /**
72
+ * Asset type
73
+ */
74
+ type: AssetType;
75
+ /**
76
+ * Status of the assets to retrieve
77
+ */
78
+ status: AssetStatus;
79
+ /**
80
+ * The start date to list assets from. This should be in the format `YYYY-MM-DD` and is inclusive.
81
+ */
82
+ startDate?: string;
83
+ /**
84
+ * The end date to list assets from. This should be in the format `YYYY-MM-DD` and is inclusive.
85
+ */
86
+ endDate?: string;
87
+ }) => Promise<{
88
+ content: string;
89
+ type: AssetType;
90
+ status: AssetStatus;
91
+ }[]>;
92
+ };
93
+ }
94
+
95
+ interface Storage {
96
+ get: (key: string) => Promise<string | null>;
97
+ set: (key: string, value: string) => Promise<void>;
98
+ delete: (key: string) => Promise<void>;
99
+ size: () => Promise<number>;
100
+ }
101
+
102
+ type Prettify<T> = T extends infer U ? (U extends string ? U : never) : never;
103
+ type DetectorAssetStatus = Prettify<AssetStatus | "IGNORED">;
104
+ type URLResult = {
105
+ ok: true;
106
+ status: DetectorAssetStatus;
107
+ url: string;
108
+ redirectUrl?: string;
109
+ } | {
110
+ ok: false;
111
+ url: string;
112
+ error: string;
113
+ };
114
+ declare class DomainParseError extends Error {
115
+ constructor(message: string);
116
+ }
117
+ declare class ThreatDetector {
118
+ static StorageKeys: {
119
+ ALLOWLIST: string;
120
+ BLOCKLIST: string;
121
+ IGNORELIST: string;
122
+ };
123
+ private static readonly Schema;
124
+ private mode;
125
+ private client?;
126
+ private storage;
127
+ private redirectUrl?;
128
+ private readonly logger;
129
+ constructor({ mode, storage, redirectUrl, }: {
130
+ mode: "local";
131
+ storage?: Storage;
132
+ redirectUrl?: string | ((url: string) => string);
133
+ });
134
+ constructor({ mode, apiKey, storage, redirectUrl, }: {
135
+ mode: "cloud";
136
+ apiKey: string;
137
+ storage?: Storage;
138
+ redirectUrl?: string | ((url: string) => string);
139
+ });
140
+ constructor({ mode, apiKey, proxyUrl, storage, redirectUrl, }: {
141
+ mode: "cloud";
142
+ apiKey: string;
143
+ proxyUrl?: string;
144
+ storage?: Storage;
145
+ redirectUrl?: string | ((url: string) => string);
146
+ });
147
+ url(url: string): Promise<URLResult>;
148
+ private generateDomains;
149
+ private urlHelper;
150
+ allow(url: string): Promise<{
151
+ ok: true;
152
+ url: string;
153
+ } | {
154
+ ok: false;
155
+ url: string;
156
+ error: string;
157
+ }>;
158
+ block(url: string): Promise<{
159
+ ok: true;
160
+ url: string;
161
+ } | {
162
+ ok: false;
163
+ url: string;
164
+ error: string;
165
+ }>;
166
+ ignore(url: string): Promise<{
167
+ ok: true;
168
+ url: string;
169
+ } | {
170
+ ok: false;
171
+ url: string;
172
+ error: string;
173
+ }>;
174
+ private parseDomainOrThrow;
175
+ private invalidateDomainInCaches;
176
+ private invalidateDomainInCache;
177
+ private addDomainToCache;
178
+ private isDomainInList;
179
+ private getListFromStorage;
180
+ private setListInStorage;
181
+ private getStatusFromCache;
182
+ }
183
+
184
+ declare const Extension: () => {
185
+ get: (key: string) => Promise<any>;
186
+ set: (key: string, value: string) => Promise<void>;
187
+ delete: (key: string) => Promise<void>;
188
+ size: () => Promise<number>;
189
+ };
190
+
191
+ declare const Browser: () => {
192
+ get: (key: string) => Promise<string | null>;
193
+ set: (key: string, value: string) => Promise<void>;
194
+ delete: (key: string) => Promise<void>;
195
+ size: () => Promise<number>;
196
+ };
197
+
198
+ declare const Memory: () => {
199
+ get: (key: string) => Promise<string | null>;
200
+ set: (key: string, value: string) => Promise<void>;
201
+ delete: (key: string) => Promise<void>;
202
+ size: () => Promise<number>;
203
+ };
204
+
205
+ interface Context {
206
+ keys: string[];
207
+ }
208
+ declare function defineStorage<T extends Storage>(config: (ctx: Context) => T): () => T;
209
+
210
+ declare const index_Browser: typeof Browser;
211
+ declare const index_Extension: typeof Extension;
212
+ declare const index_Memory: typeof Memory;
213
+ type index_Storage = Storage;
214
+ declare const index_defineStorage: typeof defineStorage;
215
+ declare namespace index {
216
+ export {
217
+ index_Browser as Browser,
218
+ index_Extension as Extension,
219
+ index_Memory as Memory,
220
+ index_Storage as Storage,
221
+ index_defineStorage as defineStorage,
222
+ };
223
+ }
224
+
225
+ export { AssetStatus, AssetType, ChainPatrolClient, ChainPatrolClientOptions, DetectorAssetStatus, DomainParseError, EventData, Events, Relay, index as Storage, ThreatDetector, URLResult };