@semaphore-protocol/group 4.0.0-alpha.5 → 4.0.0-alpha.7
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 +29 -0
- package/dist/index.cjs +23 -3
- package/dist/index.js +23 -3
- package/dist/types/group.d.ts +16 -1
- package/package.json +2 -2
- package/src/group.ts +27 -2
package/README.md
CHANGED
|
@@ -169,3 +169,32 @@ console.log(proof)
|
|
|
169
169
|
}
|
|
170
170
|
*/
|
|
171
171
|
```
|
|
172
|
+
|
|
173
|
+
\# **export**(): _string_
|
|
174
|
+
|
|
175
|
+
```typescript
|
|
176
|
+
import { Group } from "@semaphore-protocol/group"
|
|
177
|
+
|
|
178
|
+
const group = new Group([1, 2, 3])
|
|
179
|
+
|
|
180
|
+
const exportedGroup = group.export()
|
|
181
|
+
|
|
182
|
+
console.log(exportedGroup)
|
|
183
|
+
/*
|
|
184
|
+
[["1","2","3"],["7853200120776062878684798364095072458815029376092732009249414926327459813530","3"],["13816780880028945690020260331303642730075999758909899334839547418969502592169"]]
|
|
185
|
+
*/
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
\# **import**(exportedGroup: _string_): _Group_
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
import { Group } from "@semaphore-protocol/group"
|
|
192
|
+
|
|
193
|
+
const group1 = new Group([1, 2, 3])
|
|
194
|
+
|
|
195
|
+
const exportedGroup = group.export()
|
|
196
|
+
|
|
197
|
+
const group2 = Group.import(exportedGroup)
|
|
198
|
+
|
|
199
|
+
assert(group1.root === group2.root)
|
|
200
|
+
```
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/group
|
|
3
|
-
* @version 4.0.0-alpha.
|
|
3
|
+
* @version 4.0.0-alpha.7
|
|
4
4
|
* @file A library to create and manage Semaphore groups.
|
|
5
5
|
* @copyright Ethereum Foundation 2024
|
|
6
6
|
* @license MIT
|
|
@@ -126,8 +126,7 @@ var Group = /** @class */ (function () {
|
|
|
126
126
|
* @returns Root hash.
|
|
127
127
|
*/
|
|
128
128
|
get: function () {
|
|
129
|
-
|
|
130
|
-
return (_a = this.leanIMT.root) === null || _a === void 0 ? void 0 : _a.toString();
|
|
129
|
+
return this.leanIMT.root ? this.leanIMT.root.toString() : "0";
|
|
131
130
|
},
|
|
132
131
|
enumerable: false,
|
|
133
132
|
configurable: true
|
|
@@ -216,6 +215,27 @@ var Group = /** @class */ (function () {
|
|
|
216
215
|
siblings: siblings.map(String)
|
|
217
216
|
};
|
|
218
217
|
};
|
|
218
|
+
/**
|
|
219
|
+
* It enables the conversion of the group into a JSON string that
|
|
220
|
+
* can be re-used for future imports. This approach is beneficial for
|
|
221
|
+
* large groups, as it avoids re-calculating the tree hashes.
|
|
222
|
+
* @returns The stringified JSON of the group.
|
|
223
|
+
*/
|
|
224
|
+
Group.prototype.export = function () {
|
|
225
|
+
return this.leanIMT.export();
|
|
226
|
+
};
|
|
227
|
+
/**
|
|
228
|
+
* It imports an entire group by initializing the tree without calculating
|
|
229
|
+
* any hashes. Note that it is crucial to ensure the integrity of the
|
|
230
|
+
* exported group.
|
|
231
|
+
* @param nodes The stringified JSON of the group.
|
|
232
|
+
* @returns The group instance.
|
|
233
|
+
*/
|
|
234
|
+
Group.import = function (exportedGroup) {
|
|
235
|
+
var group = new Group();
|
|
236
|
+
group.leanIMT.import(exportedGroup);
|
|
237
|
+
return group;
|
|
238
|
+
};
|
|
219
239
|
return Group;
|
|
220
240
|
}());
|
|
221
241
|
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @module @semaphore-protocol/group
|
|
3
|
-
* @version 4.0.0-alpha.
|
|
3
|
+
* @version 4.0.0-alpha.7
|
|
4
4
|
* @file A library to create and manage Semaphore groups.
|
|
5
5
|
* @copyright Ethereum Foundation 2024
|
|
6
6
|
* @license MIT
|
|
@@ -124,8 +124,7 @@ var Group = /** @class */ (function () {
|
|
|
124
124
|
* @returns Root hash.
|
|
125
125
|
*/
|
|
126
126
|
get: function () {
|
|
127
|
-
|
|
128
|
-
return (_a = this.leanIMT.root) === null || _a === void 0 ? void 0 : _a.toString();
|
|
127
|
+
return this.leanIMT.root ? this.leanIMT.root.toString() : "0";
|
|
129
128
|
},
|
|
130
129
|
enumerable: false,
|
|
131
130
|
configurable: true
|
|
@@ -214,6 +213,27 @@ var Group = /** @class */ (function () {
|
|
|
214
213
|
siblings: siblings.map(String)
|
|
215
214
|
};
|
|
216
215
|
};
|
|
216
|
+
/**
|
|
217
|
+
* It enables the conversion of the group into a JSON string that
|
|
218
|
+
* can be re-used for future imports. This approach is beneficial for
|
|
219
|
+
* large groups, as it avoids re-calculating the tree hashes.
|
|
220
|
+
* @returns The stringified JSON of the group.
|
|
221
|
+
*/
|
|
222
|
+
Group.prototype.export = function () {
|
|
223
|
+
return this.leanIMT.export();
|
|
224
|
+
};
|
|
225
|
+
/**
|
|
226
|
+
* It imports an entire group by initializing the tree without calculating
|
|
227
|
+
* any hashes. Note that it is crucial to ensure the integrity of the
|
|
228
|
+
* exported group.
|
|
229
|
+
* @param nodes The stringified JSON of the group.
|
|
230
|
+
* @returns The group instance.
|
|
231
|
+
*/
|
|
232
|
+
Group.import = function (exportedGroup) {
|
|
233
|
+
var group = new Group();
|
|
234
|
+
group.leanIMT.import(exportedGroup);
|
|
235
|
+
return group;
|
|
236
|
+
};
|
|
217
237
|
return Group;
|
|
218
238
|
}());
|
|
219
239
|
|
package/dist/types/group.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export default class Group {
|
|
|
11
11
|
* Returns the root hash of the tree.
|
|
12
12
|
* @returns Root hash.
|
|
13
13
|
*/
|
|
14
|
-
get root(): string
|
|
14
|
+
get root(): string;
|
|
15
15
|
/**
|
|
16
16
|
* Returns the depth of the tree.
|
|
17
17
|
* @returns Tree depth.
|
|
@@ -60,4 +60,19 @@ export default class Group {
|
|
|
60
60
|
* @returns Proof object.
|
|
61
61
|
*/
|
|
62
62
|
generateMerkleProof(_index: number): MerkleProof;
|
|
63
|
+
/**
|
|
64
|
+
* It enables the conversion of the group into a JSON string that
|
|
65
|
+
* can be re-used for future imports. This approach is beneficial for
|
|
66
|
+
* large groups, as it avoids re-calculating the tree hashes.
|
|
67
|
+
* @returns The stringified JSON of the group.
|
|
68
|
+
*/
|
|
69
|
+
export(): string;
|
|
70
|
+
/**
|
|
71
|
+
* It imports an entire group by initializing the tree without calculating
|
|
72
|
+
* any hashes. Note that it is crucial to ensure the integrity of the
|
|
73
|
+
* exported group.
|
|
74
|
+
* @param nodes The stringified JSON of the group.
|
|
75
|
+
* @returns The group instance.
|
|
76
|
+
*/
|
|
77
|
+
static import(exportedGroup: string): Group;
|
|
63
78
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semaphore-protocol/group",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.7",
|
|
4
4
|
"description": "A library to create and manage Semaphore groups.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,6 +37,6 @@
|
|
|
37
37
|
"rollup-plugin-typescript2": "^0.36.0"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@zk-kit/imt": "^2.0.0-beta"
|
|
40
|
+
"@zk-kit/imt": "^2.0.0-beta.1"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/src/group.ts
CHANGED
|
@@ -17,8 +17,8 @@ export default class Group {
|
|
|
17
17
|
* Returns the root hash of the tree.
|
|
18
18
|
* @returns Root hash.
|
|
19
19
|
*/
|
|
20
|
-
get root(): string
|
|
21
|
-
return this.leanIMT.root
|
|
20
|
+
get root(): string {
|
|
21
|
+
return this.leanIMT.root ? this.leanIMT.root.toString() : "0"
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -102,4 +102,29 @@ export default class Group {
|
|
|
102
102
|
siblings: siblings.map(String)
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* It enables the conversion of the group into a JSON string that
|
|
108
|
+
* can be re-used for future imports. This approach is beneficial for
|
|
109
|
+
* large groups, as it avoids re-calculating the tree hashes.
|
|
110
|
+
* @returns The stringified JSON of the group.
|
|
111
|
+
*/
|
|
112
|
+
export(): string {
|
|
113
|
+
return this.leanIMT.export()
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* It imports an entire group by initializing the tree without calculating
|
|
118
|
+
* any hashes. Note that it is crucial to ensure the integrity of the
|
|
119
|
+
* exported group.
|
|
120
|
+
* @param nodes The stringified JSON of the group.
|
|
121
|
+
* @returns The group instance.
|
|
122
|
+
*/
|
|
123
|
+
static import(exportedGroup: string): Group {
|
|
124
|
+
const group = new Group()
|
|
125
|
+
|
|
126
|
+
group.leanIMT.import(exportedGroup)
|
|
127
|
+
|
|
128
|
+
return group
|
|
129
|
+
}
|
|
105
130
|
}
|