{
  "openapi": "3.1.0",
  "info": {
    "title": "VoidNote API",
    "version": "1.0.0",
    "description": "Zero-knowledge self-destructing notes. The server stores only encrypted blobs — plaintext never leaves the client. Encryption: AES-256-GCM with a 12-byte random IV and no AAD. The secret is 16 random bytes (32 hex chars) carried in the share link's #fragment. Key derivation, named by the note's kdf: 'sha256' key = SHA-256(hex_decode(secret)); 'pbkdf2-sha256-600k' key = PBKDF2-HMAC-SHA256(password as UTF-8, salt = hex_decode(secret), 600000 iterations, 32 bytes). Creating a note needs no account; a Bearer API key from a free account raises the limits.",
    "contact": {
      "email": "api@voidnote.net"
    }
  },
  "servers": [
    {
      "url": "https://voidnote.net",
      "description": "Production"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key from your dashboard (starts with vn_)"
      }
    },
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "string"
          }
        },
        "required": [
          "error"
        ]
      },
      "CreateNoteRequest": {
        "type": "object",
        "required": [
          "encrypted",
          "iv"
        ],
        "properties": {
          "encrypted": {
            "type": "string",
            "description": "AES-256-GCM ciphertext (hex-encoded)",
            "example": "a1b2c3..."
          },
          "iv": {
            "type": "string",
            "description": "12-byte GCM nonce (hex-encoded)",
            "example": "000102030405060708090a0b"
          },
          "viewLimit": {
            "type": "integer",
            "minimum": 1,
            "maximum": 100,
            "default": 1,
            "description": "How many times the note can be read before destruction. 1–10 without authentication, 1–100 with an account."
          },
          "expiresIn": {
            "type": "integer",
            "minimum": 60,
            "maximum": 2592000,
            "default": 3600,
            "description": "Lifetime in seconds. 60–604800 (7 days) without authentication, 60–2592000 (30 days) with an account. Default 3600."
          },
          "kdf": {
            "type": "string",
            "enum": [
              "sha256",
              "pbkdf2-sha256-600k"
            ],
            "default": "sha256",
            "description": "How the reader derives the AES key. 'sha256': key = SHA-256(hex_decode(secret)). 'pbkdf2-sha256-600k': key = PBKDF2-HMAC-SHA256(password, salt = hex_decode(secret), 600000 iterations, 32 bytes) — a password-protected note."
          }
        }
      },
      "CreateNoteResponse": {
        "type": "object",
        "properties": {
          "token": {
            "type": "string",
            "description": "32-char hex tokenId (server-generated)",
            "example": "a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4"
          },
          "url": {
            "type": "string",
            "description": "Base URL without secret — append #<secret> to get the full shareable link",
            "example": "https://voidnote.net/n/a1b2c3d4e5f6a1b2c3d4e5f6a1b2c3d4"
          },
          "expiresAt": {
            "type": "string",
            "description": "UTC, formatted YYYY-MM-DD HH:MM:SS"
          },
          "viewLimit": {
            "type": "integer"
          },
          "kdf": {
            "type": "string",
            "enum": [
              "sha256",
              "pbkdf2-sha256-600k"
            ]
          }
        }
      },
      "ConsumeNoteResponse": {
        "type": "object",
        "properties": {
          "token": {
            "type": "string"
          },
          "encrypted": {
            "type": "string",
            "description": "AES-256-GCM ciphertext followed by the 16-byte tag (hex). Derive the key as named by kdf."
          },
          "iv": {
            "type": "string",
            "description": "12-byte GCM nonce (hex)"
          },
          "algorithm": {
            "type": "string",
            "enum": [
              "AES-256-GCM"
            ]
          },
          "kdf": {
            "type": "string",
            "enum": [
              "sha256",
              "pbkdf2-sha256-600k"
            ],
            "description": "Key derivation to use; 'pbkdf2-sha256-600k' means the reader must supply the note's password"
          },
          "keyDerivation": {
            "type": "string",
            "enum": [
              "SHA-256",
              "PBKDF2-HMAC-SHA256"
            ],
            "description": "Human-readable form of kdf"
          },
          "consumed": {
            "type": "boolean"
          },
          "viewsRemaining": {
            "type": "integer"
          },
          "destroyed": {
            "type": "boolean",
            "description": "true if this was the last view"
          }
        }
      },
      "NoteMetaResponse": {
        "type": "object",
        "properties": {
          "token": {
            "type": "string"
          },
          "exists": {
            "type": "boolean",
            "description": "false when the note never existed, has expired, or has no views left; the other fields are then omitted"
          },
          "type": {
            "type": "string",
            "enum": [
              "note"
            ]
          },
          "createdAt": {
            "type": "string",
            "format": "date-time"
          },
          "expiresAt": {
            "type": "string",
            "format": "date-time"
          },
          "viewLimit": {
            "type": "integer"
          },
          "viewsRemaining": {
            "type": "integer"
          },
          "kdf": {
            "type": "string",
            "enum": [
              "sha256",
              "pbkdf2-sha256-600k"
            ]
          }
        }
      }
    }
  },
  "paths": {
    "/api/v1/note/": {
      "post": {
        "summary": "Create a note",
        "description": "Encrypt content client-side and store the ciphertext. The server generates a tokenId and never sees plaintext. Append #<your_secret> to the returned url to form the full shareable link. Authentication is optional: without it the note has no owner, is held to the anonymous limits (expiresIn ≤ 604800, viewLimit ≤ 10) and creation is rate-limited per client IP (IPv6 per /64). With a Bearer API key or a session the note belongs to the account and gets the account limits (expiresIn ≤ 2592000, viewLimit ≤ 100).",
        "security": [
          {},
          {
            "bearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CreateNoteRequest"
              },
              "example": {
                "encrypted": "a1b2c3...",
                "iv": "000102030405060708090a0b",
                "viewLimit": 1,
                "expiresIn": 3600,
                "kdf": "sha256"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Note created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/CreateNoteResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request body, or a limit exceeded for this kind of caller"
          },
          "401": {
            "description": "A Bearer API key was sent but is not valid. It is refused, never treated as anonymous."
          },
          "429": {
            "description": "Rate limit exceeded",
            "headers": {
              "Retry-After": {
                "schema": {
                  "type": "integer"
                },
                "description": "Seconds to wait"
              }
            }
          }
        }
      }
    },
    "/api/v1/note/{tokenId}/consume/": {
      "get": {
        "summary": "Consume (read + burn) a note",
        "description": "Returns the encrypted blob and decrements the view count. On the last view, the note is permanently destroyed. Decrypt locally: derive the key as named by kdf, then AES-256-GCM decrypt.",
        "security": [],
        "parameters": [
          {
            "name": "tokenId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{32}$"
            },
            "description": "32-char hex tokenId from the shareable URL"
          }
        ],
        "responses": {
          "200": {
            "description": "Encrypted blob returned",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConsumeNoteResponse"
                }
              }
            }
          },
          "410": {
            "description": "Note not found, expired, or already destroyed"
          },
          "429": {
            "description": "Rate limit exceeded"
          }
        }
      }
    },
    "/api/v1/note/{tokenId}/meta/": {
      "get": {
        "summary": "Peek at note metadata",
        "description": "Returns metadata without consuming a view. Safe to call before revealing.",
        "security": [],
        "parameters": [
          {
            "name": "tokenId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{32}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Note metadata",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/NoteMetaResponse"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded"
          }
        }
      }
    },
    "/api/v1/vault/{tokenId}/meta": {
      "get": {
        "summary": "Peek at vault file metadata",
        "security": [],
        "parameters": [
          {
            "name": "tokenId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{32}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "File metadata",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "token": {
                      "type": "string"
                    },
                    "exists": {
                      "type": "boolean"
                    },
                    "fileName": {
                      "type": "string"
                    },
                    "sizeBytes": {
                      "type": "integer"
                    },
                    "createdAt": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "expiresAt": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/vault/{tokenId}/consume": {
      "get": {
        "summary": "Download and destroy a vault file",
        "description": "Returns the raw encrypted binary. IV is in the X-Vault-IV response header. Decrypt with AES-256-GCM using key=SHA-256(hex_decode(secret)). Single-use — file is destroyed after download.",
        "security": [],
        "parameters": [
          {
            "name": "tokenId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "pattern": "^[0-9a-f]{32}$"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Encrypted binary",
            "headers": {
              "X-Vault-IV": {
                "schema": {
                  "type": "string"
                },
                "description": "12-byte GCM nonce (hex)"
              },
              "X-VoidNote-Algorithm": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "AES-256-GCM"
                  ]
                }
              },
              "X-VoidNote-Key-Derivation": {
                "schema": {
                  "type": "string",
                  "enum": [
                    "SHA-256"
                  ]
                }
              }
            },
            "content": {
              "application/octet-stream": {}
            }
          },
          "404": {
            "description": "File not found or already downloaded"
          }
        }
      }
    }
  }
}