enclavia-dart

Dart bindings for the enclavia client SDK: an attested, end-to-end-encrypted Noise tunnel to an enclave. The repo contains the sources for generating UniFFI-based bindings (lib/enclavia_ffi.dart) and the libenclavia_dart_ffi native library, so Dart and Flutter apps can connect to an enclave, verify its attestation, and send HTTP requests through the encrypted channel.

Mirrors enclavia-wasm's surface (connect + Client.fetch) for native mobile/desktop targets, and follows the same model bdk-dart uses for BDK: a thin per-language wrapper crate (native/) re-exporting a shared UniFFI interface crate (here, enclavia-ffi), with uniffi-dart generating the Dart bindings. The same enclavia-ffi crate is the intended shared core for future Swift and Kotlin bindings.

Repository layout

Path Purpose
native/ Rust sources and uniffi-dart build scripts/configs wrapping enclavia-ffi, used by the Dart build hook.
lib/ Dart bindings (enclavia_ffi.dart) generated by UniFFI-Dart, plus the enclavia_dart.dart package entrypoint.
example/ Standalone Dart example connecting to a running enclave.
scripts/generate_bindings.sh Helper used to rebuild the native library and regenerate the Dart bindings.

Prerequisites

To use this package you need:

  • Dart SDK >= 3.10 (see pubspec.yaml).
  • Rust toolchain with cargo. Install via rustup, or enter this repo's nix develop shell.
  • Flutter SDK if you plan to use the package in a Flutter app.

Add to your project

dependencies:
  enclavia_dart:
    git:
      url: https://github.com/EnclaviaIO/enclavia.git
      path: enclavia-dart
      ref: master # or a specific tag

Import the package entrypoint:

import 'package:enclavia_dart/enclavia_dart.dart';

Usage

final client = await Client.connect(
  url: 'wss://<id>.enclaves.beta.enclavia.io',
  pcrs: Pcrs(pcr0: pcr0Bytes, pcr1: pcr1Bytes, pcr2: pcr2Bytes),
  options: ConnectOptions(debugMode: false, trustUpgrades: null),
);
final response = await client.fetch(method: 'GET', path: '/health', options: null);
print('${response.status}: ${utf8.decode(response.body)}');

See example/main.dart for a runnable version (reads the endpoint and PCRs from ENCLAVIA_URL / ENCLAVIA_PCR0/1/2 env vars):

dart run example/main.dart

If you have the Rust toolchain installed, the native library is built automatically by Dart's Native Assets system on dart pub get / dart run / flutter run. As a user of the package, you don't need to build the native library or bindings yourself — only if you're modifying enclavia-ffi or the Dart binding generation, see development below. The first build can take a few minutes (subsequent builds are cached).

Development

Generating bindings

  1. Modify enclavia-ffi/src/lib.rs (the shared interface) or the Rust sources/config in native/ as needed.

  2. Run the bindings generator script:

    bash ./scripts/generate_bindings.sh
    

    This regenerates lib/enclavia_ffi.dart, which is checked into git (like bdk-dart's lib/bdk.dart) so pub.dev/git consumers never need a Rust toolchain to install the package — only to build the native library, which Native Assets handles for them.

Publishing to pub.dev (maintainers)

In-repo, native/Cargo.toml depends on enclavia-ffi by path so that generate_bindings.sh, CI's Dart smoke test, and local development all build against the working tree. A pub.dev archive only contains the enclavia-dart/ directory, so that path cannot resolve for consumers: at publish time (and only then), point the dependency at the release tag instead.

  1. Merge the release version bump and push the enclavia-vX.Y.Z tag.

  2. In native/Cargo.toml, temporarily replace

    enclavia-ffi = { path = "../../enclavia-ffi" }
    

    with

    enclavia-ffi = { git = "https://github.com/EnclaviaIO/enclavia", tag = "enclavia-vX.Y.Z" }
    

    and run cargo update --workspace in native/ to refresh its Cargo.lock.

  3. Run dart pub publish --dry-run from enclavia-dart/. The "checked-in files are modified in git" note refers to the two files above and is expected; there must be no other issues beyond analyzer warnings inside the generated lib/enclavia_ffi.dart.

  4. Run dart pub publish, then discard the local dependency flip (git checkout -- native/Cargo.toml native/Cargo.lock).

License

The Rust crates and generated bindings are dual-licensed under MIT or Apache 2.0.

Libraries

enclavia_dart
Package-root export for enclavia_dart.
enclavia_ffi