@bloxchain/sdk 1.0.0-alpha.22 → 1.0.0-alpha.24

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 (106) hide show
  1. package/README.md +411 -376
  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 +32 -30
  21. package/dist/index.d.ts.map +1 -1
  22. package/dist/index.js +28 -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-tx-signatures.d.ts +9 -0
  81. package/dist/types/meta-tx-signatures.d.ts.map +1 -0
  82. package/dist/types/meta-tx-signatures.js +11 -0
  83. package/dist/types/meta-tx-signatures.js.map +1 -0
  84. package/dist/utils/bitmap.d.ts +1 -1
  85. package/dist/utils/bitmap.d.ts.map +1 -1
  86. package/dist/utils/erc20/erc20Token.d.ts +1 -1
  87. package/dist/utils/erc20/erc20Token.d.ts.map +1 -1
  88. package/dist/utils/erc20/erc20Token.js +5 -1
  89. package/dist/utils/erc20/erc20Token.js.map +1 -1
  90. package/dist/utils/interface-ids.d.ts +5 -31
  91. package/dist/utils/interface-ids.d.ts.map +1 -1
  92. package/dist/utils/interface-ids.js +23 -84
  93. package/dist/utils/interface-ids.js.map +1 -1
  94. package/dist/utils/metaTx/metaTransaction.d.ts +7 -2
  95. package/dist/utils/metaTx/metaTransaction.d.ts.map +1 -1
  96. package/dist/utils/metaTx/metaTransaction.js +11 -2
  97. package/dist/utils/metaTx/metaTransaction.js.map +1 -1
  98. package/dist/utils/validations.d.ts +1 -1
  99. package/dist/utils/validations.d.ts.map +1 -1
  100. package/dist/utils/validations.js +2 -1
  101. package/dist/utils/validations.js.map +1 -1
  102. package/dist/utils/viem-error-handler.d.ts +1 -1
  103. package/dist/utils/viem-error-handler.d.ts.map +1 -1
  104. package/dist/utils/viem-error-handler.js +1 -1
  105. package/dist/utils/viem-error-handler.js.map +1 -1
  106. package/package.json +7 -6
