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,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EVM reads for the wallet-safety checks.
|
|
3
|
+
* RPC: public endpoints (publicnode), with Alchemy (ALCHEMY_API_KEY, free) as the fallback when one fails.
|
|
4
|
+
* History: an explorer API for logs, transaction lists and token transfers: Etherscan v2 (free key: Ethereum,
|
|
5
|
+
* Arbitrum, Polygon) or Blockscout (BLOCKSCOUT_API_KEY, free: Optimism, Robinhood Chain). Where neither
|
|
6
|
+
* covers a chain (Base, BNB Chain), Alchemy's transfers API gives transfers and value transactions, but not
|
|
7
|
+
* logs, so approvals stay unavailable there and the checks say so.
|
|
8
|
+
* Verified code: Sourcify, then the explorer.
|
|
9
|
+
*/
|
|
10
|
+
import { type Ctx } from '../core/context.js';
|
|
11
|
+
import type { Sourced } from '../core/types.js';
|
|
12
|
+
export interface EvmChain {
|
|
13
|
+
key: string;
|
|
14
|
+
id: number;
|
|
15
|
+
label: string;
|
|
16
|
+
native: string;
|
|
17
|
+
rpc: string | null;
|
|
18
|
+
/** Explorer API that answers logs, transaction lists and token transfers for free on this chain. */
|
|
19
|
+
scan: 'etherscan' | 'blockscout' | null;
|
|
20
|
+
/** Alchemy network name (transfers, prices, RPC fallback). */
|
|
21
|
+
alchemy: string | null;
|
|
22
|
+
explorer: string;
|
|
23
|
+
}
|
|
24
|
+
/** What a check needs from a chain: event logs (approvals), transfers (poisoning, trace), contract creation (creator). */
|
|
25
|
+
export type Need = 'logs' | 'transfers' | 'creation';
|
|
26
|
+
export declare const EVM_CHAINS: Record<string, EvmChain>;
|
|
27
|
+
/** Can this install answer `need` on chain `c` with the keys it has? */
|
|
28
|
+
export declare function chainCan(c: EvmChain, need: Need): boolean;
|
|
29
|
+
export declare function evmChain(name: string | undefined, need?: Need): EvmChain;
|
|
30
|
+
export declare const isAddr: (s: string) => boolean;
|
|
31
|
+
export declare const ZERO = "0x0000000000000000000000000000000000000000";
|
|
32
|
+
export declare const DEAD: RegExp;
|
|
33
|
+
export declare const TOPIC: {
|
|
34
|
+
transfer: string;
|
|
35
|
+
approval: string;
|
|
36
|
+
approvalForAll: string;
|
|
37
|
+
};
|
|
38
|
+
export declare const MAX_UINT: bigint;
|
|
39
|
+
/** Treat anything above 2^200 as "unlimited": wallets send max uint256 or max uint160 (Permit2). */
|
|
40
|
+
export declare const UNLIMITED: bigint;
|
|
41
|
+
export declare const pad: (a: string) => string;
|
|
42
|
+
export declare const topicAddr: (t: string) => string;
|
|
43
|
+
export declare const wordAt: (hex: string, i: number) => string;
|
|
44
|
+
export declare const wordAddr: (hex: string, i: number) => string;
|
|
45
|
+
export declare const wordInt: (hex: string, i: number) => bigint;
|
|
46
|
+
/** Decode an ABI-encoded string return (name(), symbol()), or a bytes32 one some old tokens use. */
|
|
47
|
+
export declare function abiString(hex: string | null): string | null;
|
|
48
|
+
export declare function rpcCall<T>(ctx: Ctx, c: EvmChain, method: string, params: unknown[], ttlSec?: number): Promise<Sourced<T>>;
|
|
49
|
+
export declare const ethCall: (ctx: Ctx, c: EvmChain, to: string, data: string, ttlSec?: number) => Promise<Sourced<string>>;
|
|
50
|
+
export declare function codeAt(ctx: Ctx, c: EvmChain, a: string): Promise<string | null>;
|
|
51
|
+
/** name, symbol and decimals of a token; null fields when the call fails. */
|
|
52
|
+
export declare function tokenMeta(ctx: Ctx, c: EvmChain, token: string): Promise<{
|
|
53
|
+
name: string | null;
|
|
54
|
+
symbol: string | null;
|
|
55
|
+
decimals: number | null;
|
|
56
|
+
}>;
|
|
57
|
+
export declare function formatUnits(v: bigint, decimals: number | null, digits?: number): string;
|
|
58
|
+
/** Etherscan-style explorer API: Etherscan v2 or Blockscout, whichever covers the chain for free. */
|
|
59
|
+
export declare function etherscan<T>(ctx: Ctx, c: EvmChain, params: Record<string, string>, ttlSec?: number): Promise<Sourced<T>>;
|
|
60
|
+
export interface EsLog {
|
|
61
|
+
address: string;
|
|
62
|
+
topics: string[];
|
|
63
|
+
data: string;
|
|
64
|
+
blockNumber: string;
|
|
65
|
+
timeStamp: string;
|
|
66
|
+
transactionHash: string;
|
|
67
|
+
}
|
|
68
|
+
export interface EsTokenTx {
|
|
69
|
+
hash: string;
|
|
70
|
+
timeStamp: string;
|
|
71
|
+
from: string;
|
|
72
|
+
to: string;
|
|
73
|
+
value: string;
|
|
74
|
+
contractAddress: string;
|
|
75
|
+
tokenSymbol: string;
|
|
76
|
+
tokenName: string;
|
|
77
|
+
tokenDecimal: string;
|
|
78
|
+
}
|
|
79
|
+
export interface EsTx {
|
|
80
|
+
hash: string;
|
|
81
|
+
timeStamp: string;
|
|
82
|
+
from: string;
|
|
83
|
+
to: string;
|
|
84
|
+
value: string;
|
|
85
|
+
isError: string;
|
|
86
|
+
functionName?: string;
|
|
87
|
+
methodId?: string;
|
|
88
|
+
contractAddress?: string;
|
|
89
|
+
}
|
|
90
|
+
export declare const esLogs: (ctx: Ctx, c: EvmChain, topic0: string, topic1: string) => Promise<Sourced<EsLog[]>>;
|
|
91
|
+
/** Where a chain's transfer history comes from: an explorer API, or Alchemy's transfers API. */
|
|
92
|
+
export declare const historySource: (c: EvmChain) => 'explorer' | 'alchemy' | null;
|
|
93
|
+
export declare const esTokenTx: (ctx: Ctx, c: EvmChain, address: string, n?: number) => Promise<Sourced<EsTokenTx[]>>;
|
|
94
|
+
/** Transactions of an address. From Alchemy only value transfers are listed (no zero-value contract calls). */
|
|
95
|
+
export declare const esTxList: (ctx: Ctx, c: EvmChain, address: string, n?: number, sort?: 'asc' | 'desc') => Promise<Sourced<EsTx[]>>;
|
|
96
|
+
/**
|
|
97
|
+
* Transfers in and out of an address (alchemy_getAssetTransfers), shaped like Etherscan's tokentx / txlist rows,
|
|
98
|
+
* newest first. Two requests: one for each direction.
|
|
99
|
+
*/
|
|
100
|
+
export declare function alchemyTransfers(ctx: Ctx, c: EvmChain, address: string, category: ('erc20' | 'external' | 'erc721' | 'erc1155')[], n?: number, sort?: 'asc' | 'desc'): Promise<Sourced<(EsTokenTx & EsTx)[]>>;
|
|
101
|
+
/** Alchemy marks NFT collections it considers spam. Null when unknown or without a key. */
|
|
102
|
+
export declare function alchemyIsSpam(ctx: Ctx, c: EvmChain, contract: string): Promise<boolean | null>;
|
|
103
|
+
/** USD prices of tokens on a chain (Alchemy Prices API), by lower-case address. */
|
|
104
|
+
export declare function alchemyPrices(ctx: Ctx, c: EvmChain, tokens: string[]): Promise<Map<string, number>>;
|
|
105
|
+
export interface AbiItem {
|
|
106
|
+
type: string;
|
|
107
|
+
name?: string;
|
|
108
|
+
inputs?: {
|
|
109
|
+
name: string;
|
|
110
|
+
type: string;
|
|
111
|
+
}[];
|
|
112
|
+
stateMutability?: string;
|
|
113
|
+
}
|
|
114
|
+
export interface Verified {
|
|
115
|
+
name: string | null;
|
|
116
|
+
abi: AbiItem[];
|
|
117
|
+
compiler: string | null;
|
|
118
|
+
proxy: {
|
|
119
|
+
isProxy: boolean;
|
|
120
|
+
type: string | null;
|
|
121
|
+
implementations: {
|
|
122
|
+
address: string;
|
|
123
|
+
name: string | null;
|
|
124
|
+
}[];
|
|
125
|
+
} | null;
|
|
126
|
+
source: 'sourcify' | 'etherscan';
|
|
127
|
+
}
|
|
128
|
+
export declare function sourcify(ctx: Ctx, c: EvmChain, a: string): Promise<Sourced<Verified>>;
|
|
129
|
+
/** Verified source from Etherscan (Ethereum, Arbitrum, Polygon on the free plan). */
|
|
130
|
+
export declare function etherscanSource(ctx: Ctx, c: EvmChain, a: string): Promise<Sourced<Verified>>;
|
|
131
|
+
/** Function selectors pushed in deployed bytecode (PUSH4 operands), for contracts without verified source. */
|
|
132
|
+
export declare function bytecodeSelectors(code: string): string[];
|
|
133
|
+
/** Names of well known spenders and routers, so an approval to them reads as what it is. */
|
|
134
|
+
export declare const KNOWN: Record<string, string>;
|
|
135
|
+
export declare const labelOf: (a: string) => string | null;
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EVM reads for the wallet-safety checks.
|
|
3
|
+
* RPC: public endpoints (publicnode), with Alchemy (ALCHEMY_API_KEY, free) as the fallback when one fails.
|
|
4
|
+
* History: an explorer API for logs, transaction lists and token transfers: Etherscan v2 (free key: Ethereum,
|
|
5
|
+
* Arbitrum, Polygon) or Blockscout (BLOCKSCOUT_API_KEY, free: Optimism, Robinhood Chain). Where neither
|
|
6
|
+
* covers a chain (Base, BNB Chain), Alchemy's transfers API gives transfers and value transactions, but not
|
|
7
|
+
* logs, so approvals stay unavailable there and the checks say so.
|
|
8
|
+
* Verified code: Sourcify, then the explorer.
|
|
9
|
+
*/
|
|
10
|
+
import { enc } from '../core/context.js';
|
|
11
|
+
import { key } from '../core/keys.js';
|
|
12
|
+
import { postJson } from './press.js';
|
|
13
|
+
export const EVM_CHAINS = {
|
|
14
|
+
eth: { key: 'eth', id: 1, label: 'Ethereum', native: 'ETH', rpc: 'https://ethereum-rpc.publicnode.com', scan: 'etherscan', alchemy: 'eth-mainnet', explorer: 'https://etherscan.io' },
|
|
15
|
+
arbitrum: { key: 'arbitrum', id: 42161, label: 'Arbitrum', native: 'ETH', rpc: 'https://arbitrum-one-rpc.publicnode.com', scan: 'etherscan', alchemy: 'arb-mainnet', explorer: 'https://arbiscan.io' },
|
|
16
|
+
polygon: { key: 'polygon', id: 137, label: 'Polygon', native: 'POL', rpc: 'https://polygon-bor-rpc.publicnode.com', scan: 'etherscan', alchemy: 'polygon-mainnet', explorer: 'https://polygonscan.com' },
|
|
17
|
+
optimism: { key: 'optimism', id: 10, label: 'Optimism', native: 'ETH', rpc: 'https://optimism-rpc.publicnode.com', scan: 'blockscout', alchemy: 'opt-mainnet', explorer: 'https://optimistic.etherscan.io' },
|
|
18
|
+
base: { key: 'base', id: 8453, label: 'Base', native: 'ETH', rpc: 'https://base-rpc.publicnode.com', scan: null, alchemy: 'base-mainnet', explorer: 'https://basescan.org' },
|
|
19
|
+
bsc: { key: 'bsc', id: 56, label: 'BNB Chain', native: 'BNB', rpc: 'https://bsc-rpc.publicnode.com', scan: null, alchemy: 'bnb-mainnet', explorer: 'https://bscscan.com' },
|
|
20
|
+
robinhood: { key: 'robinhood', id: 4663, label: 'Robinhood Chain', native: 'ETH', rpc: null, scan: 'blockscout', alchemy: null, explorer: 'https://robinhood.blockscout.com' },
|
|
21
|
+
};
|
|
22
|
+
const ALIAS = { ethereum: 'eth', mainnet: 'eth', arb: 'arbitrum', matic: 'polygon', pol: 'polygon', op: 'optimism', bnb: 'bsc', rh: 'robinhood' };
|
|
23
|
+
const scanKey = (c) => (c.scan === 'etherscan' ? key('ETHERSCAN_API_KEY') : c.scan === 'blockscout' ? key('BLOCKSCOUT_API_KEY') : undefined);
|
|
24
|
+
/** Can this install answer `need` on chain `c` with the keys it has? */
|
|
25
|
+
export function chainCan(c, need) {
|
|
26
|
+
if (need === 'transfers')
|
|
27
|
+
return Boolean((c.scan && scanKey(c)) || (c.alchemy && key('ALCHEMY_API_KEY')));
|
|
28
|
+
return Boolean(c.scan && scanKey(c));
|
|
29
|
+
}
|
|
30
|
+
export function evmChain(name, need) {
|
|
31
|
+
const k = (name ?? 'eth').trim().toLowerCase();
|
|
32
|
+
const c = EVM_CHAINS[ALIAS[k] ?? k];
|
|
33
|
+
const ok = Object.values(EVM_CHAINS).filter((x) => !need || chainCan(x, need));
|
|
34
|
+
if (!c)
|
|
35
|
+
throw new Error(`not a supported chain: ${k} (use ${ok.map((x) => x.key).join(', ')})`);
|
|
36
|
+
if (need && !chainCan(c, need))
|
|
37
|
+
throw new Error(`${c.label} is not covered for this check by the free data sources (${need === 'logs' ? 'it needs event logs' : need === 'creation' ? 'it needs contract creation data' : 'it needs transaction history'}); supported here: ${ok.map((x) => x.label).join(', ')}`);
|
|
38
|
+
return c;
|
|
39
|
+
}
|
|
40
|
+
export const isAddr = (s) => /^0x[0-9a-fA-F]{40}$/.test(s.trim());
|
|
41
|
+
export const ZERO = '0x0000000000000000000000000000000000000000';
|
|
42
|
+
export const DEAD = /^0x0{40}$|^0x0{36}dead$|^0x000000000000000000000000000000000000dead$/i;
|
|
43
|
+
export const TOPIC = {
|
|
44
|
+
transfer: '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
|
|
45
|
+
approval: '0x8c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925',
|
|
46
|
+
approvalForAll: '0x17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c31',
|
|
47
|
+
};
|
|
48
|
+
export const MAX_UINT = (1n << 256n) - 1n;
|
|
49
|
+
/** Treat anything above 2^200 as "unlimited": wallets send max uint256 or max uint160 (Permit2). */
|
|
50
|
+
export const UNLIMITED = 1n << 150n;
|
|
51
|
+
export const pad = (a) => a.toLowerCase().replace(/^0x/, '').padStart(64, '0');
|
|
52
|
+
export const topicAddr = (t) => `0x${t.slice(-40)}`.toLowerCase();
|
|
53
|
+
export const wordAt = (hex, i) => hex.replace(/^0x/, '').slice(i * 64, i * 64 + 64);
|
|
54
|
+
export const wordAddr = (hex, i) => `0x${wordAt(hex, i).slice(24)}`.toLowerCase();
|
|
55
|
+
export const wordInt = (hex, i) => { const w = wordAt(hex, i); return w ? BigInt(`0x${w}`) : 0n; };
|
|
56
|
+
/** Decode an ABI-encoded string return (name(), symbol()), or a bytes32 one some old tokens use. */
|
|
57
|
+
export function abiString(hex) {
|
|
58
|
+
if (!hex || hex === '0x')
|
|
59
|
+
return null;
|
|
60
|
+
const h = hex.replace(/^0x/, '');
|
|
61
|
+
try {
|
|
62
|
+
if (h.length >= 128) {
|
|
63
|
+
const off = Number(BigInt(`0x${h.slice(0, 64)}`)) * 2;
|
|
64
|
+
const len = Number(BigInt(`0x${h.slice(off, off + 64)}`));
|
|
65
|
+
if (len < 200)
|
|
66
|
+
return Buffer.from(h.slice(off + 64, off + 64 + len * 2), 'hex').toString('utf8').replace(/\0/g, '').trim() || null;
|
|
67
|
+
}
|
|
68
|
+
if (h.length === 64)
|
|
69
|
+
return Buffer.from(h, 'hex').toString('utf8').replace(/\0/g, '').trim() || null;
|
|
70
|
+
}
|
|
71
|
+
catch { }
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
function rpcUrl(c) {
|
|
75
|
+
return c.key === 'robinhood' ? key('ROBINHOOD_PUBLIC_RPC_URL') ?? null : c.rpc;
|
|
76
|
+
}
|
|
77
|
+
export async function rpcCall(ctx, c, method, params, ttlSec = 60) {
|
|
78
|
+
const url = rpcUrl(c);
|
|
79
|
+
const source = `rpc-${c.key}`;
|
|
80
|
+
if (!url)
|
|
81
|
+
return { data: null, prov: { source, url: 'rpc', status: 'UNAVAILABLE', fetchedAt: ctx.now().toISOString(), note: 'no RPC configured for this chain' } };
|
|
82
|
+
const r = await postJson(ctx, url, { jsonrpc: '2.0', id: 1, method, params }, {}, source, ttlSec);
|
|
83
|
+
const failed = !r.data || (r.data.error && !/execution reverted|invalid opcode|out of gas/i.test(r.data.error.message));
|
|
84
|
+
// The public endpoint is down or refuses: ask Alchemy instead when a key is set.
|
|
85
|
+
const ak = key('ALCHEMY_API_KEY');
|
|
86
|
+
if (failed && c.alchemy && ak) {
|
|
87
|
+
const a = await postJson(ctx, `https://${c.alchemy}.g.alchemy.com/v2/${ak}`, { jsonrpc: '2.0', id: 1, method, params }, {}, `alchemy-${c.key}`, ttlSec);
|
|
88
|
+
const prov = { ...a.prov, url: a.prov.url.replace(/\/v2\/[^/?]+/, '/v2/***') };
|
|
89
|
+
if (a.data && !a.data.error)
|
|
90
|
+
return { data: a.data.result ?? null, prov };
|
|
91
|
+
}
|
|
92
|
+
if (r.data?.error)
|
|
93
|
+
return { data: null, prov: { ...r.prov, status: 'ERROR', note: r.data.error.message.slice(0, 120) } };
|
|
94
|
+
return { data: r.data?.result ?? null, prov: r.prov };
|
|
95
|
+
}
|
|
96
|
+
export const ethCall = (ctx, c, to, data, ttlSec = 60) => rpcCall(ctx, c, 'eth_call', [{ to, data }, 'latest'], ttlSec);
|
|
97
|
+
export async function codeAt(ctx, c, a) {
|
|
98
|
+
return (await rpcCall(ctx, c, 'eth_getCode', [a, 'latest'], 3600)).data;
|
|
99
|
+
}
|
|
100
|
+
/** name, symbol and decimals of a token; null fields when the call fails. */
|
|
101
|
+
export async function tokenMeta(ctx, c, token) {
|
|
102
|
+
const [n, s, d] = await Promise.all([ethCall(ctx, c, token, '0x06fdde03', 86_400), ethCall(ctx, c, token, '0x95d89b41', 86_400), ethCall(ctx, c, token, '0x313ce567', 86_400)]);
|
|
103
|
+
const dec = d.data && d.data.length >= 66 ? Number(BigInt(d.data.slice(0, 66))) : null;
|
|
104
|
+
return { name: abiString(n.data), symbol: abiString(s.data), decimals: dec !== null && dec <= 36 ? dec : null };
|
|
105
|
+
}
|
|
106
|
+
export function formatUnits(v, decimals, digits = 4) {
|
|
107
|
+
if (v >= UNLIMITED)
|
|
108
|
+
return 'unlimited';
|
|
109
|
+
const d = decimals ?? 18;
|
|
110
|
+
const whole = v / 10n ** BigInt(d);
|
|
111
|
+
const frac = Number(v % 10n ** BigInt(d)) / 10 ** d;
|
|
112
|
+
const n = Number(whole) + frac;
|
|
113
|
+
return n >= 1e9 ? `${(n / 1e9).toFixed(2)}B` : n >= 1e6 ? `${(n / 1e6).toFixed(2)}M` : n.toLocaleString('en-US', { maximumFractionDigits: n < 1 ? 6 : digits });
|
|
114
|
+
}
|
|
115
|
+
/** Etherscan-style explorer API: Etherscan v2 or Blockscout, whichever covers the chain for free. */
|
|
116
|
+
export async function etherscan(ctx, c, params, ttlSec = 600) {
|
|
117
|
+
const k = scanKey(c);
|
|
118
|
+
const qs = Object.entries(params).map(([a, b]) => `${a}=${enc(b)}`).join('&');
|
|
119
|
+
const source = c.scan === 'blockscout' ? 'blockscout' : 'etherscan';
|
|
120
|
+
const url = c.scan === 'blockscout' ? `https://api.blockscout.com/${c.id}/api?${qs}` : `https://api.etherscan.io/v2/api?chainid=${c.id}&${qs}`;
|
|
121
|
+
if (!c.scan)
|
|
122
|
+
return { data: null, prov: { source, url, status: 'UNAVAILABLE', fetchedAt: ctx.now().toISOString(), note: `no free explorer API covers ${c.label}` } };
|
|
123
|
+
if (!k)
|
|
124
|
+
return { data: null, prov: { source, url, status: 'UNAVAILABLE', fetchedAt: ctx.now().toISOString(), note: `set ${c.scan === 'blockscout' ? 'BLOCKSCOUT_API_KEY' : 'ETHERSCAN_API_KEY'} (free)` } };
|
|
125
|
+
const r = await ctx.http.get(`${url}&apikey=${k}`, { source, ttlSec });
|
|
126
|
+
const prov = { ...r.prov, url: r.prov.url.replace(/apikey=[^&]+/, 'apikey=***') };
|
|
127
|
+
const res = r.data?.result;
|
|
128
|
+
if (typeof res === 'string' || res === undefined) {
|
|
129
|
+
// "No records found" style answers are an empty list, not a failure.
|
|
130
|
+
if (/no (transactions|records|logs) found/i.test(r.data?.message ?? '') || /no (transactions|records|logs) found/i.test(String(res ?? '')))
|
|
131
|
+
return { data: [], prov };
|
|
132
|
+
return { data: null, prov: { ...prov, status: r.data ? 'ERROR' : prov.status, note: String(res ?? r.data?.message ?? prov.note ?? '').slice(0, 120) } };
|
|
133
|
+
}
|
|
134
|
+
return { data: res, prov };
|
|
135
|
+
}
|
|
136
|
+
export const esLogs = (ctx, c, topic0, topic1) => etherscan(ctx, c, { module: 'logs', action: 'getLogs', fromBlock: '0', toBlock: 'latest', topic0, topic1, topic0_1_opr: 'and', page: '1', offset: '1000' }, 600);
|
|
137
|
+
/** Where a chain's transfer history comes from: an explorer API, or Alchemy's transfers API. */
|
|
138
|
+
export const historySource = (c) => (c.scan && scanKey(c) ? 'explorer' : c.alchemy && key('ALCHEMY_API_KEY') ? 'alchemy' : null);
|
|
139
|
+
export const esTokenTx = (ctx, c, address, n = 200) => historySource(c) === 'alchemy'
|
|
140
|
+
? alchemyTransfers(ctx, c, address, ['erc20'], n).then((r) => ({ data: r.data, prov: r.prov }))
|
|
141
|
+
: etherscan(ctx, c, { module: 'account', action: 'tokentx', address, page: '1', offset: String(n), sort: 'desc' }, 600);
|
|
142
|
+
/** Transactions of an address. From Alchemy only value transfers are listed (no zero-value contract calls). */
|
|
143
|
+
export const esTxList = (ctx, c, address, n = 100, sort = 'desc') => historySource(c) === 'alchemy'
|
|
144
|
+
? alchemyTransfers(ctx, c, address, ['external'], n, sort).then((r) => ({ data: r.data, prov: r.prov }))
|
|
145
|
+
: etherscan(ctx, c, { module: 'account', action: 'txlist', address, page: '1', offset: String(n), sort }, 600);
|
|
146
|
+
/**
|
|
147
|
+
* Transfers in and out of an address (alchemy_getAssetTransfers), shaped like Etherscan's tokentx / txlist rows,
|
|
148
|
+
* newest first. Two requests: one for each direction.
|
|
149
|
+
*/
|
|
150
|
+
export async function alchemyTransfers(ctx, c, address, category, n = 200, sort = 'desc') {
|
|
151
|
+
const k = key('ALCHEMY_API_KEY');
|
|
152
|
+
const url = `https://${c.alchemy}.g.alchemy.com/v2/${k}`;
|
|
153
|
+
const shown = url.replace(/\/v2\/.*$/, '/v2/***');
|
|
154
|
+
if (!k || !c.alchemy)
|
|
155
|
+
return { data: null, prov: { source: 'alchemy', url: shown, status: 'UNAVAILABLE', fetchedAt: ctx.now().toISOString(), note: 'set ALCHEMY_API_KEY (free)' } };
|
|
156
|
+
const max = `0x${Math.min(1000, n).toString(16)}`;
|
|
157
|
+
const q = (dir) => postJson(ctx, url, { jsonrpc: '2.0', id: 1, method: 'alchemy_getAssetTransfers', params: [{ [dir]: address, category, maxCount: max, order: sort, withMetadata: true, excludeZeroValue: false }] }, {}, `alchemy-${c.key}`, 600);
|
|
158
|
+
const [a, b] = await Promise.all([q('fromAddress'), q('toAddress')]);
|
|
159
|
+
const prov = { ...a.prov, url: shown };
|
|
160
|
+
if (!a.data?.result && !b.data?.result)
|
|
161
|
+
return { data: null, prov: { ...prov, status: 'ERROR', note: (a.data?.error ?? b.data?.error)?.message?.slice(0, 120) ?? prov.note } };
|
|
162
|
+
const rows = [...(a.data?.result?.transfers ?? []), ...(b.data?.result?.transfers ?? [])].map((t) => {
|
|
163
|
+
const raw = t.rawContract?.value ?? '0x0';
|
|
164
|
+
const dec = t.rawContract?.decimal ? String(Number(BigInt(t.rawContract.decimal))) : '18';
|
|
165
|
+
return { hash: t.hash, timeStamp: String(Math.floor(Date.parse(t.metadata?.blockTimestamp ?? '1970-01-01') / 1000)), from: t.from, to: t.to ?? '', value: BigInt(raw || '0x0').toString(), contractAddress: t.category === 'external' ? '' : (t.rawContract?.address ?? ''), tokenSymbol: t.asset ?? '', tokenName: t.asset ?? '', tokenDecimal: dec, isError: '0' };
|
|
166
|
+
});
|
|
167
|
+
const seen = new Set();
|
|
168
|
+
const uniq = rows.filter((r) => { const id = `${r.hash}|${r.from}|${r.to}|${r.contractAddress}|${r.value}`; if (seen.has(id))
|
|
169
|
+
return false; seen.add(id); return true; });
|
|
170
|
+
uniq.sort((x, y) => (sort === 'desc' ? Number(y.timeStamp) - Number(x.timeStamp) : Number(x.timeStamp) - Number(y.timeStamp)));
|
|
171
|
+
return { data: uniq.slice(0, n), prov };
|
|
172
|
+
}
|
|
173
|
+
/** Alchemy marks NFT collections it considers spam. Null when unknown or without a key. */
|
|
174
|
+
export async function alchemyIsSpam(ctx, c, contract) {
|
|
175
|
+
const k = key('ALCHEMY_API_KEY');
|
|
176
|
+
if (!k || !c.alchemy)
|
|
177
|
+
return null;
|
|
178
|
+
const r = await ctx.http.get(`https://${c.alchemy}.g.alchemy.com/nft/v3/${k}/isSpamContract?contractAddress=${contract}`, { source: `alchemy-${c.key}`, ttlSec: 86_400, retries: 0 });
|
|
179
|
+
return typeof r.data?.isSpamContract === 'boolean' ? r.data.isSpamContract : null;
|
|
180
|
+
}
|
|
181
|
+
/** USD prices of tokens on a chain (Alchemy Prices API), by lower-case address. */
|
|
182
|
+
export async function alchemyPrices(ctx, c, tokens) {
|
|
183
|
+
const out = new Map();
|
|
184
|
+
const k = key('ALCHEMY_API_KEY');
|
|
185
|
+
if (!k || !c.alchemy || !tokens.length)
|
|
186
|
+
return out;
|
|
187
|
+
for (let i = 0; i < tokens.length && i < 75; i += 25) {
|
|
188
|
+
const r = await postJson(ctx, `https://api.g.alchemy.com/prices/v1/${k}/tokens/by-address`, { addresses: tokens.slice(i, i + 25).map((address) => ({ network: c.alchemy, address })) }, {}, 'alchemy-prices', 900);
|
|
189
|
+
for (const d of r.data?.data ?? []) {
|
|
190
|
+
const v = Number(d.prices?.[0]?.value);
|
|
191
|
+
if (Number.isFinite(v) && v > 0)
|
|
192
|
+
out.set(d.address.toLowerCase(), v);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
return out;
|
|
196
|
+
}
|
|
197
|
+
export async function sourcify(ctx, c, a) {
|
|
198
|
+
const r = await ctx.http.get(`https://sourcify.dev/server/v2/contract/${c.id}/${a}?fields=abi,compilation,proxyResolution`, { source: 'sourcify', ttlSec: 86_400, retries: 1 });
|
|
199
|
+
if (!r.data?.abi)
|
|
200
|
+
return { data: null, prov: r.prov.note === 'HTTP 404' ? { ...r.prov, status: 'LIVE', note: 'not verified on Sourcify' } : r.prov };
|
|
201
|
+
const p = r.data.proxyResolution;
|
|
202
|
+
return {
|
|
203
|
+
data: { name: r.data.compilation?.name ?? null, abi: r.data.abi, compiler: r.data.compilation?.compilerVersion ?? null, proxy: p ? { isProxy: Boolean(p.isProxy), type: p.proxyType ?? null, implementations: (p.implementations ?? []).map((i) => ({ address: i.address, name: i.name ?? null })) } : null, source: 'sourcify' },
|
|
204
|
+
prov: r.prov,
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
/** Verified source from Etherscan (Ethereum, Arbitrum, Polygon on the free plan). */
|
|
208
|
+
export async function etherscanSource(ctx, c, a) {
|
|
209
|
+
if (!chainCan(c, 'logs'))
|
|
210
|
+
return { data: null, prov: { source: 'etherscan', url: 'https://api.etherscan.io/v2/api', status: 'UNAVAILABLE', fetchedAt: ctx.now().toISOString(), note: `no free explorer API for ${c.label}` } };
|
|
211
|
+
const r = await etherscan(ctx, c, { module: 'contract', action: 'getsourcecode', address: a }, 86_400);
|
|
212
|
+
const d = r.data?.[0];
|
|
213
|
+
if (!d?.ABI || !d.ABI.startsWith('['))
|
|
214
|
+
return { data: null, prov: d ? { ...r.prov, note: 'not verified on Etherscan' } : r.prov };
|
|
215
|
+
let abi = [];
|
|
216
|
+
try {
|
|
217
|
+
abi = JSON.parse(d.ABI);
|
|
218
|
+
}
|
|
219
|
+
catch { }
|
|
220
|
+
return { data: { name: d.ContractName || null, abi, compiler: d.CompilerVersion || null, proxy: d.Proxy === '1' ? { isProxy: true, type: null, implementations: d.Implementation ? [{ address: d.Implementation, name: null }] : [] } : null, source: 'etherscan' }, prov: r.prov };
|
|
221
|
+
}
|
|
222
|
+
/** Function selectors pushed in deployed bytecode (PUSH4 operands), for contracts without verified source. */
|
|
223
|
+
export function bytecodeSelectors(code) {
|
|
224
|
+
const h = code.replace(/^0x/, '');
|
|
225
|
+
const out = new Set();
|
|
226
|
+
for (let i = 0; i < h.length; i += 2) {
|
|
227
|
+
const op = parseInt(h.slice(i, i + 2), 16);
|
|
228
|
+
if (op === 0x63)
|
|
229
|
+
out.add(`0x${h.slice(i + 2, i + 10)}`);
|
|
230
|
+
if (op >= 0x60 && op <= 0x7f)
|
|
231
|
+
i += (op - 0x5f) * 2;
|
|
232
|
+
}
|
|
233
|
+
return [...out].filter((s) => s.length === 10 && s !== '0xffffffff' && s !== '0x00000000');
|
|
234
|
+
}
|
|
235
|
+
/** Names of well known spenders and routers, so an approval to them reads as what it is. */
|
|
236
|
+
export const KNOWN = {
|
|
237
|
+
'0x000000000022d473030f116ddee9f6b43ac78ba3': 'Uniswap Permit2',
|
|
238
|
+
'0x3fc91a3afd70395cd496c647d5a6cc9d4b2b7fad': 'Uniswap Universal Router',
|
|
239
|
+
'0x66a9893cc07d91d95644aedd05d03f95e1dba8af': 'Uniswap Universal Router (v4)',
|
|
240
|
+
'0xef1c6e67703c7bd7107eed8303fbe6ec2554bf6b': 'Uniswap Universal Router (old)',
|
|
241
|
+
'0x7a250d5630b4cf539739df2c5dacb4c659f2488d': 'Uniswap V2 Router',
|
|
242
|
+
'0xe592427a0aece92de3edee1f18e0157c05861564': 'Uniswap V3 Router',
|
|
243
|
+
'0x68b3465833fb72a70ecdf485e0e4c7bd8665fc45': 'Uniswap V3 Router 02',
|
|
244
|
+
'0x1111111254eeb25477b68fb85ed929f73a960582': '1inch Router v5',
|
|
245
|
+
'0x111111125421ca6dc452d289314280a0f8842a65': '1inch Router v6',
|
|
246
|
+
'0xdef1c0ded9bec7f1a1670819833240f027b25eff': '0x Exchange Proxy',
|
|
247
|
+
'0xc92e8bdf79f0507f65a392b0ab4667716bfe0110': 'CoW Protocol Vault Relayer',
|
|
248
|
+
'0x0000000000000068f116a894984e2db1123eb395': 'OpenSea Seaport 1.6',
|
|
249
|
+
'0x00000000000000adc04c56bf30ac9d3c0aaf14dc': 'OpenSea Seaport 1.5',
|
|
250
|
+
'0x1e0049783f008a0085193e00003d00cd54003c71': 'OpenSea Conduit',
|
|
251
|
+
'0xd9e1ce17f2641f24ae83637ab66a2cca9c378b9f': 'SushiSwap Router',
|
|
252
|
+
'0x881d40237659c251811cec9c364ef91dc08d300c': 'MetaMask Swap Router',
|
|
253
|
+
'0x6131b5fae19ea4f9d964eac0408e4408b66337b5': 'KyberSwap Router',
|
|
254
|
+
'0x87870bca3f3fd6335c3f4ce8392d69350b4fa4e2': 'Aave V3 Pool',
|
|
255
|
+
'0x7d2768de32b0b80b7a3454c06bdac94a69ddc7a9': 'Aave V2 Pool',
|
|
256
|
+
'0xba12222222228d8ba445958a75a0704d566bf2c8': 'Balancer Vault',
|
|
257
|
+
'0x9008d19f58aabd9ed0d60971565aa8510560ab41': 'CoW Protocol Settlement',
|
|
258
|
+
'0x00000000006c3852cbef3e08e8df289169ede581': 'OpenSea Seaport 1.1',
|
|
259
|
+
};
|
|
260
|
+
export const labelOf = (a) => KNOWN[a.toLowerCase()] ?? null;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Open phishing blocklists, kept in the local database and refreshed once a day (no keys):
|
|
3
|
+
* ScamSniffer scam-database: about 358k crypto phishing and wallet drainer domains (published with a 7-day
|
|
4
|
+
* delay), plus its older list of scam addresses (no longer updated since 2024).
|
|
5
|
+
* MetaMask eth-phishing-detect: the blocklist MetaMask uses to warn wallet users, and its allowlist of real
|
|
6
|
+
* sites, which keeps well known domains from being flagged by lookalike rules.
|
|
7
|
+
* Lookups are offline: a domain matches when it or any parent domain is listed.
|
|
8
|
+
*/
|
|
9
|
+
import type { Ctx } from '../core/context.js';
|
|
10
|
+
import type { Provenance } from '../core/types.js';
|
|
11
|
+
/** Replace one list's rows in a single transaction. */
|
|
12
|
+
export declare function loadPhishList(ctx: Ctx, table: 'phish_domains' | 'phish_addresses' | 'phish_allow', source: string, values: string[]): number;
|
|
13
|
+
/** Make sure the lists are present and at most a day old. */
|
|
14
|
+
export declare function ensurePhishLists(ctx: Ctx): Promise<Provenance[]>;
|
|
15
|
+
/** Which blocklists list this host (or a parent domain), unless the allowlist names it. */
|
|
16
|
+
export declare function phishDomain(ctx: Ctx, host: string): {
|
|
17
|
+
listed: string[];
|
|
18
|
+
allowed: boolean;
|
|
19
|
+
};
|
|
20
|
+
export declare function phishAddress(ctx: Ctx, address: string): string | null;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
const SOURCES = {
|
|
2
|
+
scamsnifferDomains: 'https://raw.githubusercontent.com/scamsniffer/scam-database/main/blacklist/domains.json',
|
|
3
|
+
scamsnifferAddresses: 'https://raw.githubusercontent.com/scamsniffer/scam-database/main/blacklist/address.json',
|
|
4
|
+
metamask: 'https://raw.githubusercontent.com/MetaMask/eth-phishing-detect/main/src/config.json',
|
|
5
|
+
};
|
|
6
|
+
const REFRESH_MS = 24 * 3600_000;
|
|
7
|
+
const LOADED = 'derived:phishlists:loaded';
|
|
8
|
+
function ensureTables(ctx) {
|
|
9
|
+
ctx.store.db.exec(`CREATE TABLE IF NOT EXISTS phish_domains (domain TEXT NOT NULL, source TEXT NOT NULL, PRIMARY KEY (domain, source));
|
|
10
|
+
CREATE TABLE IF NOT EXISTS phish_addresses (address TEXT NOT NULL PRIMARY KEY, source TEXT NOT NULL);
|
|
11
|
+
CREATE TABLE IF NOT EXISTS phish_allow (domain TEXT NOT NULL PRIMARY KEY)`);
|
|
12
|
+
}
|
|
13
|
+
/** Replace one list's rows in a single transaction. */
|
|
14
|
+
export function loadPhishList(ctx, table, source, values) {
|
|
15
|
+
ensureTables(ctx);
|
|
16
|
+
const db = ctx.store.db;
|
|
17
|
+
const col = table === 'phish_addresses' ? 'address' : 'domain';
|
|
18
|
+
db.exec('BEGIN');
|
|
19
|
+
try {
|
|
20
|
+
if (table === 'phish_allow')
|
|
21
|
+
db.exec('DELETE FROM phish_allow');
|
|
22
|
+
else
|
|
23
|
+
db.prepare(`DELETE FROM ${table} WHERE source = ?`).run(source);
|
|
24
|
+
const ins = table === 'phish_allow' ? db.prepare('INSERT OR IGNORE INTO phish_allow (domain) VALUES (?)') : db.prepare(`INSERT OR IGNORE INTO ${table} (${col}, source) VALUES (?, ?)`);
|
|
25
|
+
let n = 0;
|
|
26
|
+
for (const v of values) {
|
|
27
|
+
const x = String(v).trim().toLowerCase();
|
|
28
|
+
if (!x || x.length > 253)
|
|
29
|
+
continue;
|
|
30
|
+
if (table === 'phish_allow')
|
|
31
|
+
ins.run(x);
|
|
32
|
+
else
|
|
33
|
+
ins.run(x, source);
|
|
34
|
+
n++;
|
|
35
|
+
}
|
|
36
|
+
db.exec('COMMIT');
|
|
37
|
+
return n;
|
|
38
|
+
}
|
|
39
|
+
catch (e) {
|
|
40
|
+
db.exec('ROLLBACK');
|
|
41
|
+
throw e;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
/** Make sure the lists are present and at most a day old. */
|
|
45
|
+
export async function ensurePhishLists(ctx) {
|
|
46
|
+
ensureTables(ctx);
|
|
47
|
+
const loaded = ctx.store.cacheGet(LOADED);
|
|
48
|
+
if (loaded && ctx.now().getTime() - loaded.fetchedAt < REFRESH_MS)
|
|
49
|
+
return [{ source: 'phishing-lists', url: SOURCES.scamsnifferDomains, status: 'CACHED', fetchedAt: new Date(loaded.fetchedAt).toISOString(), note: loaded.body }];
|
|
50
|
+
const out = [];
|
|
51
|
+
const counts = [];
|
|
52
|
+
const get = async (url, source) => {
|
|
53
|
+
const r = await ctx.http.get(url, { source, ttlSec: 0, timeoutMs: 120_000, retries: 1 });
|
|
54
|
+
out.push(r.prov);
|
|
55
|
+
ctx.store.db.prepare('DELETE FROM cache WHERE key = ?').run(url);
|
|
56
|
+
return r.data;
|
|
57
|
+
};
|
|
58
|
+
const sd = await get(SOURCES.scamsnifferDomains, 'scamsniffer');
|
|
59
|
+
if (Array.isArray(sd))
|
|
60
|
+
counts.push(`${loadPhishList(ctx, 'phish_domains', 'scamsniffer', sd)} ScamSniffer domains`);
|
|
61
|
+
const sa = await get(SOURCES.scamsnifferAddresses, 'scamsniffer');
|
|
62
|
+
if (Array.isArray(sa))
|
|
63
|
+
counts.push(`${loadPhishList(ctx, 'phish_addresses', 'scamsniffer', sa.filter((a) => /^0x[0-9a-f]{40}$/i.test(a)))} ScamSniffer addresses`);
|
|
64
|
+
const mm = await get(SOURCES.metamask, 'metamask-phishing');
|
|
65
|
+
if (mm?.blacklist)
|
|
66
|
+
counts.push(`${loadPhishList(ctx, 'phish_domains', 'metamask', mm.blacklist)} MetaMask blocked domains`);
|
|
67
|
+
if (mm?.whitelist)
|
|
68
|
+
loadPhishList(ctx, 'phish_allow', 'metamask', mm.whitelist);
|
|
69
|
+
if (counts.length)
|
|
70
|
+
ctx.store.cachePut(LOADED, counts.join(', '), ctx.now().getTime());
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
/** The domain itself and each parent domain: a.b.example.com -> [a.b.example.com, b.example.com, example.com]. */
|
|
74
|
+
const parents = (host) => { const p = host.toLowerCase().replace(/\.$/, '').split('.'); return p.slice(0, -1).map((_, i) => p.slice(i).join('.')); };
|
|
75
|
+
/** Which blocklists list this host (or a parent domain), unless the allowlist names it. */
|
|
76
|
+
export function phishDomain(ctx, host) {
|
|
77
|
+
ensureTables(ctx);
|
|
78
|
+
const ps = parents(host);
|
|
79
|
+
if (!ps.length)
|
|
80
|
+
return { listed: [], allowed: false };
|
|
81
|
+
const q = ps.map(() => '?').join(',');
|
|
82
|
+
const allowed = Boolean(ctx.store.db.prepare(`SELECT 1 FROM phish_allow WHERE domain IN (${q}) LIMIT 1`).get(...ps));
|
|
83
|
+
const rows = ctx.store.db.prepare(`SELECT DISTINCT source FROM phish_domains WHERE domain IN (${q})`).all(...ps);
|
|
84
|
+
return { listed: allowed ? [] : rows.map((r) => (r.source === 'metamask' ? 'MetaMask phishing list' : 'ScamSniffer blocklist')), allowed };
|
|
85
|
+
}
|
|
86
|
+
export function phishAddress(ctx, address) {
|
|
87
|
+
ensureTables(ctx);
|
|
88
|
+
const r = ctx.store.db.prepare('SELECT source FROM phish_addresses WHERE address = ?').get(address.toLowerCase());
|
|
89
|
+
return r ? 'ScamSniffer scam address list' : null;
|
|
90
|
+
}
|
package/dist/telegram.d.ts
CHANGED
|
@@ -28,6 +28,16 @@ interface Update {
|
|
|
28
28
|
from?: {
|
|
29
29
|
username?: string;
|
|
30
30
|
};
|
|
31
|
+
photo?: {
|
|
32
|
+
file_id: string;
|
|
33
|
+
file_size?: number;
|
|
34
|
+
}[];
|
|
35
|
+
document?: {
|
|
36
|
+
file_id: string;
|
|
37
|
+
file_name?: string;
|
|
38
|
+
mime_type?: string;
|
|
39
|
+
file_size?: number;
|
|
40
|
+
};
|
|
31
41
|
};
|
|
32
42
|
callback_query?: {
|
|
33
43
|
id: string;
|
|
@@ -92,6 +102,13 @@ export declare class TelegramBot {
|
|
|
92
102
|
/** A tap on Useful / Noise under an alert. */
|
|
93
103
|
handleCallback(q: NonNullable<Update['callback_query']>): Promise<void>;
|
|
94
104
|
handle(u: Update): Promise<void>;
|
|
105
|
+
/**
|
|
106
|
+
* A file sent to the bot: a QR code, a photo to check for AI or edits, or a document to check for editing.
|
|
107
|
+
* The caption picks the check (/qr, /photo, /doc); without one, documents go to the document check and
|
|
108
|
+
* images are read for a QR code first. Telegram re-compresses photos and drops their metadata, so the
|
|
109
|
+
* AI and edit check needs the image sent as a file.
|
|
110
|
+
*/
|
|
111
|
+
handleFile(m: NonNullable<Update['message']>): Promise<void>;
|
|
95
112
|
/** Push signals the chat has not seen yet. Returns how many were sent. */
|
|
96
113
|
pushAlerts(signals: Signal[]): Promise<number>;
|
|
97
114
|
scanAndAlert(): Promise<number>;
|