-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEMIS.sol
More file actions
489 lines (427 loc) · 14.8 KB
/
Copy pathEMIS.sol
File metadata and controls
489 lines (427 loc) · 14.8 KB
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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
pragma solidity >=0.8.4;
import "./IdentityIdentifier.sol";
contract EMIS{
struct User{
address owner;
address identity_identifier_addr;
address content_identifier;
address service_identifier;
address geographicalLocation_identifier;
address hyperbolicCoordinate_identifier;
address IPv4Address_identifier;
address domainName_identifier;
}
string private constant IDENTITY_IDENTIFIER = "type0";
string private constant CONTENT_IDENTIFIER = "type1";
string private constant SERVICE_IDENTIFIER = "type2";
string private constant GEOGRAPHICAL_LOCATION_IDENTIFIER = "type3";
string private constant HYPERBOLIC_COORDINATE_IDENTIFIER = "type4";
string private constant IPv4_IDENTIFIER = "type5";
string private constant DOMAIN_NAME_IDENTIFIER = "type6";
uint256 private constant DEFAULT_METAVERSE = 0;
IdentityIdentifier immutable identity;
uint public immutable identityPrice;
uint256 public immutable minCommitmentAge = 60 seconds;
uint256 public immutable maxCommitmentAge = 24 hours;
mapping(bytes32 => uint256) public commitments;
mapping(string => User) records;
mapping(address =>mapping(address => bool)) operators;
mapping(string => bool) sensitiveWords;
mapping(string => uint) attribute;
constructor(IdentityIdentifier _identityIdentifier,uint256 _identityPrice){
identity = _identityIdentifier;
identityPrice = _identityPrice;
}
/**
* @dev Add a sensitive word to the sensitiveWords.
* @param word The sensitive word.
*/
function addSensitive(string calldata word) public {
sensitiveWords[word] = true;
}
/**
* @dev Returns whether a word is a sensitive word.
* @param word The specified word.
* @return Bool if the word is a sensitive word.
*/
function sensitive(string memory word)
public
view
returns(bool)
{
return sensitiveWords[word];
}
/**
* @dev Make a commitment before registry.
* @param name The username which user want to registry.
* @param owner The address of the username's owner.
*/
//Some configurations depend on other modules such as the front end
function makeCommitment(
string memory name,
address owner
// bytes32 secret
) public
// pure
returns(bytes32){
bytes32 label = keccak256(bytes(name));
return keccak256(
abi.encode(
label,
owner
// secret
)
);
}
/**
* @dev Commit the commitment to the commitments table.
*/
function commit(bytes32 commitment) public {
if (commitments[commitment] + maxCommitmentAge >= block.timestamp) {
revert ("UnexpiredCommitmentExists");
}
commitments[commitment] = block.timestamp;
}
/**
* @dev Registry a username and set the username's owner.
* @param username The name that user want to registry.
* @param owner The address of the username's owner.
*/
function register(
string calldata username,
address owner
// bytes32 secret
) public payable {
_consumeCommitment(
username,
makeCommitment(
username,
owner
// secret
)
);
registerUsername(username,owner);
}
/**
* @dev Consume the commitment that produced by makeCommitment function.
* @param name The name that user want to registry.
* @param commitment The hash of the name which user wants to registry,
address of the owner ans so on.
*/
//it will work better if some configurations are combined with other modules
function _consumeCommitment(
string memory name,
// uint256 duration,
bytes32 commitment
)internal{
// if(commitments[commitment] + minCommitmentAge > block.timestamp){
// revert ("commitment too new");
// }
// if(commitments[commitment] + maxCommitmentAge <= block.timestamp){
// revert ("commitment too old");
// }
// set some rules
if(!available(name)){
revert ("name is not validate");
}
delete (commitments[commitment]);
}
/**
* @dev Returns whether a name is a sensitive word.
* @param name The username which user want to registry.
* @return Bool if a name is available for the sensitiveWords.
*/
function available(string memory name)
public
view
returns(bool)
{
return !sensitiveWords[name];
}
/**
* @dev Permits modifications only by the person/address
that authorised in isAuthorised function.
*/
modifier authorised(string calldata username) {
require(isAuthorised(username));
_;
}
/**
* @dev Returns whether the msg.sender is the username's owner or
the person that approved by the username's owner.
* @param username The specified username.
* @return Bool if the msg.sender is authorised.
*/
function isAuthorised(string calldata username)
internal
view
returns(bool)
{
address usernameOwner = usernameOwner(username);
return usernameOwner == msg.sender || isApprovedForAll(usernameOwner,msg.sender);
}
/**
* @dev Enable or disable approval for a third party ("operator") to manage
* all of `msg.sender`'s username records.
* @param operator Address to add to the set of authorized operators.
* @param approved True if the operator is approved, false to revoke approval.
*/
function setApprovalForAll(address operator, bool approved) public {
require(
msg.sender != operator,
"setting approval status for self"
);
operators[msg.sender][operator] = approved;
}
/**
* @dev Query if an address is an authorized operator for another address.
* @param owner The address that owns the username.
* @param operator The address that acts on behalf of the owner.
* @return True if `operator` is an approved operator for `owner`, false otherwise.
*/
function isApprovedForAll(address owner, address operator)
public
view
virtual
returns (bool)
{
return operators[owner][operator];
}
/**
* @dev Sets the username's owner in records.
* @param username The specified username.
* @param owner The address of the username that user wants to set.
*/
function registerUsername(string calldata username, address owner) internal{
records[username].owner = owner;
attribute[username] = DEFAULT_METAVERSE;
}
/**
* @dev Sets the Identity Identifier's contract address for the username.
* @param username The specified username.
* @param identityAddress The address of the identity identifier's contranct address.
*/
// function setIdentityIdentifierAddress(string calldata username,address identityAddress)public {
// records[username].identity_identifier_addr = identityAddress;
// }
/**
* @dev Transfers ownership of a username to a new address.
May only be called by the current owner of the node or
the operator that approved by current owner.
* @param username The username to transfer ownership of..
* @param _owner The address of the new owner.
*/
function transferOwner(string calldata username,address _owner) public authorised(username){
records[username].owner = _owner;
}
/**
* @dev Returns the address that owns the specified username.
* @param username The specified username.
*/
function usernameOwner(string calldata username)
public
view
returns(address)
{
return records[username].owner;
}
/**
* @dev Sets the permissions for username in the sub-metaverse.
* @param username The specified username.
* @param subMetaverse The flag number of the subMetaverse.
*/
function setSubMetaverse(string calldata username, uint256 subMetaverse)public {
attribute[username] = subMetaverse;
}
/**
* @dev Registry an identity identifier for a specified username
in the identity identifier space contract.
It only be called when the username is already registered.
* @param username The specified username.
*/
function registerIdentityIdentifier(
string calldata username
)
public
payable
authorised(username)
{
uint256 expiryTime = calculate(msg.value,identityPrice);
identity.registerIdentity(username,msg.sender,expiryTime);
}
/**
* @dev Update the information of AboutMe in the identity identifier
space contract of the specified username.
* @param username The specified username.
* @param aboutMe The information of the username, company, organization or person.
*/
function updateAboutMe(string calldata username, string calldata aboutMe) public authorised(username){
identity.setAboutMe(username,aboutMe);
}
/**
* @dev Pays the fee to extend the use of the registered identity
identifier of the specified username.
* @param username The specified username.
*/
function renewal(string calldata username)
public
payable
authorised(username)
{
uint256 payTime = calculate(msg.value,identityPrice);
identity.renewal(username,payTime);
}
/**
* @dev Revoke the identity identifier of the specified username and
stop billing to keep the effective usage time.
* @param username The specified username.
*/
function revoke(string calldata username) public authorised(username){
identity.revoke(username);
}
/**
* @dev Restart the identity identifier of the specified username that
is already revoked by revoke function and start billing again.
* @param username The specified username.
*/
function restart(string calldata username) public authorised(username){
identity.restart(username);
}
/**
* @dev Revoke the identity identifier of the specified username and
return the remaining money in the account.
* @param username The specified username.
*/
function revokeAndReturnBack(string calldata username)
public
payable
authorised(username)
{
uint256 remainTime = identity.remainT(username);
uint amount = identityPrice * remainTime;
payable(msg.sender).transfer(amount);
identity.deleteIdentity(username);
}
/**
* @dev Returns the value of the username's remaining money in identity
identifier space contract.
* @param username The specified username.
*/
function remainValue(string calldata username)
public
view
authorised(username)
returns(uint)
{
uint256 remainTime = identity.remainT(username);
uint amount = identityPrice * remainTime;
return amount;
}
/**
* @dev Query whether the username's identity identifier is in expiry date.
* @param username The specified username.
* @return True if username is activc, false otherwise.
*/
function isIdentityActive(string calldata username)
public
view
returns(bool)
{
return identity.isActive(username);
}
/**
* @dev Returns the identity identifier of the specified username.
* @param username The specified username.
* @return identityIdentifier The string of the username's identity identifier.
*/
function getIdentity(string calldata username)
public
view
returns(string memory)
{
return identity.identityIdentifier(username);
}
/**
* @dev Returns the resolved identity identifier.
* @param identifierType The identifier's type.
* @param identifierContent The identifier's content.
* @return result The resolved identity identifier.
*/
function resolve(string calldata identifierType,string calldata identifierContent)
public
view
returns(string memory result)
{
if(keccak256(abi.encodePacked(identifierType)) == keccak256(abi.encodePacked(IDENTITY_IDENTIFIER))){
result = identity.resolveIdentityByIdentifier(identifierContent);
}
// else if(keccak256(abi.encodePacked(identifierType)) == keccak256(abi.encodePacked(xxx))){}
else{
result = "This identifier is not supported";
}
return result;
}
/**
* @dev Returns the resolved identity identifier by Username.
* @param username The specified username.
* @return identityIdentifier The string of the username's identity identifier.
*/
function resolveIdentityByUsername(string calldata username)
public
view
authorised(username)
returns(string memory)
{
return identity.resolveIdentityByUsername(username);
}
/**
* @dev Returns the aboutMe information of the specified username.
* @param username The specified username.
* @return aboutMe The information of the username, company, organization or person.
*/
function getAboutMe(string calldata username)
public
view
returns(string memory)
{
return identity.aboutMe(username);
}
/**
* @dev Returns the TTL of the specified username.
* @param username The specified username.
* @return ttl The ttl of the username.
*/
function getTTL(string calldata username)
public
view
returns(uint256)
{
return identity.ttl(username);
}
/**
* @dev Returns the remaining days of the username's identity identifier.
* @param username The specified username.
* @return days The days of the remaining time
*/
function remainTime(string calldata username) public view returns(uint){
uint256 remainTime = getTTL(username) - block.timestamp;
return remainTime/(60*60*24);
}
/**
* @dev Returns expiration time that calculated according to the amount and the price.
* @param amount The amount of the msg.value.
* @param price The price of the identifier.
* @return expiration time calculated by the amount and price
*/
function calculate(uint amount,uint price) internal returns(uint){
uint expires = amount / price;
return expires;
}
/**
* @dev Returns current block timestamp.
* @return timestamp of current block
*/
function blockTime() public view returns(uint){
return block.timestamp;
}
}