@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,74 @@
1
+ // SPDX-License-Identifier: MIT
2
+ // Vendored from OpenZeppelin openzeppelin-accounts (audited)
3
+ // Source: packages/contracts/src/modules/validators/ERC7579Validator.sol
4
+
5
+ pragma solidity ^0.8.27;
6
+
7
+ import { ERC4337Utils } from "@openzeppelin/contracts/account/utils/ERC4337Utils.sol";
8
+ import { IERC1271 } from "@openzeppelin/contracts/interfaces/IERC1271.sol";
9
+ import { PackedUserOperation } from "@openzeppelin/contracts/interfaces/IERC4337.sol";
10
+ import {
11
+ IERC7579Module,
12
+ IERC7579Validator,
13
+ MODULE_TYPE_VALIDATOR
14
+ } from "@openzeppelin/contracts/interfaces/draft-IERC7579.sol";
15
+
16
+ /**
17
+ * @dev Abstract validator module for ERC-7579 accounts.
18
+ *
19
+ * Provides base implementation for signature validation in ERC-7579 accounts.
20
+ * Derived contracts must implement {onInstall}, {onUninstall}, and {_rawERC7579Validation}.
21
+ */
22
+ abstract contract ERC7579Validator is IERC7579Module, IERC7579Validator {
23
+
24
+ /// @inheritdoc IERC7579Module
25
+ function isModuleType(uint256 moduleTypeId) public pure virtual returns (bool) {
26
+ return moduleTypeId == MODULE_TYPE_VALIDATOR;
27
+ }
28
+
29
+ /// @inheritdoc IERC7579Validator
30
+ function validateUserOp(PackedUserOperation calldata userOp, bytes32 userOpHash) public virtual returns (uint256) {
31
+ return _validateUserOp(userOp, userOpHash);
32
+ }
33
+
34
+ /// @dev Internal version of {validateUserOp}.
35
+ function _validateUserOp(PackedUserOperation calldata userOp, bytes32 userOpHash)
36
+ internal
37
+ virtual
38
+ returns (uint256)
39
+ {
40
+ return _rawERC7579Validation(userOp.sender, userOpHash, userOp.signature)
41
+ ? ERC4337Utils.SIG_VALIDATION_SUCCESS
42
+ : ERC4337Utils.SIG_VALIDATION_FAILED;
43
+ }
44
+
45
+ /**
46
+ * @dev See {IERC7579Validator-isValidSignatureWithSender}.
47
+ *
48
+ * Ignores the `sender` parameter and validates using {_rawERC7579Validation}.
49
+ */
50
+ function isValidSignatureWithSender(
51
+ address,
52
+ /* sender */
53
+ bytes32 hash,
54
+ bytes calldata signature
55
+ )
56
+ public
57
+ view
58
+ virtual
59
+ returns (bytes4)
60
+ {
61
+ return
62
+ _rawERC7579Validation(msg.sender, hash, signature) ? IERC1271.isValidSignature.selector : bytes4(0xffffffff);
63
+ }
64
+
65
+ /**
66
+ * @dev Validation algorithm. Implementations must handle cryptographic verification.
67
+ */
68
+ function _rawERC7579Validation(address account, bytes32 hash, bytes calldata signature)
69
+ internal
70
+ view
71
+ virtual
72
+ returns (bool);
73
+
74
+ }
@@ -0,0 +1,36 @@
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.27;
24
+
25
+ import { IdentityUtilities } from "../IdentityUtilities.sol";
26
+ import { ERC1967Proxy } from "@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol";
27
+
28
+ contract IdentityUtilitiesProxy is ERC1967Proxy {
29
+
30
+ /// @dev Takes the admin instead of raw init data, so the proxy can only ever be
31
+ /// deployed initialized. An uninitialized one is open for anyone to claim.
32
+ constructor(address implementation, address admin)
33
+ ERC1967Proxy(implementation, abi.encodeCall(IdentityUtilities.initialize, (admin)))
34
+ { }
35
+
36
+ }
@@ -0,0 +1,117 @@
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.27;
24
+
25
+ /// @title IReputationRegistry
26
+ /// @notice A single per-identity reputation primitive that any feature can read.
27
+ ///
28
+ /// The registry is a thin key-value store. Two write seams, both gated
29
+ /// by the AccessManager's REPUTATION_MANAGER role:
30
+ ///
31
+ /// * {setReputation} writes a per-identity explicit score.
32
+ /// * {setDefault} writes a per-type default score.
33
+ ///
34
+ /// One canonical read seam, {reputationOf}:
35
+ /// * If an explicit entry exists (`setAt != 0`), its score is returned,
36
+ /// including an explicit `0` (which is how a manager revokes trust
37
+ /// without deleting the entry).
38
+ /// * Otherwise the lookup falls back to `defaultFor[type]` where `type`
39
+ /// is read from the identity itself via `IIdentity.getIdentityType()`.
40
+ ///
41
+ /// Factory-membership gating. The fallback path is gated on
42
+ /// {IIdentityFactory.isFactoryIdentity}: an arbitrary contract that
43
+ /// self-declares type 5 cannot inherit the CLAIM_ISSUER default. The
44
+ /// explicit-entry path bypasses the factory check because the manager
45
+ /// may want to score externally-deployed identities by hand.
46
+ interface IReputationRegistry {
47
+
48
+ /// @dev Per-identity entry. Packs into a single 32-byte slot. `setAt == 0`
49
+ /// means "no explicit entry" and the lookup falls back to a per-type
50
+ /// default. `score` is `uint128` because no reputation use case
51
+ /// anticipates needing more than 2^128 - 1 distinct levels, and packing
52
+ /// keeps the per-identity slot count at one.
53
+ struct Entry {
54
+ uint128 score;
55
+ uint128 setAt;
56
+ }
57
+
58
+ /// @notice Emitted whenever an identity's explicit reputation entry is written.
59
+ /// Both the previous score and the writer are recorded so off-chain
60
+ /// indexers can reconstruct full history from this event alone.
61
+ /// @param identity The identity whose entry changed.
62
+ /// @param oldScore Previous explicit score (`0` if the entry was uninitialized).
63
+ /// @param newScore New explicit score.
64
+ /// @param setter `msg.sender` on the call that produced the change.
65
+ event ReputationSet(address indexed identity, uint128 oldScore, uint128 newScore, address indexed setter);
66
+
67
+ /// @notice Emitted whenever the default score for a given identity type changes.
68
+ /// @param identityType The identity type whose default changed.
69
+ /// @param oldDefault Previous default score for that type.
70
+ /// @param newDefault New default score for that type.
71
+ event DefaultSet(uint256 indexed identityType, uint128 oldDefault, uint128 newDefault);
72
+
73
+ /// @notice Emitted whenever the global claim-add auto-approval threshold changes.
74
+ /// Consumers compare this against {reputationOf} to decide whether a
75
+ /// claim-add should auto-approve.
76
+ /// @param oldThreshold Previous threshold.
77
+ /// @param newThreshold New threshold.
78
+ event ClaimAddThresholdSet(uint128 oldThreshold, uint128 newThreshold);
79
+
80
+ // ---- Reads (open) ----
81
+
82
+ /// @notice Effective reputation score for `identity`.
83
+ /// Returns the explicit entry when {setReputation} has been called
84
+ /// for `identity` (including an explicit `0`), otherwise the per-type
85
+ /// default, but only when `identity` is a factory-deployed identity.
86
+ /// Non-factory identities without an explicit entry read `0`.
87
+ function reputationOf(address identity) external view returns (uint128);
88
+
89
+ /// @notice Raw explicit entry for `identity`. Does **not** fall back to the
90
+ /// per-type default. `setAt == 0` means "no explicit entry."
91
+ /// Useful for callers that want to distinguish "manager revoked to 0"
92
+ /// from "never written."
93
+ function entryOf(address identity) external view returns (uint128 score, uint128 setAt);
94
+
95
+ /// @notice Default score for `identityType`. Written via {setDefault}.
96
+ function defaultFor(uint256 identityType) external view returns (uint128);
97
+
98
+ /// @notice Global threshold consumers compare against {reputationOf} when
99
+ /// deciding whether a claim-add should auto-approve. Tunable by the
100
+ /// REPUTATION_MANAGER via {setClaimAddThreshold}.
101
+ function claimAddThreshold() external view returns (uint128);
102
+
103
+ // ---- Writes: REPUTATION_MANAGER (restricted via AccessManager) ----
104
+
105
+ /// @notice Set the explicit reputation score for `identity`. Use `0` to
106
+ /// revoke trust without removing the entry. `restricted` via the AM.
107
+ function setReputation(address identity, uint128 newScore) external;
108
+
109
+ /// @notice Set the default reputation score for `identityType`. `restricted`
110
+ /// via the AM.
111
+ function setDefault(uint256 identityType, uint128 newDefault) external;
112
+
113
+ /// @notice Set the global claim-add auto-approval threshold consumers use.
114
+ /// `restricted` via the AM.
115
+ function setClaimAddThreshold(uint128 newThreshold) external;
116
+
117
+ }
@@ -0,0 +1,155 @@
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.27;
24
+
25
+ import { AccessManaged } from "@openzeppelin/contracts/access/manager/AccessManaged.sol";
26
+
27
+ import { IIdentityFactory } from "../factory/IIdentityFactory.sol";
28
+ import { IIdentity } from "../interface/IIdentity.sol";
29
+ import { Errors } from "../libraries/Errors.sol";
30
+ import { IReputationRegistry } from "./IReputationRegistry.sol";
31
+
32
+ /// @title ReputationRegistry
33
+ /// @notice Per-identity reputation scores, plus per-type defaults.
34
+ ///
35
+ /// Two writers, both gated by REPUTATION_MANAGER via the AccessManager:
36
+ /// * {setReputation} overwrites an identity's explicit entry.
37
+ /// * {setDefault} overwrites the default score for a given identity type.
38
+ ///
39
+ /// One canonical read, {reputationOf}:
40
+ /// * Explicit entry (`setAt != 0`) returns its score, including `0`
41
+ /// (manager-revoked trust). This path bypasses the factory check
42
+ /// because the manager may want to score externally-deployed
43
+ /// identities by hand.
44
+ /// * No explicit entry returns `defaultFor[type]` only if the identity
45
+ /// was deployed by the factory (verified via the immutable
46
+ /// {IIdentityFactory} reference). Any address that was not deployed by
47
+ /// the factory and has no explicit entry reads `0`. This stops a
48
+ /// random contract from inheriting the CLAIM_ISSUER default just by
49
+ /// returning `5` from {getIdentityType}; only the factory can mint
50
+ /// that trust signal.
51
+ ///
52
+ /// Storage is namespaced under ERC-7201 so a future proxy variant slots
53
+ /// in without a layout migration. v1 ships non-upgradeable.
54
+ contract ReputationRegistry is IReputationRegistry, AccessManaged {
55
+
56
+ /// @notice The factory whose `isFactoryIdentity` view gates the default-tier
57
+ /// fallback. Immutable so the trust anchor is pinned at construction.
58
+ IIdentityFactory public immutable factory;
59
+
60
+ /// @dev EIP-7201 namespaced storage. All mutable state lives here so a
61
+ /// future upgradeable variant doesn't collide with inherited slots.
62
+ /// @custom:storage-location erc7201:onchainid.ReputationRegistry
63
+ struct ReputationRegistryStorage {
64
+ /// @dev Per-identity explicit entry. `setAt == 0` means no entry exists,
65
+ /// and the lookup falls back to `defaultFor[type]`.
66
+ mapping(address identity => Entry entry) reputation;
67
+ /// @dev Per-type default. Applied lazily on read. Tunable by
68
+ /// REPUTATION_MANAGER. Stored `uint128` to match `Entry.score`.
69
+ mapping(uint256 identityType => uint128 score) defaultFor;
70
+ /// @dev Global threshold consumers compare against {reputationOf} when
71
+ /// deciding whether a claim-add auto-approves. Tunable by
72
+ /// REPUTATION_MANAGER.
73
+ uint128 claimAddThreshold;
74
+ }
75
+
76
+ // keccak256(abi.encode(uint256(keccak256("onchainid.ReputationRegistry")) - 1)) & ~bytes32(uint256(0xff))
77
+ bytes32 private constant _REPUTATION_REGISTRY_STORAGE_SLOT =
78
+ 0xf14f9ea5236057e326d1c26ab089d99ae0165f5465c8413baa51d790a28f1500;
79
+
80
+ function _storage() private pure returns (ReputationRegistryStorage storage $) {
81
+ bytes32 slot = _REPUTATION_REGISTRY_STORAGE_SLOT;
82
+ assembly ("memory-safe") {
83
+ $.slot := slot
84
+ }
85
+ }
86
+
87
+ /// @param initialAuthority AccessManager that backs every `restricted` write.
88
+ /// @param identityFactory The IdentityFactory whose `isFactoryIdentity` view gates
89
+ /// the default-tier fallback. Reverts the deploy on zero.
90
+ constructor(address initialAuthority, address identityFactory) AccessManaged(initialAuthority) {
91
+ require(initialAuthority != address(0), Errors.ZeroAddress());
92
+ require(identityFactory != address(0), Errors.ZeroAddress());
93
+ factory = IIdentityFactory(identityFactory);
94
+ }
95
+
96
+ /// @inheritdoc IReputationRegistry
97
+ function setReputation(address identity, uint128 newScore) external restricted {
98
+ require(identity != address(0), Errors.ZeroAddress());
99
+ Entry storage entry = _storage().reputation[identity];
100
+ uint128 previousScore = entry.score;
101
+ entry.score = newScore;
102
+ // block.timestamp fits comfortably in uint64; uint128 is overkill but
103
+ // keeps the (score, setAt) pair packed in one slot.
104
+ // forge-lint: disable-next-line(unsafe-typecast)
105
+ entry.setAt = uint128(block.timestamp);
106
+ emit ReputationSet(identity, previousScore, newScore, msg.sender);
107
+ }
108
+
109
+ /// @inheritdoc IReputationRegistry
110
+ function setDefault(uint256 identityType, uint128 newDefault) external restricted {
111
+ uint128 previousDefault = _storage().defaultFor[identityType];
112
+ _storage().defaultFor[identityType] = newDefault;
113
+ emit DefaultSet(identityType, previousDefault, newDefault);
114
+ }
115
+
116
+ /// @inheritdoc IReputationRegistry
117
+ function setClaimAddThreshold(uint128 newThreshold) external restricted {
118
+ uint128 previousThreshold = _storage().claimAddThreshold;
119
+ _storage().claimAddThreshold = newThreshold;
120
+ emit ClaimAddThresholdSet(previousThreshold, newThreshold);
121
+ }
122
+
123
+ /// @inheritdoc IReputationRegistry
124
+ function reputationOf(address identity) external view returns (uint128) {
125
+ Entry storage entry = _storage().reputation[identity];
126
+ if (entry.setAt != 0) {
127
+ return entry.score;
128
+ }
129
+ // Lazy fallback: gated on factory membership so an arbitrary contract
130
+ // that self-declares its type cannot inherit a default. Manager-set
131
+ // entries above bypass this gate by design.
132
+ if (!factory.isFactoryIdentity(identity)) {
133
+ return 0;
134
+ }
135
+ uint256 identityType = IIdentity(identity).getIdentityType();
136
+ return _storage().defaultFor[identityType];
137
+ }
138
+
139
+ /// @inheritdoc IReputationRegistry
140
+ function entryOf(address identity) external view returns (uint128 score, uint128 setAt) {
141
+ Entry storage entry = _storage().reputation[identity];
142
+ return (entry.score, entry.setAt);
143
+ }
144
+
145
+ /// @inheritdoc IReputationRegistry
146
+ function defaultFor(uint256 identityType) external view returns (uint128) {
147
+ return _storage().defaultFor[identityType];
148
+ }
149
+
150
+ /// @inheritdoc IReputationRegistry
151
+ function claimAddThreshold() external view returns (uint128) {
152
+ return _storage().claimAddThreshold;
153
+ }
154
+
155
+ }
@@ -0,0 +1,176 @@
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.27;
24
+
25
+ import { EnumerableSet } from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
26
+
27
+ library Structs {
28
+
29
+ /**
30
+ * @dev Definition of the structure of a Key.
31
+ *
32
+ * Specification: Keys are cryptographic public keys, or contract addresses associated with this identity.
33
+ * The structure should be as follows:
34
+ * key: A public key owned by this identity
35
+ * purposes: uint256[] Array of the key purposes, like KeyPurposes.MANAGEMENT = MANAGEMENT,
36
+ * KeyPurposes.ACTION = ACTION
37
+ * keyType: The type of key used, which would be a uint256 for different key types. e.g. KeyTypes.ECDSA = ECDSA,
38
+ * KeyTypes.RSA = RSA, etc.
39
+ * key: bytes32 The public key. // Its the Keccak256 hash of the key
40
+ */
41
+ struct Key {
42
+ EnumerableSet.UintSet purposes;
43
+ uint256 keyType;
44
+ bytes32 key;
45
+ /// @dev ERC-7913 signer bytes used for on-chain signature verification.
46
+ /// Capped at {MAX_SIGNER_DATA_LENGTH} (fits a 20-byte verifier + RSA-4096 key).
47
+ bytes signerData;
48
+ /// @dev Non-cryptographic metadata for dapps (e.g. WebAuthn credentialId). Empty for ECDSA keys.
49
+ /// Capped at {MAX_CLIENT_DATA_LENGTH} (WebAuthn credentialIds are spec-capped at 1023 bytes).
50
+ bytes clientData;
51
+ }
52
+
53
+ /// @dev Caps on the dynamic fields of {Key}, enforced when a key is registered.
54
+ uint256 internal constant MAX_SIGNER_DATA_LENGTH = 1024;
55
+ uint256 internal constant MAX_CLIENT_DATA_LENGTH = 1024;
56
+
57
+ /**
58
+ * @dev Definition of the structure of an Execution
59
+ *
60
+ * Specification: Executions are requests for transactions to be issued by the ONCHAINID
61
+ * to: address of contract to interact with, can be address(this)
62
+ * value: ETH to transfer with the transaction
63
+ * data: payload of the transaction to execute
64
+ * approved: approval status of the Execution
65
+ * executed: execution status of the Execution (set as false when the Execution is created
66
+ * and updated to true when the Execution is processed)
67
+ */
68
+ struct Execution {
69
+ address to;
70
+ uint256 value;
71
+ bytes data;
72
+ bool approved;
73
+ bool executed;
74
+ }
75
+
76
+ /**
77
+ * @dev Definition of the structure of a Claim.
78
+ *
79
+ * Specification: Claims are information an issuer has about the identity holder.
80
+ * The structure should be as follows:
81
+ * claim: A claim published for the Identity.
82
+ * topic: A uint256 number which represents the topic of the claim. (e.g. biometric,
83
+ * residence (ToBeDefined: number schemes, sub topics based on number ranges??))
84
+ * scheme : The scheme with which this claim SHOULD be verified or how it should be processed. Its a uint256 for
85
+ * different schemes. E.g. could mean contract verification, where the data will be call data, and the issuer a
86
+ * contract address to call (ToBeDefined). Those can also mean different key types e.g. KeyTypes.ECDSA = ECDSA,
87
+ * KeyTypes.RSA = RSA, etc.
88
+ * (ToBeDefined)
89
+ * issuer: The issuers identity contract address, or the address used to sign the above signature. If an
90
+ * identity contract, it should hold the key with which the above message was signed, if the key is not present
91
+ * anymore, the claim SHOULD be treated as invalid. The issuer can also be a contract address itself, at which the
92
+ * claim can be verified using the call data.
93
+ * signature: Signature which is the proof that the claim issuer issued a claim of topic for this identity. it
94
+ * MUST be a signed message of the following structure:
95
+ * `keccak256(abi.encode(identityHolder_address, topic, data))`
96
+ * data: The hash of the claim data, sitting in another location, a bit-mask, call data, or actual data based on
97
+ * the claim scheme.
98
+ * uri: The location of the claim, this can be HTTP links, swarm hashes, IPFS hashes, and such.
99
+ */
100
+ struct Claim {
101
+ uint256 topic;
102
+ uint256 scheme;
103
+ address issuer;
104
+ bytes signature;
105
+ ClaimData data;
106
+ string uri;
107
+ }
108
+
109
+ /**
110
+ * @dev Typed envelope for the signed portion of a Claim.
111
+ *
112
+ * issuedAt: block timestamp when the issuer signed the claim. MUST be > 0.
113
+ * `block.timestamp < issuedAt` means the claim is not yet valid.
114
+ * validUntil: block timestamp after which the claim expires. 0 means no expiry.
115
+ * metadataHash: the EIP-712 hash of `Metadata(uint256 scheme,string uri)`. Binds the
116
+ * claim's scheme and uri to the signature; every add checks it against the
117
+ * submitted values.
118
+ * payload: topic-specific claim contents.
119
+ *
120
+ * The EIP-712 type is nested as
121
+ * `ClaimData(uint256 issuedAt,uint256 validUntil,Metadata metadata,bytes payload)` with
122
+ * `Metadata(uint256 scheme,string uri)`, so wallets render each field legibly during
123
+ * typed-data signing — including the actual scheme and uri — instead of surfacing an
124
+ * opaque hex blob.
125
+ */
126
+ struct ClaimData {
127
+ uint256 issuedAt;
128
+ uint256 validUntil;
129
+ bytes32 metadataHash;
130
+ bytes payload;
131
+ }
132
+
133
+ /// @dev Caps on the dynamic fields of {Claim} and {ClaimData}, enforced when a claim is
134
+ /// added. They keep every claim small enough to remove in one block.
135
+ uint256 internal constant MAX_CLAIM_SIGNATURE_LENGTH = 2048;
136
+ uint256 internal constant MAX_CLAIM_PAYLOAD_LENGTH = 2048;
137
+ uint256 internal constant MAX_CLAIM_URI_LENGTH = 2048;
138
+
139
+ /**
140
+ * @dev Definition of the structure of a KeyParam, used by the factory to set up keys on a new identity.
141
+ *
142
+ * keyHash: keccak256(signerData) for the key
143
+ * purpose: Key purpose (MANAGEMENT=1, ACTION=2, CLAIM_SIGNER=3, ENCRYPTION=4, CLAIM_ADDER=5)
144
+ * keyType: Key type (ECDSA=1, RSA=2, WEBAUTHN=3)
145
+ * signerData: ERC-7913 signer bytes (abi.encodePacked(address) for ECDSA, etc.)
146
+ * clientData: Non-cryptographic metadata (e.g. WebAuthn credentialId) — not used for on-chain verification
147
+ */
148
+ struct KeyParam {
149
+ bytes32 keyHash;
150
+ uint256 purpose;
151
+ uint256 keyType;
152
+ bytes signerData;
153
+ bytes clientData;
154
+ }
155
+
156
+ /**
157
+ * @dev Definition of an ERC-7579 module to install on an identity during factory deployment.
158
+ * The frontend decides which modules (validators, executors, fallback handlers) and their init data.
159
+ *
160
+ * moduleType: ERC-7579 module type (1=VALIDATOR, 2=EXECUTOR, 3=FALLBACK, 4=HOOK)
161
+ * module: Address of the module singleton
162
+ * initData: Module-specific initialization data (e.g. signer address for ECDSA, keyHash+qx+qy for WebAuthn)
163
+ * purpose: If non zero, the factory registers `hashAddress(module)` in the
164
+ * key registry with this purpose. Executor modules need this to dispatch through
165
+ * `executeFromExecutor`, and so do fallback handlers that call privileged
166
+ * self targeted functions. On uninstall the purpose is removed automatically,
167
+ * so you don't need to follow up with `removeKey`.
168
+ */
169
+ struct ModuleInstall {
170
+ uint256 moduleType;
171
+ address module;
172
+ bytes initData;
173
+ uint256 purpose;
174
+ }
175
+
176
+ }
@@ -0,0 +1,36 @@
1
+ // SPDX-License-Identifier: MIT
2
+ pragma solidity ^0.8.27;
3
+
4
+ /**
5
+ * @title IEAS (minimal)
6
+ * @notice Vendored subset of the Ethereum Attestation Service interface. Only the surface the
7
+ * ONCHAINID EAS adapter reads is included: one struct and one view function.
8
+ *
9
+ * @dev Full interface: https://github.com/ethereum-attestation-service/eas-contracts. The
10
+ * eas-contracts package is not pulled in as a dependency because the adapter is a
11
+ * stateless view over EAS and only consumes what is declared here. Field ordering and
12
+ * types must match the upstream `Attestation` layout so `getAttestation` decodes
13
+ * correctly.
14
+ */
15
+ struct Attestation {
16
+ bytes32 uid;
17
+ bytes32 schema;
18
+ uint64 time;
19
+ uint64 expirationTime;
20
+ uint64 revocationTime;
21
+ bytes32 refUID;
22
+ address recipient;
23
+ address attester;
24
+ bool revocable;
25
+ bytes data;
26
+ }
27
+
28
+ interface IEAS {
29
+
30
+ /**
31
+ * @notice Read a single attestation by UID.
32
+ * @dev A missing attestation is returned with `uid == 0`.
33
+ */
34
+ function getAttestation(bytes32 uid) external view returns (Attestation memory);
35
+
36
+ }
@@ -0,0 +1,61 @@
1
+ // SPDX-License-Identifier: GPL-3.0
2
+ pragma solidity ^0.8.28;
3
+
4
+ import { ERC7579Utils } from "@openzeppelin/contracts/account/utils/draft-ERC7579Utils.sol";
5
+ import { Execution } from "@openzeppelin/contracts/interfaces/draft-IERC7579.sol";
6
+
7
+ /// @title SafeCalldataBatch
8
+ /// @notice Calldata-preserving batch decoder that closes the cross-frame bounds gap in
9
+ /// OpenZeppelin's {ERC7579Utils-decodeBatch} without copying the batch into memory.
10
+ ///
11
+ /// @dev `ERC7579Utils.decodeBatch` bounds only the array's pointer region against the
12
+ /// `executionCalldata` slice; per-entry pointer resolution is left to Solidity's generated
13
+ /// calldata-array accessor, which bounds the resolved pointer against `calldatasize()` — the
14
+ /// enclosing frame, not the slice. When the same blob is decoded in two different frames
15
+ /// (the account entered as `execute`, the validator entered as `validateUserOp` with the
16
+ /// blob at an offset inside the re-encoded user operation), a backward-pointing entry can
17
+ /// resolve to different targets on each side, escalating a low-privilege key.
18
+ ///
19
+ /// This helper re-runs `decodeBatch` and then, only when `executionCalldata` is not the last
20
+ /// buffer in `msg.data` (the exact case Solidity's lazy checks miss), walks every entry and
21
+ /// rejects any whose struct head or `callData` tail escapes the slice. The batch stays in
22
+ /// calldata, so callers keep OZ's gas profile. Ported from OpenZeppelin PR #5400
23
+ /// (`ERC7579Utils._validateCalldataBound`), which the vendored 5.7.0-rc.0 predates.
24
+ library SafeCalldataBatch {
25
+
26
+ /// @dev Decodes a batch and validates every entry against the slice bounds. Reverts with
27
+ /// {ERC7579Utils.ERC7579DecodingError} on a malformed or out-of-bounds encoding.
28
+ function decodeBatch(bytes calldata executionCalldata) internal pure returns (Execution[] calldata batch) {
29
+ batch = ERC7579Utils.decodeBatch(executionCalldata);
30
+
31
+ uint256 bound;
32
+ assembly ("memory-safe") {
33
+ bound := add(executionCalldata.offset, executionCalldata.length)
34
+ }
35
+ _validateCalldataBound(batch, bound);
36
+ }
37
+
38
+ /// @dev In-depth sanity check. Solidity verifies calldata objects lazily, bounding them against
39
+ /// `calldatasize()` when they are dereferenced. If `executionCalldata` is not the last buffer
40
+ /// in `msg.data`, that lazy check does not catch entries pointing into the space past the
41
+ /// slice but still inside the frame. When the slice ends before `msg.data`, traverse the
42
+ /// array and reject any entry whose struct head (`target|value|callData-offset`, 0x60 bytes)
43
+ /// or `callData` tail extends beyond `bound`.
44
+ function _validateCalldataBound(Execution[] calldata batch, uint256 bound) private pure {
45
+ if (bound < msg.data.length) {
46
+ for (uint256 i = 0; i < batch.length; ++i) {
47
+ Execution calldata item = batch[i];
48
+ bytes calldata itemCalldata = item.callData;
49
+
50
+ uint256 itemEnd;
51
+ uint256 itemCalldataEnd;
52
+ assembly ("memory-safe") {
53
+ itemEnd := add(item, 0x60)
54
+ itemCalldataEnd := add(itemCalldata.offset, itemCalldata.length)
55
+ }
56
+ if (itemEnd > bound || itemCalldataEnd > bound) revert ERC7579Utils.ERC7579DecodingError();
57
+ }
58
+ }
59
+ }
60
+
61
+ }