Skip to main content

Module ffi

Module ffi 

Source
Expand description

uniffi surface over the SDK’s user-flow primitives (login → upload → status → sync) for Swift/Kotlin/Linux consumers (ffi feature). A thin, async-capable wrapper over auth, upload, and sync; tokens never cross the boundary (the session-handle pattern). See ffi. uniffi bindings: an async-capable wrapper over the SDK’s user-flow primitives, so iOS/macOS (Swift), Android (Kotlin), and Linux consumers call one SDK instead of reimplementing login/upload/sync flows.

§Surface

FfiCapsuleClient is the unauthenticated entry point (auth + upload endpoints and the protocol pin). FfiCapsuleClient::login/register return an FfiSession handle — an opaque object that owns the token store internally. Every subsequent call (upload, push_asset, push_assets, upload_status, fetch_blob_to_path, apply_lifecycle_op, deliver_purge, deliver_lifecycle_at_hash, sync_pull, logout) rides that handle, and transfer_events subscribes to the step-by-step progress of the uploads and fetches it drives. Tokens never cross the FFI boundary raw: the SDK session store injects and auto-refreshes the bearer behind the handle, so foreign code never sees access/refresh token material.

§Async

The flows are inherently networked, so the exported methods are async fn under #[uniffi::export(async_runtime = "tokio")]: uniffi drives the returned future on the tokio runtime reqwest/tonic require, and foreign callers see idiomatic suspend (Kotlin) / async (Swift) functions. The Rust methods stay plain async fn, so the in-crate smoke exercises them with a direct .await.

§Types

Following capsule-core’s FFI philosophy, the surface is deliberately minimal: ids/hashes/paths cross as String, blobs/manifests/cursors as bytes, and the rich SDK enums/records are flattened into Ffi* mirrors so the Rust API stays free to evolve behind the boundary. Errors carry the stable error.* catalog code (which clients localize) plus the English detail (which stays English) — mirroring the server’s { error, code } contract. The field is detail, not message, because uniffi turns each variant into a Kotlin Throwable subclass whose own message property a val message field would clash with.

Structs§

