This guide is for the wallet-app developers. It shows, with the PowerAuth Mobile SDK, how the app builds the signed request, encrypts it and calls the Secure Keystore through the Wallet Integration Server. Terms are explained in the Glossary.

The keystore REST API is the target design; the endpoints are not implemented yet. The SDK calls below are taken from the PowerAuth Mobile SDK documentation and sources, and the snippets are illustrations, not tested code.

Prerequisites

The Flow of One Keystore Call

Request flow

  1. Unlock the vault and sign. The user enters the PIN or uses biometry once; the SDK unlocks the vault and signs the claims with every device key of the activation (one signature for a classical activation, two for a hybrid one), in a single call.
  2. Encrypt. The app gets an activation-scope encryptor and encrypts the signed request. The encryptor yields the request body (the EncryptedRequest) and the X-PowerAuth-Encryption header.
  3. Send. The app posts the body to the Wallet Integration Server, which forwards it unchanged.
  4. Decrypt. The app decrypts the response with the same encryptor and parses it.

Every call needs a new signed request (new jti, current iat) and a new encryption. Never resend an old body.

Vault Unlock and Signed Request

There is no separate vault call for the keystore: calculateJwsSignature unlocks the vault and signs in one step. The vault unlock is a network call: the SDK sends POST /pa/v4/vault/unlock to the Wallet Integration Server with a PowerAuth authentication code, and PowerAuth Server checks the PIN or biometry there. A wrong PIN fails the call before anything reaches the keystore, and PowerAuth Server counts it as a failed attempt; after the configured number of failed attempts the activation is blocked.

Each keystore call needs its own PowerAuthAuthentication object, because one object is used for one vault unlock only. The app may ask the user once and build a new object from the same PIN for every call of a flow (an issuance makes four keystore calls, see EUDI Wallet Flows); with biometry, every call shows the biometric prompt. Pass the key identifier DEVICE (Android) or .device (iOS) to sign with all device keys, and compact = false to get the JSON serialization (see Signed Request for the claims and rules). The typ must be sk-request+jwt.

The keystore requires an iat from the SDK’s synchronized time. The Android service returns milliseconds and iOS returns seconds as TimeInterval. Synchronize the time first if isTimeSynchronized is false.

Android (Kotlin)

val unitId = "2a7d9c14-5e0b-4c1e-9d0a-6f3b8e21c7a4"
val timeService = powerAuthSDK.timeSynchronizationService

val claims = JSONObject()
    .put("aud", "/v1/eudi/units/$unitId/wallet-instance-keys")
    .put("sub", unitId)
    .put("iat", timeService.currentTime / 1000)            // milliseconds to seconds
    .put("jti", randomBase64Url(16))                        // your helper: 16 random bytes, base64url without padding
    .put("request", JSONObject())                           // the request members of the endpoint
val claimsData = claims.toString().toByteArray(Charsets.UTF_8)

// PIN; for biometry use powerAuthSDK.authenticateUsingBiometrics(...) to get the authentication object
val authentication = PowerAuthAuthentication.possessionWithPassword("1234")

powerAuthSDK.calculateJwsSignature(context, authentication, claimsData, "sk-request+jwt", false,
    PowerAuthSignatureKeyId.DEVICE, object : IJwsSignatureListener {
        override fun onJwsSignatureSucceed(signedData: String, compactForm: Boolean) {
            // signedData is the JSON serialization of the signed request
        }
        override fun onJwsSignatureFailed(throwable: Throwable) { /* wrong PIN, canceled, ... */ }
    })

iOS (Swift)

let unitId = "2a7d9c14-5e0b-4c1e-9d0a-6f3b8e21c7a4"
let timeService = powerAuthSDK.timeSynchronizationService

let claims: [String: Any] = [
    "aud": "/v1/eudi/units/\(unitId)/wallet-instance-keys",
    "sub": unitId,
    "iat": Int(timeService.currentTime()),                  // seconds
    "jti": randomBase64Url(16),                             // your helper: 16 random bytes, base64url without padding
    "request": [String: Any]()                              // the request members of the endpoint
]
let claimsData = try JSONSerialization.data(withJSONObject: claims)

let auth = PowerAuthAuthentication.possessionWithPassword(password: "1234")
powerAuthSDK.calculateJwsSignature(authentication: auth, forData: claimsData, dataType: "sk-request+jwt",
                                   compact: false, withKey: .device) { jws, error in
    if let jws {
        // jws is the JSON serialization of the signed request
    } else {
        // authentication failed or canceled
    }
}

A wrong iat or a repeated jti is refused as 403 invalid_user_authorization. The Secure Vault functions (fetchSecureVaultKey) return a key-derivation key for the app’s own purposes; the keystore flows do not use them.

