-
Notifications
You must be signed in to change notification settings - Fork 72
Expand file tree
/
Copy pathIdentity.sol
More file actions
744 lines (652 loc) · 25.5 KB
/
Identity.sol
File metadata and controls
744 lines (652 loc) · 25.5 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
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.27;
import "./interface/IIdentity.sol";
import "./interface/IClaimIssuer.sol";
import "./version/Version.sol";
import "./storage/Storage.sol";
/**
* @dev Implementation of the `IERC734` "KeyHolder" and the `IERC735` "ClaimHolder" interfaces
* into a common Identity Contract.
* This implementation has a separate contract were it declares all storage,
* allowing for it to be used as an upgradable logic contract.
*/
contract Identity is Storage, IIdentity, Version {
/**
* @notice Prevent any direct calls to the implementation contract (marked by _canInteract = false).
*/
modifier delegatedOnly() {
require(_canInteract == true, "Interacting with the library contract is forbidden.");
_;
}
/**
* @notice requires management key to call this function, or internal call
*/
modifier onlyManager() {
require(msg.sender == address(this) || keyHasPurpose(keccak256(abi.encode(msg.sender)), 1)
, "Permissions: Sender does not have management key");
_;
}
/**
* @notice requires claim key to call this function, or internal call
*/
modifier onlyClaimKey() {
require(msg.sender == address(this) || keyHasPurpose(keccak256(abi.encode(msg.sender)), 3)
, "Permissions: Sender does not have claim signer key");
_;
}
/**
* @notice constructor of the Identity contract
* @param initialManagementKey the address of the management key at deployment
* @param _isLibrary boolean value stating if the contract is library or not
* calls __Identity_init if contract is not library
*/
constructor(address initialManagementKey, bool _isLibrary) {
require(initialManagementKey != address(0), "invalid argument - zero address");
if (!_isLibrary) {
__Identity_init(initialManagementKey);
} else {
_initialized = true;
}
}
receive() external payable {}
/**
* @notice When using this contract as an implementation for a proxy, call this initializer with a delegatecall.
*
* @param initialManagementKey The ethereum address to be set as the management key of the ONCHAINID.
*/
function initialize(address initialManagementKey) external {
require(initialManagementKey != address(0), "invalid argument - zero address");
__Identity_init(initialManagementKey);
}
/**
* @dev See {IERC734-execute}.
* @notice Passes an execution instruction to the keymanager.
* If the sender is an ACTION key and the destination address is not the identity contract itself, then the
* execution is immediately approved and performed.
* If the destination address is the identity itself, then the execution would be performed immediately only if
* the sender is a MANAGEMENT key.
* Otherwise the execution request must be approved via the `approve` method.
* @return executionId to use in the approve function, to approve or reject this execution.
*/
function execute(address _to, uint256 _value, bytes memory _data)
external
delegatedOnly
override
payable
returns (uint256 executionId)
{
uint256 _executionId = _executionNonce;
_executions[_executionId].to = _to;
_executions[_executionId].value = _value;
_executions[_executionId].data = _data;
_executionNonce++;
emit ExecutionRequested(_executionId, _to, _value, _data);
if (keyHasPurpose(keccak256(abi.encode(msg.sender)), 1)) {
_approveAndExecute(_executionId, true);
}
else if (_to != address(this) && keyHasPurpose(keccak256(abi.encode(msg.sender)), 2)){
_approveAndExecute(_executionId, true);
}
return _executionId;
}
/**
* @dev See {IERC734-execute}.
* @notice Passes an execution instruction to the keymanager, using signatures instead of sender verification.
* If the sender is an ACTION key and the destination address is not the identity contract itself, then the
* execution is immediately approved and performed.
* If the destination address is the identity itself, then the execution would be performed immediately only if
* the sender is a MANAGEMENT key.
* Otherwise the execution request must be approved via the `approve` method.
* @param _keyType The type of key used for the signature, a uint256 for different key types. 1 = ECDSA, 2 = RSA, 3 = P256.
* @return executionId to use in the approve function, to approve or reject this execution.
*/
function executeSigned(address _to, uint256 _value, bytes memory _data, uint256 nonce, uint256 _keyType, uint8 v, bytes32 r, bytes32 s)
external
delegatedOnly
override
payable
returns (uint256 executionId) {
bytes32 executionSigner = _recoverSignerForExecution(_to, _value, _data, nonce, _keyType, v, r, s);
uint256 _executionId = _executionNonce;
_executions[_executionId].to = _to;
_executions[_executionId].value = _value;
_executions[_executionId].data = _data;
_executionNonce++;
emit ExecutionRequested(_executionId, _to, _value, _data);
if (keyHasPurpose(executionSigner, 1)) {
require(nonce == _operationNonce, "Invalid nonce");
_operationNonce++;
_approveAndExecute(_executionId, true);
} else if (_to != address(this) && keyHasPurpose(executionSigner, 2)){
require(nonce == _operationNonce, "Invalid nonce");
_operationNonce++;
_approveAndExecute(_executionId, true);
}
return _executionId;
}
/**
* @dev See {IERC734-getKey}.
* @notice Implementation of the getKey function from the ERC-734 standard
* @param _key The public key. for non-hex and long keys, its the Keccak256 hash of the key
* @return purposes Returns the full key data, if present in the identity.
* @return keyType Returns the full key data, if present in the identity.
* @return key Returns the full key data, if present in the identity.
*/
function getKey(bytes32 _key)
external
override
view
returns(uint256[] memory purposes, uint256 keyType, bytes32 key)
{
return (_keys[_key].purposes, _keys[_key].keyType, _keys[_key].key);
}
/**
* @dev See {IERC734-getKeyPurposes}.
* @notice gets the purposes of a key
* @param _key The public key. for non-hex and long keys, its the Keccak256 hash of the key
* @return _purposes Returns the purposes of the specified key
*/
function getKeyPurposes(bytes32 _key)
external
override
view
returns(uint256[] memory _purposes)
{
return (_keys[_key].purposes);
}
/**
* @dev See {IERC734-getKeysByPurpose}.
* @notice gets all the keys with a specific purpose from an identity
* @param _purpose a uint256[] Array of the key types, like 1 = MANAGEMENT, 2 = ACTION, 3 = CLAIM, 4 = ENCRYPTION
* @return keys Returns an array of public key bytes32 hold by this identity and having the specified purpose
*/
function getKeysByPurpose(uint256 _purpose)
external
override
view
returns(bytes32[] memory keys)
{
return _keysByPurpose[_purpose];
}
/**
* @dev See {IERC735-getClaimIdsByTopic}.
* @notice Implementation of the getClaimIdsByTopic function from the ERC-735 standard.
* used to get all the claims from the specified topic
* @param _topic The identity of the claim i.e. keccak256(abi.encode(_issuer, _topic))
* @return claimIds Returns an array of claim IDs by topic.
*/
function getClaimIdsByTopic(uint256 _topic)
external
override
view
returns(bytes32[] memory claimIds)
{
return _claimsByTopic[_topic];
}
/**
* @notice implementation of the addKey function of the ERC-734 standard
* Adds a _key to the identity. The _purpose specifies the purpose of key. Initially we propose four purposes:
* 1: MANAGEMENT keys, which can manage the identity
* 2: ACTION keys, which perform actions in this identities name (signing, logins, transactions, etc.)
* 3: CLAIM signer keys, used to sign claims on other identities which need to be revokable.
* 4: ENCRYPTION keys, used to encrypt data e.g. hold in claims.
* MUST only be done by keys of purpose 1, or the identity itself.
* If its the identity itself, the approval process will determine its approval.
* @param _key keccak256 representation of an ethereum address
* @param _type type of key used, which would be a uint256 for different key types. e.g. 1 = ECDSA, 2 = RSA, etc.
* @param _purpose a uint256 specifying the key type, like 1 = MANAGEMENT, 2 = ACTION, 3 = CLAIM, 4 = ENCRYPTION
* @return success Returns TRUE if the addition was successful and FALSE if not
*/
function addKey(bytes32 _key, uint256 _purpose, uint256 _type)
public
delegatedOnly
onlyManager
override
returns (bool success)
{
if (_keys[_key].key == _key) {
uint256[] memory _purposes = _keys[_key].purposes;
for (uint keyPurposeIndex = 0; keyPurposeIndex < _purposes.length; keyPurposeIndex++) {
uint256 purpose = _purposes[keyPurposeIndex];
if (purpose == _purpose) {
revert("Conflict: Key already has purpose");
}
}
_keys[_key].purposes.push(_purpose);
} else {
_keys[_key].key = _key;
_keys[_key].purposes = [_purpose];
_keys[_key].keyType = _type;
}
_keysByPurpose[_purpose].push(_key);
emit KeyAdded(_key, _purpose, _type);
return true;
}
/**
* @dev See {IERC734-approve}.
* @notice Approves an execution.
* If the sender is an ACTION key and the destination address is not the identity contract itself, then the
* approval is authorized and the operation would be performed.
* If the destination address is the identity itself, then the execution would be authorized and performed only
* if the sender is a MANAGEMENT key.
*/
function approve(uint256 _id, bool _approve)
public
delegatedOnly
override
returns (bool success)
{
require(_id < _executionNonce, "Cannot approve a non-existing execution");
require(!_executions[_id].executed, "Request already executed");
if(_executions[_id].to == address(this)) {
require(keyHasPurpose(keccak256(abi.encode(msg.sender)), 1), "Sender does not have management key");
}
else {
require(keyHasPurpose(keccak256(abi.encode(msg.sender)), 2), "Sender does not have action key");
}
return _approveAndExecute(_id, _approve);
}
function approveSigned(uint256 _id, bool _approve, uint256 _keyType, uint8 v, bytes32 r, bytes32 s)
public
delegatedOnly
override
returns (bool success)
{
require(_id < _executionNonce, "Cannot approve a non-existing execution");
require(!_executions[_id].executed, "Request already executed");
bytes32 executionSigner = _recoverSignerForPendingExecution(
_id,
_executions[_id].to,
_executions[_id].value,
_executions[_id].data,
_keyType,
v,
r,
s
);
if(_executions[_id].to == address(this)) {
require(keyHasPurpose(executionSigner, 1), "Sender does not have management key");
} else {
require(keyHasPurpose(executionSigner, 2), "Sender does not have action key");
}
return _approveAndExecute(_id, _approve);
}
/**
* @dev See {IERC734-removeKey}.
* @notice Remove the purpose from a key.
*/
function removeKey(bytes32 _key, uint256 _purpose)
public
delegatedOnly
onlyManager
override
returns (bool success)
{
require(_keys[_key].key == _key, "NonExisting: Key isn't registered");
uint256[] memory _purposes = _keys[_key].purposes;
uint purposeIndex = 0;
while (_purposes[purposeIndex] != _purpose) {
purposeIndex++;
if (purposeIndex == _purposes.length) {
revert("NonExisting: Key doesn't have such purpose");
}
}
_purposes[purposeIndex] = _purposes[_purposes.length - 1];
_keys[_key].purposes = _purposes;
_keys[_key].purposes.pop();
uint keyIndex = 0;
uint arrayLength = _keysByPurpose[_purpose].length;
while (_keysByPurpose[_purpose][keyIndex] != _key) {
keyIndex++;
if (keyIndex >= arrayLength) {
break;
}
}
_keysByPurpose[_purpose][keyIndex] = _keysByPurpose[_purpose][arrayLength - 1];
_keysByPurpose[_purpose].pop();
uint keyType = _keys[_key].keyType;
if (_purposes.length - 1 == 0) {
delete _keys[_key];
}
emit KeyRemoved(_key, _purpose, keyType);
return true;
}
/**
* @dev See {IERC735-addClaim}.
* @notice Implementation of the addClaim function from the ERC-735 standard
* Require that the msg.sender has claim signer key.
*
* @param _topic The type of claim
* @param _scheme The scheme with which this claim SHOULD be verified or how it should be processed.
* @param _issuer The issuers identity contract address, or the address used to sign the above signature.
* @param _signature Signature which is the proof that the claim issuer issued a claim of topic for this identity.
* it MUST be a signed message of the following structure:
* keccak256(abi.encode(address identityHolder_address, uint256 _ topic, bytes data))
* @param _data The hash of the claim data, sitting in another
* location, a bit-mask, call data, or actual data based on the claim scheme.
* @param _uri The location of the claim, this can be HTTP links, swarm hashes, IPFS hashes, and such.
*
* @return claimRequestId Returns claimRequestId: COULD be
* send to the approve function, to approve or reject this claim.
* triggers ClaimAdded event.
*/
function addClaim(
uint256 _topic,
uint256 _scheme,
address _issuer,
bytes memory _signature,
bytes memory _data,
string memory _uri
)
public
delegatedOnly
onlyClaimKey
override
returns (bytes32 claimRequestId)
{
if (_issuer != address(this)) {
require(IClaimIssuer(_issuer).isClaimValid(
IIdentity(address(this)),
_topic,
_signature,
_data),
"invalid claim");
}
bytes32 claimId = keccak256(abi.encode(_issuer, _topic));
_claims[claimId].topic = _topic;
_claims[claimId].scheme = _scheme;
_claims[claimId].signature = _signature;
_claims[claimId].data = _data;
_claims[claimId].uri = _uri;
if (_claims[claimId].issuer != _issuer) {
_claimsByTopic[_topic].push(claimId);
_claims[claimId].issuer = _issuer;
emit ClaimAdded(claimId, _topic, _scheme, _issuer, _signature, _data, _uri);
}
else {
emit ClaimChanged(claimId, _topic, _scheme, _issuer, _signature, _data, _uri);
}
return claimId;
}
/**
* @dev See {IERC735-removeClaim}.
* @notice Implementation of the removeClaim function from the ERC-735 standard
* Require that the msg.sender has management key.
* Can only be removed by the claim issuer, or the claim holder itself.
*
* @param _claimId The identity of the claim i.e. keccak256(abi.encode(_issuer, _topic))
*
* @return success Returns TRUE when the claim was removed.
* triggers ClaimRemoved event
*/
function removeClaim(bytes32 _claimId)
public
delegatedOnly
onlyClaimKey
override
returns
(bool success) {
uint256 _topic = _claims[_claimId].topic;
if (_topic == 0) {
revert("NonExisting: There is no claim with this ID");
}
uint claimIndex = 0;
uint arrayLength = _claimsByTopic[_topic].length;
while (_claimsByTopic[_topic][claimIndex] != _claimId) {
claimIndex++;
if (claimIndex >= arrayLength) {
break;
}
}
_claimsByTopic[_topic][claimIndex] =
_claimsByTopic[_topic][arrayLength - 1];
_claimsByTopic[_topic].pop();
emit ClaimRemoved(
_claimId,
_topic,
_claims[_claimId].scheme,
_claims[_claimId].issuer,
_claims[_claimId].signature,
_claims[_claimId].data,
_claims[_claimId].uri
);
delete _claims[_claimId];
return true;
}
/**
* @dev See {IERC735-getClaim}.
* @notice Implementation of the getClaim function from the ERC-735 standard.
*
* @param _claimId The identity of the claim i.e. keccak256(abi.encode(_issuer, _topic))
*
* @return topic Returns all the parameters of the claim for the
* specified _claimId (topic, scheme, signature, issuer, data, uri) .
* @return scheme Returns all the parameters of the claim for the
* specified _claimId (topic, scheme, signature, issuer, data, uri) .
* @return issuer Returns all the parameters of the claim for the
* specified _claimId (topic, scheme, signature, issuer, data, uri) .
* @return signature Returns all the parameters of the claim for the
* specified _claimId (topic, scheme, signature, issuer, data, uri) .
* @return data Returns all the parameters of the claim for the
* specified _claimId (topic, scheme, signature, issuer, data, uri) .
* @return uri Returns all the parameters of the claim for the
* specified _claimId (topic, scheme, signature, issuer, data, uri) .
*/
function getClaim(bytes32 _claimId)
public
override
view
returns(
uint256 topic,
uint256 scheme,
address issuer,
bytes memory signature,
bytes memory data,
string memory uri
)
{
return (
_claims[_claimId].topic,
_claims[_claimId].scheme,
_claims[_claimId].issuer,
_claims[_claimId].signature,
_claims[_claimId].data,
_claims[_claimId].uri
);
}
/**
* @dev See {IERC734-keyHasPurpose}.
* @notice Returns true if the key has MANAGEMENT purpose or the specified purpose.
*/
function keyHasPurpose(bytes32 _key, uint256 _purpose)
public
override
view
returns(bool result)
{
Key memory key = _keys[_key];
if (key.key == 0) return false;
for (uint keyPurposeIndex = 0; keyPurposeIndex < key.purposes.length; keyPurposeIndex++) {
uint256 purpose = key.purposes[keyPurposeIndex];
if (purpose == 1 || purpose == _purpose) return true;
}
return false;
}
/**
* @dev Checks if a claim is valid. Claims issued by the identity are self-attested claims. They do not have a
* built-in revocation mechanism and are considered valid as long as their signature is valid and they are still
* stored by the identity contract.
* @param _identity the identity contract related to the claim
* @param claimTopic the claim topic of the claim
* @param sig the signature of the claim
* @param data the data field of the claim
* @return claimValid true if the claim is valid, false otherwise
*/
function isClaimValid(
IIdentity _identity,
uint256 claimTopic,
bytes memory sig,
bytes memory data)
public override virtual view returns (bool claimValid)
{
bytes32 dataHash = keccak256(abi.encode(_identity, claimTopic, data));
// Use abi.encodePacked to concatenate the message prefix and the message to sign.
bytes32 prefixedHash = keccak256(
abi.encodePacked("\x19Ethereum Signed Message:\n32", dataHash)
);
// Recover address of data signer
address recovered = getRecoveredAddress(sig, prefixedHash);
// Take hash of recovered address
bytes32 hashedAddr = keccak256(abi.encode(recovered));
// Does the trusted identifier have they key which signed the user's claim?
// && (isClaimRevoked(_claimId) == false)
if (keyHasPurpose(hashedAddr, 3)) {
return true;
}
return false;
}
/**
* @dev returns the address that signed the given data
* @param sig the signature of the data
* @param dataHash the data that was signed
* returns the address that signed dataHash and created the signature sig
*/
function getRecoveredAddress(bytes memory sig, bytes32 dataHash)
public
pure
returns (address addr)
{
bytes32 ra;
bytes32 sa;
uint8 va;
// Check the signature length
if (sig.length != 65) {
return address(0);
}
// Divide the signature in r, s and v variables
// solhint-disable-next-line no-inline-assembly
assembly {
ra := mload(add(sig, 32))
sa := mload(add(sig, 64))
va := byte(0, mload(add(sig, 96)))
}
if (va < 27) {
va += 27;
}
address recoveredAddress = ecrecover(dataHash, va, ra, sa);
return (recoveredAddress);
}
/**
* @notice Initializer internal function for the Identity contract.
*
* @param initialManagementKey The ethereum address to be set as the management key of the ONCHAINID.
*/
// solhint-disable-next-line func-name-mixedcase
function __Identity_init(address initialManagementKey) internal {
require(!_initialized || _isConstructor(), "Initial key was already setup.");
_initialized = true;
_canInteract = true;
bytes32 _key = keccak256(abi.encode(initialManagementKey));
_keys[_key].key = _key;
_keys[_key].purposes = [1];
_keys[_key].keyType = 1;
_keysByPurpose[1].push(_key);
emit KeyAdded(_key, 1, 1);
}
function _approveAndExecute(uint256 _id, bool _approve) internal delegatedOnly returns (bool success) {
require(_id < _executionNonce, "Cannot approve a non-existing execution");
require(!_executions[_id].executed, "Request already executed");
emit Approved(_id, _approve);
if (_approve == true) {
_executions[_id].approved = true;
// solhint-disable-next-line avoid-low-level-calls
(success,) = _executions[_id].to.call{value:(_executions[_id].value)}(_executions[_id].data);
if (success) {
_executions[_id].executed = true;
emit Executed(
_id,
_executions[_id].to,
_executions[_id].value,
_executions[_id].data
);
return true;
} else {
emit ExecutionFailed(
_id,
_executions[_id].to,
_executions[_id].value,
_executions[_id].data
);
return false;
}
} else {
_executions[_id].approved = false;
}
return false;
}
function _recoverSignerForExecution(
address _to,
uint256 _value,
bytes memory _data,
uint256 _nonce,
uint256 _keyType,
uint8 v,
bytes32 r,
bytes32 s
) internal delegatedOnly view returns(bytes32 keyHash) {
if (_keyType == 1) {
bytes32 dataHash = keccak256(abi.encode(address(this), _to, _value, _data, _nonce));
bytes32 prefixedHash = keccak256(
abi.encodePacked("\x19Ethereum Signed Message:\n32", dataHash)
);
address recovered = ecrecover(prefixedHash, v, r, s);
return keccak256(abi.encode(recovered));
} else if (_keyType == 3) {
revert("Not implemented.");
} else {
revert("Invalid key type");
}
}
function _recoverSignerForPendingExecution(
uint256 _id,
address _to,
uint256 _value,
bytes memory _data,
uint256 _keyType,
uint8 v,
bytes32 r,
bytes32 s
) internal delegatedOnly view returns(bytes32 keyHash) {
if (_keyType == 1) {
bytes32 dataHash = keccak256(abi.encode(address(this), _id, _to, _value, _data));
bytes32 prefixedHash = keccak256(
abi.encodePacked("\x19Ethereum Signed Message:\n32", dataHash)
);
address recovered = ecrecover(prefixedHash, v, r, s);
return keccak256(abi.encode(recovered));
} else if (_keyType == 3) {
revert("Not implemented.");
} else {
revert("Invalid key type");
}
}
/**
* @notice Return the operation nonce (for signed operations).
* @return The next sequential nonce.
*/
function getNonce() public view virtual returns (uint256) {
return _operationNonce;
}
/**
* @notice Computes if the context in which the function is called is a constructor or not.
*
* @return true if the context is a constructor.
*/
function _isConstructor() private view returns (bool) {
address self = address(this);
uint256 cs;
// solhint-disable-next-line no-inline-assembly
assembly { cs := extcodesize(self) }
return cs == 0;
}
}