@@ -6,17 +6,15 @@ import { batchSettlementABI } from "../abi";
66import { BATCH_SETTLEMENT_ADDRESS , MIN_WITHDRAW_DELAY } from "../constants" ;
77import type { BatchSettlementPaymentRequirementsExtra , ChannelConfig } from "../types" ;
88import { computeChannelId } from "../utils" ;
9- import type { BatchSettlementClientContext , ClientSessionStorage } from "./storage" ;
9+ import type { BatchSettlementClientContext , ClientChannelStorage } from "./storage" ;
1010
1111/**
12- * Runtime dependency bag shared by every storage-bound client helper (session,
13- * recovery, refund) and the {@link BatchSettlementEvmScheme} class. Carries the
14- * live signer + storage plus the channel-id inputs (`salt`, `payerAuthorizer`,
15- * optional separate `voucherSigner`).
12+ * Runtime dependency bag shared by every storage-bound client helper (channel,
13+ * recovery, refund) and the {@link BatchSettlementEvmScheme} class.
1614 */
1715export interface BatchSettlementClientDeps {
1816 signer : ClientEvmSigner ;
19- storage : ClientSessionStorage ;
17+ storage : ClientChannelStorage ;
2018 salt : `0x${string } `;
2119 payerAuthorizer ?: `0x${string } `;
2220 voucherSigner ?: ClientEvmSigner ;
@@ -53,13 +51,13 @@ export function buildChannelConfig(
5351}
5452
5553/**
56- * Updates local session state from a parsed `SettleResponse`.
54+ * Updates local channel state from a parsed `SettleResponse`.
5755 *
58- * @param storage - Client session storage.
56+ * @param storage - Client channel storage.
5957 * @param settle - The parsed settle response.
6058 */
6159export async function processSettleResponse (
62- storage : ClientSessionStorage ,
60+ storage : ClientChannelStorage ,
6361 settle : SettleResponse ,
6462) : Promise < void > {
6563 const extra = settle . extra ?? { } ;
@@ -70,7 +68,7 @@ export async function processSettleResponse(
7068 const key = channelId . toLowerCase ( ) ;
7169
7270 if ( extra . refund === true ) {
73- await updateSessionAfterRefund ( storage , key , extra ) ;
71+ await updateChannelAfterRefund ( storage , key , extra ) ;
7472 return ;
7573 }
7674
@@ -91,18 +89,18 @@ export async function processSettleResponse(
9189}
9290
9391/**
94- * Reconciles local session state with the outcome of a cooperative refund.
92+ * Reconciles local channel state with the outcome of a cooperative refund.
9593 *
96- * Deletes the session when the post-refund balance is zero (full refund),
94+ * Deletes the channel record when the post-refund balance is zero (full refund),
9795 * otherwise updates `balance`, `chargedCumulativeAmount`, and `totalClaimed`
9896 * from the server snapshot (partial refund — channel stays open).
9997 *
100- * @param storage - Client session storage.
98+ * @param storage - Client channel storage.
10199 * @param channelKey - Lowercased channel id used as the storage key.
102100 * @param settleExtra - The `extra` block from the refund settle response.
103101 */
104- export async function updateSessionAfterRefund (
105- storage : ClientSessionStorage ,
102+ export async function updateChannelAfterRefund (
103+ storage : ClientChannelStorage ,
106104 channelKey : string ,
107105 settleExtra : Record < string , unknown > ,
108106) : Promise < void > {
@@ -132,11 +130,11 @@ export async function updateSessionAfterRefund(
132130 * Decodes the header into a `SettleResponse` and delegates to
133131 * {@link processSettleResponse}.
134132 *
135- * @param storage - Client session storage.
133+ * @param storage - Client channel storage.
136134 * @param getHeader - Function to retrieve a response header by name.
137135 */
138136export async function processPaymentResponse (
139- storage : ClientSessionStorage ,
137+ storage : ClientChannelStorage ,
140138 getHeader : ( name : string ) => string | null | undefined ,
141139) : Promise < void > {
142140 const raw = getHeader ( "PAYMENT-RESPONSE" ) ;
@@ -147,19 +145,19 @@ export async function processPaymentResponse(
147145}
148146
149147/**
150- * Recovers a channel session from on-chain state (useful after a cold start or
151- * session loss).
148+ * Recovers a channel record from on-chain state (useful after a cold start or
149+ * channel record loss).
152150 *
153151 * @param deps - Signer + storage + identity inputs.
154152 * @param paymentRequirements - Server payment requirements used to derive the ChannelConfig.
155153 * @returns The recovered client context.
156154 */
157- export async function recoverSession (
155+ export async function recoverChannel (
158156 deps : BatchSettlementClientDeps ,
159157 paymentRequirements : PaymentRequirements ,
160158) : Promise < BatchSettlementClientContext > {
161159 if ( ! deps . signer . readContract ) {
162- throw new Error ( "recoverSession requires ClientEvmSigner.readContract" ) ;
160+ throw new Error ( "recoverChannel requires ClientEvmSigner.readContract" ) ;
163161 }
164162
165163 const config = buildChannelConfig ( deps , paymentRequirements ) ;
@@ -203,29 +201,29 @@ export async function readChannelBalanceAndTotalClaimed(
203201}
204202
205203/**
206- * Returns whether a local session exists for the given channel.
204+ * Returns whether a local channel record exists for the given channel.
207205 *
208- * @param storage - Client session storage.
206+ * @param storage - Client channel storage.
209207 * @param channelId - The channel identifier to check.
210- * @returns `true` when a session is stored for the channel .
208+ * @returns `true` when a channel record is stored.
211209 */
212- export async function hasSession (
213- storage : ClientSessionStorage ,
210+ export async function hasChannel (
211+ storage : ClientChannelStorage ,
214212 channelId : string ,
215213) : Promise < boolean > {
216- const session = await storage . get ( channelId . toLowerCase ( ) ) ;
217- return session !== undefined ;
214+ const channel = await storage . get ( channelId . toLowerCase ( ) ) ;
215+ return channel !== undefined ;
218216}
219217
220218/**
221- * Returns the local session context for a channel, if present.
219+ * Returns the local channel context for a channel, if present.
222220 *
223- * @param storage - Client session storage.
221+ * @param storage - Client channel storage.
224222 * @param channelId - The channel identifier.
225223 * @returns Stored context or `undefined`.
226224 */
227- export async function getSession (
228- storage : ClientSessionStorage ,
225+ export async function getChannel (
226+ storage : ClientChannelStorage ,
229227 channelId : string ,
230228) : Promise < BatchSettlementClientContext | undefined > {
231229 return storage . get ( channelId . toLowerCase ( ) ) ;
0 commit comments