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>
70 lines
2.6 KiB
TypeScript
70 lines
2.6 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { loadConfig } from "../src/config/env.js";
|
|
|
|
const prodSecrets = {
|
|
DATABASE_URL: "postgres://user:pass@localhost:5432/settlekit",
|
|
LICENSE_TOKEN_SECRET: "a-real-license-secret",
|
|
WEBHOOK_SIGNING_SECRET: "a-real-webhook-secret",
|
|
AUTH_COOKIE_SECRET: "a-real-auth-cookie-secret",
|
|
};
|
|
|
|
describe("loadConfig production fail-closed guard", () => {
|
|
it("boots with dev defaults when NODE_ENV is not production", () => {
|
|
expect(() => loadConfig({})).not.toThrow();
|
|
});
|
|
|
|
it("refuses to boot in production without DATABASE_URL", () => {
|
|
expect(() => loadConfig({ NODE_ENV: "production" })).toThrow(/DATABASE_URL must be set/);
|
|
});
|
|
|
|
it("refuses to boot in production with dev-default signing secrets", () => {
|
|
expect(() =>
|
|
loadConfig({ NODE_ENV: "production", DATABASE_URL: prodSecrets.DATABASE_URL }),
|
|
).toThrow(/LICENSE_TOKEN_SECRET must be set/);
|
|
});
|
|
|
|
it("boots in production once DB and real secrets are supplied", () => {
|
|
expect(() => loadConfig({ NODE_ENV: "production", ...prodSecrets })).not.toThrow();
|
|
});
|
|
});
|
|
|
|
describe("loadConfig chain verifiers", () => {
|
|
it("leaves solana and base unset by default", () => {
|
|
const cfg = loadConfig({});
|
|
expect(cfg.solana).toBeNull();
|
|
expect(cfg.base).toBeNull();
|
|
expect(cfg.hasSolana).toBe(false);
|
|
});
|
|
|
|
it("derives the RPC URL and USDC mint from SOLANA_CLUSTER", () => {
|
|
const cfg = loadConfig({ SOLANA_CLUSTER: "devnet" });
|
|
expect(cfg.solana).toEqual({
|
|
cluster: "devnet",
|
|
rpcUrl: "https://api.devnet.solana.com",
|
|
usdcMint: "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU",
|
|
});
|
|
const mainnet = loadConfig({ SOLANA_CLUSTER: "mainnet-beta", SOLANA_RPC_URL: "https://rpc.example.com" });
|
|
expect(mainnet.solana).toMatchObject({
|
|
cluster: "mainnet",
|
|
rpcUrl: "https://rpc.example.com",
|
|
usdcMint: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
|
|
});
|
|
});
|
|
|
|
it("rejects partial or malformed solana configuration", () => {
|
|
expect(() => loadConfig({ SOLANA_RPC_URL: "https://rpc.example.com" })).toThrow(/SOLANA_CLUSTER/);
|
|
expect(() => loadConfig({ SOLANA_CLUSTER: "testnet" })).toThrow(/mainnet or devnet/);
|
|
expect(() => loadConfig({ SOLANA_CLUSTER: "devnet", SOLANA_USDC_MINT: "0xabc" })).toThrow(/base58/);
|
|
});
|
|
|
|
it("enables Base verification with the canonical USDC contract", () => {
|
|
const cfg = loadConfig({ BASE_RPC_URL: "https://mainnet.base.org" });
|
|
expect(cfg.base).toEqual({
|
|
rpcUrl: "https://mainnet.base.org",
|
|
usdcAddress: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
|
|
chainId: 8453,
|
|
minConfirmations: 3,
|
|
});
|
|
});
|
|
});
|