Artur Schaback 8cf3422186
feat(codescan): detect crypto apps and flag Guideline 3.1.5(b) obligations (#14)
* feat(codescan): detect crypto apps and flag Guideline 3.1.5(b) obligations

Crypto apps carry App Review obligations that static analysis can detect
the *need* for but cannot verify: wallet apps must ship from an
Organization account (3.1.5(b)(i)), and exchange / fiat on-off-ramp /
transmission apps must be the licensed exchange itself or an approved,
law-compliant organization in every region they ship (3.1.5(b)(iii)) --
which App Review routinely backs with a request for licensing evidence or
a legal opinion, geo-restricted availability, and a working demo account.

greenlight previously only knew one crypto rule (on-device mining), so a
custodial/exchange app could scan near-clean and still hit the single most
common crypto rejection. This adds:

- crypto-wallet-org-account (3.1.5, WARN): web3/wallet SDKs (ethers, viem,
  wagmi, @reown, @walletconnect, @privy-io, @solana/web3.js, ...) -> the
  Organization-account reminder.
- crypto-exchange-licensing (3.1.5, HIGH): on/off-ramp + exchange providers
  (MoonPay, Transak, Ramp, Banxa, ...) and exchange/ramp/P2P domain phrases
  -> the licensing / legal-opinion / geo-restriction / demo-account tier.

Both are project-level facts (firstMatchOnly, one finding per project) with
no antiPatterns -- the obligation cannot be discharged in source -- and are
suppressible with the existing greenlight:ignore[<rule-id>] directive.

Also expands the 3.1.5 guideline entry with (b)(i)/(ii)/(iii) subsections so
"greenlight guidelines search wallet|exchange|custody" returns results.

Tests cover firing, quote-bounded no-fire cases, severity, project-level
collapse, and the ignore directive. Verified against a real Expo crypto app.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(codescan): correct ignore-directive syntax and match scoped ramp SDKs

Addresses two P2 review comments on the crypto rules:

- The fix/doc text recommended the bracketed form
  greenlight:ignore[<rule-id>], but directiveSuppresses splits on
  whitespace/comma only, so the bracketed token never matches the rule id
  and the advisory keeps firing. Switched to the supported space form
  greenlight:ignore <rule-id>.
- The on/off-ramp provider regex required ramp-network/banxa/mercuryo/
  onramper to be the whole quoted token, so scoped SDKs like
  @ramp-network/ramp-instant-sdk never matched. Unified all providers to
  allow an optional scope/subpath.

Tests: scoped Ramp + Sardine packages now fire; new assertions lock the
fix text to the directive form the scanner actually honors.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix(codescan): calibrate crypto rules to kill non-crypto false positives

Addresses maintainer review + two Codex P2s on PR #14. The exchange rule was
HIGH and fired on loose phrases, so non-crypto apps failed preflight --exit-code.

Rework:
- crypto-exchange-sdk (HIGH): fires ONLY on real provider-SDK package
  identifiers -- a scope subpath (@moonpay/react-native-moonpay-sdk,
  @ramp-network/ramp-instant-sdk) or a -suffixed package (transak-react-native-
  sdk). Bare words ("sardine", "sardines", "wyred", "moonpayments", "banxample")
  can no longer match, so a recipe/maps/tracker app can't be gated by it.
- crypto-exchange-signals (WARN, new): the loose exchange/on-ramp/P2P phrase
  heuristics, moved off the HIGH path. Skips obvious negations ("not a crypto
  exchange", "does not buy crypto") and requires a real separator on the ramp
  phrase so bare "onramp"/"offramp" road copy doesn't fire. Adds
  "cryptocurrency exchange", "trade/swap crypto".
- crypto-wallet-org-account (WARN): native WalletCore/web3swift now anchored to
  an import (a bare WalletCore identifier / Apple Wallet code no longer fires);
  added @wagmi/core, @ethersproject/*, @coinbase/wallet-sdk, @rainbow-me/*,
  thirdweb, @web3-onboard/* which the bare-name alternatives missed.

Guidelines: quote Apple's actual 3.1.5(b) bullet wording ("offered by the
exchange itself"), label the Resolution-Center asks as practical guidance (they
aren't guideline text), drop the invented (i)/(ii)/(iii) numbering for
descriptive "3.1.5(b) Wallets/Mining/Exchanges/ICOs" keys, add the ICO bullet
where "comply with all applicable law" actually comes from.

Also:
- Suppression: fix text now points to .greenlight.yml (enabled:false) since the
  SDK rules fire on package.json where an inline directive can't live.
- Scanner: classify .mm as objc so native rules run on Obj-C++.
- Fix the bracketed greenlight:ignore[...] doc comment in rules.go.

Tests rewritten to cover every reviewer false-positive case and use non-comment
noFire lines that actually exercise the regex. Verified on a real build: the
reviewer's disclaimer+recipe app scans GREENLIT; a MoonPay/Ramp dependency
still trips the HIGH.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* feat(codescan): add crypto-exchange-brand rule (exchange/wallet brands)

Adds a WARN rule matching references to known cryptocurrency exchange /
wallet brands (Coinbase, Binance, Kraken, Bybit, OKX, KuCoin, Crypto.com,
Bitfinex, Unigox, ...). Matched only as a domain (deep-link / API host /
associated domain) or an SDK package (ccxt, scoped @brand/*, binance-
connector), never a bare word — so the .tld / package anchor keeps Google
Gemini (gemini.google.com), the mythical kraken, "stargate.io", and the
node crypto module from firing.

WARN, not HIGH: a reference can just mean the app links out to the
exchange website. But for an app that ships its own exchange brand (its
associated domain or scoped SDK), this is a strong "this is a crypto
exchange" signal that pairs with the wallet/SDK/phrase rules.

firstMatchOnly + no antiPatterns like the other crypto rules; suppressible
inline or via .greenlight.yml. Tests cover brand domains/SDKs firing and
the FP guards (Google Gemini, stargate, bare word, node crypto) staying
clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-01 12:43:11 -07:00
..