@bloxchain/sdk 1.0.0-alpha

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 (132) hide show
  1. package/README.md +338 -0
  2. package/abi/BareBlox.abi.json +1341 -0
  3. package/abi/BaseStateMachine.abi.json +1308 -0
  4. package/abi/ControlBlox.abi.json +6210 -0
  5. package/abi/EngineBlox.abi.json +872 -0
  6. package/abi/GuardController.abi.json +3045 -0
  7. package/abi/IDefinition.abi.json +94 -0
  8. package/abi/RoleBlox.abi.json +4569 -0
  9. package/abi/RuntimeRBAC.abi.json +1857 -0
  10. package/abi/RuntimeRBACDefinitions.abi.json +133 -0
  11. package/abi/SecureBlox.abi.json +4085 -0
  12. package/abi/SecureOwnable.abi.json +4085 -0
  13. package/abi/SecureOwnableDefinitions.abi.json +354 -0
  14. package/abi/SimpleRWA20.abi.json +5545 -0
  15. package/abi/SimpleRWA20Definitions.abi.json +172 -0
  16. package/abi/SimpleVault.abi.json +5208 -0
  17. package/abi/SimpleVaultDefinitions.abi.json +250 -0
  18. package/dist/abi/BaseStateMachine.abi.json +1308 -0
  19. package/dist/abi/GuardController.abi.json +3045 -0
  20. package/dist/abi/IDefinition.abi.json +94 -0
  21. package/dist/abi/RuntimeRBAC.abi.json +1857 -0
  22. package/dist/abi/SecureOwnable.abi.json +4085 -0
  23. package/dist/contracts/BaseStateMachine.d.ts +83 -0
  24. package/dist/contracts/BaseStateMachine.d.ts.map +1 -0
  25. package/dist/contracts/BaseStateMachine.js +251 -0
  26. package/dist/contracts/BaseStateMachine.js.map +1 -0
  27. package/dist/contracts/GuardController.d.ts +120 -0
  28. package/dist/contracts/GuardController.d.ts.map +1 -0
  29. package/dist/contracts/GuardController.js +149 -0
  30. package/dist/contracts/GuardController.js.map +1 -0
  31. package/dist/contracts/RuntimeRBAC.d.ts +56 -0
  32. package/dist/contracts/RuntimeRBAC.d.ts.map +1 -0
  33. package/dist/contracts/RuntimeRBAC.js +57 -0
  34. package/dist/contracts/RuntimeRBAC.js.map +1 -0
  35. package/dist/contracts/SecureOwnable.d.ts +41 -0
  36. package/dist/contracts/SecureOwnable.d.ts.map +1 -0
  37. package/dist/contracts/SecureOwnable.js +82 -0
  38. package/dist/contracts/SecureOwnable.js.map +1 -0
  39. package/dist/index.d.ts +30 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +32 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/interfaces/base.index.d.ts +18 -0
  44. package/dist/interfaces/base.index.d.ts.map +1 -0
  45. package/dist/interfaces/base.index.js +2 -0
  46. package/dist/interfaces/base.index.js.map +1 -0
  47. package/dist/interfaces/base.state.machine.index.d.ts +72 -0
  48. package/dist/interfaces/base.state.machine.index.d.ts.map +1 -0
  49. package/dist/interfaces/base.state.machine.index.js +2 -0
  50. package/dist/interfaces/base.state.machine.index.js.map +1 -0
  51. package/dist/interfaces/core.access.index.d.ts +37 -0
  52. package/dist/interfaces/core.access.index.d.ts.map +1 -0
  53. package/dist/interfaces/core.access.index.js +2 -0
  54. package/dist/interfaces/core.access.index.js.map +1 -0
  55. package/dist/interfaces/core.execution.index.d.ts +44 -0
  56. package/dist/interfaces/core.execution.index.d.ts.map +1 -0
  57. package/dist/interfaces/core.execution.index.js +2 -0
  58. package/dist/interfaces/core.execution.index.js.map +1 -0
  59. package/dist/interfaces/core.security.index.d.ts +83 -0
  60. package/dist/interfaces/core.security.index.d.ts.map +1 -0
  61. package/dist/interfaces/core.security.index.js +2 -0
  62. package/dist/interfaces/core.security.index.js.map +1 -0
  63. package/dist/interfaces/definition.index.d.ts +38 -0
  64. package/dist/interfaces/definition.index.d.ts.map +1 -0
  65. package/dist/interfaces/definition.index.js +2 -0
  66. package/dist/interfaces/definition.index.js.map +1 -0
  67. package/dist/interfaces/lib.index.d.ts +83 -0
  68. package/dist/interfaces/lib.index.d.ts.map +1 -0
  69. package/dist/interfaces/lib.index.js +2 -0
  70. package/dist/interfaces/lib.index.js.map +1 -0
  71. package/dist/lib/Definition.d.ts +84 -0
  72. package/dist/lib/Definition.d.ts.map +1 -0
  73. package/dist/lib/Definition.js +159 -0
  74. package/dist/lib/Definition.js.map +1 -0
  75. package/dist/lib/EngineBlox.d.ts +167 -0
  76. package/dist/lib/EngineBlox.d.ts.map +1 -0
  77. package/dist/lib/EngineBlox.js +266 -0
  78. package/dist/lib/EngineBlox.js.map +1 -0
  79. package/dist/types/base.state.machine.index.d.ts +45 -0
  80. package/dist/types/base.state.machine.index.d.ts.map +1 -0
  81. package/dist/types/base.state.machine.index.js +49 -0
  82. package/dist/types/base.state.machine.index.js.map +1 -0
  83. package/dist/types/core.access.index.d.ts +51 -0
  84. package/dist/types/core.access.index.d.ts.map +1 -0
  85. package/dist/types/core.access.index.js +41 -0
  86. package/dist/types/core.access.index.js.map +1 -0
  87. package/dist/types/core.execution.index.d.ts +36 -0
  88. package/dist/types/core.execution.index.d.ts.map +1 -0
  89. package/dist/types/core.execution.index.js +30 -0
  90. package/dist/types/core.execution.index.js.map +1 -0
  91. package/dist/types/core.security.index.d.ts +36 -0
  92. package/dist/types/core.security.index.d.ts.map +1 -0
  93. package/dist/types/core.security.index.js +37 -0
  94. package/dist/types/core.security.index.js.map +1 -0
  95. package/dist/types/definition.index.d.ts +36 -0
  96. package/dist/types/definition.index.d.ts.map +1 -0
  97. package/dist/types/definition.index.js +4 -0
  98. package/dist/types/definition.index.js.map +1 -0
  99. package/dist/types/lib.index.d.ts +66 -0
  100. package/dist/types/lib.index.d.ts.map +1 -0
  101. package/dist/types/lib.index.js +68 -0
  102. package/dist/types/lib.index.js.map +1 -0
  103. package/dist/utils/bitmap.d.ts +75 -0
  104. package/dist/utils/bitmap.d.ts.map +1 -0
  105. package/dist/utils/bitmap.js +124 -0
  106. package/dist/utils/bitmap.js.map +1 -0
  107. package/dist/utils/contract-errors.d.ts +536 -0
  108. package/dist/utils/contract-errors.d.ts.map +1 -0
  109. package/dist/utils/contract-errors.js +412 -0
  110. package/dist/utils/contract-errors.js.map +1 -0
  111. package/dist/utils/erc20/ERC20Token.abi.json +217 -0
  112. package/dist/utils/erc20/erc20Token.d.ts +83 -0
  113. package/dist/utils/erc20/erc20Token.d.ts.map +1 -0
  114. package/dist/utils/erc20/erc20Token.js +173 -0
  115. package/dist/utils/erc20/erc20Token.js.map +1 -0
  116. package/dist/utils/interface-ids.d.ts +59 -0
  117. package/dist/utils/interface-ids.d.ts.map +1 -0
  118. package/dist/utils/interface-ids.js +149 -0
  119. package/dist/utils/interface-ids.js.map +1 -0
  120. package/dist/utils/metaTx/metaTransaction.d.ts +138 -0
  121. package/dist/utils/metaTx/metaTransaction.d.ts.map +1 -0
  122. package/dist/utils/metaTx/metaTransaction.js +271 -0
  123. package/dist/utils/metaTx/metaTransaction.js.map +1 -0
  124. package/dist/utils/validations.d.ts +104 -0
  125. package/dist/utils/validations.d.ts.map +1 -0
  126. package/dist/utils/validations.js +254 -0
  127. package/dist/utils/validations.js.map +1 -0
  128. package/dist/utils/viem-error-handler.d.ts +48 -0
  129. package/dist/utils/viem-error-handler.d.ts.map +1 -0
  130. package/dist/utils/viem-error-handler.js +172 -0
  131. package/dist/utils/viem-error-handler.js.map +1 -0
  132. package/package.json +65 -0
