@t-rex-network/onchainid 0.0.0-stage → 3.0.0-beta2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/LICENSE.md +674 -0
  2. package/NOTICE.md +66 -0
  3. package/README.md +177 -2
  4. package/contracts/Identity.sol +235 -0
  5. package/contracts/IdentityUtilities.sol +269 -0
  6. package/contracts/KeyManager.sol +193 -0
  7. package/contracts/SmartAccount.sol +222 -0
  8. package/contracts/factory/IIdentityFactory.sol +325 -0
  9. package/contracts/factory/IdentityFactory.sol +818 -0
  10. package/contracts/interface/IClaimIssuer.sol +105 -0
  11. package/contracts/interface/IERC734.sol +69 -0
  12. package/contracts/interface/IERC735.sol +149 -0
  13. package/contracts/interface/IIdentity.sol +63 -0
  14. package/contracts/interface/IIdentityUtilities.sol +135 -0
  15. package/contracts/interface/IKeyExecutor.sol +84 -0
  16. package/contracts/libraries/Errors.sol +407 -0
  17. package/contracts/libraries/FormatResolver.sol +74 -0
  18. package/contracts/libraries/Hashing.sol +35 -0
  19. package/contracts/libraries/IdentityTypes.sol +53 -0
  20. package/contracts/libraries/KeyPurposes.sol +49 -0
  21. package/contracts/libraries/KeyTypes.sol +46 -0
  22. package/contracts/modules/claims/EASClaimIssuer.sol +348 -0
  23. package/contracts/modules/executors/KeyApprovalModule.sol +313 -0
  24. package/contracts/modules/executors/RecoveryModule.sol +88 -0
  25. package/contracts/modules/validators/ERC734Validator.sol +1000 -0
  26. package/contracts/modules/validators/ERC7579Validator.sol +74 -0
  27. package/contracts/proxy/IdentityUtilitiesProxy.sol +36 -0
  28. package/contracts/reputation/IReputationRegistry.sol +117 -0
  29. package/contracts/reputation/ReputationRegistry.sol +155 -0
  30. package/contracts/storage/Structs.sol +176 -0
  31. package/contracts/vendor/eas/IEAS.sol +36 -0
  32. package/contracts/vendor/utils/SafeCalldataBatch.sol +61 -0
  33. package/out/AbstractSigner.sol/AbstractSigner.json +1 -0
  34. package/out/AccessControlUpgradeable.sol/AccessControlUpgradeable.json +1 -0
  35. package/out/AccessManaged.sol/AccessManaged.json +1 -0
  36. package/out/AccessManager.sol/AccessManager.json +1 -0
  37. package/out/Account.sol/Account.json +1 -0
  38. package/out/AddClaimByTrustedIssuer.t.sol/AddClaimAsTrustedIssuerTest.json +1 -0
  39. package/out/Address.sol/Address.json +1 -0
  40. package/out/Arrays.sol/Arrays.json +1 -0
  41. package/out/AuthorityUtils.sol/AuthorityUtils.json +1 -0
  42. package/out/Base.sol/CommonBase.json +1 -0
  43. package/out/Base.sol/ScriptBase.json +1 -0
  44. package/out/Base.sol/TestBase.json +1 -0
  45. package/out/Base64.sol/Base64.json +1 -0
  46. package/out/BatchDecodeParity.t.sol/BatchDecodeParityTest.json +1 -0
  47. package/out/BeaconProxy.sol/BeaconProxy.json +1 -0
  48. package/out/Bytes.sol/Bytes.json +1 -0
  49. package/out/Calldata.sol/Calldata.json +1 -0
  50. package/out/ClaimSignatureDefinition.t.sol/ClaimSignatureDefinitionTest.json +1 -0
  51. package/out/ClaimSignatureDefinition.t.sol/NoERC1271Delegate.json +1 -0
  52. package/out/ClaimSignatureDefinition.t.sol/PickyERC1271Delegate.json +1 -0
  53. package/out/ClaimSignerHelper.sol/ClaimSignerHelper.json +1 -0
  54. package/out/ClaimTo.t.sol/ClaimToTest.json +1 -0
  55. package/out/Claims.t.sol/ClaimsTest.json +1 -0
  56. package/out/Claims.t.sol/ExternalIssuer.json +1 -0
  57. package/out/Comparators.sol/Comparators.json +1 -0
  58. package/out/Constants.sol/Constants.json +1 -0
  59. package/out/Context.sol/Context.json +1 -0
  60. package/out/ContextUpgradeable.sol/ContextUpgradeable.json +1 -0
  61. package/out/Create2.sol/Create2.json +1 -0
  62. package/out/Create3.sol/Create3.json +1 -0
  63. package/out/DeployOnchainID.s.sol/DeployOnchainID.json +1 -0
  64. package/out/EASClaimIssuer.sol/EASClaimIssuer.json +1 -0
  65. package/out/EASClaimIssuer.t.sol/EASClaimIssuerTest.json +1 -0
  66. package/out/EASClaimIssuer.t.sol/VmContractHelper29562166e1daff82a9ba4e08c324c14e885cfef135c42b5774ced18642e5fa19.json +1 -0
  67. package/out/EASTypes.sol/IEASTest.json +1 -0
  68. package/out/EASTypes.sol/ISchemaRegistryTest.json +1 -0
  69. package/out/ECDSA.sol/ECDSA.json +1 -0
  70. package/out/EIP712.sol/EIP712.json +1 -0
  71. package/out/ERC165.sol/ERC165.json +1 -0
  72. package/out/ERC165Upgradeable.sol/ERC165Upgradeable.json +1 -0
  73. package/out/ERC1967Proxy.sol/ERC1967Proxy.json +1 -0
  74. package/out/ERC1967Utils.sol/ERC1967Utils.json +1 -0
  75. package/out/ERC4337Utils.sol/ERC4337Utils.json +1 -0
  76. package/out/ERC4337Utils.sol/IEntryPointExtra.json +1 -0
  77. package/out/ERC734Validator.sol/ERC734Validator.json +1 -0
  78. package/out/ERC734Validator.t.sol/ERC734ValidatorTest.json +1 -0
  79. package/out/ERC734Validator.t.sol/PocCounter.json +1 -0
  80. package/out/ERC734Validator.t.sol/VmContractHelper7beb488c9b6c5f9f79178a8ce1e9ea8b7d447a9f1b366d4a3784214e9066b776.json +1 -0
  81. package/out/ERC7579DelayedExecutor.sol/ERC7579DelayedExecutor.json +1 -0
  82. package/out/ERC7579Executor.sol/ERC7579Executor.json +1 -0
  83. package/out/ERC7579Multisig.sol/ERC7579Multisig.json +1 -0
  84. package/out/ERC7579MultisigWeighted.sol/ERC7579MultisigWeighted.json +1 -0
  85. package/out/ERC7579SocialRecoveryExecutor.sol/ERC7579SocialRecoveryExecutor.json +1 -0
  86. package/out/ERC7579Validator.sol/ERC7579Validator.json +1 -0
  87. package/out/ERC7786Recipient.sol/ERC7786Recipient.json +1 -0
  88. package/out/ERC7913WebAuthnVerifier.sol/ERC7913WebAuthnVerifier.json +1 -0
  89. package/out/EnumerableSet.sol/EnumerableSet.json +1 -0
  90. package/out/Errors.sol/Errors.json +1 -0
  91. package/out/Executions.t.sol/ETHReceiver.json +1 -0
  92. package/out/Executions.t.sol/ExecutionsTest.json +1 -0
  93. package/out/Executions.t.sol/RevertingReceiver.json +1 -0
  94. package/out/FormatResolver.sol/FormatResolver.json +1 -0
  95. package/out/Hashes.sol/Hashes.json +1 -0
  96. package/out/IAccessControl.sol/IAccessControl.json +1 -0
  97. package/out/IAccessManaged.sol/IAccessManaged.json +1 -0
  98. package/out/IAccessManager.sol/IAccessManager.json +1 -0
  99. package/out/IAuthority.sol/IAuthority.json +1 -0
  100. package/out/IBeacon.sol/IBeacon.json +1 -0
  101. package/out/IClaimIssuer.sol/IClaimIssuer.json +1 -0
  102. package/out/IEAS.sol/IEAS.json +1 -0
  103. package/out/IERC1271.sol/IERC1271.json +1 -0
  104. package/out/IERC165.sol/IERC165.json +1 -0
  105. package/out/IERC1967.sol/IERC1967.json +1 -0
  106. package/out/IERC4337.sol/IAccount.json +1 -0
  107. package/out/IERC4337.sol/IAccountExecute.json +1 -0
  108. package/out/IERC4337.sol/IAggregator.json +1 -0
  109. package/out/IERC4337.sol/IEntryPoint.json +1 -0
  110. package/out/IERC4337.sol/IEntryPointNonces.json +1 -0
  111. package/out/IERC4337.sol/IEntryPointStake.json +1 -0
  112. package/out/IERC4337.sol/IPaymaster.json +1 -0
  113. package/out/IERC5267.sol/IERC5267.json +1 -0
  114. package/out/IERC734.sol/IERC734.json +1 -0
  115. package/out/IERC734Surface.t.sol/IERC734SurfaceTest.json +1 -0
  116. package/out/IERC735.sol/IERC735.json +1 -0
  117. package/out/IERC7913.sol/IERC7913SignatureVerifier.json +1 -0
  118. package/out/IIdentity.sol/IIdentity.json +1 -0
  119. package/out/IIdentityFactory.sol/IIdentityFactory.json +1 -0
  120. package/out/IIdentityUtilities.sol/IIdentityUtilities.json +1 -0
  121. package/out/IKeyExecutor.sol/IKeyExecutor.json +1 -0
  122. package/out/IMulticall3.sol/IMulticall3.json +1 -0
  123. package/out/IReputationRegistry.sol/IReputationRegistry.json +1 -0
  124. package/out/Identity.sol/Identity.json +1 -0
  125. package/out/IdentityFactory.sol/IdentityFactory.json +1 -0
  126. package/out/IdentityFactory.t.sol/IdentityFactoryTest.json +1 -0
  127. package/out/IdentityFactory.t.sol/VmContractHelper28a7b3ffc37fea8b5c41ecc8f253eb5ab470e21bb0401440d9a55fcb4f8afe5c.json +1 -0
  128. package/out/IdentityHelper.sol/IdentityHelper.json +1 -0
  129. package/out/IdentityHelper.sol/VmContractHelper78387a8fc41a64804f1f0fc2cbba310bbca11e4f057b06dfa169d4c103c08be5.json +1 -0
  130. package/out/IdentityTypes.sol/IdentityTypes.json +1 -0
  131. package/out/IdentityUtilities.sol/IdentityUtilities.json +1 -0
  132. package/out/IdentityUtilities.t.sol/IdentityUtilitiesTest.json +1 -0
  133. package/out/IdentityUtilities.t.sol/VmContractHelper7ed074704942d210565581d7e79e91a1d3425a5a7e758acb90866c42420e726c.json +1 -0
  134. package/out/IdentityUtilitiesProxy.sol/IdentityUtilitiesProxy.json +1 -0
  135. package/out/Init.t.sol/InitTest.json +1 -0
  136. package/out/Init.t.sol/VmContractHelper95bc81f417f4a3acb58eafba49b7834c5e65588c78654308ee428eb7d9276cce.json +1 -0
  137. package/out/Initializable.sol/Initializable.json +1 -0
  138. package/out/InteroperableAddressEncoding.t.sol/InteroperableAddressEncodingTest.json +1 -0
  139. package/out/KeyApprovalModule.sol/IIdentityAccount.json +1 -0
  140. package/out/KeyApprovalModule.sol/KeyApprovalModule.json +1 -0
  141. package/out/KeyApprovalModuleFactoryGuard.t.sol/KeyApprovalModuleFactoryGuardTest.json +1 -0
  142. package/out/KeyManager.sol/KeyManager.json +1 -0
  143. package/out/KeyPurposes.sol/KeyPurposes.json +1 -0
  144. package/out/KeyTypes.sol/KeyTypes.json +1 -0
  145. package/out/Keys.t.sol/KeysTest.json +1 -0
  146. package/out/LowLevelCall.sol/LowLevelCall.json +1 -0
  147. package/out/Math.sol/Math.json +1 -0
  148. package/out/MessageHashUtils.sol/MessageHashUtils.json +1 -0
  149. package/out/MockERC1271Signer.sol/MockERC1271Signer.json +1 -0
  150. package/out/MockERC1271Wallet.sol/MockERC1271Wallet.json +1 -0
  151. package/out/MockERC7786Gateway.sol/MockERC7786Gateway.json +1 -0
  152. package/out/MockERC7913PermissiveVerifier.sol/MockERC7913PermissiveVerifier.json +1 -0
  153. package/out/MockLyingERC734Getter.sol/MockLyingERC734Getter.json +1 -0
  154. package/out/MockStockECDSAValidator.sol/MockStockECDSAValidator.json +1 -0
  155. package/out/Multicall.sol/Multicall.json +1 -0
  156. package/out/Multisig.sol/Multisig.json +1 -0
  157. package/out/Nonces.sol/Nonces.json +1 -0
  158. package/out/OnchainIDSetup.sol/OnchainIDSetup.json +1 -0
  159. package/out/Ownable.sol/Ownable.json +1 -0
  160. package/out/P256.sol/P256.json +1 -0
  161. package/out/Packing.sol/Packing.json +1 -0
  162. package/out/Panic.sol/Panic.json +1 -0
  163. package/out/PrivilegedReentryGuard.t.sol/PocCounter.json +1 -0
  164. package/out/PrivilegedReentryGuard.t.sol/PrivilegedReentryGuardTest.json +1 -0
  165. package/out/Proxy.sol/Proxy.json +1 -0
  166. package/out/Proxy.t.sol/ProxyTest.json +1 -0
  167. package/out/Proxy.t.sol/VmContractHelper20ec29ce959b555228240226871c123d935ae49f617ce49540ee53c85f9f8cd4.json +1 -0
  168. package/out/ProxyPattern.t.sol/ProxyPatternTest.json +1 -0
  169. package/out/RecoveryModule.sol/RecoveryModule.json +1 -0
  170. package/out/RecoveryModule.t.sol/RecoveryModuleTest.json +1 -0
  171. package/out/RecoveryModule.t.sol/VmContractHelper84563bc19cefad0d2824def84f4cab79093d389b1866eff467a2908e14dd8421.json +1 -0
  172. package/out/ReputationRegistry.sol/ReputationRegistry.json +1 -0
  173. package/out/ReputationRegistry.t.sol/FakeIdentity.json +1 -0
  174. package/out/ReputationRegistry.t.sol/ReputationRegistryTest.json +1 -0
  175. package/out/ReputationRegistry.t.sol/VmContractHelper4353cedc5e63171396a0756138ec48ebba489252c7f4fef50b08f9e2c0989ec9.json +1 -0
  176. package/out/RevertingIdentity.sol/RevertingIdentity.json +1 -0
  177. package/out/SafeCalldataBatch.sol/SafeCalldataBatch.json +1 -0
  178. package/out/SafeCast.sol/SafeCast.json +1 -0
  179. package/out/Script.sol/Script.json +1 -0
  180. package/out/ShortStrings.sol/ShortStrings.json +1 -0
  181. package/out/SignatureChecker.sol/SignatureChecker.json +1 -0
  182. package/out/SignedMath.sol/SignedMath.json +1 -0
  183. package/out/SlotDerivation.sol/SlotDerivation.json +1 -0
  184. package/out/SmartAccount.sol/SmartAccount.json +1 -0
  185. package/out/SmartAccount.t.sol/AlwaysApprovePolicy.json +1 -0
  186. package/out/SmartAccount.t.sol/Counter.json +1 -0
  187. package/out/SmartAccount.t.sol/IAddKeyWithData.json +1 -0
  188. package/out/SmartAccount.t.sol/ReentrantUninstaller.json +1 -0
  189. package/out/SmartAccount.t.sol/SmartAccountTest.json +1 -0
  190. package/out/SmartAccount.t.sol/TestExecutor.json +1 -0
  191. package/out/StdAssertions.sol/StdAssertions.json +1 -0
  192. package/out/StdChains.sol/StdChains.json +1 -0
  193. package/out/StdCheats.sol/StdCheats.json +1 -0
  194. package/out/StdCheats.sol/StdCheatsSafe.json +1 -0
  195. package/out/StdConstants.sol/StdConstants.json +1 -0
  196. package/out/StdError.sol/stdError.json +1 -0
  197. package/out/StdInvariant.sol/StdInvariant.json +1 -0
  198. package/out/StdJson.sol/stdJson.json +1 -0
  199. package/out/StdMath.sol/stdMath.json +1 -0
  200. package/out/StdStorage.sol/stdStorage.json +1 -0
  201. package/out/StdStorage.sol/stdStorageSafe.json +1 -0
  202. package/out/StdStyle.sol/StdStyle.json +1 -0
  203. package/out/StdToml.sol/stdToml.json +1 -0
  204. package/out/StdUtils.sol/StdUtils.json +1 -0
  205. package/out/StorageSlot.sol/StorageSlot.json +1 -0
  206. package/out/Strings.sol/Strings.json +1 -0
  207. package/out/Structs.sol/Structs.json +1 -0
  208. package/out/Test.sol/Test.json +1 -0
  209. package/out/TestIdentityUtilities.sol/TestIdentityUtilities.json +1 -0
  210. package/out/Time.sol/Time.json +1 -0
  211. package/out/TokenOid.t.sol/TokenOidTest.json +1 -0
  212. package/out/UUPSUpgradeable.sol/UUPSUpgradeable.json +1 -0
  213. package/out/UnlockedIdentity.sol/UnlockedIdentity.json +1 -0
  214. package/out/UpgradeableBeacon.sol/UpgradeableBeacon.json +1 -0
  215. package/out/VersionUpgrade.t.sol/VersionUpgradeTest.json +1 -0
  216. package/out/Vm.sol/Vm.json +1 -0
  217. package/out/Vm.sol/VmSafe.json +1 -0
  218. package/out/WebAuthn.sol/WebAuthn.json +1 -0
  219. package/out/WebAuthn.t.sol/WebAuthnTest.json +1 -0
  220. package/out/build-info/1056f64abc9637ee.json +1 -0
  221. package/out/console.sol/console.json +1 -0
  222. package/out/draft-AccountERC7579Upgradeable.sol/AccountERC7579Upgradeable.json +1 -0
  223. package/out/draft-ERC7579Utils.sol/ERC7579Utils.json +1 -0
  224. package/out/draft-IERC1822.sol/IERC1822Proxiable.json +1 -0
  225. package/out/draft-IERC7579.sol/IERC7579AccountConfig.json +1 -0
  226. package/out/draft-IERC7579.sol/IERC7579Execution.json +1 -0
  227. package/out/draft-IERC7579.sol/IERC7579Hook.json +1 -0
  228. package/out/draft-IERC7579.sol/IERC7579Module.json +1 -0
  229. package/out/draft-IERC7579.sol/IERC7579ModuleConfig.json +1 -0
  230. package/out/draft-IERC7579.sol/IERC7579Validator.json +1 -0
  231. package/out/draft-IERC7786.sol/IERC7786GatewaySource.json +1 -0
  232. package/out/draft-IERC7786.sol/IERC7786Recipient.json +1 -0
  233. package/out/draft-InteroperableAddress.sol/InteroperableAddress.json +1 -0
  234. package/out/safeconsole.sol/safeconsole.json +1 -0
  235. package/out/src/Test.sol/Test.json +1 -0
  236. package/out/utils/Errors.sol/Errors.json +1 -0
  237. package/package.json +75 -4
