{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "/schemas/call-credential/v1.json",
  "title": "Provenance call credential, version 1",
  "description": "The claims of a call credential: a compact JWS whose protected header is { alg: EdDSA, typ: call+jws, kid } (see $defs.header), signed with the calling agent's Ed25519 key. kid is the key's RFC 7638 JWK thumbprint, and the key is published in the agent's directory named by iss. A verifier checks the signature against that directory, that exp - nbf is at most 900 seconds, that the call happens inside [nbf, exp], that from and to match the call, and that jti was not seen before.",
  "type": "object",
  "required": ["v", "iss", "agent", "from", "to", "nbf", "exp", "jti", "purpose"],
  "properties": {
    "v": { "const": 1, "description": "The format version." },
    "iss": {
      "type": "string",
      "format": "uri",
      "description": "The agent's key directory: its Provenance directory (https://<api>/v1/public/agents/<agent_id>/directory), or the agent's own directory or JWKS URL, over https."
    },
    "agent": { "type": "string", "minLength": 1, "description": "The agent's ID: agt_… for an agent registered with Provenance, else the agent's own identifier." },
    "from": { "type": "string", "pattern": "^\\+[1-9][0-9]{6,14}$", "description": "The number the agent calls from, in E.164." },
    "to": { "type": "string", "pattern": "^\\+[1-9][0-9]{6,14}$", "description": "The number the agent calls, in E.164. Differs from from." },
    "nbf": { "type": "integer", "description": "The start of the call's window, in seconds since the epoch. Within 60 seconds of the time the call is registered." },
    "exp": { "type": "integer", "description": "The end of the call's window, in seconds since the epoch. At most 900 seconds after nbf." },
    "jti": { "type": "string", "minLength": 1, "maxLength": 200, "description": "A unique ID for this credential. It is used once." },
    "purpose": {
      "type": "string",
      "enum": ["book", "buy", "cancel", "change", "support", "inquire"],
      "description": "Why the agent is calling."
    },
    "purpose_text": { "type": "string", "maxLength": 120, "description": "The purpose in a sentence, such as \"Table for 2 at 7pm Friday\"." },
    "grant": { "type": "string", "description": "The grant that authorizes the call. Give this or approval." },
    "approval": { "type": "string", "description": "A one-time approval that authorizes the call, when there is no grant." },
    "disclosure": {
      "type": "object",
      "required": ["ai", "statement"],
      "additionalProperties": false,
      "description": "The caller's AI-disclosure record, designed to support disclosure rules.",
      "properties": {
        "ai": { "type": "boolean", "description": "Whether the caller is an AI." },
        "statement": { "type": "string", "maxLength": 60, "description": "How the caller discloses it, such as spoken_at_start." }
      }
    },
    "consent": {
      "type": "object",
      "required": ["basis"],
      "additionalProperties": false,
      "description": "The caller's consent record, designed to support consent rules.",
      "properties": {
        "basis": { "type": "string", "maxLength": 60, "description": "The basis, such as customer_request." },
        "ref": { "type": "string", "maxLength": 200, "description": "The caller's own reference for the consent." }
      }
    }
  },
  "anyOf": [{ "required": ["grant"] }, { "required": ["approval"] }],
  "$defs": {
    "header": {
      "type": "object",
      "required": ["alg", "typ", "kid"],
      "properties": {
        "alg": { "const": "EdDSA" },
        "typ": { "const": "call+jws" },
        "kid": { "type": "string", "minLength": 1, "description": "The signing key's RFC 7638 JWK thumbprint." }
      }
    }
  }
}
