@semaphore-protocol/contracts 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/Semaphore.sol
CHANGED
|
@@ -56,6 +56,11 @@ contract Semaphore is ISemaphore, SemaphoreGroups {
|
|
|
56
56
|
_updateGroupAdmin(groupId, newAdmin);
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/// @dev See {SemaphoreGroups- acceptGroupAdmin}.
|
|
60
|
+
function acceptGroupAdmin(uint256 groupId) external override {
|
|
61
|
+
_acceptGroupAdmin(groupId);
|
|
62
|
+
}
|
|
63
|
+
|
|
59
64
|
/// @dev See {ISemaphore-updateGroupMerkleTreeDuration}.
|
|
60
65
|
function updateGroupMerkleTreeDuration(
|
|
61
66
|
uint256 groupId,
|
package/base/SemaphoreGroups.sol
CHANGED
|
@@ -19,6 +19,10 @@ abstract contract SemaphoreGroups is ISemaphoreGroups {
|
|
|
19
19
|
/// The admin can be an Ethereum account or a smart contract.
|
|
20
20
|
mapping(uint256 => address) internal admins;
|
|
21
21
|
|
|
22
|
+
/// @dev Gets a group id and returns any pending admin.
|
|
23
|
+
/// The pending admin can be an Ethereum account or a smart contract.
|
|
24
|
+
mapping(uint256 => address) internal pendingAdmins;
|
|
25
|
+
|
|
22
26
|
/// @dev Checks if the group admin is the transaction sender.
|
|
23
27
|
/// @param groupId: Id of the group.
|
|
24
28
|
modifier onlyGroupAdmin(uint256 groupId) {
|
|
@@ -48,13 +52,30 @@ abstract contract SemaphoreGroups is ISemaphoreGroups {
|
|
|
48
52
|
emit GroupAdminUpdated(groupId, address(0), admin);
|
|
49
53
|
}
|
|
50
54
|
|
|
51
|
-
/// @dev Updates the group admin.
|
|
55
|
+
/// @dev Updates the group admin. In order for the new admin to actually be updated,
|
|
56
|
+
/// they must explicitly accept by calling `_acceptGroupAdmin`.
|
|
52
57
|
/// @param groupId: Id of the group.
|
|
53
58
|
/// @param newAdmin: New admin of the group.
|
|
54
59
|
function _updateGroupAdmin(uint256 groupId, address newAdmin) internal virtual onlyGroupAdmin(groupId) {
|
|
55
|
-
|
|
60
|
+
pendingAdmins[groupId] = newAdmin;
|
|
61
|
+
|
|
62
|
+
emit GroupAdminPending(groupId, msg.sender, newAdmin);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/// @dev Allows the new admin to accept to update the group admin with their address.
|
|
66
|
+
/// @param groupId: Id of the group.
|
|
67
|
+
function _acceptGroupAdmin(uint256 groupId) internal virtual {
|
|
68
|
+
if (pendingAdmins[groupId] != msg.sender) {
|
|
69
|
+
revert Semaphore__CallerIsNotThePendingGroupAdmin();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
address oldAdmin = admins[groupId];
|
|
73
|
+
|
|
74
|
+
admins[groupId] = msg.sender;
|
|
75
|
+
|
|
76
|
+
delete pendingAdmins[groupId];
|
|
56
77
|
|
|
57
|
-
emit GroupAdminUpdated(groupId, msg.sender
|
|
78
|
+
emit GroupAdminUpdated(groupId, oldAdmin, msg.sender);
|
|
58
79
|
}
|
|
59
80
|
|
|
60
81
|
/// @dev Adds an identity commitment to an existing group.
|
|
@@ -70,6 +70,9 @@ interface ISemaphore {
|
|
|
70
70
|
/// @dev See {SemaphoreGroups-_updateGroupAdmin}.
|
|
71
71
|
function updateGroupAdmin(uint256 groupId, address newAdmin) external;
|
|
72
72
|
|
|
73
|
+
/// @dev See {SemaphoreGroups-_acceptGroupAdmin}.
|
|
74
|
+
function acceptGroupAdmin(uint256 groupId) external;
|
|
75
|
+
|
|
73
76
|
/// @dev Updates the group Merkle tree duration.
|
|
74
77
|
/// @param groupId: Id of the group.
|
|
75
78
|
/// @param newMerkleTreeDuration: New Merkle tree duration.
|
|
@@ -5,17 +5,24 @@ pragma solidity 0.8.23;
|
|
|
5
5
|
interface ISemaphoreGroups {
|
|
6
6
|
error Semaphore__GroupDoesNotExist();
|
|
7
7
|
error Semaphore__CallerIsNotTheGroupAdmin();
|
|
8
|
+
error Semaphore__CallerIsNotThePendingGroupAdmin();
|
|
8
9
|
|
|
9
10
|
/// @dev Event emitted when a new group is created.
|
|
10
11
|
/// @param groupId: Id of the group.
|
|
11
12
|
event GroupCreated(uint256 indexed groupId);
|
|
12
13
|
|
|
13
|
-
/// @dev Event emitted when
|
|
14
|
+
/// @dev Event emitted when a new admin is assigned to a group.
|
|
14
15
|
/// @param groupId: Id of the group.
|
|
15
16
|
/// @param oldAdmin: Old admin of the group.
|
|
16
17
|
/// @param newAdmin: New admin of the group.
|
|
17
18
|
event GroupAdminUpdated(uint256 indexed groupId, address indexed oldAdmin, address indexed newAdmin);
|
|
18
19
|
|
|
20
|
+
/// @dev Event emitted when a group admin is being updated.
|
|
21
|
+
/// @param groupId: Id of the group.
|
|
22
|
+
/// @param oldAdmin: Old admin of the group.
|
|
23
|
+
/// @param newAdmin: New admin of the group.
|
|
24
|
+
event GroupAdminPending(uint256 indexed groupId, address indexed oldAdmin, address indexed newAdmin);
|
|
25
|
+
|
|
19
26
|
/// @dev Event emitted when a new identity commitment is added.
|
|
20
27
|
/// @param groupId: Group id of the group.
|
|
21
28
|
/// @param index: Merkle tree leaf index.
|