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.
- FfiAsset
Facts - The verified facts one applied entry contributes, flattened for a catalog upsert.
- FfiAsset
Metadata - The decrypted sidecar’s facts, flattened for a catalog upsert.
- FfiBlob
Manifest - FFI mirror of
BlobManifest— an asset’s blobs by role. - FfiBlob
Ref - FFI mirror of
BlobRef— a blob’s content address and role. - FfiCapsule
Client - The unauthenticated entry point over the SDK’s auth + upload endpoints. Turns
credentials into an
FfiSessionhandle; the protocol pin and endpoints are captured once here and reused by every session this client mints. - FfiClass
Deadline - One class and the instant its local notification should be armed for.
- FfiClient
Build - 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+commitclient_versionevery manifest carries — so a defect in a shipped app build is traceable across the assets it produced. - FfiEmbedded
Preview - A RAW original’s embedded JPEG, as
embedded_previewreads it. - FfiEscrow
Stored - FFI mirror of
EscrowStored— whatFfiSession::escrow_putdid. - FfiFeed
Drain - A sync that drained the feed to its head, the evidence
FfiWorkspace::expired_trashneeds before it judges a retention deadline. - FfiFeed
Entry - FFI mirror of
FeedEntry— one decoded sync feed entry. Ids/manifest/metadata cross as opaque bytes. - FfiHistory
Sources - FFI mirror of
HistorySources: the blobs adopting an asset from its fetched history needs beyond its records. - FfiLocal
Holdings - What this device holds for the asset. Flat, like
FfiNotifyInput: an embedded preview is present when both of its dimensions are. - FfiManifest
Envelope - FFI mirror of
ManifestEnvelope— the server-visible envelope fields the import pipeline builds and signs; opaque to this layer, carried verbatim. - FfiNotify
Input - The device-held state the predicate decides from, flattened for the bindings.
- FfiPath
Snapshot - One sample of the path as the app’s OS listeners report it.
- FfiPurge
Outcome - What a
FfiWorkspace::purge_assetdid. - FfiPush
Report - What
FfiSession::push_assetdid — FFI mirror ofAssetPushReport. - FfiPushed
Blob - How one blob of a pushed asset resolved — FFI mirror of
PushedBlob. - FfiRegion
- One live region of an asset and its labels.
- FfiRender
Request - A surface’s request: its intent and its size in device pixels when the view opened.
- FfiRender
Step - 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. - FfiStack
Member - Where one live asset sits in its stack, read from its signed
stack_membershipregister. - FfiStamped
Transfer Event - A transfer event and when it arrived: milliseconds since the subscription opened, on a monotonic clock.
- FfiSync
Entry - One remote feed entry to apply, as a sync feed delivers it.
- FfiSync
Head - One remote feed entry whose original is on disk rather than in hand: an
FfiSyncEntrywithout itsoriginal_ciphertext, whichFfiWorkspace::apply_sync_entry_from_fileandFfiWorkspace::open_synced_originalread from the fileFfiSession::fetch_blob_to_pathproduced, in memory bounded by one STREAM chunk whatever the original’s size. - FfiSync
Page - FFI mirror of
SyncPage— a decoded page plus the opaque cursor for the next pull (the client persistsnext_cursorand passes it back to advance). - FfiTransfer
Subscription - A live subscription to a session’s transfer events: every step published after it opened.
- FfiTrash
Entry - One asset in the trash, as its latest signed
deleterecord describes it. - FfiUpload
Blob - One transferable blob of a sealed asset, paired with the
POST /uploadbody that declares it. Handrequestandbytesstraight toFfiSession::upload— this record exists so an app never has to assemble a manifest envelope itself. - FfiUpload
Request - FFI mirror of
CreateUploadRequest— thePOST /uploadbody. - FfiUpload
Status - FFI mirror of
HeadInfo— theHEAD /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§
- FfiAlert
Class - Every alert class, flattened for the bindings. A closed enum on both sides of the boundary.
- FfiAlert
Severity - How prominently a client presents an alert. Neither variant gates anything — no alert blocks sync, unlock, upload, or any critical flow.
- FfiBlob
Role - FFI mirror of
BlobRole(snake_case on the wire, closed enum). - FfiChange
Kind - FFI mirror of
ChangeKind. - FfiCull
Flag - The trinary culling flag, mirrored from core’s
CullFlag.Neutralis the never-flagged state and what an unwritten register reads as. - FfiDevice
Tier - Device hardware tier, selecting the Argon2id cost at wrap time. Mirrors core’s
DeviceTierin 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.*catalogcode(when one applies — clients localize it) and the Englishdetail(stays English), mirroring the SDK’s{ error, code }contract so foreign apps switch on the code, never a bare HTTP status. - FfiHardware
Signer Error - Failure surfaced by a foreign
FfiHardwareSigner. Mirrorscapsule-core’sHardwareSignerErrorvariant for variant — it is the same contract, declared in thecapsule_sdknamespace because core’s own type carries no uniffi derive. - FfiLabel
Refusal - Why a label or region edit was refused (
FfiError::Label). Nothing was written. - FfiLabel
Target - 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.
- FfiLifecycle
OpOutcome - What became of one lifecycle op.
- FfiLogin
Outcome - What a password login answered with, across the FFI.
- FfiNext
Step - How to obtain the next rung.
- FfiOpened
Original - How
FfiWorkspace::open_synced_originalresolved. OnlyOpenedleaves anything at the destination path. - FfiPath
Cost - FFI mirror of
PathCost. - FfiPath
Interface - FFI mirror of
PathInterface. - FfiPower
State - FFI mirror of
PowerState. - FfiPush
Asset Result - How one asset of an
FfiSession::push_assetscall ended. - FfiQuota
Advisory - The quota state, as
GET /v1/quotareports it. - FfiRegion
Shape - A region’s outline, in coordinates normalized to
[0, 1]over the original’s display orientation. Mirrorscapsule_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.
- FfiRetry
Reason - Why an upload chunk is sent again. Mirrors
RetryReasonvariant for variant. - FfiRung
Source - Where a shown rung’s pixels come from.
- FfiStack
Cull State - A stack’s derived cull state, by the doc’s precedence
all-rejected → any-pick → else mixed. - FfiSync
Apply Outcome - 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.
- FfiThermal
State - FFI mirror of
ThermalState. - FfiTransfer
Event - One step of an upload, a custody check or a ranged fetch. Mirrors
TransferEventvariant for variant and field for field;blobis the content address (lowercase hex) and offsets and lengths are bytes of ciphertext. - FfiTransfer
Feed Item - What one pull of a subscription yields.
- FfiTrash
Refusal - Why a trash verb was refused (
FfiError::Trash). Nothing was written. - FfiUpload
Outcome - FFI mirror of
UploadOutcome— how a full upload resolved. - FfiVerify
Outcome - The verification verdict, flattened for FFI (reasons as stable reason-code strings).
Constants§
- MAX_
METADATA_ BLOB_ BYTES - The most
FfiSession::fetch_metadata_blobreads 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_opdecodes. 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§
- FfiHardware
KeyAgreement - 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 ofFfiHardwareSigner, and this namespace’s declaration ofcapsule-core’sHardwareKeyAgreementcontract. - FfiHardware
Signer - 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) isext. - evaluate_
alerts - Every alert that is true at
now, in delivery order. - next_
alert_ deadline - The earliest instant in
pre_arm_deadlines(RFC 3339), orNonewhen 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
hardwareunderkey_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. Returnstrueiff 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/AlarmManageralarms from. - render_
step - One step of the render ladder (
crate::fetch::render_step): what to show now and what to obtain next.shownis what the surface shows,Nonewhen it shows nothing yet or is falling back below what it showed;fetchableis 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) andhistory, the records before it thatFfiSession::fetch_provenance_historyreturned. - synced_
retention_ closed - Whether a tombstone’s retention window had closed at
changed_at(RFC 3339, a feed entry’s own):manifest_cboris adeleterecord andchanged_atis at or after theretention_untilsigned into it.