mppx 0.8.19 → 0.9.1

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.
Files changed (135) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +0 -6
  3. package/dist/Challenge.d.ts +7 -0
  4. package/dist/Challenge.js +32 -6
  5. package/dist/Constants.d.ts +1 -0
  6. package/dist/Constants.js +1 -0
  7. package/dist/Credential.d.ts +11 -5
  8. package/dist/Credential.js +8 -8
  9. package/dist/Errors.d.ts +10 -0
  10. package/dist/Errors.js +12 -0
  11. package/dist/Html.js +1 -1
  12. package/dist/Mcp.d.ts +9 -1
  13. package/dist/Mcp.js +18 -0
  14. package/dist/Method.d.ts +7 -0
  15. package/dist/cli/THIRD-PARTY-LICENSES.txt +1 -1
  16. package/dist/cli/cli.d.ts +2 -2
  17. package/dist/cli/cli.js +134 -134
  18. package/dist/cli/plugins/index.js +13 -13
  19. package/dist/cli/sessions/Manager.js +4 -6
  20. package/dist/cli/sessions/commands.d.ts +1 -1
  21. package/dist/cli/sessions/store.js +13 -19
  22. package/dist/cli/validate/index.d.ts +2 -2
  23. package/dist/client/Mppx.d.ts +39 -2
  24. package/dist/client/Mppx.js +102 -46
  25. package/dist/client/Transport.js +1 -1
  26. package/dist/client/internal/protocols/Mcp.js +2 -1
  27. package/dist/client/internal/protocols/Mpp.d.ts +1 -1
  28. package/dist/client/internal/protocols/Mpp.js +5 -3
  29. package/dist/client/internal/protocols/Protocol.d.ts +3 -1
  30. package/dist/client/internal/protocols/Shared.js +5 -1
  31. package/dist/integrations/x402/Evm.d.ts +29 -0
  32. package/dist/integrations/x402/Evm.js +150 -0
  33. package/dist/integrations/x402/Negotiator.d.ts +36 -0
  34. package/dist/integrations/x402/Negotiator.js +165 -0
  35. package/dist/mcp/client/McpClient.js +22 -10
  36. package/dist/mcp/internal/Credential.d.ts +9 -0
  37. package/dist/mcp/internal/Credential.js +16 -0
  38. package/dist/mcp/server/Transport.d.ts +2 -2
  39. package/dist/mcp/server/Transport.js +11 -6
  40. package/dist/middlewares/express.js +5 -12
  41. package/dist/middlewares/internal/express.d.ts +8 -0
  42. package/dist/middlewares/internal/express.js +24 -0
  43. package/dist/middlewares/internal/node.d.ts +10 -0
  44. package/dist/middlewares/internal/node.js +34 -0
  45. package/dist/proxy/Proxy.js +15 -9
  46. package/dist/server/Mppx.d.ts +8 -0
  47. package/dist/server/Mppx.js +92 -20
  48. package/dist/server/Transport.d.ts +8 -2
  49. package/dist/server/Transport.js +14 -18
  50. package/dist/server/internal/SecretKey.d.ts +3 -0
  51. package/dist/server/internal/SecretKey.js +9 -0
  52. package/dist/server/internal/html/serviceWorker.client.d.ts +1 -1
  53. package/dist/server/internal/html/serviceWorker.client.js +2 -2
  54. package/dist/server/internal/html/serviceWorker.gen.d.ts +1 -1
  55. package/dist/server/internal/html/serviceWorker.gen.js +1 -1
  56. package/dist/stripe/Methods.d.ts +6 -0
  57. package/dist/stripe/Methods.js +3 -1
  58. package/dist/stripe/client/Charge.d.ts +6 -0
  59. package/dist/stripe/client/Methods.d.ts +6 -0
  60. package/dist/stripe/internal/payment-intent.d.ts +7 -0
  61. package/dist/stripe/internal/payment-intent.js +6 -0
  62. package/dist/stripe/server/Charge.d.ts +6 -0
  63. package/dist/stripe/server/Charge.js +8 -3
  64. package/dist/stripe/server/Methods.js +62 -7
  65. package/dist/stripe/server/internal/html.gen.d.ts +1 -1
  66. package/dist/stripe/server/internal/html.gen.js +1 -1
  67. package/dist/tempo/Methods.d.ts +0 -10
  68. package/dist/tempo/Methods.js +3 -12
  69. package/dist/tempo/Tokens.d.ts +13 -0
  70. package/dist/tempo/Tokens.js +13 -0
  71. package/dist/tempo/client/Charge.d.ts +1 -4
  72. package/dist/tempo/client/Charge.js +20 -13
  73. package/dist/tempo/client/Methods.d.ts +0 -10
  74. package/dist/tempo/index.d.ts +1 -0
  75. package/dist/tempo/index.js +1 -0
  76. package/dist/tempo/internal/account.d.ts +15 -6
  77. package/dist/tempo/internal/account.js +17 -26
  78. package/dist/tempo/internal/defaults.d.ts +0 -11
  79. package/dist/tempo/internal/defaults.js +0 -11
  80. package/dist/tempo/internal/fee-payer.d.ts +22 -4
  81. package/dist/tempo/internal/fee-payer.js +12 -31
  82. package/dist/tempo/internal/fee-token.d.ts +2 -0
  83. package/dist/tempo/internal/fee-token.js +7 -0
  84. package/dist/tempo/internal/remote-fee-payer.d.ts +12 -0
  85. package/dist/tempo/internal/remote-fee-payer.js +17 -0
  86. package/dist/tempo/legacy/client/Session.d.ts +0 -7
  87. package/dist/tempo/server/Charge.d.ts +0 -3
  88. package/dist/tempo/server/Charge.js +26 -68
  89. package/dist/tempo/server/Methods.d.ts +4 -18
  90. package/dist/tempo/server/Methods.js +4 -8
  91. package/dist/tempo/server/internal/html.gen.d.ts +1 -1
  92. package/dist/tempo/server/internal/html.gen.js +1 -1
  93. package/dist/tempo/session/client/ChannelOps.d.ts +0 -14
  94. package/dist/tempo/session/client/ChannelOps.js +0 -22
  95. package/dist/tempo/session/client/ChannelStore.d.ts +5 -0
  96. package/dist/tempo/session/client/ChannelStore.js +2 -2
  97. package/dist/tempo/session/client/CredentialState.d.ts +2 -12
  98. package/dist/tempo/session/client/CredentialState.js +75 -73
  99. package/dist/tempo/session/client/Session.d.ts +2 -9
  100. package/dist/tempo/session/client/Session.js +71 -176
  101. package/dist/tempo/session/client/SessionManager.js +7 -27
  102. package/dist/tempo/session/precompile/Chain.d.ts +0 -4
  103. package/dist/tempo/session/precompile/Chain.js +1 -29
  104. package/dist/tempo/session/precompile/Protocol.d.ts +0 -13
  105. package/dist/tempo/session/precompile/Voucher.d.ts +1 -3
  106. package/dist/tempo/session/precompile/Voucher.js +12 -6
  107. package/dist/tempo/session/server/ChannelStore.d.ts +0 -6
  108. package/dist/tempo/session/server/ChannelStore.js +4 -11
  109. package/dist/tempo/session/server/CredentialVerification.d.ts +7 -9
  110. package/dist/tempo/session/server/CredentialVerification.js +118 -184
  111. package/dist/tempo/session/server/RequestState.d.ts +0 -17
  112. package/dist/tempo/session/server/RequestState.js +15 -59
  113. package/dist/tempo/session/server/Session.d.ts +0 -9
  114. package/dist/tempo/session/server/Session.js +13 -39
  115. package/dist/tempo/session/server/Settlement.d.ts +0 -7
  116. package/dist/tempo/session/server/Settlement.js +16 -50
  117. package/dist/viem/Client.d.ts +7 -2
  118. package/dist/viem/Client.js +17 -5
  119. package/dist/x402/Types.d.ts +2 -0
  120. package/dist/x402/Types.js +2 -0
  121. package/dist/x402/mcp.d.ts +20 -0
  122. package/dist/x402/mcp.js +154 -0
  123. package/dist/x402/middlewares/express.d.ts +23 -0
  124. package/dist/x402/middlewares/express.js +49 -0
  125. package/dist/x402/middlewares/hono.d.ts +13 -0
  126. package/dist/x402/middlewares/hono.js +36 -0
  127. package/dist/x402/middlewares/next.d.ts +17 -0
  128. package/dist/x402/middlewares/next.js +58 -0
  129. package/package.json +41 -1
  130. package/dist/tempo/internal/machine-token-charge.d.ts +0 -51
  131. package/dist/tempo/internal/machine-token-charge.js +0 -113
  132. package/dist/tempo/internal/machine-token-session.d.ts +0 -88
  133. package/dist/tempo/internal/machine-token-session.js +0 -173
  134. package/dist/tempo/internal/signature-envelope.d.ts +0 -14
  135. package/dist/tempo/internal/signature-envelope.js +0 -28
