@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
@@ -12241,7 +12241,7 @@ var init_constants = __esm({
12241
12241
  "src/constants.ts"() {
12242
12242
  "use strict";
12243
12243
  SDK_NAME = "@trustware/sdk";
12244
- SDK_VERSION = "1.1.9-staging.6";
12244
+ SDK_VERSION = "1.1.10-staging.0";
12245
12245
  API_ROOT = "https://bv-staging-api.trustware.io";
12246
12246
  API_PREFIX = "/api";
12247
12247
  }
@@ -13199,7 +13199,9 @@ var init_chains2 = __esm({
13199
13199
  btc: "bitcoin",
13200
13200
  bitcoin: "bitcoin",
13201
13201
  sei: "cosmos",
13202
- "pacific-1": "cosmos"
13202
+ "pacific-1": "cosmos",
13203
+ nibiru: "cosmos",
13204
+ "cataclysm-1": "cosmos"
13203
13205
  };
13204
13206
  }
13205
13207
  });
@@ -13243,16 +13245,23 @@ function validateEvmAddress(address) {
13243
13245
  }
13244
13246
  return { isValid: true };
13245
13247
  }
13246
- function validateSeiAddress(address) {
13248
+ function resolveCosmosBech32Prefix(chain) {
13249
+ const chainDef = typeof chain === "object" && chain ? chain : void 0;
13250
+ const identifier = chainDef?.networkIdentifier ?? chainDef?.chainId ?? chainDef?.id ?? (typeof chain === "string" ? chain : void 0);
13251
+ const normalized = String(identifier ?? "").trim().toLowerCase();
13252
+ return COSMOS_BECH32_PREFIX_BY_CHAIN_ID[normalized] ?? "sei";
13253
+ }
13254
+ function validateCosmosAddress(address, chain) {
13247
13255
  const trimmed = address.trim();
13248
- if (isEvmAddress(trimmed)) {
13256
+ const prefix = resolveCosmosBech32Prefix(chain);
13257
+ if (prefix === "sei" && isEvmAddress(trimmed)) {
13249
13258
  return { isValid: true };
13250
13259
  }
13251
- const result = validateBech32LikeAddress(trimmed, "sei");
13260
+ const result = validateBech32LikeAddress(trimmed, prefix);
13252
13261
  if (result.isValid) return result;
13253
13262
  return {
13254
13263
  isValid: false,
13255
- error: "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings."
13264
+ error: prefix === "sei" ? "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings." : `Address must be a valid ${prefix}1 bech32 string.`
13256
13265
  };
13257
13266
  }
13258
13267
  function validateSolanaAddress(address) {
@@ -13302,21 +13311,24 @@ function validateAddressForChain(address, chain) {
13302
13311
  case "bitcoin":
13303
13312
  return validateBtcAddress(trimmed);
13304
13313
  case "cosmos":
13305
- if (chainDef?.networkIdentifier?.toLowerCase() === "sei") {
13306
- return validateSeiAddress(trimmed);
13307
- }
13308
- return validateBech32LikeAddress(trimmed, "sei");
13314
+ return validateCosmosAddress(trimmed, chainDef ?? chain);
13309
13315
  default:
13310
13316
  return { isValid: false, error: "Unsupported or unknown chain type." };
13311
13317
  }
13312
13318
  }
13313
- var BECH32_CHARSET;
13319
+ var BECH32_CHARSET, COSMOS_BECH32_PREFIX_BY_CHAIN_ID;
13314
13320
  var init_address = __esm({
13315
13321
  "src/validation/address.ts"() {
13316
13322
  "use strict";
13317
13323
  init_index_node4();
13318
13324
  init_chains2();
13319
13325
  BECH32_CHARSET = /^[023456789acdefghjklmnpqrstuvwxyz]+$/i;
13326
+ COSMOS_BECH32_PREFIX_BY_CHAIN_ID = {
13327
+ "pacific-1": "sei",
13328
+ sei: "sei",
13329
+ "cataclysm-1": "nibi",
13330
+ nibiru: "nibi"
13331
+ };
13320
13332
  }
13321
13333
  });
13322
13334
 
@@ -13328,7 +13340,7 @@ var init_identity = __esm({
13328
13340
  });
13329
13341
 
13330
13342
  // src/core/routes.ts
13331
- async function submitReceipt(intentId, txHash, sponsorshipRequestId) {
13343
+ async function submitReceipt(intentId, txHash, sponsorshipRequestId, eoaAddress) {
13332
13344
  const r = await rateLimitedFetch(
13333
13345
  `${apiBase()}/v1/route-intent/${intentId}/receipt`,
13334
13346
  {
@@ -13336,7 +13348,8 @@ async function submitReceipt(intentId, txHash, sponsorshipRequestId) {
13336
13348
  headers: jsonHeaders({ "Idempotency-Key": txHash }),
13337
13349
  body: JSON.stringify({
13338
13350
  txHash,
13339
- ...sponsorshipRequestId ? { sponsorshipRequestId } : {}
13351
+ ...sponsorshipRequestId ? { sponsorshipRequestId } : {},
13352
+ ...eoaAddress ? { eoaAddress } : {}
13340
13353
  })
13341
13354
  }
13342
13355
  );
@@ -13351,6 +13364,31 @@ var init_routes = __esm({
13351
13364
  }
13352
13365
  });
13353
13366
 
13367
+ // src/errors/TrustwareError.ts
13368
+ var TrustwareError;
13369
+ var init_TrustwareError = __esm({
13370
+ "src/errors/TrustwareError.ts"() {
13371
+ "use strict";
13372
+ TrustwareError = class extends Error {
13373
+ constructor(params) {
13374
+ super(params.message);
13375
+ this.name = "TrustwareError";
13376
+ this.code = params.code;
13377
+ this.userMessage = params.userMessage;
13378
+ this.cause = params.cause;
13379
+ }
13380
+ toJSON() {
13381
+ return {
13382
+ name: this.name,
13383
+ code: this.code,
13384
+ message: this.message,
13385
+ userMessage: this.userMessage
13386
+ };
13387
+ }
13388
+ };
13389
+ }
13390
+ });
13391
+
13354
13392
  // src/types/routes.ts
13355
13393
  var init_routes2 = __esm({
13356
13394
  "src/types/routes.ts"() {
@@ -13430,46 +13468,80 @@ function normalizeSlippage(v) {
13430
13468
  if (n > 5) return 5;
13431
13469
  return n;
13432
13470
  }
13471
+ function warnDeprecatedSwapModeFlag() {
13472
+ if (hasWarnedDeprecatedSwapModeFlag) return;
13473
+ hasWarnedDeprecatedSwapModeFlag = true;
13474
+ console.warn(
13475
+ '[Trustware SDK] `features.swapMode` is deprecated \u2014 use `mode: "swap"` on the top-level config instead.'
13476
+ );
13477
+ }
13478
+ function resolveMode(input) {
13479
+ if (input.mode === "swap") return "swap";
13480
+ if (input.mode === "deposit") return "deposit";
13481
+ if (input.features?.swapMode) {
13482
+ warnDeprecatedSwapModeFlag();
13483
+ return "swap";
13484
+ }
13485
+ return "deposit";
13486
+ }
13433
13487
  function resolveConfig(input) {
13434
13488
  if (!input?.apiKey) {
13435
- throw new Error("TrustwareConfig: 'apiKey' is required.");
13489
+ throw new TrustwareError({
13490
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
13491
+ message: "TrustwareConfig: 'apiKey' is required.",
13492
+ userMessage: "Missing required API key configuration."
13493
+ });
13436
13494
  }
13437
- if (!input.routes?.toChain || !input.routes?.toToken) {
13438
- throw new Error(
13439
- "TrustwareConfig: 'routes.toChain' and 'routes.toToken' are required."
13440
- );
13495
+ const mode = resolveMode(input);
13496
+ if (mode === "deposit" && (!input.routes?.toChain || !input.routes?.toToken)) {
13497
+ throw new TrustwareError({
13498
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
13499
+ message: "TrustwareConfig: 'routes.toChain' and 'routes.toToken' are required in deposit mode.",
13500
+ userMessage: "Missing required destination chain/token configuration."
13501
+ });
13441
13502
  }
13442
- const toChain = input.routes.toChain;
13443
- if (input.routes.toAddress) {
13503
+ const toChain = input.routes?.toChain;
13504
+ if (input.routes?.toAddress && toChain) {
13444
13505
  const result = validateAddressForChain(input.routes.toAddress, toChain);
13445
13506
  if (!result.isValid) {
13446
13507
  console.error(`[Trustware SDK] Invalid toAddress: ${result.error}`);
13447
- throw new Error(`Invalid toAddress: ${result.error}`);
13508
+ throw new TrustwareError({
13509
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
13510
+ message: `Invalid toAddress: ${result.error}`,
13511
+ userMessage: "The configured destination address is invalid."
13512
+ });
13448
13513
  }
13449
13514
  }
13450
- if (input.routes.fromAddress) {
13451
- const result = validateAddressForChain(
13452
- input.routes.fromAddress,
13453
- input.routes.fromChain ?? toChain
13454
- );
13455
- if (!result.isValid) {
13456
- console.error(`[Trustware SDK] Invalid fromAddress: ${result.error}`);
13457
- throw new Error(`Invalid fromAddress: ${result.error}`);
13515
+ if (input.routes?.fromAddress) {
13516
+ const fromChain = input.routes.fromChain ?? toChain;
13517
+ if (fromChain) {
13518
+ const result = validateAddressForChain(
13519
+ input.routes.fromAddress,
13520
+ fromChain
13521
+ );
13522
+ if (!result.isValid) {
13523
+ console.error(`[Trustware SDK] Invalid fromAddress: ${result.error}`);
13524
+ throw new TrustwareError({
13525
+ code: "INVALID_CONFIG" /* INVALID_CONFIG */,
13526
+ message: `Invalid fromAddress: ${result.error}`,
13527
+ userMessage: "The configured source address is invalid."
13528
+ });
13529
+ }
13458
13530
  }
13459
13531
  }
13460
13532
  const autoDetectProvider = typeof input.autoDetectProvider === "boolean" ? input.autoDetectProvider : DEFAULT_AUTO_DETECT_PROVIDER;
13461
13533
  const routes = {
13462
- toChain: input.routes.toChain,
13463
- toToken: input.routes.toToken,
13464
- fromToken: input.routes.fromToken,
13465
- fromAddress: input.routes.fromAddress,
13466
- fromChain: input.routes.fromChain,
13467
- toAddress: input.routes.toAddress,
13534
+ toChain: input.routes?.toChain ?? "",
13535
+ toToken: input.routes?.toToken ?? "",
13536
+ fromToken: input.routes?.fromToken,
13537
+ fromAddress: input.routes?.fromAddress,
13538
+ fromChain: input.routes?.fromChain,
13539
+ toAddress: input.routes?.toAddress,
13468
13540
  defaultSlippage: normalizeSlippage(
13469
- input.routes.defaultSlippage ?? DEFAULT_SLIPPAGE
13541
+ input.routes?.defaultSlippage ?? DEFAULT_SLIPPAGE
13470
13542
  ),
13471
13543
  options: {
13472
- ...input.routes.options
13544
+ ...input.routes?.options
13473
13545
  }
13474
13546
  };
13475
13547
  const theme = input.theme ?? "system";
@@ -13488,13 +13560,16 @@ function resolveConfig(input) {
13488
13560
  tokensPagination: input.features?.tokensPagination ?? DEFAULT_FEATURE_FLAGS.tokensPagination,
13489
13561
  balanceStreaming: input.features?.balanceStreaming ?? DEFAULT_FEATURE_FLAGS.balanceStreaming,
13490
13562
  shouldAllowGA4: input.features?.shouldAllowGA4 ?? DEFAULT_FEATURE_FLAGS.shouldAllowGA4,
13491
- swapMode: input.features?.swapMode ?? DEFAULT_FEATURE_FLAGS.swapMode,
13563
+ // Always mirrors the canonical `mode`, however the caller set it (new `mode` field
13564
+ // or the deprecated `features.swapMode` flag).
13565
+ swapMode: mode === "swap",
13492
13566
  swapDefaultDestToken: input.features?.swapDefaultDestToken ?? DEFAULT_FEATURE_FLAGS.swapDefaultDestToken,
13493
13567
  swapLockDestToken: input.features?.swapLockDestToken ?? DEFAULT_FEATURE_FLAGS.swapLockDestToken,
13494
13568
  swapAllowedDestTokens: input.features?.swapAllowedDestTokens ?? DEFAULT_FEATURE_FLAGS.swapAllowedDestTokens
13495
13569
  };
13496
13570
  return {
13497
13571
  apiKey: input.apiKey,
13572
+ mode,
13498
13573
  routes,
13499
13574
  autoDetectProvider,
13500
13575
  theme,
@@ -13507,12 +13582,15 @@ function resolveConfig(input) {
13507
13582
  onEvent: input.onEvent
13508
13583
  };
13509
13584
  }
13585
+ var hasWarnedDeprecatedSwapModeFlag;
13510
13586
  var init_merge = __esm({
13511
13587
  "src/config/merge.ts"() {
13512
13588
  "use strict";
13513
13589
  init_defaults3();
13514
13590
  init_config();
13515
13591
  init_index();
13592
+ init_TrustwareError();
13593
+ hasWarnedDeprecatedSwapModeFlag = false;
13516
13594
  }
13517
13595
  });
13518
13596
 
@@ -14629,7 +14707,7 @@ async function sendRouteAsUserOperation(params) {
14629
14707
  );
14630
14708
  }
14631
14709
  console.debug("[send] UserOp included", { userOpHash, txHash });
14632
- await submitReceipt(intentId, txHash, getSponsorshipRequestId());
14710
+ await submitReceipt(intentId, txHash, getSponsorshipRequestId(), eoaAddress);
14633
14711
  return { userOpHash, txHash, intentId };
14634
14712
  }
14635
14713
  var NATIVE_ADDRS;