@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.mjs CHANGED
@@ -563,7 +563,7 @@ var init_constants = __esm({
563
563
  "src/constants.ts"() {
564
564
  "use strict";
565
565
  SDK_NAME = "@trustware/sdk";
566
- SDK_VERSION = "1.1.9-staging.6";
566
+ SDK_VERSION = "1.1.9-staging.7";
567
567
  API_ROOT = "https://bv-staging-api.trustware.io";
568
568
  GTM_ID = "GTM-TZDGNCXB";
569
569
  API_PREFIX = "/api";
@@ -774,7 +774,9 @@ var init_chains = __esm({
774
774
  btc: "bitcoin",
775
775
  bitcoin: "bitcoin",
776
776
  sei: "cosmos",
777
- "pacific-1": "cosmos"
777
+ "pacific-1": "cosmos",
778
+ nibiru: "cosmos",
779
+ "cataclysm-1": "cosmos"
778
780
  };
779
781
  }
780
782
  });
@@ -1971,16 +1973,23 @@ function validateEvmAddress(address) {
1971
1973
  }
1972
1974
  return { isValid: true };
1973
1975
  }
1974
- function validateSeiAddress(address) {
1976
+ function resolveCosmosBech32Prefix(chain) {
1977
+ const chainDef = typeof chain === "object" && chain ? chain : void 0;
1978
+ const identifier = chainDef?.networkIdentifier ?? chainDef?.chainId ?? chainDef?.id ?? (typeof chain === "string" ? chain : void 0);
1979
+ const normalized = String(identifier ?? "").trim().toLowerCase();
1980
+ return COSMOS_BECH32_PREFIX_BY_CHAIN_ID[normalized] ?? "sei";
1981
+ }
1982
+ function validateCosmosAddress(address, chain) {
1975
1983
  const trimmed = address.trim();
1976
- if (isEvmAddress(trimmed)) {
1984
+ const prefix = resolveCosmosBech32Prefix(chain);
1985
+ if (prefix === "sei" && isEvmAddress(trimmed)) {
1977
1986
  return { isValid: true };
1978
1987
  }
1979
- const result = validateBech32LikeAddress(trimmed, "sei");
1988
+ const result = validateBech32LikeAddress(trimmed, prefix);
1980
1989
  if (result.isValid) return result;
1981
1990
  return {
1982
1991
  isValid: false,
1983
- error: "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings."
1992
+ error: prefix === "sei" ? "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings." : `Address must be a valid ${prefix}1 bech32 string.`
1984
1993
  };
1985
1994
  }
1986
1995
  function validateSolanaAddress(address) {
@@ -2030,15 +2039,12 @@ function validateAddressForChain(address, chain) {
2030
2039
  case "bitcoin":
2031
2040
  return validateBtcAddress(trimmed);
2032
2041
  case "cosmos":
2033
- if (chainDef?.networkIdentifier?.toLowerCase() === "sei") {
2034
- return validateSeiAddress(trimmed);
2035
- }
2036
- return validateBech32LikeAddress(trimmed, "sei");
2042
+ return validateCosmosAddress(trimmed, chainDef ?? chain);
2037
2043
  default:
2038
2044
  return { isValid: false, error: "Unsupported or unknown chain type." };
2039
2045
  }
2040
2046
  }
2041
- function validateAddressForRouteChain(address, chainType) {
2047
+ function validateAddressForRouteChain(address, chainType, chainRef) {
2042
2048
  switch (normalizeChainType(chainType)) {
2043
2049
  case "evm":
2044
2050
  return validateEvmAddress(address);
@@ -2047,7 +2053,7 @@ function validateAddressForRouteChain(address, chainType) {
2047
2053
  case "bitcoin":
2048
2054
  return validateBtcAddress(address);
2049
2055
  case "cosmos":
2050
- return validateSeiAddress(address);
2056
+ return validateCosmosAddress(address, chainRef ?? chainType);
2051
2057
  default:
2052
2058
  return { isValid: false, error: "Unsupported chain type." };
2053
2059
  }
@@ -2069,14 +2075,18 @@ function validateRouteAddresses(params) {
2069
2075
  const normalizedDirection = params.direction?.trim().toLowerCase();
2070
2076
  const isDepositFlow = normalizedDirection === "deposit" || (toType === "evm" || toType === "cosmos") && (fromType === "bitcoin" || fromType === "solana");
2071
2077
  if (isDepositFlow) {
2072
- const fromResult2 = validateAddressForRouteChain(fromAddress, fromType);
2078
+ const fromResult2 = validateAddressForRouteChain(
2079
+ fromAddress,
2080
+ fromType,
2081
+ params.fromChain
2082
+ );
2073
2083
  if (!fromResult2.isValid) {
2074
2084
  return {
2075
2085
  isValid: false,
2076
2086
  error: `From address: ${fromResult2.error ?? "Invalid address."}`
2077
2087
  };
2078
2088
  }
2079
- const toResult2 = toType === "cosmos" ? validateSeiAddress(toAddress) : validateEvmAddress(toAddress);
2089
+ const toResult2 = toType === "cosmos" ? validateCosmosAddress(toAddress, params.toChain) : validateEvmAddress(toAddress);
2080
2090
  if (!toResult2.isValid) {
2081
2091
  return {
2082
2092
  isValid: false,
@@ -2101,14 +2111,22 @@ function validateRouteAddresses(params) {
2101
2111
  }
2102
2112
  return { isValid: true };
2103
2113
  }
2104
- const fromResult = validateAddressForRouteChain(fromAddress, fromType);
2114
+ const fromResult = validateAddressForRouteChain(
2115
+ fromAddress,
2116
+ fromType,
2117
+ params.fromChain
2118
+ );
2105
2119
  if (!fromResult.isValid) {
2106
2120
  return {
2107
2121
  isValid: false,
2108
2122
  error: `From address: ${fromResult.error ?? "Invalid address."}`
2109
2123
  };
2110
2124
  }
2111
- const toResult = validateAddressForRouteChain(toAddress, toType);
2125
+ const toResult = validateAddressForRouteChain(
2126
+ toAddress,
2127
+ toType,
2128
+ params.toChain
2129
+ );
2112
2130
  if (!toResult.isValid) {
2113
2131
  return {
2114
2132
  isValid: false,
@@ -2117,13 +2135,19 @@ function validateRouteAddresses(params) {
2117
2135
  }
2118
2136
  return { isValid: true };
2119
2137
  }
2120
- var BECH32_CHARSET;
2138
+ var BECH32_CHARSET, COSMOS_BECH32_PREFIX_BY_CHAIN_ID;
2121
2139
  var init_address = __esm({
2122
2140
  "src/validation/address.ts"() {
2123
2141
  "use strict";
2124
2142
  init_index_node4();
2125
2143
  init_chains();
2126
2144
  BECH32_CHARSET = /^[023456789acdefghjklmnpqrstuvwxyz]+$/i;
2145
+ COSMOS_BECH32_PREFIX_BY_CHAIN_ID = {
2146
+ "pacific-1": "sei",
2147
+ sei: "sei",
2148
+ "cataclysm-1": "nibi",
2149
+ nibiru: "nibi"
2150
+ };
2127
2151
  }
2128
2152
  });
2129
2153
 
@@ -2515,7 +2539,7 @@ async function buildDepositAddress(body, signal) {
2515
2539
  route
2516
2540
  };
2517
2541
  }
2518
- async function submitReceipt(intentId, txHash, sponsorshipRequestId) {
2542
+ async function submitReceipt(intentId, txHash, sponsorshipRequestId, eoaAddress) {
2519
2543
  const r = await rateLimitedFetch(
2520
2544
  `${apiBase()}/v1/route-intent/${intentId}/receipt`,
2521
2545
  {
@@ -2523,7 +2547,8 @@ async function submitReceipt(intentId, txHash, sponsorshipRequestId) {
2523
2547
  headers: jsonHeaders({ "Idempotency-Key": txHash }),
2524
2548
  body: JSON.stringify({
2525
2549
  txHash,
2526
- ...sponsorshipRequestId ? { sponsorshipRequestId } : {}
2550
+ ...sponsorshipRequestId ? { sponsorshipRequestId } : {},
2551
+ ...eoaAddress ? { eoaAddress } : {}
2527
2552
  })
2528
2553
  }
2529
2554
  );
@@ -2833,6 +2858,7 @@ function useTrustwareConfig() {
2833
2858
  } catch {
2834
2859
  return {
2835
2860
  apiKey: "",
2861
+ mode: "deposit",
2836
2862
  routes: {
2837
2863
  toChain: "",
2838
2864
  toToken: "",
@@ -3095,7 +3121,9 @@ var init_chainHelpers = __esm({
3095
3121
  btc: "bitcoin",
3096
3122
  bitcoin: "bitcoin",
3097
3123
  sei: "cosmos",
3098
- "pacific-1": "cosmos"
3124
+ "pacific-1": "cosmos",
3125
+ nibiru: "cosmos",
3126
+ "cataclysm-1": "cosmos"
3099
3127
  };
3100
3128
  SEI_EVM_CHAIN_ID = "1329";
3101
3129
  SEI_COSMOS_CHAIN_ID = "pacific-1";
@@ -3311,7 +3339,8 @@ function filterSupportedChains(chains) {
3311
3339
  }
3312
3340
  if (chainType === "cosmos") {
3313
3341
  const seiKey = canonicalSeiChainKey(chain.chainId ?? chain.id);
3314
- if (seiKey !== "sei" && seiKey !== "pacific-1") {
3342
+ const isNibiru = normalizeChainKey2(chain.chainId ?? chain.id) === NIBIRU_COSMOS_CHAIN_ID;
3343
+ if (seiKey !== "sei" && !isNibiru) {
3315
3344
  return false;
3316
3345
  }
3317
3346
  }
@@ -3411,7 +3440,7 @@ function useChains() {
3411
3440
  error
3412
3441
  };
3413
3442
  }
3414
- var POPULAR_CHAINS_BY_TVL, POPULAR_LIMIT;
3443
+ var POPULAR_CHAINS_BY_TVL, POPULAR_LIMIT, NIBIRU_COSMOS_CHAIN_ID;
3415
3444
  var init_useChains = __esm({
3416
3445
  "src/core/useChains.ts"() {
3417
3446
  "use strict";
@@ -3421,6 +3450,7 @@ var init_useChains = __esm({
3421
3450
  init_popularChains();
3422
3451
  POPULAR_CHAINS_BY_TVL = popularChains_default.byTvl;
3423
3452
  POPULAR_LIMIT = popularChains_default.popularLimit;
3453
+ NIBIRU_COSMOS_CHAIN_ID = "cataclysm-1";
3424
3454
  }
3425
3455
  });
3426
3456
 
@@ -8755,46 +8785,80 @@ function normalizeSlippage(v) {
8755
8785
  if (n > 5) return 5;
8756
8786
  return n;
8757
8787
  }
8788
+ function warnDeprecatedSwapModeFlag() {
8789
+ if (hasWarnedDeprecatedSwapModeFlag) return;
8790
+ hasWarnedDeprecatedSwapModeFlag = true;
8791
+ console.warn(
8792
+ '[Trustware SDK] `features.swapMode` is deprecated \u2014 use `mode: "swap"` on the top-level config instead.'
8793
+ );
8794
+ }
8795
+ function resolveMode(input) {
8796
+ if (input.mode === "swap") return "swap";
8797
+ if (input.mode === "deposit") return "deposit";
8798
+ if (input.features?.swapMode) {
8799
+ warnDeprecatedSwapModeFlag();
8800
+ return "swap";
8801
+ }
8802
+ return "deposit";
8803
+ }
8758
8804
  function resolveConfig(input) {
8759
8805
  if (!input?.apiKey) {
8760
- throw new Error("TrustwareConfig: 'apiKey' is required.");
8806
+ throw new TrustwareError({
8807
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
8808
+ message: "TrustwareConfig: 'apiKey' is required.",
8809
+ userMessage: "Missing required API key configuration."
8810
+ });
8761
8811
  }
8762
- if (!input.routes?.toChain || !input.routes?.toToken) {
8763
- throw new Error(
8764
- "TrustwareConfig: 'routes.toChain' and 'routes.toToken' are required."
8765
- );
8812
+ const mode = resolveMode(input);
8813
+ if (mode === "deposit" && (!input.routes?.toChain || !input.routes?.toToken)) {
8814
+ throw new TrustwareError({
8815
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
8816
+ message: "TrustwareConfig: 'routes.toChain' and 'routes.toToken' are required in deposit mode.",
8817
+ userMessage: "Missing required destination chain/token configuration."
8818
+ });
8766
8819
  }
8767
- const toChain = input.routes.toChain;
8768
- if (input.routes.toAddress) {
8820
+ const toChain = input.routes?.toChain;
8821
+ if (input.routes?.toAddress && toChain) {
8769
8822
  const result = validateAddressForChain(input.routes.toAddress, toChain);
8770
8823
  if (!result.isValid) {
8771
8824
  console.error(`[Trustware SDK] Invalid toAddress: ${result.error}`);
8772
- throw new Error(`Invalid toAddress: ${result.error}`);
8825
+ throw new TrustwareError({
8826
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
8827
+ message: `Invalid toAddress: ${result.error}`,
8828
+ userMessage: "The configured destination address is invalid."
8829
+ });
8773
8830
  }
8774
8831
  }
8775
- if (input.routes.fromAddress) {
8776
- const result = validateAddressForChain(
8777
- input.routes.fromAddress,
8778
- input.routes.fromChain ?? toChain
8779
- );
8780
- if (!result.isValid) {
8781
- console.error(`[Trustware SDK] Invalid fromAddress: ${result.error}`);
8782
- throw new Error(`Invalid fromAddress: ${result.error}`);
8832
+ if (input.routes?.fromAddress) {
8833
+ const fromChain = input.routes.fromChain ?? toChain;
8834
+ if (fromChain) {
8835
+ const result = validateAddressForChain(
8836
+ input.routes.fromAddress,
8837
+ fromChain
8838
+ );
8839
+ if (!result.isValid) {
8840
+ console.error(`[Trustware SDK] Invalid fromAddress: ${result.error}`);
8841
+ throw new TrustwareError({
8842
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
8843
+ message: `Invalid fromAddress: ${result.error}`,
8844
+ userMessage: "The configured source address is invalid."
8845
+ });
8846
+ }
8783
8847
  }
8784
8848
  }
8785
8849
  const autoDetectProvider = typeof input.autoDetectProvider === "boolean" ? input.autoDetectProvider : DEFAULT_AUTO_DETECT_PROVIDER;
8786
8850
  const routes = {
8787
- toChain: input.routes.toChain,
8788
- toToken: input.routes.toToken,
8789
- fromToken: input.routes.fromToken,
8790
- fromAddress: input.routes.fromAddress,
8791
- fromChain: input.routes.fromChain,
8792
- toAddress: input.routes.toAddress,
8851
+ toChain: input.routes?.toChain ?? "",
8852
+ toToken: input.routes?.toToken ?? "",
8853
+ fromToken: input.routes?.fromToken,
8854
+ fromAddress: input.routes?.fromAddress,
8855
+ fromChain: input.routes?.fromChain,
8856
+ toAddress: input.routes?.toAddress,
8793
8857
  defaultSlippage: normalizeSlippage(
8794
- input.routes.defaultSlippage ?? DEFAULT_SLIPPAGE
8858
+ input.routes?.defaultSlippage ?? DEFAULT_SLIPPAGE
8795
8859
  ),
8796
8860
  options: {
8797
- ...input.routes.options
8861
+ ...input.routes?.options
8798
8862
  }
8799
8863
  };
8800
8864
  const theme = input.theme ?? "system";
@@ -8813,13 +8877,16 @@ function resolveConfig(input) {
8813
8877
  tokensPagination: input.features?.tokensPagination ?? DEFAULT_FEATURE_FLAGS.tokensPagination,
8814
8878
  balanceStreaming: input.features?.balanceStreaming ?? DEFAULT_FEATURE_FLAGS.balanceStreaming,
8815
8879
  shouldAllowGA4: input.features?.shouldAllowGA4 ?? DEFAULT_FEATURE_FLAGS.shouldAllowGA4,
8816
- swapMode: input.features?.swapMode ?? DEFAULT_FEATURE_FLAGS.swapMode,
8880
+ // Always mirrors the canonical `mode`, however the caller set it (new `mode` field
8881
+ // or the deprecated `features.swapMode` flag).
8882
+ swapMode: mode === "swap",
8817
8883
  swapDefaultDestToken: input.features?.swapDefaultDestToken ?? DEFAULT_FEATURE_FLAGS.swapDefaultDestToken,
8818
8884
  swapLockDestToken: input.features?.swapLockDestToken ?? DEFAULT_FEATURE_FLAGS.swapLockDestToken,
8819
8885
  swapAllowedDestTokens: input.features?.swapAllowedDestTokens ?? DEFAULT_FEATURE_FLAGS.swapAllowedDestTokens
8820
8886
  };
8821
8887
  return {
8822
8888
  apiKey: input.apiKey,
8889
+ mode,
8823
8890
  routes,
8824
8891
  autoDetectProvider,
8825
8892
  theme,
@@ -8832,12 +8899,15 @@ function resolveConfig(input) {
8832
8899
  onEvent: input.onEvent
8833
8900
  };
8834
8901
  }
8902
+ var hasWarnedDeprecatedSwapModeFlag;
8835
8903
  var init_merge = __esm({
8836
8904
  "src/config/merge.ts"() {
8837
8905
  "use strict";
8838
8906
  init_defaults();
8839
8907
  init_config();
8840
8908
  init_index();
8909
+ init_TrustwareError();
8910
+ hasWarnedDeprecatedSwapModeFlag = false;
8841
8911
  }
8842
8912
  });
8843
8913
 
@@ -31339,7 +31409,7 @@ async function sendRouteAsUserOperation(params) {
31339
31409
  );
31340
31410
  }
31341
31411
  console.debug("[send] UserOp included", { userOpHash, txHash });
31342
- await submitReceipt(intentId, txHash, getSponsorshipRequestId());
31412
+ await submitReceipt(intentId, txHash, getSponsorshipRequestId(), eoaAddress);
31343
31413
  return { userOpHash, txHash, intentId };
31344
31414
  }
31345
31415
  var NATIVE_ADDRS;
@@ -39628,7 +39698,7 @@ var init_TrustwareWidgetV2 = __esm({
39628
39698
  if (!isOpen) {
39629
39699
  return null;
39630
39700
  }
39631
- if (config.features.swapMode) {
39701
+ if (config.mode === "swap") {
39632
39702
  return /* @__PURE__ */ jsx60(SwapMode, { theme, style });
39633
39703
  }
39634
39704
  return /* @__PURE__ */ jsx60(DepositProvider, { initialStep: effectiveInitialStep, children: /* @__PURE__ */ jsx60(