FfiAlbum
One album this workspace holds key material for.
FfiAlert
One alert that is true at an instant.
FfiAssetFacts
The verified facts one applied entry contributes, flattened for a catalog upsert.
FfiAssetMetadata
The decrypted sidecar’s facts, flattened for a catalog upsert.
FfiBlobManifest
FFI mirror of BlobManifest — an asset’s blobs by role.
FfiBlobRef
FFI mirror of BlobRef — a blob’s content address and role.
FfiCapsuleClient
The unauthenticated entry point over the SDK’s auth + upload endpoints. Turns credentials into an FfiSession handle; the protocol pin and endpoints are captured once here and reused by every session this client mints.
FfiClassDeadline
One class and the instant its local notification should be armed for.
FfiClientBuild
A foreign client’s self-reported build identity: its product id and own semver. The git commit + dirty flag come from the core this app links, together composing the client_id/semver+commit client_version every manifest carries — so a defect in a shipped app build is traceable across the assets it produced.
FfiEmbeddedPreview
A RAW original’s embedded JPEG, as embedded_preview reads it.
FfiEscrowStored
FFI mirror of EscrowStored — what FfiSession::escrow_put did.
FfiFeedDrain
A sync that drained the feed to its head, the evidence FfiWorkspace::expired_trash needs before it judges a retention deadline.
FfiFeedEntry
FFI mirror of FeedEntry — one decoded sync feed entry. Ids/manifest/metadata cross as opaque bytes.
FfiHistorySources
FFI mirror of HistorySources: the blobs adopting an asset from its fetched history needs beyond its records.
FfiLocalHoldings
What this device holds for the asset. Flat, like FfiNotifyInput: an embedded preview is present when both of its dimensions are.
FfiManifestEnvelope
FFI mirror of ManifestEnvelope — the server-visible envelope fields the import pipeline builds and signs; opaque to this layer, carried verbatim.
FfiNotifyInput
The device-held state the predicate decides from, flattened for the bindings.
FfiPathSnapshot
One sample of the path as the app’s OS listeners report it.
FfiPurgeOutcome
What a FfiWorkspace::purge_asset did.
FfiPushReport
What FfiSession::push_asset did — FFI mirror of AssetPushReport.
FfiPushedBlob
How one blob of a pushed asset resolved — FFI mirror of PushedBlob.
FfiRegion
One live region of an asset and its labels.
FfiRenderRequest
A surface’s request: its intent and its size in device pixels when the view opened.
FfiRenderStep
The answer to one render_step.
FfiRendition
What a surface shows: a rung and its source. The caller keeps the last one and passes it back as shown.
FfiSession
An authenticated session handle. Owns the SDK token store internally (auto pre-flight refresh, single-flight, 401-retry-once); no token ever crosses the FFI boundary. Every flow rides this handle.
FfiStackMember
Where one live asset sits in its stack, read from its signed stack_membership register.
FfiStampedTransferEvent
A transfer event and when it arrived: milliseconds since the subscription opened, on a monotonic clock.
FfiSyncEntry
One remote feed entry to apply, as a sync feed delivers it.
FfiSyncHead
One remote feed entry whose original is on disk rather than in hand: an FfiSyncEntry without its original_ciphertext, which FfiWorkspace::apply_sync_entry_from_file and FfiWorkspace::open_synced_original read from the file FfiSession::fetch_blob_to_path produced, in memory bounded by one STREAM chunk whatever the original’s size.
FfiSyncPage
FFI mirror of SyncPage — a decoded page plus the opaque cursor for the next pull (the client persists next_cursor and passes it back to advance).
FfiTransferSubscription
A live subscription to a session’s transfer events: every step published after it opened.
FfiTrashEntry
One asset in the trash, as its latest signed delete record describes it.
FfiUploadBlob
One transferable blob of a sealed asset, paired with the POST /upload body that declares it. Hand request and bytes straight to FfiSession::upload — this record exists so an app never has to assemble a manifest envelope itself.
FfiUploadRequest
FFI mirror of CreateUploadRequest — the POST /upload body.
FfiUploadStatus
FFI mirror of HeadInfo — the HEAD /upload/{id} resumption/status primitive.
FfiWorkspace
A Capsule workspace, callable from Swift/Kotlin: the durable library at a filesystem root plus everything an app does with it.

Enums§

FfiAlertClass
Every alert class, flattened for the bindings. A closed enum on both sides of the boundary.
FfiAlertSeverity
How prominently a client presents an alert. Neither variant gates anything — no alert blocks sync, unlock, upload, or any critical flow.
FfiBlobRole
FFI mirror of BlobRole (snake_case on the wire, closed enum).
FfiChangeKind
FFI mirror of ChangeKind.
FfiCullFlag
The trinary culling flag, mirrored from core’s CullFlag. Neutral is the never-flagged state and what an unwritten register reads as.
FfiDeviceTier
Device hardware tier, selecting the Argon2id cost at wrap time. Mirrors core’s DeviceTier in this namespace (see the module docs on why it is not shared).
FfiError
Every failure the FFI flows can surface, flattened by originating layer. Each variant carries the stable error.* catalog code (when one applies — clients localize it) and the English detail (stays English), mirroring the SDK’s { error, code } contract so foreign apps switch on the code, never a bare HTTP status.
FfiHardwareSignerError
Failure surfaced by a foreign FfiHardwareSigner. Mirrors capsule-core’s HardwareSignerError variant for variant — it is the same contract, declared in the capsule_sdk namespace because core’s own type carries no uniffi derive.
FfiLabelRefusal
Why a label or region edit was refused (FfiError::Label). Nothing was written.
FfiLabelTarget
What a label attaches to beyond the asset itself, whose own labels are its user tags. The label rule is the same at every level.
FfiLifecycleOpOutcome
What became of one lifecycle op.
FfiLoginOutcome
What a password login answered with, across the FFI.
FfiNextStep
How to obtain the next rung.
FfiOpenedOriginal
How FfiWorkspace::open_synced_original resolved. Only Opened leaves anything at the destination path.
FfiPathCost
FFI mirror of PathCost.
FfiPathInterface
FFI mirror of PathInterface.
FfiPowerState
FFI mirror of PowerState.
FfiPushAssetResult
How one asset of an FfiSession::push_assets call ended.
FfiQuotaAdvisory
The quota state, as GET /v1/quota reports it.
FfiRegionShape
A region’s outline, in coordinates normalized to [0, 1] over the original’s display orientation. Mirrors capsule_core::sidecar::RegionShape, single precision included, so a shape that validates on one side validates on the other.
FfiRepresentation
A rung of the ladder, cheapest first.
FfiRetryReason
Why an upload chunk is sent again. Mirrors RetryReason variant for variant.
FfiRungSource
Where a shown rung’s pixels come from.
FfiStackCullState
A stack’s derived cull state, by the doc’s precedence all-rejected → any-pick → else mixed.
FfiSyncApplyOutcome
How applying one remote entry resolved — the three verdicts the client validation duties permit. There is no “ignored” case: a failure is always a named quarantine or a hold.
FfiThermalState
FFI mirror of ThermalState.
FfiTransferEvent
One step of an upload, a custody check or a ranged fetch. Mirrors TransferEvent variant for variant and field for field; blob is the content address (lowercase hex) and offsets and lengths are bytes of ciphertext.
FfiTransferFeedItem
What one pull of a subscription yields.
FfiTrashRefusal
Why a trash verb was refused (FfiError::Trash). Nothing was written.
FfiUploadOutcome
FFI mirror of UploadOutcome — how a full upload resolved.
FfiVerifyOutcome
The verification verdict, flattened for FFI (reasons as stable reason-code strings).

