{
  "$defs": {
    "FederationMessageKind": {
      "description": "Closed message discriminator covered by every federation signature.",
      "oneOf": [
        {
          "const": "sync_request",
          "description": "Pull-based entry synchronization request.",
          "type": "string"
        },
        {
          "const": "sync_response",
          "description": "Pull-based entry synchronization response.",
          "type": "string"
        },
        {
          "const": "discovery_request",
          "description": "Typed MARS-QL discovery request.",
          "type": "string"
        },
        {
          "const": "discovery_response",
          "description": "Typed MARS-QL discovery response.",
          "type": "string"
        }
      ]
    },
    "SyncRequest": {
      "description": "Pull-based sync request sent between federation peers.\nPer MARS Specification Section 11.3.",
      "properties": {
        "entryTypes": {
          "description": "Filter by entry types (empty = all).",
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        "fromSequence": {
          "description": "Start from this sequence number (exclusive).",
          "format": "uint64",
          "minimum": 0,
          "type": "integer"
        },
        "maxEntries": {
          "description": "Maximum entries to return in this batch.",
          "format": "uint32",
          "minimum": 1,
          "type": "integer"
        },
        "namespaces": {
          "description": "Filter by namespaces (empty = all).",
          "items": {
            "type": "string"
          },
          "type": "array"
        }
      },
      "required": [
        "fromSequence",
        "maxEntries"
      ],
      "type": "object"
    }
  },
  "$id": "urn:mars:schema:v1:signed-sync-request",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "additionalProperties": false,
  "description": "JCS-canonical, detached Ed25519 envelope used for federation traffic.\n\nThe signature covers every field except `signature`, including the sender,\nrecipient, key controller, timestamp, nonce, request digest, and payload.\nRequest digests bind responses to the exact request they answer.",
  "properties": {
    "algorithm": {
      "description": "Signature algorithm. MARS federation v1 permits only `Ed25519`.",
      "type": "string"
    },
    "keyId": {
      "description": "Sender-controlled OAS DID URL used to verify the signature.",
      "type": "string"
    },
    "kind": {
      "$ref": "#/$defs/FederationMessageKind",
      "description": "Message type covered by the signature."
    },
    "nonce": {
      "description": "32 random bytes encoded as 64 lowercase hexadecimal characters.",
      "type": "string"
    },
    "payload": {
      "$ref": "#/$defs/SyncRequest",
      "description": "Typed federation payload."
    },
    "recipientDid": {
      "description": "Canonical OAS service DID of the intended registry.",
      "type": "string"
    },
    "requestDigest": {
      "description": "`sha256:` digest of the request payload, or of the request envelope for\na response.",
      "type": "string"
    },
    "senderDid": {
      "description": "Canonical OAS service DID of the sending registry.",
      "type": "string"
    },
    "signature": {
      "description": "Raw Ed25519 signature encoded as canonical unpadded base64url.",
      "type": "string"
    },
    "timestamp": {
      "description": "Envelope creation time.",
      "format": "date-time",
      "type": "string"
    },
    "version": {
      "description": "Stable signing profile.",
      "type": "string"
    }
  },
  "required": [
    "version",
    "kind",
    "senderDid",
    "recipientDid",
    "keyId",
    "algorithm",
    "timestamp",
    "nonce",
    "requestDigest",
    "payload",
    "signature"
  ],
  "title": "SignedFederationEnvelope",
  "type": "object"
}
