{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://labs.hummand.com.br/humanproof/especificacao/humanproof-1-revisao-2.schema.json",
  "title": "humanproof/1, revisão 2",
  "description": "Recibo assinado de um ato da Hummand, revisão 2 (2026-10-29). Só hashes, compromissos e identificadores opacos: nenhuma biometria, imagem ou contexto em claro. Campo desconhecido é erro; o que é novo e não exigido vai em `extensoes`.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "formato", "revisao", "recibo_id", "ato_id", "emissor", "tenant", "tipo", "resultado", "motivo",
    "nivel", "politica", "sujeito", "contexto", "consentimentos", "etapas", "fontes", "garantias",
    "evidencia_tecnica", "participantes", "revisao_humana", "mandato", "ingredientes",
    "ts_criado", "ts_concluido", "ts_emitido", "expira_em", "retencao", "prev_hash", "assinaturas"
  ],
  "properties": {
    "formato": { "const": "humanproof/1" },
    "revisao": { "const": 2 },
    "recibo_id": { "type": "string", "pattern": "^rcb_[0-9a-f]{32}$" },
    "ato_id": { "type": "string", "pattern": "^[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": { "$ref": "#/$defs/id" },
        "nome_publico": { "type": "string", "minLength": 1, "maxLength": 200 }
      }
    },
    "tipo": {
      "enum": [
        "presenca.recorrente", "stepup.transacao", "stepup.cadastral", "stepup.operador",
        "operador.dupla", "onboarding.identidade", "concessao", "mandato.pessoa", "mandato.agente",
        "ato.delegado", "assinatura", "prova.excecao"
      ]
    },
    "resultado": { "enum": ["positivo", "negativo", "expirado", "cancelado", "falhou", "revogado"] },
    "motivo": {
      "oneOf": [
        { "type": "null" },
        {
          "enum": [
            "presenca_negada", "comparacao_negada", "identidade_negada", "passkey_negada",
            "consentimento_recusado", "revisao_negou", "mandato_invalido", "mandato_revogado",
            "mandato_vencido", "fora_de_escopo", "prazo", "cancelado_pelo_cliente",
            "cancelado_pela_pessoa", "falha_tecnica_fonte", "falha_tecnica_emissor",
            "revogado_pelo_mandante"
          ]
        }
      ]
    },
    "nivel": {
      "type": "object",
      "additionalProperties": false,
      "required": ["exigido", "atingido"],
      "properties": {
        "exigido": { "type": "integer", "minimum": 0, "maximum": 3 },
        "atingido": { "type": "integer", "minimum": 0, "maximum": 3 }
      }
    },
    "politica": {
      "type": "object",
      "additionalProperties": false,
      "required": ["versao", "hash"],
      "properties": {
        "versao": { "type": "string", "minLength": 1, "maxLength": 64 },
        "hash": { "$ref": "#/$defs/hash" }
      }
    },
    "sujeito": {
      "type": "object",
      "additionalProperties": false,
      "required": ["ref_compromisso", "ref_sal"],
      "properties": {
        "ref_compromisso": { "oneOf": [{ "type": "null" }, { "$ref": "#/$defs/hash" }] },
        "ref_sal": { "oneOf": [{ "type": "null" }, { "$ref": "#/$defs/sal" }] },
        "referencia": {
          "type": "object",
          "additionalProperties": false,
          "required": ["tipo", "origem", "hash", "anexada_em"],
          "properties": {
            "tipo": { "enum": ["imagem"] },
            "origem": { "enum": ["api", "painel", "ato_anterior", "base_oficial"] },
            "hash": { "$ref": "#/$defs/hash" },
            "anexada_em": { "$ref": "#/$defs/ts" }
          }
        }
      }
    },
    "contexto": {
      "type": "object",
      "additionalProperties": false,
      "required": ["hash", "chaves_declaradas"],
      "properties": {
        "hash": { "$ref": "#/$defs/hash" },
        "chaves_declaradas": {
          "type": "array",
          "uniqueItems": true,
          "maxItems": 64,
          "items": { "type": "string", "minLength": 1, "maxLength": 64 }
        }
      }
    },
    "consentimentos": {
      "type": "array",
      "maxItems": 8,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["camada", "versao", "idioma", "texto_hash", "ts"],
        "properties": {
          "camada": { "enum": ["geral", "biometrico", "escopo"] },
          "versao": { "type": "string", "minLength": 1, "maxLength": 32 },
          "idioma": { "type": "string", "pattern": "^[a-z]{2}(-[A-Z]{2})?$" },
          "texto_hash": { "$ref": "#/$defs/hash" },
          "ts": { "$ref": "#/$defs/ts" }
        }
      }
    },
    "etapas": {
      "type": "array",
      "maxItems": 32,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["nome", "resultado", "ts", "medido"],
        "properties": {
          "nome": {
            "enum": [
              "contexto_transparencia", "consentimento_geral", "consentimento_biometrico",
              "presenca", "comparacao", "identidade", "federada", "passkey", "escopo",
              "documento_anexo", "presenca_participante", "assinatura_juridica",
              "verificacao_mandato"
            ]
          },
          "resultado": { "enum": ["ok", "negado", "recusado", "falha_tecnica"] },
          "ts": { "$ref": "#/$defs/ts" },
          "medido": { "type": "boolean" }
        }
      }
    },
    "fontes": {
      "type": "array",
      "maxItems": 16,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["fonte", "fornecedor", "componente", "versao_componente", "versao_adaptador", "ambiente"],
        "properties": {
          "fonte": { "type": "string", "pattern": "^[a-z][a-z0-9_.]{1,63}$" },
          "fornecedor": { "type": "string", "minLength": 1, "maxLength": 64 },
          "componente": { "type": "string", "minLength": 1, "maxLength": 64 },
          "versao_componente": { "type": "string", "minLength": 1, "maxLength": 64 },
          "versao_adaptador": { "type": "string", "minLength": 1, "maxLength": 32 },
          "ambiente": { "enum": ["producao", "homologacao"] },
          "certificacao": {
            "type": "object",
            "additionalProperties": false,
            "required": ["esquema", "laboratorio", "relatorio", "data"],
            "properties": {
              "esquema": { "type": "string", "minLength": 1, "maxLength": 64 },
              "laboratorio": { "type": "string", "minLength": 1, "maxLength": 64 },
              "relatorio": { "type": "string", "minLength": 1, "maxLength": 64 },
              "data": { "type": "string", "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$" }
            }
          }
        }
      }
    },
    "garantias": {
      "type": "object",
      "additionalProperties": false,
      "required": ["humano_vivo", "mesma_pessoa_da_referencia", "identidade_civil", "consentiu", "biometria_retida"],
      "properties": {
        "humano_vivo": { "$ref": "#/$defs/garantia" },
        "mesma_pessoa_da_referencia": { "$ref": "#/$defs/garantia" },
        "identidade_civil": { "$ref": "#/$defs/garantia" },
        "consentiu": { "$ref": "#/$defs/garantia" },
        "biometria_retida": { "const": false }
      }
    },
    "evidencia_tecnica": {
      "oneOf": [
        { "type": "null" },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["politica_de_limiar"],
          "properties": {
            "politica_de_limiar": {
              "type": "object",
              "additionalProperties": false,
              "required": ["id", "hash"],
              "properties": {
                "id": { "type": "string", "minLength": 1, "maxLength": 64 },
                "hash": { "$ref": "#/$defs/hash" }
              }
            },
            "deteccao_ataque": {
              "type": "object",
              "additionalProperties": false,
              "required": ["norma", "resultado"],
              "properties": {
                "norma": { "type": "string", "minLength": 1, "maxLength": 64 },
                "resultado": { "enum": ["ok", "negado"] }
              }
            },
            "deteccao_injecao": {
              "type": "object",
              "additionalProperties": false,
              "required": ["metodo", "resultado"],
              "properties": {
                "metodo": { "type": "string", "minLength": 1, "maxLength": 64 },
                "resultado": { "enum": ["ok", "negado", "nao_executada"] }
              }
            },
            "dispositivo": {
              "type": "object",
              "additionalProperties": false,
              "required": ["atestacao", "resultado"],
              "properties": {
                "atestacao": { "type": "string", "minLength": 1, "maxLength": 64 },
                "resultado": { "enum": ["ok", "negado", "nao_executada"] }
              }
            }
          }
        }
      ]
    },
    "participantes": {
      "type": "array",
      "maxItems": 8,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["papel", "ref_compromisso", "ref_sal"],
        "properties": {
          "papel": { "enum": ["sujeito", "assistente", "mandatario", "testemunha", "revisor", "operador"] },
          "ref_compromisso": { "$ref": "#/$defs/hash" },
          "ref_sal": { "$ref": "#/$defs/sal" },
          "presenca_recibo_hash": { "$ref": "#/$defs/hash" }
        }
      }
    },
    "revisao_humana": {
      "oneOf": [
        { "type": "null" },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["via", "revisor", "protocolo", "ts"],
          "properties": {
            "via": { "enum": ["emissor", "cliente"] },
            "revisor": { "type": "string", "pattern": "^(sha256:[0-9a-f]{64}|apikey:[A-Za-z0-9_-]{1,64})$" },
            "protocolo": { "type": "string", "minLength": 1, "maxLength": 32 },
            "ts": { "$ref": "#/$defs/ts" }
          }
        }
      ]
    },
    "mandato": {
      "oneOf": [
        { "type": "null" },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["concessao"],
          "properties": {
            "concessao": {
              "type": "object",
              "additionalProperties": false,
              "required": ["escopo", "mandatario"],
              "properties": {
                "escopo": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["acoes", "limites", "validade_ate", "revogavel"],
                  "properties": {
                    "acoes": {
                      "type": "array",
                      "minItems": 1,
                      "maxItems": 32,
                      "uniqueItems": true,
                      "items": { "type": "string", "pattern": "^[a-z][a-z0-9_.]{0,63}$" }
                    },
                    "limites": {
                      "type": "object",
                      "maxProperties": 32,
                      "additionalProperties": {
                        "type": "object",
                        "additionalProperties": false,
                        "required": ["valor", "unidade"],
                        "properties": {
                          "valor": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 },
                          "unidade": { "type": "string", "minLength": 1, "maxLength": 32 },
                          "moeda": { "type": "string", "pattern": "^[A-Z]{3}$" },
                          "janela": { "enum": ["por_uso", "dia", "mes", "total"] }
                        }
                      }
                    },
                    "validade_ate": { "$ref": "#/$defs/ts" },
                    "revogavel": { "type": "boolean" }
                  }
                },
                "mandatario": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["tipo", "ref_compromisso", "ref_sal"],
                  "properties": {
                    "tipo": { "enum": ["pessoa", "agente"] },
                    "ref_compromisso": { "$ref": "#/$defs/hash" },
                    "ref_sal": { "$ref": "#/$defs/sal" },
                    "chave_agente": { "$ref": "#/$defs/jkt" }
                  }
                }
              }
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["uso"],
          "properties": {
            "uso": {
              "type": "object",
              "additionalProperties": false,
              "required": ["mandato_recibo_hash", "acao", "valores_hash", "executor", "nonce", "expira_em", "verificacao"],
              "properties": {
                "mandato_recibo_hash": { "$ref": "#/$defs/hash" },
                "acao": { "type": "string", "pattern": "^[a-z][a-z0-9_.]{0,63}$" },
                "valores_hash": { "$ref": "#/$defs/hash" },
                "executor": { "type": "string", "minLength": 1, "maxLength": 128 },
                "nonce": { "type": "string", "pattern": "^[0-9a-f]{32}$" },
                "expira_em": { "$ref": "#/$defs/ts" },
                "chave_agente": { "$ref": "#/$defs/jkt" },
                "verificacao": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["valido", "dentro_escopo", "dentro_validade", "revogado"],
                  "properties": {
                    "valido": { "type": "boolean" },
                    "dentro_escopo": { "type": "boolean" },
                    "dentro_validade": { "type": "boolean" },
                    "revogado": { "type": "boolean" }
                  }
                }
              }
            }
          }
        },
        {
          "type": "object",
          "additionalProperties": false,
          "required": ["revogacao"],
          "properties": {
            "revogacao": {
              "type": "object",
              "additionalProperties": false,
              "required": ["mandato_recibo_hash"],
              "properties": { "mandato_recibo_hash": { "$ref": "#/$defs/hash" } }
            }
          }
        }
      ]
    },
    "ingredientes": {
      "type": "array",
      "maxItems": 16,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["papel", "alg", "hash"],
        "properties": {
          "papel": {
            "enum": ["termo_exibido", "documento_anexo", "gatilho", "assinatura_juridica", "evidencia_contexto"]
          },
          "alg": { "const": "sha256" },
          "hash": { "$ref": "#/$defs/hash" },
          "declarado_pelo_cliente": { "type": "boolean" }
        }
      }
    },
    "ts_criado": { "$ref": "#/$defs/ts" },
    "ts_concluido": { "$ref": "#/$defs/ts" },
    "ts_emitido": { "$ref": "#/$defs/ts" },
    "expira_em": { "$ref": "#/$defs/ts" },
    "retencao": {
      "type": "object",
      "additionalProperties": false,
      "required": ["ate", "base"],
      "properties": {
        "ate": { "$ref": "#/$defs/ts" },
        "base": { "type": "string", "pattern": "^[a-z][a-z0-9_]{0,63}$" }
      }
    },
    "prev_hash": { "$ref": "#/$defs/hash" },
    "inclusao": {
      "type": "object",
      "additionalProperties": false,
      "required": ["log", "indice", "caminho", "ponto_hash"],
      "properties": {
        "log": { "type": "string", "minLength": 1, "maxLength": 128 },
        "indice": { "type": "integer", "minimum": 0, "maximum": 9007199254740991 },
        "caminho": { "type": "array", "maxItems": 64, "items": { "$ref": "#/$defs/hash" } },
        "ponto_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": {
    "id": { "type": "string", "minLength": 1, "maxLength": 128 },
    "hash": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" },
    "sal": { "type": "string", "pattern": "^[0-9a-f]{32}$" },
    "jkt": { "type": "string", "pattern": "^[A-Za-z0-9_-]{43}$" },
    "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$" },
    "garantia": {
      "type": "object",
      "additionalProperties": false,
      "required": ["valor", "sustentada_por"],
      "properties": {
        "valor": { "type": ["boolean", "null"] },
        "sustentada_por": {
          "oneOf": [
            { "type": "null" },
            { "enum": ["componente", "revisao", "declaracao_cliente", "base_oficial", "mandato"] }
          ]
        }
      }
    }
  }
}
