@toon-protocol/client 3.1.1 → 3.3.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.
- package/dist/{chunk-KQE6S23B.js → chunk-G36D22II.js} +360 -112
- package/dist/chunk-G36D22II.js.map +1 -0
- package/dist/{chunk-GOLBDUNV.js → chunk-LJSOTVUT.js} +36 -3
- package/dist/chunk-LJSOTVUT.js.map +1 -0
- package/dist/{chunk-7MPONJW5.js → chunk-O6KX7MHD.js} +4 -4
- package/dist/{chunk-7MPONJW5.js.map → chunk-O6KX7MHD.js.map} +1 -1
- package/dist/{chunk-4I3JQ7KA.js → chunk-PTTRHLYV.js} +2 -2
- package/dist/cli/main.js +11 -4
- package/dist/cli/main.js.map +1 -1
- package/dist/{client-AV355FHQ.js → client-FFEFAMJ4.js} +7 -3
- package/dist/hidden-service-BsBH2HNi.d.ts +301 -0
- package/dist/index.d.ts +270 -157
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/dist/socks-K6QOOWJ5.js +23 -0
- package/dist/transport/hidden-service.d.ts +1 -116
- package/dist/transport/hidden-service.js +9 -1
- package/package.json +1 -1
- package/dist/chunk-GOLBDUNV.js.map +0 -1
- package/dist/chunk-KQE6S23B.js.map +0 -1
- package/dist/socks-CCMHMB35.js +0 -15
- /package/dist/{chunk-4I3JQ7KA.js.map → chunk-PTTRHLYV.js.map} +0 -0
- /package/dist/{client-AV355FHQ.js.map → client-FFEFAMJ4.js.map} +0 -0
- /package/dist/{socks-CCMHMB35.js.map → socks-K6QOOWJ5.js.map} +0 -0
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
deriveFullIdentity,
|
|
8
8
|
evmIdentityFromKey,
|
|
9
9
|
isHiddenServiceUrl
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-O6KX7MHD.js";
|
|
11
11
|
import {
|
|
12
12
|
validateSocks5hUrl
|
|
13
13
|
} from "./chunk-32MD3CXE.js";
|
|
@@ -66,6 +66,24 @@ var RouteNotPricedError = class extends ToonClientError {
|
|
|
66
66
|
this.name = "RouteNotPricedError";
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
|
+
var BeforePayRefusedError = class extends ToonClientError {
|
|
70
|
+
/** The reason the hook returned, verbatim. */
|
|
71
|
+
reason;
|
|
72
|
+
/** The route the refused packet was addressed to. */
|
|
73
|
+
destination;
|
|
74
|
+
/** The resolved price the hook was shown, in base units. */
|
|
75
|
+
amount;
|
|
76
|
+
constructor(reason, destination, amount) {
|
|
77
|
+
super(
|
|
78
|
+
`beforePay refused this send to "${destination}" for ${amount.toString()}: ${reason}`,
|
|
79
|
+
"BEFORE_PAY_REFUSED"
|
|
80
|
+
);
|
|
81
|
+
this.name = "BeforePayRefusedError";
|
|
82
|
+
this.reason = reason;
|
|
83
|
+
this.destination = destination;
|
|
84
|
+
this.amount = amount;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
69
87
|
var PaymentRequiredError = class extends ToonClientError {
|
|
70
88
|
/** The route's terms, parsed from the x402 challenge body. */
|
|
71
89
|
terms;
|
|
@@ -163,6 +181,18 @@ function chainUnavailableMessage(wanted, offered, reason) {
|
|
|
163
181
|
}
|
|
164
182
|
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.`;
|
|
165
183
|
}
|
|
184
|
+
var TransactionOutcomeError = class extends ToonClientError {
|
|
185
|
+
constructor(message, chain, txHash, outcome, cause) {
|
|
186
|
+
super(message, "TRANSACTION_OUTCOME", cause);
|
|
187
|
+
this.chain = chain;
|
|
188
|
+
this.txHash = txHash;
|
|
189
|
+
this.outcome = outcome;
|
|
190
|
+
this.name = "TransactionOutcomeError";
|
|
191
|
+
}
|
|
192
|
+
chain;
|
|
193
|
+
txHash;
|
|
194
|
+
outcome;
|
|
195
|
+
};
|
|
166
196
|
|
|
167
197
|
// src/btp/protocol.ts
|
|
168
198
|
var textEncoder = new TextEncoder();
|
|
@@ -549,6 +579,9 @@ function readString(obj, key) {
|
|
|
549
579
|
const v = obj[key];
|
|
550
580
|
return typeof v === "string" && v.trim().length > 0 ? v.trim() : void 0;
|
|
551
581
|
}
|
|
582
|
+
function readRequiredTransport(value) {
|
|
583
|
+
return value === "http" || value === "btp" ? value : void 0;
|
|
584
|
+
}
|
|
552
585
|
function readBaseUnits(value) {
|
|
553
586
|
if (typeof value === "bigint") return value;
|
|
554
587
|
if (typeof value === "number" && Number.isFinite(value)) return BigInt(Math.trunc(value));
|
|
@@ -609,14 +642,15 @@ function parseSelfDescription(body, readFrom) {
|
|
|
609
642
|
const price = readBaseUnits(r["price"]);
|
|
610
643
|
if (prefix === void 0 || price === void 0) return void 0;
|
|
611
644
|
const pricePerKib = readBaseUnits(r["pricePerKib"] ?? r["price_per_kib"]);
|
|
645
|
+
const routeTransport = readRequiredTransport(r["requiredTransport"]);
|
|
612
646
|
return {
|
|
613
647
|
prefix,
|
|
614
648
|
price,
|
|
615
|
-
...pricePerKib !== void 0 ? { pricePerKib } : {}
|
|
649
|
+
...pricePerKib !== void 0 ? { pricePerKib } : {},
|
|
650
|
+
...routeTransport !== void 0 ? { requiredTransport: routeTransport } : {}
|
|
616
651
|
};
|
|
617
652
|
}).filter((r) => r !== void 0) : [];
|
|
618
|
-
const
|
|
619
|
-
const requiredTransport = required === "http" || required === "btp" ? required : void 0;
|
|
653
|
+
const requiredTransport = readRequiredTransport(b["requiredTransport"]);
|
|
620
654
|
const supportedVersions = Array.isArray(b["supportedVersions"]) ? b["supportedVersions"].filter((v) => typeof v === "number") : [1];
|
|
621
655
|
const defaultVersion = typeof b["defaultVersion"] === "number" ? b["defaultVersion"] : 1;
|
|
622
656
|
const httpEndpoint = readString(b, "httpEndpoint");
|
|
@@ -651,6 +685,10 @@ function routeFor(desc, destination) {
|
|
|
651
685
|
}
|
|
652
686
|
return best;
|
|
653
687
|
}
|
|
688
|
+
function requiredTransportFor(desc, destination) {
|
|
689
|
+
const route = destination !== void 0 ? routeFor(desc, destination) : void 0;
|
|
690
|
+
return route?.requiredTransport ?? desc.requiredTransport;
|
|
691
|
+
}
|
|
654
692
|
|
|
655
693
|
// src/utils/binary.ts
|
|
656
694
|
function toBase64(bytes) {
|
|
@@ -828,9 +866,9 @@ var IsomorphicBtpClient = class {
|
|
|
828
866
|
};
|
|
829
867
|
this.ws.onclose = () => {
|
|
830
868
|
this._isConnected = false;
|
|
831
|
-
for (const [id,
|
|
832
|
-
clearTimeout(
|
|
833
|
-
|
|
869
|
+
for (const [id, pending2] of this.pendingRequests) {
|
|
870
|
+
clearTimeout(pending2.timeoutId);
|
|
871
|
+
pending2.reject(new BtpConnectionError("Connection closed"));
|
|
834
872
|
this.pendingRequests.delete(id);
|
|
835
873
|
}
|
|
836
874
|
this.failInFlightInbound("Connection closed before inbound request could be answered");
|
|
@@ -843,9 +881,9 @@ var IsomorphicBtpClient = class {
|
|
|
843
881
|
this.ws.close();
|
|
844
882
|
this.ws = null;
|
|
845
883
|
}
|
|
846
|
-
for (const [id,
|
|
847
|
-
clearTimeout(
|
|
848
|
-
|
|
884
|
+
for (const [id, pending2] of this.pendingRequests) {
|
|
885
|
+
clearTimeout(pending2.timeoutId);
|
|
886
|
+
pending2.reject(new BtpConnectionError("Disconnected"));
|
|
849
887
|
this.pendingRequests.delete(id);
|
|
850
888
|
}
|
|
851
889
|
this.failInFlightInbound("Disconnected before inbound request could be answered");
|
|
@@ -1001,27 +1039,27 @@ var IsomorphicBtpClient = class {
|
|
|
1001
1039
|
const data = this.toUint8Array(raw);
|
|
1002
1040
|
const message = parseBtpMessage(data);
|
|
1003
1041
|
if (message.type === BTPMessageType.RESPONSE || message.type === BTPMessageType.ERROR) {
|
|
1004
|
-
const
|
|
1005
|
-
if (!
|
|
1006
|
-
clearTimeout(
|
|
1042
|
+
const pending2 = this.pendingRequests.get(message.requestId);
|
|
1043
|
+
if (!pending2) return;
|
|
1044
|
+
clearTimeout(pending2.timeoutId);
|
|
1007
1045
|
this.pendingRequests.delete(message.requestId);
|
|
1008
1046
|
if (message.type === BTPMessageType.ERROR) {
|
|
1009
1047
|
const errData = message.data;
|
|
1010
|
-
|
|
1048
|
+
pending2.reject(
|
|
1011
1049
|
new BtpConnectionError(`BTP error: ${errData.code} ${errData.name}`)
|
|
1012
1050
|
);
|
|
1013
1051
|
return;
|
|
1014
1052
|
}
|
|
1015
1053
|
const msgData = message.data;
|
|
1016
1054
|
if (!msgData.ilpPacket || msgData.ilpPacket.length === 0) {
|
|
1017
|
-
|
|
1055
|
+
pending2.reject(
|
|
1018
1056
|
new BtpConnectionError(
|
|
1019
1057
|
`BTP RESPONSE ${message.requestId} carried no ILP packet`
|
|
1020
1058
|
)
|
|
1021
1059
|
);
|
|
1022
1060
|
return;
|
|
1023
1061
|
}
|
|
1024
|
-
|
|
1062
|
+
pending2.resolve({
|
|
1025
1063
|
packet: deserializeIlpPacket(msgData.ilpPacket),
|
|
1026
1064
|
// Everything riding beside the packet — `toon-accumulated-cost` on a
|
|
1027
1065
|
// REJECT, `payment-required` on a greeting, `claim-ack` — handed to
|
|
@@ -2658,10 +2696,10 @@ function parseConnectorRouteTerms(body) {
|
|
|
2658
2696
|
}
|
|
2659
2697
|
|
|
2660
2698
|
// src/btp/transport-select.ts
|
|
2661
|
-
function selectTransport(description, preference = "auto", baseUrl = description.readFrom) {
|
|
2699
|
+
function selectTransport(description, preference = "auto", baseUrl = description.readFrom, destination) {
|
|
2662
2700
|
const http2 = resolveEndpoint2(description.httpEndpoint, baseUrl);
|
|
2663
2701
|
const btp = resolveEndpoint2(description.btpEndpoint, baseUrl);
|
|
2664
|
-
const required = description
|
|
2702
|
+
const required = requiredTransportFor(description, destination);
|
|
2665
2703
|
if (preference === "http" || preference === "btp") {
|
|
2666
2704
|
const url = preference === "http" ? http2 : btp;
|
|
2667
2705
|
if (url === void 0) {
|
|
@@ -3063,8 +3101,8 @@ var ChannelManager = class _ChannelManager {
|
|
|
3063
3101
|
*/
|
|
3064
3102
|
async ensureChannel(connector, terms, options = {}) {
|
|
3065
3103
|
const key = _ChannelManager.bindingKey(connector, terms);
|
|
3066
|
-
const
|
|
3067
|
-
if (
|
|
3104
|
+
const pending2 = this.pendingOpens.get(key);
|
|
3105
|
+
if (pending2) return pending2;
|
|
3068
3106
|
const existing = this.resolveChannel(connector, terms);
|
|
3069
3107
|
if (existing) return existing;
|
|
3070
3108
|
if (!this.channelClient) {
|
|
@@ -3627,19 +3665,72 @@ import { ed25519 as ed255192 } from "@noble/curves/ed25519.js";
|
|
|
3627
3665
|
|
|
3628
3666
|
// src/transport/rpc.ts
|
|
3629
3667
|
import { http } from "viem";
|
|
3668
|
+
var PROXIED_RPC_DEFAULTS = {
|
|
3669
|
+
timeout: 3e4,
|
|
3670
|
+
retryCount: 3,
|
|
3671
|
+
retryDelay: 500
|
|
3672
|
+
};
|
|
3630
3673
|
function rpcTransport(url, dispatcher, options = {}) {
|
|
3631
|
-
const { timeout, retryCount } = options;
|
|
3674
|
+
const { timeout, retryCount, retryDelay } = dispatcher === void 0 ? options : { ...PROXIED_RPC_DEFAULTS, ...definedOnly(options) };
|
|
3632
3675
|
return http(url, {
|
|
3633
3676
|
...timeout !== void 0 ? { timeout } : {},
|
|
3634
3677
|
...retryCount !== void 0 ? { retryCount } : {},
|
|
3678
|
+
...retryDelay !== void 0 ? { retryDelay } : {},
|
|
3635
3679
|
...dispatcher !== void 0 ? { fetchOptions: { dispatcher } } : {}
|
|
3636
3680
|
});
|
|
3637
3681
|
}
|
|
3682
|
+
function definedOnly(options) {
|
|
3683
|
+
return Object.fromEntries(
|
|
3684
|
+
Object.entries(options).filter(([, value]) => value !== void 0)
|
|
3685
|
+
);
|
|
3686
|
+
}
|
|
3638
3687
|
function rpcFetch(dispatcher, fetchImpl = globalThis.fetch) {
|
|
3639
3688
|
if (dispatcher === void 0) return fetchImpl;
|
|
3640
3689
|
return ((input, init) => fetchImpl(input, { ...init, dispatcher }));
|
|
3641
3690
|
}
|
|
3642
3691
|
|
|
3692
|
+
// src/channel/evm/receipt.ts
|
|
3693
|
+
import {
|
|
3694
|
+
WaitForTransactionReceiptTimeoutError
|
|
3695
|
+
} from "viem";
|
|
3696
|
+
var RECEIPT_TIMEOUT_MS = 18e4;
|
|
3697
|
+
var RETRY_DELAY_MS = 1e3;
|
|
3698
|
+
async function waitForReceipt(client, hash, options = {}) {
|
|
3699
|
+
const timeoutMs = options.timeoutMs ?? RECEIPT_TIMEOUT_MS;
|
|
3700
|
+
const retryDelayMs = options.retryDelayMs ?? RETRY_DELAY_MS;
|
|
3701
|
+
const deadline = Date.now() + timeoutMs;
|
|
3702
|
+
let lastError;
|
|
3703
|
+
for (; ; ) {
|
|
3704
|
+
const remaining = deadline - Date.now();
|
|
3705
|
+
if (remaining <= 0) {
|
|
3706
|
+
throw pending(hash, timeoutMs, lastError);
|
|
3707
|
+
}
|
|
3708
|
+
try {
|
|
3709
|
+
return await client.waitForTransactionReceipt({
|
|
3710
|
+
hash,
|
|
3711
|
+
timeout: remaining
|
|
3712
|
+
});
|
|
3713
|
+
} catch (err) {
|
|
3714
|
+
if (err instanceof WaitForTransactionReceiptTimeoutError) {
|
|
3715
|
+
throw pending(hash, timeoutMs, lastError);
|
|
3716
|
+
}
|
|
3717
|
+
lastError = err;
|
|
3718
|
+
}
|
|
3719
|
+
await new Promise(
|
|
3720
|
+
(resolve) => setTimeout(resolve, Math.min(retryDelayMs, deadline - Date.now()))
|
|
3721
|
+
);
|
|
3722
|
+
}
|
|
3723
|
+
}
|
|
3724
|
+
function pending(hash, timeoutMs, lastError) {
|
|
3725
|
+
return new TransactionOutcomeError(
|
|
3726
|
+
`Transaction ${hash} was sent, but no receipt was seen within ${timeoutMs}ms. It may still be mined. Look the hash up before sending anything that would repeat it.` + (lastError instanceof Error ? ` Last RPC error: ${lastError.message}` : ""),
|
|
3727
|
+
"evm",
|
|
3728
|
+
hash,
|
|
3729
|
+
"unknown",
|
|
3730
|
+
lastError instanceof Error ? lastError : void 0
|
|
3731
|
+
);
|
|
3732
|
+
}
|
|
3733
|
+
|
|
3643
3734
|
// src/channel/evm/TokenNetworkClient.ts
|
|
3644
3735
|
import {
|
|
3645
3736
|
createPublicClient,
|
|
@@ -4058,9 +4149,7 @@ var TokenNetworkClient = class {
|
|
|
4058
4149
|
chain: this.walletClient.chain,
|
|
4059
4150
|
account: this.signer.account
|
|
4060
4151
|
});
|
|
4061
|
-
const receipt = await this.publicClient
|
|
4062
|
-
hash: openHash
|
|
4063
|
-
});
|
|
4152
|
+
const receipt = await waitForReceipt(this.publicClient, openHash);
|
|
4064
4153
|
const channelId = readOpenedChannelId(receipt);
|
|
4065
4154
|
if (channelId === void 0) {
|
|
4066
4155
|
throw new ConfigError(
|
|
@@ -4095,7 +4184,7 @@ var TokenNetworkClient = class {
|
|
|
4095
4184
|
chain: this.walletClient.chain,
|
|
4096
4185
|
account: this.signer.account
|
|
4097
4186
|
});
|
|
4098
|
-
await this.publicClient
|
|
4187
|
+
await waitForReceipt(this.publicClient, hash);
|
|
4099
4188
|
return { txHash: hash, depositTotal: newTotal };
|
|
4100
4189
|
}
|
|
4101
4190
|
/**
|
|
@@ -4113,7 +4202,7 @@ var TokenNetworkClient = class {
|
|
|
4113
4202
|
chain: this.walletClient.chain,
|
|
4114
4203
|
account: this.signer.account
|
|
4115
4204
|
});
|
|
4116
|
-
await this.publicClient
|
|
4205
|
+
await waitForReceipt(this.publicClient, hash);
|
|
4117
4206
|
const record = await this.readChannel(tokenNetwork, channelId);
|
|
4118
4207
|
return {
|
|
4119
4208
|
txHash: hash,
|
|
@@ -4136,7 +4225,7 @@ var TokenNetworkClient = class {
|
|
|
4136
4225
|
chain: this.walletClient.chain,
|
|
4137
4226
|
account: this.signer.account
|
|
4138
4227
|
});
|
|
4139
|
-
await this.publicClient
|
|
4228
|
+
await waitForReceipt(this.publicClient, hash);
|
|
4140
4229
|
return { txHash: hash };
|
|
4141
4230
|
}
|
|
4142
4231
|
// ─── Private ──────────────────────────────────────────────────────────────
|
|
@@ -4157,7 +4246,7 @@ var TokenNetworkClient = class {
|
|
|
4157
4246
|
chain: this.walletClient.chain,
|
|
4158
4247
|
account: this.signer.account
|
|
4159
4248
|
});
|
|
4160
|
-
await this.publicClient
|
|
4249
|
+
await waitForReceipt(this.publicClient, hash);
|
|
4161
4250
|
}
|
|
4162
4251
|
/**
|
|
4163
4252
|
* Poll until the RPC reports the just-opened channel (non-zero `participant1`).
|
|
@@ -4197,7 +4286,7 @@ var TokenNetworkClient = class {
|
|
|
4197
4286
|
chain: this.walletClient.chain,
|
|
4198
4287
|
account: this.signer.account
|
|
4199
4288
|
});
|
|
4200
|
-
await this.publicClient
|
|
4289
|
+
await waitForReceipt(this.publicClient, hash);
|
|
4201
4290
|
return;
|
|
4202
4291
|
} catch (err) {
|
|
4203
4292
|
if (attempt2 >= depositRetries || !isInvalidChannelStateRevert(err)) throw err;
|
|
@@ -4415,8 +4504,54 @@ function resolveRpcTarget(target) {
|
|
|
4415
4504
|
if (typeof target === "string") return { url: target, fetchImpl: globalThis.fetch };
|
|
4416
4505
|
return { url: target.url, fetchImpl: target.fetchImpl ?? globalThis.fetch };
|
|
4417
4506
|
}
|
|
4507
|
+
var SOLANA_RPC_RETRY_DELAYS_MS = [250, 500, 1e3];
|
|
4508
|
+
var RETRYABLE_HTTP_STATUS = /* @__PURE__ */ new Set([403, 408, 413, 429, 500, 502, 503, 504]);
|
|
4509
|
+
var MAX_RETRY_AFTER_MS = 1e4;
|
|
4510
|
+
var SOLANA_RPC_TIMEOUT_MS = 3e4;
|
|
4511
|
+
var SolanaRpcTransportError = class extends NetworkError {
|
|
4512
|
+
constructor(method, attempts, mayHaveArrived, cause) {
|
|
4513
|
+
super(
|
|
4514
|
+
`Solana RPC [${method}] got no answer after ${attempts} tries: ` + (cause instanceof Error ? cause.message : String(cause)),
|
|
4515
|
+
cause instanceof Error ? cause : void 0
|
|
4516
|
+
);
|
|
4517
|
+
this.method = method;
|
|
4518
|
+
this.attempts = attempts;
|
|
4519
|
+
this.mayHaveArrived = mayHaveArrived;
|
|
4520
|
+
this.name = "SolanaRpcTransportError";
|
|
4521
|
+
}
|
|
4522
|
+
method;
|
|
4523
|
+
attempts;
|
|
4524
|
+
mayHaveArrived;
|
|
4525
|
+
};
|
|
4526
|
+
var SolanaRpcHttpError = class extends Error {
|
|
4527
|
+
constructor(status, retryAfterMs2) {
|
|
4528
|
+
super(`HTTP ${status}`);
|
|
4529
|
+
this.status = status;
|
|
4530
|
+
this.retryAfterMs = retryAfterMs2;
|
|
4531
|
+
this.name = "SolanaRpcHttpError";
|
|
4532
|
+
}
|
|
4533
|
+
status;
|
|
4534
|
+
retryAfterMs;
|
|
4535
|
+
};
|
|
4418
4536
|
async function solanaRpc(rpcUrl, method, params = []) {
|
|
4419
4537
|
const { url, fetchImpl } = resolveRpcTarget(rpcUrl);
|
|
4538
|
+
let mayHaveArrived = false;
|
|
4539
|
+
for (let attempt2 = 0; ; attempt2++) {
|
|
4540
|
+
try {
|
|
4541
|
+
return await solanaRpcOnce(url, fetchImpl, method, params);
|
|
4542
|
+
} catch (err) {
|
|
4543
|
+
if (err instanceof SolanaRpcError) throw err;
|
|
4544
|
+
mayHaveArrived ||= !failedBeforeSending(err);
|
|
4545
|
+
const retryable = !(err instanceof SolanaRpcHttpError) || RETRYABLE_HTTP_STATUS.has(err.status);
|
|
4546
|
+
const delay = err instanceof SolanaRpcHttpError && err.retryAfterMs !== void 0 ? err.retryAfterMs : SOLANA_RPC_RETRY_DELAYS_MS[attempt2];
|
|
4547
|
+
if (!retryable || attempt2 >= SOLANA_RPC_RETRY_DELAYS_MS.length || delay === void 0 || delay > MAX_RETRY_AFTER_MS) {
|
|
4548
|
+
throw new SolanaRpcTransportError(method, attempt2 + 1, mayHaveArrived, err);
|
|
4549
|
+
}
|
|
4550
|
+
await sleep3(delay);
|
|
4551
|
+
}
|
|
4552
|
+
}
|
|
4553
|
+
}
|
|
4554
|
+
async function solanaRpcOnce(url, fetchImpl, method, params) {
|
|
4420
4555
|
const res = await fetchImpl(url, {
|
|
4421
4556
|
method: "POST",
|
|
4422
4557
|
headers: { "Content-Type": "application/json" },
|
|
@@ -4426,19 +4561,43 @@ async function solanaRpc(rpcUrl, method, params = []) {
|
|
|
4426
4561
|
params,
|
|
4427
4562
|
id: rpcIdCounter++
|
|
4428
4563
|
}),
|
|
4429
|
-
signal: AbortSignal.timeout(
|
|
4564
|
+
signal: AbortSignal.timeout(SOLANA_RPC_TIMEOUT_MS)
|
|
4430
4565
|
});
|
|
4566
|
+
if (res.ok === false) {
|
|
4567
|
+
throw new SolanaRpcHttpError(res.status, retryAfterMs(res.headers?.get("retry-after")));
|
|
4568
|
+
}
|
|
4431
4569
|
const json = await res.json();
|
|
4432
4570
|
if (json.error) {
|
|
4433
4571
|
throw new SolanaRpcError(method, json.error.code, json.error.message);
|
|
4434
4572
|
}
|
|
4435
4573
|
return json.result;
|
|
4436
4574
|
}
|
|
4437
|
-
|
|
4575
|
+
function retryAfterMs(header) {
|
|
4576
|
+
if (header === null || header === void 0 || !/^\d+$/.test(header.trim())) return void 0;
|
|
4577
|
+
return Number.parseInt(header.trim(), 10) * 1e3;
|
|
4578
|
+
}
|
|
4579
|
+
function failedBeforeSending(err) {
|
|
4580
|
+
let e = err;
|
|
4581
|
+
for (let depth = 0; e instanceof Error && depth < 5; depth++) {
|
|
4582
|
+
const code = e.code;
|
|
4583
|
+
if (e.name === "SocksClientError") return true;
|
|
4584
|
+
if (code === "ECONNREFUSED" || code === "ENOTFOUND" || code === "EAI_AGAIN") return true;
|
|
4585
|
+
if (code === "UND_ERR_CONNECT_TIMEOUT") return true;
|
|
4586
|
+
e = e.cause;
|
|
4587
|
+
}
|
|
4588
|
+
return false;
|
|
4589
|
+
}
|
|
4590
|
+
function sleep3(ms) {
|
|
4591
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
4592
|
+
}
|
|
4593
|
+
async function getLatestBlockhashWithExpiry(rpcUrl) {
|
|
4438
4594
|
const result = await solanaRpc(rpcUrl, "getLatestBlockhash", [
|
|
4439
4595
|
{ commitment: "confirmed" }
|
|
4440
4596
|
]);
|
|
4441
|
-
return
|
|
4597
|
+
return {
|
|
4598
|
+
blockhash: result.value.blockhash,
|
|
4599
|
+
lastValidBlockHeight: result.value.lastValidBlockHeight
|
|
4600
|
+
};
|
|
4442
4601
|
}
|
|
4443
4602
|
async function getAccountInfo(rpcUrl, pubkey) {
|
|
4444
4603
|
const result = await solanaRpc(rpcUrl, "getAccountInfo", [
|
|
@@ -4491,26 +4650,64 @@ async function assertOpenFunding(opts) {
|
|
|
4491
4650
|
);
|
|
4492
4651
|
}
|
|
4493
4652
|
}
|
|
4494
|
-
|
|
4495
|
-
|
|
4496
|
-
|
|
4497
|
-
|
|
4498
|
-
|
|
4499
|
-
|
|
4500
|
-
|
|
4501
|
-
|
|
4502
|
-
|
|
4503
|
-
|
|
4504
|
-
|
|
4653
|
+
var CONFIRM_TIMEOUT_MS = RECEIPT_TIMEOUT_MS;
|
|
4654
|
+
async function waitForConfirmation(rpcUrl, signature, options = {}) {
|
|
4655
|
+
const { lastValidBlockHeight, pollIntervalMs = 500 } = options;
|
|
4656
|
+
const timeoutMs = options.timeoutMs ?? (lastValidBlockHeight !== void 0 ? CONFIRM_TIMEOUT_MS : 3e4);
|
|
4657
|
+
const deadline = Date.now() + timeoutMs;
|
|
4658
|
+
let lastError;
|
|
4659
|
+
let failedPolls = 0;
|
|
4660
|
+
for (; ; ) {
|
|
4661
|
+
try {
|
|
4662
|
+
if (await isConfirmed(rpcUrl, signature)) return;
|
|
4663
|
+
if (lastValidBlockHeight !== void 0) {
|
|
4664
|
+
const height = Number(
|
|
4665
|
+
await solanaRpc(rpcUrl, "getBlockHeight", [{ commitment: "confirmed" }])
|
|
4505
4666
|
);
|
|
4667
|
+
if (height > lastValidBlockHeight && !await isConfirmed(rpcUrl, signature)) {
|
|
4668
|
+
throw new TransactionOutcomeError(
|
|
4669
|
+
`Transaction ${signature} expired: block height ${height} is past its blockhash's last valid height ${lastValidBlockHeight}, and it never appeared, so it cannot land. It is safe to build and send it again.`,
|
|
4670
|
+
"solana",
|
|
4671
|
+
signature,
|
|
4672
|
+
"expired"
|
|
4673
|
+
);
|
|
4674
|
+
}
|
|
4506
4675
|
}
|
|
4507
|
-
|
|
4676
|
+
} catch (err) {
|
|
4677
|
+
if (err instanceof TransactionOutcomeError) throw err;
|
|
4678
|
+
lastError = err;
|
|
4679
|
+
failedPolls += 1;
|
|
4680
|
+
}
|
|
4681
|
+
if (Date.now() >= deadline) {
|
|
4682
|
+
throw new TransactionOutcomeError(
|
|
4683
|
+
`Transaction ${signature} was not seen confirmed within ${timeoutMs}ms, and the RPC could not say whether it can still land. Look the signature up before sending anything that would repeat it.` + (lastError instanceof Error ? ` Last RPC error: ${lastError.message}` : ""),
|
|
4684
|
+
"solana",
|
|
4685
|
+
signature,
|
|
4686
|
+
"unknown",
|
|
4687
|
+
lastError instanceof Error ? lastError : void 0
|
|
4688
|
+
);
|
|
4508
4689
|
}
|
|
4509
|
-
await
|
|
4690
|
+
await sleep3(pollIntervalMs * 2 ** Math.min(failedPolls, 3));
|
|
4510
4691
|
}
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
);
|
|
4692
|
+
}
|
|
4693
|
+
async function isConfirmed(rpcUrl, signature) {
|
|
4694
|
+
const result = await solanaRpc(rpcUrl, "getSignatureStatuses", [[signature]]);
|
|
4695
|
+
const status = result.value[0];
|
|
4696
|
+
if (status?.confirmationStatus !== "confirmed" && status?.confirmationStatus !== "finalized") {
|
|
4697
|
+
return false;
|
|
4698
|
+
}
|
|
4699
|
+
if (status.err) {
|
|
4700
|
+
throw new TransactionOutcomeError(
|
|
4701
|
+
`Transaction ${signature} failed: ${JSON.stringify(status.err)}`,
|
|
4702
|
+
"solana",
|
|
4703
|
+
signature,
|
|
4704
|
+
"failed"
|
|
4705
|
+
);
|
|
4706
|
+
}
|
|
4707
|
+
return true;
|
|
4708
|
+
}
|
|
4709
|
+
function isAlreadyProcessed(err) {
|
|
4710
|
+
return /already been processed|AlreadyProcessed/i.test(err.rpcMessage);
|
|
4514
4711
|
}
|
|
4515
4712
|
function compactU16Size(value) {
|
|
4516
4713
|
if (value > 65535) {
|
|
@@ -4531,8 +4728,8 @@ function writeCompactU16(buf, offset, value) {
|
|
|
4531
4728
|
}
|
|
4532
4729
|
return offset;
|
|
4533
4730
|
}
|
|
4534
|
-
async function buildAndSendTransaction(rpcUrl, feePayer, instructions, additionalSigners = []) {
|
|
4535
|
-
const blockhash = await
|
|
4731
|
+
async function buildAndSendTransaction(rpcUrl, feePayer, instructions, additionalSigners = [], confirmation = {}) {
|
|
4732
|
+
const { blockhash, lastValidBlockHeight } = await getLatestBlockhashWithExpiry(rpcUrl);
|
|
4536
4733
|
const feePayerPubkey = base58Encode(feePayer.publicKey);
|
|
4537
4734
|
const accountMap = /* @__PURE__ */ new Map();
|
|
4538
4735
|
accountMap.set(feePayerPubkey, {
|
|
@@ -4631,15 +4828,27 @@ async function buildAndSendTransaction(rpcUrl, feePayer, instructions, additiona
|
|
|
4631
4828
|
}
|
|
4632
4829
|
tx.set(finalMessage, txOffset);
|
|
4633
4830
|
const txBase64 = Buffer.from(tx).toString("base64");
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4642
|
-
|
|
4831
|
+
let txSig;
|
|
4832
|
+
try {
|
|
4833
|
+
txSig = await solanaRpc(rpcUrl, "sendTransaction", [
|
|
4834
|
+
txBase64,
|
|
4835
|
+
{
|
|
4836
|
+
encoding: "base64",
|
|
4837
|
+
skipPreflight: false,
|
|
4838
|
+
preflightCommitment: "confirmed"
|
|
4839
|
+
}
|
|
4840
|
+
]);
|
|
4841
|
+
} catch (err) {
|
|
4842
|
+
const alreadyOnChain = err instanceof SolanaRpcError && isAlreadyProcessed(err);
|
|
4843
|
+
const answerLost = err instanceof SolanaRpcTransportError && err.mayHaveArrived;
|
|
4844
|
+
if (!alreadyOnChain && !answerLost) throw err;
|
|
4845
|
+
const firstSignature = compactU16Size(signatures.length);
|
|
4846
|
+
txSig = base58Encode(tx.subarray(firstSignature, firstSignature + 64));
|
|
4847
|
+
}
|
|
4848
|
+
await waitForConfirmation(rpcUrl, txSig, {
|
|
4849
|
+
...confirmation,
|
|
4850
|
+
...lastValidBlockHeight !== void 0 ? { lastValidBlockHeight } : {}
|
|
4851
|
+
});
|
|
4643
4852
|
return txSig;
|
|
4644
4853
|
}
|
|
4645
4854
|
var STATE_MAP2 = ["opened", "closed", "settled"];
|
|
@@ -6387,7 +6596,7 @@ function resolveConfig(config) {
|
|
|
6387
6596
|
connectorIsHiddenService,
|
|
6388
6597
|
socksProxy,
|
|
6389
6598
|
proxyRpc: config.proxyRpc ?? true,
|
|
6390
|
-
|
|
6599
|
+
chainRpc: void 0,
|
|
6391
6600
|
settlementTimeout,
|
|
6392
6601
|
autoOpenChannel: config.autoOpenChannel ?? true,
|
|
6393
6602
|
timeoutMs,
|
|
@@ -6448,11 +6657,6 @@ function resolveSocksProxy(socksProxy, connector, connectorIsHiddenService) {
|
|
|
6448
6657
|
`connector ${JSON.stringify(connector)} is a hidden service, which is reachable only through a SOCKS5h proxy. Set \`socksProxy\` to a running Anyone Protocol \`anon\` daemon (e.g. "socks5h://127.0.0.1:9050"), or use the \`toon\` CLI, which can start one for you.`
|
|
6449
6658
|
);
|
|
6450
6659
|
}
|
|
6451
|
-
if (!connectorIsHiddenService) {
|
|
6452
|
-
throw new ConfigError(
|
|
6453
|
-
`socksProxy is set, but connector ${JSON.stringify(connector)} is a clearnet address, so nothing would ride the proxy. Point \`connector\` at the node's .anyone address, or drop \`socksProxy\`.`
|
|
6454
|
-
);
|
|
6455
|
-
}
|
|
6456
6660
|
try {
|
|
6457
6661
|
validateSocks5hUrl(socksProxy);
|
|
6458
6662
|
} catch (error) {
|
|
@@ -6874,20 +7078,22 @@ function parseEvmChainId2(chainKey) {
|
|
|
6874
7078
|
}
|
|
6875
7079
|
var RPC_TIMEOUT_ENV = "TOON_WALLET_RPC_TIMEOUT_MS";
|
|
6876
7080
|
var DEFAULT_RPC_TIMEOUT_MS = 8e3;
|
|
6877
|
-
|
|
7081
|
+
var DEFAULT_PROXIED_RPC_TIMEOUT_MS = PROXIED_RPC_DEFAULTS.timeout;
|
|
7082
|
+
function rpcTimeoutMs(proxied = false) {
|
|
6878
7083
|
const raw = typeof process !== "undefined" ? process.env?.[RPC_TIMEOUT_ENV] : void 0;
|
|
6879
7084
|
const n = raw === void 0 || raw === "" ? NaN : Number(raw);
|
|
6880
|
-
|
|
7085
|
+
if (Number.isFinite(n) && n >= 0) return n;
|
|
7086
|
+
return proxied ? DEFAULT_PROXIED_RPC_TIMEOUT_MS : DEFAULT_RPC_TIMEOUT_MS;
|
|
6881
7087
|
}
|
|
6882
|
-
function rpcAbortSignal() {
|
|
6883
|
-
const ms = rpcTimeoutMs();
|
|
7088
|
+
function rpcAbortSignal(proxied = false) {
|
|
7089
|
+
const ms = rpcTimeoutMs(proxied);
|
|
6884
7090
|
return ms > 0 ? AbortSignal.timeout(ms) : void 0;
|
|
6885
7091
|
}
|
|
6886
7092
|
async function readEvmTokenBalance(opts) {
|
|
6887
7093
|
const chainId = parseEvmChainId2(opts.chainKey);
|
|
6888
7094
|
const client = createPublicClient2({
|
|
6889
7095
|
transport: rpcTransport(opts.rpcUrl, opts.rpcDispatcher, {
|
|
6890
|
-
...rpcTimeoutMs() ? { timeout: rpcTimeoutMs() } : {},
|
|
7096
|
+
...rpcTimeoutMs(opts.rpcDispatcher !== void 0) ? { timeout: rpcTimeoutMs(opts.rpcDispatcher !== void 0) } : {},
|
|
6891
7097
|
retryCount: 1
|
|
6892
7098
|
}),
|
|
6893
7099
|
chain: defineChain2({
|
|
@@ -6913,7 +7119,7 @@ async function readEvmNativeBalance(opts) {
|
|
|
6913
7119
|
const chainId = parseEvmChainId2(opts.chainKey);
|
|
6914
7120
|
const client = createPublicClient2({
|
|
6915
7121
|
transport: rpcTransport(opts.rpcUrl, opts.rpcDispatcher, {
|
|
6916
|
-
...rpcTimeoutMs() ? { timeout: rpcTimeoutMs() } : {},
|
|
7122
|
+
...rpcTimeoutMs(opts.rpcDispatcher !== void 0) ? { timeout: rpcTimeoutMs(opts.rpcDispatcher !== void 0) } : {},
|
|
6917
7123
|
retryCount: 1
|
|
6918
7124
|
}),
|
|
6919
7125
|
chain: defineChain2({
|
|
@@ -6937,7 +7143,7 @@ async function readSolanaNativeBalance(opts) {
|
|
|
6937
7143
|
method: "getBalance",
|
|
6938
7144
|
params: [opts.owner, { commitment: "confirmed" }]
|
|
6939
7145
|
}),
|
|
6940
|
-
signal: rpcAbortSignal()
|
|
7146
|
+
signal: rpcAbortSignal(opts.proxied)
|
|
6941
7147
|
});
|
|
6942
7148
|
if (!res.ok) throw new Error(`Solana RPC request failed: HTTP ${res.status}`);
|
|
6943
7149
|
const json = await res.json();
|
|
@@ -6956,7 +7162,7 @@ async function readSolanaTokenBalance(opts) {
|
|
|
6956
7162
|
method: "getTokenAccountsByOwner",
|
|
6957
7163
|
params: [opts.owner, { mint: opts.mint }, { encoding: "jsonParsed", commitment: "confirmed" }]
|
|
6958
7164
|
}),
|
|
6959
|
-
signal: rpcAbortSignal()
|
|
7165
|
+
signal: rpcAbortSignal(opts.proxied)
|
|
6960
7166
|
});
|
|
6961
7167
|
if (!res.ok) throw new Error(`Solana RPC request failed: HTTP ${res.status}`);
|
|
6962
7168
|
const json = await res.json();
|
|
@@ -6996,7 +7202,7 @@ function finalizeChain(out, errors) {
|
|
|
6996
7202
|
if (out.native === void 0 && out.tokens.length === 0) out.unreadable = true;
|
|
6997
7203
|
}
|
|
6998
7204
|
async function readWalletBalances(sources) {
|
|
6999
|
-
const { fetchImpl } = sources;
|
|
7205
|
+
const { fetchImpl, solanaProxied: proxied } = sources;
|
|
7000
7206
|
const tasks = [];
|
|
7001
7207
|
if (sources.evm) {
|
|
7002
7208
|
const { chainKey, rpcUrl, owner, tokenAddress, rpcDispatcher } = sources.evm;
|
|
@@ -7022,8 +7228,8 @@ async function readWalletBalances(sources) {
|
|
|
7022
7228
|
const out = { chain: "solana", chainKey, address: owner, tokens: [] };
|
|
7023
7229
|
const errors = [];
|
|
7024
7230
|
const [nativeR, tokenR] = await Promise.allSettled([
|
|
7025
|
-
readSolanaNativeBalance({ rpcUrl, owner, fetchImpl }),
|
|
7026
|
-
tokenMint ? readSolanaTokenBalance({ rpcUrl, mint: tokenMint, owner, fetchImpl }) : Promise.resolve(void 0)
|
|
7231
|
+
readSolanaNativeBalance({ rpcUrl, owner, fetchImpl, proxied }),
|
|
7232
|
+
tokenMint ? readSolanaTokenBalance({ rpcUrl, mint: tokenMint, owner, fetchImpl, proxied }) : Promise.resolve(void 0)
|
|
7027
7233
|
]);
|
|
7028
7234
|
foldNative(out, nativeR, errors);
|
|
7029
7235
|
if (tokenR.status === "fulfilled" && tokenR.value && tokenR.value.asset === void 0) {
|
|
@@ -7162,9 +7368,7 @@ async function sendEvmTransfer(cfg, params, amount) {
|
|
|
7162
7368
|
const readDest2 = () => publicClient.getBalance({ address: to });
|
|
7163
7369
|
const before2 = await readDest2();
|
|
7164
7370
|
const txHash2 = await walletClient.sendTransaction({ to, value: amount });
|
|
7165
|
-
const receipt2 = await publicClient
|
|
7166
|
-
hash: txHash2
|
|
7167
|
-
});
|
|
7371
|
+
const receipt2 = await waitForReceipt(publicClient, txHash2);
|
|
7168
7372
|
if (receipt2.status === "reverted") {
|
|
7169
7373
|
throw new TransferNotDeliveredError(
|
|
7170
7374
|
`EVM native transfer ${txHash2} reverted on-chain \u2014 no funds reached ${to}.`
|
|
@@ -7211,9 +7415,7 @@ async function sendEvmTransfer(cfg, params, amount) {
|
|
|
7211
7415
|
functionName: "transfer",
|
|
7212
7416
|
args: [to, amount]
|
|
7213
7417
|
});
|
|
7214
|
-
const receipt = await publicClient
|
|
7215
|
-
hash: txHash
|
|
7216
|
-
});
|
|
7418
|
+
const receipt = await waitForReceipt(publicClient, txHash);
|
|
7217
7419
|
if (receipt.status === "reverted") {
|
|
7218
7420
|
throw new TransferNotDeliveredError(
|
|
7219
7421
|
`EVM token transfer ${txHash} reverted on-chain \u2014 no funds reached ${to}.`
|
|
@@ -7446,7 +7648,10 @@ async function fundWallet(faucetUrl, address, chain, options = {}) {
|
|
|
7446
7648
|
// src/client/wallet-facade.ts
|
|
7447
7649
|
function solanaRpcFetch(config) {
|
|
7448
7650
|
if (config.socksProxy === void 0) return config.fetch;
|
|
7449
|
-
return config.
|
|
7651
|
+
return config.chainRpc?.solana.fetch ?? globalThis.fetch;
|
|
7652
|
+
}
|
|
7653
|
+
function evmRpcDispatcher(config) {
|
|
7654
|
+
return config.chainRpc !== void 0 ? { rpcDispatcher: config.chainRpc.evm.dispatcher } : {};
|
|
7450
7655
|
}
|
|
7451
7656
|
var ClientWalletFacade = class {
|
|
7452
7657
|
deps;
|
|
@@ -7467,7 +7672,8 @@ var ClientWalletFacade = class {
|
|
|
7467
7672
|
const settlements = await this.settlements();
|
|
7468
7673
|
const wanted = chain !== void 0 ? [chain] : ["evm", "solana"];
|
|
7469
7674
|
const sources = {
|
|
7470
|
-
fetchImpl: solanaRpcFetch(config)
|
|
7675
|
+
fetchImpl: solanaRpcFetch(config),
|
|
7676
|
+
...config.chainRpc !== void 0 ? { solanaProxied: true } : {}
|
|
7471
7677
|
};
|
|
7472
7678
|
for (const kind of wanted) {
|
|
7473
7679
|
const entry = settlements.get(kind);
|
|
@@ -7476,7 +7682,7 @@ var ClientWalletFacade = class {
|
|
|
7476
7682
|
chainKey: entry?.chain ?? "evm",
|
|
7477
7683
|
rpcUrl: config.rpcUrls.evm,
|
|
7478
7684
|
owner: config.identity.evm.address,
|
|
7479
|
-
...config
|
|
7685
|
+
...evmRpcDispatcher(config),
|
|
7480
7686
|
...entry?.tokenAddress ? { tokenAddress: entry.tokenAddress } : {}
|
|
7481
7687
|
};
|
|
7482
7688
|
}
|
|
@@ -7517,14 +7723,14 @@ var ClientWalletFacade = class {
|
|
|
7517
7723
|
chainKey: entry?.kind === "evm" ? entry.chain : "evm",
|
|
7518
7724
|
rpcUrl: config.rpcUrls.evm,
|
|
7519
7725
|
signer: this.signer(),
|
|
7520
|
-
...config
|
|
7726
|
+
...evmRpcDispatcher(config),
|
|
7521
7727
|
...entry?.tokenAddress ? { tokenAddress: entry.tokenAddress } : {}
|
|
7522
7728
|
}
|
|
7523
7729
|
} : {},
|
|
7524
7730
|
...config.identity.solana ? {
|
|
7525
7731
|
solana: {
|
|
7526
7732
|
rpcUrl: config.rpcUrls.solana,
|
|
7527
|
-
...config.
|
|
7733
|
+
...config.chainRpc !== void 0 ? { rpcFetch: config.chainRpc.solana.fetch } : {},
|
|
7528
7734
|
keypair: config.identity.solana.secretKey,
|
|
7529
7735
|
...entry?.tokenAddress ? { tokenMint: entry.tokenAddress } : {}
|
|
7530
7736
|
}
|
|
@@ -7630,7 +7836,8 @@ async function send(context, destination, request = {}, options = {}) {
|
|
|
7630
7836
|
options.amount,
|
|
7631
7837
|
exchange.data.length
|
|
7632
7838
|
);
|
|
7633
|
-
|
|
7839
|
+
refuseIfCallerSaysSo(options.beforePay, destination, amount, request);
|
|
7840
|
+
const carriage = await context.transport(description, destination);
|
|
7634
7841
|
const first = await attempt(context, {
|
|
7635
7842
|
destination,
|
|
7636
7843
|
amount,
|
|
@@ -7649,6 +7856,12 @@ async function send(context, destination, request = {}, options = {}) {
|
|
|
7649
7856
|
});
|
|
7650
7857
|
return retry ?? first.result;
|
|
7651
7858
|
}
|
|
7859
|
+
function refuseIfCallerSaysSo(beforePay, destination, amount, request) {
|
|
7860
|
+
if (beforePay === void 0) return;
|
|
7861
|
+
const reason = beforePay({ destination, amount, request });
|
|
7862
|
+
if (typeof reason !== "string") return;
|
|
7863
|
+
throw new BeforePayRefusedError(reason, destination, amount);
|
|
7864
|
+
}
|
|
7652
7865
|
async function attempt(context, params) {
|
|
7653
7866
|
if (params.amount === 0n) return attemptUnpaid(context, params);
|
|
7654
7867
|
const channelId = await context.ensureChannel(params.description);
|
|
@@ -7866,7 +8079,16 @@ var ToonClient = class _ToonClient {
|
|
|
7866
8079
|
channelFacade;
|
|
7867
8080
|
description;
|
|
7868
8081
|
onChain;
|
|
7869
|
-
|
|
8082
|
+
/**
|
|
8083
|
+
* One live carriage per kind, not one per client.
|
|
8084
|
+
*
|
|
8085
|
+
* A node pins carriages **per route** (connector ADR 0072), so one client can
|
|
8086
|
+
* legitimately owe one destination a BTP session and another an HTTP one-shot.
|
|
8087
|
+
* Keying by kind keeps each carriage chosen once and reused — which is the
|
|
8088
|
+
* point of caching at all — without letting the first destination decide for
|
|
8089
|
+
* every later one.
|
|
8090
|
+
*/
|
|
8091
|
+
carriages = {};
|
|
7870
8092
|
btpSession;
|
|
7871
8093
|
hiddenService;
|
|
7872
8094
|
closed = false;
|
|
@@ -8094,7 +8316,7 @@ var ToonClient = class _ToonClient {
|
|
|
8094
8316
|
this.closed = true;
|
|
8095
8317
|
const session = this.btpSession;
|
|
8096
8318
|
this.btpSession = void 0;
|
|
8097
|
-
this.
|
|
8319
|
+
this.carriages = {};
|
|
8098
8320
|
if (session) await session.disconnect();
|
|
8099
8321
|
if (this.hiddenService) await this.hiddenService.close();
|
|
8100
8322
|
}
|
|
@@ -8128,7 +8350,7 @@ var ToonClient = class _ToonClient {
|
|
|
8128
8350
|
evictChannel: (channelId) => this.evictChannel(channelId),
|
|
8129
8351
|
channels: this.channels,
|
|
8130
8352
|
reconcileWatermark: (channelId) => this.reconcileWatermark(channelId),
|
|
8131
|
-
transport: (description) => this.transportFor(description),
|
|
8353
|
+
transport: (description, destination) => this.transportFor(description, destination),
|
|
8132
8354
|
senderId: this.identity.senderId,
|
|
8133
8355
|
chain: this.chain,
|
|
8134
8356
|
timeoutMs: this.config.timeoutMs
|
|
@@ -8215,13 +8437,14 @@ var ToonClient = class _ToonClient {
|
|
|
8215
8437
|
const client = new OnChainChannelClient({
|
|
8216
8438
|
evmSigner: new EvmSigner(this.requireEvmKey()),
|
|
8217
8439
|
chainRpcUrls,
|
|
8218
|
-
...this.config.
|
|
8440
|
+
...this.config.chainRpc !== void 0 ? { rpcDispatcher: this.config.chainRpc.evm.dispatcher } : {},
|
|
8219
8441
|
...this.config.identity.solana ? {
|
|
8220
8442
|
solanaConfig: {
|
|
8221
8443
|
rpcUrl: this.config.rpcUrls.solana,
|
|
8222
|
-
// Same condition as the EVM dispatcher
|
|
8223
|
-
// a proxy and the caller has not opted
|
|
8224
|
-
|
|
8444
|
+
// Same condition as the EVM dispatcher, and its own circuit:
|
|
8445
|
+
// proxied only when there is a proxy and the caller has not opted
|
|
8446
|
+
// RPC out of it. Never `config.fetch`, which may be the caller's.
|
|
8447
|
+
...this.config.chainRpc !== void 0 ? { rpcFetch: this.config.chainRpc.solana.fetch } : {},
|
|
8225
8448
|
keypair: this.config.identity.solana.secretKey,
|
|
8226
8449
|
// The DEFAULT only. Each channel opens under the program its own
|
|
8227
8450
|
// terms name, because ADR 0053 binds that program into the signed
|
|
@@ -8253,19 +8476,26 @@ var ToonClient = class _ToonClient {
|
|
|
8253
8476
|
return key;
|
|
8254
8477
|
}
|
|
8255
8478
|
/**
|
|
8256
|
-
* The carriage
|
|
8479
|
+
* The carriage for `destination`, chosen once per kind and then reused.
|
|
8257
8480
|
*
|
|
8258
8481
|
* Reuse matters for BTP specifically: the whole reason to prefer it is that one
|
|
8259
8482
|
* ordered socket cannot race its own claim nonces into `F01 NonceNotAdvancing`
|
|
8260
8483
|
* (`client-edge-spec.md` §1.9), and a session rebuilt per request would give
|
|
8261
8484
|
* that up while paying for the handshake.
|
|
8485
|
+
*
|
|
8486
|
+
* `destination` is what lets the node's **per-route** pin decide, rather than
|
|
8487
|
+
* only its node-wide summary — which is silent on any node that pins one of
|
|
8488
|
+
* its own addresses and not another (TOON_Network#111). The choice is made
|
|
8489
|
+
* before the first packet, so a pinned route is dialled correctly on the first
|
|
8490
|
+
* attempt and never learns its carriage from a refusal.
|
|
8262
8491
|
*/
|
|
8263
|
-
async transportFor(description) {
|
|
8492
|
+
async transportFor(description, destination) {
|
|
8264
8493
|
if (this.closed) {
|
|
8265
8494
|
throw new ConfigError("This client has been closed; construct a new one to send again.");
|
|
8266
8495
|
}
|
|
8267
|
-
|
|
8268
|
-
const
|
|
8496
|
+
const choice = selectTransport(description, this.config.transport, void 0, destination);
|
|
8497
|
+
const cached = this.carriages[choice.kind];
|
|
8498
|
+
if (cached) return cached;
|
|
8269
8499
|
const httpEndpoint = choice.kind === "http" ? choice.url : httpEndpointOf(description, this.connector);
|
|
8270
8500
|
this.assertEndpointReachable(choice.url);
|
|
8271
8501
|
this.assertEndpointReachable(httpEndpoint);
|
|
@@ -8277,7 +8507,7 @@ var ToonClient = class _ToonClient {
|
|
|
8277
8507
|
});
|
|
8278
8508
|
if (choice.kind === "http") {
|
|
8279
8509
|
const carriage2 = { kind: "http", transport: http2 };
|
|
8280
|
-
this.
|
|
8510
|
+
this.carriages.http = carriage2;
|
|
8281
8511
|
return carriage2;
|
|
8282
8512
|
}
|
|
8283
8513
|
const session = new BtpRuntimeClient({
|
|
@@ -8297,15 +8527,18 @@ var ToonClient = class _ToonClient {
|
|
|
8297
8527
|
kind: "btp",
|
|
8298
8528
|
transport: new BtpPaidWriteTransport({
|
|
8299
8529
|
session,
|
|
8300
|
-
// HTTP fallback only where the node did not REQUIRE btp
|
|
8301
|
-
// onto a carriage the route refuses would
|
|
8302
|
-
// outage into a `402` per request.
|
|
8303
|
-
|
|
8530
|
+
// HTTP fallback only where the node did not REQUIRE btp *for this
|
|
8531
|
+
// destination*: falling back onto a carriage the route refuses would
|
|
8532
|
+
// turn a recoverable socket outage into a `402` per request. Read
|
|
8533
|
+
// through the same per-route resolution the choice above was made with,
|
|
8534
|
+
// so the fallback cannot be enabled against a route the node-wide field
|
|
8535
|
+
// happens not to describe (TOON_Network#111).
|
|
8536
|
+
...requiredTransportFor(description, destination) === "btp" ? {} : { fallback: http2 },
|
|
8304
8537
|
...this.config.btp.maxReconnectAttempts !== void 0 ? { maxReconnectAttempts: this.config.btp.maxReconnectAttempts } : {},
|
|
8305
8538
|
...this.config.btp.reconnectDelay !== void 0 ? { reconnectDelay: this.config.btp.reconnectDelay } : {}
|
|
8306
8539
|
})
|
|
8307
8540
|
};
|
|
8308
|
-
this.
|
|
8541
|
+
this.carriages.btp = carriage;
|
|
8309
8542
|
return carriage;
|
|
8310
8543
|
}
|
|
8311
8544
|
/**
|
|
@@ -8389,16 +8622,27 @@ function httpEndpointOf(description, connector) {
|
|
|
8389
8622
|
async function openHiddenService(resolved, config) {
|
|
8390
8623
|
const socksProxy = resolved.socksProxy;
|
|
8391
8624
|
if (socksProxy === void 0) return void 0;
|
|
8392
|
-
const { createHiddenServiceTransport, probeSocks5Proxy } = await import("./socks-
|
|
8625
|
+
const { createChainRpcTransport, createHiddenServiceTransport, probeSocks5Proxy } = await import("./socks-K6QOOWJ5.js");
|
|
8393
8626
|
await probeSocks5Proxy(socksProxy);
|
|
8394
|
-
const
|
|
8627
|
+
const edge = createHiddenServiceTransport(socksProxy);
|
|
8628
|
+
const rpc = resolved.proxyRpc ? {
|
|
8629
|
+
evm: createChainRpcTransport(socksProxy, "evm"),
|
|
8630
|
+
solana: createChainRpcTransport(socksProxy, "solana")
|
|
8631
|
+
} : void 0;
|
|
8395
8632
|
return {
|
|
8396
|
-
transport
|
|
8633
|
+
transport: {
|
|
8634
|
+
async close() {
|
|
8635
|
+
await Promise.all([edge.close(), rpc?.evm.close(), rpc?.solana.close()]);
|
|
8636
|
+
}
|
|
8637
|
+
},
|
|
8397
8638
|
config: {
|
|
8398
8639
|
...resolved,
|
|
8399
|
-
fetch: config.fetch ??
|
|
8400
|
-
createWebSocket: config.createWebSocket ??
|
|
8401
|
-
|
|
8640
|
+
fetch: config.fetch ?? edge.fetch,
|
|
8641
|
+
createWebSocket: config.createWebSocket ?? edge.createWebSocket,
|
|
8642
|
+
chainRpc: rpc === void 0 ? void 0 : {
|
|
8643
|
+
evm: { dispatcher: rpc.evm.dispatcher, fetch: rpc.evm.fetch },
|
|
8644
|
+
solana: { dispatcher: rpc.solana.dispatcher, fetch: rpc.solana.fetch }
|
|
8645
|
+
}
|
|
8402
8646
|
}
|
|
8403
8647
|
};
|
|
8404
8648
|
}
|
|
@@ -8412,6 +8656,7 @@ export {
|
|
|
8412
8656
|
ChainUnavailableError,
|
|
8413
8657
|
ChannelNotOpenError,
|
|
8414
8658
|
RouteNotPricedError,
|
|
8659
|
+
BeforePayRefusedError,
|
|
8415
8660
|
PaymentRequiredError,
|
|
8416
8661
|
TransportRequiredError,
|
|
8417
8662
|
ChannelFundingError,
|
|
@@ -8424,6 +8669,7 @@ export {
|
|
|
8424
8669
|
TransferUnsupportedError,
|
|
8425
8670
|
isInsufficientGasError,
|
|
8426
8671
|
chainUnavailableMessage,
|
|
8672
|
+
TransactionOutcomeError,
|
|
8427
8673
|
BTPMessageType,
|
|
8428
8674
|
ILPPacketType,
|
|
8429
8675
|
serializeIlpPrepare,
|
|
@@ -8487,6 +8733,7 @@ export {
|
|
|
8487
8733
|
sameSettlementAddress,
|
|
8488
8734
|
counterpartyMatch,
|
|
8489
8735
|
ChannelManager,
|
|
8736
|
+
PROXIED_RPC_DEFAULTS,
|
|
8490
8737
|
rpcTransport,
|
|
8491
8738
|
rpcFetch,
|
|
8492
8739
|
TOKEN_NETWORK_ABI,
|
|
@@ -8497,6 +8744,7 @@ export {
|
|
|
8497
8744
|
MIN_SETTLEMENT_TIMEOUT_SECONDS,
|
|
8498
8745
|
TokenNetworkClient,
|
|
8499
8746
|
parseEvmChainId,
|
|
8747
|
+
SolanaRpcTransportError,
|
|
8500
8748
|
OnChainChannelClient,
|
|
8501
8749
|
SolanaSigner,
|
|
8502
8750
|
OerErrorKind,
|
|
@@ -8559,4 +8807,4 @@ export {
|
|
|
8559
8807
|
toEnvelopeRequest,
|
|
8560
8808
|
ToonClient
|
|
8561
8809
|
};
|
|
8562
|
-
//# sourceMappingURL=chunk-
|
|
8810
|
+
//# sourceMappingURL=chunk-G36D22II.js.map
|