@0xobelisk/client 0.4.8 → 1.2.0-pre.92

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 (64) hide show
  1. package/README.md +550 -2
  2. package/dist/browser/obelisk-client.js +102 -0
  3. package/dist/browser/obelisk-client.js.LICENSE.txt +16 -0
  4. package/dist/browser/obelisk-client.js.map +1 -0
  5. package/dist/browser/obelisk-client.min.js +101 -0
  6. package/dist/browser/obelisk-client.min.js.map +1 -0
  7. package/dist/index.d.ts +27 -9
  8. package/dist/sui/client.d.ts +59 -0
  9. package/dist/sui/index.d.mts +150 -0
  10. package/dist/sui/index.d.ts +19 -0
  11. package/dist/sui/index.js +92 -0
  12. package/dist/sui/index.js.map +1 -0
  13. package/dist/sui/index.mjs +87 -0
  14. package/dist/sui/index.mjs.map +1 -0
  15. package/dist/sui/types.d.ts +84 -0
  16. package/package.json +60 -121
  17. package/src/index.ts +31 -9
  18. package/src/sui/client.test.ts +277 -0
  19. package/src/sui/client.ts +156 -0
  20. package/src/sui/index.ts +30 -0
  21. package/src/sui/types.ts +87 -0
  22. package/LICENSE +0 -92
  23. package/dist/index.js +0 -1310
  24. package/dist/index.js.map +0 -1
  25. package/dist/index.mjs +0 -1291
  26. package/dist/index.mjs.map +0 -1
  27. package/dist/libs/suiAccountManager/crypto.d.ts +0 -1
  28. package/dist/libs/suiAccountManager/index.d.ts +0 -35
  29. package/dist/libs/suiAccountManager/keypair.d.ts +0 -21
  30. package/dist/libs/suiAccountManager/util.d.ts +0 -29
  31. package/dist/libs/suiContractFactory/index.d.ts +0 -20
  32. package/dist/libs/suiContractFactory/types.d.ts +0 -49
  33. package/dist/libs/suiInteractor/defaultConfig.d.ts +0 -10
  34. package/dist/libs/suiInteractor/index.d.ts +0 -2
  35. package/dist/libs/suiInteractor/suiInteractor.d.ts +0 -205
  36. package/dist/libs/suiInteractor/util.d.ts +0 -1
  37. package/dist/libs/suiModel/index.d.ts +0 -2
  38. package/dist/libs/suiModel/suiOwnedObject.d.ts +0 -24
  39. package/dist/libs/suiModel/suiSharedObject.d.ts +0 -12
  40. package/dist/libs/suiTxBuilder/index.d.ts +0 -544
  41. package/dist/libs/suiTxBuilder/util.d.ts +0 -76
  42. package/dist/metadata/index.d.ts +0 -34
  43. package/dist/obelisk.d.ts +0 -2568
  44. package/dist/types/index.d.ts +0 -141
  45. package/dist/utils/index.d.ts +0 -3
  46. package/src/libs/suiAccountManager/crypto.ts +0 -7
  47. package/src/libs/suiAccountManager/index.ts +0 -72
  48. package/src/libs/suiAccountManager/keypair.ts +0 -38
  49. package/src/libs/suiAccountManager/util.ts +0 -70
  50. package/src/libs/suiContractFactory/index.ts +0 -120
  51. package/src/libs/suiContractFactory/types.ts +0 -54
  52. package/src/libs/suiInteractor/defaultConfig.ts +0 -32
  53. package/src/libs/suiInteractor/index.ts +0 -2
  54. package/src/libs/suiInteractor/suiInteractor.ts +0 -319
  55. package/src/libs/suiInteractor/util.ts +0 -2
  56. package/src/libs/suiModel/index.ts +0 -2
  57. package/src/libs/suiModel/suiOwnedObject.ts +0 -62
  58. package/src/libs/suiModel/suiSharedObject.ts +0 -33
  59. package/src/libs/suiTxBuilder/index.ts +0 -245
  60. package/src/libs/suiTxBuilder/util.ts +0 -84
  61. package/src/metadata/index.ts +0 -22
  62. package/src/obelisk.ts +0 -625
  63. package/src/types/index.ts +0 -205
  64. package/src/utils/index.ts +0 -23
