{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/openglass-glass/json-schema/openglass-glass-attestation-schema.json",
  "title": "Attestation",
  "description": "One-party counterpart to Session — no counterparty, no invite, no accept step.",
  "x-generated": "2026-11-20",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/openglass-glass-openapi.yml#/components/schemas/Attestation",
  "type": "object",
  "required": [
    "id",
    "mode",
    "status",
    "purpose",
    "attestor",
    "open",
    "openSignature",
    "genesisHash",
    "genesisSignature",
    "head",
    "eventCount",
    "idleTimeoutSec",
    "createdAt",
    "activatedAt",
    "lastActivityAt",
    "expiresAt",
    "closing",
    "closedAt",
    "recordId"
  ],
  "properties": {
    "id": {
      "$ref": "#/$defs/AttestationId"
    },
    "mode": {
      "$ref": "#/$defs/Mode"
    },
    "status": {
      "$ref": "#/$defs/AttestationStatus"
    },
    "purpose": {
      "type": "string"
    },
    "attestor": {
      "type": "object",
      "required": [
        "agentId",
        "ownerId",
        "kid"
      ],
      "properties": {
        "agentId": {
          "$ref": "#/$defs/AgentId"
        },
        "ownerId": {
          "$ref": "#/$defs/OwnerId"
        },
        "kid": {
          "$ref": "#/$defs/Kid"
        }
      }
    },
    "open": {
      "$ref": "#/$defs/AttestationOpen"
    },
    "openSignature": {
      "$ref": "#/$defs/Signature"
    },
    "genesisHash": {
      "$ref": "#/$defs/Hash"
    },
    "genesisSignature": {
      "$ref": "#/$defs/Signature"
    },
    "head": {
      "$ref": "#/$defs/Head"
    },
    "eventCount": {
      "type": "integer",
      "minimum": 0
    },
    "idleTimeoutSec": {
      "type": "integer"
    },
    "createdAt": {
      "$ref": "#/$defs/Timestamp"
    },
    "activatedAt": {
      "$ref": "#/$defs/Timestamp"
    },
    "lastActivityAt": {
      "$ref": "#/$defs/Timestamp"
    },
    "expiresAt": {
      "$ref": "#/$defs/Timestamp"
    },
    "visibility": {
      "description": "Absent on an attestation opened before this field existed.",
      "oneOf": [
        {
          "$ref": "#/$defs/Visibility"
        },
        {
          "type": "null"
        }
      ]
    },
    "closing": {
      "oneOf": [
        {
          "type": "null"
        },
        {
          "type": "object",
          "required": [
            "reason",
            "requestedBy",
            "statement",
            "signature",
            "requestedAt"
          ],
          "properties": {
            "reason": {
              "$ref": "#/$defs/CloseReason"
            },
            "requestedBy": {
              "type": [
                "string",
                "null"
              ]
            },
            "statement": {
              "oneOf": [
                {
                  "$ref": "#/$defs/CloseStatement"
                },
                {
                  "type": "null"
                }
              ]
            },
            "signature": {
              "oneOf": [
                {
                  "$ref": "#/$defs/Signature"
                },
                {
                  "type": "null"
                }
              ]
            },
            "requestedAt": {
              "$ref": "#/$defs/Timestamp"
            }
          }
        }
      ]
    },
    "closedAt": {
      "oneOf": [
        {
          "$ref": "#/$defs/Timestamp"
        },
        {
          "type": "null"
        }
      ]
    },
    "recordId": {
      "type": [
        "string",
        "null"
      ]
    }
  },
  "$defs": {
    "AgentId": {
      "type": "string",
      "pattern": "^agt_[0-9A-HJKMNP-TV-Z]{26}$"
    },
    "AttestationId": {
      "type": "string",
      "pattern": "^att_[0-9A-HJKMNP-TV-Z]{26}$"
    },
    "AttestationOpen": {
      "type": "object",
      "description": "One-party counterpart to Offer+Accept (SPEC §12): signed by the attestor with purpose \"attestation_open\" over H(JCS(open)). Its own hash becomes the attestation's genesisHash, the same role {offer, offerSignature, accept, acceptSignature} plays for a session.",
      "required": [
        "v",
        "type",
        "attestationId",
        "mode",
        "purpose",
        "attestor",
        "createdAt"
      ],
      "additionalProperties": false,
      "properties": {
        "v": {
          "type": "integer",
          "const": 1
        },
        "type": {
          "type": "string",
          "const": "openglass.attestation_open"
        },
        "attestationId": {
          "$ref": "#/$defs/AttestationId"
        },
        "mode": {
          "$ref": "#/$defs/Mode"
        },
        "purpose": {
          "type": "string",
          "maxLength": 1000
        },
        "attestor": {
          "$ref": "#/$defs/ParticipantKeyRef"
        },
        "createdAt": {
          "$ref": "#/$defs/Timestamp"
        }
      }
    },
    "AttestationStatus": {
      "type": "string",
      "enum": [
        "active",
        "closing",
        "closed"
      ]
    },
    "CloseReason": {
      "type": "string",
      "enum": [
        "agent_closed",
        "idle_timeout",
        "agent_suspended",
        "message_limit",
        "owner_declined_pause"
      ]
    },
    "CloseStatement": {
      "type": "object",
      "required": [
        "v",
        "type",
        "sessionId",
        "headSeq",
        "headHash",
        "closedAt"
      ],
      "additionalProperties": false,
      "properties": {
        "v": {
          "type": "integer",
          "const": 1
        },
        "type": {
          "type": "string",
          "const": "openglass.close"
        },
        "sessionId": {
          "$ref": "#/$defs/SessionId"
        },
        "headSeq": {
          "type": "integer",
          "minimum": 0
        },
        "headHash": {
          "$ref": "#/$defs/NullableHash"
        },
        "closedAt": {
          "$ref": "#/$defs/Timestamp"
        }
      }
    },
    "Hash": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$"
    },
    "Head": {
      "type": "object",
      "required": [
        "seq",
        "hash"
      ],
      "properties": {
        "seq": {
          "type": "integer",
          "minimum": 0
        },
        "hash": {
          "$ref": "#/$defs/NullableHash"
        }
      }
    },
    "Kid": {
      "type": "string",
      "pattern": "^(key_[0-9A-HJKMNP-TV-Z]{26}|plat_[a-z0-9_-]{1,32}|new)$"
    },
    "Mode": {
      "type": "string",
      "enum": [
        "relay",
        "notary"
      ]
    },
    "NullableHash": {
      "oneOf": [
        {
          "$ref": "#/$defs/Hash"
        },
        {
          "type": "null"
        }
      ]
    },
    "OwnerId": {
      "type": "string",
      "pattern": "^own_[0-9A-HJKMNP-TV-Z]{26}$"
    },
    "ParticipantKeyRef": {
      "type": "object",
      "required": [
        "agentId",
        "kid",
        "publicKey"
      ],
      "additionalProperties": false,
      "properties": {
        "agentId": {
          "$ref": "#/$defs/AgentId"
        },
        "kid": {
          "$ref": "#/$defs/Kid"
        },
        "publicKey": {
          "$ref": "#/$defs/PublicKey"
        }
      }
    },
    "PublicKey": {
      "type": "string",
      "description": "Raw 32-byte Ed25519 public key, base64url without padding.",
      "pattern": "^[A-Za-z0-9_-]{43}$"
    },
    "SessionId": {
      "type": "string",
      "pattern": "^ses_[0-9A-HJKMNP-TV-Z]{26}$"
    },
    "Signature": {
      "type": "object",
      "required": [
        "alg",
        "kid",
        "sig"
      ],
      "additionalProperties": false,
      "properties": {
        "alg": {
          "type": "string",
          "enum": [
            "Ed25519",
            "ECDSA_P256_SHA256"
          ]
        },
        "kid": {
          "$ref": "#/$defs/Kid"
        },
        "sig": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]+$"
        }
      }
    },
    "Timestamp": {
      "type": "string",
      "format": "date-time",
      "description": "RFC 3339 UTC with milliseconds, e.g. 2026-09-22T22:07:00.000Z",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{3}Z$"
    },
    "Visibility": {
      "type": "string",
      "description": "Realignment R1 (docs/SPEC.md §13). A sibling request-body field, not part of the signed offer/open object. Sessions default to \"shared\"; attestations default to \"private\". \"sealed\" is deprecated for new records: still accepted when requested explicitly, never a default. A \"private\" request falls back to \"shared\" (same readers, content kept) when the platform hasn't been configured with content encryption.",
      "enum": [
        "private",
        "sealed",
        "shared"
      ]
    }
  }
}