cloudflare/zkp-ecdsa

GitHub: cloudflare/zkp-ecdsa

Cloudflare 开源的 TypeScript 零知识证明库,允许在不暴露具体公钥的前提下证明对 ECDSA-P256 签名的知识。

Stars: 227 | Forks: 19

[![NPM](https://img.shields.io/npm/v/@cloudflare/zkp-ecdsa?style=plastic)](https://www.npmjs.com/package/@cloudflare/zkp-ecdsa) [![NPM](https://img.shields.io/npm/l/@cloudflare/zkp-ecdsa?style=plastic)](LICENSE.txt) [![DOI](https://zenodo.org/badge/DOI/10.1007/978-3-030-99277-4_4.svg)](https://doi.org/10.1007/978-3-030-99277-4_4) [![NPM](https://nodei.co/npm/@cloudflare/zkp-ecdsa.png)](https://www.npmjs.com/package/@cloudflare/zkp-ecdsa) # zkp-ecdsa:ZKAttest 的 Typescript 实现 **ZKAttest** 用于证明知晓存储在列表中的众多公钥之一对应的 ECDSA-P256 签名,且不透露具体是使用哪个公钥签署的消息。 | [用法](#usage) | [开发](#development) | [引用本文](#citation) | [未来工作](#future-work) | |--|--|--|--| ### 用法 请按照以下简短指南使用 ZKAttest 证明。 #### 步骤 1 假设你已经拥有使用 ECDSA (P-256) 生成的消息签名。否则,请按如下方式创建签名: ``` // Message to be signed. const msg = new TextEncoder().encode('kilroy was here'); // Generate a keypair for signing. const keyPair = await crypto.subtle.generateKey( { name: 'ECDSA', namedCurve: 'P-256' }, true, [ 'sign', 'verify'], ); // Sign a message as usual. const signature = new Uint8Array( await crypto.subtle.sign( { name: 'ECDSA', hash: 'SHA-256' }, keyPair.privateKey, msg, ) ); ``` #### 步骤 2 然后,将你的公钥插入到一个密钥环中。这可以将你的公钥隐藏在密钥环背后。(在此示例中,假设该列表是由有效的密钥生成的)。 ``` import { keyToInt } from '@cloudflare/zkp-ecdsa' // Add the public key to an existing ring of keys, const listKeys = [BigInt(4), BigInt(5), BigInt(6), BigInt(7), BigInt(8)]; listKeys.unshift(await keyToInt(keyPair.publicKey)); ``` #### 步骤 3 现在,创建一个 **ZKAttest 知识证明**,表明: - 该签名是使用私钥生成的,并且 - 该公钥位于密钥环中。 此证明不会透露在签名期间使用了哪个公钥。 ``` import { generateParamsList, proveSignatureList } from '@cloudflare/zkp-ecdsa' // Create a zero-knowledge proof about the signature. const params = generateParamsList(); const msgHash = new Uint8Array(await crypto.subtle.digest('SHA-256', msg)); const zkAttestProof = await proveSignatureList( params, msgHash, signature, keyPair.publicKey, 0, // position of the public key in the list. listKeys ); ``` #### 步骤 4 此后,任何人都可以验证该证明是否有效,这意味着该消息是由 ECDSA 密钥对的持有者签署的,但不会确切识别出使用密钥环中的哪个密钥来生成该证明。请不要披露原始签名,因为它已经嵌入在证明内部了。 ``` import { verifySignatureList } from '@cloudflare/zkp-ecdsa' // Verify that zero-knowledge proof is valid. const valid = await verifySignatureList(params, msgHash, listKeys, zkAttestProof) console.assert(valid == true) ``` 以上就是全部内容。 ### 引用 本软件库是 _["ZKAttest: Ring and Group Signatures for Existing ECDSA Keys"](https://doi.org/10.1007/978-3-030-99277-4_4)_ 文章的一部分,该文章由 Armando Faz Hernández、Watson Ladd 和 Deepak Maram 撰写,发表在 [Selected Areas in Cryptography (SAC 2021)](https://www.sac2021.ca/) 上。 你可以在 [research.cloudflare.com](https://research.cloudflare.com/publications/Faz-Hernandez2021/) 或 [IACR ePrint 2021/1183](https://eprint.iacr.org/2021/1183) 下载该论文的副本。 要引用此库,请使用以下格式之一,并更新你访问此项目时的版本和日期。 **APA 格式** Faz-Hernández, A., Ladd, W., Maram, D. (2021). ZKAttest: Ring and Group Signatures for Existing ECDSA Keys. In: AlTawy, R., Hülsing, A. (eds) Selected Areas in Cryptography. SAC 2021. Available at https://github.com/cloudflare/zkp-ecdsa. v0.2.6 Accessed Jan 2026. **BibTex 源码** ``` @inproceedings{zkattest, doi = {10.1007/978-3-030-99277-4_4}, title = {ZKAttest: Ring and Group Signatures for Existing ECDSA Keys}, author = {Faz-Hernández, Armando and Ladd, Watson and Maram, Deepak}, booktitle = {Selected Areas in Cryptography}, editor = {AlTawy, Riham and Hülsing, Andreas}, publisher = {Springer International Publishing}, address = {Cham}, isbn = {978-3-030-99277-4}, pages = {68--83}, month = {oct}, year = {2021}, note = {Available at \url{https://github.com/cloudflare/zkp-ecdsa}. v0.2.6 Accessed Jan 2026}, } ``` **CFF 格式** 请查看随附的 [CITATION.cff](CITATION.cff) 文件。 ### 开发 | 任务 | NPM 脚本 | |--|--| | 安装 | `$ npm ci` | | 构建 | `$ npm run build` | | 单元测试 | `$ npm run test` | | 基准测试 | `$ npm run bench` | | 火焰图性能分析 | `$ npm run flame` | | 代码 Lint | `$ npm run lint` | | 代码格式化 | `$ npm run format` | | 打包库 | `$ npm run bundle` | ### 未来工作 - 加速证明验证。 - 使用其他编程语言实现该证明。 - 移除对原生 Bignum 的依赖。 ### 许可证 本项目基于 [Apache 2.0 许可证](LICENSE.txt) 授权。
标签:ECDSA, MITM代理, TypeScript, 安全插件, 密码学, 手动系统调用, 数据可视化, 环签名, 网络安全, 自动化攻击, 隐私保护, 零知识证明