fedimint-web-sdk icon indicating copy to clipboard operation
fedimint-web-sdk copied to clipboard

Make SDK work with React Native

Open elsirion opened this issue 1 year ago • 8 comments

@alexlwn123 can you add some context please?

1Msat bounty once scoped out.

elsirion avatar Oct 21 '24 12:10 elsirion

Make the Fedimint Web SDK Work with React Native

Scope overview: Enable the fedimint-client SDK to function within React Native environments, sharing library code with the existing web SDK.

Background

Our current SDK includes a WebAssembly (WASM) bundle that exposes the Rust-based fedimint-client to web applications. This setup allows web environments to interact seamlessly with the fedimint client.

However, React Native—a popular framework for building native/mobile apps using React—cannot directly leverage the existing WASM bundle due to environment differences between web and native mobile platforms.

Objective

  • Build React Native Compatibility:
  • Utilize UniFFI to generate bindings for the fedimint-client, making it compatible with React Native applications on both iOS and Android platforms.
  • Architect Shared Library Code:
  • Structure the React Native package to share as much library code as possible with the existing web SDK, minimizing code duplication and easing future maintenance.

Scope of Work

1. UniFFI Bindings for React Native

  • Generate UniFFI Bindings:
  • Configure the fedimint-client Rust codebase to produce UniFFI bindings suitable for React Native.
  • Ensure all necessary functionalities are exposed through these bindings.
  • Address any platform-specific issues on iOS and Android, ensuring smooth operation across devices.

2. Architecting Shared Library Code

  • Implement a modular architecture that allows both SDKs to import shared code without conflicts.

3. Testing and Validation

  • Ensure tests run successfully on both iOS and Android platforms.
  • (Optional but Preferred) Develop a sample React Native app demonstrating the SDK’s capabilities.

Deliverables

  • React Native Compatible SDK: A fully functional React Native package of the fedimint-client.
  • Sample App (Optional): A demo React Native application showcasing the SDK in action.

Acceptance Criteria

  • The React Native SDK must support all features currently available in the web SDK.
  • The SDK should work on both iOS and Android devices.
  • Shared code must be cleanly abstracted with no unnecessary duplication.

Additional Information

  • Coordinate with the maintainers of the existing web SDK (@alexlwn123) to ensure compatibility.

Challenges to Anticipate

  • Handling differences in threading models between Rust and React Native.
  • Managing asynchronous operations and callbacks across the FFI boundary.

References:

Note: This bounty aims to expand our SDK’s reach to mobile platforms via React Native, promoting broader adoption and community engagement. Your contribution will play a crucial role in achieving this goal.

alexlwn123 avatar Oct 21 '24 14:10 alexlwn123

@maan2003 take a look

alexlwn123 avatar Oct 21 '24 14:10 alexlwn123

fedimint react native is not going to be fun

we have to bundle rocksdb, and doing it as a library is not great :/ Maybe we can just force nix on all developers. But, forcing it for existing wallets is not great.

maan2003 avatar Nov 05 '24 13:11 maan2003

sad... any way around using rocks? Can we get a lighter-weight version of the DB with similar guarantees?

alexlwn123 avatar Nov 06 '24 10:11 alexlwn123

we have to bundle rocksdb, and doing it as a library is not great :/

Is that a problem if we just leave it to the rust RocksDB crate? That is statically linking by default anyway, right? We only do dynamic linking because it avoids recompiling it all the time.

elsirion avatar Nov 06 '24 12:11 elsirion

yea that sounds like the way to go

maan2003 avatar Nov 06 '24 12:11 maan2003

Hi all, following up on this issue after our discussion with @alexlwn123 and @maan2003,
We (Minmo) would like to contribute React Native support for Fedimint web-sdk by helping build a UniFFI-based client and a corresponding React Native SDK package.

Proposal

1. New Client Module (Rust)

  • Create fedimint-client-uniffi (parallel to fedimint-client-wasm).
  • Use UniFFI to generate Swift/Kotlin bindings from Rust.
  • This replaces the current WASM dependency in RN environments with first-class mobile bindings.
  • Acts as the foundation for React Native integration.

2. New React Native Package (Web SDK Monorepo)

  • Add @fedimint/react-native alongside @fedimint/core-web and @fedimint/react.
  • Responsibilities:
    • JS/TS wrappers for UniFFI bindings
    • Turbo Module glue to expose bindings to RN
    • Optional React hooks (similar to @fedimint/react) for balances, federation membership, recovery
    • Example RN app under examples/react-native to validate integration

Initial Function Set

We’ll identify the core functions required by a wallet and start by binding those to validate the pipeline end-to-end (Rust -> UniFFI -> Swift/Kotlin -> Turbo Module -> RN JS).
Proposed initial functions include:

  • joinFederation(federationId, inviteCode)
  • getBalance()
  • sendEcash(amount) / receiveEcash(token)

These cover federation onboarding, balance checks, and basic transfers.

Benefits

  • Aligns mobile with web:
    • fedimint-client-wasm -> @fedimint/core-web / @fedimint/react
    • fedimint-client-uniffi -> @fedimint/react-native
  • Avoids WASM/Worker issues in RN by using native bindings
  • Provides a clear entry point for RN developers
  • Strengthens Fedimint’s cross-platform developer story

Next Steps / Actionables

  1. Confirm with maintainers that this approach (fedimint-client-uniffi + @fedimint/react-native) aligns with project goals.
  2. Define .udl file(s) for the initial wallet functions listed above.
  3. Prototype UniFFI bindings for Swift/Kotlin.
  4. Set up @fedimint/react-native package with Turbo Module integration.
  5. Build an example RN app under examples/react-native to validate end-to-end usage.

We’re happy to take the lead on prototyping this and contributing upstream. Does this direction align with the Fedimint team’s expectations?

tobynwuba avatar Sep 24 '25 07:09 tobynwuba

@tobynwuba

Define .udl file(s) for the initial wallet functions listed above.

the new way is to use #[uniffi::export] in rust files instead of using udl

Prototype UniFFI bindings for Swift/Kotlin.

you can use uniffi-bindgen-react-native and skip the swift/kotlin step

maan2003 avatar Sep 24 '25 07:09 maan2003