Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Fast, lightweight Argon2id implementation for both browser and Node:
We initially tried implementing a solution in pure JS (no Wasm) but the running time was unacceptable. We resorted to implement part of the module in Wasm, to take advantage of 64-bit multiplications and SIMD instructions. The Wasm binary remains small thanks to the fact that the memory is fully managed by the JS side, hence no memory management function gets included in the Wasm binary.
Install from npm (compiled wasm files included):
npm i argon2id
With bundlers like Rollup (through plugin-wasm) or Webpack (through wasm-loader), that automatically translate import statements like import wasmModule from '*.wasm'
to a loader of type wasmModule: (instanceOptions) => WebAssembly.WebAssemblyInstantiatedSource
(either sync or async), you can simply use the default export like so:
import loadArgon2idWasm from 'argon2id';
const argon2id = await loadArgon2idWasm();
const hash = argon2id({
password: new Uint8Array(...),
salt: crypto.getRandomValues(new Uint8Array(32)),
parallelism: 4,
passes: 3,
memorySize: 2**16
});
Refer to the Argon2 RFC for details about how to pick the parameters.
Note about memory usage: every call to loadArgon2idWasm
will instantiate and run a separate Wasm instance, with separate memory.
The used Wasm memory is cleared after each call to argon2id
, but it isn't deallocated (this is due to Wasm limitations).
Re-loading the Wasm module is thus recommended in order to free the memory if multiple argon2id
hashes are computed and some of them require considerably more memory than the rest.
The library does not require a particular toolchain. If the aforementioned bundlers are not an option, you can manually take care of setting up the Wasm modules.
For instance, in Node, the library can be used without bundlers. You will need to pass two functions that instantiate the Wasm modules to setupWasm
(first function is expected to take care of the SIMD binary, second one the non-SIMD one):
import fs from 'fs';
import setupWasm from 'argon2id/lib/setup.js';
// point to compiled binaries
const SIMD_FILENAME = 'argon2id/dist/simd.wasm';
const NON_SIMD_FILENAME = 'argon2id/dist/no-simd.wasm';
const argon2id = await setupWasm(
(importObject) => WebAssembly.instantiate(fs.readFileSync(SIMD_FILENAME), importObject),
(importObject) => WebAssembly.instantiate(fs.readFileSync(NON_SIMD_FILENAME), importObject),
);
Using the same principle, for browsers you can use bundlers with simple base-64 file loaders.
The npm package already includes the compiled binaries.
If you fork the repo, you'll have to manually compile wasm (Docker required):
npm run build
The resulting binaries will be under dist/
.
If you do not want to use docker, you can look into installing emscripten; you'll find the compilation commands to use in build_wasm.sh
.
FAQs
Argon2id implementation in pure Javascript
The npm package argon2id receives a total of 54 weekly downloads. As such, argon2id popularity was classified as not popular.
We found that argon2id demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.