@aeternity/argon2-browser

中文文档
0.1.2发布于 2022/02/12MITCommonJS零依赖近 30 天下载 3896

Argon2 library compiled for browser runtime

此软件包已被标记为弃用

This package is no longer maintained

原始使用文档
文档目录12 节
  1. The numbers
  2. Test Environment
  3. Code size
  4. Is Argon2 modified?
  5. SIMD
  6. JS Library
  7. Usage
  8. Bundlers
  9. Node.js support
  10. Is it used anywhere?
  11. Building
  12. License

Argon2 in browser Build

Argon2 is a password-hashing function, the winner of Password Hashing Competition. Here Argon2 library is compiled for browser runtime.

Live demo

More about Argon2

Usage

The numbers

Time, ms (lower is better)
Chrome WASM225
Chrome WASM+SIMD119
Firefox WASM195
Firefox WASM+SIMD135
Safari WASM174
Native -O3 SSE15
Native -O342
Native -O155
Native -O0395

Test Environment

Environment used to get the numbers above:

Algorithm parameters (-d -t 100 -m 10 -p 1):

  • iterations: 100
  • memory: 1MiB (1024 KiB)
  • hash length: 32
  • parallelism: 1
  • argon2d

Environment:

  • MacBook pro 2020, Intel Core i7, 2.3GHz (x64), macOS 10.14.6 (18G95)
  • Chrome 85.0.4183.83 (Official Build)
  • Firefox 80.0.1
  • Safari 13.1.2 (15609.3.5.1.3)
  • native argon2 compiled from https://github.com/P-H-C/phc-winner-argon2 @440ceb9

Code size

ll -h dist

FileCode size, kB
argon2.js14
argon2.wasm25

Is Argon2 modified?

No, it's used a submodule from upstream.

SIMD

SIMD is not quite here in WebAssembly, however for those who would like to give it a try, we already provide a working build with SIMD. At the moment it works only in Chrome, to be able to use it, you need to either add this origin trial to your website, or enable the SIMD feature in Chrome flags.

More about WebAssembly SIMD support in V8: https://v8.dev/features/simd

On Firefox you need to enable javascript.options.wasm_simd option in about:config.

To use the SIMD version, load argon2-simd.wasm instead of argon2.wasm.

JS Library

The library can be installed from npm:

npm install argon2-browser

Then add this script to your HTML or use your favorite bundler:

<script src="node_modules/argon2-browser/dist/argon2.min.js"></script>

Alternatively, you can use the bundled version, this way you can include just one script:

<script src="node_modules/argon2-browser/dist/argon2-bundled.min.js"></script>

Calculate the hash:

argon2.hash({ pass: 'password', salt: 'somesalt' })
    .then(h => console.log(h.hash, h.hashHex, h.encoded))
    .catch(e => console.error(e.message, e.code))

Verify the encoded hash (if you need it):

argon2.verify({ pass: 'password', encoded: 'enc-hash' })
    .then(() => console.log('OK'))
    .catch(e => console.error(e.message, e.code))

Other parameters:

argon2.hash({
    // required
    pass: 'password',
    salt: 'salt',
    // optional
    time: 1, // the number of iterations
    mem: 1024, // used memory, in KiB
    hashLen: 24, // desired hash length
    parallelism: 1, // desired parallelism (it won't be computed in parallel, however)
    secret: new Uint8Array([...]), // optional secret data
    ad: new Uint8Array([...]), // optional associated data
    type: argon2.ArgonType.Argon2d, // Argon2d, Argon2i, Argon2id
})
// result
.then(res => {
    res.hash // hash as Uint8Array
    res.hashHex // hash as hex-string
    res.encoded // encoded hash, as required by argon2
})
// or error
.catch(err => {
    err.message // error message as string, if available
    err.code // numeric error code
})
argon2.verify({
    // required
    pass: 'password',
    encoded: 'enc-hash',
    // optional
    secret: new Uint8Array([...]), // optional secret data
    ad: new Uint8Array([...]), // optional associated data
    type: argon2.ArgonType.Argon2d, // Argon2d, Argon2i, Argon2id. default: guess
})
// result
.then(res => {
    res.hash // hash as Uint8Array
    res.hashHex // hash as hex-string
    res.encoded // encoded hash, as required by argon2
})
// or error
.catch(err => {
    err.message // error message as string, if available
    err.code // numeric error code
})

Usage

You can use this module in several ways:

  1. write the WASM loader manually, for example, if you need more control over memory (example);
  2. bundle it with WebPack or another bundler (example);
  3. in vanilla js: example;
  4. in node.js: example (see a note below).

Bundlers

Node.js support

Of course you can use generated WASM in node.js, but it's not sensible: you will get much better speed by compiling it as a native node.js addon, which is not that hard. Wait, it's already done, just install this package.

Is it used anywhere?

It is! KeeWeb (web-based password manager) is using it as a password hashing function implementation. Check out the source code, if you're interested.

Building

You can build everything with

./build.sh

Prerequisites:

  • emscripten with WebAssembly support (howto)
  • CMake

License

MIT

版本与发布记录

@aeternity/argon2-browser 共发布 3 个版本,首次发布于 2022/02/07;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.1.2latest2022/02/124 年前
0.1.12022/02/074 年前
0.1.02022/02/074 年前

关于 @aeternity/argon2-browser 的常见问题

@aeternity/argon2-browser 是什么?

Argon2 library compiled for browser runtime注意:该包已被作者标记为弃用——This package is no longer maintained

如何安装 @aeternity/argon2-browser?

在项目目录运行 npm install @aeternity/argon2-browser,或使用 pnpm add / yarn add / bun add。

@aeternity/argon2-browser 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/aeternity__argon2-browser 是否存在。

@aeternity/argon2-browser 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@aeternity/argon2-browser 可以商用吗?

@aeternity/argon2-browser 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@aeternity/argon2-browser 的下载量有多少?

根据 npm 官方下载统计,@aeternity/argon2-browser 在 2026/10/05 – 2026/11/03 这 30 天内被下载 3,896 次,日均约 130 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@aeternity/argon2-browser 还在维护吗?

最新版本 0.1.2 发布于 2022/02/12(4 年前);至今共发布 3 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/02/07。作者已将其标记为弃用,新项目建议寻找替代方案。