@trustware/sdk-staging 1.1.16-staging.2 → 1.1.16-staging.3

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/README.md CHANGED
@@ -108,39 +108,41 @@ export function App() {
108
108
  keyed on `mode` — `routes` is only required in the default `"deposit"` mode:
109
109
 
110
110
  ```ts
111
- type TrustwareConfigOptions = {
112
- apiKey: string;
113
- mode?: "deposit"; // default, omit this field entirely for a normal deposit/top-up widget
114
- routes: {
115
- toChain: string;
116
- toToken: string;
117
- fromToken?: string;
118
- fromChain?: string;
119
- fromAddress?: string;
120
- toAddress?: string;
121
- defaultSlippage?: number;
122
- options?: {
123
- routeRefreshMs?: number;
124
- fixedFromAmount?: string | number;
125
- minAmountOut?: string | number;
126
- maxAmountOut?: string | number;
111
+ type TrustwareConfigOptions =
112
+ | {
113
+ apiKey: string;
114
+ mode?: "deposit"; // default, omit this field entirely for a normal deposit/top-up widget
115
+ routes: {
116
+ toChain: string;
117
+ toToken: string;
118
+ fromToken?: string;
119
+ fromChain?: string;
120
+ fromAddress?: string;
121
+ toAddress?: string;
122
+ defaultSlippage?: number;
123
+ options?: {
124
+ routeRefreshMs?: number;
125
+ fixedFromAmount?: string | number;
126
+ minAmountOut?: string | number;
127
+ maxAmountOut?: string | number;
128
+ };
129
+ };
130
+ autoDetectProvider?: boolean;
131
+ theme?: "light" | "dark" | "system"; // TrustwareTheme
132
+ messages?: Partial<TrustwareWidgetMessages>;
133
+ retry?: RetryConfig;
134
+ walletConnect?: WalletConnectConfig;
135
+ features?: FeatureFlags;
136
+ onError?: (error: TrustwareError) => void;
137
+ onSuccess?: (transaction: Transaction) => void;
138
+ onEvent?: (event: TrustwareEvent) => void;
139
+ }
140
+ | {
141
+ apiKey: string;
142
+ mode: "swap"; // swap widget — from/to chain+token are chosen entirely in-widget
143
+ routes?: Partial<TrustwareConfigOptions["routes"]>; // optional, not required
144
+ // ...same common fields as above
127
145
  };
128
- };
129
- autoDetectProvider?: boolean;
130
- theme?: "light" | "dark" | "system"; // TrustwareTheme
131
- messages?: Partial<TrustwareWidgetMessages>;
132
- retry?: RetryConfig;
133
- walletConnect?: WalletConnectConfig;
134
- features?: FeatureFlags;
135
- onError?: (error: TrustwareError) => void;
136
- onSuccess?: (transaction: Transaction) => void;
137
- onEvent?: (event: TrustwareEvent) => void;
138
- } | {
139
- apiKey: string;
140
- mode: "swap"; // swap widget — from/to chain+token are chosen entirely in-widget
141
- routes?: Partial<TrustwareConfigOptions["routes"]>; // optional, not required
142
- // ...same common fields as above
143
- };
144
146
  ```
145
147
 
146
148
  ### Modes
@@ -412,6 +414,12 @@ whose fees exceed what it delivers, throwing a `RouteError` with code
412
414
  `fees_exceed_output`. A route the provider did not price in USD is not refused.
413
415
  `routeNetUsd(estimate)` / `isValueDestroying(estimate)` expose the same check.
414
416
 
417
+ An address the backend cannot accept on its chain (wrong EIP-55 checksum, not a
418
+ Solana public key) comes back as a 400 `RouteError` with code `invalid_address`
419
+ and one `rejected` provider outcome per provider. No provider was called; fix
420
+ the request rather than retry it. `validateRouteAddresses` catches the same
421
+ cases client-side before the request is spent.
422
+
415
423
  ### Provider Context
416
424
 
417
425
  `useTrustware()` returns `{ status, errors, core, emitError, emitSuccess,
@@ -30,7 +30,7 @@ __export(constants_exports, {
30
30
  });
31
31
  module.exports = __toCommonJS(constants_exports);
32
32
  var SDK_NAME = "@trustware/sdk";
33
- var SDK_VERSION = "1.1.16-staging.2";
33
+ var SDK_VERSION = "1.1.16-staging.3";
34
34
  var API_ROOT = "https://bv-staging-api.trustware.io";
35
35
  var GTM_ID = "GTM-TZDGNCXB";
36
36
  var API_PREFIX = "/api";
@@ -1,6 +1,6 @@
1
1
  // src/constants.ts
2
2
  var SDK_NAME = "@trustware/sdk";
3
- var SDK_VERSION = "1.1.16-staging.2";
3
+ var SDK_VERSION = "1.1.16-staging.3";
4
4
  var API_ROOT = "https://bv-staging-api.trustware.io";
5
5
  var GTM_ID = "GTM-TZDGNCXB";
6
6
  var API_PREFIX = "/api";
@@ -123,9 +123,12 @@ declare function assertRouteDeliversValue(route: RoutePlan | undefined): void;
123
123
  /** One provider's answer, as the routing API reports it. */
124
124
  type RouteProviderOutcome = {
125
125
  name: string;
126
- /** "declined" — this provider cannot route the pair; "failed" — it errored. */
127
- outcome: "declined" | "failed" | (string & {});
128
- /** Stable machine code; see RouteDeclineCode / RouteFailureCode. */
126
+ /** "declined" — this provider cannot route the pair; "failed" — it errored;
127
+ * "rejected" — it refused the request before any call because the caller's
128
+ * own input cannot be valid (see RouteRejectionCode). */
129
+ outcome: "declined" | "failed" | "rejected" | (string & {});
130
+ /** Stable machine code; see RouteDeclineCode / RouteFailureCode /
131
+ * RouteRejectionCode. */
129
132
  code: string;
130
133
  message: string;
131
134
  };
@@ -152,12 +155,25 @@ declare const RouteFailureCode: {
152
155
  readonly Timeout: "timeout";
153
156
  readonly ProviderError: "provider_error";
154
157
  };
158
+ /**
159
+ * Codes for a provider that refused the request before any call. The caller's
160
+ * input is the problem, not the pair and not the provider: an address that
161
+ * cannot be valid on its chain (not hex, wrong EIP-55 checksum, not a Solana
162
+ * public key). The backend's validators are shared and deterministic, so one
163
+ * rejection is the verdict whatever the other providers said.
164
+ */
165
+ declare const RouteRejectionCode: {
166
+ readonly InvalidAddress: "invalid_address";
167
+ };
155
168
  /** Top-level verdict for the request as a whole. */
156
169
  declare const RouteErrorCode: {
157
170
  /** Every provider declined: a negative result, returned as 404. */
158
171
  readonly NoRouteAvailable: "no_route_available";
159
172
  /** At least one provider failed, so "unroutable" cannot be claimed: 502. */
160
173
  readonly ProvidersFailed: "providers_failed";
174
+ /** The caller's address cannot be valid on its chain; no provider was
175
+ * asked. Returned as 400. Fix the request rather than retry it. */
176
+ readonly InvalidAddress: "invalid_address";
161
177
  /** A route came back but the SDK refused it: its fees exceed its output.
162
178
  * Reached client-side, so `status` is 0. */
163
179
  readonly FeesExceedOutput: "fees_exceed_output";
@@ -175,7 +191,8 @@ declare const RouteErrorCode: {
175
191
  */
176
192
  declare class RouteError extends Error {
177
193
  /** HTTP status: 404 when every provider declined, 502 when one failed,
178
- * 0 when the SDK reached the verdict itself without a response. */
194
+ * 400 when the caller's address was rejected, 0 when the SDK reached the
195
+ * verdict itself without a response. */
179
196
  readonly status: number;
180
197
  /** Top-level verdict — see RouteErrorCode. Empty when the API sent none. */
181
198
  readonly code: string;
@@ -189,6 +206,8 @@ declare class RouteError extends Error {
189
206
  });
190
207
  /** True when every provider declined — nobody failed, so the pair is the problem. */
191
208
  get isNoRouteAvailable(): boolean;
209
+ /** True when the caller's address was rejected — nothing to retry, fix the request. */
210
+ get isInvalidAddress(): boolean;
192
211
  /** The distinct provider codes, e.g. ["amount_too_low", "no_routes"]. */
193
212
  get providerCodes(): string[];
194
213
  }
@@ -200,8 +219,13 @@ type RouteErrorFacts = {
200
219
  codes: string[];
201
220
  /** Per-provider outcomes, empty when only the message survived. */
202
221
  providers: readonly RouteProviderOutcome[];
203
- /** True when no provider failed — every one of them declined. */
222
+ /** True when no provider failed or rejected — every one of them declined. */
204
223
  allDeclined: boolean;
224
+ /**
225
+ * True when a provider rejected the caller's own input. Outranks the rest:
226
+ * the pair may route fine and no provider failed, the request is wrong.
227
+ */
228
+ rejected: boolean;
205
229
  /**
206
230
  * The smallest amount a provider said it would accept, when one said so.
207
231
  * Both spellings are covered: Squid's own "Minimum swap amount for this route
@@ -324,4 +348,4 @@ declare const Trustware: {
324
348
  };
325
349
  type TrustwareCore = typeof Trustware;
326
350
 
327
- export { RouteDeclineCode as R, Trustware as T, RouteError as a, RouteErrorCode as b, type RouteErrorFacts as c, RouteFailureCode as d, type RouteProviderOutcome as e, type TrustwareCore as f, assertRouteDeliversValue as g, formatMinimum as h, isRouteError as i, isValueDestroying as j, validateBtcAddress as k, validateCosmosAddress as l, validateEvmAddress as m, validateRouteAddresses as n, validateSeiAddress as o, parseRouteError as p, validateSolanaAddress as q, routeNetUsd as r, validateAddressForChain as v };
351
+ export { RouteDeclineCode as R, Trustware as T, RouteError as a, RouteErrorCode as b, type RouteErrorFacts as c, RouteFailureCode as d, type RouteProviderOutcome as e, RouteRejectionCode as f, type TrustwareCore as g, assertRouteDeliversValue as h, formatMinimum as i, isRouteError as j, isValueDestroying as k, validateBtcAddress as l, validateCosmosAddress as m, validateEvmAddress as n, validateRouteAddresses as o, parseRouteError as p, validateSeiAddress as q, routeNetUsd as r, validateSolanaAddress as s, validateAddressForChain as v };
@@ -123,9 +123,12 @@ declare function assertRouteDeliversValue(route: RoutePlan | undefined): void;
123
123
  /** One provider's answer, as the routing API reports it. */
124
124
  type RouteProviderOutcome = {
125
125
  name: string;
126
- /** "declined" — this provider cannot route the pair; "failed" — it errored. */
127
- outcome: "declined" | "failed" | (string & {});
128
- /** Stable machine code; see RouteDeclineCode / RouteFailureCode. */
126
+ /** "declined" — this provider cannot route the pair; "failed" — it errored;
127
+ * "rejected" — it refused the request before any call because the caller's
128
+ * own input cannot be valid (see RouteRejectionCode). */
129
+ outcome: "declined" | "failed" | "rejected" | (string & {});
130
+ /** Stable machine code; see RouteDeclineCode / RouteFailureCode /
131
+ * RouteRejectionCode. */
129
132
  code: string;
130
133
  message: string;
131
134
  };
@@ -152,12 +155,25 @@ declare const RouteFailureCode: {
152
155
  readonly Timeout: "timeout";
153
156
  readonly ProviderError: "provider_error";
154
157
  };
158
+ /**
159
+ * Codes for a provider that refused the request before any call. The caller's
160
+ * input is the problem, not the pair and not the provider: an address that
161
+ * cannot be valid on its chain (not hex, wrong EIP-55 checksum, not a Solana
162
+ * public key). The backend's validators are shared and deterministic, so one
163
+ * rejection is the verdict whatever the other providers said.
164
+ */
165
+ declare const RouteRejectionCode: {
166
+ readonly InvalidAddress: "invalid_address";
167
+ };
155
168
  /** Top-level verdict for the request as a whole. */
156
169
  declare const RouteErrorCode: {
157
170
  /** Every provider declined: a negative result, returned as 404. */
158
171
  readonly NoRouteAvailable: "no_route_available";
159
172
  /** At least one provider failed, so "unroutable" cannot be claimed: 502. */
160
173
  readonly ProvidersFailed: "providers_failed";
174
+ /** The caller's address cannot be valid on its chain; no provider was
175
+ * asked. Returned as 400. Fix the request rather than retry it. */
176
+ readonly InvalidAddress: "invalid_address";
161
177
  /** A route came back but the SDK refused it: its fees exceed its output.
162
178
  * Reached client-side, so `status` is 0. */
163
179
  readonly FeesExceedOutput: "fees_exceed_output";
@@ -175,7 +191,8 @@ declare const RouteErrorCode: {
175
191
  */
176
192
  declare class RouteError extends Error {
177
193
  /** HTTP status: 404 when every provider declined, 502 when one failed,
178
- * 0 when the SDK reached the verdict itself without a response. */
194
+ * 400 when the caller's address was rejected, 0 when the SDK reached the
195
+ * verdict itself without a response. */
179
196
  readonly status: number;
180
197
  /** Top-level verdict — see RouteErrorCode. Empty when the API sent none. */
181
198
  readonly code: string;
@@ -189,6 +206,8 @@ declare class RouteError extends Error {
189
206
  });
190
207
  /** True when every provider declined — nobody failed, so the pair is the problem. */
191
208
  get isNoRouteAvailable(): boolean;
209
+ /** True when the caller's address was rejected — nothing to retry, fix the request. */
210
+ get isInvalidAddress(): boolean;
192
211
  /** The distinct provider codes, e.g. ["amount_too_low", "no_routes"]. */
193
212
  get providerCodes(): string[];
194
213
  }
@@ -200,8 +219,13 @@ type RouteErrorFacts = {
200
219
  codes: string[];
201
220
  /** Per-provider outcomes, empty when only the message survived. */
202
221
  providers: readonly RouteProviderOutcome[];
203
- /** True when no provider failed — every one of them declined. */
222
+ /** True when no provider failed or rejected — every one of them declined. */
204
223
  allDeclined: boolean;
224
+ /**
225
+ * True when a provider rejected the caller's own input. Outranks the rest:
226
+ * the pair may route fine and no provider failed, the request is wrong.
227
+ */
228
+ rejected: boolean;
205
229
  /**
206
230
  * The smallest amount a provider said it would accept, when one said so.
207
231
  * Both spellings are covered: Squid's own "Minimum swap amount for this route
@@ -324,4 +348,4 @@ declare const Trustware: {
324
348
  };
325
349
  type TrustwareCore = typeof Trustware;
326
350
 
327
- export { RouteDeclineCode as R, Trustware as T, RouteError as a, RouteErrorCode as b, type RouteErrorFacts as c, RouteFailureCode as d, type RouteProviderOutcome as e, type TrustwareCore as f, assertRouteDeliversValue as g, formatMinimum as h, isRouteError as i, isValueDestroying as j, validateBtcAddress as k, validateCosmosAddress as l, validateEvmAddress as m, validateRouteAddresses as n, validateSeiAddress as o, parseRouteError as p, validateSolanaAddress as q, routeNetUsd as r, validateAddressForChain as v };
351
+ export { RouteDeclineCode as R, Trustware as T, RouteError as a, RouteErrorCode as b, type RouteErrorFacts as c, RouteFailureCode as d, type RouteProviderOutcome as e, RouteRejectionCode as f, type TrustwareCore as g, assertRouteDeliversValue as h, formatMinimum as i, isRouteError as j, isValueDestroying as k, validateBtcAddress as l, validateCosmosAddress as m, validateEvmAddress as n, validateRouteAddresses as o, parseRouteError as p, validateSeiAddress as q, routeNetUsd as r, validateSolanaAddress as s, validateAddressForChain as v };
package/dist/core.cjs CHANGED
@@ -83,7 +83,7 @@ var init_constants = __esm({
83
83
  "src/constants.ts"() {
84
84
  "use strict";
85
85
  SDK_NAME = "@trustware/sdk";
86
- SDK_VERSION = "1.1.16-staging.2";
86
+ SDK_VERSION = "1.1.16-staging.3";
87
87
  API_ROOT = "https://bv-staging-api.trustware.io";
88
88
  API_PREFIX = "/api";
89
89
  WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
@@ -4105,10 +4105,12 @@ function routeErrorFromResponse(status, body, fallbackMessage) {
4105
4105
  }
4106
4106
  function parseRouteError(raw) {
4107
4107
  if (isRouteError(raw) && raw.providers.length > 0) {
4108
+ const rejected = raw.providers.some((p) => p.outcome === "rejected");
4108
4109
  return {
4109
4110
  codes: providerCodes(raw.providers),
4110
4111
  providers: raw.providers,
4111
- allDeclined: raw.providers.every((p) => p.outcome !== "failed"),
4112
+ allDeclined: !rejected && raw.providers.every((p) => p.outcome !== "failed"),
4113
+ rejected,
4112
4114
  minimum: firstMinimum(raw.providers.map((p) => p.message))
4113
4115
  };
4114
4116
  }
@@ -4123,6 +4125,7 @@ function parseRouteError(raw) {
4123
4125
  codes,
4124
4126
  providers: [],
4125
4127
  allDeclined: !codes.some((code) => failureCodes.includes(code)),
4128
+ rejected: false,
4126
4129
  minimum: firstMinimum([text])
4127
4130
  };
4128
4131
  }
@@ -4172,7 +4175,7 @@ function formatMinimum(minimum) {
4172
4175
  if (minimum.symbol.toUpperCase() === "USD") return `$${minimum.amount}`;
4173
4176
  return `${minimum.amount} ${minimum.symbol}`;
4174
4177
  }
4175
- var RouteDeclineCode, RouteFailureCode, RouteErrorCode, ALL_PROVIDER_CODES, RouteError, MAX_ROUTE_ERROR_TEXT, ROUTE_SUMMARIES;
4178
+ var RouteDeclineCode, RouteFailureCode, RouteRejectionCode, RouteErrorCode, ALL_PROVIDER_CODES, RouteError, MAX_ROUTE_ERROR_TEXT, ROUTE_SUMMARIES;
4176
4179
  var init_routeError = __esm({
4177
4180
  "src/core/routeError.ts"() {
4178
4181
  "use strict";
@@ -4194,18 +4197,25 @@ var init_routeError = __esm({
4194
4197
  Timeout: "timeout",
4195
4198
  ProviderError: "provider_error"
4196
4199
  };
4200
+ RouteRejectionCode = {
4201
+ InvalidAddress: "invalid_address"
4202
+ };
4197
4203
  RouteErrorCode = {
4198
4204
  /** Every provider declined: a negative result, returned as 404. */
4199
4205
  NoRouteAvailable: "no_route_available",
4200
4206
  /** At least one provider failed, so "unroutable" cannot be claimed: 502. */
4201
4207
  ProvidersFailed: "providers_failed",
4208
+ /** The caller's address cannot be valid on its chain; no provider was
4209
+ * asked. Returned as 400. Fix the request rather than retry it. */
4210
+ InvalidAddress: "invalid_address",
4202
4211
  /** A route came back but the SDK refused it: its fees exceed its output.
4203
4212
  * Reached client-side, so `status` is 0. */
4204
4213
  FeesExceedOutput: "fees_exceed_output"
4205
4214
  };
4206
4215
  ALL_PROVIDER_CODES = [
4207
4216
  ...Object.values(RouteDeclineCode),
4208
- ...Object.values(RouteFailureCode)
4217
+ ...Object.values(RouteFailureCode),
4218
+ ...Object.values(RouteRejectionCode)
4209
4219
  ];
4210
4220
  RouteError = class extends Error {
4211
4221
  constructor(params) {
@@ -4219,6 +4229,10 @@ var init_routeError = __esm({
4219
4229
  get isNoRouteAvailable() {
4220
4230
  return this.code === RouteErrorCode.NoRouteAvailable || this.status === 404;
4221
4231
  }
4232
+ /** True when the caller's address was rejected — nothing to retry, fix the request. */
4233
+ get isInvalidAddress() {
4234
+ return this.code === RouteErrorCode.InvalidAddress;
4235
+ }
4222
4236
  /** The distinct provider codes, e.g. ["amount_too_low", "no_routes"]. */
4223
4237
  get providerCodes() {
4224
4238
  return providerCodes(this.providers);
@@ -7340,6 +7354,7 @@ __export(core_exports, {
7340
7354
  RouteError: () => RouteError,
7341
7355
  RouteErrorCode: () => RouteErrorCode,
7342
7356
  RouteFailureCode: () => RouteFailureCode,
7357
+ RouteRejectionCode: () => RouteRejectionCode,
7343
7358
  Trustware: () => Trustware,
7344
7359
  assertRouteDeliversValue: () => assertRouteDeliversValue,
7345
7360
  assertValidPostHook: () => assertValidPostHook,
@@ -7362,6 +7377,7 @@ init_core2();
7362
7377
  RouteError,
7363
7378
  RouteErrorCode,
7364
7379
  RouteFailureCode,
7380
+ RouteRejectionCode,
7365
7381
  Trustware,
7366
7382
  assertRouteDeliversValue,
7367
7383
  assertValidPostHook,