Skip to content

Commit 6223667

Browse files
authored
Renaming (#37)
* Announce -> Publish * uri -> url * Updated packages * Solc 0.8.4 -> 0.8.6 * Added indexes to Delegation events for searching consistency
1 parent cfa9445 commit 6223667

17 files changed

+1175
-1006
lines changed

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ $ npm install @dsnp/contracts
1313
### JavaScript ABI Usage
1414

1515
```javascript
16-
const announcer = require("@dsnp/contracts/abi/Announcer.json");
17-
const annoucerABI = announcer.abi;
16+
const publisher = require("@dsnp/contracts/abi/Publisher.json");
17+
const publisherABI = publisher.abi;
1818

1919
```
2020
### TypeScript ABI Usage
2121

2222
```typescript
2323
// Requires "resolveJsonModule": true in [tsconfig](https://www.typescriptlang.org/tsconfig#resolveJsonModule)
24-
import { abi as announcerABI } from "@dsnp/contracts/abi/Announcer.json";
24+
import { abi as publisherABI } from "@dsnp/contracts/abi/Publisher.json";
2525
```
2626

2727
#### TypeScript Contract Types
@@ -37,23 +37,23 @@ To maintain types, it is suggested to use [TypeChain](https://github.com/ethereu
3737
```typescript
3838
// web3 example
3939
import web3 from "web3";
40-
import { Announcer } from "./types/typechain/Announcer";
41-
import { abi as announcerABI } from "@dsnp/contracts/abi/Announcer.json";
40+
import { Publisher } from "./types/typechain/Publisher";
41+
import { abi as publisherABI } from "@dsnp/contracts/abi/Publisher.json";
4242

43-
const getAnnouncerContract = (contractAddress: string) => {
43+
const getPublisherContract = (contractAddress: string) => {
4444
// web3 requires the type casts
45-
return (new web3.eth.Contract(announcerABI, contractAddress) as any) as Announcer;
45+
return (new web3.eth.Contract(publisherABI, contractAddress) as any) as Publisher;
4646
}
4747
```
4848

4949
```typescript
5050
// ethersjsv5 example
5151
import { Provider } from "@ethersproject/providers";
52-
import { Announcer } from "./types/typechain/Announcer";
52+
import { Publisher } from "./types/typechain/Publisher";
5353

54-
const getAnnouncerContract = (contractAddress: string, provider: Provider) => {
54+
const getPublisherContract = (contractAddress: string, provider: Provider) => {
5555
// TypeChain for Ethers provides factories
56-
return Announcer__factory.connect(contractAddress, provider);
56+
return Publisher__factory.connect(contractAddress, provider);
5757
}
5858
```
5959

@@ -64,9 +64,9 @@ Once installed, you can use the contracts in the library by importing them:
6464
```solidity
6565
pragma solidity ^0.8.0;
6666
67-
import "@dsnp/contracts/IAnnounce.sol";
67+
import "@dsnp/contracts/IPublish.sol";
6868
69-
contract MyAnnouncer is IAnnounce {
69+
contract MyPublisher is IPublish {
7070
// ...
7171
}
7272
```

contracts/Announcer.sol

Lines changed: 0 additions & 16 deletions
This file was deleted.

contracts/Beacon.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ pragma solidity >=0.8.0 <0.9.0;
44
import "@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol";
55

66
contract Beacon is UpgradeableBeacon {
7+
// solhint-disable-next-line no-empty-blocks
78
constructor(address _logic) UpgradeableBeacon(_logic) {}
89
}

contracts/IAnnounce.sol

Lines changed: 0 additions & 17 deletions
This file was deleted.

contracts/IDelegation.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ interface IDelegation {
2828
*/
2929
NONE,
3030
/**
31-
* @dev 0x1 Announce any DSNP message
31+
* @dev 0x1 Sign a DSNP Announcement
3232
*/
3333
ANNOUNCE,
3434
/**
@@ -72,14 +72,14 @@ interface IDelegation {
7272
* @param delegate Address delegated
7373
* @param role Permission Role
7474
*/
75-
event DSNPAddDelegate(address delegate, Role role);
75+
event DSNPAddDelegate(address indexed delegate, Role role);
7676

7777
/**
7878
* @dev Log for removal of a delegate
7979
* @param delegate Address revoked
8080
* @param endBlock Block number considered to be the end of the delegate permissions
8181
*/
82-
event DSNPRemoveDelegate(address delegate, uint64 endBlock);
82+
event DSNPRemoveDelegate(address indexed delegate, uint64 endBlock);
8383

8484
/**
8585
* @dev Add or change permissions for delegate
@@ -116,7 +116,7 @@ interface IDelegation {
116116
* @param endBlock Block number to consider the permissions terminated (MUST be > 0x0).
117117
*
118118
* MUST be called by the delegate, owner, or other delegate with permissions
119-
* MUST store endBlock for response in isAuthorizedToAnnounce (exclusive)
119+
* MUST store endBlock for response in isAuthorizedTo (exclusive)
120120
* MUST emit DSNPRemoveDelegate
121121
*/
122122
function delegateRemove(address addr, uint64 endBlock) external;
@@ -129,7 +129,7 @@ interface IDelegation {
129129
* @param change Change data containing new delegate address, endBlock, and nonce
130130
*
131131
* MUST be signed by the delegate, owner, or other delegate with permissions
132-
* MUST store endBlock for response in isAuthorizedToAnnounce (exclusive)
132+
* MUST store endBlock for response in isAuthorizedTo (exclusive)
133133
* MUST emit DSNPRemoveDelegate
134134
*/
135135
function delegateRemoveByEIP712Sig(

contracts/IPublish.sol

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity >=0.8.0 <0.9.0;
3+
4+
interface IPublish {
5+
struct Batch {
6+
int16 dsnpType;
7+
string url;
8+
bytes32 hash;
9+
}
10+
11+
/**
12+
* @dev Log for each batch published
13+
* @param dsnpType The type of Announcement in the batch file
14+
* @param dsnpHash The keccak hash of the batch file
15+
* @param dsnpUrl A url that resolves to the batch file of Announcements
16+
*/
17+
event DSNPBatchPublication(int16 indexed dsnpType, bytes32 dsnpHash, string dsnpUrl);
18+
19+
/**
20+
* @param publications Array of Batch struct to publish
21+
*/
22+
function publish(Batch[] calldata publications) external;
23+
}

contracts/Identity.sol

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ contract Identity is IDelegation, ERC165 {
221221
* @param endBlock Block number to consider the permissions terminated (MUST be > 0x0).
222222
*
223223
* MUST be called by the delegate, owner, or other delegate with permissions
224-
* MUST store endBlock for response in isAuthorizedToAnnounce (exclusive)
224+
* MUST store endBlock for response in isAuthorizedTo (exclusive)
225225
* MUST emit DSNPRemoveDelegate
226226
*/
227227
function delegateRemove(address addr, uint64 endBlock) external override {
@@ -247,7 +247,7 @@ contract Identity is IDelegation, ERC165 {
247247
* @param change Change data containing new delegate address, endBlock, and nonce
248248
*
249249
* MUST be signed by the delegate, owner, or other delegate with permissions
250-
* MUST store endBlock for response in isAuthorizedToAnnounce (exclusive)
250+
* MUST store endBlock for response in isAuthorizedTo (exclusive)
251251
* MUST emit DSNPRemoveDelegate
252252
*/
253253
function delegateRemoveByEIP712Sig(
@@ -340,10 +340,9 @@ contract Identity is IDelegation, ERC165 {
340340
bytes32 s,
341341
DelegateAdd calldata change
342342
) internal view returns (address) {
343-
bytes32 typeHash =
344-
keccak256(
345-
abi.encode(DELEGATE_ADD_TYPEHASH, change.nonce, change.delegateAddr, change.role)
346-
);
343+
bytes32 typeHash = keccak256(
344+
abi.encode(DELEGATE_ADD_TYPEHASH, change.nonce, change.delegateAddr, change.role)
345+
);
347346
return signerFromHashStruct(v, r, s, typeHash);
348347
}
349348

@@ -361,15 +360,9 @@ contract Identity is IDelegation, ERC165 {
361360
bytes32 s,
362361
DelegateRemove calldata change
363362
) internal view returns (address) {
364-
bytes32 typeHash =
365-
keccak256(
366-
abi.encode(
367-
DELEGATE_REMOVE_TYPEHASH,
368-
change.nonce,
369-
change.delegateAddr,
370-
change.endBlock
371-
)
372-
);
363+
bytes32 typeHash = keccak256(
364+
abi.encode(DELEGATE_REMOVE_TYPEHASH, change.nonce, change.delegateAddr, change.endBlock)
365+
);
373366
return signerFromHashStruct(v, r, s, typeHash);
374367
}
375368

@@ -387,10 +380,9 @@ contract Identity is IDelegation, ERC165 {
387380
bytes32 s,
388381
bytes32 hashStruct
389382
) internal view returns (address) {
390-
bytes32 digest =
391-
keccak256(
392-
abi.encodePacked("\x19\x01", _delegationData().domainSeparatorHash, hashStruct)
393-
);
383+
bytes32 digest = keccak256(
384+
abi.encodePacked("\x19\x01", _delegationData().domainSeparatorHash, hashStruct)
385+
);
394386
return ecrecover(digest, v, r, s);
395387
}
396388
}

contracts/IdentityBeaconProxy.sol

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ contract IdentityBeaconProxy is Proxy {
3333
bs.initialized = true;
3434

3535
// Call Base Logic
36-
(bool success, ) =
37-
IBeacon(beacon).implementation().delegatecall(
38-
abi.encodeWithSignature("initialize(address)", owner)
39-
);
36+
// solhint-disable avoid-low-level-calls
37+
(bool success, ) = IBeacon(beacon).implementation().delegatecall(
38+
abi.encodeWithSignature("initialize(address)", owner)
39+
);
4040
require(success, "initialize failed");
4141
}
4242

@@ -47,7 +47,7 @@ contract IdentityBeaconProxy is Proxy {
4747
*/
4848
function _beaconData() internal pure returns (BeaconStorage storage beaconStorage) {
4949
bytes32 position = BEACON_SLOT;
50-
/* solhint-disable no-inline-assembly */
50+
// solhint-disable no-inline-assembly
5151
assembly {
5252
beaconStorage.slot := position
5353
}

contracts/Publisher.sol

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity >=0.8.0 <0.9.0;
3+
4+
import "./IPublish.sol";
5+
6+
contract Publisher is IPublish {
7+
/**
8+
* @param publications Array of Batch structs to publish
9+
*/
10+
function publish(Batch[] calldata publications) external override {
11+
require(publications.length < 100, "gas consumption is high");
12+
for (uint256 i = 0; i < publications.length; i++) {
13+
emit DSNPBatchPublication(
14+
publications[i].dsnpType,
15+
publications[i].hash,
16+
publications[i].url
17+
);
18+
}
19+
}
20+
}

contracts/Registry.sol

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -304,15 +304,14 @@ contract Registry is IRegistry {
304304
bytes32 s,
305305
AddressChange calldata change
306306
) internal view returns (address) {
307-
bytes32 typeHash =
308-
keccak256(
309-
abi.encode(
310-
ADDRESS_CHANGE_TYPEHASH,
311-
change.nonce,
312-
change.addr,
313-
keccak256(bytes(change.handle))
314-
)
315-
);
307+
bytes32 typeHash = keccak256(
308+
abi.encode(
309+
ADDRESS_CHANGE_TYPEHASH,
310+
change.nonce,
311+
change.addr,
312+
keccak256(bytes(change.handle))
313+
)
314+
);
316315
return signerFromHashStruct(v, r, s, typeHash);
317316
}
318317

@@ -330,15 +329,14 @@ contract Registry is IRegistry {
330329
bytes32 s,
331330
HandleChange calldata change
332331
) internal view returns (address) {
333-
bytes32 typeHash =
334-
keccak256(
335-
abi.encode(
336-
HANDLE_CHANGE_TYPEHASH,
337-
change.nonce,
338-
keccak256(bytes(change.oldHandle)),
339-
keccak256(bytes(change.newHandle))
340-
)
341-
);
332+
bytes32 typeHash = keccak256(
333+
abi.encode(
334+
HANDLE_CHANGE_TYPEHASH,
335+
change.nonce,
336+
keccak256(bytes(change.oldHandle)),
337+
keccak256(bytes(change.newHandle))
338+
)
339+
);
342340
return signerFromHashStruct(v, r, s, typeHash);
343341
}
344342

contracts/mocks/TestDelegate.sol

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,41 +21,41 @@ contract TestDelegate is ERC165, IDelegation {
2121
delegateAddr = owner;
2222
}
2323

24-
function delegate(address newDelegate, Role role) external override {
24+
function delegate(address, Role) external pure override {
2525
require(false, "Not implemented");
2626
}
2727

2828
function delegateByEIP712Sig(
29-
uint8 v,
30-
bytes32 r,
31-
bytes32 s,
32-
DelegateAdd calldata change
33-
) external override {
29+
uint8,
30+
bytes32,
31+
bytes32,
32+
DelegateAdd calldata
33+
) external pure override {
3434
require(false, "Not implemented");
3535
}
3636

37-
function delegateRemove(address addr, uint64 endBlock) external override {
37+
function delegateRemove(address, uint64) external pure override {
3838
require(false, "Not implemented");
3939
}
4040

4141
function delegateRemoveByEIP712Sig(
42-
uint8 v,
43-
bytes32 r,
44-
bytes32 s,
45-
DelegateRemove calldata change
46-
) external override {
42+
uint8,
43+
bytes32,
44+
bytes32,
45+
DelegateRemove calldata
46+
) external pure override {
4747
require(false, "Not implemented");
4848
}
4949

5050
function isAuthorizedTo(
5151
address addr,
52-
Permission permission,
53-
uint256 blockNumber
52+
Permission,
53+
uint256
5454
) external view override returns (bool) {
5555
return addr == delegateAddr;
5656
}
5757

58-
function getNonceForDelegate(address addr) external view override returns (uint32) {
58+
function getNonceForDelegate(address) external pure override returns (uint32) {
5959
require(false, "Not implemented");
6060
return 0;
6161
}

hardhat.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const getAccounts = (network: string) => {
2525
const config: HardhatUserConfig = {
2626
defaultNetwork: "hardhat",
2727
solidity: {
28-
compilers: [{ version: "0.8.4", settings: {} }],
28+
compilers: [{ version: "0.8.6", settings: {} }],
2929
},
3030
networks: {
3131
hardhat: {},

0 commit comments

Comments
 (0)