@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/core.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- export { T as Trustware, a as TrustwareCore } from './core-BTPkApRH.cjs';
2
- import './manager-BZwbtOyf.cjs';
1
+ export { T as Trustware, a as TrustwareCore } from './core-gNyi5xsp.cjs';
2
+ import './manager-DWFNyouP.cjs';
3
3
  import './blockchain-BxAFzp0s.cjs';
4
4
  import './types-DX3HtFcn.cjs';
package/dist/core.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { T as Trustware, a as TrustwareCore } from './core-2oZuxC1J.js';
2
- import './manager-BMO1O-cW.js';
1
+ export { T as Trustware, a as TrustwareCore } from './core-DzqVEWwP.js';
2
+ import './manager-Dn4muk74.js';
3
3
  import './blockchain-BxAFzp0s.js';
4
4
  import './types-BJY9r-mz.js';
package/dist/core.mjs CHANGED
@@ -53,7 +53,7 @@ var init_constants = __esm({
53
53
  "src/constants.ts"() {
54
54
  "use strict";
55
55
  SDK_NAME = "@trustware/sdk";
56
- SDK_VERSION = "1.1.9-staging.6";
56
+ SDK_VERSION = "1.1.9-staging.7";
57
57
  API_ROOT = "https://bv-staging-api.trustware.io";
58
58
  API_PREFIX = "/api";
59
59
  WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
@@ -262,7 +262,9 @@ var init_chains = __esm({
262
262
  btc: "bitcoin",
263
263
  bitcoin: "bitcoin",
264
264
  sei: "cosmos",
265
- "pacific-1": "cosmos"
265
+ "pacific-1": "cosmos",
266
+ nibiru: "cosmos",
267
+ "cataclysm-1": "cosmos"
266
268
  };
267
269
  }
268
270
  });
@@ -1459,16 +1461,23 @@ function validateEvmAddress(address) {
1459
1461
  }
1460
1462
  return { isValid: true };
1461
1463
  }