@@ -0,0 +1,13 @@
1
+ import { defineToken } from 'viem/tokens';
2
+ /** MACH token metadata and deployed addresses. */
3
+ export declare const mach: defineToken.ReturnType<{
4
+ readonly addresses: {
5
+ readonly 4217: "0x20c000000000000000000000f37de3740ADec032";
6
+ readonly 42431: "0x20c000000000000000000000f37de3740ADec032";
7
+ };
8
+ readonly currency: "USD";
9
+ readonly decimals: 6;
10
+ readonly name: "MACH";
11
+ readonly symbol: "MACH";
12
+ }>;
13
+ //# sourceMappingURL=Tokens.d.ts.map
@@ -0,0 +1,13 @@
1
+ import { defineToken } from 'viem/tokens';
2
+ /** MACH token metadata and deployed addresses. */
3
+ export const mach = defineToken({
4
+ addresses: {
5
+ 4217: '0x20c000000000000000000000f37de3740ADec032',
6
+ 42431: '0x20c000000000000000000000f37de3740ADec032',
7
+ },
8
+ currency: 'USD',
9
+ decimals: 6,
10
+ name: 'MACH',
11
+ symbol: 'MACH',
12
+ });
13
+ //# sourceMappingURL=Tokens.js.map
@@ -1,4 +1,4 @@
1
- import type { Address } from 'viem';
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';
@@ -42,7 +42,6 @@ export declare function charge(parameters?: charge.Parameters): Method.Client<{
42
42
  }, z.core.$strip>], "type">;
43
43
  };
