use wasm_bindgen properly in CrossOrigin version

This commit is contained in:
Your Name 2025-10-31 14:52:21 -05:00
parent 48abd8be27
commit ac27924f68
2 changed files with 242 additions and 141 deletions

File diff suppressed because one or more lines are too long

View File

@ -67,6 +67,7 @@ scryptPromise = wasm_bindgen({module_or_path: "/static/scrypt.wasm"});
## This is neccesary when the pow-bot-deterrent static assets can't be hosted on the same origin
## However, it also means that the site can't use a content-security-policy which restricts external javascript
echo '
// THIS FILE IS GENERATED AUTOMATICALLY
// Dont edit this file by hand.
@ -75,8 +76,13 @@ echo '
cat ../proofOfWorkerStub.js | tail -n +6 >> ../static/proofOfWorker_CrossOrigin.js
# wasm was defined at the top of proofOfWorker.js, so don't define it again.
cat scrypt-wasm/pkg/scrypt_wasm.js | grep -v 'let wasm = ' >> ../static/proofOfWorker_CrossOrigin.js
# see: https://rustwasm.github.io/docs/wasm-bindgen/examples/without-a-bundler.html
echo '
// https://caniuse.com/mdn-javascript_builtins_uint8array_frombase64 its at 60% in oct 2025
if (!Uint8Array.fromBase64) {
Uint8Array.fromBase64 = function(base64String) {
@ -93,27 +99,14 @@ const base64WASM = "'"$(cat ../static/scrypt.wasm | base64 -w 0)"'";
const wasmBinary = Uint8Array.fromBase64(base64WASM);
scryptPromise = WebAssembly.instantiate(wasmBinary, {}).then(instantiatedModule => {
wasm = instantiatedModule.instance.exports;
scrypt = wasm_bindgen.scrypt;
scryptPromise = wasm_bindgen({module_or_path: wasmBinary});
' >> ../static/proofOfWorker_CrossOrigin.js
# wasm was defined at the top of proofOfWorker.js, so don't define it again.
# tail -n +5 skips the first 4 lines.
# we are trying to skip all of:
#
# let wasm;
# export function __wbg_set_wasm(val) {
# wasm = val;
# }
#
cat scrypt-wasm/pkg/scrypt_wasm_bg.js | tail -n +5 \
| sed 's/export function scrypt/scrypt = function/' \
| sed 's/^export //' \
| sed -E 's/^/ /' >> ../static/proofOfWorker_CrossOrigin.js
echo '
});
' >> ../static/proofOfWorker_CrossOrigin.js
echo "Build successful!"