@@ -0,0 +1,1000 @@
1
+ // SPDX-License-Identifier: GPL-3.0
2
+ //
3
+ // ONCHAINID Smart Contracts
4
+ // Digital identities for the T-REX ecosystem.
5
+ //
6
+ // Copyright (C) 2026 Digital Asset Operational Services ISAC Ltd. ("T-REX Network")
7
+ //
8
+ // This file is part of the ONCHAINID smart contract suite.
9
+ //
10
+ // This program is free software: you can redistribute it and/or modify
11
+ // it under the terms of the GNU General Public License as published by
12
+ // the Free Software Foundation, either version 3 of the License, or
13
+ // (at your option) any later version.
14
+ //
15
+ // This program is distributed in the hope that it will be useful,
16
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
17
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
+ // GNU General Public License for more details.
19
+ //
20
+ // You should have received a copy of the GNU General Public License
21
+ // along with this program. If not, see <https://www.gnu.org/licenses/>.
22
+
23
+ pragma solidity ^0.8.28;
24
+
25
+ import { ERC4337Utils } from "@openzeppelin/contracts/account/utils/ERC4337Utils.sol";
26
+ import { CallType, ERC7579Utils, Mode } from "@openzeppelin/contracts/account/utils/draft-ERC7579Utils.sol";
27
+ import { IERC1271 } from "@openzeppelin/contracts/interfaces/IERC1271.sol";
28
+ import { PackedUserOperation } from "@openzeppelin/contracts/interfaces/IERC4337.sol";
29
+ import { IERC5267 } from "@openzeppelin/contracts/interfaces/IERC5267.sol";
30
+ import { IERC7913SignatureVerifier } from "@openzeppelin/contracts/interfaces/IERC7913.sol";
31
+ import {
32
+ Execution,
33
+ IERC7579Execution,
34
+ MODULE_TYPE_EXECUTOR,
35
+ MODULE_TYPE_FALLBACK
36
+ } from "@openzeppelin/contracts/interfaces/draft-IERC7579.sol";
37
+ import { Bytes } from "@openzeppelin/contracts/utils/Bytes.sol";
38
+ import { ECDSA } from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
39
+ import { MessageHashUtils } from "@openzeppelin/contracts/utils/cryptography/MessageHashUtils.sol";
40
+ import { SignatureChecker } from "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
41
+ import { InteroperableAddress } from "@openzeppelin/contracts/utils/draft-InteroperableAddress.sol";
42
+ import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
43
+
44
+ import { IIdentityFactory } from "../../factory/IIdentityFactory.sol";
45
+ import { IClaimIssuer } from "../../interface/IClaimIssuer.sol";
46
+ import { IERC734 } from "../../interface/IERC734.sol";
47
+ import { IERC735 } from "../../interface/IERC735.sol";
48
+ import { IIdentity } from "../../interface/IIdentity.sol";
49
+ import { Errors } from "../../libraries/Errors.sol";
50
+ import { hashAddress } from "../../libraries/Hashing.sol";
51
+ import { IdentityTypes } from "../../libraries/IdentityTypes.sol";
52
+ import { KeyPurposes } from "../../libraries/KeyPurposes.sol";
53
+ import { KeyTypes } from "../../libraries/KeyTypes.sol";
54
+ import { IReputationRegistry } from "../../reputation/IReputationRegistry.sol";
55
+ import { Structs } from "../../storage/Structs.sol";
56
+ import { SafeCalldataBatch } from "../../vendor/utils/SafeCalldataBatch.sol";
57
+ import { ERC7579Validator } from "./ERC7579Validator.sol";
58
+
59
+ /// @title ERC734Validator
60
+ /// @notice One module holding both the ERC-734 key registry (keys + purposes) and the ERC-735
61
+ /// claim registry. It is installed as a validator (userOp signature verification), and as
62
+ /// a fallback handler for the ERC-734 getters and the ERC-735 claim selectors, so the key
63
+ /// registry and the claims share one contract and one storage area.
64
+ ///
65
+ /// The account calls `validateUserOp`; this module verifies the signature, checks the
66
+ /// signer is a registered key, and enforces the purpose the userOp needs.
67
+ ///
68
+ /// Constraint: the scoping rule guards this module's own address, but it does not know
69
+ /// about other privileged targets (installed executors, fallback handlers). A userOp from
70
+ /// an ACTION signer that calls `execute(installedExecutor, ...)` reads as an external
71
+ /// target here, so ACTION suffices; the call then reaches the executor with
72
+ /// `msg.sender == account`. Executor and fallback modules must gate their own callers
73
+ /// rather than trust that reaching them implies authorization.
74
+ ///
75
+ /// @dev userOp signature wire format: `abi.encode(bytes signer, bytes signature)`, where
76
+ /// `signer` is ERC-7913 (20 bytes = EOA/1271, longer = `verifier(20) || key`). Storage is
77
+ /// ERC-7201 namespaced.
78
+ contract ERC734Validator is ERC7579Validator, IERC735 {
79
+
80
+ using EnumerableSet for EnumerableSet.UintSet;
81
+ using EnumerableSet for EnumerableSet.Bytes32Set;
82
+
83
+ /// @dev Same shape as `Structs.Key`. `signerData` is the ERC-7913 verification material
84
+ /// (for WebAuthn, `verifier(20) || pubkey`), committed by `keyHash == keccak256(signerData)`.
85
+ /// `clientData` is non-cryptographic metadata (e.g. WebAuthn credentialId) kept per key.
86
+ /// `keyType` is ECDSA / RSA / WEBAUTHN / MODULE.
87
+ struct Key {
88
+ EnumerableSet.UintSet purposes;
89
+ uint256 keyType;
90
+ bytes signerData;
91
+ bytes clientData;
92
+ }
93
+
94
+ /// @dev ERC-734 key registry plus ERC-735 claim state, scoped to one account. `allKeys` is
95
+ /// the membership index backing `keyHasPurpose` and the getters. `byPurpose` enumerates
96
+ /// keys per purpose, with one exception: MODULE keys are kept out of the MANAGEMENT set
97
+ /// (see {_addKey}), so that set holds signer keys only. Module keys still appear under
98
+ /// every other purpose. `claims` / `claimsByTopic` / `revokedDigests` hold the claim
99
+ /// registry (see the claims section below).
100
+ struct AccountRegistry {
101
+ mapping(bytes32 keyHash => Key) keys;
102
+ mapping(uint256 purpose => EnumerableSet.Bytes32Set) byPurpose;
103
+ EnumerableSet.Bytes32Set allKeys;
104
+ mapping(bytes32 claimId => Structs.Claim) claims;
105
+ mapping(uint256 topic => EnumerableSet.Bytes32Set) claimsByTopic;
106
+ mapping(bytes32 digest => bool) revokedDigests;
107
+ }
108
+
109
+ /// @dev One registry per account. Singleton deployment shared across all installers.
110
+ /// @custom:storage-location erc7201:onchainid.validators.erc734-validator
111
+ struct ModuleStorage {
112
+ mapping(address account => AccountRegistry) registries;
113
+ }
114
+
115
+ /// @dev keccak256(abi.encode(uint256(keccak256("onchainid.validators.erc734-validator")) - 1)) & ~bytes32(uint256(0xff))
116
+ bytes32 private constant _MODULE_STORAGE_SLOT = keccak256(
117
+ abi.encode(uint256(keccak256(bytes("onchainid.validators.erc734-validator"))) - 1)
118
+ ) & ~bytes32(uint256(0xff));
119
+
120
+ error KeyAlreadyRegistered(bytes32 keyHash);
121
+ error KeyNotRegistered(bytes32 keyHash);
122
+ error InvalidSignerLength();
123
+ error CannotRemoveLastManagementKey();
124
+ /// @dev A registered key's `keyType` differs from the one supplied on re-purpose.
125
+ error KeyTypeMismatch(bytes32 keyHash);
126
+ /// @dev The purpose is outside the ERC-734 range 1..6.
127
+ error InvalidPurpose(uint256 purpose);
128
+ /// @dev The grantee is this module itself. See the guard in {_addKey}.
129
+ error ModuleCannotBeKey();
130
+
131
+ event KeyAdded(address indexed account, bytes32 indexed keyHash, uint256 indexed purpose, uint256 keyType);
132
+ event KeyRemoved(address indexed account, bytes32 indexed keyHash, uint256 indexed purpose);
133
+
134
+ /// @dev EIP-712 typehash for `Claim`. The nested `ClaimData` type is appended per the EIP-712
135
+ /// rule for nested struct types.
136
+ bytes32 internal constant _CLAIM_TYPEHASH = keccak256(
137
+ "Claim(uint256 topic,address subject,ClaimData data)"
138
+ "ClaimData(uint256 issuedAt,uint256 validUntil,Metadata metadata,bytes payload)"
139
+ "Metadata(uint256 scheme,string uri)"
140
+ );
141
+
142
+ /// @dev EIP-712 typehash for the nested `ClaimData` envelope.
143
+ bytes32 internal constant _CLAIM_DATA_TYPEHASH = keccak256(
144
+ "ClaimData(uint256 issuedAt,uint256 validUntil,Metadata metadata,bytes payload)"
145
+ "Metadata(uint256 scheme,string uri)"
146
+ );
147
+
148
+ /// @dev EIP-712 typehash for the nested `Metadata` struct. Signers see the actual scheme and
149
+ /// uri in their wallet instead of an opaque hash.
150
+ bytes32 internal constant _METADATA_TYPEHASH = keccak256("Metadata(uint256 scheme,string uri)");
151
+
152
+ /// @notice Emitted when a claim digest is marked revoked by the issuer. Holder-side removals
153
+ /// emit `ClaimRemoved` (from IERC735) instead.
154
+ event ClaimRevoked(bytes32 indexed digest, address indexed issuer);
155
+
156
+ /// @notice Emitted when `addClaimTo` successfully writes a claim to another identity.
157
+ event ClaimAddedTo(address indexed identity, uint256 topic, bytes signature, Structs.ClaimData data);
158
+
159
+ /// @notice Factory used by {addClaimByTrustedIssuer} to resolve a caller wallet to
160
+ /// its issuer identity and to confirm that identity came from the factory.
161
+ IIdentityFactory public immutable factory;
162
+
163
+ /// @notice Registry consulted by {addClaimByTrustedIssuer} to confirm the issuer
164
+ /// identity meets the global claim-add threshold.
165
+ IReputationRegistry public immutable reputationRegistry;
166
+
167
+ /// @param identityFactory Factory used to resolve a caller wallet to its issuer
168
+ /// identity in {addClaimByTrustedIssuer}. Reverts on zero.
169
+ /// @param registry Reputation registry consulted by {addClaimByTrustedIssuer}.
170
+ /// Reverts on zero.
171
+ constructor(address identityFactory, address registry) {
172
+ require(identityFactory != address(0), Errors.ZeroAddress());
173
+ require(registry != address(0), Errors.ZeroAddress());
174
+ factory = IIdentityFactory(identityFactory);
175
+ reputationRegistry = IReputationRegistry(registry);
176
+ }
177
+
178
+ // --- installation ----------------------------------------------------
179
+
180
+ /// @dev Seeds the registry with a single MANAGEMENT key from `data` (an ERC-7913 signer
181
+ /// blob). keyType is inferred by length; clientData is empty at install.
182
+ ///
183
+ /// The registry is durable on purpose. It is enshrined in the account implementation,
184
+ /// and {KeyManager} keeps reading it whether or not this module is installed, so an
185
+ /// install never wipes prior state: a reinstall resumes the existing registry (keys,
186
+ /// claims and revoked digests included), and stale keys are removed individually via
187
+ /// {removeKey}. The seed is idempotent so a reinstall may reuse the same signer.
188
+ function onInstall(bytes calldata data) public virtual {
189
+ // Empty data is an executor or fallback install (claims and the ERC-734 getters). There is
190
+ // no key to seed, so it is a no-op; the registry is seeded by the validator install below.
191
+ if (data.length == 0) return;
192
+
193
+ // Reinstall with a signer that already holds MANAGEMENT: nothing to seed.
194
+ if (_keyHasPurpose(msg.sender, keccak256(data), KeyPurposes.MANAGEMENT)) return;
195
+
196
+ // keyType is stored metadata only; _verify dispatches on the signer length, not on this.
197
+ // A 20-byte signer is an EOA (ECDSA=1). A longer one is a generic ERC-7913 verifier+key
198
+ // blob; we can't tell WebAuthn from RSA by length, so we label the common case, WEBAUTHN=3.
199
+ _addKey(msg.sender, data, "", KeyPurposes.MANAGEMENT, data.length == 20 ? 1 : 3);
200
+ }
201
+
202
+ /// @dev Works as a validator (userOp signatures), an executor (issuer claim flows), and a
203
+ /// fallback handler (the ERC-734 getters and ERC-735 claim selectors).
204
+ function isModuleType(uint256 moduleTypeId) public pure virtual override returns (bool) {
205
+ return super.isModuleType(moduleTypeId) || moduleTypeId == MODULE_TYPE_EXECUTOR
206
+ || moduleTypeId == MODULE_TYPE_FALLBACK;
207
+ }
208
+
209
+ /// @dev No-op by design: the registry is durable (see {onInstall}), and this hook can be
210
+ /// bypassed by a gas-starved `callNoReturn` anyway, so nothing may depend on it running.
211
+ /// Uninstalling leaves the keys in place, which is intended: the enshrined registry
212
+ /// keeps serving the account's ERC-734 reads whether or not this module is installed.
213
+ function onUninstall(
214
+ bytes calldata /* data */
215
+ )
216
+ public
217
+ virtual { }
218
+
219
+ // --- registry (called by the account on itself) ----------------------
220
+
221
+ /// @notice Register a key for the caller. Equivalent to `KeyManager.addKeyWithData`:
222
+ /// `keyHash` is `keccak256(signerData)`, and signerData/clientData are stored.
223
+ /// @param signerData ERC-7913 signer bytes.
224
+ /// @param clientData Non-cryptographic per-key metadata (e.g. WebAuthn credentialId).
225
+ /// @param purpose Purpose to grant.
226
+ /// @param keyType ECDSA / RSA / WEBAUTHN / MODULE.
227
+ function addKey(bytes calldata signerData, bytes calldata clientData, uint256 purpose, uint256 keyType) external {
228
+ _addKey(msg.sender, signerData, clientData, purpose, keyType);
229
+ }
230
+
231
+ /// @notice Remove a purpose from a key for the caller. The last MANAGEMENT key that can
232
+ /// sign cannot be removed. Deletes the record once its last purpose is gone.
233
+ /// @dev The MANAGEMENT index only holds signer keys (see {_addKey}), so its length is the
234
+ /// manager count. The guard is skipped for MODULE keys: they hold no signing
235
+ /// authority, so removing them can never strand the identity.
236
+ function removeKey(bytes32 keyHash, uint256 purpose) external {
237
+ AccountRegistry storage registry = _store().registries[msg.sender];
238
+ require(registry.allKeys.contains(keyHash), KeyNotRegistered(keyHash));
239
+ Key storage key = registry.keys[keyHash];
240
+
241
+ if (purpose == KeyPurposes.MANAGEMENT && key.keyType != KeyTypes.MODULE) {
242
+ require(registry.byPurpose[KeyPurposes.MANAGEMENT].length() > 1, CannotRemoveLastManagementKey());
243
+ }
244
+ // Revert if the key doesn't have this purpose.
245
+ require(key.purposes.remove(purpose), Errors.KeyDoesNotHavePurpose(keyHash, purpose));
246
+ registry.byPurpose[purpose].remove(keyHash);
247
+ if (key.purposes.length() == 0) {
248
+ delete registry.keys[keyHash];
249
+ registry.allKeys.remove(keyHash);
250
+ }
251
+
252
+ emit KeyRemoved(msg.sender, keyHash, purpose);
253
+ }
254
+
255
+ /// @notice `IERC734.keyHasPurpose`, scoped to `account`. MANAGEMENT satisfies any purpose.
256
+ function keyHasPurpose(address account, bytes32 keyHash, uint256 purpose) public view returns (bool) {
257
+ return _keyHasPurpose(account, keyHash, purpose);
258
+ }
259
+
260
+ /// @dev Shared implementation for both `keyHasPurpose` overloads. MANAGEMENT satisfies any purpose.
261
+ function _keyHasPurpose(address account, bytes32 keyHash, uint256 purpose) internal view returns (bool) {
262
+ AccountRegistry storage registry = _store().registries[account];
263
+ return registry.allKeys.contains(keyHash)
264
+ && (registry.keys[keyHash].purposes.contains(purpose)
265
+ || registry.keys[keyHash].purposes.contains(KeyPurposes.MANAGEMENT));
266
+ }
267
+
268
+ /// @notice Purposes held by `keyHash` on `account`. Returns the full set. Use the
269
+ /// `(account, keyHash, start, end)` overload for large sets.
270
+ function getKeyPurposes(address account, bytes32 keyHash) public view returns (uint256[] memory) {
271
+ return _getKeyPurposes(account, keyHash, 0, type(uint64).max);
272
+ }
273
+
274
+ /// @notice Paginated variant of {getKeyPurposes}. Returns purposes in the index range
275
+ /// `[start, end)`. `end` past the set size returns the available tail.
276
+ function getKeyPurposes(address account, bytes32 keyHash, uint256 start, uint256 end)
277
+ public
278
+ view
279
+ returns (uint256[] memory)
280
+ {
281
+ return _getKeyPurposes(account, keyHash, start, end);
282
+ }
283
+
284
+ /// @dev Shared implementation for every `getKeyPurposes` overload.
285
+ function _getKeyPurposes(address account, bytes32 keyHash, uint256 start, uint256 end)
286
+ internal
287
+ view
288
+ returns (uint256[] memory)
289
+ {
290
+ return _store().registries[account].keys[keyHash].purposes.values(start, end);
291
+ }
292
+
293
+ /// @notice Key hashes with `purpose` on `account`. Returns the full set. Use the
294
+ /// `(account, purpose, start, end)` overload for large sets. For MANAGEMENT the set
295
+ /// holds signer keys only; MODULE keys are left out (see {_addKey}). Use
296
+ /// {keyHasPurpose} to check a module key's authority.
297
+ function getKeysByPurpose(address account, uint256 purpose) public view returns (bytes32[] memory) {
298
+ return _getKeysByPurpose(account, purpose, 0, type(uint64).max);
299
+ }
300
+
301
+ /// @notice Paginated variant of {getKeysByPurpose}. Returns key hashes in the index range
302
+ /// `[start, end)`. `end` past the set size returns the available tail.
303
+ function getKeysByPurpose(address account, uint256 purpose, uint256 start, uint256 end)
304
+ public
305
+ view
306
+ returns (bytes32[] memory)
307
+ {
308
+ return _getKeysByPurpose(account, purpose, start, end);
309
+ }
310
+
311
+ /// @dev Shared implementation for every `getKeysByPurpose` overload.
312
+ function _getKeysByPurpose(address account, uint256 purpose, uint256 start, uint256 end)
313
+ internal
314
+ view
315
+ returns (bytes32[] memory)
316
+ {
317
+ return _store().registries[account].byPurpose[purpose].values(start, end);
318
+ }
319
+
320
+ /// @notice `KeyManager.getKeyData` for `account`: the signerData/clientData a key carries.
321
+ function getKeyData(address account, bytes32 keyHash)
322
+ external
323
+ view
324
+ returns (bytes memory signerData, bytes memory clientData)
325
+ {
326
+ Key storage key = _store().registries[account].keys[keyHash];
327
+ return (key.signerData, key.clientData);
328
+ }
329
+
330
+ /// @notice `IERC734.getKey` for `account`.
331
+ function getKey(address account, bytes32 keyHash)
332
+ public
333
+ view
334
+ returns (uint256[] memory purposes, uint256 keyType, bytes32 key)
335
+ {
336
+ Key storage stored = _store().registries[account].keys[keyHash];
337
+ return (stored.purposes.values(), stored.keyType, stored.signerData.length == 0 ? bytes32(0) : keyHash);
338
+ }
339
+
340
+ // --- ERC-734 getters, account taken from msg.sender ------------------
341
+ // The standard ERC-734 read functions, without the account argument. When this module is a
342
+ // fallback handler, msg.sender is the account, so each reuses the account-scoped version above.
343
+
344
+ /// @notice ERC-734 keyHasPurpose for the calling account.
345
+ function keyHasPurpose(bytes32 _key, uint256 _purpose) external view returns (bool) {
346
+ return _keyHasPurpose(msg.sender, _key, _purpose);
347
+ }
348
+
349
+ /// @notice ERC-734 getKeyPurposes for the calling account. Returns the full set. Use the
350
+ /// `(_key, start, end)` overload for large sets.
351
+ function getKeyPurposes(bytes32 _key) external view returns (uint256[] memory) {
352
+ return _getKeyPurposes(msg.sender, _key, 0, type(uint64).max);
353
+ }
354
+
355
+ /// @notice Paginated variant of {getKeyPurposes} for the calling account.
356
+ function getKeyPurposes(bytes32 _key, uint256 start, uint256 end) external view returns (uint256[] memory) {
357
+ return _getKeyPurposes(msg.sender, _key, start, end);
358
+ }
359
+
360
+ /// @notice ERC-734 getKeysByPurpose for the calling account. Returns the full set. Use the
361
+ /// `(_purpose, start, end)` overload for large sets. For MANAGEMENT the set holds
362
+ /// signer keys only; MODULE keys are left out (see {_addKey}).
363
+ function getKeysByPurpose(uint256 _purpose) external view returns (bytes32[] memory) {
364
+ return _getKeysByPurpose(msg.sender, _purpose, 0, type(uint64).max);
365
+ }
366
+
367
+ /// @notice Paginated variant of {getKeysByPurpose} for the calling account.
368
+ function getKeysByPurpose(uint256 _purpose, uint256 start, uint256 end) external view returns (bytes32[] memory) {
369
+ return _getKeysByPurpose(msg.sender, _purpose, start, end);
370
+ }
371
+
372
+ /// @notice ERC-734 getKey for the calling account.
373
+ function getKey(bytes32 _key) external view returns (uint256[] memory purposes, uint256 keyType, bytes32 key) {
374
+ return getKey(msg.sender, _key);
375
+ }
376
+
377
+ // --- validation ------------------------------------------------------
378
+
379
+ /// @dev Verifies the signer is a registered key on `account`, then that it signed `hash`.
380
+ /// Membership is checked first so an unknown key skips signature verification. The 1271
381
+ /// path stops here; userOps also run scoping in {_validateUserOp}.
382
+ function _rawERC7579Validation(address account, bytes32 hash, bytes calldata moduleSignature)
383
+ internal
384
+ view
385
+ virtual
386
+ override
387
+ returns (bool)
388
+ {
389
+ (bytes memory signer, bytes memory signature) = abi.decode(moduleSignature, (bytes, bytes));
390
+ bytes32 keyHash = keccak256(signer);
391
+ AccountRegistry storage registry = _store().registries[account];
392
+
393
+ // The signer must be a registered key (a too-short signer can't be in `allKeys`), and it
394
+ // must not be a MODULE key: those belong to installed modules (like KAM) and only gate what
395
+ // a module can do, so they must never sign a user op or a 1271 signature. Then verify.
396
+ return registry.allKeys.contains(keyHash) && registry.keys[keyHash].keyType != KeyTypes.MODULE
397
+ && _verify(signer, hash, signature);
398
+ }
399
+
400
+ /// @dev ERC-1271. Only a key that can act for the account may sign as the account. We require
401
+ /// ACTION, which MANAGEMENT also satisfies. Claim, encryption and proposer keys are
402
+ /// registered but hold no signing authority, so they are rejected here. The crypto and
403
+ /// membership check itself is left to super via {_rawERC7579Validation}.
404
+ function isValidSignatureWithSender(address sender, bytes32 hash, bytes calldata signature)
405
+ public
406
+ view
407
+ virtual
408
+ override
409
+ returns (bytes4)
410
+ {
411
+ (bytes memory signer,) = abi.decode(signature, (bytes, bytes));
412
+ if (!_keyHasPurpose(msg.sender, keccak256(signer), KeyPurposes.ACTION)) return bytes4(0xffffffff);
413
+ return super.isValidSignatureWithSender(sender, hash, signature);
414
+ }
415
+
416
+ /// @dev Adds per-target scoping on top of crypto + membership. The account routes
417
+ /// `validateUserOp` here through the base contract.
418
+ function _validateUserOp(PackedUserOperation calldata userOp, bytes32 userOpHash)
419
+ internal
420
+ virtual
421
+ override
422
+ returns (uint256)
423
+ {
424
+ // Super does the crypto + membership check; we add the per-target scoping on top.
425
+ // Keep super's return value: it may pack an aggregator or time bounds, not just success.
426
+ uint256 validationData = super._validateUserOp(userOp, userOpHash);
427
+ if (validationData == ERC4337Utils.SIG_VALIDATION_FAILED) {
428
+ return ERC4337Utils.SIG_VALIDATION_FAILED;
429
+ }
430
+
431
+ (bytes memory signer,) = abi.decode(userOp.signature, (bytes, bytes));
432
+ if (!_scopeAllows(userOp.sender, keccak256(signer), userOp.callData)) {
433
+ return ERC4337Utils.SIG_VALIDATION_FAILED;
434
+ }
435
+
436
+ return validationData;
437
+ }
438
+
439
+ // --- internal --------------------------------------------------------
440
+
441
+ /// @dev Whether the signer may run this userOp. Decodes `execute(mode, executionCalldata)`,
442
+ /// then applies {_targetAllowed} to the single call or to every call in a batch. Only
443
+ /// the standard `execute(bytes32,bytes)` selector is accepted; unknown call types fail.
444
+ function _scopeAllows(address account, bytes32 keyHash, bytes calldata callData) internal view returns (bool) {
445
+ // MANAGEMENT passes everything.
446
+ if (_keyHasPurpose(account, keyHash, KeyPurposes.MANAGEMENT)) return true;
447
+
448
+ // Short calldata zero-pads and can't match the execute selector.
449
+ if (bytes4(callData) != IERC7579Execution.execute.selector) return false;
450
+
451
+ (Mode mode, bytes calldata executionCalldata) = _decodeExecute(callData);
452
+ (CallType callType,,,) = ERC7579Utils.decodeMode(mode);
453
+
454
+ if (callType == ERC7579Utils.CALLTYPE_SINGLE) {
455
+ // A single execution is at least 52 bytes (20 target + 32 value).
456
+ if (executionCalldata.length < 52) return false;
457
+ (address target,,) = ERC7579Utils.decodeSingle(executionCalldata);
458
+ return _targetAllowed(account, keyHash, target);
459
+ }
460
+
461
+ if (callType == ERC7579Utils.CALLTYPE_BATCH) {
462
+ // Every call in the batch must pass. {SafeCalldataBatch} keeps the batch in calldata but
463
+ // validates each entry against the slice bounds, so a backward offset can't point past
464
+ // the batch and make us read a different target than the account runs. The account
465
+ // decodes the same way, so the two checks always agree.
466
+ Execution[] calldata batch = SafeCalldataBatch.decodeBatch(executionCalldata);
467
+ for (uint256 i = 0; i < batch.length; i++) {
468
+ if (!_targetAllowed(account, keyHash, batch[i].target)) return false;
469
+ }
470
+ return true;
471
+ }
472
+
473
+ return false;
474
+ }
475
+
476
+ /// @dev Purpose required for one (target, inner-call) pair. MANAGEMENT already short-circuited
477
+ /// in {_scopeAllows}, so this only decides the sub-MANAGEMENT cases:
478
+ /// target == this module -> MANAGEMENT only (self-guard, see below)
479
+ /// self + addClaim -> CLAIM_SIGNER or CLAIM_ADDER (read on the account)
480
+ /// self + removeClaim -> CLAIM_SIGNER (read on the account)
481
+ /// self, anything else -> MANAGEMENT only
482
+ /// external target -> ACTION
483
+ /// Claim purposes are read from this module's per-account registry (the same storage that
484
+ /// holds the keys), so the check works the same for any identity, including cross-identity
485
+ /// claim issuers.
486
+ function _targetAllowed(address account, bytes32 keyHash, address target) private view returns (bool) {
487
+ if (target == address(0)) target = account; // OZ aliases target 0 to self.
488
+
489
+ // Self-guard: a call to this validator can rotate its own registry (addKey, etc.).
490
+ // Only MANAGEMENT may do that, and MANAGEMENT already passed in _scopeAllows, so any
491
+ // non-MANAGEMENT signer reaching here must be rejected. Without this, an ACTION signer
492
+ // could execute(validator, addKey(attacker, MANAGEMENT)), an external target where ACTION
493
+ // suffices, and escalate itself.
494
+ if (target == address(this)) return false;
495
+
496
+ // Factory-guard: the factory's wallet-binding calls (linkAccount, revokeAccount,
497
+ // settlePendingCrossChainLink) change the identity's own bindings and are management-grade.
498
+ // The factory is an external target, so without this an ACTION key could, for example,
499
+ // terminally revoke one of the identity's wallets. MANAGEMENT already passed, so reject.
500
+ if (target == address(factory)) return false;
501
+
502
+ // An external target needs ACTION. A self-targeted call (addKey, addClaim, etc.) needs
503
+ // MANAGEMENT, which already passed in _scopeAllows, so a non-MANAGEMENT signer is rejected.
504
+ // Claims are not addable through a user op: the account calls itself, so the ERC-2771 caller
505
+ // seen by addClaim is the account, which holds no claim key. Claim keys add claims by
506
+ // calling the identity directly, not through execute().
507
+ if (target != account) return keyHasPurpose(account, keyHash, KeyPurposes.ACTION);
508
+ return false;
509
+ }
510
+
511
+ /// @dev Splits `execute(bytes32 mode, bytes executionCalldata)` calldata into its two args,
512
+ /// keeping `executionCalldata` as a calldata slice.
513
+ function _decodeExecute(bytes calldata callData)
514
+ private
515
+ pure
516
+ returns (Mode mode, bytes calldata executionCalldata)
517
+ {
518
+ // Hand-rolled so `executionCalldata` stays a calldata slice (decodeSingle/decodeBatch below
519
+ // need calldata); `abi.decode` would return memory. Reads the ABI head the same way the
520
+ // decoder does: mode, then the offset/length of the bytes arg. Callers guard the length.
521
+ mode = Mode.wrap(bytes32(callData[4:36]));
522
+ uint256 dataOffset = uint256(bytes32(callData[36:68]));
523
+ uint256 lenPos = 4 + dataOffset;
524
+ uint256 dataLen = uint256(bytes32(callData[lenPos:lenPos + 32]));
525
+ uint256 dataStart = lenPos + 32;
526
+ executionCalldata = callData[dataStart:dataStart + dataLen];
527
+ }
528
+
529
+ /// @dev ERC-7913 dispatch: 20-byte signer = EOA/1271, longer = verifier+key. Uses the
530
+ /// ECDSA path directly instead of `SignatureChecker.isValidSignatureNow(bytes,...)` to
531
+ /// avoid its `signer.code.length` check, which violates ERC-7562 bundler validation rules.
532
+ /// That only helps the EOA fast path: a contract signer still falls through to the
533
+ /// ERC-1271 external call below, so ERC-1271 signers do incur an external call during
534
+ /// user-op validation.
535
+ /// Single definition of a valid signature for the whole module: the key path and the claim
536
+ /// path both go through here, so a signer that gains code (EIP-7702) can't be judged valid
537
+ /// by one and invalid by the other.
538
+ function _verify(bytes memory signer, bytes32 hash, bytes memory signature) internal view returns (bool) {
539
+ if (signer.length == 20) {
540
+ address signerAddr = address(bytes20(signer));
541
+ // Try ECDSA first: the common EOA case resolves with no external call at all.
542
+ // A contract signer, whose sig isn't a valid ECDSA sig, falls through to 1271,
543
+ // which does staticcall the signer — the no-external-call property is EOA-only.
544
+ (address recovered, ECDSA.RecoverError err,) = ECDSA.tryRecover(hash, signature);
545
+ if (err == ECDSA.RecoverError.NoError && recovered == signerAddr) return true;
546
+ return SignatureChecker.isValidERC1271SignatureNow(signerAddr, hash, signature);
547
+ }
548
+ address verifier = address(bytes20(Bytes.slice(signer, 0, 20)));
549
+ bytes memory key = Bytes.slice(signer, 20);
550
+ // Raw staticcall on purpose. A high-level call would revert on a codeless verifier in
551
+ // THIS frame (outside any try/catch), and guarding that with an explicit code check
552
+ // would put an EXTCODESIZE in the 4337 validation path, which strict ERC-7562 bundler
553
+ // rules frown on. Here a codeless verifier just returns no data and fails the length
554
+ // check. Only registered signers reach this call: membership is checked first, so an
555
+ // arbitrary user op cannot even execute it with an unregistered verifier.
556
+ (bool success, bytes memory result) =
557
+ verifier.staticcall(abi.encodeCall(IERC7913SignatureVerifier.verify, (key, hash, signature)));
558
+ // The length check is required: nothing here ABI-decodes the returndata, and
559
+ // bytes-to-bytes32 pads on the RIGHT, so a verifier returning the 4 raw magic bytes
560
+ // would otherwise pass the compare. Verifiers must ABI-encode their bytes4 return.
561
+ return success && result.length >= 32 && bytes32(result) == bytes32(IERC7913SignatureVerifier.verify.selector);
562
+ }
563
+
564
+ function _addKey(
565
+ address account,
566
+ bytes memory signerData,
567
+ bytes memory clientData,
568
+ uint256 purpose,
569
+ uint256 keyType
570
+ ) internal {
571
+ // An ERC-7913 signer is at least 20 bytes (a 20-byte EOA/1271 address, or verifier+key).
572
+ // Checked here so every caller (onInstall, addKey) is covered by a single guard.
573
+ require(signerData.length >= 20 && signerData.length <= Structs.MAX_SIGNER_DATA_LENGTH, InvalidSignerLength());
574
+ require(clientData.length <= Structs.MAX_CLIENT_DATA_LENGTH, Errors.ClientDataTooLong());
575
+
576
+ // The module owns every ERC-734 purpose (1..6). Reject anything out of range.
577
+ require(_isValidPurpose(purpose), InvalidPurpose(purpose));
578
+
579
+ // keyHash is derived from signerData, so the record always commits to its own bytes.
580
+ bytes32 keyHash = keccak256(signerData);
581
+
582
+ // This module is one shared singleton, and addClaim treats its own address as "the call
583
+ // came from addClaimTo". A key granted to the module itself would act as a claim key for
584
+ // every issuer at once, so reject it here instead of trusting admins to never grant one.
585
+ // This also makes initialize revert if this module is installed with a non-zero purpose.
586
+ require(keyHash != hashAddress(address(this)), ModuleCannotBeKey());
587
+ AccountRegistry storage registry = _store().registries[account];
588
+ Key storage key = registry.keys[keyHash];
589
+
590
+ if (registry.allKeys.add(keyHash)) {
591
+ key.signerData = signerData;
592
+ key.clientData = clientData;
593
+ key.keyType = keyType;
594
+ } else {
595
+ // Re-purposing an existing key: keep the stored type, reject a mismatch.
596
+ require(key.keyType == keyType, KeyTypeMismatch(keyHash));
597
+ }
598
+
599
+ require(key.purposes.add(purpose), KeyAlreadyRegistered(keyHash));
600
+ // Module keys never enter the MANAGEMENT index. They cannot sign (the validator
601
+ // rejects MODULE keys), so they must not count as managers. The last-manager guard
602
+ // in removeKey and the factory's post-deploy check both rely on this index.
603
+ // keyHasPurpose reads the key's own purpose set, so module authority is unchanged.
604
+ // MANAGEMENT is the only purpose treated this way: its enumeration gates last-key
605
+ // removal. Module keys still index under every other purpose.
606
+ if (purpose != KeyPurposes.MANAGEMENT || key.keyType != KeyTypes.MODULE) {
607
+ registry.byPurpose[purpose].add(keyHash);
608
+ }
609
+ emit KeyAdded(account, keyHash, purpose, keyType);
610
+ }
611
+
612
+ /// @dev The six ERC-734 purposes this module holds (1..6).
613
+ function _isValidPurpose(uint256 purpose) private pure returns (bool) {
614
+ return purpose >= KeyPurposes.MANAGEMENT && purpose <= KeyPurposes.PROPOSER;
615
+ }
616
+
617
+ // --- ERC-735 claims --------------------------------------------------
618
+ // The claim registry, folded into this module so keys and claims share one contract. Claim
619
+ // state lives per account in the same registry as the keys. Reached via the account's fallback,
620
+ // so msg.sender is the identity and _msgSender() is the off-chain caller (ERC-2771 tail).
621
+ //
622
+ // So the key holder has to call these directly. If the call arrives any other way, for example
623
+ // relayed by the EntryPoint or dispatched by the account itself through an executor, nothing is
624
+ // appended, the recovered caller holds no claim key, and the call is refused. These entry
625
+ // points cannot be used through a meta-transaction.
626
+
627
+ /// @inheritdoc IERC735
628
+ function addClaim(
629
+ uint256 _topic,
630
+ uint256 _scheme,
631
+ address _issuer,
632
+ bytes memory _signature,
633
+ Structs.ClaimData memory _data,
634
+ string memory _uri
635
+ ) public returns (bytes32 claimRequestId) {
636
+ // CLAIM_SIGNER or CLAIM_ADDER can add a claim. Self-issued claims still need a real
637
+ // signature (checked by isClaimValid in _addClaim), so CLAIM_ADDER cannot fake
638
+ // self-attestations.
639
+ address caller = _msgSender();
640
+ // If the caller is this module itself, the call came from {addClaimTo}: the module made
641
+ // the outbound call, so the target's fallback appended the module's own address as the
642
+ // ERC-2771 caller. addClaimTo already checked that a MANAGEMENT key of `_issuer` started
643
+ // the flow and that a CLAIM_SIGNER of `_issuer` signed the claim, so the claim-key check
644
+ // below runs against `_issuer` instead.
645
+ //
646
+ // {addClaimTo} is the only path that can produce this caller. The other candidates are
647
+ // closed: `execute(module, ...)` is blocked by the account's own-module guard
648
+ // (Errors.OwnModuleTargetBlocked in SmartAccount), a direct call to the module with a
649
+ // forged calldata tail only reaches the caller's own registry entry (msg.sender selects
650
+ // the registry), and every other outbound call this module makes is a staticcall. As a
651
+ // last line of defense, {_addKey} rejects the module's own address as a grantee. A new
652
+ // state-changing outbound call added to this module must revisit this rebind.
653
+ if (caller == address(this)) caller = _issuer;
654
+ _requireClaimKey(msg.sender, caller, false);
655
+ return _addClaim(msg.sender, _topic, _scheme, _issuer, _signature, _data, _uri);
656
+ }
657
+
658
+ /// @notice Add a claim without holding a CLAIM_ADDER / CLAIM_SIGNER key on the target
659
+ /// identity, by proving the caller is a trusted issuer in the {ReputationRegistry}.
660
+ ///
661
+ /// Trust check (see {_requireTrustedIssuer}):
662
+ /// 1. The caller's wallet resolves through the factory to a non-zero issuer
663
+ /// identity (i.e. the wallet is a linked account on a factory-deployed
664
+ /// identity).
665
+ /// 2. `_issuer` equals that resolved identity. A trusted issuer cannot ship a
666
+ /// claim attributed to a different issuer.
667
+ /// 3. The identity self-declares type CLAIM_ISSUER.
668
+ /// 4. The issuer's score in the registry meets the global claim-add threshold.
669
+ ///
670
+ /// When all four hold the rest of the flow is identical to {addClaim}: the issuer's
671
+ /// `isClaimValid` confirms the signature, the storage write happens, and
672
+ /// `ClaimAdded` / `ClaimChanged` fires. Removal is not exposed via this path.
673
+ function addClaimByTrustedIssuer(
674
+ uint256 _topic,
675
+ uint256 _scheme,
676
+ address _issuer,
677
+ bytes memory _signature,
678
+ Structs.ClaimData memory _data,
679
+ string memory _uri
680
+ ) public returns (bytes32 claimRequestId) {
681
+ _requireTrustedIssuer(_msgSender(), _issuer);
682
+ return _addClaim(msg.sender, _topic, _scheme, _issuer, _signature, _data, _uri);
683
+ }
684
+
685
+ /// @dev Shared write path for `addClaim` and `addClaimByTrustedIssuer`. The issuer-side
686
+ /// `isClaimValid` is called unconditionally; the storage write and event match the
687
+ /// standard `addClaim` body. Claim id is (issuer, topic); re-adding overwrites.
688
+ function _addClaim(
689
+ address account,
690
+ uint256 topic,
691
+ uint256 scheme,
692
+ address issuer,
693
+ bytes memory signature,
694
+ Structs.ClaimData memory data,
695
+ string memory uri
696
+ ) internal returns (bytes32 claimId) {
697
+ // removeClaim reads a claim's topic and treats 0 as "no such claim". So a claim stored
698
+ // under topic 0 could never be removed. Reject it up front.
699
+ require(topic != 0, Errors.InvalidClaimTopic());
700
+ require(signature.length <= Structs.MAX_CLAIM_SIGNATURE_LENGTH, Errors.ClaimSignatureTooLong());
701
+ require(data.payload.length <= Structs.MAX_CLAIM_PAYLOAD_LENGTH, Errors.ClaimPayloadTooLong());
702
+ require(bytes(uri).length <= Structs.MAX_CLAIM_URI_LENGTH, Errors.ClaimUriTooLong());
703
+
704
+ // scheme and uri are signed through data.metadataHash, so a replayed signature
705
+ // cannot repoint the claim.
706
+ require(data.metadataHash == getMetadataHash(scheme, uri), Errors.ClaimMetadataMismatch(scheme, uri));
707
+
708
+ require(IClaimIssuer(issuer).isClaimValid(IIdentity(account), topic, signature, data), Errors.InvalidClaim());
709
+
710
+ AccountRegistry storage s = _store().registries[account];
711
+ claimId = keccak256(abi.encode(issuer, topic));
712
+
713
+ s.claims[claimId] =
714
+ Structs.Claim({ topic: topic, scheme: scheme, issuer: issuer, signature: signature, data: data, uri: uri });
715
+
716
+ if (s.claimsByTopic[topic].add(claimId)) {
717
+ emit ClaimAdded(account, claimId, topic, scheme, issuer, signature, data, uri);
718
+ } else {
719
+ emit ClaimChanged(account, claimId, topic, scheme, issuer, signature, data, uri);
720
+ }
721
+ }
722
+
723
+ /// @dev Trusted-issuer gate. Four conditions, all required:
724
+ /// 1. The caller wallet resolves through the factory to a non-zero issuer identity
725
+ /// (i.e. it is a linked account on a factory-deployed identity).
726
+ /// 2. That identity equals the claim's declared issuer (issuer-bound rule).
727
+ /// 3. That identity self-declares type `CLAIM_ISSUER`. Without this, any identity
728
+ /// that happens to be scored above the threshold (e.g. an INDIVIDUAL elevated by
729
+ /// the manager) could write claims silently.
730
+ /// 4. Its reputation in the registry meets the global claim-add threshold.
731
+ /// `reputationOf` already returns `0` for non-factory identities, so the score check
732
+ /// implicitly re-confirms factory membership.
733
+ function _requireTrustedIssuer(address caller, address expectedIssuer) internal view {
734
+ address callerIdentity = factory.getIdentity(InteroperableAddress.formatEvmV1(block.chainid, caller));
735
+ require(callerIdentity != address(0), Errors.CallerNotLinkedToFactoryIdentity(caller));
736
+ require(expectedIssuer == callerIdentity, Errors.DeclaredIssuerMismatch(expectedIssuer, callerIdentity));
737
+ require(
738
+ IIdentity(callerIdentity).getIdentityType() == IdentityTypes.CLAIM_ISSUER,
739
+ Errors.IdentityNotClaimIssuerType(callerIdentity)
740
+ );
741
+ IReputationRegistry registry = reputationRegistry;
742
+ uint128 score = registry.reputationOf(callerIdentity);
743
+ uint128 threshold = registry.claimAddThreshold();
744
+ require(score >= threshold, Errors.ReputationBelowClaimAddThreshold(callerIdentity, score, threshold));
745
+ }
746
+
747
+ /// @inheritdoc IERC735
748
+ /// @dev Marks the removed claim's digest revoked. Issuers backed by this module then refuse
749
+ /// the same (issuer, topic, ClaimData) and must sign a fresh claim to re-attest.
750
+ function removeClaim(bytes32 _claimId) public returns (bool success) {
751
+ address account = msg.sender;
752
+ // CLAIM_ADDER cannot remove; only CLAIM_SIGNER (or self-call) is accepted here.
753
+ _requireClaimKey(account, _msgSender(), true);
754
+
755
+ AccountRegistry storage s = _store().registries[account];
756
+ Structs.Claim storage c = s.claims[_claimId];
757
+ uint256 topic = c.topic;
758
+ require(topic != 0, Errors.ClaimNotRegistered(_claimId));
759
+
760
+ // Revoke the digest on both the holder's and the issuer's sets so _getClaimStatus (which
761
+ // reads the issuer's set) blocks re-adding the same bytes. Marking an already marked
762
+ // digest is fine: an outside issuer can accept the same claim again, and that one still
763
+ // has to be removable. The topic check above already rejects a double removal. A zero
764
+ // digest means the issuer has no EIP-712 domain, so there is nothing to revoke here and
765
+ // removal still proceeds; those issuers keep their own revocation source, see
766
+ // EASClaimIssuer, which reads EAS live.
767
+ bytes32 digest = _getClaimDigest(c.issuer, account, topic, c.data);
768
+ if (digest != bytes32(0)) {
769
+ s.revokedDigests[digest] = true;
770
+ _store().registries[c.issuer].revokedDigests[digest] = true;
771
+ }
772
+
773
+ s.claimsByTopic[topic].remove(_claimId);
774
+ emit ClaimRemoved(account, _claimId, topic, c.scheme, c.issuer, c.signature, c.data, c.uri);
775
+ delete s.claims[_claimId];
776
+
777
+ return true;
778
+ }
779
+
780
+ /// @inheritdoc IERC735
781
+ function getClaim(bytes32 _claimId)
782
+ public
783
+ view
784
+ returns (
785
+ uint256 topic,
786
+ uint256 scheme,
787
+ address issuer,
788
+ bytes memory signature,
789
+ Structs.ClaimData memory data,
790
+ string memory uri
791
+ )
792
+ {
793
+ Structs.Claim storage claim = _store().registries[msg.sender].claims[_claimId];
794
+ return (claim.topic, claim.scheme, claim.issuer, claim.signature, claim.data, claim.uri);
795
+ }
796
+
797
+ /// @inheritdoc IERC735
798
+ function getClaimIdsByTopic(uint256 _topic) external view returns (bytes32[] memory claimIds) {
799
+ return _store().registries[msg.sender].claimsByTopic[_topic].values();
800
+ }
801
+
802
+ /// @notice Paginated variant of {getClaimIdsByTopic} for identities with many claims per topic.
803
+ function getClaimIdsByTopicPaginated(uint256 _topic, uint256 start, uint256 end)
804
+ external
805
+ view
806
+ returns (bytes32[] memory)
807
+ {
808
+ return _store().registries[msg.sender].claimsByTopic[_topic].values(start, end);
809
+ }
810
+
811
+ /// @notice Mark a claim digest revoked. Issuer-side revocation entry point.
812
+ function revokeClaimByDigest(bytes32 digest) external {
813
+ address account = msg.sender;
814
+ _requireManagement(account, _msgSender());
815
+ require(!_store().registries[account].revokedDigests[digest], Errors.ClaimAlreadyRevoked());
816
+
817
+ _store().registries[account].revokedDigests[digest] = true;
818
+ emit ClaimRevoked(digest, account);
819
+ }
820
+
821
+ /// @notice True if `digest` was marked revoked by the calling issuer (via revoke or removal).
822
+ function isDigestRevoked(bytes32 digest) public view returns (bool) {
823
+ return _store().registries[msg.sender].revokedDigests[digest];
824
+ }
825
+
826
+ /// @notice Verify a claim against the calling identity (msg.sender is the issuer). Returns true
827
+ /// only when the status is Valid.
828
+ function isClaimValid(IIdentity _identity, uint256 claimTopic, bytes calldata sig, Structs.ClaimData calldata data)
829
+ external
830
+ view
831
+ returns (bool)
832
+ {
833
+ return _getClaimStatus(msg.sender, _identity, claimTopic, sig, data) == IClaimIssuer.ClaimStatus.Valid;
834
+ }
835
+
836
+ /// @notice Detailed status for a claim (Revoked / Expired / NotYetValid / NotIssued /
837
+ /// BadSignature / Valid), for off-chain consumers that need a reason.
838
+ function getClaimStatus(
839
+ IIdentity _identity,
840
+ uint256 claimTopic,
841
+ bytes calldata sig,
842
+ Structs.ClaimData calldata data
843
+ ) external view returns (IClaimIssuer.ClaimStatus) {
844
+ return _getClaimStatus(msg.sender, _identity, claimTopic, sig, data);
845
+ }
846
+
847
+ /// @notice Off-chain helper: the EIP-712 hash a signer should sign for a claim against
848
+ /// `_identity` on the calling issuer's domain.
849
+ function getClaimHash(address _identity, uint256 _topic, Structs.ClaimData memory _data)
850
+ external
851
+ view
852
+ returns (bytes32)
853
+ {
854
+ return _getClaimDigest(msg.sender, _identity, _topic, _data);
855
+ }
856
+
857
+ /// @notice Verify a claim then write it to the target identity via its `addClaim`. The target
858
+ /// must have granted the calling issuer identity a CLAIM_SIGNER or CLAIM_ADDER key.
859
+ function addClaimTo(
860
+ uint256 _topic,
861
+ uint256 _scheme,
862
+ bytes calldata _signature,
863
+ Structs.ClaimData calldata _data,
864
+ string calldata _uri,
865
+ IIdentity _identity
866
+ ) external {
867
+ address account = msg.sender;
868
+ _requireManagement(account, _msgSender());
869
+
870
+ require(
871
+ _getClaimStatus(account, _identity, _topic, _signature, _data) == IClaimIssuer.ClaimStatus.Valid,
872
+ Errors.InvalidClaim()
873
+ );
874
+
875
+ // This call lands back in {addClaim} on the target, with this module as the ERC-2771
876
+ // caller. addClaim detects that and checks the target's claim keys against `account`,
877
+ // passed here as the issuer. Keep this the module's only state-changing external call
878
+ // to an arbitrary address; the issuer rebinding in addClaim depends on it.
879
+ _identity.addClaim(_topic, _scheme, account, _signature, _data, _uri);
880
+ emit ClaimAddedTo(address(_identity), _topic, _signature, _data);
881
+ }
882
+
883
+ /// @notice The `metadataHash` a claim's `ClaimData` must carry for `_scheme` and `_uri`:
884
+ /// the EIP-712 hash of `Metadata(uint256 scheme,string uri)`.
885
+ function getMetadataHash(uint256 _scheme, string memory _uri) public pure returns (bytes32) {
886
+ return keccak256(abi.encode(_METADATA_TYPEHASH, _scheme, keccak256(bytes(_uri))));
887
+ }
888
+
889
+ // --- claims internals ------------------------------------------------
890
+
891
+ /// @dev Build the EIP-712 claim digest using the issuer identity's domain (read via IERC5267),
892
+ /// so signers sign against the issuer address, not this module. Issuers are not required
893
+ /// to implement ERC-5267: `_addClaim` only asks the issuer to validate its own claim, so
894
+ /// one without a domain (EASClaimIssuer) can be named as issuer. Returns zero for those
895
+ /// instead of bubbling the failed call, which would make their claims unremovable.
896
+ function _getClaimDigest(address account, address subject, uint256 topic, Structs.ClaimData memory data)
897
+ internal
898
+ view
899
+ virtual
900
+ returns (bytes32)
901
+ {
902
+ try IERC5267(account).eip712Domain() returns (
903
+ bytes1 fields,
904
+ string memory name,
905
+ string memory version,
906
+ uint256 chainId,
907
+ address verifyingContract,
908
+ bytes32 salt,
909
+ uint256[] memory
910
+ ) {
911
+ bytes32 domainSeparator = MessageHashUtils.toDomainSeparator(
912
+ fields, name, version, chainId, verifyingContract, salt
913
+ );
914
+
915
+ bytes32 dataHash = keccak256(
916
+ abi.encode(
917
+ _CLAIM_DATA_TYPEHASH, data.issuedAt, data.validUntil, data.metadataHash, keccak256(data.payload)
918
+ )
919
+ );
920
+ bytes32 structHash = keccak256(abi.encode(_CLAIM_TYPEHASH, topic, subject, dataHash));
921
+ return MessageHashUtils.toTypedDataHash(domainSeparator, structHash);
922
+ } catch {
923
+ return bytes32(0);
924
+ }
925
+ }
926
+
927
+ /// @dev Detailed claim validity. Checks are ordered cheapest first: time bounds, revoked
928
+ /// digest, signature shape, CLAIM_SIGNER on the issuer, then cryptographic verification.
929
+ function _getClaimStatus(
930
+ address account,
931
+ IIdentity _identity,
932
+ uint256 topic,
933
+ bytes memory sig,
934
+ Structs.ClaimData memory data
935
+ ) internal view virtual returns (IClaimIssuer.ClaimStatus) {
936
+ if (data.issuedAt == 0) return IClaimIssuer.ClaimStatus.BadSignature;
937
+ if (block.timestamp < data.issuedAt) return IClaimIssuer.ClaimStatus.NotYetValid;
938
+ if (data.validUntil != 0 && block.timestamp > data.validUntil) return IClaimIssuer.ClaimStatus.Expired;
939
+
940
+ bytes32 digest = _getClaimDigest(account, address(_identity), topic, data);
941
+ if (_store().registries[account].revokedDigests[digest]) return IClaimIssuer.ClaimStatus.Revoked;
942
+
943
+ // A `(bytes signer, bytes rawSig)` blob needs 2 offset words + 2 length words = 128 bytes
944
+ // minimum before any data, so a shorter blob can't decode.
945
+ if (sig.length < 128) return IClaimIssuer.ClaimStatus.BadSignature;
946
+ (bytes memory signer, bytes memory rawSig) = abi.decode(sig, (bytes, bytes));
947
+ if (signer.length < 20) return IClaimIssuer.ClaimStatus.BadSignature;
948
+ if (!keyHasPurpose(account, keccak256(signer), KeyPurposes.CLAIM_SIGNER)) {
949
+ return IClaimIssuer.ClaimStatus.NotIssued;
950
+ }
951
+ if (!_verify(signer, digest, rawSig)) {
952
+ return IClaimIssuer.ClaimStatus.BadSignature;
953
+ }
954
+ return IClaimIssuer.ClaimStatus.Valid;
955
+ }
956
+
957
+ /// @dev Require the off-chain caller to hold a claim key on `account`. CLAIM_SIGNER covers add
958
+ /// and remove; CLAIM_ADDER is accepted only when `onlyClaimSigner` is false (addClaim).
959
+ function _requireClaimKey(address account, address caller, bool onlyClaimSigner) internal view {
960
+ bytes32 keyHash = hashAddress(caller);
961
+
962
+ if (keyHasPurpose(account, keyHash, KeyPurposes.CLAIM_SIGNER)) return;
963
+ if (!onlyClaimSigner && keyHasPurpose(account, keyHash, KeyPurposes.CLAIM_ADDER)) return;
964
+
965
+ revert Errors.SenderDoesNotHaveClaimSignerKey();
966
+ }
967
+
968
+ /// @dev Require the off-chain caller to hold MANAGEMENT on `account`.
969
+ function _requireManagement(address account, address caller) internal view {
970
+ require(
971
+ keyHasPurpose(account, hashAddress(caller), KeyPurposes.MANAGEMENT), Errors.SenderDoesNotHaveManagementKey()
972
+ );
973
+ }
974
+
975
+ /// @dev When reached through the account's ERC-7579 fallback, msg.sender is the identity and
976
+ /// the real caller is the last 20 bytes of calldata (ERC-2771).
977
+ /// @dev The length check only says a tail could fit, not that one was actually appended. On a
978
+ /// path that skips the fallback the last 20 bytes are just ABI arguments, so the caller
979
+ /// reads back as some address that holds no key and the call is refused. We ask for a
980
+ /// selector plus the tail, so a call too short to carry one uses `msg.sender` instead.
981
+ function _msgSender() internal view returns (address sender) {
982
+ if (msg.data.length >= 24) {
983
+ // solhint-disable-next-line no-inline-assembly
984
+ assembly ("memory-safe") {
985
+ sender := shr(96, calldataload(sub(calldatasize(), 20)))
986
+ }
987
+ } else {
988
+ sender = msg.sender;
989
+ }
990
+ }
991
+
992
+ function _store() private pure returns (ModuleStorage storage store) {
993
+ bytes32 slot = _MODULE_STORAGE_SLOT;
994
+ // solhint-disable-next-line no-inline-assembly
995
+ assembly ("memory-safe") {
996
+ store.slot := slot
997
+ }
998
+ }
999
+
1000
+ }