oculon 0.1.7 → 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 +73 -13
- package/dist/cli/main.js +316 -1
- package/dist/core/der.d.ts +2 -0
- package/dist/core/der.js +17 -0
- package/dist/core/http.d.ts +19 -1
- package/dist/core/http.js +24 -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.js +1 -1
- package/dist/core/zip.d.ts +9 -0
- package/dist/core/zip.js +46 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +99 -0
- package/dist/mcp.js +131 -5
- 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.js +33 -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 +24 -2
- package/dist/modules/doc.js +133 -7
- 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/where.d.ts +63 -0
- package/dist/modules/where.js +165 -0
- package/dist/report-pdf.js +3 -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/docs.html +1 -1
- package/dist/web/index.html +147 -11
- 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 +13 -0
- package/dist/web/pages.js +2 -2
- package/dist/web/public.js +14 -1
- package/dist/web/server.d.ts +13 -0
- package/dist/web/server.js +77 -12
- package/dist/web/token.html +24 -4
- package/dist/web/token.json +12 -1
- package/package.json +2 -2
|
@@ -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>>;
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import { codeAt, EVM_CHAINS, evmChain, formatUnits, isAddr, labelOf, sourcify, tokenMeta, UNLIMITED, wordAddr, wordInt } from '../sources/evm.js';
|
|
2
|
+
import { decodeSelectors } from '../sources/signatures.js';
|
|
3
|
+
const big = (v) => { try {
|
|
4
|
+
return v === undefined || v === null || v === '' ? null : BigInt(String(v));
|
|
5
|
+
}
|
|
6
|
+
catch {
|
|
7
|
+
return null;
|
|
8
|
+
} };
|
|
9
|
+
const isUnl = (v) => v !== null && v >= UNLIMITED;
|
|
10
|
+
const when = (s) => { const n = Number(s); return !n ? null : n > 1e12 ? new Date(n).toISOString().slice(0, 10) : new Date(n * 1000).toISOString().slice(0, 10); };
|
|
11
|
+
const farFuture = (s) => { const n = Number(s); return !n || n > Date.now() / 1000 + 365 * 86_400 * 5; };
|
|
12
|
+
async function party(x, address, role) {
|
|
13
|
+
const a = String(address).toLowerCase();
|
|
14
|
+
if (!isAddr(a) || x.parties.some((p) => p.address === a && p.role === role))
|
|
15
|
+
return;
|
|
16
|
+
const name = labelOf(a);
|
|
17
|
+
let type = name ? 'known' : null;
|
|
18
|
+
if (!name && x.chain) {
|
|
19
|
+
const code = await codeAt(x.ctx, x.chain, a);
|
|
20
|
+
if (code === '0x' || (code && /^0xef0100/i.test(code)))
|
|
21
|
+
type = 'wallet';
|
|
22
|
+
else if (code)
|
|
23
|
+
type = (await sourcify(x.ctx, x.chain, a)).data ? 'verified contract' : 'unverified contract';
|
|
24
|
+
}
|
|
25
|
+
x.parties.push({ address: a, role, name, type });
|
|
26
|
+
if (/spender|operator|receiver of your assets/.test(role)) {
|
|
27
|
+
if (type === 'wallet')
|
|
28
|
+
x.reasons.push([`the ${role} is a plain wallet, not an app contract: this is how drainers collect approvals`, 45]);
|
|
29
|
+
if (type === 'unverified contract')
|
|
30
|
+
x.reasons.push([`the ${role} is a contract with unpublished code`, 25]);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function tokenLabel(x, token) {
|
|
34
|
+
if (!x.chain || !isAddr(token))
|
|
35
|
+
return { sym: String(token).slice(0, 12), dec: null };
|
|
36
|
+
const m = await tokenMeta(x.ctx, x.chain, token);
|
|
37
|
+
return { sym: m.symbol ?? token.slice(0, 10), dec: m.decimals };
|
|
38
|
+
}
|
|
39
|
+
async function typed(x, d) {
|
|
40
|
+
const pt = String(d.primaryType ?? '');
|
|
41
|
+
const m = (d.message ?? {});
|
|
42
|
+
const dom = (d.domain ?? {});
|
|
43
|
+
const vc = String(dom.verifyingContract ?? '').toLowerCase();
|
|
44
|
+
if (dom.chainId && !x.chain) {
|
|
45
|
+
const id = Number(dom.chainId);
|
|
46
|
+
const k = Object.values(EVM_CHAINS).find((c) => c.id === id);
|
|
47
|
+
if (k)
|
|
48
|
+
x.chain = k;
|
|
49
|
+
}
|
|
50
|
+
if (pt === 'Permit' && m.spender) {
|
|
51
|
+
const t = await tokenLabel(x, vc);
|
|
52
|
+
const allowed = m.allowed !== undefined ? Boolean(m.allowed) : null;
|
|
53
|
+
const v = allowed === null ? big(m.value) : allowed ? 1n << 255n : 0n;
|
|
54
|
+
const amt = isUnl(v) ? `all your ${t.sym}` : `${formatUnits(v ?? 0n, t.dec)} ${t.sym}`;
|
|
55
|
+
x.allows.push(`${m.spender} can take ${amt} from your wallet${m.deadline || m.expiry ? `, until ${when(m.deadline ?? m.expiry) ?? 'forever'}` : ''}, with no further transaction from you`);
|
|
56
|
+
if (isUnl(v))
|
|
57
|
+
x.reasons.push(['unlimited permit: the spender can take every token of this kind, now and later', 35]);
|
|
58
|
+
if (farFuture(m.deadline ?? m.expiry))
|
|
59
|
+
x.reasons.push(['the permit never expires (or not for years)', 10]);
|
|
60
|
+
x.reasons.push(['permits move no tokens when signed, so wallets often show them as harmless; they are the most common drain signature', 15]);
|
|
61
|
+
await party(x, m.spender, 'spender');
|
|
62
|
+
return `Token permit (${t.sym})`;
|
|
63
|
+
}
|
|
64
|
+
if ((pt === 'PermitSingle' || pt === 'PermitBatch') && m.spender) {
|
|
65
|
+
const det = (Array.isArray(m.details) ? m.details : [m.details]).filter(Boolean);
|
|
66
|
+
for (const dd of det) {
|
|
67
|
+
const t = await tokenLabel(x, String(dd.token));
|
|
68
|
+
const v = big(dd.amount);
|
|
69
|
+
x.allows.push(`${m.spender} can take ${isUnl(v) ? `all your ${t.sym}` : `${formatUnits(v ?? 0n, t.dec)} ${t.sym}`} through Permit2, until ${when(dd.expiration) ?? 'forever'}`);
|
|
70
|
+
if (isUnl(v))
|
|
71
|
+
x.reasons.push([`unlimited Permit2 allowance for ${t.sym}`, 30]);
|
|
72
|
+
}
|
|
73
|
+
if (det.length > 1)
|
|
74
|
+
x.reasons.push([`${det.length} tokens in one signature: drainers bundle every token they found in the wallet`, 25]);
|
|
75
|
+
await party(x, m.spender, 'spender');
|
|
76
|
+
return `Permit2 allowance (${det.length} token${det.length > 1 ? 's' : ''})`;
|
|
77
|
+
}
|
|
78
|
+
if (/^Permit(Batch)?(Witness)?TransferFrom$/.test(pt) && m.spender) {
|
|
79
|
+
const perm = (Array.isArray(m.permitted) ? m.permitted : [m.permitted]).filter(Boolean);
|
|
80
|
+
for (const p of perm) {
|
|
81
|
+
const t = await tokenLabel(x, String(p.token));
|
|
82
|
+
x.allows.push(`${m.spender} can transfer ${formatUnits(big(p.amount) ?? 0n, t.dec)} ${t.sym} out of your wallet once, before ${when(m.deadline) ?? 'the deadline'}`);
|
|
83
|
+
}
|
|
84
|
+
if (perm.length > 2)
|
|
85
|
+
x.reasons.push([`${perm.length} tokens moved in one signature`, 25]);
|
|
86
|
+
await party(x, m.spender, 'spender');
|
|
87
|
+
return 'Permit2 signature transfer';
|
|
88
|
+
}
|
|
89
|
+
if (pt === 'OrderComponents' || (m.offer && m.consideration)) {
|
|
90
|
+
const offer = (m.offer ?? []), cons = (m.consideration ?? []);
|
|
91
|
+
const offerer = String(m.offerer ?? '').toLowerCase();
|
|
92
|
+
const toYou = cons.filter((c) => String(c.recipient ?? '').toLowerCase() === offerer);
|
|
93
|
+
const desc = (i) => `${[0].includes(Number(i.itemType)) ? 'native coin' : [1].includes(Number(i.itemType)) ? 'tokens' : 'NFT'} ${i.token ? String(i.token).slice(0, 10) : ''}${i.identifierOrCriteria && Number(i.itemType) >= 2 ? ` #${String(i.identifierOrCriteria).slice(0, 12)}` : ''} x${i.startAmount ?? i.endAmount ?? '?'}`;
|
|
94
|
+
for (const o of offer)
|
|
95
|
+
x.allows.push(`you give: ${desc(o)}`);
|
|
96
|
+
for (const c of cons)
|
|
97
|
+
x.allows.push(`${String(c.recipient ?? '').toLowerCase() === offerer ? 'you get' : `${String(c.recipient).slice(0, 10)}... gets`}: ${desc(c)}`);
|
|
98
|
+
const youGet = toYou.reduce((s, c) => s + (big(c.startAmount) ?? 0n), 0n);
|
|
99
|
+
if (offer.length && (!toYou.length || youGet === 0n))
|
|
100
|
+
x.reasons.push(['you give assets and get nothing back: this listing hands them over for free', 70]);
|
|
101
|
+
if (offer.length >= 3)
|
|
102
|
+
x.reasons.push([`${offer.length} items offered in one order`, 15]);
|
|
103
|
+
for (const c of cons.filter((c) => String(c.recipient ?? '').toLowerCase() !== offerer).slice(0, 3))
|
|
104
|
+
await party(x, String(c.recipient), 'receiver of your assets');
|
|
105
|
+
return 'Marketplace order (Seaport)';
|
|
106
|
+
}
|
|
107
|
+
// Any other typed message: list the addresses and amounts it names.
|
|
108
|
+
const addrs = JSON.stringify(m).match(/0x[0-9a-fA-F]{40}/g) ?? [];
|
|
109
|
+
for (const a of [...new Set(addrs)].slice(0, 4))
|
|
110
|
+
await party(x, a, 'named in the message');
|
|
111
|
+
x.allows.push(`a "${pt || 'typed'}" message for ${dom.name ?? 'an app'}${vc ? ` (contract ${vc})` : ''}`);
|
|
112
|
+
if (/order|permit|approv|transfer|withdraw|delegat/i.test(pt))
|
|
113
|
+
x.reasons.push([`"${pt}" messages can move or allow assets; only sign it on the app's real site`, 20]);
|
|
114
|
+
return `Typed message (${pt || 'unknown'})`;
|
|
115
|
+
}
|
|
116
|
+
const SELECTORS = {
|
|
117
|
+
'0x095ea7b3': 'approve', '0x39509351': 'increaseAllowance', '0xa22cb465': 'setApprovalForAll', '0xa9059cbb': 'transfer', '0x23b872dd': 'transferFrom',
|
|
118
|
+
'0x42842e0e': 'safeTransferFrom', '0xb88d4fde': 'safeTransferFrom', '0xf242432a': 'safeTransferFrom (1155)', '0x2eb2c2d6': 'safeBatchTransferFrom', '0x87517c45': 'Permit2 approve',
|
|
119
|
+
'0xac9650d8': 'multicall', '0x5ae401dc': 'multicall', '0xd505accf': 'permit',
|
|
120
|
+
};
|
|
121
|
+
async function calldata(x, data, to, value, depth = 0) {
|
|
122
|
+
const sel = data.slice(0, 10).toLowerCase();
|
|
123
|
+
const args = data.slice(10);
|
|
124
|
+
const name = SELECTORS[sel];
|
|
125
|
+
const t = to ? await tokenLabel(x, to) : { sym: 'the token', dec: null };
|
|
126
|
+
if (sel === '0x095ea7b3' || sel === '0x39509351') {
|
|
127
|
+
const spender = wordAddr(args, 0), v = wordInt(args, 1);
|
|
128
|
+
if (v === 0n) {
|
|
129
|
+
x.allows.push(`removes the approval of ${spender} for ${t.sym}`);
|
|
130
|
+
return 'Revoke approval';
|
|
131
|
+
}
|
|
132
|
+
x.allows.push(`${spender} can take ${isUnl(v) ? `all your ${t.sym}, now and later` : `${formatUnits(v, t.dec)} ${t.sym}`}`);
|
|
133
|
+
if (isUnl(v))
|
|
134
|
+
x.reasons.push(['unlimited approval', 20]);
|
|
135
|
+
await party(x, spender, 'spender');
|
|
136
|
+
return `${name} (${t.sym})`;
|
|
137
|
+
}
|
|
138
|
+
if (sel === '0xa22cb465') {
|
|
139
|
+
const op = wordAddr(args, 0), on = wordInt(args, 1) !== 0n;
|
|
140
|
+
if (!on) {
|
|
141
|
+
x.allows.push(`removes ${op} as operator`);
|
|
142
|
+
return 'Revoke NFT approval';
|
|
143
|
+
}
|
|
144
|
+
x.allows.push(`${op} can move every NFT you hold in collection ${to ?? ''}, now and later`);
|
|
145
|
+
x.reasons.push(['approval for all NFTs in a collection: the most common NFT drain', 35]);
|
|
146
|
+
await party(x, op, 'operator');
|
|
147
|
+
return 'Approve all NFTs';
|
|
148
|
+
}
|
|
149
|
+
if (sel === '0xa9059cbb') {
|
|
150
|
+
const rcp = wordAddr(args, 0), v = wordInt(args, 1);
|
|
151
|
+
x.allows.push(`sends ${formatUnits(v, t.dec)} ${t.sym} to ${rcp}`);
|
|
152
|
+
await party(x, rcp, 'recipient');
|
|
153
|
+
return `Token transfer (${t.sym})`;
|
|
154
|
+
}
|
|
155
|
+
if (['0x23b872dd', '0x42842e0e', '0xb88d4fde', '0xf242432a'].includes(sel)) {
|
|
156
|
+
const from = wordAddr(args, 0), rcp = wordAddr(args, 1);
|
|
157
|
+
x.allows.push(`moves ${sel === '0x23b872dd' ? `${formatUnits(wordInt(args, 2), t.dec)} ${t.sym}` : `item #${wordInt(args, 2).toString().slice(0, 16)}`} from ${from} to ${rcp}`);
|
|
158
|
+
await party(x, rcp, 'recipient');
|
|
159
|
+
return name;
|
|
160
|
+
}
|
|
161
|
+
if (sel === '0x2eb2c2d6') {
|
|
162
|
+
x.allows.push(`moves a batch of items to ${wordAddr(args, 1)}`);
|
|
163
|
+
x.reasons.push(['batch transfer of many items', 20]);
|
|
164
|
+
await party(x, wordAddr(args, 1), 'recipient');
|
|
165
|
+
return name;
|
|
166
|
+
}
|
|
167
|
+
if (sel === '0x87517c45') {
|
|
168
|
+
const tok = wordAddr(args, 0), spender = wordAddr(args, 1), v = wordInt(args, 2);
|
|
169
|
+
const tl = await tokenLabel(x, tok);
|
|
170
|
+
x.allows.push(`${spender} can take ${isUnl(v) ? `all your ${tl.sym}` : `${formatUnits(v, tl.dec)} ${tl.sym}`} through Permit2 until ${when(wordInt(args, 3).toString()) ?? 'forever'}`);
|
|
171
|
+
await party(x, spender, 'spender');
|
|
172
|
+
return 'Permit2 approve';
|
|
173
|
+
}
|
|
174
|
+
if ((sel === '0xac9650d8' || sel === '0x5ae401dc') && depth === 0) {
|
|
175
|
+
const base = sel === '0x5ae401dc' ? 1 : 0;
|
|
176
|
+
const off = Number(wordInt(args, base)) / 32;
|
|
177
|
+
const n = Number(wordInt(args, off));
|
|
178
|
+
const inner = [];
|
|
179
|
+
for (let i = 0; i < Math.min(n, 12); i++) {
|
|
180
|
+
const o = off + 1 + Number(wordInt(args, off + 1 + i)) / 32;
|
|
181
|
+
const len = Number(wordInt(args, o));
|
|
182
|
+
const hex = args.slice((o + 1) * 64, (o + 1) * 64 + len * 2);
|
|
183
|
+
if (hex.length >= 8)
|
|
184
|
+
inner.push(await calldata(x, `0x${hex}`, to, 0n, 1));
|
|
185
|
+
}
|
|
186
|
+
return `Bundle of ${n} calls: ${inner.join(', ')}`;
|
|
187
|
+
}
|
|
188
|
+
// Unknown function: name it if a database knows it.
|
|
189
|
+
const d = await decodeSelectors(x.ctx, [sel]).catch(() => ({}));
|
|
190
|
+
const sig = d[sel] ?? null;
|
|
191
|
+
x.allows.push(`calls ${sig ?? `an unknown function ${sel}`} on ${to ?? 'a contract'}${value ? ` and sends ${formatUnits(value, 18)} ${x.chain?.native ?? 'ETH'}` : ''}`);
|
|
192
|
+
if (!sig)
|
|
193
|
+
x.reasons.push(['the function is not in any public signature database: nobody can say what it does', 20]);
|
|
194
|
+
if (value && sig && /^(claim|claimreward|claimrewards|claimairdrop|securityupdate|connect|verify|airdrop|mint)\b/i.test(sig) && !sig.includes(','))
|
|
195
|
+
x.reasons.push([`"${sig.split('(')[0]}" with a payment attached: a classic fake airdrop or "security update" drainer`, 40]);
|
|
196
|
+
if (to)
|
|
197
|
+
await party(x, to, 'contract called');
|
|
198
|
+
return sig ? `Call ${sig.split('(')[0]}` : 'Unknown call';
|
|
199
|
+
}
|
|
200
|
+
export async function signatureCheck(ctx, input, opts = {}) {
|
|
201
|
+
const raw = input.trim();
|
|
202
|
+
if (!raw)
|
|
203
|
+
throw new Error('paste the signature request: typed data JSON, transaction data (0x...), or the message');
|
|
204
|
+
if (raw.length > 100_000)
|
|
205
|
+
throw new Error('the request is too long (max 100,000 characters)');
|
|
206
|
+
const x = { ctx, chain: opts.chain ? evmChain(opts.chain) : null, parties: [], reasons: [], allows: [], prov: [] };
|
|
207
|
+
let kind = 'message', type = 'Plain message';
|
|
208
|
+
let parsed = null;
|
|
209
|
+
try {
|
|
210
|
+
parsed = JSON.parse(raw);
|
|
211
|
+
}
|
|
212
|
+
catch { }
|
|
213
|
+
if (parsed && Array.isArray(parsed.params))
|
|
214
|
+
parsed = parsed.params.find((p) => typeof p === 'object' || (typeof p === 'string' && p.trim().startsWith('{'))) ?? parsed;
|
|
215
|
+
if (typeof parsed === 'string') {
|
|
216
|
+
try {
|
|
217
|
+
parsed = JSON.parse(parsed);
|
|
218
|
+
}
|
|
219
|
+
catch { }
|
|
220
|
+
}
|
|
221
|
+
if (parsed && typeof parsed === 'object' && (parsed.primaryType || parsed.types)) {
|
|
222
|
+
kind = 'typed data';
|
|
223
|
+
type = await typed(x, parsed);
|
|
224
|
+
}
|
|
225
|
+
else if (parsed && typeof parsed === 'object' && typeof parsed.data === 'string') {
|
|
226
|
+
kind = 'transaction';
|
|
227
|
+
if (!x.chain && parsed.chainId) {
|
|
228
|
+
const id = Number(parsed.chainId);
|
|
229
|
+
x.chain = Object.values(EVM_CHAINS).find((c) => c.id === id) ?? null;
|
|
230
|
+
}
|
|
231
|
+
if (!x.chain)
|
|
232
|
+
x.chain = evmChain('eth');
|
|
233
|
+
const v = big(parsed.value) ?? 0n;
|
|
234
|
+
type = parsed.data.length >= 10 ? await calldata(x, parsed.data, parsed.to ? String(parsed.to).toLowerCase() : null, v) : 'Plain transfer';
|
|
235
|
+
if (parsed.data.length < 10 && parsed.to) {
|
|
236
|
+
x.allows.push(`sends ${formatUnits(v, 18)} ${x.chain.native} to ${parsed.to}`);
|
|
237
|
+
await party(x, parsed.to, 'recipient');
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
else if (/^0x[0-9a-fA-F]{64}$/.test(raw)) {
|
|
241
|
+
kind = 'raw hash';
|
|
242
|
+
type = 'Raw hash (eth_sign)';
|
|
243
|
+
x.allows.push('nothing you can read: a raw hash can stand for any transaction, including one that empties the wallet');
|
|
244
|
+
x.reasons.push(['blind signature: a raw 32-byte hash hides what it authorizes. Legitimate apps do not ask for this', 75]);
|
|
245
|
+
}
|
|
246
|
+
else if (/^0x[0-9a-fA-F]{8,}$/.test(raw)) {
|
|
247
|
+
kind = 'transaction';
|
|
248
|
+
x.chain ??= evmChain('eth');
|
|
249
|
+
type = await calldata(x, raw, opts.to && isAddr(opts.to) ? opts.to.toLowerCase() : null, 0n);
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
let text = raw;
|
|
253
|
+
if (/^0x[0-9a-fA-F]+$/.test(raw)) {
|
|
254
|
+
try {
|
|
255
|
+
text = Buffer.from(raw.slice(2), 'hex').toString('utf8');
|
|
256
|
+
}
|
|
257
|
+
catch { }
|
|
258
|
+
}
|
|
259
|
+
x.allows.push(`signs the text: "${text.slice(0, 160)}${text.length > 160 ? '...' : ''}"`);
|
|
260
|
+
if (/seed|recovery phrase|private key|mnemonic/i.test(text))
|
|
261
|
+
x.reasons.push(['the message mentions your seed phrase or private key: no real app asks for that', 80]);
|
|
262
|
+
if (/sign.?in|login|log in|nonce|verify (your )?wallet|SIWE|wants you to sign in/i.test(text)) {
|
|
263
|
+
type = 'Sign-in message';
|
|
264
|
+
const dom = /^(\S+) wants you to sign in/m.exec(text)?.[1];
|
|
265
|
+
if (dom)
|
|
266
|
+
x.allows.push(`proves you own this wallet to ${dom}. Check that ${dom} is the site you are on`);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
const reasons = x.reasons.sort((a, b) => b[1] - a[1]);
|
|
270
|
+
const risk = Math.min(100, reasons.reduce((s, [, w]) => s + w, 0));
|
|
271
|
+
const verdict = risk >= 70 ? 'dangerous signature' : risk >= 40 ? 'risky signature' : risk >= 15 || kind === 'typed data' ? 'check before signing' : 'no known risk found';
|
|
272
|
+
const summary = x.allows[0] ?? type;
|
|
273
|
+
const advice = verdict === 'dangerous signature'
|
|
274
|
+
? ['Do not sign. Close the site.', 'If you already signed, revoke approvals right away (oculon approvals <wallet>) and move your funds to a new wallet.']
|
|
275
|
+
: verdict === 'risky signature'
|
|
276
|
+
? ['Only sign if you started this yourself on the real site of the app, and the spender is the app you expect.', 'Prefer a limited amount over unlimited.']
|
|
277
|
+
: ['Sign only on the site you meant to use. Typed messages and approvals can move assets later without another prompt.'];
|
|
278
|
+
return {
|
|
279
|
+
module: 'signature', input: raw.slice(0, 200), generatedAt: ctx.now().toISOString(),
|
|
280
|
+
result: { kind, type, verdict, risk, summary, allows: x.allows.slice(0, 20), reasons: reasons.map(([r]) => r), parties: x.parties, chain: x.chain?.label ?? null, advice },
|
|
281
|
+
signals: [], provenance: [{ source: 'oculon-signature', url: 'local', status: 'LIVE', fetchedAt: ctx.now().toISOString(), note: 'decoded locally; addresses and selectors looked up on chain' }, ...x.prov],
|
|
282
|
+
};
|
|
283
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Site check: open a page the way a visitor would and look for what phishing pages and wallet drainers do.
|
|
3
|
+
* Drainers: wallet connection code next to signature requests that hand over assets (permits, Permit2,
|
|
4
|
+
* setApprovalForAll, unlimited approve, Seaport orders, eth_sign), a receiver address written into the
|
|
5
|
+
* script, token-balance APIs used to rank what to take first, and heavy obfuscation.
|
|
6
|
+
* Phishing: a login, card or seed-phrase form on a domain that is not the brand the page shows, forms that send
|
|
7
|
+
* to another domain, and Telegram bot tokens or Discord webhooks in the code (phishing kits send what people
|
|
8
|
+
* type there).
|
|
9
|
+
* Reputation: the link check (Safe Browsing, URLhaus, urlscan.io, domain age) of the final address after
|
|
10
|
+
* redirects, and lookalikes of well known apps and brands.
|
|
11
|
+
* Browser: when a Cloudflare URL Scanner token is set, the page is also opened in a real browser on Cloudflare's
|
|
12
|
+
* side, so scripts that load later, redirects done in JavaScript and the rendered page are read too, and
|
|
13
|
+
* Cloudflare's own verdict is added. Victims' reports on the domain come from Chainabuse.
|
|
14
|
+
* The page is fetched here with a normal browser User-Agent; scripts are read here, never run here.
|
|
15
|
+
*/
|
|
16
|
+
import type { Ctx } from '../core/context.js';
|
|
17
|
+
import type { ModuleResult } from '../core/types.js';
|
|
18
|
+
import { type AbuseReports } from '../sources/chainabuse.js';
|
|
19
|
+
export interface SiteReport {
|
|
20
|
+
url: string;
|
|
21
|
+
finalUrl: string;
|
|
22
|
+
domain: string;
|
|
23
|
+
title: string | null;
|
|
24
|
+
verdict: 'wallet drainer' | 'phishing page' | 'suspicious' | 'no known risk found';
|
|
25
|
+
risk: number;
|
|
26
|
+
drainer: string[];
|
|
27
|
+
phishing: string[];
|
|
28
|
+
reputation: {
|
|
29
|
+
verdict: string;
|
|
30
|
+
risk: number;
|
|
31
|
+
ageDays: number | null;
|
|
32
|
+
reasons: string[];
|
|
33
|
+
} | null;
|
|
34
|
+
forms: {
|
|
35
|
+
action: string;
|
|
36
|
+
password: boolean;
|
|
37
|
+
seed: boolean;
|
|
38
|
+
card: boolean;
|
|
39
|
+
external: boolean;
|
|
40
|
+
}[];
|
|
41
|
+
scripts: {
|
|
42
|
+
read: number;
|
|
43
|
+
external: string[];
|
|
44
|
+
};
|
|
45
|
+
/** The page opened in a real browser (Cloudflare URL Scanner), when configured. */
|
|
46
|
+
browser: {
|
|
47
|
+
malicious: boolean;
|
|
48
|
+
categories: string[];
|
|
49
|
+
report: string;
|
|
50
|
+
finalUrl: string | null;
|
|
51
|
+
domains: number;
|
|
52
|
+
scripts: number;
|
|
53
|
+
} | null;
|
|
54
|
+
/** Scam reports on the domain filed by victims (Chainabuse). */
|
|
55
|
+
reports: AbuseReports | null;
|
|
56
|
+
exfil: string[];
|
|
57
|
+
reasons: string[];
|
|
58
|
+
advice: string[];
|
|
59
|
+
}
|
|
60
|
+
export declare function siteCheck(ctx: Ctx, input: string, opts?: {
|
|
61
|
+
browser?: boolean;
|
|
62
|
+
}): Promise<ModuleResult<SiteReport>>;
|