{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/farofinance-app/json-schema/farofinance-app-receipt-out-schema.json",
  "title": "ReceiptOut",
  "x-generated": "2026-11-08",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/_original/farofinance-app-api-openapi.json#/components/schemas/ReceiptOut",
  "properties": {
    "receipt_id": {
      "type": "string",
      "title": "Receipt Id"
    },
    "request_id": {
      "type": "string",
      "title": "Request Id"
    },
    "payload": {
      "additionalProperties": true,
      "type": "object",
      "title": "Payload",
      "description": "The frozen receipt contract: verdict, confidence, reason_hash, request_id, artifact_hash, timestamp. Hashes only — no PII."
    },
    "jws": {
      "type": "string",
      "title": "Jws",
      "description": "Detached Ed25519 JWS over the canonical payload bytes."
    },
    "kid": {
      "type": "string",
      "title": "Kid",
      "description": "JWKS key id that signed this receipt."
    },
    "algorithm": {
      "type": "string",
      "title": "Algorithm",
      "default": "EdDSA"
    },
    "log_index": {
      "type": "integer",
      "title": "Log Index",
      "description": "This receipt's sequence number in the transparency log."
    },
    "prev_hash": {
      "type": "string",
      "title": "Prev Hash",
      "description": "entry_hash of the previous log entry (hex)."
    },
    "entry_hash": {
      "type": "string",
      "title": "Entry Hash",
      "description": "sha256(prev_hash + '\\n' + payload_hash + '\\n' + jws) — the chain link (hex)."
    },
    "day": {
      "type": "string",
      "title": "Day"
    },
    "inclusion_proof": {
      "anyOf": [
        {
          "$ref": "#/$defs/InclusionProofOut"
        },
        {
          "type": "null"
        }
      ],
      "description": "Merkle proof against the day's signed root; null until the root publishes."
    },
    "verify": {
      "type": "string",
      "title": "Verify",
      "default": "Verify offline: re-serialize `payload` as canonical JSON (sorted keys, minimal separators), re-attach it to the detached `jws`, and check the Ed25519 signature against /.well-known/jwks.json. Then verify `inclusion_proof` against the signed day root at /.well-known/faro-log-roots (and its Base transaction). Reference: scripts/verify_receipt.py."
    }
  },
  "type": "object",
  "required": [
    "receipt_id",
    "request_id",
    "payload",
    "jws",
    "kid",
    "log_index",
    "prev_hash",
    "entry_hash",
    "day"
  ],
  "$defs": {
    "InclusionProofOut": {
      "properties": {
        "leaf": {
          "type": "string",
          "title": "Leaf",
          "description": "The receipt's entry_hash — the Merkle leaf (hex)."
        },
        "index": {
          "type": "integer",
          "title": "Index",
          "description": "Zero-based position of the leaf in the day's tree."
        },
        "tree_size": {
          "type": "integer",
          "title": "Tree Size"
        },
        "path": {
          "items": {
            "type": "string"
          },
          "type": "array",
          "title": "Path",
          "description": "Sibling hashes from leaf to root (hex)."
        },
        "root": {
          "$ref": "#/$defs/LogRootOut"
        }
      },
      "type": "object",
      "required": [
        "leaf",
        "index",
        "tree_size",
        "path",
        "root"
      ],
      "title": "InclusionProofOut"
    },
    "LogRootOut": {
      "properties": {
        "day": {
          "type": "string",
          "title": "Day",
          "description": "UTC day this root covers, YYYY-MM-DD."
        },
        "tree_size": {
          "type": "integer",
          "title": "Tree Size",
          "description": "Number of receipt entries under this root."
        },
        "root_hash": {
          "type": "string",
          "title": "Root Hash",
          "description": "RFC 6962 Merkle root over the day's entry hashes (hex)."
        },
        "chain_head": {
          "type": "string",
          "title": "Chain Head",
          "description": "entry_hash of the day's last log entry (hex)."
        },
        "generated_at": {
          "type": "string",
          "format": "date-time",
          "title": "Generated At"
        },
        "jws": {
          "type": "string",
          "title": "Jws",
          "description": "Detached Ed25519 JWS over the canonical root payload."
        },
        "kid": {
          "type": "string",
          "title": "Kid",
          "description": "JWKS key id that signed this root."
        },
        "base_tx_hash": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "null"
            }
          ],
          "title": "Base Tx Hash",
          "description": "Base transaction carrying this root as calldata (null until anchored)."
        },
        "anchored_at": {
          "anyOf": [
            {
              "type": "string",
              "format": "date-time"
            },
            {
              "type": "null"
            }
          ],
          "title": "Anchored At"
        }
      },
      "type": "object",
      "required": [
        "day",
        "tree_size",
        "root_hash",
        "chain_head",
        "generated_at",
        "jws",
        "kid"
      ],
      "title": "LogRootOut"
    }
  }
}