@bloxchain/sdk 1.0.0-alpha.21 → 1.0.0-alpha.23

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 (110) hide show
  1. package/README.md +399 -377
  2. package/dist/abi.js +1 -1
  3. package/dist/abi.js.map +1 -1
  4. package/dist/contracts/core/BaseStateMachine.d.ts +5 -5
  5. package/dist/contracts/core/BaseStateMachine.d.ts.map +1 -1
  6. package/dist/contracts/core/BaseStateMachine.js +7 -2
  7. package/dist/contracts/core/BaseStateMachine.js.map +1 -1
  8. package/dist/contracts/core/GuardController.d.ts +4 -4
  9. package/dist/contracts/core/GuardController.d.ts.map +1 -1
  10. package/dist/contracts/core/GuardController.js +3 -3
  11. package/dist/contracts/core/GuardController.js.map +1 -1
  12. package/dist/contracts/core/RuntimeRBAC.d.ts +4 -4
  13. package/dist/contracts/core/RuntimeRBAC.d.ts.map +1 -1
  14. package/dist/contracts/core/RuntimeRBAC.js +4 -4
  15. package/dist/contracts/core/RuntimeRBAC.js.map +1 -1
  16. package/dist/contracts/core/SecureOwnable.d.ts +12 -4
  17. package/dist/contracts/core/SecureOwnable.d.ts.map +1 -1
  18. package/dist/contracts/core/SecureOwnable.js +19 -3
  19. package/dist/contracts/core/SecureOwnable.js.map +1 -1
  20. package/dist/index.d.ts +31 -30
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +27 -26
  23. package/dist/index.js.map +1 -1
  24. package/dist/interfaces/base.state.machine.index.d.ts +3 -3
  25. package/dist/interfaces/base.state.machine.index.d.ts.map +1 -1
  26. package/dist/interfaces/core.access.index.d.ts +2 -2
  27. package/dist/interfaces/core.access.index.d.ts.map +1 -1
  28. package/dist/interfaces/core.execution.index.d.ts +3 -3
  29. package/dist/interfaces/core.execution.index.d.ts.map +1 -1
  30. package/dist/interfaces/core.security.index.d.ts +3 -3
  31. package/dist/interfaces/core.security.index.d.ts.map +1 -1
  32. package/dist/interfaces/definition.index.d.ts +1 -1
  33. package/dist/interfaces/definition.index.d.ts.map +1 -1
  34. package/dist/interfaces/lib.index.d.ts +1 -1
  35. package/dist/interfaces/lib.index.d.ts.map +1 -1
  36. package/dist/lib/Definition.d.ts +2 -2
  37. package/dist/lib/Definition.d.ts.map +1 -1
  38. package/dist/lib/Definition.js +7 -2
  39. package/dist/lib/Definition.js.map +1 -1
  40. package/dist/lib/EngineBlox.d.ts +2 -2
  41. package/dist/lib/EngineBlox.d.ts.map +1 -1
  42. package/dist/lib/EngineBlox.js +42 -42
  43. package/dist/lib/EngineBlox.js.map +1 -1
  44. package/dist/lib/definitions/GuardControllerDefinitions.d.ts +2 -2
  45. package/dist/lib/definitions/GuardControllerDefinitions.d.ts.map +1 -1
  46. package/dist/lib/definitions/GuardControllerDefinitions.js +1 -1
  47. package/dist/lib/definitions/GuardControllerDefinitions.js.map +1 -1
  48. package/dist/lib/definitions/RuntimeRBACDefinitions.d.ts +1 -1
  49. package/dist/lib/definitions/RuntimeRBACDefinitions.d.ts.map +1 -1
  50. package/dist/lib/definitions/RuntimeRBACDefinitions.js +1 -1
  51. package/dist/lib/definitions/RuntimeRBACDefinitions.js.map +1 -1
  52. package/dist/lib/definitions/SecureOwnableDefinitions.js +1 -1
  53. package/dist/lib/definitions/SecureOwnableDefinitions.js.map +1 -1
  54. package/dist/lib/definitions/index.d.ts +4 -4
  55. package/dist/lib/definitions/index.d.ts.map +1 -1
  56. package/dist/lib/definitions/index.js +3 -3
  57. package/dist/lib/definitions/index.js.map +1 -1
  58. package/dist/types/base.state.machine.index.d.ts +4 -19
  59. package/dist/types/base.state.machine.index.d.ts.map +1 -1
  60. package/dist/types/base.state.machine.index.js +20 -39
  61. package/dist/types/base.state.machine.index.js.map +1 -1
  62. package/dist/types/core.access.index.d.ts +0 -16
  63. package/dist/types/core.access.index.d.ts.map +1 -1
  64. package/dist/types/core.access.index.js +2 -13
  65. package/dist/types/core.access.index.js.map +1 -1
  66. package/dist/types/core.execution.index.d.ts +8 -10
  67. package/dist/types/core.execution.index.d.ts.map +1 -1
  68. package/dist/types/core.execution.index.js +16 -14
  69. package/dist/types/core.execution.index.js.map +1 -1
  70. package/dist/types/core.security.index.d.ts +4 -6
  71. package/dist/types/core.security.index.d.ts.map +1 -1
  72. package/dist/types/core.security.index.js +23 -27
  73. package/dist/types/core.security.index.js.map +1 -1
  74. package/dist/types/definition.index.d.ts +1 -1
  75. package/dist/types/definition.index.d.ts.map +1 -1
  76. package/dist/types/lib.index.d.ts +7 -27
  77. package/dist/types/lib.index.d.ts.map +1 -1
  78. package/dist/types/lib.index.js +12 -34
  79. package/dist/types/lib.index.js.map +1 -1
  80. package/dist/types/meta-transaction.signatures.d.ts +10 -0
  81. package/dist/types/meta-transaction.signatures.d.ts.map +1 -0
  82. package/dist/types/meta-transaction.signatures.js +12 -0
  83. package/dist/types/meta-transaction.signatures.js.map +1 -0
  84. package/dist/types/meta-tx-signatures.d.ts +9 -0
  85. package/dist/types/meta-tx-signatures.d.ts.map +1 -0
  86. package/dist/types/meta-tx-signatures.js +11 -0
  87. package/dist/types/meta-tx-signatures.js.map +1 -0
  88. package/dist/utils/bitmap.d.ts +1 -1
  89. package/dist/utils/bitmap.d.ts.map +1 -1
  90. package/dist/utils/erc20/erc20Token.d.ts +1 -1
  91. package/dist/utils/erc20/erc20Token.d.ts.map +1 -1
  92. package/dist/utils/erc20/erc20Token.js +5 -1
  93. package/dist/utils/erc20/erc20Token.js.map +1 -1
  94. package/dist/utils/interface-ids.d.ts +7 -31
  95. package/dist/utils/interface-ids.d.ts.map +1 -1
  96. package/dist/utils/interface-ids.js +29 -85
  97. package/dist/utils/interface-ids.js.map +1 -1
  98. package/dist/utils/metaTx/metaTransaction.d.ts +7 -2
  99. package/dist/utils/metaTx/metaTransaction.d.ts.map +1 -1
  100. package/dist/utils/metaTx/metaTransaction.js +11 -2
  101. package/dist/utils/metaTx/metaTransaction.js.map +1 -1
  102. package/dist/utils/validations.d.ts +1 -1
  103. package/dist/utils/validations.d.ts.map +1 -1
  104. package/dist/utils/validations.js +2 -1
  105. package/dist/utils/validations.js.map +1 -1
  106. package/dist/utils/viem-error-handler.d.ts +1 -1
  107. package/dist/utils/viem-error-handler.d.ts.map +1 -1
  108. package/dist/utils/viem-error-handler.js +1 -1
  109. package/dist/utils/viem-error-handler.js.map +1 -1
  110. package/package.json +9 -8
