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

(Freature) Add ERC-735 claim generation + PoPA ERC-725 Contract #212

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7af9fd4
Add jquery as a web-dapp npm dependency.
unjapones Oct 24, 2018
83af092
Add BackButton UI component the "to" property.
unjapones Oct 24, 2018
2d02627
Add AddClaimToIdentityPage ui component.
unjapones Oct 24, 2018
6fc2b50
Merge remote-tracking branch 'origin/master' into add-to-my-identity-…
unjapones Oct 24, 2018
52ffebc
Add /add-claim-to-identity to web-dapp/app.js.
unjapones Oct 25, 2018
98e141a
Make server-lib/sign function return extra data.
unjapones Oct 25, 2018
7396bb4
Add /issueErc725Claim endpoint to backend.
unjapones Oct 29, 2018
a22a47c
Use /server-lib/validations in issueErc725Claim.js.
unjapones Oct 29, 2018
eb60b46
Use server-lib contract methods in issueErc725Claim.
unjapones Oct 30, 2018
145247d
Merge pull request #207 from unjapones/add-claim-to-identity-page
phahulin Oct 30, 2018
e40d4eb
Add get_erc725_signature to web-dapp/server-lib.
unjapones Oct 30, 2018
e6b2750
Change erc725 code refs to erc735 accordingly.
unjapones Nov 1, 2018
7203f6c
Add ProofOfPhysicalAddressKeyHolder.sol.
unjapones Nov 5, 2018
d2efb95
Add restricto to KeyHolder.removeKey.
unjapones Nov 6, 2018
df5b11d
Fix solidity-coverage errors.
unjapones Nov 7, 2018
7692d8c
Merge branch 'update-logo-registered-addresses-icons' into add-claim-…
unjapones Nov 8, 2018
8d8ed5e
Merge remote-tracking branch 'unjapones/erc-725-with-origin-playgroun…
unjapones Nov 8, 2018
c7bc57f
Update MyAddressesPage "add claim to identity" icon.
unjapones Nov 8, 2018
ee61a4f
Decouple erc735 claim generation and addition.
unjapones Nov 13, 2018
8cb2367
Add AddClaimToIdentityPage add identity tests.
unjapones Nov 13, 2018
43de2bc
Prevent submit+refresh in generate erc-735 form.
unjapones Nov 27, 2018
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 .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
REACT_APP_POPA_CONTRACT_ADDRESS=0xc395234b5d14bed13eb69595da09d7795892087a
REACT_APP_POPA_ERC725_CONTRACT_ADDRESS=0xd0a01db20de37853c02bd33619485ef1ab961929
REACT_APP_PRICE=1
REACT_APP_PRICE_SYMBOL=POA
REACT_APP_POPA_ERC725_URI='http://popa.poa.network'
2 changes: 1 addition & 1 deletion blockchain/.solcover.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ module.exports = {
testrpcOptions: '-p 8555 --mnemonic "toddler weather rocket off sentence chat unlock flame organ shuffle treat awful"',
compileCommand: '../node_modules/.bin/truffle compile',
testCommand: '../node_modules/.bin/truffle test --network coverage',
skipFiles: ['ERC20.sol', 'TestERC20.sol'],
skipFiles: ['ERC20.sol', 'TestERC20.sol', 'ERC725.sol', 'mocks/PhysicalAddressClaimMock.sol'],
};
52,052 changes: 34,533 additions & 17,519 deletions blockchain/build/contracts/ProofOfPhysicalAddress.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion blockchain/contracts/ERC20.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.4.19;
pragma solidity 0.4.24;