package/README.md CHANGED
@@ -1,3 +1,551 @@
1
- #
1
+ # @0xobelisk/client
2
2
 
3
- Test QA
3
+ Unified client creation layer for Dubhe framework with multi-chain support.
4
+
5
+ ## 🚀 Features
6
+
7
+ - **🎯 Unified Interface** - Configuration aligned with @0xobelisk/react for consistency
8
+ - **⚡ All-in-One Bundle** - Contract, GraphQL, gRPC, and ECS clients in one call
9
+ - **🛡️ Type Safety** - Complete TypeScript support with strict typing
10
+ - **🌐 Platform Agnostic** - Works in Browser, Node.js, and COCOS
11
+ - **📦 Multi-Chain Ready** - Extensible architecture for multiple blockchains
12
+ - **🔧 Factory Pattern** - Simple client instantiation with validation
13
+
14
+ ## 📦 Installation
15
+
16
+ ```bash
17
+ # Install the client package
18
+ npm install @0xobelisk/client
19
+
20
+ # Peer dependencies (automatically installed in most cases)
21
+ npm install @0xobelisk/sui-client @0xobelisk/graphql-client @0xobelisk/grpc-client @0xobelisk/ecs
22
+ ```
23
+
24
+ ### Requirements
25
+
26
+ - **Node.js**: 18.0.0+
27
+ - **TypeScript**: 5.0+ (recommended)
28
+
29
+ ## 🌐 Multi-Chain Support
30
+
31
+ | Blockchain | Status | Import Path |
32
+ | ---------- | -------------- | -------------------------- |
33
+ | **Sui** | ✅ Ready | `@0xobelisk/client/sui` |
34
+ | **Aptos** | 🚧 Coming Soon | `@0xobelisk/client/aptos` |
35
+ | **Initia** | 🚧 Coming Soon | `@0xobelisk/client/initia` |
36
+ | **Rooch** | 🚧 Coming Soon | `@0xobelisk/client/rooch` |
37
+
38
+ ## 🚀 Quick Start
39
+
40
+ ### Basic Usage
41
+
42
+ ```typescript
43
+ import { createClient } from '@0xobelisk/client/sui';
44
+ import { Transaction } from '@0xobelisk/sui-client';
45
+ import metadata from './contracts/metadata.json';
46
+
47
+ // Create client with configuration
48
+ const client = createClient({
49
+ network: 'devnet',
50
+ packageId: '0x123...',
51
+ metadata,
52
+ credentials: {
53
+ secretKey: process.env.PRIVATE_KEY
54
+ }
55
+ });
56
+
57
+ // Access all clients from the bundle
58
+ const { contract, graphqlClient, grpcClient, ecsWorld, address } = client;
59
+
60
+ console.log('Connected as:', address);
61
+
62
+ // Execute a transaction
63
+ const tx = new Transaction();
64
+ const result = await contract.tx.counter_system.inc({ tx });
65
+ console.log('Transaction result:', result);
66
+ ```
67
+
68
+ ### With Custom Endpoints
69
+
70
+ ```typescript
71
+ const client = createClient({
72
+ network: 'testnet',
73
+ packageId: '0x456...',
74
+ metadata,
75
+ credentials: {
76
+ mnemonics: 'your twelve word mnemonic phrase here...'
77
+ },
78
+ endpoints: {
79
+ fullnodeUrls: ['https://custom-rpc.example.com'],
80
+ graphql: 'https://graphql.example.com/graphql',
81
+ websocket: 'wss://graphql.example.com/graphql',
82
+ grpc: 'https://grpc.example.com'
83
+ }
84
+ });
85
+ ```
86
+
87
+ ### With Performance Options
88
+
89
+ ```typescript
90
+ const client = createClient({
91
+ network: 'mainnet',
92
+ packageId: '0x789...',
93
+ metadata,
94
+ credentials: { secretKey: '...' },
95
+ options: {
96
+ enableBatchOptimization: true,
97
+ cacheTimeout: 10000,
98
+ debounceMs: 200,
99
+ reconnectOnError: true
100
+ }
101
+ });
102
+ ```
103
+
104
+ ## 🌐 Browser Usage
105
+
106
+ The `@0xobelisk/client` package can be used directly in browsers via a UMD bundle, perfect for vanilla JavaScript projects, Cocos Engine, Flutter WebView, and other browser environments.
107
+
108
+ ### CDN (Recommended)
109
+
110
+ ```html
111
+ <!-- Latest version -->
112
+ <script src="https://unpkg.com/@0xobelisk/client@latest/dist/browser/obelisk-client.min.js"></script>
113
+
114
+ <!-- Specific version (recommended for production) -->
115
+ <script src="https://unpkg.com/@0xobelisk/client@1.2.0/dist/browser/obelisk-client.min.js"></script>
116
+ ```
117
+
118
+ ### Local Installation
119
+
120
+ ```html
121
+ <script src="./node_modules/@0xobelisk/client/dist/browser/obelisk-client.min.js"></script>
122
+ ```
123
+
124
+ ### Basic Browser Example
125
+
126
+ ```html
127
+ <!DOCTYPE html>
128
+ <html>
129
+ <head>
130
+ <title>Obelisk Client Demo</title>
131
+ </head>
132
+ <body>
133
+ <h1>Dubhe Client Browser Example</h1>
134
+ <button id="connect">Connect</button>
135
+ <div id="result"></div>
136
+
137
+ <!-- Load the client -->
138
+ <script src="https://unpkg.com/@0xobelisk/client@latest/dist/browser/obelisk-client.min.js"></script>
139
+
140
+ <script>
141
+ // Access via global variable
142
+ const { createClient } = window.ObeliskClient;
143
+
144
+ document.getElementById('connect').addEventListener('click', async () => {
145
+ try {
146
+ // Create client
147
+ const client = createClient({
148
+ network: 'devnet',
149
+ packageId: '0x123...',
150
+ metadata: {...}, // Your contract metadata
151
+ credentials: {
152
+ secretKey: 'your-private-key'
153
+ }
154
+ });
155
+
156
+ // Use the client
157
+ const { contract, address } = client;
158
+ document.getElementById('result').innerHTML =
159
+ `Connected as: ${address}`;
160
+
161
+ // Execute transaction
162
+ const tx = new Transaction();
163
+ const result = await contract.tx.counter_system.inc({ tx });
164
+ console.log('Transaction result:', result);
165
+
166
+ } catch (error) {
167
+ console.error('Error:', error);
168
+ document.getElementById('result').innerHTML =
169
+ `Error: ${error.message}`;
170
+ }
171
+ });
172
+ </script>
173
+ </body>
174
+ </html>
175
+ ```
176
+
177
+ ### Cocos Engine Integration
178
+
179
+ ```javascript
180
+ // In your Cocos Creator script
181
+ const { Component } = cc;
182
+
183
+ cc.Class({
184
+ extends: Component,
185
+
186
+ onLoad() {
187
+ // Access ObeliskClient from window
188
+ const { createClient } = window.ObeliskClient;
189
+
190
+ this.client = createClient({
191
+ network: 'mainnet',
192
+ packageId: '0xabc...',
193
+ metadata: this.contractMetadata,
194
+ credentials: {
195
+ secretKey: this.privateKey
196
+ }
197
+ });
198
+
199
+ console.log('Dubhe client initialized:', this.client.address);
200
+ },
201
+
202
+ async executeTransaction() {
203
+ const tx = new Transaction();
204
+ const result = await this.client.contract.tx.game_system.move({
205
+ tx,
206
+ params: [this.x, this.y]
207
+ });
208
+ console.log('Move result:', result);
209
+ }
210
+ });
211
+ ```
212
+
213
+ ### Flutter WebView Integration
214
+
215
+ ```dart
216
+ import 'package:flutter/material.dart';
217
+ import 'package:webview_flutter/webview_flutter.dart';
218
+
219
+ class DubheWebView extends StatefulWidget {
220
+ @override
221
+ _DubheWebViewState createState() => _DubheWebViewState();
222
+ }
223
+
224
+ class _DubheWebViewState extends State<DubheWebView> {
225
+ late final WebViewController controller;
226
+
227
+ @override
228
+ void initState() {
229
+ super.initState();
230
+
231
+ controller = WebViewController()
232
+ ..setJavaScriptMode(JavaScriptMode.unrestricted)
233
+ ..loadHtmlString('''
234
+ <!DOCTYPE html>
235
+ <html>
236
+ <head>
237
+ <script src="https://unpkg.com/@0xobelisk/client@latest/dist/browser/obelisk-client.min.js"></script>
238
+ </head>
239
+ <body>
240
+ <script>
241
+ const { createClient } = window.ObeliskClient;
242
+
243
+ // Initialize client
244
+ window.dubheClient = createClient({
245
+ network: 'testnet',
246
+ packageId: '0x123...',
247
+ metadata: {...}
248
+ });
249
+
250
+ // Expose functions to Flutter
251
+ window.executeMove = async (x, y) => {
252
+ const tx = new Transaction();
253
+ const result = await window.dubheClient.contract.tx.move({
254
+ tx,
255
+ params: [x, y]
256
+ });
257
+ return JSON.stringify(result);
258
+ };
259
+ </script>
260
+ </body>
261
+ </html>
262
+ ''');
263
+ }
264
+
265
+ Future<void> callMove(int x, int y) async {
266
+ final result = await controller.runJavaScriptReturningResult(
267
+ 'window.executeMove($x, $y)'
268
+ );
269
+ print('Move result: $result');
270
+ }
271
+
272
+ @override
273
+ Widget build(BuildContext context) {
274
+ return WebViewWidget(controller: controller);
275
+ }
276
+ }
277
+ ```
278
+
279
+ ### Browser Build Files
280
+
281
+ The package provides two versions:
282
+
283
+ | File | Size | Use Case |
284
+ | ----------------------- | ------- | ------------------------------ |
285
+ | `obelisk-client.js` | ~241 KB | Development (with source maps) |
286
+ | `obelisk-client.min.js` | ~242 KB | Production (optimized) |
287
+
288
+ ### Global API
289
+
290
+ When loaded in the browser, all exports are available under `window.ObeliskClient`:
291
+
292
+ ```javascript
293
+ // Available functions
294
+ window.ObeliskClient.createClient;
295
+ window.ObeliskClient.createClientWithValidation;
296
+ window.ObeliskClient.validateClientConfig;
297
+ window.ObeliskClient.isNetworkType;
298
+ ```
299
+
300
+ ### TypeScript Support for Browser
301
+
302
+ If you're using TypeScript in a browser environment, you can still get type safety:
303
+
304
+ ```typescript
305
+ declare global {
306
+ interface Window {
307
+ ObeliskClient: typeof import('@0xobelisk/client/sui');
308
+ }
309
+ }
310
+
311
+ const { createClient } = window.ObeliskClient;
312
+ ```
313
+
314
+ ## 📖 API Reference
315
+
316
+ ### `createClient(config: ClientConfig): DubheClientBundle`
317
+
318
+ Creates a complete Dubhe client bundle with all necessary instances.
319
+
320
+ #### Configuration (`ClientConfig`)
321
+
322
+ | Property | Type | Required | Description |
323
+ | --------------- | ----------- | -------- | --------------------------------------------------- |
324
+ | `network` | NetworkType | ✅ | Network: 'mainnet', 'testnet', 'devnet', 'localnet' |
325
+ | `packageId` | string | ✅ | Contract package ID |
326
+ | `metadata` | any | ✅ | Contract metadata (from dubhe schemagen) |
327
+ | `dubheSchemaId` | string | ❌ | Dubhe Schema ID for enhanced features |
328
+ | `dubheMetadata` | any | ❌ | Dubhe metadata for GraphQL/ECS |
329
+ | `credentials` | object | ❌ | Authentication credentials |
330
+ | `endpoints` | object | ❌ | Custom service endpoints |
331
+ | `options` | object | ❌ | Performance and behavior options |
332
+
333
+ #### Credentials
334
+
335
+ ```typescript
336
+ credentials?: {
337
+ secretKey?: string; // Private key (base64 or hex)
338
+ mnemonics?: string; // 12 or 24 word mnemonic phrase
339
+ }
340
+ ```
341
+
342
+ #### Endpoints
343
+
344
+ ```typescript
345
+ endpoints?: {
346
+ fullnodeUrls?: string[]; // RPC node URLs (multiple for redundancy)
347
+ graphql?: string; // GraphQL endpoint (default: http://localhost:4000/graphql)
348
+ websocket?: string; // WebSocket endpoint (default: ws://localhost:4000/graphql)
349
+ grpc?: string; // gRPC endpoint (default: http://localhost:50051)
350
+ }
351
+ ```
352
+
353
+ #### Options
354
+
355
+ ```typescript
356
+ options?: {
357
+ enableBatchOptimization?: boolean; // Default: true
358
+ cacheTimeout?: number; // Default: 5000 (ms)
359
+ debounceMs?: number; // Default: 100 (ms)
360
+ reconnectOnError?: boolean; // Default: true
361
+ }
362
+ ```
363
+
364
+ #### Return Type (`DubheClientBundle`)
365
+
366
+ ```typescript
367
+ {
368
+ contract: Dubhe; // Main contract client
369
+ graphqlClient: DubheGraphqlClient; // GraphQL query client
370
+ grpcClient: DubheGrpcClient; // gRPC client
371
+ ecsWorld: DubheECSWorld; // ECS World for entity queries
372
+ metadata: SuiMoveNormalizedModules; // Contract metadata
373
+ network: NetworkType; // Network type
374
+ packageId: string; // Package ID
375
+ dubheSchemaId?: string; // Schema ID (if provided)
376
+ address: string; // User address
377
+ options?: {...}; // Options used
378
+ }
379
+ ```
380
+
381
+ ### `createClientWithValidation(config: Partial<ClientConfig>): DubheClientBundle`
382
+
383
+ Creates a client with strict configuration validation. Throws descriptive errors for invalid configurations.
384
+
385
+ ```typescript
386
+ try {
387
+ const client = createClientWithValidation(externalConfig);
388
+ } catch (error) {
389
+ console.error('Invalid configuration:', error.message);
390
+ }
391
+ ```
392
+
393
+ ### `validateClientConfig(config: Partial<ClientConfig>): asserts config is ClientConfig`
394
+
395
+ Validates a configuration object. Useful for pre-validation before client creation.
396
+
397
+ ```typescript
398
+ const config = loadFromFile();
399
+ validateClientConfig(config); // Throws if invalid
400
+ // config is now guaranteed to be valid
401
+ ```
402
+
403
+ ## 🔍 Usage Examples
404
+
405
+ ### Contract Interactions
406
+
407
+ ```typescript
408
+ import { Transaction } from '@0xobelisk/sui-client';
409
+
410
+ const client = createClient({
411
+ /* ... */
412
+ });
413
+
414
+ // Execute a contract method
415
+ const tx = new Transaction();
416
+ await client.contract.tx.my_system.my_method({
417
+ tx,
418
+ params: [arg1, arg2]
419
+ });
420
+
421
+ // Query contract state
422
+ const result = await client.contract.query.my_system.get_value({
423
+ tx: new Transaction()
424
+ });
425
+ ```
426
+
427
+ ### GraphQL Queries
428
+
429
+ ```typescript
430
+ // Query indexed data
431
+ const data = await client.graphqlClient.query({
432
+ query: `
433
+ query GetEntities {
434
+ entities {
435
+ id
436
+ components
437
+ }
438
+ }
439
+ `
440
+ });
441
+
442
+ // Subscribe to real-time updates
443
+ client.graphqlClient.subscribe({
444
+ query: `
445
+ subscription OnEntityUpdate {
446
+ entityUpdated {
447
+ id
448
+ components
449
+ }
450
+ }
451
+ `,
452
+ onData: (data) => {
453
+ console.log('Entity updated:', data);
454
+ }
455
+ });
456
+ ```
457
+
458
+ ### ECS World Queries
459
+
460
+ ```typescript
461
+ // Get all entities
462
+ const entities = client.ecsWorld.getEntities();
463
+
464
+ // Query entities with specific components
465
+ const filtered = client.ecsWorld.queryEntities({
466
+ with: ['Position', 'Velocity']
467
+ });
468
+
469
+ // Watch for entity changes
470
+ client.ecsWorld.watchEntity(entityId, (entity) => {
471
+ console.log('Entity changed:', entity);
472
+ });
473
+ ```
474
+
475
+ ### gRPC Queries
476
+
477
+ ```typescript
478
+ // High-performance queries via gRPC
479
+ const response = await client.grpcClient.query({
480
+ method: 'GetEntity',
481
+ params: { entityId: '0x123...' }
482
+ });
483
+ ```
484
+
485
+ ## 🆚 Comparison with Other Packages
486
+
487
+ | Package | Use Case | Dependencies |
488
+ | ----------------------- | ------------------------------- | --------------- |
489
+ | `@0xobelisk/sui-client` | Low-level contract interactions | None |
490
+ | `@0xobelisk/client` | Unified client for any platform | sui-client, etc |
491
+ | `@0xobelisk/react` | React applications with hooks | React, client |
492
+
493
+ **When to use @0xobelisk/client:**
494
+
495
+ - Node.js scripts and backend services
496
+ - COCOS game engine integration
497
+ - Browser applications without React
498
+ - When you need all client types (contract + GraphQL + ECS)
499
+ - Consistency with @0xobelisk/react configuration
500
+
501
+ **When to use @0xobelisk/sui-client:**
502
+
503
+ - You only need contract interactions
504
+ - Minimal dependencies are important
505
+ - Custom client setup is required
506
+
507
+ ## 🛠️ Development
508
+
509
+ ### Build
510
+
511
+ ```bash
512
+ pnpm build
513
+ ```
514
+
515
+ ### Type Check
516
+
517
+ ```bash
518
+ pnpm type-check
519
+ ```
520
+
521
+ ### Linting
522
+
523
+ ```bash
524
+ pnpm lint
525
+ ```
526
+
527
+ ### Watch Mode
528
+
529
+ ```bash
530
+ pnpm watch
531
+ ```
532
+
533
+ ## 📄 License
534
+
535
+ Apache-2.0
536
+
537
+ ## 🤝 Contributing
538
+
539
+ Contributions welcome! Please read our contributing guidelines and submit PRs to the [main repository](https://github.com/0xobelisk/dubhe).
540
+
541
+ ## 📚 Resources
542
+
543
+ - [Dubhe Documentation](https://docs.obelisk.build)
544
+ - [GitHub Repository](https://github.com/0xobelisk/dubhe)
545
+ - [Examples](https://github.com/0xobelisk/dubhe/tree/main/examples)
546
+
547
+ ## 💬 Support
548
+
549
+ - Discord: [Join our community](https://discord.gg/obelisk)
550
+ - Twitter: [@0xobelisk](https://twitter.com/0xobelisk)
551
+ - Email: team@obelisk.build