1462
- function validateSeiAddress(address) {
1464
+ function resolveCosmosBech32Prefix(chain) {
1465
+ const chainDef = typeof chain === "object" && chain ? chain : void 0;
1466
+ const identifier = chainDef?.networkIdentifier ?? chainDef?.chainId ?? chainDef?.id ?? (typeof chain === "string" ? chain : void 0);
1467
+ const normalized = String(identifier ?? "").trim().toLowerCase();
1468
+ return COSMOS_BECH32_PREFIX_BY_CHAIN_ID[normalized] ?? "sei";
1469
+ }
1470
+ function validateCosmosAddress(address, chain) {
1463
1471
  const trimmed = address.trim();
1464
- if (isEvmAddress(trimmed)) {
1472
+ const prefix = resolveCosmosBech32Prefix(chain);
1473
+ if (prefix === "sei" && isEvmAddress(trimmed)) {
1465
1474
  return { isValid: true };
1466
1475
  }
1467
- const result = validateBech32LikeAddress(trimmed, "sei");
1476
+ const result = validateBech32LikeAddress(trimmed, prefix);
1468
1477
  if (result.isValid) return result;
1469
1478
  return {
1470
1479
  isValid: false,
1471
- error: "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings."
1480
+ error: prefix === "sei" ? "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings." : `Address must be a valid ${prefix}1 bech32 string.`
1472
1481
  };
1473
1482
  }
1474
1483
  function validateSolanaAddress(address) {
@@ -1518,15 +1527,12 @@ function validateAddressForChain(address, chain) {
1518
1527
  case "bitcoin":
1519
1528
  return validateBtcAddress(trimmed);
1520
1529
  case "cosmos":
1521
- if (chainDef?.networkIdentifier?.toLowerCase() === "sei") {
1522
- return validateSeiAddress(trimmed);
1523
- }
1524
- return validateBech32LikeAddress(trimmed, "sei");
1530
+ return validateCosmosAddress(trimmed, chainDef ?? chain);
1525
1531
  default:
1526
1532
  return { isValid: false, error: "Unsupported or unknown chain type." };
1527
1533
  }
1528
1534
  }
1529
- function validateAddressForRouteChain(address, chainType) {
1535
+ function validateAddressForRouteChain(address, chainType, chainRef) {
1530
1536
  switch (normalizeChainType(chainType)) {
1531
1537
  case "evm":
1532
1538
  return validateEvmAddress(address);
@@ -1535,7 +1541,7 @@ function validateAddressForRouteChain(address, chainType) {
1535
1541
  case "bitcoin":
1536
1542
  return validateBtcAddress(address);
1537
1543
  case "cosmos":
1538
- return validateSeiAddress(address);
1544
+ return validateCosmosAddress(address, chainRef ?? chainType);
1539
1545
  default:
1540
1546
  return { isValid: false, error: "Unsupported chain type." };
1541
1547
  }
@@ -1557,14 +1563,18 @@ function validateRouteAddresses(params) {
1557
1563
  const normalizedDirection = params.direction?.trim().toLowerCase();
1558
1564
  const isDepositFlow = normalizedDirection === "deposit" || (toType === "evm" || toType === "cosmos") && (fromType === "bitcoin" || fromType === "solana");
1559
1565
  if (isDepositFlow) {
1560
- const fromResult2 = validateAddressForRouteChain(fromAddress, fromType);
1566
+ const fromResult2 = validateAddressForRouteChain(
1567
+ fromAddress,
1568
+ fromType,
1569
+ params.fromChain
1570
+ );
1561
1571
  if (!fromResult2.isValid) {
1562
1572
  return {
1563
1573
  isValid: false,
1564
1574
  error: `From address: ${fromResult2.error ?? "Invalid address."}`
1565
1575
  };
1566
1576
  }
1567
- const toResult2 = toType === "cosmos" ? validateSeiAddress(toAddress) : validateEvmAddress(toAddress);
1577
+ const toResult2 = toType === "cosmos" ? validateCosmosAddress(toAddress, params.toChain) : validateEvmAddress(toAddress);
1568
1578
  if (!toResult2.isValid) {
1569
1579
  return {
1570
1580
  isValid: false,
@@ -1589,14 +1599,22 @@ function validateRouteAddresses(params) {
1589
1599
  }
1590
1600
  return { isValid: true };
1591
1601
  }
1592
- const fromResult = validateAddressForRouteChain(fromAddress, fromType);
1602
+ const fromResult = validateAddressForRouteChain(
1603
+ fromAddress,
1604
+ fromType,
1605
+ params.fromChain
1606
+ );
1593
1607
  if (!fromResult.isValid) {
1594
1608
  return {
1595
1609
  isValid: false,
1596
1610
  error: `From address: ${fromResult.error ?? "Invalid address."}`
1597
1611
  };
1598
1612
  }
1599
- const toResult = validateAddressForRouteChain(toAddress, toType);
1613
+ const toResult = validateAddressForRouteChain(
1614
+ toAddress,
1615
+ toType,
1616
+ params.toChain
1617
+ );
1600
1618
  if (!toResult.isValid) {
1601
1619
  return {
1602
1620
  isValid: false,
@@ -1605,13 +1623,19 @@ function validateRouteAddresses(params) {
1605
1623
  }
1606
1624
  return { isValid: true };
1607
1625
  }
1608
- var BECH32_CHARSET;
1626
+ var BECH32_CHARSET, COSMOS_BECH32_PREFIX_BY_CHAIN_ID;
1609
1627
  var init_address = __esm({
1610
1628
  "src/validation/address.ts"() {
1611
1629
  "use strict";
1612
1630
  init_index_node4();
1613
1631
  init_chains();
1614
1632
  BECH32_CHARSET = /^[023456789acdefghjklmnpqrstuvwxyz]+$/i;
1633
+ COSMOS_BECH32_PREFIX_BY_CHAIN_ID = {
1634
+ "pacific-1": "sei",
1635
+ sei: "sei",
1636
+ "cataclysm-1": "nibi",
1637
+ nibiru: "nibi"
1638
+ };
1615
1639
  }
1616
1640
  });
1617
1641
 
@@ -3979,7 +4003,7 @@ async function buildDepositAddress(body, signal) {
3979
4003
  route
3980
4004
  };
3981
4005
  }
3982
- async function submitReceipt(intentId, txHash, sponsorshipRequestId) {
4006
+ async function submitReceipt(intentId, txHash, sponsorshipRequestId, eoaAddress) {
3983
4007
  const r = await rateLimitedFetch(
3984
4008
  `${apiBase()}/v1/route-intent/${intentId}/receipt`,
3985
4009
  {
@@ -3987,7 +4011,8 @@ async function submitReceipt(intentId, txHash, sponsorshipRequestId) {
3987
4011
  headers: jsonHeaders({ "Idempotency-Key": txHash }),
3988
4012
  body: JSON.stringify({
3989
4013
  txHash,
3990
- ...sponsorshipRequestId ? { sponsorshipRequestId } : {}
4014
+ ...sponsorshipRequestId ? { sponsorshipRequestId } : {},
4015
+ ...eoaAddress ? { eoaAddress } : {}
3991
4016
  })
3992
4017
  }
3993
4018
  );
@@ -4109,7 +4134,9 @@ var init_chainHelpers = __esm({
4109
4134
  btc: "bitcoin",
4110
4135
  bitcoin: "bitcoin",
4111
4136
  sei: "cosmos",
4112
- "pacific-1": "cosmos"
4137
+ "pacific-1": "cosmos",
4138
+ nibiru: "cosmos",
4139
+ "cataclysm-1": "cosmos"
4113
4140
  };
4114
4141
  SEI_EVM_CHAIN_ID = "1329";
4115
4142
  SEI_COSMOS_CHAIN_ID = "pacific-1";
@@ -4264,7 +4291,8 @@ function filterSupportedChains(chains) {
4264
4291
  }
4265
4292
  if (chainType === "cosmos") {
4266
4293
  const seiKey = canonicalSeiChainKey(chain.chainId ?? chain.id);
4267
- if (seiKey !== "sei" && seiKey !== "pacific-1") {
4294
+ const isNibiru = normalizeChainKey2(chain.chainId ?? chain.id) === NIBIRU_COSMOS_CHAIN_ID;
4295
+ if (seiKey !== "sei" && !isNibiru) {
4268
4296
  return false;
4269
4297
  }
4270
4298
  }
@@ -4364,7 +4392,7 @@ function useChains() {
4364
4392
  error
4365
4393
  };
4366
4394
  }
4367
- var POPULAR_CHAINS_BY_TVL, POPULAR_LIMIT;
4395
+ var POPULAR_CHAINS_BY_TVL, POPULAR_LIMIT, NIBIRU_COSMOS_CHAIN_ID;
4368
4396
  var init_useChains = __esm({
4369
4397
  "src/core/useChains.ts"() {
4370
4398
  "use strict";
@@ -4374,6 +4402,7 @@ var init_useChains = __esm({
4374
4402
  init_popularChains();
4375
4403
  POPULAR_CHAINS_BY_TVL = popularChains_default.byTvl;
4376
4404
  POPULAR_LIMIT = popularChains_default.popularLimit;
4405
+ NIBIRU_COSMOS_CHAIN_ID = "cataclysm-1";
4377
4406
  }
4378
4407
  });
4379
4408
 
@@ -6158,46 +6187,80 @@ function normalizeSlippage(v) {
6158
6187
  if (n > 5) return 5;
6159
6188
  return n;
6160
6189
  }
6190
+ function warnDeprecatedSwapModeFlag() {
6191
+ if (hasWarnedDeprecatedSwapModeFlag) return;
6192
+ hasWarnedDeprecatedSwapModeFlag = true;
6193
+ console.warn(
6194
+ '[Trustware SDK] `features.swapMode` is deprecated \u2014 use `mode: "swap"` on the top-level config instead.'
6195
+ );
6196
+ }
6197
+ function resolveMode(input) {
6198
+ if (input.mode === "swap") return "swap";
6199
+ if (input.mode === "deposit") return "deposit";
6200
+ if (input.features?.swapMode) {
6201
+ warnDeprecatedSwapModeFlag();
6202
+ return "swap";
6203
+ }
6204
+ return "deposit";
6205
+ }
6161
6206
  function resolveConfig(input) {
6162
6207
  if (!input?.apiKey) {
6163
- throw new Error("TrustwareConfig: 'apiKey' is required.");
6208
+ throw new TrustwareError({
6209
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
6210
+ message: "TrustwareConfig: 'apiKey' is required.",
6211
+ userMessage: "Missing required API key configuration."
6212
+ });
6164
6213
  }
6165
- if (!input.routes?.toChain || !input.routes?.toToken) {
6166
- throw new Error(
6167
- "TrustwareConfig: 'routes.toChain' and 'routes.toToken' are required."
6168
- );
6214
+ const mode = resolveMode(input);
6215
+ if (mode === "deposit" && (!input.routes?.toChain || !input.routes?.toToken)) {
6216
+ throw new TrustwareError({
6217
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
6218
+ message: "TrustwareConfig: 'routes.toChain' and 'routes.toToken' are required in deposit mode.",
6219
+ userMessage: "Missing required destination chain/token configuration."
6220
+ });
6169
6221
  }
6170
- const toChain = input.routes.toChain;
6171
- if (input.routes.toAddress) {
6222
+ const toChain = input.routes?.toChain;
6223
+ if (input.routes?.toAddress && toChain) {
6172
6224
  const result = validateAddressForChain(input.routes.toAddress, toChain);
6173
6225
  if (!result.isValid) {
6174
6226
  console.error(`[Trustware SDK] Invalid toAddress: ${result.error}`);
6175
- throw new Error(`Invalid toAddress: ${result.error}`);
6227
+ throw new TrustwareError({
6228
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
6229
+ message: `Invalid toAddress: ${result.error}`,
6230
+ userMessage: "The configured destination address is invalid."
6231
+ });
6176
6232
  }
6177
6233
  }
6178
- if (input.routes.fromAddress) {
6179
- const result = validateAddressForChain(
6180
- input.routes.fromAddress,
6181
- input.routes.fromChain ?? toChain
6182
- );
6183
- if (!result.isValid) {
6184
- console.error(`[Trustware SDK] Invalid fromAddress: ${result.error}`);
6185
- throw new Error(`Invalid fromAddress: ${result.error}`);
6234
+ if (input.routes?.fromAddress) {
6235
+ const fromChain = input.routes.fromChain ?? toChain;
6236
+ if (fromChain) {
6237
+ const result = validateAddressForChain(
6238
+ input.routes.fromAddress,
6239
+ fromChain
6240
+ );
6241
+ if (!result.isValid) {
6242
+ console.error(`[Trustware SDK] Invalid fromAddress: ${result.error}`);
6243
+ throw new TrustwareError({
6244
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
6245
+ message: `Invalid fromAddress: ${result.error}`,
6246
+ userMessage: "The configured source address is invalid."
6247
+ });
6248
+ }
6186
6249
  }
6187
6250
  }
6188
6251
  const autoDetectProvider = typeof input.autoDetectProvider === "boolean" ? input.autoDetectProvider : DEFAULT_AUTO_DETECT_PROVIDER;
6189
6252
  const routes = {
6190
- toChain: input.routes.toChain,
6191
- toToken: input.routes.toToken,
6192
- fromToken: input.routes.fromToken,
6193
- fromAddress: input.routes.fromAddress,
6194
- fromChain: input.routes.fromChain,
6195
- toAddress: input.routes.toAddress,
6253
+ toChain: input.routes?.toChain ?? "",
6254
+ toToken: input.routes?.toToken ?? "",
6255
+ fromToken: input.routes?.fromToken,
6256
+ fromAddress: input.routes?.fromAddress,
6257
+ fromChain: input.routes?.fromChain,
6258
+ toAddress: input.routes?.toAddress,
6196
6259
  defaultSlippage: normalizeSlippage(
6197
- input.routes.defaultSlippage ?? DEFAULT_SLIPPAGE
6260
+ input.routes?.defaultSlippage ?? DEFAULT_SLIPPAGE
6198
6261
  ),
6199
6262
  options: {
6200
- ...input.routes.options
6263
+ ...input.routes?.options
6201
6264
  }
6202
6265
  };
6203
6266
  const theme = input.theme ?? "system";
@@ -6216,13 +6279,16 @@ function resolveConfig(input) {
6216
6279
  tokensPagination: input.features?.tokensPagination ?? DEFAULT_FEATURE_FLAGS.tokensPagination,
6217
6280
  balanceStreaming: input.features?.balanceStreaming ?? DEFAULT_FEATURE_FLAGS.balanceStreaming,
6218
6281
  shouldAllowGA4: input.features?.shouldAllowGA4 ?? DEFAULT_FEATURE_FLAGS.shouldAllowGA4,
6219
- swapMode: input.features?.swapMode ?? DEFAULT_FEATURE_FLAGS.swapMode,
6282
+ // Always mirrors the canonical `mode`, however the caller set it (new `mode` field
6283
+ // or the deprecated `features.swapMode` flag).
6284
+ swapMode: mode === "swap",
6220
6285
  swapDefaultDestToken: input.features?.swapDefaultDestToken ?? DEFAULT_FEATURE_FLAGS.swapDefaultDestToken,
6221
6286
  swapLockDestToken: input.features?.swapLockDestToken ?? DEFAULT_FEATURE_FLAGS.swapLockDestToken,
6222
6287
  swapAllowedDestTokens: input.features?.swapAllowedDestTokens ?? DEFAULT_FEATURE_FLAGS.swapAllowedDestTokens
6223
6288
  };
6224
6289
  return {
6225
6290
  apiKey: input.apiKey,
6291
+ mode,
6226
6292
  routes,
6227
6293
  autoDetectProvider,
6228
6294
  theme,
@@ -6235,12 +6301,15 @@ function resolveConfig(input) {
6235
6301
  onEvent: input.onEvent
6236
6302
  };
6237
6303
  }
6304
+ var hasWarnedDeprecatedSwapModeFlag;
6238
6305
  var init_merge = __esm({
6239
6306
  "src/config/merge.ts"() {
6240
6307
  "use strict";
6241
6308
  init_defaults();
6242
6309
  init_config();
6243
6310
  init_index();
6311
+ init_TrustwareError();
6312
+ hasWarnedDeprecatedSwapModeFlag = false;
6244
6313
  }
6245
6314
  });
6246
6315