LSP6KeyManager
Implementation of a contract acting as a controller of an ERC725 Account, using permissions stored in the ERC725Y storage.
All the permissions can be set on the ERC725 Account using setData(bytes32,bytes)
or setData(bytes32[],bytes[])
.
Public Methods
Public methods are accessible externally from users, allowing interaction with this function from dApps or other smart contracts. When marked as 'public', a method can be called both externally and internally, on the other hand, when marked as 'external', a method can only be called externally.
constructor
- Specification details: LSP-6-KeyManager
- Solidity implementation:
LSP6KeyManager.sol
constructor(address target_);
Deploying a LSP6KeyManager linked to the contract at address target_
.
Deploy a Key Manager and set the target_
address in the contract storage, making this Key Manager linked to this target_
contract.
Parameters
Name | Type | Description |
---|---|---|
target_ | address | The address of the contract to control and forward calldata payloads to. |
VERSION
- Specification details: LSP-6-KeyManager
- Solidity implementation:
LSP6KeyManager.sol
- Function signature:
VERSION()
- Function selector:
0xffa1ad74
function VERSION() external view returns (string);
Contract version.
Returns
Name | Type | Description |
---|---|---|
0 | string | - |
execute
- Specification details: LSP-6-KeyManager
- Solidity implementation:
LSP6KeyManager.sol
- Function signature:
execute(bytes)
- Function selector:
0x09c5eabe
function execute(bytes payload) external payable returns (bytes);
Executing the following payload on the linked contract: payload
Execute A payload
on the linked target
contract after having verified the permissions associated with the function being run. The payload
MUST be a valid abi-encoded function call of one of the functions present in the linked target
, otherwise the call will fail. The linked target
will return some data on successful execution, or revert on failure.
Emitted events:
PermissionsVerified
event when the permissions related topayload
have been verified successfully.
Parameters
Name | Type | Description |
---|---|---|
payload | bytes | The abi-encoded function call to execute on the linked target . |
Returns
Name | Type | Description |
---|---|---|
0 | bytes | The abi-decoded data returned by the function called on the linked target . |
executeBatch
- Specification details: LSP-6-KeyManager
- Solidity implementation:
LSP6KeyManager.sol
- Function signature:
executeBatch(uint256[],bytes[])
- Function selector:
0xbf0176ff
function executeBatch(
uint256[] values,
bytes[] payloads
) external payable returns (bytes[]);
*Executing the following batch of payloads and sensind on the linked contract.
-
payloads:
payloads
-
values transferred for each payload:
values
*
Same as execute
but execute a batch of payloads (abi-encoded function calls) in a single transaction.
Emitted events:
PermissionsVerified
event for each permissions related to eachpayload
that have been verified successfully.
Parameters
Name | Type | Description |
---|---|---|
values | uint256[] | An array of amount of native tokens to be transferred for each payload . |
payloads | bytes[] | An array of abi-encoded function calls to execute successively on the linked target . |
Returns
Name | Type | Description |
---|---|---|
0 | bytes[] | An array of abi-decoded data returned by the functions called on the linked target . |
executeRelayCall
- Specification details: LSP-6-KeyManager
- Solidity implementation:
LSP6KeyManager.sol
- Function signature:
executeRelayCall(bytes,uint256,uint256,bytes)
- Function selector:
0x4c8a4e74
If you are looking to learn how to sign and execute relay transactions via the Key Manager, see our Javascript step by step guide "Execute Relay Transactions". See the LSP6 Standard page for more details on how to generate a valid signature for Execute Relay Call.
function executeRelayCall(
bytes signature,
uint256 nonce,
uint256 validityTimestamps,
bytes payload
) external payable returns (bytes);
Executing the following payload given the nonce nonce
and signature signature
. Payload: payload
Allows any address (executor) to execute a payload (= abi-encoded function call), given they have a valid signature from a signer address and a valid nonce
for this signer. The signature MUST be generated according to the signature format defined by the LSP25 standard. The signer that generated the signature
MUST be a controller with some permissions on the linked target
. The payload
will be executed on the target
contract once the LSP25 signature and the permissions of the signer have been verified.
Emitted events:
PermissionsVerified
event when the permissions related topayload
have been verified successfully.
Parameters
Name | Type | Description |
---|---|---|
signature | bytes | A 65 bytes long signature for a meta transaction according to LSP25. |
nonce | uint256 | The nonce of the address that signed the calldata (in a specific _channel ), obtained via getNonce . Used to prevent replay attack. |
validityTimestamps | uint256 | Two uint128 timestamps concatenated together that describes when the relay transaction is valid "from" (left uint128 ) and "until" as a deadline (right uint128 ). |
payload | bytes | The abi-encoded function call to execute. |
Returns
Name | Type | Description |
---|---|---|
0 | bytes | The data being returned by the function executed. |
executeRelayCallBatch
- Specification details: LSP-6-KeyManager
- Solidity implementation:
LSP6KeyManager.sol
- Function signature:
executeRelayCallBatch(bytes[],uint256[],uint256[],uint256[],bytes[])
- Function selector:
0xa20856a5
function executeRelayCallBatch(
bytes[] signatures,
uint256[] nonces,
uint256[] validityTimestamps,
uint256[] values,
bytes[] payloads
) external payable returns (bytes[]);
Executing a batch of relay calls (= meta-transactions).
Same as executeRelayCall
but execute a batch of signed calldata payloads (abi-encoded function calls) in a single transaction. The signatures
can be from multiple controllers, not necessarely the same controller, as long as each of these controllers that signed have the right permissions related to the calldata payload
they signed.
Requirements:
- the length of
signatures
,nonces
,validityTimestamps
,values
andpayloads
MUST be the same.- the value sent to this function (
msg.value
) MUST be equal to the sum of allvalues
in the batch. There should not be any excess value sent to this function.
Parameters
Name | Type | Description |
---|---|---|
signatures | bytes[] | An array of 65 bytes long signatures for meta transactions according to LSP25. |
nonces | uint256[] | An array of nonces of the addresses that signed the calldata payloads (in specific channels). Obtained via getNonce . Used to prevent replay attack. |
validityTimestamps | uint256[] | An array of two uint128 concatenated timestamps that describe when the relay transaction is valid "from" (left uint128 ) and "until" (right uint128 ). |
values | uint256[] | An array of amount of native tokens to be transferred for each calldata payload . |
payloads | bytes[] | An array of abi-encoded function calls to be executed successively. |
Returns
Name | Type | Description |
---|---|---|
0 | bytes[] | An array of abi-decoded data returned by the functions executed. |
getNonce
- Specification details: LSP-6-KeyManager
- Solidity implementation:
LSP6KeyManager.sol
- Function signature:
getNonce(address,uint128)
- Function selector:
0xb44581d9
A signer can choose its channel number arbitrarily. The recommended practice is to:
- use
channelId == 0
for transactions for which the ordering of execution matters.abi Example: you have two transactions A and B, and transaction A must be executed first and complete successfully before transaction B should be executed). - use any other
channelId
number for transactions that you want to be order independant (out-of-order execution, execution "in parallel"). _Example: you have two transactions A and B. You want transaction B to be executed a) without having to wait for transaction A to complete, or b) regardless if transaction A completed successfully or not.
function getNonce(
address from,
uint128 channelId
) external view returns (uint256);
Reading the latest nonce of address from
in the channel ID channelId
.
Get the nonce for a specific from
address that can be used for signing relay transactions via executeRelayCall
.
Parameters
Name | Type | Description |
---|---|---|
from | address | The address of the signer of the transaction. |
channelId | uint128 | The channel id that the signer wants to use for executing the transaction. |
Returns
Name | Type | Description |
---|---|---|
0 | uint256 | The current nonce on a specific channelId . |
isValidSignature
- Specification details: LSP-6-KeyManager
- Solidity implementation:
LSP6KeyManager.sol
- Function signature:
isValidSignature(bytes32,bytes)
- Function selector:
0x1626ba7e
This function does not enforce by default the inclusion of the address of this contract in the signature digest. It is recommended that protocols or applications using this contract include the targeted address (= this contract) in the data to sign. To ensure that a signature is valid for a specific LSP6KeyManager and prevent signatures from the same EOA to be replayed across different LSP6KeyManager.
function isValidSignature(
bytes32 dataHash,
bytes signature
) external view returns (bytes4 returnedStatus);
Checks if a signature was signed by a controller that has the permission SIGN
. If the signer is a controller with the permission SIGN
, it will return the ERC1271 success value.
Parameters
Name | Type | Description |
---|---|---|
dataHash | bytes32 | - |
signature | bytes | Signature byte array associated with _data |
Returns
Name | Type | Description |
---|---|---|
returnedStatus | bytes4 | 0x1626ba7e on success, or 0xffffffff on failure. |
lsp20VerifyCall
- Specification details: LSP-6-KeyManager
- Solidity implementation:
LSP6KeyManager.sol
- Function signature:
lsp20VerifyCall(address,address,address,uint256,bytes)
- Function selector:
0xde928f14
This function can call by any other address than the target
. This allows to verify permissions in a "read-only" manner. Anyone can call this function to verify if the caller
has the right permissions to perform the abi-encoded function call data
on the target
contract (while sending msgValue
alongside the call). If the permissions have been verified successfully and caller
is authorized, one of the following two LSP20 success value will be returned:
0x1a238000
: LSP20 success value without post verification (last byte is0x00
).0x1a238001
: LSP20 success value with post-verification (last byte is0x01
).
function lsp20VerifyCall(
address,
address targetContract,
address caller,
uint256 msgValue,
bytes callData
) external nonpayable returns (bytes4);
Parameters
Name | Type | Description |
---|---|---|
_0 | address | - |
targetContract | address | - |
caller | address | The address who called the function on the target contract. |
msgValue | uint256 | - |
callData | bytes | The calldata sent by the caller to the msg.sender |
Returns
Name | Type | Description |
---|---|---|
0 | bytes4 | MUST return the first 3 bytes of lsp20VerifyCall(address,uint256,bytes) function selector if the call to the function is allowed, concatened with a byte that determines if the lsp20VerifyCallResult function should be called after the original function call. The byte that invoke the lsp20VerifyCallResult function is strictly 0x01 . |
lsp20VerifyCallResult
- Specification details: LSP-6-KeyManager
- Solidity implementation:
LSP6KeyManager.sol
- Function signature:
lsp20VerifyCallResult(bytes32,bytes)
- Function selector:
0xd3fc45d3
function lsp20VerifyCallResult(
bytes32,
bytes
) external nonpayable returns (bytes4);
Parameters
Name | Type | Description |
---|---|---|
_0 | bytes32 | - |
_1 | bytes | - |
Returns
Name | Type | Description |
---|---|---|
0 | bytes4 | MUST return the lsp20VerifyCallResult function selector if the call to the function is allowed |
supportsInterface
- Specification details: LSP-6-KeyManager
- Solidity implementation:
LSP6KeyManager.sol
- Function signature:
supportsInterface(bytes4)
- Function selector:
0x01ffc9a7
function supportsInterface(bytes4 interfaceId) external view returns (bool);
See IERC165-supportsInterface
.
Parameters
Name | Type | Description |
---|---|---|
interfaceId | bytes4 | - |
Returns
Name | Type | Description |
---|---|---|
0 | bool | - |
target
- Specification details: LSP-6-KeyManager
- Solidity implementation:
LSP6KeyManager.sol
- Function signature:
target()
- Function selector:
0xd4b83992
function target() external view returns (address);
Get The address of the contract linked to this Key Manager.
Returns
Name | Type | Description |
---|---|---|
0 | address | The address of the linked contract |
Internal Methods
Any method labeled as internal
serves as utility function within the contract. They can be used when writing solidity contracts that inherit from this contract. These methods can be extended or modified by overriding their internal behavior to suit specific needs.
Internal functions cannot be called externally, whether from other smart contracts, dApp interfaces, or backend services. Their restricted accessibility ensures that they remain exclusively available within the context of the current contract, promoting controlled and encapsulated usage of these internal utilities.