@toon-protocol/client 0.29.6 → 0.29.8
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 +136 -9
- package/dist/index.js +331 -60
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -361,7 +361,9 @@ declare class BtpRuntimeClient implements IlpClient {
|
|
|
361
361
|
* header: `ILP-Payment-Channel-Claim: base64(JSON of the claim)` — the
|
|
362
362
|
* SAME claim JSON the BTP path attaches as the
|
|
363
363
|
* `payment-channel-claim` protocolData entry.
|
|
364
|
-
* optional: `ILP-Peer-Id` + `Authorization: Bearer <secret>` identity
|
|
364
|
+
* optional: `ILP-Peer-Id` + `Authorization: Bearer <secret>` identity —
|
|
365
|
+
* sent as a PAIR or not at all (issue #565), since the connector
|
|
366
|
+
* 401s a presented id it cannot authenticate.
|
|
365
367
|
* response: `200 OK` with an OER FULFILL or REJECT body. HTTP non-2xx is
|
|
366
368
|
* reserved for TRANSPORT errors (400/401/413/5xx); ILP-level
|
|
367
369
|
* rejects come back as a 200 + REJECT body.
|
|
@@ -387,6 +389,10 @@ interface HttpIlpClientConfig {
|
|
|
387
389
|
* Optional peer identity. With no `peerId`/`authToken` the connector treats
|
|
388
390
|
* the request as an anonymous no-auth peer (permissionless default) and
|
|
389
391
|
* derives an ephemeral id from the claim signer.
|
|
392
|
+
*
|
|
393
|
+
* NOTE (issue #565): this is only PRESENTED on the wire when an `authToken`
|
|
394
|
+
* accompanies it — see {@link HttpIlpClient.authHeaders}. It is still used
|
|
395
|
+
* as the BTP auth-frame id on the {@link HttpIlpClient.upgradeToBtp} path.
|
|
390
396
|
*/
|
|
391
397
|
peerId?: string;
|
|
392
398
|
/** Bearer secret for `Authorization`. Omit for the no-auth peer path. */
|
|
@@ -467,6 +473,31 @@ declare class HttpIlpClient implements IlpClient {
|
|
|
467
473
|
* transport or BTP-with-auth-frame instead.
|
|
468
474
|
*/
|
|
469
475
|
upgradeToBtp(): Promise<BtpRuntimeClient>;
|
|
476
|
+
/**
|
|
477
|
+
* The identity headers to present, if any.
|
|
478
|
+
*
|
|
479
|
+
* A peer id and its bearer secret are ONE credential, so both are sent or
|
|
480
|
+
* neither is (issue #565). Presenting a `peerId` this client cannot back
|
|
481
|
+
* with a secret is strictly WORSE than presenting nothing: the connector's
|
|
482
|
+
* client edge resolves a PRESENTED identity first and answers `401` before
|
|
483
|
+
* it ever looks at the route
|
|
484
|
+
* (connector `crates/connector-client-edge/src/lib.rs`, whose own comment
|
|
485
|
+
* reads "A request presenting no `ILP-Peer-Id` is unaffected here — it is
|
|
486
|
+
* anonymous, resolved once the claim (if any) has been admitted"), whereas
|
|
487
|
+
* anonymous + a valid payment-channel claim is the supported permissionless
|
|
488
|
+
* path. The live devnet daemon shipped `ILP-Peer-Id: g.toon.client` with an
|
|
489
|
+
* EMPTY token — an id no connector has a registration for — so every default
|
|
490
|
+
* paid write over `POST /ilp` 401'd before the claim was read at all.
|
|
491
|
+
*
|
|
492
|
+
* An empty-string token is not a credential; `''` is falsy here on purpose.
|
|
493
|
+
*
|
|
494
|
+
* This REMOVES the 401 rather than recovering from it, so it complements
|
|
495
|
+
* #569's {@link Http401RequiresBtpError} fallback instead of replacing it:
|
|
496
|
+
* that fallback still catches a 401 with any other cause, but it costs a
|
|
497
|
+
* failed round trip per write and can only rescue a client that has a BTP
|
|
498
|
+
* uplink — a proxy-only client had no route to a paid write at all, even
|
|
499
|
+
* though anonymous + claim is exactly the path that would have worked.
|
|
500
|
+
*/
|
|
470
501
|
private authHeaders;
|
|
471
502
|
/**
|
|
472
503
|
* Single attempt: serialize the PREPARE, POST it, and map the response.
|
|
@@ -3487,6 +3518,42 @@ declare class ToonClient {
|
|
|
3487
3518
|
* requires BTP but this client has no `btpClient` configured at all.
|
|
3488
3519
|
*/
|
|
3489
3520
|
private getClaimTransport;
|
|
3521
|
+
/**
|
|
3522
|
+
* Sends a claim-bearing PREPARE over the ALREADY-RESOLVED `transport` (a
|
|
3523
|
+
* prior {@link getClaimTransport} call — kept as a separate argument so the
|
|
3524
|
+
* NO_ILP_TRANSPORT/BTP_REQUIRED failure modes of resolving a transport at
|
|
3525
|
+
* all still surface before any claim is resolved, matching every caller's
|
|
3526
|
+
* existing behavior), retrying once over the BTP uplink when it comes back
|
|
3527
|
+
* with a transport signal that says so — {@link btpFallbackSignal}.
|
|
3528
|
+
*
|
|
3529
|
+
* {@link Http402RequiresBtpError} (issue #561) is the first such signal.
|
|
3530
|
+
* `getClaimTransport`'s own `requiredTransport` check ({@link
|
|
3531
|
+
* terminatorRequiresBtp}) reads the peer's kind:10032 announce — but the
|
|
3532
|
+
* live devnet relay's announce never carries that field, only its `402`
|
|
3533
|
+
* response does, and only once a write has already been posted over HTTP.
|
|
3534
|
+
* So the announce-based guard alone is dead code against that fleet: this
|
|
3535
|
+
* is the fallback that actually avoids the repeat-402 loop, discovered
|
|
3536
|
+
* live rather than assumed from the announce.
|
|
3537
|
+
*
|
|
3538
|
+
* `Http401RequiresBtpError` (issue #565) is the same shape of problem from
|
|
3539
|
+
* a different connector generation: the rust edge live on the two-box
|
|
3540
|
+
* devnet answers a discovered/unconfigured peer identity with a bare `401`
|
|
3541
|
+
* rather than the 402 x402 greeting, so it gets the identical retry — both
|
|
3542
|
+
* error types are transport-signal-only and neither implies the write
|
|
3543
|
+
* itself was invalid.
|
|
3544
|
+
*
|
|
3545
|
+
* A retry is attempted only when the failing transport was not already the
|
|
3546
|
+
* BTP one (neither error can come from the BTP transport in the first
|
|
3547
|
+
* place — BTP has no HTTP status codes) and a BTP uplink is actually
|
|
3548
|
+
* configured; otherwise this throws the same `BTP_REQUIRED` error
|
|
3549
|
+
* `getClaimTransport` throws for the announce-based case, so callers see
|
|
3550
|
+
* one consistent code regardless of which guard caught it.
|
|
3551
|
+
*
|
|
3552
|
+
* @throws {ToonClientError} BTP_REQUIRED when the terminator's 401/402
|
|
3553
|
+
* response demands BTP but this client has no BTP uplink (`btpUrl`)
|
|
3554
|
+
* configured.
|
|
3555
|
+
*/
|
|
3556
|
+
private sendClaimBearingPacket;
|
|
3490
3557
|
/**
|
|
3491
3558
|
* Shared claim-resolution logic used by `publishEvent` and `sendSwapPacket`.
|
|
3492
3559
|
*/
|
|
@@ -3510,6 +3577,13 @@ declare class ToonClient {
|
|
|
3510
3577
|
* can force the open. Idempotent — returns the existing channel ID for the
|
|
3511
3578
|
* peer if one is already open.
|
|
3512
3579
|
*
|
|
3580
|
+
* The counterparty is driven by `destination` (issue #565): the channel is
|
|
3581
|
+
* opened against the settlement address of whoever TERMINATES it — an
|
|
3582
|
+
* existing negotiation for that peer, else the terminating kind:10032
|
|
3583
|
+
* announce's own `settlementAddresses`, else the route's x402 greeting. Two
|
|
3584
|
+
* destinations that terminate at different nodes therefore get two channels,
|
|
3585
|
+
* each with the right counterparty.
|
|
3586
|
+
*
|
|
3513
3587
|
* @param destination - Optional ILP destination address. Defaults to
|
|
3514
3588
|
* `config.destinationAddress`.
|
|
3515
3589
|
* @returns The channel ID of the (now) open channel.
|
|
@@ -3739,17 +3813,19 @@ declare class ToonClient {
|
|
|
3739
3813
|
*/
|
|
3740
3814
|
sendTransfer(params: SendTransferParams): Promise<SendTransferResult>;
|
|
3741
3815
|
/**
|
|
3742
|
-
*
|
|
3743
|
-
*
|
|
3744
|
-
*
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
* The peer id a claim for `destination` accounts under. Normally
|
|
3748
|
-
* `resolvePeerId` — but where that throws `PEER_NOT_FOUND` (an empty
|
|
3749
|
-
* negotiation map: nothing announced, nothing registered), the
|
|
3816
|
+
* The peer id a claim for `destination` accounts under — and therefore WHICH
|
|
3817
|
+
* counterparty's channel that claim is drawn on. Normally `resolvePeerId`,
|
|
3818
|
+
* which resolves by identity (an existing negotiation key, or the announce
|
|
3819
|
+
* that terminates `destination`) — but where that throws `PEER_NOT_FOUND`
|
|
3820
|
+
* (nothing announced, nothing registered, nothing unambiguous to guess), the
|
|
3750
3821
|
* destination itself is the key, so the announce-less greeting bootstrap
|
|
3751
3822
|
* (connector #617) has a stable identity to remember its synthesized
|
|
3752
3823
|
* negotiation under.
|
|
3824
|
+
*
|
|
3825
|
+
* Never a positional guess across several peers (issue #565): keying a
|
|
3826
|
+
* second destination onto the first peer's negotiation opens the channel
|
|
3827
|
+
* against the WRONG settlement address, and the real terminator then rejects
|
|
3828
|
+
* every claim (F01 — "names a channel this connector has no record of").
|
|
3753
3829
|
*/
|
|
3754
3830
|
private peerIdForClaim;
|
|
3755
3831
|
/**
|
|
@@ -3835,6 +3911,47 @@ declare class ToonClient {
|
|
|
3835
3911
|
*/
|
|
3836
3912
|
private withSolanaLegHint;
|
|
3837
3913
|
private resolvePeerId;
|
|
3914
|
+
/**
|
|
3915
|
+
* The winning kind:10032 claim on `destination` from this client's discovery
|
|
3916
|
+
* tracker, or `undefined` when there is no tracker yet or no announce claims
|
|
3917
|
+
* it. Probed rather than assumed, exactly as {@link terminatorRequiresBtp}
|
|
3918
|
+
* does — a half-built state (a stub, a client mid-`start()`) simply has
|
|
3919
|
+
* nothing to resolve against, and a missing announce is a normal state, not
|
|
3920
|
+
* an error.
|
|
3921
|
+
*/
|
|
3922
|
+
private terminatorClaimFor;
|
|
3923
|
+
/**
|
|
3924
|
+
* The negotiation to settle `destination` with, in order of authority
|
|
3925
|
+
* (issue #565):
|
|
3926
|
+
*
|
|
3927
|
+
* 1. an ALREADY-negotiated peer (bootstrap, or a host that injected one);
|
|
3928
|
+
* 2. the terminating announce's OWN settlement facts — the counterparty
|
|
3929
|
+
* states its `settlementAddresses`/`tokenNetworks` in the same
|
|
3930
|
+
* kind:10032 event that claims the destination, so this is the
|
|
3931
|
+
* counterparty naming itself rather than us inferring one;
|
|
3932
|
+
* 3. the route's x402 greeting ({@link negotiateFromGreeting}, connector
|
|
3933
|
+
* #617) for an announce-less route.
|
|
3934
|
+
*
|
|
3935
|
+
* Step 2 is what makes a SECOND destination openable at all: bootstrap only
|
|
3936
|
+
* negotiates with `knownPeers`, so a client seeded with the relay had no
|
|
3937
|
+
* negotiation for the store box and used to fall through to the relay's.
|
|
3938
|
+
*/
|
|
3939
|
+
private negotiationFor;
|
|
3940
|
+
/**
|
|
3941
|
+
* The {@link PeerNegotiation} a peer's own kind:10032 announce supports: the
|
|
3942
|
+
* chain both sides support, plus the settlement address / token / token
|
|
3943
|
+
* network THAT PEER advertises for it (falling back to this client's
|
|
3944
|
+
* configured maps only where the announce is silent).
|
|
3945
|
+
*
|
|
3946
|
+
* `undefined` when the announce names no settlement address for the matched
|
|
3947
|
+
* chain — there is nothing to open a channel against, and guessing one is how
|
|
3948
|
+
* a claim ends up unverifiable at the counterparty.
|
|
3949
|
+
*
|
|
3950
|
+
* @throws {ToonClientError} CHAIN_NOT_SUPPORTED when no mutually supported
|
|
3951
|
+
* chain exists (from {@link matchNegotiatedChain}) — bootstrap surfaces
|
|
3952
|
+
* this; the lazy per-destination path catches it.
|
|
3953
|
+
*/
|
|
3954
|
+
private negotiationFromAnnounce;
|
|
3838
3955
|
/**
|
|
3839
3956
|
* Extracts chain context (chainId + tokenNetworkAddress) from a chain key like 'evm:base:421614'.
|
|
3840
3957
|
*/
|
|
@@ -5347,8 +5464,18 @@ declare class ChannelManager {
|
|
|
5347
5464
|
* Update the tracked on-chain deposit total after a successful deposit, so the
|
|
5348
5465
|
* available balance (`depositTotal - cumulativeAmount`) reflects the new
|
|
5349
5466
|
* collateral on the next read.
|
|
5467
|
+
*
|
|
5468
|
+
* Also written through to the peer BINDING (issue #565) — the deposit is an
|
|
5469
|
+
* on-chain fact, so a restart must resume with the collateral that is
|
|
5470
|
+
* actually locked, not the amount recorded when the channel was first opened.
|
|
5350
5471
|
*/
|
|
5351
5472
|
setDepositTotal(channelId: string, total: bigint): void;
|
|
5473
|
+
/**
|
|
5474
|
+
* Write `total` into whichever peer binding names `channelId`. No-op without
|
|
5475
|
+
* a store that persists bindings, or when no binding names this channel (an
|
|
5476
|
+
* untracked/foreign channel has no collateral of ours to record).
|
|
5477
|
+
*/
|
|
5478
|
+
private persistDepositTotal;
|
|
5352
5479
|
/** Persist a channel's full nonce/amount + withdraw-timer state to the store. */
|
|
5353
5480
|
private persist;
|
|
5354
5481
|
/**
|