oculon 0.1.4 → 0.1.6
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 +75 -5
- package/dist/cli/main.js +297 -0
- package/dist/core/evm.d.ts +20 -0
- package/dist/core/evm.js +165 -0
- package/dist/core/http.js +7 -0
- package/dist/core/quota.js +23 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +68 -0
- package/dist/mcp.js +81 -2
- package/dist/modules/address.d.ts +32 -0
- package/dist/modules/address.js +91 -0
- package/dist/modules/breach.d.ts +53 -0
- package/dist/modules/breach.js +98 -0
- package/dist/modules/company.d.ts +53 -0
- package/dist/modules/company.js +149 -0
- package/dist/modules/hashcheck.d.ts +29 -0
- package/dist/modules/hashcheck.js +82 -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/ipintel.d.ts +52 -0
- package/dist/modules/ipintel.js +149 -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/phone.d.ts +32 -0
- package/dist/modules/phone.js +148 -0
- package/dist/modules/ransomware.d.ts +56 -0
- package/dist/modules/ransomware.js +85 -0
- package/dist/modules/satellites.d.ts +45 -0
- package/dist/modules/satellites.js +113 -0
- package/dist/modules/utility.d.ts +121 -0
- package/dist/modules/utility.js +306 -0
- package/dist/sources/threatintel.d.ts +151 -0
- package/dist/sources/threatintel.js +256 -0
- package/dist/telegram.d.ts +2 -0
- package/dist/telegram.js +93 -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/index.html +70 -3
- package/dist/web/insights.js +2 -0
- 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 +11 -0
- package/dist/web/public.js +13 -1
- package/dist/web/server.d.ts +17 -0
- package/dist/web/server.js +161 -4
- package/dist/web/token.html +97 -0
- package/dist/web/token.json +9 -0
- package/dist/web/utility.html +225 -0
- package/package.json +2 -2
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* $OCULON utility, read straight from Robinhood Chain: nothing is custodied, nothing is paid to anyone.
|
|
3
|
+
* A. Burn-to-Investigate: burn 1,500,000 OCULON, get a deep investigation of one domain, wallet, token or
|
|
4
|
+
* company, published as a public page that links the burn transaction.
|
|
5
|
+
* B. Live Safety Badge: burn 2,000,000 OCULON, and Oculon watches one Robinhood Chain token for 30 days.
|
|
6
|
+
* The badge shows the live verdict. Burning buys monitoring, never a better verdict.
|
|
7
|
+
* C. Holder tier: sign a message with a wallet that holds 3,500,000 OCULON (no account, no email) and get
|
|
8
|
+
* more personal monitors, checked every 15 minutes instead of every hour.
|
|
9
|
+
* A burn is a transfer of OCULON to the dead or zero address, confirmed on chain; each transaction counts once.
|
|
10
|
+
*/
|
|
11
|
+
import { randomBytes } from 'node:crypto';
|
|
12
|
+
import { readFileSync } from 'node:fs';
|
|
13
|
+
import { dirname, join } from 'node:path';
|
|
14
|
+
import { fileURLToPath } from 'node:url';
|
|
15
|
+
import { recoverPersonalSigner } from '../core/evm.js';
|
|
16
|
+
import { formatUnits, rpcClient } from '../web/burns.js';
|
|
17
|
+
export const UTILITY = { investigate: 1500000n, safety: 2000000n, holder: 3500000n, safetyDays: 30, holderMonitors: 30, sessionDays: 7 };
|
|
18
|
+
/** Burns before the utility went live (buyback burns, for example) do not count. */
|
|
19
|
+
export const UTILITY_START = Date.parse('2026-11-26T00:00:00Z');
|
|
20
|
+
/** What the burning wallet signs, so only the wallet that burned can spend its burn. */
|
|
21
|
+
export function utilityMessage(kind, target, tx) {
|
|
22
|
+
return `Oculon ${kind === 'investigate' ? 'investigation' : 'safety badge'}\nTarget: ${target.trim()}\nBurn: ${tx.trim().toLowerCase()}`;
|
|
23
|
+
}
|
|
24
|
+
function checkSigner(kind, target, burn, signature) {
|
|
25
|
+
const signer = recoverPersonalSigner(utilityMessage(kind, target, burn.tx), signature);
|
|
26
|
+
if (!signer)
|
|
27
|
+
throw new Error('sign the request with the wallet that made the burn');
|
|
28
|
+
if (signer !== burn.from)
|
|
29
|
+
throw new Error('the signature is not from the wallet that made this burn');
|
|
30
|
+
}
|
|
31
|
+
const E18 = 10n ** 18n;
|
|
32
|
+
const TRANSFER = '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef';
|
|
33
|
+
const BURN_TO = new Set(['0x000000000000000000000000000000000000dead', '0x0000000000000000000000000000000000000000']);
|
|
34
|
+
const DEFAULT_RPC = 'https://rpc.mainnet.chain.robinhood.com';
|
|
35
|
+
export function tokenConfig() {
|
|
36
|
+
try {
|
|
37
|
+
const t = JSON.parse(readFileSync(join(dirname(fileURLToPath(import.meta.url)), '..', 'web', 'token.json'), 'utf8'));
|
|
38
|
+
return t.ca && /^0x[0-9a-fA-F]{40}$/.test(t.ca) ? { ca: t.ca.toLowerCase(), txBase: t.txBase ?? null } : null;
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
let rpcOverride = null;
|
|
45
|
+
/** Tests replace the chain with a stub. */
|
|
46
|
+
export function setUtilityRpc(r) { rpcOverride = r; }
|
|
47
|
+
const rpc = () => rpcOverride ?? rpcClient(process.env.ROBINHOOD_PUBLIC_RPC_URL?.trim() || DEFAULT_RPC);
|
|
48
|
+
function db(ctx) {
|
|
49
|
+
const d = ctx.store.db;
|
|
50
|
+
d.exec(`CREATE TABLE IF NOT EXISTS utility_burns (tx TEXT PRIMARY KEY, kind TEXT NOT NULL, target TEXT NOT NULL, from_addr TEXT NOT NULL, amount TEXT NOT NULL, block INTEGER, burned_at TEXT, created_at INTEGER NOT NULL);
|
|
51
|
+
CREATE TABLE IF NOT EXISTS investigations (id TEXT PRIMARY KEY, tx TEXT NOT NULL, target TEXT NOT NULL, status TEXT NOT NULL, result TEXT, created_at INTEGER NOT NULL, finished_at INTEGER);
|
|
52
|
+
CREATE TABLE IF NOT EXISTS safety_monitors (token TEXT PRIMARY KEY, expires_at INTEGER NOT NULL, created_at INTEGER NOT NULL, last_check INTEGER, verdict TEXT, reasons TEXT, name TEXT, symbol TEXT);
|
|
53
|
+
CREATE TABLE IF NOT EXISTS safety_checks (token TEXT NOT NULL, at INTEGER NOT NULL, verdict TEXT NOT NULL, reasons TEXT NOT NULL);
|
|
54
|
+
CREATE TABLE IF NOT EXISTS holder_sessions (key TEXT PRIMARY KEY, owner TEXT NOT NULL, address TEXT NOT NULL, balance TEXT NOT NULL, expires_at INTEGER NOT NULL, created_at INTEGER NOT NULL);`);
|
|
55
|
+
return d;
|
|
56
|
+
}
|
|
57
|
+
/** Confirms that `tx` burned at least `min` whole OCULON and has not been used before. Throws a readable error otherwise. */
|
|
58
|
+
export async function verifyBurn(ctx, txInput, min) {
|
|
59
|
+
const tx = txInput.trim().toLowerCase();
|
|
60
|
+
if (!/^0x[0-9a-f]{64}$/.test(tx))
|
|
61
|
+
throw new Error('give the burn transaction hash: 0x followed by 64 hex characters');
|
|
62
|
+
const cfg = tokenConfig();
|
|
63
|
+
if (!cfg)
|
|
64
|
+
throw new Error('the official token address is not configured on this install');
|
|
65
|
+
const used = db(ctx).prepare('SELECT kind FROM utility_burns WHERE tx = ?').get(tx);
|
|
66
|
+
if (used)
|
|
67
|
+
throw new Error(`this burn was already used for ${used.kind === 'investigate' ? 'an investigation' : used.kind === 'safety' ? 'a safety badge' : used.kind}`);
|
|
68
|
+
const r = rpc();
|
|
69
|
+
const receipt = await r('eth_getTransactionReceipt', [tx]);
|
|
70
|
+
if (!receipt)
|
|
71
|
+
throw new Error('transaction not found yet: wait until it is confirmed, then try again');
|
|
72
|
+
if (receipt.status !== '0x1')
|
|
73
|
+
throw new Error('this transaction failed on chain, so nothing was burned');
|
|
74
|
+
let raw = 0n;
|
|
75
|
+
let from = receipt.from.toLowerCase();
|
|
76
|
+
for (const l of receipt.logs) {
|
|
77
|
+
if (l.address.toLowerCase() !== cfg.ca || l.topics[0] !== TRANSFER || l.topics.length < 3)
|
|
78
|
+
continue;
|
|
79
|
+
const to = `0x${l.topics[2].slice(26)}`.toLowerCase();
|
|
80
|
+
if (!BURN_TO.has(to))
|
|
81
|
+
continue;
|
|
82
|
+
raw += BigInt(l.data);
|
|
83
|
+
from = `0x${l.topics[1].slice(26)}`.toLowerCase();
|
|
84
|
+
}
|
|
85
|
+
if (raw === 0n)
|
|
86
|
+
throw new Error('no OCULON was sent to the burn address in this transaction');
|
|
87
|
+
if (raw < min * E18)
|
|
88
|
+
throw new Error(`this burn is ${formatUnits(raw, 18)} OCULON; it needs at least ${min.toLocaleString('en-US')}`);
|
|
89
|
+
const blk = await r('eth_getBlockByNumber', [receipt.blockNumber, false]);
|
|
90
|
+
if (Number(BigInt(blk.timestamp)) * 1000 < UTILITY_START)
|
|
91
|
+
throw new Error('this burn happened before the utility went live, so it cannot be used');
|
|
92
|
+
return { tx, from, amount: formatUnits(raw, 18), raw: raw.toString(), block: Number(BigInt(receipt.blockNumber)), time: new Date(Number(BigInt(blk.timestamp)) * 1000).toISOString() };
|
|
93
|
+
}
|
|
94
|
+
function recordBurn(ctx, kind, target, b) {
|
|
95
|
+
db(ctx).prepare('INSERT INTO utility_burns (tx, kind, target, from_addr, amount, block, burned_at, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)').run(b.tx, kind, target, b.from, b.amount, b.block, b.time, ctx.now().getTime());
|
|
96
|
+
}
|
|
97
|
+
export function targetKind(t) {
|
|
98
|
+
if (/^0x[0-9a-fA-F]{40}$/.test(t))
|
|
99
|
+
return 'evm';
|
|
100
|
+
if (/^(bc1|[13])[a-zA-HJ-NP-Z0-9]{25,62}$/.test(t) || /^T[1-9A-HJ-NP-Za-km-z]{33}$/.test(t) || /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(t))
|
|
101
|
+
return 'crypto';
|
|
102
|
+
if (/^(https?:\/\/)?([a-z0-9-]+\.)+[a-z]{2,}(\/.*)?$/i.test(t))
|
|
103
|
+
return 'domain';
|
|
104
|
+
return 'name';
|
|
105
|
+
}
|
|
106
|
+
/** A few readable lines out of any module result: its verdict, then its reasons, warnings or flags. */
|
|
107
|
+
export function summarize(title, r) {
|
|
108
|
+
const x = r.result;
|
|
109
|
+
const verdict = ['verdict', 'risk'].map((k) => x?.[k]).find((v) => typeof v === 'string' || typeof v === 'number');
|
|
110
|
+
const lines = [];
|
|
111
|
+
for (const k of ['reasons', 'warnings', 'flags', 'problems', 'fixes']) {
|
|
112
|
+
const v = x?.[k];
|
|
113
|
+
if (Array.isArray(v))
|
|
114
|
+
lines.push(...v.filter((s) => typeof s === 'string').slice(0, 8));
|
|
115
|
+
}
|
|
116
|
+
if (Array.isArray(x?.live))
|
|
117
|
+
lines.push(...x.live.slice(0, 12).map((l) => `lookalike live: ${l.domain} (${l.kind})`));
|
|
118
|
+
if (Array.isArray(x?.breaches))
|
|
119
|
+
lines.push(...x.breaches.slice(0, 6).map((b) => `breach: ${b.title}, ${b.accounts.toLocaleString('en-US')} accounts, ${b.breachDate}`));
|
|
120
|
+
if (Array.isArray(x?.victims))
|
|
121
|
+
lines.push(...x.victims.slice(0, 6).map((v) => `ransomware claim: ${v.group} lists ${v.victim}${v.discovered ? ` (${v.discovered.slice(0, 10)})` : ''}`));
|
|
122
|
+
if (typeof x?.score === 'number' && !verdict)
|
|
123
|
+
lines.unshift(`score ${x.score}`);
|
|
124
|
+
return { title, ok: true, verdict: verdict === undefined ? null : String(verdict), lines: lines.slice(0, 16), sources: r.provenance.map((p) => `${p.source} ${p.status.toLowerCase()}`) };
|
|
125
|
+
}
|
|
126
|
+
async function part(title, f) {
|
|
127
|
+
try {
|
|
128
|
+
return summarize(title, await f());
|
|
129
|
+
}
|
|
130
|
+
catch (e) {
|
|
131
|
+
return { title, ok: false, verdict: null, lines: [], error: e.message.slice(0, 200), sources: [] };
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
export async function runInvestigation(o, target) {
|
|
135
|
+
const kind = targetKind(target);
|
|
136
|
+
if (kind === 'evm') {
|
|
137
|
+
return Promise.all([
|
|
138
|
+
part('Robinhood Chain token', () => o.robinhoodToken(target)),
|
|
139
|
+
part('Deployer history', () => o.robinhoodDeployer(target)),
|
|
140
|
+
part('Address on Robinhood Chain', () => o.addressCheck(target, { network: 'robinhood' })),
|
|
141
|
+
part('Address on Ethereum', () => o.addressCheck(target)),
|
|
142
|
+
]);
|
|
143
|
+
}
|
|
144
|
+
if (kind === 'crypto')
|
|
145
|
+
return Promise.all([part('Address', () => o.addressCheck(target))]);
|
|
146
|
+
if (kind === 'domain') {
|
|
147
|
+
const d = target.replace(/^https?:\/\//, '').replace(/\/.*$/, '').toLowerCase();
|
|
148
|
+
return Promise.all([
|
|
149
|
+
part('Link safety', () => o.urlCheck(`https://${d}`)),
|
|
150
|
+
part('Lookalike domains', () => o.lookalikes(d)),
|
|
151
|
+
part('Email spoofing protection', () => o.emailSecurity(d)),
|
|
152
|
+
part('Data breaches', () => o.breaches(d)),
|
|
153
|
+
part('Ransomware claims', () => o.ransomware(d.split('.')[0].length >= 3 ? d.split('.')[0] : d)),
|
|
154
|
+
]);
|
|
155
|
+
}
|
|
156
|
+
return Promise.all([
|
|
157
|
+
part('Company registers', () => o.companyCheck(target)),
|
|
158
|
+
part('Ransomware claims', () => o.ransomware(target)),
|
|
159
|
+
part('Scam patterns in the name', () => o.scamCheck(target)),
|
|
160
|
+
]);
|
|
161
|
+
}
|
|
162
|
+
export async function startInvestigation(o, tx, targetInput, signature) {
|
|
163
|
+
const target = targetInput.trim().slice(0, 200);
|
|
164
|
+
if (target.length < 3)
|
|
165
|
+
throw new Error('give what to investigate: a domain, a wallet or token address, or a company name');
|
|
166
|
+
const burn = await verifyBurn(o.ctx, tx, UTILITY.investigate);
|
|
167
|
+
checkSigner('investigate', target, burn, signature);
|
|
168
|
+
const id = randomBytes(6).toString('hex');
|
|
169
|
+
const d = db(o.ctx);
|
|
170
|
+
recordBurn(o.ctx, 'investigate', target, burn);
|
|
171
|
+
d.prepare('INSERT INTO investigations (id, tx, target, status, created_at) VALUES (?, ?, ?, ?, ?)').run(id, burn.tx, target, 'running', o.ctx.now().getTime());
|
|
172
|
+
void runInvestigation(o, target).then((parts) => {
|
|
173
|
+
d.prepare('UPDATE investigations SET status = ?, result = ?, finished_at = ? WHERE id = ?').run('done', JSON.stringify(parts), Date.now(), id);
|
|
174
|
+
}).catch((e) => {
|
|
175
|
+
d.prepare('UPDATE investigations SET status = ?, result = ?, finished_at = ? WHERE id = ?').run('done', JSON.stringify([{ title: 'Investigation', ok: false, verdict: null, lines: [], error: String(e.message), sources: [] }]), Date.now(), id);
|
|
176
|
+
});
|
|
177
|
+
return { id, burn };
|
|
178
|
+
}
|
|
179
|
+
export function getInvestigation(ctx, id) {
|
|
180
|
+
if (!/^[0-9a-f]{12}$/.test(id))
|
|
181
|
+
return null;
|
|
182
|
+
const row = db(ctx).prepare('SELECT i.*, b.from_addr, b.amount, b.raw, b.block, b.burned_at FROM investigations i LEFT JOIN (SELECT tx, from_addr, amount, amount AS raw, block, burned_at FROM utility_burns) b ON b.tx = i.tx WHERE i.id = ?').get(id);
|
|
183
|
+
if (!row)
|
|
184
|
+
return null;
|
|
185
|
+
return {
|
|
186
|
+
id, target: String(row.target), kind: targetKind(String(row.target)), status: row.status,
|
|
187
|
+
burn: row.from_addr ? { tx: String(row.tx), from: String(row.from_addr), amount: String(row.amount), raw: '', block: Number(row.block), time: String(row.burned_at) } : null,
|
|
188
|
+
parts: row.result ? JSON.parse(String(row.result)) : [],
|
|
189
|
+
createdAt: new Date(Number(row.created_at)).toISOString(), finishedAt: row.finished_at ? new Date(Number(row.finished_at)).toISOString() : null,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
export function listInvestigations(ctx, limit = 20) {
|
|
193
|
+
return db(ctx).prepare('SELECT id, target, status, created_at FROM investigations ORDER BY created_at DESC LIMIT ?').all(limit).map((r) => ({ id: r.id, target: r.target, status: r.status, createdAt: new Date(r.created_at).toISOString() }));
|
|
194
|
+
}
|
|
195
|
+
export async function checkSafety(o, token) {
|
|
196
|
+
const t = token.toLowerCase();
|
|
197
|
+
const r = await o.robinhoodToken(t);
|
|
198
|
+
const now = o.ctx.now().getTime();
|
|
199
|
+
const d = db(o.ctx);
|
|
200
|
+
d.prepare('UPDATE safety_monitors SET last_check = ?, verdict = ?, reasons = ?, name = ?, symbol = ? WHERE token = ?').run(now, r.result.verdict, JSON.stringify(r.result.reasons), r.result.name, r.result.symbol, t);
|
|
201
|
+
const last = d.prepare('SELECT verdict FROM safety_checks WHERE token = ? ORDER BY at DESC LIMIT 1').get(t);
|
|
202
|
+
if (!last || last.verdict !== r.result.verdict)
|
|
203
|
+
d.prepare('INSERT INTO safety_checks (token, at, verdict, reasons) VALUES (?, ?, ?, ?)').run(t, now, r.result.verdict, JSON.stringify(r.result.reasons));
|
|
204
|
+
return safetyState(o.ctx, t);
|
|
205
|
+
}
|
|
206
|
+
export async function startSafety(o, tx, tokenInput, signature) {
|
|
207
|
+
const token = tokenInput.trim().toLowerCase();
|
|
208
|
+
if (!/^0x[0-9a-f]{40}$/.test(token))
|
|
209
|
+
throw new Error('give the Robinhood Chain token address to monitor: 0x followed by 40 hex characters');
|
|
210
|
+
const burn = await verifyBurn(o.ctx, tx, UTILITY.safety);
|
|
211
|
+
checkSigner('safety', token, burn, signature);
|
|
212
|
+
const d = db(o.ctx);
|
|
213
|
+
const now = o.ctx.now().getTime();
|
|
214
|
+
const cur = d.prepare('SELECT expires_at FROM safety_monitors WHERE token = ?').get(token);
|
|
215
|
+
const start = cur && cur.expires_at > now ? cur.expires_at : now;
|
|
216
|
+
const expires = start + UTILITY.safetyDays * 86_400_000;
|
|
217
|
+
recordBurn(o.ctx, 'safety', token, burn);
|
|
218
|
+
d.prepare('INSERT INTO safety_monitors (token, expires_at, created_at) VALUES (?, ?, ?) ON CONFLICT(token) DO UPDATE SET expires_at = excluded.expires_at').run(token, expires, now);
|
|
219
|
+
const state = await checkSafety(o, token).catch(() => safetyState(o.ctx, token));
|
|
220
|
+
return { state, burn };
|
|
221
|
+
}
|
|
222
|
+
export function safetyState(ctx, token) {
|
|
223
|
+
const t = token.toLowerCase();
|
|
224
|
+
const d = db(ctx);
|
|
225
|
+
const m = d.prepare('SELECT * FROM safety_monitors WHERE token = ?').get(t);
|
|
226
|
+
const hist = d.prepare('SELECT at, verdict FROM safety_checks WHERE token = ? ORDER BY at DESC LIMIT 30').all(t).map((h) => ({ at: new Date(h.at).toISOString(), verdict: h.verdict }));
|
|
227
|
+
return { token: t, active: !!m && m.expires_at > ctx.now().getTime(), expiresAt: m ? new Date(m.expires_at).toISOString() : null, verdict: m?.verdict ?? null, reasons: m?.reasons ? JSON.parse(m.reasons) : [], name: m?.name ?? null, symbol: m?.symbol ?? null, lastCheck: m?.last_check ? new Date(m.last_check).toISOString() : null, history: hist };
|
|
228
|
+
}
|
|
229
|
+
/** Re-checks every active monitor not checked in the last `everyMs` (default 14 minutes). Returns verdict changes. */
|
|
230
|
+
export async function runSafety(o, everyMs = 14 * 60_000) {
|
|
231
|
+
const now = o.ctx.now().getTime();
|
|
232
|
+
const rows = db(o.ctx).prepare('SELECT token, verdict FROM safety_monitors WHERE expires_at > ? AND (last_check IS NULL OR last_check <= ?)').all(now, now - everyMs);
|
|
233
|
+
const changes = [];
|
|
234
|
+
for (const r of rows) {
|
|
235
|
+
try {
|
|
236
|
+
const s = await checkSafety(o, r.token);
|
|
237
|
+
if (s.verdict && s.verdict !== r.verdict)
|
|
238
|
+
changes.push({ token: r.token, from: r.verdict, to: s.verdict });
|
|
239
|
+
}
|
|
240
|
+
catch { /* next round */ }
|
|
241
|
+
}
|
|
242
|
+
return changes;
|
|
243
|
+
}
|
|
244
|
+
const esc = (s) => s.replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]);
|
|
245
|
+
/** A shields-style SVG badge with the live verdict, or "not monitored". */
|
|
246
|
+
export function badgeSvg(s) {
|
|
247
|
+
const v = s.active ? s.verdict ?? 'CHECKING' : 'NOT MONITORED';
|
|
248
|
+
const color = !s.active ? '#5d676b' : v === 'OK' ? '#2ea36b' : v === 'CAUTION' ? '#c98a12' : v === 'DANGER' ? '#d23b4a' : '#5d676b';
|
|
249
|
+
const left = 'Oculon safety', lw = 96, rw = Math.max(64, Math.ceil(v.length * 8.2 + 22));
|
|
250
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" width="${lw + rw}" height="22" role="img" aria-label="${left}: ${esc(v)}"><title>${left}: ${esc(v)}</title><rect width="${lw}" height="22" fill="#0b1013"/><rect x="${lw}" width="${rw}" height="22" fill="${color}"/><g fill="#fff" font-family="Verdana,DejaVu Sans,sans-serif" font-size="11"><text x="9" y="15" fill="#00f0ff">${left}</text><text x="${lw + 9}" y="15" font-weight="bold">${esc(v)}</text></g></svg>`;
|
|
251
|
+
}
|
|
252
|
+
// ---------- C. Holder tier ----------
|
|
253
|
+
const nonces = new Map();
|
|
254
|
+
export function holderMessage(domain, address, nonce, issuedAt) {
|
|
255
|
+
return `${domain} wants you to sign in with your wallet:\n${address}\n\nSign in to Oculon to check your OCULON holder tier. This does not send a transaction or cost anything.\n\nNonce: ${nonce}\nIssued At: ${issuedAt}`;
|
|
256
|
+
}
|
|
257
|
+
export function createNonce(domain, addressInput, now = Date.now()) {
|
|
258
|
+
const address = addressInput.trim().toLowerCase();
|
|
259
|
+
if (!/^0x[0-9a-f]{40}$/.test(address))
|
|
260
|
+
throw new Error('give the wallet address you will sign with');
|
|
261
|
+
for (const [k, v] of nonces)
|
|
262
|
+
if (v.exp < now)
|
|
263
|
+
nonces.delete(k);
|
|
264
|
+
if (nonces.size > 5000)
|
|
265
|
+
throw new Error('too many sign-in attempts right now, try again in a minute');
|
|
266
|
+
const nonce = randomBytes(12).toString('hex');
|
|
267
|
+
nonces.set(nonce, { address, exp: now + 10 * 60_000 });
|
|
268
|
+
return { nonce, message: holderMessage(domain, address, nonce, new Date(now).toISOString()) };
|
|
269
|
+
}
|
|
270
|
+
export async function balanceOf(address) {
|
|
271
|
+
const cfg = tokenConfig();
|
|
272
|
+
if (!cfg)
|
|
273
|
+
throw new Error('the official token address is not configured on this install');
|
|
274
|
+
const hex = await rpc()('eth_call', [{ to: cfg.ca, data: `0x70a08231${address.slice(2).toLowerCase().padStart(64, '0')}` }, 'latest']);
|
|
275
|
+
return BigInt(hex);
|
|
276
|
+
}
|
|
277
|
+
export async function verifyHolder(ctx, owner, message, signature) {
|
|
278
|
+
const nonce = /Nonce: ([0-9a-f]{24})/.exec(message)?.[1];
|
|
279
|
+
const entry = nonce ? nonces.get(nonce) : undefined;
|
|
280
|
+
if (!nonce || !entry || entry.exp < Date.now())
|
|
281
|
+
throw new Error('this sign-in request expired; start again');
|
|
282
|
+
const signer = recoverPersonalSigner(message, signature);
|
|
283
|
+
if (!signer || signer !== entry.address || !message.includes(entry.address))
|
|
284
|
+
throw new Error('the signature does not match the wallet address');
|
|
285
|
+
nonces.delete(nonce);
|
|
286
|
+
const raw = await balanceOf(signer);
|
|
287
|
+
const balance = formatUnits(raw, 18);
|
|
288
|
+
const needs = `${UTILITY.holder.toLocaleString('en-US')} OCULON`;
|
|
289
|
+
if (raw < UTILITY.holder * E18)
|
|
290
|
+
return { key: null, address: signer, balance, holder: false, expiresAt: null, needs };
|
|
291
|
+
const key = randomBytes(24).toString('hex');
|
|
292
|
+
const exp = ctx.now().getTime() + UTILITY.sessionDays * 86_400_000;
|
|
293
|
+
db(ctx).prepare('INSERT INTO holder_sessions (key, owner, address, balance, expires_at, created_at) VALUES (?, ?, ?, ?, ?, ?)').run(key, owner, signer, raw.toString(), exp, ctx.now().getTime());
|
|
294
|
+
return { key, address: signer, balance, holder: true, expiresAt: new Date(exp).toISOString(), needs };
|
|
295
|
+
}
|
|
296
|
+
/** The holder session behind an owner (web visitor), if any is still valid. */
|
|
297
|
+
export function holderFor(ctx, owner) {
|
|
298
|
+
const r = db(ctx).prepare('SELECT address, expires_at FROM holder_sessions WHERE owner = ? AND expires_at > ? ORDER BY expires_at DESC LIMIT 1').get(owner, ctx.now().getTime());
|
|
299
|
+
return r ? { address: r.address, expiresAt: new Date(r.expires_at).toISOString() } : null;
|
|
300
|
+
}
|
|
301
|
+
export function holderOwners(ctx) {
|
|
302
|
+
return new Set(db(ctx).prepare('SELECT DISTINCT owner FROM holder_sessions WHERE expires_at > ?').all(ctx.now().getTime()).map((r) => r.owner));
|
|
303
|
+
}
|
|
304
|
+
export function signOutHolder(ctx, owner) {
|
|
305
|
+
db(ctx).prepare('DELETE FROM holder_sessions WHERE owner = ?').run(owner);
|
|
306
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import type { Ctx } from '../core/context.js';
|
|
2
|
+
import type { Provenance, Sourced } from '../core/types.js';
|
|
3
|
+
/** POST with a response cache keyed by URL and body (abuse.ch answers lookups only over POST). */
|
|
4
|
+
export declare function postCached<T>(ctx: Ctx, url: string, body: string, contentType: string, headers: Record<string, string>, source: string, ttlSec: number): Promise<Sourced<T>>;
|
|
5
|
+
/** IPv4 or IPv6 as a BigInt plus its bit length, for CIDR matching. */
|
|
6
|
+
export declare function ipToBig(ip: string): {
|
|
7
|
+
v: bigint;
|
|
8
|
+
bits: number;
|
|
9
|
+
} | null;
|
|
10
|
+
export declare function inCidr(ip: string, cidr: string): boolean;
|
|
11
|
+
/** Private, loopback, documentation, multicast and other addresses that are not on the public internet. */
|
|
12
|
+
export declare function isPublicIp(ip: string): boolean;
|
|
13
|
+
export interface IpApi {
|
|
14
|
+
country: string | null;
|
|
15
|
+
countryCode: string | null;
|
|
16
|
+
region: string | null;
|
|
17
|
+
city: string | null;
|
|
18
|
+
lat: number | null;
|
|
19
|
+
lon: number | null;
|
|
20
|
+
isp: string | null;
|
|
21
|
+
org: string | null;
|
|
22
|
+
as: string | null;
|
|
23
|
+
reverse: string | null;
|
|
24
|
+
mobile: boolean;
|
|
25
|
+
proxy: boolean;
|
|
26
|
+
hosting: boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare function ipApi(ctx: Ctx, ip: string): Promise<Sourced<IpApi>>;
|
|
29
|
+
export interface GreyNoise {
|
|
30
|
+
observed: boolean;
|
|
31
|
+
noise: boolean;
|
|
32
|
+
riot: boolean;
|
|
33
|
+
classification: string | null;
|
|
34
|
+
name: string | null;
|
|
35
|
+
lastSeen: string | null;
|
|
36
|
+
link: string | null;
|
|
37
|
+
}
|
|
38
|
+
export declare function greyNoise(ctx: Ctx, ip: string): Promise<Sourced<GreyNoise>>;
|
|
39
|
+
export declare function torExits(ctx: Ctx): Promise<Sourced<Set<string>>>;
|
|
40
|
+
export interface DropLists {
|
|
41
|
+
cidrs: {
|
|
42
|
+
cidr: string;
|
|
43
|
+
id: string;
|
|
44
|
+
}[];
|
|
45
|
+
asns: {
|
|
46
|
+
asn: number;
|
|
47
|
+
name: string;
|
|
48
|
+
}[];
|
|
49
|
+
}
|
|
50
|
+
export declare function spamhausDrop(ctx: Ctx): Promise<{
|
|
51
|
+
data: DropLists | null;
|
|
52
|
+
prov: Provenance[];
|
|
53
|
+
}>;
|
|
54
|
+
export interface PeeringNet {
|
|
55
|
+
name: string;
|
|
56
|
+
type: string | null;
|
|
57
|
+
website: string | null;
|
|
58
|
+
policy: string | null;
|
|
59
|
+
}
|
|
60
|
+
export declare function peeringDb(ctx: Ctx, asn: number): Promise<Sourced<PeeringNet>>;
|
|
61
|
+
export interface InternetDb {
|
|
62
|
+
ports: number[];
|
|
63
|
+
vulns: string[];
|
|
64
|
+
hostnames: string[];
|
|
65
|
+
tags: string[];
|
|
66
|
+
}
|
|
67
|
+
export declare function internetDb(ctx: Ctx, ip: string): Promise<Sourced<InternetDb>>;
|
|
68
|
+
export interface AbuseIpDb {
|
|
69
|
+
score: number;
|
|
70
|
+
reports: number;
|
|
71
|
+
reporters: number;
|
|
72
|
+
lastReported: string | null;
|
|
73
|
+
usageType: string | null;
|
|
74
|
+
isp: string | null;
|
|
75
|
+
domain: string | null;
|
|
76
|
+
countryCode: string | null;
|
|
77
|
+
isTor: boolean;
|
|
78
|
+
whitelisted: boolean;
|
|
79
|
+
}
|
|
80
|
+
export declare function abuseIpDb(ctx: Ctx, ip: string): Promise<Sourced<AbuseIpDb>>;
|
|
81
|
+
export interface OtxPulses {
|
|
82
|
+
count: number;
|
|
83
|
+
pulses: {
|
|
84
|
+
name: string;
|
|
85
|
+
created: string | null;
|
|
86
|
+
tags: string[];
|
|
87
|
+
url: string;
|
|
88
|
+
}[];
|
|
89
|
+
whitelisted: boolean;
|
|
90
|
+
family: string[];
|
|
91
|
+
}
|
|
92
|
+
/** AlienVault OTX community threat reports ("pulses") that mention an IP, domain or file hash. */
|
|
93
|
+
export declare function otx(ctx: Ctx, type: 'IPv4' | 'IPv6' | 'file' | 'domain', value: string): Promise<Sourced<OtxPulses>>;
|
|
94
|
+
export interface IpInfoLite {
|
|
95
|
+
asn: string | null;
|
|
96
|
+
asName: string | null;
|
|
97
|
+
asDomain: string | null;
|
|
98
|
+
country: string | null;
|
|
99
|
+
countryCode: string | null;
|
|
100
|
+
}
|
|
101
|
+
export declare function ipInfo(ctx: Ctx, ip: string): Promise<Sourced<IpInfoLite>>;
|
|
102
|
+
export interface VtStats {
|
|
103
|
+
malicious: number;
|
|
104
|
+
suspicious: number;
|
|
105
|
+
harmless: number;
|
|
106
|
+
undetected: number;
|
|
107
|
+
engines: number;
|
|
108
|
+
reputation: number | null;
|
|
109
|
+
label: string | null;
|
|
110
|
+
name: string | null;
|
|
111
|
+
type: string | null;
|
|
112
|
+
size: number | null;
|
|
113
|
+
firstSeen: string | null;
|
|
114
|
+
owner: string | null;
|
|
115
|
+
link: string;
|
|
116
|
+
}
|
|
117
|
+
/** VirusTotal verdicts for an IP address or a file hash (free public API: 4 requests a minute, 500 a day, non-commercial). */
|
|
118
|
+
export declare function virusTotal(ctx: Ctx, kind: 'ip' | 'file', value: string): Promise<Sourced<VtStats>>;
|
|
119
|
+
export interface CirclHit {
|
|
120
|
+
known: boolean;
|
|
121
|
+
fileName: string | null;
|
|
122
|
+
size: number | null;
|
|
123
|
+
sources: string[];
|
|
124
|
+
knownMalicious: string | null;
|
|
125
|
+
trust: number | null;
|
|
126
|
+
}
|
|
127
|
+
/** CIRCL hashlookup: is this a known file (NIST NSRL and other software sets), or known malware? */
|
|
128
|
+
export declare function circlHash(ctx: Ctx, algo: 'md5' | 'sha1' | 'sha256', hash: string): Promise<Sourced<CirclHit>>;
|
|
129
|
+
export interface BazaarHit {
|
|
130
|
+
sha256: string;
|
|
131
|
+
fileName: string | null;
|
|
132
|
+
fileType: string | null;
|
|
133
|
+
signature: string | null;
|
|
134
|
+
firstSeen: string | null;
|
|
135
|
+
lastSeen: string | null;
|
|
136
|
+
tags: string[];
|
|
137
|
+
delivery: string | null;
|
|
138
|
+
link: string;
|
|
139
|
+
}
|
|
140
|
+
export declare function malwareBazaar(ctx: Ctx, hash: string): Promise<Sourced<BazaarHit>>;
|
|
141
|
+
export interface ThreatFoxHit {
|
|
142
|
+
ioc: string;
|
|
143
|
+
threat: string | null;
|
|
144
|
+
malware: string | null;
|
|
145
|
+
confidence: number | null;
|
|
146
|
+
firstSeen: string | null;
|
|
147
|
+
link: string;
|
|
148
|
+
}
|
|
149
|
+
/** ThreatFox indicators of compromise: an IP:port, domain or file hash used by a malware family. */
|
|
150
|
+
export declare function threatFox(ctx: Ctx, kind: 'hash' | 'ioc', value: string): Promise<Sourced<ThreatFoxHit[]>>;
|
|
151
|
+
export declare const unavailable: (source: string, url: string, note: string) => Provenance;
|