I am building the back-end of an iOS crypto wallet app using FFI bridge between flutter and rust. In doing so, I am required to mirror the external types onto the rust input file, or api.rs
when following the flutter_rust_bridge
official. Here is the tutorial I have been following.
OFFICIAL DOC: flutter_rust_bridge -> for using 'external types'
Issue: Some of the structs, such as PublicKey
, contain layers of nested structs or separately defined types which I assume all need to be mirrored as well. The crate containing these types is curve25519-dalek.
In order to fully mirror the PublicKey
, I need to re-export 2 private modules from the same crate. So far, I have been unsuccessful.
Here is the current error when running cargo check
from root of the flutter>>rust;
error[E0433]: failed to resolve: use of undeclared crate or module `backend`
error[E0603]: module `backend` is private
error[E0603]: module `field` is private
I went through the relevant modules locally, in .cargo/registry/src...
to try to make any necessary changes to data types visibility and by double-checking lib.rs
for pub mod field/backend
, but nothing has changed.
This is what I've written so far.
pub use curve25519_dalek::{
edwards::{EdwardsPoint},
ristretto::{CompressedRistretto, RistrettoPoint},
scalar::{Scalar},
backend::serial::u64::field::FieldElement51,
field::FieldElement,
};
pub use schnorrkel::{
keys::{
Keypair,
SecretKey,
PublicKey
},
points::{RistrettoBoth},
sign::{Signature},
};
// keypair
#[frb(mirror(Keypair))]
pub struct _Keypair {...}
// public key
#[frb(mirror(PublicKey))]
pub struct _PublicKey(pub (crate) RistrettoBoth);
...
#[frb(mirror(EdwardsPoint))]
pub struct _EdwardsPoint {
pub(crate) X: FieldElement,
pub(crate) Y: FieldElement,
pub(crate) Z: FieldElement,
pub(crate) T: FieldElement,
}
#[frb(mirror(FieldElement))]
pub type _FieldElement = backend::serial::u64::field::FieldElement51;
#[frb(mirror(FieldElement51))]
pub struct _FieldElement51(pub (crate) [u64; 5]);
Specifically I'd like advice on either or both;
- Would I be right to say that all nested data types need to be mirrored as well for FFI?
- Are there any other ways to approach the task of making modules public? What am I currently doing wrong?