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

refactor: clean up legacy stuff #148

Merged
merged 5 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 0 additions & 6 deletions jest/setup.ts

This file was deleted.

6 changes: 0 additions & 6 deletions jest/teardown.ts

This file was deleted.

12 changes: 0 additions & 12 deletions jest/utils.ts

This file was deleted.

22 changes: 0 additions & 22 deletions scripts/generateHashes.js

This file was deleted.

50 changes: 0 additions & 50 deletions scripts/postTypechain.js

This file was deleted.

42 changes: 1 addition & 41 deletions src/BaseDocumentStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

pragma solidity ^0.8.0;

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {IDocumentStore} from "./interfaces/IDocumentStore.sol";

/**
* @title BaseDocumentStore
* @notice A base contract for storing and revoking documents
*/
contract BaseDocumentStore is Initializable, IDocumentStore {
abstract contract BaseDocumentStore is Initializable, IDocumentStore {
/**
* @notice The name of the contract
*/
Expand Down Expand Up @@ -40,16 +39,6 @@ contract BaseDocumentStore is Initializable, IDocumentStore {
*/
function _issue(bytes32 document) internal {
documentIssued[document] = block.number;
// emit DocumentIssued(document);
}

/**
* @notice Gets the block number at which a document was issued
* @param document The hash of the issued document
* @return The block number at which the document was issued
*/
function getIssuedBlock(bytes32 document) public view onlyIssued(document) returns (uint256) {
return documentIssued[document];
}

/**
Expand All @@ -61,16 +50,6 @@ contract BaseDocumentStore is Initializable, IDocumentStore {
return (documentIssued[document] != 0);
}

/**
* @notice Checks if a document was issued before a specific block number (inclusive)
* @param document The hash of the document to check
* @param blockNumber The block number to check against
* @return A boolean indicating whether the document was issued before the specified block number
*/
function isIssuedBefore(bytes32 document, uint256 blockNumber) public view returns (bool) {
return documentIssued[document] != 0 && documentIssued[document] <= blockNumber;
}

/**
* @notice Revokes a document
* @param document The hash of the document to revoke
Expand All @@ -87,23 +66,4 @@ contract BaseDocumentStore is Initializable, IDocumentStore {
function _isRevoked(bytes32 document) internal view returns (bool) {
return documentRevoked[document] != 0;
}

/**
* @notice Checks if a document was revoked before a specific block number (inclusive)
* @param document The hash of the document to check
* @param blockNumber The block number to check against
* @return A boolean indicating whether the document was revoked before the specified block number
*/
function isRevokedBefore(bytes32 document, uint256 blockNumber) public view returns (bool) {
return documentRevoked[document] <= blockNumber && documentRevoked[document] != 0;
}

/**
* @dev Checks if a document has been issued
* @param document The hash of the document to check
*/
modifier onlyIssued(bytes32 document) {
require(_isIssued(document), "Error: Only issued document hashes can be revoked");
_;
}
}
21 changes: 7 additions & 14 deletions src/DocumentStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@

pragma solidity ^0.8.0;

import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";

import "./BaseDocumentStore.sol";
import "./base/DocumentStoreAccessControl.sol";

Expand Down Expand Up @@ -40,7 +37,7 @@ contract DocumentStore is DocumentStoreAccessControl, BaseDocumentStore {
* @param documentRoot The hash of the document to issue
*/
function issue(bytes32 documentRoot) public onlyRole(ISSUER_ROLE) {
if (isRootIssued(documentRoot)) {
if (isIssued(documentRoot)) {
revert DocumentExists(documentRoot);
}

Expand All @@ -63,7 +60,7 @@ contract DocumentStore is DocumentStoreAccessControl, BaseDocumentStore {
* @notice Revokes a document
* @param documentRoot The hash of the document to revoke
*/
function revokeRoot(bytes32 documentRoot) public onlyRole(REVOKER_ROLE) {
function revoke(bytes32 documentRoot) public onlyRole(REVOKER_ROLE) {
revoke(documentRoot, documentRoot, new bytes32[](0));
}

Expand Down Expand Up @@ -101,7 +98,7 @@ contract DocumentStore is DocumentStoreAccessControl, BaseDocumentStore {
return _isIssued(documentRoot);
}

function isRootIssued(bytes32 documentRoot) public view returns (bool) {
function isIssued(bytes32 documentRoot) public view returns (bool) {
return isIssued(documentRoot, documentRoot, new bytes32[](0));
}

Expand All @@ -113,14 +110,10 @@ contract DocumentStore is DocumentStoreAccessControl, BaseDocumentStore {
if (!isIssued(documentRoot, document, proof)) {
revert InvalidDocument(documentRoot, document);
}
return _isRevokedInternal(documentRoot, document, proof);
return _isRevoked(documentRoot, document, proof);
}

function _isRevokedInternal(
bytes32 documentRoot,
bytes32 document,
bytes32[] memory proof
) internal view returns (bool) {
function _isRevoked(bytes32 documentRoot, bytes32 document, bytes32[] memory proof) internal view returns (bool) {
if (documentRoot == document && proof.length == 0) {
return _isRevoked(document);
}
Expand All @@ -132,15 +125,15 @@ contract DocumentStore is DocumentStoreAccessControl, BaseDocumentStore {
* @param documentRoot The hash of the document to check
* @return A boolean indicating whether the document has been revoked
*/
function isRootRevoked(bytes32 documentRoot) public view returns (bool) {
function isRevoked(bytes32 documentRoot) public view returns (bool) {
return isRevoked(documentRoot, documentRoot, new bytes32[](0));
}

function isActive(bytes32 documentRoot, bytes32 document, bytes32[] memory proof) public view returns (bool) {
if (!isIssued(documentRoot, document, proof)) {
revert InvalidDocument(documentRoot, document);
}
return !_isRevokedInternal(documentRoot, document, proof);
return !_isRevoked(documentRoot, document, proof);
}

modifier onlyValidDocument(
Expand Down
32 changes: 0 additions & 32 deletions src/DocumentStoreCreator.sol

This file was deleted.

62 changes: 0 additions & 62 deletions src/DocumentStoreWithRevokeReasons.sol

This file was deleted.

6 changes: 5 additions & 1 deletion src/base/DocumentStoreAccessControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol"
* @notice Base contract for managing access control roles for a DocumentStore
*/
contract DocumentStoreAccessControl is AccessControlUpgradeable {
error ZeroOwner();

bytes32 public constant ISSUER_ROLE = keccak256("ISSUER_ROLE");
bytes32 public constant REVOKER_ROLE = keccak256("REVOKER_ROLE");

Expand All @@ -17,7 +19,9 @@ contract DocumentStoreAccessControl is AccessControlUpgradeable {
* @param owner The owner of the contract
*/
function __DocumentStoreAccessControl_init(address owner) internal onlyInitializing {
require(owner != address(0), "Owner is zero");
if (owner == address(0)) {
revert ZeroOwner();
}
_grantRole(DEFAULT_ADMIN_ROLE, owner);
_grantRole(ISSUER_ROLE, owner);
_grantRole(REVOKER_ROLE, owner);
Expand Down
Loading
Loading