{
  "paths": {
    "/api/v1/timestamp": {
      "post": {
        "responses": {
          "422": {
            "$ref": "#/components/responses/UNPROCESSABLE_ENTITY"
          },
          "201": {
            "description": "Created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/TimestampResponse"
                }
              }
            }
          },
          "default": {
            "$ref": "#/components/responses/DEFAULT_ERROR"
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/TimestampRequest"
              }
            }
          }
        },
        "summary": "Create a timestamp.",
        "description": "The request has two levels, and they mirror the record:\n\n- `hash` and `hash_algorithm` are public. They are written on-chain in\n  clear, and anyone can read them.\n- everything under `metadata` is private. It is encrypted before it is\n  written, and only the seed returned in the answer opens it.\n\nOnly `hash` is required. There is no network to choose: this endpoint\nwrites to the chain of the environment you are calling.\n\nNo email is part of the record unless you send\n`metadata.include_account_email: true`. The email is then the one of the account\nthat owns the token: EMOZ reads it from the token, never from the\nrequest, and records its SHA-256 hash in the encrypted metadata.\n\nA hash can be recorded once: a second request with the same hash is\nanswered 409.",
        "tags": [
          "timestamp"
        ],
        "security": [
          {
            "bearerAuth": []
          }
        ]
      }
    }
  },
  "info": {
    "title": "EMOZ API",
    "version": "v1"
  },
  "tags": [
    {
      "name": "timestamp",
      "description": "Record on a public blockchain that a piece of data existed at a point in time. You send its hash, never the data, and receive a tamper-evident, independently verifiable record. Authenticate with an Authorization: Bearer <token> header. Two things are public: the hash and the name of its algorithm, written on-chain in clear. Everything else goes under metadata, is optional, and is encrypted before it is written: the answer carries the seed that opens it. No email is recorded unless you ask for it with metadata.include_account_email, which adds the verified email of the account that owns the token, as a SHA-256 hash."
    }
  ],
  "openapi": "3.0.3",
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "code": {
            "type": "integer",
            "description": "Error code"
          },
          "status": {
            "type": "string",
            "description": "Error name"
          },
          "message": {
            "type": "string",
            "description": "Error message"
          },
          "errors": {
            "type": "object",
            "description": "Errors",
            "additionalProperties": {}
          }
        },
        "additionalProperties": false
      },
      "PaginationMetadata": {
        "type": "object",
        "properties": {
          "total": {
            "type": "integer"
          },
          "total_pages": {
            "type": "integer"
          },
          "first_page": {
            "type": "integer"
          },
          "last_page": {
            "type": "integer"
          },
          "page": {
            "type": "integer"
          },
          "previous_page": {
            "type": "integer"
          },
          "next_page": {
            "type": "integer"
          }
        },
        "additionalProperties": false
      },
      "Metadata": {
        "type": "object",
        "properties": {
          "full_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255,
            "description": "A name to record with the hash. Optional."
          },
          "file_name": {
            "type": "string",
            "minLength": 1,
            "maxLength": 255,
            "description": "A name for the data, for example the file name. Optional. Written into the encrypted record, and used as the label of the timestamp in your EMOZ account."
          },
          "include_account_email": {
            "type": "boolean",
            "default": false,
            "description": "Set to true to bind the record to the email of the account that owns the token, which EMOZ verified with a one-time code. Its SHA-256 hash is written into the encrypted record; the address itself is never written. Default false: no email at all."
          },
          "declaration": {
            "type": "boolean",
            "default": false,
            "description": "Set to true only if the person has accepted this sentence in your own interface: \"I declare that I am the rightful owner of this file or am authorized to register it\". It is then written into the record. Default false."
          },
          "custom": {
            "type": "object",
            "description": "Any JSON object of your own: a location, a capture time, an order number. At most 1024 bytes as compact JSON. It is written on-chain inside the encrypted part and can never be changed or removed, so put there only what you are entitled to record for good.",
            "additionalProperties": {}
          }
        },
        "additionalProperties": false
      },
      "TimestampRequest": {
        "type": "object",
        "properties": {
          "hash": {
            "type": "string",
            "pattern": "^\\S{1,255}$",
            "description": "The hash (fingerprint) of the data, computed on your side. The data itself is never sent. Written on-chain in clear. For SHA-256, 64 hex characters."
          },
          "hash_algorithm": {
            "type": "string",
            "default": "SHA-256",
            "pattern": "^[A-Za-z0-9][A-Za-z0-9._/+-]{0,49}$",
            "description": "The algorithm that produced the hash, for example SHA-256, SHA-512, SHA3-256 or BLAKE3. Default SHA-256. Written on-chain in clear next to the hash, as you give it: EMOZ does not check that the hash was really made with it."
          },
          "metadata": {
            "description": "Optional. The private part of the record: everything in it is encrypted before it is written on-chain, and only the seed returned in the answer opens it.",
            "allOf": [
              {
                "$ref": "#/components/schemas/Metadata"
              }
            ]
          }
        },
        "required": [
          "hash"
        ],
        "additionalProperties": false
      },
      "TimestampResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "description": "confirmed once the transaction receipt is in."
          },
          "certificate_id": {
            "type": "string"
          },
          "transaction_hash": {
            "type": "string"
          },
          "verification_url": {
            "type": "string"
          },
          "hash": {
            "type": "string"
          },
          "hash_algorithm": {
            "type": "string"
          },
          "blockchain_network": {
            "type": "string"
          },
          "seed": {
            "type": "string",
            "description": "Base64 seed that decrypts the metadata of this record. Keep it: whoever holds it can read the metadata, and it cannot be changed."
          }
        },
        "additionalProperties": false
      }
    },
    "responses": {
      "UNPROCESSABLE_ENTITY": {
        "description": "Unprocessable Entity",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "DEFAULT_ERROR": {
        "description": "Default error response",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    },
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "The token identifies one EMOZ account. No email is written into a record unless the request sets metadata.include_account_email to true: the email of that account, verified with a one-time code, is then taken from the token and recorded as a SHA-256 hash in the encrypted metadata."
      }
    }
  }
}