oculon 0.1.6 → 0.2.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.
Files changed (106) hide show
  1. package/README.md +93 -17
  2. package/dist/cli/main.js +397 -0
  3. package/dist/core/calls.d.ts +63 -0
  4. package/dist/core/calls.js +120 -0
  5. package/dist/core/der.d.ts +2 -0
  6. package/dist/core/der.js +17 -0
  7. package/dist/core/http.d.ts +30 -1
  8. package/dist/core/http.js +133 -29
  9. package/dist/core/pdf.d.ts +51 -0
  10. package/dist/core/pdf.js +211 -0
  11. package/dist/core/qr.d.ts +23 -0
  12. package/dist/core/qr.js +577 -0
  13. package/dist/core/quota.js +5 -0
  14. package/dist/core/raster.d.ts +6 -0
  15. package/dist/core/raster.js +298 -0
  16. package/dist/core/safeurl.d.ts +5 -0
  17. package/dist/core/safeurl.js +26 -0
  18. package/dist/core/verdict.d.ts +30 -0
  19. package/dist/core/verdict.js +164 -0
  20. package/dist/core/zip.d.ts +9 -0
  21. package/dist/core/zip.js +46 -0
  22. package/dist/index.d.ts +83 -0
  23. package/dist/index.js +128 -0
  24. package/dist/mcp.d.ts +1 -0
  25. package/dist/mcp.js +256 -6
  26. package/dist/modules/address.d.ts +6 -2
  27. package/dist/modules/address.js +32 -5
  28. package/dist/modules/apk.d.ts +37 -0
  29. package/dist/modules/apk.js +191 -0
  30. package/dist/modules/approvals.d.ts +40 -0
  31. package/dist/modules/approvals.js +155 -0
  32. package/dist/modules/archive.d.ts +21 -0
  33. package/dist/modules/archive.js +94 -0
  34. package/dist/modules/checks.d.ts +59 -0
  35. package/dist/modules/checks.js +167 -0
  36. package/dist/modules/contract.d.ts +56 -0
  37. package/dist/modules/contract.js +167 -0
  38. package/dist/modules/deployer.d.ts +42 -0
  39. package/dist/modules/deployer.js +90 -0
  40. package/dist/modules/doc.d.ts +83 -0
  41. package/dist/modules/doc.js +841 -0
  42. package/dist/modules/eml.d.ts +46 -0
  43. package/dist/modules/eml.js +175 -0
  44. package/dist/modules/hashcheck.d.ts +19 -3
  45. package/dist/modules/hashcheck.js +28 -4
  46. package/dist/modules/image.d.ts +32 -0
  47. package/dist/modules/image.js +276 -0
  48. package/dist/modules/invite.d.ts +27 -0
  49. package/dist/modules/invite.js +69 -0
  50. package/dist/modules/job.d.ts +33 -0
  51. package/dist/modules/job.js +64 -0
  52. package/dist/modules/meerkat.d.ts +1 -1
  53. package/dist/modules/meerkat.js +35 -2
  54. package/dist/modules/monitor.js +14 -0
  55. package/dist/modules/poisoning.d.ts +43 -0
  56. package/dist/modules/poisoning.js +114 -0
  57. package/dist/modules/qrcheck.d.ts +24 -0
  58. package/dist/modules/qrcheck.js +136 -0
  59. package/dist/modules/repo.d.ts +61 -0
  60. package/dist/modules/repo.js +162 -0
  61. package/dist/modules/report.d.ts +32 -0
  62. package/dist/modules/report.js +108 -0
  63. package/dist/modules/signature.d.ts +35 -0
  64. package/dist/modules/signature.js +283 -0
  65. package/dist/modules/site.d.ts +62 -0
  66. package/dist/modules/site.js +191 -0
  67. package/dist/modules/stocktoken.d.ts +48 -0
  68. package/dist/modules/stocktoken.js +99 -0
  69. package/dist/modules/trace.d.ts +37 -0
  70. package/dist/modules/trace.js +150 -0
  71. package/dist/modules/txexplain.d.ts +40 -0
  72. package/dist/modules/txexplain.js +135 -0
  73. package/dist/modules/urlcheck.js +15 -1
  74. package/dist/modules/utility.d.ts +27 -1
  75. package/dist/modules/utility.js +108 -11
  76. package/dist/modules/where.d.ts +63 -0
  77. package/dist/modules/where.js +165 -0
  78. package/dist/report-pdf.d.ts +7 -0
  79. package/dist/report-pdf.js +84 -0
  80. package/dist/sources/cfurlscan.d.ts +24 -0
  81. package/dist/sources/cfurlscan.js +46 -0
  82. package/dist/sources/chainabuse.d.ts +17 -0
  83. package/dist/sources/chainabuse.js +19 -0
  84. package/dist/sources/evm.d.ts +135 -0
  85. package/dist/sources/evm.js +260 -0
  86. package/dist/sources/phishlists.d.ts +20 -0
  87. package/dist/sources/phishlists.js +90 -0
  88. package/dist/telegram.d.ts +17 -0
  89. package/dist/telegram.js +151 -4
  90. package/dist/web/card.d.ts +28 -0
  91. package/dist/web/card.js +75 -0
  92. package/dist/web/docs.html +1 -1
  93. package/dist/web/index.html +213 -5
  94. package/dist/web/landing.html +1 -1
  95. package/dist/web/legal.html +3 -1
  96. package/dist/web/mcp.html +1 -1
  97. package/dist/web/openapi.js +15 -0
  98. package/dist/web/pages.d.ts +24 -0
  99. package/dist/web/pages.js +139 -0
  100. package/dist/web/public.js +16 -1
  101. package/dist/web/server.d.ts +13 -0
  102. package/dist/web/server.js +152 -13
  103. package/dist/web/token.html +25 -4
  104. package/dist/web/token.json +12 -1
  105. package/dist/web/utility.html +40 -14
  106. package/package.json +2 -2
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Repo check: is this GitHub repository safe to clone and run?
3
+ * Built for the "take-home test" and "run our bot" scams, where a fake recruiter or project sends a repo that
4
+ * steals wallets and browser passwords the moment it is installed or opened.
5
+ * - Install hooks: package.json preinstall / postinstall / prepare scripts, setup.py commands, and VS Code
6
+ * tasks that run when the folder is opened (runOn: folderOpen).
7
+ * - Code that fetches and runs code: eval or new Function on downloaded text, base64 or hex blobs fed to eval,
8
+ * child_process running curl / PowerShell, Python exec of decoded strings.
9
+ * - Theft targets: wallet extension ids and folders, browser login and cookie databases, keychains,
10
+ * Discord and Telegram webhooks used to send stolen data.
11
+ * - Obfuscation: obfuscator.io names, very long lines hidden past the edge of the editor.
12
+ * - The account and stars: owner account age, repo age vs stars, and whether recent stargazers are
13
+ * brand-new empty accounts (bought stars).
14
+ * Reads the repo through the GitHub API and raw files; nothing is cloned or run.
15
+ */
16
+ import type { Ctx } from '../core/context.js';
17
+ import type { ModuleResult } from '../core/types.js';
18
+ export interface RepoFinding {
19
+ file: string;
20
+ line: number | null;
21
+ what: string;
22
+ severity: 'high' | 'medium' | 'low';
23
+ excerpt: string | null;
24
+ }
25
+ export interface RepoReport {
26
+ repo: string;
27
+ url: string;
28
+ verdict: 'malicious code found' | 'suspicious' | 'no known risk found';
29
+ risk: number;
30
+ findings: RepoFinding[];
31
+ account: {
32
+ login: string;
33
+ type: string;
34
+ createdAt: string | null;
35
+ ageDays: number | null;
36
+ repos: number | null;
37
+ followers: number | null;
38
+ } | null;
39
+ stats: {
40
+ stars: number;
41
+ forks: number;
42
+ createdAt: string;
43
+ pushedAt: string;
44
+ ageDays: number;
45
+ files: number;
46
+ scanned: number;
47
+ fork: boolean;
48
+ archived: boolean;
49
+ license: string | null;
50
+ };
51
+ stars: {
52
+ sampled: number;
53
+ newAccounts: number;
54
+ emptyAccounts: number;
55
+ } | null;
56
+ reasons: string[];
57
+ advice: string[];
58
+ }
59
+ export declare function parseRepo(input: string): string;
60
+ export declare function scanText(file: string, text: string): RepoFinding[];
61
+ export declare function repoCheck(ctx: Ctx, input: string): Promise<ModuleResult<RepoReport>>;
@@ -0,0 +1,162 @@
1
+ import { key } from '../core/keys.js';
2
+ import { signalId } from '../core/text.js';
3
+ import { postJson } from '../sources/press.js';
4
+ const DAY = 86_400_000;
5
+ const CODE = /\.(m?js|cjs|ts|tsx|jsx|py|sh|ps1|bat|cmd|vbs)$/i;
6
+ const BINARY = /\.(exe|dll|scr|msi|jar|apk|bin|so|dylib|node|pyc)$/i;
7
+ const PRIORITY = /(^|\/)(package\.json|setup\.py|pyproject\.toml|\.vscode\/tasks\.json|\.vscode\/settings\.json|requirements\.txt|install\.(sh|ps1|py|js)|(tailwind|postcss|next|vite|webpack|babel|hardhat|truffle|jest|eslint)\.config\.(c|m)?js|server\.js|index\.js|app\.js|main\.js|main\.py|bot\.py|run\.py|start\.(sh|js)|config\.js)$/i;
8
+ const PATTERNS = [
9
+ [/\beval\s*\(\s*(atob|Buffer\.from|decodeURIComponent|unescape)\s*\(/, 'eval of decoded text: hides code from readers', 'high'],
10
+ [/new\s+Function\s*\(\s*(atob|Buffer\.from|[a-z_$][\w$]*\.data\b|response|res\b)/i, 'builds a function from downloaded or decoded text', 'high'],
11
+ [/\.then\s*\(\s*\(?\s*\w*\s*\)?\s*=>\s*(eval|new Function)\b|\beval\s*\(\s*\w+\.(data|text|body)\b/, 'runs code downloaded from the internet', 'high'],
12
+ [/child_process[\s\S]{0,200}\b(curl|wget|powershell|iwr|Invoke-WebRequest|bitsadmin|certutil|mshta)\b/i, 'starts a shell that downloads something', 'high'],
13
+ [/\b(exec|execSync|spawn)\s*\(\s*['"`][^'"`]*\b(curl|wget|powershell|iex|Invoke-Expression)\b/i, 'runs curl or PowerShell from the code', 'high'],
14
+ [/exec\s*\(\s*(base64\.b64decode|zlib\.decompress|marshal\.loads|codecs\.decode|bytes\.fromhex)/, 'Python exec of a decoded string', 'high'],
15
+ [/exec\s*\(\s*requests\.get\(|exec\s*\(\s*urllib/, 'Python exec of downloaded code', 'high'],
16
+ [/nkbihfbeogaeaoehlefnkodbefgpgknn|bfnaelmomeimhlpmgjnjophhpkkoljpa|ejbalbakoplchlghecdalmeeeajnimhm|hnfanknocfeofbddgcijnmhnfnkdnaad|ibnejdfjmmkpcnlpebklmnkoeoihofec|fhbohimaelbohpjbbldcngcnapndodjp/, 'reads crypto wallet extension data (MetaMask, Phantom, Coinbase, TronLink...)', 'high'],
17
+ [/Local Extension Settings|Login Data|Web Data['"]|\\Cookies['"]|Network[\\/]+Cookies|Local State['"]/, 'reads browser password, cookie or extension databases', 'high'],
18
+ [/Exodus[\\/]exodus\.wallet|Electrum[\\/]wallets|\.config[\\/]solana[\\/]id\.json|Atomic[\\/]Local Storage|keychain-db|login\.keychain/i, 'reads wallet files or the keychain', 'high'],
19
+ [/discord(app)?\.com\/api\/webhooks\/\d+|api\.telegram\.org\/bot\d+:[\w-]{20,}/, 'sends data to a Discord or Telegram webhook', 'medium'],
20
+ [/_0x[0-9a-f]{4,6}\b[\s\S]*_0x[0-9a-f]{4,6}\b[\s\S]*_0x[0-9a-f]{4,6}\b/, 'obfuscated with obfuscator.io (_0x names)', 'medium'],
21
+ [/['"`][A-Za-z0-9+/]{400,}={0,2}['"`]/, 'large base64 blob in the code', 'medium'],
22
+ [/(\\x[0-9a-f]{2}){40,}/i, 'long hex-escaped string', 'medium'],
23
+ [/\bprocess\.env\b[\s\S]{0,80}\b(axios|fetch|request)\s*\.?\s*(post|\()/, 'sends environment variables (keys, tokens) somewhere', 'medium'],
24
+ [/require\(\s*['"]os['"]\s*\)[\s\S]{0,400}(homedir|hostname)[\s\S]{0,400}(axios|fetch|https?\.request)/, 'collects machine details and sends them out', 'medium'],
25
+ ];
26
+ export function parseRepo(input) {
27
+ const s = input.trim().replace(/\.git$/, '').replace(/\/+$/, '');
28
+ const m = /^(?:https?:\/\/)?(?:www\.)?github\.com\/([\w.-]+)\/([\w.-]+)/i.exec(s) ?? /^([\w.-]+)\/([\w.-]+)$/.exec(s);
29
+ if (!m)
30
+ throw new Error('give a GitHub repository: owner/name or a github.com link');
31
+ return `${m[1]}/${m[2]}`;
32
+ }
33
+ export function scanText(file, text) {
34
+ const out = [];
35
+ const lines = text.split(/\r?\n/);
36
+ const minified = /\.min\.js$/.test(file) || (lines.length < 5 && text.length > 20_000);
37
+ for (const [re, what, severity] of PATTERNS) {
38
+ if (minified && severity !== 'high')
39
+ continue;
40
+ const m = re.exec(text);
41
+ if (!m)
42
+ continue;
43
+ const line = text.slice(0, m.index).split('\n').length;
44
+ out.push({ file, line, what, severity, excerpt: m[0].slice(0, 120) });
45
+ }
46
+ if (!minified) {
47
+ const i = lines.findIndex((l) => /^\s{200,}\S/.test(l) || /\S\s{300,}\S/.test(l));
48
+ if (i >= 0)
49
+ out.push({ file, line: i + 1, what: 'code hidden far to the right of the screen after a run of spaces', severity: 'high', excerpt: lines[i].trim().slice(0, 120) });
50
+ }
51
+ if (/(^|\/)package\.json$/.test(file)) {
52
+ try {
53
+ const p = JSON.parse(text);
54
+ for (const h of ['preinstall', 'install', 'postinstall', 'prepare', 'prestart', 'predev']) {
55
+ const cmd = p.scripts?.[h];
56
+ if (!cmd)
57
+ continue;
58
+ const bad = /curl|wget|powershell|node\s+-e|base64|http|\|\s*(sh|bash)/i.test(cmd);
59
+ if (bad || /install|prepare/.test(h))
60
+ out.push({ file, line: null, what: `"${h}" script runs on install: ${cmd.slice(0, 100)}`, severity: bad ? 'high' : /^(husky|husky install|tsc|npm run build|node-gyp rebuild|patch-package)/.test(cmd.trim()) ? 'low' : 'medium', excerpt: null });
61
+ }
62
+ for (const [n, v] of Object.entries({ ...p.dependencies, ...p.devDependencies })) {
63
+ if (/^(https?:|git\+|github:)/.test(v) && !/github\.com\/(npm|nodejs|microsoft|facebook|vercel)\//.test(v))
64
+ out.push({ file, line: null, what: `dependency ${n} comes from a URL, not the npm registry (${v.slice(0, 80)})`, severity: 'medium', excerpt: null });
65
+ }
66
+ }
67
+ catch { /* not JSON */ }
68
+ }
69
+ if (/\.vscode\/tasks\.json$/.test(file) && /"runOn"\s*:\s*"folderOpen"/.test(text))
70
+ out.push({ file, line: null, what: 'a VS Code task runs by itself when the folder is opened', severity: 'high', excerpt: (/"command"\s*:\s*"([^"]{0,100})/.exec(text)?.[1]) ?? null });
71
+ if (/setup\.py$/.test(file) && /cmdclass|os\.system|subprocess/.test(text))
72
+ out.push({ file, line: null, what: 'setup.py runs commands during install', severity: /curl|wget|http|base64|exec\(/.test(text) ? 'high' : 'medium', excerpt: null });
73
+ return out;
74
+ }
75
+ export async function repoCheck(ctx, input) {
76
+ const repo = parseRepo(input);
77
+ const tok = key('GITHUB_TOKEN');
78
+ const headers = { accept: 'application/vnd.github+json', ...(tok ? { authorization: `Bearer ${tok}` } : {}) };
79
+ const provenance = [];
80
+ const r = await ctx.http.get(`https://api.github.com/repos/${repo}`, { source: 'github', headers, ttlSec: 1800 });
81
+ provenance.push(r.prov);
82
+ if (!r.data)
83
+ throw new Error(r.prov.note === 'HTTP 404' ? `no public repository ${repo} on GitHub` : `GitHub is not answering (${r.prov.note ?? r.prov.status})`);
84
+ const g = r.data;
85
+ const nowMs = ctx.now().getTime();
86
+ const [u, tree] = await Promise.all([
87
+ ctx.http.get(`https://api.github.com/users/${g.owner.login}`, { source: 'github', headers, ttlSec: 86_400 }),
88
+ ctx.http.get(`https://api.github.com/repos/${repo}/git/trees/${encodeURIComponent(g.default_branch)}?recursive=1`, { source: 'github', headers, ttlSec: 1800 }),
89
+ ]);
90
+ provenance.push(tree.prov);
91
+ const files = (tree.data?.tree ?? []).filter((f) => f.type === 'blob');
92
+ const findings = [];
93
+ for (const f of files.filter((x) => BINARY.test(x.path)).slice(0, 5))
94
+ findings.push({ file: f.path, line: null, what: `program file committed to the repo (${f.path.split('.').pop()})`, severity: /\.(exe|scr|dll|msi)$/i.test(f.path) ? 'high' : 'medium', excerpt: null });
95
+ if (files.some((f) => f.path.startsWith('node_modules/')))
96
+ findings.push({ file: 'node_modules/', line: null, what: 'node_modules is committed: packages in it can be modified and run without coming from npm', severity: 'medium', excerpt: null });
97
+ // Which files to read: install hooks and configs first, then small code files near the root.
98
+ const pick = [
99
+ ...files.filter((f) => PRIORITY.test(f.path)),
100
+ ...files.filter((f) => CODE.test(f.path) && !PRIORITY.test(f.path) && !/node_modules\/|\/(test|tests|__tests__|dist|build|vendor)\//.test(f.path)).sort((a, b) => a.path.split('/').length - b.path.split('/').length || (a.size ?? 0) - (b.size ?? 0)),
101
+ ].filter((f) => (f.size ?? 0) < 400_000).slice(0, 40);
102
+ let scanned = 0;
103
+ for (let i = 0; i < pick.length; i += 8) {
104
+ const got = await Promise.all(pick.slice(i, i + 8).map((f) => ctx.http.get(`https://raw.githubusercontent.com/${repo}/${encodeURIComponent(g.default_branch)}/${f.path.split('/').map(encodeURIComponent).join('/')}`, { source: 'github-raw', as: 'text', ttlSec: 1800, retries: 0 }).then((x) => [f.path, x])));
105
+ if (i === 0 && got[0])
106
+ provenance.push(got[0][1].prov);
107
+ for (const [p, x] of got)
108
+ if (typeof x.data === 'string') {
109
+ scanned++;
110
+ findings.push(...scanText(p, x.data));
111
+ }
112
+ }
113
+ // Account and stars.
114
+ const acc = u.data ? { login: u.data.login, type: u.data.type, createdAt: u.data.created_at ?? null, ageDays: u.data.created_at ? Math.floor((nowMs - Date.parse(u.data.created_at)) / DAY) : null, repos: u.data.public_repos ?? null, followers: u.data.followers ?? null } : null;
115
+ let stars = null;
116
+ if (tok && g.stargazers_count >= 20) {
117
+ const [owner, name] = repo.split('/');
118
+ const q = await postJson(ctx, 'https://api.github.com/graphql', { query: 'query($o:String!,$n:String!){repository(owner:$o,name:$n){stargazers(last:60){nodes{createdAt repositories{totalCount} followers{totalCount}}}}}', variables: { o: owner, n: name } }, { authorization: `Bearer ${tok}` }, 'github-graphql', 3600);
119
+ let nodes = q.data?.data?.repository?.stargazers?.nodes ?? [];
120
+ // Fine-grained tokens cannot read stargazers over GraphQL: sample the newest stars over REST instead.
121
+ if (!nodes.length && g.stargazers_count <= 40_000) {
122
+ const page = Math.max(1, Math.ceil(g.stargazers_count / 30));
123
+ const list = await ctx.http.get(`https://api.github.com/repos/${repo}/stargazers?per_page=30&page=${page}`, { source: 'github', headers, ttlSec: 3600 });
124
+ const logins = (Array.isArray(list.data) ? list.data : []).slice(-20).map((x) => x.login);
125
+ const users = await Promise.all(logins.map((l) => ctx.http.get(`https://api.github.com/users/${l}`, { source: 'github', headers, ttlSec: 7 * 86_400 })));
126
+ nodes = users.filter((x) => x.data?.created_at).map((x) => ({ createdAt: x.data.created_at, repositories: { totalCount: x.data.public_repos ?? 0 }, followers: { totalCount: x.data.followers ?? 0 } }));
127
+ }
128
+ if (nodes.length)
129
+ stars = { sampled: nodes.length, newAccounts: nodes.filter((n) => nowMs - Date.parse(n.createdAt) < 60 * DAY).length, emptyAccounts: nodes.filter((n) => n.repositories.totalCount === 0 && n.followers.totalCount === 0).length };
130
+ }
131
+ const ageDays = Math.floor((nowMs - Date.parse(g.created_at)) / DAY);
132
+ const reasons = [];
133
+ const high = findings.filter((f) => f.severity === 'high'), med = findings.filter((f) => f.severity === 'medium');
134
+ for (const f of [...high, ...med].slice(0, 8))
135
+ reasons.push(`${f.file}${f.line ? `:${f.line}` : ''}: ${f.what}`);
136
+ let risk = high.length * 40 + med.length * 12;
137
+ if (acc?.ageDays !== null && acc?.ageDays !== undefined && acc.ageDays < 30) {
138
+ risk += 15;
139
+ reasons.push(`the owner account is ${acc.ageDays} days old`);
140
+ }
141
+ if (stars && stars.sampled >= 15 && (stars.newAccounts + stars.emptyAccounts) / (2 * stars.sampled) > 0.5) {
142
+ risk += 20;
143
+ reasons.push(`${stars.newAccounts} of the last ${stars.sampled} stars come from accounts younger than 60 days, ${stars.emptyAccounts} from empty accounts: likely bought stars`);
144
+ }
145
+ if (ageDays < 14 && g.stargazers_count > 300) {
146
+ risk += 10;
147
+ reasons.push(`${g.stargazers_count} stars on a repo only ${ageDays} days old`);
148
+ }
149
+ risk = Math.min(100, risk);
150
+ const verdict = high.length ? 'malicious code found' : risk >= 25 ? 'suspicious' : 'no known risk found';
151
+ const advice = verdict === 'malicious code found'
152
+ ? ['Do not install, run or open this repo in your editor. If you already did, assume wallets, browser passwords and SSH keys on that machine are stolen: move funds to a new wallet from another device and change passwords.', 'Report the repo to GitHub (Report repository).']
153
+ : verdict === 'suspicious' ? ['Read the flagged files before running anything. Run it in a throwaway virtual machine or a GitHub Codespace, never on the machine with your wallet.']
154
+ : ['No known malicious patterns in the files read. That is not a guarantee: run code from strangers in a throwaway environment.'];
155
+ const now = ctx.now().toISOString();
156
+ const signals = high.length ? [{ id: signalId('repo', repo.toLowerCase()), module: 'repo', title: `GitHub repo ${repo}: ${high[0].what}`, score: Math.min(95, 60 + high.length * 10), entity: `repo:${repo.toLowerCase()}`, evidence: high.slice(0, 3).map((f) => ({ source: 'github', text: `${f.file}: ${f.what}`, url: `${g.html_url}/blob/${g.default_branch}/${f.file}` })), createdAt: now }] : [];
157
+ return {
158
+ module: 'repo', input: repo, generatedAt: now,
159
+ result: { repo: g.full_name, url: g.html_url, verdict, risk, findings: findings.slice(0, 40), account: acc, stats: { stars: g.stargazers_count, forks: g.forks_count, createdAt: g.created_at, pushedAt: g.pushed_at, ageDays, files: files.length, scanned, fork: g.fork, archived: g.archived, license: g.license?.spdx_id ?? null }, stars, reasons, advice },
160
+ signals, provenance,
161
+ };
162
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Full reports: several checks on one target, run together and summed up on one page (and one PDF).
3
+ * domainReport: link check of the site, email protection (SPF, DKIM, DMARC), what the domain exposes to the
4
+ * internet (open ports, known CVEs), lookalike domains, and the company behind the name (GLEIF).
5
+ * walletReport: address check (sanctions, activity), active approvals, address poisoning, where the funds
6
+ * went, and for token contracts the contract risk and a sell simulation.
7
+ * Each part keeps its own verdict and sources; a part that fails is listed as not checked, never guessed.
8
+ */
9
+ import type { Ctx } from '../core/context.js';
10
+ import type { ModuleResult } from '../core/types.js';
11
+ import { type Tone } from '../core/verdict.js';
12
+ export interface ReportPart {
13
+ part: string;
14
+ verdict: string | null;
15
+ tone: Tone;
16
+ risk: number | null;
17
+ points: string[];
18
+ error: string | null;
19
+ }
20
+ export interface FullReport {
21
+ target: string;
22
+ kind: 'domain' | 'wallet' | 'token';
23
+ verdict: string;
24
+ risk: number;
25
+ parts: ReportPart[];
26
+ reasons: string[];
27
+ advice: string[];
28
+ }
29
+ export declare function domainReport(ctx: Ctx, input: string): Promise<ModuleResult<FullReport>>;
30
+ export declare function walletReport(ctx: Ctx, input: string, opts?: {
31
+ chain?: string;
32
+ }): Promise<ModuleResult<FullReport>>;
@@ -0,0 +1,108 @@
1
+ import { toneOf, verdictOf } from '../core/verdict.js';
2
+ import { chainCan, codeAt, evmChain, isAddr } from '../sources/evm.js';
3
+ import { urlCheck } from './urlcheck.js';
4
+ import { emailSecurity } from './emailsec.js';
5
+ import { exposure } from './exposure.js';
6
+ import { lookalikes } from './lookalike.js';
7
+ import { companyCheck } from './company.js';
8
+ import { addressCheck } from './address.js';
9
+ import { approvalsCheck } from './approvals.js';
10
+ import { poisoningCheck } from './poisoning.js';
11
+ import { traceFunds } from './trace.js';
12
+ import { contractRisk } from './contract.js';
13
+ import { honeypotCheck } from './honeypot.js';
14
+ async function runAll(jobs, provenance, signals) {
15
+ const settled = await Promise.allSettled(jobs.map(([, f]) => f()));
16
+ const parts = [], results = {};
17
+ settled.forEach((s, i) => {
18
+ const part = jobs[i][0];
19
+ if (s.status === 'fulfilled') {
20
+ const v = verdictOf(s.value);
21
+ provenance.push(...s.value.provenance.slice(0, 6));
22
+ signals.push(...s.value.signals);
23
+ results[part] = s.value.result;
24
+ // Only a result's own "risk" counts here: some modules report a "score" where higher is better.
25
+ const own = s.value.result?.risk;
26
+ const risk = typeof own === 'number' ? Math.round(own) : null;
27
+ parts.push({ part, verdict: v.verdict, tone: risk === null && v.risk !== null ? toneOf(v.verdict, null) : v.tone, risk, points: v.points.slice(0, 5), error: null });
28
+ }
29
+ else
30
+ parts.push({ part, verdict: null, tone: 'info', risk: null, points: [], error: String(s.reason?.message ?? s.reason).slice(0, 160) });
31
+ });
32
+ return { parts, results };
33
+ }
34
+ function sum(parts) {
35
+ const bad = parts.filter((p) => p.tone === 'bad'), warn = parts.filter((p) => p.tone === 'warn');
36
+ const risk = Math.min(100, Math.max(0, ...parts.map((p) => p.risk ?? (p.tone === 'bad' ? 80 : p.tone === 'warn' ? 40 : 0))));
37
+ const verdict = bad.length ? `high risk: ${bad.map((p) => p.part).join(', ')}` : warn.length ? `check: ${warn.map((p) => p.part).join(', ')}` : 'no major risks found';
38
+ const reasons = [...bad, ...warn].map((p) => `${p.part}: ${p.verdict ?? 'flagged'}${p.points[0] ? ` (${p.points[0]})` : ''}`);
39
+ const failed = parts.filter((p) => p.error);
40
+ if (failed.length)
41
+ reasons.push(`not checked: ${failed.map((p) => p.part).join(', ')}`);
42
+ return { verdict, risk, reasons };
43
+ }
44
+ export async function domainReport(ctx, input) {
45
+ const domain = input.trim().toLowerCase().replace(/^https?:\/\//, '').replace(/^www\./, '').split(/[/?#]/)[0];
46
+ if (!/^[a-z0-9-]+(\.[a-z0-9-]+)+$/.test(domain))
47
+ throw new Error('give a domain, e.g. example.com');
48
+ const provenance = [], signals = [];
49
+ const brand = domain.split('.').slice(-2)[0];
50
+ const { parts } = await runAll([
51
+ ['link check', () => urlCheck(ctx, `https://${domain}`)],
52
+ ['email protection', () => emailSecurity(ctx, domain)],
53
+ ['internet exposure', () => exposure(ctx, domain)],
54
+ ['lookalike domains', () => lookalikes(ctx, domain)],
55
+ ['company', () => companyCheck(ctx, brand)],
56
+ ], provenance, signals);
57
+ // A company match by name alone is a hint, and lookalikes say how much the brand is copied, not whether this
58
+ // domain is bad: neither raises the risk.
59
+ for (const p of parts.filter((x) => x.part === 'company' || x.part === 'lookalike domains')) {
60
+ p.tone = 'info';
61
+ p.risk = null;
62
+ }
63
+ const { verdict, risk, reasons } = sum(parts);
64
+ const advice = risk >= 70
65
+ ? ['Do not log in, pay or reply through this domain until the flagged parts are explained.']
66
+ : ['Keep the PDF of this report with the check id: it lists every source and its answer.'];
67
+ return { module: 'report', input: domain, generatedAt: ctx.now().toISOString(), result: { target: domain, kind: 'domain', verdict, risk, parts, reasons, advice }, signals, provenance };
68
+ }
69
+ export async function walletReport(ctx, input, opts = {}) {
70
+ const address = input.trim().toLowerCase();
71
+ if (!isAddr(address))
72
+ throw new Error('give an EVM address: 0x followed by 40 hex characters');
73
+ const c = evmChain(opts.chain);
74
+ const code = await codeAt(ctx, c, address);
75
+ const isContract = Boolean(code && code !== '0x' && !/^0xef0100/i.test(code));
76
+ const provenance = [], signals = [];
77
+ const chain = c.key;
78
+ const jobs = isContract
79
+ ? [
80
+ ['contract risk', () => contractRisk(ctx, address, { chain })],
81
+ ...(['eth', 'bsc', 'base'].includes(chain) ? [['sell simulation', () => honeypotCheck(ctx, address, { chain })]] : []),
82
+ ['address', () => addressCheck(ctx, address, chain === 'robinhood' ? { network: 'robinhood' } : {})],
83
+ ]
84
+ : [
85
+ ['address', () => addressCheck(ctx, address, chain === 'robinhood' ? { network: 'robinhood' } : {})],
86
+ ...(chainCan(c, 'logs') ? [['approvals', () => approvalsCheck(ctx, address, { chain })]] : []),
87
+ ...(chainCan(c, 'transfers') ? [
88
+ ['address poisoning', () => poisoningCheck(ctx, address, { chain })],
89
+ ['where funds went', () => traceFunds(ctx, address, { chain, hops: 2, width: 3 })],
90
+ ] : []),
91
+ ];
92
+ const { parts } = await runAll(jobs, provenance, signals);
93
+ // Where funds went describes the past, not this wallet's safety, unless it reached a sanctioned address.
94
+ const tr = parts.find((p) => p.part === 'where funds went');
95
+ if (tr && !/sanction/.test(tr.verdict ?? '')) {
96
+ tr.tone = 'info';
97
+ tr.risk = null;
98
+ }
99
+ const { verdict, risk, reasons } = sum(parts);
100
+ if (!isContract && !chainCan(c, 'logs'))
101
+ reasons.push(`${c.label}: approvals need event logs that no free source covers here`);
102
+ if (!isContract && !chainCan(c, 'transfers'))
103
+ reasons.push(`${c.label}: poisoning and fund trace need transaction history that no configured source covers`);
104
+ const advice = isContract
105
+ ? risk >= 70 ? ['Do not buy this token.'] : ['Owner powers and liquidity can change; check again before a large trade.']
106
+ : risk >= 70 ? ['Revoke flagged approvals and move funds to a new wallet if you did not sign them.'] : ['Nothing urgent. Revoke approvals you no longer use.'];
107
+ return { module: 'report', input: address, generatedAt: ctx.now().toISOString(), result: { target: address, kind: isContract ? 'token' : 'wallet', verdict, risk, parts, reasons, advice }, signals, provenance };
108
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Signature decoder: paste what a wallet asks you to sign and read what it really allows, before you sign it.
3
+ * Understands:
4
+ * - EIP-712 typed data (eth_signTypedData_v4): ERC-2612 and DAI permits, Uniswap Permit2 (allowance and
5
+ * signature transfers), Seaport orders (what you give and what you get back), and any other typed message.
6
+ * - Transaction calldata, alone or as a { to, data, value } object: approve, increaseAllowance,
7
+ * setApprovalForAll, transfer, transferFrom, NFT transfers, Permit2 approve, and multicall bundles of these.
8
+ * Unknown functions are named through the public signature databases.
9
+ * - Raw 32-byte hashes (eth_sign), which hide what they authorize.
10
+ * The spender or receiver is looked up on chain (wallet or contract, verified or not) when an address is known.
11
+ * Decoding is local; only the address and selector lookups go out.
12
+ */
13
+ import type { Ctx } from '../core/context.js';
14
+ import type { ModuleResult } from '../core/types.js';
15
+ export interface SignatureReport {
16
+ kind: 'typed data' | 'transaction' | 'raw hash' | 'message';
17
+ type: string;
18
+ verdict: 'dangerous signature' | 'risky signature' | 'check before signing' | 'no known risk found';
19
+ risk: number;
20
+ summary: string;
21
+ allows: string[];
22
+ reasons: string[];
23
+ parties: {
24
+ address: string;
25
+ role: string;
26
+ name: string | null;
27
+ type: string | null;
28
+ }[];
29
+ chain: string | null;
30
+ advice: string[];
31
+ }
32
+ export declare function signatureCheck(ctx: Ctx, input: string, opts?: {
33
+ chain?: string;
34
+ to?: string;
35
+ }): Promise<ModuleResult<SignatureReport>>;