From e3f5fed01f8a2d28524ce5a1b3ad86b22b4f1c3d Mon Sep 17 00:00:00 2001 From: Chris Leal <184772742+chrisjleal@users.noreply.github.com> Date: Tue, 21 Jul 2026 08:00:01 -0600 Subject: [PATCH 1/2] Document x402 v2 trust checks --- docs/api/overview.mdx | 2 +- docs/openapi/public-api.json | 28 +++++++- docs/platform/billing.mdx | 2 +- docs/platform/x402.mdx | 125 +++++++++++++++++------------------ 4 files changed, 90 insertions(+), 67 deletions(-) diff --git a/docs/api/overview.mdx b/docs/api/overview.mdx index bda4384e..23926e31 100644 --- a/docs/api/overview.mdx +++ b/docs/api/overview.mdx @@ -39,7 +39,7 @@ Send end users through the **[JavaScript SDK](../sdks/javascript)** or **[Hosted The SDK's `getGate()` / `fulfillGate()` wrap the gate endpoints above. -> **Scope note:** This reference covers the core HTTP proof and verification surface. Gate endpoints (`/api/v1/profile/gates/{gateId}`, `.../fulfill`, `/api/v1/profile/gates/discoverable`) and `POST /api/v1/payments/verify` (x402 pay-per-call settlement) are product checkout endpoints documented in [Hosted Gate Checkout](../platform/hosted-gate-checkout) and [x402](../platform/x402); they are intentionally not included in the OpenAPI reference on the API Reference tab. +> **Scope note:** This reference covers the core HTTP proof and verification surface. Gate endpoints (`/api/v1/profile/gates/{gateId}`, `.../fulfill`, `/api/v1/profile/gates/discoverable`) are product checkout endpoints documented in [Hosted Gate Checkout](../platform/hosted-gate-checkout). Standards-native x402 v2 payment for `GET /api/v1/proofs/check` is documented in [x402](../platform/x402). **Same-origin in the product app:** `https://neus.network/api/v1/gates/{gateId}` and `.../fulfill` return the same gate contract for browser calls. Server integrations should call `api.neus.network` paths directly (or use the SDK). diff --git a/docs/openapi/public-api.json b/docs/openapi/public-api.json index 3b2f83dd..cc1ca344 100644 --- a/docs/openapi/public-api.json +++ b/docs/openapi/public-api.json @@ -2169,7 +2169,7 @@ "get": { "operationId": "proofCheck", "summary": "Check gate eligibility or proof criteria (server-side)", - "description": "Primary server-side integrator endpoint for access control. Pass gateId from your deployed gate, or explicit verifier/criteria filters. Returns eligible plus matched proof references without exposing private proof payloads.", + "description": "Primary server-side integrator and x402 v2 resource for pre-action trust decisions. Pass gateId from your deployed gate, or explicit verifier/criteria filters. Unpaid public calls receive HTTP 402 with base64-encoded PAYMENT-REQUIRED instructions; retry the identical request with PAYMENT-SIGNATURE. Returns eligible plus matched proof references without exposing private proof payloads.", "tags": [ "Proofs", "Gates" @@ -2602,6 +2602,14 @@ "$ref": "#/components/schemas/GateCheckResponse" } } + }, + "headers": { + "PAYMENT-RESPONSE": { + "description": "Base64-encoded x402 v2 settlement result when the request was paid with x402", + "schema": { + "type": "string" + } + } } }, "400": { @@ -2624,6 +2632,24 @@ } } }, + "402": { + "description": "x402 v2 payment required", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ErrorResponse" + } + } + }, + "headers": { + "PAYMENT-REQUIRED": { + "description": "Base64-encoded x402 v2 PaymentRequired object", + "schema": { + "type": "string" + } + } + } + }, "500": { "description": "Server error", "content": { diff --git a/docs/platform/billing.mdx b/docs/platform/billing.mdx index 0602e25a..29cfe393 100644 --- a/docs/platform/billing.mdx +++ b/docs/platform/billing.mdx @@ -73,7 +73,7 @@ For a dedicated agent account, create identity first, then send the user through ## When credits run out -Billable calls return **402** with a quote. Complete payment and retry with `PAYMENT-SIGNATURE`. +The public trust-check resource supports standards-native x402 v2 payment. See [x402 pay-per-call](./x402) for the payable URL, transport headers, and retry flow. ## Advanced server integration diff --git a/docs/platform/x402.mdx b/docs/platform/x402.mdx index b7412013..68957127 100644 --- a/docs/platform/x402.mdx +++ b/docs/platform/x402.mdx @@ -1,97 +1,94 @@ --- title: x402 pay-per-call -description: Charge per request for APIs and agents — a signed quote on 402, pay, then retry with one header. +description: Pay for NEUS trust checks with x402 v2 and USDC on Base — no account or prepaid balance required. icon: coins --- -x402 turns any billable NEUS call into pay-as-you-go. When prepaid credits cannot cover a request, NEUS returns **HTTP 402** with a signed quote. Pay the quote, then retry the **same request** with one header. It is built for agents and machine-to-machine APIs that settle value as they go — no subscription, no human in the loop. +NEUS exposes a standards-native x402 v2 resource for agents and server applications that need a trust decision before taking an action. A caller can discover the price, authorize USDC, retry the same request, and receive the result without creating a NEUS account. -## Flow +## Payable HTTP resource + +The canonical x402 resource is: + +```text +GET https://api.neus.network/api/v1/proofs/check +``` + +Pass either a deployed `gateId` or explicit receipt criteria. This example checks whether an account has a reusable `ownership-basic` receipt: + +```bash +curl -i --get https://api.neus.network/api/v1/proofs/check \ + --data-urlencode "address=0xYOUR_ACCOUNT" \ + --data-urlencode "verifierId=ownership-basic" +``` + + + `https://mcp.neus.network/mcp` is the authenticated MCP transport for MCP clients. HTTP x402 clients should use the `api.neus.network` resource above. + + +## Standards-native v2 flow - - Make your normal request (for example `POST /api/v1/verification`). + + Send the final HTTP method, URL, query parameters, and body you intend to use. - - If credits are short, NEUS responds **402** with a quote in the body and the **`PAYMENT-REQUIRED`** response header. + + An unpaid request returns HTTP `402`. The `PAYMENT-REQUIRED` response header contains a base64-encoded x402 v2 `PaymentRequired` object with `x402Version: 2`, the resource, and an `accepts` array. - - Settle in USDC (or native ETH) via `POST /api/v1/payments/verify`. NEUS returns a one-time payment receipt. + + Select the advertised `exact` requirement and let an x402 v2 client create the payment payload. NEUS currently accepts USDC settlement on Base for production. - - Repeat the original call with the receipt in the **`PAYMENT-SIGNATURE`** header. The call now succeeds. + + Repeat the same request with the base64-encoded payment payload in `PAYMENT-SIGNATURE`. NEUS verifies it before execution and settles it after a successful call. + + + A successful paid response includes `PAYMENT-RESPONSE`, a base64-encoded settlement result containing the network and transaction reference. -## The 402 response - -The body carries `error.code: "INSUFFICIENT_CREDITS"` and an `x402` block you can act on directly: - -```json -{ - "success": false, - "error": { "code": "INSUFFICIENT_CREDITS", "remaining": 0, "required": 4 }, - "x402": { - "scheme": "x402", - "requiredCredits": 4, - "remainingCredits": 0, - "quote": { - "quoteId": "…", - "amountUSD": 0.01, - "amountCents": 1, - "creditsNeeded": 4, - "exp": 1713312300000 - }, - "pay": { "pricing": "/api/v1/payments/pricing" }, - "receiptHeader": "PAYMENT-SIGNATURE" - } -} -``` +The three x402 v2 transport headers are: -The same quote is also sent as JSON in the `PAYMENT-REQUIRED` response header. `exp` is a millisecond timestamp — quotes are short-lived, so pay and retry promptly. +| Header | Direction | Purpose | +| --- | --- | --- | +| `PAYMENT-REQUIRED` | NEUS → caller | Base64-encoded price and payment requirements on HTTP 402 | +| `PAYMENT-SIGNATURE` | Caller → NEUS | Base64-encoded payment payload on the retry | +| `PAYMENT-RESPONSE` | NEUS → caller | Base64-encoded settlement result | -## Pay and retry - -```bash -# 1. Original call returns 402 with the quote above. -# 2. Settle the quote (USDC or ETH), then retry with the receipt: -curl -X POST https://api.neus.network/api/v1/verification \ - -H "Content-Type: application/json" \ - -H "PAYMENT-SIGNATURE: " \ - -d '{ /* the same body as the original request */ }' -``` +Do not parse these headers as raw JSON. Use an x402 v2 client or the header helpers from `@x402/core/http`. -Get the receipt by settling the quote through `POST /api/v1/payments/verify` (`type: "x402"`). The successful response returns the receipt token and a `PAYMENT-RESPONSE` header. Each receipt is **single-use** — reusing one is rejected. +## Bazaar discovery -## Payment methods +The trust-check resource declares the official x402 v2 Bazaar extension with: -| Rail | Where it settles | -|------|------------------| -| **USDC** | Base mainnet (`eip155:8453`), with Ethereum mainnet as fallback | -| **Native ETH** | NEUS treasury | +- a semantic description oriented around pre-action trust and authority decisions; +- a realistic query example; +- JSON Schema for supported input fields; +- output metadata, schema, and an example result; +- an `exact` USDC payment requirement on a CAIP-2 Base network. -Card (Stripe) is **not** used for x402 API billing — it is available for [gate checkout](./hosted-gate-checkout). Live unit, minimum, and maximum pricing: `GET /api/v1/payments/pricing`. +Compatible facilitators can index the declared resource after a paid call settles. Discovery catalogs refresh asynchronously, so a newly settled resource may not appear immediately. ## Agents that pay on their own -Pair x402 with an agent permission receipt to set a spending cap. The receipt identifies the agent, records who approved it, and limits how much it may pay. +Pair x402 with an `agent-delegation` receipt to constrain autonomous spend: -- Grant `agent-delegation` with `scope: "payments:x402"` and a `maxSpend` cap. -- `maxSpend` is a whole-number string in token base units — for USDC (6 decimals), 25 USDC is `"25000000"`. Use `toAgentDelegationMaxSpend('25', 6)` from `@neus/sdk`. -- The agent can pay per call up to the cap; spend beyond it is refused. +- set `scope: "payments:x402"`; +- restrict `allowedPaymentTypes` to `x402`; +- store `maxSpend` as a whole-number string in token base units (USDC has 6 decimals); +- reject payment when the requested amount exceeds the remaining delegated cap. -Details: [Agent permissions](../agents/agent-delegation). +Use `toAgentDelegationMaxSpend('25', 6)` from `@neus/sdk` to represent a 25 USDC cap as `"25000000"`. ## Next - - Credits, who pays, and the 402 fallback. + + Signing and session rules for raw verification calls. - - Charge visitors with USDC or card. + + Connect the separate hosted MCP transport. - - Spend caps for autonomous agents. + + Authority scopes and autonomous spending caps. From f48940efc672c62e293fcd43626faad7796cfcb3 Mon Sep 17 00:00:00 2001 From: Chris Leal <184772742+chrisjleal@users.noreply.github.com> Date: Tue, 21 Jul 2026 08:11:53 -0600 Subject: [PATCH 2/2] chore: docs and CLI spawn --- docs/index.mdx | 4 ++-- docs/verifiers/README.md | 2 +- sdk/cli/neus.mjs | 25 +++++++++++++++++-------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/docs/index.mdx b/docs/index.mdx index 5f17ae13..f991fa82 100644 --- a/docs/index.mdx +++ b/docs/index.mdx @@ -24,8 +24,8 @@ Three drop-in paths cover most products. Pick the one that matches what you are One command: `neus setup` — same account and receipts in Cursor, Claude Code, Codex, and VS Code. - - Agent identity and permission receipts a runtime can check before tools run. + + Portable agent identity, context, and control across any runtime. diff --git a/docs/verifiers/README.md b/docs/verifiers/README.md index d21e591b..8576362c 100644 --- a/docs/verifiers/README.md +++ b/docs/verifiers/README.md @@ -1,6 +1,6 @@ # Verifier JSON Schemas -Request shapes for the public verifier catalog. Guides for people integrating NEUS live under **[Verification](../verification/verifiers)**. +Request shapes for the public verifier catalog. Guides for people integrating NEUS live under **[Verification](../verification/verifiers.mdx)**. ## Source of truth diff --git a/sdk/cli/neus.mjs b/sdk/cli/neus.mjs index 0887c13c..0f7a23e5 100644 --- a/sdk/cli/neus.mjs +++ b/sdk/cli/neus.mjs @@ -1,5 +1,5 @@ #!/usr/bin/env node -import { exec, spawnSync } from 'node:child_process'; +import { spawn, spawnSync } from 'node:child_process'; import { createHash, randomBytes } from 'node:crypto'; import fs from 'node:fs'; import os from 'node:os'; @@ -2098,13 +2098,22 @@ async function runAuthBrowser(options) { logStep('next', 'wait', 'finish sign-in in the browser'); } - const openCommand = process.platform === 'win32' - ? `cmd /c start "" "${authUrl.replace(/"/g, '\\"')}"` - : process.platform === 'darwin' - ? `open "${authUrl.replace(/"/g, '\\"')}"` - : `xdg-open "${authUrl.replace(/"/g, '\\"')}"`; - exec(openCommand, { shell: true }, err => { - if (err && !options.json) { + // shell:false + argv array passes authUrl as a single argv element with no + // shell re-parse, so URL metacharacters (& | ; etc.) cannot be interpreted + // as shell control — eliminates the command-injection sink. + const opener = + process.platform === 'win32' + ? { command: 'explorer', args: [authUrl] } + : process.platform === 'darwin' + ? { command: 'open', args: [authUrl] } + : { command: 'xdg-open', args: [authUrl] }; + const browser = spawn(opener.command, opener.args, { + shell: false, + stdio: 'ignore', + windowsHide: true + }); + browser.on('error', () => { + if (!options.json) { logStep('warn', 'browser', 'open the URL above manually'); } });