@bloxchain/contracts 1.0.0-alpha.2 → 1.0.0-alpha.20

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 (42) hide show
  1. package/README.md +7 -7
  2. package/abi/BaseStateMachine.abi.json +85 -45
  3. package/abi/EngineBlox.abi.json +73 -90
  4. package/abi/GuardController.abi.json +252 -806
  5. package/abi/{SimpleVaultDefinitions.abi.json → GuardControllerDefinitions.abi.json} +170 -28
  6. package/abi/IDefinition.abi.json +5 -0
  7. package/abi/RuntimeRBAC.abi.json +155 -218
  8. package/abi/RuntimeRBACDefinitions.abi.json +179 -0
  9. package/abi/SecureOwnable.abi.json +524 -1621
  10. package/abi/SecureOwnableDefinitions.abi.json +5 -0
  11. package/components/README.md +8 -0
  12. package/core/access/RuntimeRBAC.sol +255 -270
  13. package/core/access/interface/IRuntimeRBAC.sol +55 -84
  14. package/core/access/lib/definitions/RuntimeRBACDefinitions.sol +93 -2
  15. package/core/base/BaseStateMachine.sol +193 -107
  16. package/core/base/interface/IBaseStateMachine.sol +153 -153
  17. package/core/execution/GuardController.sol +155 -131
  18. package/core/execution/interface/IGuardController.sol +146 -120
  19. package/core/execution/lib/definitions/GuardControllerDefinitions.sol +193 -43
  20. package/core/lib/EngineBlox.sol +2683 -2322
  21. package/{interfaces → core/lib/interfaces}/IDefinition.sol +49 -49
  22. package/{interfaces → core/lib/interfaces}/IEventForwarder.sol +33 -33
  23. package/{utils → core/lib/utils}/SharedValidation.sol +61 -8
  24. package/core/pattern/Account.sol +84 -0
  25. package/core/security/SecureOwnable.sol +456 -412
  26. package/core/security/interface/ISecureOwnable.sol +105 -104
  27. package/core/security/lib/definitions/SecureOwnableDefinitions.sol +22 -6
  28. package/package.json +5 -5
  29. package/standards/README.md +12 -0
  30. package/standards/behavior/ICopyable.sol +34 -0
  31. package/standards/hooks/IOnActionHook.sol +21 -0
  32. package/abi/AccountBlox.abi.json +0 -5799
  33. package/abi/BareBlox.abi.json +0 -1284
  34. package/abi/RoleBlox.abi.json +0 -4209
  35. package/abi/SecureBlox.abi.json +0 -3828
  36. package/abi/SimpleRWA20.abi.json +0 -5288
  37. package/abi/SimpleRWA20Definitions.abi.json +0 -191
  38. package/abi/SimpleVault.abi.json +0 -4951
  39. package/core/research/BloxchainWallet.sol +0 -306
  40. package/core/research/erc20-blox/ERC20Blox.sol +0 -140
  41. package/core/research/erc20-blox/lib/definitions/ERC20BloxDefinitions.sol +0 -185
  42. package/interfaces/IOnActionHook.sol +0 -79