44
44
  request: z.ZodMiniPipe<z.ZodMiniObject<{
45
- machineTokenEnabled: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
46
45
  amount: z.ZodMiniString<string>;
47
46
  chainId: z.ZodMiniOptional<z.ZodMiniNumber<number>>;
48
47
  currency: z.ZodMiniString<string>;
@@ -68,7 +67,6 @@ export declare function charge(parameters?: charge.Parameters): Method.Client<{
68
67
  recipient?: string | undefined;
69
68
  amount: string;
70
69
  methodDetails?: {
71
- machineTokenEnabled?: boolean | undefined;
72
70
  chainId?: number | undefined;
73
71
  feePayer?: boolean | undefined;
74
72
  memo?: string | undefined;
@@ -80,7 +78,6 @@ export declare function charge(parameters?: charge.Parameters): Method.Client<{
80
78
  supportedModes?: ("pull" | "push")[] | undefined;
81
79
  } | undefined;
82
80
  }, {
83
- machineTokenEnabled?: boolean | undefined;
84
81
  amount: string;
85
82
  chainId?: number | undefined;
86
83
  currency: string;
@@ -1,3 +1,4 @@
1
+ import { isAddressEqual } from 'viem';
1
2
  import { prepareTransactionRequest, sendCallsSync, sendTransactionSync, signTypedData, signTransaction, } from 'viem/actions';
2
3
  import { Actions } from 'viem/tempo';
3
4
  import { tempo as tempo_chain } from 'viem/tempo/chains';
@@ -10,9 +11,10 @@ import * as Attribution from '../Attribution.js';
10
11
  import * as AutoSwap from '../internal/auto-swap.js';
11
12
  import * as Charge_internal from '../internal/charge.js';
12
13
  import * as defaults from '../internal/defaults.js';
13
- import * as MachineTokenCharge from '../internal/machine-token-charge.js';
14
+ import { defaultFeeTokens, resolveFeeToken } from '../internal/fee-token.js';
14
15
  import * as Proof from '../internal/proof.js';
15
16
  import * as Methods from '../Methods.js';
17
+ import { mach } from '../Tokens.js';
16
18
  const chargeContextSchema = z.object({
17
19
  account: z.optional(z.custom()),
18
20
  autoSwap: z.optional(z.custom()),
@@ -106,13 +108,12 @@ export function charge(parameters = {}) {
106
108
  token: currency,
107
109
  }));
108
110
  const autoSwap = AutoSwap.resolve(context?.autoSwap ?? parameters.autoSwap, AutoSwap.defaultCurrencies);
109
- const machineTokenEnabled = methodDetails?.machineTokenEnabled === true;
110
111
  const account = (await parameters.resolveAccount?.({
111
112
  account: defaultAccount,
112
113
  chainId,
113
114
  operation: {
114
115
  kind: 'executeCalls',
115
- ...(autoSwap || machineTokenEnabled ? {} : { calls: transferCalls }),
116
+ ...(autoSwap ? {} : { calls: transferCalls }),
116
117
  },
117
118
  })) ?? defaultAccount;
118
119
  const mode = (() => {
@@ -127,15 +128,7 @@ export function charge(parameters = {}) {
127
128
  return preferredMode;
128
129
  return supportedModes[0];
129
130
  })();
130
- const machineTokenRoute = machineTokenEnabled
131
- ? await MachineTokenCharge.findRoute(client, {
132
- account: account.address,
133
- chainId,
134
- currency,
135
- transfers,
136
- })
137
- : undefined;
138
- const swapCalls = !machineTokenRoute && autoSwap
131
+ const swapCalls = autoSwap
139
132
  ? await AutoSwap.findCalls(client, {
140
133
  account: account.address,
141
134
  amountOut: BigInt(amount),
@@ -144,7 +137,18 @@ export function charge(parameters = {}) {
144
137
  slippage: autoSwap.slippage,
145
138
  })
146
139
  : undefined;
147
- const calls = machineTokenRoute?.calls ?? [...(swapCalls ?? []), ...transferCalls];
140
+ const calls = [...(swapCalls ?? []), ...transferCalls];
141
+ const machAddress = mach.addresses[chainId];
142
+ const allowedFeeTokens = defaultFeeTokens(chainId);
143
+ const feeToken = machAddress && isAddressEqual(currency, machAddress)
144
+ ? await resolveFeeToken({
145
+ account: account.address,
146
+ allowedTokens: allowedFeeTokens,
147
+ candidateTokens: allowedFeeTokens,
148
+ client,
149
+ prioritizeCandidates: true,
150
+ })
151
+ : undefined;
148
152
  const validBefore = (() => {
149
153
  const defaultExpiry = Math.floor(Date.now() / 1000) + 25;
150
154
  if (!challenge.expires)
@@ -159,6 +163,7 @@ export function charge(parameters = {}) {
159
163
  await sendTransactionSync(client, {
160
164
  account,
161
165
  calls,
166
+ ...(feeToken ? { feeToken } : {}),
162
167
  nonceKey: 'expiring',
163
168
  validBefore,
164
169
  }),
@@ -166,6 +171,7 @@ export function charge(parameters = {}) {
166
171
  }
167
172
  : await sendCallsSync(client, {
168
173
  account,
174
+ ...(feeToken ? { capabilities: { feeToken } } : {}),
169
175
  calls: calls,
170
176
  experimental_fallback: calls.length === 1,
171
177
  forceAtomic: calls.length > 1,
@@ -182,6 +188,7 @@ export function charge(parameters = {}) {
182
188
  const prepared = await prepareTransactionRequest(client, {
183
189
  account,
184
190
  calls,
191
+ ...(feeToken ? { feeToken } : {}),
185
192
  nonceKey: 'expiring',
186
193
  validBefore,
187
194
  });
@@ -37,7 +37,6 @@ export declare function tempo(parameters?: tempo.Parameters): readonly [import("
37
37
  }, import("zod/v4/core").$strip>], "type">;
38
38
  };
39
39
  request: import("zod/mini").ZodMiniPipe<import("zod/mini").ZodMiniObject<{
40
- machineTokenEnabled: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniBoolean<boolean>>;
41
40
  amount: import("zod/mini").ZodMiniString<string>;
42
41
  chainId: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniNumber<number>>;
43
42
  currency: import("zod/mini").ZodMiniString<string>;
@@ -63,7 +62,6 @@ export declare function tempo(parameters?: tempo.Parameters): readonly [import("
63
62
  recipient?: string | undefined;
64
63
  amount: string;
65
64
  methodDetails?: {
66
- machineTokenEnabled?: boolean | undefined;
67
65
  chainId?: number | undefined;
68
66
  feePayer?: boolean | undefined;
69
67
  memo?: string | undefined;
@@ -75,7 +73,6 @@ export declare function tempo(parameters?: tempo.Parameters): readonly [import("
75
73
  supportedModes?: ("pull" | "push")[] | undefined;
76
74
  } | undefined;
77
75
  }, {
78
- machineTokenEnabled?: boolean | undefined;
79
76
  amount: string;
80
77
  chainId?: number | undefined;
81
78
  currency: string;
@@ -107,7 +104,6 @@ export declare function tempo(parameters?: tempo.Parameters): readonly [import("
107
104
  credential: {
108
105
  payload: import("zod/mini").ZodMiniDiscriminatedUnion<[import("zod/mini").ZodMiniObject<{
109
106
  action: import("zod/mini").ZodMiniLiteral<"open">;
110
- authorizationSignature: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
111
107
  authorizedSigner: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
112
108
  channelId: import("zod/mini").ZodMiniString<string>;
113
109
  cumulativeAmount: import("zod/mini").ZodMiniString<string>;
@@ -124,18 +120,15 @@ export declare function tempo(parameters?: tempo.Parameters): readonly [import("
124
120
  type: import("zod/mini").ZodMiniLiteral<"transaction">;
125
121
  }, import("zod/v4/core").$strip>, import("zod/mini").ZodMiniObject<{
126
122
  action: import("zod/mini").ZodMiniLiteral<"voucher">;
127
- authorizationSignature: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
128
123
  channelId: import("zod/mini").ZodMiniString<string>;
129
124
  cumulativeAmount: import("zod/mini").ZodMiniString<string>;
130
125
  descriptor: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniCustom<import("../session/precompile/Protocol.js").ChannelDescriptor, import("../session/precompile/Protocol.js").ChannelDescriptor>>;
131
126
  signature: import("zod/mini").ZodMiniString<string>;
132
127
  }, import("zod/v4/core").$strip>, import("zod/mini").ZodMiniObject<{
133
128
  action: import("zod/mini").ZodMiniLiteral<"close">;
134
- authorizationSignature: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
135
129
  channelId: import("zod/mini").ZodMiniString<string>;
136
130
  cumulativeAmount: import("zod/mini").ZodMiniString<string>;
137
131
  descriptor: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniCustom<import("../session/precompile/Protocol.js").ChannelDescriptor, import("../session/precompile/Protocol.js").ChannelDescriptor>>;
138
- refundSignature: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
139
132
  signature: import("zod/mini").ZodMiniString<string>;
140
133
  }, import("zod/v4/core").$strip>], "action">;
141
134
  };
@@ -148,7 +141,6 @@ export declare function tempo(parameters?: tempo.Parameters): readonly [import("
148
141
  escrowContract: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
149
142
  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>>>;
150
143
  feeToken: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
151
- machineTokenEnabled: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniBoolean<boolean>>;
152
144
  minVoucherDelta: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
153
145
  operator: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
154
146
  recipient: import("zod/mini").ZodMiniOptional<import("zod/mini").ZodMiniString<string>>;
@@ -172,7 +164,6 @@ export declare function tempo(parameters?: tempo.Parameters): readonly [import("
172
164
  chainId?: number | undefined;
173
165
  feePayer?: boolean | undefined;
174
166
  feeToken?: string | undefined;
175
- machineTokenEnabled?: boolean | undefined;
176
167
  operator?: string | undefined;
177
168
  sessionProtocol?: "v1" | "v2" | undefined;
178
169
  sessionSnapshot?: import("../session/Snapshot.js").SessionSnapshot | undefined;
@@ -186,7 +177,6 @@ export declare function tempo(parameters?: tempo.Parameters): readonly [import("
186
177
  escrowContract?: string | undefined;
187
178
  feePayer?: boolean | undefined;
188
179
  feeToken?: string | undefined;
189
- machineTokenEnabled?: boolean | undefined;
190
180
  minVoucherDelta?: string | undefined;
191
181
  operator?: string | undefined;
192
182
  recipient?: string | undefined;
@@ -3,4 +3,5 @@ export * as Methods from './Methods.js';
3
3
  export * as Session from './session/index.js';
4
4
  export * as SessionLegacy from './legacy/index.js';
5
5
  export * as Subscription from './subscription/index.js';
6
+ export { mach } from './Tokens.js';
6
7
  //# sourceMappingURL=index.d.ts.map
@@ -3,4 +3,5 @@ export * as Methods from './Methods.js';
3
3
  export * as Session from './session/index.js';
4
4
  export * as SessionLegacy from './legacy/index.js';
5
5
  export * as Subscription from './subscription/index.js';
6
+ export { mach } from './Tokens.js';
6
7
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,8 @@
1
1
  import type { Account, Address } from 'viem';
2
2
  import type { Account as TempoAccount } from 'viem/tempo';
3
+ import * as RemoteFeePayer from './remote-fee-payer.js';
4
+ /** Returns whether a value is a viem account. */
5
+ export declare function is(value: unknown): value is Account;
3
6
  /** Returns whether an account is a Tempo access-key account. */
4
7
  export declare function isAccessKeyAccount(account: Account): account is Account & TempoAccount.AccessKeyAccount;
5
8
  /** Returns the address that should authorize direct account signatures. */
@@ -10,15 +13,18 @@ export declare function getAccountSignerAddress(account: Account): Address;
10
13
  * Accepts either `account` or `recipient` as the parameter name. When the value
11
14
  * is an `Account`, its address is extracted. If `feePayer` is `true`, the
12
15
  * account also acts as the fee payer. Alternatively, a separate `Account`
13
- * can be provided as the fee payer, or a URL string pointing to a fee payer
14
- * relay service (used with `withFeePayer` transport wrapping).
16
+ * can be provided as the fee payer, or remote fee-payer configuration (used
17
+ * with `withFeePayer` transport wrapping).
15
18
  *
16
- * @returns An object with `account`, `feePayer`, `feePayerUrl`, and `recipient`.
19
+ * @returns Resolved account, local fee payer, remote fee payer, and recipient.
17
20
  */
18
21
  export declare function resolve(parameters: resolve.Parameters): {
19
22
  account: Account | undefined;
20
23
  feePayer: Account | undefined;
21
- feePayerUrl: string | undefined;
24
+ remoteFeePayer: Readonly<{
25
+ headers?: Readonly<Record<string, string>> | undefined;
26
+ url: string;
27
+ }> | undefined;
22
28
  recipient: Address | undefined;
23
29
  };
24
30
  export declare namespace resolve {
@@ -26,8 +32,11 @@ export declare namespace resolve {
26
32
  recipient?: Address | undefined;
27
33
  /** Account or address that performs payment operations / receives payment. */
28
34
  account?: Account | Address | undefined;
29
- /** When `true`, the account also sponsors fees. An `Account` object or URL string can also be provided as a dedicated fee payer. */
30
- feePayer?: Account | string | true | undefined;
35
+ /**
36
+ * When `true`, the account also sponsors fees. An `Account` or remote fee-payer
37
+ * configuration can also be provided. A string is shorthand for its URL.
38
+ */
39
+ feePayer?: Account | RemoteFeePayer.Config | string | true | undefined;
31
40
  };
32
41
  }
33
42
  //# sourceMappingURL=account.d.ts.map
@@ -1,3 +1,8 @@
1
+ import * as RemoteFeePayer from './remote-fee-payer.js';
2
+ /** Returns whether a value is a viem account. */
3
+ export function is(value) {
4
+ return typeof value === 'object' && value !== null && 'address' in value;
5
+ }
1
6
  /** Returns whether an account is a Tempo access-key account. */
2
7
  export function isAccessKeyAccount(account) {
3
8
  return 'accessKeyAddress' in account;
@@ -12,34 +17,20 @@ export function getAccountSignerAddress(account) {
12
17
  * Accepts either `account` or `recipient` as the parameter name. When the value
13
18
  * is an `Account`, its address is extracted. If `feePayer` is `true`, the
14
19
  * account also acts as the fee payer. Alternatively, a separate `Account`
15
- * can be provided as the fee payer, or a URL string pointing to a fee payer
16
- * relay service (used with `withFeePayer` transport wrapping).
20
+ * can be provided as the fee payer, or remote fee-payer configuration (used
21
+ * with `withFeePayer` transport wrapping).
17
22
  *
18
- * @returns An object with `account`, `feePayer`, `feePayerUrl`, and `recipient`.
23
+ * @returns Resolved account, local fee payer, remote fee payer, and recipient.
19
24
  */
20
25
  export function resolve(parameters) {
21
- const account = (() => {
22
- if (typeof parameters.account === 'object')
23
- return parameters.account;
24
- return undefined;
25
- })();
26
- const recipient = (() => {
27
- if (parameters.recipient)
28
- return parameters.recipient;
29
- if (typeof parameters.account === 'object')
30
- return parameters.account.address;
31
- return parameters.account;
32
- })();
33
- const feePayerUrl = typeof parameters.feePayer === 'string' ? parameters.feePayer : undefined;
34
- const feePayer = (() => {
35
- if (typeof parameters.feePayer === 'string')
36
- return undefined;
37
- if (typeof parameters.account === 'object' && parameters.feePayer === true)
38
- return parameters.account;
39
- if (typeof parameters.feePayer === 'object')
40
- return parameters.feePayer;
41
- return undefined;
42
- })();
43
- return { account, feePayer, feePayerUrl, recipient: recipient };
26
+ const account = is(parameters.account) ? parameters.account : undefined;
27
+ const recipient = parameters.recipient ?? account?.address ?? parameters.account;
28
+ const remoteFeePayer = RemoteFeePayer.from(parameters.feePayer);
29
+ const feePayer = parameters.feePayer === true
30
+ ? account
31
+ : is(parameters.feePayer)
32
+ ? parameters.feePayer
33
+ : undefined;
34
+ return { account, feePayer, remoteFeePayer, recipient: recipient };
44
35
  }
45
36
  //# sourceMappingURL=account.js.map
@@ -16,17 +16,6 @@ export declare const currency: {
16
16
  readonly 4217: "0x20C000000000000000000000b9537d11c60E8b50";
17
17
  readonly 42431: "0x20c0000000000000000000000000000000000000";
18
18
  };
19
- /** Unified first-party machine-token deployments used by charges and sessions. */
20
- export declare const machineToken: {
21
- readonly 4217: {
22
- readonly swap: '0xd588ED9Ae08643A450157Adaf61c3C0C1BBd0dbb';
23
- readonly token: '0x20c0000000000000000000006637932dE5413804';
24
- };
25
- readonly 42431: {
26
- readonly swap: '0xd588ED9Ae08643A450157Adaf61c3C0C1BBd0dbb';
27
- readonly token: '0x20c0000000000000000000006637932dE5413804';
28
- };
29
- };
30
19
  /**
31
20
  * Default token decimals for TIP-20 stablecoins (e.g. pathUSD, USDC).
32
21
  *
@@ -14,17 +14,6 @@ export const currency = {
14
14
  [chainId.mainnet]: tokens.usdc,
15
15
  [chainId.testnet]: tokens.pathUsd,
16
16
  };
17
- /** Unified first-party machine-token deployments used by charges and sessions. */
18
- export const machineToken = {
19
- [chainId.mainnet]: {
20
- swap: '0xd588ED9Ae08643A450157Adaf61c3C0C1BBd0dbb',
21
- token: '0x20c0000000000000000000006637932dE5413804',
22
- },
23
- [chainId.testnet]: {
24
- swap: '0xd588ED9Ae08643A450157Adaf61c3C0C1BBd0dbb',
25
- token: '0x20c0000000000000000000006637932dE5413804',
26
- },
27
- };
28
17
  /**
29
18
  * Default token decimals for TIP-20 stablecoins (e.g. pathUSD, USDC).
30
19
  *
@@ -24,14 +24,29 @@ type ExpectedTransfer = {
24
24
  recipient: TempoAddress.Address;
25
25
  };
26
26
  /** Returns fee tokens that mppx allows sponsored transactions to charge. */
27
- export declare function defaultAllowedFeeTokens(chainId: number | undefined): TempoAddress.Address[];
27
+ export declare function defaultAllowedFeeTokens(chainId: number | undefined): `0x${string}`[];
28
28
  /** Rejects a sponsored fee token outside the server's allowlist. */
29
29
  export declare function assertAllowedFeeToken(transaction: {
30
30
  feeToken?: unknown;
31
31
  }, allowedFeeTokens: readonly TempoAddress.Address[]): void;
32
+ declare function hostedFeePayerRequest(transaction: SponsoredTransaction): {
33
+ accessList?: any;
34
+ calls: any;
35
+ feePayer: boolean;
36
+ from: any;
37
+ gas?: `0x${string}` | undefined;
38
+ keyAuthorization?: any;
39
+ maxFeePerGas?: `0x${string}` | undefined;
40
+ maxPriorityFeePerGas?: `0x${string}` | undefined;
41
+ nonce: `0x${string}`;
42
+ nonceKey?: `0x${string}` | undefined;
43
+ type: string;
44
+ validAfter?: `0x${string}` | undefined;
45
+ validBefore?: `0x${string}` | undefined;
46
+ };
32
47
  /**
33
- * Co-signs a sender-signed partial sponsorship envelope using a hosted
34
- * fee-payer endpoint without letting the endpoint mutate sender-committed
48
+ * Co-signs a sender-signed partial sponsorship envelope through a hosted
49
+ * fee-payer transport without letting the endpoint mutate sender-committed
35
50
  * transaction fields.
36
51
  *
37
52
  * @returns The serialized co-signed transaction plus the sponsor's recovered
@@ -44,8 +59,11 @@ export declare function fillHostedFeePayerTransaction(parameters: {
44
59
  chainId: number;
45
60
  details: Record<string, string>;
46
61
  policy?: Partial<Policy> | undefined;
62
+ request: (args: {
63
+ method: 'eth_fillTransaction';
64
+ params: readonly [ReturnType<typeof hostedFeePayerRequest>];
65
+ }) => Promise<unknown>;
47
66
  transaction: SponsoredTransaction;
48
- url: string;
49
67
  }): Promise<{
50
68
  feePayer: `0x${string}`;
51
69
  feeToken: TempoAddress.Address;
@@ -4,6 +4,7 @@ import { decodeFunctionData, encodeFunctionData, maxUint256, toHex } from 'viem'
4
4
  import { Abis, Addresses, Transaction } from 'viem/tempo';
5
5
  import * as TempoAddress_internal from './address.js';
6
6
  import * as defaults from './defaults.js';
7
+ import { defaultFeeTokens } from './fee-token.js';
7
8
  import * as Selectors from './selectors.js';
8
9
  /** Returns true if the serialized transaction has a Tempo envelope prefix. */
9
10
  export function isTempoTransaction(serialized) {
@@ -58,20 +59,9 @@ const supportedTransactionKeys = new Set([
58
59
  ...rejectedTransactionKeys,
59
60
  ...rewrittenTransactionKeys,
60
61
  ]);
61
- function pushAllowedFeeToken(tokens, token) {
62
- if (!token)
63
- return;
64
- const normalized = token;
65
- if (tokens.some((existing) => TempoAddress_internal.isEqual(existing, normalized)))
66
- return;
67
- tokens.push(normalized);
68
- }
69
62
  /** Returns fee tokens that mppx allows sponsored transactions to charge. */
70
63
  export function defaultAllowedFeeTokens(chainId) {
71
- const tokens = [];
72
- pushAllowedFeeToken(tokens, defaults.tokens.pathUsd);
73
- pushAllowedFeeToken(tokens, defaults.currency[chainId]);
74
- return tokens;
64
+ return defaultFeeTokens(chainId);
75
65
  }
76
66
  /** Rejects a sponsored fee token outside the server's allowlist. */
77
67
  export function assertAllowedFeeToken(transaction, allowedFeeTokens) {
@@ -116,8 +106,8 @@ function hostedFeePayerRequest(transaction) {
116
106
  };
117
107
  }
118
108
  /**
119
- * Co-signs a sender-signed partial sponsorship envelope using a hosted
120
- * fee-payer endpoint without letting the endpoint mutate sender-committed
109
+ * Co-signs a sender-signed partial sponsorship envelope through a hosted
110
+ * fee-payer transport without letting the endpoint mutate sender-committed
121
111
  * transaction fields.
122
112
  *
123
113
  * @returns The serialized co-signed transaction plus the sponsor's recovered
@@ -125,7 +115,7 @@ function hostedFeePayerRequest(transaction) {
125
115
  * simulate the exact transaction the sponsor broadcasts.
126
116
  */
127
117
  export async function fillHostedFeePayerTransaction(parameters) {
128
- const { allowedFeeTokens, challengeExpires, chainId, details, policy, transaction, url } = parameters;
118
+ const { allowedFeeTokens, challengeExpires, chainId, details, policy, request, transaction } = parameters;
129
119
  assertTransactionPolicy({
130
120
  challengeExpires,
131
121
  chainId,
@@ -133,22 +123,13 @@ export async function fillHostedFeePayerTransaction(parameters) {
133
123
  policy,
134
124
  transaction,
135
125
  });
136
- const response = await fetch(url, {
137
- body: JSON.stringify({
138
- id: 1,
139
- jsonrpc: '2.0',
140
- method: 'eth_fillTransaction',
141
- params: [hostedFeePayerRequest(transaction)],
142
- }, (_key, value) => (typeof value === 'bigint' ? toHex(value) : value)),
143
- headers: { 'content-type': 'application/json' },
144
- method: 'POST',
145
- });
146
- const payload = (await response.json().catch(async () => ({
147
- error: { message: await response.text() },
148
- })));
149
- const filled = payload.result?.tx;
150
- if (!response.ok || payload.error || !filled?.feePayerSignature)
151
- throw new FeePayerValidationError(payload.error?.message ?? 'hosted fee payer failed to sponsor transaction', {});
126
+ const result = (await request({
127
+ method: 'eth_fillTransaction',
128
+ params: [hostedFeePayerRequest(transaction)],
129
+ }));
130
+ const filled = result?.tx;
131
+ if (!filled?.feePayerSignature)
132
+ throw new FeePayerValidationError('hosted fee payer failed to sponsor transaction', {});
152
133
  if (typeof filled.feeToken !== 'string')
153
134
  throw new FeePayerValidationError('hosted fee payer did not return a feeToken', {});
154
135
  assertAllowedFeeToken({ feeToken: filled.feeToken }, allowedFeeTokens);
@@ -1,4 +1,6 @@
1
1
  import type { Address, Client } from 'viem';
2
+ /** Returns the stablecoins mppx supports for Tempo transaction fees. */
3
+ export declare function defaultFeeTokens(chainId: number | undefined): Address[];
2
4
  /**
3
5
  * Resolves a funded fee token from account, chain, and caller-supplied preferences.
4
6
  *
@@ -27,6 +27,13 @@ function getChainFeeToken(client) {
27
27
  const chainId = client.chain?.id;
28
28
  return chainId ? defaults.currency[chainId] : undefined;
29
29
  }
30
+ /** Returns the stablecoins mppx supports for Tempo transaction fees. */
31
+ export function defaultFeeTokens(chainId) {
32
+ const tokens = [];
33
+ pushUnique(tokens, defaults.tokens.pathUsd);
34
+ pushUnique(tokens, defaults.currency[chainId]);
35
+ return tokens;
36
+ }
30
37
  /**
31
38
  * Resolves a funded fee token from account, chain, and caller-supplied preferences.
32
39
  *
@@ -0,0 +1,12 @@
1
+ /** Configuration for a remote Tempo fee-payer service. */
2
+ export type Config = Readonly<{
3
+ headers?: Readonly<Record<string, string>> | undefined;
4
+ url: string;
5
+ }>;
6
+ /** Returns whether a value is remote fee-payer configuration. */
7
+ export declare function is(value: unknown): value is Config;
8
+ /** Normalizes remote fee-payer string and object inputs. */
9
+ export declare function from(value: unknown): Config | undefined;
10
+ /** Returns a cloned header record while reserving JSON content type for MPPX. */
11
+ export declare function resolveHeaders(config: Config): Record<string, string>;
12
+ //# sourceMappingURL=remote-fee-payer.d.ts.map
@@ -0,0 +1,17 @@
1
+ /** Returns whether a value is remote fee-payer configuration. */
2
+ export function is(value) {
3
+ return (typeof value === 'object' && value !== null && 'url' in value && typeof value.url === 'string');
4
+ }
5
+ /** Normalizes remote fee-payer string and object inputs. */
6
+ export function from(value) {
7
+ if (typeof value === 'string')
8
+ return { url: value };
9
+ if (is(value))
10
+ return value;
11
+ return undefined;
12
+ }
13
+ /** Returns a cloned header record while reserving JSON content type for MPPX. */
14
+ export function resolveHeaders(config) {
15
+ return Object.fromEntries(Object.entries(config.headers ?? {}).filter(([name]) => name.toLowerCase() !== 'content-type'));
16
+ }
17
+ //# sourceMappingURL=remote-fee-payer.js.map
@@ -65,7 +65,6 @@ export declare function session(parameters?: session.Parameters): Method.Client<
65
65
  credential: {
66
66
  payload: z.ZodMiniDiscriminatedUnion<[z.ZodMiniObject<{
67
67
  action: z.ZodMiniLiteral<"open">;
68
- authorizationSignature: z.ZodMiniOptional<z.ZodMiniString<string>>;
69
68
  authorizedSigner: z.ZodMiniOptional<z.ZodMiniString<string>>;
70
69
  channelId: z.ZodMiniString<string>;
71
70
  cumulativeAmount: z.ZodMiniString<string>;
@@ -82,18 +81,15 @@ export declare function session(parameters?: session.Parameters): Method.Client<
82
81
  type: z.ZodMiniLiteral<"transaction">;
83
82
  }, z.core.$strip>, z.ZodMiniObject<{
84
83
  action: z.ZodMiniLiteral<"voucher">;
85
- authorizationSignature: z.ZodMiniOptional<z.ZodMiniString<string>>;
86
84
  channelId: z.ZodMiniString<string>;
87
85
  cumulativeAmount: z.ZodMiniString<string>;
88
86
  descriptor: z.ZodMiniOptional<z.ZodMiniCustom<import("../../session/precompile/Protocol.js").ChannelDescriptor, import("../../session/precompile/Protocol.js").ChannelDescriptor>>;
89
87
  signature: z.ZodMiniString<string>;
90
88
  }, z.core.$strip>, z.ZodMiniObject<{
91
89
  action: z.ZodMiniLiteral<"close">;
92
- authorizationSignature: z.ZodMiniOptional<z.ZodMiniString<string>>;
93
90
  channelId: z.ZodMiniString<string>;
94
91
  cumulativeAmount: z.ZodMiniString<string>;
95
92
  descriptor: z.ZodMiniOptional<z.ZodMiniCustom<import("../../session/precompile/Protocol.js").ChannelDescriptor, import("../../session/precompile/Protocol.js").ChannelDescriptor>>;
96
- refundSignature: z.ZodMiniOptional<z.ZodMiniString<string>>;
97
93
  signature: z.ZodMiniString<string>;
98
94
  }, z.core.$strip>], "action">;
99
95
  };
@@ -106,7 +102,6 @@ export declare function session(parameters?: session.Parameters): Method.Client<
106
102
  escrowContract: z.ZodMiniOptional<z.ZodMiniString<string>>;
107
103
  feePayer: z.ZodMiniOptional<z.ZodMiniPipe<z.ZodMiniUnion<readonly [z.ZodMiniBoolean<boolean>, z.ZodMiniCustom<viem_Account, viem_Account>]>, z.ZodMiniTransform<boolean, boolean | viem_Account>>>;
108
104
  feeToken: z.ZodMiniOptional<z.ZodMiniString<string>>;
109
- machineTokenEnabled: z.ZodMiniOptional<z.ZodMiniBoolean<boolean>>;
110
105
  minVoucherDelta: z.ZodMiniOptional<z.ZodMiniString<string>>;
111
106
  operator: z.ZodMiniOptional<z.ZodMiniString<string>>;
112
107
  recipient: z.ZodMiniOptional<z.ZodMiniString<string>>;
@@ -130,7 +125,6 @@ export declare function session(parameters?: session.Parameters): Method.Client<
130
125
  chainId?: number | undefined;
131
126
  feePayer?: boolean | undefined;
132
127
  feeToken?: string | undefined;
133
- machineTokenEnabled?: boolean | undefined;
134
128
  operator?: string | undefined;
135
129
  sessionProtocol?: "v1" | "v2" | undefined;
136
130
  sessionSnapshot?: import("../../session/Snapshot.js").SessionSnapshot | undefined;
@@ -144,7 +138,6 @@ export declare function session(parameters?: session.Parameters): Method.Client<
144
138
  escrowContract?: string | undefined;
145
139
  feePayer?: boolean | undefined;
146
140
  feeToken?: string | undefined;
147
- machineTokenEnabled?: boolean | undefined;
148
141
  minVoucherDelta?: string | undefined;
149
142
  operator?: string | undefined;
150
143
  recipient?: string | undefined;
@@ -45,8 +45,6 @@ export declare namespace charge {
45
45
  } | undefined;
46
46
  };
47
47
  type Parameters = {
48
- /** Enables first-party machine-token settlement for supported Tempo charges. */
49
- machineTokenEnabled?: boolean | undefined;
50
48
  /** Render payment page when Accept header is text/html (e.g. in browsers) */
51
49
  html?: boolean | Html.Config | undefined;
52
50
  /**
@@ -101,7 +99,6 @@ export declare namespace charge {
101
99
  * relay broadcasts pull credentials, while it recognizes a push
102
100
  * credential as already broadcast and returns its receipt without sending
103
101
  * it again.
104
- *
105
102
  */
106
103
  relay?: RelayOptions | undefined;
107
104
  /**