mirror of
https://github.com/semaphore-protocol/semaphore.git
synced 2026-01-12 08:07:55 -05:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b93acc884b | ||
|
|
c9e565a445 | ||
|
|
6cea8c5dcc | ||
|
|
5bd7cd93f7 | ||
|
|
da1b4f6d8f | ||
|
|
124f627d39 | ||
|
|
199dca2a3b | ||
|
|
51accfc939 | ||
|
|
1696294881 | ||
|
|
c85b758120 | ||
|
|
12fd0f7a80 | ||
|
|
78da99055d | ||
|
|
77e4770b53 | ||
|
|
799afc82f4 |
22
README.md
22
README.md
@@ -217,6 +217,28 @@ The core of the Semaphore protocol is in the [circuit logic](/packages/circuits/
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<a href="/packages/heyauthn">
|
||||
@semaphore-protocol/heyauthn
|
||||
</a>
|
||||
<a href="https://semaphore-protocol.github.io/semaphore/heyauthn">
|
||||
(docs)
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<!-- NPM version -->
|
||||
<a href="https://npmjs.org/package/@semaphore-protocol/heyauthn">
|
||||
<img src="https://img.shields.io/npm/v/@semaphore-protocol/heyauthn.svg?style=flat-square" alt="NPM version" />
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<!-- Downloads -->
|
||||
<a href="https://npmjs.org/package/@semaphore-protocol/heyauthn">
|
||||
<img src="https://img.shields.io/npm/dm/@semaphore-protocol/heyauthn.svg?style=flat-square" alt="Downloads" />
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tbody>
|
||||
|
||||
</table>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/cli-template-hardhat",
|
||||
"version": "3.3.0",
|
||||
"version": "3.5.0",
|
||||
"description": "Semaphore Hardhat template.",
|
||||
"license": "Unlicense",
|
||||
"files": [
|
||||
@@ -36,10 +36,10 @@
|
||||
"@nomicfoundation/hardhat-toolbox": "^2.0.0",
|
||||
"@nomiclabs/hardhat-ethers": "^2.0.0",
|
||||
"@nomiclabs/hardhat-etherscan": "^3.0.0",
|
||||
"@semaphore-protocol/group": "3.3.0",
|
||||
"@semaphore-protocol/hardhat": "3.3.0",
|
||||
"@semaphore-protocol/identity": "3.3.0",
|
||||
"@semaphore-protocol/proof": "3.3.0",
|
||||
"@semaphore-protocol/group": "3.5.0",
|
||||
"@semaphore-protocol/hardhat": "3.5.0",
|
||||
"@semaphore-protocol/identity": "3.5.0",
|
||||
"@semaphore-protocol/proof": "3.5.0",
|
||||
"@typechain/ethers-v5": "^10.1.0",
|
||||
"@typechain/hardhat": "^6.1.2",
|
||||
"@types/chai": "^4.2.0",
|
||||
@@ -58,7 +58,7 @@
|
||||
"typescript": ">=4.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@semaphore-protocol/contracts": "3.3.0"
|
||||
"@semaphore-protocol/contracts": "3.5.0"
|
||||
},
|
||||
"config": {
|
||||
"solidity": {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/cli",
|
||||
"type": "module",
|
||||
"version": "3.3.0",
|
||||
"version": "3.5.0",
|
||||
"description": "A command line tool to set up your Semaphore project and get group data.",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
@@ -41,7 +41,7 @@
|
||||
"typedoc": "^0.22.11"
|
||||
},
|
||||
"dependencies": {
|
||||
"@semaphore-protocol/data": "3.3.0",
|
||||
"@semaphore-protocol/data": "3.5.0",
|
||||
"axios": "^1.3.2",
|
||||
"boxen": "^7.0.1",
|
||||
"chalk": "^5.1.2",
|
||||
|
||||
@@ -14,7 +14,7 @@ import Spinner from "./spinner.js"
|
||||
const packagePath = `${dirname(fileURLToPath(import.meta.url))}/..`
|
||||
const { description, version } = JSON.parse(readFileSync(`${packagePath}/package.json`, "utf8"))
|
||||
|
||||
const supportedNetworks = ["sepolia", "goerli", "mumbai", "optimism-goerli", "arbitrum"]
|
||||
const supportedNetworks = ["sepolia", "goerli", "mumbai", "optimism-goerli", "arbitrum", "arbitrum-goerli"]
|
||||
|
||||
program
|
||||
.name("semaphore")
|
||||
|
||||
@@ -89,8 +89,8 @@ library Pairing {
|
||||
/// @return r the product of a point on G1 and a scalar, i.e.
|
||||
/// p == p.scalar_mul(1) and p.addition(p) == p.scalar_mul(2) for all points p.
|
||||
function scalar_mul(G1Point memory p, uint256 s) public view returns (G1Point memory r) {
|
||||
// By EIP-196 the values p.X and p.Y are verified to less than the BASE_MODULUS and
|
||||
// form a valid point on the curve. But the scalar is not verified, so we do that explicitelly.
|
||||
// By EIP-196 the values p.X and p.Y are verified to be less than the BASE_MODULUS and
|
||||
// form a valid point on the curve. But the scalar is not verified, so we do that explicitly.
|
||||
if (s >= SCALAR_MODULUS) {
|
||||
revert InvalidProof();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/contracts",
|
||||
"version": "3.3.0",
|
||||
"version": "3.5.0",
|
||||
"description": "Semaphore contracts to manage groups and broadcast anonymous signals.",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/data",
|
||||
"version": "3.3.0",
|
||||
"version": "3.5.0",
|
||||
"description": "A library to query Semaphore contracts.",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.node.js",
|
||||
|
||||
@@ -275,7 +275,7 @@ export default class SemaphoreEthers {
|
||||
signal: event.signal.toString(),
|
||||
merkleTreeRoot: event.merkleTreeRoot.toString(),
|
||||
externalNullifier: event.externalNullifier.toString(),
|
||||
nullifierHash: event.externalNullifier.toString()
|
||||
nullifierHash: event.nullifierHash.toString()
|
||||
}))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/group",
|
||||
"version": "3.3.0",
|
||||
"version": "3.5.0",
|
||||
"description": "A library to create and manage Semaphore groups.",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.node.js",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/hardhat",
|
||||
"version": "3.3.0",
|
||||
"version": "3.5.0",
|
||||
"description": "A Semaphore Hardhat plugin to deploy verifiers and Semaphore contract.",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.node.js",
|
||||
@@ -38,7 +38,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@nomiclabs/hardhat-ethers": "^2.1.1",
|
||||
"@semaphore-protocol/contracts": "3.3.0",
|
||||
"@semaphore-protocol/contracts": "3.5.0",
|
||||
"circomlibjs": "^0.0.8",
|
||||
"ethers": "^5.7.1",
|
||||
"hardhat-dependency-compiler": "^1.1.3"
|
||||
|
||||
@@ -112,7 +112,8 @@ generateProof(identity, group, group.id, "42", {
|
||||
|
||||
## Authors
|
||||
|
||||
- @vb7401
|
||||
- @rrrliu
|
||||
- @emmaguo13
|
||||
- @sehyunc
|
||||
- [Vivek Bhupatiraju](https://github.com/vb7401)
|
||||
- [Richard Liu](https://github.com/rrrliu)
|
||||
- [emma](https://github.com/emmaguo13)
|
||||
- [Sehyun Chung](https://github.com/sehyunc)
|
||||
- [Enrico Bottazzi](https://github.com/enricobottazzi)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/heyauthn",
|
||||
"version": "3.3.0",
|
||||
"version": "3.5.0",
|
||||
"description": "A library to allow developers to create and manage Semaphore identities using WebAuthn",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.node.js",
|
||||
@@ -35,7 +35,7 @@
|
||||
"typedoc": "^0.22.11"
|
||||
},
|
||||
"dependencies": {
|
||||
"@semaphore-protocol/identity": "3.3.0",
|
||||
"@semaphore-protocol/identity": "3.5.0",
|
||||
"@simplewebauthn/browser": "7.2.0",
|
||||
"@simplewebauthn/server": "7.2.0"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/identity",
|
||||
"version": "3.3.0",
|
||||
"version": "3.5.0",
|
||||
"description": "A library to create Semaphore identities.",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.node.js",
|
||||
|
||||
@@ -19,6 +19,7 @@ describe("Identity", () => {
|
||||
|
||||
expect(identity1.trapdoor).not.toBe(identity2.getTrapdoor())
|
||||
expect(identity1.nullifier).not.toBe(identity2.getNullifier())
|
||||
expect(identity1.secret).not.toBe(identity2.getSecret())
|
||||
expect(identity1.commitment).not.toBe(identity2.getCommitment())
|
||||
})
|
||||
|
||||
@@ -82,8 +83,18 @@ describe("Identity", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("# generateCommitment", () => {
|
||||
it("Should generate an identity commitment", () => {
|
||||
describe("# getSecret", () => {
|
||||
it("Should return an identity secret", () => {
|
||||
const { secret } = new Identity("message")
|
||||
|
||||
expect(secret.toString()).toBe(
|
||||
"17452394798940441025978193762953691632066258438336130543532009665042636950194"
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe("# getCommitment", () => {
|
||||
it("Should return an identity commitment", () => {
|
||||
const { commitment } = new Identity("message")
|
||||
|
||||
expect(commitment.toString()).toBe(
|
||||
|
||||
@@ -1,11 +1,14 @@
|
||||
import { BigNumber } from "@ethersproject/bignumber"
|
||||
import hash from "js-sha512"
|
||||
import { poseidon1 } from "poseidon-lite/poseidon1"
|
||||
import { poseidon2 } from "poseidon-lite/poseidon2"
|
||||
import checkParameter from "./checkParameter"
|
||||
import { generateCommitment, genRandomNumber, isJsonArray } from "./utils"
|
||||
import { genRandomNumber, isJsonArray } from "./utils"
|
||||
|
||||
export default class Identity {
|
||||
private _trapdoor: bigint
|
||||
private _nullifier: bigint
|
||||
private _secret: bigint
|
||||
private _commitment: bigint
|
||||
|
||||
/**
|
||||
@@ -16,7 +19,8 @@ export default class Identity {
|
||||
if (identityOrMessage === undefined) {
|
||||
this._trapdoor = genRandomNumber()
|
||||
this._nullifier = genRandomNumber()
|
||||
this._commitment = generateCommitment(this._nullifier, this._trapdoor)
|
||||
this._secret = poseidon2([this._nullifier, this._trapdoor])
|
||||
this._commitment = poseidon1([this._secret])
|
||||
|
||||
return
|
||||
}
|
||||
@@ -25,10 +29,11 @@ export default class Identity {
|
||||
|
||||
if (!isJsonArray(identityOrMessage)) {
|
||||
const h = hash.sha512(identityOrMessage).padStart(128, "0")
|
||||
// alt_bn128 is 253.6 bits, so we can safely use 253 bits
|
||||
// alt_bn128 is 253.6 bits, so we can safely use 253 bits.
|
||||
this._trapdoor = BigInt(`0x${h.slice(64)}`) >> BigInt(3)
|
||||
this._nullifier = BigInt(`0x${h.slice(0, 64)}`) >> BigInt(3)
|
||||
this._commitment = generateCommitment(this._nullifier, this._trapdoor)
|
||||
this._secret = poseidon2([this._nullifier, this._trapdoor])
|
||||
this._commitment = poseidon1([this._secret])
|
||||
|
||||
return
|
||||
}
|
||||
@@ -37,7 +42,8 @@ export default class Identity {
|
||||
|
||||
this._trapdoor = BigNumber.from(trapdoor).toBigInt()
|
||||
this._nullifier = BigNumber.from(nullifier).toBigInt()
|
||||
this._commitment = generateCommitment(this._nullifier, this._trapdoor)
|
||||
this._secret = poseidon2([this._nullifier, this._trapdoor])
|
||||
this._commitment = poseidon1([this._secret])
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,6 +78,22 @@ export default class Identity {
|
||||
return this._nullifier
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identity secret.
|
||||
* @returns The identity secret.
|
||||
*/
|
||||
public get secret(): bigint {
|
||||
return this._secret
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identity secret.
|
||||
* @returns The identity secret.
|
||||
*/
|
||||
public getSecret(): bigint {
|
||||
return this._secret
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the identity commitment.
|
||||
* @returns The identity commitment.
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import { BigNumber } from "@ethersproject/bignumber"
|
||||
import { randomBytes } from "@ethersproject/random"
|
||||
import { poseidon1 } from "poseidon-lite/poseidon1"
|
||||
import { poseidon2 } from "poseidon-lite/poseidon2"
|
||||
|
||||
/**
|
||||
* Generates a random big number.
|
||||
@@ -12,16 +10,6 @@ export function genRandomNumber(numberOfBytes = 31): bigint {
|
||||
return BigNumber.from(randomBytes(numberOfBytes)).toBigInt()
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates the identity commitment from trapdoor and nullifier.
|
||||
* @param nullifier The identity nullifier.
|
||||
* @param trapdoor The identity trapdoor.
|
||||
* @returns identity commitment
|
||||
*/
|
||||
export function generateCommitment(nullifier: bigint, trapdoor: bigint): bigint {
|
||||
return poseidon1([poseidon2([nullifier, trapdoor])])
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a string is a JSON.
|
||||
* @param jsonString The JSON string.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/proof",
|
||||
"version": "3.3.0",
|
||||
"version": "3.5.0",
|
||||
"description": "A library to generate and verify Semaphore proofs.",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.node.js",
|
||||
@@ -37,8 +37,8 @@
|
||||
"typedoc": "^0.22.11"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@semaphore-protocol/group": "3.3.0",
|
||||
"@semaphore-protocol/identity": "3.3.0"
|
||||
"@semaphore-protocol/group": "3.5.0",
|
||||
"@semaphore-protocol/identity": "3.5.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ethersproject/bignumber": "^5.5.0",
|
||||
|
||||
@@ -1 +1 @@
|
||||
db9ac44677af043f133407f3ec845b045c7ad6fa
|
||||
23fe56d2949cd7a272f84fdb2bad9bde366662d7
|
||||
Reference in New Issue
Block a user