-
Notifications
You must be signed in to change notification settings - Fork 196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(world-modules): add callWithSignature
#2592
Changes from 11 commits
14a5428
5ab6b1e
123684e
95e22ee
15d4d31
55de311
ff3e917
11ec4a4
2d35a45
cd400d4
2cc25ce
e50e100
74ca5d4
5b10bc5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,46 @@ | ||||||
// SPDX-License-Identifier: MIT | ||||||
pragma solidity >=0.8.24; | ||||||
|
||||||
import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; | ||||||
import { System } from "@latticexyz/world/src/System.sol"; | ||||||
import { SystemCall } from "@latticexyz/world/src/SystemCall.sol"; | ||||||
import { createDelegation } from "@latticexyz/world/src/modules/init/implementations/createDelegation.sol"; | ||||||
|
||||||
import { CallWithSignatureNonces } from "./tables/CallWithSignatureNonces.sol"; | ||||||
import { getSignedMessageHash } from "./getSignedMessageHash.sol"; | ||||||
import { ECDSA } from "./ECDSA.sol"; | ||||||
|
||||||
contract Unstable_CallWithSignatureSystem is System { | ||||||
/** | ||||||
* @dev Mismatched signature. | ||||||
*/ | ||||||
error InvalidSignature(address signer); | ||||||
|
||||||
/** | ||||||
* @notice Calls a system with a given system ID using the given signature. | ||||||
* @param delegator The address on whose behalf the system is called. | ||||||
* @param systemId The ID of the system to be called. | ||||||
* @param callData The ABI data for the system call. | ||||||
* @param signature The EIP712 signature. | ||||||
* @return Return data from the system call. | ||||||
*/ | ||||||
function callWithSignature( | ||||||
address delegator, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wonder if we should call this
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree |
||||||
ResourceId systemId, | ||||||
bytes memory callData, | ||||||
bytes memory signature | ||||||
) external payable returns (bytes memory) { | ||||||
uint256 nonce = CallWithSignatureNonces.get(delegator); | ||||||
bytes32 hash = getSignedMessageHash(delegator, systemId, callData, nonce, _world()); | ||||||
|
||||||
// If the message was not signed by the delegator or is invalid, revert | ||||||
address signer = ECDSA.recover(hash, signature); | ||||||
if (signer != delegator) { | ||||||
revert InvalidSignature(signer); | ||||||
} | ||||||
|
||||||
CallWithSignatureNonces.set(delegator, nonce + 1); | ||||||
|
||||||
return SystemCall.callWithHooksOrRevert(delegator, systemId, callData, _msgValue()); | ||||||
} | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason we can't import this from world-modules?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I didn't think to try it 🤯