Skip to content

ivanalejandro0/rust-and-wasm-from-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

What's this?

This is an experiment to replace a Javascript library with a Rust one, using WebAssembly.

I've picked a library to work with base58check encoding, because it is simple enough for a proof of concept and because is a dependency I'm using on a project I'm working on.

npm package:

rust crate:

Requirements

You will need:

Note: the rust+wasm code was set up using a template, you can find more informantion on https://rustwasm.github.io/docs/wasm-pack/tutorials/index.html

Running the test

You need to set up the dependencies, compile the the rust code to wasm and use if from JS.

I wrote a couple of tests to make sure that I'm getting the same results from both libraries.

$ # inside this repository
$ cd mybase58check/
$ wasm-pack build --target nodejs
$ cd ..
$ yarn install
$ yarn run test
yarn run v1.21.1
$ jest --verbose
 PASS  ./base58check.test.js
  Verify that both implementations are equivalent
    ✓ same decoding result (7ms)
    ✓ same encoding result (2ms)
    ✓ both fail on invalid decode (2ms)

Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        1.63s
Ran all test suites.
✨  Done in 4.07s.

About

Replacing base58check js dependency with rust+wasm

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published