openapi: 3.1.0
info:
  title: Dojo Jutsu Phone Security
  version: 1.0.0
servers:
  - url: https://PROJECT.supabase.co/functions/v1
paths:
  /phone-security:
    get:
      summary: Read public phone-page configuration
      parameters:
        - in: query
          name: operation
          required: true
          schema: { type: string, const: config }
      responses:
        '200':
          description: Public project URL/key and allowed portal origin
          content:
            application/json:
              schema:
                type: object
                required: [project_url, public_key, approval_origin]
                properties:
                  project_url: { type: string, format: uri }
                  public_key: { type: string }
                  approval_origin: { type: string, format: uri }
        '503': { $ref: '#/components/responses/Failure' }
    post:
      summary: Manage account phone credentials or verify a computer unlock
      description: >-
        Account operations require a verified bearer token. Registration and
        revocation require second-factor verification within five minutes.
        Authentication operations require the QR nonce; approval additionally
        requires a valid user-verified WebAuthn assertion from the request owner's
        enrolled credential. Approval does not upgrade the desktop auth JWT.
      security:
        - bearerAuth: []
        - {}
      requestBody:
        required: true
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/AccountRead'
                - $ref: '#/components/schemas/Create'
                - $ref: '#/components/schemas/RequestRead'
                - $ref: '#/components/schemas/Revoke'
                - $ref: '#/components/schemas/Register'
                - $ref: '#/components/schemas/PhoneRequest'
                - $ref: '#/components/schemas/Assertion'
      responses:
        '200':
          description: Operation-specific response (see accompanying API guide)
          content:
            application/json:
              schema:
                type: object
                additionalProperties: true
        '400': { $ref: '#/components/responses/Failure' }
        '401': { $ref: '#/components/responses/Failure' }
        '403': { $ref: '#/components/responses/Failure' }
        '404': { $ref: '#/components/responses/Failure' }
        '405': { $ref: '#/components/responses/Failure' }
        '409': { $ref: '#/components/responses/Failure' }
        '413': { $ref: '#/components/responses/Failure' }
        '503': { $ref: '#/components/responses/Failure' }
components:
  securitySchemes:
    bearerAuth: { type: http, scheme: bearer, bearerFormat: JWT }
  responses:
    Failure:
      description: Verification or configuration failed; no approval is granted
      content:
        application/json:
          schema:
            type: object
            required: [error]
            properties:
              error: { type: string }
  schemas:
    AccountRead:
      type: object
      required: [operation]
      properties:
        operation: { enum: [availability, devices, registration-options] }
    Create:
      type: object
      required: [operation, action_title, requesting_device_label]
      properties:
        operation: { const: create }
        action_title: { type: string, maxLength: 120 }
        requesting_device_label: { type: string, maxLength: 80 }
    RequestRead:
      type: object
      required: [operation, challenge_id]
      properties:
        operation: { enum: [status, cancel] }
        challenge_id: { type: string, format: uuid }
    Revoke:
      type: object
      required: [operation, device_id]
      properties:
        operation: { const: revoke }
        device_id: { type: string }
    Register:
      type: object
      required: [operation, ceremony_id, response, label]
      properties:
        operation: { const: registration-verify }
        ceremony_id: { type: string, format: uuid }
        response: { $ref: '#/components/schemas/WebAuthnResponse' }
        label: { type: string, maxLength: 80 }
    PhoneRequest:
      type: object
      required: [operation, challenge_id, nonce]
      properties:
        operation: { enum: [authentication-options, authentication-cancel] }
        challenge_id: { type: string, format: uuid }
        nonce: { type: string, maxLength: 128 }
    Assertion:
      type: object
      required: [operation, challenge_id, nonce, ceremony_id, response]
      properties:
        operation: { const: authentication-verify }
        challenge_id: { type: string, format: uuid }
        nonce: { type: string, maxLength: 128 }
        ceremony_id: { type: string, format: uuid }
        response: { $ref: '#/components/schemas/WebAuthnResponse' }
    WebAuthnResponse:
      type: object
      description: Standard base64url-encoded WebAuthn registration or authentication response
      required: [id, rawId, type, response, clientExtensionResults]
      properties:
        id: { type: string }
        rawId: { type: string }
        type: { const: public-key }
        clientExtensionResults: { type: object }
        authenticatorAttachment: { type: string }
        response:
          type: object
          required: [clientDataJSON]
          properties:
            clientDataJSON: { type: string }
            attestationObject: { type: string }
            authenticatorData: { type: string }
            signature: { type: string }
            userHandle: { type: [string, 'null'] }
            transports: { type: array, items: { type: string } }
