@semaphore-protocol/group 3.8.0 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -15
- package/dist/index.mjs +6 -3
- package/dist/index.node.js +6 -3
- package/dist/types/group.d.ts +3 -1
- package/package.json +2 -2
- package/src/group.test.ts +16 -1
- package/src/group.ts +4 -2
package/README.md
CHANGED
|
@@ -74,6 +74,7 @@ yarn add @semaphore-protocol/group
|
|
|
74
74
|
|
|
75
75
|
```typescript
|
|
76
76
|
import { Group } from "@semaphore-protocol/group"
|
|
77
|
+
import { Identity } from "@semaphore-protocol/identity"
|
|
77
78
|
|
|
78
79
|
// Group with max 1048576 members (20^²).
|
|
79
80
|
const group1 = new Group(1)
|
|
@@ -83,6 +84,13 @@ const group2 = new Group(1, 16)
|
|
|
83
84
|
|
|
84
85
|
// Group with max 16777216 members (24^²).
|
|
85
86
|
const group3 = new Group(1, 24)
|
|
87
|
+
|
|
88
|
+
// Group with a list of predefined members.
|
|
89
|
+
const identity1 = new Identity()
|
|
90
|
+
const identity2 = new Identity()
|
|
91
|
+
const identity3 = new Identity()
|
|
92
|
+
|
|
93
|
+
const group3 = new Group(1, 16, [identity1.commitment, identity2.commitment, identity3.commitment])
|
|
86
94
|
```
|
|
87
95
|
|
|
88
96
|
\# **addMember**(identityCommitment: _Member_)
|
|
@@ -96,21 +104,6 @@ const commitment = identity.generateCommitment()
|
|
|
96
104
|
group.addMember(commitment)
|
|
97
105
|
```
|
|
98
106
|
|
|
99
|
-
\# **addMembers**(identityCommitments: _Member\[]_)
|
|
100
|
-
|
|
101
|
-
```typescript
|
|
102
|
-
let identityCommitments: bigint[]
|
|
103
|
-
|
|
104
|
-
for (let i = 0; i < 10; i++) {
|
|
105
|
-
const identity = new Identity()
|
|
106
|
-
const commitment = identity.generateCommitment()
|
|
107
|
-
|
|
108
|
-
identityCommitments.push(commitment)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
group.addMember(identityCommitments)
|
|
112
|
-
```
|
|
113
|
-
|
|
114
107
|
\# **removeMember**(index: _number_)
|
|
115
108
|
|
|
116
109
|
```typescript
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/group
|
|
3
|
-
* @version 3.
|
|
3
|
+
* @version 3.10.0
|
|
4
4
|
* @file A library to create and manage Semaphore groups.
|
|
5
5
|
* @copyright Ethereum Foundation 2022
|
|
6
6
|
* @license MIT
|
|
@@ -123,14 +123,16 @@ var Group = /** @class */ (function () {
|
|
|
123
123
|
* Initializes the group with the group id and the tree depth.
|
|
124
124
|
* @param id Group identifier.
|
|
125
125
|
* @param treeDepth Tree depth.
|
|
126
|
+
* @param members List of group members.
|
|
126
127
|
*/
|
|
127
|
-
function Group(id, treeDepth) {
|
|
128
|
+
function Group(id, treeDepth, members) {
|
|
128
129
|
if (treeDepth === void 0) { treeDepth = 20; }
|
|
130
|
+
if (members === void 0) { members = []; }
|
|
129
131
|
if (treeDepth < 16 || treeDepth > 32) {
|
|
130
132
|
throw new Error("The tree depth must be between 16 and 32");
|
|
131
133
|
}
|
|
132
134
|
this._id = id;
|
|
133
|
-
this.merkleTree = new IncrementalMerkleTree(poseidon2_2, treeDepth, hash(id), 2);
|
|
135
|
+
this.merkleTree = new IncrementalMerkleTree(poseidon2_2, treeDepth, hash(id), 2, members);
|
|
134
136
|
}
|
|
135
137
|
Object.defineProperty(Group.prototype, "id", {
|
|
136
138
|
/**
|
|
@@ -205,6 +207,7 @@ var Group = /** @class */ (function () {
|
|
|
205
207
|
/**
|
|
206
208
|
* Adds new members to the group.
|
|
207
209
|
* @param members New members.
|
|
210
|
+
* @deprecated Use the new class parameter to add a list of members.
|
|
208
211
|
*/
|
|
209
212
|
Group.prototype.addMembers = function (members) {
|
|
210
213
|
for (var _i = 0, members_1 = members; _i < members_1.length; _i++) {
|
package/dist/index.node.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/group
|
|
3
|
-
* @version 3.
|
|
3
|
+
* @version 3.10.0
|
|
4
4
|
* @file A library to create and manage Semaphore groups.
|
|
5
5
|
* @copyright Ethereum Foundation 2022
|
|
6
6
|
* @license MIT
|
|
@@ -127,14 +127,16 @@ var Group = /** @class */ (function () {
|
|
|
127
127
|
* Initializes the group with the group id and the tree depth.
|
|
128
128
|
* @param id Group identifier.
|
|
129
129
|
* @param treeDepth Tree depth.
|
|
130
|
+
* @param members List of group members.
|
|
130
131
|
*/
|
|
131
|
-
function Group(id, treeDepth) {
|
|
132
|
+
function Group(id, treeDepth, members) {
|
|
132
133
|
if (treeDepth === void 0) { treeDepth = 20; }
|
|
134
|
+
if (members === void 0) { members = []; }
|
|
133
135
|
if (treeDepth < 16 || treeDepth > 32) {
|
|
134
136
|
throw new Error("The tree depth must be between 16 and 32");
|
|
135
137
|
}
|
|
136
138
|
this._id = id;
|
|
137
|
-
this.merkleTree = new incrementalMerkleTree.IncrementalMerkleTree(poseidon2_2, treeDepth, hash(id), 2);
|
|
139
|
+
this.merkleTree = new incrementalMerkleTree.IncrementalMerkleTree(poseidon2_2, treeDepth, hash(id), 2, members);
|
|
138
140
|
}
|
|
139
141
|
Object.defineProperty(Group.prototype, "id", {
|
|
140
142
|
/**
|
|
@@ -209,6 +211,7 @@ var Group = /** @class */ (function () {
|
|
|
209
211
|
/**
|
|
210
212
|
* Adds new members to the group.
|
|
211
213
|
* @param members New members.
|
|
214
|
+
* @deprecated Use the new class parameter to add a list of members.
|
|
212
215
|
*/
|
|
213
216
|
Group.prototype.addMembers = function (members) {
|
|
214
217
|
for (var _i = 0, members_1 = members; _i < members_1.length; _i++) {
|
package/dist/types/group.d.ts
CHANGED
|
@@ -7,8 +7,9 @@ export default class Group {
|
|
|
7
7
|
* Initializes the group with the group id and the tree depth.
|
|
8
8
|
* @param id Group identifier.
|
|
9
9
|
* @param treeDepth Tree depth.
|
|
10
|
+
* @param members List of group members.
|
|
10
11
|
*/
|
|
11
|
-
constructor(id: BigNumberish, treeDepth?: number);
|
|
12
|
+
constructor(id: BigNumberish, treeDepth?: number, members?: BigNumberish[]);
|
|
12
13
|
/**
|
|
13
14
|
* Returns the id of the group.
|
|
14
15
|
* @returns Group id.
|
|
@@ -48,6 +49,7 @@ export default class Group {
|
|
|
48
49
|
/**
|
|
49
50
|
* Adds new members to the group.
|
|
50
51
|
* @param members New members.
|
|
52
|
+
* @deprecated Use the new class parameter to add a list of members.
|
|
51
53
|
*/
|
|
52
54
|
addMembers(members: BigNumberish[]): void;
|
|
53
55
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semaphore-protocol/group",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.0",
|
|
4
4
|
"description": "A library to create and manage Semaphore groups.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.node.js",
|
|
@@ -41,6 +41,6 @@
|
|
|
41
41
|
"@ethersproject/bignumber": "^5.7.0",
|
|
42
42
|
"@ethersproject/bytes": "^5.7.0",
|
|
43
43
|
"@ethersproject/keccak256": "^5.7.0",
|
|
44
|
-
"@zk-kit/incremental-merkle-tree": "1.
|
|
44
|
+
"@zk-kit/incremental-merkle-tree": "1.1.0"
|
|
45
45
|
}
|
|
46
46
|
}
|
package/src/group.test.ts
CHANGED
|
@@ -19,7 +19,7 @@ describe("Group", () => {
|
|
|
19
19
|
expect(fun).toThrow("The tree depth must be between 16 and 32")
|
|
20
20
|
})
|
|
21
21
|
|
|
22
|
-
it("Should create a group with different
|
|
22
|
+
it("Should create a group with a different tree depth", () => {
|
|
23
23
|
const group = new Group(1, 32)
|
|
24
24
|
|
|
25
25
|
expect(group.root.toString()).toContain("460373")
|
|
@@ -27,6 +27,21 @@ describe("Group", () => {
|
|
|
27
27
|
expect(group.zeroValue).toBe(hash(1))
|
|
28
28
|
expect(group.members).toHaveLength(0)
|
|
29
29
|
})
|
|
30
|
+
|
|
31
|
+
it("Should create a group with a list of members", () => {
|
|
32
|
+
const group = new Group(2, 20, [1, 2, 3])
|
|
33
|
+
|
|
34
|
+
const group2 = new Group(2, 20)
|
|
35
|
+
|
|
36
|
+
group2.addMember(1)
|
|
37
|
+
group2.addMember(2)
|
|
38
|
+
group2.addMember(3)
|
|
39
|
+
|
|
40
|
+
expect(group.root.toString()).toContain(group2.root.toString())
|
|
41
|
+
expect(group.depth).toBe(20)
|
|
42
|
+
expect(group.zeroValue).toBe(hash(2))
|
|
43
|
+
expect(group.members).toHaveLength(3)
|
|
44
|
+
})
|
|
30
45
|
})
|
|
31
46
|
|
|
32
47
|
describe("# addMember", () => {
|
package/src/group.ts
CHANGED
|
@@ -12,14 +12,15 @@ export default class Group {
|
|
|
12
12
|
* Initializes the group with the group id and the tree depth.
|
|
13
13
|
* @param id Group identifier.
|
|
14
14
|
* @param treeDepth Tree depth.
|
|
15
|
+
* @param members List of group members.
|
|
15
16
|
*/
|
|
16
|
-
constructor(id: BigNumberish, treeDepth = 20) {
|
|
17
|
+
constructor(id: BigNumberish, treeDepth = 20, members: BigNumberish[] = []) {
|
|
17
18
|
if (treeDepth < 16 || treeDepth > 32) {
|
|
18
19
|
throw new Error("The tree depth must be between 16 and 32")
|
|
19
20
|
}
|
|
20
21
|
|
|
21
22
|
this._id = id
|
|
22
|
-
this.merkleTree = new IncrementalMerkleTree(poseidon2, treeDepth, hash(id), 2)
|
|
23
|
+
this.merkleTree = new IncrementalMerkleTree(poseidon2, treeDepth, hash(id), 2, members)
|
|
23
24
|
}
|
|
24
25
|
|
|
25
26
|
/**
|
|
@@ -82,6 +83,7 @@ export default class Group {
|
|
|
82
83
|
/**
|
|
83
84
|
* Adds new members to the group.
|
|
84
85
|
* @param members New members.
|
|
86
|
+
* @deprecated Use the new class parameter to add a list of members.
|
|
85
87
|
*/
|
|
86
88
|
addMembers(members: BigNumberish[]) {
|
|
87
89
|
for (const member of members) {
|