@toon-protocol/client 0.26.0 → 0.26.1
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 +62 -30
- 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
|
@@ -7719,6 +7719,19 @@ function parseMakerMinaSignature(raw) {
|
|
|
7719
7719
|
}
|
|
7720
7720
|
return void 0;
|
|
7721
7721
|
}
|
|
7722
|
+
function canonicalChainId(chain) {
|
|
7723
|
+
const parts = chain.split(":");
|
|
7724
|
+
return parts[0] === "evm" && parts.length >= 3 ? `evm:${parts[2]}` : chain;
|
|
7725
|
+
}
|
|
7726
|
+
function lookupByCanonicalChain(map, chain) {
|
|
7727
|
+
if (!map) return void 0;
|
|
7728
|
+
if (map[chain] !== void 0) return map[chain];
|
|
7729
|
+
const canonical = canonicalChainId(chain);
|
|
7730
|
+
for (const [key2, value] of Object.entries(map)) {
|
|
7731
|
+
if (canonicalChainId(key2) === canonical) return value;
|
|
7732
|
+
}
|
|
7733
|
+
return void 0;
|
|
7734
|
+
}
|
|
7722
7735
|
var ToonClient = class {
|
|
7723
7736
|
config;
|
|
7724
7737
|
state = null;
|
|
@@ -7961,20 +7974,24 @@ var ToonClient = class {
|
|
|
7961
7974
|
peerChains,
|
|
7962
7975
|
result.registeredPeerId
|
|
7963
7976
|
);
|
|
7964
|
-
|
|
7965
|
-
|
|
7966
|
-
|
|
7967
|
-
|
|
7968
|
-
|
|
7969
|
-
|
|
7970
|
-
|
|
7971
|
-
|
|
7972
|
-
|
|
7973
|
-
|
|
7974
|
-
|
|
7975
|
-
|
|
7976
|
-
|
|
7977
|
-
|
|
7977
|
+
const peerAddr = peerInfo.settlementAddresses?.[matchedChain];
|
|
7978
|
+
const parts = matchedChain.split(":");
|
|
7979
|
+
const chainId = parts.length >= 3 ? parseInt(parts[2] ?? "0", 10) : parts.length >= 2 ? parseInt(parts[1] ?? "0", 10) : 0;
|
|
7980
|
+
if (peerAddr) {
|
|
7981
|
+
this.peerNegotiations.set(result.registeredPeerId, {
|
|
7982
|
+
chain: matchedChain,
|
|
7983
|
+
chainType: parts[0] ?? "evm",
|
|
7984
|
+
chainId: isNaN(chainId) ? 0 : chainId,
|
|
7985
|
+
settlementAddress: peerAddr,
|
|
7986
|
+
tokenAddress: peerInfo.preferredTokens?.[matchedChain] ?? lookupByCanonicalChain(
|
|
7987
|
+
this.config.preferredTokens,
|
|
7988
|
+
matchedChain
|
|
7989
|
+
),
|
|
7990
|
+
tokenNetwork: peerInfo.tokenNetworks?.[matchedChain] ?? lookupByCanonicalChain(
|
|
7991
|
+
this.config.tokenNetworks,
|
|
7992
|
+
matchedChain
|
|
7993
|
+
)
|
|
7994
|
+
});
|
|
7978
7995
|
}
|
|
7979
7996
|
}
|
|
7980
7997
|
if (this.channelManager && result.channelId && !this.channelManager.isTracking(result.channelId)) {
|
|
@@ -9234,29 +9251,44 @@ var ToonClient = class {
|
|
|
9234
9251
|
* Picks the settlement chain both `ourChains` and `peerChains` support,
|
|
9235
9252
|
* used by the lightweight bootstrap-fallback negotiation (peer discovered
|
|
9236
9253
|
* but no connector admin registered a chain). Prefers
|
|
9237
|
-
* `this.config.preferredChain`'s family (#485) over array order;
|
|
9238
|
-
*
|
|
9239
|
-
*
|
|
9254
|
+
* `this.config.preferredChain`'s family (#485) over array order; picks the
|
|
9255
|
+
* first mutually-supported chain (legacy behavior) when unconfigured.
|
|
9256
|
+
*
|
|
9257
|
+
* Chains are matched by {@link canonicalChainId} rather than exact string
|
|
9258
|
+
* equality (#500): the devnet preset's family-qualified `evm:base:84532`
|
|
9259
|
+
* and the live apex's unqualified `evm:84532` name the same chain, and
|
|
9260
|
+
* exact matching skipped straight past it to the next mutually-supported
|
|
9261
|
+
* chain (`solana:devnet`) — negotiating a chain nobody asked for instead
|
|
9262
|
+
* of failing loudly. The PEER's own chain string is returned (not ours),
|
|
9263
|
+
* since callers index the peer's own `settlementAddresses` /
|
|
9264
|
+
* `preferredTokens` / `tokenNetworks` maps with it.
|
|
9240
9265
|
*
|
|
9241
|
-
* @throws {ToonClientError} `CHAIN_NOT_SUPPORTED`
|
|
9242
|
-
*
|
|
9243
|
-
*
|
|
9266
|
+
* @throws {ToonClientError} `CHAIN_NOT_SUPPORTED` naming both chain sets
|
|
9267
|
+
* when no common chain exists — a caller explicitly configured this
|
|
9268
|
+
* peer as a counterparty, so silently negotiating a different chain (or
|
|
9269
|
+
* returning nothing) would hide a real incompatibility behind an
|
|
9270
|
+
* unrelated failure several layers downstream (#500).
|
|
9244
9271
|
*/
|
|
9245
9272
|
matchNegotiatedChain(ourChains, peerChains, peerId) {
|
|
9273
|
+
const peerByCanonical = new Map(
|
|
9274
|
+
peerChains.map((c) => [canonicalChainId(c), c])
|
|
9275
|
+
);
|
|
9246
9276
|
const preferred = this.config.preferredChain;
|
|
9277
|
+
const candidates = preferred ? ourChains.filter((c) => c.split(":")[0] === preferred) : ourChains;
|
|
9278
|
+
for (const c of candidates) {
|
|
9279
|
+
const peerMatch = peerByCanonical.get(canonicalChainId(c));
|
|
9280
|
+
if (peerMatch) return peerMatch;
|
|
9281
|
+
}
|
|
9247
9282
|
if (preferred) {
|
|
9248
|
-
|
|
9249
|
-
|
|
9283
|
+
throw new ToonClientError(
|
|
9284
|
+
`Configured chain "${preferred}" is not supported by peer "${peerId}" (peer supportedChains: ${peerChains.join(", ") || "(none)"}).`,
|
|
9285
|
+
"CHAIN_NOT_SUPPORTED"
|
|
9250
9286
|
);
|
|
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
9287
|
}
|
|
9259
|
-
|
|
9288
|
+
throw new ToonClientError(
|
|
9289
|
+
`No common settlement chain with peer "${peerId}" (our supportedChains: ${ourChains.join(", ") || "(none)"}; peer supportedChains: ${peerChains.join(", ") || "(none)"}).`,
|
|
9290
|
+
"CHAIN_NOT_SUPPORTED"
|
|
9291
|
+
);
|
|
9260
9292
|
}
|
|
9261
9293
|
/**
|
|
9262
9294
|
* Gets the default chain context: the explicitly-configured
|