@toon-protocol/client 5.1.1 → 5.2.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.
@@ -9,221 +9,36 @@ import {
9
9
  evmIdentityFromKey,
10
10
  isHiddenServiceUrl
11
11
  } from "./chunk-6O5OXJVR.js";
12
+ import {
13
+ BeforePayRefusedError,
14
+ ChainUnavailableError,
15
+ ChannelNotOpenError,
16
+ ConfigError,
17
+ ConnectorError,
18
+ FacilitatorError,
19
+ InsufficientBalanceError,
20
+ InvalidAddressError,
21
+ NetworkError,
22
+ PROXIED_RPC_DEFAULTS,
23
+ PaymentRequiredError,
24
+ RouteNotPricedError,
25
+ SponsorRefusedError,
26
+ ToonClientError,
27
+ TransactionOutcomeError,
28
+ TransferNotDeliveredError,
29
+ TransferUnsupportedError,
30
+ TransportRequiredError,
31
+ UnknownChainError,
32
+ ValidationError,
33
+ chainUnavailableMessage,
34
+ describeEndpoint,
35
+ directFetch,
36
+ rpcTransport
37
+ } from "./chunk-ABOW5ZCE.js";
12
38
  import {
13
39
  validateSocks5hUrl
14
40
  } from "./chunk-32MD3CXE.js";
15
41
 
16
- // src/client/errors.ts
17
- var ToonClientError = class extends Error {
18
- constructor(message, code, cause) {
19
- super(message, { cause });
20
- this.code = code;
21
- this.name = "ToonClientError";
22
- }
23
- code;
24
- };
25
- var NetworkError = class extends ToonClientError {
26
- /** The URL that could not be reached, when the failure was reaching one. */
27
- endpoint;
28
- constructor(message, cause, endpoint) {
29
- super(message, "NETWORK_ERROR", cause);
30
- this.name = "NetworkError";
31
- if (endpoint !== void 0) this.endpoint = endpoint;
32
- }
33
- };
34
- function describeEndpoint(url, source) {
35
- return source === "published" ? `${url} (the endpoint the connector published in its self-description)` : url;
36
- }
37
- var ConnectorError = class extends ToonClientError {
38
- constructor(message, cause) {
39
- super(message, "CONNECTOR_ERROR", cause);
40
- this.name = "ConnectorError";
41
- }
42
- };
43
- var ValidationError = class extends ToonClientError {
44
- constructor(message, cause) {
45
- super(message, "VALIDATION_ERROR", cause);
46
- this.name = "ValidationError";
47
- }
48
- };
49
- var ConfigError = class extends ToonClientError {
50
- constructor(message, cause) {
51
- super(message, "CONFIG", cause);
52
- this.name = "ConfigError";
53
- }
54
- };
55
- var ChainUnavailableError = class extends ToonClientError {
56
- /** The CAIP-2 networks the node publishes (`eip155:84532`, `solana:EtWT…`). */
57
- offered;
58
- constructor(message, offered, cause) {
59
- super(message, "CHAIN_UNAVAILABLE", cause);
60
- this.name = "ChainUnavailableError";
61
- this.offered = [...offered];
62
- }
63
- };
64
- var ChannelNotOpenError = class extends ToonClientError {
65
- constructor(message, cause) {
66
- super(message, "CHANNEL_NOT_OPEN", cause);
67
- this.name = "ChannelNotOpenError";
68
- }
69
- };
70
- var RouteNotPricedError = class extends ToonClientError {
71
- constructor(message, cause) {
72
- super(message, "ROUTE_NOT_PRICED", cause);
73
- this.name = "RouteNotPricedError";
74
- }
75
- };
76
- var BeforePayRefusedError = class extends ToonClientError {
77
- /** The reason the hook returned, verbatim. */
78
- reason;
79
- /** The route the refused packet was addressed to. */
80
- destination;
81
- /** The resolved price the hook was shown, in base units. */
82
- amount;
83
- constructor(reason, destination, amount) {
84
- super(
85
- `beforePay refused this send to "${destination}" for ${amount.toString()}: ${reason}`,
86
- "BEFORE_PAY_REFUSED"
87
- );
88
- this.name = "BeforePayRefusedError";
89
- this.reason = reason;
90
- this.destination = destination;
91
- this.amount = amount;
92
- }
93
- };
94
- var PaymentRequiredError = class extends ToonClientError {
95
- /** The route's terms, parsed from the x402 challenge body. */
96
- terms;
97
- constructor(message, terms, cause) {
98
- super(message, "PAYMENT_REQUIRED", cause);
99
- this.name = "PaymentRequiredError";
100
- this.terms = terms;
101
- }
102
- };
103
- var TransportRequiredError = class extends ToonClientError {
104
- /** The carriage the node requires, when the refusal named one. */
105
- required;
106
- /** The route's terms, when the refusal carried them. */
107
- terms;
108
- constructor(message, options = {}) {
109
- super(message, "TRANSPORT_REQUIRED", options.cause);
110
- this.name = "TransportRequiredError";
111
- this.required = options.required;
112
- this.terms = options.terms;
113
- }
114
- };
115
- var ChannelFundingError = class extends ToonClientError {
116
- retryable = true;
117
- constructor(message, cause) {
118
- super(message, "CHANNEL_FUNDING", cause);
119
- this.name = "ChannelFundingError";
120
- }
121
- };
122
- var ChannelResumeError = class extends ToonClientError {
123
- constructor(message, cause) {
124
- super(message, "CHANNEL_RESUME", cause);
125
- this.name = "ChannelResumeError";
126
- }
127
- };
128
- var InsufficientBalanceError = class extends ToonClientError {
129
- constructor(message, cause) {
130
- super(message, "INSUFFICIENT_BALANCE", cause);
131
- this.name = "InsufficientBalanceError";
132
- }
133
- };
134
- var StaleRpcReadError = class extends ToonClientError {
135
- retryable = true;
136
- constructor(message, cause) {
137
- super(message, "STALE_RPC_READ", cause);
138
- this.name = "StaleRpcReadError";
139
- }
140
- };
141
- var UnknownChainError = class extends ToonClientError {
142
- constructor(message, cause) {
143
- super(message, "UNKNOWN_CHAIN", cause);
144
- this.name = "UnknownChainError";
145
- }
146
- };
147
- var InvalidAddressError = class extends ToonClientError {
148
- constructor(message, cause) {
149
- super(message, "INVALID_ADDRESS", cause);
150
- this.name = "InvalidAddressError";
151
- }
152
- };
153
- var TransferNotDeliveredError = class extends ToonClientError {
154
- constructor(message, cause) {
155
- super(message, "TRANSFER_NOT_DELIVERED", cause);
156
- this.name = "TransferNotDeliveredError";
157
- }
158
- };
159
- var TransferUnsupportedError = class extends ToonClientError {
160
- constructor(message, cause) {
161
- super(message, "TRANSFER_UNSUPPORTED", cause);
162
- this.name = "TransferUnsupportedError";
163
- }
164
- };
165
- var FacilitatorError = class extends ToonClientError {
166
- constructor(message, reason, cause) {
167
- super(message, "FACILITATOR", cause);
168
- this.reason = reason;
169
- this.name = "FacilitatorError";
170
- }
171
- reason;
172
- };
173
- var SponsorRefusedError = class extends ToonClientError {
174
- /**
175
- * @param status the endpoint's HTTP status. `502` is its "failed" class — a
176
- * co-signed open that was sent and did not confirm — so, unlike every other
177
- * refusal, it does not prove nothing landed.
178
- */
179
- constructor(message, reason, status, cause) {
180
- super(message, "SPONSOR_REFUSED", cause);
181
- this.reason = reason;
182
- this.status = status;
183
- this.name = "SponsorRefusedError";
184
- }
185
- reason;
186
- status;
187
- };
188
- var INSUFFICIENT_GAS_MARKERS = [
189
- "exceeds the balance of the account",
190
- "insufficient funds for gas",
191
- "insufficient funds for intrinsic transaction cost",
192
- "insufficient funds for transfer"
193
- ];
194
- function isInsufficientGasError(err) {
195
- const parts = [];
196
- let cur = err;
197
- for (let i = 0; i < 10 && cur != null; i++) {
198
- parts.push(cur instanceof Error ? cur.message : String(cur));
199
- cur = cur instanceof Error ? cur.cause : void 0;
200
- }
201
- const text = parts.join(" | ").toLowerCase();
202
- return INSUFFICIENT_GAS_MARKERS.some((m) => text.includes(m));
203
- }
204
- function chainUnavailableMessage(wanted, offered, reason) {
205
- const list = offered.length > 0 ? offered.join(", ") : "(none)";
206
- if (reason === "none") {
207
- return "This connector publishes no settlement chains at all, so there is no channel to open and nothing can be paid for. Check that it is configured with a settlement backend.";
208
- }
209
- if (reason === "not-offered") {
210
- return `This connector does not settle on "${String(wanted)}". It settles on: ${list}. Set \`chain\` to 'evm' or 'solana' to match one of those, or leave it unset to take the first one this client holds a key for.`;
211
- }
212
- return `This client holds no key for any chain this connector settles on (${list}). Supply a \`mnemonic\` \u2014 which derives both an EVM and a Solana key \u2014 or the raw key for one of those chains.`;
213
- }
214
- var TransactionOutcomeError = class extends ToonClientError {
215
- constructor(message, chain, txHash, outcome, cause) {
216
- super(message, "TRANSACTION_OUTCOME", cause);
217
- this.chain = chain;
218
- this.txHash = txHash;
219
- this.outcome = outcome;
220
- this.name = "TransactionOutcomeError";
221
- }
222
- chain;
223
- txHash;
224
- outcome;
225
- };
226
-
227
42
  // src/btp/protocol.ts
