{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "/schemas/call-receipt/v1.json",
  "title": "Provenance call receipt, version 1",
  "description": "The claims of a call receipt: an ES256 JWS with header typ provenance-receipt+jwt, signed with a key published at /.well-known/jwks.json on the Provenance API. It records one verified check of an incoming call. It holds no phone number: numbers_digest is the SHA-256 (hex) of from|to|jti, which anyone who knows both numbers can recompute.",
  "type": "object",
  "required": ["receipt_id", "type", "v", "check_id", "call_id", "result", "transport", "agent", "person", "purpose", "window", "jti", "numbers_digest", "disclosure", "consent", "checked_at", "iss"],
  "properties": {
    "receipt_id": { "type": "string", "pattern": "^rcpt_[0-9a-f]{32}$", "description": "The receipt's ID." },
    "type": { "const": "verified_call" },
    "v": { "const": 1, "description": "The format version." },
    "check_id": { "type": "string", "description": "The answering business's check." },
    "call_id": { "type": ["string", "null"], "description": "The registered call that matched, if one did." },
    "result": { "type": "string", "description": "The check's result: verified for a receipt that a check returned." },
    "transport": {
      "type": "string",
      "enum": ["lookup", "code", "sip", "in_call_challenge", "guest_confirmation", "relayed_code"],
      "description": "How the call was matched."
    },
    "agent": {
      "type": ["object", "null"],
      "required": ["id", "kid", "directory"],
      "additionalProperties": false,
      "description": "The agent that signed the call credential. Null when a person approved without an agent credential.",
      "properties": {
        "id": { "type": "string" },
        "kid": { "type": "string", "description": "The thumbprint of the key that signed the credential." },
        "directory": { "type": "string", "format": "uri", "description": "Where that key is published." }
      }
    },
    "person": {
      "type": "object",
      "required": ["approved", "approved_at", "approved_via", "pseudonym"],
      "additionalProperties": false,
      "properties": {
        "approved": { "type": "boolean", "description": "Whether a person approved the call." },
        "approved_at": { "type": ["string", "null"], "format": "date-time" },
        "approved_via": {
          "type": ["string", "null"],
          "enum": ["grant", "approval", "booking_contact", "relayed_code", null],
          "description": "How the person approved."
        },
        "pseudonym": { "type": ["string", "null"], "description": "A stable ID for the person at the answering business only." }
      }
    },
    "purpose": { "type": ["string", "null"], "description": "The call's purpose." },
    "window": {
      "type": ["object", "null"],
      "required": ["from", "until"],
      "additionalProperties": false,
      "properties": {
        "from": { "type": "string", "format": "date-time" },
        "until": { "type": "string", "format": "date-time" }
      }
    },
    "jti": { "type": ["string", "null"], "description": "The call credential's jti." },
    "numbers_digest": { "type": ["string", "null"], "pattern": "^[0-9a-f]{64}$", "description": "SHA-256 hex of from|to|jti." },
    "disclosure": {
      "type": ["object", "null"],
      "description": "The credential's disclosure record, as signed.",
      "properties": { "ai": { "type": "boolean" }, "statement": { "type": "string" } }
    },
    "consent": {
      "type": ["object", "null"],
      "description": "The credential's consent record, as signed.",
      "properties": { "basis": { "type": "string" }, "ref": { "type": "string" } }
    },
    "checked_at": { "type": "string", "format": "date-time", "description": "When the check ran." },
    "iss": { "type": "string", "format": "uri", "description": "The issuer: the Provenance site's URL." }
  }
}
