mppx 0.8.18 → 0.9.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/CHANGELOG.md +22 -0
- package/README.md +0 -6
- package/dist/Challenge.d.ts +7 -0
- package/dist/Challenge.js +32 -6
- package/dist/Constants.d.ts +1 -0
- package/dist/Constants.js +1 -0
- package/dist/Credential.d.ts +11 -5
- package/dist/Credential.js +8 -8
- package/dist/Html.js +1 -1
- package/dist/cli/THIRD-PARTY-LICENSES.txt +1 -1
- package/dist/cli/cli.d.ts +2 -2
- package/dist/cli/cli.js +134 -134
- package/dist/cli/plugins/index.js +13 -13
- package/dist/cli/sessions/Manager.js +4 -6
- package/dist/cli/sessions/commands.d.ts +1 -1
- package/dist/cli/sessions/store.js +13 -19
- package/dist/cli/validate/index.d.ts +2 -2
- package/dist/client/Mppx.d.ts +39 -2
- package/dist/client/Mppx.js +102 -46
- package/dist/client/Transport.js +1 -1
- package/dist/client/internal/protocols/Mpp.d.ts +1 -1
- package/dist/client/internal/protocols/Mpp.js +5 -3
- package/dist/client/internal/protocols/Protocol.d.ts +3 -1
- package/dist/client/internal/protocols/Shared.js +5 -1
- package/dist/integrations/x402/Evm.d.ts +29 -0
- package/dist/integrations/x402/Evm.js +150 -0
- package/dist/integrations/x402/Negotiator.d.ts +36 -0
- package/dist/integrations/x402/Negotiator.js +165 -0
- package/dist/mcp/internal/Credential.d.ts +9 -0
- package/dist/mcp/internal/Credential.js +16 -0
- package/dist/mcp/server/Transport.js +2 -4
- package/dist/middlewares/express.js +5 -12
- package/dist/middlewares/internal/express.d.ts +8 -0
- package/dist/middlewares/internal/express.js +24 -0
- package/dist/middlewares/internal/node.d.ts +10 -0
- package/dist/middlewares/internal/node.js +34 -0
- package/dist/proxy/Proxy.js +15 -9
- package/dist/server/Mppx.d.ts +2 -0
- package/dist/server/Mppx.js +17 -14
- package/dist/server/Transport.d.ts +8 -2
- package/dist/server/Transport.js +6 -3
- package/dist/server/internal/SecretKey.d.ts +3 -0
- package/dist/server/internal/SecretKey.js +9 -0
- package/dist/server/internal/html/serviceWorker.client.d.ts +1 -1
- package/dist/server/internal/html/serviceWorker.client.js +2 -2
- package/dist/server/internal/html/serviceWorker.gen.d.ts +1 -1
- package/dist/server/internal/html/serviceWorker.gen.js +1 -1
- package/dist/stripe/server/internal/html.gen.d.ts +1 -1
- package/dist/stripe/server/internal/html.gen.js +1 -1
- package/dist/tempo/Methods.d.ts +0 -10
- package/dist/tempo/Methods.js +3 -12
- package/dist/tempo/client/Charge.d.ts +0 -3
- package/dist/tempo/client/Charge.js +3 -13
- package/dist/tempo/client/Methods.d.ts +0 -10
- package/dist/tempo/internal/account.d.ts +15 -6
- package/dist/tempo/internal/account.js +17 -26
- package/dist/tempo/internal/defaults.d.ts +0 -11
- package/dist/tempo/internal/defaults.js +0 -11
- package/dist/tempo/internal/fee-payer.d.ts +21 -3
- package/dist/tempo/internal/fee-payer.js +10 -19
- package/dist/tempo/internal/remote-fee-payer.d.ts +12 -0
- package/dist/tempo/internal/remote-fee-payer.js +17 -0
- package/dist/tempo/legacy/client/Session.d.ts +0 -7
- package/dist/tempo/server/Charge.d.ts +0 -3
- package/dist/tempo/server/Charge.js +26 -68
- package/dist/tempo/server/Methods.d.ts +4 -18
- package/dist/tempo/server/Methods.js +4 -8
- package/dist/tempo/server/internal/html.gen.d.ts +1 -1
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/session/client/ChannelOps.d.ts +0 -14
- package/dist/tempo/session/client/ChannelOps.js +0 -22
- package/dist/tempo/session/client/ChannelStore.d.ts +5 -0
- package/dist/tempo/session/client/ChannelStore.js +2 -2
- package/dist/tempo/session/client/CredentialState.d.ts +2 -12
- package/dist/tempo/session/client/CredentialState.js +75 -73
- package/dist/tempo/session/client/Session.d.ts +2 -9
- package/dist/tempo/session/client/Session.js +71 -176
- package/dist/tempo/session/client/SessionManager.js +9 -28
- package/dist/tempo/session/precompile/Chain.d.ts +0 -4
- package/dist/tempo/session/precompile/Chain.js +2 -29
- package/dist/tempo/session/precompile/Protocol.d.ts +0 -13
- package/dist/tempo/session/precompile/Voucher.d.ts +1 -3
- package/dist/tempo/session/precompile/Voucher.js +12 -6
- package/dist/tempo/session/server/ChannelStore.d.ts +0 -6
- package/dist/tempo/session/server/ChannelStore.js +4 -11
- package/dist/tempo/session/server/CredentialVerification.d.ts +7 -9
- package/dist/tempo/session/server/CredentialVerification.js +118 -184
- package/dist/tempo/session/server/RequestState.d.ts +0 -17
- package/dist/tempo/session/server/RequestState.js +15 -59
- package/dist/tempo/session/server/Session.d.ts +0 -9
- package/dist/tempo/session/server/Session.js +8 -37
- package/dist/tempo/session/server/Settlement.d.ts +0 -7
- package/dist/tempo/session/server/Settlement.js +16 -50
- package/dist/viem/Client.d.ts +7 -2
- package/dist/viem/Client.js +17 -5
- package/dist/x402/Types.d.ts +2 -0
- package/dist/x402/Types.js +2 -0
- package/dist/x402/mcp.d.ts +20 -0
- package/dist/x402/mcp.js +153 -0
- package/dist/x402/middlewares/express.d.ts +23 -0
- package/dist/x402/middlewares/express.js +49 -0
- package/dist/x402/middlewares/hono.d.ts +13 -0
- package/dist/x402/middlewares/hono.js +36 -0
- package/dist/x402/middlewares/next.d.ts +17 -0
- package/dist/x402/middlewares/next.js +58 -0
- package/package.json +41 -1
- package/dist/tempo/internal/machine-token-charge.d.ts +0 -51
- package/dist/tempo/internal/machine-token-charge.js +0 -113
- package/dist/tempo/internal/machine-token-session.d.ts +0 -88
- package/dist/tempo/internal/machine-token-session.js +0 -173
- package/dist/tempo/internal/signature-envelope.d.ts +0 -14
- package/dist/tempo/internal/signature-envelope.js +0 -28
|
@@ -33,11 +33,6 @@ export type ChannelEntry = {
|
|
|
33
33
|
chainId: number;
|
|
34
34
|
/** Whether the client considers the channel reusable for new vouchers. */
|
|
35
35
|
opened: boolean;
|
|
36
|
-
/** Logical merchant payment scope when it differs from the on-chain descriptor. */
|
|
37
|
-
paymentScope?: {
|
|
38
|
-
payee: Address;
|
|
39
|
-
token: Address;
|
|
40
|
-
} | undefined;
|
|
41
36
|
};
|
|
42
37
|
/** Resolves the voucher authority address for a client account. */
|
|
43
38
|
export declare function resolveAuthorizedSigner(account: Account): Address;
|
|
@@ -51,15 +46,6 @@ export declare function resolveEscrow(challenge: {
|
|
|
51
46
|
export declare function serializeCredential(challenge: Challenge, payload: SessionCredentialPayload, chainId: number, account: Account): string;
|
|
52
47
|
/** Case-insensitive EVM address equality. */
|
|
53
48
|
export declare function isSameAddress(a: Address, b: Address): boolean;
|
|
54
|
-
/** Returns whether a stored entry funds a machine-token session channel. */
|
|
55
|
-
export declare function isMachineChannel(entry: Pick<ChannelEntry, 'chainId' | 'descriptor' | 'escrow'>): boolean;
|
|
56
|
-
/**
|
|
57
|
-
* Returns whether a stored entry's logical payment scope differs from its
|
|
58
|
-
* on-chain descriptor. Such entries cannot be re-derived from a challenge, so
|
|
59
|
-
* their descriptor is the only local copy — even when the deployment table no
|
|
60
|
-
* longer recognizes the route (for example after a rotation).
|
|
61
|
-
*/
|
|
62
|
-
export declare function hasRewrittenScope(entry: Pick<ChannelEntry, 'descriptor' | 'paymentScope'>): boolean;
|
|
63
49
|
/**
|
|
64
50
|
* Signs and creates a TIP-1034 voucher credential payload for an existing channel.
|
|
65
51
|
*
|
|
@@ -13,7 +13,6 @@ import { encodeFunctionData, isAddress } from 'viem';
|
|
|
13
13
|
import { prepareTransactionRequest, signTransaction } from 'viem/actions';
|
|
14
14
|
import { Transaction } from 'viem/tempo';
|
|
15
15
|
import * as Credential from '../../../Credential.js';
|
|
16
|
-
import * as MachineTokenSession from '../../internal/machine-token-session.js';
|
|
17
16
|
import * as Channel from '../precompile/Channel.js';
|
|
18
17
|
import { escrowAbi } from '../precompile/escrow.abi.js';
|
|
19
18
|
import { tip20ChannelEscrow } from '../precompile/Protocol.js';
|
|
@@ -87,27 +86,6 @@ export function serializeCredential(challenge, payload, chainId, account) {
|
|
|
87
86
|
export function isSameAddress(a, b) {
|
|
88
87
|
return a.toLowerCase() === b.toLowerCase();
|
|
89
88
|
}
|
|
90
|
-
/** Returns whether a stored entry funds a machine-token session channel. */
|
|
91
|
-
export function isMachineChannel(entry) {
|
|
92
|
-
return (isSameAddress(entry.escrow, tip20ChannelEscrow) &&
|
|
93
|
-
MachineTokenSession.matchDeployment({
|
|
94
|
-
chainId: entry.chainId,
|
|
95
|
-
descriptor: entry.descriptor,
|
|
96
|
-
}) !== undefined);
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Returns whether a stored entry's logical payment scope differs from its
|
|
100
|
-
* on-chain descriptor. Such entries cannot be re-derived from a challenge, so
|
|
101
|
-
* their descriptor is the only local copy — even when the deployment table no
|
|
102
|
-
* longer recognizes the route (for example after a rotation).
|
|
103
|
-
*/
|
|
104
|
-
export function hasRewrittenScope(entry) {
|
|
105
|
-
const scope = entry.paymentScope;
|
|
106
|
-
if (!scope)
|
|
107
|
-
return false;
|
|
108
|
-
return (!isSameAddress(scope.payee, entry.descriptor.payee) ||
|
|
109
|
-
!isSameAddress(scope.token, entry.descriptor.token));
|
|
110
|
-
}
|
|
111
89
|
/**
|
|
112
90
|
* Signs and creates a TIP-1034 voucher credential payload for an existing channel.
|
|
113
91
|
*
|
|
@@ -10,6 +10,11 @@ export type ChannelStore = {
|
|
|
10
10
|
/** Removes the channel cached for `key`. */
|
|
11
11
|
delete(key: string): MaybePromise<void>;
|
|
12
12
|
};
|
|
13
|
+
/** Channel persistence and update notification for credential results. */
|
|
14
|
+
export type ChannelSink = {
|
|
15
|
+
store: ChannelStore;
|
|
16
|
+
notifyUpdate: (entry: ChannelEntry) => void;
|
|
17
|
+
};
|
|
13
18
|
/** Returns the scope key for a reusable payer session channel. */
|
|
14
19
|
export declare function channelKey(scope: {
|
|
15
20
|
payee: Address;
|
|
@@ -6,8 +6,8 @@ export function channelKey(scope) {
|
|
|
6
6
|
/** Returns the scope key for a stored channel entry. */
|
|
7
7
|
export function entryKey(entry) {
|
|
8
8
|
return channelKey({
|
|
9
|
-
payee: entry.
|
|
10
|
-
token: entry.
|
|
9
|
+
payee: entry.descriptor.payee,
|
|
10
|
+
token: entry.descriptor.token,
|
|
11
11
|
escrow: entry.escrow,
|
|
12
12
|
chainId: entry.chainId,
|
|
13
13
|
});
|
|
@@ -8,6 +8,7 @@ import * as Channel from '../precompile/Channel.js';
|
|
|
8
8
|
import type { SessionCredentialPayload } from '../precompile/Protocol.js';
|
|
9
9
|
import type { SessionSnapshot } from '../Snapshot.js';
|
|
10
10
|
import { type ChannelEntry } from './ChannelOps.js';
|
|
11
|
+
import { type ChannelSink } from './ChannelStore.js';
|
|
11
12
|
/** Credential payload variants that carry cumulative voucher authorization. */
|
|
12
13
|
export type CumulativeCredentialPayload = Extract<SessionCredentialPayload, {
|
|
13
14
|
cumulativeAmount: string;
|
|
@@ -166,11 +167,6 @@ export type ChallengeContext = {
|
|
|
166
167
|
key: string;
|
|
167
168
|
operator?: Address | undefined;
|
|
168
169
|
payee: Address;
|
|
169
|
-
/** Logical merchant scope when the channel uses an indirect payment route. */
|
|
170
|
-
paymentScope?: {
|
|
171
|
-
payee: Address;
|
|
172
|
-
token: Address;
|
|
173
|
-
} | undefined;
|
|
174
170
|
snapshot?: SessionSnapshot | undefined;
|
|
175
171
|
/** Server-provided raw deposit hint for opening a channel, before local maxDeposit capping. */
|
|
176
172
|
suggestedDepositRaw?: string | undefined;
|
|
@@ -257,14 +253,8 @@ export type CredentialPlan =
|
|
|
257
253
|
account: ViemAccount;
|
|
258
254
|
context: ManualSessionDescriptorContext;
|
|
259
255
|
decimals: number;
|
|
260
|
-
entry?: ChannelEntry | undefined;
|
|
261
256
|
resolved: ChallengeContext;
|
|
262
257
|
};
|
|
263
|
-
/** Signed credential plus the channel state to commit after all signing succeeds. */
|
|
264
|
-
export type CredentialResult = {
|
|
265
|
-
payload: SessionCredentialPayload;
|
|
266
|
-
entry?: ChannelEntry | undefined;
|
|
267
|
-
};
|
|
268
258
|
/** Resolves raw challenge fields into the typed data required by client credential planning. */
|
|
269
259
|
export declare function resolveChallengeContext(parameters: ResolveChallengeContextParameters): Promise<ChallengeContext>;
|
|
270
260
|
/** Validates descriptor identity and reads open channel state for client-side recovery. */
|
|
@@ -280,5 +270,5 @@ export declare function canSignDescriptor(account: ViemAccount, descriptor: Chan
|
|
|
280
270
|
/** Chooses the next credential plan from local channel cache and optional caller context. */
|
|
281
271
|
export declare function planCredential(parameters: PlanCredentialParameters): CredentialPlan;
|
|
282
272
|
/** Executes a credential plan and returns the concrete session credential payload. */
|
|
283
|
-
export declare function executeCredentialPlan(plan: CredentialPlan, autoSwap?: AutoSwap.resolve.Resolved | false
|
|
273
|
+
export declare function executeCredentialPlan(plan: CredentialPlan, sink: ChannelSink, autoSwap?: AutoSwap.resolve.Resolved | false): Promise<SessionCredentialPayload>;
|
|
284
274
|
//# sourceMappingURL=CredentialState.d.ts.map
|
|
@@ -6,7 +6,7 @@ import * as Chain from '../precompile/Chain.js';
|
|
|
6
6
|
import * as Channel from '../precompile/Channel.js';
|
|
7
7
|
import * as Voucher from '../precompile/Voucher.js';
|
|
8
8
|
import { createClosePayload, createOpenPayload, createTopUpPayload, createVoucherPayload, isSameAddress, resolveAuthorizedSigner, resolveEscrow, } from './ChannelOps.js';
|
|
9
|
-
import { channelKey } from './ChannelStore.js';
|
|
9
|
+
import { channelKey, entryKey } from './ChannelStore.js';
|
|
10
10
|
import { assertWithinMaxDeposit, resolveOpeningDeposit } from './Runtime.js';
|
|
11
11
|
/** Returns whether a credential payload carries cumulative voucher authorization. */
|
|
12
12
|
export function hasCredentialCumulativeAmount(payload) {
|
|
@@ -18,18 +18,33 @@ export function readCredentialCumulativeAmount(payload) {
|
|
|
18
18
|
return undefined;
|
|
19
19
|
return BigInt(payload.cumulativeAmount);
|
|
20
20
|
}
|
|
21
|
-
/**
|
|
22
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Persists a channel entry through the sink and notifies observers. Closed
|
|
23
|
+
* channels are removed from the store but still reported to observers so callers
|
|
24
|
+
* can react to the close.
|
|
25
|
+
*/
|
|
26
|
+
async function storeChannelEntry(sink, entry) {
|
|
27
|
+
if (entry.opened)
|
|
28
|
+
await sink.store.set(entry);
|
|
29
|
+
else
|
|
30
|
+
await sink.store.delete(entryKey(entry));
|
|
31
|
+
sink.notifyUpdate(entry);
|
|
32
|
+
}
|
|
33
|
+
/** Applies a credential payload's cumulative amount to the stored channel at `key`. */
|
|
34
|
+
async function applyCumulative(sink, key, payload) {
|
|
23
35
|
const cumulativeAmount = readCredentialCumulativeAmount(payload);
|
|
24
|
-
if (cumulativeAmount === undefined
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
36
|
+
if (cumulativeAmount === undefined)
|
|
37
|
+
return;
|
|
38
|
+
const entry = await sink.store.get(key);
|
|
39
|
+
if (!entry)
|
|
40
|
+
return;
|
|
41
|
+
if (entry.channelId.toLowerCase() !== payload.channelId.toLowerCase())
|
|
42
|
+
return;
|
|
43
|
+
entry.cumulativeAmount =
|
|
44
|
+
entry.cumulativeAmount > cumulativeAmount ? entry.cumulativeAmount : cumulativeAmount;
|
|
45
|
+
if (payload.action === 'close')
|
|
46
|
+
entry.opened = false;
|
|
47
|
+
await storeChannelEntry(sink, entry);
|
|
33
48
|
}
|
|
34
49
|
const hexSchema = z.custom((value) => typeof value === 'string' && /^0x[0-9a-fA-F]*$/.test(value));
|
|
35
50
|
const hashSchema = z.custom((value) => typeof value === 'string' && /^0x[0-9a-fA-F]{64}$/.test(value));
|
|
@@ -275,7 +290,6 @@ export function planCredential(parameters) {
|
|
|
275
290
|
account,
|
|
276
291
|
context,
|
|
277
292
|
decimals,
|
|
278
|
-
entry,
|
|
279
293
|
resolved,
|
|
280
294
|
};
|
|
281
295
|
}
|
|
@@ -283,39 +297,30 @@ export function planCredential(parameters) {
|
|
|
283
297
|
throw new Error('descriptor required to reuse TIP-1034 channel');
|
|
284
298
|
const recoverContext = resolveRecoverContext({ context, snapshot: resolved.snapshot });
|
|
285
299
|
if (!entry && recoverContext && canSignDescriptor(account, recoverContext.descriptor)) {
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
if (recoverable)
|
|
295
|
-
return {
|
|
296
|
-
type: 'recover',
|
|
297
|
-
account,
|
|
298
|
-
context: recoverContext,
|
|
299
|
-
decimals,
|
|
300
|
-
maxDeposit,
|
|
301
|
-
resolved,
|
|
302
|
-
};
|
|
300
|
+
return {
|
|
301
|
+
type: 'recover',
|
|
302
|
+
account,
|
|
303
|
+
context: recoverContext,
|
|
304
|
+
decimals,
|
|
305
|
+
maxDeposit,
|
|
306
|
+
resolved,
|
|
307
|
+
};
|
|
303
308
|
}
|
|
304
309
|
if (entry?.opened && canSignDescriptor(account, entry.descriptor))
|
|
305
310
|
return { type: 'voucher', account, entry, maxDeposit, resolved };
|
|
306
311
|
return { type: 'open', account, context, maxDeposit, resolved };
|
|
307
312
|
}
|
|
308
313
|
/** Executes a credential plan and returns the concrete session credential payload. */
|
|
309
|
-
export async function executeCredentialPlan(plan, autoSwap = false
|
|
314
|
+
export async function executeCredentialPlan(plan, sink, autoSwap = false) {
|
|
310
315
|
switch (plan.type) {
|
|
311
316
|
case 'open':
|
|
312
|
-
return open(plan,
|
|
317
|
+
return open(plan, sink, autoSwap);
|
|
313
318
|
case 'recover':
|
|
314
|
-
return recover(plan);
|
|
319
|
+
return recover(plan, sink);
|
|
315
320
|
case 'voucher':
|
|
316
|
-
return voucher(plan);
|
|
321
|
+
return voucher(plan, sink);
|
|
317
322
|
case 'manual':
|
|
318
|
-
return manual(plan,
|
|
323
|
+
return manual(plan, sink, autoSwap);
|
|
319
324
|
}
|
|
320
325
|
}
|
|
321
326
|
async function resolveAutoSwapCalls(autoSwap, parameters) {
|
|
@@ -329,7 +334,7 @@ async function resolveAutoSwapCalls(autoSwap, parameters) {
|
|
|
329
334
|
slippage: autoSwap.slippage,
|
|
330
335
|
}));
|
|
331
336
|
}
|
|
332
|
-
async function open(plan,
|
|
337
|
+
async function open(plan, sink, autoSwap) {
|
|
333
338
|
const { account, resolved } = plan;
|
|
334
339
|
const deposit = resolveOpeningDeposit({
|
|
335
340
|
contextDepositRaw: plan.context?.depositRaw,
|
|
@@ -342,7 +347,7 @@ async function open(plan, autoSwap, feeToken) {
|
|
|
342
347
|
deposit,
|
|
343
348
|
escrow: resolved.escrow,
|
|
344
349
|
feePayer: resolved.feePayer,
|
|
345
|
-
feeToken,
|
|
350
|
+
feeToken: resolved.feeToken,
|
|
346
351
|
initialAmount: resolved.amount,
|
|
347
352
|
operator: resolved.operator,
|
|
348
353
|
payee: resolved.payee,
|
|
@@ -354,21 +359,18 @@ async function open(plan, autoSwap, feeToken) {
|
|
|
354
359
|
}),
|
|
355
360
|
token: resolved.token,
|
|
356
361
|
});
|
|
357
|
-
|
|
358
|
-
payload,
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
...(resolved.paymentScope && { paymentScope: resolved.paymentScope }),
|
|
368
|
-
},
|
|
369
|
-
};
|
|
362
|
+
await storeChannelEntry(sink, {
|
|
363
|
+
channelId: payload.channelId,
|
|
364
|
+
cumulativeAmount: resolved.amount,
|
|
365
|
+
deposit,
|
|
366
|
+
descriptor: payload.descriptor,
|
|
367
|
+
escrow: resolved.escrow,
|
|
368
|
+
chainId: resolved.chainId,
|
|
369
|
+
opened: true,
|
|
370
|
+
});
|
|
371
|
+
return payload;
|
|
370
372
|
}
|
|
371
|
-
async function recover(plan) {
|
|
373
|
+
async function recover(plan, sink) {
|
|
372
374
|
const { account, context, decimals, maxDeposit, resolved } = plan;
|
|
373
375
|
const { descriptor } = context;
|
|
374
376
|
const reusable = await resolveReusableChannel({
|
|
@@ -395,28 +397,27 @@ async function recover(plan) {
|
|
|
395
397
|
throw new Error('recovered voucher amount exceeds on-chain channel deposit');
|
|
396
398
|
assertWithinMaxDeposit(cumulativeAmount, maxDeposit);
|
|
397
399
|
const payload = await createVoucherPayload(resolved.client, account, descriptor, cumulativeAmount, resolved.chainId, resolved.escrow);
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
...(resolved.paymentScope && { paymentScope: resolved.paymentScope }),
|
|
409
|
-
},
|
|
410
|
-
};
|
|
400
|
+
await storeChannelEntry(sink, {
|
|
401
|
+
channelId: reusable.channelId,
|
|
402
|
+
cumulativeAmount,
|
|
403
|
+
deposit: reusable.state.deposit,
|
|
404
|
+
descriptor,
|
|
405
|
+
escrow: resolved.escrow,
|
|
406
|
+
chainId: resolved.chainId,
|
|
407
|
+
opened: true,
|
|
408
|
+
});
|
|
409
|
+
return payload;
|
|
411
410
|
}
|
|
412
|
-
async function voucher(plan) {
|
|
411
|
+
async function voucher(plan, sink) {
|
|
413
412
|
const { account, entry, resolved } = plan;
|
|
414
413
|
const cumulativeAmount = entry.cumulativeAmount + resolved.amount;
|
|
415
414
|
assertWithinMaxDeposit(cumulativeAmount, plan.maxDeposit);
|
|
416
415
|
const payload = await createVoucherPayload(resolved.client, account, entry.descriptor, cumulativeAmount, resolved.chainId, resolved.escrow);
|
|
417
|
-
|
|
416
|
+
entry.cumulativeAmount = cumulativeAmount;
|
|
417
|
+
await storeChannelEntry(sink, entry);
|
|
418
|
+
return payload;
|
|
418
419
|
}
|
|
419
|
-
async function manual(plan,
|
|
420
|
+
async function manual(plan, sink, autoSwap) {
|
|
420
421
|
const { account, context, decimals, resolved } = plan;
|
|
421
422
|
const { descriptor } = context;
|
|
422
423
|
const channelId = Channel.computeId({
|
|
@@ -440,15 +441,16 @@ async function manual(plan, autoSwap, feeToken) {
|
|
|
440
441
|
decimals,
|
|
441
442
|
descriptor,
|
|
442
443
|
resolved,
|
|
443
|
-
}, autoSwap
|
|
444
|
-
|
|
444
|
+
}, autoSwap);
|
|
445
|
+
await applyCumulative(sink, resolved.key, payload);
|
|
446
|
+
return payload;
|
|
445
447
|
}
|
|
446
|
-
async function executeManualCredential(parameters, autoSwap
|
|
448
|
+
async function executeManualCredential(parameters, autoSwap) {
|
|
447
449
|
switch (parameters.context.action) {
|
|
448
450
|
case 'open':
|
|
449
451
|
return manualOpen(parameters);
|
|
450
452
|
case 'topUp':
|
|
451
|
-
return manualTopUp(parameters, autoSwap
|
|
453
|
+
return manualTopUp(parameters, autoSwap);
|
|
452
454
|
case 'voucher':
|
|
453
455
|
return manualVoucher(parameters);
|
|
454
456
|
case 'close':
|
|
@@ -472,7 +474,7 @@ async function manualOpen(parameters) {
|
|
|
472
474
|
authorizedSigner: descriptor.authorizedSigner,
|
|
473
475
|
};
|
|
474
476
|
}
|
|
475
|
-
async function manualTopUp(parameters, autoSwap
|
|
477
|
+
async function manualTopUp(parameters, autoSwap) {
|
|
476
478
|
const { account, channelId, context, decimals, descriptor, resolved } = parameters;
|
|
477
479
|
const additionalDeposit = requireContextAmount(context, decimals, 'additionalDeposit', 'topUp');
|
|
478
480
|
if (context.transaction) {
|
|
@@ -490,7 +492,7 @@ async function manualTopUp(parameters, autoSwap, feeToken) {
|
|
|
490
492
|
amountOut: additionalDeposit,
|
|
491
493
|
client: resolved.client,
|
|
492
494
|
tokenOut: resolved.token,
|
|
493
|
-
}), feeToken);
|
|
495
|
+
}), resolved.feeToken);
|
|
494
496
|
}
|
|
495
497
|
function manualVoucher(parameters) {
|
|
496
498
|
const { account, context, decimals, descriptor, resolved } = parameters;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Address } from 'viem';
|
|
2
2
|
import * as Method from '../../../Method.js';
|
|
3
3
|
import * as Account from '../../../viem/Account.js';
|
|
4
4
|
import * as Client from '../../../viem/Client.js';
|
|
@@ -22,7 +22,6 @@ export declare function session(parameters?: session.Parameters): Method.Client<
|
|
|
22
22
|
credential: {
|
|
23
23
|
payload: import("zod/mini").ZodMiniDiscriminatedUnion<[import("zod/mini").ZodMiniObject<{
|
|
24
24
|
action: import("zod/mini").ZodMiniLiteral<"open">;
|
|
25
|
-
authorizationSignature: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
26
25
|
authorizedSigner: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
27
26
|
channelId: import("zod/mini").ZodMiniString<string>;
|
|
28
27
|
cumulativeAmount: import("zod/mini").ZodMiniString<string>;
|
|
@@ -39,18 +38,15 @@ export declare function session(parameters?: session.Parameters): Method.Client<
|
|
|
39
38
|
type: import("zod/mini").ZodMiniLiteral<"transaction">;
|
|
40
39
|
}, import("zod/v4/core").$strip>, import("zod/mini").ZodMiniObject<{
|
|
41
40
|
action: import("zod/mini").ZodMiniLiteral<"voucher">;
|
|
42
|
-
authorizationSignature: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
43
41
|
channelId: import("zod/mini").ZodMiniString<string>;
|
|
44
42
|
cumulativeAmount: import("zod/mini").ZodMiniString<string>;
|
|
45
43
|
descriptor: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniCustom<Channel.ChannelDescriptor, Channel.ChannelDescriptor>>;
|
|
46
44
|
signature: import("zod/mini").ZodMiniString<string>;
|
|
47
45
|
}, import("zod/v4/core").$strip>, import("zod/mini").ZodMiniObject<{
|
|
48
46
|
action: import("zod/mini").ZodMiniLiteral<"close">;
|
|
49
|
-
authorizationSignature: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
50
47
|
channelId: import("zod/mini").ZodMiniString<string>;
|
|
51
48
|
cumulativeAmount: import("zod/mini").ZodMiniString<string>;
|
|
52
49
|
descriptor: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniCustom<Channel.ChannelDescriptor, Channel.ChannelDescriptor>>;
|
|
53
|
-
refundSignature: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
54
50
|
signature: import("zod/mini").ZodMiniString<string>;
|
|
55
51
|
}, import("zod/v4/core").$strip>], "action">;
|
|
56
52
|
};
|
|
@@ -61,9 +57,8 @@ export declare function session(parameters?: session.Parameters): Method.Client<
|
|
|
61
57
|
currency: import("zod/mini").ZodMiniString<string>;
|
|
62
58
|
decimals: import("zod/mini").ZodMiniNumber<number>;
|
|
63
59
|
escrowContract: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
64
|
-
feePayer: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniPipe<import("zod/mini").ZodMiniUnion<readonly [import("zod/mini").ZodMiniBoolean<boolean>, import("zod/mini").ZodMiniCustom<
|
|
60
|
+
feePayer: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniPipe<import("zod/mini").ZodMiniUnion<readonly [import("zod/mini").ZodMiniBoolean<boolean>, import("zod/mini").ZodMiniCustom<import("viem").Account, import("viem").Account>]>, import("zod/mini").ZodMiniTransform<boolean, boolean | import("viem").Account>>>;
|
|
65
61
|
feeToken: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
66
|
-
machineTokenEnabled: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniBoolean<boolean>>;
|
|
67
62
|
minVoucherDelta: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
68
63
|
operator: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
69
64
|
recipient: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
|
|
@@ -87,7 +82,6 @@ export declare function session(parameters?: session.Parameters): Method.Client<
|
|
|
87
82
|
chainId?: number | undefined;
|
|
88
83
|
feePayer?: boolean | undefined;
|
|
89
84
|
feeToken?: string | undefined;
|
|
90
|
-
machineTokenEnabled?: boolean | undefined;
|
|
91
85
|
operator?: string | undefined;
|
|
92
86
|
sessionProtocol?: "v1" | "v2" | undefined;
|
|
93
87
|
sessionSnapshot?: import("./Runtime.js").SessionSnapshot | undefined;
|
|
@@ -101,7 +95,6 @@ export declare function session(parameters?: session.Parameters): Method.Client<
|
|
|
101
95
|
escrowContract?: string | undefined;
|
|
102
96
|
feePayer?: boolean | undefined;
|
|
103
97
|
feeToken?: string | undefined;
|
|
104
|
-
machineTokenEnabled?: boolean | undefined;
|
|
105
98
|
minVoucherDelta?: string | undefined;
|
|
106
99
|
operator?: string | undefined;
|
|
107
100
|
recipient?: string | undefined;
|