as-chacha20poly1305
AssemblyScript implementation of chacha20poly1305, it's 20% - 60% faster compared to stablelib with no memory allocation in the middle.
This was ported from the typescript version https://github.com/StableLib/stablelib/tree/master/packages/chacha20poly1305
Usage
yarn add @chainsafe/as-chacha20poly1305
const ctx = newInstance();
const asImpl = new ChaCha20Poly1305(ctx);
const key = new Uint8Array(crypto.randomBytes(KEY_LENGTH));
const nonce = new Uint8Array(crypto.randomBytes(NONCE_LENGTH));
const plainText = new Uint8Array(crypto.randomBytes(512));
const ad = new Uint8Array(crypto.randomBytes(32))
const asSealed = asImpl.seal(key, nonce, plainText, ad);
// overwrite sealed to save memory allocation
const plainText2 = asImpl.open(key, nonce, sealed, true, ad);
expect(plainText2).to.be.deep.equal(plainText);
License
Apache 2.0
关于 @chainsafe/as-chacha20poly1305 的常见问题
@chainsafe/as-chacha20poly1305 是什么?
An AssemblyScript implementation of chacha20poly1305
如何安装 @chainsafe/as-chacha20poly1305?
在项目目录运行 npm install @chainsafe/as-chacha20poly1305,或使用 pnpm add / yarn add / bun add。
@chainsafe/as-chacha20poly1305 支持 TypeScript 吗?
支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。
@chainsafe/as-chacha20poly1305 支持 ESM 还是 CommonJS?
以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。
@chainsafe/as-chacha20poly1305 可以商用吗?
@chainsafe/as-chacha20poly1305 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。
@chainsafe/as-chacha20poly1305 的下载量有多少?
根据 npm 官方下载统计,@chainsafe/as-chacha20poly1305 在 2026/10/10 – 2026/11/08 这 30 天内被下载 313,849 次,日均约 10,462 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。
@chainsafe/as-chacha20poly1305 还在维护吗?
最新版本 0.1.0 发布于 2022/11/22(3 年前);至今共发布 1 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/11/22。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。