{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://mandateshield.com/schemas/x402-gate-artifact-v1.json",
  "title": "MandateShield x402 Gate Artifact Journal v1",
  "description": "Customer-controlled durable record for one x402 v2 exact/EIP-3009 signed payment artifact. payment_payload is a payment credential and must not be sent to MandateShield or public telemetry.",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "id",
    "version",
    "state",
    "binding_digest",
    "receipt_id",
    "payload_digest",
    "authorization_digest",
    "authorization_claim_key",
    "request_digest",
    "payer",
    "nonce",
    "valid_after",
    "valid_before",
    "settlement_deadline_at",
    "submission_anchor_requested_at",
    "submission_anchor_accepted_at",
    "submission_anchor",
    "payment_payload",
    "created_at",
    "updated_at"
  ],
  "properties": {
    "id": {
      "type": "string",
      "pattern": "^msx4_[a-f0-9]{64}$"
    },
    "version": {
      "type": "integer",
      "minimum": 1
    },
    "state": {
      "type": "string",
      "enum": [
        "SIGNED",
        "TRANSMITTING",
        "RESPONSE_REPORTED",
        "PENDING",
        "CONFIRMED",
        "UNUSED_EXPIRED",
        "UNKNOWN"
      ]
    },
    "binding_digest": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "receipt_id": {
      "type": "string",
      "pattern": "^msr_[a-f0-9]{32}$"
    },
    "payload_digest": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "authorization_digest": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "authorization_claim_key": {
      "type": "string",
      "pattern": "^msx4_nonce_[a-f0-9]{64}$",
      "description": "Atomic customer-journal ownership key for network, asset, payer and EIP-3009 nonce. One key may belong to only one artifact ID."
    },
    "request_digest": {
      "type": "string",
      "pattern": "^sha256:[a-f0-9]{64}$"
    },
    "payer": {
      "type": "string",
      "pattern": "^0x[a-fA-F0-9]{40}$"
    },
    "nonce": {
      "type": "string",
      "pattern": "^0x[a-fA-F0-9]{64}$"
    },
    "valid_after": {
      "type": "string",
      "pattern": "^(?:0|[1-9][0-9]{0,77})$"
    },
    "valid_before": {
      "type": "string",
      "pattern": "^(?:0|[1-9][0-9]{0,77})$"
    },
    "settlement_deadline_at": {
      "type": "integer",
      "minimum": 1,
      "description": "Epoch-millisecond release deadline returned by MandateShield CONSUME and bound into this artifact."
    },
    "submission_anchor_requested_at": {
      "type": "string",
      "format": "date-time"
    },
    "submission_anchor_accepted_at": {
      "type": "string",
      "format": "date-time"
    },
    "submission_anchor": {
      "$ref": "#/$defs/submissionAnchor"
    },
    "payment_payload": {
      "$ref": "#/$defs/paymentPayload"
    },
    "transmission_started_at": {
      "type": "string",
      "format": "date-time"
    },
    "reconciliation_started_at": {
      "type": "string",
      "format": "date-time"
    },
    "response_status": {
      "type": "integer",
      "minimum": 100,
      "maximum": 599
    },
    "settlement_response": {
      "anyOf": [
        {
          "$ref": "#/$defs/settlementResponse"
        },
        {
          "type": "null"
        }
      ]
    },
    "verifier_result": {
      "oneOf": [
        {
          "$ref": "#/$defs/confirmedVerification"
        },
        {
          "$ref": "#/$defs/unusedExpiredVerification"
        },
        {
          "$ref": "#/$defs/unresolvedVerification"
        }
      ]
    },
    "provider_reference": {
      "type": "string",
      "minLength": 1,
      "maxLength": 240
    },
    "created_at": {
      "type": "string",
      "format": "date-time"
    },
    "updated_at": {
      "type": "string",
      "format": "date-time"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "state": {
            "enum": [
              "TRANSMITTING",
              "RESPONSE_REPORTED"
            ]
          }
        },
        "required": [
          "state"
        ]
      },
      "then": {
        "required": [
          "transmission_started_at"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "state": {
            "enum": [
              "PENDING",
              "CONFIRMED",
              "UNUSED_EXPIRED",
              "UNKNOWN"
            ]
          }
        },
        "required": [
          "state"
        ]
      },
      "then": {
        "anyOf": [
          {
            "required": [
              "transmission_started_at"
            ]
          },
          {
            "required": [
              "reconciliation_started_at"
            ]
          }
        ]
      }
    },
    {
      "if": {
        "properties": {
          "state": {
            "const": "RESPONSE_REPORTED"
          }
        },
        "required": [
          "state"
        ]
      },
      "then": {
        "required": [
          "response_status"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "state": {
            "enum": [
              "PENDING",
              "CONFIRMED",
              "UNUSED_EXPIRED"
            ]
          }
        },
        "required": [
          "state"
        ]
      },
      "then": {
        "required": [
          "verifier_result",
          "provider_reference"
        ]
      }
    },
    {
      "if": {
        "properties": {
          "state": {
            "const": "PENDING"
          }
        },
        "required": [
          "state"
        ]
      },
      "then": {
        "properties": {
          "verifier_result": {
            "properties": {
              "status": {
                "const": "PENDING"
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "state": {
            "const": "CONFIRMED"
          }
        },
        "required": [
          "state"
        ]
      },
      "then": {
        "properties": {
          "provider_reference": {
            "pattern": "^0x[a-fA-F0-9]{64}$"
          },
          "verifier_result": {
            "properties": {
              "status": {
                "const": "CONFIRMED"
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "state": {
            "const": "UNUSED_EXPIRED"
          }
        },
        "required": [
          "state"
        ]
      },
      "then": {
        "properties": {
          "provider_reference": {
            "pattern": "^msx4_[a-f0-9]{64}$"
          },
          "verifier_result": {
            "properties": {
              "status": {
                "const": "UNUSED_EXPIRED"
              }
            }
          }
        }
      }
    }
  ],
  "$defs": {
    "submissionAnchor": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "status",
        "canonical",
        "latest_canonical_block",
        "nonce_unused",
        "nonce_state_query",
        "block_number",
        "block_hash",
        "block_timestamp",
        "network",
        "asset",
        "payer",
        "pay_to",
        "amount",
        "nonce",
        "valid_after",
        "valid_before",
        "authorization_digest",
        "payload_digest",
        "observed_at"
      ],
      "properties": {
        "status": {
          "const": "NONCE_UNUSED_ANCHOR"
        },
        "canonical": {
          "const": true
        },
        "latest_canonical_block": {
          "const": true
        },
        "nonce_unused": {
          "const": true
        },
        "nonce_state_query": {
          "const": "BLOCK_HASH_REQUIRE_CANONICAL"
        },
        "block_number": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,77})$"
        },
        "block_hash": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{64}$"
        },
        "block_timestamp": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,77})$"
        },
        "network": {
          "type": "string"
        },
        "asset": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{40}$"
        },
        "payer": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{40}$"
        },
        "pay_to": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{40}$"
        },
        "amount": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,77})$"
        },
        "nonce": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{64}$"
        },
        "valid_after": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,77})$"
        },
        "valid_before": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,77})$"
        },
        "authorization_digest": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        },
        "payload_digest": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        },
        "observed_at": {
          "type": "string",
          "format": "date-time"
        }
      }
    },
    "paymentPayload": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "x402Version",
        "resource",
        "accepted",
        "payload"
      ],
      "properties": {
        "x402Version": {
          "const": 2
        },
        "resource": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "url"
          ],
          "properties": {
            "url": {
              "type": "string",
              "format": "uri",
              "maxLength": 2048
            },
            "description": {
              "type": "string",
              "minLength": 1,
              "maxLength": 2048
            },
            "mimeType": {
              "type": "string",
              "minLength": 1,
              "maxLength": 240
            }
          }
        },
        "accepted": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "scheme",
            "network",
            "asset",
            "amount",
            "payTo",
            "maxTimeoutSeconds",
            "extra"
          ],
          "properties": {
            "scheme": {
              "const": "exact"
            },
            "network": {
              "type": "string",
              "pattern": "^eip155:[1-9][0-9]{0,31}$"
            },
            "asset": {
              "type": "string",
              "pattern": "^0x[a-fA-F0-9]{40}$"
            },
            "amount": {
              "type": "string",
              "pattern": "^(?:0|[1-9][0-9]{0,77})$"
            },
            "payTo": {
              "type": "string",
              "pattern": "^0x[a-fA-F0-9]{40}$"
            },
            "maxTimeoutSeconds": {
              "type": "integer",
              "minimum": 1,
              "maximum": 600
            },
            "extra": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "name",
                "version"
              ],
              "properties": {
                "assetTransferMethod": {
                  "const": "eip3009"
                },
                "name": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 100
                },
                "version": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 50
                }
              }
            }
          }
        },
        "payload": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "signature",
            "authorization"
          ],
          "properties": {
            "signature": {
              "type": "string",
              "pattern": "^0x[a-fA-F0-9]{130}$"
            },
            "authorization": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "from",
                "to",
                "value",
                "validAfter",
                "validBefore",
                "nonce"
              ],
              "properties": {
                "from": {
                  "type": "string",
                  "pattern": "^0x[a-fA-F0-9]{40}$"
                },
                "to": {
                  "type": "string",
                  "pattern": "^0x[a-fA-F0-9]{40}$"
                },
                "value": {
                  "type": "string",
                  "pattern": "^(?:0|[1-9][0-9]{0,77})$"
                },
                "validAfter": {
                  "type": "string",
                  "pattern": "^(?:0|[1-9][0-9]{0,77})$"
                },
                "validBefore": {
                  "type": "string",
                  "pattern": "^(?:0|[1-9][0-9]{0,77})$"
                },
                "nonce": {
                  "type": "string",
                  "pattern": "^0x[a-fA-F0-9]{64}$"
                }
              }
            }
          }
        },
        "extensions": {
          "type": "object",
          "maxProperties": 0
        }
      }
    },
    "settlementResponse": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "success",
        "transaction",
        "network"
      ],
      "properties": {
        "success": {
          "type": "boolean"
        },
        "transaction": {
          "type": "string",
          "maxLength": 240
        },
        "network": {
          "type": "string",
          "maxLength": 240
        },
        "payer": {
          "type": "string",
          "maxLength": 240
        },
        "amount": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,77})$"
        }
      }
    },
    "confirmedVerification": {
      "type": "object",
      "required": [
        "status",
        "canonical",
        "authorization_consumed",
        "transfer_method",
        "confirmations",
        "transaction",
        "block_number",
        "block_hash",
        "block_timestamp",
        "network",
        "asset",
        "payer",
        "pay_to",
        "amount",
        "nonce",
        "valid_after",
        "valid_before",
        "authorization_digest",
        "payload_digest",
        "submission_anchor_block_number",
        "submission_anchor_block_hash",
        "submission_anchor_canonical_ancestor",
        "observed_at"
      ],
      "properties": {
        "status": {
          "const": "CONFIRMED"
        },
        "observed_at": {
          "type": "string",
          "format": "date-time"
        },
        "canonical": {
          "const": true
        },
        "authorization_consumed": {
          "const": true
        },
        "transfer_method": {
          "const": "transferWithAuthorization"
        },
        "confirmations": {
          "type": "integer",
          "minimum": 1
        },
        "transaction": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{64}$"
        },
        "block_number": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,77})$"
        },
        "block_hash": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{64}$"
        },
        "block_timestamp": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,77})$"
        },
        "network": {
          "type": "string"
        },
        "asset": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{40}$"
        },
        "payer": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{40}$"
        },
        "pay_to": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{40}$"
        },
        "amount": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,77})$"
        },
        "nonce": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{64}$"
        },
        "valid_after": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,77})$"
        },
        "valid_before": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,77})$"
        },
        "authorization_digest": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        },
        "payload_digest": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        },
        "submission_anchor_block_number": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,77})$"
        },
        "submission_anchor_block_hash": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{64}$"
        },
        "submission_anchor_canonical_ancestor": {
          "const": true
        }
      },
      "additionalProperties": false
    },
    "unusedExpiredVerification": {
      "type": "object",
      "required": [
        "status",
        "canonical",
        "nonce_unused",
        "confirmations",
        "block_number",
        "block_hash",
        "block_timestamp",
        "network",
        "asset",
        "payer",
        "pay_to",
        "amount",
        "nonce",
        "valid_after",
        "valid_before",
        "authorization_digest",
        "payload_digest",
        "submission_anchor_block_number",
        "submission_anchor_block_hash",
        "submission_anchor_canonical_ancestor",
        "observed_at"
      ],
      "properties": {
        "status": {
          "const": "UNUSED_EXPIRED"
        },
        "observed_at": {
          "type": "string",
          "format": "date-time"
        },
        "canonical": {
          "const": true
        },
        "nonce_unused": {
          "const": true
        },
        "confirmations": {
          "type": "integer",
          "minimum": 1
        },
        "block_number": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,77})$"
        },
        "block_hash": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{64}$"
        },
        "block_timestamp": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,77})$"
        },
        "network": {
          "type": "string"
        },
        "asset": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{40}$"
        },
        "payer": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{40}$"
        },
        "pay_to": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{40}$"
        },
        "amount": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,77})$"
        },
        "nonce": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{64}$"
        },
        "valid_after": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,77})$"
        },
        "valid_before": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,77})$"
        },
        "authorization_digest": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        },
        "payload_digest": {
          "type": "string",
          "pattern": "^sha256:[a-f0-9]{64}$"
        },
        "submission_anchor_block_number": {
          "type": "string",
          "pattern": "^(?:0|[1-9][0-9]{0,77})$"
        },
        "submission_anchor_block_hash": {
          "type": "string",
          "pattern": "^0x[a-fA-F0-9]{64}$"
        },
        "submission_anchor_canonical_ancestor": {
          "const": true
        }
      },
      "additionalProperties": false
    },
    "unresolvedVerification": {
      "type": "object",
      "required": [
        "status",
        "observed_at"
      ],
      "properties": {
        "status": {
          "enum": [
            "PENDING",
            "UNKNOWN"
          ]
        },
        "observed_at": {
          "type": "string",
          "format": "date-time"
        }
      },
      "additionalProperties": false
    }
  }
}
