@bloxchain/sdk 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 (129) hide show
  1. package/README.md +376 -376
  2. package/abi/AccountBlox.abi.json +609 -2479
  3. package/abi/BareBlox.abi.json +94 -0
  4. package/abi/BaseStateMachine.abi.json +85 -45
  5. package/abi/CopyBlox.abi.json +1593 -0
  6. package/abi/EngineBlox.abi.json +73 -90
  7. package/abi/GuardController.abi.json +252 -806
  8. package/abi/GuardControllerDefinitions.abi.json +411 -0
  9. package/abi/IDefinition.abi.json +5 -0
  10. package/abi/RoleBlox.abi.json +375 -1590
  11. package/abi/RuntimeRBAC.abi.json +155 -218
  12. package/abi/RuntimeRBACDefinitions.abi.json +179 -0
  13. package/abi/SecureBlox.abi.json +436 -1511
  14. package/abi/SecureOwnable.abi.json +524 -1621
  15. package/abi/SecureOwnableDefinitions.abi.json +5 -0
  16. package/abi/SimpleRWA20.abi.json +478 -1756
  17. package/abi/SimpleRWA20Definitions.abi.json +5 -0
  18. package/abi/SimpleVault.abi.json +648 -2214
  19. package/abi/SimpleVaultDefinitions.abi.json +5 -0
  20. package/dist/abi/AccountBlox.abi.json +3929 -0
  21. package/dist/abi/BareBlox.abi.json +1378 -0
  22. package/dist/abi/BaseStateMachine.abi.json +1213 -1173
  23. package/dist/abi/CopyBlox.abi.json +1593 -0
  24. package/dist/abi/EngineBlox.abi.json +855 -0
  25. package/dist/abi/GuardController.abi.json +2222 -2776
  26. package/dist/abi/GuardControllerDefinitions.abi.json +411 -0
  27. package/dist/abi/IDefinition.abi.json +113 -108
  28. package/dist/abi/RoleBlox.abi.json +2994 -0
  29. package/dist/abi/RuntimeRBAC.abi.json +1540 -1603
  30. package/dist/abi/RuntimeRBACDefinitions.abi.json +381 -0
  31. package/dist/abi/SecureBlox.abi.json +2753 -0
  32. package/dist/abi/SecureOwnable.abi.json +2585 -3682
  33. package/dist/abi/SecureOwnableDefinitions.abi.json +416 -0
  34. package/dist/abi/SimpleRWA20.abi.json +4010 -0
  35. package/dist/abi/SimpleRWA20Definitions.abi.json +196 -0
  36. package/dist/abi/SimpleVault.abi.json +3385 -0
  37. package/dist/abi/SimpleVaultDefinitions.abi.json +274 -0
  38. package/dist/abi.d.ts +11 -0
  39. package/dist/abi.d.ts.map +1 -0
  40. package/dist/abi.js +10 -0
  41. package/dist/abi.js.map +1 -0
  42. package/dist/contracts/{BaseStateMachine.d.ts → core/BaseStateMachine.d.ts} +20 -6
  43. package/dist/contracts/core/BaseStateMachine.d.ts.map +1 -0
  44. package/dist/contracts/{BaseStateMachine.js → core/BaseStateMachine.js} +88 -38
  45. package/dist/contracts/core/BaseStateMachine.js.map +1 -0
  46. package/dist/contracts/{GuardController.d.ts → core/GuardController.d.ts} +22 -15
  47. package/dist/contracts/core/GuardController.d.ts.map +1 -0
  48. package/dist/contracts/{GuardController.js → core/GuardController.js} +19 -21
  49. package/dist/contracts/core/GuardController.js.map +1 -0
  50. package/dist/contracts/core/RuntimeRBAC.d.ts +27 -0
  51. package/dist/contracts/core/RuntimeRBAC.d.ts.map +1 -0
  52. package/dist/contracts/core/RuntimeRBAC.js +33 -0
  53. package/dist/contracts/core/RuntimeRBAC.js.map +1 -0
  54. package/dist/contracts/{SecureOwnable.d.ts → core/SecureOwnable.d.ts} +5 -15
  55. package/dist/contracts/core/SecureOwnable.d.ts.map +1 -0
  56. package/dist/contracts/{SecureOwnable.js → core/SecureOwnable.js} +4 -23
  57. package/dist/contracts/core/SecureOwnable.js.map +1 -0
  58. package/dist/index.d.ts +8 -7
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +6 -6
  61. package/dist/index.js.map +1 -1
  62. package/dist/interfaces/base.index.d.ts +10 -2
  63. package/dist/interfaces/base.index.d.ts.map +1 -1
  64. package/dist/interfaces/base.state.machine.index.d.ts +3 -2
  65. package/dist/interfaces/base.state.machine.index.d.ts.map +1 -1
  66. package/dist/interfaces/core.access.index.d.ts +2 -16
  67. package/dist/interfaces/core.access.index.d.ts.map +1 -1
  68. package/dist/interfaces/core.execution.index.d.ts +8 -11
  69. package/dist/interfaces/core.execution.index.d.ts.map +1 -1
  70. package/dist/interfaces/core.security.index.d.ts +1 -4
  71. package/dist/interfaces/core.security.index.d.ts.map +1 -1
  72. package/dist/lib/Definition.d.ts.map +1 -1
  73. package/dist/lib/Definition.js +1 -0
  74. package/dist/lib/Definition.js.map +1 -1
  75. package/dist/lib/EngineBlox.d.ts +16 -49
  76. package/dist/lib/EngineBlox.d.ts.map +1 -1
  77. package/dist/lib/EngineBlox.js +20 -108
  78. package/dist/lib/EngineBlox.js.map +1 -1
  79. package/dist/lib/definitions/GuardControllerDefinitions.d.ts +34 -7
  80. package/dist/lib/definitions/GuardControllerDefinitions.d.ts.map +1 -1
  81. package/dist/lib/definitions/GuardControllerDefinitions.js +62 -10
  82. package/dist/lib/definitions/GuardControllerDefinitions.js.map +1 -1
  83. package/dist/lib/definitions/RuntimeRBACDefinitions.d.ts +48 -7
  84. package/dist/lib/definitions/RuntimeRBACDefinitions.d.ts.map +1 -1
  85. package/dist/lib/definitions/RuntimeRBACDefinitions.js +73 -10
  86. package/dist/lib/definitions/RuntimeRBACDefinitions.js.map +1 -1
  87. package/dist/lib/definitions/SecureOwnableDefinitions.d.ts +12 -7
  88. package/dist/lib/definitions/SecureOwnableDefinitions.d.ts.map +1 -1
  89. package/dist/lib/definitions/SecureOwnableDefinitions.js +25 -9
  90. package/dist/lib/definitions/SecureOwnableDefinitions.js.map +1 -1
  91. package/dist/lib/definitions/index.d.ts +6 -4
  92. package/dist/lib/definitions/index.d.ts.map +1 -1
  93. package/dist/lib/definitions/index.js +5 -4
  94. package/dist/lib/definitions/index.js.map +1 -1
  95. package/dist/types/base.state.machine.index.d.ts +0 -2
  96. package/dist/types/base.state.machine.index.d.ts.map +1 -1
  97. package/dist/types/base.state.machine.index.js +1 -3
  98. package/dist/types/base.state.machine.index.js.map +1 -1
  99. package/dist/types/core.execution.index.d.ts +1 -0
  100. package/dist/types/core.execution.index.d.ts.map +1 -1
  101. package/dist/types/core.execution.index.js +1 -0
  102. package/dist/types/core.execution.index.js.map +1 -1
  103. package/dist/types/core.security.index.d.ts.map +1 -1
  104. package/dist/types/core.security.index.js +2 -2
  105. package/dist/types/core.security.index.js.map +1 -1
  106. package/dist/types/definition.index.d.ts +2 -0
  107. package/dist/types/definition.index.d.ts.map +1 -1
  108. package/dist/types/definition.index.js.map +1 -1
  109. package/dist/utils/contract-errors.d.ts +125 -6
  110. package/dist/utils/contract-errors.d.ts.map +1 -1
  111. package/dist/utils/contract-errors.js +375 -107
  112. package/dist/utils/contract-errors.js.map +1 -1
  113. package/dist/utils/interface-ids.js +8 -8
  114. package/dist/utils/interface-ids.js.map +1 -1
  115. package/dist/utils/metaTx/metaTransaction.d.ts +103 -7
  116. package/dist/utils/metaTx/metaTransaction.d.ts.map +1 -1
  117. package/dist/utils/metaTx/metaTransaction.js +136 -25
  118. package/dist/utils/metaTx/metaTransaction.js.map +1 -1
  119. package/package.json +10 -6
  120. package/dist/contracts/BaseStateMachine.d.ts.map +0 -1
  121. package/dist/contracts/BaseStateMachine.js.map +0 -1
  122. package/dist/contracts/GuardController.d.ts.map +0 -1
  123. package/dist/contracts/GuardController.js.map +0 -1
  124. package/dist/contracts/RuntimeRBAC.d.ts +0 -54
  125. package/dist/contracts/RuntimeRBAC.d.ts.map +0 -1
  126. package/dist/contracts/RuntimeRBAC.js +0 -58
  127. package/dist/contracts/RuntimeRBAC.js.map +0 -1
  128. package/dist/contracts/SecureOwnable.d.ts.map +0 -1
  129. package/dist/contracts/SecureOwnable.js.map +0 -1