package/README.md CHANGED
@@ -1,377 +1,399 @@
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 repository root [`docs/`](../../docs/) folder:
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.EXECUTING
316
- TxStatus.PROCESSING_PAYMENT
317
- TxStatus.CANCELLED
318
- TxStatus.COMPLETED
319
- TxStatus.FAILED
320
- ```
321
-
322
- ## Error Handling
323
-
324
- All SDK methods throw errors for failed operations. Always wrap SDK calls in try-catch blocks:
325
-
326
- ```typescript
327
- try {
328
- const result = await secureOwnable.transferOwnershipRequest({
329
- from: ownerAddress
330
- });
331
- console.log('Transaction successful:', result.hash);
332
- } catch (error) {
333
- console.error('Transaction failed:', error);
334
- }
335
- ```
336
-
337
- ## Security Considerations
338
-
339
- - Always validate addresses and parameters before making transactions
340
- - Use proper time-lock periods for critical operations
341
- - Implement proper access control using RuntimeRBAC
342
- - Monitor transaction status and handle failures appropriately
343
- - Keep private keys secure and never expose them in client-side code
344
-
345
- ## Versioning and stability
346
-
347
- 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.
348
-
349
- ## Security
350
-
351
- - **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).
352
- - **Audit status**: The underlying protocol is not yet audited. Do not use with mainnet assets without an independent security review.
353
-
354
- ## Support and links
355
-
356
- - **Documentation**: [SDK and protocol guides](../../docs/) in the repository `docs/` folder; [Bloxchain Protocol README](https://github.com/PracticalParticle/Bloxchain-Protocol#readme) for protocol details
357
- - **Issues and feature requests**: [GitHub Issues](https://github.com/PracticalParticle/Bloxchain-Protocol/issues)
358
- - **Homepage**: [bloxchain.app](https://bloxchain.app/)
359
- - **Author**: [Particle Crypto Security](https://particlecs.com/)
360
-
361
- ## Repository
362
-
363
- Part of [Bloxchain Protocol](https://github.com/PracticalParticle/Bloxchain-Protocol). For protocol architecture and contract documentation, see the main repository README.
364
-
365
- ## Contributing
366
-
367
- When contributing to the SDK:
368
-
369
- 1. Follow TypeScript best practices
370
- 2. Add comprehensive type definitions
371
- 3. Include JSDoc comments for all public methods
372
- 4. Test all new functionality thoroughly
373
- 5. Update this README with new features
374
-
375
- ## License
376
-
377
- 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-6.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
+ The SDK mirrors the audited core protocol and is intended for production integrations. Pin an exact package version and review release notes before upgrading.
11
+
12
+ ## Requirements
13
+
14
+ - **Node.js**: >= 18.0.0
15
+ - **TypeScript**: 6.x (recommended)
16
+ - **Peer dependency**: `viem` ^2.49.4 (required; align with SDK dependency, currently `2.50.x`)
17
+ - **Optional peer**: `@bloxchain/contracts` ^1.0.0-alpha (for Solidity/ABI alignment when building apps that use both)
18
+
19
+ ## 🏗️ **Unique Architecture**
20
+
21
+ Bloxchain Protocol implements a **state machine architecture** with `SecureOperationState` as the core engine, providing:
22
+
23
+ - **Centralized State Management**: All security operations flow through a unified state machine
24
+ - **Multi-Phase Transaction Processing**: Time-locked operations with request/approval workflows
25
+ - **Dynamic Role-Based Access Control**: Flexible, hierarchical permission system
26
+ - **Meta-Transaction Support**: Gasless transactions and delegated execution
27
+ - **Event-Driven Architecture**: Comprehensive audit trails and external monitoring
28
+
29
+ ## Features
30
+
31
+ - **SecureOwnable**: Multi-phase ownership management with time-locked operations
32
+ - **RuntimeRBAC**: Runtime role-based access control system with batch configuration
33
+ - **Definitions**: Dynamic interaction with any definition library implementing IDefinition
34
+ - **Guardian**: State abstraction with secure operations
35
+ - **Type Safety**: Full TypeScript support with comprehensive type definitions
36
+ - **Viem Integration**: Built on top of Viem for modern Ethereum development
37
+
38
+ ## 📚 Documentation
39
+
40
+ Comprehensive documentation is available in the repository root [`docs/`](../../docs/) folder:
41
+
42
+ ### **🏗️ Architecture & Design**
43
+ - **[Protocol Architecture](../../docs/bloxchain-architecture.md)** - Bloxchain protocol overview and design principles
44
+ - **[State Machine Engine](../../docs/state-machine-engine.md)** - SecureOperationState engine and state management
45
+ - **[Architecture Patterns](../../docs/architecture-patterns.md)** - Design patterns and best practices
46
+
47
+ ### **🚀 Getting Started**
48
+ - **[Getting Started](../../docs/getting-started.md)** - Quick setup and basic usage
49
+ - **[API Reference](../../docs/api-reference.md)** - Complete API documentation
50
+ - **[SecureOwnable Guide](../../docs/secure-ownable.md)** - Ownership management
51
+ - **[RuntimeRBAC Guide](../../docs/runtime-rbac.md)** - Role-based access control
52
+
53
+ ### **🔍 Development Tools**
54
+ - **[Best Practices](../../docs/best-practices.md)** - Development guidelines
55
+ - **[Examples](../../docs/examples-basic.md)** - Practical code samples
56
+ - **[Types & Interfaces](../../docs/types-interfaces.md)** - Type definitions
57
+
58
+ **📖 [View All Documentation](../../docs/README.md)**
59
+
60
+ ## Installation
61
+
62
+ ```bash
63
+ # Install the SDK and its required peer dependency
64
+ npm install @bloxchain/sdk viem
65
+
66
+ # Optional: install contracts package when building apps that use both SDK and Solidity
67
+ npm install @bloxchain/contracts
68
+ ```
69
+
70
+ To install from the repository (e.g. for development):
71
+
72
+ ```bash
73
+ npm install https://github.com/PracticalParticle/Bloxchain-Protocol.git#main --save
74
+ ```
75
+
76
+ ### Node.js ESM (`"type": "module"`)
77
+
78
+ The published package is **native ESM**, built with TypeScript **`module` / `moduleResolution`: `NodeNext`**. All relative imports in `sdk/typescript` source use explicit **`.js`** extensions (and `with { type: 'json' }` for ABIs) so `tsc` output loads under Node without a bundler or post-build patches.
79
+
80
+ **Requires Node.js >= 18.20.5** (JSON import attributes). Node 18.0–18.19 will fail at runtime when loading `dist/`.
81
+
82
+ When adding or moving SDK files, follow the same import style (e.g. `from './SecureOwnable.js'`, not `from './SecureOwnable'`).
83
+
84
+ From the protocol repo, run `npm run release:prepare` before publish (includes SDK build, Node ESM import of `dist/`, and selector alignment vs Solidity). Then `npm run publish:contracts` or `npm run publish:sdk`.
85
+
86
+ ### Public exports (stable integrator surface)
87
+
88
+ | Export | Purpose |
89
+ |--------|---------|
90
+ | `SECURITY_FUNCTION_SELECTORS` | SecureOwnable function selectors (`FUNCTION_SELECTORS` in Solidity definitions) |
91
+ | `RUNTIME_RBAC_FUNCTION_SELECTORS` / `GUARD_CONTROLLER_FUNCTION_SELECTORS` | Batch, timelock, payment, and execute selectors (see `types/meta-tx-signatures.ts`) |
92
+ | `ENGINE_BLOX_META_TRANSACTION_PARAM` / `ENGINE_BLOX_META_TX_PARAMS` / `metaTxHandlerSignature` | Canonical MetaTransaction tuple strings and selector builders (aligned with `EngineBlox.sol`) |
93
+ | `INTERFACE_IDS` / `ComponentDetection` | ERC-165 checks aligned with current `I*` interfaces |
94
+ | `EngineBlox`, `Definitions` | Pure helpers and definition-library reads |
95
+ | `roleConfigBatchExecutionParams`, `guardConfigBatchExecutionParams`, encoders | Batch calldata builders |
96
+ | `extractErrorInfo`, `enhanceViemError` | Revert decoding and Viem error enrichment |
97
+ | `@bloxchain/sdk/abi` | `engineBloxAbi`, `engineBloxErrorAbi` |
98
+
99
+ ## Quick Start
100
+
101
+ ```typescript
102
+ import {
103
+ SecureOwnable,
104
+ RuntimeRBAC,
105
+ GuardController,
106
+ Definitions,
107
+ type Address,
108
+ type PublicClient,
109
+ type WalletClient,
110
+ type Chain
111
+ } from '@bloxchain/sdk';
112
+
113
+ // Initialize clients (using your preferred provider)
114
+ const publicClient: PublicClient = createPublicClient({...});
115
+ const walletClient: WalletClient = createWalletClient({...});
116
+ const chain: Chain = mainnet; // or your target chain
117
+
118
+ // Initialize SDK classes
119
+ const secureOwnable = new SecureOwnable(
120
+ publicClient,
121
+ walletClient,
122
+ contractAddress,
123
+ chain
124
+ );
125
+
126
+ const runtimeRBAC = new RuntimeRBAC(
127
+ publicClient,
128
+ walletClient,
129
+ contractAddress,
130
+ chain
131
+ );
132
+
133
+ const definitions = new Definitions(
134
+ publicClient,
135
+ walletClient,
136
+ definitionsAddress,
137
+ chain
138
+ );
139
+ ```
140
+
141
+ ## SecureOwnable Usage
142
+
143
+ ### Ownership Management
144
+
145
+ ```typescript
146
+ // Request ownership transfer
147
+ const txResult = await secureOwnable.transferOwnershipRequest({
148
+ from: ownerAddress
149
+ });
150
+
151
+ // Approve after time lock period
152
+ const approvalResult = await secureOwnable.transferOwnershipDelayedApproval(
153
+ txId,
154
+ { from: ownerAddress }
155
+ );
156
+
157
+ // Cancel ownership transfer
158
+ const cancelResult = await secureOwnable.transferOwnershipCancellation(
159
+ txId,
160
+ { from: ownerAddress }
161
+ );
162
+ ```
163
+
164
+ ### Meta Transactions
165
+
166
+ ```typescript
167
+ // Create meta transaction parameters
168
+ const metaTxParams = await secureOwnable.createMetaTxParams(
169
+ handlerContract,
170
+ handlerSelector,
171
+ deadline,
172
+ maxGasPrice,
173
+ signer
174
+ );
175
+
176
+ // Generate unsigned meta transaction
177
+ const metaTx = await secureOwnable.generateUnsignedMetaTransactionForNew(
178
+ requester,
179
+ target,
180
+ value,
181
+ gasLimit,
182
+ operationType,
183
+ executionType,
184
+ executionOptions,
185
+ metaTxParams
186
+ );
187
+ ```
188
+
189
+ ## RuntimeRBAC Usage
190
+
191
+ RuntimeRBAC uses batch-based configuration for all role management operations. See the [RuntimeRBAC Guide](../../docs/runtime-rbac.md) for complete examples.
192
+
193
+ ### Query Functions
194
+
195
+ ```typescript
196
+ // Get role information
197
+ const role = await runtimeRBAC.getRole(roleHash);
198
+ console.log(role.roleName, role.maxWallets, role.isProtected);
199
+
200
+ // Check if wallet has role
201
+ const hasRole = await runtimeRBAC.hasRole(roleHash, walletAddress);
202
+
203
+ // Get authorized wallets in role
204
+ const wallets = await runtimeRBAC.getAuthorizedWallets(roleHash);
205
+
206
+ // Get roles for a wallet
207
+ const walletRoles = await runtimeRBAC.getWalletRoles(walletAddress);
208
+
209
+ // Get supported roles
210
+ const supportedRoles = await runtimeRBAC.getSupportedRoles();
211
+
212
+ // Get active role permissions
213
+ const permissions = await runtimeRBAC.getActiveRolePermissions(roleHash);
214
+ ```
215
+
216
+ ### Batch Configuration
217
+
218
+ 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.
219
+
220
+ ## Definitions Usage
221
+
222
+ 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.
223
+
224
+ ### Basic Usage
225
+
226
+ ```typescript
227
+ // Initialize Definitions
228
+ const definitions = new Definitions(
229
+ publicClient,
230
+ walletClient,
231
+ definitionsAddress,
232
+ chain
233
+ );
234
+
235
+ // Get all operation types
236
+ const operationTypes = await definitions.getOperationTypes();
237
+ console.log('Available operations:', operationTypes);
238
+
239
+ // Get all function schemas
240
+ const functionSchemas = await definitions.getFunctionSchemas();
241
+ console.log('Function schemas:', functionSchemas);
242
+
243
+ // Get role permissions
244
+ const rolePermissions = await definitions.getRolePermissions();
245
+ console.log('Role permissions:', rolePermissions);
246
+ ```
247
+
248
+ ### Workflow Management
249
+
250
+ ```typescript
251
+ // Get all operation workflows
252
+ const workflows = await definitions.getOperationWorkflows();
253
+ console.log('Available workflows:', workflows);
254
+
255
+ // Get workflow for specific operation
256
+ const operationType = '0x1234...'; // operation type hash
257
+ const workflow = await definitions.getWorkflowForOperation(operationType);
258
+ console.log('Workflow for operation:', workflow);
259
+
260
+ // Get all workflow paths
261
+ const paths = await definitions.getWorkflowPaths();
262
+ console.log('Available paths:', paths);
263
+ ```
264
+
265
+ ### Utility Functions
266
+
267
+ ```typescript
268
+ // Find operation type by name
269
+ const operationType = await definitions.getOperationTypeByName('TRANSFER_OWNERSHIP');
270
+ console.log('Operation type hash:', operationType);
271
+
272
+ // Get function schema by selector
273
+ const functionSelector = '0xabcd...';
274
+ const schema = await definitions.getFunctionSchemaBySelector(functionSelector);
275
+ console.log('Function schema:', schema);
276
+
277
+ // Check role permission for function
278
+ const roleHash = '0xefgh...';
279
+ const hasPermission = await definitions.hasRolePermission(roleHash, functionSelector);
280
+ console.log('Has permission:', hasPermission);
281
+
282
+ // Get all roles that can execute a function
283
+ const allowedRoles = await definitions.getRolesForFunction(functionSelector);
284
+ console.log('Allowed roles:', allowedRoles);
285
+ ```
286
+
287
+ ### Configuration Management
288
+
289
+ ```typescript
290
+ // Get current configuration
291
+ const config = definitions.getConfig();
292
+ console.log('Current config:', config);
293
+
294
+ // Update configuration
295
+ definitions.updateConfig({
296
+ chainId: 137, // Polygon
297
+ rpcUrl: 'https://polygon-rpc.com'
298
+ });
299
+ ```
300
+
301
+ ## Types and Constants
302
+
303
+ ### Transaction Actions
304
+
305
+ ```typescript
306
+ import { TxAction } from '@bloxchain/sdk';
307
+
308
+ // Available transaction actions
309
+ TxAction.EXECUTE_TIME_DELAY_REQUEST
310
+ TxAction.EXECUTE_TIME_DELAY_APPROVE
311
+ TxAction.EXECUTE_TIME_DELAY_CANCEL
312
+ TxAction.SIGN_META_REQUEST_AND_APPROVE
313
+ TxAction.SIGN_META_APPROVE
314
+ TxAction.SIGN_META_CANCEL
315
+ TxAction.EXECUTE_META_REQUEST_AND_APPROVE
316
+ TxAction.EXECUTE_META_APPROVE
317
+ TxAction.EXECUTE_META_CANCEL
318
+ ```
319
+
320
+ ### Execution Types
321
+
322
+ ```typescript
323
+ import { ExecutionType } from '@bloxchain/sdk';
324
+
325
+ ExecutionType.NONE
326
+ ExecutionType.STANDARD
327
+ ExecutionType.RAW
328
+ ```
329
+
330
+ ### Transaction Status
331
+
332
+ ```typescript
333
+ import { TxStatus } from '@bloxchain/sdk';
334
+
335
+ TxStatus.UNDEFINED
336
+ TxStatus.PENDING
337
+ TxStatus.EXECUTING
338
+ TxStatus.PROCESSING_PAYMENT
339
+ TxStatus.CANCELLED
340
+ TxStatus.COMPLETED
341
+ TxStatus.FAILED
342
+ ```
343
+
344
+ ## Error Handling
345
+
346
+ All SDK methods throw errors for failed operations. Always wrap SDK calls in try-catch blocks:
347
+
348
+ ```typescript
349
+ try {
350
+ const result = await secureOwnable.transferOwnershipRequest({
351
+ from: ownerAddress
352
+ });
353
+ console.log('Transaction successful:', result.hash);
354
+ } catch (error) {
355
+ console.error('Transaction failed:', error);
356
+ }
357
+ ```
358
+
359
+ ## Security Considerations
360
+
361
+ - Always validate addresses and parameters before making transactions
362
+ - Use proper time-lock periods for critical operations
363
+ - Implement proper access control using RuntimeRBAC
364
+ - Monitor transaction status and handle failures appropriately
365
+ - Keep private keys secure and never expose them in client-side code
366
+
367
+ ## Versioning and stability
368
+
369
+ This package follows [Semantic Versioning](https://semver.org/). Published versions use the **alpha** channel (`1.0.0-alpha.x`) while we finalize the 1.0.0 release line. Pin the exact version in production and review release notes before upgrading.
370
+
371
+ ## Security
372
+
373
+ - **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).
374
+ - **Audit status**: The underlying core protocol smart contracts have completed an independent security audit. Follow your own deployment, upgrade, and operational review processes before production use.
375
+
376
+ ## Support and links
377
+
378
+ - **Documentation**: [SDK and protocol guides](../../docs/) in the repository `docs/` folder; [Bloxchain Protocol README](https://github.com/PracticalParticle/Bloxchain-Protocol#readme) for protocol details
379
+ - **Issues and feature requests**: [GitHub Issues](https://github.com/PracticalParticle/Bloxchain-Protocol/issues)
380
+ - **Homepage**: [bloxchain.app](https://bloxchain.app/)
381
+ - **Author**: [Particle Crypto Security](https://particlecs.com/)
382
+
383
+ ## Repository
384
+
385
+ Part of [Bloxchain Protocol](https://github.com/PracticalParticle/Bloxchain-Protocol). For protocol architecture and contract documentation, see the main repository README.
386
+
387
+ ## Contributing
388
+
389
+ When contributing to the SDK:
390
+
391
+ 1. Follow TypeScript best practices
392
+ 2. Add comprehensive type definitions
393
+ 3. Include JSDoc comments for all public methods
394
+ 4. Test all new functionality thoroughly
395
+ 5. Update this README with new features
396
+
397
+ ## License
398
+
399
+ 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.