Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Add a light client code that compiles in the browser #2416

@tomaka

Description

@tomaka

This is a long term issue that I'm opening in order to keep track of PRs moving towards this direction.

We can't directly compile node for wasm32-unknown-unknown. Instead, we should create a new library (named for example substrate-light-wasm) that exposes an API usable from JavaScript, thanks to wasm-bindgen.

Once that crate exists, we can use wasm-pack to generate .js and .wasm files from substrate-light-wasm. The .js can then be used from regular JavaScript code.

Some challenges include:

  • We can't use TCP/IP. Libp2p already provides a wasm-ext transport that can be used to "import" a transport from the JavaScript world, such as WebSockets.
  • The RPC needs either to be disabled, or be replaced with something that compiles for the browser.
  • The telemetry needs either be disabled, or be replaced with something that compiles for the browser. I have a WIP branch that replaces the telemetry with libp2p.
  • We need to remove background threads, and have a fall-back for background tasks when tokio isn't available.
  • The tokio dependencies need to be replaced with dependencies to their sub-crates: tokio-io, tokio-codec, etc.
  • ring and rust-crypto don't compile for WASM. As far as I know, only diffie-hellman exchanges aren't possible through pure-Rust-only crates at the moment. Libp2p uses WebCrypto as a replacement.

Metadata

Metadata

Assignees

Labels

J0-enhancementAn additional feature request.J1-metaA specific issue for grouping tasks or bugs of a specific category.

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions