-
Notifications
You must be signed in to change notification settings - Fork 37
feat: Add noosphere
crate-based Swift package
#131
Conversation
BREAKING CHANGE: The `noosphere-api` Client now holds an owned key instead of a reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work on wrangling FFIs in noosphere!
Note: the FFI'd opaque structs are not namespaced: SphereReceipt_t * noosphere_create_sphere (
NoosphereContext_t * * noosphere,
char const * owner_key_name); While functions are ( Also, for the C++ export, consider a namespace e.g. |
This change introduces a counterpart Swift package for the
noosphere
crate, in service of imminent integration between our iOS app and the Noosphere body of libraries. Thenoosphere
crate compiles for both web and native targets. On native targets, it has an auxiliary FFI interface making it suitable for use from any language that can talk C ABI (such as Swift). The change also includes anIndexedDB
+WebCrypto
key storage backend, to ensure parity in the API on web.At this time, it's capabilities are limited, but the intention is for us to relocate most of the substantive implementation of
noosphere-cli
's commands under this crate, and re-implementnoosphere-cli
commands in terms ofnoosphere
functionality.Currently supported capabilities include: creating a key, and initializing a sphere.
Note that the
Package.swift
currently refers to a hand-uploaded artifact in a temporary Github repo that I intend to delete. This is necessary until we get a release of this library that uploads an artifact to an official Github release on the Noosphere repo, which can happen about as soon as this PR can be merged. At that time, we will update thePackage.swift
by hand to point to the new release.I considered automating the
Package.swift
changes, but we can figure out if that would be useful down the road as we collectively hammer out our XCode workflow.A word on FFI...
In Rust, it is very common practice to leverage macros to automatically generate bindings to other languages. A common approach for C ABI-speaking languages is to use a wonderful crate called
cbindgen
. The advantage of this approach is that it reduces a lot of code duplication. Instead of maintaining a C header file that matches, you can lean on codegen to produce the header for you.However, one inescapable problem with FFI in Rust is that when you share access to memory with another language, you lose most of Rust's memory safety guarantees. So, FFI boundaries are almost always written in terms of
unsafe
Rust.To partially alleviate this condition, we are using an alternative to
cbindgen
calledsafer-ffi
.safer-ffi
enables us to express our FFI interface in terms of safe Rust (with some constraints on what can be expressed), and moves all of theunsafe
parts into codegen. This strikes an appealing balance from a safety perspective: code that is maintained by humans is able to be checked for memory safety, and code that isunsafe
can (in theory) be patched when there is a bug. It may turn out thatsafer-ffi
is burdensome, but for now I would like us to give it a shot.Here is the C header that is produced by
safer-ffi
as of this change:BREAKING CHANGE: The
noosphere-api
Client now holds an owned key instead of a reference.