mirror of
https://github.com/sequentialread/pow-captcha.git
synced 2025-11-23 22:15:47 +00:00
use wasm_bindgen properly in CrossOrigin version
This commit is contained in:
parent
48abd8be27
commit
ac27924f68
File diff suppressed because one or more lines are too long
@ -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
|
## 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
|
## However, it also means that the site can't use a content-security-policy which restricts external javascript
|
||||||
|
|
||||||
|
|
||||||
echo '
|
echo '
|
||||||
// THIS FILE IS GENERATED AUTOMATICALLY
|
// THIS FILE IS GENERATED AUTOMATICALLY
|
||||||
// Dont edit this file by hand.
|
// Dont edit this file by hand.
|
||||||
@ -75,8 +76,13 @@ echo '
|
|||||||
|
|
||||||
cat ../proofOfWorkerStub.js | tail -n +6 >> ../static/proofOfWorker_CrossOrigin.js
|
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 '
|
echo '
|
||||||
|
|
||||||
|
|
||||||
// https://caniuse.com/mdn-javascript_builtins_uint8array_frombase64 its at 60% in oct 2025
|
// https://caniuse.com/mdn-javascript_builtins_uint8array_frombase64 its at 60% in oct 2025
|
||||||
if (!Uint8Array.fromBase64) {
|
if (!Uint8Array.fromBase64) {
|
||||||
Uint8Array.fromBase64 = function(base64String) {
|
Uint8Array.fromBase64 = function(base64String) {
|
||||||
@ -93,27 +99,14 @@ const base64WASM = "'"$(cat ../static/scrypt.wasm | base64 -w 0)"'";
|
|||||||
|
|
||||||
const wasmBinary = Uint8Array.fromBase64(base64WASM);
|
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
|
' >> ../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!"
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user