@trustware/sdk-staging 1.1.9-staging.6 → 1.1.10-staging.0

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.
Files changed (40) hide show
  1. package/LICENSE +5 -4
  2. package/README.md +32 -1
  3. package/THIRD_PARTY_NOTICES.md +118 -0
  4. package/dist/constants.cjs +1 -1
  5. package/dist/constants.mjs +1 -1
  6. package/dist/{core-BTPkApRH.d.cts → core-B7Ez-5-r.d.cts} +3 -2
  7. package/dist/{core-2oZuxC1J.d.ts → core-BPLiD1UG.d.ts} +3 -2
  8. package/dist/core.cjs +246 -48
  9. package/dist/core.cjs.map +1 -1
  10. package/dist/core.d.cts +2 -2
  11. package/dist/core.d.ts +2 -2
  12. package/dist/core.mjs +247 -48
  13. package/dist/core.mjs.map +1 -1
  14. package/dist/index.cjs +300 -76
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.d.cts +5 -5
  17. package/dist/index.d.ts +5 -5
  18. package/dist/index.mjs +325 -103
  19. package/dist/index.mjs.map +1 -1
  20. package/dist/{manager-BMO1O-cW.d.ts → manager-B6NNV-E_.d.ts} +129 -18
  21. package/dist/{manager-BZwbtOyf.d.cts → manager-BwjyFjjz.d.cts} +129 -18
  22. package/dist/{detect-B8xXLwHK.d.ts → metadata-BiTMMvlY.d.ts} +5 -2
  23. package/dist/{detect-C8xpZRrL.d.cts → metadata-HCflXcsF.d.cts} +5 -2
  24. package/dist/smart-account.cjs +117 -39
  25. package/dist/smart-account.cjs.map +1 -1
  26. package/dist/smart-account.d.cts +235 -222
  27. package/dist/smart-account.d.ts +235 -222
  28. package/dist/smart-account.mjs +117 -39
  29. package/dist/smart-account.mjs.map +1 -1
  30. package/dist/wallet.cjs +113 -36
  31. package/dist/wallet.cjs.map +1 -1
  32. package/dist/wallet.d.cts +4 -7
  33. package/dist/wallet.d.ts +4 -7
  34. package/dist/wallet.mjs +113 -36
  35. package/dist/wallet.mjs.map +1 -1
  36. package/dist/widget.cjs +239 -54
  37. package/dist/widget.cjs.map +1 -1
  38. package/dist/widget.mjs +267 -81
  39. package/dist/widget.mjs.map +1 -1
  40. package/package.json +3 -2
package/dist/wallet.d.cts CHANGED
@@ -1,6 +1,6 @@
1
- import { u as SolanaProviderLike, Q as WalletMeta, h as DetectedWallet, M as WalletId, v as SolanaWalletInterface } from './manager-BZwbtOyf.cjs';
2
- export { A as WagmiBridge, C as WagmiConnector, a1 as WalletSnapshot, a2 as useWalletConnectConnect, Z as useWalletExternalDisconnect, _ as useWalletInfo, $ as useWireDetectionIntoManager, a0 as walletManager } from './manager-BZwbtOyf.cjs';
3
- export { d as autoDetectWallet, e as buildDetectedWalletFromProvider, c as connectDetectedWallet, f as createWalletConnectEntry, t as toWalletInterfaceFromDetected, u as useEIP1193, g as useIsMobile, a as useWagmi, b as useWalletDetection } from './detect-C8xpZRrL.cjs';
1
+ import { S as SolanaProviderLike, W as WalletMeta, D as DetectedWallet, a as WalletId, b as SolanaWalletInterface } from './manager-BwjyFjjz.cjs';
2
+ export { c as WagmiBridge, d as WagmiConnector, e as WalletSnapshot, u as useWalletConnectConnect, f as useWalletExternalDisconnect, g as useWalletInfo, h as useWireDetectionIntoManager, w as walletManager } from './manager-BwjyFjjz.cjs';
3
+ export { P as POPULAR_ORDER, W as WALLETS, a as autoDetectWallet, b as buildDetectedWalletFromProvider, c as connectDetectedWallet, d as createWalletConnectEntry, t as toWalletInterfaceFromDetected, u as useEIP1193, e as useIsMobile, f as useWagmi, g as useWalletDetection } from './metadata-HCflXcsF.cjs';
4
4
  import './blockchain-BxAFzp0s.cjs';
