Technical Flow
Complete step-by-step guide showing how all the pieces of the Digital Receipt Protocol work together, from user onboarding to receipt retrieval.What Happens Behind the Scenes
1
Generate Key Pair
Create an RSA-2048 key pair for a new userResponse includes public and private keys. Store the private key securely on the client device.
2
Register User
Onboard the user with their identifiers and public key
3
Encrypt Receipt
When a transaction occurs, encrypt the receipt data with the user’s public keyReturns encrypted receipt data using AES-256-GCM with RSA key wrapping.
4
Store Receipt
Store the encrypted receipt linked to the transaction
5
Request Access Token
User requests a short-lived access token to decrypt their receiptReturns a time-limited access token (valid for 2-3 minutes).
6
Retrieve and Decrypt
Fetch the encrypted receipt and decrypt client-sideClient receives encrypted receipt and decrypts it using their private key stored in the device’s secure enclave.
Security Flow Diagram
The following diagram illustrates the complete security flow from key generation through receipt decryption:User Onboarding Flow
Initial Setup
When a new user signs up for your application:-
Client generates keys - Call
/api/v1/onboarding/generate-keys- Returns RSA-2048 public/private key pair
- Client stores private key in device secure storage (iOS Secure Enclave, Android KeyStore)
- Never transmit private key over network
-
Client registers user - Call
/api/v1/onboarding/register- Send user identifiers (email, phone, card number)
- Send public key
- DRP API associates public key with user identifiers
- User is ready - User can now receive encrypted receipts
Key Storage Requirements
Receipt Encryption Flow
Merchant Workflow
When a transaction completes:- Merchant identifies user - Via card token, email, or phone number
-
Merchant encrypts receipt - Call
/api/v1/receipts/encrypt- Provide user identifier
- Provide receipt data (merchant name, amount, items, etc.)
- DRP API encrypts using user’s public key (AES-256-GCM with RSA key wrapping)
-
Merchant stores encrypted receipt - Call
/api/v1/receipts- Store encrypted receipt data
- Link to transaction ID
- Add metadata (merchant ID, amount, timestamp)
Receipt Data Format
Receipt data should include:Pricing Format: All amounts are in the smallest currency unit (cents for USD).Example: $42.00 = 4200
Receipt Retrieval Flow
User/Client Workflow
When a user wants to view their receipts:-
Request access token - Call
/api/v1/keys/request-access- Provide user ID and receipt ID
- Receive short-lived access token (valid 2-3 minutes)
-
Fetch encrypted receipt - Call
/api/v1/receipts/{userId}- Include access token in headers
- Receive encrypted receipt data
-
Decrypt client-side - Use stored private key
- Decrypt using device secure storage (Secure Enclave/KeyStore)
- Never send private key over network
- Display decrypted receipt to user
Access Token Security
Access tokens are intentionally short-lived (2-3 minutes) to minimize security risks:- Limits exposure window if token is intercepted
- Forces fresh authentication for each receipt access
- Tokens automatically expire and cannot be reused
- New token required for each receipt retrieval
Error Scenarios
User Not Onboarded
If a user hasn’t onboarded yet, the encrypt endpoint will return an error:Access Token Expired
Access tokens expire after 2-3 minutes:/api/v1/keys/request-access.
Private Key Lost
If a user loses their private key (e.g., device reset):- Cannot decrypt old receipts - This is by design for security
- Solution: Generate new key pair and re-onboard
- Best practice: Implement key backup mechanisms in your app
Security Best Practices
Key Storage
Always store private keys in device secure storage:
- iOS: Secure Enclave
- Android: KeyStore
- Never in plain text or regular storage
Access Tokens
Use short-lived access tokens:
- Request fresh token for each receipt
- Don’t cache or reuse tokens
- Tokens expire in 2-3 minutes
API Keys
Protect your API keys:
- Use environment variables
- Never commit to source control
- Rotate regularly
- Use different keys for dev/staging/prod
HTTPS Only
Always use HTTPS:
- All API calls must use HTTPS
- Verify SSL certificates
- Don’t bypass certificate validation