diff --git a/src/GuardianManager.sol b/src/GuardianManager.sol index 96a990c..f421921 100644 --- a/src/GuardianManager.sol +++ b/src/GuardianManager.sol @@ -252,4 +252,16 @@ abstract contract GuardianManager is IGuardianManager { function removeAllGuardians(address account) internal { guardiansStorage[account].removeAll(guardiansStorage[account].keys()); } + + /** + * @notice Gets all guardians associated with an account + * @dev Return an array containing all the keys. O(n) where n <= 32 + * + * WARNING: This operation will copy the entire storage to memory, which could + * be quite expensive. + * @param account The address of the account associated with the guardians + */ + function getAllGuardians(address account) external returns (address[] memory) { + return guardiansStorage[account].keys(); + } } diff --git a/src/interfaces/IGuardianManager.sol b/src/interfaces/IGuardianManager.sol index 51e4734..2f6ac27 100644 --- a/src/interfaces/IGuardianManager.sol +++ b/src/interfaces/IGuardianManager.sol @@ -53,4 +53,6 @@ interface IGuardianManager { function removeGuardian(address guardian) external; function changeThreshold(uint256 threshold) external; + + function getAllGuardians(address account) external returns (address[] memory); } diff --git a/test/unit/GuardianManager/getAllGuardians.t.sol b/test/unit/GuardianManager/getAllGuardians.t.sol new file mode 100644 index 0000000..7905016 --- /dev/null +++ b/test/unit/GuardianManager/getAllGuardians.t.sol @@ -0,0 +1,18 @@ +// SPDX-License-Identifier: MIT +pragma solidity ^0.8.25; + +import { UnitBase } from "../UnitBase.t.sol"; + +contract GuardianManager_getAllGuardians_Test is UnitBase { + function setUp() public override { + super.setUp(); + } + + function test_getAllGuardians_Succeeds() public { + address[] memory guardians = emailRecoveryModule.getAllGuardians(accountAddress1); + assertEq(guardians.length, guardians1.length); + assertEq(guardians[0], guardians1[0]); + assertEq(guardians[1], guardians1[1]); + assertEq(guardians[2], guardians1[2]); + } +}