-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add libraries and basic example in MinimalDelegation
- Loading branch information
Showing
4 changed files
with
61 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.23; | ||
|
||
/// @dev The type of key. | ||
enum KeyType { | ||
P256, | ||
WebAuthnP256, | ||
Secp256k1 | ||
} | ||
|
||
struct Key { | ||
/// @dev Unix timestamp at which the key expires (0 = never). | ||
uint40 expiry; | ||
/// @dev Type of key. See the {KeyType} enum. | ||
KeyType keyType; | ||
/// @dev Whether the key is a super admin key. | ||
/// Super admin keys are allowed to call into super admin functions such as | ||
/// `authorize` and `revoke` via `execute`. | ||
bool isSuperAdmin; | ||
/// @dev Public key in encoded form. | ||
bytes publicKey; | ||
} | ||
|
||
library KeyLib { | ||
function hash(Key memory key) internal pure returns (bytes32) { | ||
return keccak256(abi.encode(key.keyType, keccak256(key.publicKey))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.23; | ||
|
||
library MinimalDelegationStorageLib { | ||
struct MinimalDelegationStorage { | ||
mapping(bytes32 keyHash => bytes encodedKey) keyStorage; | ||
} | ||
|
||
bytes32 private constant MINIMAL_DELEGATION_STORAGE_LOCATION = | ||
0x21f3d48e9724698d61a2dadd352c365013ee5d0f841f7fc54fb8a78301ee0c00; | ||
|
||
function _getMinimalDelegationStorage() private pure returns (MinimalDelegationStorage storage $) { | ||
assembly { | ||
$.slot := MINIMAL_DELEGATION_STORAGE_LOCATION | ||
} | ||
} | ||
|
||
function getKeyStorage(bytes32 keyHash) internal view returns (bytes memory) { | ||
return _getMinimalDelegationStorage().keyStorage[keyHash]; | ||
} | ||
|
||
function setKeyStorage(bytes32 keyHash, bytes memory encodedKey) internal { | ||
_getMinimalDelegationStorage().keyStorage[keyHash] = encodedKey; | ||
} | ||
} |