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

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 +154 -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 +88 -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 +92 -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/dist/index.d.ts CHANGED
@@ -1,9 +1,27 @@
1
- export * from '@mysten/sui.js';
2
- export { Ed25519Keypair } from '@mysten/sui.js/keypairs/ed25519';
3
- export { BCS, getSuiMoveConfig } from '@mysten/bcs';
4
- export { Obelisk } from './obelisk';
5
- export { SuiAccountManager } from './libs/suiAccountManager';
6
- export { SuiTxBlock } from './libs/suiTxBuilder';
7
- export { SuiContractFactory } from './libs/suiContractFactory';
8
- export { loadMetadata } from './metadata';
9
- export type * from './types';
1
+ /**
2
+ * @0xobelisk/client - Unified Client Creation Layer for Dubhe Framework
3
+ *
4
+ * This package provides a unified interface for creating blockchain clients
5
+ * across different chains. Currently supports Sui, with more chains coming soon.
6
+ *
7
+ * Usage:
8
+ * - For Sui: import from '@0xobelisk/client/sui'
9
+ * - For Aptos: import from '@0xobelisk/client/aptos' (coming soon)
10
+ * - For Initia: import from '@0xobelisk/client/initia' (coming soon)
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { createClient } from '@0xobelisk/client/sui';
15
+ *
16
+ * const client = createClient({
17
+ * network: 'devnet',
18
+ * packageId: '0x123...',
19
+ * metadata: contractMetadata,
20
+ * credentials: { secretKey: '...' }
21
+ * });
22
+ * ```
23
+ */
24
+ /**
25
+ * Note: Import chain-specific clients from their subpaths:
26
+ * - '@0xobelisk/client/sui'
27
+ */
@@ -0,0 +1,59 @@
1
+ import type { ClientConfig, DubheClientBundle } from './types';
2
+ /**
3
+ * Create a Dubhe client bundle with all necessary instances
4
+ *
5
+ * This factory function creates and initializes:
6
+ * - Dubhe contract client for on-chain interactions
7
+ * - GraphQL client for querying indexed data
8
+ * - gRPC client for high-performance queries
9
+ * - ECS World for entity-component-system queries
10
+ *
11
+ * @param config - Client configuration matching @0xobelisk/react interface
12
+ * @returns DubheClientBundle with all initialized client instances
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { createClient } from '@0xobelisk/client/sui';
17
+ * import metadata from './metadata.json';
18
+ *
19
+ * const client = createClient({
20
+ * network: 'devnet',
21
+ * packageId: '0x123...',
22
+ * metadata,
23
+ * credentials: {
24
+ * secretKey: process.env.PRIVATE_KEY
25
+ * }
26
+ * });
27
+ *
28
+ * // Use the contract client
29
+ * const tx = new Transaction();
30
+ * await client.contract.tx.counter_system.inc({ tx });
31
+ *
32
+ * // Use GraphQL client
33
+ * const data = await client.graphqlClient.query(...);
34
+ *
35
+ * // Use ECS World
36
+ * const entities = client.ecsWorld.getEntities();
37
+ * ```
38
+ */
39
+ export declare function createClient(config: ClientConfig): DubheClientBundle;
40
+ /**
41
+ * Type guard to check if a value is a valid NetworkType
42
+ */
43
+ export declare function isNetworkType(value: string): value is ClientConfig['network'];
44
+ /**
45
+ * Helper function to validate client configuration
46
+ * Throws descriptive errors for invalid configurations
47
+ */
48
+ export declare function validateClientConfig(config: Partial<ClientConfig>): asserts config is ClientConfig;
49
+ /**
50
+ * Create client with configuration validation
51
+ * Useful when working with external configuration sources
52
+ *
53
+ * @example
54
+ * ```typescript
55
+ * const config = loadConfigFromFile(); // May be incomplete
56
+ * const client = createClientWithValidation(config); // Throws if invalid
57
+ * ```
58
+ */
59
+ export declare function createClientWithValidation(config: Partial<ClientConfig>): DubheClientBundle;
@@ -0,0 +1,154 @@
1
+ import { Dubhe, SuiMoveNormalizedModules } from '@0xobelisk/sui-client';
2
+ export { Dubhe } from '@0xobelisk/sui-client';
3
+ import { DubheGraphqlClient } from '@0xobelisk/graphql-client';
4
+ export { DubheGraphqlClient } from '@0xobelisk/graphql-client';
5
+ import { DubheECSWorld } from '@0xobelisk/ecs';
6
+ export { DubheECSWorld } from '@0xobelisk/ecs';
7
+ import { DubheGrpcClient } from '@0xobelisk/grpc-client';
8
+ export { DubheGrpcClient } from '@0xobelisk/grpc-client';
9
+
10
+ /**
11
+ * Network type for Sui blockchain
12
+ */
13
+ type NetworkType = 'mainnet' | 'testnet' | 'devnet' | 'localnet';
14
+ /**
15
+ * Client configuration interface
16
+ * Aligned with @0xobelisk/react configuration for consistency
17
+ */
18
+ interface ClientConfig {
19
+ /** Network type */
20
+ network: NetworkType;
21
+ /** Contract package ID */
22
+ packageId: string;
23
+ /** Contract metadata (required for contract instantiation) */
24
+ metadata: any;
25
+ /** Dubhe Schema ID (optional, for enhanced features) */
26
+ dubheSchemaId?: string;
27
+ /** Dubhe metadata (enables GraphQL/ECS features) */
28
+ dubheMetadata?: any;
29
+ /** Authentication credentials */
30
+ credentials?: {
31
+ /** Private key (base64 or hex string) */
32
+ secretKey?: string;
33
+ /** Mnemonic phrase (12 or 24 words) */
34
+ mnemonics?: string;
35
+ };
36
+ /** Service endpoints configuration */
37
+ endpoints?: {
38
+ /** Full node RPC URLs (can provide multiple for redundancy) */
39
+ fullnodeUrls?: string[];
40
+ /** GraphQL endpoint URL */
41
+ graphql?: string;
42
+ /** WebSocket endpoint URL for subscriptions */
43
+ websocket?: string;
44
+ /** gRPC endpoint URL */
45
+ grpc?: string;
46
+ };
47
+ /** Performance and behavior options */
48
+ options?: {
49
+ /** Enable batch query optimization */
50
+ enableBatchOptimization?: boolean;
51
+ /** Default cache timeout (milliseconds) */
52
+ cacheTimeout?: number;
53
+ /** Request debounce delay (milliseconds) */
54
+ debounceMs?: number;
55
+ /** Auto-reconnect on WebSocket errors */
56
+ reconnectOnError?: boolean;
57
+ };
58
+ }
59
+ /**
60
+ * Type alias for consistency with @0xobelisk/react package
61
+ */
62
+ type DubheConfig = ClientConfig;
63
+ /**
64
+ * Client bundle returned by createClient
65
+ * Contains all initialized client instances
66
+ */
67
+ interface DubheClientBundle {
68
+ /** Dubhe contract instance - core client for contract interactions */
69
+ contract: Dubhe;
70
+ /** GraphQL client for querying indexed data */
71
+ graphqlClient: DubheGraphqlClient;
72
+ /** gRPC client for high-performance queries */
73
+ grpcClient: DubheGrpcClient;
74
+ /** ECS World instance for entity-component-system queries */
75
+ ecsWorld: DubheECSWorld;
76
+ /** Contract metadata */
77
+ metadata: SuiMoveNormalizedModules;
78
+ /** Network type */
79
+ network: NetworkType;
80
+ /** Package ID */
81
+ packageId: string;
82
+ /** Dubhe Schema ID (if provided) */
83
+ dubheSchemaId?: string;
84
+ /** User address */
85
+ address: string;
86
+ /** Configuration options used */
87
+ options?: {
88
+ enableBatchOptimization?: boolean;
89
+ cacheTimeout?: number;
90
+ debounceMs?: number;
91
+ reconnectOnError?: boolean;
92
+ };
93
+ }
94
+
95
+ /**
96
+ * Create a Dubhe client bundle with all necessary instances
97
+ *
98
+ * This factory function creates and initializes:
99
+ * - Dubhe contract client for on-chain interactions
100
+ * - GraphQL client for querying indexed data
101
+ * - gRPC client for high-performance queries
102
+ * - ECS World for entity-component-system queries
103
+ *
104
+ * @param config - Client configuration matching @0xobelisk/react interface
105
+ * @returns DubheClientBundle with all initialized client instances
106
+ *
107
+ * @example
108
+ * ```typescript
109
+ * import { createClient } from '@0xobelisk/client/sui';
110
+ * import metadata from './metadata.json';
111
+ *
112
+ * const client = createClient({
113
+ * network: 'devnet',
114
+ * packageId: '0x123...',
115
+ * metadata,
116
+ * credentials: {
117
+ * secretKey: process.env.PRIVATE_KEY
118
+ * }
119
+ * });
120
+ *
121
+ * // Use the contract client
122
+ * const tx = new Transaction();
123
+ * await client.contract.tx.counter_system.inc({ tx });
124
+ *
125
+ * // Use GraphQL client
126
+ * const data = await client.graphqlClient.query(...);
127
+ *
128
+ * // Use ECS World
129
+ * const entities = client.ecsWorld.getEntities();
130
+ * ```
131
+ */
132
+ declare function createClient(config: ClientConfig): DubheClientBundle;
133
+ /**
134
+ * Type guard to check if a value is a valid NetworkType
135
+ */
136
+ declare function isNetworkType(value: string): value is ClientConfig['network'];
137
+ /**
138
+ * Helper function to validate client configuration
139
+ * Throws descriptive errors for invalid configurations
140
+ */
141
+ declare function validateClientConfig(config: Partial<ClientConfig>): asserts config is ClientConfig;
142
+ /**
143
+ * Create client with configuration validation
144
+ * Useful when working with external configuration sources
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * const config = loadConfigFromFile(); // May be incomplete
149
+ * const client = createClientWithValidation(config); // Throws if invalid
150
+ * ```
151
+ */
152
+ declare function createClientWithValidation(config: Partial<ClientConfig>): DubheClientBundle;
153
+
154
+ export { type ClientConfig, type DubheClientBundle, type DubheConfig, type NetworkType, createClient, createClientWithValidation, isNetworkType, validateClientConfig };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @0xobelisk/client/sui - Unified Dubhe Client for Sui Blockchain
3
+ *
4
+ * 🚀 Simple, powerful client creation aligned with @0xobelisk/react
5
+ *
6
+ * Features:
7
+ * - ⚡ Unified configuration interface
8
+ * - 🔧 Factory pattern for easy instantiation
9
+ * - 🛡️ Complete type safety with strict TypeScript
10
+ * - 📦 All-in-one bundle with contract, GraphQL, gRPC, and ECS clients
11
+ * - 🎯 Intuitive API design
12
+ * - 🌐 Platform-agnostic (Browser, Node.js, COCOS)
13
+ */
14
+ export type { NetworkType, ClientConfig, DubheConfig, DubheClientBundle } from './types';
15
+ export { createClient, createClientWithValidation, validateClientConfig, isNetworkType } from './client';
16
+ export type { Dubhe } from '@0xobelisk/sui-client';
17
+ export type { DubheGraphqlClient } from '@0xobelisk/graphql-client';
18
+ export type { DubheECSWorld } from '@0xobelisk/ecs';
19
+ export type { DubheGrpcClient } from '@0xobelisk/grpc-client';
@@ -0,0 +1,92 @@
1
+ 'use strict';
2
+
3
+ var suiClient = require('@0xobelisk/sui-client');
4
+ var graphqlClient = require('@0xobelisk/graphql-client');
5
+ var ecs = require('@0xobelisk/ecs');
6
+ var grpcClient = require('@0xobelisk/grpc-client');
7
+
8
+ // src/sui/client.ts
9
+ function createClient(config) {
10
+ if (!config.network) {
11
+ throw new Error("ClientConfig: network is required");
12
+ }
13
+ if (!config.packageId) {
14
+ throw new Error("ClientConfig: packageId is required");
15
+ }
16
+ if (!config.metadata) {
17
+ throw new Error("ClientConfig: metadata is required");
18
+ }
19
+ const contract = new suiClient.Dubhe({
20
+ networkType: config.network,
21
+ packageId: config.packageId,
22
+ metadata: config.metadata,
23
+ secretKey: config.credentials?.secretKey,
24
+ mnemonics: config.credentials?.mnemonics,
25
+ fullnodeUrls: config.endpoints?.fullnodeUrls
26
+ });
27
+ const graphqlClient$1 = graphqlClient.createDubheGraphqlClient({
28
+ endpoint: config.endpoints?.graphql || "http://localhost:4000/graphql",
29
+ subscriptionEndpoint: config.endpoints?.websocket || "ws://localhost:4000/graphql",
30
+ dubheMetadata: config.dubheMetadata
31
+ });
32
+ const grpcClient$1 = new grpcClient.DubheGrpcClient({
33
+ baseUrl: config.endpoints?.grpc || "http://localhost:8080"
34
+ });
35
+ const ecsWorld = ecs.createECSWorld(graphqlClient$1, {
36
+ dubheMetadata: config.dubheMetadata,
37
+ queryConfig: {
38
+ enableBatchOptimization: config.options?.enableBatchOptimization ?? true,
39
+ defaultCacheTimeout: config.options?.cacheTimeout ?? 5e3
40
+ },
41
+ subscriptionConfig: {
42
+ defaultDebounceMs: config.options?.debounceMs ?? 100,
43
+ reconnectOnError: config.options?.reconnectOnError ?? true
44
+ }
45
+ });
46
+ const address = contract.getAddress();
47
+ return {
48
+ contract,
49
+ graphqlClient: graphqlClient$1,
50
+ grpcClient: grpcClient$1,
51
+ ecsWorld,
52
+ metadata: config.metadata,
53
+ network: config.network,
54
+ packageId: config.packageId,
55
+ dubheSchemaId: config.dubheSchemaId,
56
+ address,
57
+ options: config.options
58
+ };
59
+ }
60
+ function isNetworkType(value) {
61
+ return ["mainnet", "testnet", "devnet", "localnet"].includes(value);
62
+ }
63
+ function validateClientConfig(config) {
64
+ if (!config.network) {
65
+ throw new Error("ClientConfig validation failed: network is required");
66
+ }
67
+ if (!isNetworkType(config.network)) {
68
+ throw new Error(
69
+ `ClientConfig validation failed: invalid network type "${config.network}". Must be one of: mainnet, testnet, devnet, localnet`
70
+ );
71
+ }
72
+ if (!config.packageId) {
73
+ throw new Error("ClientConfig validation failed: packageId is required");
74
+ }
75
+ if (typeof config.packageId !== "string" || config.packageId.trim() === "") {
76
+ throw new Error("ClientConfig validation failed: packageId must be a non-empty string");
77
+ }
78
+ if (!config.metadata) {
79
+ throw new Error("ClientConfig validation failed: metadata is required");
80
+ }
81
+ }
82
+ function createClientWithValidation(config) {
83
+ validateClientConfig(config);
84
+ return createClient(config);
85
+ }
86
+
87
+ exports.createClient = createClient;
88
+ exports.createClientWithValidation = createClientWithValidation;
89
+ exports.isNetworkType = isNetworkType;
90
+ exports.validateClientConfig = validateClientConfig;
91
+ //# sourceMappingURL=out.js.map
92
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/sui/client.ts"],"names":[],"mappings":";AAAA,SAAS,aAAa;AACtB,SAAS,gCAAgC;AACzC,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAwCzB,SAAS,aAAa,QAAyC;AAEpE,MAAI,CAAC,OAAO,SAAS;AACnB,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACrD;AACA,MAAI,CAAC,OAAO,WAAW;AACrB,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AACA,MAAI,CAAC,OAAO,UAAU;AACpB,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AAGA,QAAM,WAAW,IAAI,MAAM;AAAA,IACzB,aAAa,OAAO;AAAA,IACpB,WAAW,OAAO;AAAA,IAClB,UAAU,OAAO;AAAA,IACjB,WAAW,OAAO,aAAa;AAAA,IAC/B,WAAW,OAAO,aAAa;AAAA,IAC/B,cAAc,OAAO,WAAW;AAAA,EAClC,CAAC;AAGD,QAAM,gBAAgB,yBAAyB;AAAA,IAC7C,UAAU,OAAO,WAAW,WAAW;AAAA,IACvC,sBAAsB,OAAO,WAAW,aAAa;AAAA,IACrD,eAAe,OAAO;AAAA,EACxB,CAAC;AAGD,QAAM,aAAa,IAAI,gBAAgB;AAAA,IACrC,SAAS,OAAO,WAAW,QAAQ;AAAA,EACrC,CAAC;AAGD,QAAM,WAAW,eAAe,eAAe;AAAA,IAC7C,eAAe,OAAO;AAAA,IACtB,aAAa;AAAA,MACX,yBAAyB,OAAO,SAAS,2BAA2B;AAAA,MACpE,qBAAqB,OAAO,SAAS,gBAAgB;AAAA,IACvD;AAAA,IACA,oBAAoB;AAAA,MAClB,mBAAmB,OAAO,SAAS,cAAc;AAAA,MACjD,kBAAkB,OAAO,SAAS,oBAAoB;AAAA,IACxD;AAAA,EACF,CAAC;AAGD,QAAM,UAAU,SAAS,WAAW;AAGpC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,OAAO;AAAA,IACjB,SAAS,OAAO;AAAA,IAChB,WAAW,OAAO;AAAA,IAClB,eAAe,OAAO;AAAA,IACtB;AAAA,IACA,SAAS,OAAO;AAAA,EAClB;AACF;AAKO,SAAS,cAAc,OAAiD;AAC7E,SAAO,CAAC,WAAW,WAAW,UAAU,UAAU,EAAE,SAAS,KAAK;AACpE;AAMO,SAAS,qBACd,QACgC;AAChC,MAAI,CAAC,OAAO,SAAS;AACnB,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AACA,MAAI,CAAC,cAAc,OAAO,OAAO,GAAG;AAClC,UAAM,IAAI;AAAA,MACR,yDAAyD,OAAO,OAAO;AAAA,IAEzE;AAAA,EACF;AACA,MAAI,CAAC,OAAO,WAAW;AACrB,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AACA,MAAI,OAAO,OAAO,cAAc,YAAY,OAAO,UAAU,KAAK,MAAM,IAAI;AAC1E,UAAM,IAAI,MAAM,sEAAsE;AAAA,EACxF;AACA,MAAI,CAAC,OAAO,UAAU;AACpB,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AACF;AAYO,SAAS,2BAA2B,QAAkD;AAC3F,uBAAqB,MAAM;AAC3B,SAAO,aAAa,MAAM;AAC5B","sourcesContent":["import { Dubhe } from '@0xobelisk/sui-client';\nimport { createDubheGraphqlClient } from '@0xobelisk/graphql-client';\nimport { createECSWorld } from '@0xobelisk/ecs';\nimport { DubheGrpcClient } from '@0xobelisk/grpc-client';\nimport type { ClientConfig, DubheClientBundle } from './types';\n\n/**\n * Create a Dubhe client bundle with all necessary instances\n *\n * This factory function creates and initializes:\n * - Dubhe contract client for on-chain interactions\n * - GraphQL client for querying indexed data\n * - gRPC client for high-performance queries\n * - ECS World for entity-component-system queries\n *\n * @param config - Client configuration matching @0xobelisk/react interface\n * @returns DubheClientBundle with all initialized client instances\n *\n * @example\n * ```typescript\n * import { createClient } from '@0xobelisk/client/sui';\n * import metadata from './metadata.json';\n *\n * const client = createClient({\n * network: 'devnet',\n * packageId: '0x123...',\n * metadata,\n * credentials: {\n * secretKey: process.env.PRIVATE_KEY\n * }\n * });\n *\n * // Use the contract client\n * const tx = new Transaction();\n * await client.contract.tx.counter_system.inc({ tx });\n *\n * // Use GraphQL client\n * const data = await client.graphqlClient.query(...);\n *\n * // Use ECS World\n * const entities = client.ecsWorld.getEntities();\n * ```\n */\nexport function createClient(config: ClientConfig): DubheClientBundle {\n // Validate required fields\n if (!config.network) {\n throw new Error('ClientConfig: network is required');\n }\n if (!config.packageId) {\n throw new Error('ClientConfig: packageId is required');\n }\n if (!config.metadata) {\n throw new Error('ClientConfig: metadata is required');\n }\n\n // Initialize Dubhe contract client\n const contract = new Dubhe({\n networkType: config.network,\n packageId: config.packageId,\n metadata: config.metadata,\n secretKey: config.credentials?.secretKey,\n mnemonics: config.credentials?.mnemonics,\n fullnodeUrls: config.endpoints?.fullnodeUrls\n });\n\n // Initialize GraphQL client with default localhost endpoint if not provided\n const graphqlClient = createDubheGraphqlClient({\n endpoint: config.endpoints?.graphql || 'http://localhost:4000/graphql',\n subscriptionEndpoint: config.endpoints?.websocket || 'ws://localhost:4000/graphql',\n dubheMetadata: config.dubheMetadata\n });\n\n // Initialize gRPC client with default localhost endpoint if not provided\n const grpcClient = new DubheGrpcClient({\n baseUrl: config.endpoints?.grpc || 'http://localhost:8080'\n });\n\n // Initialize ECS World (depends on GraphQL client)\n const ecsWorld = createECSWorld(graphqlClient, {\n dubheMetadata: config.dubheMetadata,\n queryConfig: {\n enableBatchOptimization: config.options?.enableBatchOptimization ?? true,\n defaultCacheTimeout: config.options?.cacheTimeout ?? 5000\n },\n subscriptionConfig: {\n defaultDebounceMs: config.options?.debounceMs ?? 100,\n reconnectOnError: config.options?.reconnectOnError ?? true\n }\n });\n\n // Get user address from contract\n const address = contract.getAddress();\n\n // Return complete client bundle\n return {\n contract,\n graphqlClient,\n grpcClient,\n ecsWorld,\n metadata: config.metadata,\n network: config.network,\n packageId: config.packageId,\n dubheSchemaId: config.dubheSchemaId,\n address,\n options: config.options\n };\n}\n\n/**\n * Type guard to check if a value is a valid NetworkType\n */\nexport function isNetworkType(value: string): value is ClientConfig['network'] {\n return ['mainnet', 'testnet', 'devnet', 'localnet'].includes(value);\n}\n\n/**\n * Helper function to validate client configuration\n * Throws descriptive errors for invalid configurations\n */\nexport function validateClientConfig(\n config: Partial<ClientConfig>\n): asserts config is ClientConfig {\n if (!config.network) {\n throw new Error('ClientConfig validation failed: network is required');\n }\n if (!isNetworkType(config.network)) {\n throw new Error(\n `ClientConfig validation failed: invalid network type \"${config.network}\". ` +\n 'Must be one of: mainnet, testnet, devnet, localnet'\n );\n }\n if (!config.packageId) {\n throw new Error('ClientConfig validation failed: packageId is required');\n }\n if (typeof config.packageId !== 'string' || config.packageId.trim() === '') {\n throw new Error('ClientConfig validation failed: packageId must be a non-empty string');\n }\n if (!config.metadata) {\n throw new Error('ClientConfig validation failed: metadata is required');\n }\n}\n\n/**\n * Create client with configuration validation\n * Useful when working with external configuration sources\n *\n * @example\n * ```typescript\n * const config = loadConfigFromFile(); // May be incomplete\n * const client = createClientWithValidation(config); // Throws if invalid\n * ```\n */\nexport function createClientWithValidation(config: Partial<ClientConfig>): DubheClientBundle {\n validateClientConfig(config);\n return createClient(config);\n}\n"]}
@@ -0,0 +1,87 @@
1
+ import { Dubhe } from '@0xobelisk/sui-client';
2
+ import { createDubheGraphqlClient } from '@0xobelisk/graphql-client';
3
+ import { createECSWorld } from '@0xobelisk/ecs';
4
+ import { DubheGrpcClient } from '@0xobelisk/grpc-client';
5
+
6
+ // src/sui/client.ts
7
+ function createClient(config) {
8
+ if (!config.network) {
9
+ throw new Error("ClientConfig: network is required");
10
+ }
11
+ if (!config.packageId) {
12
+ throw new Error("ClientConfig: packageId is required");
13
+ }
14
+ if (!config.metadata) {
15
+ throw new Error("ClientConfig: metadata is required");
16
+ }
17
+ const contract = new Dubhe({
18
+ networkType: config.network,
19
+ packageId: config.packageId,
20
+ metadata: config.metadata,
21
+ secretKey: config.credentials?.secretKey,
22
+ mnemonics: config.credentials?.mnemonics,
23
+ fullnodeUrls: config.endpoints?.fullnodeUrls
24
+ });
25
+ const graphqlClient = createDubheGraphqlClient({
26
+ endpoint: config.endpoints?.graphql || "http://localhost:4000/graphql",
27
+ subscriptionEndpoint: config.endpoints?.websocket || "ws://localhost:4000/graphql",
28
+ dubheMetadata: config.dubheMetadata
29
+ });
30
+ const grpcClient = new DubheGrpcClient({
31
+ baseUrl: config.endpoints?.grpc || "http://localhost:8080"
32
+ });
33
+ const ecsWorld = createECSWorld(graphqlClient, {
34
+ dubheMetadata: config.dubheMetadata,
35
+ queryConfig: {
36
+ enableBatchOptimization: config.options?.enableBatchOptimization ?? true,
37
+ defaultCacheTimeout: config.options?.cacheTimeout ?? 5e3
38
+ },
39
+ subscriptionConfig: {
40
+ defaultDebounceMs: config.options?.debounceMs ?? 100,
41
+ reconnectOnError: config.options?.reconnectOnError ?? true
42
+ }
43
+ });
44
+ const address = contract.getAddress();
45
+ return {
46
+ contract,
47
+ graphqlClient,
48
+ grpcClient,
49
+ ecsWorld,
50
+ metadata: config.metadata,
51
+ network: config.network,
52
+ packageId: config.packageId,
53
+ dubheSchemaId: config.dubheSchemaId,
54
+ address,
55
+ options: config.options
56
+ };
57
+ }
58
+ function isNetworkType(value) {
59
+ return ["mainnet", "testnet", "devnet", "localnet"].includes(value);
60
+ }
61
+ function validateClientConfig(config) {
62
+ if (!config.network) {
63
+ throw new Error("ClientConfig validation failed: network is required");
64
+ }
65
+ if (!isNetworkType(config.network)) {
66
+ throw new Error(
67
+ `ClientConfig validation failed: invalid network type "${config.network}". Must be one of: mainnet, testnet, devnet, localnet`
68
+ );
69
+ }
70
+ if (!config.packageId) {
71
+ throw new Error("ClientConfig validation failed: packageId is required");
72
+ }
73
+ if (typeof config.packageId !== "string" || config.packageId.trim() === "") {
74
+ throw new Error("ClientConfig validation failed: packageId must be a non-empty string");
75
+ }
76
+ if (!config.metadata) {
77
+ throw new Error("ClientConfig validation failed: metadata is required");
78
+ }
79
+ }
80
+ function createClientWithValidation(config) {
81
+ validateClientConfig(config);
82
+ return createClient(config);
83
+ }
84
+
85
+ export { createClient, createClientWithValidation, isNetworkType, validateClientConfig };
86
+ //# sourceMappingURL=out.js.map
87
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/sui/client.ts"],"names":[],"mappings":";AAAA,SAAS,aAAa;AACtB,SAAS,gCAAgC;AACzC,SAAS,sBAAsB;AAC/B,SAAS,uBAAuB;AAwCzB,SAAS,aAAa,QAAyC;AAEpE,MAAI,CAAC,OAAO,SAAS;AACnB,UAAM,IAAI,MAAM,mCAAmC;AAAA,EACrD;AACA,MAAI,CAAC,OAAO,WAAW;AACrB,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AACA,MAAI,CAAC,OAAO,UAAU;AACpB,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AAGA,QAAM,WAAW,IAAI,MAAM;AAAA,IACzB,aAAa,OAAO;AAAA,IACpB,WAAW,OAAO;AAAA,IAClB,UAAU,OAAO;AAAA,IACjB,WAAW,OAAO,aAAa;AAAA,IAC/B,WAAW,OAAO,aAAa;AAAA,IAC/B,cAAc,OAAO,WAAW;AAAA,EAClC,CAAC;AAGD,QAAM,gBAAgB,yBAAyB;AAAA,IAC7C,UAAU,OAAO,WAAW,WAAW;AAAA,IACvC,sBAAsB,OAAO,WAAW,aAAa;AAAA,IACrD,eAAe,OAAO;AAAA,EACxB,CAAC;AAGD,QAAM,aAAa,IAAI,gBAAgB;AAAA,IACrC,SAAS,OAAO,WAAW,QAAQ;AAAA,EACrC,CAAC;AAGD,QAAM,WAAW,eAAe,eAAe;AAAA,IAC7C,eAAe,OAAO;AAAA,IACtB,aAAa;AAAA,MACX,yBAAyB,OAAO,SAAS,2BAA2B;AAAA,MACpE,qBAAqB,OAAO,SAAS,gBAAgB;AAAA,IACvD;AAAA,IACA,oBAAoB;AAAA,MAClB,mBAAmB,OAAO,SAAS,cAAc;AAAA,MACjD,kBAAkB,OAAO,SAAS,oBAAoB;AAAA,IACxD;AAAA,EACF,CAAC;AAGD,QAAM,UAAU,SAAS,WAAW;AAGpC,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,OAAO;AAAA,IACjB,SAAS,OAAO;AAAA,IAChB,WAAW,OAAO;AAAA,IAClB,eAAe,OAAO;AAAA,IACtB;AAAA,IACA,SAAS,OAAO;AAAA,EAClB;AACF;AAKO,SAAS,cAAc,OAAiD;AAC7E,SAAO,CAAC,WAAW,WAAW,UAAU,UAAU,EAAE,SAAS,KAAK;AACpE;AAMO,SAAS,qBACd,QACgC;AAChC,MAAI,CAAC,OAAO,SAAS;AACnB,UAAM,IAAI,MAAM,qDAAqD;AAAA,EACvE;AACA,MAAI,CAAC,cAAc,OAAO,OAAO,GAAG;AAClC,UAAM,IAAI;AAAA,MACR,yDAAyD,OAAO,OAAO;AAAA,IAEzE;AAAA,EACF;AACA,MAAI,CAAC,OAAO,WAAW;AACrB,UAAM,IAAI,MAAM,uDAAuD;AAAA,EACzE;AACA,MAAI,OAAO,OAAO,cAAc,YAAY,OAAO,UAAU,KAAK,MAAM,IAAI;AAC1E,UAAM,IAAI,MAAM,sEAAsE;AAAA,EACxF;AACA,MAAI,CAAC,OAAO,UAAU;AACpB,UAAM,IAAI,MAAM,sDAAsD;AAAA,EACxE;AACF;AAYO,SAAS,2BAA2B,QAAkD;AAC3F,uBAAqB,MAAM;AAC3B,SAAO,aAAa,MAAM;AAC5B","sourcesContent":["import { Dubhe } from '@0xobelisk/sui-client';\nimport { createDubheGraphqlClient } from '@0xobelisk/graphql-client';\nimport { createECSWorld } from '@0xobelisk/ecs';\nimport { DubheGrpcClient } from '@0xobelisk/grpc-client';\nimport type { ClientConfig, DubheClientBundle } from './types';\n\n/**\n * Create a Dubhe client bundle with all necessary instances\n *\n * This factory function creates and initializes:\n * - Dubhe contract client for on-chain interactions\n * - GraphQL client for querying indexed data\n * - gRPC client for high-performance queries\n * - ECS World for entity-component-system queries\n *\n * @param config - Client configuration matching @0xobelisk/react interface\n * @returns DubheClientBundle with all initialized client instances\n *\n * @example\n * ```typescript\n * import { createClient } from '@0xobelisk/client/sui';\n * import metadata from './metadata.json';\n *\n * const client = createClient({\n * network: 'devnet',\n * packageId: '0x123...',\n * metadata,\n * credentials: {\n * secretKey: process.env.PRIVATE_KEY\n * }\n * });\n *\n * // Use the contract client\n * const tx = new Transaction();\n * await client.contract.tx.counter_system.inc({ tx });\n *\n * // Use GraphQL client\n * const data = await client.graphqlClient.query(...);\n *\n * // Use ECS World\n * const entities = client.ecsWorld.getEntities();\n * ```\n */\nexport function createClient(config: ClientConfig): DubheClientBundle {\n // Validate required fields\n if (!config.network) {\n throw new Error('ClientConfig: network is required');\n }\n if (!config.packageId) {\n throw new Error('ClientConfig: packageId is required');\n }\n if (!config.metadata) {\n throw new Error('ClientConfig: metadata is required');\n }\n\n // Initialize Dubhe contract client\n const contract = new Dubhe({\n networkType: config.network,\n packageId: config.packageId,\n metadata: config.metadata,\n secretKey: config.credentials?.secretKey,\n mnemonics: config.credentials?.mnemonics,\n fullnodeUrls: config.endpoints?.fullnodeUrls\n });\n\n // Initialize GraphQL client with default localhost endpoint if not provided\n const graphqlClient = createDubheGraphqlClient({\n endpoint: config.endpoints?.graphql || 'http://localhost:4000/graphql',\n subscriptionEndpoint: config.endpoints?.websocket || 'ws://localhost:4000/graphql',\n dubheMetadata: config.dubheMetadata\n });\n\n // Initialize gRPC client with default localhost endpoint if not provided\n const grpcClient = new DubheGrpcClient({\n baseUrl: config.endpoints?.grpc || 'http://localhost:8080'\n });\n\n // Initialize ECS World (depends on GraphQL client)\n const ecsWorld = createECSWorld(graphqlClient, {\n dubheMetadata: config.dubheMetadata,\n queryConfig: {\n enableBatchOptimization: config.options?.enableBatchOptimization ?? true,\n defaultCacheTimeout: config.options?.cacheTimeout ?? 5000\n },\n subscriptionConfig: {\n defaultDebounceMs: config.options?.debounceMs ?? 100,\n reconnectOnError: config.options?.reconnectOnError ?? true\n }\n });\n\n // Get user address from contract\n const address = contract.getAddress();\n\n // Return complete client bundle\n return {\n contract,\n graphqlClient,\n grpcClient,\n ecsWorld,\n metadata: config.metadata,\n network: config.network,\n packageId: config.packageId,\n dubheSchemaId: config.dubheSchemaId,\n address,\n options: config.options\n };\n}\n\n/**\n * Type guard to check if a value is a valid NetworkType\n */\nexport function isNetworkType(value: string): value is ClientConfig['network'] {\n return ['mainnet', 'testnet', 'devnet', 'localnet'].includes(value);\n}\n\n/**\n * Helper function to validate client configuration\n * Throws descriptive errors for invalid configurations\n */\nexport function validateClientConfig(\n config: Partial<ClientConfig>\n): asserts config is ClientConfig {\n if (!config.network) {\n throw new Error('ClientConfig validation failed: network is required');\n }\n if (!isNetworkType(config.network)) {\n throw new Error(\n `ClientConfig validation failed: invalid network type \"${config.network}\". ` +\n 'Must be one of: mainnet, testnet, devnet, localnet'\n );\n }\n if (!config.packageId) {\n throw new Error('ClientConfig validation failed: packageId is required');\n }\n if (typeof config.packageId !== 'string' || config.packageId.trim() === '') {\n throw new Error('ClientConfig validation failed: packageId must be a non-empty string');\n }\n if (!config.metadata) {\n throw new Error('ClientConfig validation failed: metadata is required');\n }\n}\n\n/**\n * Create client with configuration validation\n * Useful when working with external configuration sources\n *\n * @example\n * ```typescript\n * const config = loadConfigFromFile(); // May be incomplete\n * const client = createClientWithValidation(config); // Throws if invalid\n * ```\n */\nexport function createClientWithValidation(config: Partial<ClientConfig>): DubheClientBundle {\n validateClientConfig(config);\n return createClient(config);\n}\n"]}
@@ -0,0 +1,88 @@
1
+ import type { SuiMoveNormalizedModules, Dubhe } from '@0xobelisk/sui-client';
2
+ import type { DubheGraphqlClient } from '@0xobelisk/graphql-client';
3
+ import type { DubheECSWorld } from '@0xobelisk/ecs';
4
+ import type { DubheGrpcClient } from '@0xobelisk/grpc-client';
5
+ /**
6
+ * Network type for Sui blockchain
7
+ */
8
+ export type NetworkType = 'mainnet' | 'testnet' | 'devnet' | 'localnet';
9
+ /**
10
+ * Client configuration interface
11
+ * Aligned with @0xobelisk/react configuration for consistency
12
+ */
13
+ export interface ClientConfig {
14
+ /** Network type */
15
+ network: NetworkType;
16
+ /** Contract package ID */
17
+ packageId: string;
18
+ /** Contract metadata (required for contract instantiation) */
19
+ metadata: any;
20
+ /** Dubhe Schema ID (optional, for enhanced features) */
21
+ dubheSchemaId?: string;
22
+ /** Dubhe metadata (enables GraphQL/ECS features) */
23
+ dubheMetadata?: any;
24
+ /** Authentication credentials */
25
+ credentials?: {
26
+ /** Private key (base64 or hex string) */
27
+ secretKey?: string;
28
+ /** Mnemonic phrase (12 or 24 words) */
29
+ mnemonics?: string;
30
+ };
31
+ /** Service endpoints configuration */
32
+ endpoints?: {
33
+ /** Full node RPC URLs (can provide multiple for redundancy) */
34
+ fullnodeUrls?: string[];
35
+ /** GraphQL endpoint URL */
36
+ graphql?: string;
37
+ /** WebSocket endpoint URL for subscriptions */
38
+ websocket?: string;
39
+ /** gRPC endpoint URL */
40
+ grpc?: string;
41
+ };
42
+ /** Performance and behavior options */
43
+ options?: {
44
+ /** Enable batch query optimization */
45
+ enableBatchOptimization?: boolean;
46
+ /** Default cache timeout (milliseconds) */
47
+ cacheTimeout?: number;
48
+ /** Request debounce delay (milliseconds) */
49
+ debounceMs?: number;
50
+ /** Auto-reconnect on WebSocket errors */
51
+ reconnectOnError?: boolean;
52
+ };
53
+ }
54
+ /**
55
+ * Type alias for consistency with @0xobelisk/react package
56
+ */
57
+ export type DubheConfig = ClientConfig;
58
+ /**
59
+ * Client bundle returned by createClient
60
+ * Contains all initialized client instances
61
+ */
62
+ export interface DubheClientBundle {
63
+ /** Dubhe contract instance - core client for contract interactions */
64
+ contract: Dubhe;
65
+ /** GraphQL client for querying indexed data */
66
+ graphqlClient: DubheGraphqlClient;
67
+ /** gRPC client for high-performance queries */
68
+ grpcClient: DubheGrpcClient;
69
+ /** ECS World instance for entity-component-system queries */
70
+ ecsWorld: DubheECSWorld;
71
+ /** Contract metadata */
72
+ metadata: SuiMoveNormalizedModules;
73
+ /** Network type */
74
+ network: NetworkType;
75
+ /** Package ID */
76
+ packageId: string;
77
+ /** Dubhe Schema ID (if provided) */
78
+ dubheSchemaId?: string;
79
+ /** User address */
80
+ address: string;
81
+ /** Configuration options used */
82
+ options?: {
83
+ enableBatchOptimization?: boolean;
84
+ cacheTimeout?: number;
85
+ debounceMs?: number;
86
+ reconnectOnError?: boolean;
87
+ };
88
+ }