Server
Two servers speak the same /v1 API. Node is the @attackfee/server package. It is not on npm yet. From a clone of this repo, run npm install and npm run build, then install packages/server-node by path. PHP is the Attackfee\Protocol library shipped inside the WordPress plugin (GPL-2.0-or-later), under lib/server-php. That library is not a separate package on a public PHP registry.
Reads stay free. A write with no pass gets 403 and attackfee_required. The pass cookie is attackfee_pass. The header is Authorization: Attackfee.
No real money moves on the self-hosted server's stub backend.
Paid passes are off. The owner chooses each route's class, which sets its relative cost. The demo at /demo checks writes only and takes no payment.
Node
# From a clone of this repo: npm install && npm run build
npm install /path/to/attackfee/packages/server-node express
secret in the config is at least 16 characters. Put it in the environment. Do not commit it.
site_id: site_abc123
secret: env:ATTACKFEE_SECRET
issuer_public_url: http://127.0.0.1:8787
routes:
- { prefix: "/", class: read }
- { prefix: "/contact", class: write }
The / route keeps every page view free. A route's class applies to writes under that prefix.
import express from "express";
import { Attackfee, loadConfig } from "@attackfee/server";
const attackfee = Attackfee.create(loadConfig("attackfee.yaml"));
const app = express();
app.use(Attackfee.router(attackfee));
app.post("/contact", Attackfee.middleware(attackfee, { action: "write" }), (req, res) => {
res.status(200).json({ ok: true });
});
app.listen(8787);
Attackfee.router() serves /v1 and the widget files. Attackfee.middleware() checks the pass before your handler runs.
Behind a reverse proxy, list it in the ATTACKFEE_TRUSTED_PROXIES environment variable (comma-separated addresses and ranges). Attackfee does not read the framework's proxy setting.
PHP
From a checkout, run composer install in packages/server-php, then load vendor/autoload.php. Inside the plugin zip the same library is lib/server-php.
<?php
require __DIR__ . '/vendor/autoload.php';
use Attackfee\Protocol;
$claims = Protocol::verifyPass($secret, $pass, time(), $siteId, 'write');
A bad pass throws Attackfee\AttackfeeError. The WordPress plugin is the PHP issuer: the same routes live under /wp-json/attackfee/v1/. On a theme form, call attackfee_wp_verify_request('write') before handling the post. The WordPress page covers that.
/v1 API
GET /v1/healthreports the issuer.GET /v1/challengereturns a challenge for a write. Asking for a read is refused.POST /v1/redeemturns finished work into a pass.GET /v1/statusreports whether a pass is still good, without spending a use.POST /v1/siteverifyis for your own server. Send the secret and the pass. It spends one use.GET /v1/pricereturns the current check for one write, and the work alternative. It mints nothing.
GET /.well-known/attackfee.json and GET /.well-known/agents.json are free. They describe the write check. They do not identify the caller.