228
43
  var textEncoder = new TextEncoder();
229
44
  var textDecoder = new TextDecoder();
@@ -2704,12 +2519,12 @@ function parseConnectorRouteTerms(body) {
2704
2519
  }
2705
2520
 
2706
2521
  // src/btp/transport-select.ts
2707
- function selectTransport(description, preference = "auto", baseUrl = description.readFrom, destination) {
2708
- const http2 = resolveEndpoint2(description.httpEndpoint, baseUrl);
2709
- const btp = resolveEndpoint2(description.btpEndpoint, baseUrl);
2522
+ function selectTransport(description, preference = "auto", baseUrl = description.readFrom, destination, overrides = {}) {
2523
+ const http = overrides.http ?? resolveEndpoint2(description.httpEndpoint, baseUrl);
2524
+ const btp = overrides.btp ?? resolveEndpoint2(description.btpEndpoint, baseUrl);
2710
2525
  const required = requiredTransportFor(description, destination);
2711
2526
  if (preference === "http" || preference === "btp") {
2712
- const url = preference === "http" ? http2 : btp;
2527
+ const url = preference === "http" ? http : btp;
2713
2528
  if (url === void 0) {
2714
2529
  throw new TransportRequiredError(
2715
2530
  `the connector publishes no ${preference} endpoint` + (required !== void 0 ? `; its self-description requires the ${required} transport` : ""),
@@ -2719,7 +2534,7 @@ function selectTransport(description, preference = "auto", baseUrl = description
2719
2534
  return { kind: preference, url };
2720
2535
  }
2721
2536
  if (required !== void 0) {
2722
- const url = required === "http" ? http2 : btp;
2537
+ const url = required === "http" ? http : btp;
2723
2538
  if (url === void 0) {
2724
2539
  throw new TransportRequiredError(
2725
2540
  `the connector requires the ${required} transport but publishes no ${required} endpoint`,
@@ -2728,7 +2543,7 @@ function selectTransport(description, preference = "auto", baseUrl = description
2728
2543
  }
2729
2544
  return { kind: required, url };
2730
2545
  }
2731
- if (http2 !== void 0) return { kind: "http", url: http2 };
2546
+ if (http !== void 0) return { kind: "http", url: http };
2732
2547
  if (btp !== void 0) return { kind: "btp", url: btp };
2733
2548
  throw new TransportRequiredError(
2734
2549
  "the connector publishes neither an httpEndpoint nor a btpEndpoint"
@@ -3630,6 +3445,7 @@ function resolveConfig(config) {
3630
3445
  const connector = resolveConnector(config.connector);
3631
3446
  const connectorIsHiddenService = isHiddenServiceUrl(connector);
3632
3447
  const socksProxy = resolveSocksProxy(config.socksProxy, connector, connectorIsHiddenService);
3448
+ const carriageEndpoints = resolveCarriageEndpoints(config.carriageEndpoints);
3633
3449
  const accountIndex = resolveAccountIndex(config.accountIndex);
3634
3450
  const keyDerivation = config.keyDerivation ?? "standard";
3635
3451
  const identity = resolveIdentity(config, keyDerivation, accountIndex);
@@ -3672,6 +3488,7 @@ function resolveConfig(config) {
3672
3488
  depositGas: config.depositGas ?? "auto",
3673
3489
  connectorIsHiddenService,
3674
3490
  socksProxy,
3491
+ carriageEndpoints,
3675
3492
  proxyRpc: config.proxyRpc ?? true,
3676
3493
  chainRpc: void 0,
3677
3494
  autoOpenChannel: config.autoOpenChannel ?? true,
@@ -3856,6 +3673,32 @@ function resolveChannelStore(store) {
3856
3673
  );
3857
3674
  return { channelStore: new InMemoryChannelStore(), channelStoreIsEphemeral: true };
3858
3675
  }
3676
+ function resolveCarriageEndpoints(overrides) {
3677
+ const out = {};
3678
+ if (overrides === void 0) return out;
3679
+ const schemes = { http: ["http:", "https:"], btp: ["ws:", "wss:"] };
3680
+ for (const kind of ["http", "btp"]) {
3681
+ const value = overrides[kind];
3682
+ if (value === void 0) continue;
3683
+ const label = `carriageEndpoints.${kind}`;
3684
+ const trimmed = value.trim();
3685
+ let url;
3686
+ try {
3687
+ url = new URL(trimmed);
3688
+ } catch {
3689
+ throw new ConfigError(
3690
+ `${label} must be an absolute URL; got ${JSON.stringify(value)}.`
3691
+ );
3692
+ }
3693
+ if (!schemes[kind].includes(url.protocol)) {
3694
+ throw new ConfigError(
3695
+ `${label} must be a ${schemes[kind].join(" or ")} URL; got ${JSON.stringify(value)}.`
3696
+ );
3697
+ }
3698
+ out[kind] = trimmed;
3699
+ }
3700
+ return out;
3701
+ }
3859
3702
 
3860
3703
  // src/client/channel-facade.ts
3861
3704
  import {
@@ -4328,10 +4171,6 @@ function isAccountNotFoundError(err) {
4328
4171
  err.rpcMessage
4329
4172
  );
4330
4173
  }
4331
- function resolveRpcTarget(target) {
4332
- if (typeof target === "string") return { url: target, fetchImpl: globalThis.fetch };
4333
- return { url: target.url, fetchImpl: target.fetchImpl ?? globalThis.fetch };
4334
- }
4335
4174
  var SOLANA_RPC_RETRY_DELAYS_MS = [250, 500, 1e3];
4336
4175
  var RETRYABLE_HTTP_STATUS = /* @__PURE__ */ new Set([403, 408, 413, 429, 500, 502, 503, 504]);
4337
4176
  var MAX_RETRY_AFTER_MS = 1e4;
@@ -4362,7 +4201,7 @@ var SolanaRpcHttpError = class extends Error {
4362
4201
  retryAfterMs;
4363
4202
  };
4364
4203
  async function solanaRpc(rpcUrl, method, params = []) {
4365
- const { url, fetchImpl } = resolveRpcTarget(rpcUrl);
4204
+ const { url, fetch: fetchImpl } = rpcUrl;
4366
4205
  let mayHaveArrived = false;
4367
4206
  for (let attempt2 = 0; ; attempt2++) {
4368
4207
  try {
@@ -5293,32 +5132,6 @@ async function withdrawSvmBatchChannel(rpc, payer, channelId, config, now = BigI
5293
5132
  };
5294
5133
  }
5295
5134
 
5296
- // src/transport/rpc.ts
5297
- import { http } from "viem";
5298
- var PROXIED_RPC_DEFAULTS = {
5299
- timeout: 3e4,
5300
- retryCount: 3,
5301
- retryDelay: 500
5302
- };
5303
- function rpcTransport(url, dispatcher, options = {}) {
5304
- const { timeout, retryCount, retryDelay } = dispatcher === void 0 ? options : { ...PROXIED_RPC_DEFAULTS, ...definedOnly(options) };
5305
- return http(url, {
5306
- ...timeout !== void 0 ? { timeout } : {},
5307
- ...retryCount !== void 0 ? { retryCount } : {},
5308
- ...retryDelay !== void 0 ? { retryDelay } : {},
5309
- ...dispatcher !== void 0 ? { fetchOptions: { dispatcher } } : {}
5310
- });
5311
- }
5312
- function definedOnly(options) {
5313
- return Object.fromEntries(
5314
- Object.entries(options).filter(([, value]) => value !== void 0)
5315
- );
5316
- }
5317
- function rpcFetch(dispatcher, fetchImpl = globalThis.fetch) {
5318
- if (dispatcher === void 0) return fetchImpl;
5319
- return ((input, init) => fetchImpl(input, { ...init, dispatcher }));
5320
- }
5321
-
5322
5135
  // src/client/channel-facade.ts
5323
5136
  var ClientChannelFacade = class {
5324
5137
  constructor(deps) {
@@ -5519,10 +5332,10 @@ var ClientChannelFacade = class {
5519
5332
  id: evmChainIdOf(network),
5520
5333
  name: network,
5521
5334
  nativeCurrency: { name: "ETH", symbol: "ETH", decimals: 18 },
5522
- rpcUrls: { default: { http: [evm.rpcUrl] } }
5335
+ rpcUrls: { default: { http: [evm.rpc.url] } }
5523
5336
  });
5524
5337
  const account = privateKeyToAccount(toHexKey(evm.privateKey));
5525
- const transport = rpcTransport(evm.rpcUrl, evm.rpcDispatcher);
5338
+ const transport = rpcTransport(evm.rpc);
5526
5339
  const publicClient = createPublicClient({ chain, transport });
5527
5340
  const walletClient = createWalletClient({ account, chain, transport });
5528
5341
  return {
@@ -5581,13 +5394,22 @@ function rpcAbortSignal(proxied = false) {
5581
5394
  const ms = rpcTimeoutMs(proxied);
5582
5395
  return ms > 0 ? AbortSignal.timeout(ms) : void 0;
5583
5396
  }
5397
+ function evmReadRoute(opts) {
5398
+ return {
5399
+ url: opts.rpcUrl,
5400
+ fetch: opts.evmRpcFetch ?? directFetch,
5401
+ proxied: opts.proxied ?? opts.evmRpcFetch !== void 0
5402
+ };
5403
+ }
5404
+ function evmReadTransport(opts) {
5405
+ const route = evmReadRoute(opts);
5406
+ const timeout = rpcTimeoutMs(route.proxied);
5407
+ return rpcTransport(route, { ...timeout ? { timeout } : {}, retryCount: 1 });
5408
+ }
5584
5409
  async function readEvmTokenBalance(opts) {
5585
5410
  const chainId = parseEvmChainId(opts.chainKey);
5586
5411
  const client = createPublicClient2({
5587
- transport: rpcTransport(opts.rpcUrl, opts.rpcDispatcher, {
5588
- ...rpcTimeoutMs(opts.rpcDispatcher !== void 0) ? { timeout: rpcTimeoutMs(opts.rpcDispatcher !== void 0) } : {},
5589
- retryCount: 1
5590
- }),
5412
+ transport: evmReadTransport(opts),
5591
5413
  chain: defineChain2({
5592
5414
  id: chainId,
5593
5415
  name: opts.chainKey,
@@ -5610,10 +5432,7 @@ async function readEvmTokenBalance(opts) {
5610
5432
  async function readEvmNativeBalance(opts) {
5611
5433
  const chainId = parseEvmChainId(opts.chainKey);
5612
5434
  const client = createPublicClient2({
5613
- transport: rpcTransport(opts.rpcUrl, opts.rpcDispatcher, {
5614
- ...rpcTimeoutMs(opts.rpcDispatcher !== void 0) ? { timeout: rpcTimeoutMs(opts.rpcDispatcher !== void 0) } : {},
5615
- retryCount: 1
5616
- }),
5435
+ transport: evmReadTransport(opts),
5617
5436
  chain: defineChain2({
5618
5437
  id: chainId,
5619
5438
  name: opts.chainKey,
@@ -5625,7 +5444,7 @@ async function readEvmNativeBalance(opts) {
5625
5444
  return { symbol: "ETH", amount: wei.toString(), decimals: 18 };
5626
5445
  }
5627
5446
  async function readSolanaNativeBalance(opts) {
5628
- const fetchImpl = opts.fetchImpl ?? fetch;
5447
+ const fetchImpl = opts.fetchImpl ?? directFetch;
5629
5448
  const res = await fetchImpl(opts.rpcUrl, {
5630
5449
  method: "POST",
5631
5450
  headers: { "content-type": "application/json" },
@@ -5644,7 +5463,7 @@ async function readSolanaNativeBalance(opts) {
5644
5463
  return { symbol: "SOL", amount: lamports.toString(), decimals: 9 };
5645
5464
  }
5646
5465
  async function readSolanaTokenBalance(opts) {
5647
- const fetchImpl = opts.fetchImpl ?? fetch;
5466
+ const fetchImpl = opts.fetchImpl ?? directFetch;
5648
5467
  const res = await fetchImpl(opts.rpcUrl, {
5649
5468
  method: "POST",
5650
5469
  headers: { "content-type": "application/json" },
@@ -5697,14 +5516,14 @@ async function readWalletBalances(sources) {
5697
5516
  const { fetchImpl, solanaProxied: proxied } = sources;
5698
5517
  const tasks = [];
5699
5518
  if (sources.evm) {
5700
- const { chainKey, rpcUrl, owner, tokenAddress, rpcDispatcher } = sources.evm;
5519
+ const { chainKey, rpcUrl, owner, tokenAddress, evmRpcFetch, proxied: evmProxied } = sources.evm;
5701
5520
  tasks.push(
5702
5521
  (async () => {
5703
5522
  const out = { chain: "evm", chainKey, address: owner, tokens: [] };
5704
5523
  const errors = [];
5705
5524
  const [nativeR, tokenR] = await Promise.allSettled([
5706
- readEvmNativeBalance({ rpcUrl, chainKey, owner, rpcDispatcher }),
5707
- tokenAddress ? readEvmTokenBalance({ rpcUrl, chainKey, tokenAddress, owner, rpcDispatcher }) : Promise.resolve(void 0)
5525
+ readEvmNativeBalance({ rpcUrl, chainKey, owner, evmRpcFetch, proxied: evmProxied }),
5526
+ tokenAddress ? readEvmTokenBalance({ rpcUrl, chainKey, tokenAddress, owner, evmRpcFetch, proxied: evmProxied }) : Promise.resolve(void 0)
5708
5527
  ]);
5709
5528
  foldNative(out, nativeR, errors);
5710
5529
  foldToken(out, tokenR, tokenAddress, errors);
@@ -5824,7 +5643,14 @@ var ERC20_TRANSFER_ABI = [
5824
5643
  }
5825
5644
  ];
5826
5645
  function solanaRpcTarget(cfg) {
5827
- return cfg.rpcFetch === void 0 ? cfg.rpcUrl : { url: cfg.rpcUrl, fetchImpl: cfg.rpcFetch };
5646
+ return { url: cfg.rpcUrl, fetch: cfg.rpcFetch ?? directFetch };
5647
+ }
5648
+ function evmRpcRoute(cfg) {
5649
+ return {
5650
+ url: cfg.rpcUrl,
5651
+ fetch: cfg.evmRpcFetch ?? directFetch,
5652
+ proxied: cfg.proxied ?? cfg.evmRpcFetch !== void 0
5653
+ };
5828
5654
  }
5829
5655
  function evmClients(cfg) {
5830
5656
  const chainId = parseEvmChainId(cfg.chainKey);
@@ -5835,12 +5661,12 @@ function evmClients(cfg) {
5835
5661
  rpcUrls: { default: { http: [cfg.rpcUrl] } }
5836
5662
  });
5837
5663
  const publicClient = createPublicClient3({
5838
- transport: rpcTransport(cfg.rpcUrl, cfg.rpcDispatcher),
5664
+ transport: rpcTransport(evmRpcRoute(cfg)),
5839
5665
  chain: viemChain
5840
5666
  });
5841
5667
  const walletClient = createWalletClient2({
5842
5668
  account: cfg.signer.account,
5843
- transport: rpcTransport(cfg.rpcUrl, cfg.rpcDispatcher),
5669
+ transport: rpcTransport(evmRpcRoute(cfg)),
5844
5670
  chain: viemChain
5845
5671
  });
5846
5672
  return { publicClient, walletClient };
@@ -6165,14 +5991,25 @@ var EvmSigner = class {
6165
5991
  }
6166
5992
  };
6167
5993
 
6168
- // src/client/wallet-facade.ts
6169
- function solanaRpcFetch(config) {
6170
- if (config.socksProxy === void 0) return config.fetch;
6171
- return config.chainRpc?.solana.fetch ?? globalThis.fetch;
6172
- }
6173
- function evmRpcDispatcher(config) {
6174
- return config.chainRpc !== void 0 ? { rpcDispatcher: config.chainRpc.evm.dispatcher } : {};
5994
+ // src/client/chain-access.ts
5995
+ function chainRoutes(config) {
5996
+ const { chainRpc, rpcUrls } = config;
5997
+ if (chainRpc !== void 0) {
5998
+ return {
5999
+ evm: { url: rpcUrls.evm, fetch: chainRpc.evm.fetch, proxied: true },
6000
+ solana: { url: rpcUrls.solana, fetch: chainRpc.solana.fetch, proxied: true }
6001
+ };
6002
+ }
6003
+ return {
6004
+ evm: { url: rpcUrls.evm, fetch: directFetch },
6005
+ solana: {
6006
+ url: rpcUrls.solana,
6007
+ fetch: config.socksProxy === void 0 ? config.fetch : directFetch
6008
+ }
6009
+ };
6175
6010
  }
6011
+
6012
+ // src/client/wallet-facade.ts
6176
6013
  var ClientWalletFacade = class {
6177
6014
  deps;
6178
6015
  evmSigner;
@@ -6191,25 +6028,27 @@ var ClientWalletFacade = class {
6191
6028
  const { config } = this.deps;
6192
6029
  const settlements = await this.settlements();
6193
6030
  const wanted = chain !== void 0 ? [chain] : ["evm", "solana"];
6031
+ const routes = chainRoutes(config);
6194
6032
  const sources = {
6195
- fetchImpl: solanaRpcFetch(config),
6196
- ...config.chainRpc !== void 0 ? { solanaProxied: true } : {}
6033
+ fetchImpl: routes.solana.fetch,
6034
+ solanaProxied: routes.solana.proxied === true
6197
6035
  };
6198
6036
  for (const kind of wanted) {
6199
6037
  const entry = settlements.get(kind);
6200
6038
  if (kind === "evm" && config.identity.evm) {
6201
6039
  sources.evm = {
6202
6040
  chainKey: entry?.chain ?? "evm",
6203
- rpcUrl: config.rpcUrls.evm,
6041
+ rpcUrl: routes.evm.url,
6204
6042
  owner: config.identity.evm.address,
6205
- ...evmRpcDispatcher(config),
6043
+ evmRpcFetch: routes.evm.fetch,
6044
+ proxied: routes.evm.proxied === true,
6206
6045
  ...entry?.tokenAddress ? { tokenAddress: entry.tokenAddress } : {}
6207
6046
  };
6208
6047
  }
6209
6048
  if (kind === "solana" && config.identity.solana) {
6210
6049
  sources.solana = {
6211
6050
  ...entry?.chain ? { chainKey: entry.chain } : {},
6212
- rpcUrl: config.rpcUrls.solana,
6051
+ rpcUrl: routes.solana.url,
6213
6052
  owner: config.identity.solana.publicKey,
6214
6053
  ...entry?.tokenAddress ? { tokenMint: entry.tokenAddress } : {}
6215
6054
  };
@@ -6236,21 +6075,23 @@ var ClientWalletFacade = class {
6236
6075
  const { config } = this.deps;
6237
6076
  const settlements = await this.settlements();
6238
6077
  const entry = settlements.get(params.chain);
6078
+ const routes = chainRoutes(config);
6239
6079
  return sendTransfer(
6240
6080
  {
6241
6081
  ...config.identity.evm ? {
6242
6082
  evm: {
6243
6083
  chainKey: entry?.kind === "evm" ? entry.chain : "evm",
6244
- rpcUrl: config.rpcUrls.evm,
6084
+ rpcUrl: routes.evm.url,
6245
6085
  signer: this.signer(),
6246
- ...evmRpcDispatcher(config),
6086
+ evmRpcFetch: routes.evm.fetch,
6087
+ proxied: routes.evm.proxied === true,
6247
6088
  ...entry?.tokenAddress ? { tokenAddress: entry.tokenAddress } : {}
6248
6089
  }
6249
6090
  } : {},
6250
6091
  ...config.identity.solana ? {
6251
6092
  solana: {
6252
- rpcUrl: config.rpcUrls.solana,
6253
- ...config.chainRpc !== void 0 ? { rpcFetch: config.chainRpc.solana.fetch } : {},
6093
+ rpcUrl: routes.solana.url,
6094
+ rpcFetch: routes.solana.fetch,
6254
6095
  keypair: config.identity.solana.secretKey,
6255
6096
  ...entry?.tokenAddress ? { tokenMint: entry.tokenAddress } : {}
6256
6097
  }
@@ -6408,7 +6249,7 @@ var EIP2612_PERMIT_TYPES = {
6408
6249
  };
6409
6250
  function evmWalletAccess(params) {
6410
6251
  const { account } = params;
6411
- const transport = rpcTransport(params.rpcUrl, params.dispatcher);
6252
+ const transport = rpcTransport(params.rpc);
6412
6253
  const reader = createPublicClient4({ transport });
6413
6254
  let writer;
6414
6255
  const wallet = () => writer ??= reader.getChainId().then(
@@ -6419,7 +6260,7 @@ function evmWalletAccess(params) {
6419
6260
  id,
6420
6261
  name: `eip155:${id}`,
6421
6262
  nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
6422
- rpcUrls: { default: { http: [params.rpcUrl] } }
6263
+ rpcUrls: { default: { http: [params.rpc.url] } }
6423
6264
  })
6424
6265
  })
6425
6266
  );
@@ -6452,7 +6293,7 @@ async function eip2612Nonce(reader, token, owner) {
6452
6293
  return void 0;
6453
6294
  }
6454
6295
  }
6455
- async function facilitatorExtensions(facilitatorUrl, fetchImpl = fetch) {
6296
+ async function facilitatorExtensions(facilitatorUrl, fetchImpl = directFetch) {
6456
6297
  const url = `${facilitatorUrl.replace(/\/+$/, "")}/supported`;
6457
6298
  let body;
6458
6299
  try {
@@ -6631,7 +6472,7 @@ async function settleDeposit(params) {
6631
6472
  withdrawDelay: payload.channelConfig.withdrawDelay
6632
6473
  }
6633
6474
  };
6634
- const fetchImpl = params.fetchImpl ?? fetch;
6475
+ const fetchImpl = params.fetchImpl ?? directFetch;
6635
6476
  const url = `${params.facilitatorUrl.replace(/\/+$/, "")}/settle`;
6636
6477
  let response;
6637
6478
  let text;
@@ -6739,7 +6580,7 @@ async function requestSponsoredOpen(params) {
6739
6580
  params.sponsorEndpoint,
6740
6581
  `${params.connector.replace(/\/+$/, "")}/`
6741
6582
  ).toString();
6742
- const fetchImpl = params.fetchImpl ?? fetch;
6583
+ const fetchImpl = params.fetchImpl ?? directFetch;
6743
6584
  let response;
6744
6585
  let text;
6745
6586
  try {
@@ -7265,7 +7106,7 @@ var BatchSettlementPayer = class {
7265
7106
  offer: { ...offer, extra: { ...offer.extra, assetTransferMethod: method } },
7266
7107
  payload,
7267
7108
  ...extensions ? { extensions } : {},
7268
- ...this.config.fetch ? { fetchImpl: this.config.fetch } : {}
7109
+ fetchImpl: this.config.fetch
7269
7110
  });
7270
7111
  } catch (err) {
7271
7112
  const retry = mode === "auto" && extensions === void 0 && facilitatorCannotHandle(err) && await holdsEth(evm.wallet);
@@ -7404,7 +7245,7 @@ var BatchSettlementPayer = class {
7404
7245
  connector: this.config.connector,
7405
7246
  sponsorEndpoint,
7406
7247
  transaction,
7407
- ...this.config.fetch ? { fetchImpl: this.config.fetch } : {}
7248
+ fetchImpl: this.config.fetch
7408
7249
  });
7409
7250
  } catch (err) {
7410
7251
  if (isDefinitiveRefusal(err)) manager.abandon(channelId);
@@ -8118,7 +7959,8 @@ var ToonClient = class _ToonClient {
8118
7959
  senderId: init.senderId
8119
7960
  };
8120
7961
  this.manager = new BatchChannelManager(init.config.channelStore);
8121
- const chains = chainAccess(init.config);
7962
+ const routes = chainRoutes(init.config);
7963
+ const chains = chainAccess(init.config, routes.solana);
8122
7964
  this.payer = new BatchSettlementPayer({
8123
7965
  connector: init.config.connector,
8124
7966
  manager: this.manager,
@@ -8129,12 +7971,8 @@ var ToonClient = class _ToonClient {
8129
7971
  ...init.config.facilitatorUrl !== void 0 ? { facilitatorUrl: init.config.facilitatorUrl } : {},
8130
7972
  ...init.config.depositMethod !== void 0 ? { depositMethod: init.config.depositMethod } : {},
8131
7973
  depositGas: init.config.depositGas,
8132
- reader: lazyEvmReader(init.config),
8133
- wallet: evmWalletAccess({
8134
- rpcUrl: init.config.rpcUrls.evm,
8135
- account: chains.evm.account,
8136
- dispatcher: init.config.chainRpc?.evm.dispatcher
8137
- })
7974
+ reader: lazyEvmReader(routes.evm),
7975
+ wallet: evmWalletAccess({ rpc: routes.evm, account: chains.evm.account })
8138
7976
  }
8139
7977
  } : {},
8140
7978
  ...chains.solana !== void 0 ? { solana: chains.solana } : {},
@@ -8151,8 +7989,7 @@ var ToonClient = class _ToonClient {
8151
7989
  ...chains.evm !== void 0 ? {
8152
7990
  evm: {
8153
7991
  privateKey: chains.evm.privateKey,
8154
- rpcUrl: init.config.rpcUrls.evm,
8155
- rpcDispatcher: init.config.chainRpc?.evm.dispatcher
7992
+ rpc: routes.evm
8156
7993
  }
8157
7994
  } : {},
8158
7995
  ...chains.solana !== void 0 ? { solana: chains.solana } : {}
@@ -8175,6 +8012,9 @@ var ToonClient = class _ToonClient {
8175
8012
  */
8176
8013
  static async create(config) {
8177
8014
  const base = resolveConfig(config);
8015
+ for (const override of Object.values(base.carriageEndpoints)) {
8016
+ assertReachableWithoutProxy(override, base.socksProxy, "override");
8017
+ }
8178
8018
  const hiddenService = await openHiddenService(base, config);
8179
8019
  const resolved = hiddenService?.config ?? base;
8180
8020
  const edge = new ConnectorEdgeClient({
@@ -8362,11 +8202,7 @@ var ToonClient = class _ToonClient {
8362
8202
  * this fails loudly, naming the proxy, before anything dials.
8363
8203
  */
8364
8204
  assertEndpointReachable(endpoint) {
8365
- if (this.config.socksProxy !== void 0) return;
8366
- if (!isHiddenServiceUrl(endpoint)) return;
8367
- throw new ConfigError(
8368
- `The connector published the endpoint ${JSON.stringify(endpoint)}, which is a hidden service, but this client has no \`socksProxy\` to reach it through. Set one to a running Anyone Protocol \`anon\` daemon (e.g. "socks5h://127.0.0.1:9050"), or ask the operator for a clearnet endpoint.`
8369
- );
8205
+ assertReachableWithoutProxy(endpoint, this.config.socksProxy, "published");
8370
8206
  }
8371
8207
  /** The port {@link send} runs against. */
8372
8208
  sendContext() {
@@ -8428,21 +8264,37 @@ var ToonClient = class _ToonClient {
8428
8264
  if (this.closed) {
8429
8265
  throw new ConfigError("This client has been closed; construct a new one to send again.");
8430
8266
  }
8431
- const choice = selectTransport(description, this.config.transport, void 0, destination);
8267
+ const overrides = this.config.carriageEndpoints;
8268
+ const choice = selectTransport(
8269
+ description,
8270
+ this.config.transport,
8271
+ void 0,
8272
+ destination,
8273
+ overrides
8274
+ );
8432
8275
  const cached = this.carriages[choice.kind];
8433
8276
  if (cached) return cached;
8434
- const httpEndpoint = choice.kind === "http" ? choice.url : httpEndpointOf(description, this.connector);
8277
+ const httpEndpoint = choice.kind === "http" ? choice.url : overrides.http ?? httpEndpointOf(description, this.connector);
8435
8278
  this.assertEndpointReachable(choice.url);
8436
8279
  this.assertEndpointReachable(httpEndpoint);
8437
- const http2 = new HttpIlpClient({
8280
+ const sourceOf = (kind) => {
8281
+ const published = description[kind === "http" ? "httpEndpoint" : "btpEndpoint"];
8282
+ if (overrides[kind] !== void 0) {
8283
+ return { override: published !== void 0 ? { published } : {} };
8284
+ }
8285
+ return published !== void 0 ? "published" : void 0;
8286
+ };
8287
+ const httpSource = sourceOf("http");
8288
+ const btpSource = sourceOf("btp");
8289
+ const http = new HttpIlpClient({
8438
8290
  httpEndpoint,
8439
- ...description.httpEndpoint !== void 0 ? { endpointSource: "published" } : {},
8291
+ ...httpSource !== void 0 ? { endpointSource: httpSource } : {},
8440
8292
  timeout: this.config.timeoutMs,
8441
8293
  httpClient: this.config.fetch,
8442
8294
  ...this.config.createWebSocket ? { createWebSocket: this.config.createWebSocket } : {}
8443
8295
  });
8444
8296
  if (choice.kind === "http") {
8445
- const carriage2 = { kind: "http", transport: http2 };
8297
+ const carriage2 = { kind: "http", transport: http };
8446
8298
  this.carriages.http = carriage2;
8447
8299
  return carriage2;
8448
8300
  }
@@ -8464,14 +8316,14 @@ var ToonClient = class _ToonClient {
8464
8316
  transport: new BtpPaidWriteTransport({
8465
8317
  session,
8466
8318
  url: choice.url,
8467
- endpointSource: "published",
8319
+ ...btpSource !== void 0 ? { endpointSource: btpSource } : {},
8468
8320
  // HTTP fallback only where the node did not REQUIRE btp *for this
8469
8321
  // destination*: falling back onto a carriage the route refuses would
8470
8322
  // turn a recoverable socket outage into a `402` per request. Read
8471
8323
  // through the same per-route resolution the choice above was made with,
8472
8324
  // so the fallback cannot be enabled against a route the node-wide field
8473
8325
  // happens not to describe (TOON_Network#111).
8474
- ...requiredTransportFor(description, destination) === "btp" ? {} : { fallback: http2 },
8326
+ ...requiredTransportFor(description, destination) === "btp" ? {} : { fallback: http },
8475
8327
  ...this.config.btp.maxReconnectAttempts !== void 0 ? { maxReconnectAttempts: this.config.btp.maxReconnectAttempts } : {},
8476
8328
  ...this.config.btp.reconnectDelay !== void 0 ? { reconnectDelay: this.config.btp.reconnectDelay } : {}
8477
8329
  })
@@ -8513,6 +8365,17 @@ function pickChain(config, description) {
8513
8365
  }
8514
8366
  return match.chain;
8515
8367
  }
8368
+ function assertReachableWithoutProxy(endpoint, socksProxy, chosenBy) {
8369
+ if (socksProxy !== void 0) return;
8370
+ if (!isHiddenServiceUrl(endpoint)) return;
8371
+ const [subject, alternative] = chosenBy === "published" ? [
8372
+ "The connector published the endpoint",
8373
+ "ask the operator for a clearnet endpoint"
8374
+ ] : ["The carriage endpoint override", "use a clearnet override"];
8375
+ throw new ConfigError(
8376
+ `${subject} ${JSON.stringify(endpoint)}, which is a hidden service, but this client has no \`socksProxy\` to reach it through. Set one to a running Anyone Protocol \`anon\` daemon (e.g. "socks5h://127.0.0.1:9050"), or ${alternative}.`
8377
+ );
8378
+ }
8516
8379
  function httpEndpointOf(description, connector) {
8517
8380
  const published = description.httpEndpoint;
8518
8381
  if (published === void 0) return `${connector}/ilp`;
@@ -8521,31 +8384,41 @@ function httpEndpointOf(description, connector) {
8521
8384
  async function openHiddenService(resolved, config) {
8522
8385
  const socksProxy = resolved.socksProxy;
8523
8386
  if (socksProxy === void 0) return void 0;
8524
- const { createChainRpcTransport, createHiddenServiceTransport, probeSocks5Proxy } = await import("./socks-KNSFCLBG.js");
8387
+ const { createChainRpcTransport, createHiddenServiceTransport, probeSocks5Proxy } = await import("./socks-OGGKES7C.js");
8388
+ const { proveProxy } = await import("./canary-FYKD66CX.js");
8525
8389
  await probeSocks5Proxy(socksProxy);
8526
8390
  const edge = createHiddenServiceTransport(socksProxy);
8527
8391
  const rpc = resolved.proxyRpc ? {
8528
8392
  evm: createChainRpcTransport(socksProxy, "evm"),
8529
8393
  solana: createChainRpcTransport(socksProxy, "solana")
8530
8394
  } : void 0;
8395
+ const close = async () => {
8396
+ await Promise.all([edge.close(), rpc?.evm.close(), rpc?.solana.close()]);
8397
+ };
8398
+ try {
8399
+ await proveProxy({
8400
+ edge,
8401
+ ...rpc !== void 0 ? { rpc } : {},
8402
+ ...config.canaryPaths !== void 0 ? { overrides: config.canaryPaths } : {}
8403
+ });
8404
+ } catch (err) {
8405
+ await close().catch(() => void 0);
8406
+ throw err;
8407
+ }
8531
8408
  return {
8532
- transport: {
8533
- async close() {
8534
- await Promise.all([edge.close(), rpc?.evm.close(), rpc?.solana.close()]);
8535
- }
8536
- },
8409
+ transport: { close },
8537
8410
  config: {
8538
8411
  ...resolved,
8539
8412
  fetch: config.fetch ?? edge.fetch,
8540
8413
  createWebSocket: config.createWebSocket ?? edge.createWebSocket,
8541
8414
  chainRpc: rpc === void 0 ? void 0 : {
8542
- evm: { dispatcher: rpc.evm.dispatcher, fetch: rpc.evm.fetch },
8543
- solana: { dispatcher: rpc.solana.dispatcher, fetch: rpc.solana.fetch }
8415
+ evm: { fetch: rpc.evm.fetch },
8416
+ solana: { fetch: rpc.solana.fetch }
8544
8417
  }
8545
8418
  }
8546
8419
  };
8547
8420
  }
8548
- function chainAccess(config) {
8421
+ function chainAccess(config, solanaRpc2) {
8549
8422
  const evmKey = config.identity.evm?.privateKey;
8550
8423
  const solanaKey = config.identity.solana;
8551
8424
  return {
@@ -8556,20 +8429,17 @@ function chainAccess(config) {
8556
8429
  privateKey: solanaKey.secretKey.slice(0, 32),
8557
8430
  publicKey: base58Decode(solanaKey.publicKey)
8558
8431
  },
8559
- rpc: {
8560
- url: config.rpcUrls.solana,
8561
- ...config.chainRpc !== void 0 ? { fetchImpl: config.chainRpc.solana.fetch } : {}
8562
- }
8432
+ rpc: solanaRpc2
8563
8433
  }
8564
8434
  } : {}
8565
8435
  };
8566
8436
  }
8567
- function lazyEvmReader(config) {
8437
+ function lazyEvmReader(route) {
8568
8438
  let client;
8569
8439
  return {
8570
8440
  readContract: (params) => {
8571
8441
  client ??= createPublicClient5({
8572
- transport: rpcTransport(config.rpcUrls.evm, config.chainRpc?.evm.dispatcher)
8442
+ transport: rpcTransport(route)
8573
8443
  });
8574
8444
  return client.readContract(params);
8575
8445
  }
@@ -8577,31 +8447,6 @@ function lazyEvmReader(config) {
8577
8447
  }
8578
8448
 
8579
8449
  export {
8580
- ToonClientError,
8581
- NetworkError,
8582
- describeEndpoint,
8583
- ConnectorError,
8584
- ValidationError,
8585
- ConfigError,
8586
- ChainUnavailableError,
8587
- ChannelNotOpenError,
8588
- RouteNotPricedError,
8589
- BeforePayRefusedError,
8590
- PaymentRequiredError,
8591
- TransportRequiredError,
8592
- ChannelFundingError,
8593
- ChannelResumeError,
8594
- InsufficientBalanceError,
8595
- StaleRpcReadError,
8596
- UnknownChainError,
8597
- InvalidAddressError,
8598
- TransferNotDeliveredError,
8599
- TransferUnsupportedError,
8600
- FacilitatorError,
8601
- SponsorRefusedError,
8602
- isInsufficientGasError,
8603
- chainUnavailableMessage,
8604
- TransactionOutcomeError,
8605
8450
  BTPMessageType,
8606
8451
  ILPPacketType,
8607
8452
  serializeIlpPrepare,
@@ -8747,9 +8592,6 @@ export {
8747
8592
  buildSvmWithdrawPayerInstruction,
8748
8593
  requestSvmBatchClose,
8749
8594
  withdrawSvmBatchChannel,
8750
- PROXIED_RPC_DEFAULTS,
8751
- rpcTransport,
8752
- rpcFetch,
8753
8595
  ClientChannelFacade,
8754
8596
  readEvmTokenBalance,
8755
8597
  readEvmNativeBalance,
@@ -8792,4 +8634,4 @@ export {
8792
8634
  toEnvelopeRequest,
8793
8635
  ToonClient
8794
8636
  };
8795
- //# sourceMappingURL=chunk-GNPJRJ6U.js.map
8637
+ //# sourceMappingURL=chunk-KGT4XOBZ.js.map