@trustware/sdk-staging 1.1.5-staging.1 → 1.1.6-staging.2

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.
@@ -1,475 +0,0 @@
1
- import { C as ChainDef, c as ChainType, B as BalanceRow, a as BalanceStreamOptions, p as WalletAddressBalanceWrapper, W as WalletInterFaceAPI, v as WalletIdentity, J as walletManager, q as WalletAddressResolution } from './manager-tnJ6BGOZ.js';
2
- import { T as Token } from './types-BrVfNxND.js';
3
-
4
- declare enum TrustwareErrorCode {
5
- INVALID_CONFIG = "INVALID_CONFIG",
6
- INVALID_API_KEY = "INVALID_API_KEY",
7
- WALLET_NOT_CONNECTED = "WALLET_NOT_CONNECTED",
8
- BRIDGE_FAILED = "BRIDGE_FAILED",
9
- NETWORK_ERROR = "NETWORK_ERROR",
10
- UNKNOWN_ERROR = "UNKNOWN_ERROR",
11
- INPUT_ERROR = "INPUT_ERROR"
12
- }
13
-
14
- declare class TrustwareError extends Error {
15
- code: TrustwareErrorCode;
16
- userMessage?: string;
17
- cause?: unknown;
18
- constructor(params: {
19
- code: TrustwareErrorCode;
20
- message: string;
21
- userMessage?: string;
22
- cause?: unknown;
23
- });
24
- toJSON(): {
25
- name: string;
26
- code: TrustwareErrorCode;
27
- message: string;
28
- userMessage: string | undefined;
29
- };
30
- }
31
-
32
- type TrustwareWidgetTheme = {
33
- primaryColor: string;
34
- secondaryColor: string;
35
- backgroundColor: string;
36
- textColor: string;
37
- borderColor: string;
38
- radius: number;
39
- };
40
- type TrustwareWidgetMessages = {
41
- title: string;
42
- description: string;
43
- };
44
- declare const DEFAULT_THEME: TrustwareWidgetTheme;
45
- declare const DEFAULT_MESSAGES: TrustwareWidgetMessages;
46
-
47
- type BuildRouteBody = {
48
- fromChain: string;
49
- toChain: string;
50
- fromToken: string;
51
- toToken: string;
52
- fromAmount: string;
53
- fromAddress: string;
54
- toAddress: string;
55
- fromAmountUsd?: string;
56
- fromAmountUSD?: string;
57
- refundAddress?: string;
58
- direction?: string;
59
- slippage?: number;
60
- slippageBps?: number;
61
- linkId?: string;
62
- memo?: string;
63
- };
64
- type TxRequest = {
65
- to?: string;
66
- target?: string;
67
- data: string;
68
- value?: string;
69
- gasLimit?: string;
70
- maxFeePerGas?: string;
71
- maxPriorityFeePerGas?: string;
72
- chainId?: number | string;
73
- gasPrice?: string;
74
- };
75
- declare function buildRoute(body: BuildRouteBody, signal?: AbortSignal): Promise<{
76
- intentId: string;
77
- txReq: TxRequest;
78
- actions: unknown[];
79
- finalExchangeRate: {
80
- fromAmountUSD?: string;
81
- toAmountMinUSD?: string;
82
- };
83
- route: RoutePlan | undefined;
84
- }>;
85
- declare function buildDepositAddress(body: BuildRouteBody, signal?: AbortSignal): Promise<{
86
- intentId: string;
87
- depositAddress: string;
88
- actions: unknown[];
89
- finalExchangeRate: {
90
- fromAmountUSD?: string;
91
- toAmountMinUSD?: string;
92
- };
93
- route: RoutePlan | undefined;
94
- }>;
95
- declare function submitReceipt(intentId: string, txHash: string): Promise<any>;
96
- declare function getStatus(intentId: string): Promise<Transaction>;
97
- declare function pollStatus(intentId: string, { intervalMs, timeoutMs }?: {
98
- intervalMs?: number | undefined;
99
- timeoutMs?: number | undefined;
100
- }): Promise<Transaction>;
101
-
102
- type RouteParams = {
103
- fromChain: string;
104
- toChain: string;
105
- fromToken: string;
106
- toToken: string;
107
- fromAmount: string | number;
108
- fromAddress: string;
109
- toAddress: string;
110
- slippage?: number;
111
- };
112
- type RouteIntent = {
113
- id: string;
114
- fromChainId: string | number;
115
- toChainId: string | number;
116
- fromToken: string;
117
- toToken: string;
118
- fromAddress: string;
119
- toAddress: string;
120
- fromAmountWei: string | number;
121
- quoteToAmountWei: string | number;
122
- minToAmountWei: string | number;
123
- requestId?: string;
124
- routeRaw?: unknown;
125
- status: "created" | "submitted" | "bridging" | "success" | "failed";
126
- createdDate: Date | string;
127
- updatedDate: Date | string;
128
- };
129
- type Transaction = {
130
- id: string;
131
- intentId: string;
132
- fromAddress: string;
133
- toAddress: string;
134
- fromChainId: string | number;
135
- toChainId: string | number;
136
- sourceTxHash: string;
137
- destTxHash: string;
138
- requestId: string;
139
- transactionRequest: unknown;
140
- status: "submitted" | "bridging" | "success" | "failed";
141
- statusRaw?: unknown;
142
- routePath?: unknown;
143
- routeStatus?: unknown;
144
- toAmountWei?: string | number;
145
- fromChainBlock: number;
146
- toChainBlock: number;
147
- fromChainTxUrl?: string;
148
- toChainTxUrl?: string;
149
- gasStatus?: string;
150
- isGMPTransaction?: boolean;
151
- axelarTransactionUrl?: string;
152
- createdDate: Date | string;
153
- updatedDate: Date | string;
154
- timeSpentMs?: number;
155
- };
156
- type RouteEstimate = {
157
- fromAmount?: string;
158
- toAmount?: string;
159
- toAmountMin?: string;
160
- fromAmountUsd?: string;
161
- toAmountUsd?: string;
162
- totalFeesUsd?: string;
163
- toAmountMinUsd?: string;
164
- fees?: unknown[];
165
- };
166
- type RoutePlan = {
167
- estimate?: RouteEstimate;
168
- execution?: {
169
- transaction?: TxRequest;
170
- };
171
- steps?: unknown[];
172
- provider?: string;
173
- requestId?: string;
174
- reliabilityScore?: number;
175
- diagnostics?: {
176
- rawPayload?: unknown;
177
- };
178
- };
179
- type BuildRouteResult = {
180
- intentId: string;
181
- txReq: TxRequest;
182
- actions: unknown[];
183
- finalExchangeRate: {
184
- fromAmountUSD?: string;
185
- toAmountMinUSD?: string;
186
- };
187
- route: RoutePlan | undefined;
188
- };
189
-
190
- type TrustwareEvent = {
191
- type: "error";
192
- error: TrustwareError;
193
- } | {
194
- type: "transaction_started";
195
- } | {
196
- type: "transaction_success";
197
- txHash: string;
198
- transaction?: Transaction;
199
- } | {
200
- type: "wallet_connected";
201
- address: string;
202
- } | {
203
- type: "token_page_loaded";
204
- chainRef: string;
205
- query?: string;
206
- count: number;
207
- hasNextPage: boolean;
208
- cursor?: string;
209
- } | {
210
- type: "token_page_error";
211
- chainRef: string;
212
- query?: string;
213
- cursor?: string;
214
- message: string;
215
- } | {
216
- type: "balance_stream_chunk";
217
- address: string;
218
- chunkSize: number;
219
- } | {
220
- type: "balance_stream_fallback";
221
- address: string;
222
- message: string;
223
- };
224
-
225
- /** WalletConnect configuration options (all optional - SDK has built-in defaults) */
226
- type WalletConnectConfig = {
227
- /** Override the built-in WalletConnect project ID (optional - SDK includes one) */
228
- projectId?: string;
229
- /** Chain IDs to support (defaults to [1] for Ethereum mainnet) */
230
- chains?: number[];
231
- /** Optional chain IDs (chains that can be switched to) */
232
- optionalChains?: number[];
233
- /** dApp metadata shown in wallet */
234
- metadata?: {
235
- name: string;
236
- description?: string;
237
- url: string;
238
- icons?: string[];
239
- };
240
- /** Custom relay URL (defaults to WalletConnect's relay) */
241
- relayUrl?: string;
242
- /** Whether to show our custom QR modal (default: true) */
243
- showQrModal?: boolean;
244
- /** Disable WalletConnect entirely (default: false) */
245
- disabled?: boolean;
246
- };
247
- /** Resolved WalletConnect config with defaults applied */
248
- type ResolvedWalletConnectConfig = {
249
- projectId: string;
250
- chains: number[];
251
- optionalChains: number[];
252
- metadata: {
253
- name: string;
254
- description: string;
255
- url: string;
256
- icons: string[];
257
- };
258
- relayUrl?: string;
259
- showQrModal: boolean;
260
- };
261
- type TrustwareConfigOptions = {
262
- apiKey: string;
263
- routes: {
264
- toChain: string;
265
- toToken: string;
266
- fromToken?: string;
267
- fromAddress?: string;
268
- toAddress?: string;
269
- defaultSlippage?: number;
270
- routeType?: string;
271
- options?: {
272
- routeRefreshMs?: number;
273
- fixedFromAmount?: string | number;
274
- minAmountOut?: string | number;
275
- maxAmountOut?: string | number;
276
- };
277
- };
278
- autoDetectProvider?: boolean;
279
- theme?: TrustwareWidgetTheme;
280
- messages?: Partial<TrustwareWidgetMessages>;
281
- retry?: RetryConfig;
282
- walletConnect?: WalletConnectConfig;
283
- features?: FeatureFlags;
284
- onError?: (error: TrustwareError) => void;
285
- onSuccess?: (transaction: Transaction) => void;
286
- onEvent?: (event: TrustwareEvent) => void;
287
- };
288
- type ResolvedTrustwareConfig = {
289
- apiKey: string;
290
- routes: {
291
- toChain: string;
292
- toToken: string;
293
- fromToken?: string;
294
- fromAddress?: string;
295
- toAddress?: string;
296
- defaultSlippage: number;
297
- routeType: string;
298
- options: {
299
- routeRefreshMs?: number;
300
- fixedFromAmount?: string | number;
301
- minAmountOut?: string | number;
302
- maxAmountOut?: string | number;
303
- };
304
- };
305
- autoDetectProvider: boolean;
306
- theme: TrustwareWidgetTheme;
307
- messages: TrustwareWidgetMessages;
308
- retry: ResolvedRetryConfig;
309
- walletConnect?: ResolvedWalletConnectConfig | WalletConnectConfig | undefined;
310
- features: ResolvedFeatureFlags;
311
- onError?: (error: TrustwareError) => void;
312
- onSuccess?: (transaction: Transaction) => void;
313
- onEvent?: (event: TrustwareEvent) => void;
314
- };
315
- type FeatureFlags = {
316
- tokensPagination?: boolean;
317
- balanceStreaming?: boolean;
318
- shouldAllowGA4?: boolean;
319
- };
320
- type ResolvedFeatureFlags = {
321
- tokensPagination: boolean;
322
- balanceStreaming: boolean;
323
- shouldAllowGA4: boolean;
324
- };
325
- declare const DEFAULT_SLIPPAGE = 1;
326
- declare const DEFAULT_AUTO_DETECT_PROVIDER = false;
327
- type RateLimitInfo = {
328
- /** Maximum requests allowed in the current window */
329
- limit: number;
330
- /** Requests remaining in the current window */
331
- remaining: number;
332
- /** Unix timestamp when the rate limit window resets */
333
- reset: number;
334
- /** Seconds until rate limit resets (only present on 429 responses) */
335
- retryAfter?: number;
336
- };
337
- type RetryConfig = {
338
- /** Enable automatic retry on 429 responses (default: true). Note: This does NOT disable backend rate limits, only client-side retry behavior. */
339
- autoRetry?: boolean;
340
- /** Maximum number of retries on 429 (default: 3) */
341
- maxRetries?: number;
342
- /** Base delay in ms for exponential backoff (default: 1000) */
343
- baseDelayMs?: number;
344
- /** Callback when rate limit info is received from server */
345
- onRateLimitInfo?: (info: RateLimitInfo) => void;
346
- /** Callback when rate limit is hit (429 received) */
347
- onRateLimited?: (info: RateLimitInfo, retryCount: number) => void;
348
- /** Callback when remaining requests fall below threshold */
349
- onRateLimitApproaching?: (info: RateLimitInfo, threshold: number) => void;
350
- /** Threshold for onRateLimitApproaching callback (default: 5) */
351
- approachingThreshold?: number;
352
- };
353
- type ResolvedRetryConfig = {
354
- autoRetry: boolean;
355
- maxRetries: number;
356
- baseDelayMs: number;
357
- approachingThreshold: number;
358
- onRateLimitInfo?: (info: RateLimitInfo) => void;
359
- onRateLimited?: (info: RateLimitInfo, retryCount: number) => void;
360
- onRateLimitApproaching?: (info: RateLimitInfo, threshold: number) => void;
361
- };
362
- declare const DEFAULT_RETRY_CONFIG: ResolvedRetryConfig;
363
- declare const DEFAULT_FEATURE_FLAGS: ResolvedFeatureFlags;
364
-
365
- type AddressValidationResult = {
366
- isValid: boolean;
367
- error?: string;
368
- };
369
- declare function validateEvmAddress(address: string): AddressValidationResult;
370
- declare function validateSeiAddress(address: string): AddressValidationResult;
371
- declare function validateSolanaAddress(address: string): AddressValidationResult;
372
- declare function validateBtcAddress(address: string): AddressValidationResult;
373
- declare function validateAddressForChain(address: string, chain?: ChainDef | ChainType | string | null): AddressValidationResult;
374
- declare function validateRouteAddresses(params: {
375
- fromChain?: ChainDef | ChainType | string | null;
376
- toChain?: ChainDef | ChainType | string | null;
377
- fromAddress: string;
378
- toAddress: string;
379
- refundAddress?: string;
380
- direction?: string;
381
- }): AddressValidationResult;
382
-
383
- /** Map chain reference -> backend chain_key and return enriched balances */
384
- declare function getBalances(chainRef: string | number, address: string): Promise<BalanceRow[]>;
385
- declare function getBalancesByAddress(address: string, opts?: BalanceStreamOptions): Promise<WalletAddressBalanceWrapper[]>;
386
- declare function getBalancesByAddressStream(address: string, opts?: BalanceStreamOptions): AsyncGenerator<WalletAddressBalanceWrapper[], void, void>;
387
-
388
- declare function sendRouteTransaction(b: BuildRouteResult, fallbackChainId?: number | string): Promise<string>;
389
- declare function runTopUp(params: {
390
- fromChain?: string;
391
- toChain?: string;
392
- fromToken?: string;
393
- toToken?: string;
394
- toAddress?: string;
395
- fromAmount: string | number;
396
- }): Promise<Transaction>;
397
-
398
- interface UseChainsResult {
399
- /** All available chains */
400
- chains: ChainDef[];
401
- /** Popular/featured chains (Ethereum, Polygon, Base) */
402
- popularChains: ChainDef[];
403
- /** Other chains (not in popular list) */
404
- otherChains: ChainDef[];
405
- /** Whether chains are currently loading */
406
- isLoading: boolean;
407
- /** Error message if loading failed */
408
- error: string | null;
409
- chainMap: Map<string, ChainDef>;
410
- }
411
- /**
412
- * Hook to load available chains from the registry.
413
- * Returns chains split into popular and other categories.
414
- */
415
- declare function useChains(): UseChainsResult;
416
-
417
- interface UseTokensResult {
418
- /** All available tokens for the selected chain */
419
- tokens: Token[];
420
- /** Filtered tokens based on search query */
421
- filteredTokens: Token[];
422
- /** Whether tokens are currently loading */
423
- isLoading: boolean;
424
- /** Error message if loading failed */
425
- error: string | null;
426
- /** Current search query */
427
- searchQuery: string;
428
- /** Set the search query to filter tokens */
429
- setSearchQuery: (query: string) => void;
430
- /** Whether more tokens can be loaded for the active query */
431
- hasNextPage: boolean;
432
- /** Load the next token page when pagination is enabled */
433
- loadMore: () => Promise<void>;
434
- /** Whether an additional page request is in flight */
435
- isLoadingMore: boolean;
436
- }
437
- declare function useTokens(chainId: string | number | null | undefined): UseTokensResult;
438
-
439
- declare const Trustware: {
440
- /** Initialize config */
441
- init(cfg: TrustwareConfigOptions): Promise</*elided*/ any>;
442
- /** Attach a wallet interface directly (skips detection) */
443
- useWallet(w: WalletInterFaceAPI): /*elided*/ any;
444
- /** Best-effort background attach to detected wallet(s) (detection hook should be running in the app) */
445
- autoDetect(_timeoutMs?: number): Promise<boolean>;
446
- /** Read resolved config */
447
- getConfig(): ResolvedTrustwareConfig;
448
- setDestinationAddress(address?: string | null): /*elided*/ any;
449
- setDestinationChain(chain: string): /*elided*/ any;
450
- setDestinationToken(token: string): /*elided*/ any;
451
- /** Read active wallet */
452
- getWallet(): WalletInterFaceAPI | null;
453
- getIdentity(): WalletIdentity;
454
- resolveAddressForChain(chain: Parameters<typeof walletManager.resolveAddressForChain>[0]): WalletAddressResolution;
455
- addIdentityAddress(address: Parameters<typeof walletManager.addIdentityAddress>[0]): /*elided*/ any;
456
- /** Simple helpers */
457
- getAddress(): Promise<string>;
458
- buildRoute: typeof buildRoute;
459
- buildDepositAddress: typeof buildDepositAddress;
460
- submitReceipt: typeof submitReceipt;
461
- getStatus: typeof getStatus;
462
- pollStatus: typeof pollStatus;
463
- getBalances: typeof getBalances;
464
- getBalancesByAddress: typeof getBalancesByAddress;
465
- getBalancesByAddressStream: typeof getBalancesByAddressStream;
466
- useChains: typeof useChains;
467
- useTokens: typeof useTokens;
468
- validateAddressForChain: typeof validateAddressForChain;
469
- validateRouteAddresses: typeof validateRouteAddresses;
470
- sendRouteTransaction: typeof sendRouteTransaction;
471
- runTopUp: typeof runTopUp;
472
- };
473
- type TrustwareCore = typeof Trustware;
474
-
475
- export { validateSolanaAddress as A, type BuildRouteResult as B, DEFAULT_AUTO_DETECT_PROVIDER as D, type FeatureFlags as F, type RateLimitInfo as R, type TrustwareConfigOptions as T, type WalletConnectConfig as W, Trustware as a, TrustwareError as b, type Transaction as c, type TrustwareEvent as d, DEFAULT_FEATURE_FLAGS as e, DEFAULT_MESSAGES as f, DEFAULT_RETRY_CONFIG as g, DEFAULT_SLIPPAGE as h, DEFAULT_THEME as i, type ResolvedFeatureFlags as j, type ResolvedRetryConfig as k, type ResolvedTrustwareConfig as l, type ResolvedWalletConnectConfig as m, type RetryConfig as n, type RouteEstimate as o, type RouteIntent as p, type RouteParams as q, type RoutePlan as r, type TrustwareCore as s, type TrustwareWidgetMessages as t, type TrustwareWidgetTheme as u, validateAddressForChain as v, validateBtcAddress as w, validateEvmAddress as x, validateRouteAddresses as y, validateSeiAddress as z };