@varity-labs/sdk 2.0.0-alpha.1

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 (295) hide show
  1. package/LICENSE +31 -0
  2. package/README.md +253 -0
  3. package/dist/analytics/index.d.ts +7 -0
  4. package/dist/analytics/index.d.ts.map +1 -0
  5. package/dist/analytics/index.js +6 -0
  6. package/dist/analytics/tracker.d.ts +128 -0
  7. package/dist/analytics/tracker.d.ts.map +1 -0
  8. package/dist/analytics/tracker.js +203 -0
  9. package/dist/blockchain/BlockchainService.d.ts +100 -0
  10. package/dist/blockchain/BlockchainService.d.ts.map +1 -0
  11. package/dist/blockchain/BlockchainService.js +188 -0
  12. package/dist/blockchain/NFTLicensingService.d.ts +69 -0
  13. package/dist/blockchain/NFTLicensingService.d.ts.map +1 -0
  14. package/dist/blockchain/NFTLicensingService.js +136 -0
  15. package/dist/blockchain/RevenueSplitService.d.ts +71 -0
  16. package/dist/blockchain/RevenueSplitService.d.ts.map +1 -0
  17. package/dist/blockchain/RevenueSplitService.js +111 -0
  18. package/dist/blockchain/index.d.ts +48 -0
  19. package/dist/blockchain/index.d.ts.map +1 -0
  20. package/dist/blockchain/index.js +46 -0
  21. package/dist/blockchain/types.d.ts +63 -0
  22. package/dist/blockchain/types.d.ts.map +1 -0
  23. package/dist/blockchain/types.js +6 -0
  24. package/dist/chains/arbitrum.d.ts +89 -0
  25. package/dist/chains/arbitrum.d.ts.map +1 -0
  26. package/dist/chains/arbitrum.js +134 -0
  27. package/dist/chains/base.d.ts +84 -0
  28. package/dist/chains/base.d.ts.map +1 -0
  29. package/dist/chains/base.js +131 -0
  30. package/dist/chains/index.d.ts +36 -0
  31. package/dist/chains/index.d.ts.map +1 -0
  32. package/dist/chains/index.js +32 -0
  33. package/dist/chains/registry.d.ts +113 -0
  34. package/dist/chains/registry.d.ts.map +1 -0
  35. package/dist/chains/registry.js +201 -0
  36. package/dist/chains/varityL3.d.ts +81 -0
  37. package/dist/chains/varityL3.d.ts.map +1 -0
  38. package/dist/chains/varityL3.js +125 -0
  39. package/dist/cli/commands/clone.d.ts +8 -0
  40. package/dist/cli/commands/clone.d.ts.map +1 -0
  41. package/dist/cli/commands/clone.js +391 -0
  42. package/dist/cli/commands/dev.d.ts +8 -0
  43. package/dist/cli/commands/dev.d.ts.map +1 -0
  44. package/dist/cli/commands/dev.js +40 -0
  45. package/dist/cli/commands/generate.d.ts +8 -0
  46. package/dist/cli/commands/generate.d.ts.map +1 -0
  47. package/dist/cli/commands/generate.js +303 -0
  48. package/dist/cli/commands/init.d.ts +8 -0
  49. package/dist/cli/commands/init.d.ts.map +1 -0
  50. package/dist/cli/commands/init.js +317 -0
  51. package/dist/cli/commands/validate.d.ts +8 -0
  52. package/dist/cli/commands/validate.d.ts.map +1 -0
  53. package/dist/cli/commands/validate.js +69 -0
  54. package/dist/cli/index.d.ts +8 -0
  55. package/dist/cli/index.d.ts.map +1 -0
  56. package/dist/cli/index.js +33 -0
  57. package/dist/cli/utils/logger.d.ts +17 -0
  58. package/dist/cli/utils/logger.d.ts.map +1 -0
  59. package/dist/cli/utils/logger.js +35 -0
  60. package/dist/cli/utils/prompts.d.ts +21 -0
  61. package/dist/cli/utils/prompts.d.ts.map +1 -0
  62. package/dist/cli/utils/prompts.js +103 -0
  63. package/dist/contracts/abis/iso/AccessControlRegistry.json +1468 -0
  64. package/dist/contracts/abis/iso/DataProofRegistry.json +797 -0
  65. package/dist/contracts/abis/iso/MerchantRegistry.json +1237 -0
  66. package/dist/contracts/abis/iso/RepPerformance.json +1351 -0
  67. package/dist/contracts/abis/iso/ResidualCalculator.json +1118 -0
  68. package/dist/contracts/abis/iso/TransactionVault.json +1588 -0
  69. package/dist/contracts/abis/iso/VarityWalletFactory.json +475 -0
  70. package/dist/contracts/addresses.d.ts +88 -0
  71. package/dist/contracts/addresses.d.ts.map +1 -0
  72. package/dist/contracts/addresses.js +94 -0
  73. package/dist/contracts/index.d.ts +7 -0
  74. package/dist/contracts/index.d.ts.map +1 -0
  75. package/dist/contracts/index.js +6 -0
  76. package/dist/core/VaritySDK.d.ts +177 -0
  77. package/dist/core/VaritySDK.d.ts.map +1 -0
  78. package/dist/core/VaritySDK.js +325 -0
  79. package/dist/core/config.d.ts +120 -0
  80. package/dist/core/config.d.ts.map +1 -0
  81. package/dist/core/config.js +187 -0
  82. package/dist/core/credentials-proxy.d.ts +157 -0
  83. package/dist/core/credentials-proxy.d.ts.map +1 -0
  84. package/dist/core/credentials-proxy.js +345 -0
  85. package/dist/core/credentials.d.ts +219 -0
  86. package/dist/core/credentials.d.ts.map +1 -0
  87. package/dist/core/credentials.js +345 -0
  88. package/dist/core/template-loader.d.ts +15 -0
  89. package/dist/core/template-loader.d.ts.map +1 -0
  90. package/dist/core/template-loader.js +380 -0
  91. package/dist/core/template.d.ts +321 -0
  92. package/dist/core/template.d.ts.map +1 -0
  93. package/dist/core/template.js +189 -0
  94. package/dist/core/types.d.ts +572 -0
  95. package/dist/core/types.d.ts.map +1 -0
  96. package/dist/core/types.js +52 -0
  97. package/dist/dev/dev-server.d.ts +16 -0
  98. package/dist/dev/dev-server.d.ts.map +1 -0
  99. package/dist/dev/dev-server.js +119 -0
  100. package/dist/generators/contracts/generator.d.ts +21 -0
  101. package/dist/generators/contracts/generator.d.ts.map +1 -0
  102. package/dist/generators/contracts/generator.js +252 -0
  103. package/dist/generators/tests/generator.d.ts +20 -0
  104. package/dist/generators/tests/generator.d.ts.map +1 -0
  105. package/dist/generators/tests/generator.js +375 -0
  106. package/dist/generators/types/generator.d.ts +19 -0
  107. package/dist/generators/types/generator.d.ts.map +1 -0
  108. package/dist/generators/types/generator.js +165 -0
  109. package/dist/generators/ui/component-generator.d.ts +20 -0
  110. package/dist/generators/ui/component-generator.d.ts.map +1 -0
  111. package/dist/generators/ui/component-generator.js +749 -0
  112. package/dist/generators/ui/dashboard-generator.d.ts +20 -0
  113. package/dist/generators/ui/dashboard-generator.d.ts.map +1 -0
  114. package/dist/generators/ui/dashboard-generator.js +349 -0
  115. package/dist/index.d.ts +61 -0
  116. package/dist/index.d.ts.map +1 -0
  117. package/dist/index.js +74 -0
  118. package/dist/modules/analytics/AnalyticsModule.d.ts +349 -0
  119. package/dist/modules/analytics/AnalyticsModule.d.ts.map +1 -0
  120. package/dist/modules/analytics/AnalyticsModule.js +274 -0
  121. package/dist/modules/analytics/index.d.ts +3 -0
  122. package/dist/modules/analytics/index.d.ts.map +1 -0
  123. package/dist/modules/analytics/index.js +1 -0
  124. package/dist/modules/auth/AccessKeyModule.d.ts +189 -0
  125. package/dist/modules/auth/AccessKeyModule.d.ts.map +1 -0
  126. package/dist/modules/auth/AccessKeyModule.js +322 -0
  127. package/dist/modules/auth/AuthModule.d.ts +133 -0
  128. package/dist/modules/auth/AuthModule.d.ts.map +1 -0
  129. package/dist/modules/auth/AuthModule.js +214 -0
  130. package/dist/modules/auth/index.d.ts +8 -0
  131. package/dist/modules/auth/index.d.ts.map +1 -0
  132. package/dist/modules/auth/index.js +6 -0
  133. package/dist/modules/cache/CacheModule.d.ts +279 -0
  134. package/dist/modules/cache/CacheModule.d.ts.map +1 -0
  135. package/dist/modules/cache/CacheModule.js +493 -0
  136. package/dist/modules/cache/index.d.ts +3 -0
  137. package/dist/modules/cache/index.d.ts.map +1 -0
  138. package/dist/modules/cache/index.js +1 -0
  139. package/dist/modules/compute/ComputeModule.d.ts +226 -0
  140. package/dist/modules/compute/ComputeModule.d.ts.map +1 -0
  141. package/dist/modules/compute/ComputeModule.js +379 -0
  142. package/dist/modules/compute/index.d.ts +6 -0
  143. package/dist/modules/compute/index.d.ts.map +1 -0
  144. package/dist/modules/compute/index.js +4 -0
  145. package/dist/modules/contracts/ContractsModule.d.ts +164 -0
  146. package/dist/modules/contracts/ContractsModule.d.ts.map +1 -0
  147. package/dist/modules/contracts/ContractsModule.js +242 -0
  148. package/dist/modules/contracts/index.d.ts +6 -0
  149. package/dist/modules/contracts/index.d.ts.map +1 -0
  150. package/dist/modules/contracts/index.js +4 -0
  151. package/dist/modules/export/ExportModule.d.ts +346 -0
  152. package/dist/modules/export/ExportModule.d.ts.map +1 -0
  153. package/dist/modules/export/ExportModule.js +432 -0
  154. package/dist/modules/export/index.d.ts +3 -0
  155. package/dist/modules/export/index.d.ts.map +1 -0
  156. package/dist/modules/export/index.js +1 -0
  157. package/dist/modules/forecasting/ForecastingModule.d.ts +579 -0
  158. package/dist/modules/forecasting/ForecastingModule.d.ts.map +1 -0
  159. package/dist/modules/forecasting/ForecastingModule.js +310 -0
  160. package/dist/modules/forecasting/index.d.ts +3 -0
  161. package/dist/modules/forecasting/index.d.ts.map +1 -0
  162. package/dist/modules/forecasting/index.js +1 -0
  163. package/dist/modules/monitoring/MonitoringModule.d.ts +359 -0
  164. package/dist/modules/monitoring/MonitoringModule.d.ts.map +1 -0
  165. package/dist/modules/monitoring/MonitoringModule.js +483 -0
  166. package/dist/modules/monitoring/index.d.ts +3 -0
  167. package/dist/modules/monitoring/index.d.ts.map +1 -0
  168. package/dist/modules/monitoring/index.js +1 -0
  169. package/dist/modules/notifications/NotificationsModule.d.ts +336 -0
  170. package/dist/modules/notifications/NotificationsModule.d.ts.map +1 -0
  171. package/dist/modules/notifications/NotificationsModule.js +418 -0
  172. package/dist/modules/notifications/index.d.ts +3 -0
  173. package/dist/modules/notifications/index.d.ts.map +1 -0
  174. package/dist/modules/notifications/index.js +1 -0
  175. package/dist/modules/oracle/OracleModule.d.ts +110 -0
  176. package/dist/modules/oracle/OracleModule.d.ts.map +1 -0
  177. package/dist/modules/oracle/OracleModule.js +151 -0
  178. package/dist/modules/oracle/index.d.ts +6 -0
  179. package/dist/modules/oracle/index.d.ts.map +1 -0
  180. package/dist/modules/oracle/index.js +4 -0
  181. package/dist/modules/storage/S3Module.d.ts +377 -0
  182. package/dist/modules/storage/S3Module.d.ts.map +1 -0
  183. package/dist/modules/storage/S3Module.js +680 -0
  184. package/dist/modules/storage/StorageModule.d.ts +157 -0
  185. package/dist/modules/storage/StorageModule.d.ts.map +1 -0
  186. package/dist/modules/storage/StorageModule.js +302 -0
  187. package/dist/modules/storage/adapters/AdapterFactory.d.ts +100 -0
  188. package/dist/modules/storage/adapters/AdapterFactory.d.ts.map +1 -0
  189. package/dist/modules/storage/adapters/AdapterFactory.js +209 -0
  190. package/dist/modules/storage/adapters/FilecoinAdapter.d.ts +94 -0
  191. package/dist/modules/storage/adapters/FilecoinAdapter.d.ts.map +1 -0
  192. package/dist/modules/storage/adapters/FilecoinAdapter.js +263 -0
  193. package/dist/modules/storage/adapters/IStorageAdapter.d.ts +287 -0
  194. package/dist/modules/storage/adapters/IStorageAdapter.d.ts.map +1 -0
  195. package/dist/modules/storage/adapters/IStorageAdapter.js +81 -0
  196. package/dist/modules/storage/adapters/MultiTierAdapter.d.ts +187 -0
  197. package/dist/modules/storage/adapters/MultiTierAdapter.d.ts.map +1 -0
  198. package/dist/modules/storage/adapters/MultiTierAdapter.js +430 -0
  199. package/dist/modules/storage/adapters/index.d.ts +12 -0
  200. package/dist/modules/storage/adapters/index.d.ts.map +1 -0
  201. package/dist/modules/storage/adapters/index.js +12 -0
  202. package/dist/modules/storage/index.d.ts +16 -0
  203. package/dist/modules/storage/index.d.ts.map +1 -0
  204. package/dist/modules/storage/index.js +15 -0
  205. package/dist/modules/storage/tiering/AccessAnalyzer.d.ts +227 -0
  206. package/dist/modules/storage/tiering/AccessAnalyzer.d.ts.map +1 -0
  207. package/dist/modules/storage/tiering/AccessAnalyzer.js +367 -0
  208. package/dist/modules/storage/tiering/CostOptimizer.d.ts +248 -0
  209. package/dist/modules/storage/tiering/CostOptimizer.d.ts.map +1 -0
  210. package/dist/modules/storage/tiering/CostOptimizer.js +356 -0
  211. package/dist/modules/storage/tiering/MetadataStore.d.ts +287 -0
  212. package/dist/modules/storage/tiering/MetadataStore.d.ts.map +1 -0
  213. package/dist/modules/storage/tiering/MetadataStore.js +535 -0
  214. package/dist/modules/storage/tiering/TieringEngine.d.ts +237 -0
  215. package/dist/modules/storage/tiering/TieringEngine.d.ts.map +1 -0
  216. package/dist/modules/storage/tiering/TieringEngine.js +419 -0
  217. package/dist/modules/storage/tiering/example.d.ts +8 -0
  218. package/dist/modules/storage/tiering/example.d.ts.map +1 -0
  219. package/dist/modules/storage/tiering/example.js +250 -0
  220. package/dist/modules/storage/tiering/index.d.ts +17 -0
  221. package/dist/modules/storage/tiering/index.d.ts.map +1 -0
  222. package/dist/modules/storage/tiering/index.js +13 -0
  223. package/dist/modules/webhooks/WebhooksModule.d.ts +476 -0
  224. package/dist/modules/webhooks/WebhooksModule.d.ts.map +1 -0
  225. package/dist/modules/webhooks/WebhooksModule.js +359 -0
  226. package/dist/modules/webhooks/index.d.ts +3 -0
  227. package/dist/modules/webhooks/index.d.ts.map +1 -0
  228. package/dist/modules/webhooks/index.js +1 -0
  229. package/dist/modules/zk/ZKModule.d.ts +153 -0
  230. package/dist/modules/zk/ZKModule.d.ts.map +1 -0
  231. package/dist/modules/zk/ZKModule.js +262 -0
  232. package/dist/modules/zk/index.d.ts +7 -0
  233. package/dist/modules/zk/index.d.ts.map +1 -0
  234. package/dist/modules/zk/index.js +4 -0
  235. package/dist/thirdweb/BridgeClient.d.ts +228 -0
  236. package/dist/thirdweb/BridgeClient.d.ts.map +1 -0
  237. package/dist/thirdweb/BridgeClient.js +160 -0
  238. package/dist/thirdweb/EngineClient.d.ts +396 -0
  239. package/dist/thirdweb/EngineClient.d.ts.map +1 -0
  240. package/dist/thirdweb/EngineClient.js +386 -0
  241. package/dist/thirdweb/GatewayClient.d.ts +190 -0
  242. package/dist/thirdweb/GatewayClient.d.ts.map +1 -0
  243. package/dist/thirdweb/GatewayClient.js +257 -0
  244. package/dist/thirdweb/NebulaClient.d.ts +292 -0
  245. package/dist/thirdweb/NebulaClient.d.ts.map +1 -0
  246. package/dist/thirdweb/NebulaClient.js +180 -0
  247. package/dist/thirdweb/StorageClient.d.ts +445 -0
  248. package/dist/thirdweb/StorageClient.d.ts.map +1 -0
  249. package/dist/thirdweb/StorageClient.js +405 -0
  250. package/dist/thirdweb/ThirdwebWrapper.d.ts +236 -0
  251. package/dist/thirdweb/ThirdwebWrapper.d.ts.map +1 -0
  252. package/dist/thirdweb/ThirdwebWrapper.js +332 -0
  253. package/dist/thirdweb/index.d.ts +21 -0
  254. package/dist/thirdweb/index.d.ts.map +1 -0
  255. package/dist/thirdweb/index.js +28 -0
  256. package/dist/thirdweb/varity-chain.d.ts +48 -0
  257. package/dist/thirdweb/varity-chain.d.ts.map +1 -0
  258. package/dist/thirdweb/varity-chain.js +64 -0
  259. package/dist/thirdweb/x402Client.d.ts +319 -0
  260. package/dist/thirdweb/x402Client.d.ts.map +1 -0
  261. package/dist/thirdweb/x402Client.js +223 -0
  262. package/dist/tracking/gasTracker.d.ts +158 -0
  263. package/dist/tracking/gasTracker.d.ts.map +1 -0
  264. package/dist/tracking/gasTracker.js +227 -0
  265. package/dist/tracking/index.d.ts +10 -0
  266. package/dist/tracking/index.d.ts.map +1 -0
  267. package/dist/tracking/index.js +8 -0
  268. package/dist/tracking/types.d.ts +327 -0
  269. package/dist/tracking/types.d.ts.map +1 -0
  270. package/dist/tracking/types.js +8 -0
  271. package/dist/ui/components/ChartWidget.d.ts +36 -0
  272. package/dist/ui/components/ChartWidget.d.ts.map +1 -0
  273. package/dist/ui/components/ChartWidget.js +82 -0
  274. package/dist/ui/components/DashboardLayout.d.ts +41 -0
  275. package/dist/ui/components/DashboardLayout.d.ts.map +1 -0
  276. package/dist/ui/components/DashboardLayout.js +102 -0
  277. package/dist/ui/components/DataTable.d.ts +49 -0
  278. package/dist/ui/components/DataTable.d.ts.map +1 -0
  279. package/dist/ui/components/DataTable.js +96 -0
  280. package/dist/ui/components/EntityForm.d.ts +60 -0
  281. package/dist/ui/components/EntityForm.d.ts.map +1 -0
  282. package/dist/ui/components/EntityForm.js +182 -0
  283. package/dist/ui/components/KPICard.d.ts +29 -0
  284. package/dist/ui/components/KPICard.d.ts.map +1 -0
  285. package/dist/ui/components/KPICard.js +61 -0
  286. package/dist/ui/components/Modal.d.ts +34 -0
  287. package/dist/ui/components/Modal.d.ts.map +1 -0
  288. package/dist/ui/components/Modal.js +30 -0
  289. package/dist/ui/components/index.d.ts +18 -0
  290. package/dist/ui/components/index.d.ts.map +1 -0
  291. package/dist/ui/components/index.js +11 -0
  292. package/dist/validation/template-validator.d.ts +25 -0
  293. package/dist/validation/template-validator.d.ts.map +1 -0
  294. package/dist/validation/template-validator.js +305 -0
  295. package/package.json +102 -0
