@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/wallet.cjs CHANGED
@@ -250,7 +250,7 @@ var init_constants = __esm({
250
250
  "src/constants.ts"() {
251
251
  "use strict";
252
252
  SDK_NAME = "@trustware/sdk";
253
- SDK_VERSION = "1.1.9-staging.6";
253
+ SDK_VERSION = "1.1.9-staging.7";
254
254
  API_ROOT = "https://bv-staging-api.trustware.io";
255
255
  API_PREFIX = "/api";
256
256
  WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
@@ -1214,7 +1214,9 @@ var init_chains = __esm({
1214
1214
  btc: "bitcoin",
1215
1215
  bitcoin: "bitcoin",
1216
1216
  sei: "cosmos",
1217
- "pacific-1": "cosmos"
1217
+ "pacific-1": "cosmos",
1218
+ nibiru: "cosmos",
1219
+ "cataclysm-1": "cosmos"
1218
1220
  };
1219
1221
  }
1220
1222
  });
@@ -1257,16 +1259,23 @@ function validateEvmAddress(address) {
1257
1259
  }
1258
1260
  return { isValid: true };
1259
1261
  }
1260
- function validateSeiAddress(address) {
1262
+ function resolveCosmosBech32Prefix(chain) {
1263
+ const chainDef = typeof chain === "object" && chain ? chain : void 0;
1264
+ const identifier = chainDef?.networkIdentifier ?? chainDef?.chainId ?? chainDef?.id ?? (typeof chain === "string" ? chain : void 0);
1265
+ const normalized = String(identifier ?? "").trim().toLowerCase();
1266
+ return COSMOS_BECH32_PREFIX_BY_CHAIN_ID[normalized] ?? "sei";
1267
+ }
1268
+ function validateCosmosAddress(address, chain) {
1261
1269
  const trimmed = address.trim();
1262
- if ((0, import_viem.isAddress)(trimmed)) {
1270
+ const prefix = resolveCosmosBech32Prefix(chain);
1271
+ if (prefix === "sei" && (0, import_viem.isAddress)(trimmed)) {
1263
1272
  return { isValid: true };
1264
1273
  }
1265
- const result = validateBech32LikeAddress(trimmed, "sei");
1274
+ const result = validateBech32LikeAddress(trimmed, prefix);
1266
1275
  if (result.isValid) return result;
1267
1276
  return {
1268
1277
  isValid: false,
1269
- error: "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings."
1278
+ error: prefix === "sei" ? "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings." : `Address must be a valid ${prefix}1 bech32 string.`
1270
1279
  };
1271
1280
  }
1272
1281
  function validateSolanaAddress(address) {
@@ -1316,15 +1325,12 @@ function validateAddressForChain(address, chain) {
1316
1325
  case "bitcoin":
1317
1326
  return validateBtcAddress(trimmed);
1318
1327
  case "cosmos":
1319
- if (chainDef?.networkIdentifier?.toLowerCase() === "sei") {
1320
- return validateSeiAddress(trimmed);
1321
- }
1322
- return validateBech32LikeAddress(trimmed, "sei");
1328
+ return validateCosmosAddress(trimmed, chainDef ?? chain);
1323
1329
  default:
1324
1330
  return { isValid: false, error: "Unsupported or unknown chain type." };
1325
1331
  }
1326
1332
  }
1327
- var import_viem, BECH32_CHARSET;
1333
+ var import_viem, BECH32_CHARSET, COSMOS_BECH32_PREFIX_BY_CHAIN_ID;
1328
1334
  var init_address = __esm({
1329
1335
  "src/validation/address.ts"() {
1330
1336
  "use strict";
@@ -1332,6 +1338,37 @@ var init_address = __esm({
1332
1338
  init_index_node4();
1333
1339
  init_chains();
1334
1340
  BECH32_CHARSET = /^[023456789acdefghjklmnpqrstuvwxyz]+$/i;
1341
+ COSMOS_BECH32_PREFIX_BY_CHAIN_ID = {
1342
+ "pacific-1": "sei",
1343
+ sei: "sei",
1344
+ "cataclysm-1": "nibi",
1345
+ nibiru: "nibi"
1346
+ };
1347
+ }
1348
+ });
1349
+
1350
+ // src/errors/TrustwareError.ts
1351
+ var TrustwareError;
1352
+ var init_TrustwareError = __esm({
1353
+ "src/errors/TrustwareError.ts"() {
1354
+ "use strict";
1355
+ TrustwareError = class extends Error {
1356
+ constructor(params) {
1357
+ super(params.message);
1358
+ this.name = "TrustwareError";
1359
+ this.code = params.code;
1360
+ this.userMessage = params.userMessage;
1361
+ this.cause = params.cause;
1362
+ }
1363
+ toJSON() {
1364
+ return {
1365
+ name: this.name,
1366
+ code: this.code,
1367
+ message: this.message,
1368
+ userMessage: this.userMessage
1369
+ };
1370
+ }
1371
+ };
1335
1372
  }
1336
1373
  });
1337
1374
 
@@ -3619,46 +3656,80 @@ function normalizeSlippage(v) {
3619
3656
  if (n > 5) return 5;
3620
3657
  return n;
3621
3658
  }
3659
+ function warnDeprecatedSwapModeFlag() {
3660
+ if (hasWarnedDeprecatedSwapModeFlag) return;
3661
+ hasWarnedDeprecatedSwapModeFlag = true;
3662
+ console.warn(
3663
+ '[Trustware SDK] `features.swapMode` is deprecated \u2014 use `mode: "swap"` on the top-level config instead.'
3664
+ );
3665
+ }
3666
+ function resolveMode(input) {
3667
+ if (input.mode === "swap") return "swap";
3668
+ if (input.mode === "deposit") return "deposit";
3669
+ if (input.features?.swapMode) {
3670
+ warnDeprecatedSwapModeFlag();
3671
+ return "swap";
3672
+ }
3673
+ return "deposit";
3674
+ }
3622
3675
  function resolveConfig(input) {
3623
3676
  if (!input?.apiKey) {
3624
- throw new Error("TrustwareConfig: 'apiKey' is required.");
3677
+ throw new TrustwareError({
3678
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
3679
+ message: "TrustwareConfig: 'apiKey' is required.",
3680
+ userMessage: "Missing required API key configuration."
3681
+ });
3625
3682
  }
3626
- if (!input.routes?.toChain || !input.routes?.toToken) {
3627
- throw new Error(
3628
- "TrustwareConfig: 'routes.toChain' and 'routes.toToken' are required."
3629
- );
3683
+ const mode = resolveMode(input);
3684
+ if (mode === "deposit" && (!input.routes?.toChain || !input.routes?.toToken)) {
3685
+ throw new TrustwareError({
3686
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
3687
+ message: "TrustwareConfig: 'routes.toChain' and 'routes.toToken' are required in deposit mode.",
3688
+ userMessage: "Missing required destination chain/token configuration."
3689
+ });
3630
3690
  }
3631
- const toChain = input.routes.toChain;
3632
- if (input.routes.toAddress) {
3691
+ const toChain = input.routes?.toChain;
3692
+ if (input.routes?.toAddress && toChain) {
3633
3693
  const result = validateAddressForChain(input.routes.toAddress, toChain);
3634
3694
  if (!result.isValid) {
3635
3695
  console.error(`[Trustware SDK] Invalid toAddress: ${result.error}`);
3636
- throw new Error(`Invalid toAddress: ${result.error}`);
3696
+ throw new TrustwareError({
3697
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
3698
+ message: `Invalid toAddress: ${result.error}`,
3699
+ userMessage: "The configured destination address is invalid."
3700
+ });
3637
3701
  }
3638
3702
  }
3639
- if (input.routes.fromAddress) {
3640
- const result = validateAddressForChain(
3641
- input.routes.fromAddress,
3642
- input.routes.fromChain ?? toChain
3643
- );
3644
- if (!result.isValid) {
3645
- console.error(`[Trustware SDK] Invalid fromAddress: ${result.error}`);
3646
- throw new Error(`Invalid fromAddress: ${result.error}`);
3703
+ if (input.routes?.fromAddress) {
3704
+ const fromChain = input.routes.fromChain ?? toChain;
3705
+ if (fromChain) {
3706
+ const result = validateAddressForChain(
3707
+ input.routes.fromAddress,
3708
+ fromChain
3709
+ );
3710
+ if (!result.isValid) {
3711
+ console.error(`[Trustware SDK] Invalid fromAddress: ${result.error}`);
3712
+ throw new TrustwareError({
3713
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
3714
+ message: `Invalid fromAddress: ${result.error}`,
3715
+ userMessage: "The configured source address is invalid."
3716
+ });
3717
+ }
3647
3718
  }
3648
3719
  }
3649
3720
  const autoDetectProvider = typeof input.autoDetectProvider === "boolean" ? input.autoDetectProvider : DEFAULT_AUTO_DETECT_PROVIDER;
3650
3721
  const routes = {
3651
- toChain: input.routes.toChain,
3652
- toToken: input.routes.toToken,
3653
- fromToken: input.routes.fromToken,
3654
- fromAddress: input.routes.fromAddress,
3655
- fromChain: input.routes.fromChain,
3656
- toAddress: input.routes.toAddress,
3722
+ toChain: input.routes?.toChain ?? "",
3723
+ toToken: input.routes?.toToken ?? "",
3724
+ fromToken: input.routes?.fromToken,
3725
+ fromAddress: input.routes?.fromAddress,
3726
+ fromChain: input.routes?.fromChain,
3727
+ toAddress: input.routes?.toAddress,
3657
3728
  defaultSlippage: normalizeSlippage(
3658
- input.routes.defaultSlippage ?? DEFAULT_SLIPPAGE
3729
+ input.routes?.defaultSlippage ?? DEFAULT_SLIPPAGE
3659
3730
  ),
3660
3731
  options: {
3661
- ...input.routes.options
3732
+ ...input.routes?.options
3662
3733
  }
3663
3734
  };
3664
3735
  const theme = input.theme ?? "system";
@@ -3677,13 +3748,16 @@ function resolveConfig(input) {
3677
3748
  tokensPagination: input.features?.tokensPagination ?? DEFAULT_FEATURE_FLAGS.tokensPagination,
3678
3749
  balanceStreaming: input.features?.balanceStreaming ?? DEFAULT_FEATURE_FLAGS.balanceStreaming,
3679
3750
  shouldAllowGA4: input.features?.shouldAllowGA4 ?? DEFAULT_FEATURE_FLAGS.shouldAllowGA4,
3680
- swapMode: input.features?.swapMode ?? DEFAULT_FEATURE_FLAGS.swapMode,
3751
+ // Always mirrors the canonical `mode`, however the caller set it (new `mode` field
3752
+ // or the deprecated `features.swapMode` flag).
3753
+ swapMode: mode === "swap",
3681
3754
  swapDefaultDestToken: input.features?.swapDefaultDestToken ?? DEFAULT_FEATURE_FLAGS.swapDefaultDestToken,
3682
3755
  swapLockDestToken: input.features?.swapLockDestToken ?? DEFAULT_FEATURE_FLAGS.swapLockDestToken,
3683
3756
  swapAllowedDestTokens: input.features?.swapAllowedDestTokens ?? DEFAULT_FEATURE_FLAGS.swapAllowedDestTokens
3684
3757
  };
3685
3758
  return {
3686
3759
  apiKey: input.apiKey,
3760
+ mode,
3687
3761
  routes,
3688
3762
  autoDetectProvider,
3689
3763
  theme,
@@ -3696,12 +3770,15 @@ function resolveConfig(input) {
3696
3770
  onEvent: input.onEvent
3697
3771
  };
3698
3772
  }
3773
+ var hasWarnedDeprecatedSwapModeFlag;
3699
3774
  var init_merge = __esm({
3700
3775
  "src/config/merge.ts"() {
3701
3776
  "use strict";
3702
3777
  init_defaults();
3703
3778
  init_config();
3704
3779
  init_index();
3780
+ init_TrustwareError();
3781
+ hasWarnedDeprecatedSwapModeFlag = false;
3705
3782
  }
3706
3783
  });
3707
3784