c0dearm / sharks

Fast, small and secure Shamir's Secret Sharing library crate
https://crates.io/crates/sharks
Other
59 stars 12 forks source link

WASM bindings #10

Closed zer0x64 closed 4 years ago

zer0x64 commented 4 years ago

This PR implements a WASM interface to be used in a browser as an NPM module.

For now it's a draft because a couple of things are missing and might require work in the library to do right (Error handling requires use of actual Error to get right, for example).

In the actual state, it is working, even if the code quality is not enough to merge now. Here is how to use it:

  1. Install wasm-pack cargo install wasm-pack
  2. Add ~/.cargo/bin to your $PATH.
  3. Build wasm-pack build
  4. Create a nodejs project and add the crate as a dependency in packages.json: "sharks": "file:../pkg/"
  5. Import your wrapper asynchronously, since WASM cannot be run synchronously at the moment. For example: import("./sharks_wrapper.js");
  6. Here is a working piece of code:
    
    import {generate_shares, recover} from "sharks";

var secret = Uint8Array.of(1, 2, 3, 4)

var test = generate_shares(5, 3, secret);

var secret2 = recover(3, test);

alert(secret2);

c0dearm commented 4 years ago

After some work, I found out creating a new repository for the bindings was a better idea, so I've opened a pull request in the new repo: https://github.com/c0dearm/sharks-wasm/pull/1

Let's follow the discussion there! I will close the PR if you agree.

zer0x64 commented 4 years ago

Good! You can close it here.

However, is it good if I create the PR on the other repo? Since I don't have write access to the repo, I cannot modify your branch, while if I fork the repo we can both write in it.

c0dearm commented 4 years ago

Arrghh, right! Didn't thought of that. Sure, go ahead an create the PR.

I close this.