KOG fee over x402 on Solana: verifier and fee gate
Pure verifier for a Kognai fee paid over x402 in an SPL Token 2022 (or SPL Token) mint on Solana. Built for the Kognai seats "KOG fee verification over x402 on Solana" and "Tests: listing and bid refused without the KOG fee". MIT. No runtime dependency, no RPC, no clock, no logging.
import { verifyKogFee } from "kog-fee-verify";
verifyKogFee({ tx, quote: { amount: "40000000", expires_at: 1792620821 }, payee, mint, seen });
// { ok: true, reason: "ok", signature, received: "40000000" }
tx: the parsed transaction from getTransaction (encoding jsonParsed), passed in.quote: { amount, expires_at, mint?, payee? }; amount in base units (decimal string), expires_at in unix seconds or ISO 8601.payee: the payee wallet (owner of the receiving token account) or the receiving token account.seen: signatures already used (Set, Map, array, or anything with has).Checks, in order, each with a fixed reason: bad_input, bad_quote, tx_failed (meta.err set), replay (signature in seen), expired (blockTime after the quote expiry; now used only when blockTime is missing), wrong_mint (no token transfer instruction of the mint), wrong_payee (the mint moved, but not to the payee), short_fee (net amount the payee received, after any Token 2022 transfer fee, below the quote). A balance rise without a transfer instruction to the payee is not a fee.
createFeeGate({ mint, payee, store }) wraps the verifier for registry writes (POST /offers, POST /jobs/
npm ci && npm test: 17 tests on recorded mainnet transactions (fixtures/, recorded 21 Oct 2026): a real x402 exact shaped Token 2022 transferChecked of 40 PYUSD (two compute budget instructions plus transferChecked), a PYUSD transfer with a memo, and a USDG Token 2022 transfer for the wrong mint case. A1 right fee, A2 short fee, A3 wrong mint, A4 wrong payee, A5 expired quote, A6 replay, A7 failed transaction, bad quote and purity. test/gate.test.ts drives an in memory registry: refused without a fee, with a short fee, with a reused fee (also across routes), accepted with a valid fee, for both write routes.
agentgate-source: code mirror on Cloudflare Pages. All repos