@trustware/sdk-staging 1.1.9-staging.6 → 1.1.9-staging.7

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,4 +1,4 @@
1
- import { h as DetectedWallet, A as WagmiBridge, W as WalletInterFaceAPI, E as EIP1193, M as WalletId, i as EIP6963ProviderDetail } from './manager-BMO1O-cW.js';
1
+ import { h as DetectedWallet, C as WagmiBridge, W as WalletInterFaceAPI, E as EIP1193, N as WalletId, i as EIP6963ProviderDetail } from './manager-Dn4muk74.js';
2
2
 
3
3
  /** Try wagmi bridge first (if provided), otherwise return EIP-1193 adapter. */
4
4
  declare function connectDetectedWallet(dw: DetectedWallet, opts?: {
@@ -1,4 +1,4 @@
1
- import { h as DetectedWallet, A as WagmiBridge, W as WalletInterFaceAPI, E as EIP1193, M as WalletId, i as EIP6963ProviderDetail } from './manager-BZwbtOyf.cjs';
1
+ import { h as DetectedWallet, C as WagmiBridge, W as WalletInterFaceAPI, E as EIP1193, N as WalletId, i as EIP6963ProviderDetail } from './manager-DWFNyouP.cjs';
2
2
 
3
3
  /** Try wagmi bridge first (if provided), otherwise return EIP-1193 adapter. */
4
4
  declare function connectDetectedWallet(dw: DetectedWallet, opts?: {
package/dist/index.cjs CHANGED
@@ -71,6 +71,31 @@ var init_config = __esm({
71
71
  }
72
72
  });
73
73
 
74
+ // src/errors/TrustwareError.ts
75
+ var TrustwareError;
76
+ var init_TrustwareError = __esm({
77
+ "src/errors/TrustwareError.ts"() {
78
+ "use strict";
79
+ TrustwareError = class extends Error {
80
+ constructor(params) {
81
+ super(params.message);
82
+ this.name = "TrustwareError";
83
+ this.code = params.code;
84
+ this.userMessage = params.userMessage;
85
+ this.cause = params.cause;
86
+ }
87
+ toJSON() {
88
+ return {
89
+ name: this.name,
90
+ code: this.code,
91
+ message: this.message,
92
+ userMessage: this.userMessage
93
+ };
94
+ }
95
+ };
96
+ }
97
+ });
98
+
74
99
  // src/config/merge.ts
75
100
  function deepMerge(base2, patch) {
76
101
  if (!patch) return { ...base2 };
@@ -91,46 +116,80 @@ function normalizeSlippage(v) {
91
116
  if (n > 5) return 5;
92
117
  return n;
93
118
  }
119
+ function warnDeprecatedSwapModeFlag() {
120
+ if (hasWarnedDeprecatedSwapModeFlag) return;
121
+ hasWarnedDeprecatedSwapModeFlag = true;
122
+ console.warn(
123
+ '[Trustware SDK] `features.swapMode` is deprecated \u2014 use `mode: "swap"` on the top-level config instead.'
124
+ );
125
+ }
126
+ function resolveMode(input) {
127
+ if (input.mode === "swap") return "swap";
128
+ if (input.mode === "deposit") return "deposit";
129
+ if (input.features?.swapMode) {
130
+ warnDeprecatedSwapModeFlag();
131
+ return "swap";
132
+ }
133
+ return "deposit";
134
+ }
94
135
  function resolveConfig(input) {
95
136
  if (!input?.apiKey) {
96
- throw new Error("TrustwareConfig: 'apiKey' is required.");
137
+ throw new TrustwareError({
138
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
139
+ message: "TrustwareConfig: 'apiKey' is required.",
140
+ userMessage: "Missing required API key configuration."
141
+ });
97
142
  }
98
- if (!input.routes?.toChain || !input.routes?.toToken) {
99
- throw new Error(
100
- "TrustwareConfig: 'routes.toChain' and 'routes.toToken' are required."
101
- );
143
+ const mode = resolveMode(input);
144
+ if (mode === "deposit" && (!input.routes?.toChain || !input.routes?.toToken)) {
145
+ throw new TrustwareError({
146
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
147
+ message: "TrustwareConfig: 'routes.toChain' and 'routes.toToken' are required in deposit mode.",
148
+ userMessage: "Missing required destination chain/token configuration."
149
+ });
102
150
  }
103
- const toChain = input.routes.toChain;
104
- if (input.routes.toAddress) {
151
+ const toChain = input.routes?.toChain;
152
+ if (input.routes?.toAddress && toChain) {
105
153
  const result = validateAddressForChain(input.routes.toAddress, toChain);
106
154
  if (!result.isValid) {
107
155
  console.error(`[Trustware SDK] Invalid toAddress: ${result.error}`);
108
- throw new Error(`Invalid toAddress: ${result.error}`);
156
+ throw new TrustwareError({
157
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
158
+ message: `Invalid toAddress: ${result.error}`,
159
+ userMessage: "The configured destination address is invalid."
160
+ });
109
161
  }
110
162
  }
111
- if (input.routes.fromAddress) {
112
- const result = validateAddressForChain(
113
- input.routes.fromAddress,
114
- input.routes.fromChain ?? toChain
115
- );
116
- if (!result.isValid) {
117
- console.error(`[Trustware SDK] Invalid fromAddress: ${result.error}`);
118
- throw new Error(`Invalid fromAddress: ${result.error}`);
163
+ if (input.routes?.fromAddress) {
164
+ const fromChain = input.routes.fromChain ?? toChain;
165
+ if (fromChain) {
166
+ const result = validateAddressForChain(
167
+ input.routes.fromAddress,
168
+ fromChain
169
+ );
170
+ if (!result.isValid) {
171
+ console.error(`[Trustware SDK] Invalid fromAddress: ${result.error}`);
172
+ throw new TrustwareError({
173
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
174
+ message: `Invalid fromAddress: ${result.error}`,
175
+ userMessage: "The configured source address is invalid."
176
+ });
177
+ }
119
178
  }
120
179
  }
121
180
  const autoDetectProvider = typeof input.autoDetectProvider === "boolean" ? input.autoDetectProvider : DEFAULT_AUTO_DETECT_PROVIDER;
122
181
  const routes = {
123
- toChain: input.routes.toChain,
124
- toToken: input.routes.toToken,
125
- fromToken: input.routes.fromToken,
126
- fromAddress: input.routes.fromAddress,
127
- fromChain: input.routes.fromChain,
128
- toAddress: input.routes.toAddress,
182
+ toChain: input.routes?.toChain ?? "",
183
+ toToken: input.routes?.toToken ?? "",
184
+ fromToken: input.routes?.fromToken,
185
+ fromAddress: input.routes?.fromAddress,
186
+ fromChain: input.routes?.fromChain,
187
+ toAddress: input.routes?.toAddress,
129
188
  defaultSlippage: normalizeSlippage(
130
- input.routes.defaultSlippage ?? DEFAULT_SLIPPAGE
189
+ input.routes?.defaultSlippage ?? DEFAULT_SLIPPAGE
131
190
  ),
132
191
  options: {
133
- ...input.routes.options
192
+ ...input.routes?.options
134
193
  }
135
194
  };
136
195
  const theme = input.theme ?? "system";
@@ -149,13 +208,16 @@ function resolveConfig(input) {
149
208
  tokensPagination: input.features?.tokensPagination ?? DEFAULT_FEATURE_FLAGS.tokensPagination,
150
209
  balanceStreaming: input.features?.balanceStreaming ?? DEFAULT_FEATURE_FLAGS.balanceStreaming,
151
210
  shouldAllowGA4: input.features?.shouldAllowGA4 ?? DEFAULT_FEATURE_FLAGS.shouldAllowGA4,
152
- swapMode: input.features?.swapMode ?? DEFAULT_FEATURE_FLAGS.swapMode,
211
+ // Always mirrors the canonical `mode`, however the caller set it (new `mode` field
212
+ // or the deprecated `features.swapMode` flag).
213
+ swapMode: mode === "swap",
153
214
  swapDefaultDestToken: input.features?.swapDefaultDestToken ?? DEFAULT_FEATURE_FLAGS.swapDefaultDestToken,
154
215
  swapLockDestToken: input.features?.swapLockDestToken ?? DEFAULT_FEATURE_FLAGS.swapLockDestToken,
155
216
  swapAllowedDestTokens: input.features?.swapAllowedDestTokens ?? DEFAULT_FEATURE_FLAGS.swapAllowedDestTokens
156
217
  };
157
218
  return {
158
219
  apiKey: input.apiKey,
220
+ mode,
159
221
  routes,
160
222
  autoDetectProvider,
161
223
  theme,
@@ -168,12 +230,15 @@ function resolveConfig(input) {
168
230
  onEvent: input.onEvent
169
231
  };
170
232
  }
233
+ var hasWarnedDeprecatedSwapModeFlag;
171
234
  var init_merge = __esm({
172
235
  "src/config/merge.ts"() {
173
236
  "use strict";
174
237
  init_defaults();
175
238
  init_config();
176
239
  init_index();
240
+ init_TrustwareError();
241
+ hasWarnedDeprecatedSwapModeFlag = false;
177
242
  }
178
243
  });
179
244
 
@@ -430,7 +495,7 @@ var init_constants = __esm({
430
495
  "src/constants.ts"() {
431
496
  "use strict";
432
497
  SDK_NAME = "@trustware/sdk";
433
- SDK_VERSION = "1.1.9-staging.6";
498
+ SDK_VERSION = "1.1.9-staging.7";
434
499
  API_ROOT = "https://bv-staging-api.trustware.io";
435
500
  GTM_ID = "GTM-TZDGNCXB";
436
501
  API_PREFIX = "/api";
@@ -2414,7 +2479,9 @@ var init_chains = __esm({
2414
2479
  btc: "bitcoin",
2415
2480
  bitcoin: "bitcoin",
2416
2481
  sei: "cosmos",
2417
- "pacific-1": "cosmos"
2482
+ "pacific-1": "cosmos",
2483
+ nibiru: "cosmos",
2484
+ "cataclysm-1": "cosmos"
2418
2485
  };
2419
2486
  }
2420
2487
  });
@@ -2469,6 +2536,25 @@ function validateSeiAddress(address) {
2469
2536
  error: "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings."
2470
2537
  };
2471
2538
  }
2539
+ function resolveCosmosBech32Prefix(chain) {
2540
+ const chainDef = typeof chain === "object" && chain ? chain : void 0;
2541
+ const identifier = chainDef?.networkIdentifier ?? chainDef?.chainId ?? chainDef?.id ?? (typeof chain === "string" ? chain : void 0);
2542
+ const normalized = String(identifier ?? "").trim().toLowerCase();
2543
+ return COSMOS_BECH32_PREFIX_BY_CHAIN_ID[normalized] ?? "sei";
2544
+ }
2545
+ function validateCosmosAddress(address, chain) {
2546
+ const trimmed = address.trim();
2547
+ const prefix = resolveCosmosBech32Prefix(chain);
2548
+ if (prefix === "sei" && (0, import_viem.isAddress)(trimmed)) {
2549
+ return { isValid: true };
2550
+ }
2551
+ const result = validateBech32LikeAddress(trimmed, prefix);
2552
+ if (result.isValid) return result;
2553
+ return {
2554
+ isValid: false,
2555
+ error: prefix === "sei" ? "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings." : `Address must be a valid ${prefix}1 bech32 string.`
2556
+ };
2557
+ }
2472
2558
  function validateSolanaAddress(address) {
2473
2559
  const trimmed = address.trim();
2474
2560
  if (trimmed.startsWith("0x") || (0, import_viem.isAddress)(trimmed)) {
@@ -2516,15 +2602,12 @@ function validateAddressForChain(address, chain) {
2516
2602
  case "bitcoin":
2517
2603
  return validateBtcAddress(trimmed);
2518
2604
  case "cosmos":
2519
- if (chainDef?.networkIdentifier?.toLowerCase() === "sei") {
2520
- return validateSeiAddress(trimmed);
2521
- }
2522
- return validateBech32LikeAddress(trimmed, "sei");
2605
+ return validateCosmosAddress(trimmed, chainDef ?? chain);
2523
2606
  default:
2524
2607
  return { isValid: false, error: "Unsupported or unknown chain type." };
2525
2608
  }
2526
2609
  }
2527
- function validateAddressForRouteChain(address, chainType) {
2610
+ function validateAddressForRouteChain(address, chainType, chainRef) {
2528
2611
  switch (normalizeChainType(chainType)) {
2529
2612
  case "evm":
2530
2613
  return validateEvmAddress(address);
@@ -2533,7 +2616,7 @@ function validateAddressForRouteChain(address, chainType) {
2533
2616
  case "bitcoin":
2534
2617
  return validateBtcAddress(address);
2535
2618
  case "cosmos":
2536
- return validateSeiAddress(address);
2619
+ return validateCosmosAddress(address, chainRef ?? chainType);
2537
2620
  default:
2538
2621
  return { isValid: false, error: "Unsupported chain type." };
2539
2622
  }
@@ -2555,14 +2638,18 @@ function validateRouteAddresses(params) {
2555
2638
  const normalizedDirection = params.direction?.trim().toLowerCase();
2556
2639
  const isDepositFlow = normalizedDirection === "deposit" || (toType === "evm" || toType === "cosmos") && (fromType === "bitcoin" || fromType === "solana");
2557
2640
  if (isDepositFlow) {
2558
- const fromResult2 = validateAddressForRouteChain(fromAddress, fromType);
2641
+ const fromResult2 = validateAddressForRouteChain(
2642
+ fromAddress,
2643
+ fromType,
2644
+ params.fromChain
2645
+ );
2559
2646
  if (!fromResult2.isValid) {
2560
2647
  return {
2561
2648
  isValid: false,
2562
2649
  error: `From address: ${fromResult2.error ?? "Invalid address."}`
2563
2650
  };
2564
2651
  }
2565
- const toResult2 = toType === "cosmos" ? validateSeiAddress(toAddress) : validateEvmAddress(toAddress);
2652
+ const toResult2 = toType === "cosmos" ? validateCosmosAddress(toAddress, params.toChain) : validateEvmAddress(toAddress);
2566
2653
  if (!toResult2.isValid) {
2567
2654
  return {
2568
2655
  isValid: false,
@@ -2587,14 +2674,22 @@ function validateRouteAddresses(params) {
2587
2674
  }
2588
2675
  return { isValid: true };
2589
2676
  }
2590
- const fromResult = validateAddressForRouteChain(fromAddress, fromType);
2677
+ const fromResult = validateAddressForRouteChain(
2678
+ fromAddress,
2679
+ fromType,
2680
+ params.fromChain
2681
+ );
2591
2682
  if (!fromResult.isValid) {
2592
2683
  return {
2593
2684
  isValid: false,
2594
2685
  error: `From address: ${fromResult.error ?? "Invalid address."}`
2595
2686
  };
2596
2687
  }
2597
- const toResult = validateAddressForRouteChain(toAddress, toType);
2688
+ const toResult = validateAddressForRouteChain(
2689
+ toAddress,
2690
+ toType,
2691
+ params.toChain
2692
+ );
2598
2693
  if (!toResult.isValid) {
2599
2694
  return {
2600
2695
  isValid: false,
@@ -2603,7 +2698,7 @@ function validateRouteAddresses(params) {
2603
2698
  }
2604
2699
  return { isValid: true };
2605
2700
  }
2606
- var import_viem, BECH32_CHARSET;
2701
+ var import_viem, BECH32_CHARSET, COSMOS_BECH32_PREFIX_BY_CHAIN_ID;
2607
2702
  var init_address = __esm({
2608
2703
  "src/validation/address.ts"() {
2609
2704
  "use strict";
@@ -2611,6 +2706,12 @@ var init_address = __esm({
2611
2706
  init_index_node4();
2612
2707
  init_chains();
2613
2708
  BECH32_CHARSET = /^[023456789acdefghjklmnpqrstuvwxyz]+$/i;
2709
+ COSMOS_BECH32_PREFIX_BY_CHAIN_ID = {
2710
+ "pacific-1": "sei",
2711
+ sei: "sei",
2712
+ "cataclysm-1": "nibi",
2713
+ nibiru: "nibi"
2714
+ };
2614
2715
  }
2615
2716
  });
2616
2717
 
@@ -4374,7 +4475,7 @@ async function buildDepositAddress(body, signal) {
4374
4475
  route
4375
4476
  };
4376
4477
  }
4377
- async function submitReceipt(intentId, txHash, sponsorshipRequestId) {
4478
+ async function submitReceipt(intentId, txHash, sponsorshipRequestId, eoaAddress) {
4378
4479
  const r = await rateLimitedFetch(
4379
4480
  `${apiBase()}/v1/route-intent/${intentId}/receipt`,
4380
4481
  {
@@ -4382,7 +4483,8 @@ async function submitReceipt(intentId, txHash, sponsorshipRequestId) {
4382
4483
  headers: jsonHeaders({ "Idempotency-Key": txHash }),
4383
4484
  body: JSON.stringify({
4384
4485
  txHash,
4385
- ...sponsorshipRequestId ? { sponsorshipRequestId } : {}
4486
+ ...sponsorshipRequestId ? { sponsorshipRequestId } : {},
4487
+ ...eoaAddress ? { eoaAddress } : {}
4386
4488
  })
4387
4489
  }
4388
4490
  );
@@ -5341,7 +5443,9 @@ var init_chainHelpers = __esm({
5341
5443
  btc: "bitcoin",
5342
5444
  bitcoin: "bitcoin",
5343
5445
  sei: "cosmos",
5344
- "pacific-1": "cosmos"
5446
+ "pacific-1": "cosmos",
5447
+ nibiru: "cosmos",
5448
+ "cataclysm-1": "cosmos"
5345
5449
  };
5346
5450
  SEI_EVM_CHAIN_ID = "1329";
5347
5451
  SEI_COSMOS_CHAIN_ID = "pacific-1";
@@ -5556,7 +5660,8 @@ function filterSupportedChains(chains) {
5556
5660
  }
5557
5661
  if (chainType === "cosmos") {
5558
5662
  const seiKey = canonicalSeiChainKey(chain.chainId ?? chain.id);
5559
- if (seiKey !== "sei" && seiKey !== "pacific-1") {
5663
+ const isNibiru = normalizeChainKey2(chain.chainId ?? chain.id) === NIBIRU_COSMOS_CHAIN_ID;
5664
+ if (seiKey !== "sei" && !isNibiru) {
5560
5665
  return false;
5561
5666
  }
5562
5667
  }
@@ -5656,7 +5761,7 @@ function useChains() {
5656
5761
  error
5657
5762
  };
5658
5763
  }
5659
- var import_react3, POPULAR_CHAINS_BY_TVL, POPULAR_LIMIT;
5764
+ var import_react3, POPULAR_CHAINS_BY_TVL, POPULAR_LIMIT, NIBIRU_COSMOS_CHAIN_ID;
5660
5765
  var init_useChains = __esm({
5661
5766
  "src/core/useChains.ts"() {
5662
5767
  "use strict";
@@ -5667,6 +5772,7 @@ var init_useChains = __esm({
5667
5772
  init_popularChains();
5668
5773
  POPULAR_CHAINS_BY_TVL = popularChains_default.byTvl;
5669
5774
  POPULAR_LIMIT = popularChains_default.popularLimit;
5775
+ NIBIRU_COSMOS_CHAIN_ID = "cataclysm-1";
5670
5776
  }
5671
5777
  });
5672
5778
 
@@ -7347,31 +7453,6 @@ var init_useTokens = __esm({
7347
7453
  }
7348
7454
  });
7349
7455
 
7350
- // src/errors/TrustwareError.ts
7351
- var TrustwareError;
7352
- var init_TrustwareError = __esm({
7353
- "src/errors/TrustwareError.ts"() {
7354
- "use strict";
7355
- TrustwareError = class extends Error {
7356
- constructor(params) {
7357
- super(params.message);
7358
- this.name = "TrustwareError";
7359
- this.code = params.code;
7360
- this.userMessage = params.userMessage;
7361
- this.cause = params.cause;
7362
- }
7363
- toJSON() {
7364
- return {
7365
- name: this.name,
7366
- code: this.code,
7367
- message: this.message,
7368
- userMessage: this.userMessage
7369
- };
7370
- }
7371
- };
7372
- }
7373
- });
7374
-
7375
7456
  // src/core/index.ts
7376
7457
  var _lastValidatedKey, Trustware;
7377
7458
  var init_core = __esm({
@@ -7967,6 +8048,7 @@ function useTrustwareConfig() {
7967
8048
  } catch {
7968
8049
  return {
7969
8050
  apiKey: "",
8051
+ mode: "deposit",
7970
8052
  routes: {
7971
8053
  toChain: "",
7972
8054
  toToken: "",
@@ -31525,7 +31607,7 @@ async function sendRouteAsUserOperation(params) {
31525
31607
  );
31526
31608
  }
31527
31609
  console.debug("[send] UserOp included", { userOpHash, txHash });
31528
- await submitReceipt(intentId, txHash, getSponsorshipRequestId());
31610
+ await submitReceipt(intentId, txHash, getSponsorshipRequestId(), eoaAddress);
31529
31611
  return { userOpHash, txHash, intentId };
31530
31612
  }
31531
31613
  var NATIVE_ADDRS;
@@ -39805,7 +39887,7 @@ var init_TrustwareWidgetV2 = __esm({
39805
39887
  if (!isOpen) {
39806
39888
  return null;
39807
39889
  }
39808
- if (config.features.swapMode) {
39890
+ if (config.mode === "swap") {
39809
39891
  return /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(SwapMode, { theme, style });
39810
39892
  }
39811
39893
  return /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(DepositProvider, { initialStep: effectiveInitialStep, children: /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(
@@ -39920,6 +40002,7 @@ __export(index_exports, {
39920
40002
  useWireDetectionIntoManager: () => useWireDetectionIntoManager,
39921
40003
  validateAddressForChain: () => validateAddressForChain,
39922
40004
  validateBtcAddress: () => validateBtcAddress,
40005
+ validateCosmosAddress: () => validateCosmosAddress,
39923
40006
  validateEvmAddress: () => validateEvmAddress,
39924
40007
  validateRouteAddresses: () => validateRouteAddresses,
39925
40008
  validateSeiAddress: () => validateSeiAddress,
@@ -39979,6 +40062,7 @@ init_index();
39979
40062
  useWireDetectionIntoManager,
39980
40063
  validateAddressForChain,
39981
40064
  validateBtcAddress,
40065
+ validateCosmosAddress,
39982
40066
  validateEvmAddress,
39983
40067
  validateRouteAddresses,
39984
40068
  validateSeiAddress,