snoopy3476 / eth-blockies-rs

A pure Rust library to get raw data of Ethereum-style blockies (for saving blockies icon images, printing to terminal, ...)
https://crates.io/crates/eth-blockies
MIT License
8 stars 1 forks source link

Add Node.js Support via npm for Rust Library #3

Open x-ror opened 4 months ago

x-ror commented 4 months ago

I would like to request the addition of Node.js support for this Rust library. This can be achieved by creating an npm package that allows Node.js developers to easily install and use the Rust library in their JavaScript/TypeScript projects.

snoopy3476 commented 4 months ago

Thanks for your comment.

As the existing wasm implementation can't be ported directly to a public wasm library, I'll check what can be done at this point to port the library to a wasm version nicely.

I couldn't write it because it was not simple to convert data types between Rust and JS (except for some hacky ways), but it seems possible now.

snoopy3476 commented 3 months ago

I'm working on this, but it looks like the "optimal (minimal-sized)" version of wasm library (for JS/TS) is currently not available yet. [^1]

But if you don't mind occupying your disk a little bit more (about +100KB [^2]), you can use the eth-blockies@0.0.1-dev.2 package (temporary dev version) in your Node.js projects for now. [^3] This dev version 0.0.1-dev.2 will remain forever, even after optimized versions are published.

[^1]: The current Rust implementation only supports const size for identicon outputs, so an output size to use must be specified before compiling a Rust code. This isn't much of a problem when using the library directly on Rust since library users can specify their size before compiling. However, a wasm file is a compiled output, so wasm codes for all size candidates must be generated and compiled into a single wasm file so that library users can choose a size they want. I'm thinking of adding support for runtime-sized blockies to Rust implementation first, then replacing constant functions in the JS/TS wrapper library with the new runtime ones to make the wasm file smaller.

[^2]: Estimated file size to be decreased after optimization

[^3]: It's marked as temporary version but it should make the same outputs with ones from the Rust version. "Temporary" here is mainly for JS/TS wrapper function signature (e.g. arguments or returned data type of wrapper functions can be changed dramatically on later versions), not for implementation of generator Rust functions itself.