Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Solium (solidity linter) #523

Merged
merged 20 commits into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from 19 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
2 changes: 2 additions & 0 deletions .soliumignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
contracts/contracts/Migrations.sol
23 changes: 23 additions & 0 deletions .soliumrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"extends": "solium:recommended",
"plugins": [
"security"
],
"rules": {
"security/no-inline-assembly": "off",
"security/no-tx-origin": "off",
"security/no-block-members": "off",
"security/no-low-level-calls": "off",
"security/no-send": "off",
"max-len": "off",
"no-empty-blocks": "off",
"quotes": [
"error",
"double"
],
"indentation": [
"error",
4
]
}
}
9 changes: 5 additions & 4 deletions contracts/contracts/identity/ClaimHolder.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
pragma solidity ^0.4.24;

import './ERC735.sol';
import './KeyHolder.sol';
import "./ERC735.sol";
import "./KeyHolder.sol";
import "./ClaimHolderLibrary.sol";


contract ClaimHolder is KeyHolder, ERC735 {

ClaimHolderLibrary.Claims claims;
Expand Down Expand Up @@ -57,7 +58,7 @@ contract ClaimHolder is KeyHolder, ERC735 {

function getClaim(bytes32 _claimId)
public
constant
view
returns(
uint256 topic,
uint256 scheme,
Expand All @@ -72,7 +73,7 @@ contract ClaimHolder is KeyHolder, ERC735 {

function getClaimIdsByTopic(uint256 _topic)
public
constant
view
returns(bytes32[] claimIds)
{
return claims.byTopic[_topic];
Expand Down
287 changes: 144 additions & 143 deletions contracts/contracts/identity/ClaimHolderLibrary.sol
Original file line number Diff line number Diff line change
@@ -1,154 +1,155 @@
pragma solidity ^0.4.24;

import './KeyHolderLibrary.sol';
import "./KeyHolderLibrary.sol";


library ClaimHolderLibrary {
event ClaimAdded(bytes32 indexed claimId, uint256 indexed topic, uint256 scheme, address indexed issuer, bytes signature, bytes data, string uri);
event ClaimRemoved(bytes32 indexed claimId, uint256 indexed topic, uint256 scheme, address indexed issuer, bytes signature, bytes data, string uri);

struct Claim {
uint256 topic;
uint256 scheme;
address issuer; // msg.sender
bytes signature; // this.address + topic + data
bytes data;
string uri;
}

struct Claims {
mapping (bytes32 => Claim) byId;
mapping (uint256 => bytes32[]) byTopic;
}

function addClaim(
KeyHolderLibrary.KeyHolderData storage _keyHolderData,
Claims storage _claims,
uint256 _topic,
uint256 _scheme,
address _issuer,
bytes _signature,
bytes _data,
string _uri
)
public
returns (bytes32 claimRequestId)
{
if (msg.sender != address(this)) {
require(KeyHolderLibrary.keyHasPurpose( _keyHolderData, keccak256(abi.encodePacked(msg.sender)), 3), "Sender does not have claim signer key");
}

bytes32 claimId = keccak256(abi.encodePacked(_issuer, _topic));

if (_claims.byId[claimId].issuer != _issuer) {
_claims.byTopic[_topic].push(claimId);
}

_claims.byId[claimId].topic = _topic;
_claims.byId[claimId].scheme = _scheme;
_claims.byId[claimId].issuer = _issuer;
_claims.byId[claimId].signature = _signature;
_claims.byId[claimId].data = _data;
_claims.byId[claimId].uri = _uri;

emit ClaimAdded(
claimId,
_topic,
_scheme,
_issuer,
_signature,
_data,
_uri
);

return claimId;
}

function addClaims(
KeyHolderLibrary.KeyHolderData storage _keyHolderData,
Claims storage _claims,
uint256[] _topic,
address[] _issuer,
bytes _signature,
bytes _data,
uint256[] _offsets
)
public
{
uint offset = 0;
for (uint8 i = 0; i < _topic.length; i++) {
addClaim(
_keyHolderData,
_claims,
_topic[i],
1,
_issuer[i],
getBytes(_signature, (i * 65), 65),
getBytes(_data, offset, _offsets[i]),
""
);
offset += _offsets[i];
}
}

function removeClaim(
KeyHolderLibrary.KeyHolderData storage _keyHolderData,
Claims storage _claims,
bytes32 _claimId
)
public
returns (bool success)
{
if (msg.sender != address(this)) {
require(KeyHolderLibrary.keyHasPurpose(_keyHolderData, keccak256(abi.encodePacked(msg.sender)), 1), "Sender does not have management key");
}

emit ClaimRemoved(
_claimId,
_claims.byId[_claimId].topic,
_claims.byId[_claimId].scheme,
_claims.byId[_claimId].issuer,
_claims.byId[_claimId].signature,
_claims.byId[_claimId].data,
_claims.byId[_claimId].uri
);

delete _claims.byId[_claimId];
return true;
}

function getClaim(Claims storage _claims, bytes32 _claimId)
public
constant
returns(
event ClaimAdded(bytes32 indexed claimId, uint256 indexed topic, uint256 scheme, address indexed issuer, bytes signature, bytes data, string uri);
event ClaimRemoved(bytes32 indexed claimId, uint256 indexed topic, uint256 scheme, address indexed issuer, bytes signature, bytes data, string uri);

struct Claim {
uint256 topic;
uint256 scheme;
address issuer; // msg.sender
bytes signature; // this.address + topic + data
bytes data;
string uri;
}

struct Claims {
mapping (bytes32 => Claim) byId;
mapping (uint256 => bytes32[]) byTopic;
}

function addClaim(
KeyHolderLibrary.KeyHolderData storage _keyHolderData,
Claims storage _claims,
uint256 _topic,
uint256 _scheme,
address _issuer,
bytes _signature,
bytes _data,
string _uri
)
public
returns (bytes32 claimRequestId)
{
if (msg.sender != address(this)) {
require(KeyHolderLibrary.keyHasPurpose(_keyHolderData, keccak256(abi.encodePacked(msg.sender)), 3), "Sender does not have claim signer key");
}

bytes32 claimId = keccak256(abi.encodePacked(_issuer, _topic));

if (_claims.byId[claimId].issuer != _issuer) {
_claims.byTopic[_topic].push(claimId);
}

_claims.byId[claimId].topic = _topic;
_claims.byId[claimId].scheme = _scheme;
_claims.byId[claimId].issuer = _issuer;
_claims.byId[claimId].signature = _signature;
_claims.byId[claimId].data = _data;
_claims.byId[claimId].uri = _uri;

emit ClaimAdded(
claimId,
_topic,
_scheme,
_issuer,
_signature,
_data,
_uri
);

return claimId;
}

function addClaims(
KeyHolderLibrary.KeyHolderData storage _keyHolderData,
Claims storage _claims,
uint256[] _topic,
address[] _issuer,
bytes _signature,
bytes _data,
uint256[] _offsets
)
public
{
uint offset = 0;
for (uint8 i = 0; i < _topic.length; i++) {
addClaim(
_keyHolderData,
_claims,
_topic[i],
1,
_issuer[i],
getBytes(_signature, (i * 65), 65),
getBytes(_data, offset, _offsets[i]),
""
);
offset += _offsets[i];
}
}

function removeClaim(
KeyHolderLibrary.KeyHolderData storage _keyHolderData,
Claims storage _claims,
bytes32 _claimId
)
public
returns (bool success)
{
if (msg.sender != address(this)) {
require(KeyHolderLibrary.keyHasPurpose(_keyHolderData, keccak256(abi.encodePacked(msg.sender)), 1), "Sender does not have management key");
}

emit ClaimRemoved(
_claimId,
_claims.byId[_claimId].topic,
_claims.byId[_claimId].scheme,
_claims.byId[_claimId].issuer,
_claims.byId[_claimId].signature,
_claims.byId[_claimId].data,
_claims.byId[_claimId].uri
);

delete _claims.byId[_claimId];
return true;
}

function getClaim(Claims storage _claims, bytes32 _claimId)
public
view
returns(
uint256 topic,
uint256 scheme,
address issuer,
bytes signature,
bytes data,
string uri
)
{
return (
_claims.byId[_claimId].topic,
_claims.byId[_claimId].scheme,
_claims.byId[_claimId].issuer,
_claims.byId[_claimId].signature,
_claims.byId[_claimId].data,
_claims.byId[_claimId].uri
);
}

function getBytes(bytes _str, uint256 _offset, uint256 _length)
internal
pure
returns (bytes)
{
bytes memory sig = new bytes(_length);
uint256 j = 0;
for (uint256 k = _offset; k< _offset + _length; k++) {
sig[j] = _str[k];
j++;
}
return sig;
}
)
{
return (
_claims.byId[_claimId].topic,
_claims.byId[_claimId].scheme,
_claims.byId[_claimId].issuer,
_claims.byId[_claimId].signature,
_claims.byId[_claimId].data,
_claims.byId[_claimId].uri
);
}

function getBytes(bytes _str, uint256 _offset, uint256 _length)
internal
pure
returns (bytes)
{
bytes memory sig = new bytes(_length);
uint256 j = 0;
for (uint256 k = _offset; k < _offset + _length; k++) {
sig[j] = _str[k];
j++;
}
return sig;
}
}
3 changes: 2 additions & 1 deletion contracts/contracts/identity/ClaimHolderPresigned.sol
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
pragma solidity ^0.4.24;

import './ClaimHolderRegistered.sol';
import "./ClaimHolderRegistered.sol";

/**
* NOTE: This contract exists as a convenience for deploying an identity with
* some 'pre-signed' claims. If you don't care about that, just use ClaimHolder
* instead.
*/


contract ClaimHolderPresigned is ClaimHolderRegistered {

constructor(
Expand Down
Loading