5
5
 
6
6
  type SolanaEventHandlers = {
@@ -15,9 +15,6 @@ declare function detectSolanaWallets(wallets: WalletMeta[]): DetectedWallet[];
15
15
  declare function bindSolanaProviderEvents(provider: SolanaProviderLike, handlers: SolanaEventHandlers): () => void;
16
16
  declare function toSolanaWalletInterface(provider: SolanaProviderLike): SolanaWalletInterface;
17
17
 
18
- declare const POPULAR_ORDER: WalletId[];
19
- declare const WALLETS: WalletMeta[];
20
-
21
18
  declare function formatDeepLink(id: string, currentUrl: string): string | undefined;
22
19
  /**
23
20
  * Format a WalletConnect URI for mobile deep linking.
@@ -37,4 +34,4 @@ declare function formatWalletConnectDeepLink(wcUri: string): string;
37
34
  */
38
35
  declare function formatWalletConnectDeepLinkForWallet(walletId: string, wcUri: string): string;
39
36
 
40
- export { POPULAR_ORDER, WALLETS, bindSolanaProviderEvents, decodeBase64, detectSolanaWallets, encodeBase64, formatDeepLink, formatWalletConnectDeepLink, formatWalletConnectDeepLinkForWallet, getSolanaProviders, toSolanaWalletInterface };
37
+ export { bindSolanaProviderEvents, decodeBase64, detectSolanaWallets, encodeBase64, formatDeepLink, formatWalletConnectDeepLink, formatWalletConnectDeepLinkForWallet, getSolanaProviders, toSolanaWalletInterface };
package/dist/wallet.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { u as SolanaProviderLike, Q as WalletMeta, h as DetectedWallet, M as WalletId, v as SolanaWalletInterface } from './manager-BMO1O-cW.js';
2
- export { A as WagmiBridge, C as WagmiConnector, a1 as WalletSnapshot, a2 as useWalletConnectConnect, Z as useWalletExternalDisconnect, _ as useWalletInfo, $ as useWireDetectionIntoManager, a0 as walletManager } from './manager-BMO1O-cW.js';
3
- export { d as autoDetectWallet, e as buildDetectedWalletFromProvider, c as connectDetectedWallet, f as createWalletConnectEntry, t as toWalletInterfaceFromDetected, u as useEIP1193, g as useIsMobile, a as useWagmi, b as useWalletDetection } from './detect-B8xXLwHK.js';
1
+ import { S as SolanaProviderLike, W as WalletMeta, D as DetectedWallet, a as WalletId, b as SolanaWalletInterface } from './manager-B6NNV-E_.js';
2
+ export { c as WagmiBridge, d as WagmiConnector, e as WalletSnapshot, u as useWalletConnectConnect, f as useWalletExternalDisconnect, g as useWalletInfo, h as useWireDetectionIntoManager, w as walletManager } from './manager-B6NNV-E_.js';
3
+ export { P as POPULAR_ORDER, W as WALLETS, a as autoDetectWallet, b as buildDetectedWalletFromProvider, c as connectDetectedWallet, d as createWalletConnectEntry, t as toWalletInterfaceFromDetected, u as useEIP1193, e as useIsMobile, f as useWagmi, g as useWalletDetection } from './metadata-BiTMMvlY.js';
4
4
  import './blockchain-BxAFzp0s.js';
5
5
 
6
6
  type SolanaEventHandlers = {
@@ -15,9 +15,6 @@ declare function detectSolanaWallets(wallets: WalletMeta[]): DetectedWallet[];
15
15
  declare function bindSolanaProviderEvents(provider: SolanaProviderLike, handlers: SolanaEventHandlers): () => void;
16
16
  declare function toSolanaWalletInterface(provider: SolanaProviderLike): SolanaWalletInterface;
17
17
 
18
- declare const POPULAR_ORDER: WalletId[];
19
- declare const WALLETS: WalletMeta[];
20
-
21
18
  declare function formatDeepLink(id: string, currentUrl: string): string | undefined;
22
19
  /**
23
20
  * Format a WalletConnect URI for mobile deep linking.
@@ -37,4 +34,4 @@ declare function formatWalletConnectDeepLink(wcUri: string): string;
37
34
  */
38
35
  declare function formatWalletConnectDeepLinkForWallet(walletId: string, wcUri: string): string;
39
36
 
40
- export { POPULAR_ORDER, WALLETS, bindSolanaProviderEvents, decodeBase64, detectSolanaWallets, encodeBase64, formatDeepLink, formatWalletConnectDeepLink, formatWalletConnectDeepLinkForWallet, getSolanaProviders, toSolanaWalletInterface };
37
+ export { bindSolanaProviderEvents, decodeBase64, detectSolanaWallets, encodeBase64, formatDeepLink, formatWalletConnectDeepLink, formatWalletConnectDeepLinkForWallet, getSolanaProviders, toSolanaWalletInterface };
package/dist/wallet.mjs CHANGED
@@ -224,7 +224,7 @@ var init_constants = __esm({
224
224
  "src/constants.ts"() {
225
225
  "use strict";
226
226
  SDK_NAME = "@trustware/sdk";
227
- SDK_VERSION = "1.1.9-staging.6";
227
+ SDK_VERSION = "1.1.10-staging.0";
228
228
  API_ROOT = "https://bv-staging-api.trustware.io";
229
229
  API_PREFIX = "/api";
230
230
  WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
@@ -1188,7 +1188,9 @@ var init_chains = __esm({
1188
1188
  btc: "bitcoin",
1189
1189
  bitcoin: "bitcoin",
1190
1190
  sei: "cosmos",
1191
- "pacific-1": "cosmos"
1191
+ "pacific-1": "cosmos",
1192
+ nibiru: "cosmos",
1193
+ "cataclysm-1": "cosmos"
1192
1194
  };
1193
1195
  }
1194
1196
  });
@@ -1232,16 +1234,23 @@ function validateEvmAddress(address) {
1232
1234
  }
1233
1235
  return { isValid: true };
1234
1236
  }
1235
- function validateSeiAddress(address) {
1237
+ function resolveCosmosBech32Prefix(chain) {
1238
+ const chainDef = typeof chain === "object" && chain ? chain : void 0;
1239
+ const identifier = chainDef?.networkIdentifier ?? chainDef?.chainId ?? chainDef?.id ?? (typeof chain === "string" ? chain : void 0);
1240
+ const normalized = String(identifier ?? "").trim().toLowerCase();
1241
+ return COSMOS_BECH32_PREFIX_BY_CHAIN_ID[normalized] ?? "sei";
1242
+ }
1243
+ function validateCosmosAddress(address, chain) {
1236
1244
  const trimmed = address.trim();
1237
- if (isEvmAddress(trimmed)) {
1245
+ const prefix = resolveCosmosBech32Prefix(chain);
1246
+ if (prefix === "sei" && isEvmAddress(trimmed)) {
1238
1247
  return { isValid: true };
1239
1248
  }
1240
- const result = validateBech32LikeAddress(trimmed, "sei");
1249
+ const result = validateBech32LikeAddress(trimmed, prefix);
1241
1250
  if (result.isValid) return result;
1242
1251
  return {
1243
1252
  isValid: false,
1244
- error: "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings."
1253
+ error: prefix === "sei" ? "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings." : `Address must be a valid ${prefix}1 bech32 string.`
1245
1254
  };
1246
1255
  }
1247
1256
  function validateSolanaAddress(address) {
@@ -1291,21 +1300,49 @@ function validateAddressForChain(address, chain) {
1291
1300
  case "bitcoin":
1292
1301
  return validateBtcAddress(trimmed);
1293
1302
  case "cosmos":
1294
- if (chainDef?.networkIdentifier?.toLowerCase() === "sei") {
1295
- return validateSeiAddress(trimmed);
1296
- }
1297
- return validateBech32LikeAddress(trimmed, "sei");
1303
+ return validateCosmosAddress(trimmed, chainDef ?? chain);
1298
1304
  default:
1299
1305
  return { isValid: false, error: "Unsupported or unknown chain type." };
1300
1306
  }
1301
1307
  }
1302
- var BECH32_CHARSET;
1308
+ var BECH32_CHARSET, COSMOS_BECH32_PREFIX_BY_CHAIN_ID;
1303
1309
  var init_address = __esm({
1304
1310
  "src/validation/address.ts"() {
1305
1311
  "use strict";
1306
1312
  init_index_node4();
1307
1313
  init_chains();
1308
1314
  BECH32_CHARSET = /^[023456789acdefghjklmnpqrstuvwxyz]+$/i;
1315
+ COSMOS_BECH32_PREFIX_BY_CHAIN_ID = {
1316
+ "pacific-1": "sei",
1317
+ sei: "sei",
1318
+ "cataclysm-1": "nibi",
1319
+ nibiru: "nibi"
1320
+ };
1321
+ }
1322
+ });
1323
+
1324
+ // src/errors/TrustwareError.ts
1325
+ var TrustwareError;
1326
+ var init_TrustwareError = __esm({
1327
+ "src/errors/TrustwareError.ts"() {
1328
+ "use strict";
1329
+ TrustwareError = class extends Error {
1330
+ constructor(params) {
1331
+ super(params.message);
1332
+ this.name = "TrustwareError";
1333
+ this.code = params.code;
1334
+ this.userMessage = params.userMessage;
1335
+ this.cause = params.cause;
1336
+ }
1337
+ toJSON() {
1338
+ return {
1339
+ name: this.name,
1340
+ code: this.code,
1341
+ message: this.message,
1342
+ userMessage: this.userMessage
1343
+ };
1344
+ }
1345
+ };
1309
1346
  }
1310
1347
  });
1311
1348
 
@@ -3593,46 +3630,80 @@ function normalizeSlippage(v) {
3593
3630
  if (n > 5) return 5;
3594
3631
  return n;
3595
3632
  }
3633
+ function warnDeprecatedSwapModeFlag() {
3634
+ if (hasWarnedDeprecatedSwapModeFlag) return;
3635
+ hasWarnedDeprecatedSwapModeFlag = true;
3636
+ console.warn(
3637
+ '[Trustware SDK] `features.swapMode` is deprecated \u2014 use `mode: "swap"` on the top-level config instead.'
3638
+ );
3639
+ }
3640
+ function resolveMode(input) {
3641
+ if (input.mode === "swap") return "swap";
3642
+ if (input.mode === "deposit") return "deposit";
3643
+ if (input.features?.swapMode) {
3644
+ warnDeprecatedSwapModeFlag();
3645
+ return "swap";
3646
+ }
3647
+ return "deposit";
3648
+ }
3596
3649
  function resolveConfig(input) {
3597
3650
  if (!input?.apiKey) {
3598
- throw new Error("TrustwareConfig: 'apiKey' is required.");
3651
+ throw new TrustwareError({
3652
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
3653
+ message: "TrustwareConfig: 'apiKey' is required.",
3654
+ userMessage: "Missing required API key configuration."
3655
+ });
3599
3656
  }
3600
- if (!input.routes?.toChain || !input.routes?.toToken) {
3601
- throw new Error(
3602
- "TrustwareConfig: 'routes.toChain' and 'routes.toToken' are required."
3603
- );
3657
+ const mode = resolveMode(input);
3658
+ if (mode === "deposit" && (!input.routes?.toChain || !input.routes?.toToken)) {
3659
+ throw new TrustwareError({
3660
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
3661
+ message: "TrustwareConfig: 'routes.toChain' and 'routes.toToken' are required in deposit mode.",
3662
+ userMessage: "Missing required destination chain/token configuration."
3663
+ });
3604
3664
  }
3605
- const toChain = input.routes.toChain;
3606
- if (input.routes.toAddress) {
3665
+ const toChain = input.routes?.toChain;
3666
+ if (input.routes?.toAddress && toChain) {
3607
3667
  const result = validateAddressForChain(input.routes.toAddress, toChain);
3608
3668
  if (!result.isValid) {
3609
3669
  console.error(`[Trustware SDK] Invalid toAddress: ${result.error}`);
3610
- throw new Error(`Invalid toAddress: ${result.error}`);
3670
+ throw new TrustwareError({
3671
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
3672
+ message: `Invalid toAddress: ${result.error}`,
3673
+ userMessage: "The configured destination address is invalid."
3674
+ });
3611
3675
  }
3612
3676
  }
3613
- if (input.routes.fromAddress) {
3614
- const result = validateAddressForChain(
3615
- input.routes.fromAddress,
3616
- input.routes.fromChain ?? toChain
3617
- );
3618
- if (!result.isValid) {
3619
- console.error(`[Trustware SDK] Invalid fromAddress: ${result.error}`);
3620
- throw new Error(`Invalid fromAddress: ${result.error}`);
3677
+ if (input.routes?.fromAddress) {
3678
+ const fromChain = input.routes.fromChain ?? toChain;
3679
+ if (fromChain) {
3680
+ const result = validateAddressForChain(
3681
+ input.routes.fromAddress,
3682
+ fromChain
3683
+ );
3684
+ if (!result.isValid) {
3685
+ console.error(`[Trustware SDK] Invalid fromAddress: ${result.error}`);
3686
+ throw new TrustwareError({
3687
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
3688
+ message: `Invalid fromAddress: ${result.error}`,
3689
+ userMessage: "The configured source address is invalid."
3690
+ });
3691
+ }
3621
3692
  }
3622
3693
  }
3623
3694
  const autoDetectProvider = typeof input.autoDetectProvider === "boolean" ? input.autoDetectProvider : DEFAULT_AUTO_DETECT_PROVIDER;
3624
3695
  const routes = {
3625
- toChain: input.routes.toChain,
3626
- toToken: input.routes.toToken,
3627
- fromToken: input.routes.fromToken,
3628
- fromAddress: input.routes.fromAddress,
3629
- fromChain: input.routes.fromChain,
3630
- toAddress: input.routes.toAddress,
3696
+ toChain: input.routes?.toChain ?? "",
3697
+ toToken: input.routes?.toToken ?? "",
3698
+ fromToken: input.routes?.fromToken,
3699
+ fromAddress: input.routes?.fromAddress,
3700
+ fromChain: input.routes?.fromChain,
3701
+ toAddress: input.routes?.toAddress,
3631
3702
  defaultSlippage: normalizeSlippage(
3632
- input.routes.defaultSlippage ?? DEFAULT_SLIPPAGE
3703
+ input.routes?.defaultSlippage ?? DEFAULT_SLIPPAGE
3633
3704
  ),
3634
3705
  options: {
3635
- ...input.routes.options
3706
+ ...input.routes?.options
3636
3707
  }
3637
3708
  };
3638
3709
  const theme = input.theme ?? "system";
@@ -3651,13 +3722,16 @@ function resolveConfig(input) {
3651
3722
  tokensPagination: input.features?.tokensPagination ?? DEFAULT_FEATURE_FLAGS.tokensPagination,
3652
3723
  balanceStreaming: input.features?.balanceStreaming ?? DEFAULT_FEATURE_FLAGS.balanceStreaming,
3653
3724
  shouldAllowGA4: input.features?.shouldAllowGA4 ?? DEFAULT_FEATURE_FLAGS.shouldAllowGA4,
3654
- swapMode: input.features?.swapMode ?? DEFAULT_FEATURE_FLAGS.swapMode,
3725
+ // Always mirrors the canonical `mode`, however the caller set it (new `mode` field
3726
+ // or the deprecated `features.swapMode` flag).
3727
+ swapMode: mode === "swap",
3655
3728
  swapDefaultDestToken: input.features?.swapDefaultDestToken ?? DEFAULT_FEATURE_FLAGS.swapDefaultDestToken,
3656
3729
  swapLockDestToken: input.features?.swapLockDestToken ?? DEFAULT_FEATURE_FLAGS.swapLockDestToken,
3657
3730
  swapAllowedDestTokens: input.features?.swapAllowedDestTokens ?? DEFAULT_FEATURE_FLAGS.swapAllowedDestTokens
3658
3731
  };
3659
3732
  return {
3660
3733
  apiKey: input.apiKey,
3734
+ mode,
3661
3735
  routes,
3662
3736
  autoDetectProvider,
3663
3737
  theme,
@@ -3670,12 +3744,15 @@ function resolveConfig(input) {
3670
3744
  onEvent: input.onEvent
3671
3745
  };
3672
3746
  }
3747
+ var hasWarnedDeprecatedSwapModeFlag;
3673
3748
  var init_merge = __esm({
3674
3749
  "src/config/merge.ts"() {
3675
3750
  "use strict";
3676
3751
  init_defaults();
3677
3752
  init_config();
3678
3753
  init_index();
3754
+ init_TrustwareError();
3755
+ hasWarnedDeprecatedSwapModeFlag = false;
3679
3756
  }
3680
3757
  });
3681
3758