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

# Generate Key Pair

> Generate an RSA-2048 key pair for a new user. The private key should be
securely stored by the client and never transmitted again after this response.




## OpenAPI

````yaml post /api/v1/onboarding/generate-keys
openapi: 3.1.0
info:
  title: Digital Receipt Protocol API
  description: >
    The Digital Receipt Protocol (DRP) provides a secure, end-to-end encrypted
    digital receipt system

    for banks, merchants, and fintech applications. This API enables secure
    receipt encryption,

    decryption, and storage with robust key management and access control.


    ## Key Features

    - **End-to-End Encryption**: AES-256-GCM for receipt data with
    RSA-OAEP-SHA256 key wrapping

    - **User Onboarding**: Generate key pairs and register users with hashed PAN
    identifiers

    - **Access Control**: Short-lived access tokens (2-3 minutes) for receipt
    decryption

    - **Escrow Support**: Encrypted receipts for non-onboarded users via escrow
    keys

    - **Payment Gateway Integration**: Store receipts with transaction mappings
    for Stripe, Square, etc.

    - **Audit Logging**: Comprehensive tracking of all cryptographic operations


    ## Pricing Format

    All monetary values are represented in the smallest currency unit (e.g.,
    cents for USD).

    Example: $42.00 = 4200
  version: 1.0.0
  contact:
    name: Digital Receipt Protocol Team
    url: https://digitalreceiptprotocol.org
    email: api@digitalreceiptprotocol.org
  license:
    name: GNU General Public License v3.0
    url: https://www.gnu.org/licenses/gpl-3.0.html
servers:
  - url: https://api.digitalreceiptprotocol.org
    description: Production server
  - url: https://staging-api.digitalreceiptprotocol.org
    description: Staging server
  - url: http://localhost:3000
    description: Local development server
security: []
tags:
  - name: Health
    description: Service health monitoring
  - name: Onboarding
    description: User registration and key generation
  - name: Keys
    description: Key management and access control
  - name: Receipts
    description: Receipt encryption and decryption
  - name: Transactions
    description: Transaction storage and retrieval
  - name: Payments
    description: Payment gateway integration (Stripe, Square)
paths:
  /api/v1/onboarding/generate-keys:
    post:
      tags:
        - Onboarding
      summary: Generate key pair
      description: >
        Generate an RSA-2048 key pair for a new user. The private key should be

        securely stored by the client and never transmitted again after this
        response.
      operationId: generateKeys
      responses:
        '200':
          description: Key pair generated successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GenerateKeysResponse'
              example:
                success: true
                data:
                  keyId: a1b2c3d4-e5f6-4a7b-8c9d-0e1f2a3b4c5d
                  publicKey: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAz3...
                  privateKey: MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDP...
                  algorithm: RSA-OAEP-256
        '500':
          description: Key generation failed
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                success: false
                error:
                  code: KEY_GENERATION_FAILED
                  message: Failed to generate RSA key pair
components:
  schemas:
    GenerateKeysResponse:
      type: object
      properties:
        success:
          type: boolean
          example: true
        data:
          type: object
          properties:
            keyId:
              type: string
              format: uuid
              description: Unique identifier for the key pair
              example: 550e8400-e29b-41d4-a716-446655440000
            publicKey:
              type: string
              description: Base64-encoded RSA public key
              example: MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A...
            privateKey:
              type: string
              description: Base64-encoded RSA private key (store securely!)
              example: MIIEvQIBADANBgkqhkiG9w0BAQEFAASC...
            algorithm:
              type: string
              enum:
                - RSA-OAEP-256
              example: RSA-OAEP-256
    ErrorResponse:
      type: object
      properties:
        success:
          type: boolean
          example: false
        error:
          type: object
          properties:
            code:
              type: string
              description: Machine-readable error code
            message:
              type: string
              description: Human-readable error message
            details:
              type: object
              description: Additional error details
              additionalProperties: true

````