Git Product home page Git Product logo

web-totp's Introduction

Web - TOTP

deploy workflow

A Totp generation react web application with WebAssembly hooks.

Table of Contents

Introduction

Manage your authentication codes using a simple browser based pwa. It's built on react along with web assembly bindings to ensure predictable performance for totp generation. All your authentication codes are stored in local storage and can be exported or erased at your will.

Build Process

The wasm binaries are already compiled and stored in the public folder. So it just requires you to install the npm modules:

npm install

However, if you want to modify the wasm, you first need to get the Emscripten SDK, using these instructions: https://emscripten.org/docs/getting_started/downloads.html

Then to compile and post the wasm bytecode a neat little makefile will do the trick:

cd wasm
make

Web Assembly

Web Assembly is a low-level virtual machine that runs the bytecode that is stored in .wasm files. This byte code is strongly typed and structured in such a way that it can be compiled and optimized for the host system much quicker than JavaScript can.

Why did we need wasm?

In general, JavaScript and WebAssembly can achieve the same peak performance. However, for JavaScript this performance can only be reached on the "fast path", and it's often tricky to stay on that "fast path". One key benefit that WebAssembly offers is predictable performance, even across browsers.

Some reference: https://developers.google.com/web/updates/2019/02/hotpath-with-wasm

Totp calculation in native c seemed to be one of those use cases, which needs predictable performance on the web. It is a pure computational code and is expected to be highly fast when used via wasm rather than js libraries. Although note that no performance benchmarks were done yet.

For our implementation, the HMAC-SHA1 code was taken from a reliable open source implementation. The hotp and totp wrapper were then written following the rfc specifications (rfc 4226 and rfc 6238 respectively).

The c bindings are then compiled using emcc with the -O3 optimization level:

emcc -O3 -s WASM=1 -s EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]' \
-I ./lib lib/*.c hotp.c totp.c wasm_entrypoint.c -o totp.js

web-totp's People

Contributors

raydwaipayan avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

kzfk abeldex rdwz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.