@toon-protocol/client 0.26.0 → 0.26.2
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/index.d.ts +17 -7
- package/dist/index.js +65 -32
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -3273,13 +3273,23 @@ declare class ToonClient {
|
|
|
3273
3273
|
* Picks the settlement chain both `ourChains` and `peerChains` support,
|
|
3274
3274
|
* used by the lightweight bootstrap-fallback negotiation (peer discovered
|
|
3275
3275
|
* but no connector admin registered a chain). Prefers
|
|
3276
|
-
* `this.config.preferredChain`'s family (#485) over array order;
|
|
3277
|
-
*
|
|
3278
|
-
*
|
|
3279
|
-
*
|
|
3280
|
-
*
|
|
3281
|
-
*
|
|
3282
|
-
*
|
|
3276
|
+
* `this.config.preferredChain`'s family (#485) over array order; picks the
|
|
3277
|
+
* first mutually-supported chain (legacy behavior) when unconfigured.
|
|
3278
|
+
*
|
|
3279
|
+
* Chains are matched by {@link canonicalChainId} rather than exact string
|
|
3280
|
+
* equality (#500): the devnet preset's family-qualified `evm:base:84532`
|
|
3281
|
+
* and the live apex's unqualified `evm:84532` name the same chain, and
|
|
3282
|
+
* exact matching skipped straight past it to the next mutually-supported
|
|
3283
|
+
* chain (`solana:devnet`) — negotiating a chain nobody asked for instead
|
|
3284
|
+
* of failing loudly. The PEER's own chain string is returned (not ours),
|
|
3285
|
+
* since callers index the peer's own `settlementAddresses` /
|
|
3286
|
+
* `preferredTokens` / `tokenNetworks` maps with it.
|
|
3287
|
+
*
|
|
3288
|
+
* @throws {ToonClientError} `CHAIN_NOT_SUPPORTED` naming both chain sets
|
|
3289
|
+
* when no common chain exists — a caller explicitly configured this
|
|
3290
|
+
* peer as a counterparty, so silently negotiating a different chain (or
|
|
3291
|
+
* returning nothing) would hide a real incompatibility behind an
|
|
3292
|
+
* unrelated failure several layers downstream (#500).
|
|
3283
3293
|
*/
|
|
3284
3294
|
private matchNegotiatedChain;
|
|
3285
3295
|
/**
|
package/dist/index.js
CHANGED
|
@@ -5031,11 +5031,12 @@ async function initializeHttpMode(config) {
|
|
|
5031
5031
|
supportsUpgrade: config.connectorSupportsUpgrade
|
|
5032
5032
|
});
|
|
5033
5033
|
const transportChoice = discoveredPeer.httpEndpoint || discoveredPeer.btpEndpoint ? selectIlpTransport(discoveredPeer, { needsDuplex: false }) : null;
|
|
5034
|
+
const btpPeerId = config.btpPeerId ?? config.ilpInfo.ilpAddress;
|
|
5034
5035
|
let btpClient = null;
|
|
5035
5036
|
if (effectiveBtpUrl) {
|
|
5036
5037
|
btpClient = new BtpRuntimeClient({
|
|
5037
5038
|
btpUrl: effectiveBtpUrl,
|
|
5038
|
-
peerId:
|
|
5039
|
+
peerId: btpPeerId,
|
|
5039
5040
|
authToken: config.btpAuthToken ?? "",
|
|
5040
5041
|
// Serve-side job registration (toon-client#494): a connector-originated
|
|
5041
5042
|
// MESSAGE carrying a PREPARE is answered by the configured handler.
|
|
@@ -5049,7 +5050,7 @@ async function initializeHttpMode(config) {
|
|
|
5049
5050
|
if (transportChoice && (transportChoice.kind === "http" || transportChoice.kind === "http-upgradable")) {
|
|
5050
5051
|
httpIlpClient = new HttpIlpClient({
|
|
5051
5052
|
httpEndpoint: transportChoice.httpEndpoint,
|
|
5052
|
-
|
|
5053
|
+
peerId: btpPeerId,
|
|
5053
5054
|
...config.btpAuthToken !== void 0 ? { authToken: config.btpAuthToken } : {},
|
|
5054
5055
|
timeout: config.queryTimeout,
|
|
5055
5056
|
maxRetries: config.maxRetries,
|
|
@@ -7719,6 +7720,19 @@ function parseMakerMinaSignature(raw) {
|
|
|
7719
7720
|
}
|
|
7720
7721
|
return void 0;
|
|
7721
7722
|
}
|
|
7723
|
+
function canonicalChainId(chain) {
|
|
7724
|
+
const parts = chain.split(":");
|
|
7725
|
+
return parts[0] === "evm" && parts.length >= 3 ? `evm:${parts[2]}` : chain;
|
|
7726
|
+
}
|
|
7727
|
+
function lookupByCanonicalChain(map, chain) {
|
|
7728
|
+
if (!map) return void 0;
|
|
7729
|
+
if (map[chain] !== void 0) return map[chain];
|
|
7730
|
+
const canonical = canonicalChainId(chain);
|
|
7731
|
+
for (const [key2, value] of Object.entries(map)) {
|
|
7732
|
+
if (canonicalChainId(key2) === canonical) return value;
|
|
7733
|
+
}
|
|
7734
|
+
return void 0;
|
|
7735
|
+
}
|
|
7722
7736
|
var ToonClient = class {
|
|
7723
7737
|
config;
|
|
7724
7738
|
state = null;
|
|
@@ -7961,20 +7975,24 @@ var ToonClient = class {
|
|
|
7961
7975
|
peerChains,
|
|
7962
7976
|
result.registeredPeerId
|
|
7963
7977
|
);
|
|
7964
|
-
|
|
7965
|
-
|
|
7966
|
-
|
|
7967
|
-
|
|
7968
|
-
|
|
7969
|
-
|
|
7970
|
-
|
|
7971
|
-
|
|
7972
|
-
|
|
7973
|
-
|
|
7974
|
-
|
|
7975
|
-
|
|
7976
|
-
|
|
7977
|
-
|
|
7978
|
+
const peerAddr = peerInfo.settlementAddresses?.[matchedChain];
|
|
7979
|
+
const parts = matchedChain.split(":");
|
|
7980
|
+
const chainId = parts.length >= 3 ? parseInt(parts[2] ?? "0", 10) : parts.length >= 2 ? parseInt(parts[1] ?? "0", 10) : 0;
|
|
7981
|
+
if (peerAddr) {
|
|
7982
|
+
this.peerNegotiations.set(result.registeredPeerId, {
|
|
7983
|
+
chain: matchedChain,
|
|
7984
|
+
chainType: parts[0] ?? "evm",
|
|
7985
|
+
chainId: isNaN(chainId) ? 0 : chainId,
|
|
7986
|
+
settlementAddress: peerAddr,
|
|
7987
|
+
tokenAddress: peerInfo.preferredTokens?.[matchedChain] ?? lookupByCanonicalChain(
|
|
7988
|
+
this.config.preferredTokens,
|
|
7989
|
+
matchedChain
|
|
7990
|
+
),
|
|
7991
|
+
tokenNetwork: peerInfo.tokenNetworks?.[matchedChain] ?? lookupByCanonicalChain(
|
|
7992
|
+
this.config.tokenNetworks,
|
|
7993
|
+
matchedChain
|
|
7994
|
+
)
|
|
7995
|
+
});
|
|
7978
7996
|
}
|
|
7979
7997
|
}
|
|
7980
7998
|
if (this.channelManager && result.channelId && !this.channelManager.isTracking(result.channelId)) {
|
|
@@ -9234,29 +9252,44 @@ var ToonClient = class {
|
|
|
9234
9252
|
* Picks the settlement chain both `ourChains` and `peerChains` support,
|
|
9235
9253
|
* used by the lightweight bootstrap-fallback negotiation (peer discovered
|
|
9236
9254
|
* but no connector admin registered a chain). Prefers
|
|
9237
|
-
* `this.config.preferredChain`'s family (#485) over array order;
|
|
9238
|
-
*
|
|
9239
|
-
*
|
|
9255
|
+
* `this.config.preferredChain`'s family (#485) over array order; picks the
|
|
9256
|
+
* first mutually-supported chain (legacy behavior) when unconfigured.
|
|
9257
|
+
*
|
|
9258
|
+
* Chains are matched by {@link canonicalChainId} rather than exact string
|
|
9259
|
+
* equality (#500): the devnet preset's family-qualified `evm:base:84532`
|
|
9260
|
+
* and the live apex's unqualified `evm:84532` name the same chain, and
|
|
9261
|
+
* exact matching skipped straight past it to the next mutually-supported
|
|
9262
|
+
* chain (`solana:devnet`) — negotiating a chain nobody asked for instead
|
|
9263
|
+
* of failing loudly. The PEER's own chain string is returned (not ours),
|
|
9264
|
+
* since callers index the peer's own `settlementAddresses` /
|
|
9265
|
+
* `preferredTokens` / `tokenNetworks` maps with it.
|
|
9240
9266
|
*
|
|
9241
|
-
* @throws {ToonClientError} `CHAIN_NOT_SUPPORTED`
|
|
9242
|
-
*
|
|
9243
|
-
*
|
|
9267
|
+
* @throws {ToonClientError} `CHAIN_NOT_SUPPORTED` naming both chain sets
|
|
9268
|
+
* when no common chain exists — a caller explicitly configured this
|
|
9269
|
+
* peer as a counterparty, so silently negotiating a different chain (or
|
|
9270
|
+
* returning nothing) would hide a real incompatibility behind an
|
|
9271
|
+
* unrelated failure several layers downstream (#500).
|
|
9244
9272
|
*/
|
|
9245
9273
|
matchNegotiatedChain(ourChains, peerChains, peerId) {
|
|
9274
|
+
const peerByCanonical = new Map(
|
|
9275
|
+
peerChains.map((c) => [canonicalChainId(c), c])
|
|
9276
|
+
);
|
|
9246
9277
|
const preferred = this.config.preferredChain;
|
|
9278
|
+
const candidates = preferred ? ourChains.filter((c) => c.split(":")[0] === preferred) : ourChains;
|
|
9279
|
+
for (const c of candidates) {
|
|
9280
|
+
const peerMatch = peerByCanonical.get(canonicalChainId(c));
|
|
9281
|
+
if (peerMatch) return peerMatch;
|
|
9282
|
+
}
|
|
9247
9283
|
if (preferred) {
|
|
9248
|
-
|
|
9249
|
-
|
|
9284
|
+
throw new ToonClientError(
|
|
9285
|
+
`Configured chain "${preferred}" is not supported by peer "${peerId}" (peer supportedChains: ${peerChains.join(", ") || "(none)"}).`,
|
|
9286
|
+
"CHAIN_NOT_SUPPORTED"
|
|
9250
9287
|
);
|
|
9251
|
-
if (!matched) {
|
|
9252
|
-
throw new ToonClientError(
|
|
9253
|
-
`Configured chain "${preferred}" is not supported by peer "${peerId}" (peer supportedChains: ${peerChains.join(", ") || "(none)"}).`,
|
|
9254
|
-
"CHAIN_NOT_SUPPORTED"
|
|
9255
|
-
);
|
|
9256
|
-
}
|
|
9257
|
-
return matched;
|
|
9258
9288
|
}
|
|
9259
|
-
|
|
9289
|
+
throw new ToonClientError(
|
|
9290
|
+
`No common settlement chain with peer "${peerId}" (our supportedChains: ${ourChains.join(", ") || "(none)"}; peer supportedChains: ${peerChains.join(", ") || "(none)"}).`,
|
|
9291
|
+
"CHAIN_NOT_SUPPORTED"
|
|
9292
|
+
);
|
|
9260
9293
|
}
|
|
9261
9294
|
/**
|
|
9262
9295
|
* Gets the default chain context: the explicitly-configured
|