Skip to content

Commit a407555

Browse files
ONCHAINID v2 (#73)
## [2.0.0] Version 2.0.0 Audited by Hacken, more details [here](https://tokeny.com/wp-content/uploads/2023/04/Tokeny_ONCHAINID_SC-Audit_Report.pdf) ### Breaking changes ## Deprecation Notice - ClaimIssuer `revokeClaim` is now deprecated, usage of `revokeClaimBySignature(bytes signature)` is preferred. ### Added - Add typechain-types (targeting ethers v5). - Add tests cases for `execute` and `approve` methods. - Add method `revokeClaimBySignature(bytes signature)` in ClaimIssuer, prefer using this method instead of the now deprecated `revokeClaim` method. - Add checks on ClaimIssuer to prevent revoking an already revoked claim. - Added Factory for ONCHAINIDs ### Updated - Switch development tooling to hardhat. - Implemented tests for hardhat (using fixture for faster testing time). - Prevent calling `approve` method with a non-request execute nonce (added a require on `executionNone`). - Update NatSpec of `execute` and `approve` methods. --------- Co-authored-by: Joachim <[email protected]>
1 parent a1bd352 commit a407555

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

63 files changed

+19984
-9274
lines changed

.eslintrc.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
module.exports = {
2-
extends: [
3-
'airbnb-base',
4-
'plugin:prettier/recommended',
5-
'plugin:import/errors',
6-
'plugin:import/warnings',
7-
'plugin:import/typescript',
8-
],
2+
extends: [],
93
parserOptions: { ecmaVersion: 2018 },
104
root: true,
115
rules: {

.github/workflows/publish-prerelease.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ jobs:
99
if: "github.event.release.prerelease"
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v1
13-
- uses: actions/setup-node@v1
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-node@v3
1414
with:
15-
node-version: 12
15+
node-version: 16
1616
- run: npm ci
1717
- run: npm run build
1818

1919
publish-gpr:
2020
needs: build
2121
runs-on: ubuntu-latest
2222
steps:
23-
- uses: actions/checkout@v1
24-
- uses: actions/setup-node@v1
23+
- uses: actions/checkout@v2
24+
- uses: actions/setup-node@v3
2525
with:
26-
node-version: 12
26+
node-version: 16
2727
registry-url: https://npm.pkg.github.com/
2828
scope: '@onchain-id'
2929
- run: npm ci
@@ -36,10 +36,10 @@ jobs:
3636
needs: build
3737
runs-on: ubuntu-latest
3838
steps:
39-
- uses: actions/checkout@v1
40-
- uses: actions/setup-node@v1
39+
- uses: actions/checkout@v2
40+
- uses: actions/setup-node@v3
4141
with:
42-
node-version: 12
42+
node-version: 16
4343
registry-url: https://registry.npmjs.org/
4444
scope: '@onchain-id'
4545
- run: npm ci

.github/workflows/publish-release.yml

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ jobs:
99
if: "!github.event.release.prerelease"
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v1
13-
- uses: actions/setup-node@v1
12+
- uses: actions/checkout@v2
13+
- uses: actions/setup-node@v3
1414
with:
15-
node-version: 12
15+
node-version: 16
1616
- run: npm ci
1717
- run: npm run build
1818

1919
publish-gpr:
2020
needs: build
2121
runs-on: ubuntu-latest
2222
steps:
23-
- uses: actions/checkout@v1
24-
- uses: actions/setup-node@v1
23+
- uses: actions/checkout@v2
24+
- uses: actions/setup-node@v3
2525
with:
26-
node-version: 12
26+
node-version: 16
2727
registry-url: https://npm.pkg.github.com/
2828
scope: '@onchain-id'
2929
- run: npm ci
@@ -36,10 +36,10 @@ jobs:
3636
needs: build
3737
runs-on: ubuntu-latest
3838
steps:
39-
- uses: actions/checkout@v1
40-
- uses: actions/setup-node@v1
39+
- uses: actions/checkout@v2
40+
- uses: actions/setup-node@v3
4141
with:
42-
node-version: 12
42+
node-version: 16
4343
registry-url: https://registry.npmjs.org/
4444
scope: '@onchain-id'
4545
- run: npm ci

.github/workflows/push_checking.yml

+6-6
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ jobs:
66
lint:
77
name: "Lint"
88
runs-on: ubuntu-latest
9-
container: node:12
9+
container: node:16
1010

1111
strategy:
1212
matrix:
13-
node-version: [12.x]
13+
node-version: [16.x]
1414

1515
steps:
1616
- uses: actions/checkout@v2
1717
- name: Use Node.js ${{ matrix.node-version }}
18-
uses: actions/setup-node@v1
18+
uses: actions/setup-node@v3
1919
with:
2020
node-version: ${{ matrix.node-version }}
2121
registry-url: https://npm.pkg.github.com/
@@ -32,11 +32,11 @@ jobs:
3232
test:
3333
name: "Build and Test"
3434
runs-on: ubuntu-latest
35-
container: node:12
35+
container: node:16
3636

3737
strategy:
3838
matrix:
39-
node-version: [12.x]
39+
node-version: [16.x]
4040

4141
steps:
4242
- uses: actions/checkout@v2
@@ -53,4 +53,4 @@ jobs:
5353
- name: Build application
5454
run: npm run build
5555
- name: Run tests
56-
run: npm run test
56+
run: npm run coverage

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,9 @@ build/
1717
# IDE
1818
.idea
1919
.vscode
20+
21+
# Artifacts
22+
artifacts
23+
coverage.json
24+
cache
25+
typechain-types

.solhint.json

+29-12
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
{
22
"extends": "solhint:recommended",
33
"rules": {
4-
"func-order": "off",
5-
"mark-callable-contracts": "off",
6-
"compiler-version": ["error", "^0.8.0"],
7-
"no-inline-assembly": "off",
8-
"avoid-call-value": "off",
9-
"no-empty-blocks": "off",
10-
"state-visibility": "off",
11-
"func-visibility": "off",
12-
"reason-string": "off",
13-
"no-complex-fallback": "off",
14-
"avoid-low-level-calls": "off"
15-
}
4+
"compiler-version": ["error", "^0.8.17"],
5+
"func-visibility": ["warn", { "ignoreConstructors": true }],
6+
"reentrancy": "error",
7+
"state-visibility": "error",
8+
"quotes": ["error", "double"],
9+
"const-name-snakecase": "error",
10+
"contract-name-camelcase": "error",
11+
"event-name-camelcase": "error",
12+
"func-name-mixedcase": "error",
13+
"func-param-name-mixedcase": "error",
14+
"modifier-name-mixedcase": "error",
15+
"private-vars-leading-underscore": ["error", { "strict": false }],
16+
"use-forbidden-name": "error",
17+
"var-name-mixedcase": "error",
18+
"imports-on-top": "error",
19+
"ordering": "error",
20+
"visibility-modifier-order": "error",
21+
"code-complexity": ["error", 7],
22+
"function-max-lines": ["error", 50],
23+
"max-line-length": ["error", 130],
24+
"max-states-count": ["error", 15],
25+
"no-empty-blocks": "error",
26+
"no-unused-vars": "error",
27+
"payable-fallback": "error",
28+
"constructor-syntax": "error",
29+
"not-rely-on-time": "off",
30+
"reason-string": "off"
31+
},
32+
"plugins": ["prettier"]
1633
}

CHANGELOG.md

+23
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,29 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [2.0.0]
8+
9+
Version 2.0.0 Audited by Hacken, more details [here](https://tokeny.com/wp-content/uploads/2023/04/Tokeny_ONCHAINID_SC-Audit_Report.pdf)
10+
11+
### Breaking changes
12+
13+
## Deprecation Notice
14+
- ClaimIssuer `revokeClaim` is now deprecated, usage of `revokeClaimBySignature(bytes signature)` is preferred.
15+
16+
### Added
17+
- Add typechain-types (targeting ethers v5).
18+
- Add tests cases for `execute` and `approve` methods.
19+
- Add method `revokeClaimBySignature(bytes signature)` in ClaimIssuer, prefer using this method instead of the now
20+
deprecated `revokeClaim` method.
21+
- Add checks on ClaimIssuer to prevent revoking an already revoked claim.
22+
- Added Factory for ONCHAINIDs
23+
24+
### Updated
25+
- Switch development tooling to hardhat.
26+
- Implemented tests for hardhat (using fixture for faster testing time).
27+
- Prevent calling `approve` method with a non-request execute nonce (added a require on `executionNone`).
28+
- Update NatSpec of `execute` and `approve` methods.
29+
730
## [1.4.0] - 2021-01-26
831
### Updated
932
- Remove constructor's visibility

README.md

+21-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
![OnchainID Smart Contracts](./onchainid_logo_small.png)
1+
![OnchainID Smart Contracts](./onchainid_logo_final.png)
2+
---
23

4+
![GitHub](https://img.shields.io/github/license/onchain-id/solidity?color=green)
5+
![GitHub release (latest by date)](https://img.shields.io/github/v/release/onchain-id/solidity)
6+
![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/onchain-id/solidity/publish-release.yml)
7+
![GitHub repo size](https://img.shields.io/github/repo-size/onchain-id/solidity)
8+
![GitHub Release Date](https://img.shields.io/github/release-date/onchain-id/solidity)
9+
10+
---
311
# OnchainID Smart Contracts
412

513
Smart Contracts for secure Blockchain Identities, implementation of the ERC734 and ERC735 proposal standards.
614

7-
Learn more about OnchainID and Blockchain Identities on the official OnchainID website: [https://onchainid.com](https://onchainid.com).
15+
Learn more about OnchainID and Blockchain Identities on the official OnchainID website: [https://onchainid.com](https://onchainid.com).
816

917
## Usage
1018

@@ -21,15 +29,21 @@ Learn more about OnchainID and Blockchain Identities on the official OnchainID w
2129

2230
## Development
2331

24-
- Install dev dependencies `npm i`
32+
- Install dev dependencies `npm ci`
2533
- Update interfaces and contracts code.
2634
- Run lint `npm run lint`
2735
- Compile code `npm run compile`
2836

2937
### Testing
3038

31-
- Install [Ganache](https://www.trufflesuite.com/ganache) or run another blockchain network.
32-
33-
> The contracts WILL NOT WORK without at least version 2 of Ganache!
34-
39+
- Run `npm ci`
3540
- Run `npm test`
41+
- Test will be executed against a local Hardhat network.
42+
43+
---
44+
45+
<div style="padding: 16px;">
46+
<a href="https://tokeny.com/wp-content/uploads/2023/04/Tokeny_ONCHAINID_SC-Audit_Report.pdf" target="_blank">
47+
<img src="https://hacken.io/wp-content/uploads/2023/02/ColorWBTypeSmartContractAuditBackFilled.png" alt="Proofed by Hacken - Smart contract audit" style="width: 258px; height: 100px;">
48+
</a>
49+
</div>

contracts/ClaimIssuer.sol

+42-32
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,54 @@
11
// SPDX-License-Identifier: GPL-3.0
2-
pragma solidity ^0.8.0;
2+
pragma solidity 0.8.17;
33

44
import "./interface/IClaimIssuer.sol";
55
import "./Identity.sol";
66

77
contract ClaimIssuer is IClaimIssuer, Identity {
88
mapping (bytes => bool) public revokedClaims;
99

10+
// solhint-disable-next-line no-empty-blocks
1011
constructor(address initialManagementKey) Identity(initialManagementKey, false) {}
1112

1213
/**
13-
* @dev Revoke a claim previously issued, the claim is no longer considered as valid after revocation.
14-
* @param _claimId the id of the claim
15-
* @param _identity the address of the identity contract
16-
* @return isRevoked true when the claim is revoked
14+
* @dev See {IClaimIssuer-revokeClaimBySignature}.
1715
*/
18-
function revokeClaim(bytes32 _claimId, address _identity) public override delegatedOnly returns(bool) {
16+
function revokeClaimBySignature(bytes calldata signature) external override delegatedOnly onlyManager {
17+
require(!revokedClaims[signature], "Conflict: Claim already revoked");
18+
19+
revokedClaims[signature] = true;
20+
21+
emit ClaimRevoked(signature);
22+
}
23+
24+
/**
25+
* @dev See {IClaimIssuer-revokeClaim}.
26+
*/
27+
function revokeClaim(bytes32 _claimId, address _identity) external override delegatedOnly onlyManager returns(bool) {
1928
uint256 foundClaimTopic;
2029
uint256 scheme;
2130
address issuer;
22-
bytes memory sig;
23-
bytes memory data;
24-
25-
if (msg.sender != address(this)) {
26-
require(keyHasPurpose(keccak256(abi.encode(msg.sender)), 1), "Permissions: Sender does not have management key");
27-
}
31+
bytes memory sig;
32+
bytes memory data;
2833

2934
( foundClaimTopic, scheme, issuer, sig, data, ) = Identity(_identity).getClaim(_claimId);
3035

36+
require(!revokedClaims[sig], "Conflict: Claim already revoked");
37+
3138
revokedClaims[sig] = true;
39+
emit ClaimRevoked(sig);
3240
return true;
3341
}
3442

3543
/**
36-
* @dev Returns revocation status of a claim.
37-
* @param _sig the signature of the claim
38-
* @return isRevoked true if the claim is revoked and false otherwise
44+
* @dev See {IClaimIssuer-isClaimValid}.
3945
*/
40-
function isClaimRevoked(bytes memory _sig) public override view returns (bool) {
41-
if (revokedClaims[_sig]) {
42-
return true;
43-
}
44-
45-
return false;
46-
}
47-
48-
/**
49-
* @dev Checks if a claim is valid.
50-
* @param _identity the identity contract related to the claim
51-
* @param claimTopic the claim topic of the claim
52-
* @param sig the signature of the claim
53-
* @param data the data field of the claim
54-
* @return claimValid true if the claim is valid, false otherwise
55-
*/
56-
function isClaimValid(IIdentity _identity, uint256 claimTopic, bytes memory sig, bytes memory data) public override view returns (bool claimValid)
46+
function isClaimValid(
47+
IIdentity _identity,
48+
uint256 claimTopic,
49+
bytes memory sig,
50+
bytes memory data)
51+
external override view returns (bool claimValid)
5752
{
5853
bytes32 dataHash = keccak256(abi.encode(_identity, claimTopic, data));
5954
// Use abi.encodePacked to concatenate the message prefix and the message to sign.
@@ -74,6 +69,20 @@ contract ClaimIssuer is IClaimIssuer, Identity {
7469
return false;
7570
}
7671

72+
/**
73+
* @dev See {IClaimIssuer-isClaimRevoked}.
74+
*/
75+
function isClaimRevoked(bytes memory _sig) public override view returns (bool) {
76+
if (revokedClaims[_sig]) {
77+
return true;
78+
}
79+
80+
return false;
81+
}
82+
83+
/**
84+
* @dev See {IClaimIssuer-getRecoveredAddress}.
85+
*/
7786
function getRecoveredAddress(bytes memory sig, bytes32 dataHash)
7887
public override
7988
pure
@@ -89,6 +98,7 @@ contract ClaimIssuer is IClaimIssuer, Identity {
8998
}
9099

91100
// Divide the signature in r, s and v variables
101+
// solhint-disable-next-line no-inline-assembly
92102
assembly {
93103
ra := mload(add(sig, 32))
94104
sa := mload(add(sig, 64))

0 commit comments

Comments
 (0)