Skip to content

Instantly share code, notes, and snippets.

@grbIzl
Created January 23, 2018 14:57
Show Gist options
  • Save grbIzl/14541e57f50b3ceae9831512c8234624 to your computer and use it in GitHub Desktop.
Save grbIzl/14541e57f50b3ceae9831512c8234624 to your computer and use it in GitHub Desktop.
Trivial secret store permissioning contract
pragma solidity ^0.4.11;
contract SecretStorePermissions {
mapping (bytes32 => address[]) keyOwners;
mapping (uint => bytes32) keysIndex;
uint keysCount;
function addKey(address[] users, bytes32 key) public {
keyOwners[key] = users;
keysIndex[keysCount] = key;
keysCount = keysCount + 1;
}
function checkPermissions(address user, bytes32 document) public constant returns (bool) {
bool key_found = false;
address[] owners;
for(uint i = 0; i < keysCount; i++) {
if (keysIndex[i] == document) {
key_found = true;
owners = keyOwners[keysIndex[i]];
}
}
if (!key_found) {
return false;
}
for (uint j = 0; j < owners.length; j++) {
if (owners[j] == user) {
return true;
}
}
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment