Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fyeo did bnb 01 Fix #19

Merged
merged 4 commits into from
Oct 3, 2023
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 29 additions & 33 deletions src/DidRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -203,54 +203,49 @@ contract DIDRegistry is IDidRegistry, Initializable, UUPSUpgradeable, OwnableUpg
}

function addNativeController(address didIdentifier, address controller) onlyNonGenerativeDid(didIdentifier) onlyAuthorizedKeys(didIdentifier) public {
require(!_doesNativeControllerExist(didIdentifier,controller), "Native controller already exist");
require(_doesNativeControllerExist(didIdentifier,controller) == -1, "Native controller already exist");
didStates[didIdentifier].nativeControllers.push(controller);

emit ControllerAdded(didIdentifier, abi.encodePacked(controller), true);
}

function removeNativeController(address didIdentifier, address controller) onlyNonGenerativeDid(didIdentifier) onlyAuthorizedKeys(didIdentifier) public returns(bool) {
function removeNativeController(address didIdentifier, address controller) onlyNonGenerativeDid(didIdentifier) onlyAuthorizedKeys(didIdentifier) public {
require(didIdentifier != controller, "Cannot remove default authority key");
require(_doesNativeControllerExist(didIdentifier,controller), "Native controller does not exist");

// If an index is returned the controller exits
int index = _doesNativeControllerExist(didIdentifier,controller);
require(index >= 0, "Native controller does not exist");

DidState storage didState = didStates[didIdentifier];

for(uint i=0; i < didState.nativeControllers.length; i++) {
if(didState.nativeControllers[i] == controller) {
// Remove native controller from array (not built into solidity so manipulating array to remove)
didState.nativeControllers[i] = didState.nativeControllers[didState.nativeControllers.length - 1];
didState.nativeControllers.pop();
// Remove native controller from array (not built into solidity so manipulating array to remove)
didState.nativeControllers[uint(index)] = didState.nativeControllers[didState.nativeControllers.length - 1];
didState.nativeControllers.pop();

emit ControllerRemoved(didIdentifier, abi.encodePacked(controller), true);
return true;
}
}
return false;
emit ControllerRemoved(didIdentifier, abi.encodePacked(controller), true);
}

function addExternalController(address didIdentifier, string calldata controller) onlyNonGenerativeDid(didIdentifier) onlyAuthorizedKeys(didIdentifier) public {
require(!_doesExternalControllerExist(didIdentifier,controller), "External controller already exist");
require(_doesExternalControllerExist(didIdentifier,controller) == -1, "External controller already exist");
didStates[didIdentifier].externalControllers.push(controller);

emit ControllerAdded(didIdentifier, abi.encodePacked(controller), false);
}

function removeExternalController(address didIdentifier, string calldata controller) onlyNonGenerativeDid(didIdentifier) onlyAuthorizedKeys(didIdentifier) public returns(bool) {
require(_doesExternalControllerExist(didIdentifier,controller), "External controller does not exist");
function removeExternalController(address didIdentifier, string calldata controller) onlyNonGenerativeDid(didIdentifier) onlyAuthorizedKeys(didIdentifier) public {

// If an index is returned the controller exits
int index = _doesExternalControllerExist(didIdentifier,controller);
require(index >= 0, "External controller does not exist");

DidState storage didState = didStates[didIdentifier];

for(uint i=0; i < didState.externalControllers.length; i++) {
if(_stringCompare(didState.externalControllers[i], controller)) {
// Remove native controller from array (not built into solidity so manipulating array to remove)
didState.externalControllers[i] = didState.externalControllers[didState.externalControllers.length - 1];
didState.externalControllers.pop();

emit ControllerRemoved(didIdentifier, abi.encodePacked(controller), false);
return true;
}
}
return false;
// Remove native controller from array (not built into solidity so manipulating array to remove)
didState.externalControllers[uint(index)] = didState.externalControllers[didState.externalControllers.length - 1];
didState.externalControllers.pop();

emit ControllerRemoved(didIdentifier, abi.encodePacked(controller), false);
}

function _isKeyAuthority(address didIdentifier, address authority) internal view returns(bool) {
Expand Down Expand Up @@ -305,24 +300,25 @@ contract DIDRegistry is IDidRegistry, Initializable, UUPSUpgradeable, OwnableUpg
return false;
}

function _doesNativeControllerExist(address didIdentifier, address controller) internal view returns(bool) {
function _doesNativeControllerExist(address didIdentifier, address controller) internal view returns(int index) {
DidState storage didState = didStates[didIdentifier];
for(uint i=0; i < didState.nativeControllers.length; i++) {
for(uint32 i=0; i < didState.nativeControllers.length; i++) {
Robert-H-Leonard marked this conversation as resolved.
Show resolved Hide resolved
if(didState.nativeControllers[i] == controller) {
return true;
// Return index if controller found
return int32(i);
}
}
return false;
return -1;
}

function _doesExternalControllerExist(address didIdentifier, string calldata controller) internal view returns(bool) {
function _doesExternalControllerExist(address didIdentifier, string calldata controller) internal view returns(int index) {
DidState storage didState = didStates[didIdentifier];
for(uint i=0; i < didState.externalControllers.length; i++) {
if(_stringCompare(didState.externalControllers[i], controller)) {
return true;
return int(i);
}
}
return false;
return -1;
}

function _hasAuthorityVerificationMethod(address didIdentifier) internal view returns(bool) {
Expand Down