{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://rootz.global/schemas/ask-orders/origin-receipt.schema.json",
  "title": "ASK Orders origin receipt \u2014 the portable bundle a recipient verifies: who authorised it, what was asked, what it was made from, and the process it ran under",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "kind",
    "subject",
    "inclusion",
    "checkpoint",
    "orders",
    "manifest",
    "authority",
    "genesis",
    "materials",
    "inputs",
    "keys"
  ],
  "properties": {
    "kind": {
      "const": "ask-orders.origin-receipt.v1"
    },
    "subject": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "request",
        "response"
      ],
      "properties": {
        "request": {
          "oneOf": [
            {
              "$ref": "leaf.schema.json"
            },
            {
              "$ref": "#/$defs/Withheld"
            }
          ]
        },
        "response": {
          "$ref": "leaf.schema.json"
        }
      }
    },
    "inclusion": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "request",
        "response"
      ],
      "properties": {
        "request": {
          "$ref": "#/$defs/InclusionProof"
        },
        "response": {
          "$ref": "#/$defs/InclusionProof"
        }
      }
    },
    "checkpoint": {
      "$ref": "checkpoint.schema.json"
    },
    "orders": {
      "type": "array",
      "minItems": 1,
      "items": {
        "$ref": "order.schema.json"
      }
    },
    "manifest": {
      "oneOf": [
        {
          "$ref": "controls-manifest.schema.json"
        },
        {
          "$ref": "#/$defs/Withheld"
        }
      ]
    },
    "authority": {
      "$ref": "#/$defs/AuthorityEvidence"
    },
    "materials": {
      "description": "What was fetched before the response \u2014 not what the answer entailed.",
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "leaf",
          "inclusion"
        ],
        "properties": {
          "leaf": {
            "oneOf": [
              {
                "$ref": "leaf.schema.json"
              },
              {
                "$ref": "#/$defs/Withheld"
              }
            ]
          },
          "inclusion": {
            "$ref": "#/$defs/InclusionProof"
          }
        }
      }
    },
    "keys": {
      "type": "object",
      "description": "JWKS of every public key needed to verify the bundle."
    },
    "genesis": {
      "description": "The session's genesis leaf and its inclusion proof: what was installed and the effective policy hash at install (ORD-015).",
      "type": "object",
      "additionalProperties": false,
      "required": [
        "leaf",
        "inclusion"
      ],
      "properties": {
        "leaf": {
          "$ref": "leaf.schema.json"
        },
        "inclusion": {
          "$ref": "#/$defs/InclusionProof"
        }
      }
    },
    "inputs": {
      "description": "Origin receipts the subject request declared as inputs (keep the chain alive, ORD-015). A withheld input is null.",
      "type": "array",
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "digest",
          "receipt"
        ],
        "properties": {
          "digest": {
            "$ref": "common.schema.json#/$defs/Digest"
          },
          "receipt": {
            "oneOf": [
              {
                "$ref": "#"
              },
              {
                "type": "null"
              }
            ]
          }
        }
      }
    }
  },
  "$defs": {
    "InclusionProof": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "leaf_index",
        "tree_size",
        "path"
      ],
      "properties": {
        "leaf_index": {
          "type": "integer",
          "minimum": 0
        },
        "tree_size": {
          "type": "integer",
          "minimum": 1
        },
        "path": {
          "type": "array",
          "items": {
            "$ref": "common.schema.json#/$defs/Digest"
          }
        }
      }
    },
    "AuthorityEvidence": {
      "description": "Snapshot of the corporate chain at order time. Offline, chain facts are 'asserted'; with an RPC they become 'verified'.",
      "type": "object",
      "additionalProperties": false,
      "required": [
        "root",
        "hops",
        "legal_anchor"
      ],
      "properties": {
        "root": {
          "$ref": "common.schema.json#/$defs/Caip10"
        },
        "legal_anchor": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "jurisdiction",
            "registry_ids"
          ],
          "properties": {
            "jurisdiction": {
              "type": "string",
              "maxLength": 20
            },
            "registry_ids": {
              "type": "array",
              "items": {
                "type": "string",
                "maxLength": 200
              }
            }
          }
        },
        "hops": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "from",
              "to",
              "evidence",
              "valid_from",
              "valid_until"
            ],
            "properties": {
              "from": {
                "$ref": "common.schema.json#/$defs/Caip10"
              },
              "to": {
                "$ref": "common.schema.json#/$defs/Account"
              },
              "evidence": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "type",
                  "ref"
                ],
                "properties": {
                  "type": {
                    "enum": [
                      "safe-exec-transaction",
                      "eip191-signature",
                      "transaction-calldata"
                    ]
                  },
                  "ref": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 400
                  },
                  "message": {
                    "type": "string",
                    "maxLength": 2000
                  }
                }
              },
              "valid_from": {
                "$ref": "common.schema.json#/$defs/Time"
              },
              "valid_until": {
                "oneOf": [
                  {
                    "$ref": "common.schema.json#/$defs/Time"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            }
          }
        }
      }
    },
    "Withheld": {
      "description": "A part the issuer withheld (M15): only its digest is public. For a leaf, its RFC 9162 Merkle leaf hash; for the manifest, its object digest.",
      "type": "object",
      "additionalProperties": false,
      "required": [
        "withheld"
      ],
      "properties": {
        "withheld": {
          "$ref": "common.schema.json#/$defs/Digest"
        }
      }
    }
  }
}
