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

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 (228) 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/EASTypes.sol/IEASTest.json +1 -0
  67. package/out/EASTypes.sol/ISchemaRegistryTest.json +1 -0
  68. package/out/ECDSA.sol/ECDSA.json +1 -0
  69. package/out/EIP712.sol/EIP712.json +1 -0
  70. package/out/ERC165.sol/ERC165.json +1 -0
  71. package/out/ERC165Upgradeable.sol/ERC165Upgradeable.json +1 -0
  72. package/out/ERC1967Proxy.sol/ERC1967Proxy.json +1 -0
  73. package/out/ERC1967Utils.sol/ERC1967Utils.json +1 -0
  74. package/out/ERC4337Utils.sol/ERC4337Utils.json +1 -0
  75. package/out/ERC4337Utils.sol/IEntryPointExtra.json +1 -0
  76. package/out/ERC734Validator.sol/ERC734Validator.json +1 -0
  77. package/out/ERC734Validator.t.sol/ERC734ValidatorTest.json +1 -0
  78. package/out/ERC734Validator.t.sol/PocCounter.json +1 -0
  79. package/out/ERC7579DelayedExecutor.sol/ERC7579DelayedExecutor.json +1 -0
  80. package/out/ERC7579Executor.sol/ERC7579Executor.json +1 -0
  81. package/out/ERC7579Multisig.sol/ERC7579Multisig.json +1 -0
  82. package/out/ERC7579MultisigWeighted.sol/ERC7579MultisigWeighted.json +1 -0
  83. package/out/ERC7579SocialRecoveryExecutor.sol/ERC7579SocialRecoveryExecutor.json +1 -0
  84. package/out/ERC7579Validator.sol/ERC7579Validator.json +1 -0
  85. package/out/ERC7786Recipient.sol/ERC7786Recipient.json +1 -0
  86. package/out/ERC7913WebAuthnVerifier.sol/ERC7913WebAuthnVerifier.json +1 -0
  87. package/out/EnumerableSet.sol/EnumerableSet.json +1 -0
  88. package/out/Errors.sol/Errors.json +1 -0
  89. package/out/Executions.t.sol/ETHReceiver.json +1 -0
  90. package/out/Executions.t.sol/ExecutionsTest.json +1 -0
  91. package/out/Executions.t.sol/RevertingReceiver.json +1 -0
  92. package/out/FormatResolver.sol/FormatResolver.json +1 -0
  93. package/out/Hashes.sol/Hashes.json +1 -0
  94. package/out/IAccessControl.sol/IAccessControl.json +1 -0
  95. package/out/IAccessManaged.sol/IAccessManaged.json +1 -0
  96. package/out/IAccessManager.sol/IAccessManager.json +1 -0
  97. package/out/IAuthority.sol/IAuthority.json +1 -0
  98. package/out/IBeacon.sol/IBeacon.json +1 -0
  99. package/out/IClaimIssuer.sol/IClaimIssuer.json +1 -0
  100. package/out/IEAS.sol/IEAS.json +1 -0
  101. package/out/IERC1271.sol/IERC1271.json +1 -0
  102. package/out/IERC165.sol/IERC165.json +1 -0
  103. package/out/IERC1967.sol/IERC1967.json +1 -0
  104. package/out/IERC4337.sol/IAccount.json +1 -0
  105. package/out/IERC4337.sol/IAccountExecute.json +1 -0
  106. package/out/IERC4337.sol/IAggregator.json +1 -0
  107. package/out/IERC4337.sol/IEntryPoint.json +1 -0
  108. package/out/IERC4337.sol/IEntryPointNonces.json +1 -0
  109. package/out/IERC4337.sol/IEntryPointStake.json +1 -0
  110. package/out/IERC4337.sol/IPaymaster.json +1 -0
  111. package/out/IERC5267.sol/IERC5267.json +1 -0
  112. package/out/IERC734.sol/IERC734.json +1 -0
  113. package/out/IERC734Surface.t.sol/IERC734SurfaceTest.json +1 -0
  114. package/out/IERC735.sol/IERC735.json +1 -0
  115. package/out/IERC7913.sol/IERC7913SignatureVerifier.json +1 -0
  116. package/out/IIdentity.sol/IIdentity.json +1 -0
  117. package/out/IIdentityFactory.sol/IIdentityFactory.json +1 -0
  118. package/out/IIdentityUtilities.sol/IIdentityUtilities.json +1 -0
  119. package/out/IKeyExecutor.sol/IKeyExecutor.json +1 -0
  120. package/out/IMulticall3.sol/IMulticall3.json +1 -0
  121. package/out/IReputationRegistry.sol/IReputationRegistry.json +1 -0
  122. package/out/Identity.sol/Identity.json +1 -0
  123. package/out/IdentityFactory.sol/IdentityFactory.json +1 -0
  124. package/out/IdentityFactory.t.sol/IdentityFactoryTest.json +1 -0
  125. package/out/IdentityHelper.sol/IdentityHelper.json +1 -0
  126. package/out/IdentityTypes.sol/IdentityTypes.json +1 -0
  127. package/out/IdentityUtilities.sol/IdentityUtilities.json +1 -0
  128. package/out/IdentityUtilities.t.sol/IdentityUtilitiesTest.json +1 -0
  129. package/out/IdentityUtilitiesProxy.sol/IdentityUtilitiesProxy.json +1 -0
  130. package/out/Init.t.sol/InitTest.json +1 -0
  131. package/out/Initializable.sol/Initializable.json +1 -0
  132. package/out/InteroperableAddressEncoding.t.sol/InteroperableAddressEncodingTest.json +1 -0
  133. package/out/KeyApprovalModule.sol/IIdentityAccount.json +1 -0
  134. package/out/KeyApprovalModule.sol/KeyApprovalModule.json +1 -0
  135. package/out/KeyApprovalModuleFactoryGuard.t.sol/KeyApprovalModuleFactoryGuardTest.json +1 -0
  136. package/out/KeyManager.sol/KeyManager.json +1 -0
  137. package/out/KeyPurposes.sol/KeyPurposes.json +1 -0
  138. package/out/KeyTypes.sol/KeyTypes.json +1 -0
  139. package/out/Keys.t.sol/KeysTest.json +1 -0
  140. package/out/LowLevelCall.sol/LowLevelCall.json +1 -0
  141. package/out/Math.sol/Math.json +1 -0
  142. package/out/MessageHashUtils.sol/MessageHashUtils.json +1 -0
  143. package/out/MockERC1271Signer.sol/MockERC1271Signer.json +1 -0
  144. package/out/MockERC1271Wallet.sol/MockERC1271Wallet.json +1 -0
  145. package/out/MockERC7786Gateway.sol/MockERC7786Gateway.json +1 -0
  146. package/out/MockERC7913PermissiveVerifier.sol/MockERC7913PermissiveVerifier.json +1 -0
  147. package/out/MockLyingERC734Getter.sol/MockLyingERC734Getter.json +1 -0
  148. package/out/MockStockECDSAValidator.sol/MockStockECDSAValidator.json +1 -0
  149. package/out/Multicall.sol/Multicall.json +1 -0
  150. package/out/Multisig.sol/Multisig.json +1 -0
  151. package/out/Nonces.sol/Nonces.json +1 -0
  152. package/out/OnchainIDSetup.sol/OnchainIDSetup.json +1 -0
  153. package/out/Ownable.sol/Ownable.json +1 -0
  154. package/out/P256.sol/P256.json +1 -0
  155. package/out/Packing.sol/Packing.json +1 -0
  156. package/out/Panic.sol/Panic.json +1 -0
  157. package/out/PrivilegedReentryGuard.t.sol/PocCounter.json +1 -0
  158. package/out/PrivilegedReentryGuard.t.sol/PrivilegedReentryGuardTest.json +1 -0
  159. package/out/Proxy.sol/Proxy.json +1 -0
  160. package/out/Proxy.t.sol/ProxyTest.json +1 -0
  161. package/out/ProxyPattern.t.sol/ProxyPatternTest.json +1 -0
  162. package/out/RecoveryModule.sol/RecoveryModule.json +1 -0
  163. package/out/RecoveryModule.t.sol/RecoveryModuleTest.json +1 -0
  164. package/out/ReputationRegistry.sol/ReputationRegistry.json +1 -0
  165. package/out/ReputationRegistry.t.sol/FakeIdentity.json +1 -0
  166. package/out/ReputationRegistry.t.sol/ReputationRegistryTest.json +1 -0
  167. package/out/RevertingIdentity.sol/RevertingIdentity.json +1 -0
  168. package/out/SafeCalldataBatch.sol/SafeCalldataBatch.json +1 -0
  169. package/out/SafeCast.sol/SafeCast.json +1 -0
  170. package/out/Script.sol/Script.json +1 -0
  171. package/out/ShortStrings.sol/ShortStrings.json +1 -0
  172. package/out/SignatureChecker.sol/SignatureChecker.json +1 -0
  173. package/out/SignedMath.sol/SignedMath.json +1 -0
  174. package/out/SlotDerivation.sol/SlotDerivation.json +1 -0
  175. package/out/SmartAccount.sol/SmartAccount.json +1 -0
  176. package/out/SmartAccount.t.sol/AlwaysApprovePolicy.json +1 -0
  177. package/out/SmartAccount.t.sol/Counter.json +1 -0
  178. package/out/SmartAccount.t.sol/IAddKeyWithData.json +1 -0
  179. package/out/SmartAccount.t.sol/ReentrantUninstaller.json +1 -0
  180. package/out/SmartAccount.t.sol/SmartAccountTest.json +1 -0
  181. package/out/SmartAccount.t.sol/TestExecutor.json +1 -0
  182. package/out/StdAssertions.sol/StdAssertions.json +1 -0
  183. package/out/StdChains.sol/StdChains.json +1 -0
  184. package/out/StdCheats.sol/StdCheats.json +1 -0
  185. package/out/StdCheats.sol/StdCheatsSafe.json +1 -0
  186. package/out/StdConstants.sol/StdConstants.json +1 -0
  187. package/out/StdError.sol/stdError.json +1 -0
  188. package/out/StdInvariant.sol/StdInvariant.json +1 -0
  189. package/out/StdJson.sol/stdJson.json +1 -0
  190. package/out/StdMath.sol/stdMath.json +1 -0
  191. package/out/StdStorage.sol/stdStorage.json +1 -0
  192. package/out/StdStorage.sol/stdStorageSafe.json +1 -0
  193. package/out/StdStyle.sol/StdStyle.json +1 -0
  194. package/out/StdToml.sol/stdToml.json +1 -0
  195. package/out/StdUtils.sol/StdUtils.json +1 -0
  196. package/out/StorageSlot.sol/StorageSlot.json +1 -0
  197. package/out/Strings.sol/Strings.json +1 -0
  198. package/out/Structs.sol/Structs.json +1 -0
  199. package/out/Test.sol/Test.json +1 -0
  200. package/out/TestIdentityUtilities.sol/TestIdentityUtilities.json +1 -0
  201. package/out/Time.sol/Time.json +1 -0
  202. package/out/TokenOid.t.sol/TokenOidTest.json +1 -0
  203. package/out/UUPSUpgradeable.sol/UUPSUpgradeable.json +1 -0
  204. package/out/UnlockedIdentity.sol/UnlockedIdentity.json +1 -0
  205. package/out/UpgradeableBeacon.sol/UpgradeableBeacon.json +1 -0
  206. package/out/VersionUpgrade.t.sol/VersionUpgradeTest.json +1 -0
  207. package/out/Vm.sol/Vm.json +1 -0
  208. package/out/Vm.sol/VmSafe.json +1 -0
  209. package/out/WebAuthn.sol/WebAuthn.json +1 -0
  210. package/out/WebAuthn.t.sol/WebAuthnTest.json +1 -0
  211. package/out/build-info/6d7390a9a3d29c7420710a69f614fbce.json +1 -0
  212. package/out/console.sol/console.json +1 -0
  213. package/out/draft-AccountERC7579Upgradeable.sol/AccountERC7579Upgradeable.json +1 -0
  214. package/out/draft-ERC7579Utils.sol/ERC7579Utils.json +1 -0
  215. package/out/draft-IERC1822.sol/IERC1822Proxiable.json +1 -0
  216. package/out/draft-IERC7579.sol/IERC7579AccountConfig.json +1 -0
  217. package/out/draft-IERC7579.sol/IERC7579Execution.json +1 -0
  218. package/out/draft-IERC7579.sol/IERC7579Hook.json +1 -0
  219. package/out/draft-IERC7579.sol/IERC7579Module.json +1 -0
  220. package/out/draft-IERC7579.sol/IERC7579ModuleConfig.json +1 -0
  221. package/out/draft-IERC7579.sol/IERC7579Validator.json +1 -0
  222. package/out/draft-IERC7786.sol/IERC7786GatewaySource.json +1 -0
  223. package/out/draft-IERC7786.sol/IERC7786Recipient.json +1 -0
  224. package/out/draft-InteroperableAddress.sol/InteroperableAddress.json +1 -0
  225. package/out/safeconsole.sol/safeconsole.json +1 -0
  226. package/out/src/Test.sol/Test.json +1 -0
  227. package/out/utils/Errors.sol/Errors.json +1 -0
  228. package/package.json +75 -4
