Skip to content

Commit

Permalink
update cryptonight_wasm.cjs lib
Browse files Browse the repository at this point in the history
  • Loading branch information
pk910 committed Jan 5, 2024
1 parent d772fb8 commit 6305717
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 157 deletions.
2 changes: 1 addition & 1 deletion faucet-wasm/cryptonight/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
TARGET = prog
LIBS = -lm

CC = emcc -O3 -s NO_FILESYSTEM=1 -s TOTAL_MEMORY=67108864 -s EXPORTED_FUNCTIONS="['_hash_cn']" -s WASM=1 -s ENVIRONMENT=worker -s MODULARIZE=1 -s EXPORT_ES6=1 -s STANDALONE_WASM --no-entry --pre-js ../../../wasm-pre.js
CC = emcc -O3 -s NO_FILESYSTEM=1 -s 'EXPORTED_RUNTIME_METHODS=["ccall", "cwrap"]' -s TOTAL_MEMORY=67108864 -s EXPORTED_FUNCTIONS="['_hash_cn']" -s WASM=1 -s ENVIRONMENT=worker -s MODULARIZE=1 -sWASM_BIGINT -s EXPORT_ES6=1 --no-entry --pre-js ../../../wasm-pre.js
CFLAGS =

# -s ASSERTIONS=1
Expand Down
14 changes: 8 additions & 6 deletions faucet-wasm/cryptonight/build_wasm.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

const base32768 = require('base32768');
const fs = require('fs');
import { encode } from "base32768";
import fs from "fs";

const base32768Module = fs.readFileSync("node_modules/base32768/dist/iife/base32768.js", { encoding: "utf8" });
const base32768WASM = base32768.encode(fs.readFileSync("cryptonight-wasm/hash_cn/webassembly/cn.wasm"));
const base32768Module = fs.readFileSync("node_modules/base32768/src/index.js", { encoding: "utf8" }).replace(/^export .*$/m, "");
const base32768WASM = encode(fs.readFileSync("cryptonight-wasm/hash_cn/webassembly/cn.wasm"));

const wasmWrappperJS = fs.readFileSync("cryptonight-wasm/hash_cn/webassembly/cn.js", { encoding: "utf8" });
let lines = wasmWrappperJS.replace(/import\.meta/g, "wasmMeta").split("\n");
Expand All @@ -25,13 +25,15 @@ var cryptonightPromise, cryptonight;
module.exports = {
getCryptoNight: function() { return cryptonight; },
getCryptoNightReadyPromise: function() { return cryptonightPromise; }
getCryptoNightReadyPromise: function() {
return cryptonightPromise;
}
};
function getWasmBinary() {
${base32768Module}
const base32768WASM = "${base32768WASM}";
return base32768.decode(base32768WASM);
return decode(base32768WASM);
}
(function() {
Expand Down
8 changes: 5 additions & 3 deletions faucet-wasm/cryptonight/build_wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ fi
emcc_is_installed="$(which emcc | wc -l)"

if [ "$emcc_is_installed" == "0" ]; then
git clone https://github.com/emscripten-core/emsdk.git
if [ ! -d ./emsdk ]; then
git clone https://github.com/emscripten-core/emsdk.git
fi
cd emsdk
./emsdk install latest
./emsdk activate latest
Expand All @@ -21,15 +23,15 @@ if [ "$emcc_is_installed" == "0" ]; then
fi

cd cryptonight-wasm/hash_cn/webassembly
if [ ! -f ./cn.wasm ]; then

printf "running ./Makefile for webminerpool/hash_cn/webassembly... \n"

# included Makefile is not working...
mv Makefile Makefile.org
cp ../../../Makefile ./Makefile
make
mv Makefile.org Makefile
fi

cd ../../..

nodejs_is_installed="$(which node | wc -l)"
Expand Down
20 changes: 14 additions & 6 deletions faucet-wasm/cryptonight/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion faucet-wasm/cryptonight/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
"version": "0.0.0",
"description": "build wasm module into webworker",
"main": "build_wasm_webworker.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "GPL-3.0-or-later",
"dependencies": {
"base32768": "^2.0.1"
"base32768": "^3.0.1"
}
}
272 changes: 132 additions & 140 deletions libs/cryptonight_wasm.cjs

Large diffs are not rendered by default.

0 comments on commit 6305717

Please sign in to comment.