# Copyright 2018 New Vector Ltd
# Copyright 2019 The Matrix.org Foundation C.I.C.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
openapi: 3.1.0
info:
  title: Matrix Identity Service Ephemeral Invitation Signing API
  version: 2.0.0
paths:
  /sign-ed25519:
    post:
      summary: Sign invitation details
      description: |-
        Sign invitation details.

        The identity server will look up `token` which was stored in a call
        to `store-invite`, and fetch the sender of the invite.
      operationId: blindlySignStuffV2
      security:
        - accessTokenQuery: []
        - accessTokenBearer: []
      requestBody:
        content:
          application/json:
            schema:
              type: object
              example: {
                "mxid": "@foo:bar.com",
                "token": "sometoken",
                "private_key": "base64encodedkey"
              }
              properties:
                mxid:
                  type: string
                  description: The Matrix user ID of the user accepting the invitation.
                token:
                  type: string
                  description: The token from the call to `store-invite`.
                private_key:
                  type: string
                  description: The private key, encoded as [Unpadded
                    base64](/appendices/#unpadded-base64).
              required:
                - mxid
                - token
                - private_key
      responses:
        "200":
          description: The signed JSON of the mxid, sender, and token.
          content:
            application/json:
              schema:
                type: object
                properties:
                  mxid:
                    type: string
                    description: The Matrix user ID of the user accepting the invitation.
                  sender:
                    type: string
                    description: The Matrix user ID of the user who sent the invitation.
                  signatures:
                    type: object
                    description: The signature of the mxid, sender, and token.
                    allOf:
                      - $ref: ../../schemas/server-signatures.yaml
                  token:
                    type: string
                    description: The token for the invitation.
                required:
                  - mxid
                  - sender
                  - signatures
                  - token
              examples:
                response:
                  value: {
                    "mxid": "@foo:bar.com",
                    "sender": "@baz:bar.com",
                    "signatures": {
                      "my.id.server": {
                        "ed25519:0": "def987"
                      }
                    },
                    "token": "abc123"
                  }
        "403":
          description: |
            The user must do something in order to use this endpoint. One example
            is an `M_TERMS_NOT_SIGNED` error where the user must [agree to more terms](/identity-service-api/#terms-of-service).
          content:
            application/json:
              schema:
                $ref: ../client-server/definitions/errors/error.yaml
              examples:
                response:
                  value: {
                    "errcode": "M_TERMS_NOT_SIGNED",
                    "error": "Please accept our updated terms of service before continuing"
                  }
        "404":
          description: The token was not found.
          content:
            application/json:
              schema:
                $ref: ../client-server/definitions/errors/error.yaml
              examples:
                response:
                  value: {
                    "errcode": "M_UNRECOGNIZED",
                    "error": "Didn't recognize token"
                  }
servers:
  - url: "{protocol}://{hostname}{basePath}"
    variables:
      protocol:
        enum:
          - http
          - https
        default: https
      hostname:
        default: localhost:8090
      basePath:
        default: /_matrix/identity/v2
components:
  securitySchemes:
    accessTokenQuery:
      $ref: definitions/security.yaml#/accessTokenQuery
    accessTokenBearer:
      $ref: definitions/security.yaml#/accessTokenBearer