package/README.md CHANGED
@@ -1,376 +1,411 @@
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.0.0 (required for all SDK usage)
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
- ## Quick Start
77
-
78
- ```typescript
79
- import {
80
- SecureOwnable,
81
- RuntimeRBAC,
82
- GuardController,
83
- Definitions,
84
- type Address,
85
- type PublicClient,
86
- type WalletClient,
87
- type Chain
88
- } from '@bloxchain/sdk';
89
-
90
- // Initialize clients (using your preferred provider)
91
- const publicClient: PublicClient = createPublicClient({...});
92
- const walletClient: WalletClient = createWalletClient({...});
93
- const chain: Chain = mainnet; // or your target chain
94
-
95
- // Initialize SDK classes
96
- const secureOwnable = new SecureOwnable(
97
- publicClient,
98
- walletClient,
99
- contractAddress,
100
- chain
101
- );
102
-
103
- const runtimeRBAC = new RuntimeRBAC(
104
- publicClient,
105
- walletClient,
106
- contractAddress,
107
- chain
108
- );
109
-
110
- const definitions = new Definitions(
111
- publicClient,
112
- walletClient,
113
- definitionsAddress,
114
- chain
115
- );
116
- ```
117
-
118
- ## SecureOwnable Usage
119
-
120
- ### Ownership Management
121
-
122
- ```typescript
123
- // Request ownership transfer
124
- const txResult = await secureOwnable.transferOwnershipRequest({
125
- from: ownerAddress
126
- });
127
-
128
- // Approve after time lock period
129
- const approvalResult = await secureOwnable.transferOwnershipDelayedApproval(
130
- txId,
131
- { from: ownerAddress }
132
- );
133
-
134
- // Cancel ownership transfer
135
- const cancelResult = await secureOwnable.transferOwnershipCancellation(
136
- txId,
137
- { from: ownerAddress }
138
- );
139
- ```
140
-
141
- ### Meta Transactions
142
-
143
- ```typescript
144
- // Create meta transaction parameters
145
- const metaTxParams = await secureOwnable.createMetaTxParams(
146
- handlerContract,
147
- handlerSelector,
148
- deadline,
149
- maxGasPrice,
150
- signer
151
- );
152
-
153
- // Generate unsigned meta transaction
154
- const metaTx = await secureOwnable.generateUnsignedMetaTransactionForNew(
155
- requester,
156
- target,
157
- value,
158
- gasLimit,
159
- operationType,
160
- executionType,
161
- executionOptions,
162
- metaTxParams
163
- );
164
- ```
165
-
166
- ## RuntimeRBAC Usage
167
-
168
- RuntimeRBAC uses batch-based configuration for all role management operations. See the [RuntimeRBAC Guide](../../docs/runtime-rbac.md) for complete examples.
169
-
170
- ### Query Functions
171
-
172
- ```typescript
173
- // Get role information
174
- const role = await runtimeRBAC.getRole(roleHash);
175
- console.log(role.roleName, role.maxWallets, role.isProtected);
176
-
177
- // Check if wallet has role
178
- const hasRole = await runtimeRBAC.hasRole(roleHash, walletAddress);
179
-
180
- // Get authorized wallets in role
181
- const wallets = await runtimeRBAC.getAuthorizedWallets(roleHash);
182
-
183
- // Get roles for a wallet
184
- const walletRoles = await runtimeRBAC.getWalletRoles(walletAddress);
185
-
186
- // Get supported roles
187
- const supportedRoles = await runtimeRBAC.getSupportedRoles();
188
-
189
- // Get active role permissions
190
- const permissions = await runtimeRBAC.getActiveRolePermissions(roleHash);
191
- ```
192
-
193
- ### Batch Configuration
194
-
195
- 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.
196
-
197
- ## Definitions Usage
198
-
199
- 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.
200
-
201
- ### Basic Usage
202
-
203
- ```typescript
204
- // Initialize Definitions
205
- const definitions = new Definitions(
206
- publicClient,
207
- walletClient,
208
- definitionsAddress,
209
- chain
210
- );
211
-
212
- // Get all operation types
213
- const operationTypes = await definitions.getOperationTypes();
214
- console.log('Available operations:', operationTypes);
215
-
216
- // Get all function schemas
217
- const functionSchemas = await definitions.getFunctionSchemas();
218
- console.log('Function schemas:', functionSchemas);
219
-
220
- // Get role permissions
221
- const rolePermissions = await definitions.getRolePermissions();
222
- console.log('Role permissions:', rolePermissions);
223
- ```
224
-
225
- ### Workflow Management
226
-
227
- ```typescript
228
- // Get all operation workflows
229
- const workflows = await definitions.getOperationWorkflows();
230
- console.log('Available workflows:', workflows);
231
-
232
- // Get workflow for specific operation
233
- const operationType = '0x1234...'; // operation type hash
234
- const workflow = await definitions.getWorkflowForOperation(operationType);
235
- console.log('Workflow for operation:', workflow);
236
-
237
- // Get all workflow paths
238
- const paths = await definitions.getWorkflowPaths();
239
- console.log('Available paths:', paths);
240
- ```
241
-
242
- ### Utility Functions
243
-
244
- ```typescript
245
- // Find operation type by name
246
- const operationType = await definitions.getOperationTypeByName('TRANSFER_OWNERSHIP');
247
- console.log('Operation type hash:', operationType);
248
-
249
- // Get function schema by selector
250
- const functionSelector = '0xabcd...';
251
- const schema = await definitions.getFunctionSchemaBySelector(functionSelector);
252
- console.log('Function schema:', schema);
253
-
254
- // Check role permission for function
255
- const roleHash = '0xefgh...';
256
- const hasPermission = await definitions.hasRolePermission(roleHash, functionSelector);
257
- console.log('Has permission:', hasPermission);
258
-
259
- // Get all roles that can execute a function
260
- const allowedRoles = await definitions.getRolesForFunction(functionSelector);
261
- console.log('Allowed roles:', allowedRoles);
262
- ```
263
-
264
- ### Configuration Management
265
-
266
- ```typescript
267
- // Get current configuration
268
- const config = definitions.getConfig();
269
- console.log('Current config:', config);
270
-
271
- // Update configuration
272
- definitions.updateConfig({
273
- chainId: 137, // Polygon
274
- rpcUrl: 'https://polygon-rpc.com'
275
- });
276
- ```
277
-
278
- ## Types and Constants
279
-
280
- ### Transaction Actions
281
-
282
- ```typescript
283
- import { TxAction } from '@bloxchain/sdk';
284
-
285
- // Available transaction actions
286
- TxAction.EXECUTE_TIME_DELAY_REQUEST
287
- TxAction.EXECUTE_TIME_DELAY_APPROVE
288
- TxAction.EXECUTE_TIME_DELAY_CANCEL
289
- TxAction.SIGN_META_REQUEST_AND_APPROVE
290
- TxAction.SIGN_META_APPROVE
291
- TxAction.SIGN_META_CANCEL
292
- TxAction.EXECUTE_META_REQUEST_AND_APPROVE
293
- TxAction.EXECUTE_META_APPROVE
294
- TxAction.EXECUTE_META_CANCEL
295
- ```
296
-
297
- ### Execution Types
298
-
299
- ```typescript
300
- import { ExecutionType } from '@bloxchain/sdk';
301
-
302
- ExecutionType.NONE
303
- ExecutionType.STANDARD
304
- ExecutionType.RAW
305
- ```
306
-
307
- ### Transaction Status
308
-
309
- ```typescript
310
- import { TxStatus } from '@bloxchain/sdk';
311
-
312
- TxStatus.UNDEFINED
313
- TxStatus.PENDING
314
- TxStatus.EXECUTING
315
- TxStatus.PROCESSING_PAYMENT
316
- TxStatus.CANCELLED
317
- TxStatus.COMPLETED
318
- TxStatus.FAILED
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/). 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.
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 core protocol smart contracts have completed an independent security audit. Follow your own deployment, upgrade, and operational review processes before production use.
352
-
353
- ## Support and links
354
-
355
- - **Documentation**: [SDK and protocol guides](../../docs/) in the repository `docs/` folder; [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-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` / `supportsInterface` | ERC-165 checks aligned with current `I*` interfaces (strict — no fallback selector) |
94
+ | `EngineBlox`, `Definitions` | Pure helpers and definition-library reads |
95
+ | `roleConfigBatchExecutionParams`, `guardConfigBatchExecutionParams`, encoders | Batch calldata builders |
96
+ | `updateRecoveryExecutionParams`, `updateTimeLockExecutionParams` | SecureOwnable execution params via deployed `SecureOwnableDefinitions` |
97
+ | `extractErrorInfo`, `enhanceViemError` | Revert decoding and Viem error enrichment |
98
+ | `@bloxchain/sdk/abi` | `engineBloxAbi`, `engineBloxErrorAbi` |
99
+
100
+ ## Quick Start
101
+
102
+ ```typescript
103
+ import {
104
+ SecureOwnable,
105
+ RuntimeRBAC,
106
+ GuardController,
107
+ Definitions,
108
+ type Address,
109
+ type PublicClient,
110
+ type WalletClient,
111
+ type Chain
112
+ } from '@bloxchain/sdk';
113
+
114
+ // Initialize clients (using your preferred provider)
115
+ const publicClient: PublicClient = createPublicClient({...});
116
+ const walletClient: WalletClient = createWalletClient({...});
117
+ const chain: Chain = mainnet; // or your target chain
118
+
119
+ // Initialize SDK classes
120
+ const secureOwnable = new SecureOwnable(
121
+ publicClient,
122
+ walletClient,
123
+ contractAddress,
124
+ chain
125
+ );
126
+
127
+ const runtimeRBAC = new RuntimeRBAC(
128
+ publicClient,
129
+ walletClient,
130
+ contractAddress,
131
+ chain
132
+ );
133
+
134
+ const definitions = new Definitions(
135
+ publicClient,
136
+ walletClient,
137
+ definitionsAddress,
138
+ chain
139
+ );
140
+ ```
141
+
142
+ ## SecureOwnable Usage
143
+
144
+ ### Ownership Management
145
+
146
+ ```typescript
147
+ // Request ownership transfer
148
+ const txResult = await secureOwnable.transferOwnershipRequest({
149
+ from: ownerAddress
150
+ });
151
+
152
+ // Approve after time lock period
153
+ const approvalResult = await secureOwnable.transferOwnershipDelayedApproval(
154
+ txId,
155
+ { from: ownerAddress }
156
+ );
157
+
158
+ // Cancel ownership transfer
159
+ const cancelResult = await secureOwnable.transferOwnershipCancellation(
160
+ txId,
161
+ { from: ownerAddress }
162
+ );
163
+ ```
164
+
165
+ ### Meta Transactions
166
+
167
+ ```typescript
168
+ // Create meta transaction parameters
169
+ const metaTxParams = await secureOwnable.createMetaTxParams(
170
+ handlerContract,
171
+ handlerSelector,
172
+ deadline,
173
+ maxGasPrice,
174
+ signer
175
+ );
176
+
177
+ // Generate unsigned meta transaction
178
+ const metaTx = await secureOwnable.generateUnsignedMetaTransactionForNew(
179
+ requester,
180
+ target,
181
+ value,
182
+ gasLimit,
183
+ operationType,
184
+ executionType,
185
+ executionOptions,
186
+ metaTxParams
187
+ );
188
+ ```
189
+
190
+ ## RuntimeRBAC Usage
191
+
192
+ RuntimeRBAC uses batch-based configuration for all role management operations. See the [RuntimeRBAC Guide](../../docs/runtime-rbac.md) for complete examples.
193
+
194
+ ### Query Functions
195
+
196
+ ```typescript
197
+ // Get role information
198
+ const role = await runtimeRBAC.getRole(roleHash);
199
+ console.log(role.roleName, role.maxWallets, role.isProtected);
200
+
201
+ // Check if wallet has role
202
+ const hasRole = await runtimeRBAC.hasRole(roleHash, walletAddress);
203
+
204
+ // Get authorized wallets in role
205
+ const wallets = await runtimeRBAC.getAuthorizedWallets(roleHash);
206
+
207
+ // Get roles for a wallet
208
+ const walletRoles = await runtimeRBAC.getWalletRoles(walletAddress);
209
+
210
+ // Get supported roles
211
+ const supportedRoles = await runtimeRBAC.getSupportedRoles();
212
+
213
+ // Get active role permissions
214
+ const permissions = await runtimeRBAC.getActiveRolePermissions(roleHash);
215
+ ```
216
+
217
+ ### Batch Configuration
218
+
219
+ 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.
220
+
221
+ ## Definitions Usage
222
+
223
+ 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.
224
+
225
+ ### Basic Usage
226
+
227
+ ```typescript
228
+ // Initialize Definitions
229
+ const definitions = new Definitions(
230
+ publicClient,
231
+ walletClient,
232
+ definitionsAddress,
233
+ chain
234
+ );
235
+
236
+ // Get all operation types
237
+ const operationTypes = await definitions.getOperationTypes();
238
+ console.log('Available operations:', operationTypes);
239
+
240
+ // Get all function schemas
241
+ const functionSchemas = await definitions.getFunctionSchemas();
242
+ console.log('Function schemas:', functionSchemas);
243
+
244
+ // Get role permissions
245
+ const rolePermissions = await definitions.getRolePermissions();
246
+ console.log('Role permissions:', rolePermissions);
247
+ ```
248
+
249
+ ### Workflow Management
250
+
251
+ ```typescript
252
+ // Get all operation workflows
253
+ const workflows = await definitions.getOperationWorkflows();
254
+ console.log('Available workflows:', workflows);
255
+
256
+ // Get workflow for specific operation
257
+ const operationType = '0x1234...'; // operation type hash
258
+ const workflow = await definitions.getWorkflowForOperation(operationType);
259
+ console.log('Workflow for operation:', workflow);
260
+
261
+ // Get all workflow paths
262
+ const paths = await definitions.getWorkflowPaths();
263
+ console.log('Available paths:', paths);
264
+ ```
265
+
266
+ ### Utility Functions
267
+
268
+ ```typescript
269
+ // Find operation type by name
270
+ const operationType = await definitions.getOperationTypeByName('TRANSFER_OWNERSHIP');
271
+ console.log('Operation type hash:', operationType);
272
+
273
+ // Get function schema by selector
274
+ const functionSelector = '0xabcd...';
275
+ const schema = await definitions.getFunctionSchemaBySelector(functionSelector);
276
+ console.log('Function schema:', schema);
277
+
278
+ // Check role permission for function
279
+ const roleHash = '0xefgh...';
280
+ const hasPermission = await definitions.hasRolePermission(roleHash, functionSelector);
281
+ console.log('Has permission:', hasPermission);
282
+
283
+ // Get all roles that can execute a function
284
+ const allowedRoles = await definitions.getRolesForFunction(functionSelector);
285
+ console.log('Allowed roles:', allowedRoles);
286
+ ```
287
+
288
+ ### Configuration Management
289
+
290
+ ```typescript
291
+ // Get current configuration
292
+ const config = definitions.getConfig();
293
+ console.log('Current config:', config);
294
+
295
+ // Update configuration
296
+ definitions.updateConfig({
297
+ chainId: 137, // Polygon
298
+ rpcUrl: 'https://polygon-rpc.com'
299
+ });
300
+ ```
301
+
302
+ ## Types and Constants
303
+
304
+ ### Transaction Actions
305
+
306
+ ```typescript
307
+ import { TxAction } from '@bloxchain/sdk';
308
+
309
+ // Available transaction actions
310
+ TxAction.EXECUTE_TIME_DELAY_REQUEST
311
+ TxAction.EXECUTE_TIME_DELAY_APPROVE
312
+ TxAction.EXECUTE_TIME_DELAY_CANCEL
313
+ TxAction.SIGN_META_REQUEST_AND_APPROVE
314
+ TxAction.SIGN_META_APPROVE
315
+ TxAction.SIGN_META_CANCEL
316
+ TxAction.EXECUTE_META_REQUEST_AND_APPROVE
317
+ TxAction.EXECUTE_META_APPROVE
318
+ TxAction.EXECUTE_META_CANCEL
319
+ ```
320
+
321
+ ### Execution Types
322
+
323
+ ```typescript
324
+ import { ExecutionType } from '@bloxchain/sdk';
325
+
326
+ ExecutionType.NONE
327
+ ExecutionType.STANDARD
328
+ ExecutionType.RAW
329
+ ```
330
+
331
+ ### Transaction Status
332
+
333
+ ```typescript
334
+ import { TxStatus } from '@bloxchain/sdk';
335
+
336
+ TxStatus.UNDEFINED
337
+ TxStatus.PENDING
338
+ TxStatus.EXECUTING
339
+ TxStatus.PROCESSING_PAYMENT
340
+ TxStatus.CANCELLED
341
+ TxStatus.COMPLETED
342
+ TxStatus.FAILED
343
+ ```
344
+
345
+ ### TxRecord (state machine transactions)
346
+
347
+ The canonical TypeScript shape matches on-chain `EngineBlox.TxRecord`. The completion hash field is **`resultHash`** (bytes32; zero while pending):
348
+
349
+ ```typescript
350
+ import type { TxRecord } from '@bloxchain/sdk';
351
+
352
+ const tx: TxRecord = await secureOwnable.getTransaction(txId);
353
+ console.log(tx.resultHash);
354
+ ```
355
+
356
+ ## Error Handling
357
+
358
+ All SDK methods throw errors for failed operations. Always wrap SDK calls in try-catch blocks:
359
+
360
+ ```typescript
361
+ try {
362
+ const result = await secureOwnable.transferOwnershipRequest({
363
+ from: ownerAddress
364
+ });
365
+ console.log('Transaction successful:', result.hash);
366
+ } catch (error) {
367
+ console.error('Transaction failed:', error);
368
+ }
369
+ ```
370
+
371
+ ## Security Considerations
372
+
373
+ - Always validate addresses and parameters before making transactions
374
+ - Use proper time-lock periods for critical operations
375
+ - Implement proper access control using RuntimeRBAC
376
+ - Monitor transaction status and handle failures appropriately
377
+ - Keep private keys secure and never expose them in client-side code
378
+
379
+ ## Versioning and stability
380
+
381
+ 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.
382
+
383
+ ## Security
384
+
385
+ - **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).
386
+ - **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.
387
+
388
+ ## Support and links
389
+
390
+ - **Documentation**: [SDK and protocol guides](../../docs/) in the repository `docs/` folder; [Bloxchain Protocol README](https://github.com/PracticalParticle/Bloxchain-Protocol#readme) for protocol details
391
+ - **Issues and feature requests**: [GitHub Issues](https://github.com/PracticalParticle/Bloxchain-Protocol/issues)
392
+ - **Homepage**: [bloxchain.app](https://bloxchain.app/)
393
+ - **Author**: [Particle Crypto Security](https://particlecs.com/)
394
+
395
+ ## Repository
396
+
397
+ Part of [Bloxchain Protocol](https://github.com/PracticalParticle/Bloxchain-Protocol). For protocol architecture and contract documentation, see the main repository README.
398
+
399
+ ## Contributing
400
+
401
+ When contributing to the SDK:
402
+
403
+ 1. Follow TypeScript best practices
404
+ 2. Add comprehensive type definitions
405
+ 3. Include JSDoc comments for all public methods
406
+ 4. Test all new functionality thoroughly
407
+ 5. Update this README with new features
408
+
409
+ ## License
410
+
411
+ 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.