{
  "openapi": "3.1.0",
  "info": {
    "title": "AstraNL agreement form",
    "version": "1",
    "description": "One coordination form for people, AI agents and machines. First record what the parties agreed. The recorder hands the certificate id and once-issued confirmation capability to the other party and to nobody else. Keep the original response; repeating the record cannot recover the capability. Second the holder answers confirmed or disputed within 30 days; the first valid answer stands. Third anyone holding the id reads the record and answer state. A person can answer at confirm_url; an AI agent can use MCP; a machine can use these HTTPS calls without a model or browser. Mark a rehearsal with context.data_quality=test; it is excluded from real counts. No account or secret header is needed. This is evidence of what was agreed and of the answer. It is not a signature, an identity check, a payment, legal advice or a guarantee of performance. No legal effect is promised. AstraNL is not a party, never pays and holds no money."
  },
  "servers": [{"url": "https://astranl.com"}],
  "paths": {
    "/api/commitments": {
      "post": {
        "operationId": "recordAgreement",
        "summary": "Record an agreement and retain the once-issued capability",
        "description": "Identical normalized payloads reuse the id. ISSUED_ONCE includes confirmation_capability, confirmation_expires_at and confirmation_next_calls. ALREADY_ISSUED omits them; legacy records without an offer return NOT_OFFERED. confirm_url carries the capability after #c= only when newly issued; do not publish it. For HTTPS confirmation send the capability only in the JSON body, never in the request address. An empty body is treated as {} and refused; a valid JSON non-object reaches HTTP 500. based_on references must pass the existing reference verifier before recording.",
        "requestBody": {
          "required": true,
          "description": "JSON body, at most 25000 bytes according to Content-Length.",
          "x-maxBytes": 25000,
          "content": {"application/json": {"schema": {"$ref": "#/components/schemas/RecordInput"}}}
        },
        "responses": {
          "200": {"description": "Recorded or already present.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Issued"}}}},
          "400": {
            "description": "Invalid JSON, refused fields, normalized payload too large, or refused based_on.",
            "content": {"application/json": {"schema": {"anyOf": [{"$ref": "#/components/schemas/Error"},{"$ref": "#/components/schemas/ReferenceError"}]}}}
          },
          "413": {"description": "Content-Length exceeds the byte limit.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}},
          "500": {"description": "Exception; error text is truncated to 200 characters.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}
        }
      }
    },
    "/api/commitments/{certificate_id}/confirm": {
      "post": {
        "operationId": "answerAgreement",
        "summary": "Record the capability holder's first valid answer",
        "description": "The holder's identity is not verified. role must match a stored role if supplied and non-null. A non-null reason is allowed only with disputed. The same answer can be repeated; a different answer is refused. Expired or wrong capabilities are refused. The successful result verifies the separate answer record, not the original agreement; read the original id for counterparty.state.",
        "parameters": [
          {
            "name": "certificate_id",
            "in": "path",
            "required": true,
            "description": "The handler fullmatches ASTRA-C- followed by 12 uppercase hexadecimal characters.",
            "schema": {"type": "string", "pattern": "^ASTRA-C-[0-9A-F]{12}$"}
          }
        ],
        "requestBody": {
          "required": true,
          "description": "JSON body, 1 to 4096 bytes according to Content-Length.",
          "x-maxBytes": 4096,
          "x-minBytes": 1,
          "content": {"application/json": {"schema": {"$ref": "#/components/schemas/AnswerInput"}}}
        },
        "responses": {
          "200": {"description": "Verified answer record.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Verified"}}}},
          "400": {
            "description": "invalid_body for length, JSON or extra names; otherwise the refused confirmation result.",
            "content": {"application/json": {"schema": {"anyOf": [{"$ref": "#/components/schemas/Error"},{"$ref": "#/components/schemas/AnswerError"},{"$ref": "#/components/schemas/NotFound"}]}}}
          },
          "503": {"description": "Confirmation exception: confirmation_unavailable.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/Error"}}}}
        }
      }
    },
    "/api/commitments/{certificate_id}/verify": {
      "get": {
        "operationId": "readAgreement",
        "summary": "Read a record and its current answer state",
        "description": "No request body. No id pattern is enforced here. After stripping trailing slashes, the handler takes everything between /api/commitments/ and the final /verify, including embedded slashes, and truncates it to 40 characters. The verifier then converts to string, strips whitespace and truncates to 40 characters before lookup. A missing record is HTTP 200 with ok=false, found=false and error, without verdict or counterparty. A found agreement has counterparty and separate legacy link_mark; an answer record has confirmation and data_quality instead. The shared verifier also accepts vehicle ids. verdict checks stored integrity, not identity or performance; ok remains true even for INVALID. Whoever holds an id can read the stored payload.",
        "parameters": [
          {
            "name": "certificate_id",
            "in": "path",
            "required": true,
            "description": "No pattern or rejection length; only the first 40 extracted characters are passed to the verifier.",
            "schema": {"type": "string"}
          }
        ],
        "responses": {
          "200": {
            "description": "Found record or not found.",
            "content": {"application/json": {"schema": {"anyOf": [{"$ref": "#/components/schemas/Verified"},{"$ref": "#/components/schemas/NotFound"}]}}}
          },
          "500": {"description": "Verifier exception.", "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ReadError"}}}}
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Error": {"type": "object", "properties": {"ok": {"const": false}, "error": {"type": "string"}}, "required": ["ok", "error"], "additionalProperties": false},
      "ReferenceError": {
        "type": "object",
        "properties": {"ok": {"const": false}, "error": {"const": "validation"}, "field": {"const": "based_on"}, "message": {"type": "string"}, "nothing_done": {"const": true}},
        "required": ["ok", "error", "field", "message", "nothing_done"],
        "additionalProperties": false
      },
      "AnswerError": {
        "type": "object",
        "properties": {
          "ok": {"const": false},
          "error": {"type": "string", "enum": ["confirmation_not_authorized", "invalid_answer", "answer_already_recorded", "signing_unavailable"]},
          "nothing_done": {"const": true}
        },
        "required": ["ok", "error", "nothing_done"],
        "additionalProperties": false
      },
      "NotFound": {
        "type": "object",
        "properties": {"ok": {"const": false}, "found": {"const": false}, "error": {"const": "attestation not found"}},
        "required": ["ok", "found", "error"],
        "additionalProperties": false
      },
      "ReadError": {
        "type": "object",
        "properties": {"verdict": {"const": "INVALID"}, "ok": {"const": false}, "error": {"type": "string", "maxLength": 200}},
        "required": ["verdict", "ok", "error"],
        "additionalProperties": false
      },
      "Party": {
        "type": "object",
        "properties": {"role": {"type": "string", "maxLength": 60}, "name": {"type": "string", "minLength": 1, "maxLength": 120}},
        "required": ["role", "name"],
        "additionalProperties": false
      },
      "Obligation": {
        "type": "object",
        "properties": {"who": {"type": "string", "minLength": 1, "maxLength": 120}, "what": {"type": "string", "minLength": 1, "maxLength": 500}},
        "required": ["who", "what"],
        "additionalProperties": false
      },
      "References": {"type": "array", "items": {"type": "string", "pattern": "^[A-Za-z0-9_\\-:.]{4,64}$"}, "maxItems": 8},
      "RecordInput": {
        "type": "object",
        "required": ["parties", "obligations"],
        "properties": {
          "parties": {
            "type": "array",
            "minItems": 2,
            "maxItems": 10,
            "items": {
              "type": "object",
              "properties": {
                "role": {"x-storedMaxLength": 60, "description": "Converted with str; default empty; truncated to 60 characters."},
                "name": {"x-storedMaxLength": 120, "description": "Converted with str; default empty; truncated to 120 characters; empty result refused."}
              },
              "additionalProperties": true
            }
          },
          "obligations": {
            "type": "array",
            "minItems": 1,
            "maxItems": 20,
            "items": {
              "type": "object",
              "properties": {"who": {"x-storedMaxLength": 120}, "what": {"x-storedMaxLength": 500}},
              "additionalProperties": true,
              "description": "who and what are converted with str, default empty, truncated to 120 and 500 characters. Empty results are refused."
            }
          },
          "conditions": {
            "x-storedMaxItems": 20,
            "x-storedMaxLength": 300,
            "description": "Normally a list of strings. Each item of conditions or [] is converted with str and truncated to 300 characters; only the first 20 are stored. Other iterable JSON values are iterated; a truthy non-iterable raises HTTP 500."
          },
          "context": {"description": "An object is stored unchanged; any other JSON value becomes {}. Use data_quality=test inside this object for a rehearsal."},
          "created_by": {
            "default": "api_client",
            "x-storedMaxLength": 80,
            "description": "The handler converts a truthy value with str, otherwise uses api_client; stored text is truncated to 80 characters."
          },
          "based_on": {"$ref": "#/components/schemas/References"}
        },
        "additionalProperties": true,
        "description": "Extra names are ignored. The normalized payload serialized with ensure_ascii=False and sorted keys must have at most 20000 Python characters; this is not a byte limit.",
        "x-normalizedMaxCharacters": 20000
      },
      "AnswerInput": {
        "type": "object",
        "properties": {
          "capability": {
            "type": "string",
            "maxLength": 256,
            "description": "Use the once-issued 64 lowercase hexadecimal characters. A different token is refused; no format check is applied before hashing."
          },
          "decision": {"type": "string", "enum": ["confirmed", "disputed"]},
          "role": {"type": ["string", "null"], "description": "If non-null, must equal a role in the stored certificate."},
          "reason": {"type": ["string", "null"], "maxLength": 300, "description": "A non-null reason is allowed only for disputed."}
        },
        "required": ["capability", "decision"],
        "additionalProperties": false,
        "allOf": [{"if": {"properties": {"reason": {"type": "string"}}, "required": ["reason"]}, "then": {"properties": {"decision": {"const": "disputed"}}}}]
      },
      "Arguments": {
        "type": "object",
        "properties": {"certificate_id": {"type": "string"}, "capability": {"type": "string"}, "decision": {"type": "string", "enum": ["confirmed", "disputed"]}},
        "required": ["certificate_id", "capability", "decision"],
        "additionalProperties": false
      },
      "NextCalls": {
        "type": "object",
        "properties": {
          "mcp": {
            "type": "object",
            "properties": {
              "endpoint": {"type": "string"},
              "jsonrpc": {"const": "2.0"},
              "id": {"const": 1},
              "method": {"const": "tools/call"},
              "params": {
                "type": "object",
                "properties": {"name": {"const": "commitment_confirm"}, "arguments": {"$ref": "#/components/schemas/Arguments"}},
                "required": ["name", "arguments"],
                "additionalProperties": false
              }
            },
            "required": ["endpoint", "jsonrpc", "id", "method", "params"],
            "additionalProperties": false
          },
          "https": {
            "type": "object",
            "properties": {
              "method": {"const": "POST"},
              "url": {"type": "string"},
              "body": {"type": "object", "properties": {"capability": {"type": "string"}, "decision": {"const": "confirmed"}}, "required": ["capability", "decision"], "additionalProperties": false}
            },
            "required": ["method", "url", "body"],
            "additionalProperties": false
          },
          "choice": {"type": "string"}
        },
        "required": ["mcp", "https", "choice"],
        "additionalProperties": false
      },
      "Issued": {
        "type": "object",
        "properties": {
          "ok": {"const": true},
          "attest_id": {"type": "string", "pattern": "^ASTRA-C-[0-9A-F]{12}$"},
          "issued_at": {"type": "string"},
          "issuer": {"type": "string"},
          "payload_hash": {"type": "string"},
          "chain_hash": {"type": "string"},
          "hmac_signed": {"type": "boolean"},
          "based_on": {"$ref": "#/components/schemas/References"},
          "capability_status": {"type": "string", "enum": ["ISSUED_ONCE", "ALREADY_ISSUED", "NOT_OFFERED"]},
          "confirmation_how": {"type": "string"},
          "confirmation_capability": {"type": "string", "pattern": "^[0-9a-f]{64}$"},
          "confirmation_expires_at": {"type": "string"},
          "confirmation_next_calls": {"$ref": "#/components/schemas/NextCalls"},
          "nature": {"type": "string"},
          "verify_url": {"type": "string"},
          "confirm_url": {"type": "string"},
          "confirm_how": {"type": "string"}
        },
        "required": [
          "ok",
          "attest_id",
          "issued_at",
          "issuer",
          "payload_hash",
          "chain_hash",
          "hmac_signed",
          "based_on",
          "capability_status",
          "confirmation_how",
          "nature",
          "verify_url",
          "confirm_url",
          "confirm_how"
        ],
        "additionalProperties": false,
        "allOf": [
          {
            "if": {"properties": {"capability_status": {"const": "ISSUED_ONCE"}}},
            "then": {"required": ["confirmation_capability", "confirmation_expires_at", "confirmation_next_calls"]},
            "else": {"not": {"anyOf": [{"required": ["confirmation_capability"]},{"required": ["confirmation_expires_at"]},{"required": ["confirmation_next_calls"]}]}}
          }
        ]
      },
      "Commitment": {
        "type": "object",
        "properties": {
          "claim_type": {"const": "commitment"},
          "parties": {"type": "array", "items": {"$ref": "#/components/schemas/Party"}, "minItems": 2, "maxItems": 10},
          "obligations": {"type": "array", "items": {"$ref": "#/components/schemas/Obligation"}, "minItems": 1, "maxItems": 20},
          "conditions": {"type": "array", "items": {"type": "string", "maxLength": 300}, "maxItems": 20},
          "context": {
            "type": "object",
            "additionalProperties": true,
            "description": "Caller-supplied context. data_quality=test marks a rehearsal; synthetic=true or data_quality=synthetic also excludes it from real counts."
          },
          "created_by": {"type": "string", "maxLength": 80},
          "nature": {"const": "attestation_of_agreement_fact_only"},
          "not_a_guarantee_of_performance": {"const": true},
          "no_funds_held": {"const": true},
          "based_on": {"$ref": "#/components/schemas/References"}
        },
        "required": ["claim_type", "parties", "obligations", "conditions", "context", "created_by", "nature", "not_a_guarantee_of_performance", "no_funds_held"],
        "additionalProperties": false
      },
      "AnswerRecord": {
        "type": "object",
        "properties": {
          "claim_type": {"const": "commitment_confirmation"},
          "certificate_id": {"type": "string"},
          "decision": {"type": "string", "enum": ["confirmed", "disputed"]},
          "based_on": {"type": "array", "items": {"type": "string"}},
          "limits": {"type": "string"},
          "context": {
            "type": "object",
            "additionalProperties": true,
            "description": "Caller-supplied context. data_quality=test marks a rehearsal; synthetic=true or data_quality=synthetic also excludes it from real counts."
          },
          "answered_at": {"type": "string"},
          "role": {"type": "string"},
          "reason": {"type": "string", "maxLength": 300}
        },
        "required": ["claim_type", "certificate_id", "decision", "based_on", "limits", "context", "answered_at"],
        "additionalProperties": false
      },
      "Vehicle": {
        "type": "object",
        "properties": {
          "claim_type": {"const": "vehicle"},
          "subject": {"type": "string"},
          "rdw_reality_check": {"type": "object", "additionalProperties": true, "description": "Unmodified result of the vehicle subsystem; outside the agreement form."},
          "mrb_official_estimate": {"type": "object", "additionalProperties": true, "description": "Unmodified optional vehicle tax result; outside the agreement form."}
        },
        "required": ["claim_type", "subject", "rdw_reality_check"],
        "additionalProperties": false
      },
      "Counterparty": {
        "type": "object",
        "properties": {
          "state": {"type": "string", "enum": ["PENDING", "CONFIRMED", "DISPUTED", "EXPIRED_UNANSWERED", "NOT_OFFERED"]},
          "time": {"type": ["string", "null"]},
          "confirmation_id": {"type": ["string", "null"]},
          "offered_at": {"type": "string"},
          "expires_at": {"type": "string"}
        },
        "required": ["state", "time", "confirmation_id"],
        "additionalProperties": false,
        "allOf": [
          {
            "if": {"properties": {"state": {"const": "NOT_OFFERED"}}},
            "then": {"properties": {"time": {"type": "null"}, "confirmation_id": {"type": "null"}}},
            "else": {"required": ["offered_at", "expires_at"]}
          }
        ]
      },
      "LinkMark": {
        "type": "object",
        "properties": {
          "states": {"type": "array", "items": {"type": "string", "enum": ["CONFIRMED_BY_LINK_HOLDER", "DISPUTED_BY_LINK_HOLDER", "NONE"]}},
          "marks": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {"state": {"type": "string", "enum": ["CONFIRMED_BY_LINK_HOLDER", "DISPUTED_BY_LINK_HOLDER"]}, "id": {"type": "string"}, "time": {"type": "string"}},
              "required": ["state", "id", "time"],
              "additionalProperties": false
            }
          },
          "limits": {"type": "string"}
        },
        "required": ["states", "marks", "limits"],
        "additionalProperties": false
      },
      "Confirmation": {
        "type": "object",
        "properties": {
          "decision": {"type": "string", "enum": ["confirmed", "disputed"]},
          "limits": {"type": "string"},
          "certificate_id": {"type": "string"},
          "time": {"type": "string"},
          "id": {"type": "string"},
          "role": {"type": ["string", "null"]}
        },
        "required": ["decision", "limits", "certificate_id", "time", "id", "role"],
        "additionalProperties": false
      },
      "Source": {
        "type": "object",
        "properties": {"name": {"type": "string"}, "kind": {"type": "string"}, "fetched_live": {"type": "boolean"}, "note": {"type": "string"}},
        "required": ["name", "kind", "fetched_live"],
        "additionalProperties": false
      },
      "Verified": {
        "type": "object",
        "properties": {
          "verdict": {"type": "string", "enum": ["VALID", "INVALID"]},
          "ok": {"const": true},
          "found": {"const": true},
          "attest_id": {"type": "string"},
          "hmac_valid": {"type": ["boolean", "null"]},
          "plain_summary": {
            "type": "object",
            "properties": {
              "en": {"type": "string"},
              "nl": {"type": "string"},
              "uk": {"type": "string"},
              "pl": {"type": "string"},
              "de": {"type": "string"},
              "fr": {"type": "string"},
              "es": {"type": "string"},
              "tr": {"type": "string"},
              "ar": {"type": "string"}
            },
            "required": ["en", "nl", "uk", "pl", "de", "fr", "es", "tr", "ar"],
            "additionalProperties": false
          },
          "verify_url": {"type": "string"},
          "issued_at": {"type": "string"},
          "issuer": {"type": "string"},
          "payload_hash_valid": {"type": "boolean"},
          "chain_valid": {"type": "boolean"},
          "sources": {"type": "array", "items": {"$ref": "#/components/schemas/Source"}},
          "based_on": {"type": "array", "items": {"type": "string"}},
          "payload": {"oneOf": [{"$ref": "#/components/schemas/Commitment"},{"$ref": "#/components/schemas/AnswerRecord"},{"$ref": "#/components/schemas/Vehicle"}]},
          "counterparty": {"$ref": "#/components/schemas/Counterparty"},
          "link_mark": {"$ref": "#/components/schemas/LinkMark"},
          "confirmation": {"$ref": "#/components/schemas/Confirmation"},
          "data_quality": {"type": "string", "enum": ["test", "real"]}
        },
        "required": ["verdict", "ok", "found", "attest_id", "hmac_valid", "plain_summary", "verify_url", "issued_at", "issuer", "payload_hash_valid", "chain_valid", "sources", "based_on", "payload"],
        "additionalProperties": false,
        "allOf": [
          {"if": {"properties": {"payload": {"properties": {"claim_type": {"const": "commitment"}}}}}, "then": {"required": ["counterparty", "link_mark"]}},
          {"if": {"properties": {"payload": {"properties": {"claim_type": {"const": "commitment_confirmation"}}}}}, "then": {"required": ["confirmation", "data_quality"]}}
        ]
      }
    }
  }
}
