nimiq / core-rs

Official Rust implementation of the Nimiq protocol
https://nimiq.com
Other
74 stars 10 forks source link

WebAssembly build target #9

Open riptl opened 5 years ago

riptl commented 5 years ago

Question or Feature Request

Nimiq is the web-based currency. Why not compile the Rust core to Wasm then?

Useful resources:

I'll do some research on what's required to compile to the new target.

curdbecker commented 5 years ago

That's already in progress by the core team as far as I know :)

Eligioo commented 5 years ago

@paberr already started to split up the code into seperate crates. The easy crates (like primitives, key-derivation and mnemonic) should already be compatible although the miss export annotations.

https://udoprog.github.io/rust/2018-02-19/porting-rust-to-wasm.html

Edit: add article

paberr commented 5 years ago

I did some experiments about 2 weeks ago and especially liked https://rustwasm.github.io/book/ as a resource. As @Eligioo mentioned, I think the easy crates essentially only miss #[wasm_bindgen] annotations. :)

valentinvieriu commented 5 years ago

Any progress on this? I would really like to use wasm version of public key generation https://github.com/nimiq/core-rs/tree/master/keys

@paberr can you share on how you manage to do it. I'm really no rust expert, i just need a wasm build for the public key generator

riptl commented 5 years ago

@valentinvieriu Nimiq Core JS does ed25519 in WASM: https://github.com/nimiq-network/core/blob/master/src/main/generic/consensus/base/primitive/PrivateKey.js

https://github.com/nimiq-network/core/tree/master/src/main/platform/browser

valentinvieriu commented 5 years ago

Thank you @terorie I know this is used there too. I'm looking now on how to extract only the Public key / Nimiq adress generator. (https://github.com/nimiq-network/core/blob/master/src/native/Makefile) At this moment the native project contains more. The way the rust project is structured, has the potential of being able to build those separate. I can see this be beneficial for wallet focused apps, that don't need mining or other functionality that is part of the whole package

riptl commented 5 years ago

@valentinvieriu That's true, the core-js wasm blob is a bit large. But I don't think it'll be any different with core-rs. I need a wasm build of the Nimiq core structures anyways, so I can probably help you with creating a small build: My plan is to rip out the consensus + networking and simplify the crypto package. We can work together on this if you want – my email is on my GitHub profile.

In the meantime, you can just get all the functionality from the official Nimiq lib. <script type="text/javascript" src="https://cdn.nimiq.com/nimiq.js"></script> (Nimiq.PublicKey will be available in scripts)

valentinvieriu commented 5 years ago

@terorie that is great! I've added you on Discord.