settlekit/apps/api/test/compliance-screen.test.ts
caelum0x c0b39e38aa fix: fail closed on payment confirmation without an on-chain verifier
Security: POST /v1/payments/:id/confirm only verified Arc payments; any
other network confirmed with an arbitrary txHash and granted
entitlements. The API now keeps a per-network verifier registry
(ctx.verifiers: arc via the existing Arc client, base via the generic
EVM client + BASE_RPC_URL + Base USDC, solana via @settlekit/solana)
and confirm/observe reject any network without one.

- a transaction hash settles at most one payment (409 on reuse, also
  on record); EVM hashes are normalized to lowercase
- checkout sessions accept network solana, require a base58 payTo and
  get a fresh Solana Pay paymentReference the tx must include
- observe validates hash/address formats per network (base58 vs 0x)
- compliance screening maps solana to Circle's SOL chain
- env: SOLANA_CLUSTER, SOLANA_RPC_URL, SOLANA_USDC_MINT, BASE_RPC_URL,
  BASE_MIN_CONFIRMATIONS

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-29 06:24:05 +03:00

59 lines
2.4 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { SettleKitError } from "@settlekit/common";
import type { ScreeningClient, AddressScreening } from "@settlekit/compliance";
import { circleChainForNetwork, screenAddressOrThrow } from "../src/compliance/screen.js";
function screeningReturning(result: "APPROVED" | "DENIED", riskSignals: AddressScreening["riskSignals"] = []): ScreeningClient {
return {
async screenAddress(input) {
return { address: input.address, chain: input.chain, result, riskSignals, raw: {} };
},
};
}
describe("circleChainForNetwork", () => {
it("maps known networks and falls back for Arc", () => {
expect(circleChainForNetwork("base", "ETH")).toBe("BASE");
expect(circleChainForNetwork("ethereum", "ETH")).toBe("ETH");
expect(circleChainForNetwork("solana", "ETH")).toBe("SOL");
expect(circleChainForNetwork("arc", "ETH")).toBe("ETH");
expect(circleChainForNetwork("arc", "MATIC")).toBe("MATIC");
});
});
describe("screenAddressOrThrow", () => {
const target = { address: "0xabc", network: "arc", context: "payout:po_1" };
it("is a no-op (allow) when screening is unconfigured", async () => {
const decision = await screenAddressOrThrow({ screening: null, defaultChain: "ETH" }, target);
expect(decision).toBe("allow");
});
it("allows a clean (APPROVED, no signals) address", async () => {
const decision = await screenAddressOrThrow(
{ screening: screeningReturning("APPROVED"), defaultChain: "ETH" },
target,
);
expect(decision).toBe("allow");
});
it("throws compliance_blocked on a DENIED result", async () => {
await expect(
screenAddressOrThrow({ screening: screeningReturning("DENIED"), defaultChain: "ETH" }, target),
).rejects.toMatchObject({ code: "compliance_blocked", httpStatus: 403 });
});
it("throws compliance_blocked on a SANCTIONS category", async () => {
const screening = screeningReturning("APPROVED", [{ riskCategories: ["SANCTIONS"] }]);
await expect(
screenAddressOrThrow({ screening, defaultChain: "ETH" }, target),
).rejects.toBeInstanceOf(SettleKitError);
});
it("allows but reports review on a medium-risk signal", async () => {
const screening = screeningReturning("APPROVED", [{ riskScore: "MEDIUM" }]);
const decision = await screenAddressOrThrow({ screening, defaultChain: "ETH" }, target);
expect(decision).toBe("review");
});
});