Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial WasmThemis wrapper #461

Merged
merged 3 commits into from
Apr 16, 2019
Merged

Initial WasmThemis wrapper #461

merged 3 commits into from
Apr 16, 2019

Commits on Apr 16, 2019

  1. Add "wasm_themis" target for Makefile

    The new wrapper was christened "WasmThemis". Let's get rolling!
    It will live under src/wrappers/themis/wasm.
    
    Introduce a new submakefile "wasmthemis.mk" which will contain all
    specific targets and configuration for building WasmThemis. The main
    target is "wasm_themis", that's our user-facing target which should
    be used by developers. It will build the wrapper in BUILD_PATH.
    
    We still don't have a proper wrapper so instead we're going to build
    libthemis.js library for now. This is our 'native code' as far as
    JavaScript is concerned. It simply links Themis static library and
    its dependencies with `emcc`. Note, however, a couple of caveats:
    
      - Use EMSCRIPTEN_KEEPALIVE marker for public API
    
        Emscripten does dead-code elimination when linking final WebAssembly
        application. Anything not called from main() will be removed. And if
        there is no main() -- typical for a library, eh? -- then everything
        will be removed. We don't want that, so we use EMSCRIPTEN_KEEPALIVE
        to keep LLVM from optimizing out the functions we're going to use.
    
      - Use EXTRA_EXPORTED_RUNTIME_METHODS to keep preamble.js API
    
        Emscripten provides a bunch of useful utilities for interacting with
        its sandbox from JavaScript. However, they are also optimized out by
        default. We need to explicitly list the APIs we're going to use.
    
    Finally, all WebAssembly builds must be performed in properly configured
    Emscripten environment. That is, by calling "emmake make wasm_themis".
    Add a simple check before running the build to ensure that the developer
    did not forget to use emmake.
    ilammy committed Apr 16, 2019
    Configuration menu
    Copy the full SHA
    f70ed1d View commit details
    Browse the repository at this point in the history
  2. Initial "wasm-themis" npm package

    We're going to publish WasmThemis via npm, create a package for that.
    Let's be nice and provide README and LICENSE files, fill in some
    informational fields in in package.json, etc. Note also these carefully
    crafted .gitignore and .npmignore files. They are meant to ensure that
    developers could do their thing in the working copy without accidentally
    committing unnecessary files to git or publishing them on npm.
    
    The package is currently marked as _private_ to prevent accidental
    publish. However, it is going to be named "wasm-themis" and that's the
    name used in README.
    
    As for the wrapper code itself, let's start with secure key generation.
    This gives us a good start as we need to provide all the scaffolding
    around Node.js modules and Themis error handling. The interface stays
    similar to JsThemis, but there are no compatibility requirements. Thus
    we are able to provide strongly typed PrivateKey and PublicKey wrappers
    over Uint8Array, and expose then as read-only properties of KeyPair.
    ilammy committed Apr 16, 2019
    Configuration menu
    Copy the full SHA
    7b92579 View commit details
    Browse the repository at this point in the history
  3. Test harness for "wasm-themis" package

    Add some test using Mocha as test runner (just like we do for JsThemis).
    We don't have much API to check, just verify some basic invariants.
    
    Add "test_wasm" target to Makefile and integrate that into CI builds.
    Note that this target has to be run with 'emmake' helper.
    ilammy committed Apr 16, 2019
    Configuration menu
    Copy the full SHA
    beb358f View commit details
    Browse the repository at this point in the history