@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.
package/dist/widget.cjs CHANGED
@@ -585,7 +585,7 @@ var init_constants = __esm({
585
585
  "src/constants.ts"() {
586
586
  "use strict";
587
587
  SDK_NAME = "@trustware/sdk";
588
- SDK_VERSION = "1.1.9-staging.6";
588
+ SDK_VERSION = "1.1.9-staging.7";
589
589
  API_ROOT = "https://bv-staging-api.trustware.io";
590
590
  GTM_ID = "GTM-TZDGNCXB";
591
591
  API_PREFIX = "/api";
@@ -796,7 +796,9 @@ var init_chains = __esm({
796
796
  btc: "bitcoin",
797
797
  bitcoin: "bitcoin",
798
798
  sei: "cosmos",
799
- "pacific-1": "cosmos"
799
+ "pacific-1": "cosmos",
800
+ nibiru: "cosmos",
801
+ "cataclysm-1": "cosmos"
800
802
  };
801
803
  }
802
804
  });
@@ -1992,16 +1994,23 @@ function validateEvmAddress(address) {
1992
1994
  }
1993
1995
  return { isValid: true };
1994
1996
  }
1995
- function validateSeiAddress(address) {
1997
+ function resolveCosmosBech32Prefix(chain) {
1998
+ const chainDef = typeof chain === "object" && chain ? chain : void 0;
1999
+ const identifier = chainDef?.networkIdentifier ?? chainDef?.chainId ?? chainDef?.id ?? (typeof chain === "string" ? chain : void 0);
2000
+ const normalized = String(identifier ?? "").trim().toLowerCase();
2001
+ return COSMOS_BECH32_PREFIX_BY_CHAIN_ID[normalized] ?? "sei";
2002
+ }
2003
+ function validateCosmosAddress(address, chain) {
1996
2004
  const trimmed = address.trim();
1997
- if ((0, import_viem.isAddress)(trimmed)) {
2005
+ const prefix = resolveCosmosBech32Prefix(chain);
2006
+ if (prefix === "sei" && (0, import_viem.isAddress)(trimmed)) {
1998
2007
  return { isValid: true };
1999
2008
  }
2000
- const result = validateBech32LikeAddress(trimmed, "sei");
2009
+ const result = validateBech32LikeAddress(trimmed, prefix);
2001
2010
  if (result.isValid) return result;
2002
2011
  return {
2003
2012
  isValid: false,
2004
- error: "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings."
2013
+ error: prefix === "sei" ? "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings." : `Address must be a valid ${prefix}1 bech32 string.`
2005
2014
  };
2006
2015
  }
2007
2016
  function validateSolanaAddress(address) {
@@ -2051,15 +2060,12 @@ function validateAddressForChain(address, chain) {
2051
2060
  case "bitcoin":
2052
2061
  return validateBtcAddress(trimmed);
2053
2062
  case "cosmos":
2054
- if (chainDef?.networkIdentifier?.toLowerCase() === "sei") {
2055
- return validateSeiAddress(trimmed);
2056
- }
2057
- return validateBech32LikeAddress(trimmed, "sei");
2063
+ return validateCosmosAddress(trimmed, chainDef ?? chain);
2058
2064
  default:
2059
2065
  return { isValid: false, error: "Unsupported or unknown chain type." };
2060
2066
  }
2061
2067
  }
2062
- function validateAddressForRouteChain(address, chainType) {
2068
+ function validateAddressForRouteChain(address, chainType, chainRef) {
2063
2069
  switch (normalizeChainType(chainType)) {
2064
2070
  case "evm":
2065
2071
  return validateEvmAddress(address);
@@ -2068,7 +2074,7 @@ function validateAddressForRouteChain(address, chainType) {
2068
2074
  case "bitcoin":
2069
2075
  return validateBtcAddress(address);
2070
2076
  case "cosmos":
2071
- return validateSeiAddress(address);
2077
+ return validateCosmosAddress(address, chainRef ?? chainType);
2072
2078
  default:
2073
2079
  return { isValid: false, error: "Unsupported chain type." };
2074
2080
  }
@@ -2090,14 +2096,18 @@ function validateRouteAddresses(params) {
2090
2096
  const normalizedDirection = params.direction?.trim().toLowerCase();
2091
2097
  const isDepositFlow = normalizedDirection === "deposit" || (toType === "evm" || toType === "cosmos") && (fromType === "bitcoin" || fromType === "solana");
2092
2098
  if (isDepositFlow) {
2093
- const fromResult2 = validateAddressForRouteChain(fromAddress, fromType);
2099
+ const fromResult2 = validateAddressForRouteChain(
2100
+ fromAddress,
2101
+ fromType,
2102
+ params.fromChain
2103
+ );
2094
2104
  if (!fromResult2.isValid) {
2095
2105
  return {
2096
2106
  isValid: false,
2097
2107
  error: `From address: ${fromResult2.error ?? "Invalid address."}`
2098
2108
  };
2099
2109
  }
2100
- const toResult2 = toType === "cosmos" ? validateSeiAddress(toAddress) : validateEvmAddress(toAddress);
2110
+ const toResult2 = toType === "cosmos" ? validateCosmosAddress(toAddress, params.toChain) : validateEvmAddress(toAddress);
2101
2111
  if (!toResult2.isValid) {
2102
2112
  return {
2103
2113
  isValid: false,
@@ -2122,14 +2132,22 @@ function validateRouteAddresses(params) {
2122
2132
  }
2123
2133
  return { isValid: true };
2124
2134
  }
2125
- const fromResult = validateAddressForRouteChain(fromAddress, fromType);
2135
+ const fromResult = validateAddressForRouteChain(
2136
+ fromAddress,
2137
+ fromType,
2138
+ params.fromChain
2139
+ );
2126
2140
  if (!fromResult.isValid) {
2127
2141
  return {
2128
2142
  isValid: false,
2129
2143
  error: `From address: ${fromResult.error ?? "Invalid address."}`
2130
2144
  };
2131
2145
  }
2132
- const toResult = validateAddressForRouteChain(toAddress, toType);
2146
+ const toResult = validateAddressForRouteChain(
2147
+ toAddress,
2148
+ toType,
2149
+ params.toChain
2150
+ );
2133
2151
  if (!toResult.isValid) {
2134
2152
  return {
2135
2153
  isValid: false,
@@ -2138,7 +2156,7 @@ function validateRouteAddresses(params) {
2138
2156
  }
2139
2157
  return { isValid: true };
2140
2158
  }
2141
- var import_viem, BECH32_CHARSET;
2159
+ var import_viem, BECH32_CHARSET, COSMOS_BECH32_PREFIX_BY_CHAIN_ID;
2142
2160
  var init_address = __esm({
2143
2161
  "src/validation/address.ts"() {
2144
2162
  "use strict";
@@ -2146,6 +2164,12 @@ var init_address = __esm({
2146
2164
  init_index_node4();
2147
2165
  init_chains();
2148
2166
  BECH32_CHARSET = /^[023456789acdefghjklmnpqrstuvwxyz]+$/i;
2167
+ COSMOS_BECH32_PREFIX_BY_CHAIN_ID = {
2168
+ "pacific-1": "sei",
2169
+ sei: "sei",
2170
+ "cataclysm-1": "nibi",
2171
+ nibiru: "nibi"
2172
+ };
2149
2173
  }
2150
2174
  });
2151
2175
 
@@ -2537,7 +2561,7 @@ async function buildDepositAddress(body, signal) {
2537
2561
  route
2538
2562
  };
2539
2563
  }
2540
- async function submitReceipt(intentId, txHash, sponsorshipRequestId) {
2564
+ async function submitReceipt(intentId, txHash, sponsorshipRequestId, eoaAddress) {
2541
2565
  const r = await rateLimitedFetch(
2542
2566
  `${apiBase()}/v1/route-intent/${intentId}/receipt`,
2543
2567
  {
@@ -2545,7 +2569,8 @@ async function submitReceipt(intentId, txHash, sponsorshipRequestId) {
2545
2569
  headers: jsonHeaders({ "Idempotency-Key": txHash }),
2546
2570
  body: JSON.stringify({
2547
2571
  txHash,
2548
- ...sponsorshipRequestId ? { sponsorshipRequestId } : {}
2572
+ ...sponsorshipRequestId ? { sponsorshipRequestId } : {},
2573
+ ...eoaAddress ? { eoaAddress } : {}
2549
2574
  })
2550
2575
  }
2551
2576
  );
@@ -2855,6 +2880,7 @@ function useTrustwareConfig() {
2855
2880
  } catch {
2856
2881
  return {
2857
2882
  apiKey: "",
2883
+ mode: "deposit",
2858
2884
  routes: {
2859
2885
  toChain: "",
2860
2886
  toToken: "",
@@ -3120,7 +3146,9 @@ var init_chainHelpers = __esm({
3120
3146
  btc: "bitcoin",
3121
3147
  bitcoin: "bitcoin",
3122
3148
  sei: "cosmos",
3123
- "pacific-1": "cosmos"
3149
+ "pacific-1": "cosmos",
3150
+ nibiru: "cosmos",
3151
+ "cataclysm-1": "cosmos"
3124
3152
  };
3125
3153
  SEI_EVM_CHAIN_ID = "1329";
3126
3154
  SEI_COSMOS_CHAIN_ID = "pacific-1";
@@ -3335,7 +3363,8 @@ function filterSupportedChains(chains) {
3335
3363
  }
3336
3364
  if (chainType === "cosmos") {
3337
3365
  const seiKey = canonicalSeiChainKey(chain.chainId ?? chain.id);
3338
- if (seiKey !== "sei" && seiKey !== "pacific-1") {
3366
+ const isNibiru = normalizeChainKey2(chain.chainId ?? chain.id) === NIBIRU_COSMOS_CHAIN_ID;
3367
+ if (seiKey !== "sei" && !isNibiru) {
3339
3368
  return false;
3340
3369
  }
3341
3370
  }
@@ -3435,7 +3464,7 @@ function useChains() {
3435
3464
  error
3436
3465
  };
3437
3466
  }
3438
- var import_react4, POPULAR_CHAINS_BY_TVL, POPULAR_LIMIT;
3467
+ var import_react4, POPULAR_CHAINS_BY_TVL, POPULAR_LIMIT, NIBIRU_COSMOS_CHAIN_ID;
3439
3468
  var init_useChains = __esm({
3440
3469
  "src/core/useChains.ts"() {
3441
3470
  "use strict";
@@ -3446,6 +3475,7 @@ var init_useChains = __esm({
3446
3475
  init_popularChains();
3447
3476
  POPULAR_CHAINS_BY_TVL = popularChains_default.byTvl;
3448
3477
  POPULAR_LIMIT = popularChains_default.popularLimit;
3478
+ NIBIRU_COSMOS_CHAIN_ID = "cataclysm-1";
3449
3479
  }
3450
3480
  });
3451
3481
 
@@ -8783,46 +8813,80 @@ function normalizeSlippage(v) {
8783
8813
  if (n > 5) return 5;
8784
8814
  return n;
8785
8815
  }
8816
+ function warnDeprecatedSwapModeFlag() {
8817
+ if (hasWarnedDeprecatedSwapModeFlag) return;
8818
+ hasWarnedDeprecatedSwapModeFlag = true;
8819
+ console.warn(
8820
+ '[Trustware SDK] `features.swapMode` is deprecated \u2014 use `mode: "swap"` on the top-level config instead.'
8821
+ );
8822
+ }
8823
+ function resolveMode(input) {
8824
+ if (input.mode === "swap") return "swap";
8825
+ if (input.mode === "deposit") return "deposit";
8826
+ if (input.features?.swapMode) {
8827
+ warnDeprecatedSwapModeFlag();
8828
+ return "swap";
8829
+ }
8830
+ return "deposit";
8831
+ }
8786
8832
  function resolveConfig(input) {
8787
8833
  if (!input?.apiKey) {
8788
- throw new Error("TrustwareConfig: 'apiKey' is required.");
8834
+ throw new TrustwareError({
8835
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
8836
+ message: "TrustwareConfig: 'apiKey' is required.",
8837
+ userMessage: "Missing required API key configuration."
8838
+ });
8789
8839
  }
8790
- if (!input.routes?.toChain || !input.routes?.toToken) {
8791
- throw new Error(
8792
- "TrustwareConfig: 'routes.toChain' and 'routes.toToken' are required."
8793
- );
8840
+ const mode = resolveMode(input);
8841
+ if (mode === "deposit" && (!input.routes?.toChain || !input.routes?.toToken)) {
8842
+ throw new TrustwareError({
8843
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
8844
+ message: "TrustwareConfig: 'routes.toChain' and 'routes.toToken' are required in deposit mode.",
8845
+ userMessage: "Missing required destination chain/token configuration."
8846
+ });
8794
8847
  }
8795
- const toChain = input.routes.toChain;
8796
- if (input.routes.toAddress) {
8848
+ const toChain = input.routes?.toChain;
8849
+ if (input.routes?.toAddress && toChain) {
8797
8850
  const result = validateAddressForChain(input.routes.toAddress, toChain);
8798
8851
  if (!result.isValid) {
8799
8852
  console.error(`[Trustware SDK] Invalid toAddress: ${result.error}`);
8800
- throw new Error(`Invalid toAddress: ${result.error}`);
8853
+ throw new TrustwareError({
8854
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
8855
+ message: `Invalid toAddress: ${result.error}`,
8856
+ userMessage: "The configured destination address is invalid."
8857
+ });
8801
8858
  }
8802
8859
  }
8803
- if (input.routes.fromAddress) {
8804
- const result = validateAddressForChain(
8805
- input.routes.fromAddress,
8806
- input.routes.fromChain ?? toChain
8807
- );
8808
- if (!result.isValid) {
8809
- console.error(`[Trustware SDK] Invalid fromAddress: ${result.error}`);
8810
- throw new Error(`Invalid fromAddress: ${result.error}`);
8860
+ if (input.routes?.fromAddress) {
8861
+ const fromChain = input.routes.fromChain ?? toChain;
8862
+ if (fromChain) {
8863
+ const result = validateAddressForChain(
8864
+ input.routes.fromAddress,
8865
+ fromChain
8866
+ );
8867
+ if (!result.isValid) {
8868
+ console.error(`[Trustware SDK] Invalid fromAddress: ${result.error}`);
8869
+ throw new TrustwareError({
8870
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
8871
+ message: `Invalid fromAddress: ${result.error}`,
8872
+ userMessage: "The configured source address is invalid."
8873
+ });
8874
+ }
8811
8875
  }
8812
8876
  }
8813
8877
  const autoDetectProvider = typeof input.autoDetectProvider === "boolean" ? input.autoDetectProvider : DEFAULT_AUTO_DETECT_PROVIDER;
8814
8878
  const routes = {
8815
- toChain: input.routes.toChain,
8816
- toToken: input.routes.toToken,
8817
- fromToken: input.routes.fromToken,
8818
- fromAddress: input.routes.fromAddress,
8819
- fromChain: input.routes.fromChain,
8820
- toAddress: input.routes.toAddress,
8879
+ toChain: input.routes?.toChain ?? "",
8880
+ toToken: input.routes?.toToken ?? "",
8881
+ fromToken: input.routes?.fromToken,
8882
+ fromAddress: input.routes?.fromAddress,
8883
+ fromChain: input.routes?.fromChain,
8884
+ toAddress: input.routes?.toAddress,
8821
8885
  defaultSlippage: normalizeSlippage(
8822
- input.routes.defaultSlippage ?? DEFAULT_SLIPPAGE
8886
+ input.routes?.defaultSlippage ?? DEFAULT_SLIPPAGE
8823
8887
  ),
8824
8888
  options: {
8825
- ...input.routes.options
8889
+ ...input.routes?.options
8826
8890
  }
8827
8891
  };
8828
8892
  const theme = input.theme ?? "system";
@@ -8841,13 +8905,16 @@ function resolveConfig(input) {
8841
8905
  tokensPagination: input.features?.tokensPagination ?? DEFAULT_FEATURE_FLAGS.tokensPagination,
8842
8906
  balanceStreaming: input.features?.balanceStreaming ?? DEFAULT_FEATURE_FLAGS.balanceStreaming,
8843
8907
  shouldAllowGA4: input.features?.shouldAllowGA4 ?? DEFAULT_FEATURE_FLAGS.shouldAllowGA4,
8844
- swapMode: input.features?.swapMode ?? DEFAULT_FEATURE_FLAGS.swapMode,
8908
+ // Always mirrors the canonical `mode`, however the caller set it (new `mode` field
8909
+ // or the deprecated `features.swapMode` flag).
8910
+ swapMode: mode === "swap",
8845
8911
  swapDefaultDestToken: input.features?.swapDefaultDestToken ?? DEFAULT_FEATURE_FLAGS.swapDefaultDestToken,
8846
8912
  swapLockDestToken: input.features?.swapLockDestToken ?? DEFAULT_FEATURE_FLAGS.swapLockDestToken,
8847
8913
  swapAllowedDestTokens: input.features?.swapAllowedDestTokens ?? DEFAULT_FEATURE_FLAGS.swapAllowedDestTokens
8848
8914
  };
8849
8915
  return {
8850
8916
  apiKey: input.apiKey,
8917
+ mode,
8851
8918
  routes,
8852
8919
  autoDetectProvider,
8853
8920
  theme,
@@ -8860,12 +8927,15 @@ function resolveConfig(input) {
8860
8927
  onEvent: input.onEvent
8861
8928
  };
8862
8929
  }
8930
+ var hasWarnedDeprecatedSwapModeFlag;
8863
8931
  var init_merge = __esm({
8864
8932
  "src/config/merge.ts"() {
8865
8933
  "use strict";
8866
8934
  init_defaults();
8867
8935
  init_config();
8868
8936
  init_index();
8937
+ init_TrustwareError();
8938
+ hasWarnedDeprecatedSwapModeFlag = false;
8869
8939
  }
8870
8940
  });
8871
8941
 
@@ -31396,7 +31466,7 @@ async function sendRouteAsUserOperation(params) {
31396
31466
  );
31397
31467
  }
31398
31468
  console.debug("[send] UserOp included", { userOpHash, txHash });
31399
- await submitReceipt(intentId, txHash, getSponsorshipRequestId());
31469
+ await submitReceipt(intentId, txHash, getSponsorshipRequestId(), eoaAddress);
31400
31470
  return { userOpHash, txHash, intentId };
31401
31471
  }
31402
31472
  var NATIVE_ADDRS;
@@ -39676,7 +39746,7 @@ var init_TrustwareWidgetV2 = __esm({
39676
39746
  if (!isOpen) {
39677
39747
  return null;
39678
39748
  }
39679
- if (config.features.swapMode) {
39749
+ if (config.mode === "swap") {
39680
39750
  return /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(SwapMode, { theme, style });
39681
39751
  }
39682
39752
  return /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(DepositProvider, { initialStep: effectiveInitialStep, children: /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(