forgesworn/ring-sig

GitHub: forgesworn/ring-sig

基于 secp256k1 椭圆曲线实现 SAG 和 LSAG 环签名算法,用于在不泄露身份的情况下证明群组成员资格。

Stars: 0 | Forks: 0

# @forgesworn/ring-sig **Nostr:** [`npub1mgvlrnf5hm9yf0n5mf9nqmvarhvxkc6remu5ec3vf8r0txqkuk7su0e7q2`](https://njump.me/npub1mgvlrnf5hm9yf0n5mf9nqmvarhvxkc6remu5ec3vf8r0txqkuk7su0e7q2) [![npm](https://img.shields.io/npm/v/@forgesworn/ring-sig)](https://www.npmjs.com/package/@forgesworn/ring-sig) [![CI](https://static.pigsec.cn/wp-content/uploads/repos/2026/04/d5033602d4174009.svg)](https://github.com/forgesworn/ring-sig/actions/workflows/ci.yml) [![GitHub Sponsors](https://img.shields.io/github/sponsors/TheCryptoDonkey?logo=githubsponsors&color=ea4aaa&label=Sponsor)](https://github.com/sponsors/TheCryptoDonkey) 基于 secp256k1 的 SAG 和 LSAG 环签名。 **在不泄露身份的情况下证明成员资格。** ## 用例 - **匿名成员资格证明** — 证明您是 N 个密钥持有者之一,但不透露具体是哪一个 - **举报** — 以“该组织成员”的身份签署声明,而不暴露自身身份 - **隐私保护认证** — “一位持证专业人员已验证此内容”而不指名具体专业人员(可与 [nostr-attestations](https://github.com/forgesworn/nostr-attestations) 配合使用以实现链上匿名背书) - **双重行为预防** (LSAG) — 检测同一密钥是否在同一上下文中签名了两次,而不会在不同上下文之间链接签名 ## 安装 ``` npm install @forgesworn/ring-sig ``` ## 使用 ### SAG — 自发匿名组 签名 ``` import { ringSign, ringVerify } from '@forgesworn/ring-sig'; // A ring of x-only public keys (32 bytes, hex) const ring = [pubkey0, pubkey1, pubkey2, pubkey3]; // Sign as ring member at index 2 const sig = ringSign('my message', ring, 2, privateKey2); // Anyone can verify the signature is from a ring member const valid = ringVerify(sig); // true ``` ### LSAG — 可链接 SAG(通过密钥图像检测双重行为) ``` import { lsagSign, lsagVerify, computeKeyImage, hasDuplicateKeyImage } from '@forgesworn/ring-sig'; const electionId = 'vote-2026-q1'; const ring = [pubkey0, pubkey1, pubkey2]; // Sign const sig = lsagSign('candidate-A', ring, 0, privateKey0, electionId); // Verify const valid = lsagVerify(sig); // true // Detect double-signing: key images are deterministic per (key, electionId) pair const keyImage = computeKeyImage(privateKey0, pubkey0, electionId); const isDuplicate = hasDuplicateKeyImage(keyImage, existingKeyImages); ``` ## 域分隔符 `ringSign` 和 `lsagSign` 均接受可选的 `domain` 参数(默认为 `'sag-v1'` / `'lsag-v1'`)。如果您需要跨协议隔离,请传入自定义域: ``` const sig = ringSign(message, ring, index, privateKey, 'my-app-v1'); ``` ## 错误类 - `RingSignatureError` — 基类 - `ValidationError` — 输入格式错误、超出范围 - `CryptoError` — 无效密钥、操作失败 ## 密码学 - **SAG** (Spontaneous Anonymous Group):基于 Schnorr 的环签名。签名大小相对于环为 O(n)。 - **LSAG** (Linkable SAG):增加确定性密钥图像 `I = x * H_p(P || context)`。同一密钥在同一上下文下的签名会产生相同的密钥图像,从而实现双重行为检测,同时不具备跨上下文链接能力。 - 域分隔:`'sag-v1'`、`'lsag-v1'`、`'secp256k1-hash-to-point-v1'` - 最大环大小:1000 个成员 ## ForgeSworn 工具套件的一部分 [ForgeSworn](https://forgesworn.dev) 为 Nostr 构建开源加密身份、支付和协调工具。 | 库 | 功能 | |---------|-------------| | [nsec-tree](https://github.com/forgesworn/nsec-tree) | 确定性子身份派生 | | [ring-sig](https://github.com/forgesworn/ring-sig) | secp256k1 上的 SAG/LSAG 环签名 | | [range-proof](https://github.com/forgesworn/range-proof) | Pedersen 承诺范围证明 | | [canary-kit](https://github.com/forgesworn/canary-kit) | 抗胁迫口头验证 | | [spoken-token](https://github.com/forgesworn/spoken-token) | 人类可读的验证令牌 | | [toll-booth](https://github.com/forgesworn/toll-booth) | L402 支付中间件 | | [geohash-kit](https://github.com/forgesworn/geohash-kit) | 带多边形覆盖的 Geohash 工具包 | | [nostr-attestations](https://github.com/forgesworn/nostr-attestations) | NIP-VA 可验证认证 | | [dominion](https://github.com/forgesworn/dominion) | 基于纪元的加密访问控制 | | [nostr-veil](https://github.com/forgesworn/nostr-veil) | 隐私保护信任网络 | ## 许可证 MIT
标签:Cilium, CMS安全, GNU通用公共许可证, JavaScript, LSAG, MITM代理, Node.js, Nostr, NPM, SAG, secp256k1, TypeScript, 举报保护, 以太坊兼容, 区块链, 匿名签名, 去中心化身份, 可链接签名, 安全插件, 密码学, 密钥图像, 开源库, 成员资格证明, 手动系统调用, 搜索引擎爬虫, 数据可视化, 环签名, 电子投票, 网络安全, 自动化攻击, 身份隐藏, 防双花, 隐私保护, 零知识证明