contract ERC20 {
Expand Down
30 changes: 30 additions & 0 deletions blockchain/contracts/ERC725.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// From: https://github.com/OriginProtocol/origin-playground/tree/0c9ba5c008d410e1ca82a2b1eed15705db49af0f/contracts
pragma solidity 0.4.24;


contract ERC725 {

uint256 constant MANAGEMENT_KEY = 1;
uint256 constant ACTION_KEY = 2;
uint256 constant CLAIM_SIGNER_KEY = 3;
uint256 constant ENCRYPTION_KEY = 4;

event KeyAdded(bytes32 indexed key, uint256 indexed purpose, uint256 indexed keyType);
event KeyRemoved(bytes32 indexed key, uint256 indexed purpose, uint256 indexed keyType);
event ExecutionRequested(uint256 indexed executionId, address indexed to, uint256 indexed value, bytes data);
event Executed(uint256 indexed executionId, address indexed to, uint256 indexed value, bytes data);
event Approved(uint256 indexed executionId, bool approved);

struct Key {
uint256 purpose; //e.g., MANAGEMENT_KEY = 1, ACTION_KEY = 2, etc.
uint256 keyType; // e.g. 1 = ECDSA, 2 = RSA, etc.
bytes32 key;
}

function getKey(bytes32 _key) public constant returns(uint256 purpose, uint256 keyType, bytes32 key);
function getKeyPurpose(bytes32 _key) public constant returns(uint256 purpose);
function getKeysByPurpose(uint256 _purpose) public constant returns(bytes32[] keys);
function addKey(bytes32 _key, uint256 _purpose, uint256 _keyType) public returns (bool success);
function execute(address _to, uint256 _value, bytes _data) public returns (uint256 executionId);
function approve(uint256 _id, bool _approve) public returns (bool success);
}
2 changes: 1 addition & 1 deletion blockchain/contracts/EthereumClaimsRegistry.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.4.19;
pragma solidity 0.4.24;

import "./EthereumClaimsRegistryInterface.sol";

Expand Down
2 changes: 1 addition & 1 deletion blockchain/contracts/EthereumClaimsRegistryInterface.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.4.19;
pragma solidity 0.4.24;


contract EthereumClaimsRegistryInterface {
Expand Down
164 changes: 164 additions & 0 deletions blockchain/contracts/KeyHolder.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
// From: https://github.com/OriginProtocol/origin-playground/tree/0c9ba5c008d410e1ca82a2b1eed15705db49af0f/contracts
pragma solidity 0.4.24;

import "./ERC725.sol";


contract KeyHolder is ERC725 {

uint256 executionNonce;

struct Execution {
address to;
uint256 value;
bytes data;
bool approved;
bool executed;
}

mapping (bytes32 => Key) keys;
mapping (uint256 => bytes32[]) keysByPurpose;
mapping (uint256 => Execution) executions;

event ExecutionFailed(uint256 indexed executionId, address indexed to, uint256 indexed value, bytes data);

function KeyHolder() public {
bytes32 _key = keccak256(msg.sender);
keys[_key].key = _key;
keys[_key].purpose = 1;
keys[_key].keyType = 1;
keysByPurpose[1].push(_key);
emit KeyAdded(_key, keys[_key].purpose, 1);
}

function getKey(bytes32 _key)
public
view
returns(uint256 purpose, uint256 keyType, bytes32 key)
{
return (keys[_key].purpose, keys[_key].keyType, keys[_key].key);
}

function getKeyPurpose(bytes32 _key)
public
view
returns(uint256 purpose)
{
return (keys[_key].purpose);
}

function getKeysByPurpose(uint256 _purpose)
public
view
returns(bytes32[] _keys)
{
return keysByPurpose[_purpose];
}

function addKey(bytes32 _key, uint256 _purpose, uint256 _type)
public
returns (bool success)
{
require(keys[_key].key != _key, "Key already exists"); // Key should not already exist
if (msg.sender != address(this)) {
// Sender has MANAGEMENT_KEY
require(keyHasPurpose(keccak256(msg.sender), 1), "Sender does not have management key");
}

keys[_key].key = _key;
keys[_key].purpose = _purpose;
keys[_key].keyType = _type;

keysByPurpose[_purpose].push(_key);

emit KeyAdded(_key, _purpose, _type);

return true;
}

function approve(uint256 _id, bool _approve)
public
returns (bool success)
{
require(keyHasPurpose(keccak256(msg.sender), 2), "Sender does not have action key");

emit Approved(_id, _approve);

if (_approve == true) {
executions[_id].approved = true;
success = executions[_id].to.call(executions[_id].data, 0);
if (success) {
executions[_id].executed = true;
emit Executed(
_id,
executions[_id].to,
executions[_id].value,
executions[_id].data
);
return;
} else {
emit ExecutionFailed(
_id,
executions[_id].to,
executions[_id].value,
executions[_id].data
);
return;
}
} else {
executions[_id].approved = false;
}
return true;
}

function execute(address _to, uint256 _value, bytes _data)
public
returns (uint256 executionId)
{
require(!executions[executionNonce].executed, "Already executed");
executions[executionNonce].to = _to;
executions[executionNonce].value = _value;
executions[executionNonce].data = _data;

emit ExecutionRequested(executionNonce, _to, _value, _data);

if (keyHasPurpose(keccak256(msg.sender), 1) || keyHasPurpose(keccak256(msg.sender), 2)) {
approve(executionNonce, true);
}

executionNonce++;
return executionNonce-1;
}

function removeKey(bytes32 _key)
public
returns (bool success)
{
require(keys[_key].key == _key, "No such key");

bytes32 senderKey = keccak256(msg.sender);
require(keys[senderKey].purpose == 1, "MANAGEMENT_KEY purpose required for removeKey");

emit KeyRemoved(keys[_key].key, keys[_key].purpose, keys[_key].keyType);

/* uint index;
(index,) = keysByPurpose[keys[_key].purpose.indexOf(_key);
keysByPurpose[keys[_key].purpose.removeByIndex(index); */

delete keys[_key];

return true;
}

function keyHasPurpose(bytes32 _key, uint256 _purpose)
public
view
returns(bool result)
{
bool isThere;
if (keys[_key].key == 0) return false;
isThere = keys[_key].purpose <= _purpose;
return isThere;
}

}
2 changes: 1 addition & 1 deletion blockchain/contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.4.19;
pragma solidity 0.4.24;


contract Migrations {
Expand Down
2 changes: 1 addition & 1 deletion blockchain/contracts/PhysicalAddressClaim.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.4.19;
pragma solidity 0.4.24;


library PhysicalAddressClaim {
Expand Down
2 changes: 1 addition & 1 deletion blockchain/contracts/ProofOfPhysicalAddress.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.4.19;
pragma solidity 0.4.24;

import "./EthereumClaimsRegistryInterface.sol";
import "./PhysicalAddressClaim.sol";
Expand Down
32 changes: 32 additions & 0 deletions blockchain/contracts/ProofOfPhysicalAddressKeyHolder.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
pragma solidity 0.4.24;

import "./KeyHolder.sol";


contract ProofOfPhysicalAddressKeyHolder is KeyHolder {
address public owner;
address public signer;

constructor() public {
owner = msg.sender;
signer = owner;
}

// Events:
event LogSignerChanged(address newSigner);

// Modifiers:
modifier onlyOwner() {
require(msg.sender == owner);
_;
}

// Methods:
// set address that is used on server-side to calculate signatures
// and on contract-side to verify them
function setSigner(address newSigner) public onlyOwner {
signer = newSigner;
LogSignerChanged(newSigner);
}

}
2 changes: 1 addition & 1 deletion blockchain/contracts/TestERC20.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity 0.4.19;
pragma solidity 0.4.24;

import "./ERC20.sol";

Expand Down
32 changes: 32 additions & 0 deletions blockchain/contracts/mocks/PhysicalAddressClaimMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
pragma solidity 0.4.24;

import "../PhysicalAddressClaim.sol";


/**
* PhysicalAddressClaim "library mock contract", needed to make coverage work:
* https://github.com/sc-forks/solidity-coverage/issues/234
* Essentialy this is used only on tests, and JS tests files will use this
* contracts' methods instead of the ones from the library.
*/
contract PhysicalAddressClaimMock {

function encode(uint256 _confirmationBlockNumber) public pure returns(bytes32) {
return PhysicalAddressClaim.encode(_confirmationBlockNumber);
}

function decode(bytes32 _claim) public pure returns(
uint256 version,
uint256 confirmation
) {
return PhysicalAddressClaim.decode(_claim);
}

function decodeVersion(bytes32 _claim) public pure returns(uint256 version) {
return PhysicalAddressClaim.decodeVersion(_claim);
}

function decodeConfirmation(bytes32 _claim) public pure returns(uint256 confirmation) {
return PhysicalAddressClaim.decodeConfirmation(_claim);
}
}
5 changes: 5 additions & 0 deletions blockchain/migrations/1522104575_popa.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
var POPA = artifacts.require('ProofOfPhysicalAddress');
var PhysicalAddressClaim = artifacts.require('PhysicalAddressClaim');
var PhysicalAddressClaimMock = artifacts.require('mocks/PhysicalAddressClaimMock');
var EthereumClaimsRegistry = artifacts.require('EthereumClaimsRegistry');
var TestERC20 = artifacts.require('TestERC20');
var POPAKeyHolder = artifacts.require('ProofOfPhysicalAddressKeyHolder');

module.exports = function(deployer, network) {
return deployer.then(async () => {
Expand All @@ -19,10 +21,13 @@ module.exports = function(deployer, network) {

if (network === 'test' || network === 'coverage') {
await deployer.deploy(TestERC20);
await deployer.link(PhysicalAddressClaim, PhysicalAddressClaimMock);
await deployer.deploy(PhysicalAddressClaimMock);
}

const gas = network === 'coverage' ? '0xfffffffffff' : '6000000';

await deployer.deploy(POPA, ethereumClaimsRegistryAddress, { gas });
await deployer.deploy(POPAKeyHolder);
});
};
Loading