Skip to content

Conversation

@ShahanaFarooqui
Copy link
Collaborator

@ShahanaFarooqui ShahanaFarooqui commented Feb 11, 2026

Rust → TypeScript Binding Options

Options to consider

1️⃣ Direct N-API with napi-rs

✅ Pros

  • Mature and production-ready
  • TypeScript definitions auto-generated
  • Excellent performance (native execution)
  • Actively maintained
  • Seamless Node.js integration

❌ Cons

  • Separate from UniFFI workflow (different binding system)
  • Requires maintaining separate binding definitions

2️⃣ WASM with wasm-bindgen (Browser-Focused)

✅ Pros

  • TypeScript definitions auto-generated
  • Works in browsers and Node.js
  • No native compilation required for end users

❌ Cons

  • Different runtime constraints (no threads, limited I/O)
  • Some gl-sdk dependencies are not WASM-compatible
  • Performance is good, but not native-level

High-Level Comparison

Screenshot from 2026-02-10 22-30-50

Attempted UniFFI (WASM Approach)

cargo build --release

cd ./libs/gl-sdk
npm install uniffi-bindgen-react-native --save-dev
mkdir -p test-bindings/ts
mkdir -p test-bindings/cpp

npx uniffi-bindgen-react-native generate wasm bindings   --library ../../target/release/libglsdk.so   --ts-dir test-bindings/ts   --cpp-dir test-bindings/cpp

🚨 Critical Compatibility Issue

  • Critical compatibility issue. The gl-sdk has dependencies that don't support WASM out of the box.
  • The gl-sdk cannot currently be compiled to WASM.
  • Lightning Network SDKs rely on cryptographic and system-level dependencies that require native code and are incompatible with the WASM sandbox.
  • Problematic dependencies include:
    • secp256k1-sys -- Requires native C compilation (not WASM-compatible)
    • getrandom -- Requires "js" feature flag at minimum
    • tokio -- Async runtime has WASM limitations
    • Additional Bitcoin/Lightning dependencies likely include native code

Conclusion

  • WASM is currently a showstopper for gl-sdk due to native cryptographic and system-level dependencies.
  • For Node.js environments, napi-rs is the practical and production-ready solution.

Next Steps (if we decide to add N-API bindings)

  • Generate N-API bindings for minimal targets (~99% coverage, no exotic architectures):
    • Linux (glibc): x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu
    • Linux (musl): x86_64-unknown-linux-musl
    • macOS: x86_64-apple-darwin, aarch64-apple-darwin
    • Windows: x86_64-pc-windows-msvc
  • Add GitHub Actions release workflow (matrix build for above targets)
  • Ensure all artifacts build successfully in CI
  • Enable npm publishing (via tagged release)

@ShahanaFarooqui ShahanaFarooqui marked this pull request as ready for review February 11, 2026 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant