> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dfns.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Delegate Key

> <Warning>
Only keys created with "`delayDelegation: true`" can then be delegated to an end-user. It means you need to know ahead of time that you're creating a wallet meant to be delegated to an end-user later. This is a safety to prevent, for example, a treasury wallet from being unintentionally delegated to an end-user.
</Warning>

<Note>
When a key is delegated to an end user, all wallets using this key as the signing key are also automatically delegated to the same end user. Key and wallet ownerships are guaranteed to be always consistent.
</Note>

<Danger>
This operation is irreversible. The key ownership will be transferred to the end-user
</Danger>

In most cases, when you want to implement [Wallet Delegation](https://docs.dfns.co/developers/guides/wallet-delegation), simply create the wallet by directly delegating it to an end user, in which case it will the non-custodial from the start.  There are some rare cases, however, where the key or wallet must be created before the user has accessed to the system.  To accommodate this, we've added the ability to create a key or wallet in delay delegation mode, and then later delegate it (i.e.: transfer ownership of it) to an end user via this endpoint.




## OpenAPI

````yaml /openapi.yaml post /keys/{keyId}/delegate
openapi: 3.1.0
info:
  version: 1.807.0
  title: Dfns
servers:
  - url: https://api.dfns.io
    description: Default - Europe
  - url: https://api.uae.dfns.io
    description: UAE
  - url: https://api.dfns.ninja
    description: <Deprecated> Staging
security: []
paths:
  /keys/{keyId}/delegate:
    post:
      tags:
        - Keys
      summary: Delegate Key
      description: >
        <Warning>

        Only keys created with "`delayDelegation: true`" can then be delegated
        to an end-user. It means you need to know ahead of time that you're
        creating a wallet meant to be delegated to an end-user later. This is a
        safety to prevent, for example, a treasury wallet from being
        unintentionally delegated to an end-user.

        </Warning>


        <Note>

        When a key is delegated to an end user, all wallets using this key as
        the signing key are also automatically delegated to the same end user.
        Key and wallet ownerships are guaranteed to be always consistent.

        </Note>


        <Danger>

        This operation is irreversible. The key ownership will be transferred to
        the end-user

        </Danger>


        In most cases, when you want to implement [Wallet
        Delegation](https://docs.dfns.co/developers/guides/wallet-delegation),
        simply create the wallet by directly delegating it to an end user, in
        which case it will the non-custodial from the start.  There are some
        rare cases, however, where the key or wallet must be created before the
        user has accessed to the system.  To accommodate this, we've added the
        ability to create a key or wallet in delay delegation mode, and then
        later delegate it (i.e.: transfer ownership of it) to an end user via
        this endpoint.
      parameters:
        - schema:
            type: string
            minLength: 1
          required: true
          name: keyId
          in: path
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                delegateTo:
                  type: string
                  minLength: 1
              required:
                - delegateTo
              additionalProperties: false
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  keyId:
                    type: string
                  status:
                    type: string
                    enum:
                      - Delegated
                required:
                  - keyId
                  - status
      security:
        - authenticationToken: []
          userActionSignature: []
components:
  securitySchemes:
    authenticationToken:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        **Bearer Token:** Used to authenticate API requests.

        More details how to generate the token: [Authentication
        flows](https://docs.dfns.co/api-reference/auth/login-flows)
    userActionSignature:
      type: apiKey
      in: header
      name: X-DFNS-USERACTION
      description: >-
        **User Action Signature:** Used to sign the change-inducing API
        requests.

        More details how to generate the token: [User Action Signing
        flows](https://docs.dfns.co/api-reference/auth/signing-flows)

````