@@ -1,84 +1,55 @@
1
- // SPDX-License-Identifier: MPL-2.0
2
- pragma solidity 0.8.33;
3
-
4
- import "../../lib/EngineBlox.sol";
5
-
6
- /**
7
- * @title IRuntimeRBAC
8
- * @dev Interface for Runtime Role-Based Access Control system
9
- *
10
- * This interface defines the functions for managing runtime roles through batch operations.
11
- * All role management operations are performed via the batch interface for atomic execution.
12
- *
13
- * Key Features:
14
- * - Batch-based role configuration (atomic operations)
15
- * - Runtime function schema registration
16
- * - Integration with EngineBlox for secure operations
17
- * - Query functions for role and permission inspection
18
- *
19
- * Note: This contract inherits from BaseStateMachine which provides additional query functions
20
- * such as getRole(), hasRole(), getActiveRolePermissions(), getSupportedRoles(), etc.
21
- */
22
- interface IRuntimeRBAC {
23
- /**
24
- * @dev Action types for batched RBAC configuration
25
- */
26
- enum RoleConfigActionType {
27
- CREATE_ROLE,
28
- REMOVE_ROLE,
29
- ADD_WALLET,
30
- REVOKE_WALLET,
31
- ADD_FUNCTION_TO_ROLE,
32
- REMOVE_FUNCTION_FROM_ROLE
33
- }
34
-
35
- /**
36
- * @dev Encodes a single RBAC configuration action in a batch
37
- */
38
- struct RoleConfigAction {
39
- RoleConfigActionType actionType;
40
- bytes data;
41
- }
42
-
43
- /// @dev RBAC config changes are emitted via BaseStateMachine.ComponentEvent with functionSelector = msg.sig (executeRoleConfigBatch). Decode data as (RoleConfigActionType, bytes32 roleHash, bytes4 functionSelector).
44
-
45
- // ============ ROLE CONFIGURATION BATCH INTERFACE ============
46
-
47
- /**
48
- * @dev Requests and approves a RBAC configuration batch using a meta-transaction
49
- * @param metaTx The meta-transaction
50
- * @return The transaction record
51
- */
52
- function roleConfigBatchRequestAndApprove(
53
- EngineBlox.MetaTransaction memory metaTx
54
- ) external returns (EngineBlox.TxRecord memory);
55
-
56
- // ============ QUERY FUNCTIONS ============
57
-
58
- /**
59
- * @dev Gets function schema information
60
- * @param functionSelector The function selector to get information for
61
- * @return functionSignature The function signature or name
62
- * @return functionSelectorReturn The function selector
63
- * @return operationType The operation type
64
- * @return operationName The operation name
65
- * @return supportedActions The supported actions
66
- * @return isProtected Whether the function schema is protected
67
- */
68
- function getFunctionSchema(bytes4 functionSelector) external view returns (
69
- string memory functionSignature,
70
- bytes4 functionSelectorReturn,
71
- bytes32 operationType,
72
- string memory operationName,
73
- EngineBlox.TxAction[] memory supportedActions,
74
- bool isProtected
75
- );
76
-
77
- /**
78
- * @dev Gets all authorized wallets for a role
79
- * @param roleHash The role hash to get wallets for
80
- * @return Array of authorized wallet addresses
81
- * @notice Requires caller to have any role (via _validateAnyRole) for privacy protection
82
- */
83
- function getWalletsInRole(bytes32 roleHash) external view returns (address[] memory);
84
- }
1
+ // SPDX-License-Identifier: MPL-2.0
2
+ pragma solidity 0.8.34;
3
+
4
+ import "../../lib/EngineBlox.sol";
5
+
6
+ /**
7
+ * @title IRuntimeRBAC
8
+ * @dev Interface for Runtime Role-Based Access Control system
9
+ *
10
+ * This interface defines the functions for managing runtime roles through batch operations.
11
+ * All role management operations are performed via the batch interface for atomic execution.
12
+ *
13
+ * Key Features:
14
+ * - Batch-based role configuration (atomic operations)
15
+ * - Role and permission management (function schema registration is handled by GuardController)
16
+ * - Integration with EngineBlox for secure operations
17
+ * - Query functions for role and permission inspection
18
+ *
19
+ * Note: This contract inherits from BaseStateMachine which provides additional query functions
20
+ * such as getRole(), hasRole(), getActiveRolePermissions(), getSupportedRoles(), etc.
21
+ */
22
+ interface IRuntimeRBAC {
23
+ /**
24
+ * @dev Action types for batched RBAC configuration
25
+ */
26
+ enum RoleConfigActionType {
27
+ CREATE_ROLE,
28
+ REMOVE_ROLE,
29
+ ADD_WALLET,
30
+ REVOKE_WALLET,
31
+ ADD_FUNCTION_TO_ROLE,
32
+ REMOVE_FUNCTION_FROM_ROLE
33
+ }
34
+
35
+ /**
36
+ * @dev Encodes a single RBAC configuration action in a batch
37
+ */
38
+ struct RoleConfigAction {
39
+ RoleConfigActionType actionType;
40
+ bytes data;
41
+ }
42
+
43
+ /// @dev RBAC config changes are emitted via BaseStateMachine.ComponentEvent with functionSelector = msg.sig (executeRoleConfigBatch). Decode data as (RoleConfigActionType, bytes32 roleHash, bytes4 functionSelector).
44
+
45
+ // ============ ROLE CONFIGURATION BATCH INTERFACE ============
46
+
47
+ /**
48
+ * @dev Requests and approves a RBAC configuration batch using a meta-transaction
49
+ * @param metaTx The meta-transaction
50
+ * @return The transaction ID of the applied batch
51
+ */
52
+ function roleConfigBatchRequestAndApprove(
53
+ EngineBlox.MetaTransaction memory metaTx
54
+ ) external returns (uint256);
55
+ }
@@ -1,9 +1,9 @@
1
1
  // SPDX-License-Identifier: MPL-2.0