Encrypt, Send and Decrypt

Android (Kotlin)

powerAuthSDK.getEncryptorForActivationScope(object : IGetEncryptorListener {
    override fun onGetEncryptorSuccess(encryptor: CoreEncryptor) {
        val encrypted = encryptor.encryptRequest(signedData.toByteArray(Charsets.UTF_8))
        val body = encrypted.requestBody                    // the EncryptedRequest JSON
        val headers = encrypted.requestHeaders              // contains X-PowerAuth-Encryption (key, value)
        // POST body with all headers to the Wallet Integration Server ...
        // ... then, for a 2xx response:
        val response = encryptor.decryptResponse(CoreEncryptedResponse(responseBody))
    }
    override fun onGetEncryptorFailed(t: Throwable) { /* no activation, temporary key not available, ... */ }
})

On Android, getEncryptorForActivationScope takes only the listener.

iOS (Swift)

powerAuthSDK.encryptorForActivationScope { encryptor, error in
    guard let encryptor else { return }                     // report the error
    do {
        let encrypted = try encryptor.encryptRequest(Data(jws.utf8))
        var request = URLRequest(url: wallet.keystoreUrl(operation: "wallet-instance-keys"))   // your helper
        request.httpMethod = "POST"
        request.setValue("application/json", forHTTPHeaderField: "Content-Type")
        encrypted.requestHeaders.forEach { request.addValue($0.value, forHTTPHeaderField: $0.key) }
        request.httpBody = encrypted.requestBody
        // send the request; for a 2xx response:
        // let plain = try encryptor.decryptResponse(PowerAuthEncryptedResponse(responseBody: responseBody))
    } catch { /* report */ }
}

Error responses are application/problem+json and are not encrypted; do not try to decrypt them. A 403 on a fresh request usually means a wrong iat, an inactive activation or a reused jti; see Possible Error Codes. On 503, wait for Retry-After and build a new request.

EUDI Flows

The request members below go into the request claim. The full contract is in the EUDI API, and the order of the calls in EUDI Wallet Flows. Each call repeats the three steps above with its own aud.

Step Route (POST) request claim Result to keep
Create the WIA key /v1/eudi/units/{unitId}/wallet-instance-keys {} publicJwk, wrappedKey of the WIA key
WIA and signed PoP /v1/eudi/units/{unitId}/wallet-instance-attestations publicJwk, wrappedKey, walletVersion, unsignedPop wia and signedPop, used at once for the authorization server
Create credential keys /v1/eudi/units/{unitId}/credential-keys keyCount, cNonce, optional includeProofJwt, credentialIssuer, clientId keys[] (publicJwk, wrappedKey), keyAttestation, proofJwt
Sign a key-binding JWT /v1/eudi/units/{unitId}/key-binding-signatures items[] of wrappedKey and signingInput (SHA-256 of the KB-JWT signing input) signatures[], to build the KB-JWT

Notes:

What the App Builds Itself

The keystore signs, but it does not build the OAuth and OpenID4VP messages. The app builds these inputs:

The DPoP proofs for the authorization server and the issuer are signed with a key the app holds itself; they are not keystore calls.

Read the Wrapped User-Signing Keys

If the wallet uses user signing, the keystore creates the user-signing keys while the activation is created, and the Wallet Integration Server returns their wrapped keys in the customAttributes of the activation result. The PowerAuth SDK decrypts the activation response, so the app reads them from the result of createActivation and stores them at once: without them POST /v1/pa/units/{unitId}/signatures cannot be used. The attribute name (keystoreKeys below) and its layout are agreed with your backend team.

// Android: result is the CreateActivationResult of createActivation
val keys = result.customActivationAttributes?.get("keystoreKeys") as? List<*>   // items: {keyType, wrappedKey}
// iOS: result is the PowerAuthActivationResult of createActivation
let keys = result.customAttributes?["keystoreKeys"] as? [[String: Any]]   // items: {keyType, wrappedKey}

If the activation response contains the keystore keys, store them. If your backend is set up to return them and the attribute is missing, treat the activation as failed and remove it; the keys cannot be fetched later. The wrappedKey for ECDSA_P384 is always present, plus MLDSA_65 or MLDSA_87 for a hybrid activation. Persist the activation as usual (the commit happens on the server); the unit needs nothing more.

Storing Wrapped Keys

A wrapped key is an opaque string: store and send it unchanged and never parse it. It is useless without the device keys, but it is still tied to the credential, so keep it in encrypted app storage. To remove the activation, call removeActivationWithAuthentication (Android) or removeActivation(with:) (iOS) with the user’s authentication; the request goes through the Wallet Integration Server, which revokes the unit. Then delete the stored wrapped keys.