{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://webgcp.org/schemas/receipt/v0.1.json",
  "$comment": "v0.1 stub schema for the per-invocation signed receipt. Full normative shape in prose at https://webgcp.org/spec/v0.1/#section-3-4. Wire format details defer to x402 V2 settlement spec. Validates top-level required fields only; v0.2 tightens. Receipts are MUST at L2+ governed implementations; L0/L1 implementations MAY omit.",
  "title": "webGCP Signed Receipt v0.1",
  "type": "object",
  "required": [
    "receipt_id",
    "entity_id",
    "entity_version",
    "invoked_at",
    "signature"
  ],
  "properties": {
    "receipt_id": {
      "type": "string",
      "description": "Globally unique receipt identifier (operator-namespaced)."
    },
    "entity_id": {
      "type": "string",
      "description": "URN of the entity / skill invoked."
    },
    "entity_version": {
      "type": "string",
      "pattern": "^[0-9]+\\.[0-9]+\\.[0-9]+$"
    },
    "invoked_at": {
      "type": "string",
      "format": "date-time"
    },
    "invoker": {
      "type": "object",
      "properties": {
        "subject": {"type": "string"},
        "on_behalf_of": {"type": "string"},
        "auth_assertion": {"type": "string"},
        "mandate_ref": {
          "type": "string",
          "description": "Optional AP2 mandate reference."
        }
      }
    },
    "upstream_receipt": {
      "type": "string",
      "description": "Reference to the parent receipt if this invocation is part of a delegation chain (graph composition)."
    },
    "outcome": {
      "type": "object",
      "properties": {
        "status": {
          "enum": ["ok", "failed", "partial"]
        },
        "latency_ms": {"type": "integer"},
        "tokens_used": {"type": "integer"}
      }
    },
    "settlement": {
      "type": "object",
      "description": "Optional Commerce-layer settlement reference (x402 / Circle / etc.).",
      "properties": {
        "amount": {"type": "string"},
        "currency": {"type": "string"},
        "settlement_protocol": {"type": "string"},
        "tx_ref": {"type": "string"}
      }
    },
    "signature": {
      "type": "object",
      "required": ["alg", "kid", "value"],
      "properties": {
        "alg": {
          "type": "string",
          "description": "Signing algorithm (e.g., 'EdDSA', 'ES256K')."
        },
        "kid": {
          "type": "string",
          "description": "Key identifier."
        },
        "value": {
          "type": "string",
          "description": "Base64url-encoded signature value over the canonical receipt form."
        }
      }
    }
  }
}
