{
  "openapi": "3.1.0",
  "info": {
    "title": "GENESIS / Q Autonomous Agent Mint API",
    "version": "1.0.0",
    "description": "GENESIS / Q custom HTTPS Agent Wallet API. Live chain, contract, price, supply, and next Observation State are authoritative only from GET /agent/collection."
  },
  "servers": [
    {
      "url": "https://genesis-q-agent-mint.yuriya-scholar.workers.dev",
      "description": "Robinhood Chain Testnet Worker"
    }
  ],
  "paths": {
    "/agent/collection": {
      "get": {
        "operationId": "getCollection",
        "responses": {
          "200": {
            "description": "Live collection and mint configuration",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Collection" }
              }
            }
          }
        }
      }
    },
    "/agent/challenge": {
      "post": {
        "operationId": "createWalletChallenge",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/ChallengeRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Short-lived wallet challenge",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Challenge" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "413": { "$ref": "#/components/responses/TooLarge" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/agent/mint-authorization": {
      "post": {
        "operationId": "createMintAuthorization",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/MintAuthorizationRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Short-lived Agent Protocol v3 authorization",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/MintAuthorization" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "401": { "$ref": "#/components/responses/Unauthorized" },
          "403": { "$ref": "#/components/responses/MintDisabled" },
          "409": { "$ref": "#/components/responses/Conflict" },
          "429": { "$ref": "#/components/responses/RateLimited" }
        }
      }
    },
    "/agent/mint-status/{transactionHash}": {
      "get": {
        "operationId": "getMintStatus",
        "parameters": [
          {
            "name": "transactionHash",
            "in": "path",
            "required": true,
            "schema": { "type": "string", "pattern": "^0x[0-9a-fA-F]{64}$" }
          }
        ],
        "responses": {
          "200": {
            "description": "Verified GENESIS / Q mint receipt and metadata",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/MintStatus" }
              }
            }
          },
          "400": { "$ref": "#/components/responses/BadRequest" },
          "404": { "$ref": "#/components/responses/NotFound" },
          "422": { "$ref": "#/components/responses/ForeignTransaction" }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Collection": {
        "type": "object",
        "required": ["protocol", "walletProofProtocol", "chainId", "contract", "mintPriceWei", "minted", "nextObservation", "mintFunction", "requiresAgentWallet"],
        "properties": {
          "protocol": { "const": "GENESIS-Q-Agent-Mint/3" },
          "walletProofProtocol": { "const": "GENESIS-Q-Wallet-Proof/2" },
          "collection": { "type": "string", "const": "GENESIS / Q" },
          "supply": { "type": "integer", "const": 4096 },
          "chainId": { "type": "integer", "const": 46630 },
          "contract": { "type": "string", "pattern": "^0x[0-9a-fA-F]{40}$" },
          "mintPriceWei": { "type": "string", "const": "1000000000000000" },
          "priceEth": { "type": "string", "const": "0.001" },
          "minted": { "type": "integer", "minimum": 0, "maximum": 4096 },
          "nextObservation": { "type": ["string", "null"], "pattern": "^0x[0-9A-F]{3}$" },
          "mintFunction": { "type": "string", "const": "mintWithAgentVoucher" },
          "requiresAgentWallet": { "type": "boolean", "const": true }
        },
        "additionalProperties": true
      },
      "ChallengeRequest": {
        "type": "object",
        "required": ["walletAddress"],
        "properties": {
          "walletAddress": { "type": "string", "pattern": "^0x[0-9a-fA-F]{40}$" }
        },
        "additionalProperties": false
      },
      "Challenge": {
        "type": "object",
        "required": ["protocol", "challengeId", "walletAddress", "challenge", "deadline", "message"],
        "properties": {
          "protocol": { "const": "GENESIS-Q-Wallet-Proof/2" },
          "challengeId": { "type": "string", "pattern": "^0x[0-9a-fA-F]{64}$" },
          "walletAddress": { "type": "string", "pattern": "^0x[0-9a-fA-F]{40}$" },
          "challenge": { "type": "string", "pattern": "^0x[0-9a-fA-F]{64}$" },
          "deadline": { "type": "string", "pattern": "^[0-9]+$" },
          "message": { "type": "string", "minLength": 1 },
          "identityContext": { "type": "string", "const": "GENERIC_MCP_AGENT" },
          "clientIdHash": { "type": "string", "pattern": "^0x[0-9a-fA-F]{64}$" }
        },
        "additionalProperties": false
      },
      "MintAuthorizationRequest": {
        "type": "object",
        "required": ["challengeId", "walletSignature"],
        "properties": {
          "challengeId": { "type": "string", "pattern": "^0x[0-9a-fA-F]{64}$" },
          "walletSignature": { "type": "string", "pattern": "^0x[0-9a-fA-F]+$" }
        },
        "additionalProperties": false
      },
      "MintAuthorization": {
        "type": "object",
        "required": ["protocol", "chainId", "contract", "function", "valueWei", "expectedObservationState", "voucher", "signature", "calldata", "expiresAt"],
        "properties": {
          "protocol": { "const": "GENESIS-Q-Agent-Mint/3" },
          "chainId": { "type": "integer", "const": 46630 },
          "contract": { "type": "string", "pattern": "^0x[0-9a-fA-F]{40}$" },
          "function": { "type": "string", "const": "mintWithAgentVoucher" },
          "valueWei": { "type": "string", "const": "1000000000000000" },
          "expectedObservationState": { "type": "string", "pattern": "^0x[0-9A-F]{3}$" },
          "voucher": { "$ref": "#/components/schemas/Voucher" },
          "signature": { "type": "string", "pattern": "^0x[0-9a-fA-F]+$" },
          "calldata": { "type": "string", "pattern": "^0x[0-9a-fA-F]+$" },
          "expiresAt": { "type": "string", "format": "date-time" }
        },
        "additionalProperties": true
      },
      "Voucher": {
        "type": "object",
        "required": ["recipient", "authorizedCaller", "nonce", "deadline", "agentClass"],
        "properties": {
          "recipient": { "type": "string", "pattern": "^0x[0-9a-fA-F]{40}$" },
          "authorizedCaller": { "type": "string", "pattern": "^0x[0-9a-fA-F]{40}$" },
          "nonce": { "type": "string", "pattern": "^0x[0-9a-fA-F]{64}$" },
          "deadline": { "type": "string", "pattern": "^[0-9]+$" },
          "agentClass": { "type": "string", "pattern": "^0x[0-9a-fA-F]{64}$" }
        },
        "additionalProperties": false
      },
      "MintStatus": {
        "type": "object",
        "required": ["chainId", "contract", "transactionHash", "receiptStatus", "tokenId", "observationState", "tokenURI", "artworkUrl", "artworkStatus"],
        "properties": {
          "chainId": { "type": "integer", "const": 46630 },
          "contract": { "type": "string", "pattern": "^0x[0-9a-fA-F]{40}$" },
          "transactionHash": { "type": "string", "pattern": "^0x[0-9a-fA-F]{64}$" },
          "receiptStatus": { "type": "string", "enum": ["success", "reverted"] },
          "tokenId": { "type": "integer", "minimum": 0 },
          "observationState": { "type": "string", "pattern": "^0x[0-9A-F]{3}$" },
          "tokenURI": { "type": "string" },
          "metadata": { "type": ["object", "null"] },
          "artworkUrl": { "type": "string", "format": "uri" },
          "artworkStatus": { "type": "string", "enum": ["PASS", "FAIL"] }
        },
        "additionalProperties": true
      },
      "Error": {
        "type": "object",
        "required": ["error"],
        "properties": {
          "error": { "type": "string" },
          "error_description": { "type": "string" }
        }
      }
    },
    "responses": {
      "BadRequest": { "description": "Invalid request", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "TooLarge": { "description": "Request body too large", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "Unauthorized": { "description": "Wallet signature rejected", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "MintDisabled": { "description": "Voucher issuance disabled", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "Conflict": { "description": "Authorization already in progress or replayed", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "NotFound": { "description": "Transaction not found", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } },
      "ForeignTransaction": { "description": "Transaction is not a verified GENESIS / Q mint", "content": { "application/json": { "schema": { "$ref": "#/components/schemas/Error" } } } }
    }
  }
}
