UNPKG

sidh

Version:

JavaScript wrapper for a WebAssembly build of SIDH

99 lines (89 loc) 2.88 kB
all: make clean cp -Hrf libsodium libsodium.tmp patch libsodium.tmp/src/libsodium/include/sodium/randombytes.h randombytes.h.patch patch libsodium.tmp/src/libsodium/randombytes/randombytes.c randombytes.c.patch bash -c ' \ args="$$(echo " \ --memory-init-file 0 \ -s SINGLE_FILE=1 \ -D_GENERIC_ -D__NIX__ -D_X86_ \ -s TOTAL_MEMORY=16777216 -s TOTAL_STACK=8388608 \ -s ASSERTIONS=0 \ -s AGGRESSIVE_VARIABLE_ELIMINATION=1 \ -s ALIASING_FUNCTION_POINTERS=1 \ -s DISABLE_EXCEPTION_CATCHING=1 \ -s NO_FILESYSTEM=1 \ -s ERROR_ON_UNDEFINED_SYMBOLS=0 \ -Ilibsodium.tmp/src/libsodium/include \ -Ilibsodium.tmp/src/libsodium/include/sodium \ -Isidh/src/P751 \ $$(find libsodium.tmp/src/libsodium -type f -name '\\*.c') \ sidh/src/sha3/*.c \ sidh/src/P751/generic/*.c \ sidh/src/P751/P751.c \ main.c \ -s EXPORTED_RUNTIME_METHODS=\"[ \ '"'"'writeArrayToMemory'"'"' \ ]\" \ -s EXPORTED_FUNCTIONS=\"[ \ '"'"'_free'"'"', \ '"'"'_malloc'"'"', \ '"'"'_sidhjs_init'"'"', \ '"'"'_sidhjs_keypair'"'"', \ '"'"'_sidhjs_encrypt'"'"', \ '"'"'_sidhjs_decrypt'"'"', \ '"'"'_sidhjs_public_key_bytes'"'"', \ '"'"'_sidhjs_private_key_bytes'"'"', \ '"'"'_sidhjs_cyphertext_bytes'"'"', \ '"'"'_sidhjs_secret_bytes'"'"' \ ]\" \ " | perl -pe "s/\s+/ /g" | perl -pe "s/\[ /\[/g" | perl -pe "s/ \]/\]/g")"; \ \ bash -c "emcc -Oz -s WASM=0 $$args -o dist/index.asm.js"; \ bash -c "emcc -O3 -s WASM=1 $$args -o dist/index.wasm.js"; \ ' npx babel --no-babelrc --presets @babel/preset-env dist/index.asm.js -o dist/index.asm.js npx babel --no-babelrc --presets @babel/preset-env dist/index.wasm.js -o dist/index.wasm.js cp pre.js dist/index.tmp.js echo " \ var Module = {}; \ Module.ready = new Promise(function (resolve, reject) { \ var Module = {}; \ Module.onAbort = reject; \ Module.onRuntimeInitialized = function () { \ try { \ Module._sidhjs_public_key_bytes(); \ resolve(Module); \ } \ catch (err) { \ reject(err); \ } \ }; \ " >> dist/index.tmp.js cat dist/index.wasm.js >> dist/index.tmp.js echo " \ }).catch(function () { \ var Module = {}; \ " >> dist/index.tmp.js cat dist/index.asm.js >> dist/index.tmp.js echo " \ return new Promise(function (resolve, reject) { \ Module.onAbort = reject; \ Module.onRuntimeInitialized = function () { resolve(Module); }; \ }); \ }).then(function (m) { \ Object.keys(m).forEach(function (k) { Module[k] = m[k]; }); \ }); \ " >> dist/index.tmp.js cat post.js >> dist/index.tmp.js npx terser dist/index.tmp.js -cmo dist/index.js sed -i 's|use asm||g' dist/index.js sed -i 's|require(|eval("require")(|g' dist/index.js rm -rf dist/index.*.js libsodium.tmp chmod -R 777 dist clean: rm -rf dist libsodium.tmp 2> /dev/null mkdir dist test: npm run test