Builder

class Builder(context: Context)

Builder for MidnightSdk.

Required: network, seed. Optional: accountIndex (default 0), provingMode (default LOCAL), proofServerUrl (default null → network's local-dev proof server).

Constructors

Link copied to clipboard
constructor(context: Context)

Functions

Link copied to clipboard
fun accountIndex(index: Int): <Error class: unknown class>

Set the HD wallet account index (default 0).

Link copied to clipboard
fun appStateBackupFactory(factory: (seed: ByteArray) -> AppStateCloudBackup): <Error class: unknown class>

Optional cross-device backup of host app state (≤2 KB). The factory is invoked once during build with the wallet seed (so the coordinator derives its seed-based encryption key — no per-backup biometric). The resulting AppStateCloudBackup is wired into the wallet for silent automatic backup/restore. Omit it (default) and app-state backup is absent. Sibling of dustCloudBackupFactory.

Link copied to clipboard

Build the SDK. This is a blocking operation on first launch:

Link copied to clipboard
fun dustCloudBackupFactory(factory: (address: String, dustSeed: ByteArray) -> DustCloudBackup): <Error class: unknown class>

Optional cross-device dust backup. The factory is invoked once during build with the derived address + dust seed (so the coordinator can derive its encryption key); the resulting DustCloudBackup is wired into both the dust-sync cold-start (restore) and the wallet (upload). Omit it (the default) and dust backup is simply absent.

Link copied to clipboard
fun dustRestoreGate(gate: suspend (RestoredAppState?) -> Unit): <Error class: unknown class>

Optional restore gate awaited ONCE before the first dust sync that finds no local checkpoint (a fresh install / new device / new network). The host's chance to obtain Drive consent so the cloud-checkpoint restore can succeed instead of the sync silently replaying from genesis. The SDK hands the gate the restored RestoredAppState (prefs + host payload, null when nothing is in the cloud) — the gate can fire during build, before the host holds any SDK handle, so it can't fetch that itself. Must resolve promptly (grant, decline, or nothing-to-do) and must NOT call back into wallet sync APIs (it runs inside the dust-sync critical section). Omit it (the default) and behavior is unchanged. Registered as a builder option — not a post-build property — because the proactive dust sync starts at build time and would otherwise race past the gate into genesis.

Link copied to clipboard
fun network(network: MidnightNetwork): <Error class: unknown class>

Set the Midnight network (PREPROD, PREVIEW, UNDEPLOYED).

Link copied to clipboard
fun proactiveDustSync(enabled: Boolean = true): <Error class: unknown class>

Keep dust pre-synced in the background (#235). When enabled, the SDK runs a live tip-advance dust subscription so a transaction never waits on a cold sync; progress is observable via MidnightWallet.syncStatus (and surfaced by the foreground-service Live-Update notification). Off by default — opt in for wallet-first apps. Delta only; the first cold sync is still O(chain) but now runs ahead of need.

Link copied to clipboard
fun proofServerUrl(url: String?): <Error class: unknown class>

Override the proof-server URL used when provingMode is REMOTE. Null (default) means "use the network's default proof-server URL" (NetworkConfig.forNetwork(network).proofServerUrl, which points at a local proof server on localhost:6300 for every network the SDK supports). Pass an explicit URL to point at a hosted prover.

Link copied to clipboard
fun provingMode(mode: <Error class: unknown class>): <Error class: unknown class>

Pick how transactions are proved. Defaults to ProvingMode.LOCAL — on-device proving with cached keys, no network round-trip per tx.

Link copied to clipboard
fun seed(seed: ByteArray): <Error class: unknown class>

Set the HD wallet seed (from BIP-39 mnemonic). Copied internally — caller should wipe.