@semaphore-protocol/group 4.0.0-beta.4 → 4.0.0-beta.6

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/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @module @semaphore-protocol/group
3
- * @version 4.0.0-beta.4
3
+ * @version 4.0.0-beta.6
4
4
  * @file A library to create and manage Semaphore groups.
5
5
  * @copyright Ethereum Foundation 2024
6
6
  * @license MIT
@@ -121,121 +121,104 @@ function poseidon2(inputs) {
121
121
  * This class supports operations such as member addition, update, removal and Merkle proof
122
122
  * generation and verification. Groups can also be exported or imported.
123
123
  */
124
- var Group = /** @class */ (function () {
124
+ class Group {
125
125
  /**
126
126
  * Creates a new instance of the Group. Optionally, a list of identity commitments can
127
127
  * be passed as a parameter. Adding members in chunks is more efficient than adding
128
128
  * them one by one with the `addMember` function.
129
129
  * @param members A list of identity commitments.
130
130
  */
131
- function Group(members) {
132
- if (members === void 0) { members = []; }
133
- this.leanIMT = new imt.LeanIMT(function (a, b) { return poseidon2_2([a, b]); }, members.map(BigInt));
134
- }
135
- Object.defineProperty(Group.prototype, "root", {
136
- /**
137
- * Returns the root hash of the tree.
138
- * @returns The root hash as a string.
139
- */
140
- get: function () {
141
- return this.leanIMT.root ? this.leanIMT.root.toString() : "0";
142
- },
143
- enumerable: false,
144
- configurable: true
145
- });
146
- Object.defineProperty(Group.prototype, "depth", {
147
- /**
148
- * Returns the depth of the tree.
149
- * @returns The tree depth as a number.
150
- */
151
- get: function () {
152
- return this.leanIMT.depth;
153
- },
154
- enumerable: false,
155
- configurable: true
156
- });
157
- Object.defineProperty(Group.prototype, "size", {
158
- /**
159
- * Returns the size of the tree (i.e. number of leaves).
160
- * @returns The tree size as a number.
161
- */
162
- get: function () {
163
- return this.leanIMT.size;
164
- },
165
- enumerable: false,
166
- configurable: true
167
- });
168
- Object.defineProperty(Group.prototype, "members", {
169
- /**
170
- * Returns the members (i.e. identity commitments) of the group.
171
- * @returns The list of members of the group.
172
- */
173
- get: function () {
174
- return this.leanIMT.leaves.map(String);
175
- },
176
- enumerable: false,
177
- configurable: true
178
- });
131
+ constructor(members = []) {
132
+ this.leanIMT = new imt.LeanIMT((a, b) => poseidon2_2([a, b]), members.map(BigInt));
133
+ }
134
+ /**
135
+ * Returns the root hash of the tree.
136
+ * @returns The root hash as a string.
137
+ */
138
+ get root() {
139
+ return this.leanIMT.root ? this.leanIMT.root.toString() : "0";
140
+ }
141
+ /**
142
+ * Returns the depth of the tree.
143
+ * @returns The tree depth as a number.
144
+ */
145
+ get depth() {
146
+ return this.leanIMT.depth;
147
+ }
148
+ /**
149
+ * Returns the size of the tree (i.e. number of leaves).
150
+ * @returns The tree size as a number.
151
+ */
152
+ get size() {
153
+ return this.leanIMT.size;
154
+ }
155
+ /**
156
+ * Returns the members (i.e. identity commitments) of the group.
157
+ * @returns The list of members of the group.
158
+ */
159
+ get members() {
160
+ return this.leanIMT.leaves.map(String);
161
+ }
179
162
  /**
180
163
  * Returns the index of a member. If the member does not exist it returns -1.
181
164
  * @param member A member of the group.
182
165
  * @returns The index of the member, or -1 if it does not exist.
183
166
  */
184
- Group.prototype.indexOf = function (member) {
167
+ indexOf(member) {
185
168
  return this.leanIMT.indexOf(BigInt(member));
186
- };
169
+ }
187
170
  /**
188
171
  * Adds a new member to the group.
189
172
  * @param member The new member to be added.
190
173
  */
191
- Group.prototype.addMember = function (member) {
174
+ addMember(member) {
192
175
  this.leanIMT.insert(BigInt(member));
193
- };
176
+ }
194
177
  /**
195
178
  * Adds new members to the group.
196
179
  * @param members New members.
197
180
  */
198
- Group.prototype.addMembers = function (members) {
181
+ addMembers(members) {
199
182
  this.leanIMT.insertMany(members.map(BigInt));
200
- };
183
+ }
201
184
  /**
202
185
  * Updates a member in the group.
203
186
  * @param index Index of the member to be updated.
204
187
  * @param member New member value.
205
188
  */
206
- Group.prototype.updateMember = function (index, member) {
189
+ updateMember(index, member) {
207
190
  this.leanIMT.update(index, BigInt(member));
208
- };
191
+ }
209
192
  /**
210
193
  * Removes a member from the group.
211
194
  * @param index The index of the member to be removed.
212
195
  */
213
- Group.prototype.removeMember = function (index) {
196
+ removeMember(index) {
214
197
  this.leanIMT.update(index, BigInt(0));
215
- };
198
+ }
216
199
  /**
217
200
  * Creates a proof of membership for a member of the group.
218
201
  * @param index The index of the member.
219
202
  * @returns The {@link MerkleProof} object.
220
203
  */
221
- Group.prototype.generateMerkleProof = function (_index) {
222
- var _a = this.leanIMT.generateProof(_index), index = _a.index, leaf = _a.leaf, root = _a.root, siblings = _a.siblings;
204
+ generateMerkleProof(_index) {
205
+ const { index, leaf, root, siblings } = this.leanIMT.generateProof(_index);
223
206
  return {
224
- index: index,
207
+ index,
225
208
  leaf: leaf.toString(),
226
209
  root: root.toString(),
227
210
  siblings: siblings.map(String)
228
211
  };
229
- };
212
+ }
230
213
  /**
231
214
  * Enables the conversion of the group into a JSON string that
232
215
  * can be re-used for future imports. This approach is beneficial for
233
216
  * large groups, as it avoids re-calculating the tree hashes.
234
217
  * @returns The stringified JSON of the group.
235
218
  */
236
- Group.prototype.export = function () {
219
+ export() {
237
220
  return this.leanIMT.export();
238
- };
221
+ }
239
222
  /**
240
223
  * Imports an entire group by initializing the tree without calculating
241
224
  * any hashes. Note that it is crucial to ensure the integrity of the
@@ -243,12 +226,11 @@ var Group = /** @class */ (function () {
243
226
  * @param nodes The stringified JSON of the group.
244
227
  * @returns The {@link Group} instance.
245
228
  */
246
- Group.import = function (exportedGroup) {
247
- var group = new Group();
229
+ static import(exportedGroup) {
230
+ const group = new Group();
248
231
  group.leanIMT.import(exportedGroup);
249
232
  return group;
250
- };
251
- return Group;
252
- }());
233
+ }
234
+ }
253
235
 
254
236
  exports.Group = Group;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @module @semaphore-protocol/group
3
- * @version 4.0.0-beta.4
3
+ * @version 4.0.0-beta.6
4
4
  * @file A library to create and manage Semaphore groups.
5
5
  * @copyright Ethereum Foundation 2024
6
6
  * @license MIT
@@ -119,121 +119,104 @@ function poseidon2(inputs) {
119
119
  * This class supports operations such as member addition, update, removal and Merkle proof
120
120
  * generation and verification. Groups can also be exported or imported.
121
121
  */
122
- var Group = /** @class */ (function () {
122
+ class Group {
123
123
  /**
124
124
  * Creates a new instance of the Group. Optionally, a list of identity commitments can
125
125
  * be passed as a parameter. Adding members in chunks is more efficient than adding
126
126
  * them one by one with the `addMember` function.
127
127
  * @param members A list of identity commitments.
128
128
  */
129
- function Group(members) {
130
- if (members === void 0) { members = []; }
131
- this.leanIMT = new LeanIMT(function (a, b) { return poseidon2_2([a, b]); }, members.map(BigInt));
132
- }
133
- Object.defineProperty(Group.prototype, "root", {
134
- /**
135
- * Returns the root hash of the tree.
136
- * @returns The root hash as a string.
137
- */
138
- get: function () {
139
- return this.leanIMT.root ? this.leanIMT.root.toString() : "0";
140
- },
141
- enumerable: false,
142
- configurable: true
143
- });
144
- Object.defineProperty(Group.prototype, "depth", {
145
- /**
146
- * Returns the depth of the tree.
147
- * @returns The tree depth as a number.
148
- */
149
- get: function () {
150
- return this.leanIMT.depth;
151
- },
152
- enumerable: false,
153
- configurable: true
154
- });
155
- Object.defineProperty(Group.prototype, "size", {
156
- /**
157
- * Returns the size of the tree (i.e. number of leaves).
158
- * @returns The tree size as a number.
159
- */
160
- get: function () {
161
- return this.leanIMT.size;
162
- },
163
- enumerable: false,
164
- configurable: true
165
- });
166
- Object.defineProperty(Group.prototype, "members", {
167
- /**
168
- * Returns the members (i.e. identity commitments) of the group.
169
- * @returns The list of members of the group.
170
- */
171
- get: function () {
172
- return this.leanIMT.leaves.map(String);
173
- },
174
- enumerable: false,
175
- configurable: true
176
- });
129
+ constructor(members = []) {
130
+ this.leanIMT = new LeanIMT((a, b) => poseidon2_2([a, b]), members.map(BigInt));
131
+ }
132
+ /**
133
+ * Returns the root hash of the tree.
134
+ * @returns The root hash as a string.
135
+ */
136
+ get root() {
137
+ return this.leanIMT.root ? this.leanIMT.root.toString() : "0";
138
+ }
139
+ /**
140
+ * Returns the depth of the tree.
141
+ * @returns The tree depth as a number.
142
+ */
143
+ get depth() {
144
+ return this.leanIMT.depth;
145
+ }
146
+ /**
147
+ * Returns the size of the tree (i.e. number of leaves).
148
+ * @returns The tree size as a number.
149
+ */
150
+ get size() {
151
+ return this.leanIMT.size;
152
+ }
153
+ /**
154
+ * Returns the members (i.e. identity commitments) of the group.
155
+ * @returns The list of members of the group.
156
+ */
157
+ get members() {
158
+ return this.leanIMT.leaves.map(String);
159
+ }
177
160
  /**
178
161
  * Returns the index of a member. If the member does not exist it returns -1.
179
162
  * @param member A member of the group.
180
163
  * @returns The index of the member, or -1 if it does not exist.
181
164
  */
182
- Group.prototype.indexOf = function (member) {
165
+ indexOf(member) {
183
166
  return this.leanIMT.indexOf(BigInt(member));
184
- };
167
+ }
185
168
  /**
186
169
  * Adds a new member to the group.
187
170
  * @param member The new member to be added.
188
171
  */
189
- Group.prototype.addMember = function (member) {
172
+ addMember(member) {
190
173
  this.leanIMT.insert(BigInt(member));
191
- };
174
+ }
192
175
  /**
193
176
  * Adds new members to the group.
194
177
  * @param members New members.
195
178
  */
196
- Group.prototype.addMembers = function (members) {
179
+ addMembers(members) {
197
180
  this.leanIMT.insertMany(members.map(BigInt));
198
- };
181
+ }
199
182
  /**
200
183
  * Updates a member in the group.
201
184
  * @param index Index of the member to be updated.
202
185
  * @param member New member value.
203
186
  */
204
- Group.prototype.updateMember = function (index, member) {
187
+ updateMember(index, member) {
205
188
  this.leanIMT.update(index, BigInt(member));
206
- };
189
+ }
207
190
  /**
208
191
  * Removes a member from the group.
209
192
  * @param index The index of the member to be removed.
210
193
  */
211
- Group.prototype.removeMember = function (index) {
194
+ removeMember(index) {
212
195
  this.leanIMT.update(index, BigInt(0));
213
- };
196
+ }
214
197
  /**
215
198
  * Creates a proof of membership for a member of the group.
216
199
  * @param index The index of the member.
217
200
  * @returns The {@link MerkleProof} object.
218
201
  */
219
- Group.prototype.generateMerkleProof = function (_index) {
220
- var _a = this.leanIMT.generateProof(_index), index = _a.index, leaf = _a.leaf, root = _a.root, siblings = _a.siblings;
202
+ generateMerkleProof(_index) {
203
+ const { index, leaf, root, siblings } = this.leanIMT.generateProof(_index);
221
204
  return {
222
- index: index,
205
+ index,
223
206
  leaf: leaf.toString(),
224
207
  root: root.toString(),
225
208
  siblings: siblings.map(String)
226
209
  };
227
- };
210
+ }
228
211
  /**
229
212
  * Enables the conversion of the group into a JSON string that
230
213
  * can be re-used for future imports. This approach is beneficial for
231
214
  * large groups, as it avoids re-calculating the tree hashes.
232
215
  * @returns The stringified JSON of the group.
233
216
  */
234
- Group.prototype.export = function () {
217
+ export() {
235
218
  return this.leanIMT.export();
236
- };
219
+ }
237
220
  /**
238
221
  * Imports an entire group by initializing the tree without calculating
239
222
  * any hashes. Note that it is crucial to ensure the integrity of the
@@ -241,12 +224,11 @@ var Group = /** @class */ (function () {
241
224
  * @param nodes The stringified JSON of the group.
242
225
  * @returns The {@link Group} instance.
243
226
  */
244
- Group.import = function (exportedGroup) {
245
- var group = new Group();
227
+ static import(exportedGroup) {
228
+ const group = new Group();
246
229
  group.leanIMT.import(exportedGroup);
247
230
  return group;
248
- };
249
- return Group;
250
- }());
231
+ }
232
+ }
251
233
 
252
234
  export { Group };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@semaphore-protocol/group",
3
- "version": "4.0.0-beta.4",
3
+ "version": "4.0.0-beta.6",
4
4
  "description": "A library to create and manage Semaphore groups.",
5
5
  "type": "module",
6
6
  "license": "MIT",