{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://labs.hummand.com.br/humanproof/especificacao/humanproof-acesso-1-revisao-2.schema.json",
  "title": "humanproof-acesso/1, revisão 2",
  "description": "Recibo assinado de um acesso à evidência de um ato da Hummand, revisão 2 (2026-10-29). Liga-se ao recibo do ato pelo hash, diz o que foi exposto em cada registro e carrega o motivo só como hash salgado. Campo desconhecido é erro; o que é novo e não exigido vai em `extensoes`.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "formato", "revisao", "acesso_id", "emissor", "tenant", "ato_id", "ato_recibo_hash", "ator",
    "motivo_hash", "motivo_sal", "componentes", "desfecho", "ts_acesso", "ts_emitido", "prev_hash",
    "assinaturas"
  ],
  "properties": {
    "formato": { "const": "humanproof-acesso/1" },
    "revisao": { "const": 2 },
    "acesso_id": { "type": "string", "pattern": "^acs_[0-9a-f]{32}$" },
    "emissor": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "jwks_uri"],
      "properties": {
        "id": { "type": "string", "pattern": "^[a-z][a-z0-9-]{1,63}$" },
        "jwks_uri": { "type": "string", "pattern": "^https://[^\\s]{1,500}$" }
      }
    },
    "tenant": {
      "type": "object",
      "additionalProperties": false,
      "required": ["id", "nome_publico"],
      "properties": {
        "id": { "type": "string", "minLength": 1, "maxLength": 128 },
        "nome_publico": { "type": "string", "minLength": 1, "maxLength": 200 }
      }
    },
    "ato_id": { "type": "string", "pattern": "^[0-9a-f]{32}$" },
    "ato_recibo_hash": { "oneOf": [{ "type": "null" }, { "$ref": "#/$defs/hash" }] },
    "ator": {
      "type": "object",
      "additionalProperties": false,
      "required": ["papel", "id"],
      "properties": {
        "papel": { "enum": ["cliente", "operador_hummand", "revisor_hummand", "integracao", "terceiro"] },
        "id": { "type": "string", "pattern": "^(usuario|operador|revisor|apikey|compartilhamento):[A-Za-z0-9_.-]{1,120}$" }
      }
    },
    "motivo_hash": { "$ref": "#/$defs/hash" },
    "motivo_sal": { "type": "string", "pattern": "^[0-9a-f]{32}$" },
    "componentes": {
      "type": "array",
      "maxItems": 64,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["registro", "registro_id", "desfecho", "conteudo_hash", "modo"],
        "properties": {
          "registro": { "type": "string", "pattern": "^[a-z_]{1,64}$" },
          "registro_id": { "type": "string", "minLength": 1, "maxLength": 128 },
          "desfecho": { "enum": ["aberto", "apagado", "nunca_houve", "negado", "erro"] },
          "conteudo_hash": { "oneOf": [{ "type": "null" }, { "$ref": "#/$defs/hash" }] },
          "modo": { "oneOf": [{ "type": "null" }, { "enum": ["tela", "arquivo"] }] }
        }
      }
    },
    "desfecho": { "enum": ["concedido", "negado", "erro"] },
    "ts_acesso": { "$ref": "#/$defs/ts" },
    "ts_emitido": { "$ref": "#/$defs/ts" },
    "prev_hash": { "$ref": "#/$defs/hash" },
    "extensoes": {
      "type": "object",
      "maxProperties": 16,
      "propertyNames": { "pattern": "^[a-z][a-z0-9_.-]{1,63}$" },
      "additionalProperties": { "type": "object" }
    },
    "crit": {
      "type": "array",
      "maxItems": 16,
      "uniqueItems": true,
      "items": { "type": "string", "pattern": "^[a-z][a-z0-9_.-]{1,63}$" }
    },
    "assinaturas": {
      "type": "array",
      "minItems": 1,
      "maxItems": 4,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["papel", "kid", "alg", "valor"],
        "properties": {
          "papel": { "enum": ["emissor", "emissor_complementar", "testemunha", "cliente"] },
          "kid": { "type": "string", "minLength": 1, "maxLength": 64 },
          "alg": { "enum": ["ES256", "EdDSA"] },
          "valor": { "type": "string", "pattern": "^[A-Za-z0-9_-]{1,8192}$" }
        }
      }
    }
  },
  "$defs": {
    "hash": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
    "ts": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{3}Z$" }
  }
}
