@toon-protocol/client 0.26.2 → 0.28.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/index.d.ts +2075 -1982
- package/dist/index.js +73 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1532,8 +1532,10 @@ function parseConnectorRouteTerms(body) {
|
|
|
1532
1532
|
);
|
|
1533
1533
|
}
|
|
1534
1534
|
const destination = typeof greeting.resource?.url === "string" ? greeting.resource.url : "";
|
|
1535
|
-
const
|
|
1536
|
-
const
|
|
1535
|
+
const rawExtra = option["extra"];
|
|
1536
|
+
const extra = typeof rawExtra === "object" && rawExtra !== null ? rawExtra : void 0;
|
|
1537
|
+
const extraForReads = extra ?? {};
|
|
1538
|
+
const rawSettlements = extraForReads["settlements"];
|
|
1537
1539
|
let settlements;
|
|
1538
1540
|
if (rawSettlements !== void 0) {
|
|
1539
1541
|
if (!Array.isArray(rawSettlements)) {
|
|
@@ -1544,12 +1546,13 @@ function parseConnectorRouteTerms(body) {
|
|
|
1544
1546
|
}
|
|
1545
1547
|
settlements = rawSettlements.map(parseChainSettlementEntry);
|
|
1546
1548
|
}
|
|
1547
|
-
const rawSettlement =
|
|
1549
|
+
const rawSettlement = extraForReads["settlement"];
|
|
1548
1550
|
if (rawSettlement === void 0) {
|
|
1549
1551
|
return {
|
|
1550
1552
|
destination,
|
|
1551
1553
|
price: option["amount"],
|
|
1552
|
-
...settlements ? { settlements } : {}
|
|
1554
|
+
...settlements ? { settlements } : {},
|
|
1555
|
+
...extra !== void 0 ? { extra } : {}
|
|
1553
1556
|
};
|
|
1554
1557
|
}
|
|
1555
1558
|
if (typeof rawSettlement !== "object" || rawSettlement === null) {
|
|
@@ -1564,7 +1567,8 @@ function parseConnectorRouteTerms(body) {
|
|
|
1564
1567
|
settlement: parseEvmSettlementTerms(
|
|
1565
1568
|
rawSettlement
|
|
1566
1569
|
),
|
|
1567
|
-
...settlements ? { settlements } : {}
|
|
1570
|
+
...settlements ? { settlements } : {},
|
|
1571
|
+
...extra !== void 0 ? { extra } : {}
|
|
1568
1572
|
};
|
|
1569
1573
|
}
|
|
1570
1574
|
|
|
@@ -7072,9 +7076,11 @@ var Http402Client = class {
|
|
|
7072
7076
|
createIlpClient;
|
|
7073
7077
|
needsDuplex;
|
|
7074
7078
|
connectorEdge;
|
|
7079
|
+
onChallenge;
|
|
7075
7080
|
constructor(config = {}) {
|
|
7076
7081
|
this.fetchImpl = config.fetch ?? fetch;
|
|
7077
7082
|
this.resolveClaim = config.resolveClaim;
|
|
7083
|
+
this.onChallenge = config.onChallenge;
|
|
7078
7084
|
this.createIlpClient = config.createIlpClient ?? ((httpEndpoint) => new HttpIlpClient({ httpEndpoint }));
|
|
7079
7085
|
this.needsDuplex = config.needsDuplex ?? false;
|
|
7080
7086
|
this.connectorEdge = config.connectorEdge ?? new ConnectorEdgeClient({
|
|
@@ -7099,6 +7105,7 @@ var Http402Client = class {
|
|
|
7099
7105
|
});
|
|
7100
7106
|
if (probe.status !== 402) return probe;
|
|
7101
7107
|
const challenge = await parseX402Challenge(probe.clone());
|
|
7108
|
+
this.onChallenge?.(challenge);
|
|
7102
7109
|
const accept = challenge.toonChannel;
|
|
7103
7110
|
if (!accept || !this.resolveClaim) return probe;
|
|
7104
7111
|
return this.payOverToon(url, method, opts, accept, this.resolveClaim);
|
|
@@ -7235,11 +7242,13 @@ function parseX402Body(body, baseUrl) {
|
|
|
7235
7242
|
const entry = raw;
|
|
7236
7243
|
const scheme = readString(entry, ["scheme"]);
|
|
7237
7244
|
if (scheme !== "toon-channel") continue;
|
|
7238
|
-
const
|
|
7239
|
-
const
|
|
7240
|
-
const
|
|
7245
|
+
const rawExtra = entry["extra"];
|
|
7246
|
+
const extra = typeof rawExtra === "object" && rawExtra !== null ? rawExtra : void 0;
|
|
7247
|
+
const extraForReads = extra ?? {};
|
|
7248
|
+
const destination = readString(extraForReads, ["ilpAddress", "destination"]) ?? readString(entry, ["destination", "ilpAddress", "payTo"]);
|
|
7249
|
+
const rawEndpoint = readString(entry, ["httpEndpoint", "ilpEndpoint"]) ?? readString(extraForReads, ["httpEndpoint", "endpoint"]) ?? readString(entry, ["endpoint"]);
|
|
7241
7250
|
const httpEndpoint = resolveEndpoint(rawEndpoint, baseUrl);
|
|
7242
|
-
const amount = readAmount(
|
|
7251
|
+
const amount = readAmount(extraForReads, ["price", "amount"]) ?? readAmount(entry, ["amount", "price", "maxAmountRequired"]);
|
|
7243
7252
|
if (!destination || !httpEndpoint || amount === void 0) continue;
|
|
7244
7253
|
const network = readString(entry, ["network", "chain"]);
|
|
7245
7254
|
const supportsUpgrade = entry["supportsUpgrade"] === true || entry["upgradable"] === true;
|
|
@@ -7251,7 +7260,8 @@ function parseX402Body(body, baseUrl) {
|
|
|
7251
7260
|
destination,
|
|
7252
7261
|
amount,
|
|
7253
7262
|
httpEndpoint,
|
|
7254
|
-
supportsUpgrade
|
|
7263
|
+
supportsUpgrade,
|
|
7264
|
+
...extra !== void 0 ? { extra } : {}
|
|
7255
7265
|
}
|
|
7256
7266
|
};
|
|
7257
7267
|
}
|
|
@@ -7736,6 +7746,25 @@ function lookupByCanonicalChain(map, chain) {
|
|
|
7736
7746
|
var ToonClient = class {
|
|
7737
7747
|
config;
|
|
7738
7748
|
state = null;
|
|
7749
|
+
/**
|
|
7750
|
+
* The most recently parsed `toon-channel` x402 accepts entry, from the last
|
|
7751
|
+
* `h402Fetch` call that saw a `402` (issue #506) — including its `extra`
|
|
7752
|
+
* bag (e.g. `session_lease_ttl_ms`). Captured whether or not that fetch
|
|
7753
|
+
* went on to pay, so a caller can read the negotiated terms via
|
|
7754
|
+
* {@link getLastX402Terms} without re-issuing the probe by hand.
|
|
7755
|
+
*/
|
|
7756
|
+
lastX402Terms;
|
|
7757
|
+
/**
|
|
7758
|
+
* The most recently parsed `ConnectorRouteTerms`, from the last
|
|
7759
|
+
* `negotiateFromGreeting` call — the greeting parse that ordinary channel
|
|
7760
|
+
* bootstrap (`publishEvent`/`openChannel`/`adoptChannel`) already goes
|
|
7761
|
+
* through, with no separate `h402Fetch` probe needed (issue #509).
|
|
7762
|
+
* Captured whether or not the greeting carried settlement facts to
|
|
7763
|
+
* bootstrap from, so its `extra` bag (e.g. `session_lease_ttl_ms`) is
|
|
7764
|
+
* readable via {@link getLastConnectorRouteTerms} even when the bootstrap
|
|
7765
|
+
* declined to open a channel from that greeting.
|
|
7766
|
+
*/
|
|
7767
|
+
lastConnectorRouteTerms;
|
|
7739
7768
|
evmSigner;
|
|
7740
7769
|
solanaSigner;
|
|
7741
7770
|
/**
|
|
@@ -8287,12 +8316,44 @@ var ToonClient = class {
|
|
|
8287
8316
|
// fresh Http402Client per call (below), and a paid request now needs a
|
|
8288
8317
|
// terminating key.
|
|
8289
8318
|
connectorEdge: this.connectorEdge,
|
|
8319
|
+
// Capture the negotiated terms (issue #506) regardless of the
|
|
8320
|
+
// pay/pass-through outcome — see `lastX402Terms`'s own doc comment.
|
|
8321
|
+
onChallenge: (challenge) => {
|
|
8322
|
+
this.lastX402Terms = challenge.toonChannel;
|
|
8323
|
+
},
|
|
8290
8324
|
...this.channelManager ? {
|
|
8291
8325
|
resolveClaim: (destination, amount) => this.resolveClaimForDestination(destination, amount)
|
|
8292
8326
|
} : {}
|
|
8293
8327
|
});
|
|
8294
8328
|
return client.fetch(url, opts);
|
|
8295
8329
|
}
|
|
8330
|
+
/**
|
|
8331
|
+
* The `toon-channel` accepts entry from the most recent `h402Fetch` 402
|
|
8332
|
+
* probe — including its `extra` bag (issue #506, e.g.
|
|
8333
|
+
* `extra.session_lease_ttl_ms`, connector#722) — or `undefined` if
|
|
8334
|
+
* `h402Fetch` has not yet been called or its last probe offered no
|
|
8335
|
+
* `toon-channel` entry. Captured whether or not that fetch went on to pay,
|
|
8336
|
+
* so a caller (e.g. buzz#84's mesh refresh cadence) can read the
|
|
8337
|
+
* negotiated terms without re-issuing a probe by hand.
|
|
8338
|
+
*/
|
|
8339
|
+
getLastX402Terms() {
|
|
8340
|
+
return this.lastX402Terms;
|
|
8341
|
+
}
|
|
8342
|
+
/**
|
|
8343
|
+
* The `ConnectorRouteTerms` from the most recent ordinary channel
|
|
8344
|
+
* bootstrap (`publishEvent`/`openChannel`/`adoptChannel`, via
|
|
8345
|
+
* `negotiateFromGreeting`) — including its `extra` bag (issue #509, e.g.
|
|
8346
|
+
* `extra.session_lease_ttl_ms`, connector#722) — or `undefined` if no
|
|
8347
|
+
* greeting has been parsed on this path yet. Unlike
|
|
8348
|
+
* {@link getLastX402Terms}, this populates from a client that only ever
|
|
8349
|
+
* calls `start()`/`publishEvent()`: `ConnectorEdgeClient.getRouteTerms` is
|
|
8350
|
+
* the parser the live path actually negotiates through, so a caller does
|
|
8351
|
+
* not need to issue a separate `h402Fetch` probe purely to read the lease
|
|
8352
|
+
* TTL.
|
|
8353
|
+
*/
|
|
8354
|
+
getLastConnectorRouteTerms() {
|
|
8355
|
+
return this.lastConnectorRouteTerms;
|
|
8356
|
+
}
|
|
8296
8357
|
/**
|
|
8297
8358
|
* Sends a raw swap ILP packet (Story 12.5) to a swap peer with an attached
|
|
8298
8359
|
* balance-proof claim. This is a lower-level surface than `publishEvent`:
|
|
@@ -9097,6 +9158,7 @@ var ToonClient = class {
|
|
|
9097
9158
|
}
|
|
9098
9159
|
try {
|
|
9099
9160
|
const terms = await this.connectorEdge.getRouteTerms(edge, destination);
|
|
9161
|
+
this.lastConnectorRouteTerms = terms ?? void 0;
|
|
9100
9162
|
const evmSettlement = terms?.settlement;
|
|
9101
9163
|
const solanaSettlement = terms?.settlements?.find(
|
|
9102
9164
|
(entry) => entry.kind === "solana"
|
|
@@ -11513,6 +11575,7 @@ export {
|
|
|
11513
11575
|
parseClaimStateResponse,
|
|
11514
11576
|
parseConnectorIdentity,
|
|
11515
11577
|
parseConnectorRoutePrice,
|
|
11578
|
+
parseConnectorRouteTerms,
|
|
11516
11579
|
parseEvmChainId2 as parseEvmChainId,
|
|
11517
11580
|
parseUiCoordinate,
|
|
11518
11581
|
parseX402Body,
|