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

# Create a challenge

> Creates a challenge for one action on one card. Pass the challenge to
the application unchanged: the application verifies it, asks the
cardholder's wallet to sign it, and calls the card route of the action.
Your backend never sees the card data.

Before it calls this route, the application creates a signature key pair
and an encryption key pair for this action only, and sends you the
thumbprint of the signature public key (`sigThumbprint`).

Returns 404 when the account or the card is not yours, or the card is not
a virtual card of the account. Returns 422 with reason
`CARD_STATE_NOT_ALLOWED` when the card is not active, and with reason
`ACCOUNT_HAS_NO_OWNER` when the account has no owner address.



## OpenAPI

````yaml https://core.sandbox.gnosispay.in/partner-api/openapi.json post /v1/challenge
openapi: 3.2.0
info:
  title: Gnosis Pay Partner API
  version: 1.0.0
  description: >-
    Server-to-server API for onboarding users, creating accounts and cards,
    moving

    funds, and managing the card lifecycle. Call this API only from a trusted

    backend. Every request requires a partner access token, and every resource
    is

    scoped to the authenticated partner. The exceptions are the routes that the

    cardholder's application calls directly to read and change card data

    (`GET /v1/challenge/keys` and the card routes of the encrypted data

    protocol): they take no token and allow any CORS origin.
servers:
  - url: https://core.prod.gnosispay.com/partner-api
    description: Production
    variables: {}
  - url: https://core.sandbox.gnosispay.in/core
    description: Sandbox
    variables: {}
security:
  - BearerAuth: []
tags:
  - name: KYC
  - name: Accounts
  - name: Cards
  - name: Encrypted data
    description: >-
      Lets the cardholder's application read the card data (PAN, CVV, expiration

      date and PIN) and set a new PIN. The card data is encrypted between the

      application and GP. Your backend and your network never see it, even when

      a request passes through them.


      ## Goals


      - Only the application and GP can read the card data or the new PIN.

      - The account owner approves each action: the cardholder's wallet signs an
        EIP-712 message for it.
      - Your access token alone cannot read or change card data.

      - The application can verify that each challenge and each reply came from
        GP.

      ## Algorithms


      | Use | Algorithm |

      |---|---|

      | Keys | `EC` on the `P-256` curve |

      | Signature (JWS) | `ES256` |

      | Key agreement (JWE) | `ECDH-ES` |

      | Content encryption (JWE) | `A256GCM` |

      | Key thumbprint | RFC 7638 with SHA-256, base64url without padding |

      | Wallet signature | EIP-712 (`eth_signTypedData_v4`), checked with
      ERC-1271 for a smart account |


      Every token is a JWT. A standard JOSE library can create and verify all of

      them.


      ## Flow


      ```mermaid

      sequenceDiagram
          autonumber
          participant APP as Application
          participant WALLET as Wallet
          participant BACKEND as Your backend
          participant GP

          APP->>APP: create a signature key pair and an encryption key pair
          APP->>BACKEND: thumbprint of the signature public key
          BACKEND->>GP: POST /v1/challenge
          GP-->>BACKEND: challenge (JWS)
          BACKEND-->>APP: challenge
          APP->>GP: GET /v1/challenge/keys
          GP-->>APP: GP public keys (JWKS)
          APP->>APP: verify the challenge
          APP->>WALLET: sign the EIP-712 message of the challenge
          WALLET-->>APP: signature
          APP->>GP: POST /v1/cards/... with the signed and encrypted answer (JWE)
          alt read the card details or the PIN
              GP-->>APP: data (JWE that holds a JWS)
          else change the PIN
              GP-->>APP: proof (JWS)
          end
          APP->>APP: verify the reply and delete both key pairs
      ```
  - name: PCI
  - name: 3DS
  - name: Card transactions
  - name: Deposits
  - name: Withdrawals
  - name: Webhooks
paths:
  /v1/challenge:
    post:
      tags:
        - Encrypted data
      summary: Create a challenge
      description: >-
        Creates a challenge for one action on one card. Pass the challenge to

        the application unchanged: the application verifies it, asks the

        cardholder's wallet to sign it, and calls the card route of the action.

        Your backend never sees the card data.


        Before it calls this route, the application creates a signature key pair

        and an encryption key pair for this action only, and sends you the

        thumbprint of the signature public key (`sigThumbprint`).


        Returns 404 when the account or the card is not yours, or the card is
        not

        a virtual card of the account. Returns 422 with reason

        `CARD_STATE_NOT_ALLOWED` when the card is not active, and with reason

        `ACCOUNT_HAS_NO_OWNER` when the account has no owner address.
      operationId: challenges.create.v1
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateChallengeParams'
        description: The account, the card, the action and the application key.
      responses:
        '200':
          description: The request has succeeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Challenge'
        default:
          description: An unexpected error response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    CreateChallengeParams:
      type: object
      required:
        - accountId
        - cardId
        - action
        - sigThumbprint
      properties:
        accountId:
          $ref: '#/components/schemas/uuid'
          description: The account that owns the card.
        cardId:
          $ref: '#/components/schemas/uuid'
          description: The card of the action.
        action:
          $ref: '#/components/schemas/ChallengeAction'
          description: The action that the cardholder asked for.
        sigThumbprint:
          $ref: '#/components/schemas/JWKThumbprint'
          description: |-
            The thumbprint of the signature public key that the application
            generated for this action.
    Challenge:
      type: object
      required:
        - challenge
      properties:
        challenge:
          $ref: '#/components/schemas/ChallengeJws'
          description: >-
            The challenge. Pass it to the application unchanged. It expires
            after

            300 seconds and can be used once.
    Error:
      type: object
      required:
        - code
        - message
      properties:
        code:
          type: integer
          format: int32
          description: HTTP status code.
        message:
          type: string
          description: Generic human-readable text for the status code. Do not parse it.
        reason:
          type: string
          description: >-
            Stable machine-readable code identifying the specific cause, present
            only

            for errors that expose one (e.g. `CREATE_CARD_LIMIT_EXCEEDED`).
            Branch on

            this rather than on `message`.
    uuid:
      type: string
      format: uuid
    ChallengeAction:
      type: string
      enum:
        - cards.read_details.v1
        - cards.read_pin.v1
        - cards.change_pin.v1
      description: |-
        The card action that a challenge authorizes. Each value is the
        `operationId` of the card route that the challenge unlocks.
    JWKThumbprint:
      type: string
      pattern: ^[A-Za-z0-9_-]{43}$
      description: The RFC 7638 SHA-256 thumbprint of a key, base64url without padding.
    ChallengeJws:
      type: string
      maxLength: 8192
      format: jwt
      description: >-
        A compact JWS that GP signed. Its protected header is `ChallengeHeader`
        and

        its claims are `ChallengeClaims`.


        The application, with a JOSE library:


        1. Loads the keys of `GET /v1/challenge/keys` as a JWKS.

        2. Verifies the JWS with the key whose `use` is `sig` and whose `kid` is

        the `kid` header, and checks that `alg` is `ES256`, `typ` is

        `gp-challenge+jwt` and `aud` is `gp-encrypted-data`.

        3. Checks that `client_sig_thumbprint` is the thumbprint of its
        signature

        key, and that `exp` is not past.

        4. Checks that `action` and `card_id` are the action and the card that
        the

        cardholder asked for.

        5. Asks the cardholder's wallet to sign `eip712` with

        `eth_signTypedData_v4`.
      x-jwt-claims-schema: '#/components/schemas/ChallengeClaims'
      x-jose-header-schema: '#/components/schemas/ChallengeHeader'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: Bearer

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.