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.
Files changed (92) hide show
  1. package/README.md +73 -13
  2. package/dist/cli/main.js +316 -1
  3. package/dist/core/der.d.ts +2 -0
  4. package/dist/core/der.js +17 -0
  5. package/dist/core/http.d.ts +19 -1
  6. package/dist/core/http.js +24 -0
  7. package/dist/core/qr.d.ts +23 -0
  8. package/dist/core/qr.js +577 -0
  9. package/dist/core/quota.js +5 -0
  10. package/dist/core/raster.d.ts +6 -0
  11. package/dist/core/raster.js +298 -0
  12. package/dist/core/safeurl.d.ts +5 -0
  13. package/dist/core/safeurl.js +26 -0
  14. package/dist/core/verdict.js +1 -1
  15. package/dist/core/zip.d.ts +9 -0
  16. package/dist/core/zip.js +46 -0
  17. package/dist/index.d.ts +61 -0
  18. package/dist/index.js +99 -0
  19. package/dist/mcp.js +131 -5
  20. package/dist/modules/address.d.ts +6 -2
  21. package/dist/modules/address.js +32 -5
  22. package/dist/modules/apk.d.ts +37 -0
  23. package/dist/modules/apk.js +191 -0
  24. package/dist/modules/approvals.d.ts +40 -0
  25. package/dist/modules/approvals.js +155 -0
  26. package/dist/modules/archive.d.ts +21 -0
  27. package/dist/modules/archive.js +94 -0
  28. package/dist/modules/checks.js +33 -0
  29. package/dist/modules/contract.d.ts +56 -0
  30. package/dist/modules/contract.js +167 -0
  31. package/dist/modules/deployer.d.ts +42 -0
  32. package/dist/modules/deployer.js +90 -0
  33. package/dist/modules/doc.d.ts +24 -2
  34. package/dist/modules/doc.js +133 -7
  35. package/dist/modules/eml.d.ts +46 -0
  36. package/dist/modules/eml.js +175 -0
  37. package/dist/modules/hashcheck.d.ts +19 -3
  38. package/dist/modules/hashcheck.js +28 -4
  39. package/dist/modules/image.d.ts +32 -0
  40. package/dist/modules/image.js +276 -0
  41. package/dist/modules/invite.d.ts +27 -0
  42. package/dist/modules/invite.js +69 -0
  43. package/dist/modules/job.d.ts +33 -0
  44. package/dist/modules/job.js +64 -0
  45. package/dist/modules/meerkat.d.ts +1 -1
  46. package/dist/modules/meerkat.js +35 -2
  47. package/dist/modules/monitor.js +14 -0
  48. package/dist/modules/poisoning.d.ts +43 -0
  49. package/dist/modules/poisoning.js +114 -0
  50. package/dist/modules/qrcheck.d.ts +24 -0
  51. package/dist/modules/qrcheck.js +136 -0
  52. package/dist/modules/repo.d.ts +61 -0
  53. package/dist/modules/repo.js +162 -0
  54. package/dist/modules/report.d.ts +32 -0
  55. package/dist/modules/report.js +108 -0
  56. package/dist/modules/signature.d.ts +35 -0
  57. package/dist/modules/signature.js +283 -0
  58. package/dist/modules/site.d.ts +62 -0
  59. package/dist/modules/site.js +191 -0
  60. package/dist/modules/stocktoken.d.ts +48 -0
  61. package/dist/modules/stocktoken.js +99 -0
  62. package/dist/modules/trace.d.ts +37 -0
  63. package/dist/modules/trace.js +150 -0
  64. package/dist/modules/txexplain.d.ts +40 -0
  65. package/dist/modules/txexplain.js +135 -0
  66. package/dist/modules/urlcheck.js +15 -1
  67. package/dist/modules/where.d.ts +63 -0
  68. package/dist/modules/where.js +165 -0
  69. package/dist/report-pdf.js +3 -0
  70. package/dist/sources/cfurlscan.d.ts +24 -0
  71. package/dist/sources/cfurlscan.js +46 -0
  72. package/dist/sources/chainabuse.d.ts +17 -0
  73. package/dist/sources/chainabuse.js +19 -0
  74. package/dist/sources/evm.d.ts +135 -0
  75. package/dist/sources/evm.js +260 -0
  76. package/dist/sources/phishlists.d.ts +20 -0
  77. package/dist/sources/phishlists.js +90 -0
  78. package/dist/telegram.d.ts +17 -0
  79. package/dist/telegram.js +151 -4
  80. package/dist/web/docs.html +1 -1
  81. package/dist/web/index.html +147 -11
  82. package/dist/web/landing.html +1 -1
  83. package/dist/web/legal.html +3 -1
  84. package/dist/web/mcp.html +1 -1
  85. package/dist/web/openapi.js +13 -0
  86. package/dist/web/pages.js +2 -2
  87. package/dist/web/public.js +14 -1
  88. package/dist/web/server.d.ts +13 -0
  89. package/dist/web/server.js +77 -12
  90. package/dist/web/token.html +24 -4
  91. package/dist/web/token.json +12 -1
  92. package/package.json +2 -2
package/dist/mcp.js CHANGED
@@ -12,7 +12,7 @@ import { CHECK_TOOLS } from './modules/checks.js';
12
12
  import { DOC_MAX_BYTES } from './modules/doc.js';
13
13
  import { briefOf, verdictOf } from './core/verdict.js';
14
14
  import { CARD_HTML, CARD_URI, CARD_URI_OPENAI, MCP_APP_MIME, SKYBRIDGE_MIME } from './web/card.js';
15
- export const SERVER_INFO = { name: 'oculon', version: '0.1.7' };
15
+ export const SERVER_INFO = { name: 'oculon', version: '0.2.0' };
16
16
  const SUPPORTED = ['2025-06-18', '2025-03-26', '2024-11-05'];
17
17
  const str = (d) => ({ type: 'string', description: d });