@@ -0,0 +1,269 @@
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 { IClaimIssuer } from "./interface/IClaimIssuer.sol";
26
+ import { IIdentity } from "./interface/IIdentity.sol";
27
+ import { IIdentityUtilities } from "./interface/IIdentityUtilities.sol";
28
+ import { Structs } from "./storage/Structs.sol";
29
+ import { AccessControlUpgradeable } from "@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol";
30
+ import { UUPSUpgradeable } from "@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol";
31
+
32
+ /**
33
+ * @title IdentityUtilities
34
+ * @notice Contract for registering and retrieving structured topic schemas using encoded string arrays.
35
+ * @dev Inherits from AccessControl and supports UUPS upgrades. Topics define field names and types
36
+ * using ABI-encoded `string[]` arrays.
37
+ */
38
+ contract IdentityUtilities is IIdentityUtilities, AccessControlUpgradeable, UUPSUpgradeable {
39
+
40
+ /// @notice Role identifier for accounts allowed to manage topics
41
+ bytes32 public constant TOPIC_MANAGER_ROLE = keccak256("TOPIC_MANAGER_ROLE");
42
+
43
+ /// @dev Mapping from topic ID to TopicInfo struct
44
+ mapping(uint256 => TopicInfo) private _topics;
45
+
46
+ /// @notice Disables initializers on the implementation contract
47
+ constructor() {
48
+ _disableInitializers();
49
+ }
50
+
51
+ /**
52
+ * @notice Initializes the contract and sets the admin and topic manager roles.
53
+ * @param admin Address to receive DEFAULT_ADMIN_ROLE and TOPIC_MANAGER_ROLE
54
+ */
55
+ function initialize(address admin) external initializer {
56
+ __AccessControl_init();
57
+ _grantRole(DEFAULT_ADMIN_ROLE, admin);
58
+ _grantRole(TOPIC_MANAGER_ROLE, admin);
59
+ }
60
+
61
+ /**
62
+ * @inheritdoc IIdentityUtilities
63
+ */
64
+ function addTopic(
65
+ uint256 topicId,
66
+ string calldata name,
67
+ bytes calldata encodedFieldNames,
68
+ bytes calldata encodedFieldTypes
69
+ ) external override onlyRole(TOPIC_MANAGER_ROLE) {
70
+ require(bytes(name).length > 0, "Empty topic name");
71
+ require(_topics[topicId].encodedFieldNames.length == 0, "Topic already exists");
72
+ _validateFieldArrays(encodedFieldNames, encodedFieldTypes);
73
+
74
+ _topics[topicId] =
75
+ TopicInfo({ name: name, encodedFieldNames: encodedFieldNames, encodedFieldTypes: encodedFieldTypes });
76
+
77
+ emit TopicAdded(topicId, name, encodedFieldNames, encodedFieldTypes);
78
+ }
79
+
80
+ /**
81
+ * @inheritdoc IIdentityUtilities
82
+ */
83
+ function updateTopic(
84
+ uint256 topicId,
85
+ string calldata name,
86
+ bytes calldata encodedFieldNames,
87
+ bytes calldata encodedFieldTypes
88
+ ) external override onlyRole(TOPIC_MANAGER_ROLE) {
89
+ require(_topics[topicId].encodedFieldNames.length != 0, "Topic does not exist");
90
+ require(bytes(name).length > 0, "Empty topic name");
91
+ _validateFieldArrays(encodedFieldNames, encodedFieldTypes);
92
+
93
+ _topics[topicId] =
94
+ TopicInfo({ name: name, encodedFieldNames: encodedFieldNames, encodedFieldTypes: encodedFieldTypes });
95
+
96
+ emit TopicUpdated(topicId, name, encodedFieldNames, encodedFieldTypes);
97
+ }
98
+
99
+ /**
100
+ * @inheritdoc IIdentityUtilities
101
+ */
102
+ function removeTopic(uint256 topicId) external override onlyRole(TOPIC_MANAGER_ROLE) {
103
+ require(_topics[topicId].encodedFieldNames.length != 0, "Topic does not exist");
104
+ delete _topics[topicId];
105
+ emit TopicRemoved(topicId);
106
+ }
107
+
108
+ /**
109
+ * @inheritdoc IIdentityUtilities
110
+ */
111
+ function getTopic(uint256 topicId) external view override returns (TopicInfo memory) {
112
+ return _topics[topicId];
113
+ }
114
+
115
+ /**
116
+ * @inheritdoc IIdentityUtilities
117
+ */
118
+ function getSchema(uint256 topicId)
119
+ external
120
+ view
121
+ override
122
+ returns (string[] memory fieldNames, string[] memory fieldTypes)
123
+ {
124
+ if (_topics[topicId].encodedFieldNames.length == 0) {
125
+ return (new string[](0), new string[](0));
126
+ }
127
+ fieldNames = abi.decode(_topics[topicId].encodedFieldNames, (string[]));
128
+ fieldTypes = abi.decode(_topics[topicId].encodedFieldTypes, (string[]));
129
+ }
130
+
131
+ /**
132
+ * @notice Returns decoded field names for a given topic ID
133
+ * @param topicId The ID of the topic
134
+ * @return string[] Array of field names
135
+ */
136
+ function getFieldNames(uint256 topicId) external view returns (string[] memory) {
137
+ if (_topics[topicId].encodedFieldNames.length == 0) {
138
+ return new string[](0);
139
+ }
140
+ return abi.decode(_topics[topicId].encodedFieldNames, (string[]));
141
+ }
142
+
143
+ /**
144
+ * @notice Returns decoded field types for a given topic ID
145
+ * @param topicId The ID of the topic
146
+ * @return string[] Array of field types
147
+ */
148
+ function getFieldTypes(uint256 topicId) external view returns (string[] memory) {
149
+ if (_topics[topicId].encodedFieldTypes.length == 0) {
150
+ return new string[](0);
151
+ }
152
+ return abi.decode(_topics[topicId].encodedFieldTypes, (string[]));
153
+ }
154
+
155
+ /**
156
+ * @notice Returns an array of TopicInfo structs for the given topic IDs
157
+ * @param topicIds Array of topic IDs to get TopicInfo structs for
158
+ * @return TopicInfo[] Array of TopicInfo structs corresponding to the input topic IDs
159
+ */
160
+ function getTopicInfos(uint256[] calldata topicIds) external view returns (TopicInfo[] memory) {
161
+ TopicInfo[] memory topics = new TopicInfo[](topicIds.length);
162
+ for (uint256 i = 0; i < topicIds.length; i++) {
163
+ topics[i] = _topics[topicIds[i]];
164
+ }
165
+ return topics;
166
+ }
167
+
168
+ /**
169
+ * @notice Gets comprehensive claim information for an identity across multiple topics
170
+ * @param identity The identity contract address
171
+ * @param topicIds Array of topic IDs to check
172
+ * @return result Array of claim information structs
173
+ */
174
+ function getClaimsWithTopicInfo(address identity, uint256[] calldata topicIds)
175
+ external
176
+ view
177
+ returns (ClaimInfo[] memory result)
178
+ {
179
+ uint256 totalClaims = _countTotalClaims(identity, topicIds);
180
+ result = new ClaimInfo[](totalClaims);
181
+ uint256 resultIndex = 0;
182
+
183
+ for (uint256 i = 0; i < topicIds.length; i++) {
184
+ uint256 topicId = topicIds[i];
185
+ TopicInfo memory topicInfo = _topics[topicId];
186
+ bytes32[] memory claimIds = IIdentity(identity).getClaimIdsByTopic(topicId);
187
+ for (uint256 j = 0; j < claimIds.length; j++) {
188
+ result[resultIndex] = _buildClaimInfo(identity, topicId, topicInfo, claimIds[j]);
189
+ resultIndex++;
190
+ }
191
+ }
192
+ }
193
+
194
+ /**
195
+ * @dev Required override for UUPS upgradability authorization
196
+ * @param newImplementation Address of the new implementation
197
+ */
198
+ function _authorizeUpgrade(address newImplementation) internal override onlyRole(DEFAULT_ADMIN_ROLE) { }
199
+
200
+ function _countTotalClaims(address identity, uint256[] calldata topicIds) internal view returns (uint256 total) {
201
+ for (uint256 i = 0; i < topicIds.length; i++) {
202
+ bytes32[] memory claimIds = IIdentity(identity).getClaimIdsByTopic(topicIds[i]);
203
+ total += claimIds.length;
204
+ }
205
+ }
206
+
207
+ function _isClaimValid(
208
+ address identity,
209
+ uint256 topicId,
210
+ address issuer,
211
+ bytes memory signature,
212
+ Structs.ClaimData memory data
213
+ ) internal view returns (bool) {
214
+ if (issuer == address(0)) return false;
215
+ try IClaimIssuer(issuer).isClaimValid(IIdentity(identity), topicId, signature, data) returns (bool valid) {
216
+ return valid;
217
+ } catch {
218
+ return false;
219
+ }
220
+ }
221
+
222
+ function _buildClaimInfo(address identity, uint256 topicId, TopicInfo memory topicInfo, bytes32 claimId)
223
+ internal
224
+ view
225
+ returns (ClaimInfo memory info)
226
+ {
227
+ (,
228
+ // topic - not used
229
+ uint256 scheme,
230
+ address issuer,
231
+ bytes memory signature,
232
+ Structs.ClaimData memory data,
233
+ string memory uri
234
+ ) = IIdentity(identity).getClaim(claimId);
235
+
236
+ bool isValid = _isClaimValid(identity, topicId, issuer, signature, data);
237
+
238
+ info = ClaimInfo({
239
+ topic: topicInfo,
240
+ isValid: isValid,
241
+ claimId: claimId,
242
+ scheme: scheme,
243
+ issuer: issuer,
244
+ signature: signature,
245
+ data: data,
246
+ uri: uri
247
+ });
248
+ }
249
+
250
+ /**
251
+ * @dev Validates that encoded field names/types match in length and content.
252
+ * @param encodedNames ABI-encoded string[] of field names
253
+ * @param encodedTypes ABI-encoded string[] of field types
254
+ */
255
+ function _validateFieldArrays(bytes memory encodedNames, bytes memory encodedTypes) internal pure {
256
+ string[] memory names = abi.decode(encodedNames, (string[]));
257
+ string[] memory types_ = abi.decode(encodedTypes, (string[]));
258
+ require(names.length == types_.length, "Field name/type count mismatch");
259
+
260
+ for (uint256 i = 0; i < names.length; i++) {
261
+ require(bytes(names[i]).length > 0, "Empty field name");
262
+ require(bytes(types_[i]).length > 0, "Empty field type");
263
+ }
264
+ }
265
+
266
+ /// @dev Reserved storage space to allow future layout changes
267
+ uint256[50] private __gap; // solhint-disable-line ordering
268
+
269
+ }
@@ -0,0 +1,193 @@
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 { Errors } from "./libraries/Errors.sol";
26
+ import { hashAddress } from "./libraries/Hashing.sol";
27
+ import { KeyPurposes } from "./libraries/KeyPurposes.sol";
28
+ import { ERC734Validator } from "./modules/validators/ERC734Validator.sol";
29
+
30
+ /**
31
+ * @title KeyManager
32
+ * @notice Thin ERC-734 bootstrap facade for an identity. It keeps the `onlyManagerOrSelf` gate and
33
+ * the ERC-734 write entry points, but owns no storage at all.
34
+ *
35
+ * @dev The canonical key registry lives in the enshrined {ERC734Validator} module. This contract:
36
+ * - reads MANAGEMENT membership for {onlyManagerOrSelf} via a staticcall to the enshrined module;
37
+ * - forwards ERC-734 key writes (`addKey`, `addKeyWithData`, `removeKey`) to the module as
38
+ * self-calls.
39
+ *
40
+ * The module address comes from {registryModule}, implemented by the concrete account
41
+ * ({Identity}) as an immutable fixed at implementation deploy time.
42
+ *
43
+ * The ERC-734 *getter* selectors (`getKey`, `getKeyPurposes`, `getKeysByPurpose`,
44
+ * `keyHasPurpose`) are implemented here as plain functions forwarding to the enshrined
45
+ * module, so key-state reads through the account are always answered by the registry and
46
+ * never by an installed fallback handler. A real function takes precedence over ERC-7579
47
+ * fallback dispatch, so these selectors cannot be routed elsewhere by module installation.
48
+ */
49
+ abstract contract KeyManager {
50
+
51
+ /// @notice Requires a MANAGEMENT key, or an internal self-call (`msg.sender == address(this)`).
52
+ modifier onlyManagerOrSelf() {
53
+ _checkManagerOrSelf();
54
+ _;
55
+ }
56
+
57
+ /// @dev MANAGEMENT membership is read from the registry module rather than from local storage.
58
+ /// The self-call branch (`msg.sender == address(this)`) covers post-execution dispatch from
59
+ /// the queue module or the EntryPoint, and the init path before any key exists.
60
+ function _checkManagerOrSelf() internal view {
61
+ require(
62
+ msg.sender == address(this) || _moduleKeyHasPurpose(hashAddress(msg.sender), KeyPurposes.MANAGEMENT),
63
+ Errors.SenderDoesNotHaveManagementKey()
64
+ );
65
+ }
66
+
67
+ /// @notice Add a key to the identity. Caller must hold MANAGEMENT, or be the identity itself.
68
+ /// @dev The 3-arg {addKey} carries no signer bytes; it looks up the signer bytes stored in the
69
+ /// module for `_key` and forwards. Reverts if the key is unknown to the module.
70
+ function addKey(bytes32 _key, uint256 _purpose, uint256 _type)
71
+ public
72
+ virtual
73
+ onlyManagerOrSelf
74
+ returns (bool success)
75
+ {
76
+ _addKey(_key, _purpose, _type);
77
+ return true;
78
+ }
79
+
80
+ /// @dev Internal version of {addKey}. No modifiers. Used by the external entry point and by
81
+ /// the initialization path. Looks up the module-stored signer bytes for `_key` (the module
82
+ /// derives the keyHash from the signer bytes), then forwards the write.
83
+ function _addKey(bytes32 _key, uint256 _purpose, uint256 _type) internal {
84
+ (bytes memory signerData, bytes memory clientData) =
85
+ ERC734Validator(registryModule()).getKeyData(address(this), _key);
86
+ require(signerData.length != 0, Errors.InvalidSignerData());
87
+ ERC734Validator(registryModule()).addKey(signerData, clientData, _purpose, _type);
88
+ }
89
+
90
+ /// @notice Remove a purpose from a key. Caller must hold MANAGEMENT, or be the identity itself.
91
+ /// @dev The module enforces the "can't remove the last MANAGEMENT key" guard.
92
+ function removeKey(bytes32 _key, uint256 _purpose) public virtual onlyManagerOrSelf returns (bool success) {
93
+ _removeKeyPurpose(_key, _purpose);
94
+ return true;
95
+ }
96
+
97
+ /// @dev Shared remove logic. The public {removeKey} uses it, and so does
98
+ /// {SmartAccount._uninstallModule} when it strips purposes off an uninstalled module.
99
+ /// Forwards to the module, which keeps the "can't remove the last MANAGEMENT key" check.
100
+ function _removeKeyPurpose(bytes32 _key, uint256 _purpose) internal {
101
+ ERC734Validator(registryModule()).removeKey(_key, _purpose);
102
+ }
103
+
104
+ /**
105
+ * @notice Register a key alongside its ERC-7913 signer bytes and client metadata.
106
+ * @dev Convenience entry point used by the factory and tests to set up a signer in one shot.
107
+ * Forwards to the enshrined module, which derives the keyHash from `_signerData`.
108
+ */
109
+ function addKeyWithData(
110
+ bytes32 _key,
111
+ uint256 _purpose,
112
+ uint256 _type,
113
+ bytes memory _signerData,
114
+ bytes memory _clientData
115
+ ) external virtual onlyManagerOrSelf {
116
+ _addKeyWithData(_key, _purpose, _type, _signerData, _clientData);
117
+ }
118
+
119
+ /// @dev Internal version of {addKeyWithData}. No modifiers. Used by the external entry point and
120
+ /// by the initialization path. The keyHash MUST commit to the signer bytes; the module
121
+ /// re-derives it, so a mismatch is rejected here before forwarding.
122
+ function _addKeyWithData(
123
+ bytes32 _key,
124
+ uint256 _purpose,
125
+ uint256 _type,
126
+ bytes memory _signerData,
127
+ bytes memory _clientData
128
+ ) internal {
129
+ // The keyHash MUST commit to the signer bytes forwarded with it. Without this guard a caller
130
+ // could register one keyHash while attaching a different signer's bytes.
131
+ require(_key == keccak256(_signerData), Errors.InvalidSignerData());
132
+ ERC734Validator(registryModule()).addKey(_signerData, _clientData, _purpose, _type);
133
+ }
134
+
135
+ /// @notice `IERC734.getKey` for this identity, answered by the enshrined registry.
136
+ function getKey(bytes32 _key)
137
+ public
138
+ view
139
+ virtual
140
+ returns (uint256[] memory purposes, uint256 keyType, bytes32 key)
141
+ {
142
+ return ERC734Validator(registryModule()).getKey(address(this), _key);
143
+ }
144
+
145
+ /// @notice `IERC734.getKeyPurposes` for this identity. Returns the full set; use the
146
+ /// `(_key, start, end)` overload for large sets.
147
+ function getKeyPurposes(bytes32 _key) public view virtual returns (uint256[] memory purposes) {
148
+ return ERC734Validator(registryModule()).getKeyPurposes(address(this), _key);
149
+ }
150
+
151
+ /// @notice Paginated variant of {getKeyPurposes}. Returns purposes in the index range
152
+ /// `[start, end)`; `end` past the set size returns the available tail.
153
+ function getKeyPurposes(bytes32 _key, uint256 start, uint256 end)
154
+ public
155
+ view
156
+ virtual
157
+ returns (uint256[] memory purposes)
158
+ {
159
+ return ERC734Validator(registryModule()).getKeyPurposes(address(this), _key, start, end);
160
+ }
161
+
162
+ /// @notice `IERC734.getKeysByPurpose` for this identity. Returns the full set; use the
163
+ /// `(_purpose, start, end)` overload for large sets.
164
+ function getKeysByPurpose(uint256 _purpose) public view virtual returns (bytes32[] memory keys) {
165
+ return ERC734Validator(registryModule()).getKeysByPurpose(address(this), _purpose);
166
+ }
167
+
168
+ /// @notice Paginated variant of {getKeysByPurpose}. Returns key hashes in the index range
169
+ /// `[start, end)`; `end` past the set size returns the available tail.
170
+ function getKeysByPurpose(uint256 _purpose, uint256 start, uint256 end)
171
+ public
172
+ view
173
+ virtual
174
+ returns (bytes32[] memory keys)
175
+ {
176
+ return ERC734Validator(registryModule()).getKeysByPurpose(address(this), _purpose, start, end);
177
+ }
178
+
179
+ /// @notice `IERC734.keyHasPurpose` for this identity. MANAGEMENT satisfies any purpose.
180
+ function keyHasPurpose(bytes32 _key, uint256 _purpose) public view virtual returns (bool exists) {
181
+ return _moduleKeyHasPurpose(_key, _purpose);
182
+ }
183
+
184
+ /// @notice The enshrined registry module. Implemented by the concrete account ({Identity}) as
185
+ /// an immutable, so reading it costs no storage access.
186
+ function registryModule() public view virtual returns (address);
187
+
188
+ /// @dev MANAGEMENT / purpose read for the account itself, backed by the enshrined module.
189
+ function _moduleKeyHasPurpose(bytes32 keyHash, uint256 purpose) internal view returns (bool) {
190
+ return ERC734Validator(registryModule()).keyHasPurpose(address(this), keyHash, purpose);
191
+ }
192
+
193
+ }