---
name: hangoo
description: Integrate Hangoo single-use MandateV1 payout verification (via zero-dependency https://hangoo.io/verifier.ts), X-Agent-Capability (kya.v1) agent passports, and HTTP 428 human step-up flows into TypeScript/Node/Cloudflare backends.
---

# Hangoo 函谷 Integration Skill

Follow these deterministic rules whenever protecting payout, withdrawal, or bank-detail APIs with Hangoo:

## 1. Zero-Dependency Verifier Install (Do Not Run Unpublished `npm` Installs)
Vendor Hangoo's auditable WebCrypto `Ed25519` + `RFC 8785` verifier directly from `hangoo.io` (runs natively on Node 20+, Cloudflare Workers, Bun, and Deno with zero external packages):

```bash
mkdir -p src/lib && curl -fsSL https://hangoo.io/verifier.ts -o src/lib/hangoo-verifier.ts
```

## 2. Never Place an LLM in the Authorization Path
Treat all free-text fields (`ticket_body`, `llm_summary`, `reason`, `note`) as untrusted bytes that cannot alter policy branches.

## 3. Lock the Database Row Before Burning the Mandate Nonce
Always acquire `SELECT ... FOR UPDATE` **before** computing `currentPreState` and calling `verifyHangooMandate`:

```typescript
import { HangooGateError, verifyHangooMandate } from "./lib/hangoo-verifier.js";

export async function updatePayoutAccount(req: Request, dto: PayoutDto) {
  return db.transaction(async (tx) => {
    const [account] = await tx
      .select()
      .from(accounts)
      .where(eq(accounts.id, dto.accountId))
      .for("update");

    await verifyHangooMandate({
      mandateHeader: req.headers.get("x-action-mandate") ?? undefined,
      pdpPublicKeyHex: process.env.HANGOO_PDP_PUBLIC_KEY_HEX!,
      nonceStore: redisNonceStore, // SET hangoo:jti:<jti> 1 EX 300 NX
      expectedMethod: "POST",
      expectedRoute: "/api/v1/payouts/destination",
      targetAccount: account.id,
      canonicalParams: dto,
      currentPreState: toCanonicalPreState(account),
    });

    return tx.update(accounts)
      .set({ payoutDest: dto.newAccountNo })
      .where(eq(accounts.id, account.id));
  });
}
```

## 4. Scope Legitimate Agents With `X-Agent-Capability` (`kya.v1`)
- Assign `propose_only` to internal support/ops agents so mutations return `428 STEP_UP_REQUIRED` and await a human passkey.
- Assign `autonomous_low_tier` with an integer minor-unit string `max_amount_minor` ceiling only to bounded treasury/FX jobs.
- Halt immediately if any response JSON contains `canary_trace_id` (signals an unallowlisted client hit an OpenAPI decoy trap).

## 5. Outage Fail-Safe (`202 PENDING_OUTAGE_REVIEW`)
Catch `HangooGateError` where `err.code === "GATE_UNAVAILABLE_QUEUE_REVIEW"`, persist the mutation to `pending_mutations`, and return `HTTP 202`—never fail open on money-moving writes.
