@bloxchain/sdk 1.0.0-alpha.22 → 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 (106) hide show
  1. package/README.md +399 -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 +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-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 +7 -31
  91. package/dist/utils/interface-ids.d.ts.map +1 -1
  92. package/dist/utils/interface-ids.js +29 -85
  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,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-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` | 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.