Add wasm-crypto package (just start, incomplete) (#3)
* Add wasm-crypto package (just start, incomplete) * Update * Merge master * Headers * Add sha512 * Add blake2b * Add twox * xxhash with multiple rounds * Cleanup tests (non-async) * Adjust signatures * Doc comments * schnorrkel 0.1.0 crate * Simplify export names * Bip39 * Updates, ext_* function exposure * bip39 tested and working * Re-add wasm optimisations * Cleanup build script * Auto-detect internal packages * bip39ToMiniSecret
This commit is contained in:
+18
-22
@@ -11,13 +11,23 @@ echo "*** Building WASM output"
|
||||
rustup run nightly wasm-pack build --release --scope polkadot --target nodejs
|
||||
mv pkg build
|
||||
|
||||
# shortcuts for files
|
||||
echo "*** Adjusting output"
|
||||
BGJ=build/wasm_bg.js
|
||||
SRC=build/wasm.js
|
||||
DEF=build/wasm.d.ts
|
||||
WSM=build/wasm_bg.wasm
|
||||
OPT=build/wasm_opt.wasm
|
||||
ASM=build/wasm_asm.js
|
||||
|
||||
# optimise
|
||||
echo "*** Optimising WASM output"
|
||||
../../binaryen/bin/wasm-opt build/wasm_bg.wasm -Os -o build/wasm_opt.wasm
|
||||
../../binaryen/bin/wasm-opt $WSM -Os -o $OPT
|
||||
# cp -f build/wasm_bg.wasm build/wasm_opt.wasm
|
||||
|
||||
# build asmjs version from the input (optimised) WASM
|
||||
# echo "*** Building asm.js version"
|
||||
# ../../binaryen/bin/wasm2js --no-validation --output build/wasm_temp.js build/wasm_opt.wasm
|
||||
# ../../binaryen/bin/wasm2js --no-validation --output $ASM $OPT
|
||||
|
||||
# convert wasm to base64 structure
|
||||
echo "*** Packing WASM into base64"
|
||||
@@ -27,25 +37,11 @@ node ../../scripts/pack-wasm-base64.js
|
||||
echo "*** Copying package sources"
|
||||
cp src/js/* build/
|
||||
|
||||
# shortcuts for files
|
||||
echo "*** Adjusting output"
|
||||
BGJ=build/wasm_bg.js
|
||||
SRC=build/wasm.js
|
||||
DEF=build/wasm.d.ts
|
||||
TMP=build/wasm_temp.js
|
||||
ASM=build/wasm_asm.js
|
||||
|
||||
# update the files (new addition)
|
||||
# excluded: "wasm_asm\.js",
|
||||
# sed -i -e 's/wasm_bg\.wasm/wasm_wasm\.js", "index\.js", "index\.d\.ts/g' $PKG
|
||||
# sed -i -e 's/"main": "wasm\.js"/"main": "index\.js"/g' $PKG
|
||||
# sed -i -e 's/"types": "wasm\.d\.ts"/"types": "index\.d\.ts"/g' $PKG
|
||||
|
||||
# cleanup asm
|
||||
# sed -i -e 's/import {/\/\/ import {/g' $TMP
|
||||
# sed -i -e 's/function asmFunc/var schnorrkel = require('\''\.\/wasm'\''); function asmFunc/g' $TMP
|
||||
# sed -i -e 's/export const /module\.exports\./g' $TMP
|
||||
# sed -i -e 's/{abort.*},memasmFunc/schnorrkel, memasmFunc/g' $TMP
|
||||
# sed -i -e 's/import {/\/\/ import {/g' $ASM
|
||||
# sed -i -e 's/function asmFunc/var schnorrkel = require('\''\.\/wasm'\''); function asmFunc/g' $ASM
|
||||
# sed -i -e 's/export const /module\.exports\./g' $ASM
|
||||
# sed -i -e 's/{abort.*},memasmFunc/schnorrkel, memasmFunc/g' $ASM
|
||||
|
||||
# we are swapping to a async interface for webpack support (wasm limits)
|
||||
sed -i -e 's/wasm = require/\/\/ wasm = require/g' $SRC
|
||||
@@ -73,11 +69,11 @@ export function waitReady(): Promise<boolean>;
|
||||
echo "
|
||||
const asm = null; // require('./wasm_asm');
|
||||
const bytes = require('./wasm_wasm');
|
||||
const imported = require('./wasm');
|
||||
const js = require('./wasm');
|
||||
|
||||
module.exports = async function createExportPromise () {
|
||||
const imports = {
|
||||
'./wasm': imported
|
||||
'./wasm': js
|
||||
};
|
||||
|
||||
if (!WebAssembly) {
|
||||
|
||||
+10
-8
@@ -4,20 +4,22 @@ set -e
|
||||
|
||||
./scripts/install-build-deps.sh
|
||||
|
||||
PACKAGES=( "schnorrkel" )
|
||||
|
||||
echo "*** Building packages"
|
||||
cd packages
|
||||
|
||||
PACKAGES=( $(ls -1d *) )
|
||||
|
||||
for PKG in "${PACKAGES[@]}"; do
|
||||
echo "*** Building wasm-$PKG"
|
||||
cd wasm-$PKG
|
||||
if [ -f "$PKG/package.json" ]; then
|
||||
echo "*** Building $PKG"
|
||||
cd $PKG
|
||||
|
||||
./build.sh
|
||||
rm -rf build/*-e build/package.json build/README.md
|
||||
ls -al build
|
||||
./build.sh
|
||||
rm -rf build/*-e build/package.json build/README.md
|
||||
ls -al build
|
||||
|
||||
cd ..
|
||||
cd ..
|
||||
fi
|
||||
done
|
||||
|
||||
cd ..
|
||||
|
||||
Reference in New Issue
Block a user