@toon-protocol/client 3.0.0 → 3.1.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/{chunk-GDWZ736I.js → chunk-KQE6S23B.js} +157 -2
- package/dist/chunk-KQE6S23B.js.map +1 -0
- package/dist/cli/main.js +1 -1
- package/dist/{client-TEP26FMO.js → client-AV355FHQ.js} +2 -2
- package/dist/index.d.ts +164 -6
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-GDWZ736I.js.map +0 -1
- /package/dist/{client-TEP26FMO.js.map → client-AV355FHQ.js.map} +0 -0
package/dist/cli/main.js
CHANGED
|
@@ -542,7 +542,7 @@ function buildClientConfig(settings, keys) {
|
|
|
542
542
|
};
|
|
543
543
|
}
|
|
544
544
|
async function defaultCreateClient(config) {
|
|
545
|
-
const module = await import("../client-
|
|
545
|
+
const module = await import("../client-AV355FHQ.js");
|
|
546
546
|
const factory = module.ToonClient;
|
|
547
547
|
if (factory === void 0) {
|
|
548
548
|
throw new Error(
|
|
@@ -30,7 +30,7 @@ import {
|
|
|
30
30
|
send,
|
|
31
31
|
settlementToTerms,
|
|
32
32
|
toEnvelopeRequest
|
|
33
|
-
} from "./chunk-
|
|
33
|
+
} from "./chunk-KQE6S23B.js";
|
|
34
34
|
import "./chunk-7MPONJW5.js";
|
|
35
35
|
import "./chunk-32MD3CXE.js";
|
|
36
36
|
export {
|
|
@@ -66,4 +66,4 @@ export {
|
|
|
66
66
|
settlementToTerms,
|
|
67
67
|
toEnvelopeRequest
|
|
68
68
|
};
|
|
69
|
-
//# sourceMappingURL=client-
|
|
69
|
+
//# sourceMappingURL=client-AV355FHQ.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -535,6 +535,23 @@ interface ClaimSendingTransport$1 extends IlpClient {
|
|
|
535
535
|
interface ChannelStoreEntry {
|
|
536
536
|
nonce: number;
|
|
537
537
|
cumulativeAmount: bigint;
|
|
538
|
+
/**
|
|
539
|
+
* The highest cumulative this client has ever SIGNED on the channel, which a
|
|
540
|
+
* rollback deliberately does not lower. It is the ceiling on what the
|
|
541
|
+
* connector can possibly have banked — nothing it never received a signature
|
|
542
|
+
* for is claimable — and so the clamp on adopting the connector's own figure
|
|
543
|
+
* (see {@link ChannelManager.adoptConnectorWatermark}).
|
|
544
|
+
*/
|
|
545
|
+
signedCeiling?: bigint;
|
|
546
|
+
/**
|
|
547
|
+
* Set when a signed claim's fate is unknown (a transport error or a timeout,
|
|
548
|
+
* where the packet may have been delivered and banked anyway) or when the
|
|
549
|
+
* connector refused one. It means "our watermark and the connector's may
|
|
550
|
+
* disagree", and the next claim on this channel reconciles against
|
|
551
|
+
* `POST /ilp/claim-state` before it is signed. Persisted because a timeout in
|
|
552
|
+
* one `toon` invocation desyncs the next one.
|
|
553
|
+
*/
|
|
554
|
+
watermarkUncertain?: boolean;
|
|
538
555
|
/** Unix SECONDS when close was initiated (withdraw flow). */
|
|
539
556
|
closedAt?: bigint;
|
|
540
557
|
/** Unix SECONDS the channel becomes settleable (= closedAt + settlementTimeout). */
|
|
@@ -1593,12 +1610,28 @@ interface RoutePrice extends RouteCharge {
|
|
|
1593
1610
|
* bytes of `SealedExchange.data`, not the caller's request body, which is
|
|
1594
1611
|
* smaller by the envelope and the wrap. So a charge can only be computed after
|
|
1595
1612
|
* sealing, which is why {@link ../client/send.js!send} seals before it prices.
|
|
1596
|
-
*
|
|
1597
|
-
*
|
|
1598
|
-
* `
|
|
1599
|
-
*
|
|
1600
|
-
*
|
|
1601
|
-
*
|
|
1613
|
+
* Those bytes are the PREPARE's `data` field verbatim on both carriages
|
|
1614
|
+
* (`HttpIlpClient.postPrepare`, `BtpRuntimeClient`), so `sealedBytes` is exactly
|
|
1615
|
+
* the `prepare.data.len()` the connector prices — no envelope, header or framing
|
|
1616
|
+
* sits between the two counts.
|
|
1617
|
+
*
|
|
1618
|
+
* The unit count is `ceil(bytes / 1024)`: whole kibibytes plus one for any
|
|
1619
|
+
* remainder, and **zero** for an empty payload, which pays the base alone. That
|
|
1620
|
+
* is the connector's own `Price::charge`
|
|
1621
|
+
* (`connector-domain/src/price.rs`, `bytes.div_ceil(1024)`, connector ADR 0065),
|
|
1622
|
+
* evaluated there against the same `prepare.data.len()` at every gate that
|
|
1623
|
+
* charges — the client edge, the peer price gate, and the termination.
|
|
1624
|
+
*
|
|
1625
|
+
* Measured against the deployed store node at `1000 + 10/KiB`, whose x402
|
|
1626
|
+
* greeting quotes the charge for the packet it was handed:
|
|
1627
|
+
* 0 bytes → 1000, 1 → 1010, 1023 → 1010, **1024 → 1010**, 1025 → 1020,
|
|
1628
|
+
* **2048 → 1020**, 2049 → 1030, 5161 → 1060.
|
|
1629
|
+
*
|
|
1630
|
+
* This used to compute `floor(bytes / 1024) + 1` (toon-client#629), which agrees
|
|
1631
|
+
* with `ceil` everywhere except an exact multiple of 1024 and an empty payload,
|
|
1632
|
+
* where it charged one kibibyte too many. Every size that had actually been
|
|
1633
|
+
* measured was a non-multiple, so the fit held and the overpay — silent, since a
|
|
1634
|
+
* claim that advances more than the price is simply accepted — went unnoticed.
|
|
1602
1635
|
*/
|
|
1603
1636
|
declare function chargeFor(terms: RouteCharge, sealedBytes: number): bigint;
|
|
1604
1637
|
/** Which carriage a route insists on, when its routes agree on one. */
|
|
@@ -2739,6 +2772,23 @@ declare class ToonClient implements ToonClientLike {
|
|
|
2739
2772
|
private sealKey;
|
|
2740
2773
|
/** The sealing key of a node named by its client-edge URL. */
|
|
2741
2774
|
private sealKeyAt;
|
|
2775
|
+
/**
|
|
2776
|
+
* Re-read the connector's own watermark for one channel and adopt it
|
|
2777
|
+
* (toon-client#671).
|
|
2778
|
+
*
|
|
2779
|
+
* Called by {@link send} before signing a claim on a channel whose last claim
|
|
2780
|
+
* was signed and never confirmed — a transport error, a timeout, or a refusal.
|
|
2781
|
+
* A packet that timed out on a long path may have been delivered and banked
|
|
2782
|
+
* anyway, and the local figure would then be one claim behind for good: every
|
|
2783
|
+
* later claim under-advances and is refused. The connector's figure is the one
|
|
2784
|
+
* that decides, so it is asked, and {@link ChannelManager.adoptConnectorWatermark}
|
|
2785
|
+
* takes it (clamped to what this client has actually signed).
|
|
2786
|
+
*
|
|
2787
|
+
* A channel the connector cannot verify (`ok: false`) leaves the doubt in
|
|
2788
|
+
* place rather than resolving it wrongly — `"unverified"` covers "no such
|
|
2789
|
+
* channel" and "bad signature" identically, and neither is a watermark.
|
|
2790
|
+
*/
|
|
2791
|
+
private reconcileWatermark;
|
|
2742
2792
|
/**
|
|
2743
2793
|
* Retire the binding a refused claim was drawn on. `false` when there is
|
|
2744
2794
|
* nothing to retire, which is {@link send}'s signal not to retry.
|
|
@@ -3000,6 +3050,18 @@ declare function decodeEnvelope(buf: Uint8Array, direction: 'request' | 'respons
|
|
|
3000
3050
|
* {@link ../client/send.js} calls it on every refusal path — including a thrown
|
|
3001
3051
|
* transport error, where nothing is known to have arrived at all.
|
|
3002
3052
|
*
|
|
3053
|
+
* ## And a refusal that never arrives
|
|
3054
|
+
*
|
|
3055
|
+
* Rolling back on a thrown transport error assumes nothing arrived, which is
|
|
3056
|
+
* the safer guess but is sometimes simply wrong: a request that times out on a
|
|
3057
|
+
* long path can have been delivered and banked anyway, and then our figure is
|
|
3058
|
+
* one claim BEHIND the connector's rather than level with it. Every later claim
|
|
3059
|
+
* under-advances and is refused (toon-client#671). So the assumption is no
|
|
3060
|
+
* longer left standing: {@link ChannelManager.markWatermarkUncertain} records
|
|
3061
|
+
* the doubt, and the next claim on that channel resolves it against the
|
|
3062
|
+
* connector's own watermark through
|
|
3063
|
+
* {@link ChannelManager.adoptConnectorWatermark} before it is signed.
|
|
3064
|
+
*
|
|
3003
3065
|
* ## The binding
|
|
3004
3066
|
*
|
|
3005
3067
|
* A binding says "this is the channel I hold with THAT connector, on THAT chain,
|
|
@@ -3009,6 +3071,25 @@ declare function decodeEnvelope(buf: Uint8Array, direction: 'request' | 'respons
|
|
|
3009
3071
|
* a second lot of collateral.
|
|
3010
3072
|
*/
|
|
3011
3073
|
|
|
3074
|
+
/**
|
|
3075
|
+
* What {@link ChannelManager.adoptConnectorWatermark} did.
|
|
3076
|
+
*
|
|
3077
|
+
* `moved` is signed: positive when the connector had banked MORE than we had
|
|
3078
|
+
* recorded (the timed-out packet was delivered after all), negative when it had
|
|
3079
|
+
* banked less (a claim we signed never reached it). `clampedTo` is present only
|
|
3080
|
+
* when the connector reported a figure above anything we ever signed — which it
|
|
3081
|
+
* cannot have a claim for, and which was therefore not adopted.
|
|
3082
|
+
*/
|
|
3083
|
+
type WatermarkAdoption = {
|
|
3084
|
+
adopted: false;
|
|
3085
|
+
moved: bigint;
|
|
3086
|
+
} | {
|
|
3087
|
+
adopted: true;
|
|
3088
|
+
moved: bigint;
|
|
3089
|
+
cumulative: bigint;
|
|
3090
|
+
nonce: number;
|
|
3091
|
+
clampedTo?: bigint;
|
|
3092
|
+
};
|
|
3012
3093
|
interface ChannelManagerConfig {
|
|
3013
3094
|
/**
|
|
3014
3095
|
* Collateral (base units) {@link ChannelManager.ensureChannel} locks when it
|
|
@@ -3197,10 +3278,75 @@ declare class ChannelManager {
|
|
|
3197
3278
|
* Re-signing at the next nonce with the restored cumulative is exactly what the
|
|
3198
3279
|
* spec's own remedy for an over-deposit refusal describes.
|
|
3199
3280
|
*
|
|
3281
|
+
* **The signed ceiling is not rolled back either.** What was signed was
|
|
3282
|
+
* signed, and the ceiling exists to remember exactly that — it bounds what
|
|
3283
|
+
* {@link ChannelManager.adoptConnectorWatermark} will believe the connector
|
|
3284
|
+
* when it reports having banked.
|
|
3285
|
+
*
|
|
3200
3286
|
* Clamped at zero, and a no-op for an untracked channel: this runs on error
|
|
3201
3287
|
* paths, and an error path that throws its own error hides the original.
|
|
3202
3288
|
*/
|
|
3203
3289
|
rollbackAmount(channelId: string, amount: bigint): void;
|
|
3290
|
+
/**
|
|
3291
|
+
* Record that this channel's watermark is in DOUBT: the last claim signed on
|
|
3292
|
+
* it was either sent into a transport error or a timeout — where the packet
|
|
3293
|
+
* may have been delivered and banked regardless of what this end saw — or was
|
|
3294
|
+
* refused by the connector. Either way our figure and the connector's may no
|
|
3295
|
+
* longer agree, and guessing which way costs a refused claim per request
|
|
3296
|
+
* (toon-client#671).
|
|
3297
|
+
*
|
|
3298
|
+
* The doubt is recorded rather than resolved, because resolving it here would
|
|
3299
|
+
* mean a second network round trip bolted onto a request that has already
|
|
3300
|
+
* failed, to a connector that may be exactly what is unreachable. It is
|
|
3301
|
+
* resolved instead at the one moment the answer is actually needed — before
|
|
3302
|
+
* the NEXT claim is signed — by {@link ChannelManager.adoptConnectorWatermark}
|
|
3303
|
+
* with what `POST /ilp/claim-state` reports.
|
|
3304
|
+
*
|
|
3305
|
+
* Persisted, and a no-op for an untracked channel: this runs on error paths.
|
|
3306
|
+
*/
|
|
3307
|
+
markWatermarkUncertain(channelId: string): void;
|
|
3308
|
+
/**
|
|
3309
|
+
* Record that this channel's watermark is known good again: the connector
|
|
3310
|
+
* banked the claim we signed, at the figure we signed it at, so the two agree
|
|
3311
|
+
* by construction.
|
|
3312
|
+
*
|
|
3313
|
+
* The cheap half of the reconciliation — a banked claim is proof, and proof
|
|
3314
|
+
* costs nothing, where {@link ChannelManager.adoptConnectorWatermark} costs a
|
|
3315
|
+
* round trip. Without it a channel that once timed out would re-read the
|
|
3316
|
+
* connector's watermark before every later claim.
|
|
3317
|
+
*/
|
|
3318
|
+
markWatermarkCertain(channelId: string): void;
|
|
3319
|
+
/** Whether the next claim on `channelId` must reconcile before it is signed. */
|
|
3320
|
+
isWatermarkUncertain(channelId: string): boolean;
|
|
3321
|
+
/**
|
|
3322
|
+
* Adopt the connector's OWN watermark for a channel, and clear the doubt
|
|
3323
|
+
* {@link ChannelManager.markWatermarkUncertain} recorded.
|
|
3324
|
+
*
|
|
3325
|
+
* The connector's figure is the one that decides — a claim is validated
|
|
3326
|
+
* against what IT has banked (`client-edge-spec.md` §1.3) — so on a
|
|
3327
|
+
* disagreement it is adopted rather than argued with. Two guards make that
|
|
3328
|
+
* safe to do with a number that arrived over the network:
|
|
3329
|
+
*
|
|
3330
|
+
* - **The cumulative is clamped to {@link ChannelTracking.signedCeiling}**,
|
|
3331
|
+
* the highest figure this client has ever signed. A connector can only bank
|
|
3332
|
+
* a claim it holds our signature for, so a report above that ceiling is not
|
|
3333
|
+
* a fact about this channel and must not become one: adopting it would sign
|
|
3334
|
+
* away value that was never spent. The clamp is the whole reason the ceiling
|
|
3335
|
+
* is tracked.
|
|
3336
|
+
* - **The nonce only ever rises.** A claim is a bearer instrument and a nonce
|
|
3337
|
+
* is the only thing that stops one being re-issued, so the local nonce moves
|
|
3338
|
+
* to whichever of the two figures is higher — never down to the connector's,
|
|
3339
|
+
* even when the connector's is lower because a claim we signed never reached
|
|
3340
|
+
* it.
|
|
3341
|
+
*
|
|
3342
|
+
* @returns what was adopted, and how far the cumulative moved (negative when
|
|
3343
|
+
* the connector had banked LESS than we had recorded), so a caller can say
|
|
3344
|
+
* so out loud.
|
|
3345
|
+
*/
|
|
3346
|
+
adoptConnectorWatermark(channelId: string, connector: {
|
|
3347
|
+
nonce: number;
|
|
3348
|
+
cumulativeClaimed: bigint;
|
|
3349
|
+
}): WatermarkAdoption;
|
|
3204
3350
|
private buildMetadata;
|
|
3205
3351
|
/** The last nonce signed on a tracked channel. */
|
|
3206
3352
|
getNonce(channelId: string): number;
|
|
@@ -3307,6 +3453,18 @@ interface SendContext {
|
|
|
3307
3453
|
evictChannel(channelId: string): boolean;
|
|
3308
3454
|
/** The watermark and the signers. */
|
|
3309
3455
|
channels: ChannelManager;
|
|
3456
|
+
/**
|
|
3457
|
+
* Re-read the connector's own watermark for `channelId`
|
|
3458
|
+
* (`POST /ilp/claim-state`) and adopt it, settling a doubt
|
|
3459
|
+
* {@link ChannelManager.markWatermarkUncertain} recorded.
|
|
3460
|
+
*
|
|
3461
|
+
* Optional: a context with no client edge to ask simply keeps the older
|
|
3462
|
+
* behaviour of discovering the disagreement through a refusal. It may throw —
|
|
3463
|
+
* it is a network call, and the connector may be exactly what is unreachable —
|
|
3464
|
+
* and {@link send} treats that as "still in doubt" rather than as a failed
|
|
3465
|
+
* request.
|
|
3466
|
+
*/
|
|
3467
|
+
reconcileWatermark?(channelId: string): Promise<void>;
|
|
3310
3468
|
/** The carriage, chosen and connected. */
|
|
3311
3469
|
transport(description: NodeSelfDescription): Promise<{
|
|
3312
3470
|
kind: 'http' | 'btp';
|
package/dist/index.js
CHANGED
package/package.json
CHANGED