@threatledger/sdk 0.1.0
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 +46 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +40 -0
- package/package.json +23 -0
- package/src/index.ts +64 -0
- package/tsconfig.json +14 -0
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @threatledger/sdk
|
|
2
|
+
|
|
3
|
+
Official JavaScript/TypeScript SDK for the [ThreatLedger](https://threatledger.net) Threat Intelligence API.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @threatledger/sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```typescript
|
|
14
|
+
import { ThreatLedger } from '@threatledger/sdk';
|
|
15
|
+
|
|
16
|
+
const tl = new ThreatLedger({ apiKey: 'your-api-key' });
|
|
17
|
+
|
|
18
|
+
// Check address risk
|
|
19
|
+
const result = await tl.checkAddress('0x098b716b8aaf21512996dc57eb0615e2383e2f96');
|
|
20
|
+
console.log(result.risk_level); // "CRITICAL"
|
|
21
|
+
|
|
22
|
+
// List incidents
|
|
23
|
+
const incidents = await tl.listIncidents({ severity: 'critical' });
|
|
24
|
+
|
|
25
|
+
// Check credits
|
|
26
|
+
const credits = await tl.getCredits();
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## API Reference
|
|
30
|
+
|
|
31
|
+
| Method | Description |
|
|
32
|
+
|--------|-------------|
|
|
33
|
+
| `checkAddress(address)` | Check address against threat database |
|
|
34
|
+
| `listIncidents(params?)` | List security incidents |
|
|
35
|
+
| `listActors()` | List known threat actors |
|
|
36
|
+
| `listPatterns()` | List attack patterns |
|
|
37
|
+
| `getCredits()` | Check API credit balance |
|
|
38
|
+
|
|
39
|
+
## Links
|
|
40
|
+
|
|
41
|
+
- [API Docs](https://threatledger.net/docs/)
|
|
42
|
+
- [Full Documentation](https://merkleclaw.com/developers/)
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
MIT — [ZeroVector Limited](https://zerovector.hk)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ThreatLedger JavaScript SDK
|
|
3
|
+
*/
|
|
4
|
+
export interface ThreatLedgerConfig {
|
|
5
|
+
apiKey: string;
|
|
6
|
+
baseUrl?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface AddressCheckResult {
|
|
9
|
+
address: string;
|
|
10
|
+
found: boolean;
|
|
11
|
+
risk_score: number;
|
|
12
|
+
risk_level: string;
|
|
13
|
+
entry?: {
|
|
14
|
+
chain: string;
|
|
15
|
+
tier: string;
|
|
16
|
+
entity: string;
|
|
17
|
+
reason: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export interface Incident {
|
|
21
|
+
id: string;
|
|
22
|
+
title: string;
|
|
23
|
+
date: string;
|
|
24
|
+
chain: string;
|
|
25
|
+
severity: string;
|
|
26
|
+
loss_usd: number;
|
|
27
|
+
protocol: string;
|
|
28
|
+
description: string;
|
|
29
|
+
}
|
|
30
|
+
export declare class ThreatLedger {
|
|
31
|
+
private apiKey;
|
|
32
|
+
private baseUrl;
|
|
33
|
+
constructor(config: ThreatLedgerConfig);
|
|
34
|
+
private request;
|
|
35
|
+
checkAddress(address: string): Promise<AddressCheckResult>;
|
|
36
|
+
listIncidents(params?: {
|
|
37
|
+
chain?: string;
|
|
38
|
+
severity?: string;
|
|
39
|
+
page?: number;
|
|
40
|
+
}): Promise<Incident[]>;
|
|
41
|
+
listActors(): Promise<unknown[]>;
|
|
42
|
+
listPatterns(): Promise<unknown[]>;
|
|
43
|
+
getCredits(): Promise<{
|
|
44
|
+
tier: string;
|
|
45
|
+
remaining: number;
|
|
46
|
+
total_credits: number;
|
|
47
|
+
}>;
|
|
48
|
+
}
|
|
49
|
+
export default ThreatLedger;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ThreatLedger JavaScript SDK
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ThreatLedger = void 0;
|
|
7
|
+
class ThreatLedger {
|
|
8
|
+
constructor(config) {
|
|
9
|
+
this.apiKey = config.apiKey;
|
|
10
|
+
this.baseUrl = config.baseUrl || 'https://api.threatledger.net/v1';
|
|
11
|
+
}
|
|
12
|
+
async request(path, options) {
|
|
13
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
14
|
+
...options,
|
|
15
|
+
headers: { 'X-API-Key': this.apiKey, 'Content-Type': 'application/json', ...options?.headers },
|
|
16
|
+
});
|
|
17
|
+
if (!res.ok)
|
|
18
|
+
throw new Error(`ThreatLedger API error: ${res.status}`);
|
|
19
|
+
const json = await res.json();
|
|
20
|
+
return json.data;
|
|
21
|
+
}
|
|
22
|
+
async checkAddress(address) {
|
|
23
|
+
return this.request(`/addresses/check?address=${address}`);
|
|
24
|
+
}
|
|
25
|
+
async listIncidents(params) {
|
|
26
|
+
const qs = new URLSearchParams(params).toString();
|
|
27
|
+
return this.request(`/incidents${qs ? '?' + qs : ''}`);
|
|
28
|
+
}
|
|
29
|
+
async listActors() {
|
|
30
|
+
return this.request('/actors');
|
|
31
|
+
}
|
|
32
|
+
async listPatterns() {
|
|
33
|
+
return this.request('/patterns');
|
|
34
|
+
}
|
|
35
|
+
async getCredits() {
|
|
36
|
+
return this.request('/credits/balance');
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.ThreatLedger = ThreatLedger;
|
|
40
|
+
exports.default = ThreatLedger;
|
package/package.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@threatledger/sdk",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "ThreatLedger API JavaScript/TypeScript SDK",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"prepublishOnly": "npm run build"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"blockchain",
|
|
13
|
+
"forensics",
|
|
14
|
+
"threat-intelligence",
|
|
15
|
+
"crypto",
|
|
16
|
+
"aml"
|
|
17
|
+
],
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": "https://github.com/zerovector-hk/MerkleClaw",
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"typescript": "^6.0.2"
|
|
22
|
+
}
|
|
23
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ThreatLedger JavaScript SDK
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export interface ThreatLedgerConfig {
|
|
6
|
+
apiKey: string;
|
|
7
|
+
baseUrl?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface AddressCheckResult {
|
|
11
|
+
address: string;
|
|
12
|
+
found: boolean;
|
|
13
|
+
risk_score: number;
|
|
14
|
+
risk_level: string;
|
|
15
|
+
entry?: { chain: string; tier: string; entity: string; reason: string };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface Incident {
|
|
19
|
+
id: string; title: string; date: string; chain: string;
|
|
20
|
+
severity: string; loss_usd: number; protocol: string; description: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class ThreatLedger {
|
|
24
|
+
private apiKey: string;
|
|
25
|
+
private baseUrl: string;
|
|
26
|
+
|
|
27
|
+
constructor(config: ThreatLedgerConfig) {
|
|
28
|
+
this.apiKey = config.apiKey;
|
|
29
|
+
this.baseUrl = config.baseUrl || 'https://api.threatledger.net/v1';
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
private async request<T>(path: string, options?: RequestInit): Promise<T> {
|
|
33
|
+
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
34
|
+
...options,
|
|
35
|
+
headers: { 'X-API-Key': this.apiKey, 'Content-Type': 'application/json', ...options?.headers },
|
|
36
|
+
});
|
|
37
|
+
if (!res.ok) throw new Error(`ThreatLedger API error: ${res.status}`);
|
|
38
|
+
const json = await res.json();
|
|
39
|
+
return json.data;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async checkAddress(address: string): Promise<AddressCheckResult> {
|
|
43
|
+
return this.request(`/addresses/check?address=${address}`);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async listIncidents(params?: { chain?: string; severity?: string; page?: number }): Promise<Incident[]> {
|
|
47
|
+
const qs = new URLSearchParams(params as Record<string, string>).toString();
|
|
48
|
+
return this.request(`/incidents${qs ? '?' + qs : ''}`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async listActors(): Promise<unknown[]> {
|
|
52
|
+
return this.request('/actors');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
async listPatterns(): Promise<unknown[]> {
|
|
56
|
+
return this.request('/patterns');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async getCredits(): Promise<{ tier: string; remaining: number; total_credits: number }> {
|
|
60
|
+
return this.request('/credits/balance');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default ThreatLedger;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"lib": ["ES2020", "DOM"],
|
|
6
|
+
"declaration": true,
|
|
7
|
+
"outDir": "./dist",
|
|
8
|
+
"rootDir": "./src",
|
|
9
|
+
"strict": true,
|
|
10
|
+
"esModuleInterop": true,
|
|
11
|
+
"skipLibCheck": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/**/*"]
|
|
14
|
+
}
|