Constants§

MAX_METADATA_BLOB_BYTES
The most FfiSession::fetch_metadata_blob reads of a metadata blob whose size the feed does not list (16 MiB, the upload protocol’s largest chunk), the bound the CLI’s restore reads one under. A sealed sidecar is a few KiB; the cap only stops a server that keeps answering full windows from growing the buffer without bound.
MAX_OP_RECORD_BYTES
The largest record FfiSession::apply_lifecycle_op decodes. A lifecycle record is one signed manifest with its chain position, a few kilobytes even under hybrid signatures; this leaves an order of magnitude of room and refuses anything that could only be an attack on the decoder.

Traits§

FfiHardwareKeyAgreement
The per-platform key-agreement element (Secure Enclave P256.KeyAgreement, StrongBox ECDH, TPM 2.0 ECDH), implemented by native Swift/Kotlin over the uniffi foreign-trait boundary — the ECDH analogue of FfiHardwareSigner, and this namespace’s declaration of capsule-core’s HardwareKeyAgreement contract.
FfiHardwareSigner
The per-platform secure element (Secure Enclave, StrongBox, TPM), implemented by native Swift/Kotlin over the uniffi foreign-trait boundary.

Functions§

embedded_preview
Read the embedded preview of the original at original_path, whose extension (without the dot) is ext.
evaluate_alerts
Every alert that is true at now, in delivery order.
next_alert_deadline
The earliest instant in pre_arm_deadlines (RFC 3339), or None when there is nothing to arm.
p256_hardware_dek_round_trip
Smoke the hardware-bound P-256 device encryption key across the FFI seam: enroll a key-agreement key in hardware under key_alias, publish the hybrid public key, encapsulate a fresh shared secret to it in software (the sender side), then decapsulate through the element’s ECDH. Returns true iff the two secrets match — proving the element’s ECDH composes into the hybrid KEM without the private scalar leaving hardware. ml_seed (32 bytes) is the software-sealed ML-KEM-768 half.
pre_arm_deadlines
The instant to arm a local notification for, per class — the call an app schedules its UNCalendarNotificationTrigger / AlarmManager alarms from.
render_step
One step of the render ladder (crate::fetch::render_step): what to show now and what to obtain next. shown is what the surface shows, None when it shows nothing yet or is falling back below what it showed; fetchable is what the server lists for the asset.
synced_history_sources
Name what adopting an asset from its history fetches: the live metadata blob and the original, read off the asset’s latest record manifest_cbor (a feed entry’s) and history, the records before it that FfiSession::fetch_provenance_history returned.
synced_retention_closed
Whether a tombstone’s retention window had closed at changed_at (RFC 3339, a feed entry’s own): manifest_cbor is a delete record and changed_at is at or after the retention_until signed into it.