mppx 0.12.0 → 0.13.2
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 +64 -0
- package/dist/Method.d.ts +7 -1
- package/dist/Method.js +7 -2
- package/dist/Receipt.d.ts +2 -0
- package/dist/Receipt.js +2 -0
- package/dist/cli/cli.d.ts +8 -0
- package/dist/cli/cli.js +134 -136
- package/dist/cli/plugins/index.js +12 -14
- package/dist/cli/plugins/tempo.js +9 -2
- package/dist/cli/sessions/request.d.ts +1 -1
- package/dist/cli/sessions/request.js +6 -8
- package/dist/cli/utils.d.ts +11 -1
- package/dist/cli/utils.js +15 -2
- package/dist/cli/validate/challenge.d.ts +2 -0
- package/dist/cli/validate/challenge.js +19 -4
- package/dist/cli/validate/discovery.d.ts +1 -0
- package/dist/cli/validate/discovery.js +10 -1
- package/dist/cli/validate/payment.js +34 -12
- package/dist/client/Methods.d.ts +0 -2
- package/dist/client/Methods.js +0 -2
- package/dist/client/Mppx.js +1 -0
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js +1 -1
- package/dist/client/internal/Fetch.d.ts +2 -0
- package/dist/client/internal/Fetch.js +22 -7
- package/dist/client/internal/MethodChallenge.d.ts +1 -0
- package/dist/evm/Types.js +1 -1
- package/dist/evm/server/Charge.js +5 -0
- package/dist/integrations/x402/Evm.js +4 -3
- package/dist/internal/HeaderCodec.d.ts +2 -2
- package/dist/internal/version.d.ts +2 -2
- package/dist/internal/version.js +1 -1
- package/dist/mcp/client/McpClient.js +4 -7
- package/dist/middlewares/elysia.d.ts +11 -8
- package/dist/middlewares/elysia.js +67 -14
- package/dist/middlewares/express.js +13 -6
- package/dist/middlewares/hono.js +4 -4
- package/dist/middlewares/nextjs.js +9 -5
- package/dist/proxy/internal/Headers.js +65 -0
- package/dist/proxy/services/stripe.js +1 -0
- package/dist/server/Mppx.d.ts +14 -2
- package/dist/server/Mppx.js +85 -44
- package/dist/server/NodeListener.js +71 -6
- package/dist/server/Request.d.ts +11 -1
- package/dist/server/Request.js +132 -13
- package/dist/server/Transport.d.ts +14 -1
- package/dist/server/Transport.js +1 -0
- package/dist/stripe/server/Methods.d.ts +10 -3
- package/dist/stripe/server/Methods.js +17 -2
- package/dist/stripe/server/internal/html.gen.js +1 -1
- package/dist/tempo/Methods.d.ts +1 -0
- package/dist/tempo/Methods.js +1 -0
- package/dist/tempo/client/Charge.js +17 -13
- package/dist/tempo/client/Methods.d.ts +1 -5
- package/dist/tempo/client/Methods.js +10 -5
- package/dist/tempo/client/ResolveAccount.d.ts +3 -0
- package/dist/tempo/client/index.d.ts +0 -3
- package/dist/tempo/client/index.js +0 -2
- package/dist/tempo/internal/fee-payer.d.ts +6 -3
- package/dist/tempo/internal/fee-payer.js +23 -6
- package/dist/tempo/internal/machine-token-charge.d.ts +23 -0
- package/dist/tempo/internal/machine-token-charge.js +2 -1
- package/dist/tempo/legacy/index.d.ts +1 -3
- package/dist/tempo/legacy/index.js +1 -3
- package/dist/tempo/server/Charge.js +87 -53
- package/dist/tempo/server/Methods.d.ts +55 -10
- package/dist/tempo/server/Subscription.d.ts +1 -1
- package/dist/tempo/server/Subscription.js +31 -4
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/server/internal/transport.js +28 -11
- package/dist/tempo/session/client/ChannelOps.js +5 -0
- package/dist/tempo/session/client/Session.d.ts +1 -0
- package/dist/tempo/session/client/Session.js +7 -4
- package/dist/tempo/session/client/SessionManager.js +3 -0
- package/dist/tempo/session/client/Transports.d.ts +8 -1
- package/dist/tempo/session/client/Transports.js +12 -3
- package/dist/tempo/session/precompile/Chain.js +16 -1
- package/dist/tempo/session/precompile/Protocol.d.ts +2 -0
- package/dist/tempo/session/precompile/Voucher.d.ts +16 -0
- package/dist/tempo/session/precompile/Voucher.js +48 -0
- package/dist/tempo/session/server/ChannelStore.d.ts +20 -2
- package/dist/tempo/session/server/ChannelStore.js +25 -4
- package/dist/tempo/session/server/CredentialVerification.d.ts +4 -1
- package/dist/tempo/session/server/CredentialVerification.js +34 -6
- package/dist/tempo/session/server/MeteredStream.d.ts +3 -2
- package/dist/tempo/session/server/MeteredStream.js +85 -29
- package/dist/tempo/session/server/Session.d.ts +2 -1
- package/dist/tempo/session/server/Session.js +2 -1
- package/dist/tempo/session/server/Settlement.d.ts +21 -0
- package/dist/tempo/session/server/Settlement.js +92 -17
- package/dist/tempo/session/server/Sse.d.ts +3 -1
- package/dist/tempo/session/server/Sse.js +105 -32
- package/dist/tempo/session/server/Transports.d.ts +24 -19
- package/dist/tempo/session/server/Transports.js +169 -58
- package/dist/tempo/session/server/Ws.d.ts +5 -1
- package/dist/tempo/session/server/Ws.js +75 -20
- package/dist/tempo/subscription/Store.d.ts +2 -0
- package/dist/tempo/subscription/Store.js +3 -0
- package/dist/validation/core.js +2 -1
- package/dist/x402/server/EvmCharge.d.ts +3 -1
- package/dist/x402/server/EvmCharge.js +14 -1
- package/package.json +6 -6
- package/dist/tempo/legacy/client/ChannelOps.d.ts +0 -69
- package/dist/tempo/legacy/client/ChannelOps.js +0 -168
- package/dist/tempo/legacy/client/Session.d.ts +0 -185
- package/dist/tempo/legacy/client/Session.js +0 -279
- package/dist/tempo/legacy/client/SessionManager.d.ts +0 -100
- package/dist/tempo/legacy/client/SessionManager.js +0 -706
- package/dist/tempo/legacy/client/index.d.ts +0 -7
- package/dist/tempo/legacy/client/index.js +0 -5
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mppx",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.13.2",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://github.com/wevm/mppx#readme",
|
|
@@ -163,7 +163,7 @@
|
|
|
163
163
|
"@x402/hono": ">=2.22.0",
|
|
164
164
|
"@x402/mcp": ">=2.22.0",
|
|
165
165
|
"@x402/next": ">=2.22.0",
|
|
166
|
-
"elysia": ">=1",
|
|
166
|
+
"elysia": ">=1.2.0",
|
|
167
167
|
"express": ">=5",
|
|
168
168
|
"hono": ">=4.12.25",
|
|
169
169
|
"next": ">=16.2.6",
|
|
@@ -202,11 +202,11 @@
|
|
|
202
202
|
}
|
|
203
203
|
},
|
|
204
204
|
"dependencies": {
|
|
205
|
-
"@stripe/stripe-js": "9.
|
|
206
|
-
"eventsource-parser": "
|
|
205
|
+
"@stripe/stripe-js": "9.17.0",
|
|
206
|
+
"eventsource-parser": "4.1.1",
|
|
207
207
|
"ox": "0.14.45",
|
|
208
|
-
"structured-headers": "2.0
|
|
209
|
-
"zod": "^4.
|
|
208
|
+
"structured-headers": "2.1.0",
|
|
209
|
+
"zod": "^4.6.5"
|
|
210
210
|
},
|
|
211
211
|
"repository": {
|
|
212
212
|
"type": "git",
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared client-side channel operations.
|
|
3
|
-
*
|
|
4
|
-
* Provides the low-level helpers that both `session()`
|
|
5
|
-
* and `sessionManager()` (orchestrator) rely on: escrow resolution, channel
|
|
6
|
-
* ID computation, on-chain open/voucher/close payload construction, channel
|
|
7
|
-
* recovery from on-chain state, and credential serialization.
|
|
8
|
-
*/
|
|
9
|
-
import { Hex } from 'ox';
|
|
10
|
-
import { type Address, type Account as viem_Account, type Client as viem_Client } from 'viem';
|
|
11
|
-
import type { Challenge } from '../../../Challenge.js';
|
|
12
|
-
import type { LegacySessionCredentialPayload } from '../session/Types.js';
|
|
13
|
-
/** Cached channel metadata used by the legacy auto-driving session client. */
|
|
14
|
-
export type ChannelEntry = {
|
|
15
|
-
/** Voucher authority the channel was opened with. */
|
|
16
|
-
authorizedSigner: Address;
|
|
17
|
-
/** Legacy contract-backed channel ID. */
|
|
18
|
-
channelId: Hex.Hex;
|
|
19
|
-
/** Salt used to derive the channel ID. */
|
|
20
|
-
salt: Hex.Hex;
|
|
21
|
-
/** Highest cumulative voucher amount locally authorized. */
|
|
22
|
-
cumulativeAmount: bigint;
|
|
23
|
-
/** Escrow contract backing this channel. */
|
|
24
|
-
escrowContract: Address;
|
|
25
|
-
/** Chain ID used for channel ID and voucher domain separation. */
|
|
26
|
-
chainId: number;
|
|
27
|
-
/** Whether the client considers the channel reusable. */
|
|
28
|
-
opened: boolean;
|
|
29
|
-
};
|
|
30
|
-
/** Resolves the chain ID embedded in a legacy session challenge. */
|
|
31
|
-
export declare function resolveChainId(challenge: Challenge): number;
|
|
32
|
-
/** Resolves the server-advertised escrow against the client's trust policy. */
|
|
33
|
-
export declare function resolveEscrow(challenge: {
|
|
34
|
-
request: {
|
|
35
|
-
methodDetails?: unknown;
|
|
36
|
-
};
|
|
37
|
-
}, chainId: number, escrowContractOverride?: Address, allowCustomEscrow?: boolean): Address;
|
|
38
|
-
/** Serializes a legacy session credential with a payer DID source. */
|
|
39
|
-
export declare function serializeCredential(challenge: Challenge, payload: LegacySessionCredentialPayload, chainId: number, account: viem_Account): string;
|
|
40
|
-
/** Creates a legacy cumulative voucher credential payload. */
|
|
41
|
-
export declare function createVoucherPayload(client: viem_Client, account: viem_Account, channelId: Hex.Hex, cumulativeAmount: bigint, escrowContract: Address, chainId: number, voucherSigner?: viem_Account | undefined): Promise<LegacySessionCredentialPayload>;
|
|
42
|
-
/** Creates a legacy cooperative close credential payload. */
|
|
43
|
-
export declare function createClosePayload(client: viem_Client, account: viem_Account, channelId: Hex.Hex, cumulativeAmount: bigint, escrowContract: Address, chainId: number, voucherSigner?: viem_Account | undefined): Promise<LegacySessionCredentialPayload>;
|
|
44
|
-
/** Creates a legacy open transaction credential payload and local channel entry. */
|
|
45
|
-
export declare function createOpenPayload(client: viem_Client, account: viem_Account, options: {
|
|
46
|
-
voucherSigner?: viem_Account | undefined;
|
|
47
|
-
escrowContract: Address;
|
|
48
|
-
payee: Address;
|
|
49
|
-
currency: Address;
|
|
50
|
-
deposit: bigint;
|
|
51
|
-
initialAmount: bigint;
|
|
52
|
-
chainId: number;
|
|
53
|
-
feePayer?: boolean | undefined;
|
|
54
|
-
}): Promise<{
|
|
55
|
-
entry: ChannelEntry;
|
|
56
|
-
payload: LegacySessionCredentialPayload;
|
|
57
|
-
}>;
|
|
58
|
-
/**
|
|
59
|
-
* Attempt to recover an existing on-chain channel by reading its state.
|
|
60
|
-
*
|
|
61
|
-
* If the channel has a positive deposit and is not finalized, returns a
|
|
62
|
-
* {@link ChannelEntry} with `cumulativeAmount` set to the on-chain settled
|
|
63
|
-
* amount (the safe starting point for new vouchers).
|
|
64
|
-
*
|
|
65
|
-
* Returns `undefined` if the channel doesn't exist, has zero deposit,
|
|
66
|
-
* or is already finalized.
|
|
67
|
-
*/
|
|
68
|
-
export declare function tryRecoverChannel(client: viem_Client, escrowContract: Address, channelId: Hex.Hex, chainId: number): Promise<ChannelEntry | undefined>;
|
|
69
|
-
//# sourceMappingURL=ChannelOps.d.ts.map
|
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared client-side channel operations.
|
|
3
|
-
*
|
|
4
|
-
* Provides the low-level helpers that both `session()`
|
|
5
|
-
* and `sessionManager()` (orchestrator) rely on: escrow resolution, channel
|
|
6
|
-
* ID computation, on-chain open/voucher/close payload construction, channel
|
|
7
|
-
* recovery from on-chain state, and credential serialization.
|
|
8
|
-
*/
|
|
9
|
-
import { Hex } from 'ox';
|
|
10
|
-
import { encodeFunctionData, } from 'viem';
|
|
11
|
-
import { prepareTransactionRequest, signTransaction } from 'viem/actions';
|
|
12
|
-
import { Abis } from 'viem/tempo';
|
|
13
|
-
import * as Credential from '../../../Credential.js';
|
|
14
|
-
import { getAccountSignerAddress } from '../../internal/account.js';
|
|
15
|
-
import * as defaults from '../../internal/defaults.js';
|
|
16
|
-
import { escrowAbi, getOnChainChannel } from '../session/Chain.js';
|
|
17
|
-
import * as Channel from '../session/Channel.js';
|
|
18
|
-
import { signVoucher } from '../session/Voucher.js';
|
|
19
|
-
function resolveVoucherSigner(account, voucherSigner) {
|
|
20
|
-
return voucherSigner ?? account;
|
|
21
|
-
}
|
|
22
|
-
/** Resolves the chain ID embedded in a legacy session challenge. */
|
|
23
|
-
export function resolveChainId(challenge) {
|
|
24
|
-
const md = challenge.request.methodDetails;
|
|
25
|
-
return md?.chainId ?? 0;
|
|
26
|
-
}
|
|
27
|
-
/** Resolves the server-advertised escrow against the client's trust policy. */
|
|
28
|
-
export function resolveEscrow(challenge, chainId, escrowContractOverride, allowCustomEscrow = false) {
|
|
29
|
-
const challengeEscrow = challenge.request.methodDetails
|
|
30
|
-
?.escrowContract;
|
|
31
|
-
const escrow = escrowContractOverride ??
|
|
32
|
-
defaults.escrowContract[chainId];
|
|
33
|
-
if (!escrow && !(allowCustomEscrow && challengeEscrow))
|
|
34
|
-
throw new Error('No trusted `escrowContract` available. Provide it in client parameters or use a supported chain.');
|
|
35
|
-
if (challengeEscrow &&
|
|
36
|
-
escrow &&
|
|
37
|
-
challengeEscrow.toLowerCase() !== escrow.toLowerCase() &&
|
|
38
|
-
(!allowCustomEscrow || escrowContractOverride !== undefined))
|
|
39
|
-
throw new Error(`Tempo session escrow ${challengeEscrow} does not match client escrow ${escrow}.`);
|
|
40
|
-
if (challengeEscrow && (!escrow || challengeEscrow.toLowerCase() !== escrow.toLowerCase()))
|
|
41
|
-
return challengeEscrow;
|
|
42
|
-
return escrow;
|
|
43
|
-
}
|
|
44
|
-
/** Serializes a legacy session credential with a payer DID source. */
|
|
45
|
-
export function serializeCredential(challenge, payload, chainId, account) {
|
|
46
|
-
return Credential.serialize({
|
|
47
|
-
challenge,
|
|
48
|
-
payload,
|
|
49
|
-
source: `did:pkh:eip155:${chainId}:${account.address}`,
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
/** Creates a legacy cumulative voucher credential payload. */
|
|
53
|
-
export async function createVoucherPayload(client, account, channelId, cumulativeAmount, escrowContract, chainId, voucherSigner) {
|
|
54
|
-
const signer = resolveVoucherSigner(account, voucherSigner);
|
|
55
|
-
const signature = await signVoucher(client, account, { channelId, cumulativeAmount }, escrowContract, chainId, signer);
|
|
56
|
-
return {
|
|
57
|
-
action: 'voucher',
|
|
58
|
-
channelId,
|
|
59
|
-
cumulativeAmount: cumulativeAmount.toString(),
|
|
60
|
-
signature,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
/** Creates a legacy cooperative close credential payload. */
|
|
64
|
-
export async function createClosePayload(client, account, channelId, cumulativeAmount, escrowContract, chainId, voucherSigner) {
|
|
65
|
-
const signer = resolveVoucherSigner(account, voucherSigner);
|
|
66
|
-
const signature = await signVoucher(client, account, { channelId, cumulativeAmount }, escrowContract, chainId, signer);
|
|
67
|
-
return {
|
|
68
|
-
action: 'close',
|
|
69
|
-
channelId,
|
|
70
|
-
cumulativeAmount: cumulativeAmount.toString(),
|
|
71
|
-
signature,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
/** Creates a legacy open transaction credential payload and local channel entry. */
|
|
75
|
-
export async function createOpenPayload(client, account, options) {
|
|
76
|
-
const { escrowContract, payee, currency, deposit, initialAmount, chainId, feePayer } = options;
|
|
77
|
-
const voucherSigner = resolveVoucherSigner(account, options.voucherSigner);
|
|
78
|
-
const authorizedSigner = getAccountSignerAddress(voucherSigner);
|
|
79
|
-
const salt = Hex.random(32);
|
|
80
|
-
const channelId = Channel.computeId({
|
|
81
|
-
authorizedSigner,
|
|
82
|
-
chainId,
|
|
83
|
-
escrowContract,
|
|
84
|
-
payee,
|
|
85
|
-
payer: account.address,
|
|
86
|
-
salt,
|
|
87
|
-
token: currency,
|
|
88
|
-
});
|
|
89
|
-
const approveData = encodeFunctionData({
|
|
90
|
-
abi: Abis.tip20,
|
|
91
|
-
functionName: 'approve',
|
|
92
|
-
args: [escrowContract, deposit],
|
|
93
|
-
});
|
|
94
|
-
const openData = encodeFunctionData({
|
|
95
|
-
abi: escrowAbi,
|
|
96
|
-
functionName: 'open',
|
|
97
|
-
args: [payee, currency, deposit, salt, authorizedSigner],
|
|
98
|
-
});
|
|
99
|
-
const validBefore = Math.floor(Date.now() / 1_000) + 25;
|
|
100
|
-
const prepared = await prepareTransactionRequest(client, {
|
|
101
|
-
account,
|
|
102
|
-
calls: [
|
|
103
|
-
{ to: currency, data: approveData },
|
|
104
|
-
{ to: escrowContract, data: openData },
|
|
105
|
-
],
|
|
106
|
-
feeToken: currency,
|
|
107
|
-
nonceKey: 'expiring',
|
|
108
|
-
validBefore,
|
|
109
|
-
});
|
|
110
|
-
// Estimate before enabling fee-payer mode so Tempo includes sender
|
|
111
|
-
// signature and access-key verification costs in the gas budget.
|
|
112
|
-
prepared.gas = (prepared.gas ?? 0n) + 5000n;
|
|
113
|
-
if (feePayer)
|
|
114
|
-
prepared.feePayer = true;
|
|
115
|
-
const transaction = (await signTransaction(client, prepared));
|
|
116
|
-
const signature = await signVoucher(client, account, { channelId, cumulativeAmount: initialAmount }, escrowContract, chainId, voucherSigner);
|
|
117
|
-
return {
|
|
118
|
-
entry: {
|
|
119
|
-
authorizedSigner,
|
|
120
|
-
channelId,
|
|
121
|
-
salt,
|
|
122
|
-
cumulativeAmount: initialAmount,
|
|
123
|
-
escrowContract,
|
|
124
|
-
chainId,
|
|
125
|
-
opened: true,
|
|
126
|
-
},
|
|
127
|
-
payload: {
|
|
128
|
-
action: 'open',
|
|
129
|
-
type: 'transaction',
|
|
130
|
-
channelId,
|
|
131
|
-
transaction,
|
|
132
|
-
authorizedSigner,
|
|
133
|
-
cumulativeAmount: initialAmount.toString(),
|
|
134
|
-
signature,
|
|
135
|
-
},
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Attempt to recover an existing on-chain channel by reading its state.
|
|
140
|
-
*
|
|
141
|
-
* If the channel has a positive deposit and is not finalized, returns a
|
|
142
|
-
* {@link ChannelEntry} with `cumulativeAmount` set to the on-chain settled
|
|
143
|
-
* amount (the safe starting point for new vouchers).
|
|
144
|
-
*
|
|
145
|
-
* Returns `undefined` if the channel doesn't exist, has zero deposit,
|
|
146
|
-
* or is already finalized.
|
|
147
|
-
*/
|
|
148
|
-
export async function tryRecoverChannel(client, escrowContract, channelId, chainId) {
|
|
149
|
-
try {
|
|
150
|
-
const onChain = await getOnChainChannel(client, escrowContract, channelId);
|
|
151
|
-
if (onChain.deposit > 0n && !onChain.finalized) {
|
|
152
|
-
return {
|
|
153
|
-
// A zero on-chain authorizedSigner means the escrow verifies vouchers
|
|
154
|
-
// against the payer, so record the payer as the voucher authority.
|
|
155
|
-
authorizedSigner: BigInt(onChain.authorizedSigner) === 0n ? onChain.payer : onChain.authorizedSigner,
|
|
156
|
-
channelId,
|
|
157
|
-
salt: '0x',
|
|
158
|
-
cumulativeAmount: onChain.settled,
|
|
159
|
-
escrowContract,
|
|
160
|
-
chainId,
|
|
161
|
-
opened: true,
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
catch { }
|
|
166
|
-
return undefined;
|
|
167
|
-
}
|
|
168
|
-
//# sourceMappingURL=ChannelOps.js.map
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { type Address, type Account as viem_Account } from 'viem';
|
|
2
|
-
import * as Method from '../../../Method.js';
|
|
3
|
-
import * as Account from '../../../viem/Account.js';
|
|
4
|
-
import * as Client from '../../../viem/Client.js';
|
|
5
|
-
import * as z from '../../../zod.js';
|
|
6
|
-
import { type ChannelEntry } from './ChannelOps.js';
|
|
7
|
-
/** Runtime schema for legacy low-level session credential context. */
|
|
8
|
-
export declare const sessionContextSchema: z.ZodMiniObject<{
|
|
9
|
-
account: z.ZodMiniOptional<z.ZodMiniCustom<`0x${string}` | Account.Account | undefined, `0x${string}` | Account.Account | undefined>>;
|
|
10
|
-
action: z.ZodMiniOptional<z.ZodMiniEnum<{
|
|
11
|
-
close: "close";
|
|
12
|
-
open: "open";
|
|
13
|
-
topUp: "topUp";
|
|
14
|
-
voucher: "voucher";
|
|
15
|
-
}>>;
|
|
16
|
-
channelId: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
17
|
-
cumulativeAmount: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
18
|
-
cumulativeAmountRaw: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
19
|
-
transaction: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
20
|
-
additionalDeposit: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
21
|
-
additionalDepositRaw: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
22
|
-
depositRaw: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
23
|
-
}, z.core.$strip>;
|
|
24
|
-
/** Context accepted by the legacy low-level session client method. */
|
|
25
|
-
export type SessionContext = z.infer<typeof sessionContextSchema>;
|
|
26
|
-
/**
|
|
27
|
-
* Creates a session payment method for use with `Mppx.create()`.
|
|
28
|
-
*
|
|
29
|
-
* Supports both auto mode (set `deposit` to manage channels automatically)
|
|
30
|
-
* and manual mode (pass `context.action` to control each step).
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* // Auto mode
|
|
35
|
-
* import { Mppx, tempo } from 'mppx/client'
|
|
36
|
-
*
|
|
37
|
-
* const mppx = Mppx.create({
|
|
38
|
-
* methods: [tempo({
|
|
39
|
-
* account: privateKeyToAccount('0x...'),
|
|
40
|
-
* deposit: '10',
|
|
41
|
-
* })],
|
|
42
|
-
* })
|
|
43
|
-
*
|
|
44
|
-
* const res = await mppx.fetch('/api/chat?prompt=hello')
|
|
45
|
-
* ```
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```ts
|
|
49
|
-
* // Manual mode
|
|
50
|
-
* const mppx = Mppx.create({
|
|
51
|
-
* methods: [tempo({ account })],
|
|
52
|
-
* })
|
|
53
|
-
*
|
|
54
|
-
* const credential = await mppx.createCredential(response, {
|
|
55
|
-
* action: 'voucher',
|
|
56
|
-
* channelId: '0x...',
|
|
57
|
-
* cumulativeAmount: '1',
|
|
58
|
-
* })
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
export declare function session(parameters?: session.Parameters): Method.Client<{
|
|
62
|
-
readonly name: "tempo";
|
|
63
|
-
readonly intent: "session";
|
|
64
|
-
readonly schema: {
|
|
65
|
-
credential: {
|
|
66
|
-
payload: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
|
|
67
|
-
action: z.ZodMiniLiteral<"open">;
|
|
68
|
-
authorizedSigner: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
69
|
-
channelId: z.ZodMiniString<string>;
|
|
70
|
-
cumulativeAmount: z.ZodMiniString<string>;
|
|
71
|
-
descriptor: z.ZodMiniOptional<z.ZodMiniCustom<import("../../session/precompile/Protocol.js").ChannelDescriptor, import("../../session/precompile/Protocol.js").ChannelDescriptor>>;
|
|
72
|
-
signature: z.ZodMiniString<string>;
|
|
73
|
-
transaction: z.ZodMiniString<string>;
|
|
74
|
-
type: z.ZodMiniLiteral<"transaction">;
|
|
75
|
-
}, z.core.$strip>, z.ZodMiniObject<{
|
|
76
|
-
action: z.ZodMiniLiteral<"topUp">;
|
|
77
|
-
additionalDeposit: z.ZodMiniString<string>;
|
|
78
|
-
channelId: z.ZodMiniString<string>;
|
|
79
|
-
descriptor: z.ZodMiniOptional<z.ZodMiniCustom<import("../../session/precompile/Protocol.js").ChannelDescriptor, import("../../session/precompile/Protocol.js").ChannelDescriptor>>;
|
|
80
|
-
transaction: z.ZodMiniString<string>;
|
|
81
|
-
type: z.ZodMiniLiteral<"transaction">;
|
|
82
|
-
}, z.core.$strip>, z.ZodMiniObject<{
|
|
83
|
-
action: z.ZodMiniLiteral<"voucher">;
|
|
84
|
-
channelId: z.ZodMiniString<string>;
|
|
85
|
-
cumulativeAmount: z.ZodMiniString<string>;
|
|
86
|
-
descriptor: z.ZodMiniOptional<z.ZodMiniCustom<import("../../session/precompile/Protocol.js").ChannelDescriptor, import("../../session/precompile/Protocol.js").ChannelDescriptor>>;
|
|
87
|
-
signature: z.ZodMiniString<string>;
|
|
88
|
-
}, z.core.$strip>, z.ZodMiniObject<{
|
|
89
|
-
action: z.ZodMiniLiteral<"close">;
|
|
90
|
-
channelId: z.ZodMiniString<string>;
|
|
91
|
-
cumulativeAmount: z.ZodMiniString<string>;
|
|
92
|
-
descriptor: z.ZodMiniOptional<z.ZodMiniCustom<import("../../session/precompile/Protocol.js").ChannelDescriptor, import("../../session/precompile/Protocol.js").ChannelDescriptor>>;
|
|
93
|
-
signature: z.ZodMiniString<string>;
|
|
94
|
-
}, z.core.$strip>], "action">;
|
|
95
|
-
};
|
|
96
|
-
request: z.ZodMiniPipe<z.ZodMiniObject<{
|
|
97
|
-
amount: z.ZodMiniString<string>;
|
|
98
|
-
chainId: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
|
|
99
|
-
channelId: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
100
|
-
currency: z.ZodMiniString<string>;
|
|
101
|
-
decimals: z.ZodMiniNumber<number>;
|
|
102
|
-
escrowContract: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
103
|
-
feePayer: z.ZodMiniOptional<z.ZodMiniPipe<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniCustom<viem_Account, viem_Account>]>, z.ZodMiniTransform<boolean, boolean | viem_Account>>>;
|
|
104
|
-
feeToken: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
105
|
-
minVoucherDelta: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
106
|
-
operator: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
107
|
-
recipient: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
108
|
-
sessionProtocol: z.ZodMiniOptional<z.ZodMiniEnum<{
|
|
109
|
-
v1: "v1";
|
|
110
|
-
v2: "v2";
|
|
111
|
-
}>>;
|
|
112
|
-
sessionSnapshot: z.ZodMiniOptional<z.ZodMiniCustom<import("../../session/Snapshot.js").SessionSnapshot, import("../../session/Snapshot.js").SessionSnapshot>>;
|
|
113
|
-
suggestedDeposit: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
114
|
-
unitType: z.ZodMiniString<string>;
|
|
115
|
-
}, z.core.$strip>, z.ZodMiniTransform<{
|
|
116
|
-
currency: string;
|
|
117
|
-
recipient?: string | undefined;
|
|
118
|
-
unitType: string;
|
|
119
|
-
amount: string;
|
|
120
|
-
suggestedDeposit?: string | undefined;
|
|
121
|
-
methodDetails: {
|
|
122
|
-
escrowContract: string | undefined;
|
|
123
|
-
channelId?: string | undefined;
|
|
124
|
-
minVoucherDelta?: string | undefined;
|
|
125
|
-
chainId?: number | undefined;
|
|
126
|
-
feePayer?: boolean | undefined;
|
|
127
|
-
feeToken?: string | undefined;
|
|
128
|
-
operator?: string | undefined;
|
|
129
|
-
sessionProtocol?: "v1" | "v2" | undefined;
|
|
130
|
-
sessionSnapshot?: import("../../session/Snapshot.js").SessionSnapshot | undefined;
|
|
131
|
-
};
|
|
132
|
-
}, {
|
|
133
|
-
amount: string;
|
|
134
|
-
chainId?: number | undefined;
|
|
135
|
-
channelId?: string | undefined;
|
|
136
|
-
currency: string;
|
|
137
|
-
decimals: number;
|
|
138
|
-
escrowContract?: string | undefined;
|
|
139
|
-
feePayer?: boolean | undefined;
|
|
140
|
-
feeToken?: string | undefined;
|
|
141
|
-
minVoucherDelta?: string | undefined;
|
|
142
|
-
operator?: string | undefined;
|
|
143
|
-
recipient?: string | undefined;
|
|
144
|
-
sessionProtocol?: "v1" | "v2" | undefined;
|
|
145
|
-
sessionSnapshot?: import("../../session/Snapshot.js").SessionSnapshot | undefined;
|
|
146
|
-
suggestedDeposit?: string | undefined;
|
|
147
|
-
unitType: string;
|
|
148
|
-
}>>;
|
|
149
|
-
};
|
|
150
|
-
}, z.ZodMiniObject<{
|
|
151
|
-
account: z.ZodMiniOptional<z.ZodMiniCustom<`0x${string}` | Account.Account | undefined, `0x${string}` | Account.Account | undefined>>;
|
|
152
|
-
action: z.ZodMiniOptional<z.ZodMiniEnum<{
|
|
153
|
-
close: "close";
|
|
154
|
-
open: "open";
|
|
155
|
-
topUp: "topUp";
|
|
156
|
-
voucher: "voucher";
|
|
157
|
-
}>>;
|
|
158
|
-
channelId: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
159
|
-
cumulativeAmount: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
160
|
-
cumulativeAmountRaw: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
161
|
-
transaction: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
162
|
-
additionalDeposit: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
163
|
-
additionalDepositRaw: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
164
|
-
depositRaw: z.ZodMiniOptional<z.ZodMiniString<string>>;
|
|
165
|
-
}, z.core.$strip>>;
|
|
166
|
-
/** Type helpers for the legacy low-level session client method. */
|
|
167
|
-
export declare namespace session {
|
|
168
|
-
type Parameters = Account.getResolver.Parameters & Client.getResolver.Parameters & {
|
|
169
|
-
/** Accept a noncanonical escrow contract advertised by the server. @default false */
|
|
170
|
-
allowCustomEscrow?: boolean | undefined;
|
|
171
|
-
/** Account that signs voucher digests. Defaults to `account`; access-key accounts sign raw vouchers as their access-key address. */
|
|
172
|
-
voucherSigner?: viem_Account | undefined;
|
|
173
|
-
/** Token decimals for parsing human-readable amounts (default: 6). */
|
|
174
|
-
decimals?: number | undefined;
|
|
175
|
-
/** Initial deposit amount in human-readable units (e.g. "10" for 10 tokens). When set, the method handles the full channel lifecycle (open, voucher, cumulative tracking) automatically. */
|
|
176
|
-
deposit?: string | undefined;
|
|
177
|
-
/** Exact escrow contract address pin. Takes precedence over `allowCustomEscrow`. */
|
|
178
|
-
escrowContract?: Address | undefined;
|
|
179
|
-
/** Maximum deposit in human-readable units (e.g. "10"). Caps the server's `suggestedDeposit`. Enables auto-management like `deposit`. */
|
|
180
|
-
maxDeposit?: string | undefined;
|
|
181
|
-
/** Called whenever channel state changes (open, voucher, close, recovery). */
|
|
182
|
-
onChannelUpdate?: ((entry: ChannelEntry) => void) | undefined;
|
|
183
|
-
};
|
|
184
|
-
}
|
|
185
|
-
//# sourceMappingURL=Session.d.ts.map
|