{
  "schema_version": "v1",
  "purpose": "Machine-readable capability surface for AI agents. Mirrors the llms.txt 'Feature status' section so an agent can discover what it may do without reading prose. Written for the AIPAY agent surface (agent/mcp-server.mjs, agent/cli.mjs).",
  "generated_for": "AI agents and third-party integrators",
  "product": "AIPAY",
  "site": "https://aipay.im",
  "human_docs": "https://aipay.im/llms.txt",
  "non_custodial": true,
  "human_approval_required_for_money_moves": true,
  "agent_identity": {
    "supported": true,
    "how": "node agent/cli.mjs keystore init --generate",
    "keys_are_the_agents_own": true,
    "can_access_user_wallet": false,
    "read_only_tools_need_no_credentials": false,
    "credentials_note": "Tool discovery needs no credentials. Cloud reads require a merchant credential. Wallet reads may require the local agent wallet."
  },
  "surfaces": {
    "mcp_stdio": "agent/mcp-server.mjs",
    "cli": "agent/cli.mjs",
    "tool_count": 40,
    "tool_names": [
      "aipay_audit_tail",
      "aipay_capability_delegate",
      "aipay_capability_grant",
      "aipay_capability_import",
      "aipay_capability_list",
      "aipay_capability_revoke",
      "aipay_chains_list",
      "aipay_cloud_orders_cancel",
      "aipay_cloud_orders_create",
      "aipay_cloud_orders_get",
      "aipay_cloud_orders_list",
      "aipay_cloud_profile_get",
      "aipay_escalations_deny",
      "aipay_escalations_get",
      "aipay_escalations_list",
      "aipay_mandate_list",
      "aipay_merchant_products_create",
      "aipay_merchant_products_delete",
      "aipay_merchant_products_list",
      "aipay_merchant_profile_get",
      "aipay_merchant_profile_set",
      "aipay_orders_confirm",
      "aipay_orders_create",
      "aipay_orders_get",
      "aipay_orders_list",
      "aipay_pay",
      "aipay_payment_options",
      "aipay_payment_request_create",
      "aipay_policy_status",
      "aipay_quote",
      "aipay_receive_uri",
      "aipay_spending_kill",
      "aipay_spending_revive",
      "aipay_spends_list",
      "aipay_stream_close",
      "aipay_stream_list",
      "aipay_stream_open",
      "aipay_wallet_addresses",
      "aipay_wallet_balances",
      "aipay_wallet_history"
    ],
    "cloud_tool_access": {
      "credential": "Merchant API key. These tools do not sign or spend funds.",
      "read_only": ["aipay_cloud_orders_get", "aipay_cloud_orders_list", "aipay_cloud_profile_get"],
      "writes": ["aipay_cloud_orders_cancel", "aipay_cloud_orders_create"]
    },
    "error_guidance": {
      "fields": [
        "code",
        "nextAction",
        "retryable",
        "retryAfterMs"
      ],
      "default": "unknown codes are stop / non-retryable",
      "note": "Every CoreError carries what to do next; the CLI prints it and the MCP error payload exposes it as structuredContent. Never retry a money operation just because it looked transient."
    },
    "skill": {
      "path": "/skills/aipay/SKILL.md",
      "self_check": "read options + profile + capability + MSG status; create nothing, sign nothing, never print keys",
      "note": "Step-by-step operating manual over these same tools. Includes granular consent (create != pay) and an interruption playbook (reuse merchantOrderId, never re-create, never swap tx hashes)."
    },
    "payment_options": {
      "tool": "aipay_payment_options",
      "cli": "aipay-agent options",
      "note": "Per chain: registered assets, decimals, the smallest payable amount (one base unit) and the per-payment cap of an existing capability. No USD minimum exists; every unavailable chain carries a reason."
    },
    "next_actions": {
      "values": [
        "pay_now",
        "share_link",
        "await_human_approval",
        "wait",
        "stop"
      ],
      "note": "Closed vocabulary returned with a request, a payment result or an order, so an agent branches on a value instead of prose. `stop` is terminal for that request: never pay it again after an expiry or a conflict."
    }
  },
  "streams": {
    "available": true,
    "phase": "P4.3 agent integration (local policy only)",
    "model": "allowance-pull (non-custodial): the payer approves the contract, each charge pulls payer -> payee with a fee cut, and the contract balance stays 0",
    "local_role": "authorize one session at open, reserve maxTotal against the window/lifetime budgets, and export the contract message. The reserved cap is only credited back when the close carries a settlement reference: the local ledger cannot read the chain, so an amount the agent states by itself must not widen the budget.",
    "on_chain_role": "the contract caps rate_per_sec, max_total and max_duration_secs on every charge; the chain is the source of truth for money",
    "chain_mirror": "unavailable",
    "messages": {
      "open": "open_session {session_id, payee, rate_per_sec, max_total, max_duration_secs, terms_hash} (base units)",
      "close": "close_session {session_id, reason?}"
    },
    "limits": {
      "rate": "ratePerSecond <= capability.stream.maxRatePerSecond",
      "total": "maxTotal <= capability.stream.maxTotal <= budget.perPayment",
      "duration": "maxDurationSeconds <= capability.stream.maxDurationSeconds",
      "budget": "the whole session cap is reserved, so many sessions cannot bypass the window or lifetime budget"
    },
    "deny_only": true,
    "deny_only_note": "v1 has no escalation artifact: an over-limit session is denied (stream_limit_exceeded), never held for approval",
    "no_custody": true,
    "no_custody_note": "AIPAY never holds stream funds; the payer can stop by revoking the allowance, which is why the payee accepts a revocable guarantee",
    "tools": [
      "aipay_stream_open",
      "aipay_stream_close",
      "aipay_stream_list"
    ],
    "cli": "aipay-agent stream open|close|list",
    "signs_or_broadcasts": false,
    "anchor": "every stream message is anchored to the session's terms_hash (sha256 of the canonical terms); MSGChain is not launched, so nothing here moves real money yet"
  },
  "policy_engine": {
    "available": true,
    "location": "local",
    "on_chain": false,
    "fail_closed": true,
    "default_when_no_capability": "deny",
    "verdicts": [
      "allow",
      "escalate",
      "deny"
    ],
    "enforced_on": [
      "aipay_quote",
      "aipay_pay"
    ],
    "shadow": {
      "available": true,
      "mode": "static",
      "chain_mirror": "unavailable",
      "reason": "agent_principal_authority_v1, agent_execution_guard_v1 and ai_agent_constitution_v2 are not in the MSGChain genesis set",
      "surface": {
        "status": "aipay_policy_status.shadow",
        "cli": "aipay-agent shadow (also: policy --shadow)",
        "page": "/en/agent (read-only snapshot viewer)"
      },
      "fidelity": {
        "full": [
          "within_capability",
          "capability_missing",
          "capability_revoked",
          "capability_expired",
          "timelock_pending",
          "per_payment_cap_exceeded",
          "budget_exhausted"
        ],
        "partial": [
          "chain_not_allowed",
          "asset_not_allowed",
          "recipient_not_allowed",
          "amount_requires_approval",
          "stream_limit_exceeded"
        ],
        "local_only": [
          "approval_expired",
          "approval_invalid",
          "approval_mismatch",
          "approval_replayed",
          "capability_exceeds_parent",
          "capability_invalid",
          "capability_unsigned",
          "capability_untrusted",
          "origin_not_allowed",
          "session_killed",
          "stream_not_allowed",
          "total_budget_exhausted"
        ]
      },
      "unresolved_fields": [
        "lifetime_total_local_only",
        "asset_addresses_unresolved",
        "budget_scope_hash_encoding_unconfirmed",
        "action_hash_encoding_unconfirmed",
        "origin_allowlist_local_only",
        "non_msg_chains_local_only",
        "merchant_ids_local_only",
        "recipient_resolution_required",
        "escalation_threshold_local_only",
        "approval_artifact_local_only",
        "principal_account_unresolved",
        "controller_set_unresolved",
        "guard_smart_account_contract_required",
        "guard_account_binding_unresolved",
        "profile_id_unresolved",
        "budget_fee_and_gas_caps_unresolved",
        "budget_velocity_limits_unresolved"
      ],
      "note": "Static mirror report only. It never changes a verdict and never claims on-chain enforcement."
    }
  },
  "marketing": {
    "site": "https://aipay.im",
    "primaryCta": "https://aipay.im/merchant/dashboard",
    "developerEntry": "https://aipay.im/developers",
    "integrationGuide": "https://aipay.im/integrate",
    "pricing": "https://aipay.im/pricing",
    "trust": "https://aipay.im/trust",
    "quickStart": "POST /v1/merchants -> POST /v1/orders -> GET /v1/orders/{reference}/status",
    "verifiableFacts": {
      "chainsSettledOnChain": 10,
      "keysOrFundsHeldByUs": 0,
      "commissionTakenFromAPayment": "0%",
      "productionChecksPassing": "53/53",
      "externalAuditFindingsAllDispositioned": 22
    },
    "note": "Every number here is checkable against the running service or this repository."
  },
  "distribution": {
    "tool_availability": "The download manifest's tool_names describes the version it actually serves. A legacy manifest without that field predates versioned tool discovery. Query the installed MCP server via tools/list or the installed CLI via tool --list.",
    "canonical": "https://aipay.im/downloads/",
    "installScript": "https://aipay.im/downloads/install.sh",
    "repo": "https://github.com/aipayim/aipay-agent",
    "mirrorNote": "The GitHub repository mirrors the same bytes (same sha256); aipay.im is the canonical host.",
    "manifest": "https://aipay.im/downloads/agent-latest.json",
    "tarball": "https://aipay.im/downloads/aipay-agent-<version>.tgz",
    "checksums": "https://aipay.im/downloads/CHECKSUMS.txt",
    "requires": "Node.js >= 22.18",
    "install": "AIPAY_AGENT_VERSION=<version> bash install.sh",
    "contents": "agent/ (two bundled .mjs files: the CLI and the stdio MCP server) plus the watcher SDK source the `aipay watch` command runs",
    "policy": {
      "mode": "allowlist+bundle",
      "allow_paths": [
        "agent/**",
        "src/lib/**",
        "sdk/aipay-watch/src/**"
      ],
      "shipped_paths": [
        "agent/cli.mjs",
        "agent/mcp-server.mjs",
        "sdk/aipay-watch/**",
        "package.json"
      ],
      "no_keys": true,
      "no_state": true,
      "no_docs_or_contracts": true,
      "no_source_tree": true,
      "deny_content": [
        "github tokens",
        "npm tokens",
        "openai/nvidia keys",
        "PEM private keys",
        "telegram bot tokens",
        "deployment env secrets"
      ],
      "note": "The published entry points are single-file ESM bundles built with esbuild. A module is inlined only if the bundler resolves it under agent/, src/lib/ or sdk/aipay-watch/src/ (checked against the bundler metafile), and only the bundles, the SDK source and package.json are published — no .ts file and no src/ tree reach the tarball. Every published file is scanned for credential shapes and listed with its sha256 in the manifest."
    },
    "bundled": true
  },
  "capabilities": {
    "supported": true,
    "fields": [
      "scope",
      "budget",
      "expiry",
      "issuer",
      "riskLevel",
      "approval",
      "timelockSeconds"
    ],
    "v2_optional_fields": [
      "principalAccount",
      "actionClasses",
      "policyId",
      "budgetId",
      "budgetPeriod",
      "expiresHeight",
      "actionsPerPeriod",
      "velocity",
      "chainEpoch"
    ],
    "empty_list_semantics": "none (never any)",
    "signed": true,
    "signature": "EIP-191 personal_sign over the frozen canonical form (aipay-grant-v1): scope, budget, expiry, approval mode, issuer - every field.",
    "who_signs": "the human's approval key (the same key that signs escalated payments). A delegated child is signed by the delegating holder and keeps the parent's issuer.",
    "trust_anchor": "the address of the approval key on this machine (~/.aipay/agent/approval.json). A capability signed by anybody else is not honoured there; with no approval key on the machine, no capability is honoured.",
    "engine_refuses_unsigned": true,
    "unsigned_verdict": "capability_unsigned",
    "untrusted_verdict": "capability_untrusted",
    "created_by": "aipay-agent capabilities grant (creates AND signs it with the human's approval key), or a signed envelope imported with aipay_capability_import.",
    "grant_tool": "aipay_capability_grant",
    "grant_tool_note": "It only imports an envelope a human signed; it cannot create a capability, and the agent holds no key that could sign one.",
    "migration": "aipay-agent capabilities sign --id <id> signs a capability that was stored before signing existed (the human signs what is stored).",
    "agent_can_grant_itself": false,
    "agent_can_delegate_within_scope": true,
    "delegation": {
      "model": "A subject may issue a child capability that is a strict subset of one it holds; self-granting stays impossible.",
      "signer": "the delegator (the parent capability's holder) for a delegation, otherwise the issuer",
      "approver": "capability.issuer (the human approval key); delegation never transfers approval authority",
      "holder_required_on_parent": true,
      "issuer_immutable": true,
      "bounds": [
        "scope subset of parent (chains, assets, recipients, merchants, originAllowlist)",
        "expiry <= parent expiry",
        "budget.perPayment/perWindow/total <= parent remaining",
        "budget.windowSeconds >= parent (a shorter window refills sooner, so it is wider)",
        "approval.mode is never weaker than the parent's, and escalateAbove is never raised",
        "timelockSeconds is never shortened",
        "the stream ceiling is never raised, and a child cannot invent streams the parent does not have",
        "riskLevel is never lowered; the height mirrors (expiresHeight, budgetPeriod, actionsPerPeriod, velocity) stay inside the parent's",
        "depth = 1: a delegated capability cannot delegate further"
      ],
      "requires_parent_id": true,
      "envelope": "aipay-grant-v1",
      "import_tool": "aipay_capability_import",
      "delegate_tool": "aipay_capability_delegate",
      "export_is_human_only": true,
      "export_note": "Creating an envelope needs the human approval key (CLI `capabilities export`, or the `/agent` page which decrypts the same key file in the browser), which the agent does not hold; import never needs a key.",
      "transport": {
        "encrypted": "CryptoKey.im carrier (.ckx or .png) via the web app; wrapper schema im.aipay.grant-transport, CKX label \"AIPAY capability grant\"",
        "plaintext_fallback": "JSON with encrypted:false, written mode 0600 (CLI: capabilities export --out <file>)",
        "encryption_is_not_authenticity": "the envelope signature is verified after decryption and before import; a decryptable payload is not a trusted one"
      },
      "verification_order": "signature first, then parent bounds (scope subset, expiry, budget, depth)",
      "default_enabled": false,
      "default_enabled_note": "Declared, never implicit: a child capability exists only when an envelope for it is signed.",
      "shared_allowance": "a delegation shares the parent's allowance: what the children spent counts against the parent, and a child may only spend what the parent has left. A revoked or expired parent withdraws the delegation.",
      "bounds_checked_at": "import AND every payment (the local state file is writable, so the engine re-checks them)"
    },
    "revocable": true,
    "kill_switch": true,
    "kill_switch_actor": [
      "human",
      "agent"
    ],
    "same_policy_for_human_and_agent": true,
    "audit_actor": [
      "human",
      "agent"
    ],
    "agent_can_grant_itself_note": "Enforced against the agent's own tools: the grant tool accepts only a signed envelope, the engine refuses a capability with no signature or one signed by a key this machine does not trust, and a delegated child's authority chain (parent signature, parent alive, bounds) is re-checked on every payment. It is NOT enforced against somebody who can rewrite the agent's home directory - see trust_anchor_limit.",
    "trust_anchor_limit": "the agent process runs as the same OS user, so it can rewrite that file: the signature stops 'the agent grants itself a capability with its own tools', not 'somebody with write access to your home directory'. Keep the approval key's passphrase different from the wallet's (AIPAY_AGENT_APPROVAL_PASSPHRASE)."
  },
  "escalation": {
    "supported": true,
    "approval": "single-use signature (secp256k1, EIP-191 personal_sign)",
    "agent_can_self_approve": false,
    "agent_can_call_approve_tool": false,
    "channels": [
      "cli"
    ],
    "replay_protection": "consumed approval nonce"
  },
  "signing": {
    "payment_credentials": "the agent's own key (EVM secp256k1, Tron secp256k1 at m/44'/195'/0'/0/0, Solana ed25519; MSG, when enabled, from the agent mnemonic)",
    "human_keys_exposed_to_agent": false,
    "approval_signature": "secp256k1 EIP-191 personal_sign"
  },
  "rails": {
    "evm": {
      "available": true,
      "fee_for_aipay": false
    },
    "solana": {
      "available": true,
      "fee_for_aipay": false
    },
    "tron": {
      "available": true,
      "fee_for_aipay": false,
      "assets": [
        "TRX",
        "USDT (TRC20)"
      ],
      "confirmation_depth": 19,
      "note": "sender needs TRX for bandwidth/energy"
    },
    "msgchain": {
      "available": false,
      "reason": "mainnet not launched by the chain (MSGChain publishes network_status=not_launched, mainnet_verdict=No-Go)",
      "contract_routed_design_ready": true,
      "devnet_demonstrated": true,
      "config_gate": "public/msg-config.json"
    }
  },
  "not_available": [
    "MSG (MSGChain) addresses, balances and payments",
    "fiat on-ramp (buy crypto with a card)",
    "NFT gallery",
    "EVM token swaps",
    "on-chain policy enforcement (the policy engine is local today)",
    "a human approval channel other than the local CLI",
    "off-chain channel tools in the MCP surface (channels live in the merchant HTTP API)"
  ],
  "orders": {
    "merchant_order_id": {
      "supported": true,
      "scope": "(merchantAddress, merchantOrderId)",
      "idempotent_replay": "same id + same parameters returns the original request (deduplicated: true)",
      "conflict": "same id + different parameters -> merchant_order_conflict"
    },
    "payment_confirmed_is_not_delivery": {
      "delivery_tracked": false,
      "value": "not_tracked",
      "note": "A chain-verified confirmation only proves the payment. AIPAY never claims the merchant shipped, credited or fulfilled anything."
    }
  },
  "offchain": {
    "available": true,
    "model": "orchestration-only: the merchant owns the payment link, AIPAY never calls the provider, never stores a provider credential and never receives the money",
    "channel_kinds": [
      "alipay",
      "wechat",
      "unionpay",
      "stripe",
      "other"
    ],
    "order_creation": {
      "field": "channelId",
      "endpoint": "POST /v1/orders",
      "amount_currency": "the channel's settleCurrency (2 decimals); the response carries reference, channel, payUrl",
      "payer_status": "GET /v1/orders/:reference/status exposes channel and payUrl; off-chain orders are never swept for chain transfers"
    },
    "confirmation_sources": [
      {
        "source": "merchant_manual",
        "auth": "merchant API key",
        "endpoint": "POST /v1/orders/:reference/offchain-confirm",
        "requires": "channelRef (receipt/serial)"
      },
      {
        "source": "merchant_webhook",
        "auth": "per-channel HMAC secret",
        "endpoint": "POST /v1/offchain/confirmations",
        "signature": "sha256=HMAC-SHA256(secret, \"<timestamp>.<raw body>\")",
        "window_seconds": 300,
        "note": "signature is verified before any order lookup; a bad signature and an unknown channel answer identically"
      },
      {
        "source": "statement",
        "auth": "merchant API key",
        "endpoint": "POST /v1/offchain/statements?channelId=",
        "note": "CSV import proposes matches only (confirmed=0); each row is adopted explicitly via /:id/adopt"
      },
      {
        "source": "statement_auto",
        "auth": "merchant API key",
        "endpoint": "POST /v1/offchain/statements?channelId=",
        "requires": "the merchant's own automation policy (PATCH /v1/merchants/me/automation)",
        "note": "the policy confirms the row by itself, within its ceilings; the confirmation is the merchant's own statement row, not chain evidence"
      }
    ],
    "trust": {
      "onchain": "chain evidence (channel: onchain + transaction hash)",
      "merchant_manual": "merchant receipt",
      "merchant_webhook": "merchant receipt, signed by the caller",
      "statement": "adopted statement row",
      "statement_auto": "statement row confirmed under the merchant's own automation policy; still a merchant receipt",
      "rule": "anything other than onchain is a merchant claim; never describe it as chain-verified"
    },
    "limits": {
      "statement_rows": 10000,
      "statement_bytes": 2097152,
      "statement_match_window_minutes": 10,
      "signature_window_minutes": 5,
      "policy_channels": 8,
      "policy_min_order_age_seconds": 86400
    },
    "agent_tools": {
      "available": false,
      "reason": "channels are configured and confirmed through the merchant HTTP API or the merchant UI, not through the MCP toolset",
      "consequence": "do not invent a channel tool; if a task needs an off-chain channel, hand over the HTTP endpoints above"
    }
  },
  "boundaries": [
    "enforced:false in a payment quote means no engine was wired in, never that a check passed",
    "an escalated payment is not a payment: nothing is signed until a human approval token is redeemed",
    "AIPAY never custodies funds and never asks a human for their recovery phrase"
  ],
  "merchant_api": {
    "platform_access": {
      "status": "live",
      "authorization": "merchant_opt_in",
      "grant": "POST /v1/merchants/me/platforms",
      "list_grants": "GET /v1/merchants/me/platforms",
      "revoke": "DELETE /v1/merchants/me/platforms/:id",
      "list_orders": "GET /v1/platform/orders",
      "get_order": "GET /v1/platform/orders/{reference}",
      "sync_orders": "GET /v1/platform/orders/changes (resume with epoch + nextAfter; rebuild on 409)",
      "webhook": "GET|POST|DELETE /v1/platform/webhook (signed order.confirmed|expired|cancelled; POST returns the secret once)",
      "delivery_log": "GET /v1/platform/deliveries",
      "replay_delivery": "POST /v1/platform/deliveries/:id/replay",
      "replay_failed": "POST /v1/platform/deliveries/replay-failed {limit?} (re-queue dead letters oldest first, max 25 per call; ordering per order is preserved)",
      "export_csv": "GET /v1/platform/orders/export.csv",
      "list_merchants": "GET /v1/platform/merchants?includeRevoked=&after=&limit= (active grants by default; revoked is a fact, not a deletion)",
      "invites": "GET|POST /v1/platform/merchants/invites (mint a one-time aipay_inv_ token; list by status) and DELETE /v1/platform/merchants/invites/:id (only unclaimed)",
      "claim": "POST /v1/merchants/claim {token, recipientAddress, chainKey} — the merchant creates its own key and receiving address; the platform only gets read access and never sees either",
      "rotate_own_key": "POST /v1/platform/keys/rotate (returns the new aipay_pk_ once; the previous key dies immediately, so persist it first)",
      "usage": "GET /v1/platform/usage (current-window read/export budget + grant counts; used=null means unknown, not unlimited)",
      "stats": "GET /v1/platform/stats?from=&to=&merchantId= (created vs confirmed per UTC day, per-asset base-unit totals; 92-day window; spends the export budget; amounts=null past 5000 orders instead of a partial sum)",
      "anomalies": "every order carries anomalies [{ code, detectedAt }] and an action (none|review|refund_from_merchant_wallet); codes: late_payment, unapplied_payment, duplicate_payment, payment_attribution_review, duplicate_receipt, unapplied_receipt, confirmation_regressed",
      "refunds": "AIPAY never executes refunds. Unresolved anomalies return review. refund_from_merchant_wallet is a reserved legacy value. Verify actual receipt, amount and ownership before deciding what to do.",
      "credential_prefix": "aipay_pk_",
      "reference_clients": "examples/merchant-node/aipay.mjs (Node) and examples/merchant-python/aipay.py (Python): createOrder/getOrder/listOrders/reconcile + verifyWebhook, with self-checks; no hosted sandbox — run the Worker locally",
      "read_only": true,
      "collectable": false,
      "requires_msg": false
    },
    "purpose": "Use AIPAY as a payment gateway from a backend, a platform or an AI agent. Merchant-side only: the key is created here and never leaves the caller.",
    "base_url": "https://api.aipay.im",
    "discovery": "GET /v1",
    "docs": "https://aipay.im/docs/integration.md",
    "human_entry": "https://aipay.im/en/integrate",
    "auth": "Authorization: Bearer aipay_sk_… — returned once by POST /v1/merchants, only SHA-256 stored; rotate via POST /v1/merchants/me/keys/rotate",
    "zero_fee": true,
    "custody": false,
    "provider_credentials": "never stored; off-chain money never reaches AIPAY",
    "onchain": {
      "create_order": "POST /v1/orders",
      "checkout": "order.checkoutUrl (hosted payer page, no account)",
      "payer_status": "GET /v1/orders/:reference/status"
    },
    "automation": {
      "available": true,
      "opt_in": true,
      "default_off": true,
      "endpoint": "GET|PATCH|DELETE /v1/merchants/me/automation",
      "auth": "Authorization: Bearer aipay_sk_… (the merchant's own key)",
      "purpose": "let the merchant declare which imported statement rows may confirm an order on their own, and up to what limit",
      "policy_shape": "{ \"v\": 1, \"statementAutoAdopt\": { \"enabled\": true, \"channels\": [\"ch_…\"], \"maxPerOrder\": \"50\", \"maxPerDay\": \"500\", \"minOrderAgeSeconds\": 0 } }",
      "requires": [
        "statementAutoAdopt.channels (ch_…, at most 8)",
        "statementAutoAdopt.maxPerOrder",
        "statementAutoAdopt.maxPerDay"
      ],
      "enabled_false_stores_nothing": true,
      "only_adds_a_gate": true,
      "same_path_as_manual_adopt": true,
      "cannot_confirm_onchain_orders": true,
      "caps_unit": "the channel's settle currency, 2 decimals (the off-chain order scale)",
      "daily_cap_resets": "00:00 UTC",
      "settle_currency_scoped": true,
      "confirmed_source": "statement_auto",
      "not_chain_evidence": true,
      "risk_owner": "merchant",
      "risk_attribution": "the merchant declares the authorization; AIPAY never custodies funds, never signs for the merchant and never verifies that a third-party channel really paid",
      "statement_import_response": [
        "autoAdopted",
        "autoAdoptSkipped"
      ],
      "skip_reasons": [
        "automation_disabled",
        "channel_not_in_policy",
        "order_too_new",
        "over_per_order_cap",
        "over_daily_cap",
        "policy_unreadable",
        "order_unavailable",
        "channel_currency_mismatch",
        "order_already_confirmed",
        "order_conflict"
      ],
      "daily_cap_enforcement": "the ceiling is checked inside the confirming write, so two parallel imports cannot both spend it",
      "one_row_one_order": "a statement row is claimed before it confirms anything, so one receipt can never confirm two orders",
      "audit_trail": [
        "order.confirmedSource = statement_auto",
        "order_events: automation_auto_adopt (policy:v1|maxPerOrder=…|maxPerDay=…|minAge=…)"
      ]
    },
    "webhook": {
      "events": [
        "order.confirmed",
        "order.expired",
        "order.cancelled"
      ],
      "signature": "sha256=HMAC-SHA256(secret, \"<timestamp>.<raw body>\")",
      "timestamp_window_seconds": 300
    },
    "limits": {
      "orders_per_merchant_per_day": 500,
      "request_body_bytes": 16384,
      "order_ttl_seconds": [
        120,
        3600
      ],
      "retention_days": 90
    },
    "billing": {
      "status": "free",
      "plans": [],
      "starts_at": null,
      "note": "paid subscriptions are planned but not on sale and have no start date"
    },
    "agent_note": "payer-side tools are in the MCP surface; merchant channel tools are not — call the HTTP API for those"
  },
  "merchant_onboarding": {
    "available": true,
    "why": "A third party can be set up for on-chain collection by an agent alone; the human only receives the key file.",
    "command": "aipay-agent merchant onboard --chain <key> --shop <name>",
    "creates": [
      "receiving wallet (one BIP-39 phrase; EVM, Solana and Tron addresses from the same derivation the web app uses)",
      "cloud merchant (POST /v1/merchants) with its API key and optional webhook secret"
    ],
    "secrets": "mnemonic + apiKey + webhookSecret are written to <agent home>/merchant.json with mode 0600 and are never printed to stdout, logs or prompts",
    "redacted_view": "aipay-agent merchant show",
    "handover": "aipay-agent merchant rotate-recipient --address <human wallet>, then delete the file; existing orders keep their original recipient",
    "human_only": [
      "off-chain provider signup (Alipay, WeChat Pay, UnionPay, Stripe): POST /v1/channels only registers a link the merchant already has",
      "deciding whether to trust an agent with a merchant key, and backing up the receiving wallet"
    ],
    "docs": "https://aipay.im/docs/integration.md"
  },
  "mandates": {
    "schema": "aipay-mandate-v1",
    "what": "The user's own signed limit on the agent's automatic spending: scope (chains/assets/merchants/operations), per-payment / per-window / total / daily caps, expiry, anti-replay nonce, and the user's explicit risk acceptance.",
    "where": "Signed on the user's machine and stored there. AIPAY holds no key for it and signs nothing.",
    "created_by": "aipay-agent mandate create (needs the human's approval key). The agent cannot create or widen one.",
    "tools": [
      "aipay_mandate_list"
    ],
    "rules": [
      "A mandate can only narrow the capability; it never widens it.",
      "Anything outside the limits goes back to a human as an escalation, never straight through.",
      "A refund needs its own mandate, with caps of at most 20% of the payment it refunds.",
      "Expiry is judged against chain time as well as the local clock, so moving the clock cannot extend a window.",
      "The verdict never discloses the remaining quota."
    ]
  }
}
