{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://evidence.contact/transaction-record-evidence.schema.json",
  "title": "402Mob Transaction Evidence v2: operations and protected work",
  "anyOf": [
    {
      "type": "object",
      "properties": {
        "protocol": {
          "type": "string",
          "const": "402mob.transaction-evidence.v2"
        },
        "origin": {
          "type": "string",
          "maxLength": 2048,
          "format": "uri"
        },
        "exportedAt": {
          "type": "string",
          "format": "date-time",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
        },
        "network": {
          "type": "string",
          "const": "eip155:8453"
        },
        "asset": {
          "type": "string",
          "const": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913"
        },
        "source": {
          "type": "string",
          "const": "unsigned_server_snapshot"
        },
        "kind": {
          "type": "string",
          "const": "operation"
        },
        "subject": {
          "type": "object",
          "properties": {
            "operationId": {
              "type": "string",
              "format": "uuid",
              "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
            },
            "buyer": {
              "type": "string",
              "pattern": "^0x[0-9a-fA-F]{40}$"
            },
            "seller": {
              "type": "string",
              "pattern": "^0x[0-9a-fA-F]{40}$"
            },
            "route": {
              "type": "string",
              "minLength": 1,
              "maxLength": 2048
            },
            "requestHash": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            },
            "amountAtomic": {
              "type": "string",
              "pattern": "^[1-9][0-9]{0,11}$"
            }
          },
          "required": [
            "operationId",
            "buyer",
            "seller",
            "route",
            "requestHash",
            "amountAtomic"
          ],
          "additionalProperties": false
        },
        "payment": {
          "type": "object",
          "properties": {
            "state": {
              "type": "string",
              "enum": [
                "executing",
                "staged",
                "settling",
                "pending",
                "settled",
                "failed",
                "expired"
              ]
            },
            "transactionHash": {
              "anyOf": [
                {
                  "type": "string",
                  "pattern": "^0x[0-9a-fA-F]{64}$"
                },
                {
                  "type": "null"
                }
              ]
            },
            "settlementRecorded": {
              "type": "boolean"
            },
            "createdAt": {
              "type": "string",
              "format": "date-time",
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
            },
            "retentionExpiresAt": {
              "type": "string",
              "format": "date-time",
              "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
            }
          },
          "required": [
            "state",
            "transactionHash",
            "settlementRecorded",
            "createdAt",
            "retentionExpiresAt"
          ],
          "additionalProperties": false
        },
        "offer": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "merchantId": {
                  "type": "string",
                  "format": "uuid",
                  "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                },
                "offerId": {
                  "type": "string",
                  "format": "uuid",
                  "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
                },
                "terms": {
                  "anyOf": [
                    {
                      "type": "object",
                      "properties": {
                        "document": {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 20000
                        },
                        "hash": {
                          "type": "string",
                          "pattern": "^[a-f0-9]{64}$"
                        }
                      },
                      "required": [
                        "document",
                        "hash"
                      ],
                      "additionalProperties": false
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "required": [
                "merchantId",
                "offerId",
                "terms"
              ],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ]
        },
        "delivery": {
          "type": "object",
          "properties": {
            "resultHash": {
              "anyOf": [
                {
                  "type": "string",
                  "pattern": "^[a-f0-9]{64}$"
                },
                {
                  "type": "null"
                }
              ]
            },
            "contentType": {
              "anyOf": [
                {
                  "type": "string",
                  "maxLength": 128
                },
                {
                  "type": "null"
                }
              ]
            },
            "receipts": {
              "maxItems": 100,
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "message": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 20000
                  },
                  "signature": {
                    "type": "string",
                    "pattern": "^0x[0-9a-fA-F]{130}$"
                  }
                },
                "required": [
                  "message",
                  "signature"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "resultHash",
            "contentType",
            "receipts"
          ],
          "additionalProperties": false
        },
        "complaint": {
          "type": "object",
          "properties": {
            "availability": {
              "type": "string",
              "enum": [
                "absent",
                "expired",
                "retained"
              ]
            },
            "events": {
              "maxItems": 32,
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "message": {
                    "type": "string",
                    "minLength": 1,
                    "maxLength": 20000
                  },
                  "signature": {
                    "type": "string",
                    "pattern": "^0x[0-9a-fA-F]{130}$"
                  }
                },
                "required": [
                  "message",
                  "signature"
                ],
                "additionalProperties": false
              }
            }
          },
          "required": [
            "availability",
            "events"
          ],
          "additionalProperties": false
        },
        "bundleHash": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        }
      },
      "required": [
        "protocol",
        "origin",
        "exportedAt",
        "network",
        "asset",
        "source",
        "kind",
        "subject",
        "payment",
        "offer",
        "delivery",
        "complaint",
        "bundleHash"
      ],
      "additionalProperties": false
    },
    {
      "type": "object",
      "properties": {
        "protocol": {
          "type": "string",
          "const": "402mob.transaction-evidence.v2"
        },
        "origin": {
          "type": "string",
          "maxLength": 2048,
          "format": "uri"
        },
        "exportedAt": {
          "type": "string",
          "format": "date-time",
          "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
        },
        "network": {
          "type": "string",
          "const": "eip155:8453"
        },
        "asset": {
          "type": "string",
          "const": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913"
        },
        "source": {
          "type": "string",
          "const": "unsigned_server_snapshot"
        },
        "kind": {
          "type": "string",
          "enum": [
            "protected_json",
            "protected_inspection"
          ]
        },
        "subject": {
          "type": "object",
          "properties": {
            "jobId": {
              "type": "string",
              "pattern": "^0x[a-f0-9]{64}$"
            },
            "contract": {
              "type": "string",
              "pattern": "^0x[0-9a-fA-F]{40}$"
            },
            "buyer": {
              "type": "string",
              "pattern": "^0x[0-9a-fA-F]{40}$"
            },
            "seller": {
              "type": "string",
              "pattern": "^0x[0-9a-fA-F]{40}$"
            }
          },
          "required": [
            "jobId",
            "contract",
            "buyer",
            "seller"
          ],
          "additionalProperties": false
        },
        "snapshot": {
          "type": "object",
          "properties": {
            "observedAtSeconds": {
              "type": "integer",
              "minimum": 0,
              "maximum": 9007199254740991
            },
            "job": {
              "type": "object",
              "properties": {
                "terms": {
                  "type": "object",
                  "properties": {
                    "buyer": {
                      "type": "string",
                      "pattern": "^0x[0-9a-fA-F]{40}$"
                    },
                    "seller": {
                      "type": "string",
                      "pattern": "^0x[0-9a-fA-F]{40}$"
                    },
                    "amount": {
                      "type": "string",
                      "pattern": "^[1-9][0-9]{0,11}$"
                    },
                    "workHash": {
                      "type": "string",
                      "pattern": "^0x[a-f0-9]{64}$"
                    },
                    "deliveryDeadline": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 9007199254740991
                    },
                    "evaluationPeriod": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 9007199254740991
                    },
                    "correctionPeriod": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 9007199254740991
                    },
                    "resolutionDeadline": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 9007199254740991
                    },
                    "reviewPeriod": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 9007199254740991
                    },
                    "appealPeriod": {
                      "type": "integer",
                      "minimum": 0,
                      "maximum": 9007199254740991
                    },
                    "appealVerifier": {
                      "type": "string",
                      "pattern": "^0x[0-9a-fA-F]{40}$"
                    },
                    "fallbackVerifier": {
                      "type": "string",
                      "pattern": "^0x[0-9a-fA-F]{40}$"
                    },
                    "appealOriginHash": {
                      "type": "string",
                      "pattern": "^0x[a-f0-9]{64}$"
                    },
                    "fallbackOriginHash": {
                      "type": "string",
                      "pattern": "^0x[a-f0-9]{64}$"
                    },
                    "verifierHash": {
                      "type": "string",
                      "pattern": "^0x[a-f0-9]{64}$"
                    },
                    "nonce": {
                      "type": "string",
                      "pattern": "^0x[a-f0-9]{64}$"
                    }
                  },
                  "required": [
                    "buyer",
                    "seller",
                    "amount",
                    "workHash",
                    "deliveryDeadline",
                    "evaluationPeriod",
                    "correctionPeriod",
                    "resolutionDeadline",
                    "reviewPeriod",
                    "appealPeriod",
                    "appealVerifier",
                    "fallbackVerifier",
                    "appealOriginHash",
                    "fallbackOriginHash",
                    "verifierHash",
                    "nonce"
                  ],
                  "additionalProperties": false
                },
                "state": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 8
                },
                "resultHash": {
                  "type": "string",
                  "pattern": "^0x[a-f0-9]{64}$"
                },
                "attempt": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 2
                },
                "evaluationUntil": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                },
                "correctionUntil": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                },
                "fallbackUntil": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                },
                "buyerReceived": {
                  "type": "boolean"
                },
                "outcome": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 8
                },
                "reviewUntil": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                },
                "appealUntil": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 9007199254740991
                },
                "appealUsed": {
                  "type": "boolean"
                },
                "reason": {
                  "type": "integer",
                  "minimum": 0,
                  "maximum": 255
                },
                "evidenceHash": {
                  "type": "string",
                  "pattern": "^0x[a-f0-9]{64}$"
                }
              },
              "required": [
                "terms",
                "state",
                "resultHash",
                "attempt",
                "evaluationUntil",
                "correctionUntil",
                "fallbackUntil",
                "buyerReceived",
                "outcome",
                "reviewUntil",
                "appealUntil",
                "appealUsed",
                "reason",
                "evidenceHash"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "observedAtSeconds",
            "job"
          ],
          "additionalProperties": false
        },
        "candidates": {
          "maxItems": 2,
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "attempt": {
                "type": "integer",
                "minimum": 1,
                "maximum": 2
              },
              "resultHash": {
                "type": "string",
                "pattern": "^0x[a-f0-9]{64}$"
              },
              "signature": {
                "type": "string",
                "pattern": "^0x[0-9a-fA-F]{130}$"
              },
              "replicaA": {
                "anyOf": [
                  {
                    "type": "string",
                    "pattern": "^0x[0-9a-fA-F]{130}$"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "replicaB": {
                "anyOf": [
                  {
                    "type": "string",
                    "pattern": "^0x[0-9a-fA-F]{130}$"
                  },
                  {
                    "type": "null"
                  }
                ]
              }
            },
            "required": [
              "attempt",
              "resultHash",
              "signature",
              "replicaA",
              "replicaB"
            ],
            "additionalProperties": false
          }
        },
        "unretainedProofs": {
          "type": "array",
          "prefixItems": [
            {
              "type": "string",
              "const": "funding_authorization"
            },
            {
              "type": "string",
              "const": "buyer_acceptance"
            },
            {
              "type": "string",
              "const": "verdicts"
            },
            {
              "type": "string",
              "const": "appeals"
            }
          ],
          "items": false,
          "minItems": 4,
          "maxItems": 4
        },
        "bundleHash": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        }
      },
      "required": [
        "protocol",
        "origin",
        "exportedAt",
        "network",
        "asset",
        "source",
        "kind",
        "subject",
        "snapshot",
        "candidates",
        "unretainedProofs",
        "bundleHash"
      ],
      "additionalProperties": false
    }
  ]
}