18
18
  const num = (d) => ({ type: 'number', description: d });
@@ -379,13 +379,139 @@ export const TOOLS = [
379
379
  },
380
380
  {
381
381
  name: 'oculon_doc_check',
382
- description: 'Was this invoice, bank statement or payment screenshot edited? Reads a PDF, JPEG or PNG: the programs that made and saved it (online PDF editors, image editors), creation vs modification date, how many times it was saved, fonts embedded twice, white boxes over text, annotations, dangerous parts (JavaScript, launch actions), and checks every IBAN in its text. Screenshots are read with a free AI vision model when a key is set. A clean result is not proof the document is genuine.',
382
+ description: 'Was this invoice, bank statement or payment screenshot edited? Reads a PDF, Word, Excel, PowerPoint, JPEG or PNG: macros, remote templates, DDE fields, embedded objects and hidden sheets in Office files, the programs that made and saved it (online PDF editors, image editors), creation vs modification date, how many times it was saved, fonts embedded twice, white boxes over text, annotations, dangerous parts (JavaScript, launch actions), and checks every IBAN in its text. Screenshots are read with a free AI vision model when a key is set. A clean result is not proof the document is genuine.',
383
383
  inputSchema: schema({ data: str('The file as base64 (max 10 MB)'), url: str('Or an https URL of the file'), name: str('File name, for display') }),
384
384
  run: async (o, a) => {
385
385
  const file = await docBytes(o, a);
386
386
  return compact(await o.docCheck(file, a.name ? String(a.name) : a.url ? String(a.url).split('/').pop().split('?')[0] : 'document'));
387
387
  },
388
388
  },