@@ -0,0 +1,257 @@
1
+ /**
2
+ * thirdweb Gateway Client
3
+ *
4
+ * Production-grade RPC infrastructure powered by thirdweb
5
+ * Provides reliable, fast, and scalable blockchain node access
6
+ *
7
+ * Features:
8
+ * - High-performance RPC endpoints
9
+ * - Automatic failover and load balancing
10
+ * - Request rate limiting and throttling
11
+ * - Chain-specific optimizations
12
+ * - Analytics and monitoring
13
+ * - WebSocket support for real-time data
14
+ */
15
+ import { ChainRegistry } from '../chains';
16
+ /**
17
+ * thirdweb Gateway Client
18
+ *
19
+ * Production RPC infrastructure for blockchain applications
20
+ */
21
+ export class GatewayClient {
22
+ constructor(config = {}) {
23
+ this.requestId = 0;
24
+ this.apiKey = config.apiKey;
25
+ this.gatewayUrl = config.gatewayUrl || 'https://gateway.thirdweb.com';
26
+ this.timeout = config.timeout || 30000;
27
+ this.enableRetries = config.enableRetries !== false;
28
+ this.maxRetries = config.maxRetries || 3;
29
+ this.stats = {
30
+ totalRequests: 0,
31
+ successfulRequests: 0,
32
+ failedRequests: 0,
33
+ averageResponseTime: 0,
34
+ requestsPerMinute: 0,
35
+ errorRate: 0,
36
+ };
37
+ }
38
+ /**
39
+ * Get RPC URL for a specific chain
40
+ */
41
+ getRpcUrl(chain) {
42
+ let chainObj;
43
+ if (typeof chain === 'number') {
44
+ chainObj = ChainRegistry.getChain(chain);
45
+ }
46
+ else {
47
+ chainObj = chain;
48
+ }
49
+ // Use thirdweb gateway if available, otherwise use chain's default RPC
50
+ if (this.apiKey) {
51
+ return `${this.gatewayUrl}/v1/${chainObj.id}/${this.apiKey}`;
52
+ }
53
+ // Fallback to chain's default RPC
54
+ return chainObj.rpc || '';
55
+ }
56
+ /**
57
+ * Get WebSocket URL for a specific chain
58
+ */
59
+ getWebSocketUrl(chain) {
60
+ const rpcUrl = this.getRpcUrl(chain);
61
+ // Convert HTTP(S) to WS(S)
62
+ return rpcUrl.replace('https://', 'wss://').replace('http://', 'ws://');
63
+ }
64
+ /**
65
+ * Make an RPC request
66
+ */
67
+ async request(chain, options) {
68
+ const startTime = Date.now();
69
+ this.stats.totalRequests++;
70
+ try {
71
+ const url = this.getRpcUrl(chain);
72
+ const id = ++this.requestId;
73
+ const response = await this.makeRequest(url, {
74
+ jsonrpc: '2.0',
75
+ id,
76
+ method: options.method,
77
+ params: options.params || [],
78
+ }, options.timeout || this.timeout);
79
+ const responseTime = Date.now() - startTime;
80
+ this.updateStats(true, responseTime);
81
+ return response;
82
+ }
83
+ catch (error) {
84
+ this.updateStats(false, Date.now() - startTime);
85
+ throw error;
86
+ }
87
+ }
88
+ /**
89
+ * Batch multiple RPC requests
90
+ */
91
+ async batchRequest(chain, requests) {
92
+ const url = this.getRpcUrl(chain);
93
+ const batchPayload = requests.map((req, index) => ({
94
+ jsonrpc: '2.0',
95
+ id: ++this.requestId,
96
+ method: req.method,
97
+ params: req.params || [],
98
+ }));
99
+ const responses = await this.makeRequest(url, batchPayload, this.timeout);
100
+ return Array.isArray(responses) ? responses : [responses];
101
+ }
102
+ /**
103
+ * Create a WebSocket connection
104
+ */
105
+ connectWebSocket(options) {
106
+ const url = this.getWebSocketUrl(options.chain);
107
+ const ws = new WebSocket(url);
108
+ ws.onopen = () => {
109
+ console.log(`WebSocket connected to ${options.chain.name}`);
110
+ options.onConnect?.();
111
+ };
112
+ ws.onmessage = (event) => {
113
+ try {
114
+ const data = JSON.parse(event.data);
115
+ options.onMessage?.(data);
116
+ }
117
+ catch (error) {
118
+ options.onError?.(error);
119
+ }
120
+ };
121
+ ws.onerror = (event) => {
122
+ options.onError?.(new Error('WebSocket error'));
123
+ };
124
+ ws.onclose = () => {
125
+ console.log(`WebSocket disconnected from ${options.chain.name}`);
126
+ options.onDisconnect?.();
127
+ if (options.autoReconnect) {
128
+ setTimeout(() => this.connectWebSocket(options), 5000);
129
+ }
130
+ };
131
+ return ws;
132
+ }
133
+ /**
134
+ * Subscribe to new blocks
135
+ */
136
+ async subscribeToBlocks(chain, callback) {
137
+ const chainObj = typeof chain === 'number' ? ChainRegistry.getChain(chain) : chain;
138
+ const ws = this.connectWebSocket({
139
+ chain: chainObj,
140
+ onMessage: (data) => {
141
+ if (data.method === 'eth_subscription' && data.params?.subscription) {
142
+ callback(data.params.result);
143
+ }
144
+ },
145
+ });
146
+ // Subscribe to new blocks
147
+ ws.send(JSON.stringify({
148
+ jsonrpc: '2.0',
149
+ id: ++this.requestId,
150
+ method: 'eth_subscribe',
151
+ params: ['newHeads'],
152
+ }));
153
+ // Return unsubscribe function
154
+ return () => ws.close();
155
+ }
156
+ /**
157
+ * Subscribe to contract events
158
+ */
159
+ async subscribeToLogs(chain, filter, callback) {
160
+ const chainObj = typeof chain === 'number' ? ChainRegistry.getChain(chain) : chain;
161
+ const ws = this.connectWebSocket({
162
+ chain: chainObj,
163
+ onMessage: (data) => {
164
+ if (data.method === 'eth_subscription' && data.params?.subscription) {
165
+ callback(data.params.result);
166
+ }
167
+ },
168
+ });
169
+ // Subscribe to logs
170
+ ws.send(JSON.stringify({
171
+ jsonrpc: '2.0',
172
+ id: ++this.requestId,
173
+ method: 'eth_subscribe',
174
+ params: ['logs', filter],
175
+ }));
176
+ // Return unsubscribe function
177
+ return () => ws.close();
178
+ }
179
+ /**
180
+ * Get gateway statistics
181
+ */
182
+ getStats() {
183
+ return { ...this.stats };
184
+ }
185
+ /**
186
+ * Reset statistics
187
+ */
188
+ resetStats() {
189
+ this.stats = {
190
+ totalRequests: 0,
191
+ successfulRequests: 0,
192
+ failedRequests: 0,
193
+ averageResponseTime: 0,
194
+ requestsPerMinute: 0,
195
+ errorRate: 0,
196
+ };
197
+ }
198
+ /**
199
+ * Make HTTP request with retry logic
200
+ */
201
+ async makeRequest(url, payload, timeout, retries = 0) {
202
+ try {
203
+ const controller = new AbortController();
204
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
205
+ const response = await fetch(url, {
206
+ method: 'POST',
207
+ headers: {
208
+ 'Content-Type': 'application/json',
209
+ },
210
+ body: JSON.stringify(payload),
211
+ signal: controller.signal,
212
+ });
213
+ clearTimeout(timeoutId);
214
+ if (!response.ok) {
215
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
216
+ }
217
+ const data = await response.json();
218
+ if (data.error) {
219
+ throw new Error(`RPC Error: ${data.error.message}`);
220
+ }
221
+ return data;
222
+ }
223
+ catch (error) {
224
+ if (this.enableRetries && retries < this.maxRetries) {
225
+ // Exponential backoff
226
+ const delay = Math.pow(2, retries) * 1000;
227
+ await new Promise(resolve => setTimeout(resolve, delay));
228
+ return this.makeRequest(url, payload, timeout, retries + 1);
229
+ }
230
+ throw error;
231
+ }
232
+ }
233
+ /**
234
+ * Update statistics
235
+ */
236
+ updateStats(success, responseTime) {
237
+ if (success) {
238
+ this.stats.successfulRequests++;
239
+ }
240
+ else {
241
+ this.stats.failedRequests++;
242
+ }
243
+ // Update average response time
244
+ const totalResponses = this.stats.successfulRequests + this.stats.failedRequests;
245
+ this.stats.averageResponseTime =
246
+ (this.stats.averageResponseTime * (totalResponses - 1) + responseTime) / totalResponses;
247
+ // Calculate error rate
248
+ this.stats.errorRate =
249
+ (this.stats.failedRequests / this.stats.totalRequests) * 100;
250
+ }
251
+ }
252
+ /**
253
+ * Create Gateway client instance
254
+ */
255
+ export function createGatewayClient(config) {
256
+ return new GatewayClient(config);
257
+ }
@@ -0,0 +1,292 @@
1
+ /**
2
+ * thirdweb Nebula AI Client
3
+ *
4
+ * Natural language blockchain interactions powered by AI
5
+ * Enables developers to interact with smart contracts using plain English
6
+ *
7
+ * Features:
8
+ * - Generate smart contracts from natural language descriptions
9
+ * - Query blockchain data using natural language
10
+ * - Explain transaction data in human-readable format
11
+ * - Generate contract interaction code
12
+ * - Analyze contracts for security issues
13
+ */
14
+ import type { ThirdwebClient, Chain } from 'thirdweb';
15
+ /**
16
+ * Nebula AI configuration
17
+ */
18
+ export interface NebulaConfig {
19
+ /**
20
+ * thirdweb client instance
21
+ */
22
+ client: ThirdwebClient;
23
+ /**
24
+ * API key for Nebula AI (optional - uses client's credentials if not provided)
25
+ */
26
+ apiKey?: string;
27
+ }
28
+ /**
29
+ * Contract generation options
30
+ */
31
+ export interface GenerateContractOptions {
32
+ /**
33
+ * Natural language description of the contract
34
+ * @example "Create a marketplace contract where users can list NFTs for sale"
35
+ */
36
+ prompt: string;
37
+ /**
38
+ * Contract type hint (optional)
39
+ */
40
+ contractType?: 'token' | 'nft' | 'marketplace' | 'dao' | 'custom';
41
+ /**
42
+ * Solidity version (default: 0.8.20)
43
+ */
44
+ solidityVersion?: string;
45
+ /**
46
+ * Include security features (default: true)
47
+ */
48
+ includeSecurity?: boolean;
49
+ }
50
+ /**
51
+ * Generated contract result
52
+ */
53
+ export interface GeneratedContract {
54
+ /**
55
+ * Generated Solidity source code
56
+ */
57
+ sourceCode: string;
58
+ /**
59
+ * Contract ABI
60
+ */
61
+ abi: any[];
62
+ /**
63
+ * Contract bytecode
64
+ */
65
+ bytecode: string;
66
+ /**
67
+ * Explanation of the contract
68
+ */
69
+ explanation: string;
70
+ /**
71
+ * Detected security issues (if any)
72
+ */
73
+ securityIssues?: string[];
74
+ }
75
+ /**
76
+ * Blockchain query options
77
+ */
78
+ export interface QueryChainOptions {
79
+ /**
80
+ * Natural language query
81
+ * @example "What is the total supply of USDC on Arbitrum?"
82
+ */
83
+ prompt: string;
84
+ /**
85
+ * Chain to query
86
+ */
87
+ chain: Chain;
88
+ /**
89
+ * Contract address (optional - if querying specific contract)
90
+ */
91
+ contractAddress?: string;
92
+ }
93
+ /**
94
+ * Query result
95
+ */
96
+ export interface QueryResult {
97
+ /**
98
+ * Answer to the query
99
+ */
100
+ answer: string;
101
+ /**
102
+ * Structured data (if applicable)
103
+ */
104
+ data?: any;
105
+ /**
106
+ * Sources used to answer the query
107
+ */
108
+ sources?: string[];
109
+ /**
110
+ * Confidence score (0-1)
111
+ */
112
+ confidence: number;
113
+ }
114
+ /**
115
+ * Transaction explanation options
116
+ */
117
+ export interface ExplainTransactionOptions {
118
+ /**
119
+ * Transaction hash
120
+ */
121
+ txHash: string;
122
+ /**
123
+ * Chain where transaction occurred
124
+ */
125
+ chain: Chain;
126
+ /**
127
+ * Detail level
128
+ */
129
+ detail?: 'simple' | 'detailed' | 'technical';
130
+ }
131
+ /**
132
+ * Transaction explanation
133
+ */
134
+ export interface TransactionExplanation {
135
+ /**
136
+ * Human-readable summary
137
+ */
138
+ summary: string;
139
+ /**
140
+ * Detailed breakdown
141
+ */
142
+ details: {
143
+ from: string;
144
+ to: string;
145
+ value: string;
146
+ function: string;
147
+ parameters: Record<string, any>;
148
+ };
149
+ /**
150
+ * Risk assessment
151
+ */
152
+ risks?: string[];
153
+ /**
154
+ * Gas cost explanation
155
+ */
156
+ gasCost: {
157
+ total: string;
158
+ explanation: string;
159
+ };
160
+ }
161
+ /**
162
+ * Code generation options
163
+ */
164
+ export interface GenerateCodeOptions {
165
+ /**
166
+ * Natural language description of what to do
167
+ * @example "Call the mint function with 1000 tokens"
168
+ */
169
+ prompt: string;
170
+ /**
171
+ * Contract address
172
+ */
173
+ contractAddress: string;
174
+ /**
175
+ * Chain
176
+ */
177
+ chain: Chain;
178
+ /**
179
+ * Programming language
180
+ */
181
+ language?: 'typescript' | 'python' | 'go' | 'rust';
182
+ }
183
+ /**
184
+ * Generated code
185
+ */
186
+ export interface GeneratedCode {
187
+ /**
188
+ * Generated code
189
+ */
190
+ code: string;
191
+ /**
192
+ * Explanation of the code
193
+ */
194
+ explanation: string;
195
+ /**
196
+ * Required dependencies
197
+ */
198
+ dependencies?: string[];
199
+ }
200
+ /**
201
+ * Contract analysis options
202
+ */
203
+ export interface AnalyzeContractOptions {
204
+ /**
205
+ * Contract source code or address
206
+ */
207
+ contract: string;
208
+ /**
209
+ * Chain (if analyzing deployed contract)
210
+ */
211
+ chain?: Chain;
212
+ /**
213
+ * Analysis focus
214
+ */
215
+ focus?: 'security' | 'gas' | 'general';
216
+ }
217
+ /**
218
+ * Contract analysis result
219
+ */
220
+ export interface ContractAnalysis {
221
+ /**
222
+ * Overall assessment
223
+ */
224
+ summary: string;
225
+ /**
226
+ * Security issues found
227
+ */
228
+ security: {
229
+ severity: 'critical' | 'high' | 'medium' | 'low';
230
+ issue: string;
231
+ location: string;
232
+ recommendation: string;
233
+ }[];
234
+ /**
235
+ * Gas optimization suggestions
236
+ */
237
+ gasOptimizations?: {
238
+ location: string;
239
+ currentCost: string;
240
+ optimizedCost: string;
241
+ suggestion: string;
242
+ }[];
243
+ /**
244
+ * Best practices violations
245
+ */
246
+ bestPractices?: string[];
247
+ }
248
+ /**
249
+ * thirdweb Nebula AI Client
250
+ *
251
+ * Interact with blockchain using natural language powered by AI
252
+ */
253
+ export declare class NebulaClient {
254
+ private client;
255
+ private apiKey?;
256
+ private baseUrl;
257
+ constructor(config: NebulaConfig);
258
+ /**
259
+ * Generate a smart contract from natural language description
260
+ */
261
+ generateContract(options: GenerateContractOptions): Promise<GeneratedContract>;
262
+ /**
263
+ * Query blockchain data using natural language
264
+ */
265
+ queryChain(options: QueryChainOptions): Promise<QueryResult>;
266
+ /**
267
+ * Explain a transaction in human-readable format
268
+ */
269
+ explainTransaction(options: ExplainTransactionOptions): Promise<TransactionExplanation>;
270
+ /**
271
+ * Generate code to interact with a contract
272
+ */
273
+ generateCode(options: GenerateCodeOptions): Promise<GeneratedCode>;
274
+ /**
275
+ * Analyze a contract for security issues and optimizations
276
+ */
277
+ analyzeContract(options: AnalyzeContractOptions): Promise<ContractAnalysis>;
278
+ /**
279
+ * Make HTTP request to Nebula API
280
+ */
281
+ private request;
282
+ /**
283
+ * Mock response for development
284
+ * TODO: Remove when Nebula AI is fully released
285
+ */
286
+ private getMockResponse;
287
+ }
288
+ /**
289
+ * Create Nebula AI client instance
290
+ */
291
+ export declare function createNebulaClient(config: NebulaConfig): NebulaClient;
292
+ //# sourceMappingURL=NebulaClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NebulaClient.d.ts","sourceRoot":"","sources":["../../src/thirdweb/NebulaClient.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B;;OAEG;IACH,MAAM,EAAE,cAAc,CAAC;IAEvB;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,aAAa,GAAG,KAAK,GAAG,QAAQ,CAAC;IAElE;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IAEzB;;OAEG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,GAAG,EAAE,GAAG,EAAE,CAAC;IAEX;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IAEjB;;OAEG;IACH,WAAW,EAAE,MAAM,CAAC;IAEpB;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,KAAK,EAAE,KAAK,CAAC;IAEb;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC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