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.
- package/README.md +93 -17
- package/dist/cli/main.js +397 -0
- package/dist/core/calls.d.ts +63 -0
- package/dist/core/calls.js +120 -0
- package/dist/core/der.d.ts +2 -0
- package/dist/core/der.js +17 -0
- package/dist/core/http.d.ts +30 -1
- package/dist/core/http.js +133 -29
- package/dist/core/pdf.d.ts +51 -0
- package/dist/core/pdf.js +211 -0
- package/dist/core/qr.d.ts +23 -0
- package/dist/core/qr.js +577 -0
- package/dist/core/quota.js +5 -0
- package/dist/core/raster.d.ts +6 -0
- package/dist/core/raster.js +298 -0
- package/dist/core/safeurl.d.ts +5 -0
- package/dist/core/safeurl.js +26 -0
- package/dist/core/verdict.d.ts +30 -0
- package/dist/core/verdict.js +164 -0
- package/dist/core/zip.d.ts +9 -0
- package/dist/core/zip.js +46 -0
- package/dist/index.d.ts +83 -0
- package/dist/index.js +128 -0
- package/dist/mcp.d.ts +1 -0
- package/dist/mcp.js +256 -6
- package/dist/modules/address.d.ts +6 -2
- package/dist/modules/address.js +32 -5
- package/dist/modules/apk.d.ts +37 -0
- package/dist/modules/apk.js +191 -0
- package/dist/modules/approvals.d.ts +40 -0
- package/dist/modules/approvals.js +155 -0
- package/dist/modules/archive.d.ts +21 -0
- package/dist/modules/archive.js +94 -0
- package/dist/modules/checks.d.ts +59 -0
- package/dist/modules/checks.js +167 -0
- package/dist/modules/contract.d.ts +56 -0
- package/dist/modules/contract.js +167 -0
- package/dist/modules/deployer.d.ts +42 -0
- package/dist/modules/deployer.js +90 -0
- package/dist/modules/doc.d.ts +83 -0
- package/dist/modules/doc.js +841 -0
- package/dist/modules/eml.d.ts +46 -0
- package/dist/modules/eml.js +175 -0
- package/dist/modules/hashcheck.d.ts +19 -3
- package/dist/modules/hashcheck.js +28 -4
- package/dist/modules/image.d.ts +32 -0
- package/dist/modules/image.js +276 -0
- package/dist/modules/invite.d.ts +27 -0
- package/dist/modules/invite.js +69 -0
- package/dist/modules/job.d.ts +33 -0
- package/dist/modules/job.js +64 -0
- package/dist/modules/meerkat.d.ts +1 -1
- package/dist/modules/meerkat.js +35 -2
- package/dist/modules/monitor.js +14 -0
- package/dist/modules/poisoning.d.ts +43 -0
- package/dist/modules/poisoning.js +114 -0
- package/dist/modules/qrcheck.d.ts +24 -0
- package/dist/modules/qrcheck.js +136 -0
- package/dist/modules/repo.d.ts +61 -0
- package/dist/modules/repo.js +162 -0
- package/dist/modules/report.d.ts +32 -0
- package/dist/modules/report.js +108 -0
- package/dist/modules/signature.d.ts +35 -0
- package/dist/modules/signature.js +283 -0
- package/dist/modules/site.d.ts +62 -0
- package/dist/modules/site.js +191 -0
- package/dist/modules/stocktoken.d.ts +48 -0
- package/dist/modules/stocktoken.js +99 -0
- package/dist/modules/trace.d.ts +37 -0
- package/dist/modules/trace.js +150 -0
- package/dist/modules/txexplain.d.ts +40 -0
- package/dist/modules/txexplain.js +135 -0
- package/dist/modules/urlcheck.js +15 -1
- package/dist/modules/utility.d.ts +27 -1
- package/dist/modules/utility.js +108 -11
- package/dist/modules/where.d.ts +63 -0
- package/dist/modules/where.js +165 -0
- package/dist/report-pdf.d.ts +7 -0
- package/dist/report-pdf.js +84 -0
- package/dist/sources/cfurlscan.d.ts +24 -0
- package/dist/sources/cfurlscan.js +46 -0
- package/dist/sources/chainabuse.d.ts +17 -0
- package/dist/sources/chainabuse.js +19 -0
- package/dist/sources/evm.d.ts +135 -0
- package/dist/sources/evm.js +260 -0
- package/dist/sources/phishlists.d.ts +20 -0
- package/dist/sources/phishlists.js +90 -0
- package/dist/telegram.d.ts +17 -0
- package/dist/telegram.js +151 -4
- package/dist/web/card.d.ts +28 -0
- package/dist/web/card.js +75 -0
- package/dist/web/docs.html +1 -1
- package/dist/web/index.html +213 -5
- package/dist/web/landing.html +1 -1
- package/dist/web/legal.html +3 -1
- package/dist/web/mcp.html +1 -1
- package/dist/web/openapi.js +15 -0
- package/dist/web/pages.d.ts +24 -0
- package/dist/web/pages.js +139 -0
- package/dist/web/public.js +16 -1
- package/dist/web/server.d.ts +13 -0
- package/dist/web/server.js +152 -13
- package/dist/web/token.html +25 -4
- package/dist/web/token.json +12 -1
- package/dist/web/utility.html +40 -14
- package/package.json +2 -2
package/dist/cli/main.js
CHANGED
|
@@ -9,6 +9,7 @@ import { oculonHome } from '../core/paths.js';
|
|
|
9
9
|
import { fmtTime } from '../modules/listen.js';
|
|
10
10
|
import { Oculon, summarizeProvenance } from '../index.js';
|
|
11
11
|
import { ONCHAIN_COMMANDS, ONCHAIN_PAUSED_MESSAGE, onchainEnabled } from '../core/features.js';
|
|
12
|
+
import { toneOf } from '../core/verdict.js';
|
|
12
13
|
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
13
14
|
const VERSION = (() => {
|
|
14
15
|
for (const p of [join(HERE, '..', '..', 'package.json'), join(HERE, '..', 'package.json')]) {
|
|
@@ -162,6 +163,8 @@ ${c.bold('Graph')}
|
|
|
162
163
|
oculon connect <A> to <B> how two things are linked (shortest path)
|
|
163
164
|
oculon resolve merge duplicates: org:nvidia = company:nvidia = nvidia.com
|
|
164
165
|
oculon quota today's API usage vs daily budgets
|
|
166
|
+
oculon status [--hours 24] which sources are up, slow or down (from real calls)
|
|
167
|
+
oculon replay <check id> [--pdf f] every source a check called; --pdf writes the report
|
|
165
168
|
|
|
166
169
|
${c.bold('Radar')}
|
|
167
170
|
oculon radar what the world is suddenly paying attention to
|
|
@@ -196,6 +199,30 @@ ${c.bold('Everyday checks')}
|
|
|
196
199
|
oculon iban <IBAN> [--country NL] is this IBAN valid, and is the account in the supplier's country?
|
|
197
200
|
oculon headers < headers.txt raw email headers: SPF, DKIM, DMARC, path, origin, spoofing signs
|
|
198
201
|
oculon address <crypto address> chain, OFAC sanctions, balance and activity, no keys needed
|
|
202
|
+
oculon doc <file.pdf|.docx|.xlsx|.png|.jpg> was this invoice or statement edited? macros, IBANs, editors
|
|
203
|
+
oculon photo <image> made by AI, edited, or a camera photo? C2PA credentials, generator traces
|
|
204
|
+
oculon qr <image> read a QR code and check where it leads (link, crypto, bank, Wi-Fi)
|
|
205
|
+
oculon repo <owner/name> is this GitHub repo safe to run? install hooks, stealers, fake stars
|
|
206
|
+
oculon check <domain|0x address> full report: every check on one page (--pdf report.pdf)
|
|
207
|
+
|
|
208
|
+
${c.bold('Wallet safety')}
|
|
209
|
+
oculon approvals <wallet> who can take your tokens: active approvals, risky spenders flagged
|
|
210
|
+
oculon contract <token> what the owner can still do: mint, blacklist, taxes, upgrades, liquidity
|
|
211
|
+
oculon signature <request|file> what a signature request really allows (permits, Permit2, Seaport, calldata)
|
|
212
|
+
oculon poisoning <wallet> lookalike addresses and fake tokens planted in your history
|
|
213
|
+
oculon trace <address> [--hops 3] follow the money to exchanges, mixers and bridges
|
|
214
|
+
oculon site <link> wallet drainer and phishing check of a page
|
|
215
|
+
oculon tx <hash> what happened in a transaction, in plain words
|
|
216
|
+
oculon creator <token> who made this token and how many of their tokens are dead
|
|
217
|
+
oculon stocktoken [TSLA|0x..] Robinhood Stock Tokens: official contract, live price, dividends, fakes
|
|
218
|
+
|
|
219
|
+
${c.bold('More checks')}
|
|
220
|
+
oculon eml <message.eml> a whole email: headers, message, links and attachments
|
|
221
|
+
oculon apk <app.apk> is this Android app safe to install? permissions, signer, malware
|
|
222
|
+
oculon job "<message>" is this job offer a scam?
|
|
223
|
+
oculon where <photo.jpg> where and when a photo was taken, and the weather then
|
|
224
|
+
oculon archive <link> save a page as evidence (Wayback Machine, hash)
|
|
225
|
+
oculon invite <t.me|discord.gg link> what is behind a Telegram or Discord invite
|
|
199
226
|
|
|
200
227
|
${c.bold('Threat intel')}
|
|
201
228
|
oculon ip <IP|domain> abuse reports, scanners, threat reports, Tor, Spamhaus DROP, open ports
|
|
@@ -281,6 +308,34 @@ function readHidden(prompt) {
|
|
|
281
308
|
}
|
|
282
309
|
const json = (a) => a.flags.json === true;
|
|
283
310
|
const emit = (a, data, human) => (json(a) ? out(JSON.stringify(data, null, 2)) : human());
|
|
311
|
+
const chainOpt = (a) => (typeof a.flags.chain === 'string' ? { chain: a.flags.chain } : {});
|
|
312
|
+
/**
|
|
313
|
+
* Runs a check that is recorded (seen before, replay log, PDF), prints the verdict, the module's own lines,
|
|
314
|
+
* the reasons and advice. --pdf <file> also writes the PDF report.
|
|
315
|
+
*/
|
|
316
|
+
async function checked(o, a, kind, target, run, lines, label) {
|
|
317
|
+
const chain = typeof a.flags.chain === 'string' ? `@${a.flags.chain.toLowerCase()}` : '';
|
|
318
|
+
const { value: r, check } = await o.recordCheck(kind, `${target}${chain}`, run, { label: label ?? `${target}${chain ? ` (${chain.slice(1)})` : ''}` });
|
|
319
|
+
if (typeof a.flags.pdf === 'string') {
|
|
320
|
+
const { writeFileSync } = await import('node:fs');
|
|
321
|
+
writeFileSync(a.flags.pdf, o.checkPdf(check.id));
|
|
322
|
+
}
|
|
323
|
+
emit(a, { ...r, check }, () => {
|
|
324
|
+
const d = r.result;
|
|
325
|
+
const tone = toneOf(d.verdict, d.risk);
|
|
326
|
+
const col = tone === 'bad' ? c.red : tone === 'warn' ? c.yellow : tone === 'ok' ? c.green : c.cyan;
|
|
327
|
+
out(`${c.bold(label ?? r.input)} ${col(d.verdict.toUpperCase())} ${c.dim(`risk ${d.risk}/100`)}`);
|
|
328
|
+
lines(d);
|
|
329
|
+
for (const x of d.reasons)
|
|
330
|
+
out(c.yellow(` ! ${x}`));
|
|
331
|
+
for (const x of d.advice)
|
|
332
|
+
out(` → ${x}`);
|
|
333
|
+
if (check.seenBefore)
|
|
334
|
+
out(c.cyan(` seen before ${check.seenBefore.at.slice(0, 16).replace('T', ' ')} UTC${check.seenBefore.changes.length ? `: ${check.seenBefore.changes.join('; ')}` : ', nothing changed'}`));
|
|
335
|
+
out(c.dim(` check ${check.id} · oculon replay ${check.id} --pdf report.pdf${typeof a.flags.pdf === 'string' ? ` · wrote ${a.flags.pdf}` : ''}`));
|
|
336
|
+
printSources(r);
|
|
337
|
+
});
|
|
338
|
+
}
|
|
284
339
|
export const COMMANDS = {
|
|
285
340
|
async radar(o, a) {
|
|
286
341
|
const r = await o.radar();
|
|
@@ -926,6 +981,85 @@ export const COMMANDS = {
|
|
|
926
981
|
printSources(r);
|
|
927
982
|
});
|
|
928
983
|
},
|
|
984
|
+
async doc(o, a) {
|
|
985
|
+
const file = a.pos.slice(1).join(' ').trim();
|
|
986
|
+
if (!file)
|
|
987
|
+
throw new UsageError('usage: oculon doc <file.pdf|file.png|file.jpg>');
|
|
988
|
+
if (!existsSync(file))
|
|
989
|
+
throw new UsageError(`no such file: ${file}`);
|
|
990
|
+
const bytes = readFileSync(file);
|
|
991
|
+
const { createHash } = await import('node:crypto');
|
|
992
|
+
const name = file.split(/[\\/]/).pop();
|
|
993
|
+
const { value: r, check } = await o.recordCheck('doc', createHash('sha256').update(bytes).digest('hex'), () => o.docCheck(bytes, name), { label: name });
|
|
994
|
+
emit(a, { ...r, check }, () => {
|
|
995
|
+
const d = r.result;
|
|
996
|
+
const tone = d.verdict === 'dangerous file' || d.verdict === 'likely edited' ? c.red : d.verdict === 'signs of editing' ? c.yellow : c.green;
|
|
997
|
+
out(`${c.bold(d.name)} ${tone(d.verdict.toUpperCase())} ${c.dim(`risk ${d.risk}/100 · ${d.type} · ${(d.bytes / 1024).toFixed(0)} KB`)}`);
|
|
998
|
+
const meta = ['producer', 'creator', 'creator tool', 'software', 'created', 'modified'].filter((k) => d.metadata[k]).map((k) => `${k} ${d.metadata[k]}`);
|
|
999
|
+
if (meta.length)
|
|
1000
|
+
out(c.dim(` ${meta.join(' · ')}`));
|
|
1001
|
+
if (d.revisions && d.revisions > 1)
|
|
1002
|
+
out(c.dim(` saved ${d.revisions} times${d.signed ? ' (digitally signed)' : ''}`));
|
|
1003
|
+
for (const f of d.flags)
|
|
1004
|
+
out(c.yellow(` ! ${f}`));
|
|
1005
|
+
for (const ib of d.ibans)
|
|
1006
|
+
out(` IBAN ${ib.iban} ${ib.valid ? c.green('valid') : c.red('NOT VALID')}${ib.country ? c.dim(` · ${ib.country}`) : ''}`);
|
|
1007
|
+
if (d.domains.length)
|
|
1008
|
+
out(c.dim(` domains in the text: ${d.domains.join(', ')}`));
|
|
1009
|
+
out(c.dim(` text: ${d.text.chars} characters from the ${d.text.from}`));
|
|
1010
|
+
for (const n of d.notes)
|
|
1011
|
+
out(c.dim(` ${n}`));
|
|
1012
|
+
for (const x of d.advice)
|
|
1013
|
+
out(` → ${x}`);
|
|
1014
|
+
if (check.seenBefore)
|
|
1015
|
+
out(c.cyan(` seen before ${check.seenBefore.at.slice(0, 16).replace('T', ' ')} UTC${check.seenBefore.changes.length ? `: ${check.seenBefore.changes.join('; ')}` : ', nothing changed'}`));
|
|
1016
|
+
out(c.dim(` check ${check.id} · oculon replay ${check.id} --pdf report.pdf`));
|
|
1017
|
+
printSources(r);
|
|
1018
|
+
});
|
|
1019
|
+
},
|
|
1020
|
+
async replay(o, a) {
|
|
1021
|
+
const id = String(a.pos[1] ?? '').trim();
|
|
1022
|
+
if (!id)
|
|
1023
|
+
throw new UsageError('usage: oculon replay <check id> [--pdf report.pdf]');
|
|
1024
|
+
const ck = o.check(id);
|
|
1025
|
+
if (!ck)
|
|
1026
|
+
throw new UsageError(`no check ${id} in this install's database (checks are kept for 90 days)`);
|
|
1027
|
+
if (typeof a.flags.pdf === 'string') {
|
|
1028
|
+
const { writeFileSync } = await import('node:fs');
|
|
1029
|
+
writeFileSync(a.flags.pdf, o.checkPdf(id));
|
|
1030
|
+
out(`wrote ${a.flags.pdf}`);
|
|
1031
|
+
return;
|
|
1032
|
+
}
|
|
1033
|
+
if (a.flags.json)
|
|
1034
|
+
return out(JSON.stringify({ ...ck, history: o.checkHistory(id) }, null, 2));
|
|
1035
|
+
const v = ck.verdict;
|
|
1036
|
+
out(`${c.bold(ck.label)} ${c.cyan(ck.kind)} ${(v.tone === 'bad' ? c.red : v.tone === 'warn' ? c.yellow : c.green)((v.verdict ?? 'result').toUpperCase())}${v.risk !== null ? c.dim(` risk ${v.risk}/100`) : ''}`);
|
|
1037
|
+
out(c.dim(` checked ${ck.createdAt.slice(0, 19).replace('T', ' ')} UTC · ${(ck.durationMs / 1000).toFixed(1)} s · ${ck.calls.length} source calls`));
|
|
1038
|
+
for (const p of v.points.slice(0, 8))
|
|
1039
|
+
out(` - ${p}`);
|
|
1040
|
+
if (ck.seenBefore)
|
|
1041
|
+
out(c.cyan(` seen before ${ck.seenBefore.at.slice(0, 16).replace('T', ' ')} UTC${ck.seenBefore.changes.length ? `: ${ck.seenBefore.changes.join('; ')}` : ', nothing changed'}`));
|
|
1042
|
+
out(c.bold('\n Source calls'));
|
|
1043
|
+
for (const k of ck.calls) {
|
|
1044
|
+
const st = k.status === 'LIVE' ? c.green(k.status) : k.status === 'CACHED' ? c.cyan(k.status) : c.yellow(k.status);
|
|
1045
|
+
out(` ${k.at.slice(11, 19)} ${k.source.padEnd(22)} ${st.padEnd(20)} ${String(k.ms).padStart(6)} ms ${c.dim(k.host + (k.via ? ' (mirror)' : ''))}${k.note ? c.dim(` ${trunc(k.note, 80)}`) : ''}`);
|
|
1046
|
+
}
|
|
1047
|
+
if (!ck.calls.length)
|
|
1048
|
+
out(c.dim(' none: this check ran on the input alone'));
|
|
1049
|
+
},
|
|
1050
|
+
async status(o, a) {
|
|
1051
|
+
const hours = Math.min(48, Number(a.flags.hours ?? 24) || 24);
|
|
1052
|
+
const list = o.sourceStatus(hours);
|
|
1053
|
+
if (a.flags.json)
|
|
1054
|
+
return out(JSON.stringify({ hours, sources: list }, null, 2));
|
|
1055
|
+
if (!list.length)
|
|
1056
|
+
return out(c.dim(`No live source calls in the last ${hours} hours on this install.`));
|
|
1057
|
+
out(c.bold(`Sources, last ${hours} hours`));
|
|
1058
|
+
for (const s of list) {
|
|
1059
|
+
const st = s.state === 'up' ? c.green('UP') : s.state === 'down' ? c.red('DOWN') : c.yellow(s.state.toUpperCase());
|
|
1060
|
+
out(` ${s.source.padEnd(26)} ${st.padEnd(18)} ${String(s.okPct).padStart(3)}% ${String(s.calls).padStart(4)} calls ${s.medianMs === null ? ' -' : `${String(s.medianMs).padStart(6)} ms`}${s.skippedUntil ? c.yellow(` skipped until ${s.skippedUntil.slice(11, 16)} UTC`) : ''}${s.lastError ? c.dim(` last error ${s.lastError.at.slice(11, 16)} ${trunc(s.lastError.note, 50)}`) : ''}`);
|
|
1061
|
+
}
|
|
1062
|
+
},
|
|
929
1063
|
async lookalike(o, a) {
|
|
930
1064
|
const q = String(a.pos[1] ?? '').trim();
|
|
931
1065
|
if (!q)
|
|
@@ -946,6 +1080,269 @@ export const COMMANDS = {
|
|
|
946
1080
|
printSources(r);
|
|
947
1081
|
});
|
|
948
1082
|
},
|
|
1083
|
+
async approvals(o, a) {
|
|
1084
|
+
const q = String(a.pos[1] ?? '').trim();
|
|
1085
|
+
if (!q)
|
|
1086
|
+
throw new UsageError('usage: oculon approvals <wallet address> [--chain eth|arbitrum|polygon]');
|
|
1087
|
+
await checked(o, a, 'approvals', q, () => o.approvalsCheck(q, chainOpt(a)), (d) => {
|
|
1088
|
+
out(c.dim(` ${d.active} active approval${d.active === 1 ? '' : 's'}, ${d.unlimited} unlimited · ${d.chain}`));
|
|
1089
|
+
for (const x of d.approvals.slice(0, 25)) {
|
|
1090
|
+
const tone = x.risk === 'high' ? c.red : x.risk === 'medium' ? c.yellow : c.dim;
|
|
1091
|
+
out(tone(` ${x.risk.padEnd(6)} ${(x.symbol ?? x.token.slice(0, 10)).padEnd(10)} -> ${x.spenderName ?? x.spender} (${x.spenderType}) ${x.amount}`));
|
|
1092
|
+
}
|
|
1093
|
+
out(c.dim(` revoke: ${d.revokeUrl}`));
|
|
1094
|
+
});
|
|
1095
|
+
},
|
|
1096
|
+
async contract(o, a) {
|
|
1097
|
+
const q = String(a.pos[1] ?? '').trim();
|
|
1098
|
+
if (!q)
|
|
1099
|
+
throw new UsageError('usage: oculon contract <token address> [--chain eth|base|bsc|arbitrum|polygon]');
|
|
1100
|
+
await checked(o, a, 'contract', q, () => o.contractRisk(q, chainOpt(a)), (d) => {
|
|
1101
|
+
out(c.dim(` ${d.name ?? d.contractName ?? ''} ${d.symbol ? `(${d.symbol})` : ''} · ${d.chain} · ${d.verified ? `verified on ${d.verifiedBy}` : 'NOT verified'}`));
|
|
1102
|
+
out(c.dim(` owner ${d.owner ?? 'none found'}${d.ownerRenounced ? ' (renounced)' : ''}${d.proxy ? ` · proxy -> ${d.proxy.implementation ?? '?'}` : ''}`));
|
|
1103
|
+
if (d.holders)
|
|
1104
|
+
out(c.dim(` holders ${d.holders.count ?? '?'} · top 10 hold ${d.holders.top10Percent ?? '?'}%`));
|
|
1105
|
+
if (d.liquidity)
|
|
1106
|
+
out(c.dim(` liquidity $${Math.round(d.liquidity.usd ?? 0).toLocaleString('en-US')} ${d.liquidity.pair ?? ''} ${d.liquidity.dex ?? ''}${d.liquidity.lockedPercent !== null ? ` · ${d.liquidity.lockedPercent}% LP locked or burned` : ''}`));
|
|
1107
|
+
});
|
|
1108
|
+
},
|
|
1109
|
+
async signature(o, a) {
|
|
1110
|
+
let raw = a.pos.slice(1).join(' ').trim();
|
|
1111
|
+
if (raw && existsSync(raw))
|
|
1112
|
+
raw = readFileSync(raw, 'utf8');
|
|
1113
|
+
if (!raw && !process.stdin.isTTY)
|
|
1114
|
+
raw = readFileSync(0, 'utf8');
|
|
1115
|
+
if (!raw)
|
|
1116
|
+
throw new UsageError('usage: oculon signature <typed data JSON | 0x calldata | file> [--to <contract>] [--chain eth] (or pipe it in)');
|
|
1117
|
+
await checked(o, a, 'signature', raw, () => o.signatureCheck(raw, { ...chainOpt(a), ...(typeof a.flags.to === 'string' ? { to: a.flags.to } : {}) }), (d) => {
|
|
1118
|
+
out(c.dim(` ${d.type} · ${d.kind}${d.chain ? ` · ${d.chain}` : ''}`));
|
|
1119
|
+
for (const x of d.allows)
|
|
1120
|
+
out(` allows: ${x}`);
|
|
1121
|
+
for (const p of d.parties)
|
|
1122
|
+
out(c.dim(` ${p.role}: ${p.address} ${p.name ?? p.type ?? ''}`));
|
|
1123
|
+
}, `signature request: ${raw.slice(0, 60)}`);
|
|
1124
|
+
},
|
|
1125
|
+
async poisoning(o, a) {
|
|
1126
|
+
const q = String(a.pos[1] ?? '').trim();
|
|
1127
|
+
if (!q)
|
|
1128
|
+
throw new UsageError('usage: oculon poisoning <wallet address> [--chain eth|arbitrum|polygon]');
|
|
1129
|
+
await checked(o, a, 'poisoning', q, () => o.poisoningCheck(q, chainOpt(a)), (d) => {
|
|
1130
|
+
out(c.dim(` ${d.checkedTransfers} token transfers read · ${d.realCounterparties} addresses this wallet really paid · ${d.zeroValue} zero-value transfers it never signed`));
|
|
1131
|
+
for (const l of d.lookalikes)
|
|
1132
|
+
out(c.red(` ${l.fake} posing as ${l.real} (${l.how.join(', ')}, ${l.seen}x)`));
|
|
1133
|
+
for (const f of d.fakeTokens)
|
|
1134
|
+
out(c.yellow(` fake ${f.symbol}: ${f.contract} (${f.transfers} transfers)`));
|
|
1135
|
+
});
|
|
1136
|
+
},
|
|
1137
|
+
async trace(o, a) {
|
|
1138
|
+
const q = String(a.pos[1] ?? '').trim();
|
|
1139
|
+
if (!q)
|
|
1140
|
+
throw new UsageError('usage: oculon trace <address> [--chain eth|arbitrum|polygon] [--hops 3]');
|
|
1141
|
+
await checked(o, a, 'trace', q, () => o.traceFunds(q, { ...chainOpt(a), ...(a.flags.hops ? { hops: Number(a.flags.hops) } : {}) }), (d) => {
|
|
1142
|
+
for (const n of d.nodes.slice(1)) {
|
|
1143
|
+
const tone = n.kind === 'exchange' ? c.cyan : n.kind === 'mixer' || n.kind === 'sanctioned' || n.kind === 'scam' ? c.red : c.dim;
|
|
1144
|
+
out(tone(` ${' '.repeat(n.hop - 1)}hop ${n.hop} ${n.address} ${n.label ?? n.kind} ${n.amount ?? ''}${n.stop ? ` [${n.stop}]` : ''}`));
|
|
1145
|
+
if (n.firstTx)
|
|
1146
|
+
out(c.dim(` ${' '.repeat(n.hop - 1)} tx ${n.firstTx}`));
|
|
1147
|
+
}
|
|
1148
|
+
});
|
|
1149
|
+
},
|
|
1150
|
+
async photo(o, a) {
|
|
1151
|
+
const file = a.pos.slice(1).join(' ').trim();
|
|
1152
|
+
if (!file)
|
|
1153
|
+
throw new UsageError('usage: oculon photo <photo.jpg|image.png|image.webp>');
|
|
1154
|
+
if (!existsSync(file))
|
|
1155
|
+
throw new UsageError(`no such file: ${file}`);
|
|
1156
|
+
const bytes = readFileSync(file);
|
|
1157
|
+
const { createHash } = await import('node:crypto');
|
|
1158
|
+
const name = file.split(/[\\/]/).pop();
|
|
1159
|
+
await checked(o, a, 'image', createHash('sha256').update(bytes).digest('hex'), () => o.imageCheck(bytes, name), (d) => {
|
|
1160
|
+
if (d.c2pa)
|
|
1161
|
+
out(c.dim(` Content Credentials: ${d.c2pa.generator ?? 'present'}${d.c2pa.sourceType ? ` · ${d.c2pa.sourceType}` : ''}${d.c2pa.signers.length ? ` · signed by ${d.c2pa.signers.slice(0, 3).join(', ')}` : ''}`));
|
|
1162
|
+
if (d.generator)
|
|
1163
|
+
out(c.dim(` generator: ${d.generator.tool}${d.generator.prompt ? ` · prompt: "${d.generator.prompt.slice(0, 160)}"` : ''}`));
|
|
1164
|
+
if (d.camera || d.software)
|
|
1165
|
+
out(c.dim(` ${d.camera ? `camera ${d.camera}` : ''}${d.camera && d.software ? ' · ' : ''}${d.software ? `software ${d.software}` : ''}`));
|
|
1166
|
+
for (const n of d.notes)
|
|
1167
|
+
out(c.dim(` ${n}`));
|
|
1168
|
+
}, name);
|
|
1169
|
+
},
|
|
1170
|
+
async qr(o, a) {
|
|
1171
|
+
const file = a.pos.slice(1).join(' ').trim();
|
|
1172
|
+
if (!file)
|
|
1173
|
+
throw new UsageError('usage: oculon qr <photo.jpg|screenshot.png>');
|
|
1174
|
+
if (!existsSync(file))
|
|
1175
|
+
throw new UsageError(`no such file: ${file}`);
|
|
1176
|
+
const bytes = readFileSync(file);
|
|
1177
|
+
const { createHash } = await import('node:crypto');
|
|
1178
|
+
const name = file.split(/[\\/]/).pop();
|
|
1179
|
+
await checked(o, a, 'qr', createHash('sha256').update(bytes).digest('hex'), () => o.qrCheck(bytes, name), (d) => {
|
|
1180
|
+
if (d.content)
|
|
1181
|
+
out(` content: ${d.content.slice(0, 300)}`);
|
|
1182
|
+
for (const [k, v] of Object.entries(d.target))
|
|
1183
|
+
if (k !== 'url' && k !== 'text')
|
|
1184
|
+
out(c.dim(` ${k}: ${v}`));
|
|
1185
|
+
}, name);
|
|
1186
|
+
},
|
|
1187
|
+
async repo(o, a) {
|
|
1188
|
+
const q = String(a.pos[1] ?? '').trim();
|
|
1189
|
+
if (!q)
|
|
1190
|
+
throw new UsageError('usage: oculon repo <owner/name | github.com link>');
|
|
1191
|
+
await checked(o, a, 'repo', q, () => o.repoCheck(q), (d) => {
|
|
1192
|
+
out(c.dim(` ${d.url} · ${d.stats.stars} stars · created ${d.stats.createdAt.slice(0, 10)} · ${d.stats.scanned} of ${d.stats.files} files read${d.account ? ` · owner ${d.account.login}, account ${d.account.ageDays ?? '?'} days old` : ''}`));
|
|
1193
|
+
for (const f of d.findings.slice(0, 20))
|
|
1194
|
+
out((f.severity === 'high' ? c.red : f.severity === 'medium' ? c.yellow : c.dim)(` ${f.severity.padEnd(6)} ${f.file}${f.line ? `:${f.line}` : ''} ${f.what}`));
|
|
1195
|
+
});
|
|
1196
|
+
},
|
|
1197
|
+
async check(o, a) {
|
|
1198
|
+
const q = String(a.pos[1] ?? '').trim();
|
|
1199
|
+
if (!q)
|
|
1200
|
+
throw new UsageError('usage: oculon check <domain | 0x address> [--chain eth] [--pdf report.pdf] full report: every check on one page');
|
|
1201
|
+
const wallet = /^0x[0-9a-fA-F]{40}$/.test(q);
|
|
1202
|
+
await checked(o, a, wallet ? 'walletreport' : 'domainreport', q, () => (wallet ? o.walletReport(q, chainOpt(a)) : o.domainReport(q)), (d) => {
|
|
1203
|
+
for (const p of d.parts) {
|
|
1204
|
+
const tone = p.tone === 'bad' ? c.red : p.tone === 'warn' ? c.yellow : p.tone === 'ok' ? c.green : c.dim;
|
|
1205
|
+
out(tone(` ${p.part.padEnd(20)} ${p.error ? `not checked: ${p.error}` : `${p.verdict ?? 'done'}${p.risk !== null ? ` (risk ${p.risk})` : ''}`}`));
|
|
1206
|
+
for (const x of p.points.slice(0, 2))
|
|
1207
|
+
out(c.dim(` ${' '.repeat(20)} ${x}`));
|
|
1208
|
+
}
|
|
1209
|
+
});
|
|
1210
|
+
},
|
|
1211
|
+
async site(o, a) {
|
|
1212
|
+
const q = String(a.pos[1] ?? '').trim();
|
|
1213
|
+
if (!q)
|
|
1214
|
+
throw new UsageError('usage: oculon site <link> wallet drainer and phishing check of a page');
|
|
1215
|
+
await checked(o, a, 'site', q, () => o.siteCheck(q), (d) => {
|
|
1216
|
+
out(c.dim(` ${d.finalUrl}${d.title ? ` · "${d.title.slice(0, 80)}"` : ''} · ${d.scripts.read} scripts read${d.reputation?.ageDays != null ? ` · domain ${d.reputation.ageDays} days old` : ''}`));
|
|
1217
|
+
if (d.browser)
|
|
1218
|
+
out(c.dim(` browser scan (Cloudflare): ${d.browser.malicious ? 'malicious' : 'no verdict'}${d.browser.categories.length ? ` · ${d.browser.categories.join(', ')}` : ''} · ${d.browser.domains} domains contacted · ${d.browser.report}`));
|
|
1219
|
+
if (d.reports?.count)
|
|
1220
|
+
out(c.dim(` Chainabuse: ${d.reports.count} reports · ${d.reports.url}`));
|
|
1221
|
+
for (const f of d.forms.filter((x) => x.password || x.seed || x.card))
|
|
1222
|
+
out(c.dim(` form -> ${f.action || '(same page)'}${f.external ? ' (another domain)' : ''}${f.seed ? ' · seed phrase' : ''}${f.password ? ' · password' : ''}${f.card ? ' · card' : ''}`));
|
|
1223
|
+
});
|
|
1224
|
+
},
|
|
1225
|
+
async tx(o, a) {
|
|
1226
|
+
const q = String(a.pos[1] ?? '').trim();
|
|
1227
|
+
if (!q)
|
|
1228
|
+
throw new UsageError('usage: oculon tx <transaction hash> [--chain eth|base|arbitrum|bsc|polygon]');
|
|
1229
|
+
await checked(o, a, 'tx', q, () => o.explainTx(q, chainOpt(a)), (d) => {
|
|
1230
|
+
for (const x of d.summary)
|
|
1231
|
+
out(` ${x}`);
|
|
1232
|
+
out(c.dim(` ${d.explorer}`));
|
|
1233
|
+
});
|
|
1234
|
+
},
|
|
1235
|
+
async creator(o, a) {
|
|
1236
|
+
const q = String(a.pos[1] ?? '').trim();
|
|
1237
|
+
if (!q)
|
|
1238
|
+
throw new UsageError('usage: oculon creator <token address> [--chain eth|arbitrum|polygon]');
|
|
1239
|
+
await checked(o, a, 'creator', q, () => o.creatorCheck(q, chainOpt(a)), (d) => {
|
|
1240
|
+
out(c.dim(` creator ${d.deployer ?? 'not found'}${d.createdAt ? ` · created ${d.createdAt.slice(0, 10)}` : ''}${d.fundedBy ? ` · first funded by ${d.fundedBy.label ?? d.fundedBy.address}` : ''}`));
|
|
1241
|
+
for (const x of d.deployments.filter((y) => y.isToken).slice(0, 20))
|
|
1242
|
+
out((x.dead ? c.red : c.green)(` ${(x.symbol ?? '?').padEnd(12)} ${x.address} ${x.createdAt.slice(0, 10)} ${x.liquidityUsd === null ? 'no pool' : '$' + Math.round(x.liquidityUsd).toLocaleString('en-US')}${x.dead ? ' dead' : ''}`));
|
|
1243
|
+
for (const n of d.notes)
|
|
1244
|
+
out(c.dim(` ${n}`));
|
|
1245
|
+
});
|
|
1246
|
+
},
|
|
1247
|
+
async eml(o, a) {
|
|
1248
|
+
const file = a.pos.slice(1).join(' ').trim();
|
|
1249
|
+
if (!file)
|
|
1250
|
+
throw new UsageError('usage: oculon eml <message.eml> a whole email: headers, message, links and attachments');
|
|
1251
|
+
if (!existsSync(file))
|
|
1252
|
+
throw new UsageError(`no such file: ${file}`);
|
|
1253
|
+
const bytes = readFileSync(file);
|
|
1254
|
+
const { createHash } = await import('node:crypto');
|
|
1255
|
+
const name = file.split(/[\\/]/).pop();
|
|
1256
|
+
await checked(o, a, 'eml', createHash('sha256').update(bytes).digest('hex'), () => o.emlCheck(bytes, name), (d) => {
|
|
1257
|
+
out(c.dim(` ${d.from ?? '?'} · "${d.subject ?? ''}" · ${d.date ?? ''}`));
|
|
1258
|
+
if (d.headers)
|
|
1259
|
+
out(` headers ${d.headers.verdict ?? '?'}`);
|
|
1260
|
+
if (d.body)
|
|
1261
|
+
out(` message ${d.body.verdict ?? '?'} · ${d.body.links} links`);
|
|
1262
|
+
for (const x of d.attachments)
|
|
1263
|
+
out((x.tone === 'bad' ? c.red : x.tone === 'warn' ? c.yellow : c.dim)(` attachment ${x.name} (${x.check}): ${x.verdict ?? 'checked'}${x.points[0] ? ' · ' + x.points[0] : ''}`));
|
|
1264
|
+
}, name);
|
|
1265
|
+
},
|
|
1266
|
+
async apk(o, a) {
|
|
1267
|
+
const file = a.pos.slice(1).join(' ').trim();
|
|
1268
|
+
if (!file)
|
|
1269
|
+
throw new UsageError('usage: oculon apk <app.apk> is this Android app safe to install?');
|
|
1270
|
+
if (!existsSync(file))
|
|
1271
|
+
throw new UsageError(`no such file: ${file}`);
|
|
1272
|
+
const bytes = readFileSync(file);
|
|
1273
|
+
const { createHash } = await import('node:crypto');
|
|
1274
|
+
const name = file.split(/[\\/]/).pop();
|
|
1275
|
+
await checked(o, a, 'apk', createHash('sha256').update(bytes).digest('hex'), () => o.apkCheck(bytes, name), (d) => {
|
|
1276
|
+
out(c.dim(` ${d.package ?? '?'} ${d.version ?? ''} · SDK ${d.minSdk ?? '?'}-${d.targetSdk ?? '?'} · ${d.permissions.length} permissions · signed by ${d.signer.join(', ') || 'unknown'}`));
|
|
1277
|
+
for (const r of d.risky)
|
|
1278
|
+
out(c.yellow(` ${r.permission}: ${r.why}`));
|
|
1279
|
+
}, name);
|
|
1280
|
+
},
|
|
1281
|
+
async job(o, a) {
|
|
1282
|
+
let raw = a.pos.slice(1).join(' ').trim();
|
|
1283
|
+
if (raw && existsSync(raw))
|
|
1284
|
+
raw = readFileSync(raw, 'utf8');
|
|
1285
|
+
if (!raw && !process.stdin.isTTY)
|
|
1286
|
+
raw = readFileSync(0, 'utf8');
|
|
1287
|
+
if (!raw)
|
|
1288
|
+
throw new UsageError('usage: oculon job "<the job message>" (or a file, or pipe it in)');
|
|
1289
|
+
await checked(o, a, 'job', raw, () => o.jobCheck(raw), (d) => {
|
|
1290
|
+
for (const p of d.patterns)
|
|
1291
|
+
out(c.dim(` ${p.name}: "${p.evidence}"`));
|
|
1292
|
+
if (d.repo)
|
|
1293
|
+
out(c.dim(` repo ${d.repo.repo}: ${d.repo.verdict}`));
|
|
1294
|
+
}, `job offer: ${raw.slice(0, 60)}`);
|
|
1295
|
+
},
|
|
1296
|
+
async where(o, a) {
|
|
1297
|
+
const file = a.pos.slice(1).join(' ').trim();
|
|
1298
|
+
if (!file)
|
|
1299
|
+
throw new UsageError('usage: oculon where <photo.jpg> where and when a photo was taken, and the weather then');
|
|
1300
|
+
if (!existsSync(file))
|
|
1301
|
+
throw new UsageError(`no such file: ${file}`);
|
|
1302
|
+
const bytes = readFileSync(file);
|
|
1303
|
+
const { createHash } = await import('node:crypto');
|
|
1304
|
+
const name = file.split(/[\\/]/).pop();
|
|
1305
|
+
await checked(o, a, 'where', createHash('sha256').update(bytes).digest('hex'), () => o.whereCheck(bytes, name), (d) => {
|
|
1306
|
+
if (d.gps)
|
|
1307
|
+
out(` ${d.gps.lat}, ${d.gps.lon} ${d.gps.map}`);
|
|
1308
|
+
if (d.taken)
|
|
1309
|
+
out(c.dim(` taken ${d.taken.local ?? '?'} local${d.taken.gpsUtc ? ` · GPS time ${d.taken.gpsUtc}` : ''}${d.camera ? ` · ${d.camera}` : ''}`));
|
|
1310
|
+
for (const n of d.notes)
|
|
1311
|
+
out(c.dim(` ${n}`));
|
|
1312
|
+
}, name);
|
|
1313
|
+
},
|
|
1314
|
+
async archive(o, a) {
|
|
1315
|
+
const q = String(a.pos[1] ?? '').trim();
|
|
1316
|
+
if (!q)
|
|
1317
|
+
throw new UsageError('usage: oculon archive <link> save a page as evidence (Wayback Machine, hash)');
|
|
1318
|
+
await checked(o, a, 'archive', q, () => o.archivePage(q), (d) => {
|
|
1319
|
+
if (d.snapshot)
|
|
1320
|
+
out(` snapshot ${d.snapshot}`);
|
|
1321
|
+
if (d.page)
|
|
1322
|
+
out(c.dim(` sha256 ${d.page.sha256} · HTTP ${d.page.status} · ${d.page.finalUrl}`));
|
|
1323
|
+
});
|
|
1324
|
+
},
|
|
1325
|
+
async invite(o, a) {
|
|
1326
|
+
const q = String(a.pos[1] ?? '').trim();
|
|
1327
|
+
if (!q)
|
|
1328
|
+
throw new UsageError('usage: oculon invite <t.me/... or discord.gg/... link>');
|
|
1329
|
+
await checked(o, a, 'invite', q, () => o.inviteCheck(q), (d) => {
|
|
1330
|
+
out(c.dim(` ${d.platform} ${d.kind ?? ''} "${d.name ?? '?'}" · ${d.members ?? '?'} members${d.online != null ? `, ${d.online} online` : ''}${d.verified ? ' · verified' : ''}${d.createdAt ? ` · created ${d.createdAt.slice(0, 10)}` : ''}`));
|
|
1331
|
+
});
|
|
1332
|
+
},
|
|
1333
|
+
async stocktoken(o, a) {
|
|
1334
|
+
const q = a.pos.slice(1).join(' ').trim();
|
|
1335
|
+
await checked(o, a, 'stocktoken', q || 'overview', () => o.stockToken(q), (d) => {
|
|
1336
|
+
if (d.symbol && d.contract)
|
|
1337
|
+
out(c.dim(` ${d.name ?? d.symbol} · ISIN ${d.isin ?? '?'} · ${d.contract} (${d.chain ?? '?'}) · ${d.status ?? ''}`));
|
|
1338
|
+
if (d.price)
|
|
1339
|
+
out(` bid $${d.price.tokenBid?.toFixed(2) ?? '?'} / ask $${d.price.tokenAsk?.toFixed(2) ?? '?'} · day $${d.price.dailyLow ?? '?'}-$${d.price.dailyHigh ?? '?'}${d.price.halted ? c.red(' · HALTED') : ''}`);
|
|
1340
|
+
if (Object.keys(d.sessions).length)
|
|
1341
|
+
out(c.dim(` sessions: ${Object.entries(d.sessions).map(([k, v]) => `${k} ${v}`).join(' · ')}${d.supply !== null ? ` · supply ${d.supply.toLocaleString('en-US')} tokens` : ''}`));
|
|
1342
|
+
for (const x of d.corporateActions.slice(0, 8))
|
|
1343
|
+
out(c.dim(` ${x.date ?? '?'} ${x.symbol.padEnd(6)} ${x.type}${x.detail ? ` (${x.detail})` : ''} · ${x.status}`));
|
|
1344
|
+
}, q ? `stock token ${q}` : 'Robinhood Stock Tokens');
|
|
1345
|
+
},
|
|
949
1346
|
async honeypot(o, a) {
|
|
950
1347
|
const q = String(a.pos[1] ?? '').trim();
|
|
951
1348
|
if (!q)
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Store } from './store.js';
|
|
2
|
+
import type { Status } from './types.js';
|
|
3
|
+
export interface CallEntry {
|
|
4
|
+
source: string;
|
|
5
|
+
/** Host only; full URLs can carry query text the user typed. */
|
|
6
|
+
host: string;
|
|
7
|
+
status: Status;
|
|
8
|
+
/** Wall time of the request, 0 for cache hits. */
|
|
9
|
+
ms: number;
|
|
10
|
+
at: string;
|
|
11
|
+
note?: string;
|
|
12
|
+
/** Answered by a mirror after the primary host failed or was skipped. */
|
|
13
|
+
via?: string;
|
|
14
|
+
}
|
|
15
|
+
/** Run `fn` and collect every source call it makes, including calls made by modules it calls. */
|
|
16
|
+
export declare function withCallLog<T>(fn: () => Promise<T>): Promise<{
|
|
17
|
+
value: T;
|
|
18
|
+
calls: CallEntry[];
|
|
19
|
+
}>;
|
|
20
|
+
export declare function logCall(e: CallEntry): void;
|
|
21
|
+
/** One live fetch (not cache hits). Rows older than two days are pruned now and then. */
|
|
22
|
+
export declare function recordSourceCall(store: Store, source: string, host: string, ok: boolean, ms: number, note?: string): void;
|
|
23
|
+
export type SourceState = 'up' | 'slow' | 'down' | 'degraded';
|
|
24
|
+
export interface SourceStatus {
|
|
25
|
+
source: string;
|
|
26
|
+
hosts: string[];
|
|
27
|
+
state: SourceState;
|
|
28
|
+
calls: number;
|
|
29
|
+
failed: number;
|
|
30
|
+
/** Share of calls that worked, 0-100. */
|
|
31
|
+
okPct: number;
|
|
32
|
+
medianMs: number | null;
|
|
33
|
+
lastOk: string | null;
|
|
34
|
+
lastError: {
|
|
35
|
+
at: string;
|
|
36
|
+
note: string;
|
|
37
|
+
} | null;
|
|
38
|
+
/** Skipped right now because it kept failing; a mirror or cached data answers instead. */
|
|
39
|
+
skippedUntil: string | null;
|
|
40
|
+
}
|
|
41
|
+
/** Every source that made a live call in the last `hours`, worst first. */
|
|
42
|
+
export declare function sourceStatus(store: Store, hours?: number, now?: number): SourceStatus[];
|
|
43
|
+
/** Failures in a row before a host is skipped, and for how long. */
|
|
44
|
+
export declare const BREAKER: {
|
|
45
|
+
failures: number;
|
|
46
|
+
skipMs: number;
|
|
47
|
+
};
|
|
48
|
+
export declare function breakerOpenUntil(host: string, now?: number): number | null;
|
|
49
|
+
export declare function breakerResult(host: string, ok: boolean, now?: number): void;
|
|
50
|
+
export declare function resetBreakers(): void;
|
|
51
|
+
export interface Mirror {
|
|
52
|
+
host: string;
|
|
53
|
+
/** Same request on the mirror, or null when this URL has no equivalent there. */
|
|
54
|
+
rewrite: (u: URL) => {
|
|
55
|
+
url: string;
|
|
56
|
+
headers?: Record<string, string>;
|
|
57
|
+
} | null;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Hosts with a drop-in equivalent: same query, same JSON shape. Used when the primary fails after its retries
|
|
61
|
+
* or is being skipped. Sources with a different shape keep their own fallbacks in their modules.
|
|
62
|
+
*/
|
|
63
|
+
export declare const MIRRORS: Record<string, Mirror>;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What happened on the wire, for three features that share one hook in Http:
|
|
3
|
+
* - replay log: every source call made while a check runs (AsyncLocalStorage ties calls to that check);
|
|
4
|
+
* - /status: per-source success, failures and latency over the last day, from every live fetch;
|
|
5
|
+
* - auto fallback: a host that keeps failing is skipped for a few minutes (cached data or a mirror answers instead).
|
|
6
|
+
* No dependencies: node:async_hooks and the install's own SQLite database.
|
|
7
|
+
*/
|
|
8
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
9
|
+
const log = new AsyncLocalStorage();
|
|
10
|
+
/** Run `fn` and collect every source call it makes, including calls made by modules it calls. */
|
|
11
|
+
export async function withCallLog(fn) {
|
|
12
|
+
const calls = [];
|
|
13
|
+
const value = await log.run(calls, fn);
|
|
14
|
+
return { value, calls };
|
|
15
|
+
}
|
|
16
|
+
export function logCall(e) {
|
|
17
|
+
const calls = log.getStore();
|
|
18
|
+
if (calls && calls.length < 2000)
|
|
19
|
+
calls.push(e);
|
|
20
|
+
}
|
|
21
|
+
/* ---------- source stats for /status ---------- */
|
|
22
|
+
const ensured = new WeakSet();
|
|
23
|
+
function ensure(store) {
|
|
24
|
+
if (ensured.has(store))
|
|
25
|
+
return;
|
|
26
|
+
store.db.exec(`CREATE TABLE IF NOT EXISTS source_calls (source TEXT NOT NULL, host TEXT NOT NULL, at INTEGER NOT NULL, ok INTEGER NOT NULL, ms INTEGER NOT NULL, note TEXT);
|
|
27
|
+
CREATE INDEX IF NOT EXISTS source_calls_at ON source_calls (at);`);
|
|
28
|
+
ensured.add(store);
|
|
29
|
+
}
|
|
30
|
+
let inserts = 0;
|
|
31
|
+
/** One live fetch (not cache hits). Rows older than two days are pruned now and then. */
|
|
32
|
+
export function recordSourceCall(store, source, host, ok, ms, note) {
|
|
33
|
+
try {
|
|
34
|
+
ensure(store);
|
|
35
|
+
const now = Date.now();
|
|
36
|
+
store.db.prepare('INSERT INTO source_calls (source, host, at, ok, ms, note) VALUES (?, ?, ?, ?, ?, ?)').run(source, host, now, ok ? 1 : 0, Math.round(ms), note ? note.slice(0, 200) : null);
|
|
37
|
+
if (++inserts % 500 === 0)
|
|
38
|
+
store.db.prepare('DELETE FROM source_calls WHERE at < ?').run(now - 2 * 86_400_000);
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
// Stats are best effort: a read-only or closed database must never break a check.
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const median = (xs) => {
|
|
45
|
+
if (!xs.length)
|
|
46
|
+
return null;
|
|
47
|
+
const s = [...xs].sort((a, b) => a - b);
|
|
48
|
+
return s[Math.floor(s.length / 2)];
|
|
49
|
+
};
|
|
50
|
+
/** Every source that made a live call in the last `hours`, worst first. */
|
|
51
|
+
export function sourceStatus(store, hours = 24, now = Date.now()) {
|
|
52
|
+
ensure(store);
|
|
53
|
+
const rows = store.db.prepare('SELECT source, host, at, ok, ms, note FROM source_calls WHERE at >= ? ORDER BY at ASC').all(now - hours * 3_600_000);
|
|
54
|
+
const by = new Map();
|
|
55
|
+
for (const r of rows)
|
|
56
|
+
(by.get(r.source) ?? by.set(r.source, []).get(r.source)).push(r);
|
|
57
|
+
const out = [];
|
|
58
|
+
for (const [source, rs] of by) {
|
|
59
|
+
const failed = rs.filter((r) => !r.ok);
|
|
60
|
+
const okRows = rs.filter((r) => r.ok);
|
|
61
|
+
const recent = rs.slice(-5);
|
|
62
|
+
const med = median(okRows.map((r) => r.ms));
|
|
63
|
+
const lastErr = failed[failed.length - 1];
|
|
64
|
+
const lastOk = okRows[okRows.length - 1];
|
|
65
|
+
const hosts = [...new Set(rs.map((r) => r.host))];
|
|
66
|
+
const skipped = hosts.map((h) => breakerOpenUntil(h, now)).filter((x) => x !== null);
|
|
67
|
+
const recentFail = recent.filter((r) => !r.ok).length;
|
|
68
|
+
const state = skipped.length || (recent.length >= 2 && recentFail === recent.length) ? 'down' : recentFail ? 'degraded' : med !== null && med > 5000 ? 'slow' : 'up';
|
|
69
|
+
out.push({
|
|
70
|
+
source,
|
|
71
|
+
hosts,
|
|
72
|
+
state,
|
|
73
|
+
calls: rs.length,
|
|
74
|
+
failed: failed.length,
|
|
75
|
+
okPct: Math.round((okRows.length / rs.length) * 100),
|
|
76
|
+
medianMs: med,
|
|
77
|
+
lastOk: lastOk ? new Date(lastOk.at).toISOString() : null,
|
|
78
|
+
lastError: lastErr ? { at: new Date(lastErr.at).toISOString(), note: lastErr.note ?? 'failed' } : null,
|
|
79
|
+
skippedUntil: skipped.length ? new Date(Math.max(...skipped)).toISOString() : null,
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const rank = { down: 0, degraded: 1, slow: 2, up: 3 };
|
|
83
|
+
return out.sort((a, b) => rank[a.state] - rank[b.state] || b.calls - a.calls);
|
|
84
|
+
}
|
|
85
|
+
/* ---------- breaker: skip a host that keeps failing ---------- */
|
|
86
|
+
/** Failures in a row before a host is skipped, and for how long. */
|
|
87
|
+
export const BREAKER = { failures: 3, skipMs: 5 * 60_000 };
|
|
88
|
+
const breakers = new Map();
|
|
89
|
+
export function breakerOpenUntil(host, now = Date.now()) {
|
|
90
|
+
const b = breakers.get(host);
|
|
91
|
+
return b && b.openUntil > now ? b.openUntil : null;
|
|
92
|
+
}
|
|
93
|
+
export function breakerResult(host, ok, now = Date.now()) {
|
|
94
|
+
if (ok) {
|
|
95
|
+
breakers.delete(host);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
const b = breakers.get(host) ?? { fails: 0, openUntil: 0 };
|
|
99
|
+
b.fails++;
|
|
100
|
+
if (b.fails >= BREAKER.failures) {
|
|
101
|
+
b.openUntil = now + BREAKER.skipMs;
|
|
102
|
+
b.fails = 0;
|
|
103
|
+
}
|
|
104
|
+
breakers.set(host, b);
|
|
105
|
+
}
|
|
106
|
+
export function resetBreakers() {
|
|
107
|
+
breakers.clear();
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Hosts with a drop-in equivalent: same query, same JSON shape. Used when the primary fails after its retries
|
|
111
|
+
* or is being skipped. Sources with a different shape keep their own fallbacks in their modules.
|
|
112
|
+
*/
|
|
113
|
+
export const MIRRORS = {
|
|
114
|
+
// Google and Cloudflare DNS-over-HTTPS share the JSON format (RFC 8484 JSON flavour).
|
|
115
|
+
'dns.google': { host: 'cloudflare-dns.com', rewrite: (u) => (u.pathname === '/resolve' ? { url: `https://cloudflare-dns.com/dns-query${u.search}`, headers: { accept: 'application/dns-json' } } : null) },
|
|
116
|
+
'cloudflare-dns.com': { host: 'dns.google', rewrite: (u) => (u.pathname === '/dns-query' ? { url: `https://dns.google/resolve${u.search}` } : null) },
|
|
117
|
+
// mempool.space and Blockstream both run the Esplora API.
|
|
118
|
+
'mempool.space': { host: 'blockstream.info', rewrite: (u) => (u.pathname.startsWith('/api/') ? { url: `https://blockstream.info${u.pathname}${u.search}` } : null) },
|
|
119
|
+
'blockstream.info': { host: 'mempool.space', rewrite: (u) => (u.pathname.startsWith('/api/') ? { url: `https://mempool.space${u.pathname}${u.search}` } : null) },
|
|
120
|
+
};
|
package/dist/core/der.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Organization and common names found in DER certificates (OIDs 2.5.4.10 and 2.5.4.3), without parsing ASN.1 fully. */
|
|
2
|
+
export function certNames(buf, skip = /timestamp|time ?stamping|\broot\b|intermediate|trusted g4|assured id|^ca$/i) {
|
|
3
|
+
const out = new Set();
|
|
4
|
+
for (const oid of [Buffer.from([0x06, 0x03, 0x55, 0x04, 0x0a]), Buffer.from([0x06, 0x03, 0x55, 0x04, 0x03])]) {
|
|
5
|
+
let at = buf.indexOf(oid);
|
|
6
|
+
while (at >= 0 && out.size < 12) {
|
|
7
|
+
const tag = buf[at + 5], len = buf[at + 6];
|
|
8
|
+
if ([0x0c, 0x13, 0x14, 0x16].includes(tag) && len > 1 && len < 80) {
|
|
9
|
+
const s = buf.toString('utf8', at + 7, at + 7 + len).trim();
|
|
10
|
+
if (/^[\x20-\x7e]+$/.test(s) && !skip.test(s))
|
|
11
|
+
out.add(s);
|
|
12
|
+
}
|
|
13
|
+
at = buf.indexOf(oid, at + 1);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return [...out];
|
|
17
|
+
}
|