389
+ {
390
+ name: 'oculon_approvals',
391
+ description: 'Who can take tokens out of this wallet right now: every ERC-20 and NFT approval the wallet signed (Etherscan logs), re-read on chain so revoked ones drop out. Spenders are named (Uniswap, 1inch, OpenSea...) or flagged: plain wallets, unverified contracts and unknown contracts with unlimited access. Spam approval events from fake tokens are filtered. Gives a revoke.cash link. Chains: eth, arbitrum, polygon.',
392
+ inputSchema: schema({ address: str('Wallet address (0x...)'), chain: str('eth, arbitrum or polygon (default eth)') }, ['address']),
393
+ run: async (o, a) => compact(await o.approvalsCheck(String(a.address), a.chain ? { chain: String(a.chain) } : {})),
394
+ },
395
+ {
396
+ name: 'oculon_contract_risk',
397
+ description: 'What the owner of a token contract can still do to holders: mint, blacklist, pause trading, change taxes, limit wallets, change balances, upgrade the code (proxy), self-destruct. Read from verified source (Sourcify, Etherscan) or, for unverified contracts, from selectors in the bytecode. Plus current owner (renounced or not), proxy admin and implementation, holder concentration and locked liquidity (GoPlus), main pool and age (DexScreener). Chains: eth, base, bsc, arbitrum, polygon.',
398
+ inputSchema: schema({ address: str('Token contract address (0x...)'), chain: str('eth, base, bsc, arbitrum or polygon (default eth)') }, ['address']),
399
+ run: async (o, a) => compact(await o.contractRisk(String(a.address), a.chain ? { chain: String(a.chain) } : {})),
400
+ },
401
+ {
402
+ name: 'oculon_signature_check',
403
+ description: 'Decode what a wallet signature request really allows before signing: EIP-712 typed data (ERC-2612 and DAI permits, Uniswap Permit2 allowances and transfers, Seaport orders that give NFTs away for nothing), transaction calldata or a {to, data, value} object (approve, setApprovalForAll, transfers, Permit2 approve, multicall bundles, unknown functions named via signature databases), and raw eth_sign hashes. Spenders are looked up on chain (wallet or contract, verified or not).',
404
+ inputSchema: schema({ request: str('The request: typed data JSON, 0x calldata, a {to,data,value} JSON, or the message text'), chain: str('Optional chain: eth, base, bsc, arbitrum, polygon'), to: str('Optional: the contract the calldata is sent to (token address for approve)') }, ['request']),
405
+ run: async (o, a) => compact(await o.signatureCheck(String(a.request), { ...(a.chain ? { chain: String(a.chain) } : {}), ...(a.to ? { to: String(a.to) } : {}) })),
406
+ },
407
+ {
408
+ name: 'oculon_address_poisoning',
409
+ description: 'Has someone planted lookalike addresses in this wallet\'s history? Finds addresses that share the first and last characters with ones the wallet really paid, zero-value transfers it never signed, and fake USDT/USDC tokens, and says whether funds were already sent to a lookalike. Chains: eth, arbitrum, polygon.',
410
+ inputSchema: schema({ address: str('Wallet address (0x...)'), chain: str('eth, arbitrum or polygon (default eth)') }, ['address']),
411
+ run: async (o, a) => compact(await o.poisoningCheck(String(a.address), a.chain ? { chain: String(a.chain) } : {})),
412
+ },
413
+ {
414
+ name: 'oculon_trace_funds',
415
+ description: 'Follow where money went from an address (for example a scammer or a drained wallet): the largest outgoing flows priced in USD, hop by hop, until an exchange (where funds can be frozen), a mixer, a bridge, a contract or a sanctioned address. Labels from the open eth-labels dataset, transaction hashes for a report. Chains: eth, arbitrum, polygon.',
416
+ inputSchema: schema({ address: str('Start address (0x...)'), chain: str('eth, arbitrum or polygon (default eth)'), hops: num('Hops to follow, 1-4 (default 3)') }, ['address']),
417
+ run: async (o, a) => compact(await o.traceFunds(String(a.address), { ...(a.chain ? { chain: String(a.chain) } : {}), ...(a.hops ? { hops: Number(a.hops) } : {}) })),
418
+ },
419
+ {
420
+ name: 'oculon_image_check',
421
+ description: 'Was this image made by AI, edited, or taken with a camera? Reads C2PA Content Credentials (generator app, actions, AI source type, organizations in the signing certificates), IPTC digital source type, generator settings and prompts left by Stable Diffusion, ComfyUI, NovelAI, InvokeAI and Midjourney, EXIF camera data and editing software. Read locally. Missing metadata proves nothing.',
422
+ inputSchema: schema({ data: str('The image as base64 (JPEG, PNG or WebP, max 10 MB)'), url: str('Or an https URL of the image'), name: str('File name, for display') }),
423
+ run: async (o, a) => {
424
+ const file = await docBytes(o, a);
425
+ return compact(await o.imageCheck(file, a.name ? String(a.name) : a.url ? String(a.url).split('/').pop().split('?')[0] : 'image'));
426
+ },
427
+ },
428
+ {
429
+ name: 'oculon_qr_check',
430
+ description: 'Read the QR code in a photo or screenshot (PNG or baseline JPEG, versions 1-15) and check where it leads: links go through the URL check (Safe Browsing, URLhaus, domain age, lookalikes, shorteners), crypto payment codes and addresses through the address check, SEPA payment codes get their IBAN checked, Wi-Fi, SMS and phone codes are explained. Catches fake parking, parcel and login QR codes (quishing).',
431
+ inputSchema: schema({ data: str('The image as base64 (max 10 MB)'), url: str('Or an https URL of the image'), name: str('File name, for display') }),
432
+ run: async (o, a) => {
433
+ const file = await docBytes(o, a);
434
+ return compact(await o.qrCheck(file, a.name ? String(a.name) : 'qr image'));
435
+ },
436
+ },
437
+ {
438
+ name: 'oculon_repo_check',
439
+ description: 'Is this GitHub repository safe to clone and run? Built for fake job tests and "run our bot" scams: install hooks (npm preinstall/postinstall, setup.py, VS Code tasks that run on folder open), code that downloads and runs code, wallet extension and browser password theft, Discord/Telegram webhooks, obfuscation and code hidden past the edge of the screen, committed program files, owner account age and bought stars. Reads files through the GitHub API; nothing is run.',
440
+ inputSchema: schema({ repo: str('owner/name or a github.com link') }, ['repo']),
441
+ run: async (o, a) => compact(await o.repoCheck(String(a.repo))),
442
+ },
443
+ {
444
+ name: 'oculon_domain_report',
445
+ description: 'One report for a domain, all parts run together: link check of the site, email protection (SPF, DKIM, DMARC), what it exposes to the internet (open ports, CVEs), lookalike domains, and the company behind the name. Each part keeps its verdict and sources; PDF report available through the check id.',
446
+ inputSchema: schema({ domain: str('The domain, e.g. "example.com"') }, ['domain']),
447
+ run: async (o, a) => compact(await o.domainReport(String(a.domain))),
448
+ },
449
+ {
450
+ name: 'oculon_wallet_report',
451
+ description: 'One report for a wallet or token address. Wallet: address check (sanctions, activity), active approvals, address poisoning and where funds went. Token contract: contract risk, sell simulation and address check. PDF report available through the check id.',
452
+ inputSchema: schema({ address: str('Wallet or token address (0x...)'), chain: str('eth, arbitrum, polygon, base or bsc (default eth)') }, ['address']),
453
+ run: async (o, a) => compact(await o.walletReport(String(a.address), a.chain ? { chain: String(a.chain) } : {})),
454
+ },
455
+ {
456
+ name: 'oculon_site_check',
457
+ description: 'Open a web page and look for wallet drainers and phishing: wallet connection code next to permit, Permit2, setApprovalForAll or unlimited approve requests, a receiver address written into the script, token-balance APIs used to rank what to take, known drainer kits, seed phrase and login forms on the wrong domain, forms posting elsewhere, Telegram bot tokens and Discord webhooks in the code, lookalikes of known apps, plus the link check of the final address. Scripts are read, never run.',
458
+ inputSchema: schema({ url: str('The page link') }, ['url']),
459
+ run: async (o, a) => compact(await o.siteCheck(String(a.url))),
460
+ },
461
+ {
462
+ name: 'oculon_tx_explain',
463
+ description: 'Explain a transaction in plain words: who called what, every token and NFT transfer, approvals given or removed, and the fee. Flags tokens taken from a wallet in a transaction it did not send (an earlier approval or permit being used), approvals to plain wallets or unverified contracts, and NFT collections handed over. Spam tokens faking transfers are recognized. Chains: eth, base, arbitrum, bsc, polygon (found automatically).',
464
+ inputSchema: schema({ hash: str('Transaction hash or explorer link'), chain: str('Optional: eth, base, arbitrum, bsc, polygon') }, ['hash']),
465
+ run: async (o, a) => compact(await o.explainTx(String(a.hash), a.chain ? { chain: String(a.chain) } : {})),
466
+ },
467
+ {
468
+ name: 'oculon_token_creator',
469
+ description: 'Who created this token and what is their record: the creator wallet and date, the other contracts it deployed, which of those tokens are dead today (no pool or under $1,000 of liquidity), its wallet age, and who first funded it (exchange or mixer, from eth-labels). Chains: eth, arbitrum, polygon.',
470
+ inputSchema: schema({ address: str('Token contract address (0x...)'), chain: str('eth, arbitrum or polygon (default eth)') }, ['address']),
471
+ run: async (o, a) => compact(await o.creatorCheck(String(a.address), a.chain ? { chain: String(a.chain) } : {})),
472
+ },
473
+ {
474
+ name: 'oculon_email_file',
475
+ description: 'Check a whole email file (.eml): SPF, DKIM, DMARC and spoofing in the headers, the message and every link through the scam check, and each attachment through the document check (PDF, Office), the QR reader and image check (images), or the malware hash lookup. Flags risky attachment types (programs, scripts, HTML, disk images).',
476
+ inputSchema: schema({ data: str('The file as base64 (max 10 MB)'), url: str('Or an https URL of the file'), name: str('File name, for display') }, []),
477
+ run: async (o, a) => compact(await o.emlCheck(await docBytes(o, a), a.name ? String(a.name) : 'email.eml')),
478
+ },
479
+ {
480
+ name: 'oculon_apk_check',
481
+ description: 'Is this Android app (APK) safe to install? Reads its manifest: package, version, every permission, and the ones banking trojans use (reading SMS codes, accessibility services, drawing over other apps, notification access, device admin, installing other apps); the signing certificate (debug keys flagged); and the SHA-256 in malware databases. Nothing is installed or run.',
482
+ inputSchema: schema({ data: str('The APK as base64 (max 10 MB here; the CLI takes up to 40 MB)'), url: str('Or an https URL of the APK'), name: str('File name') }, []),
483
+ run: async (o, a) => compact(await o.apkCheck(await docBytes(o, a), a.name ? String(a.name) : 'app.apk')),
484
+ },
485
+ {
486
+ name: 'oculon_job_check',
487
+ description: 'Is this job offer a scam? Matches the patterns of job scams in the message (fees before you start, paid tasks you top up, crypto pay, pay that does not fit the work, contact only through WhatsApp or Telegram, no interview, early requests for ID or bank details, check-cashing, coding test tasks that ask you to run a repo), checks every link and the sender, and runs the repo check on any GitHub link.',
488
+ inputSchema: schema({ message: str('The job message or email text') }, ['message']),
489
+ run: async (o, a) => compact(await o.jobCheck(String(a.message))),
490
+ },
491
+ {
492
+ name: 'oculon_photo_location',
493
+ description: 'Where and when was this photo taken? GPS position and capture time from its EXIF data, the place name (OpenStreetMap), and the weather and daylight at that place and hour (Open-Meteo, sun position), so claims about a photo can be checked. Flags capture and GPS times that disagree. EXIF can be edited.',
494
+ inputSchema: schema({ data: str('The file as base64 (max 10 MB)'), url: str('Or an https URL of the file'), name: str('File name, for display') }, []),
495
+ run: async (o, a) => compact(await o.whereCheck(await docBytes(o, a), a.name ? String(a.name) : 'photo.jpg')),
496
+ },
497
+ {
498
+ name: 'oculon_archive',
499
+ description: 'Save a web page as evidence: asks the Wayback Machine to save it now and records the page status, final address, title and SHA-256 of what was served. Falls back to the newest existing snapshot when saving fails.',
500
+ inputSchema: schema({ url: str('The page link') }, ['url']),
501
+ run: async (o, a) => compact(await o.archivePage(String(a.url))),
502
+ },
503
+ {
504
+ name: 'oculon_invite_check',
505
+ description: 'What is behind a Telegram (t.me) or Discord (discord.gg) invite before joining: name, members and online, verified badge, Telegram scam or fake labels, server creation date, and the fake support or fake project pattern (brand plus "official", "support", "airdrop" without a verified badge).',
506
+ inputSchema: schema({ link: str('The invite link') }, ['link']),
507
+ run: async (o, a) => compact(await o.inviteCheck(String(a.link))),
508
+ },
509
+ {
510
+ name: 'oculon_stock_token',
511
+ description: 'Robinhood Stock Tokens (tokenized shares on Robinhood Chain), from Robinhood\'s official API. A ticker (TSLA) gives the official contract, ISIN, which sessions trade, the live bid and ask per token (adjusted by the corporate-action multiplier), daily range, volume, supply on chain, and upcoming dividends and splits. An address says whether it is an official Stock Token, and flags tokens that copy a ticker or call themselves Robinhood tokens without being on the list. Empty: the list size and upcoming corporate actions.',
512
+ inputSchema: schema({ query: str('A ticker (TSLA), a token address (0x...), or empty for the overview') }),
513
+ run: async (o, a) => compact(await o.stockToken(a.query ? String(a.query) : '')),
514
+ },
389
515
  {
390
516
  name: 'oculon_replay',
391
517
  description: 'Replay log of an earlier check by its check id: the verdict, what changed since the check before it, and every source called in order with status and time.',
@@ -558,7 +684,7 @@ export const TOOLS = [
558
684
  },
559
685
  {
560
686
  name: 'oculon_watch_add',
561
- description: `Add a watchlist target. Kinds: company, domain, plane, topic, lights (place), air (place), port (place, anchored-vessel queue), news (keyword), outage (country), cve (vendor or product), quake ("place|min magnitude"), hazard (country or storm name), url, package ("npm:name" or "pypi:name"), travel (place)${onchainEnabled() ? ', wallet, token (address or address@chain)' : ''}. For plain-language requests use oculon_monitor.`,
687
+ description: `Add a watchlist target. Kinds: company, domain, plane, topic, lights (place), air (place), port (place, anchored-vessel queue), news (keyword), outage (country), cve (vendor or product), quake ("place|min magnitude"), hazard (country or storm name), url, package ("npm:name" or "pypi:name"), travel (place), approvals (wallet address or address@chain: new approvals), contract (token address or address@chain: owner, upgrade and liquidity changes)${onchainEnabled() ? ', wallet, token (address or address@chain)' : ''}. For plain-language requests use oculon_monitor.`,
562
688
  inputSchema: schema({ kind: { type: 'string', enum: availableKinds() }, target: str('What to watch'), label: str('Optional display name') }, ['kind', 'target']),
563
689
  run: (o, a) => o.watchAdd(String(a.kind), String(a.target), a.label ? String(a.label) : undefined),
564
690
  },
@@ -833,8 +959,8 @@ export class McpServer {
833
959
  let check = null;
834
960
  if (ck) {
835
961
  // Checks are kept: a check id, a replay log, and what changed since the last check of the same thing.
836
- const target = name === 'oculon_doc_check' ? String(args.url ?? '') || createHash('sha256').update(String(args.data ?? '')).digest('hex') : String(args[ck.arg] ?? '');
837
- const label = name === 'oculon_doc_check' ? String(args.name ?? args.url ?? 'document').slice(0, 90) : undefined;
962
+ const target = ck.arg === 'name' ? String(args.url ?? '') || createHash('sha256').update(String(args.data ?? '')).digest('hex') : `${String(args[ck.arg] ?? '')}${args.chain ? `@${String(args.chain).toLowerCase()}` : ''}`;
963
+ const label = ck.arg === 'name' ? String(args.name ?? args.url ?? 'file').slice(0, 90) : undefined;
838
964
  const r = await this.o.recordCheck(ck.kind, target, async () => tool.run(this.o, args), label ? { label } : {});
839
965
  out = r.value;
840
966
  check = r.check;
@@ -1,11 +1,13 @@
1
1
  /**
2
2
  * Crypto address check without API keys: which chain the address belongs to (from its format), whether it is
3
3
  * on the US OFAC sanctions list, and its age, balance and activity from free explorers (mempool.space for
4
- * Bitcoin, Blockscout for Ethereum and Robinhood Chain, the public Solana RPC). Useful before you send
5
- * funds to an address someone gave you in a chat.
4
+ * Bitcoin, Blockscout for Ethereum and Robinhood Chain, the public Solana RPC), victims' scam reports
5
+ * (Chainabuse, free key) and the ScamSniffer scam address list. Useful before you send funds to an address
6
+ * someone gave you in a chat.
6
7
  */
7
8
  import type { Ctx } from '../core/context.js';
8
9
  import type { ModuleResult } from '../core/types.js';
10
+ import { type AbuseReports } from '../sources/chainabuse.js';
9
11
  export interface AddressReport {
10
12
  address: string;
11
13
  chain: 'bitcoin' | 'evm' | 'solana' | 'tron' | 'unknown';
@@ -20,6 +22,8 @@ export interface AddressReport {
20
22
  } | null;
21
23
  sanctioned: boolean | null;
22
24
  sanctionHits: string[];
25
+ /** Scam reports filed by victims (Chainabuse). */
26
+ reports: AbuseReports | null;
23
27
  warnings: string[];
24
28
  advice: string[];
25
29
  }
@@ -1,4 +1,7 @@
1
1
  import { screen } from './sanctions.js';
2
+ import { key } from '../core/keys.js';
3
+ import { chainabuse } from '../sources/chainabuse.js';
4
+ import { ensurePhishLists, phishAddress } from '../sources/phishlists.js';
2
5
  const B58 = /^[1-9A-HJ-NP-Za-km-z]+$/;
3
6
  export function detectChain(a) {
4
7
  if (/^0x[0-9a-fA-F]{40}$/.test(a))
@@ -35,11 +38,13 @@ export async function addressCheck(ctx, input, opts = {}) {
35
38
  else if (chain === 'evm') {
36
39
  const rh = /^(rh|robinhood)$/i.test(opts.network ?? '');
37
40
  network = rh ? 'Robinhood Chain' : 'Ethereum';
41
+ const bk = key('BLOCKSCOUT_API_KEY');
38
42
  const base = rh ? 'https://api.blockscout.com/4663/api/v2' : 'https://eth.blockscout.com/api/v2';
39
- const r = await ctx.http.get(`${base}/addresses/${address}`, { source: 'blockscout', ttlSec: 900 });
40
- provenance.push(r.prov);
41
- const c = await ctx.http.get(`${base}/addresses/${address}/counters`, { source: 'blockscout', ttlSec: 900 });
42
- provenance.push(c.prov);
43
+ const q = rh && bk ? `?apikey=${bk}` : '';
44
+ const r = await ctx.http.get(`${base}/addresses/${address}${q}`, { source: 'blockscout', ttlSec: 900 });
45
+ provenance.push({ ...r.prov, url: r.prov.url.replace(/apikey=[^&]+/, 'apikey=***') });
46
+ const c = await ctx.http.get(`${base}/addresses/${address}/counters${q}`, { source: 'blockscout', ttlSec: 900 });
47
+ provenance.push({ ...c.prov, url: c.prov.url.replace(/apikey=[^&]+/, 'apikey=***') });
43
48
  if (r.data || r.prov.note === 'HTTP 404') {
44
49
  const d = r.data ?? {};
45
50
  activity = { txCount: c.data?.transactions_count ? Number(c.data.transactions_count) : 0, balance: d.coin_balance ? `${(Number(BigInt(d.coin_balance) / 10n ** 12n) / 1e6).toFixed(6)} ETH` : '0 ETH', firstSeen: null,
@@ -84,8 +89,30 @@ export async function addressCheck(ctx, input, opts = {}) {
84
89
  warnings.push('this address has traded directly with a sanctioned address');
85
90
  }
86
91
  catch { /* the list is optional here */ }
92
+ // Victims' reports and known scam addresses.
93
+ let reports = null;
94
+ try {
95
+ const ca = await chainabuse(ctx, 'address', address);
96
+ if (ca.prov)
97
+ provenance.push(ca.prov);
98
+ reports = ca.data;
99
+ // Anyone can file a report; one or two unverified ones (famous addresses collect some) are kept in the
100
+ // result but do not raise a warning.
101
+ if (reports?.count && (reports.trusted > 0 || reports.count >= 3))
102
+ warnings.unshift(`${reports.count} scam report${reports.count > 1 ? 's' : ''} filed by victims on Chainabuse${reports.trusted ? ` (${reports.trusted} verified by Chainabuse)` : ""}${reports.categories.length ? ` (${reports.categories.join(', ')})` : ''}${reports.latest ? `, latest ${reports.latest.slice(0, 10)}` : ''}`);
103
+ }
104
+ catch { }
105
+ if (chain === 'evm') {
106
+ try {
107
+ await ensurePhishLists(ctx);
108
+ const listed = phishAddress(ctx, address);
109
+ if (listed)
110
+ warnings.unshift(`on the ${listed}`);
111
+ }
112
+ catch { }
113
+ }
87
114
  const advice = warnings.length
88
115
  ? ['Do not send funds until you have confirmed the address with the recipient through a channel you already trust.']
89
116
  : ['Nothing alarming found. Still send a small test amount first, and never send to an address someone pushes on you in a chat.'];
90
- return { module: 'address', input: address, generatedAt: ctx.now().toISOString(), result: { address, chain, format, network, activity, sanctioned, sanctionHits: hits, warnings, advice }, signals: [], provenance };
117
+ return { module: 'address', input: address, generatedAt: ctx.now().toISOString(), result: { address, chain, format, network, activity, sanctioned, sanctionHits: hits, reports, warnings, advice }, signals: [], provenance };
91
118
  }
@@ -0,0 +1,37 @@
1
+ import type { Ctx } from '../core/context.js';
2
+ import type { ModuleResult } from '../core/types.js';
3
+ export declare const APK_MAX_BYTES: number;
4
+ export interface ApkReport {
5
+ name: string;
6
+ bytes: number;
7
+ sha256: string;
8
+ package: string | null;
9
+ version: string | null;
10
+ minSdk: number | null;
11
+ targetSdk: number | null;
12
+ verdict: 'known malware' | 'dangerous app' | 'risky permissions' | 'no known risk found';
13
+ risk: number;
14
+ permissions: string[];
15
+ risky: {
16
+ permission: string;
17
+ why: string;
18
+ }[];
19
+ services: string[];
20
+ signer: string[];
21
+ debugSigned: boolean;
22
+ malware: {
23
+ verdict: string;
24
+ name: string | null;
25
+ family: string | null;
26
+ } | null;
27
+ reasons: string[];
28
+ advice: string[];
29
+ }
30
+ interface Node {
31
+ name: string;
32
+ attrs: Record<string, string>;
33
+ }
34
+ /** Elements of a binary Android XML file, with attribute values as text. */
35
+ export declare function parseAxml(b: Buffer): Node[];
36
+ export declare function apkCheck(ctx: Ctx, file: Buffer, name?: string): Promise<ModuleResult<ApkReport>>;
37
+ export {};
@@ -0,0 +1,191 @@
1
+ /**
2
+ * Android app check: is this APK safe to install? Built for the fake apps sent in chats ("invoice", "parcel",
3
+ * "wedding invitation", "photo") that steal one-time codes and take over banking apps.
4
+ * Manifest: package name, version, SDK levels and every permission, read from the binary AndroidManifest.xml
5
+ * (parsed here). Services that ask for accessibility, notification access or device admin, and receivers
6
+ * that wake on incoming SMS, are what banking trojans use.
7
+ * Signer: organization and name in the signing certificate; the Android debug key means it was never
8
+ * published through a store.
9
+ * Malware: the file's SHA-256 looked up in malware databases (the hash check).
10
+ * The file is read, never installed or run.
11
+ */
12
+ import { createHash } from 'node:crypto';
13
+ import { signalId } from '../core/text.js';
14
+ import { certNames } from '../core/der.js';
15
+ import { zipEntries, zipRead } from '../core/zip.js';
16
+ import { hashCheck } from './hashcheck.js';
17
+ export const APK_MAX_BYTES = 40 * 1024 * 1024;
18
+ /** Elements of a binary Android XML file, with attribute values as text. */
19
+ export function parseAxml(b) {
20
+ const nodes = [];
21
+ if (b.length < 8 || b.readUInt16LE(0) !== 0x0003)
22
+ throw new Error('not a binary Android XML file');
23
+ let strings = [];
24
+ let resIds = [];
25
+ const ANDROID_ATTR = { 0x01010003: 'name', 0x0101021b: 'versionCode', 0x0101021c: 'versionName', 0x0101020c: 'minSdkVersion', 0x01010270: 'targetSdkVersion', 0x01010006: 'permission', 0x01010001: 'label' };
26
+ let p = b.readUInt16LE(2);
27
+ while (p + 8 <= b.length) {
28
+ const type = b.readUInt16LE(p), hsz = b.readUInt16LE(p + 2), size = b.readUInt32LE(p + 4);
29
+ if (size < 8 || p + size > b.length)
30
+ break;
31
+ if (type === 0x0001) {
32
+ const n = b.readUInt32LE(p + 8), flags = b.readUInt32LE(p + 16), start = b.readUInt32LE(p + 20);
33
+ const utf8 = (flags & 0x100) !== 0;
34
+ strings = [];
35
+ for (let i = 0; i < n; i++) {
36
+ let o = p + start + b.readUInt32LE(p + hsz + i * 4);
37
+ try {
38
+ if (utf8) {
39
+ if (b[o] & 0x80)
40
+ o += 2;
41
+ else
42
+ o += 1;
43
+ let len = b[o];
44
+ o += 1;
45
+ if (len & 0x80) {
46
+ len = ((len & 0x7f) << 8) | b[o];
47
+ o += 1;
48
+ }
49
+ strings.push(b.toString('utf8', o, o + len));
50
+ }
51
+ else {
52
+ let len = b.readUInt16LE(o);
53
+ o += 2;
54
+ if (len & 0x8000) {
55
+ len = ((len & 0x7fff) << 16) | b.readUInt16LE(o);
56
+ o += 2;
57
+ }
58
+ strings.push(b.toString('utf16le', o, o + len * 2));
59
+ }
60
+ }
61
+ catch {
62
+ strings.push('');
63
+ }
64
+ }
65
+ }
66
+ else if (type === 0x0180) {
67
+ resIds = [];
68
+ for (let o = p + 8; o + 4 <= p + size; o += 4)
69
+ resIds.push(b.readUInt32LE(o));
70
+ }
71
+ else if (type === 0x0102) {
72
+ const nameIdx = b.readUInt32LE(p + 20);
73
+ const attrStart = b.readUInt16LE(p + 24), attrSize = b.readUInt16LE(p + 26), count = b.readUInt16LE(p + 28);
74
+ const attrs = {};
75
+ for (let i = 0; i < count; i++) {
76
+ const a = p + 16 + attrStart + i * attrSize;
77
+ const ni = b.readUInt32LE(a + 4), raw = b.readUInt32LE(a + 8), dt = b[a + 15], data = b.readUInt32LE(a + 16);
78
+ // Obfuscated apps blank attribute names; the resource id still says which android: attribute it is.
79
+ const key = strings[ni] || ANDROID_ATTR[resIds[ni] ?? -1] || `attr${ni}`;
80
+ attrs[key] = raw !== 0xffffffff ? strings[raw] ?? '' : dt === 0x03 ? strings[data] ?? '' : dt === 0x12 ? String(data !== 0) : dt === 0x01 ? `@0x${data.toString(16)}` : String(data);
81
+ }
82
+ nodes.push({ name: strings[nameIdx] ?? '', attrs });
83
+ }
84
+ p += size;
85
+ }
86
+ return nodes;
87
+ }
88
+ const PERMS = [
89
+ [/\.(RECEIVE|READ)_SMS$/, 'reads incoming SMS: how one-time banking codes are stolen', 30],
90
+ [/\.SEND_SMS$/, 'sends SMS from your number (premium texts, spreading itself)', 15],
91
+ [/\.SYSTEM_ALERT_WINDOW$/, 'draws over other apps: fake login screens on top of your banking app', 15],
92
+ [/\.REQUEST_INSTALL_PACKAGES$/, 'installs other apps: a first stage that downloads the real malware', 15],
93
+ [/\.(READ_CALL_LOG|PROCESS_OUTGOING_CALLS|ANSWER_PHONE_CALLS|CALL_PHONE)$/, 'reads or controls phone calls', 10],
94
+ [/\.READ_CONTACTS$/, 'reads your contacts (often used to send itself to them)', 5],
95
+ [/\.QUERY_ALL_PACKAGES$/, 'lists every app you have installed (to find banking apps)', 5],
96
+ [/\.(READ_PHONE_STATE|READ_PHONE_NUMBERS)$/, 'reads your phone number and SIM details', 5],
97
+ [/\.(RECORD_AUDIO)$/, 'records audio', 5],
98
+ [/\.(CAMERA)$/, 'uses the camera', 2],
99
+ [/\.(ACCESS_FINE_LOCATION|ACCESS_BACKGROUND_LOCATION)$/, 'tracks location', 3],
100
+ ];
101
+ const SERVICES = [
102
+ [/BIND_ACCESSIBILITY_SERVICE/, 'asks for accessibility access: it can read the screen and tap for you, the core of banking trojans', 35],
103
+ [/BIND_NOTIFICATION_LISTENER_SERVICE/, 'asks to read all notifications, including one-time codes', 20],
104
+ [/BIND_DEVICE_ADMIN/, 'asks for device administrator rights, which makes it hard to uninstall', 25],
105
+ ];
106
+ const LURE = /invoice|receipt|parcel|delivery|courier|tracking|wedding|invitation|photo|viewer|pdf|document|tax|refund|fine|ticket|update|security|bank|wallet|support/i;
107
+ export async function apkCheck(ctx, file, name = 'app.apk') {
108
+ if (!file.length)
109
+ throw new Error('the file is empty');
110
+ if (file.length > APK_MAX_BYTES)
111
+ throw new Error('the app is larger than 40 MB');
112
+ if (file.readUInt32LE(0) !== 0x04034b50)
113
+ throw new Error('not an APK (Android apps are ZIP files)');
114
+ const entries = zipEntries(file);
115
+ const man = entries.find((e) => e.name === 'AndroidManifest.xml');
116
+ if (!man)
117
+ throw new Error('no AndroidManifest.xml: not an Android app');
118
+ const nodes = parseAxml(zipRead(file, man) ?? Buffer.alloc(0));
119
+ const provenance = [{ source: 'oculon-apk', url: 'local', status: 'LIVE', fetchedAt: ctx.now().toISOString(), note: 'manifest and certificates read here; the app is not installed or run' }];
120
+ const manifest = nodes.find((n) => n.name === 'manifest');
121
+ const sdk = nodes.find((n) => n.name === 'uses-sdk');
122
+ const permissions = [...new Set(nodes.filter((n) => /^uses-permission/.test(n.name)).map((n) => n.attrs.name ?? '').filter(Boolean))];
123
+ const svcPerms = nodes.filter((n) => n.name === 'service' || n.name === 'receiver').map((n) => n.attrs.permission ?? '').filter(Boolean);
124
+ const actions = nodes.filter((n) => n.name === 'action').map((n) => n.attrs.name ?? '');
125
+ const reasons = [];
126
+ const risky = [];
127
+ for (const p of permissions)
128
+ for (const [re, why, w] of PERMS)
129
+ if (re.test(p)) {
130
+ risky.push({ permission: p.split('.').pop(), why });
131
+ reasons.push([why, w]);
132
+ }
133
+ const services = [];
134
+ for (const sp of [...new Set(svcPerms)])
135
+ for (const [re, why, w] of SERVICES)
136
+ if (re.test(sp)) {
137
+ services.push(sp.split('.').pop());
138
+ reasons.push([why, w]);
139
+ }
140
+ if (actions.some((a) => /SMS_RECEIVED|SMS_DELIVER/.test(a)))
141
+ reasons.push(['wakes up on every incoming SMS', 15]);
142
+ if (actions.some((a) => /BOOT_COMPLETED/.test(a)) && reasons.length)
143
+ reasons.push(['starts itself when the phone boots', 5]);
144
+ // Signer: v1 certificates in META-INF, or the v2/v3 signing block before the central directory.
145
+ const certs = entries.filter((e) => /^META-INF\/[^/]+\.(RSA|DSA|EC)$/i.test(e.name));
146
+ let signer = [];
147
+ for (const c of certs) {
148
+ const d = zipRead(file, c);
149
+ if (d)
150
+ signer.push(...certNames(d, /^$/));
151
+ }
152
+ if (!signer.length) {
153
+ const sig = file.lastIndexOf('APK Sig Block 42');
154
+ if (sig > 0)
155
+ signer = certNames(file.subarray(Math.max(0, sig - 200_000), sig + 16), /^$/);
156
+ }
157
+ signer = [...new Set(signer)].slice(0, 6);
158
+ const debugSigned = signer.some((s) => /android debug/i.test(s));
159
+ if (debugSigned)
160
+ reasons.push(['signed with the Android debug key: never published through an app store', 25]);
161
+ if (!signer.length)
162
+ reasons.push(['no signing certificate found', 10]);
163
+ const pkg = manifest?.attrs.package ?? null;
164
+ const dangerous = reasons.reduce((s, [, w]) => s + w, 0) >= 40;
165
+ if (dangerous && (LURE.test(pkg ?? '') || LURE.test(name)))
166
+ reasons.push([`the name (${LURE.exec(pkg ?? '')?.[0] ?? LURE.exec(name)?.[0]}) is the kind used to lure people into installing it from a chat`, 10]);
167
+ if (dangerous && file.length < 3 * 1024 * 1024)
168
+ reasons.push([`very small for an app that asks for this much (${(file.length / 1024 / 1024).toFixed(1)} MB)`, 5]);
169
+ // Malware databases.
170
+ const sha256 = createHash('sha256').update(file).digest('hex');
171
+ let malware = null;
172
+ try {
173
+ const h = await hashCheck(ctx, sha256);
174
+ provenance.push(...h.provenance.slice(0, 4));
175
+ malware = { verdict: h.result.verdict, name: h.result.name, family: h.result.family };
176
+ if (h.result.verdict === 'malicious')
177
+ reasons.unshift([`known malware${h.result.family ? ` (${h.result.family})` : ''} in malware databases`, 100]);
178
+ }
179
+ catch { }
180
+ const risk = Math.min(100, reasons.reduce((s, [, w]) => s + w, 0));
181
+ const verdict = malware?.verdict === 'malicious' ? 'known malware' : risk >= 60 ? 'dangerous app' : risk >= 25 ? 'risky permissions' : 'no known risk found';
182
+ const advice = verdict === 'known malware' || verdict === 'dangerous app'
183
+ ? ['Do not install it. Apps sent in a chat are the most common way phones get banking malware.', 'If it is already installed: turn on airplane mode, remove it in Settings > Apps (remove its admin and accessibility rights first), then call your bank from a number you know.']
184
+ : verdict === 'risky permissions' ? ['Install apps only from Google Play or the maker\'s own site. Check that the permissions fit what the app does.'] : ['Nothing alarming in the manifest. Still prefer the store version of any app.'];
185
+ const now = ctx.now().toISOString();
186
+ const signals = verdict === 'known malware' || risk >= 80 ? [{ id: signalId('apk', sha256), module: 'apk', title: `Android app ${pkg ?? name}: ${verdict}`, score: Math.max(risk, 70), entity: `apk:${sha256.slice(0, 16)}`, evidence: reasons.slice(0, 3).map(([t]) => ({ source: 'oculon-apk', text: t })), createdAt: now }] : [];
187
+ return {
188
+ module: 'apk', input: name.slice(0, 120), generatedAt: now, signals, provenance,
189
+ result: { name: name.slice(0, 120), bytes: file.length, sha256, package: pkg, version: manifest?.attrs.versionName ?? null, minSdk: sdk?.attrs.minSdkVersion ? Number(sdk.attrs.minSdkVersion) || null : null, targetSdk: sdk?.attrs.targetSdkVersion ? Number(sdk.attrs.targetSdkVersion) || null : null, verdict, risk, permissions, risky, services, signer, debugSigned, malware, reasons: reasons.sort((a, b) => b[1] - a[1]).map(([r]) => r), advice },
190
+ };
191
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Approval check: who can move tokens out of this wallet right now.
3
+ * Reads every ERC-20 Approval and NFT ApprovalForAll event the wallet ever signed (Etherscan logs), then asks the
4
+ * chain what is still allowed today (allowance / isApprovedForAll through a public RPC), so revoked and used-up
5
+ * approvals drop out. Each spender is named when it is a known router or marketplace; unknown spenders, plain
6
+ * wallets (not contracts) and unverified contracts with unlimited access are flagged, since that is how drainers
7
+ * keep access after a bad signature.
8
+ */
9
+ import type { Ctx } from '../core/context.js';
10
+ import type { ModuleResult } from '../core/types.js';
11
+ export interface Approval {
12
+ token: string;
13
+ tokenName: string | null;
14
+ symbol: string | null;
15
+ kind: 'token' | 'nft';
16
+ spender: string;
17
+ spenderName: string | null;
18
+ spenderType: 'known' | 'verified contract' | 'unverified contract' | 'wallet' | 'unknown';
19
+ amount: string;
20
+ unlimited: boolean;
21
+ approvedAt: string | null;
22
+ risk: 'high' | 'medium' | 'low';
23
+ why: string | null;
24
+ }
25
+ export interface ApprovalsReport {
26
+ address: string;
27
+ chain: string;
28
+ verdict: 'dangerous approvals' | 'risky approvals' | 'review approvals' | 'no risky approvals found' | 'no approvals found';
29
+ risk: number;
30
+ active: number;
31
+ unlimited: number;
32
+ checkedPairs: number;
33
+ approvals: Approval[];
34
+ reasons: string[];
35
+ advice: string[];
36
+ revokeUrl: string;
37
+ }
38
+ export declare function approvalsCheck(ctx: Ctx, input: string, opts?: {
39
+ chain?: string;
40
+ }): Promise<ModuleResult<ApprovalsReport>>;