{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://lopw.com/docs/schemas/receipt.json",
  "title": "Receipt",
  "description": "The seller's signed statement of what it served (Rust: lopw_types::Receipt). Signed body; the signature travels beside it in SignedReceipt. receipt_hash = SHA-256('LOPW/RECEIPT/v1' || network_id || XDR(registry) || XDR(receipt)) where registry is the one the Claims contract is configured with.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "version",
    "service_id",
    "offer_hash",
    "terms_hash",
    "buyer",
    "payment_reference",
    "request_hash",
    "response_hash",
    "response_bytes",
    "status",
    "served_at",
    "data_as_of",
    "oracle",
    "key_version"
  ],
  "properties": {
    "version": {
      "type": "integer",
      "minimum": 0,
      "maximum": 4294967295,
      "description": "Protocol version, 1",
      "const": 1
    },
    "service_id": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$",
      "description": "The registered service"
    },
    "offer_hash": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$",
      "description": "The exact warranty offer this receipt was served under"
    },
    "terms_hash": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$",
      "description": "The terms the seller says it served under"
    },
    "buyer": {
      "type": "string",
      "pattern": "^[GC][A-Z2-7]{55}$",
      "description": "The payer, who receives any claim payout"
    },
    "payment_reference": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$",
      "description": "The settlement transaction hash"
    },
    "request_hash": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$",
      "description": "SHA-256(METHOD + '\\n' + path?query + '\\n' + lowercase-hex(SHA-256(body)))"
    },
    "response_hash": {
      "type": "string",
      "pattern": "^[0-9a-f]{64}$",
      "description": "SHA-256 of the response body as sent"
    },
    "response_bytes": {
      "type": "integer",
      "minimum": 0,
      "maximum": 4294967295,
      "description": "Size of the response body in bytes"
    },
    "status": {
      "type": "integer",
      "minimum": 0,
      "maximum": 4294967295,
      "description": "HTTP status served"
    },
    "served_at": {
      "type": "integer",
      "minimum": 0,
      "maximum": 18446744073709551615,
      "description": "Unix seconds when the response was sent"
    },
    "data_as_of": {
      "type": "integer",
      "minimum": 0,
      "maximum": 18446744073709551615,
      "description": "Unix seconds the data was true as of; 0 if not applicable (P3 is then never proven)"
    },
    "oracle": {
      "description": "Oracle evidence block for P6 services (Rust: OracleEvidenceOpt::None | OracleEvidenceOpt::Some(OracleEvidence))",
      "oneOf": [
        {
          "type": "null"
        },
        {
          "$ref": "#/$defs/OracleEvidence"
        }
      ]
    },
    "key_version": {
      "type": "integer",
      "minimum": 0,
      "maximum": 4294967295,
      "description": "Which signing key signed this receipt"
    }
  },
  "$defs": {
    "OracleAsset": {
      "description": "OracleAsset: how a SEP-40 oracle names the asset. XDR: enum variant [Symbol('Stellar'), Address] or [Symbol('Other'), Symbol]",
      "oneOf": [
        {
          "type": "object",
          "properties": {
            "Stellar": {
              "type": "string",
              "pattern": "^[GC][A-Z2-7]{55}$",
              "description": "Stellar strkey address (G... account or C... contract) in the Stellar binding"
            }
          },
          "required": [
            "Stellar"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "Other": {
              "type": "string",
              "maxLength": 32,
              "description": "Soroban Symbol"
            }
          },
          "required": [
            "Other"
          ],
          "additionalProperties": false
        }
      ]
    },
    "OracleEvidence": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "oracle_contract",
        "oracle_asset",
        "oracle_timestamp",
        "oracle_price",
        "reported_value"
      ],
      "properties": {
        "oracle_contract": {
          "type": "string",
          "pattern": "^[GC][A-Z2-7]{55}$",
          "description": "The SEP-40 oracle named in the terms"
        },
        "oracle_asset": {
          "$ref": "#/$defs/OracleAsset"
        },
        "oracle_timestamp": {
          "type": "integer",
          "minimum": 0,
          "maximum": 18446744073709551615,
          "description": "The timestamp the oracle returned for the observation used"
        },
        "oracle_price": {
          "type": "string",
          "pattern": "^-?[0-9]+$",
          "description": "The oracle price the seller saw; informational, the validator reads the oracle itself"
        },
        "reported_value": {
          "type": "string",
          "pattern": "^-?[0-9]+$",
          "description": "The value the seller served, in the oracle's decimals"
        }
      }
    },
    "SignedReceipt": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "receipt",
        "signature"
      ],
      "properties": {
        "receipt": {
          "$ref": "#"
        },
        "signature": {
          "type": "string",
          "pattern": "^[0-9a-f]{128}$",
          "description": "Ed25519 signature over receipt_hash by the service signing key"
        }
      },
      "description": "Rust: lopw_types::SignedReceipt. On the wire it travels as base64 ScVal XDR in PAYMENT-RESPONSE.extensions.lopw.receipt"
    }
  }
}
