Manage terminal keys
Prepare a terminal signing key before accepting payments. POS keys are separate from the consumer developer signing key.
Check the state
First resolve any retained financial operation. Key creation, rotation and recovery can be blocked until that operation is resolved and acknowledged.
val state = withContext(Dispatchers.IO) { sdk.keyState() }The examples use the coroutine imports from the quickstart. keyInfo() returns creation, expiry and minimum-rotation timestamps in Unix milliseconds. It never returns the private key. Read metadata only after handling recovery: keyInfo() throws when a mutation is pending, and returns null when no record exists.
| State | Meaning | Action |
|---|---|---|
MISSING | No usable local record | Import a trusted legacy key or explicitly create one |
READY | Key is usable | Continue |
ROTATION_DUE | Rotation timestamp reached; key has not expired | Schedule explicit rotation; signing remains available |
EXPIRED | Key can no longer sign | Explicitly rotate the known key |
RECOVERY_REQUIRED | A previous mutation has an uncertain outcome | Explicit recovery rotation |
Use returned timestamps for scheduling. Native POS methods do not rotate automatically. The documented React Native host can orchestrate maintenance before a new financial operation.
Create or rotate
Call the operation selected by your setup or maintenance flow:
val created = withContext(Dispatchers.IO) { sdk.createKey() } // New setup.
// For an existing local key, use sdk.rotateKey() instead.Creation returning HTTP 412 means the server rejected creation, potentially because a key already exists. It does not automatically rotate. Investigate the existing key or explicitly choose recovery. No old/new-key overlap is promised.
Import a trusted existing key
Use this when migrating an existing POS app. Read its trusted encrypted-storage record and construct PosKeyMaterial:
| Field | Required value |
|---|---|
posId, serialNo | The selected POS and original terminal serial |
value | Raw Base64 PKCS#8 RSA private key; no PEM headers |
createdDateTimeMillis | Creation timestamp converted to Unix milliseconds |
expiryDateTimeMillis | Future expiry timestamp in Unix milliseconds |
minRotationDateTimeMillis | Rotation timestamp in Unix milliseconds |
val imported = withContext(Dispatchers.IO) { sdk.importKey(material) }The SDK checks context, RSA size (3072–4096 bits), timestamp ordering, expiry and creation-clock skew. It writes the protected record and verifies readback before returning.
Delete the old host copy only after successful import. Re-importing identical material is allowed; replacing different local material is rejected. A pending key mutation blocks import.
Format and identifier checks do not prove the key matches the server's current private-key record. Use the trusted legacy source; do not send a synthetic payment to test it.
Recover an uncertain mutation
Before sending a key mutation, the SDK saves a pending marker. A valid response is stored and read back before that marker is cleared.
Definite HTTP 4xx responses other than 408 restore the prior local state. Network failure, cancellation, timeout, redirects, 5xx, malformed successful responses and storage failure can leave recovery required. Inspect keyState() after failure or restart.
If the host explicitly chooses replacement:
val replacement = withContext(Dispatchers.IO) { sdk.recoverKeyByRotation() }This requests a new server key. It does not retrieve the lost private key. Another uncertain response leaves recovery required again. Never replay a key mutation automatically.
Storage and signatures
Android protects keys in an AES-GCM file excluded from backup, with its own Android Keystore alias. The API URL and storage ID scope the records; consumer stores remain separate.
Payment and refund signatures use RSA PKCS#1 v1.5 with SHA-512 over UTF-8:
Payment: posId|branchId|merchantId|orderId|cryptogram
Refund: posId|branchId|merchantId|orderId|originalPaymentRequestId|cryptogrampay and refund perform signing. The lower-level signPayment and signRefund methods only return a signature; they do not initiate a payment.
Never log private keys, payer data, signatures or the saved financial payload. Logout clears the key but retains the payment journal needed for recovery.