Encryption (Noise) using WASM in the Browser doesn't work #4218
-
Hey, I'm trying to use LibP2P in the Browser using WebAssembly. Currently just trying to get it running at all. I'm using As far as I understand, the transport is working but the handshake fails because "the rsa feature is not enabled". But I did enable it. Failed to connect to QmU1Vrub5vJXNVg3pmpKD8JgaQiLAT3T65zaPeRBJJ675y: Failed to negotiate transport protocol(s): [(/ip4/192.168.178.28/tcp/5111/ws/p2p/QmU1Vrub5vJXNVg3pmpKD8JgaQiLAT3T65zaPeRBJJ675y: : Handshake failed: Invalid public key: Key decoding error: cargo feature `rsa` is not enabled)] Cargo.toml [package]
name = "wasm-libp2p-test"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
crate-type = ["cdylib"]
[[bin]]
name = "test"
path = "src/test.rs"
[dependencies]
parking_lot = { features = ["wasm-bindgen"] }
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4.37"
web-sys = {version = "0.3.0", features = ["console"]}
getrandom = { version = "0.2", features = ["js"] }
libp2p = {version = "0.52.0", features = ["wasm-ext", "rsa", "macros", "noise", "ping", "yamux"]}
bs58 = "0.5.0" I think I have tracked it down to https://github.com/libp2p/rust-libp2p/blob/d3b4714730cafb850be46cbbb7038658d0d560bb/identity/src/lib.rs#L56C1-L57C1 to this line in #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))]
pub mod rsa; So, the #[cfg(all(feature = "rsa", not(target_arch = "wasm32")))] attribute will only include the code block it's attached to if the "rsa" feature is enabled and the target architecture is not "wasm32". If either of these conditions is not met, the code block will be excluded from compilation. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
We don't support RSA keys in the browser, you'll have to choose a different key format, preferably ed25519. |
Beta Was this translation helpful? Give feedback.
We don't support RSA keys in the browser, you'll have to choose a different key format, preferably ed25519.