# 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.
swagger: '2.0'
info:
  title: "Matrix Identity Service Ephemeral Invitation Signing API"
  version: "2.0.0"
host: localhost:8090
schemes:
  - https
basePath: /_matrix/identity/v2
consumes:
  - application/json
produces:
  - application/json
securityDefinitions:
  $ref: definitions/security.yaml
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:
        - accessToken: []
      parameters:
        - in: body
          name: body
          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.
          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.
                $ref: "../../schemas/server-signatures.yaml"
              token:
                type: string
                description: The token for the invitation.
            required: ['mxid', 'sender', 'signatures', 'token']
          examples:
            application/json: {
              "mxid": "@foo:bar.com",
              "sender": "@baz:bar.com",
              "signatures": {
                "my.id.server": {
                  "ed25519:0": "def987"
                }
              },
              "token": "abc123"
            }
        404:
          description: The token was not found.
          examples:
            application/json: {
              "errcode": "M_UNRECOGNIZED",
              "error": "Didn't recognize token"
            }
          schema:
            $ref: "../client-server/definitions/errors/error.yaml"
        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).
          examples:
            application/json: {
              "errcode": "M_TERMS_NOT_SIGNED",
              "error": "Please accept our updated terms of service before continuing"
            }
          schema:
            $ref: "../client-server/definitions/errors/error.yaml"
