Skip to content

Commit d04b674

Browse files
committed
add verification logic
1 parent 91536f9 commit d04b674

File tree

7 files changed

+468
-111
lines changed

7 files changed

+468
-111
lines changed

.eslintrc.json

+3-5
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515
"ecmaVersion": "latest",
1616
"sourceType": "module"
1717
},
18-
"plugins": [
19-
"@typescript-eslint",
20-
"prettier"
21-
],
18+
"plugins": ["@typescript-eslint", "prettier"],
2219
"rules": {
2320
"prettier/prettier": ["error", { "singleQuote": true, "printWidth": 125 }],
2421
"no-mixed-spaces-and-tabs": ["warn", "smart-tabs"],
@@ -40,6 +37,7 @@
4037
"semi": ["error", "always"],
4138
"@typescript-eslint/no-explicit-any": "off",
4239
"@typescript-eslint/ban-ts-comment": "off",
43-
"@typescript-eslint/explicit-module-boundary-types": "off"
40+
"@typescript-eslint/explicit-module-boundary-types": "off",
41+
"@typescript-eslint/no-non-null-assertion": "off"
4442
}
4543
}

.prettierrc

+6
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
"bracketSpacing": false,
1313
"explicitTypes": "preserve"
1414
}
15+
},
16+
{
17+
"files": "*.ts",
18+
"options": {
19+
"printWidth": 125
20+
}
1521
}
1622
]
1723
}

packages/registry/contracts/CannonRegistry.sol

+34
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,27 @@ contract CannonRegistry is Storage, Ownable, UUPSImplementation {
1212
error TooManyTags();
1313

1414
event PackagePublish(bytes32 indexed name, bytes32 indexed version, bytes32[] indexed tags, string url, address owner);
15+
event PackageVerify(bytes32 indexed name, address indexed verifier);
16+
event PackageUnverify(bytes32 indexed name, address indexed verifier);
1517

1618
uint public constant MIN_PACKAGE_NAME_LENGTH = 3;
1719

1820
function upgradeTo(address _newImplementation) public override onlyOwner {
1921
_upgradeTo(_newImplementation);
2022
}
2123

24+
function addPackageVerifier(address _verifier) external onlyOwner {
25+
_store().verifiers[_verifier] = true;
26+
}
27+
28+
function removePackageVerifier(address _verifier) external onlyOwner {
29+
_store().verifiers[_verifier] = false;
30+
}
31+
32+
function isPackageVerifier(address _verifier) external view returns (bool) {
33+
return _store().verifiers[_verifier];
34+
}
35+
2236
function validatePackageName(bytes32 _name) public pure returns (bool) {
2337
// each character must be in the supported charset
2438

@@ -121,6 +135,26 @@ contract CannonRegistry is Storage, Ownable, UUPSImplementation {
121135
_p.nominatedOwner = address(0);
122136
}
123137

138+
function verifyPackage(bytes32 _packageName) external {
139+
address _verifier = msg.sender;
140+
141+
if (!_store().verifiers[_verifier]) {
142+
revert Unauthorized();
143+
}
144+
145+
emit PackageVerify(_packageName, _verifier);
146+
}
147+
148+
function unverifyPackage(bytes32 _packageName) external {
149+
address _verifier = msg.sender;
150+
151+
if (!_store().verifiers[_verifier]) {
152+
revert Unauthorized();
153+
}
154+
155+
emit PackageUnverify(_packageName, _verifier);
156+
}
157+
124158
function getPackageNominatedOwner(bytes32 _packageName) external view returns (address) {
125159
return _store().packages[_packageName].nominatedOwner;
126160
}

packages/registry/contracts/Storage.sol

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ pragma solidity ^0.8.11;
44
contract Storage {
55
struct Store {
66
mapping(bytes32 => Package) packages;
7+
mapping(address => bool) verifiers;
78
}
89

910
struct Package {

0 commit comments

Comments
 (0)