oculon 0.1.5 → 0.1.7
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 +72 -4
- package/dist/cli/main.js +184 -0
- package/dist/core/calls.d.ts +63 -0
- package/dist/core/calls.js +120 -0
- package/dist/core/evm.d.ts +20 -0
- package/dist/core/evm.js +165 -0
- package/dist/core/http.d.ts +11 -0
- package/dist/core/http.js +113 -30
- package/dist/core/pdf.d.ts +51 -0
- package/dist/core/pdf.js +211 -0
- package/dist/core/quota.js +3 -0
- package/dist/core/verdict.d.ts +30 -0
- package/dist/core/verdict.js +164 -0
- package/dist/index.d.ts +38 -0
- package/dist/index.js +54 -0
- package/dist/mcp.d.ts +1 -0
- package/dist/mcp.js +159 -5
- package/dist/modules/address.d.ts +32 -0
- package/dist/modules/address.js +91 -0
- package/dist/modules/checks.d.ts +59 -0
- package/dist/modules/checks.js +134 -0
- package/dist/modules/doc.d.ts +61 -0
- package/dist/modules/doc.js +715 -0
- package/dist/modules/headers.d.ts +50 -0
- package/dist/modules/headers.js +108 -0
- package/dist/modules/honeypot.d.ts +36 -0
- package/dist/modules/honeypot.js +53 -0
- package/dist/modules/iban.d.ts +30 -0
- package/dist/modules/iban.js +82 -0
- package/dist/modules/lookalike.d.ts +34 -0
- package/dist/modules/lookalike.js +122 -0
- package/dist/modules/personal.d.ts +1 -1
- package/dist/modules/personal.js +14 -4
- package/dist/modules/utility.d.ts +147 -0
- package/dist/modules/utility.js +403 -0
- package/dist/report-pdf.d.ts +7 -0
- package/dist/report-pdf.js +81 -0
- package/dist/telegram.d.ts +2 -0
- package/dist/telegram.js +43 -6
- package/dist/web/assets/logo-200.png +0 -0
- package/dist/web/burns.d.ts +21 -0
- package/dist/web/burns.js +53 -0
- package/dist/web/card.d.ts +28 -0
- package/dist/web/card.js +75 -0
- package/dist/web/index.html +76 -4
- package/dist/web/landing.html +1 -1
- package/dist/web/legal.html +1 -1
- package/dist/web/mcp.html +1 -1
- package/dist/web/openapi.js +6 -0
- package/dist/web/pages.d.ts +24 -0
- package/dist/web/pages.js +139 -0
- package/dist/web/public.js +7 -1
- package/dist/web/server.d.ts +17 -0
- package/dist/web/server.js +207 -7
- package/dist/web/token.html +98 -0
- package/dist/web/token.json +9 -0
- package/dist/web/utility.html +251 -0
- package/package.json +1 -1
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { screen } from './sanctions.js';
|
|
2
|
+
const B58 = /^[1-9A-HJ-NP-Za-km-z]+$/;
|
|
3
|
+
export function detectChain(a) {
|
|
4
|
+
if (/^0x[0-9a-fA-F]{40}$/.test(a))
|
|
5
|
+
return { chain: 'evm', format: 'EVM (Ethereum, Base, Robinhood Chain and other EVM chains)' };
|
|
6
|
+
if (/^(bc1|tb1)[02-9ac-hj-np-z]{11,71}$/.test(a.toLowerCase()))
|
|
7
|
+
return { chain: 'bitcoin', format: a.toLowerCase().startsWith('bc1p') ? 'Bitcoin Taproot (bech32m)' : 'Bitcoin SegWit (bech32)' };
|
|
8
|
+
if (/^[13][1-9A-HJ-NP-Za-km-z]{25,34}$/.test(a))
|
|
9
|
+
return { chain: 'bitcoin', format: a.startsWith('1') ? 'Bitcoin legacy (P2PKH)' : 'Bitcoin script (P2SH)' };
|
|
10
|
+
if (/^T[1-9A-HJ-NP-Za-km-z]{33}$/.test(a))
|
|
11
|
+
return { chain: 'tron', format: 'Tron (TRC-20 USDT lives here)' };
|
|
12
|
+
if (B58.test(a) && a.length >= 32 && a.length <= 44)
|
|
13
|
+
return { chain: 'solana', format: 'Solana' };
|
|
14
|
+
return { chain: 'unknown', format: 'not a recognized address format' };
|
|
15
|
+
}
|
|
16
|
+
export async function addressCheck(ctx, input, opts = {}) {
|
|
17
|
+
const address = input.trim();
|
|
18
|
+
if (!address)
|
|
19
|
+
throw new Error('give a crypto address');
|
|
20
|
+
const { chain, format } = detectChain(address);
|
|
21
|
+
if (chain === 'unknown')
|
|
22
|
+
throw new Error(`not a crypto address: ${address.slice(0, 60)}`);
|
|
23
|
+
const provenance = [];
|
|
24
|
+
const warnings = [];
|
|
25
|
+
let activity = null;
|
|
26
|
+
let network = null;
|
|
27
|
+
if (chain === 'bitcoin') {
|
|
28
|
+
network = 'Bitcoin';
|
|
29
|
+
const r = await ctx.http.get(`https://mempool.space/api/address/${address}`, { source: 'mempool-space', ttlSec: 600 });
|
|
30
|
+
provenance.push(r.prov);
|
|
31
|
+
const s = r.data?.chain_stats;
|
|
32
|
+
if (s)
|
|
33
|
+
activity = { txCount: s.tx_count ?? 0, balance: `${(((s.funded_txo_sum ?? 0) - (s.spent_txo_sum ?? 0)) / 1e8).toFixed(8)} BTC`, firstSeen: null, isContract: false, label: null };
|
|
34
|
+
}
|
|
35
|
+
else if (chain === 'evm') {
|
|
36
|
+
const rh = /^(rh|robinhood)$/i.test(opts.network ?? '');
|
|
37
|
+
network = rh ? 'Robinhood Chain' : 'Ethereum';
|
|
38
|
+
const base = rh ? 'https://api.blockscout.com/4663/api/v2' : 'https://eth.blockscout.com/api/v2';
|
|
39
|
+
const r = await ctx.http.get(`${base}/addresses/${address}`, { source: 'blockscout', ttlSec: 900 });
|
|
40
|
+
provenance.push(r.prov);
|
|
41
|
+
const c = await ctx.http.get(`${base}/addresses/${address}/counters`, { source: 'blockscout', ttlSec: 900 });
|
|
42
|
+
provenance.push(c.prov);
|
|
43
|
+
if (r.data || r.prov.note === 'HTTP 404') {
|
|
44
|
+
const d = r.data ?? {};
|
|
45
|
+
activity = { txCount: c.data?.transactions_count ? Number(c.data.transactions_count) : 0, balance: d.coin_balance ? `${(Number(BigInt(d.coin_balance) / 10n ** 12n) / 1e6).toFixed(6)} ETH` : '0 ETH', firstSeen: null,
|
|
46
|
+
// A wallet with an EIP-7702 delegation also has code, but no creator: only deployed contracts have one.
|
|
47
|
+
isContract: d.is_contract === undefined ? null : Boolean(d.is_contract && d.creator_address_hash),
|
|
48
|
+
label: d.ens_domain_name ?? d.public_tags?.[0]?.display_name ?? d.name ?? null };
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else if (chain === 'solana') {
|
|
52
|
+
network = 'Solana';
|
|
53
|
+
const r = await ctx.http.postBytes('https://api.mainnet-beta.solana.com', new TextEncoder().encode(JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'getBalance', params: [address] })), { source: 'solana-rpc', headers: { 'content-type': 'application/json' }, timeoutMs: 20_000 });
|
|
54
|
+
provenance.push(r.prov);
|
|
55
|
+
let lamports = null;
|
|
56
|
+
try {
|
|
57
|
+
lamports = r.data ? Number(JSON.parse(r.data.toString('utf8')).result?.value ?? NaN) : null;
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
lamports = null;
|
|
61
|
+
}
|
|
62
|
+
if (lamports !== null && Number.isFinite(lamports))
|
|
63
|
+
activity = { txCount: null, balance: `${(lamports / 1e9).toFixed(6)} SOL`, firstSeen: null, isContract: null, label: null };
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
network = 'Tron';
|
|
67
|
+
}
|
|
68
|
+
if (activity && activity.txCount === 0)
|
|
69
|
+
warnings.push('this address has never been used: double-check it with the person you are paying through another channel');
|
|
70
|
+
if (activity?.isContract)
|
|
71
|
+
warnings.push('this is a smart contract, not a personal wallet: sending to it directly can lose the funds');
|
|
72
|
+
// Sanctions: the US OFAC SDN list includes crypto addresses (Bitcoin, EVM, Tron and more).
|
|
73
|
+
let sanctioned = null;
|
|
74
|
+
const hits = [];
|
|
75
|
+
try {
|
|
76
|
+
const s = await screen(ctx, address);
|
|
77
|
+
provenance.push(...s.provenance.slice(0, 2));
|
|
78
|
+
sanctioned = s.result.verdict === 'SANCTIONED';
|
|
79
|
+
for (const h of s.result.hits.slice(0, 3))
|
|
80
|
+
hits.push(JSON.stringify(h).slice(0, 160));
|
|
81
|
+
if (sanctioned)
|
|
82
|
+
warnings.unshift('this address is on the US OFAC sanctions list: sending to it can be illegal');
|
|
83
|
+
else if (s.result.verdict === 'EXPOSED')
|
|
84
|
+
warnings.push('this address has traded directly with a sanctioned address');
|
|
85
|
+
}
|
|
86
|
+
catch { /* the list is optional here */ }
|
|
87
|
+
const advice = warnings.length
|
|
88
|
+
? ['Do not send funds until you have confirmed the address with the recipient through a channel you already trust.']
|
|
89
|
+
: ['Nothing alarming found. Still send a small test amount first, and never send to an address someone pushes on you in a chat.'];
|
|
90
|
+
return { module: 'address', input: address, generatedAt: ctx.now().toISOString(), result: { address, chain, format, network, activity, sanctioned, sanctionHits: hits, warnings, advice }, signals: [], provenance };
|
|
91
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type { Ctx } from '../core/context.js';
|
|
2
|
+
import { type CallEntry } from '../core/calls.js';
|
|
3
|
+
import { type Verdict } from '../core/verdict.js';
|
|
4
|
+
export interface SeenBefore {
|
|
5
|
+
id: string;
|
|
6
|
+
at: string;
|
|
7
|
+
verdict: string | null;
|
|
8
|
+
/** Plain-word changes since that check; empty when nothing changed. */
|
|
9
|
+
changes: string[];
|
|
10
|
+
}
|
|
11
|
+
export interface CheckMeta {
|
|
12
|
+
id: string;
|
|
13
|
+
kind: string;
|
|
14
|
+
seenBefore: SeenBefore | null;
|
|
15
|
+
replay: string;
|
|
16
|
+
report: string;
|
|
17
|
+
}
|
|
18
|
+
export interface CheckRecord {
|
|
19
|
+
id: string;
|
|
20
|
+
kind: string;
|
|
21
|
+
label: string;
|
|
22
|
+
createdAt: string;
|
|
23
|
+
durationMs: number;
|
|
24
|
+
verdict: Verdict;
|
|
25
|
+
calls: CallEntry[];
|
|
26
|
+
seenBefore: SeenBefore | null;
|
|
27
|
+
/** The full result as returned, or null when it was too large to keep. */
|
|
28
|
+
result: unknown;
|
|
29
|
+
}
|
|
30
|
+
export declare const targetKey: (kind: string, target: string) => string;
|
|
31
|
+
/** Long inputs (a pasted message, raw headers) are shown by their start only. */
|
|
32
|
+
export declare function labelFor(target: string): string;
|
|
33
|
+
/**
|
|
34
|
+
* Run a check, keep its verdict and source calls, and compare it with the last check of the same target.
|
|
35
|
+
* `target` identifies what was checked (it is hashed for matching); `label` is what pages show.
|
|
36
|
+
*/
|
|
37
|
+
export declare function recordCheck<T>(ctx: Ctx, kind: string, target: string, run: () => Promise<T>, opts?: {
|
|
38
|
+
label?: string;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
value: T;
|
|
41
|
+
check: CheckMeta;
|
|
42
|
+
}>;
|
|
43
|
+
export declare function getCheck(ctx: Ctx, id: string): CheckRecord | null;
|
|
44
|
+
/** Earlier checks of the same target, newest first (for "history" on the replay page). */
|
|
45
|
+
export declare function checkHistory(ctx: Ctx, id: string, limit?: number): {
|
|
46
|
+
id: string;
|
|
47
|
+
at: string;
|
|
48
|
+
verdict: string | null;
|
|
49
|
+
risk: number | null;
|
|
50
|
+
}[];
|
|
51
|
+
/** Checks Oculon records, by web route and by MCP tool, with how to read the target from the input. */
|
|
52
|
+
export declare const CHECK_ROUTES: Record<string, {
|
|
53
|
+
kind: string;
|
|
54
|
+
param: string;
|
|
55
|
+
}>;
|
|
56
|
+
export declare const CHECK_TOOLS: Record<string, {
|
|
57
|
+
kind: string;
|
|
58
|
+
arg: string;
|
|
59
|
+
}>;
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check history: every check (scam, link, IBAN, document, token...) is stored with its verdict and the source calls
|
|
3
|
+
* it made. That gives three features:
|
|
4
|
+
* - seen before: checking the same thing again says what changed since last time;
|
|
5
|
+
* - replay log: /replay/<id> shows every source called, when, how long it took and what it answered;
|
|
6
|
+
* - PDF report: /report/<id>.pdf is one investigation as a file to send on.
|
|
7
|
+
* Ids are random (96 bits) so a replay link is only known to whoever ran the check. Kept for 90 days.
|
|
8
|
+
*/
|
|
9
|
+
import { createHash, randomBytes } from 'node:crypto';
|
|
10
|
+
import { withCallLog } from '../core/calls.js';
|
|
11
|
+
import { verdictChanges, verdictOf } from '../core/verdict.js';
|
|
12
|
+
const KEEP_DAYS = 90;
|
|
13
|
+
const MAX_RESULT = 300_000;
|
|
14
|
+
const ensured = new WeakSet();
|
|
15
|
+
function db(ctx) {
|
|
16
|
+
const d = ctx.store.db;
|
|
17
|
+
if (!ensured.has(d)) {
|
|
18
|
+
d.exec(`CREATE TABLE IF NOT EXISTS checks (id TEXT PRIMARY KEY, kind TEXT NOT NULL, target_key TEXT NOT NULL, label TEXT NOT NULL, created_at INTEGER NOT NULL, duration_ms INTEGER NOT NULL, verdict TEXT NOT NULL, calls TEXT NOT NULL, seen_before TEXT, result TEXT);
|
|
19
|
+
CREATE INDEX IF NOT EXISTS checks_target ON checks (target_key, created_at);`);
|
|
20
|
+
ensured.add(d);
|
|
21
|
+
}
|
|
22
|
+
return d;
|
|
23
|
+
}
|
|
24
|
+
export const targetKey = (kind, target) => createHash('sha256').update(`${kind}\n${target.trim().toLowerCase().replace(/\s+/g, ' ')}`).digest('hex').slice(0, 32);
|
|
25
|
+
/** Long inputs (a pasted message, raw headers) are shown by their start only. */
|
|
26
|
+
export function labelFor(target) {
|
|
27
|
+
const t = target.replace(/\s+/g, ' ').trim();
|
|
28
|
+
return t.length > 90 ? `${t.slice(0, 87)}...` : t;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Run a check, keep its verdict and source calls, and compare it with the last check of the same target.
|
|
32
|
+
* `target` identifies what was checked (it is hashed for matching); `label` is what pages show.
|
|
33
|
+
*/
|
|
34
|
+
export async function recordCheck(ctx, kind, target, run, opts = {}) {
|
|
35
|
+
const t0 = Date.now();
|
|
36
|
+
const { value, calls } = await withCallLog(run);
|
|
37
|
+
const durationMs = Date.now() - t0;
|
|
38
|
+
const d = db(ctx);
|
|
39
|
+
const key = targetKey(kind, target);
|
|
40
|
+
const label = opts.label ?? labelFor(target);
|
|
41
|
+
const verdict = verdictOf(value, label);
|
|
42
|
+
const nowMs = ctx.now().getTime();
|
|
43
|
+
const prev = d.prepare('SELECT id, created_at, verdict FROM checks WHERE target_key = ? ORDER BY created_at DESC LIMIT 1').get(key);
|
|
44
|
+
let seenBefore = null;
|
|
45
|
+
if (prev) {
|
|
46
|
+
const was = JSON.parse(prev.verdict);
|
|
47
|
+
seenBefore = { id: prev.id, at: new Date(prev.created_at).toISOString(), verdict: was.verdict, changes: verdictChanges(was, verdict) };
|
|
48
|
+
}
|
|
49
|
+
const id = randomBytes(12).toString('base64url');
|
|
50
|
+
let result = JSON.stringify(value);
|
|
51
|
+
if (result.length > MAX_RESULT)
|
|
52
|
+
result = null;
|
|
53
|
+
d.prepare('INSERT INTO checks (id, kind, target_key, label, created_at, duration_ms, verdict, calls, seen_before, result) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)').run(id, kind, key, label, nowMs, durationMs, JSON.stringify(verdict), JSON.stringify(calls), seenBefore ? JSON.stringify(seenBefore) : null, result);
|
|
54
|
+
if (Math.random() < 0.02)
|
|
55
|
+
d.prepare('DELETE FROM checks WHERE created_at < ?').run(nowMs - KEEP_DAYS * 86_400_000);
|
|
56
|
+
return { value, check: { id, kind, seenBefore, replay: `/replay/${id}`, report: `/report/${id}.pdf` } };
|
|
57
|
+
}
|
|
58
|
+
export function getCheck(ctx, id) {
|
|
59
|
+
if (!/^[A-Za-z0-9_-]{10,40}$/.test(id))
|
|
60
|
+
return null;
|
|
61
|
+
const r = db(ctx).prepare('SELECT * FROM checks WHERE id = ?').get(id);
|
|
62
|
+
if (!r)
|
|
63
|
+
return null;
|
|
64
|
+
return {
|
|
65
|
+
id: String(r.id),
|
|
66
|
+
kind: String(r.kind),
|
|
67
|
+
label: String(r.label),
|
|
68
|
+
createdAt: new Date(Number(r.created_at)).toISOString(),
|
|
69
|
+
durationMs: Number(r.duration_ms),
|
|
70
|
+
verdict: JSON.parse(String(r.verdict)),
|
|
71
|
+
calls: JSON.parse(String(r.calls)),
|
|
72
|
+
seenBefore: r.seen_before ? JSON.parse(String(r.seen_before)) : null,
|
|
73
|
+
result: r.result ? JSON.parse(String(r.result)) : null,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/** Earlier checks of the same target, newest first (for "history" on the replay page). */
|
|
77
|
+
export function checkHistory(ctx, id, limit = 10) {
|
|
78
|
+
const d = db(ctx);
|
|
79
|
+
const row = d.prepare('SELECT target_key FROM checks WHERE id = ?').get(id);
|
|
80
|
+
if (!row)
|
|
81
|
+
return [];
|
|
82
|
+
const rows = d.prepare('SELECT id, created_at, verdict FROM checks WHERE target_key = ? ORDER BY created_at DESC LIMIT ?').all(row.target_key, limit);
|
|
83
|
+
return rows.map((r) => {
|
|
84
|
+
const v = JSON.parse(r.verdict);
|
|
85
|
+
return { id: r.id, at: new Date(r.created_at).toISOString(), verdict: v.verdict, risk: v.risk };
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
/** Checks Oculon records, by web route and by MCP tool, with how to read the target from the input. */
|
|
89
|
+
export const CHECK_ROUTES = {
|
|
90
|
+
'/api/scam': { kind: 'scam', param: 'message' },
|
|
91
|
+
'/api/url': { kind: 'url', param: 'url' },
|
|
92
|
+
'/api/iban': { kind: 'iban', param: 'iban' },
|
|
93
|
+
'/api/lookalike': { kind: 'lookalike', param: 'domain' },
|
|
94
|
+
'/api/honeypot': { kind: 'honeypot', param: 'address' },
|
|
95
|
+
'/api/address': { kind: 'address', param: 'address' },
|
|
96
|
+
'/api/phone': { kind: 'phone', param: 'number' },
|
|
97
|
+
'/api/ip': { kind: 'ip', param: 'ip' },
|
|
98
|
+
'/api/hash': { kind: 'hash', param: 'hash' },
|
|
99
|
+
'/api/emailsec': { kind: 'emailsec', param: 'domain' },
|
|
100
|
+
'/api/company': { kind: 'company', param: 'q' },
|
|
101
|
+
'/api/token': { kind: 'token', param: 'address' },
|
|
102
|
+
'/api/rhtoken': { kind: 'rhtoken', param: 'address' },
|
|
103
|
+
'/api/wallet': { kind: 'wallet', param: 'address' },
|
|
104
|
+
'/api/sanctions': { kind: 'sanctions', param: 'q' },
|
|
105
|
+
'/api/factcheck': { kind: 'factcheck', param: 'claim' },
|
|
106
|
+
'/api/recall': { kind: 'recall', param: 'q' },
|
|
107
|
+
'/api/travel': { kind: 'travel', param: 'place' },
|
|
108
|
+
'/api/cve': { kind: 'cve', param: 'id' },
|
|
109
|
+
'/api/exposure': { kind: 'exposure', param: 'domain' },
|
|
110
|
+
};
|
|
111
|
+
export const CHECK_TOOLS = {
|
|
112
|
+
oculon_scam_check: { kind: 'scam', arg: 'message' },
|
|
113
|
+
oculon_url_check: { kind: 'url', arg: 'url' },
|
|
114
|
+
oculon_iban_check: { kind: 'iban', arg: 'iban' },
|
|
115
|
+
oculon_email_headers: { kind: 'headers', arg: 'headers' },
|
|
116
|
+
oculon_lookalike_domains: { kind: 'lookalike', arg: 'domain' },
|
|
117
|
+
oculon_honeypot_check: { kind: 'honeypot', arg: 'address' },
|
|
118
|
+
oculon_address_check: { kind: 'address', arg: 'address' },
|
|
119
|
+
oculon_phone_check: { kind: 'phone', arg: 'number' },
|
|
120
|
+
oculon_ip_check: { kind: 'ip', arg: 'ip' },
|
|
121
|
+
oculon_hash_check: { kind: 'hash', arg: 'hash' },
|
|
122
|
+
oculon_email_security: { kind: 'emailsec', arg: 'domain' },
|
|
123
|
+
oculon_company_lookup: { kind: 'company', arg: 'query' },
|
|
124
|
+
oculon_token: { kind: 'token', arg: 'address' },
|
|
125
|
+
oculon_robinhood_token: { kind: 'rhtoken', arg: 'address' },
|
|
126
|
+
oculon_wallet: { kind: 'wallet', arg: 'address' },
|
|
127
|
+
oculon_sanctions: { kind: 'sanctions', arg: 'query' },
|
|
128
|
+
oculon_fact_check: { kind: 'factcheck', arg: 'claim' },
|
|
129
|
+
oculon_recall: { kind: 'recall', arg: 'query' },
|
|
130
|
+
oculon_travel: { kind: 'travel', arg: 'place' },
|
|
131
|
+
oculon_cve: { kind: 'cve', arg: 'id' },
|
|
132
|
+
oculon_exposure: { kind: 'exposure', arg: 'domain' },
|
|
133
|
+
oculon_doc_check: { kind: 'doc', arg: 'name' },
|
|
134
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Ctx } from '../core/context.js';
|
|
2
|
+
import type { ModuleResult } from '../core/types.js';
|
|
3
|
+
export interface DocIban {
|
|
4
|
+
iban: string;
|
|
5
|
+
valid: boolean;
|
|
6
|
+
country: string | null;
|
|
7
|
+
problems: string[];
|
|
8
|
+
}
|
|
9
|
+
export interface DocResult {
|
|
10
|
+
name: string;
|
|
11
|
+
type: 'pdf' | 'jpeg' | 'png';
|
|
12
|
+
bytes: number;
|
|
13
|
+
sha256: string;
|
|
14
|
+
verdict: 'dangerous file' | 'likely edited' | 'signs of editing' | 'no signs of editing found';
|
|
15
|
+
risk: number;
|
|
16
|
+
flags: string[];
|
|
17
|
+
notes: string[];
|
|
18
|
+
metadata: Record<string, string>;
|
|
19
|
+
/** PDF: times the file was saved (1 = never changed after it was made). */
|
|
20
|
+
revisions: number | null;
|
|
21
|
+
signed: boolean;
|
|
22
|
+
fonts: string[];
|
|
23
|
+
text: {
|
|
24
|
+
chars: number;
|
|
25
|
+
excerpt: string;
|
|
26
|
+
from: 'text layer' | 'ocr' | 'none';
|
|
27
|
+
};
|
|
28
|
+
ibans: DocIban[];
|
|
29
|
+
domains: string[];
|
|
30
|
+
advice: string[];
|
|
31
|
+
}
|
|
32
|
+
export declare const DOC_MAX_BYTES: number;
|
|
33
|
+
interface PdfObj {
|
|
34
|
+
num: number;
|
|
35
|
+
dict: string;
|
|
36
|
+
stream: Buffer | null;
|
|
37
|
+
/** Raw stream bytes as stored (for images). */
|
|
38
|
+
raw: Buffer | null;
|
|
39
|
+
}
|
|
40
|
+
/** Objects of a PDF, including those packed in object streams. Streams are decoded when they use FlateDecode. */
|
|
41
|
+
export declare function pdfObjects(buf: Buffer): PdfObj[];
|
|
42
|
+
/** A PDF string value: (literal) with escapes, or <hex>, UTF-16 when it starts with a byte order mark. */
|
|
43
|
+
export declare function pdfString(src: string): string;
|
|
44
|
+
/** D:YYYYMMDDHHmmSS+hh'mm' to epoch milliseconds. */
|
|
45
|
+
export declare function pdfDate(s: string | null): number | null;
|
|
46
|
+
interface PdfFont {
|
|
47
|
+
name: string;
|
|
48
|
+
cmap: {
|
|
49
|
+
map: Map<string, string>;
|
|
50
|
+
bytes: number;
|
|
51
|
+
} | null;
|
|
52
|
+
twoByte: boolean;
|
|
53
|
+
}
|
|
54
|
+
/** Text shown by a content stream, plus white filled boxes that are not page backgrounds. */
|
|
55
|
+
export declare function contentText(c: string, fonts: Map<string, PdfFont>): {
|
|
56
|
+
text: string;
|
|
57
|
+
whiteBoxes: number;
|
|
58
|
+
};
|
|
59
|
+
/** Check one document. `name` is only used for display. */
|
|
60
|
+
export declare function docCheck(ctx: Ctx, file: Buffer, name?: string): Promise<ModuleResult<DocResult>>;
|
|
61
|
+
export {};
|