@dashlane/pqc-kem-kyber512-browser

中文文档
1.0.0发布于 2022/07/19Apache-2.0TypeScriptES Module零依赖近 30 天下载 2821

JavaScript wrapper generator of WebAssembly builds of each round-3 finalists of NIST Post-Quantum Cryptography Competition

原始使用文档
文档目录10 节
  1. Overview
  2. Playground
  3. How to download pre-built bindings and NPM packages
  4. How to build
  5. How to use
  6. Key Encapsulation
  7. Signature
  8. Disable WebAssembly execution
  9. Change the path of the WebAssembly
  10. Implementation notes

pqc.js

Overview

This project provides JS bindings and playground of post-quantum asymmetric cipher compiled to WebAssembly using emscripten with a fallback in plain JS.

The available methods are the finalists (and alternate candidates) of NIST Post-Quantum Cryptography Competition:

The C implementations used to create the bindings are the clean versions provided by PQClean.

This project has been inspired by ntru.js that used to provide an NTRU JS binding.

Playground

It is possible to test the bindings, to compare them in real-world conditions on this playground.

How to download pre-built bindings and NPM packages

Pre-built bindings are available on the playground.

How to build

  • sudo apt install emscripten
  • npm ci
  • make clean
  • make kem-<the KEM algorithm you want to build> or make sign-<the signature algorithm you want to build>
  • All bindings can be built using make all

The output directory is docs/bin/ and each output binding is made of a JS module and its associated WebAssembly file, a browser package, and a node package.

How to use

Key Encapsulation

import kemBuilder from 'pqc-kem-<algoName>.js'

async function run() {
    const kem = await kemBuilder();
    
    const { publicKey, privateKey } = await kem.keypair();
    const { ciphertext, sharedSecret: sharedSecretA } = await kem.encapsulate(publicKey);
    const { sharedSecret: sharedSecretB } = await kem.decapsulate(ciphertext, privateKey);
    // sharedSecretA === sharedSecretB
}

run();

Signature

import signBuilder from 'pqc-sign-<algoName>.js'

async function run() {
    const sign = await signBuilder();
    
    const message = new Uint8Array([0x44, 0x61, 0x73, 0x68, 0x6c, 0x61, 0x6e, 0x65]);
    
    const { publicKey, privateKey } = await sign.keypair();
    const { signature } = await sign.sign(message, privateKey);
    const validSignature = await sign.verify(signature, message, publicKey);
    // validSignature === true
}

run();

Disable WebAssembly execution

The first optional parameter of the builders is set to true is you want to disable WebAssembly execution.

If it is set to false, the fallback JavaScript may still be used if the WebAssembly fails.

Change the path of the WebAssembly

The second optional parameter of the builders is the path to the WebAssembly file.

Implementation notes

  • Random generation is provided by libsodium that is using crypto.randomBytes.
  • SHA-2 and AES implementations are provided by SubtleCrypto that is an implementation of Web Crypto API. This may slow down the execution of the bindings because of the asynchronous calls to SubtleCrypto, even more when AES-ECB is used because in this case AES-CTR is called for each block.
  • SHA-2 PQClean implementation is still used by sphincs-sha256-* bindings because they are using incremental version of sha256 that do not exist in Web Crypto API.
  • SHA-3 PQClean implementation is still used by NTRU, Kyber, SABER, FrodoKEM and McEliece-Classic because there are no implementations in Web Crypto API.

版本与发布记录

@dashlane/pqc-kem-kyber512-browser 共发布 1 个版本,首次发布于 2022/07/19;过去 12 个月发布了 0 个版本。

版本发布日期距今
1.0.0latest2022/07/194 年前

关于 @dashlane/pqc-kem-kyber512-browser 的常见问题

@dashlane/pqc-kem-kyber512-browser 是什么?

JavaScript wrapper generator of WebAssembly builds of each round-3 finalists of NIST Post-Quantum Cryptography Competition

如何安装 @dashlane/pqc-kem-kyber512-browser?

在项目目录运行 npm install @dashlane/pqc-kem-kyber512-browser,或使用 pnpm add / yarn add / bun add。

@dashlane/pqc-kem-kyber512-browser 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dashlane/pqc-kem-kyber512-browser 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dashlane/pqc-kem-kyber512-browser 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=16.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@dashlane/pqc-kem-kyber512-browser 可以商用吗?

@dashlane/pqc-kem-kyber512-browser 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@dashlane/pqc-kem-kyber512-browser 的下载量有多少?

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

@dashlane/pqc-kem-kyber512-browser 还在维护吗?

最新版本 1.0.0 发布于 2022/07/19(4 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/07/19。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。