mirror of
https://github.com/semaphore-protocol/semaphore.git
synced 2026-01-15 01:28:02 -05:00
Compare commits
14 Commits
v4.0.0-alp
...
v4.0.0-alp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05b9386ec3 | ||
|
|
1555b3e5a5 | ||
|
|
fc78a69312 | ||
|
|
fad565c00a | ||
|
|
dcb217c085 | ||
|
|
afc13b7e93 | ||
|
|
8b5f95499c | ||
|
|
bca72c6f80 | ||
|
|
269a1b4fc0 | ||
|
|
b1c18bb1f8 | ||
|
|
8e604514c8 | ||
|
|
9712d21956 | ||
|
|
5438031470 | ||
|
|
2e0a671621 |
File diff suppressed because one or more lines are too long
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"sepolia": {
|
||||
"Semaphore": {
|
||||
"address": "0xb25E63B115Ffba085FeCbf196a8e720F85DC351c",
|
||||
"startBlock": 5145333
|
||||
"address": "0x5B8e7cC7bAC61A4b952d472b67056B2f260ba6dc",
|
||||
"startBlock": 5150903
|
||||
}
|
||||
},
|
||||
"mumbai": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/circuits",
|
||||
"version": "4.0.0-alpha.1",
|
||||
"version": "4.0.0-alpha.2",
|
||||
"description": "Semaphore Circom circuits to generate zero-knowledge proofs.",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
@@ -35,5 +35,5 @@
|
||||
"mocha": "^10.2.0",
|
||||
"poseidon-lite": "^0.2.0"
|
||||
},
|
||||
"stableVersion": "4.0.0-alpha"
|
||||
"stableVersion": "4.0.0-alpha.1"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/cli-template-contracts-hardhat",
|
||||
"version": "4.0.0-alpha.1",
|
||||
"version": "4.0.0-alpha.2",
|
||||
"description": "Semaphore Hardhat template.",
|
||||
"license": "Unlicense",
|
||||
"files": [
|
||||
@@ -35,10 +35,10 @@
|
||||
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
|
||||
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
|
||||
"@nomicfoundation/hardhat-verify": "^2.0.0",
|
||||
"@semaphore-protocol/group": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/hardhat": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/identity": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/proof": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/group": "4.0.0-alpha.2",
|
||||
"@semaphore-protocol/hardhat": "4.0.0-alpha.2",
|
||||
"@semaphore-protocol/identity": "4.0.0-alpha.2",
|
||||
"@semaphore-protocol/proof": "4.0.0-alpha.2",
|
||||
"@typechain/ethers-v6": "^0.5.0",
|
||||
"@typechain/hardhat": "^9.0.0",
|
||||
"@types/chai": "^4.2.0",
|
||||
@@ -55,12 +55,12 @@
|
||||
"typescript": "^5.3.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@semaphore-protocol/contracts": "4.0.0-alpha.1"
|
||||
"@semaphore-protocol/contracts": "4.0.0-alpha.2"
|
||||
},
|
||||
"config": {
|
||||
"solidity": {
|
||||
"version": "0.8.4"
|
||||
}
|
||||
},
|
||||
"stableVersion": "4.0.0-alpha"
|
||||
"stableVersion": "4.0.0-alpha.1"
|
||||
}
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
|
||||
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
|
||||
"@nomicfoundation/hardhat-verify": "^2.0.0",
|
||||
"@semaphore-protocol/group": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/hardhat": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/identity": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/proof": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/group": "4.0.0-alpha.2",
|
||||
"@semaphore-protocol/hardhat": "4.0.0-alpha.2",
|
||||
"@semaphore-protocol/identity": "4.0.0-alpha.2",
|
||||
"@semaphore-protocol/proof": "4.0.0-alpha.2",
|
||||
"@typechain/ethers-v6": "^0.5.0",
|
||||
"@typechain/hardhat": "^9.0.0",
|
||||
"@types/chai": "^4.2.0",
|
||||
@@ -39,6 +39,6 @@
|
||||
"typechain": "^8.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@semaphore-protocol/contracts": "4.0.0-alpha.1"
|
||||
"@semaphore-protocol/contracts": "4.0.0-alpha.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@next/font": "13.0.3",
|
||||
"@semaphore-protocol/data": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/group": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/identity": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/proof": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/data": "4.0.0-alpha.2",
|
||||
"@semaphore-protocol/group": "4.0.0-alpha.2",
|
||||
"@semaphore-protocol/identity": "4.0.0-alpha.2",
|
||||
"@semaphore-protocol/proof": "4.0.0-alpha.2",
|
||||
"@types/react": "18.0.25",
|
||||
"@types/react-dom": "18.0.8",
|
||||
"dotenv": "^16.0.3",
|
||||
|
||||
@@ -41,6 +41,11 @@ export default function ProofsPage() {
|
||||
return
|
||||
}
|
||||
|
||||
if (_users && _users.length < 2) {
|
||||
alert("No anonymity in a group of one!")
|
||||
return
|
||||
}
|
||||
|
||||
const feedback = prompt("Please enter your feedback:")
|
||||
|
||||
if (feedback && _users) {
|
||||
@@ -49,7 +54,7 @@ export default function ProofsPage() {
|
||||
setLogs(`Posting your anonymous feedback...`)
|
||||
|
||||
try {
|
||||
const group = new Group(env.GROUP_ID)
|
||||
const group = new Group()
|
||||
|
||||
const message = encodeBytes32String(feedback)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/cli-template-monorepo-ethers",
|
||||
"version": "4.0.0-alpha.1",
|
||||
"version": "4.0.0-alpha.2",
|
||||
"description": "Semaphore Hardhat + Next.js + SemaphoreEthers template.",
|
||||
"license": "Unlicense",
|
||||
"files": [
|
||||
@@ -40,5 +40,5 @@
|
||||
"ts-node": "^10.8.1",
|
||||
"typescript": "^4.7.3"
|
||||
},
|
||||
"stableVersion": "4.0.0-alpha"
|
||||
"stableVersion": "4.0.0-alpha.1"
|
||||
}
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
"@nomicfoundation/hardhat-network-helpers": "^1.0.0",
|
||||
"@nomicfoundation/hardhat-toolbox": "^4.0.0",
|
||||
"@nomicfoundation/hardhat-verify": "^2.0.0",
|
||||
"@semaphore-protocol/group": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/hardhat": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/identity": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/proof": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/group": "4.0.0-alpha.2",
|
||||
"@semaphore-protocol/hardhat": "4.0.0-alpha.2",
|
||||
"@semaphore-protocol/identity": "4.0.0-alpha.2",
|
||||
"@semaphore-protocol/proof": "4.0.0-alpha.2",
|
||||
"@typechain/ethers-v6": "^0.5.0",
|
||||
"@typechain/hardhat": "^9.0.0",
|
||||
"@types/chai": "^4.2.0",
|
||||
@@ -39,6 +39,6 @@
|
||||
"typechain": "^8.3.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@semaphore-protocol/contracts": "4.0.0-alpha.1"
|
||||
"@semaphore-protocol/contracts": "4.0.0-alpha.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,10 +10,10 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@next/font": "13.0.3",
|
||||
"@semaphore-protocol/data": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/group": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/identity": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/proof": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/data": "4.0.0-alpha.2",
|
||||
"@semaphore-protocol/group": "4.0.0-alpha.2",
|
||||
"@semaphore-protocol/identity": "4.0.0-alpha.2",
|
||||
"@semaphore-protocol/proof": "4.0.0-alpha.2",
|
||||
"@types/react": "18.0.25",
|
||||
"@types/react-dom": "18.0.8",
|
||||
"dotenv": "^16.0.3",
|
||||
|
||||
@@ -41,6 +41,11 @@ export default function ProofsPage() {
|
||||
return
|
||||
}
|
||||
|
||||
if (_users && _users.length < 2) {
|
||||
alert("No anonymity in a group of one!")
|
||||
return
|
||||
}
|
||||
|
||||
const feedback = prompt("Please enter your feedback:")
|
||||
|
||||
if (feedback && _users) {
|
||||
@@ -49,7 +54,7 @@ export default function ProofsPage() {
|
||||
setLogs(`Posting your anonymous feedback...`)
|
||||
|
||||
try {
|
||||
const group = new Group(env.GROUP_ID)
|
||||
const group = new Group()
|
||||
|
||||
const message = encodeBytes32String(feedback)
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/cli-template-monorepo-subgraph",
|
||||
"version": "4.0.0-alpha.1",
|
||||
"version": "4.0.0-alpha.2",
|
||||
"description": "Semaphore Hardhat + Next.js + SemaphoreSubgraph template.",
|
||||
"license": "Unlicense",
|
||||
"files": [
|
||||
@@ -40,5 +40,5 @@
|
||||
"ts-node": "^10.8.1",
|
||||
"typescript": "^4.7.3"
|
||||
},
|
||||
"stableVersion": "4.0.0-alpha"
|
||||
"stableVersion": "4.0.0-alpha.1"
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<img src="https://img.shields.io/badge/project-Semaphore-blue.svg?style=flat-square">
|
||||
</a>
|
||||
<a href="https://github.com/semaphore-protocol/semaphore/blob/main/LICENSE">
|
||||
<img alt="Github license" src="https://img.shields.io/github/license/semaphore-protocol/semaphore.svg?style=flat-square">
|
||||
<img alt="NPM license" src="https://img.shields.io/npm/l/%40semaphore-protocol%2Fcli?style=flat-square">
|
||||
</a>
|
||||
<a href="https://www.npmjs.com/package/@semaphore-protocol/cli">
|
||||
<img alt="NPM version" src="https://img.shields.io/npm/v/@semaphore-protocol/cli?style=flat-square" />
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/cli",
|
||||
"type": "module",
|
||||
"version": "4.0.0-alpha.1",
|
||||
"version": "4.0.0-alpha.2",
|
||||
"description": "A command line tool to set up your Semaphore project and get group data.",
|
||||
"license": "MIT",
|
||||
"bin": {
|
||||
@@ -24,7 +24,6 @@
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node --loader ts-node/esm --no-warnings src/index.ts",
|
||||
"build:watch": "rollup -c rollup.config.ts -w --configPlugin typescript",
|
||||
"build": "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript",
|
||||
"prepublishOnly": "yarn build"
|
||||
},
|
||||
@@ -42,7 +41,7 @@
|
||||
"ts-node": "^10.9.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"@semaphore-protocol/data": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/data": "4.0.0-alpha.2",
|
||||
"axios": "^1.3.2",
|
||||
"boxen": "^7.0.1",
|
||||
"chalk": "^5.1.2",
|
||||
@@ -55,5 +54,5 @@
|
||||
"pacote": "^15.1.1",
|
||||
"semver": "^7.3.8"
|
||||
},
|
||||
"stableVersion": "4.0.0-alpha"
|
||||
"stableVersion": "4.0.0-alpha.1"
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ const banner = `#!/usr/bin/env node
|
||||
export default {
|
||||
input: "src/index.ts",
|
||||
output: [{ file: pkg.bin.semaphore, format: "es", banner }],
|
||||
external: ["url", "fs", "path", ...Object.keys(pkg.dependencies)],
|
||||
external: [...Object.keys(pkg.dependencies), "url", "fs", "path", "child_process"],
|
||||
plugins: [
|
||||
(typescript as any)({
|
||||
tsconfig: "./build.tsconfig.json",
|
||||
|
||||
@@ -98,7 +98,7 @@ program
|
||||
console.info(`\n ${logSymbols.success}`, `Your project is ready!\n`)
|
||||
console.info(` Please, install your dependencies by running:\n`)
|
||||
console.info(` ${chalk.cyan("cd")} ${projectDirectory}`)
|
||||
console.info(` ${chalk.cyan("npm i")}\n`)
|
||||
console.info(` ${chalk.cyan("yarn install")}\n`)
|
||||
|
||||
const { scripts } = JSON.parse(readFileSync(`${currentDirectory}/${projectDirectory}/package.json`, "utf8"))
|
||||
|
||||
@@ -107,7 +107,7 @@ program
|
||||
|
||||
console.info(
|
||||
`${Object.keys(scripts)
|
||||
.map((s) => ` ${chalk.cyan(`npm run ${s}`)}`)
|
||||
.map((s) => ` ${chalk.cyan(`yarn ${s}`)}`)
|
||||
.join("\n")}\n`
|
||||
)
|
||||
|
||||
@@ -189,8 +189,6 @@ program
|
||||
|
||||
group = await semaphoreEthers.getGroup(groupId)
|
||||
|
||||
group.admin = await semaphoreEthers.getGroupAdmin(groupId)
|
||||
|
||||
spinner.stop()
|
||||
} catch {
|
||||
spinner.stop()
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<img src="https://img.shields.io/badge/project-Semaphore-blue.svg?style=flat-square">
|
||||
</a>
|
||||
<a href="https://github.com/semaphore-protocol/semaphore/blob/main/LICENSE">
|
||||
<img alt="Github license" src="https://img.shields.io/github/license/semaphore-protocol/semaphore.svg?style=flat-square">
|
||||
<img alt="NPM license" src="https://img.shields.io/npm/l/%40semaphore-protocol%2Fcontracts?style=flat-square">
|
||||
</a>
|
||||
<a href="https://www.npmjs.com/package/@semaphore-protocol/contracts">
|
||||
<img alt="NPM version" src="https://img.shields.io/npm/v/@semaphore-protocol/contracts?style=flat-square" />
|
||||
|
||||
@@ -123,6 +123,11 @@ abstract contract SemaphoreGroups is ISemaphoreGroups {
|
||||
emit MemberRemoved(groupId, index, identityCommitment, merkleTreeRoot);
|
||||
}
|
||||
|
||||
/// @dev See {ISemaphoreGroups-getGroupAdmin}.
|
||||
function getGroupAdmin(uint256 groupId) public view virtual override returns (address) {
|
||||
return admins[groupId];
|
||||
}
|
||||
|
||||
/// @dev See {ISemaphoreGroups-hasMember}.
|
||||
function hasMember(uint256 groupId, uint256 identityCommitment) public view virtual override returns (bool) {
|
||||
return merkleTrees[groupId]._has(identityCommitment);
|
||||
|
||||
@@ -57,6 +57,11 @@ interface ISemaphoreGroups {
|
||||
/// @param merkleTreeRoot: New root hash of the tree.
|
||||
event MemberRemoved(uint256 indexed groupId, uint256 index, uint256 identityCommitment, uint256 merkleTreeRoot);
|
||||
|
||||
/// @dev Returns the address of the group admin.
|
||||
/// @param groupId: Id of the group.
|
||||
/// @return Address of the group admin.
|
||||
function getGroupAdmin(uint256 groupId) external view returns (address);
|
||||
|
||||
/// @dev Returns true if a member exists in a group.
|
||||
/// @param groupId: Id of the group.
|
||||
/// @param identityCommitment: Identity commitment.
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/contracts",
|
||||
"version": "4.0.0-alpha.1",
|
||||
"version": "4.0.0-alpha.2",
|
||||
"description": "Semaphore contracts to manage groups and broadcast anonymous signals.",
|
||||
"license": "MIT",
|
||||
"files": [
|
||||
@@ -32,5 +32,5 @@
|
||||
"dependencies": {
|
||||
"@zk-kit/imt.sol": "2.0.0-beta.5"
|
||||
},
|
||||
"stableVersion": "4.0.0-alpha"
|
||||
"stableVersion": "4.0.0-alpha.1"
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"Verifier": "0xf2e44cC007f0c0965875dB77152a757159e4507D",
|
||||
"Poseidon": "0x31cF407EA3964c092F9E171D3692e9B7466288ca",
|
||||
"Semaphore": "0xb25E63B115Ffba085FeCbf196a8e720F85DC351c"
|
||||
"Verifier": "0x1E979ECf8C23d45577904974642592f80C464522",
|
||||
"Poseidon": "0x43AE9518d9FE43898cD705a06C22A73B015bCf12",
|
||||
"Semaphore": "0x5B8e7cC7bAC61A4b952d472b67056B2f260ba6dc"
|
||||
}
|
||||
|
||||
@@ -10,8 +10,8 @@ import { Semaphore } from "../typechain-types"
|
||||
|
||||
describe("Semaphore", () => {
|
||||
let semaphoreContract: Semaphore
|
||||
let signers: Signer[]
|
||||
let accounts: string[]
|
||||
let accounts: Signer[]
|
||||
let accountAddresses: string[]
|
||||
|
||||
const merkleTreeDepth = 12
|
||||
|
||||
@@ -25,27 +25,27 @@ describe("Semaphore", () => {
|
||||
|
||||
semaphoreContract = semaphore
|
||||
|
||||
signers = await run("accounts", { logs: false })
|
||||
accounts = await Promise.all(signers.map((signer: Signer) => signer.getAddress()))
|
||||
accounts = await run("accounts", { logs: false })
|
||||
accountAddresses = await Promise.all(accounts.map((signer: Signer) => signer.getAddress()))
|
||||
})
|
||||
|
||||
describe("# createGroup", () => {
|
||||
it("Should create a group", async () => {
|
||||
const transaction = semaphoreContract
|
||||
.connect(signers[1])
|
||||
["createGroup(uint256,address)"](groupId, accounts[1])
|
||||
.connect(accounts[1])
|
||||
["createGroup(uint256,address)"](groupId, accountAddresses[1])
|
||||
|
||||
await expect(transaction).to.emit(semaphoreContract, "GroupCreated").withArgs(groupId)
|
||||
await expect(transaction)
|
||||
.to.emit(semaphoreContract, "GroupAdminUpdated")
|
||||
.withArgs(groupId, ZeroAddress, accounts[1])
|
||||
.withArgs(groupId, ZeroAddress, accountAddresses[1])
|
||||
})
|
||||
|
||||
it("Should create a group with a custom Merkle tree root expiration", async () => {
|
||||
const groupId = 2
|
||||
const transaction = await semaphoreContract.connect(signers[1])["createGroup(uint256,address,uint256)"](
|
||||
const transaction = await semaphoreContract.connect(accounts[1])["createGroup(uint256,address,uint256)"](
|
||||
groupId,
|
||||
accounts[0],
|
||||
accountAddresses[0],
|
||||
5 // 5 seconds.
|
||||
)
|
||||
await semaphoreContract.addMember(groupId, members[0])
|
||||
@@ -55,7 +55,7 @@ describe("Semaphore", () => {
|
||||
await expect(transaction).to.emit(semaphoreContract, "GroupCreated").withArgs(groupId)
|
||||
await expect(transaction)
|
||||
.to.emit(semaphoreContract, "GroupAdminUpdated")
|
||||
.withArgs(groupId, ZeroAddress, accounts[0])
|
||||
.withArgs(groupId, ZeroAddress, accountAddresses[0])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -70,7 +70,7 @@ describe("Semaphore", () => {
|
||||
})
|
||||
|
||||
it("Should update the group Merkle tree duration", async () => {
|
||||
const transaction = semaphoreContract.connect(signers[1]).updateGroupMerkleTreeDuration(groupId, 300)
|
||||
const transaction = semaphoreContract.connect(accounts[1]).updateGroupMerkleTreeDuration(groupId, 300)
|
||||
|
||||
await expect(transaction)
|
||||
.to.emit(semaphoreContract, "GroupMerkleTreeDurationUpdated")
|
||||
@@ -80,7 +80,7 @@ describe("Semaphore", () => {
|
||||
|
||||
describe("# updateGroupAdmin", () => {
|
||||
it("Should not update a group admin if the caller is not the group admin", async () => {
|
||||
const transaction = semaphoreContract.updateGroupAdmin(groupId, accounts[0])
|
||||
const transaction = semaphoreContract.updateGroupAdmin(groupId, accountAddresses[0])
|
||||
|
||||
await expect(transaction).to.be.revertedWithCustomError(
|
||||
semaphoreContract,
|
||||
@@ -89,11 +89,11 @@ describe("Semaphore", () => {
|
||||
})
|
||||
|
||||
it("Should update the group admin", async () => {
|
||||
const transaction = semaphoreContract.connect(signers[1]).updateGroupAdmin(groupId, accounts[0])
|
||||
const transaction = semaphoreContract.connect(accounts[1]).updateGroupAdmin(groupId, accountAddresses[0])
|
||||
|
||||
await expect(transaction)
|
||||
.to.emit(semaphoreContract, "GroupAdminUpdated")
|
||||
.withArgs(groupId, accounts[1], accounts[0])
|
||||
.withArgs(groupId, accountAddresses[1], accountAddresses[0])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -101,7 +101,7 @@ describe("Semaphore", () => {
|
||||
it("Should not add a member if the caller is not the group admin", async () => {
|
||||
const member = BigInt(2)
|
||||
|
||||
const transaction = semaphoreContract.connect(signers[1]).addMember(groupId, member)
|
||||
const transaction = semaphoreContract.connect(accounts[1]).addMember(groupId, member)
|
||||
|
||||
await expect(transaction).to.be.revertedWithCustomError(
|
||||
semaphoreContract,
|
||||
@@ -130,7 +130,7 @@ describe("Semaphore", () => {
|
||||
|
||||
group.addMembers(members)
|
||||
|
||||
await semaphoreContract["createGroup(uint256,address)"](groupId, accounts[0])
|
||||
await semaphoreContract["createGroup(uint256,address)"](groupId, accountAddresses[0])
|
||||
|
||||
const transaction = semaphoreContract.addMembers(groupId, members)
|
||||
|
||||
@@ -144,7 +144,7 @@ describe("Semaphore", () => {
|
||||
it("Should not update a member if the caller is not the group admin", async () => {
|
||||
const member = BigInt(2)
|
||||
|
||||
const transaction = semaphoreContract.connect(signers[1]).updateMember(groupId, member, 1, [0, 1])
|
||||
const transaction = semaphoreContract.connect(accounts[1]).updateMember(groupId, member, 1, [0, 1])
|
||||
|
||||
await expect(transaction).to.be.revertedWithCustomError(
|
||||
semaphoreContract,
|
||||
@@ -161,7 +161,7 @@ describe("Semaphore", () => {
|
||||
|
||||
group.updateMember(0, BigInt(4))
|
||||
|
||||
await semaphoreContract["createGroup(uint256,address)"](groupId, accounts[0])
|
||||
await semaphoreContract["createGroup(uint256,address)"](groupId, accountAddresses[0])
|
||||
await semaphoreContract.addMembers(groupId, members)
|
||||
|
||||
const { siblings, root } = group.generateMerkleProof(0)
|
||||
@@ -178,7 +178,7 @@ describe("Semaphore", () => {
|
||||
it("Should not remove a member if the caller is not the group admin", async () => {
|
||||
const member = BigInt(2)
|
||||
|
||||
const transaction = semaphoreContract.connect(signers[1]).removeMember(groupId, member, [0, 1])
|
||||
const transaction = semaphoreContract.connect(accounts[1]).removeMember(groupId, member, [0, 1])
|
||||
|
||||
await expect(transaction).to.be.revertedWithCustomError(
|
||||
semaphoreContract,
|
||||
@@ -195,7 +195,7 @@ describe("Semaphore", () => {
|
||||
|
||||
group.removeMember(2)
|
||||
|
||||
await semaphoreContract["createGroup(uint256,address)"](groupId, accounts[0])
|
||||
await semaphoreContract["createGroup(uint256,address)"](groupId, accountAddresses[0])
|
||||
await semaphoreContract.addMembers(groupId, members)
|
||||
|
||||
const { siblings, root } = group.generateMerkleProof(2)
|
||||
@@ -206,6 +206,20 @@ describe("Semaphore", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("# getGroupAdmin", () => {
|
||||
it("Should return a 0 address if the group does not exist", async () => {
|
||||
const address = await semaphoreContract.getGroupAdmin(999)
|
||||
|
||||
expect(address).to.equal(ZeroAddress)
|
||||
})
|
||||
|
||||
it("Should return the address of the group admin", async () => {
|
||||
const address = await semaphoreContract.getGroupAdmin(groupId)
|
||||
|
||||
expect(address).to.equal(accountAddresses[0])
|
||||
})
|
||||
})
|
||||
|
||||
describe("# verifyProof", () => {
|
||||
const groupId = 10
|
||||
const message = 2
|
||||
@@ -218,7 +232,7 @@ describe("Semaphore", () => {
|
||||
let fullProof: SemaphoreProof
|
||||
|
||||
before(async () => {
|
||||
await semaphoreContract["createGroup(uint256,address)"](groupId, accounts[0])
|
||||
await semaphoreContract["createGroup(uint256,address)"](groupId, accountAddresses[0])
|
||||
|
||||
await semaphoreContract.addMembers(groupId, members)
|
||||
|
||||
@@ -279,7 +293,7 @@ describe("Semaphore", () => {
|
||||
let fullProofOneMember: SemaphoreProof
|
||||
|
||||
before(async () => {
|
||||
await semaphoreContract["createGroup(uint256,address)"](groupOneMemberId, accounts[0])
|
||||
await semaphoreContract["createGroup(uint256,address)"](groupOneMemberId, accountAddresses[0])
|
||||
|
||||
await semaphoreContract.addMembers(groupId, [members[1], members[2]])
|
||||
await semaphoreContract.addMember(groupOneMemberId, members[0])
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<img src="https://img.shields.io/badge/project-Semaphore-blue.svg?style=flat-square">
|
||||
</a>
|
||||
<a href="https://github.com/semaphore-protocol/semaphore/blob/main/LICENSE">
|
||||
<img alt="Github license" src="https://img.shields.io/github/license/semaphore-protocol/semaphore.svg?style=flat-square">
|
||||
<img alt="NPM license" src="https://img.shields.io/npm/l/%40semaphore-protocol%2Fdata?style=flat-square">
|
||||
</a>
|
||||
<a href="https://www.npmjs.com/package/@semaphore-protocol/data">
|
||||
<img alt="NPM version" src="https://img.shields.io/npm/v/@semaphore-protocol/data?style=flat-square" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/data",
|
||||
"version": "4.0.0-alpha.1",
|
||||
"version": "4.0.0-alpha.2",
|
||||
"description": "A library to query Semaphore contracts.",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.node.js",
|
||||
@@ -22,7 +22,6 @@
|
||||
"url": "https://github.com/semaphore-protocol/semaphore.git/issues"
|
||||
},
|
||||
"scripts": {
|
||||
"build:watch": "rollup -c rollup.config.ts -w --configPlugin typescript",
|
||||
"build": "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript",
|
||||
"prepublishOnly": "yarn build"
|
||||
},
|
||||
@@ -35,8 +34,8 @@
|
||||
"rollup-plugin-typescript2": "^0.31.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.27.2",
|
||||
"axios": "1.6.6",
|
||||
"ethers": "6.10.0"
|
||||
},
|
||||
"stableVersion": "4.0.0-alpha"
|
||||
"stableVersion": "4.0.0-alpha.1"
|
||||
}
|
||||
|
||||
@@ -7,7 +7,8 @@ import {
|
||||
InfuraProvider,
|
||||
JsonRpcProvider,
|
||||
PocketProvider,
|
||||
Provider
|
||||
Provider,
|
||||
ZeroAddress
|
||||
} from "ethers"
|
||||
import checkParameter from "./checkParameter"
|
||||
import getEvents from "./getEvents"
|
||||
@@ -55,8 +56,8 @@ export default class SemaphoreEthers {
|
||||
options.startBlock ??= 33995010
|
||||
break
|
||||
case "sepolia":
|
||||
options.address ??= "0xb25E63B115Ffba085FeCbf196a8e720F85DC351c"
|
||||
options.startBlock ??= 5145333
|
||||
options.address ??= "0x5B8e7cC7bAC61A4b952d472b67056B2f260ba6dc"
|
||||
options.startBlock ??= 5150903
|
||||
break
|
||||
case "optimism-sepolia":
|
||||
options.address ??= "0x3889927F0B5Eb1a02C6E2C20b39a1Bd4EAd76131"
|
||||
@@ -146,9 +147,9 @@ export default class SemaphoreEthers {
|
||||
async getGroup(groupId: string): Promise<GroupResponse> {
|
||||
checkParameter(groupId, "groupId", "string")
|
||||
|
||||
const [groupCreatedEvent] = await getEvents(this._contract, "GroupCreated", [groupId], this._options.startBlock)
|
||||
const groupAdmin = await this._contract.getGroupAdmin(groupId)
|
||||
|
||||
if (!groupCreatedEvent) {
|
||||
if (groupAdmin === ZeroAddress) {
|
||||
throw new Error(`Group '${groupId}' not found`)
|
||||
}
|
||||
|
||||
@@ -158,6 +159,7 @@ export default class SemaphoreEthers {
|
||||
|
||||
const group: GroupResponse = {
|
||||
id: groupId,
|
||||
admin: groupAdmin,
|
||||
merkleTree: {
|
||||
depth: Number(merkleTreeDepth),
|
||||
size: Number(merkleTreeSize),
|
||||
@@ -168,28 +170,6 @@ export default class SemaphoreEthers {
|
||||
return group
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a group admin.
|
||||
* @param groupId Group id.
|
||||
* @returns Group admin.
|
||||
*/
|
||||
async getGroupAdmin(groupId: string): Promise<string> {
|
||||
checkParameter(groupId, "groupId", "string")
|
||||
|
||||
const groupAdminUpdatedEvents = await getEvents(
|
||||
this._contract,
|
||||
"GroupAdminUpdated",
|
||||
[groupId],
|
||||
this._options.startBlock
|
||||
)
|
||||
|
||||
if (groupAdminUpdatedEvents.length === 0) {
|
||||
throw new Error(`Group '${groupId}' not found`)
|
||||
}
|
||||
|
||||
return groupAdminUpdatedEvents[groupAdminUpdatedEvents.length - 1][2]
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a list of group members.
|
||||
* @param groupId Group id.
|
||||
@@ -198,9 +178,9 @@ export default class SemaphoreEthers {
|
||||
async getGroupMembers(groupId: string): Promise<string[]> {
|
||||
checkParameter(groupId, "groupId", "string")
|
||||
|
||||
const [groupCreatedEvent] = await getEvents(this._contract, "GroupCreated", [groupId], this._options.startBlock)
|
||||
const groupAdmin = await this._contract.getGroupAdmin(groupId)
|
||||
|
||||
if (!groupCreatedEvent) {
|
||||
if (groupAdmin === ZeroAddress) {
|
||||
throw new Error(`Group '${groupId}' not found`)
|
||||
}
|
||||
|
||||
@@ -282,9 +262,9 @@ export default class SemaphoreEthers {
|
||||
async getGroupValidatedProofs(groupId: string): Promise<any> {
|
||||
checkParameter(groupId, "groupId", "string")
|
||||
|
||||
const [groupCreatedEvent] = await getEvents(this._contract, "GroupCreated", [groupId], this._options.startBlock)
|
||||
const groupAdmin = await this._contract.getGroupAdmin(groupId)
|
||||
|
||||
if (!groupCreatedEvent) {
|
||||
if (groupAdmin === ZeroAddress) {
|
||||
throw new Error(`Group '${groupId}' not found`)
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ export default function getURL(supportedNetwork: SupportedNetwork | string): str
|
||||
case "optimism-sepolia":
|
||||
case "arbitrum-sepolia":
|
||||
case "arbitrum":
|
||||
return `https://api.studio.thegraph.com/query/14377/semaphore-${supportedNetwork}/v4.0.0-alpha.3`
|
||||
return `https://api.studio.thegraph.com/query/14377/semaphore-${supportedNetwork}/v4.0.0-alpha.4`
|
||||
default:
|
||||
throw new TypeError(`Network '${supportedNetwork}' is not supported`)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
/* eslint-disable no-sparse-arrays */
|
||||
import { Contract, ZeroAddress } from "ethers"
|
||||
import SemaphoreEthers from "../src/ethers"
|
||||
import getEvents from "../src/getEvents"
|
||||
|
||||
@@ -15,19 +16,19 @@ jest.mock("ethers", () => ({
|
||||
({
|
||||
getMerkleTreeRoot: () => "222",
|
||||
getMerkleTreeDepth: () => BigInt(3),
|
||||
getMerkleTreeSize: () => BigInt(8)
|
||||
getMerkleTreeSize: () => BigInt(8),
|
||||
getGroupAdmin: () => "0xA9C2B639a28cDa8b59C4377e980F75A93dD8605F"
|
||||
} as any)
|
||||
)
|
||||
}))
|
||||
|
||||
const getEventsMocked = getEvents as jest.MockedFunction<typeof getEvents>
|
||||
const ContractMocked = Contract as jest.MockedClass<typeof Contract>
|
||||
|
||||
describe("SemaphoreEthers", () => {
|
||||
let semaphore: SemaphoreEthers
|
||||
|
||||
describe("# SemaphoreEthers", () => {
|
||||
it("Should instantiate a SemaphoreEthers object with different networks", () => {
|
||||
semaphore = new SemaphoreEthers()
|
||||
const semaphore = new SemaphoreEthers()
|
||||
const semaphore1 = new SemaphoreEthers("arbitrum")
|
||||
const semaphore2 = new SemaphoreEthers("mumbai")
|
||||
// const semaphore3 = new SemaphoreEthers("optimism-sepolia")
|
||||
@@ -115,6 +116,8 @@ describe("SemaphoreEthers", () => {
|
||||
|
||||
describe("# getGroupIds", () => {
|
||||
it("Should return all the existing groups", async () => {
|
||||
const semaphore = new SemaphoreEthers()
|
||||
|
||||
getEventsMocked.mockReturnValueOnce(Promise.resolve([["32"], ["42"]]))
|
||||
|
||||
const groupIds = await semaphore.getGroupIds()
|
||||
@@ -125,7 +128,7 @@ describe("SemaphoreEthers", () => {
|
||||
|
||||
describe("# getGroup", () => {
|
||||
it("Should return a specific group", async () => {
|
||||
getEventsMocked.mockReturnValueOnce(Promise.resolve([["111"]]))
|
||||
const semaphore = new SemaphoreEthers()
|
||||
|
||||
const group = await semaphore.getGroup("42")
|
||||
|
||||
@@ -135,7 +138,11 @@ describe("SemaphoreEthers", () => {
|
||||
})
|
||||
|
||||
it("Should throw an error if the group does not exist", async () => {
|
||||
getEventsMocked.mockReturnValueOnce(Promise.resolve([]))
|
||||
ContractMocked.mockReturnValueOnce({
|
||||
getGroupAdmin: () => ZeroAddress
|
||||
} as any)
|
||||
|
||||
const semaphore = new SemaphoreEthers()
|
||||
|
||||
const fun = () => semaphore.getGroup("666")
|
||||
|
||||
@@ -143,27 +150,10 @@ describe("SemaphoreEthers", () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe("# getGroupAdmin", () => {
|
||||
it("Should return a group admin", async () => {
|
||||
getEventsMocked.mockReturnValueOnce(Promise.resolve([[, , "0xA9C2B639a28cDa8b59C4377e980F75A93dD8605F"]]))
|
||||
|
||||
const admin = await semaphore.getGroupAdmin("42")
|
||||
|
||||
expect(admin).toBe("0xA9C2B639a28cDa8b59C4377e980F75A93dD8605F")
|
||||
})
|
||||
|
||||
it("Should throw an error if the group does not exist", async () => {
|
||||
getEventsMocked.mockReturnValueOnce(Promise.resolve([]))
|
||||
|
||||
const fun = () => semaphore.getGroupAdmin("666")
|
||||
|
||||
await expect(fun).rejects.toThrow("Group '666' not found")
|
||||
})
|
||||
})
|
||||
|
||||
describe("# getGroupMembers", () => {
|
||||
it("Should return a list of group members", async () => {
|
||||
getEventsMocked.mockReturnValueOnce(Promise.resolve([["20"]]))
|
||||
const semaphore = new SemaphoreEthers()
|
||||
|
||||
getEventsMocked.mockReturnValueOnce(
|
||||
Promise.resolve([
|
||||
[, "0", , , 4],
|
||||
@@ -203,7 +193,11 @@ describe("SemaphoreEthers", () => {
|
||||
})
|
||||
|
||||
it("Should throw an error if the group does not exist", async () => {
|
||||
getEventsMocked.mockReturnValueOnce(Promise.resolve([]))
|
||||
ContractMocked.mockReturnValueOnce({
|
||||
getGroupAdmin: () => ZeroAddress
|
||||
} as any)
|
||||
|
||||
const semaphore = new SemaphoreEthers()
|
||||
|
||||
const fun = () => semaphore.getGroupMembers("666")
|
||||
|
||||
@@ -213,7 +207,8 @@ describe("SemaphoreEthers", () => {
|
||||
|
||||
describe("# getGroupVerifiedProofs", () => {
|
||||
it("Should return a list of group verified proofs", async () => {
|
||||
getEventsMocked.mockReturnValueOnce(Promise.resolve([["42"]]))
|
||||
const semaphore = new SemaphoreEthers()
|
||||
|
||||
getEventsMocked.mockReturnValueOnce(
|
||||
Promise.resolve([
|
||||
[
|
||||
@@ -234,7 +229,11 @@ describe("SemaphoreEthers", () => {
|
||||
})
|
||||
|
||||
it("Should throw an error if the group does not exist", async () => {
|
||||
getEventsMocked.mockReturnValueOnce(Promise.resolve([]))
|
||||
ContractMocked.mockReturnValueOnce({
|
||||
getGroupAdmin: () => ZeroAddress
|
||||
} as any)
|
||||
|
||||
const semaphore = new SemaphoreEthers()
|
||||
|
||||
const fun = () => semaphore.getGroupValidatedProofs("666")
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<img src="https://img.shields.io/badge/project-Semaphore-blue.svg?style=flat-square">
|
||||
</a>
|
||||
<a href="https://github.com/semaphore-protocol/semaphore/blob/main/LICENSE">
|
||||
<img alt="Github license" src="https://img.shields.io/github/license/semaphore-protocol/semaphore.svg?style=flat-square">
|
||||
<img alt="NPM license" src="https://img.shields.io/npm/l/%40semaphore-protocol%2Fgroup?style=flat-square">
|
||||
</a>
|
||||
<a href="https://www.npmjs.com/package/@semaphore-protocol/group">
|
||||
<img alt="NPM version" src="https://img.shields.io/npm/v/@semaphore-protocol/group?style=flat-square" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/group",
|
||||
"version": "4.0.0-alpha.1",
|
||||
"version": "4.0.0-alpha.2",
|
||||
"description": "A library to create and manage Semaphore groups.",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.node.js",
|
||||
@@ -22,7 +22,6 @@
|
||||
"url": "https://github.com/semaphore-protocol/semaphore.git/issues"
|
||||
},
|
||||
"scripts": {
|
||||
"build:watch": "rollup -c rollup.config.ts -w --configPlugin typescript",
|
||||
"build": "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript",
|
||||
"prepublishOnly": "yarn build"
|
||||
},
|
||||
@@ -39,5 +38,5 @@
|
||||
"dependencies": {
|
||||
"@zk-kit/imt": "^2.0.0-beta"
|
||||
},
|
||||
"stableVersion": "4.0.0-alpha"
|
||||
"stableVersion": "4.0.0-alpha.1"
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<img src="https://img.shields.io/badge/project-Semaphore-blue.svg?style=flat-square">
|
||||
</a>
|
||||
<a href="https://github.com/semaphore-protocol/semaphore/blob/main/LICENSE">
|
||||
<img alt="Github license" src="https://img.shields.io/github/license/semaphore-protocol/semaphore.svg?style=flat-square">
|
||||
<img alt="NPM license" src="https://img.shields.io/npm/l/%40semaphore-protocol%2Fhardhat?style=flat-square">
|
||||
</a>
|
||||
<a href="https://www.npmjs.com/package/@semaphore-protocol/hardhat">
|
||||
<img alt="NPM version" src="https://img.shields.io/npm/v/@semaphore-protocol/hardhat?style=flat-square" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/hardhat",
|
||||
"version": "4.0.0-alpha.1",
|
||||
"version": "4.0.0-alpha.2",
|
||||
"description": "A Semaphore Hardhat plugin to deploy verifiers and Semaphore contract.",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.node.js",
|
||||
@@ -22,7 +22,6 @@
|
||||
"url": "https://github.com/semaphore-protocol/semaphore.git/issues"
|
||||
},
|
||||
"scripts": {
|
||||
"build:watch": "rollup -c rollup.config.ts -w --configPlugin typescript",
|
||||
"build": "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript",
|
||||
"prepublishOnly": "yarn build"
|
||||
},
|
||||
@@ -39,9 +38,9 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@nomicfoundation/hardhat-ethers": "^3.0.0",
|
||||
"@semaphore-protocol/contracts": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/contracts": "4.0.0-alpha.2",
|
||||
"ethers": "^6.4.0",
|
||||
"hardhat-dependency-compiler": "^1.1.3"
|
||||
},
|
||||
"stableVersion": "4.0.0-alpha"
|
||||
"stableVersion": "4.0.0-alpha.1"
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export default {
|
||||
{ file: pkg.exports.require, format: "cjs", banner, exports: "auto" },
|
||||
{ file: pkg.exports.import, format: "es", banner }
|
||||
],
|
||||
external: Object.keys(pkg.dependencies),
|
||||
external: [...Object.keys(pkg.dependencies), "hardhat/config"],
|
||||
plugins: [
|
||||
typescript({
|
||||
tsconfig: "./build.tsconfig.json",
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<img src="https://img.shields.io/badge/project-Semaphore-blue.svg?style=flat-square">
|
||||
</a>
|
||||
<a href="https://github.com/semaphore-protocol/semaphore/blob/main/LICENSE">
|
||||
<img alt="Github license" src="https://img.shields.io/github/license/semaphore-protocol/semaphore.svg?style=flat-square">
|
||||
<img alt="NPM license" src="https://img.shields.io/npm/l/%40semaphore-protocol%2Fheyauthn?style=flat-square">
|
||||
</a>
|
||||
<a href="https://www.npmjs.com/package/@semaphore-protocol/heyauthn">
|
||||
<img alt="NPM version" src="https://img.shields.io/npm/v/@semaphore-protocol/heyauthn?style=flat-square" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/heyauthn",
|
||||
"version": "4.0.0-alpha.1",
|
||||
"version": "4.0.0-alpha.2",
|
||||
"description": "A library to allow developers to create and manage Semaphore identities using WebAuthn",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.node.js",
|
||||
@@ -22,7 +22,6 @@
|
||||
"url": "https://github.com/semaphore-protocol/semaphore.git/issues"
|
||||
},
|
||||
"scripts": {
|
||||
"build:watch": "rollup -c rollup.config.ts -w --configPlugin typescript",
|
||||
"build": "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript",
|
||||
"prepublishOnly": "yarn build"
|
||||
},
|
||||
@@ -34,9 +33,9 @@
|
||||
"rollup-plugin-typescript2": "^0.31.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@semaphore-protocol/identity": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/identity": "4.0.0-alpha.2",
|
||||
"@simplewebauthn/browser": "7.2.0",
|
||||
"@simplewebauthn/server": "7.2.0"
|
||||
},
|
||||
"stableVersion": "4.0.0-alpha"
|
||||
"stableVersion": "4.0.0-alpha.1"
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<img src="https://img.shields.io/badge/project-Semaphore-blue.svg?style=flat-square">
|
||||
</a>
|
||||
<a href="https://github.com/semaphore-protocol/semaphore/blob/main/LICENSE">
|
||||
<img alt="Github license" src="https://img.shields.io/github/license/semaphore-protocol/semaphore.svg?style=flat-square">
|
||||
<img alt="NPM license" src="https://img.shields.io/npm/l/%40semaphore-protocol%2Fidentity?style=flat-square">
|
||||
</a>
|
||||
<a href="https://www.npmjs.com/package/@semaphore-protocol/identity">
|
||||
<img alt="NPM version" src="https://img.shields.io/npm/v/@semaphore-protocol/identity?style=flat-square" />
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/identity",
|
||||
"version": "4.0.0-alpha.1",
|
||||
"version": "4.0.0-alpha.2",
|
||||
"description": "A library to create Semaphore identities.",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.node.js",
|
||||
"browser": "dist/index.browser.mjs",
|
||||
"exports": {
|
||||
"import": "./dist/index.mjs",
|
||||
"require": "./dist/index.node.js",
|
||||
"types": "./dist/types/index.d.ts"
|
||||
".": {
|
||||
"node": {
|
||||
"import": "./dist/index.node.mjs",
|
||||
"require": "./dist/index.node.js"
|
||||
},
|
||||
"browser": "./dist/index.browser.mjs",
|
||||
"default": "./dist/index.browser.mjs",
|
||||
"types": "./dist/types/index.d.ts"
|
||||
}
|
||||
},
|
||||
"types": "dist/types/index.d.ts",
|
||||
"files": [
|
||||
@@ -22,14 +29,16 @@
|
||||
"url": "https://github.com/semaphore-protocol/semaphore.git/issues"
|
||||
},
|
||||
"scripts": {
|
||||
"build:watch": "rollup -c rollup.config.ts -w --configPlugin typescript",
|
||||
"build": "rimraf dist && rollup -c rollup.config.ts --configPlugin typescript",
|
||||
"build": "rimraf dist && yarn build:browser && yarn build:node",
|
||||
"build:browser": "rollup -c rollup.browser.config.ts --configPlugin typescript",
|
||||
"build:node": "rollup -c rollup.node.config.ts --configPlugin typescript",
|
||||
"prepublishOnly": "yarn build"
|
||||
},
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-alias": "^5.1.0",
|
||||
"@rollup/plugin-commonjs": "^24.0.1",
|
||||
"@rollup/plugin-node-resolve": "^15.0.1",
|
||||
"rollup-plugin-cleanup": "^3.2.1",
|
||||
@@ -39,5 +48,5 @@
|
||||
"@zk-kit/eddsa-poseidon": "0.4.1",
|
||||
"poseidon-lite": "^0.2.0"
|
||||
},
|
||||
"stableVersion": "4.0.0-alpha"
|
||||
"stableVersion": "4.0.0-alpha.1"
|
||||
}
|
||||
|
||||
38
packages/identity/rollup.browser.config.ts
Normal file
38
packages/identity/rollup.browser.config.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import alias from "@rollup/plugin-alias"
|
||||
import json from "@rollup/plugin-json"
|
||||
import * as fs from "fs"
|
||||
import cleanup from "rollup-plugin-cleanup"
|
||||
import typescript from "rollup-plugin-typescript2"
|
||||
|
||||
const pkg = JSON.parse(fs.readFileSync("./package.json", "utf-8"))
|
||||
const banner = `/**
|
||||
* @module ${pkg.name}
|
||||
* @version ${pkg.version}
|
||||
* @file ${pkg.description}
|
||||
* @copyright Ethereum Foundation 2024
|
||||
* @license ${pkg.license}
|
||||
* @see [Github]{@link ${pkg.homepage}}
|
||||
*/`
|
||||
|
||||
export default {
|
||||
input: "src/index.ts",
|
||||
output: [
|
||||
{
|
||||
file: pkg.exports["."].browser,
|
||||
format: "es",
|
||||
banner
|
||||
}
|
||||
],
|
||||
external: [...Object.keys(pkg.dependencies), "poseidon-lite/poseidon2"],
|
||||
plugins: [
|
||||
alias({
|
||||
entries: [{ find: "./random-number.node", replacement: "./random-number.browser" }]
|
||||
}),
|
||||
typescript({
|
||||
tsconfig: "./build.tsconfig.json",
|
||||
useTsconfigDeclarationDir: true
|
||||
}),
|
||||
cleanup({ comments: "jsdoc" }),
|
||||
json()
|
||||
]
|
||||
}
|
||||
@@ -1,8 +1,6 @@
|
||||
import typescript from "rollup-plugin-typescript2"
|
||||
import commonjs from "@rollup/plugin-commonjs"
|
||||
import * as fs from "fs"
|
||||
import cleanup from "rollup-plugin-cleanup"
|
||||
import { nodeResolve } from "@rollup/plugin-node-resolve"
|
||||
import typescript from "rollup-plugin-typescript2"
|
||||
|
||||
const pkg = JSON.parse(fs.readFileSync("./package.json", "utf-8"))
|
||||
const banner = `/**
|
||||
@@ -17,17 +15,15 @@ const banner = `/**
|
||||
export default {
|
||||
input: "src/index.ts",
|
||||
output: [
|
||||
{ file: pkg.exports.require, format: "cjs", banner, exports: "auto" },
|
||||
{ file: pkg.exports.import, format: "es", banner }
|
||||
{ file: pkg.exports["."].node.require, format: "cjs", banner, exports: "auto" },
|
||||
{ file: pkg.exports["."].node.import, format: "es", banner }
|
||||
],
|
||||
external: Object.keys(pkg.dependencies),
|
||||
external: [...Object.keys(pkg.dependencies), "poseidon-lite/poseidon2", "node:crypto"],
|
||||
plugins: [
|
||||
typescript({
|
||||
tsconfig: "./build.tsconfig.json",
|
||||
useTsconfigDeclarationDir: true
|
||||
}),
|
||||
commonjs(),
|
||||
nodeResolve(),
|
||||
cleanup({ comments: "jsdoc" })
|
||||
]
|
||||
}
|
||||
9
packages/identity/src/bytes-to-bigint.ts
Normal file
9
packages/identity/src/bytes-to-bigint.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export function bytesToBigint(bytes: Uint8Array): bigint {
|
||||
let hex = "0x"
|
||||
|
||||
for (let i = 0; i < bytes.length; i += 1) {
|
||||
hex += bytes[i].toString(16).padStart(2, "0")
|
||||
}
|
||||
|
||||
return BigInt(hex)
|
||||
}
|
||||
@@ -7,8 +7,8 @@ import {
|
||||
signMessage,
|
||||
verifySignature
|
||||
} from "@zk-kit/eddsa-poseidon"
|
||||
import { randomBytes } from "crypto"
|
||||
import { poseidon2 } from "poseidon-lite/poseidon2"
|
||||
import { randomNumber } from "./random-number.node"
|
||||
|
||||
export default class Identity {
|
||||
private _privateKey: BigNumberish
|
||||
@@ -20,7 +20,7 @@ export default class Identity {
|
||||
* Initializes the class attributes based on the parameters.
|
||||
* @param privateKey The secret value used to generate an EdDSA public key.
|
||||
*/
|
||||
constructor(privateKey: BigNumberish = BigInt(`0x${randomBytes(32).toString("hex")}`).toString()) {
|
||||
constructor(privateKey: BigNumberish = randomNumber().toString()) {
|
||||
this._privateKey = privateKey
|
||||
this._secretScalar = deriveSecretScalar(privateKey)
|
||||
|
||||
|
||||
8
packages/identity/src/random-number.browser.ts
Normal file
8
packages/identity/src/random-number.browser.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
/* istanbul ignore file */
|
||||
import { bytesToBigint } from "./bytes-to-bigint"
|
||||
|
||||
export function randomNumber(): bigint {
|
||||
const bytes = crypto.getRandomValues(new Uint8Array(32))
|
||||
|
||||
return bytesToBigint(bytes)
|
||||
}
|
||||
9
packages/identity/src/random-number.node.ts
Normal file
9
packages/identity/src/random-number.node.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { randomBytes } from "node:crypto"
|
||||
|
||||
export function randomNumber(): bigint {
|
||||
const bytes = randomBytes(32)
|
||||
|
||||
const hex = `0x${bytes.toString("hex")}`
|
||||
|
||||
return BigInt(hex)
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import { randomBytes } from "crypto"
|
||||
import { Identity } from "../src"
|
||||
import { bytesToBigint } from "../src/bytes-to-bigint"
|
||||
|
||||
describe("Identity", () => {
|
||||
const privateKey = "secret"
|
||||
@@ -60,4 +62,15 @@ describe("Identity", () => {
|
||||
expect(Identity.verifySignature("message", signature, identity.publicKey)).toBeTruthy()
|
||||
})
|
||||
})
|
||||
|
||||
describe("# bytesToBigint", () => {
|
||||
it("Should convert 32 bytes to bigint", () => {
|
||||
const bytes = randomBytes(32)
|
||||
|
||||
const integer = bytesToBigint(bytes)
|
||||
|
||||
expect(typeof integer).toBe("bigint")
|
||||
expect(integer).toBe(BigInt(`0x${bytes.toString("hex")}`))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["src", "tests", "rollup.config.ts"]
|
||||
"include": ["src", "tests", "rollup.node.config.ts", "rollup.browser.config.ts"]
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
<img src="https://img.shields.io/badge/project-Semaphore-blue.svg?style=flat-square">
|
||||
</a>
|
||||
<a href="https://github.com/semaphore-protocol/semaphore/blob/main/LICENSE">
|
||||
<img alt="Github license" src="https://img.shields.io/github/license/semaphore-protocol/semaphore.svg?style=flat-square">
|
||||
<img alt="NPM license" src="https://img.shields.io/npm/l/%40semaphore-protocol%2Fproof?style=flat-square">
|
||||
</a>
|
||||
<a href="https://www.npmjs.com/package/@semaphore-protocol/proof">
|
||||
<img alt="NPM version" src="https://img.shields.io/npm/v/@semaphore-protocol/proof?style=flat-square" />
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
{
|
||||
"name": "@semaphore-protocol/proof",
|
||||
"version": "4.0.0-alpha.1",
|
||||
"version": "4.0.0-alpha.2",
|
||||
"description": "A library to generate and verify Semaphore proofs.",
|
||||
"license": "MIT",
|
||||
"main": "dist/index.node.js",
|
||||
"browser": "dist/index.browser.mjs",
|
||||
"exports": {
|
||||
"node": {
|
||||
"import": "./dist/index.node.mjs",
|
||||
"require": "./dist/index.node.js"
|
||||
},
|
||||
"browser": "./dist/index.browser.mjs",
|
||||
"default": "./dist/index.browser.mjs",
|
||||
"types": "./dist/types/index.d.ts"
|
||||
".": {
|
||||
"node": {
|
||||
"import": "./dist/index.node.mjs",
|
||||
"require": "./dist/index.node.js"
|
||||
},
|
||||
"browser": "./dist/index.browser.mjs",
|
||||
"default": "./dist/index.browser.mjs",
|
||||
"types": "./dist/types/index.d.ts"
|
||||
}
|
||||
},
|
||||
"types": "dist/types/index.d.ts",
|
||||
"files": [
|
||||
@@ -47,8 +50,8 @@
|
||||
"rollup-plugin-typescript2": "^0.31.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@semaphore-protocol/group": "4.0.0-alpha.1",
|
||||
"@semaphore-protocol/identity": "4.0.0-alpha.1"
|
||||
"@semaphore-protocol/group": "4.0.0-alpha.2",
|
||||
"@semaphore-protocol/identity": "4.0.0-alpha.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@ethersproject/bignumber": "5.7.0",
|
||||
@@ -59,5 +62,5 @@
|
||||
"snarkjs": "0.7.3",
|
||||
"tmp": "0.2.1"
|
||||
},
|
||||
"stableVersion": "4.0.0-alpha"
|
||||
"stableVersion": "4.0.0-alpha.1"
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export default {
|
||||
input: "src/index.ts",
|
||||
output: [
|
||||
{
|
||||
file: pkg.exports.browser,
|
||||
file: pkg.exports["."].browser,
|
||||
format: "es",
|
||||
banner
|
||||
}
|
||||
|
||||
@@ -17,18 +17,18 @@ export default {
|
||||
input: "src/index.ts",
|
||||
output: [
|
||||
{
|
||||
file: pkg.exports.node.require,
|
||||
file: pkg.exports["."].node.require,
|
||||
format: "cjs",
|
||||
banner,
|
||||
exports: "auto"
|
||||
},
|
||||
{
|
||||
file: pkg.exports.node.import,
|
||||
file: pkg.exports["."].node.import,
|
||||
format: "es",
|
||||
banner
|
||||
}
|
||||
],
|
||||
external: Object.keys(pkg.dependencies),
|
||||
external: [...Object.keys(pkg.dependencies), "fs"],
|
||||
plugins: [
|
||||
typescript({
|
||||
tsconfig: "./build.tsconfig.json",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"extends": "../../tsconfig.json",
|
||||
"include": ["src", "tests", "rollup.config.ts"]
|
||||
"include": ["src", "tests", "rollup.node.config.ts", "rollup.browser.config.ts"]
|
||||
}
|
||||
|
||||
@@ -1 +1 @@
|
||||
21549cf9f45a2bfe91c2adcbcd583575e0d5ee19
|
||||
bfeea664bd00b9b443312a08c451a4f86217a41f
|
||||
Reference in New Issue
Block a user