From 9d97413a27d4b629d68e21065b9b26691683150e Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Fri, 12 Apr 2024 13:33:12 +0100 Subject: [PATCH 1/8] feat(world-modules): callWithSignature chain id is salt --- .../src/modules/delegation/getSignedMessageHash.sol | 2 +- packages/world-modules/test/CallWithSignatureModule.t.sol | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/world-modules/src/modules/delegation/getSignedMessageHash.sol b/packages/world-modules/src/modules/delegation/getSignedMessageHash.sol index 617b304484..74bcaf8f99 100644 --- a/packages/world-modules/src/modules/delegation/getSignedMessageHash.sol +++ b/packages/world-modules/src/modules/delegation/getSignedMessageHash.sol @@ -24,7 +24,7 @@ function getSignedMessageHash( address worldAddress ) view returns (bytes32) { bytes32 domainSeperator = keccak256( - abi.encode(keccak256("EIP712Domain(uint256 chainId,address verifyingContract)"), block.chainid, worldAddress) + abi.encode(keccak256("EIP712Domain(address verifyingContract,bytes32 salt)"), worldAddress, bytes32(block.chainid)) ); return diff --git a/packages/world-modules/test/CallWithSignatureModule.t.sol b/packages/world-modules/test/CallWithSignatureModule.t.sol index 70c7bfb6a6..bea67d359c 100644 --- a/packages/world-modules/test/CallWithSignatureModule.t.sol +++ b/packages/world-modules/test/CallWithSignatureModule.t.sol @@ -104,7 +104,7 @@ contract Unstable_CallWithSignatureModuleTest is Test, GasReporter { vm.expectRevert( abi.encodeWithSelector( IUnstable_CallWithSignatureErrors.InvalidSignature.selector, - 0x824E5E0aF3eA693b906527Dc41E4a29F037d515b + 0x5266996Bb73ce3ac0E75D79Db87f4a96063cEe1F ) ); Unstable_CallWithSignatureSystem(address(world)).callWithSignature( From ca2f283ac6e5c19b0446e240ec280f4c9ce4bb8f Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Fri, 12 Apr 2024 13:41:40 +0100 Subject: [PATCH 2/8] fix: test --- .../sync-test/registerDelegationWithSignature.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/e2e/packages/sync-test/registerDelegationWithSignature.test.ts b/e2e/packages/sync-test/registerDelegationWithSignature.test.ts index 2ee24aab38..b12a46791b 100644 --- a/e2e/packages/sync-test/registerDelegationWithSignature.test.ts +++ b/e2e/packages/sync-test/registerDelegationWithSignature.test.ts @@ -6,7 +6,7 @@ import { deployContracts, startViteServer, startBrowserAndPage, openClientWithRo import { rpcHttpUrl } from "./setup/constants"; import { waitForInitialSync } from "./data/waitForInitialSync"; import { createBurnerAccount, resourceToHex, transportObserver } from "@latticexyz/common"; -import { http, createWalletClient, ClientConfig, encodeFunctionData } from "viem"; +import { http, createWalletClient, ClientConfig, encodeFunctionData, toHex } from "viem"; import { mudFoundry } from "@latticexyz/common/chains"; import { encodeEntity } from "@latticexyz/store-sync/recs"; import { callPageFunction } from "./data/callPageFunction"; @@ -79,8 +79,8 @@ describe("callWithSignature", async () => { // Sign registration call message const signature = await delegatorWalletClient.signTypedData({ domain: { - chainId: delegatorWalletClient.chain.id, verifyingContract: worldContract.address, + salt: toHex(delegatorWalletClient.chain.id, { size: 32 }), }, types: callWithSignatureTypes, primaryType: "Call", From fbc7520b8a39c04bf99d8b9f3bb4478036d80722 Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Fri, 12 Apr 2024 13:47:42 +0100 Subject: [PATCH 3/8] chore: changeset --- .changeset/itchy-baboons-camp.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/itchy-baboons-camp.md diff --git a/.changeset/itchy-baboons-camp.md b/.changeset/itchy-baboons-camp.md new file mode 100644 index 0000000000..cca126a2b2 --- /dev/null +++ b/.changeset/itchy-baboons-camp.md @@ -0,0 +1,5 @@ +--- +"@latticexyz/world-modules": patch +--- + +Moved the chain ID in `CallWithSignature` from the `chainId` to the `salt` field, preventing wallets from attempting to switch networks based on the messages chain. From 06143fdc143e4c093b7326c7b8956bf0261bb3de Mon Sep 17 00:00:00 2001 From: yonada Date: Fri, 12 Apr 2024 13:59:09 +0100 Subject: [PATCH 4/8] chore: changeset suggestion Co-authored-by: Kevin Ingersoll --- .changeset/itchy-baboons-camp.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changeset/itchy-baboons-camp.md b/.changeset/itchy-baboons-camp.md index cca126a2b2..6d2471c077 100644 --- a/.changeset/itchy-baboons-camp.md +++ b/.changeset/itchy-baboons-camp.md @@ -2,4 +2,4 @@ "@latticexyz/world-modules": patch --- -Moved the chain ID in `CallWithSignature` from the `chainId` to the `salt` field, preventing wallets from attempting to switch networks based on the messages chain. +Moved the chain ID in `CallWithSignature` from the `domain.chainId` to the `domain.salt` field to allow for cross-chain signing without requiring wallets to switch networks. The value of this field should be the chain on which the world lives, rather than the chain the wallet is connected to. From c9aebb3d405700a40378ee53da582bf5ce65b02b Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Fri, 12 Apr 2024 14:06:25 +0100 Subject: [PATCH 5/8] docs: comment --- .../src/modules/delegation/getSignedMessageHash.sol | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/world-modules/src/modules/delegation/getSignedMessageHash.sol b/packages/world-modules/src/modules/delegation/getSignedMessageHash.sol index 74bcaf8f99..46a42fe5f9 100644 --- a/packages/world-modules/src/modules/delegation/getSignedMessageHash.sol +++ b/packages/world-modules/src/modules/delegation/getSignedMessageHash.sol @@ -3,6 +3,10 @@ pragma solidity >=0.8.24; import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; +// Note the intended value of the `salt` field is the chain ID. +// It is not included in `chainId`, to allow cross-chain signing without requiring wallets to switch networks. +// The value of this field should be the chain on which the world lives, rather than the chain the wallet is connected to. +bytes32 constant DOMAIN_TYPEHASH = keccak256("EIP712Domain(address verifyingContract,bytes32 salt)"); bytes32 constant CALL_TYPEHASH = keccak256("Call(address signer,bytes32 systemId,bytes callData,uint256 nonce)"); /** @@ -23,9 +27,7 @@ function getSignedMessageHash( uint256 nonce, address worldAddress ) view returns (bytes32) { - bytes32 domainSeperator = keccak256( - abi.encode(keccak256("EIP712Domain(address verifyingContract,bytes32 salt)"), worldAddress, bytes32(block.chainid)) - ); + bytes32 domainSeperator = keccak256(abi.encode(DOMAIN_TYPEHASH, worldAddress, bytes32(block.chainid))); return keccak256( From dd688cf502e12399542c687c780a1265822ce01b Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Fri, 12 Apr 2024 18:09:12 +0100 Subject: [PATCH 6/8] refactor: rename folder --- .../src/modules/{delegation => callwithsignature}/ECDSA.sol | 0 .../IUnstable_CallWithSignatureErrors.sol | 0 .../Unstable_CallWithSignatureModule.sol | 0 .../Unstable_CallWithSignatureSystem.sol | 0 .../src/modules/{delegation => callwithsignature}/constants.sol | 0 .../{delegation => callwithsignature}/getSignedMessageHash.sol | 0 .../tables/CallWithSignatureNonces.sol | 0 .../validateCallWithSignature.sol | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename packages/world-modules/src/modules/{delegation => callwithsignature}/ECDSA.sol (100%) rename packages/world-modules/src/modules/{delegation => callwithsignature}/IUnstable_CallWithSignatureErrors.sol (100%) rename packages/world-modules/src/modules/{delegation => callwithsignature}/Unstable_CallWithSignatureModule.sol (100%) rename packages/world-modules/src/modules/{delegation => callwithsignature}/Unstable_CallWithSignatureSystem.sol (100%) rename packages/world-modules/src/modules/{delegation => callwithsignature}/constants.sol (100%) rename packages/world-modules/src/modules/{delegation => callwithsignature}/getSignedMessageHash.sol (100%) rename packages/world-modules/src/modules/{delegation => callwithsignature}/tables/CallWithSignatureNonces.sol (100%) rename packages/world-modules/src/modules/{delegation => callwithsignature}/validateCallWithSignature.sol (100%) diff --git a/packages/world-modules/src/modules/delegation/ECDSA.sol b/packages/world-modules/src/modules/callwithsignature/ECDSA.sol similarity index 100% rename from packages/world-modules/src/modules/delegation/ECDSA.sol rename to packages/world-modules/src/modules/callwithsignature/ECDSA.sol diff --git a/packages/world-modules/src/modules/delegation/IUnstable_CallWithSignatureErrors.sol b/packages/world-modules/src/modules/callwithsignature/IUnstable_CallWithSignatureErrors.sol similarity index 100% rename from packages/world-modules/src/modules/delegation/IUnstable_CallWithSignatureErrors.sol rename to packages/world-modules/src/modules/callwithsignature/IUnstable_CallWithSignatureErrors.sol diff --git a/packages/world-modules/src/modules/delegation/Unstable_CallWithSignatureModule.sol b/packages/world-modules/src/modules/callwithsignature/Unstable_CallWithSignatureModule.sol similarity index 100% rename from packages/world-modules/src/modules/delegation/Unstable_CallWithSignatureModule.sol rename to packages/world-modules/src/modules/callwithsignature/Unstable_CallWithSignatureModule.sol diff --git a/packages/world-modules/src/modules/delegation/Unstable_CallWithSignatureSystem.sol b/packages/world-modules/src/modules/callwithsignature/Unstable_CallWithSignatureSystem.sol similarity index 100% rename from packages/world-modules/src/modules/delegation/Unstable_CallWithSignatureSystem.sol rename to packages/world-modules/src/modules/callwithsignature/Unstable_CallWithSignatureSystem.sol diff --git a/packages/world-modules/src/modules/delegation/constants.sol b/packages/world-modules/src/modules/callwithsignature/constants.sol similarity index 100% rename from packages/world-modules/src/modules/delegation/constants.sol rename to packages/world-modules/src/modules/callwithsignature/constants.sol diff --git a/packages/world-modules/src/modules/delegation/getSignedMessageHash.sol b/packages/world-modules/src/modules/callwithsignature/getSignedMessageHash.sol similarity index 100% rename from packages/world-modules/src/modules/delegation/getSignedMessageHash.sol rename to packages/world-modules/src/modules/callwithsignature/getSignedMessageHash.sol diff --git a/packages/world-modules/src/modules/delegation/tables/CallWithSignatureNonces.sol b/packages/world-modules/src/modules/callwithsignature/tables/CallWithSignatureNonces.sol similarity index 100% rename from packages/world-modules/src/modules/delegation/tables/CallWithSignatureNonces.sol rename to packages/world-modules/src/modules/callwithsignature/tables/CallWithSignatureNonces.sol diff --git a/packages/world-modules/src/modules/delegation/validateCallWithSignature.sol b/packages/world-modules/src/modules/callwithsignature/validateCallWithSignature.sol similarity index 100% rename from packages/world-modules/src/modules/delegation/validateCallWithSignature.sol rename to packages/world-modules/src/modules/callwithsignature/validateCallWithSignature.sol From 2720170c211fd1eec2502ff851cd68556afaa1bd Mon Sep 17 00:00:00 2001 From: Fraser Scott Date: Fri, 12 Apr 2024 18:14:26 +0100 Subject: [PATCH 7/8] fix: path --- packages/world-modules/mud.config.ts | 2 +- packages/world-modules/src/index.sol | 2 +- .../tables/CallWithSignatureNonces.sol | 199 ++++++++++++++++++ .../test/CallWithSignatureModule.t.sol | 10 +- 4 files changed, 206 insertions(+), 7 deletions(-) create mode 100644 packages/world-modules/src/modules/delegation/tables/CallWithSignatureNonces.sol diff --git a/packages/world-modules/mud.config.ts b/packages/world-modules/mud.config.ts index e4a75fd37c..c9813db299 100644 --- a/packages/world-modules/mud.config.ts +++ b/packages/world-modules/mud.config.ts @@ -282,7 +282,7 @@ export default defineWorld({ schema: { signer: "address", nonce: "uint256" }, key: ["signer"], codegen: { - outputDirectory: "modules/delegation/tables", + outputDirectory: "modules/callwithsignature/tables", }, }, }, diff --git a/packages/world-modules/src/index.sol b/packages/world-modules/src/index.sol index 1d323d8fe4..5fa265ec1f 100644 --- a/packages/world-modules/src/index.sol +++ b/packages/world-modules/src/index.sol @@ -22,4 +22,4 @@ import { Owners } from "./modules/erc721-puppet/tables/Owners.sol"; import { TokenApproval } from "./modules/erc721-puppet/tables/TokenApproval.sol"; import { OperatorApproval } from "./modules/erc721-puppet/tables/OperatorApproval.sol"; import { ERC721Registry } from "./modules/erc721-puppet/tables/ERC721Registry.sol"; -import { CallWithSignatureNonces } from "./modules/delegation/tables/CallWithSignatureNonces.sol"; +import { CallWithSignatureNonces } from "./modules/callwithsignature/tables/CallWithSignatureNonces.sol"; diff --git a/packages/world-modules/src/modules/delegation/tables/CallWithSignatureNonces.sol b/packages/world-modules/src/modules/delegation/tables/CallWithSignatureNonces.sol new file mode 100644 index 0000000000..554b33df9f --- /dev/null +++ b/packages/world-modules/src/modules/delegation/tables/CallWithSignatureNonces.sol @@ -0,0 +1,199 @@ +// SPDX-License-Identifier: MIT +pragma solidity >=0.8.24; + +/* Autogenerated file. Do not edit manually. */ + +// Import store internals +import { IStore } from "@latticexyz/store/src/IStore.sol"; +import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; +import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; +import { Bytes } from "@latticexyz/store/src/Bytes.sol"; +import { Memory } from "@latticexyz/store/src/Memory.sol"; +import { SliceLib } from "@latticexyz/store/src/Slice.sol"; +import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; +import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; +import { Schema } from "@latticexyz/store/src/Schema.sol"; +import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; +import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; + +library CallWithSignatureNonces { + // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "CallWithSignatur", typeId: RESOURCE_TABLE });` + ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000043616c6c576974685369676e61747572); + + FieldLayout constant _fieldLayout = + FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); + + // Hex-encoded key schema of (address) + Schema constant _keySchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000); + // Hex-encoded value schema of (uint256) + Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000); + + /** + * @notice Get the table's key field names. + * @return keyNames An array of strings with the names of key fields. + */ + function getKeyNames() internal pure returns (string[] memory keyNames) { + keyNames = new string[](1); + keyNames[0] = "signer"; + } + + /** + * @notice Get the table's value field names. + * @return fieldNames An array of strings with the names of value fields. + */ + function getFieldNames() internal pure returns (string[] memory fieldNames) { + fieldNames = new string[](1); + fieldNames[0] = "nonce"; + } + + /** + * @notice Register the table with its config. + */ + function register() internal { + StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); + } + + /** + * @notice Register the table with its config. + */ + function _register() internal { + StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); + } + + /** + * @notice Get nonce. + */ + function getNonce(address signer) internal view returns (uint256 nonce) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(signer))); + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); + } + + /** + * @notice Get nonce. + */ + function _getNonce(address signer) internal view returns (uint256 nonce) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(signer))); + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); + } + + /** + * @notice Get nonce. + */ + function get(address signer) internal view returns (uint256 nonce) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(signer))); + + bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); + } + + /** + * @notice Get nonce. + */ + function _get(address signer) internal view returns (uint256 nonce) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(signer))); + + bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); + return (uint256(bytes32(_blob))); + } + + /** + * @notice Set nonce. + */ + function setNonce(address signer, uint256 nonce) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(signer))); + + StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((nonce)), _fieldLayout); + } + + /** + * @notice Set nonce. + */ + function _setNonce(address signer, uint256 nonce) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(signer))); + + StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((nonce)), _fieldLayout); + } + + /** + * @notice Set nonce. + */ + function set(address signer, uint256 nonce) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(signer))); + + StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((nonce)), _fieldLayout); + } + + /** + * @notice Set nonce. + */ + function _set(address signer, uint256 nonce) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(signer))); + + StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((nonce)), _fieldLayout); + } + + /** + * @notice Delete all data for given keys. + */ + function deleteRecord(address signer) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(signer))); + + StoreSwitch.deleteRecord(_tableId, _keyTuple); + } + + /** + * @notice Delete all data for given keys. + */ + function _deleteRecord(address signer) internal { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(signer))); + + StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); + } + + /** + * @notice Tightly pack static (fixed length) data using this table's schema. + * @return The static data, encoded into a sequence of bytes. + */ + function encodeStatic(uint256 nonce) internal pure returns (bytes memory) { + return abi.encodePacked(nonce); + } + + /** + * @notice Encode all of a record's fields. + * @return The static (fixed length) data, encoded into a sequence of bytes. + * @return The lengths of the dynamic fields (packed into a single bytes32 value). + * @return The dynamic (variable length) data, encoded into a sequence of bytes. + */ + function encode(uint256 nonce) internal pure returns (bytes memory, EncodedLengths, bytes memory) { + bytes memory _staticData = encodeStatic(nonce); + + EncodedLengths _encodedLengths; + bytes memory _dynamicData; + + return (_staticData, _encodedLengths, _dynamicData); + } + + /** + * @notice Encode keys as a bytes32 array using this table's field layout. + */ + function encodeKeyTuple(address signer) internal pure returns (bytes32[] memory) { + bytes32[] memory _keyTuple = new bytes32[](1); + _keyTuple[0] = bytes32(uint256(uint160(signer))); + + return _keyTuple; + } +} diff --git a/packages/world-modules/test/CallWithSignatureModule.t.sol b/packages/world-modules/test/CallWithSignatureModule.t.sol index bea67d359c..1d2b74a36f 100644 --- a/packages/world-modules/test/CallWithSignatureModule.t.sol +++ b/packages/world-modules/test/CallWithSignatureModule.t.sol @@ -19,11 +19,11 @@ import { REGISTRATION_SYSTEM_ID } from "@latticexyz/world/src/modules/init/const import { createWorld } from "@latticexyz/world/test/createWorld.sol"; import { WorldTestSystem } from "@latticexyz/world/test/World.t.sol"; -import { Unstable_CallWithSignatureModule } from "../src/modules/delegation/Unstable_CallWithSignatureModule.sol"; -import { Unstable_CallWithSignatureSystem } from "../src/modules/delegation/Unstable_CallWithSignatureSystem.sol"; -import { IUnstable_CallWithSignatureErrors } from "../src/modules/delegation/IUnstable_CallWithSignatureErrors.sol"; -import { getSignedMessageHash } from "../src/modules/delegation/getSignedMessageHash.sol"; -import { ECDSA } from "../src/modules/delegation/ECDSA.sol"; +import { Unstable_CallWithSignatureModule } from "../src/modules/callwithsignature/Unstable_CallWithSignatureModule.sol"; +import { Unstable_CallWithSignatureSystem } from "../src/modules/callwithsignature/Unstable_CallWithSignatureSystem.sol"; +import { IUnstable_CallWithSignatureErrors } from "../src/modules/callwithsignature/IUnstable_CallWithSignatureErrors.sol"; +import { getSignedMessageHash } from "../src/modules/callwithsignature/getSignedMessageHash.sol"; +import { ECDSA } from "../src/modules/callwithsignature/ECDSA.sol"; contract Unstable_CallWithSignatureModuleTest is Test, GasReporter { using WorldResourceIdInstance for ResourceId; From b1b9153261729fd05175c6891f2ceaf7c55e0a7c Mon Sep 17 00:00:00 2001 From: Kevin Ingersoll Date: Fri, 12 Apr 2024 19:20:17 +0100 Subject: [PATCH 8/8] remove old file --- .../tables/CallWithSignatureNonces.sol | 199 ------------------ 1 file changed, 199 deletions(-) delete mode 100644 packages/world-modules/src/modules/delegation/tables/CallWithSignatureNonces.sol diff --git a/packages/world-modules/src/modules/delegation/tables/CallWithSignatureNonces.sol b/packages/world-modules/src/modules/delegation/tables/CallWithSignatureNonces.sol deleted file mode 100644 index 554b33df9f..0000000000 --- a/packages/world-modules/src/modules/delegation/tables/CallWithSignatureNonces.sol +++ /dev/null @@ -1,199 +0,0 @@ -// SPDX-License-Identifier: MIT -pragma solidity >=0.8.24; - -/* Autogenerated file. Do not edit manually. */ - -// Import store internals -import { IStore } from "@latticexyz/store/src/IStore.sol"; -import { StoreSwitch } from "@latticexyz/store/src/StoreSwitch.sol"; -import { StoreCore } from "@latticexyz/store/src/StoreCore.sol"; -import { Bytes } from "@latticexyz/store/src/Bytes.sol"; -import { Memory } from "@latticexyz/store/src/Memory.sol"; -import { SliceLib } from "@latticexyz/store/src/Slice.sol"; -import { EncodeArray } from "@latticexyz/store/src/tightcoder/EncodeArray.sol"; -import { FieldLayout } from "@latticexyz/store/src/FieldLayout.sol"; -import { Schema } from "@latticexyz/store/src/Schema.sol"; -import { EncodedLengths, EncodedLengthsLib } from "@latticexyz/store/src/EncodedLengths.sol"; -import { ResourceId } from "@latticexyz/store/src/ResourceId.sol"; - -library CallWithSignatureNonces { - // Hex below is the result of `WorldResourceIdLib.encode({ namespace: "", name: "CallWithSignatur", typeId: RESOURCE_TABLE });` - ResourceId constant _tableId = ResourceId.wrap(0x7462000000000000000000000000000043616c6c576974685369676e61747572); - - FieldLayout constant _fieldLayout = - FieldLayout.wrap(0x0020010020000000000000000000000000000000000000000000000000000000); - - // Hex-encoded key schema of (address) - Schema constant _keySchema = Schema.wrap(0x0014010061000000000000000000000000000000000000000000000000000000); - // Hex-encoded value schema of (uint256) - Schema constant _valueSchema = Schema.wrap(0x002001001f000000000000000000000000000000000000000000000000000000); - - /** - * @notice Get the table's key field names. - * @return keyNames An array of strings with the names of key fields. - */ - function getKeyNames() internal pure returns (string[] memory keyNames) { - keyNames = new string[](1); - keyNames[0] = "signer"; - } - - /** - * @notice Get the table's value field names. - * @return fieldNames An array of strings with the names of value fields. - */ - function getFieldNames() internal pure returns (string[] memory fieldNames) { - fieldNames = new string[](1); - fieldNames[0] = "nonce"; - } - - /** - * @notice Register the table with its config. - */ - function register() internal { - StoreSwitch.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); - } - - /** - * @notice Register the table with its config. - */ - function _register() internal { - StoreCore.registerTable(_tableId, _fieldLayout, _keySchema, _valueSchema, getKeyNames(), getFieldNames()); - } - - /** - * @notice Get nonce. - */ - function getNonce(address signer) internal view returns (uint256 nonce) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(uint160(signer))); - - bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(bytes32(_blob))); - } - - /** - * @notice Get nonce. - */ - function _getNonce(address signer) internal view returns (uint256 nonce) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(uint160(signer))); - - bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(bytes32(_blob))); - } - - /** - * @notice Get nonce. - */ - function get(address signer) internal view returns (uint256 nonce) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(uint160(signer))); - - bytes32 _blob = StoreSwitch.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(bytes32(_blob))); - } - - /** - * @notice Get nonce. - */ - function _get(address signer) internal view returns (uint256 nonce) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(uint160(signer))); - - bytes32 _blob = StoreCore.getStaticField(_tableId, _keyTuple, 0, _fieldLayout); - return (uint256(bytes32(_blob))); - } - - /** - * @notice Set nonce. - */ - function setNonce(address signer, uint256 nonce) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(uint160(signer))); - - StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((nonce)), _fieldLayout); - } - - /** - * @notice Set nonce. - */ - function _setNonce(address signer, uint256 nonce) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(uint160(signer))); - - StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((nonce)), _fieldLayout); - } - - /** - * @notice Set nonce. - */ - function set(address signer, uint256 nonce) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(uint160(signer))); - - StoreSwitch.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((nonce)), _fieldLayout); - } - - /** - * @notice Set nonce. - */ - function _set(address signer, uint256 nonce) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(uint160(signer))); - - StoreCore.setStaticField(_tableId, _keyTuple, 0, abi.encodePacked((nonce)), _fieldLayout); - } - - /** - * @notice Delete all data for given keys. - */ - function deleteRecord(address signer) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(uint160(signer))); - - StoreSwitch.deleteRecord(_tableId, _keyTuple); - } - - /** - * @notice Delete all data for given keys. - */ - function _deleteRecord(address signer) internal { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(uint160(signer))); - - StoreCore.deleteRecord(_tableId, _keyTuple, _fieldLayout); - } - - /** - * @notice Tightly pack static (fixed length) data using this table's schema. - * @return The static data, encoded into a sequence of bytes. - */ - function encodeStatic(uint256 nonce) internal pure returns (bytes memory) { - return abi.encodePacked(nonce); - } - - /** - * @notice Encode all of a record's fields. - * @return The static (fixed length) data, encoded into a sequence of bytes. - * @return The lengths of the dynamic fields (packed into a single bytes32 value). - * @return The dynamic (variable length) data, encoded into a sequence of bytes. - */ - function encode(uint256 nonce) internal pure returns (bytes memory, EncodedLengths, bytes memory) { - bytes memory _staticData = encodeStatic(nonce); - - EncodedLengths _encodedLengths; - bytes memory _dynamicData; - - return (_staticData, _encodedLengths, _dynamicData); - } - - /** - * @notice Encode keys as a bytes32 array using this table's field layout. - */ - function encodeKeyTuple(address signer) internal pure returns (bytes32[] memory) { - bytes32[] memory _keyTuple = new bytes32[](1); - _keyTuple[0] = bytes32(uint256(uint160(signer))); - - return _keyTuple; - } -}