{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://evidence.contact/transaction-evidence.schema.json",
  "title": "402Mob Transaction Evidence v1: direct Work Ticket",
  "type": "object",
  "properties": {
    "protocol": {
      "type": "string",
      "const": "402mob.transaction-evidence.v1"
    },
    "kind": {
      "type": "string",
      "const": "work_ticket"
    },
    "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"
    },
    "subject": {
      "type": "object",
      "properties": {
        "ticketId": {
          "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}$"
        },
        "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)$"
        },
        "capability": {
          "type": "string",
          "minLength": 3,
          "maxLength": 100
        },
        "inputHash": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "maxAmountAtomic": {
          "type": "string",
          "pattern": "^[1-9][0-9]{0,11}$"
        },
        "expiresAt": {
          "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))$"
        },
        "idempotencyKey": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_-]{16,128}$"
        }
      },
      "required": [
        "ticketId",
        "buyer",
        "merchantId",
        "capability",
        "inputHash",
        "maxAmountAtomic",
        "expiresAt",
        "idempotencyKey"
      ],
      "additionalProperties": false
    },
    "grant": {
      "type": "object",
      "properties": {
        "challengeId": {
          "anyOf": [
            {
              "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)$"
            },
            {
              "type": "null"
            }
          ]
        },
        "message": {
          "anyOf": [
            {
              "type": "string",
              "minLength": 1,
              "maxLength": 65536
            },
            {
              "type": "null"
            }
          ]
        },
        "signature": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^0x[0-9a-fA-F]{130}$"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "challengeId",
        "message",
        "signature"
      ],
      "additionalProperties": false
    },
    "agreement": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "protocol": {
              "type": "string",
              "const": "402mob.work-agreement.v1"
            },
            "requestId": {
              "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)$"
            },
            "proposalId": {
              "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)$"
            },
            "proposalTermsHash": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            },
            "settlementMode": {
              "type": "string",
              "const": "direct_prepayment"
            }
          },
          "required": [
            "protocol",
            "requestId",
            "proposalId",
            "proposalTermsHash",
            "settlementMode"
          ],
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "selection": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "requestId": {
              "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)$"
            },
            "proposalId": {
              "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)$"
            },
            "termsHash": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            },
            "proof": {
              "type": "object",
              "properties": {
                "challengeId": {
                  "anyOf": [
                    {
                      "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)$"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "message": {
                  "anyOf": [
                    {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 65536
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "signature": {
                  "anyOf": [
                    {
                      "type": "string",
                      "pattern": "^0x[0-9a-fA-F]{130}$"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "required": [
                "challengeId",
                "message",
                "signature"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "requestId",
            "proposalId",
            "termsHash",
            "proof"
          ],
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "quote": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "id": {
              "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)$"
            },
            "amountAtomic": {
              "type": "string",
              "pattern": "^[1-9][0-9]{0,11}$"
            },
            "payTo": {
              "type": "string",
              "pattern": "^0x[0-9a-fA-F]{40}$"
            },
            "deliverable": {
              "type": "string",
              "minLength": 1,
              "maxLength": 300
            },
            "contentType": {
              "type": "string",
              "enum": [
                "application/json",
                "text/plain; charset=utf-8"
              ]
            },
            "termsHash": {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            },
            "expiresAt": {
              "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))$"
            },
            "acceptance": {
              "type": "object",
              "properties": {
                "challengeId": {
                  "anyOf": [
                    {
                      "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)$"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "message": {
                  "anyOf": [
                    {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 65536
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "signature": {
                  "anyOf": [
                    {
                      "type": "string",
                      "pattern": "^0x[0-9a-fA-F]{130}$"
                    },
                    {
                      "type": "null"
                    }
                  ]
                }
              },
              "required": [
                "challengeId",
                "message",
                "signature"
              ],
              "additionalProperties": false
            }
          },
          "required": [
            "id",
            "amountAtomic",
            "payTo",
            "deliverable",
            "contentType",
            "termsHash",
            "expiresAt",
            "acceptance"
          ],
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "delivery": {
      "type": "object",
      "properties": {
        "resultHash": {
          "anyOf": [
            {
              "type": "string",
              "pattern": "^[a-f0-9]{64}$"
            },
            {
              "type": "null"
            }
          ]
        },
        "contentType": {
          "anyOf": [
            {
              "type": "string",
              "enum": [
                "application/json",
                "text/plain; charset=utf-8"
              ]
            },
            {
              "type": "null"
            }
          ]
        },
        "receipt": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "verdict": {
                  "type": "string",
                  "enum": [
                    "accepted",
                    "disputed"
                  ]
                },
                "proof": {
                  "type": "object",
                  "properties": {
                    "challengeId": {
                      "anyOf": [
                        {
                          "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)$"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "message": {
                      "anyOf": [
                        {
                          "type": "string",
                          "minLength": 1,
                          "maxLength": 65536
                        },
                        {
                          "type": "null"
                        }
                      ]
                    },
                    "signature": {
                      "anyOf": [
                        {
                          "type": "string",
                          "pattern": "^0x[0-9a-fA-F]{130}$"
                        },
                        {
                          "type": "null"
                        }
                      ]
                    }
                  },
                  "required": [
                    "challengeId",
                    "message",
                    "signature"
                  ],
                  "additionalProperties": false
                }
              },
              "required": [
                "verdict",
                "proof"
              ],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "resultHash",
        "contentType",
        "receipt"
      ],
      "additionalProperties": false
    },
    "observations": {
      "type": "object",
      "properties": {
        "source": {
          "type": "string",
          "const": "unsigned_server_snapshot"
        },
        "ticketState": {
          "type": "string",
          "enum": [
            "open",
            "claimed",
            "quoted",
            "accepted",
            "paying",
            "paid",
            "delivered",
            "accepted_by_buyer",
            "disputed",
            "expired"
          ]
        },
        "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))$"
        },
        "resultAvailable": {
          "type": "boolean"
        },
        "payment": {
          "anyOf": [
            {
              "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)$"
                },
                "state": {
                  "type": "string",
                  "enum": [
                    "executing",
                    "staged",
                    "settling",
                    "pending",
                    "settled",
                    "failed",
                    "expired"
                  ]
                },
                "settlementRecorded": {
                  "type": "boolean"
                },
                "transactionHash": {
                  "anyOf": [
                    {
                      "type": "string",
                      "pattern": "^0x[0-9a-fA-F]{64}$"
                    },
                    {
                      "type": "null"
                    }
                  ]
                },
                "amountAtomic": {
                  "type": "string",
                  "pattern": "^[1-9][0-9]{0,11}$"
                },
                "payer": {
                  "type": "string",
                  "pattern": "^0x[0-9a-fA-F]{40}$"
                },
                "recipient": {
                  "type": "string",
                  "pattern": "^0x[0-9a-fA-F]{40}$"
                },
                "network": {
                  "type": "string",
                  "const": "eip155:8453"
                },
                "asset": {
                  "type": "string",
                  "const": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913"
                }
              },
              "required": [
                "operationId",
                "state",
                "settlementRecorded",
                "transactionHash",
                "amountAtomic",
                "payer",
                "recipient",
                "network",
                "asset"
              ],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "source",
        "ticketState",
        "createdAt",
        "retentionExpiresAt",
        "resultAvailable",
        "payment"
      ],
      "additionalProperties": false
    },
    "bundleHash": {
      "type": "string",
      "pattern": "^[a-f0-9]{64}$"
    }
  },
  "required": [
    "protocol",
    "kind",
    "origin",
    "exportedAt",
    "network",
    "asset",
    "subject",
    "grant",
    "agreement",
    "selection",
    "quote",
    "delivery",
    "observations",
    "bundleHash"
  ],
  "additionalProperties": false
}
