generated from zeroknots/femplate
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathIRegistry.sol
379 lines (328 loc) · 17.2 KB
/
IRegistry.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
// SPDX-License-Identifier: AGPL-3.0-only
pragma solidity ^0.8.24;
import {
AttestationDataRef,
AttestationRecord,
AttestationRequest,
ModuleType,
ModuleRecord,
ResolverUID,
ResolverRecord,
RevocationRequest,
SchemaUID,
SchemaRecord
} from "./DataTypes.sol";
import { IExternalSchemaValidator } from "./external/IExternalSchemaValidator.sol";
import { IExternalResolver } from "./external/IExternalResolver.sol";
interface IERC7484 {
event NewTrustedAttesters();
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* Check with Registry internal attesters */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
function check(address module) external view;
function checkForAccount(address smartAccount, address module) external view;
function check(address module, ModuleType moduleType) external view;
function checkForAccount(address smartAccount, address module, ModuleType moduleType) external view;
/**
* Allows Smart Accounts - the end users of the registry - to appoint
* one or many attesters as trusted.
* @dev this function reverts, if address(0), or duplicates are provided in attesters[]
*
* @param threshold The minimum number of attestations required for a module
* to be considered secure.
* @param attesters The addresses of the attesters to be trusted.
*/
function trustAttesters(uint8 threshold, address[] calldata attesters) external;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* Check with external attester(s) */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
function check(address module, address[] calldata attesters, uint256 threshold) external view;
function check(address module, ModuleType moduleType, address[] calldata attesters, uint256 threshold) external view;
}
/**
* Interface definition of all features of the registry:
* - Register Schemas
* - Register External Resolvers
* - Register Modules
* - Make Attestations
* - Make Revocations
* - Delegate Trust to Attester(s)
*
* @author rhinestone | zeroknots.eth, Konrad Kopp (@kopy-kat)
*/
interface IRegistry is IERC7484 {
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* Smart Account - Trust Management */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
error InvalidResolver(IExternalResolver resolver);
error InvalidResolverUID(ResolverUID uid);
error InvalidTrustedAttesterInput();
error NoTrustedAttestersFound();
error RevokedAttestation(address attester);
error InvalidModuleType();
error AttestationNotFound();
error InsufficientAttestations();
/**
* Get trusted attester for a specific Smart Account
* @param smartAccount The address of the Smart Account
*/
function findTrustedAttesters(address smartAccount) external view returns (address[] memory attesters);
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* Attestations */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
event Revoked(address indexed moduleAddr, address indexed revoker, SchemaUID schema);
event Attested(address indexed moduleAddr, address indexed attester, SchemaUID schemaUID, AttestationDataRef indexed sstore2Pointer);
error AlreadyRevoked();
error ModuleNotFoundInRegistry(address module);
error AccessDenied();
error InvalidAttestation();
error InvalidExpirationTime();
error DifferentResolvers();
error InvalidSignature();
error InvalidModuleTypes();
/**
* Allows `msg.sender` to attest to multiple modules' security status.
* The `AttestationRequest.Data` provided should match the attestation
* schema defined by the Schema corresponding to the SchemaUID
*
* @dev This function will revert if the same module is attested twice by the same attester.
* If you want to re-attest, you have to revoke your attestation first, and then attest again.
*
* @param schemaUID The SchemaUID of the schema the attestation is based on.
* @param request a single AttestationRequest
*/
function attest(SchemaUID schemaUID, AttestationRequest calldata request) external;
/**
* Allows `msg.sender` to attest to multiple modules' security status.
* The `AttestationRequest.Data` provided should match the attestation
* schema defined by the Schema corresponding to the SchemaUID
*
* @dev This function will revert if the same module is attested twice by the same attester.
* If you want to re-attest, you have to revoke your attestation first, and then attest again.
*
* @param schemaUID The SchemaUID of the schema the attestation is based on.
* @param requests An array of AttestationRequest
*/
function attest(SchemaUID schemaUID, AttestationRequest[] calldata requests) external;
/**
* Allows attester to attest by signing an `AttestationRequest` (`ECDSA` or `ERC1271`)
* The `AttestationRequest.Data` provided should match the attestation
* schema defined by the Schema corresponding to the SchemaUID
*
* @dev This function will revert if the same module is attested twice by the same attester.
* If you want to re-attest, you have to revoke your attestation first, and then attest again.
*
* @param schemaUID The SchemaUID of the schema the attestation is based on.
* @param attester The address of the attester
* @param request An AttestationRequest
* @param signature The signature of the attester. ECDSA or ERC1271
*/
function attest(SchemaUID schemaUID, address attester, AttestationRequest calldata request, bytes calldata signature) external;
/**
* Allows attester to attest by signing an `AttestationRequest` (`ECDSA` or `ERC1271`)
* The `AttestationRequest.Data` provided should match the attestation
* schema defined by the Schema corresponding to the SchemaUID
*
* @dev This function will revert if the same module is attested twice by the same attester.
* If you want to re-attest, you have to revoke your attestation first, and then attest again.
*
* @param schemaUID The SchemaUID of the schema the attestation is based on.
* @param attester The address of the attester
* @param requests An array of AttestationRequest
* @param signature The signature of the attester. ECDSA or ERC1271
*/
function attest(SchemaUID schemaUID, address attester, AttestationRequest[] calldata requests, bytes calldata signature) external;
/**
* Getter function to get AttestationRequest made by one attester
*/
function findAttestation(address module, address attester) external view returns (AttestationRecord memory attestation);
/**
* Getter function to get AttestationRequest made by multiple attesters
*/
function findAttestations(
address module,
address[] calldata attesters
)
external
view
returns (AttestationRecord[] memory attestations);
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* Revocations */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
/**
* Allows `msg.sender` to revoke an attestation made by the same `msg.sender`
*
* @dev this function will revert if the attestation is not found
* @dev this function will revert if the attestation is already revoked
*
* @param request single RevocationRequest
*/
function revoke(RevocationRequest calldata request) external;
/**
* Allows msg.sender to revoke multiple attestation made by the same msg.sender
*
* @dev this function will revert if the attestation is not found
* @dev this function will revert if the attestation is already revoked
*
* @param requests the RevocationRequests
*/
function revoke(RevocationRequest[] calldata requests) external;
/**
* Allows attester to revoke an attestation by signing an `RevocationRequest` (`ECDSA` or `ERC1271`)
*
* @param attester the signer / revoker
* @param request single RevocationRequest
* @param signature ECDSA or ERC1271 signature
*/
function revoke(address attester, RevocationRequest calldata request, bytes calldata signature) external;
/**
* Allows attester to revoke an attestation by signing an `RevocationRequest` (`ECDSA` or `ERC1271`)
* @dev if you want to revoke multiple attestations, but from different attesters, call this function multiple times
*
* @param attester the signer / revoker
* @param requests array of RevocationRequests
* @param signature ECDSA or ERC1271 signature
*/
function revoke(address attester, RevocationRequest[] calldata requests, bytes calldata signature) external;
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* Module Registration */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
// Event triggered when a module is deployed.
event ModuleRegistration(address indexed implementation);
error AlreadyRegistered(address module);
error InvalidDeployment();
error ModuleAddressIsNotContract(address moduleAddress);
error FactoryCallFailed(address factory);
/**
* Module Developers can deploy their module Bytecode directly via the registry.
* This registry implements a `CREATE2` factory, that allows module developers to register and deploy module bytecode
* @param salt The salt to be used in the `CREATE2` factory. This adheres to Pr000xy/Create2Factory.sol salt formatting.
* The salt's first bytes20 should be the address of the sender
* or bytes20(0) to bypass the check (this will lose replay protection)
* @param resolverUID The resolverUID to be used in the `CREATE2` factory
* @param initCode The initCode to be used in the `CREATE2` factory
* @param metadata The metadata to be stored on the registry.
* This field is optional, and might be used by the module developer to store additional
* information about the module or facilitate business logic with the Resolver stub
*/
function deployModule(
bytes32 salt,
ResolverUID resolverUID,
bytes calldata initCode,
bytes calldata metadata
)
external
payable
returns (address moduleAddr);
/**
* In order to make the integration into existing business logics possible,
* the Registry is able to utilize external factories that can be utilized to deploy the modules.
* @dev Registry can use other factories to deploy the module.
* @dev Note that this function will call the external factory via the FactoryTrampoline contract.
* Factory MUST not assume that msg.sender == registry
* @dev This function is used to deploy and register a module using a factory contract.
* Since one of the parameters of this function is a unique resolverUID and any
* registered module address can only be registered once,
* using this function is of risk for a frontrun attack
*/
function deployViaFactory(
address factory,
bytes calldata callOnFactory,
bytes calldata metadata,
ResolverUID resolverUID
)
external
payable
returns (address moduleAddress);
/**
* Already deployed module addresses can be registered on the registry
* @dev This function is used to deploy and register an already deployed module.
* Since one of the parameters of this function is a unique resolverUID and any
* registered module address can only be registered once,
* using this function is of risk for a frontrun attack
* @dev the sender address of this registration is set to address(0) since anyone can invoke this function
* @param resolverUID The resolverUID to be used for the module
* @param moduleAddress The address of the module to be registered
* @param metadata The metadata to be stored on the registry.
* This field is optional, and might be used by the module developer to store additional
* information about the module or facilitate business logic with the Resolver stub
*/
function registerModule(ResolverUID resolverUID, address moduleAddress, bytes calldata metadata) external;
/**
* in conjunction with the deployModule() function, this function let's you
* predict the address of a CREATE2 module deployment
* @param salt CREATE2 salt
* @param initCode module initcode
* @return moduleAddress counterfactual address of the module deployment
*/
function calcModuleAddress(bytes32 salt, bytes calldata initCode) external view returns (address);
/**
* Getter function to get the stored ModuleRecord for a specific module address.
* @param moduleAddress The address of the module
*/
function findModule(address moduleAddress) external view returns (ModuleRecord memory moduleRecord);
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* Manage Schemas */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
event SchemaRegistered(SchemaUID indexed uid, address indexed registerer);
error SchemaAlreadyExists(SchemaUID uid);
error InvalidSchema();
error InvalidSchemaValidator(IExternalSchemaValidator validator);
/**
* Register Schema and (optional) external `IExternalSchemaValidator`
* A Schema describe the structure of the data of attestations
* every attestation made on this registry, will reference a SchemaUID to
* make it possible to decode attestation data in human readable form
* overwriting a schema is not allowed, and will revert
* @param schema ABI schema used to encode attestations that are made with this schema
* @param validator (optional) external schema validator that will be used to validate attestations.
* use address(0), if you don't need an external validator
* @return uid SchemaUID of the registered schema
*/
function registerSchema(
string calldata schema,
IExternalSchemaValidator validator // OPTIONAL
)
external
returns (SchemaUID uid);
/**
* Getter function to retrieve SchemaRecord
*/
function findSchema(SchemaUID uid) external view returns (SchemaRecord memory record);
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* Manage Resolvers */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
event NewResolver(ResolverUID indexed uid, address indexed resolver);
event NewResolverOwner(ResolverUID indexed uid, address newOwner);
error ResolverAlreadyExists();
/**
* Allows Marketplace Agents to register external resolvers.
* @param resolver external resolver contract
* @return uid ResolverUID of the registered resolver
*/
function registerResolver(IExternalResolver resolver) external returns (ResolverUID uid);
/**
* Entities that previously registered an external resolver, may update the implementation address.
* @param uid The UID of the resolver.
* @param resolver The new resolver implementation address.
*/
function setResolver(ResolverUID uid, IExternalResolver resolver) external;
/**
* Transfer ownership of resolverUID to a new address
* @param uid The UID of the resolver to transfer ownership for
* @param newOwner The address of the new owner
*/
function transferResolverOwnership(ResolverUID uid, address newOwner) external;
/**
* Getter function to get the ResolverRecord of a registered resolver
* @param uid The UID of the resolver.
*/
function findResolver(ResolverUID uid) external view returns (ResolverRecord memory record);
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* Stub Errors */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
error ExternalError_SchemaValidation();
error ExternalError_ResolveAttestation();
error ExternalError_ResolveRevocation();
error ExternalError_ModuleRegistration();
}