2
- pragma solidity 0.8.33;
2
+ pragma solidity 0.8.34;
3
3
 
4
4
  import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
5
5
  import "../../../lib/EngineBlox.sol";
6
- import "../../../../interfaces/IDefinition.sol";
6
+ import "../../../lib/interfaces/IDefinition.sol";
7
7
  import "../../../access/interface/IRuntimeRBAC.sol";
8
8
 
9
9
  /**
@@ -62,6 +62,7 @@ library RuntimeRBACDefinitions {
62
62
  operationType: ROLE_CONFIG_BATCH,
63
63
  operationName: "ROLE_CONFIG_BATCH",
64
64
  supportedActionsBitmap: EngineBlox.createBitmapFromActions(metaRequestApproveActions),
65
+ enforceHandlerRelations: true,
65
66
  isProtected: true,
66
67
  handlerForSelectors: handlerForSelectors
67
68
  });
@@ -83,6 +84,7 @@ library RuntimeRBACDefinitions {
83
84
  operationType: ROLE_CONFIG_BATCH,
84
85
  operationName: "ROLE_CONFIG_BATCH",
85
86
  supportedActionsBitmap: EngineBlox.createBitmapFromActions(executionActions),
87
+ enforceHandlerRelations: false,
86
88
  isProtected: true,
87
89
  handlerForSelectors: executionHandlerForSelectors
88
90
  });
@@ -168,6 +170,95 @@ library RuntimeRBACDefinitions {
168
170
  });
169
171
  }
170
172
 
173
+ /**
174
+ * @dev Returns all available RoleConfig action types and their decode formats for discovery.
175
+ * @return actionNames Human-readable action names (same order as RoleConfigActionType enum)
176
+ * @return formats ABI decode format for each action's data, e.g. "(string roleName, uint256 maxWallets)"
177
+ * @notice Use with RoleConfigActionType enum: actionNames[i] and formats[i] describe enum value i
178
+ */
179
+ function getRoleConfigActionSpecs() public pure returns (string[] memory actionNames, string[] memory formats) {
180
+ actionNames = new string[](6);
181
+ formats = new string[](6);
182
+
183
+ actionNames[0] = "CREATE_ROLE";
184
+ formats[0] = "(string roleName, uint256 maxWallets)";
185
+
186
+ actionNames[1] = "REMOVE_ROLE";
187
+ formats[1] = "(bytes32 roleHash)";
188
+
189
+ actionNames[2] = "ADD_WALLET";
190
+ formats[2] = "(bytes32 roleHash, address wallet)";
191
+
192
+ actionNames[3] = "REVOKE_WALLET";
193
+ formats[3] = "(bytes32 roleHash, address wallet)";
194
+
195
+ actionNames[4] = "ADD_FUNCTION_TO_ROLE";
196
+ formats[4] = "(bytes32 roleHash, FunctionPermission functionPermission)";
197
+
198
+ actionNames[5] = "REMOVE_FUNCTION_FROM_ROLE";
199
+ formats[5] = "(bytes32 roleHash, bytes4 functionSelector)";
200
+ }
201
+
202
+ // ============ ROLE CONFIG ACTION DATA ENCODERS ============
203
+ // Use these helpers to build action.data for each RoleConfigActionType without reading the contract.
204
+ // Each encoder returns bytes suitable for RoleConfigAction(actionType, data).
205
+
206
+ /**
207
+ * @dev Encodes data for CREATE_ROLE. Use with RoleConfigActionType.CREATE_ROLE.
208
+ * @param roleName Name of the role to create
209
+ * @param maxWallets Maximum number of wallets that can be assigned to this role
210
+ */
211
+ function encodeCreateRole(string memory roleName, uint256 maxWallets) public pure returns (bytes memory) {
212
+ return abi.encode(roleName, maxWallets);
213
+ }
214
+
215
+ /**
216
+ * @dev Encodes data for REMOVE_ROLE. Use with RoleConfigActionType.REMOVE_ROLE.
217
+ * @param roleHash keccak256 hash of the role name
218
+ */
219
+ function encodeRemoveRole(bytes32 roleHash) public pure returns (bytes memory) {
220
+ return abi.encode(roleHash);
221
+ }
222
+
223
+ /**
224
+ * @dev Encodes data for ADD_WALLET. Use with RoleConfigActionType.ADD_WALLET.
225
+ * @param roleHash Role to add the wallet to
226
+ * @param wallet Address to assign to the role
227
+ */
228
+ function encodeAddWallet(bytes32 roleHash, address wallet) public pure returns (bytes memory) {
229
+ return abi.encode(roleHash, wallet);
230
+ }
231
+
232
+ /**
233
+ * @dev Encodes data for REVOKE_WALLET. Use with RoleConfigActionType.REVOKE_WALLET.
234
+ * @param roleHash Role to revoke the wallet from
235
+ * @param wallet Address to revoke
236
+ */
237
+ function encodeRevokeWallet(bytes32 roleHash, address wallet) public pure returns (bytes memory) {
238
+ return abi.encode(roleHash, wallet);
239
+ }
240
+
241
+ /**
242
+ * @dev Encodes data for ADD_FUNCTION_TO_ROLE. Use with RoleConfigActionType.ADD_FUNCTION_TO_ROLE.
243
+ * @param roleHash Role to grant the function permission to
244
+ * @param functionPermission FunctionPermission (functionSelector, grantedActionsBitmap, handlerForSelectors)
245
+ */
246
+ function encodeAddFunctionToRole(
247
+ bytes32 roleHash,
248
+ EngineBlox.FunctionPermission memory functionPermission
249
+ ) public pure returns (bytes memory) {
250
+ return abi.encode(roleHash, functionPermission);
251
+ }
252
+
253
+ /**
254
+ * @dev Encodes data for REMOVE_FUNCTION_FROM_ROLE. Use with RoleConfigActionType.REMOVE_FUNCTION_FROM_ROLE.
255
+ * @param roleHash Role to remove the function from
256
+ * @param functionSelector Selector of the function to remove
257
+ */
258
+ function encodeRemoveFunctionFromRole(bytes32 roleHash, bytes4 functionSelector) public pure returns (bytes memory) {
259
+ return abi.encode(roleHash, functionSelector);
260
+ }
261
+
171
262
  /**
172
263
  * @dev Creates execution params for a RBAC configuration batch (pure helper for EngineBlox).
173
264
  * @param actions Encoded role configuration actions (IRuntimeRBAC.RoleConfigAction[] layout)