Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make simd load automatically #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build-wasm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ shasum dist/argon2.wasm

perl -pi -e 's/"argon2.js.mem"/null/g' dist/argon2.js
perl -pi -e 's/$/if(typeof module!=="undefined")module.exports=Module;Module.unloadRuntime=function(){if(typeof self!=="undefined"){delete self.Module}Module=jsModule=wasmMemory=wasmTable=asm=buffer=HEAP8=HEAPU8=HEAP16=HEAPU16=HEAP32=HEAPU32=HEAPF32=HEAPF64=undefined;if(typeof module!=="undefined"){delete module.exports}};/' dist/argon2.js
perl -pi -e 's/typeof Module!=="undefined"\?Module:\{};/typeof self!=="undefined"&&typeof self.Module!=="undefined"?self.Module:{};var jsModule=Module;/g' dist/argon2.js
perl -pi -e 's/typeof Module!="undefined"\?Module:\{};/typeof self!=="undefined"&&typeof self.Module!=="undefined"?self.Module:{};var jsModule=Module;/g' dist/argon2.js
perl -pi -e 's/receiveInstantiatedSource\(output\)\{/receiveInstantiatedSource(output){Module=jsModule;if(typeof self!=="undefined")self.Module=Module;/g' dist/argon2.js
perl -pi -e 's/argon2.wasm/argon2-simd.wasm/g' dist/argon2.js
13 changes: 8 additions & 5 deletions lib/argon2.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,18 @@
return global.loadArgon2WasmBinary();
}
if (typeof require === 'function') {
return Promise.resolve(require('../dist/argon2.wasm')).then(
(wasmModule) => {
return decodeWasmBinary(wasmModule);
}
var simd = require('wasm-feature-detect').simd;
return Promise.resolve(
simd()
.then((simd) => require('../dist/argon2' + (simd? "-simd" : "") + '.wasm'))
.then((wasmModule) => {
return decodeWasmBinary(wasmModule);
})
);
}
const wasmPath =
global.argon2WasmPath ||
'node_modules/argon2-browser/dist/argon2.wasm';
'node_modules/argon2-browser/dist/argon2-simd.wasm';
return fetch(wasmPath)
.then((response) => response.arrayBuffer())
.then((ab) => new Uint8Array(ab));
Expand Down
18 changes: 16 additions & 2 deletions package-lock.json

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

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "argon2-browser",
"version": "1.18.0",
"version": "1.18.1",
"description": "Argon2 library compiled for browser runtime",
"main": "lib/argon2.js",
"directories": {
Expand Down Expand Up @@ -30,5 +30,8 @@
"puppeteer": "^9.1.1",
"webpack": "^5.37.1",
"webpack-cli": "^4.7.0"
},
"dependencies": {
"wasm-feature-detect": "^1.5.1"
}
}