package/README.md CHANGED
@@ -1,376 +1,376 @@
1
- # Bloxchain Protocol TypeScript SDK
2
-
3
- [![npm version](https://img.shields.io/npm/v/@bloxchain/sdk.svg)](https://www.npmjs.com/package/@bloxchain/sdk)
4
- [![License: MPL-2.0](https://img.shields.io/badge/License-MPL--2.0-blue.svg)](https://opensource.org/licenses/MPL-2.0)
5
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue.svg)](https://www.typescriptlang.org/)
6
- [![Node](https://img.shields.io/badge/Node-%3E%3D18.0.0-green.svg)](https://nodejs.org/)
7
-
8
- 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.
9
-
10
- > **⚠️ EXPERIMENTAL SOFTWARE WARNING**
11
- > This package contains experimental smart contract code and SDK support. While the framework is feature-complete and tested, it is not yet audited for production use. Use at your own risk and do not deploy with real assets without proper security review.
12
-
13
- ## Requirements
14
-
15
- - **Node.js**: >= 18.0.0
16
- - **TypeScript**: 5.x (recommended)
17
- - **Peer dependency**: `viem` ^2.0.0 (required for all SDK usage)
18
- - **Optional peer**: `@bloxchain/contracts` ^1.0.0-alpha (for Solidity/ABI alignment when building apps that use both)
19
-
20
- ## 🏗️ **Unique Architecture**
21
-
22
- Bloxchain Protocol implements a **state machine architecture** with `SecureOperationState` as the core engine, providing:
23
-
24
- - **Centralized State Management**: All security operations flow through a unified state machine
25
- - **Multi-Phase Transaction Processing**: Time-locked operations with request/approval workflows
26
- - **Dynamic Role-Based Access Control**: Flexible, hierarchical permission system
27
- - **Meta-Transaction Support**: Gasless transactions and delegated execution
28
- - **Event-Driven Architecture**: Comprehensive audit trails and external monitoring
29
-
30
- ## Features
31
-
32
- - **SecureOwnable**: Multi-phase ownership management with time-locked operations
33
- - **RuntimeRBAC**: Runtime role-based access control system with batch configuration
34
- - **Definitions**: Dynamic interaction with any definition library implementing IDefinition
35
- - **Guardian**: State abstraction with secure operations
36
- - **Type Safety**: Full TypeScript support with comprehensive type definitions
37
- - **Viem Integration**: Built on top of Viem for modern Ethereum development
38
-
39
- ## 📚 Documentation
40
-
41
- Comprehensive documentation is available in the [`docs/`](./docs/) directory:
42
-
43
- ### **🏗️ Architecture & Design**
44
- - **[Protocol Architecture](./docs/bloxchain-architecture.md)** - Bloxchain protocol overview and design principles
45
- - **[State Machine Engine](./docs/state-machine-engine.md)** - SecureOperationState engine and state management
46
- - **[Architecture Patterns](./docs/architecture-patterns.md)** - Design patterns and best practices
47
-
48
- ### **🚀 Getting Started**
49
- - **[Getting Started](./docs/getting-started.md)** - Quick setup and basic usage
50
- - **[API Reference](./docs/api-reference.md)** - Complete API documentation
51
- - **[SecureOwnable Guide](./docs/secure-ownable.md)** - Ownership management
52
- - **[RuntimeRBAC Guide](./docs/runtime-rbac.md)** - Role-based access control
53
-
54
- ### **🔍 Development Tools**
55
- - **[Best Practices](./docs/best-practices.md)** - Development guidelines
56
- - **[Examples](./docs/examples-basic.md)** - Practical code samples
57
- - **[Types & Interfaces](./docs/types-interfaces.md)** - Type definitions
58
-
59
- **📖 [View All Documentation](./docs/README.md)**
60
-
61
- ## Installation
62
-
63
- ```bash
64
- # Install the SDK and its required peer dependency
65
- npm install @bloxchain/sdk viem
66
-
67
- # Optional: install contracts package when building apps that use both SDK and Solidity
68
- npm install @bloxchain/contracts
69
- ```
70
-
71
- To install from the repository (e.g. for development):
72
-
73
- ```bash
74
- npm install https://github.com/PracticalParticle/Bloxchain-Protocol.git#main --save
75
- ```
76
-
77
- ## Quick Start
78
-
79
- ```typescript
80
- import {
81
- SecureOwnable,
82
- RuntimeRBAC,
83
- GuardController,
84
- Definitions,
85
- type Address,
86
- type PublicClient,
87
- type WalletClient,
88
- type Chain
89
- } from '@bloxchain/sdk';
90
-
91
- // Initialize clients (using your preferred provider)
92
- const publicClient: PublicClient = createPublicClient({...});
93
- const walletClient: WalletClient = createWalletClient({...});
94
- const chain: Chain = mainnet; // or your target chain
95
-
96
- // Initialize SDK classes
97
- const secureOwnable = new SecureOwnable(
98
- publicClient,
99
- walletClient,
100
- contractAddress,
101
- chain
102
- );
103
-
104
- const runtimeRBAC = new RuntimeRBAC(
105
- publicClient,
106
- walletClient,
107
- contractAddress,
108
- chain
109
- );
110
-
111
- const definitions = new Definitions(
112
- publicClient,
113
- walletClient,
114
- definitionsAddress,
115
- chain
116
- );
117
- ```
118
-
119
- ## SecureOwnable Usage
120
-
121
- ### Ownership Management
122
-
123
- ```typescript
124
- // Request ownership transfer
125
- const txResult = await secureOwnable.transferOwnershipRequest({
126
- from: ownerAddress
127
- });
128
-
129
- // Approve after time lock period
130
- const approvalResult = await secureOwnable.transferOwnershipDelayedApproval(
131
- txId,
132
- { from: ownerAddress }
133
- );
134
-
135
- // Cancel ownership transfer
136
- const cancelResult = await secureOwnable.transferOwnershipCancellation(
137
- txId,
138
- { from: ownerAddress }
139
- );
140
- ```
141
-
142
- ### Meta Transactions
143
-
144
- ```typescript
145
- // Create meta transaction parameters
146
- const metaTxParams = await secureOwnable.createMetaTxParams(
147
- handlerContract,
148
- handlerSelector,
149
- deadline,
150
- maxGasPrice,
151
- signer
152
- );
153
-
154
- // Generate unsigned meta transaction
155
- const metaTx = await secureOwnable.generateUnsignedMetaTransactionForNew(
156
- requester,
157
- target,
158
- value,
159
- gasLimit,
160
- operationType,
161
- executionType,
162
- executionOptions,
163
- metaTxParams
164
- );
165
- ```
166
-
167
- ## RuntimeRBAC Usage
168
-
169
- RuntimeRBAC uses batch-based configuration for all role management operations. See the [RuntimeRBAC Guide](./docs/runtime-rbac.md) for complete examples.
170
-
171
- ### Query Functions
172
-
173
- ```typescript
174
- // Get role information
175
- const role = await runtimeRBAC.getRole(roleHash);
176
- console.log(role.roleName, role.maxWallets, role.isProtected);
177
-
178
- // Check if wallet has role
179
- const hasRole = await runtimeRBAC.hasRole(roleHash, walletAddress);
180
-
181
- // Get wallets in role
182
- const wallets = await runtimeRBAC.getWalletsInRole(roleHash);
183
-
184
- // Get roles for a wallet
185
- const walletRoles = await runtimeRBAC.getWalletRoles(walletAddress);
186
-
187
- // Get supported roles
188
- const supportedRoles = await runtimeRBAC.getSupportedRoles();
189
-
190
- // Get active role permissions
191
- const permissions = await runtimeRBAC.getActiveRolePermissions(roleHash);
192
- ```
193
-
194
- ### Batch Configuration
195
-
196
- 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.
197
-
198
- ## Definitions Usage
199
-
200
- 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.
201
-
202
- ### Basic Usage
203
-
204
- ```typescript
205
- // Initialize Definitions
206
- const definitions = new Definitions(
207
- publicClient,
208
- walletClient,
209
- definitionsAddress,
210
- chain
211
- );
212
-
213
- // Get all operation types
214
- const operationTypes = await definitions.getOperationTypes();
215
- console.log('Available operations:', operationTypes);
216
-
217
- // Get all function schemas
218
- const functionSchemas = await definitions.getFunctionSchemas();
219
- console.log('Function schemas:', functionSchemas);
220
-
221
- // Get role permissions
222
- const rolePermissions = await definitions.getRolePermissions();
223
- console.log('Role permissions:', rolePermissions);
224
- ```
225
-
226
- ### Workflow Management
227
-
228
- ```typescript
229
- // Get all operation workflows
230
- const workflows = await definitions.getOperationWorkflows();
231
- console.log('Available workflows:', workflows);
232
-
233
- // Get workflow for specific operation
234
- const operationType = '0x1234...'; // operation type hash
235
- const workflow = await definitions.getWorkflowForOperation(operationType);
236
- console.log('Workflow for operation:', workflow);
237
-
238
- // Get all workflow paths
239
- const paths = await definitions.getWorkflowPaths();
240
- console.log('Available paths:', paths);
241
- ```
242
-
243
- ### Utility Functions
244
-
245
- ```typescript
246
- // Find operation type by name
247
- const operationType = await definitions.getOperationTypeByName('TRANSFER_OWNERSHIP');
248
- console.log('Operation type hash:', operationType);
249
-
250
- // Get function schema by selector
251
- const functionSelector = '0xabcd...';
252
- const schema = await definitions.getFunctionSchemaBySelector(functionSelector);
253
- console.log('Function schema:', schema);
254
-
255
- // Check role permission for function
256
- const roleHash = '0xefgh...';
257
- const hasPermission = await definitions.hasRolePermission(roleHash, functionSelector);
258
- console.log('Has permission:', hasPermission);
259
-
260
- // Get all roles that can execute a function
261
- const allowedRoles = await definitions.getRolesForFunction(functionSelector);
262
- console.log('Allowed roles:', allowedRoles);
263
- ```
264
-
265
- ### Configuration Management
266
-
267
- ```typescript
268
- // Get current configuration
269
- const config = definitions.getConfig();
270
- console.log('Current config:', config);
271
-
272
- // Update configuration
273
- definitions.updateConfig({
274
- chainId: 137, // Polygon
275
- rpcUrl: 'https://polygon-rpc.com'
276
- });
277
- ```
278
-
279
- ## Types and Constants
280
-
281
- ### Transaction Actions
282
-
283
- ```typescript
284
- import { TxAction } from '@bloxchain/sdk';
285
-
286
- // Available transaction actions
287
- TxAction.EXECUTE_TIME_DELAY_REQUEST
288
- TxAction.EXECUTE_TIME_DELAY_APPROVE
289
- TxAction.EXECUTE_TIME_DELAY_CANCEL
290
- TxAction.SIGN_META_REQUEST_AND_APPROVE
291
- TxAction.SIGN_META_APPROVE
292
- TxAction.SIGN_META_CANCEL
293
- TxAction.EXECUTE_META_REQUEST_AND_APPROVE
294
- TxAction.EXECUTE_META_APPROVE
295
- TxAction.EXECUTE_META_CANCEL
296
- ```
297
-
298
- ### Execution Types
299
-
300
- ```typescript
301
- import { ExecutionType } from '@bloxchain/sdk';
302
-
303
- ExecutionType.NONE
304
- ExecutionType.STANDARD
305
- ExecutionType.RAW
306
- ```
307
-
308
- ### Transaction Status
309
-
310
- ```typescript
311
- import { TxStatus } from '@bloxchain/sdk';
312
-
313
- TxStatus.UNDEFINED
314
- TxStatus.PENDING
315
- TxStatus.CANCELLED
316
- TxStatus.COMPLETED
317
- TxStatus.FAILED
318
- TxStatus.REJECTED
319
- ```
320
-
321
- ## Error Handling
322
-
323
- All SDK methods throw errors for failed operations. Always wrap SDK calls in try-catch blocks:
324
-
325
- ```typescript
326
- try {
327
- const result = await secureOwnable.transferOwnershipRequest({
328
- from: ownerAddress
329
- });
330
- console.log('Transaction successful:', result.hash);
331
- } catch (error) {
332
- console.error('Transaction failed:', error);
333
- }
334
- ```
335
-
336
- ## Security Considerations
337
-
338
- - Always validate addresses and parameters before making transactions
339
- - Use proper time-lock periods for critical operations
340
- - Implement proper access control using RuntimeRBAC
341
- - Monitor transaction status and handle failures appropriately
342
- - Keep private keys secure and never expose them in client-side code
343
-
344
- ## Versioning and stability
345
-
346
- This package follows [Semantic Versioning](https://semver.org/). Current versions are **alpha** (`1.0.0-alpha.x`). Pre-1.0 releases may introduce breaking changes; we recommend pinning the exact version until the protocol is audited and stable.
347
-
348
- ## Security
349
-
350
- - **Vulnerability reporting**: Do not open public GitHub issues for security vulnerabilities. See the [Security Policy](https://github.com/PracticalParticle/Bloxchain-Protocol/blob/main/SECURITY.md) for reporting instructions (e.g. security@particlecs.com).
351
- - **Audit status**: The underlying protocol is not yet audited. Do not use with mainnet assets without an independent security review.
352
-
353
- ## Support and links
354
-
355
- - **Documentation**: [SDK docs](./docs/) in this package; [Bloxchain Protocol README](https://github.com/PracticalParticle/Bloxchain-Protocol#readme) for protocol details
356
- - **Issues and feature requests**: [GitHub Issues](https://github.com/PracticalParticle/Bloxchain-Protocol/issues)
357
- - **Homepage**: [bloxchain.app](https://bloxchain.app/)
358
- - **Author**: [Particle Crypto Security](https://particlecs.com/)
359
-
360
- ## Repository
361
-
362
- Part of [Bloxchain Protocol](https://github.com/PracticalParticle/Bloxchain-Protocol). For protocol architecture and contract documentation, see the main repository README.
363
-
364
- ## Contributing
365
-
366
- When contributing to the SDK:
367
-
368
- 1. Follow TypeScript best practices
369
- 2. Add comprehensive type definitions
370
- 3. Include JSDoc comments for all public methods
371
- 4. Test all new functionality thoroughly
372
- 5. Update this README with new features
373
-
374
- ## License
375
-
376
- MPL-2.0 (Mozilla Public License 2.0). This SDK is part of the Bloxchain Protocol. See the [LICENSE](https://github.com/PracticalParticle/Bloxchain-Protocol/blob/main/LICENSE) file in the main repository.
1
+ # Bloxchain Protocol TypeScript SDK
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@bloxchain/sdk.svg)](https://www.npmjs.com/package/@bloxchain/sdk)
4
+ [![License: MPL-2.0](https://img.shields.io/badge/License-MPL--2.0-blue.svg)](https://opensource.org/licenses/MPL-2.0)
5
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-blue.svg)](https://www.typescriptlang.org/)
6
+ [![Node](https://img.shields.io/badge/Node-%3E%3D18.0.0-green.svg)](https://nodejs.org/)
7
+
8
+ 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.
9
+
10
+ > **⚠️ EXPERIMENTAL SOFTWARE WARNING**
11
+ > This package contains experimental smart contract code and SDK support. While the framework is feature-complete and tested, it is not yet audited for production use. Use at your own risk and do not deploy with real assets without proper security review.
12
+
13
+ ## Requirements
14
+
15
+ - **Node.js**: >= 18.0.0
16
+ - **TypeScript**: 5.x (recommended)
17
+ - **Peer dependency**: `viem` ^2.0.0 (required for all SDK usage)
18
+ - **Optional peer**: `@bloxchain/contracts` ^1.0.0-alpha (for Solidity/ABI alignment when building apps that use both)
19
+
20
+ ## 🏗️ **Unique Architecture**
21
+
22
+ Bloxchain Protocol implements a **state machine architecture** with `SecureOperationState` as the core engine, providing:
23
+
24
+ - **Centralized State Management**: All security operations flow through a unified state machine
25
+ - **Multi-Phase Transaction Processing**: Time-locked operations with request/approval workflows
26
+ - **Dynamic Role-Based Access Control**: Flexible, hierarchical permission system
27
+ - **Meta-Transaction Support**: Gasless transactions and delegated execution
28
+ - **Event-Driven Architecture**: Comprehensive audit trails and external monitoring
29
+
30
+ ## Features
31
+
32
+ - **SecureOwnable**: Multi-phase ownership management with time-locked operations
33
+ - **RuntimeRBAC**: Runtime role-based access control system with batch configuration
34
+ - **Definitions**: Dynamic interaction with any definition library implementing IDefinition
35
+ - **Guardian**: State abstraction with secure operations
36
+ - **Type Safety**: Full TypeScript support with comprehensive type definitions
37
+ - **Viem Integration**: Built on top of Viem for modern Ethereum development
38
+
39
+ ## 📚 Documentation
40
+
41
+ Comprehensive documentation is available in the [`docs/`](./docs/) directory:
42
+
43
+ ### **🏗️ Architecture & Design**
44
+ - **[Protocol Architecture](./docs/bloxchain-architecture.md)** - Bloxchain protocol overview and design principles
45
+ - **[State Machine Engine](./docs/state-machine-engine.md)** - SecureOperationState engine and state management
46
+ - **[Architecture Patterns](./docs/architecture-patterns.md)** - Design patterns and best practices
47
+
48
+ ### **🚀 Getting Started**
49
+ - **[Getting Started](./docs/getting-started.md)** - Quick setup and basic usage
50
+ - **[API Reference](./docs/api-reference.md)** - Complete API documentation
51
+ - **[SecureOwnable Guide](./docs/secure-ownable.md)** - Ownership management
52
+ - **[RuntimeRBAC Guide](./docs/runtime-rbac.md)** - Role-based access control
53
+
54
+ ### **🔍 Development Tools**
55
+ - **[Best Practices](./docs/best-practices.md)** - Development guidelines
56
+ - **[Examples](./docs/examples-basic.md)** - Practical code samples
57
+ - **[Types & Interfaces](./docs/types-interfaces.md)** - Type definitions
58
+
59
+ **📖 [View All Documentation](./docs/README.md)**
60
+
61
+ ## Installation
62
+
63
+ ```bash
64
+ # Install the SDK and its required peer dependency
65
+ npm install @bloxchain/sdk viem
66
+
67
+ # Optional: install contracts package when building apps that use both SDK and Solidity
68
+ npm install @bloxchain/contracts
69
+ ```
70
+
71
+ To install from the repository (e.g. for development):
72
+
73
+ ```bash
74
+ npm install https://github.com/PracticalParticle/Bloxchain-Protocol.git#main --save
75
+ ```
76
+
77
+ ## Quick Start
78
+
79
+ ```typescript
80
+ import {
81
+ SecureOwnable,
82
+ RuntimeRBAC,
83
+ GuardController,
84
+ Definitions,
85
+ type Address,
86
+ type PublicClient,
87
+ type WalletClient,
88
+ type Chain
89
+ } from '@bloxchain/sdk';
90
+
91
+ // Initialize clients (using your preferred provider)
92
+ const publicClient: PublicClient = createPublicClient({...});
93
+ const walletClient: WalletClient = createWalletClient({...});
94
+ const chain: Chain = mainnet; // or your target chain
95
+
96
+ // Initialize SDK classes
97
+ const secureOwnable = new SecureOwnable(
98
+ publicClient,
99
+ walletClient,
100
+ contractAddress,
101
+ chain
102
+ );
103
+
104
+ const runtimeRBAC = new RuntimeRBAC(
105
+ publicClient,
106
+ walletClient,
107
+ contractAddress,
108
+ chain
109
+ );
110
+
111
+ const definitions = new Definitions(
112
+ publicClient,
113
+ walletClient,
114
+ definitionsAddress,
115
+ chain
116
+ );
117
+ ```
118
+
119
+ ## SecureOwnable Usage
120
+
121
+ ### Ownership Management
122
+
123
+ ```typescript
124
+ // Request ownership transfer
125
+ const txResult = await secureOwnable.transferOwnershipRequest({
126
+ from: ownerAddress
127
+ });
128
+
129
+ // Approve after time lock period
130
+ const approvalResult = await secureOwnable.transferOwnershipDelayedApproval(
131
+ txId,
132
+ { from: ownerAddress }
133
+ );
134
+
135
+ // Cancel ownership transfer
136
+ const cancelResult = await secureOwnable.transferOwnershipCancellation(
137
+ txId,
138
+ { from: ownerAddress }
139
+ );
140
+ ```
141
+
142
+ ### Meta Transactions
143
+
144
+ ```typescript
145
+ // Create meta transaction parameters
146
+ const metaTxParams = await secureOwnable.createMetaTxParams(
147
+ handlerContract,
148
+ handlerSelector,
149
+ deadline,
150
+ maxGasPrice,
151
+ signer
152
+ );
153
+
154
+ // Generate unsigned meta transaction
155
+ const metaTx = await secureOwnable.generateUnsignedMetaTransactionForNew(
156
+ requester,
157
+ target,
158
+ value,
159
+ gasLimit,
160
+ operationType,
161
+ executionType,
162
+ executionOptions,
163
+ metaTxParams
164
+ );
165
+ ```
166
+
167
+ ## RuntimeRBAC Usage
168
+
169
+ RuntimeRBAC uses batch-based configuration for all role management operations. See the [RuntimeRBAC Guide](./docs/runtime-rbac.md) for complete examples.
170
+
171
+ ### Query Functions
172
+
173
+ ```typescript
174
+ // Get role information
175
+ const role = await runtimeRBAC.getRole(roleHash);
176
+ console.log(role.roleName, role.maxWallets, role.isProtected);
177
+
178
+ // Check if wallet has role
179
+ const hasRole = await runtimeRBAC.hasRole(roleHash, walletAddress);
180
+
181
+ // Get authorized wallets in role
182
+ const wallets = await runtimeRBAC.getAuthorizedWallets(roleHash);
183
+
184
+ // Get roles for a wallet
185
+ const walletRoles = await runtimeRBAC.getWalletRoles(walletAddress);
186
+
187
+ // Get supported roles
188
+ const supportedRoles = await runtimeRBAC.getSupportedRoles();
189
+
190
+ // Get active role permissions
191
+ const permissions = await runtimeRBAC.getActiveRolePermissions(roleHash);
192
+ ```
193
+
194
+ ### Batch Configuration
195
+
196
+ 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.
197
+
198
+ ## Definitions Usage
199
+
200
+ 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.
201
+
202
+ ### Basic Usage
203
+
204
+ ```typescript
205
+ // Initialize Definitions
206
+ const definitions = new Definitions(
207
+ publicClient,
208
+ walletClient,
209
+ definitionsAddress,
210
+ chain
211
+ );
212
+
213
+ // Get all operation types
214
+ const operationTypes = await definitions.getOperationTypes();
215
+ console.log('Available operations:', operationTypes);
216
+
217
+ // Get all function schemas
218
+ const functionSchemas = await definitions.getFunctionSchemas();
219
+ console.log('Function schemas:', functionSchemas);
220
+
221
+ // Get role permissions
222
+ const rolePermissions = await definitions.getRolePermissions();
223
+ console.log('Role permissions:', rolePermissions);
224
+ ```
225
+
226
+ ### Workflow Management
227
+
228
+ ```typescript
229
+ // Get all operation workflows
230
+ const workflows = await definitions.getOperationWorkflows();
231
+ console.log('Available workflows:', workflows);
232
+
233
+ // Get workflow for specific operation
234
+ const operationType = '0x1234...'; // operation type hash
235
+ const workflow = await definitions.getWorkflowForOperation(operationType);
236
+ console.log('Workflow for operation:', workflow);
237
+
238
+ // Get all workflow paths
239
+ const paths = await definitions.getWorkflowPaths();
240
+ console.log('Available paths:', paths);
241
+ ```
242
+
243
+ ### Utility Functions
244
+
245
+ ```typescript
246
+ // Find operation type by name
247
+ const operationType = await definitions.getOperationTypeByName('TRANSFER_OWNERSHIP');
248
+ console.log('Operation type hash:', operationType);
249
+
250
+ // Get function schema by selector
251
+ const functionSelector = '0xabcd...';
252
+ const schema = await definitions.getFunctionSchemaBySelector(functionSelector);
253
+ console.log('Function schema:', schema);
254
+
255
+ // Check role permission for function
256
+ const roleHash = '0xefgh...';
257
+ const hasPermission = await definitions.hasRolePermission(roleHash, functionSelector);
258
+ console.log('Has permission:', hasPermission);
259
+
260
+ // Get all roles that can execute a function
261
+ const allowedRoles = await definitions.getRolesForFunction(functionSelector);
262
+ console.log('Allowed roles:', allowedRoles);
263
+ ```
264
+
265
+ ### Configuration Management
266
+
267
+ ```typescript
268
+ // Get current configuration
269
+ const config = definitions.getConfig();
270
+ console.log('Current config:', config);
271
+
272
+ // Update configuration
273
+ definitions.updateConfig({
274
+ chainId: 137, // Polygon
275
+ rpcUrl: 'https://polygon-rpc.com'
276
+ });
277
+ ```
278
+
279
+ ## Types and Constants
280
+
281
+ ### Transaction Actions
282
+
283
+ ```typescript
284
+ import { TxAction } from '@bloxchain/sdk';
285
+
286
+ // Available transaction actions
287
+ TxAction.EXECUTE_TIME_DELAY_REQUEST
288
+ TxAction.EXECUTE_TIME_DELAY_APPROVE
289
+ TxAction.EXECUTE_TIME_DELAY_CANCEL
290
+ TxAction.SIGN_META_REQUEST_AND_APPROVE
291
+ TxAction.SIGN_META_APPROVE
292
+ TxAction.SIGN_META_CANCEL
293
+ TxAction.EXECUTE_META_REQUEST_AND_APPROVE
294
+ TxAction.EXECUTE_META_APPROVE
295
+ TxAction.EXECUTE_META_CANCEL
296
+ ```
297
+
298
+ ### Execution Types
299
+
300
+ ```typescript
301
+ import { ExecutionType } from '@bloxchain/sdk';
302
+
303
+ ExecutionType.NONE
304
+ ExecutionType.STANDARD
305
+ ExecutionType.RAW
306
+ ```
307
+
308
+ ### Transaction Status
309
+
310
+ ```typescript
311
+ import { TxStatus } from '@bloxchain/sdk';
312
+
313
+ TxStatus.UNDEFINED
314
+ TxStatus.PENDING
315
+ TxStatus.CANCELLED
316
+ TxStatus.COMPLETED
317
+ TxStatus.FAILED
318
+ TxStatus.REJECTED
319
+ ```
320
+
321
+ ## Error Handling
322
+
323
+ All SDK methods throw errors for failed operations. Always wrap SDK calls in try-catch blocks:
324
+
325
+ ```typescript
326
+ try {
327
+ const result = await secureOwnable.transferOwnershipRequest({
328
+ from: ownerAddress
329
+ });
330
+ console.log('Transaction successful:', result.hash);
331
+ } catch (error) {
332
+ console.error('Transaction failed:', error);
333
+ }
334
+ ```
335
+
336
+ ## Security Considerations
337
+
338
+ - Always validate addresses and parameters before making transactions
339
+ - Use proper time-lock periods for critical operations
340
+ - Implement proper access control using RuntimeRBAC
341
+ - Monitor transaction status and handle failures appropriately
342
+ - Keep private keys secure and never expose them in client-side code
343
+
344
+ ## Versioning and stability
345
+
346
+ This package follows [Semantic Versioning](https://semver.org/). Current versions are **alpha** (`1.0.0-alpha.x`). Pre-1.0 releases may introduce breaking changes; we recommend pinning the exact version until the protocol is audited and stable.
347
+
348
+ ## Security
349
+
350
+ - **Vulnerability reporting**: Do not open public GitHub issues for security vulnerabilities. See the [Security Policy](https://github.com/PracticalParticle/Bloxchain-Protocol/blob/main/SECURITY.md) for reporting instructions (e.g. security@particlecs.com).
351
+ - **Audit status**: The underlying protocol is not yet audited. Do not use with mainnet assets without an independent security review.
352
+
353
+ ## Support and links
354
+
355
+ - **Documentation**: [SDK docs](./docs/) in this package; [Bloxchain Protocol README](https://github.com/PracticalParticle/Bloxchain-Protocol#readme) for protocol details
356
+ - **Issues and feature requests**: [GitHub Issues](https://github.com/PracticalParticle/Bloxchain-Protocol/issues)
357
+ - **Homepage**: [bloxchain.app](https://bloxchain.app/)
358
+ - **Author**: [Particle Crypto Security](https://particlecs.com/)
359
+
360
+ ## Repository
361
+
362
+ Part of [Bloxchain Protocol](https://github.com/PracticalParticle/Bloxchain-Protocol). For protocol architecture and contract documentation, see the main repository README.
363
+
364
+ ## Contributing
365
+
366
+ When contributing to the SDK:
367
+
368
+ 1. Follow TypeScript best practices
369
+ 2. Add comprehensive type definitions
370
+ 3. Include JSDoc comments for all public methods
371
+ 4. Test all new functionality thoroughly
372
+ 5. Update this README with new features
373
+
374
+ ## License
375
+
376
+ MPL-2.0 (Mozilla Public License 2.0). This SDK is part of the Bloxchain Protocol. See the [LICENSE](https://github.com/PracticalParticle/Bloxchain-Protocol/blob/main/LICENSE) file in the main repository.