@antseed/node 0.2.100 → 0.2.101
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/buyer-request-handler.d.ts +2 -0
- package/dist/buyer-request-handler.d.ts.map +1 -1
- package/dist/buyer-request-handler.js +2 -2
- package/dist/buyer-request-handler.js.map +1 -1
- package/dist/discovery/announcer.d.ts +2 -0
- package/dist/discovery/announcer.d.ts.map +1 -1
- package/dist/discovery/announcer.js +8 -2
- package/dist/discovery/announcer.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces/plugin.d.ts +42 -1
- package/dist/interfaces/plugin.d.ts.map +1 -1
- package/dist/interfaces/plugin.js +1 -1
- package/dist/interfaces/plugin.js.map +1 -1
- package/dist/node.d.ts +25 -1
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +94 -1
- package/dist/node.js.map +1 -1
- package/dist/p2p/connection-manager.d.ts.map +1 -1
- package/dist/p2p/connection-manager.js +5 -2
- package/dist/p2p/connection-manager.js.map +1 -1
- package/dist/p2p/payment-codec.d.ts +5 -1
- package/dist/p2p/payment-codec.d.ts.map +1 -1
- package/dist/p2p/payment-codec.js +54 -1
- package/dist/p2p/payment-codec.js.map +1 -1
- package/dist/p2p/payment-mux.d.ts +7 -1
- package/dist/p2p/payment-mux.d.ts.map +1 -1
- package/dist/p2p/payment-mux.js +22 -0
- package/dist/p2p/payment-mux.js.map +1 -1
- package/dist/payments/buyer-payment-manager.d.ts +14 -1
- package/dist/payments/buyer-payment-manager.d.ts.map +1 -1
- package/dist/payments/buyer-payment-manager.js +35 -0
- package/dist/payments/buyer-payment-manager.js.map +1 -1
- package/dist/payments/buyer-payment-negotiator.d.ts +18 -0
- package/dist/payments/buyer-payment-negotiator.d.ts.map +1 -1
- package/dist/payments/buyer-payment-negotiator.js +104 -6
- package/dist/payments/buyer-payment-negotiator.js.map +1 -1
- package/dist/payments/seller-payment-manager.d.ts +67 -6
- package/dist/payments/seller-payment-manager.d.ts.map +1 -1
- package/dist/payments/seller-payment-manager.js +340 -71
- package/dist/payments/seller-payment-manager.js.map +1 -1
- package/dist/seller-request-handler.d.ts +4 -0
- package/dist/seller-request-handler.d.ts.map +1 -1
- package/dist/seller-request-handler.js +103 -0
- package/dist/seller-request-handler.js.map +1 -1
- package/dist/types/protocol.d.ts +60 -0
- package/dist/types/protocol.d.ts.map +1 -1
- package/dist/types/protocol.js +24 -0
- package/dist/types/protocol.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Identity } from '../p2p/identity.js';
|
|
2
2
|
import type { PaymentMux } from '../p2p/payment-mux.js';
|
|
3
|
-
import type { SpendingAuthPayload, PaymentRequiredPayload } from '../types/protocol.js';
|
|
3
|
+
import type { SpendingAuthPayload, PaymentRequiredPayload, CloseChannelRequestPayload, CloseChannelResultPayload } from '../types/protocol.js';
|
|
4
4
|
import { ChannelsClient } from './evm/channels-client.js';
|
|
5
5
|
import { ChannelStore, type StoredChannel } from './channel-store.js';
|
|
6
6
|
export interface SellerPaymentConfig {
|
|
@@ -77,8 +77,20 @@ export declare class SellerPaymentManager {
|
|
|
77
77
|
private readonly _pendingTopUp;
|
|
78
78
|
/** Channels that must not serve more paid work until closed/renegotiated. */
|
|
79
79
|
private readonly _blockedChannels;
|
|
80
|
-
/**
|
|
80
|
+
/**
|
|
81
|
+
* channelId -> in-flight close() result. Every close path shares this map so
|
|
82
|
+
* replacement negotiation can await an existing close instead of submitting
|
|
83
|
+
* a duplicate transaction.
|
|
84
|
+
*/
|
|
81
85
|
private readonly _closingChannels;
|
|
86
|
+
/**
|
|
87
|
+
* buyerPeerId -> number of billable requests currently being served.
|
|
88
|
+
* Incremented before the provider call and decremented only after the
|
|
89
|
+
* request's spend has been recorded and its NeedAuth sent, so a non-zero
|
|
90
|
+
* count means "this buyer is still accumulating" and the channel must not be
|
|
91
|
+
* closed out from under it.
|
|
92
|
+
*/
|
|
93
|
+
private readonly _inFlightRequests;
|
|
82
94
|
/** channelId -> cumulative amount last successfully settled on-chain by this
|
|
83
95
|
* process. Lets the idle-settle loop skip the `getSession` RPC when the
|
|
84
96
|
* local accepted cumulative hasn't moved since our last settle. */
|
|
@@ -94,6 +106,14 @@ export declare class SellerPaymentManager {
|
|
|
94
106
|
*/
|
|
95
107
|
validateHydratedChannels(): Promise<void>;
|
|
96
108
|
private _evictStaleChannel;
|
|
109
|
+
/** Remove connectivity only if it still belongs to the channel being cleaned up. */
|
|
110
|
+
private _deactivateBuyerForChannel;
|
|
111
|
+
/**
|
|
112
|
+
* Submit at most one close transaction per channel and share its outcome.
|
|
113
|
+
* Callers that join an in-flight close receive the amount that close actually
|
|
114
|
+
* submitted, not the one they asked for — persist that, not `amount`.
|
|
115
|
+
*/
|
|
116
|
+
private _submitClose;
|
|
97
117
|
/**
|
|
98
118
|
* Restore a persisted SpendingAuth after in-memory cleanup. This prevents the
|
|
99
119
|
* timeout checker from mistaking an active channel with a durable signed auth
|
|
@@ -143,10 +163,6 @@ export declare class SellerPaymentManager {
|
|
|
143
163
|
* Record USDC consumption after serving a request.
|
|
144
164
|
*/
|
|
145
165
|
recordSpend(sessionId: string, costUsdc: bigint): void;
|
|
146
|
-
/**
|
|
147
|
-
* Close a completed session on-chain using the latest buyer-signed dual signatures.
|
|
148
|
-
* Uses close() for final settlement (releases remaining deposit to buyer).
|
|
149
|
-
*/
|
|
150
166
|
/** Get the latest SpendingAuth params for a channel, or zero-auth if none exists. */
|
|
151
167
|
private _getSettleParams;
|
|
152
168
|
/**
|
|
@@ -160,6 +176,17 @@ export declare class SellerPaymentManager {
|
|
|
160
176
|
cleanupOnFailure?: boolean | undefined;
|
|
161
177
|
settleOnly?: boolean | undefined;
|
|
162
178
|
}): Promise<void>;
|
|
179
|
+
/**
|
|
180
|
+
* Drop all in-memory state for a channel that is no longer live. Does not
|
|
181
|
+
* touch persisted status — callers set that first (SETTLED / TIMEOUT).
|
|
182
|
+
*/
|
|
183
|
+
private _forgetChannel;
|
|
184
|
+
/** Mark a billable request as started for this buyer. */
|
|
185
|
+
beginBillableRequest(buyerPeerId: string): void;
|
|
186
|
+
/** Mark a billable request as fully accounted for (spend recorded, NeedAuth sent). */
|
|
187
|
+
endBillableRequest(buyerPeerId: string): void;
|
|
188
|
+
/** Whether this buyer has requests still being served and billed. */
|
|
189
|
+
hasInFlightRequests(buyerPeerId: string): boolean;
|
|
163
190
|
onBuyerDisconnect(buyerPeerId: string): void;
|
|
164
191
|
/**
|
|
165
192
|
* Check for stale sessions and attempt to close them.
|
|
@@ -172,6 +199,15 @@ export declare class SellerPaymentManager {
|
|
|
172
199
|
* Called periodically and on startup for recovery.
|
|
173
200
|
*/
|
|
174
201
|
checkTimeouts(): Promise<void>;
|
|
202
|
+
/**
|
|
203
|
+
* Close the seller's previous channel before accepting a replacement
|
|
204
|
+
* ReserveAuth from the same buyer. Buyers may lose local channel state and
|
|
205
|
+
* generate a new channel ID while the previous reserve remains active
|
|
206
|
+
* on-chain. The contract rejects a second active channel for the same pair,
|
|
207
|
+
* so recover synchronously using the seller's durable state instead of
|
|
208
|
+
* leaving both peers in an unrecoverable negotiation loop.
|
|
209
|
+
*/
|
|
210
|
+
private _closeSupersededChannel;
|
|
175
211
|
/**
|
|
176
212
|
* Close a zombie channel (buyer gone, no signed auth) using the current
|
|
177
213
|
* on-chain settled cumulative as finalAmount. This intentionally settles no
|
|
@@ -203,6 +239,31 @@ export declare class SellerPaymentManager {
|
|
|
203
239
|
outputUsdPerMillion?: number;
|
|
204
240
|
cachedInputUsdPerMillion?: number;
|
|
205
241
|
}): PaymentRequiredPayload;
|
|
242
|
+
/**
|
|
243
|
+
* Handle a buyer's CloseChannelRequest: close the channel on-chain right
|
|
244
|
+
* away so the buyer's reserve is released without the `requestClose()` →
|
|
245
|
+
* 15-minute grace → `withdraw()` detour.
|
|
246
|
+
*
|
|
247
|
+
* The seller only agrees when it is not mid-accumulation with this buyer:
|
|
248
|
+
* no billable request in flight, and no served work the buyer has not signed
|
|
249
|
+
* for. It closes at `max(own last-accepted auth, buyer-supplied auth)`, so a
|
|
250
|
+
* buyer cannot use this path to settle below what it already owes, and a
|
|
251
|
+
* seller that lost the buyer's latest auth can still be paid in full by the
|
|
252
|
+
* copy the buyer attaches.
|
|
253
|
+
*/
|
|
254
|
+
handleCloseChannelRequest(buyerPeerId: string, payload: CloseChannelRequestPayload, paymentMux: PaymentMux): Promise<CloseChannelResultPayload>;
|
|
255
|
+
/**
|
|
256
|
+
* Verify a SpendingAuth attached to a CloseChannelRequest. Returns null when
|
|
257
|
+
* the buyer attached nothing; throws with a caller-safe message when the
|
|
258
|
+
* attached auth does not check out.
|
|
259
|
+
*/
|
|
260
|
+
private _verifyBuyerCloseAuth;
|
|
261
|
+
/**
|
|
262
|
+
* Take the buyer-supplied auth as our latest when it authorizes strictly more
|
|
263
|
+
* than what we already hold. Persisted so a crash between here and close()
|
|
264
|
+
* doesn't lose the higher claim.
|
|
265
|
+
*/
|
|
266
|
+
private _adoptBuyerCloseAuth;
|
|
206
267
|
/**
|
|
207
268
|
* Handle a CloseRequested event for a channel this seller manages.
|
|
208
269
|
* If the seller has a stored SpendingAuth, immediately close the channel
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"seller-payment-manager.d.ts","sourceRoot":"","sources":["../../src/payments/seller-payment-manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,KAAK,EACV,mBAAmB,EACnB,sBAAsB,
|
|
1
|
+
{"version":3,"file":"seller-payment-manager.d.ts","sourceRoot":"","sources":["../../src/payments/seller-payment-manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,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