package/README.md ADDED
@@ -0,0 +1,338 @@
1
+ # Bloxchain Protocol TypeScript SDK
2
+
3
+ A comprehensive TypeScript SDK for interacting with the Bloxchain Protocol smart contracts, providing type-safe interfaces for secure multi-phase operations, dynamic role-based access control, and state abstraction.
4
+
5
+ ## 🏗️ **Unique Architecture**
6
+
7
+ Bloxchain Protocol implements a **state machine architecture** with `SecureOperationState` as the core engine, providing:
8
+
9
+ - **Centralized State Management**: All security operations flow through a unified state machine
10
+ - **Multi-Phase Transaction Processing**: Time-locked operations with request/approval workflows
11
+ - **Dynamic Role-Based Access Control**: Flexible, hierarchical permission system
12
+ - **Meta-Transaction Support**: Gasless transactions and delegated execution
13
+ - **Event-Driven Architecture**: Comprehensive audit trails and external monitoring
14
+
15
+ ## Features
16
+
17
+ - **SecureOwnable**: Multi-phase ownership management with time-locked operations
18
+ - **RuntimeRBAC**: Runtime role-based access control system with batch configuration
19
+ - **Definitions**: Dynamic interaction with any definition library implementing IDefinition
20
+ - **Guardian**: State abstraction with secure operations
21
+ - **Type Safety**: Full TypeScript support with comprehensive type definitions
22
+ - **Viem Integration**: Built on top of Viem for modern Ethereum development
23
+
24
+ ## 📚 Documentation
25
+
26
+ Comprehensive documentation is available in the [`docs/`](./docs/) directory:
27
+
28
+ ### **🏗️ Architecture & Design**
29
+ - **[Protocol Architecture](./docs/bloxchain-architecture.md)** - Bloxchain protocol overview and design principles
30
+ - **[State Machine Engine](./docs/state-machine-engine.md)** - SecureOperationState engine and state management
31
+ - **[Architecture Patterns](./docs/architecture-patterns.md)** - Design patterns and best practices
32
+
33
+ ### **🚀 Getting Started**
34
+ - **[Getting Started](./docs/getting-started.md)** - Quick setup and basic usage
35
+ - **[API Reference](./docs/api-reference.md)** - Complete API documentation
36
+ - **[SecureOwnable Guide](./docs/secure-ownable.md)** - Ownership management
37
+ - **[RuntimeRBAC Guide](./docs/runtime-rbac.md)** - Role-based access control
38
+
39
+ ### **🔍 Development Tools**
40
+ - **[Best Practices](./docs/best-practices.md)** - Development guidelines
41
+ - **[Examples](./docs/examples-basic.md)** - Practical code samples
42
+ - **[Types & Interfaces](./docs/types-interfaces.md)** - Type definitions
43
+
44
+ **📖 [View All Documentation](./docs/README.md)**
45
+
46
+ ## Installation
47
+
48
+ ```bash
49
+ # Install the SDK package
50
+ npm install @bloxchain/sdk
51
+
52
+ # Or install from the repository
53
+ npm install https://github.com/PracticalParticle/Bloxchain-Protocol.git#main --save
54
+
55
+ # The SDK requires viem as a peer dependency
56
+ npm install viem
57
+ ```
58
+
59
+ ## Quick Start
60
+
61
+ ```typescript
62
+ import {
63
+ SecureOwnable,
64
+ RuntimeRBAC,
65
+ GuardController,
66
+ Definitions,
67
+ type Address,
68
+ type PublicClient,
69
+ type WalletClient,
70
+ type Chain
71
+ } from '@bloxchain/sdk';
72
+
73
+ // Initialize clients (using your preferred provider)
74
+ const publicClient: PublicClient = createPublicClient({...});
75
+ const walletClient: WalletClient = createWalletClient({...});
76
+ const chain: Chain = mainnet; // or your target chain
77
+
78
+ // Initialize SDK classes
79
+ const secureOwnable = new SecureOwnable(
80
+ publicClient,
81
+ walletClient,
82
+ contractAddress,
83
+ chain
84
+ );
85
+
86
+ const runtimeRBAC = new RuntimeRBAC(
87
+ publicClient,
88
+ walletClient,
89
+ contractAddress,
90
+ chain
91
+ );
92
+
93
+ const definitions = new Definitions(
94
+ publicClient,
95
+ walletClient,
96
+ definitionsAddress,
97
+ chain
98
+ );
99
+ ```
100
+
101
+ ## SecureOwnable Usage
102
+
103
+ ### Ownership Management
104
+
105
+ ```typescript
106
+ // Request ownership transfer
107
+ const txResult = await secureOwnable.transferOwnershipRequest({
108
+ from: ownerAddress
109
+ });
110
+
111
+ // Approve after time lock period
112
+ const approvalResult = await secureOwnable.transferOwnershipDelayedApproval(
113
+ txId,
114
+ { from: ownerAddress }
115
+ );
116
+
117
+ // Cancel ownership transfer
118
+ const cancelResult = await secureOwnable.transferOwnershipCancellation(
119
+ txId,
120
+ { from: ownerAddress }
121
+ );
122
+ ```
123
+
124
+ ### Meta Transactions
125
+
126
+ ```typescript
127
+ // Create meta transaction parameters
128
+ const metaTxParams = await secureOwnable.createMetaTxParams(
129
+ handlerContract,
130
+ handlerSelector,
131
+ deadline,
132
+ maxGasPrice,
133
+ signer
134
+ );
135
+
136
+ // Generate unsigned meta transaction
137
+ const metaTx = await secureOwnable.generateUnsignedMetaTransactionForNew(
138
+ requester,
139
+ target,
140
+ value,
141
+ gasLimit,
142
+ operationType,
143
+ executionType,
144
+ executionOptions,
145
+ metaTxParams
146
+ );
147
+ ```
148
+
149
+ ## RuntimeRBAC Usage
150
+
151
+ RuntimeRBAC uses batch-based configuration for all role management operations. See the [RuntimeRBAC Guide](./docs/runtime-rbac.md) for complete examples.
152
+
153
+ ### Query Functions
154
+
155
+ ```typescript
156
+ // Get role information
157
+ const role = await runtimeRBAC.getRole(roleHash);
158
+ console.log(role.roleName, role.maxWallets, role.isProtected);
159
+
160
+ // Check if wallet has role
161
+ const hasRole = await runtimeRBAC.hasRole(roleHash, walletAddress);
162
+
163
+ // Get wallets in role
164
+ const wallets = await runtimeRBAC.getWalletsInRole(roleHash);
165
+
166
+ // Get roles for a wallet
167
+ const walletRoles = await runtimeRBAC.getWalletRoles(walletAddress);
168
+
169
+ // Get supported roles
170
+ const supportedRoles = await runtimeRBAC.getSupportedRoles();
171
+
172
+ // Get active role permissions
173
+ const permissions = await runtimeRBAC.getActiveRolePermissions(roleHash);
174
+ ```
175
+
176
+ ### Batch Configuration
177
+
178
+ All role management (create role, add wallet, add permissions, etc.) is done via batch operations. See the [RuntimeRBAC Guide](./docs/runtime-rbac.md) for detailed batch configuration examples.
179
+
180
+ ## Definitions Usage
181
+
182
+ The `Definitions` class provides dynamic interaction with any definition library that implements the `IDefinition` interface. This allows you to query operation types, function schemas, role permissions, and workflow definitions from any compatible contract.
183
+
184
+ ### Basic Usage
185
+
186
+ ```typescript
187
+ // Initialize Definitions
188
+ const definitions = new Definitions(
189
+ publicClient,
190
+ walletClient,
191
+ definitionsAddress,
192
+ chain
193
+ );
194
+
195
+ // Get all operation types
196
+ const operationTypes = await definitions.getOperationTypes();
197
+ console.log('Available operations:', operationTypes);
198
+
199
+ // Get all function schemas
200
+ const functionSchemas = await definitions.getFunctionSchemas();
201
+ console.log('Function schemas:', functionSchemas);
202
+
203
+ // Get role permissions
204
+ const rolePermissions = await definitions.getRolePermissions();
205
+ console.log('Role permissions:', rolePermissions);
206
+ ```
207
+
208
+ ### Workflow Management
209
+
210
+ ```typescript
211
+ // Get all operation workflows
212
+ const workflows = await definitions.getOperationWorkflows();
213
+ console.log('Available workflows:', workflows);
214
+
215
+ // Get workflow for specific operation
216
+ const operationType = '0x1234...'; // operation type hash
217
+ const workflow = await definitions.getWorkflowForOperation(operationType);
218
+ console.log('Workflow for operation:', workflow);
219
+
220
+ // Get all workflow paths
221
+ const paths = await definitions.getWorkflowPaths();
222
+ console.log('Available paths:', paths);
223
+ ```
224
+
225
+ ### Utility Functions
226
+
227
+ ```typescript
228
+ // Find operation type by name
229
+ const operationType = await definitions.getOperationTypeByName('TRANSFER_OWNERSHIP');
230
+ console.log('Operation type hash:', operationType);
231
+
232
+ // Get function schema by selector
233
+ const functionSelector = '0xabcd...';
234
+ const schema = await definitions.getFunctionSchemaBySelector(functionSelector);
235
+ console.log('Function schema:', schema);
236
+
237
+ // Check role permission for function
238
+ const roleHash = '0xefgh...';
239
+ const hasPermission = await definitions.hasRolePermission(roleHash, functionSelector);
240
+ console.log('Has permission:', hasPermission);
241
+
242
+ // Get all roles that can execute a function
243
+ const allowedRoles = await definitions.getRolesForFunction(functionSelector);
244
+ console.log('Allowed roles:', allowedRoles);
245
+ ```
246
+
247
+ ### Configuration Management
248
+
249
+ ```typescript
250
+ // Get current configuration
251
+ const config = definitions.getConfig();
252
+ console.log('Current config:', config);
253
+
254
+ // Update configuration
255
+ definitions.updateConfig({
256
+ chainId: 137, // Polygon
257
+ rpcUrl: 'https://polygon-rpc.com'
258
+ });
259
+ ```
260
+
261
+ ## Types and Constants
262
+
263
+ ### Transaction Actions
264
+
265
+ ```typescript
266
+ import { TxAction } from './types/lib.index';
267
+
268
+ // Available transaction actions
269
+ TxAction.EXECUTE_TIME_DELAY_REQUEST
270
+ TxAction.EXECUTE_TIME_DELAY_APPROVE
271
+ TxAction.EXECUTE_TIME_DELAY_CANCEL
272
+ TxAction.SIGN_META_REQUEST_AND_APPROVE
273
+ TxAction.SIGN_META_APPROVE
274
+ TxAction.SIGN_META_CANCEL
275
+ TxAction.EXECUTE_META_REQUEST_AND_APPROVE
276
+ TxAction.EXECUTE_META_APPROVE
277
+ TxAction.EXECUTE_META_CANCEL
278
+ ```
279
+
280
+ ### Execution Types
281
+
282
+ ```typescript
283
+ import { ExecutionType } from './types/lib.index';
284
+
285
+ ExecutionType.NONE
286
+ ExecutionType.STANDARD
287
+ ExecutionType.RAW
288
+ ```
289
+
290
+ ### Transaction Status
291
+
292
+ ```typescript
293
+ import { TxStatus } from './types/lib.index';
294
+
295
+ TxStatus.UNDEFINED
296
+ TxStatus.PENDING
297
+ TxStatus.CANCELLED
298
+ TxStatus.COMPLETED
299
+ TxStatus.FAILED
300
+ TxStatus.REJECTED
301
+ ```
302
+
303
+ ## Error Handling
304
+
305
+ All SDK methods throw errors for failed operations. Always wrap SDK calls in try-catch blocks:
306
+
307
+ ```typescript
308
+ try {
309
+ const result = await secureOwnable.transferOwnershipRequest({
310
+ from: ownerAddress
311
+ });
312
+ console.log('Transaction successful:', result.hash);
313
+ } catch (error) {
314
+ console.error('Transaction failed:', error);
315
+ }
316
+ ```
317
+
318
+ ## Security Considerations
319
+
320
+ - Always validate addresses and parameters before making transactions
321
+ - Use proper time-lock periods for critical operations
322
+ - Implement proper access control using RuntimeRBAC
323
+ - Monitor transaction status and handle failures appropriately
324
+ - Keep private keys secure and never expose them in client-side code
325
+
326
+ ## Contributing
327
+
328
+ When contributing to the SDK:
329
+
330
+ 1. Follow TypeScript best practices
331
+ 2. Add comprehensive type definitions
332
+ 3. Include JSDoc comments for all public methods
333
+ 4. Test all new functionality thoroughly
334
+ 5. Update this README with new features
335
+
336
+ ## License
337
+
338
+ This SDK is part of the Bloxchain Protocol and follows the same licensing terms.