ProvingKeyManager

class ProvingKeyManager(context: Context, apkStampOverride: () -> String?? = null)

Manages proving key download, caching, and version tracking for local ZK proving.

Proving keys are downloaded from Midnight's S3 once (~24MB total) and cached in app internal storage. The phone can then prove transactions offline.

Key locations match the SDK's WasmProver.makeDefaultKeyMaterialProvider():

  • zswap/{ver}/spend.prover (10.5 MB)

  • zswap/{ver}/output.prover (5.5 MB)

  • zswap/{ver}/sign.prover (2.7 MB)

  • dust/{ver}/spend.prover (2.1 MB)

  • bls_midnight_2p13 (1.5 MB)

  • Corresponding .verifier and .bzkir files

Constructors

Link copied to clipboard
constructor(context: Context, apkStampOverride: () -> String?? = null)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Directory where proving keys are cached on device.

Functions

Link copied to clipboard

Total size of cached keys in bytes.

Link copied to clipboard

Delete all cached proving keys.

Link copied to clipboard
fun contractKeysDir(contractName: String): File

Directory for a specific contract's proving keys. Keys are stored at: proving_keys/contracts/{contractName}/{circuit}.{prover,verifier,bzkir}

Link copied to clipboard
suspend fun downloadContractKeys(contractName: String, circuitNames: List<String>, baseUrl: String, onProgress: (Float) -> Unit = {}): Int

Download contract proving keys from a remote URL.

Link copied to clipboard
suspend fun downloadWalletKeys(onProgress: (Float) -> Unit = {})

Download all wallet proving keys from S3.

Link copied to clipboard
suspend fun ensureWalletKeysAvailable(onDownloadProgress: (Float) -> Unit = {}, logger: (String) -> Unit = {})

One-call wallet-key provisioning. Tries the dev shortcut first (installFromLocalTmp — adb-pushed files in /data/local/tmp/), then falls back to the S3 download (downloadWalletKeys) when the local-tmp pass didn't populate the BLS params + zswap/dust keys. After this returns, hasWalletKeys is true unless the download itself failed (in which case the underlying IOException propagates).

Link copied to clipboard

Whether BLS parameters are available (needed for all proving).

Link copied to clipboard
fun hasContractKeys(contractName: String, circuitNames: List<String>): Boolean

Whether all required circuit keys are cached for a contract.

Link copied to clipboard

Whether the prover can find circuit keys at the root keys directory.

Link copied to clipboard

Whether all wallet-required proving keys are cached and current version.

Link copied to clipboard
fun installCircuitKeysForProving(circuitNames: List<String>, keysSourceDir: File, zkirSourceDir: File, overwrite: Boolean = false)

Install circuit keys to the root keys directory for the prover.

Link copied to clipboard
fun installCircuitKeysFromAssets(assetDir: String = "keys", overwrite: Boolean = false)

Install a dApp's own contract circuit keys from the APK's bundled assets into the prover's keysDir, where the local prover resolves them.

Link copied to clipboard
fun installContractKeys(contractName: String, circuitNames: List<String>, keysSourceDir: File, zkirSourceDir: File, overwrite: Boolean = false)

Copy contract proving keys from a source directory into the cache.

Link copied to clipboard
fun installFromLocalTmp(localTmp: File = File("/data/local/tmp")): Boolean

Dev-only convenience: install proving keys from a local-tmp staging area pushed via adb push (the convention used by Kicks's build script, the SDK e2e test, and BBoard's canary). Looks at two well-known directories on the device:

Link copied to clipboard
fun removeContractKeys(contractName: String)

Remove all cached keys for a contract.