mppx 0.1.1 → 0.2.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 (221) hide show
  1. package/dist/Challenge.d.ts +18 -18
  2. package/dist/Challenge.d.ts.map +1 -1
  3. package/dist/Challenge.js +8 -8
  4. package/dist/Challenge.js.map +1 -1
  5. package/dist/Errors.d.ts +58 -8
  6. package/dist/Errors.d.ts.map +1 -1
  7. package/dist/Errors.js +51 -9
  8. package/dist/Errors.js.map +1 -1
  9. package/dist/Method.d.ts +154 -0
  10. package/dist/Method.d.ts.map +1 -0
  11. package/dist/Method.js +81 -0
  12. package/dist/Method.js.map +1 -0
  13. package/dist/PaymentRequest.d.ts +5 -5
  14. package/dist/PaymentRequest.d.ts.map +1 -1
  15. package/dist/PaymentRequest.js +11 -6
  16. package/dist/PaymentRequest.js.map +1 -1
  17. package/dist/cli.js +67 -18
  18. package/dist/cli.js.map +1 -1
  19. package/dist/client/Methods.d.ts +2 -2
  20. package/dist/client/Methods.d.ts.map +1 -1
  21. package/dist/client/Methods.js +2 -2
  22. package/dist/client/Methods.js.map +1 -1
  23. package/dist/client/Mppx.d.ts +7 -7
  24. package/dist/client/Mppx.d.ts.map +1 -1
  25. package/dist/client/Mppx.js +3 -3
  26. package/dist/client/Mppx.js.map +1 -1
  27. package/dist/client/internal/Fetch.d.ts +10 -10
  28. package/dist/client/internal/Fetch.d.ts.map +1 -1
  29. package/dist/client/internal/Fetch.js +2 -2
  30. package/dist/client/internal/Fetch.js.map +1 -1
  31. package/dist/index.d.ts +1 -2
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +1 -2
  34. package/dist/index.js.map +1 -1
  35. package/dist/mcp-sdk/client/McpClient.d.ts +6 -6
  36. package/dist/mcp-sdk/client/McpClient.d.ts.map +1 -1
  37. package/dist/mcp-sdk/client/McpClient.js +4 -4
  38. package/dist/mcp-sdk/client/McpClient.js.map +1 -1
  39. package/dist/middlewares/elysia.d.ts +1 -1
  40. package/dist/middlewares/express.d.ts +1 -1
  41. package/dist/middlewares/hono.d.ts +1 -1
  42. package/dist/middlewares/internal/mppx.d.ts +7 -7
  43. package/dist/middlewares/internal/mppx.d.ts.map +1 -1
  44. package/dist/middlewares/internal/mppx.js +5 -5
  45. package/dist/middlewares/internal/mppx.js.map +1 -1
  46. package/dist/middlewares/nextjs.d.ts +1 -1
  47. package/dist/proxy/Service.js +2 -2
  48. package/dist/proxy/Service.js.map +1 -1
  49. package/dist/server/Methods.d.ts +2 -2
  50. package/dist/server/Methods.d.ts.map +1 -1
  51. package/dist/server/Methods.js +2 -2
  52. package/dist/server/Methods.js.map +1 -1
  53. package/dist/server/Mppx.d.ts +17 -17
  54. package/dist/server/Mppx.d.ts.map +1 -1
  55. package/dist/server/Mppx.js +9 -9
  56. package/dist/server/Mppx.js.map +1 -1
  57. package/dist/stripe/{Intents.d.ts → Methods.d.ts} +22 -22
  58. package/dist/stripe/Methods.d.ts.map +1 -0
  59. package/dist/stripe/Methods.js +42 -0
  60. package/dist/stripe/Methods.js.map +1 -0
  61. package/dist/stripe/client/Charge.d.ts +40 -27
  62. package/dist/stripe/client/Charge.d.ts.map +1 -1
  63. package/dist/stripe/client/Charge.js +15 -7
  64. package/dist/stripe/client/Charge.js.map +1 -1
  65. package/dist/stripe/client/{MethodIntents.d.ts → Methods.d.ts} +24 -23
  66. package/dist/stripe/client/Methods.d.ts.map +1 -0
  67. package/dist/stripe/client/{MethodIntents.js → Methods.js} +3 -3
  68. package/dist/stripe/client/Methods.js.map +1 -0
  69. package/dist/stripe/client/index.d.ts +1 -1
  70. package/dist/stripe/client/index.d.ts.map +1 -1
  71. package/dist/stripe/client/index.js +1 -1
  72. package/dist/stripe/client/index.js.map +1 -1
  73. package/dist/stripe/index.d.ts +1 -1
  74. package/dist/stripe/index.d.ts.map +1 -1
  75. package/dist/stripe/index.js +1 -1
  76. package/dist/stripe/index.js.map +1 -1
  77. package/dist/stripe/internal/types.d.ts +25 -0
  78. package/dist/stripe/internal/types.d.ts.map +1 -0
  79. package/dist/stripe/internal/types.js +2 -0
  80. package/dist/stripe/internal/types.js.map +1 -0
  81. package/dist/stripe/server/Charge.d.ts +47 -28
  82. package/dist/stripe/server/Charge.d.ts.map +1 -1
  83. package/dist/stripe/server/Charge.js +90 -32
  84. package/dist/stripe/server/Charge.js.map +1 -1
  85. package/dist/stripe/server/{MethodIntents.d.ts → Methods.d.ts} +24 -23
  86. package/dist/stripe/server/Methods.d.ts.map +1 -0
  87. package/dist/stripe/server/{MethodIntents.js → Methods.js} +3 -3
  88. package/dist/stripe/server/Methods.js.map +1 -0
  89. package/dist/stripe/server/index.d.ts +1 -1
  90. package/dist/stripe/server/index.d.ts.map +1 -1
  91. package/dist/stripe/server/index.js +1 -1
  92. package/dist/stripe/server/index.js.map +1 -1
  93. package/dist/tempo/{Intents.d.ts → Methods.d.ts} +72 -69
  94. package/dist/tempo/Methods.d.ts.map +1 -0
  95. package/dist/tempo/Methods.js +118 -0
  96. package/dist/tempo/Methods.js.map +1 -0
  97. package/dist/tempo/client/ChannelOps.d.ts +1 -1
  98. package/dist/tempo/client/ChannelOps.js +1 -1
  99. package/dist/tempo/client/Charge.d.ts +25 -25
  100. package/dist/tempo/client/Charge.d.ts.map +1 -1
  101. package/dist/tempo/client/Charge.js +3 -3
  102. package/dist/tempo/client/Charge.js.map +1 -1
  103. package/dist/tempo/client/{MethodIntents.d.ts → Methods.d.ts} +74 -70
  104. package/dist/tempo/client/Methods.d.ts.map +1 -0
  105. package/dist/tempo/client/{MethodIntents.js → Methods.js} +3 -3
  106. package/dist/tempo/client/Methods.js.map +1 -0
  107. package/dist/tempo/client/Session.d.ts +49 -45
  108. package/dist/tempo/client/Session.d.ts.map +1 -1
  109. package/dist/tempo/client/Session.js +4 -4
  110. package/dist/tempo/client/Session.js.map +1 -1
  111. package/dist/tempo/client/SessionManager.d.ts +1 -1
  112. package/dist/tempo/client/SessionManager.js +1 -1
  113. package/dist/tempo/client/index.d.ts +1 -1
  114. package/dist/tempo/client/index.d.ts.map +1 -1
  115. package/dist/tempo/client/index.js +1 -1
  116. package/dist/tempo/client/index.js.map +1 -1
  117. package/dist/tempo/index.d.ts +1 -1
  118. package/dist/tempo/index.d.ts.map +1 -1
  119. package/dist/tempo/index.js +1 -1
  120. package/dist/tempo/index.js.map +1 -1
  121. package/dist/tempo/server/Charge.d.ts +27 -27
  122. package/dist/tempo/server/Charge.d.ts.map +1 -1
  123. package/dist/tempo/server/Charge.js +3 -3
  124. package/dist/tempo/server/Charge.js.map +1 -1
  125. package/dist/tempo/server/{MethodIntents.d.ts → Methods.d.ts} +73 -69
  126. package/dist/tempo/server/Methods.d.ts.map +1 -0
  127. package/dist/tempo/server/{MethodIntents.js → Methods.js} +4 -4
  128. package/dist/tempo/server/Methods.js.map +1 -0
  129. package/dist/tempo/server/Session.d.ts +51 -47
  130. package/dist/tempo/server/Session.d.ts.map +1 -1
  131. package/dist/tempo/server/Session.js +4 -4
  132. package/dist/tempo/server/Session.js.map +1 -1
  133. package/dist/tempo/server/index.d.ts +6 -0
  134. package/dist/tempo/server/index.d.ts.map +1 -0
  135. package/dist/tempo/server/index.js +6 -0
  136. package/dist/tempo/server/index.js.map +1 -0
  137. package/package.json +2 -1
  138. package/src/Challenge.test-d.ts +3 -3
  139. package/src/Challenge.test.ts +7 -7
  140. package/src/Challenge.ts +34 -34
  141. package/src/Errors.test.ts +75 -21
  142. package/src/Errors.ts +74 -9
  143. package/src/Method.test.ts +76 -0
  144. package/src/Method.ts +228 -0
  145. package/src/PaymentRequest.test.ts +5 -5
  146. package/src/PaymentRequest.ts +15 -10
  147. package/src/cli.test.ts +12 -22
  148. package/src/cli.ts +74 -21
  149. package/src/client/Methods.ts +2 -2
  150. package/src/client/Mppx.test-d.ts +6 -6
  151. package/src/client/Mppx.test.ts +26 -22
  152. package/src/client/Mppx.ts +10 -10
  153. package/src/client/Transport.test.ts +6 -6
  154. package/src/client/internal/Fetch.ts +21 -24
  155. package/src/index.ts +1 -2
  156. package/src/mcp-sdk/client/McpClient.test.ts +1 -1
  157. package/src/mcp-sdk/client/McpClient.ts +11 -13
  158. package/src/middlewares/elysia.ts +1 -1
  159. package/src/middlewares/express.ts +1 -1
  160. package/src/middlewares/hono.ts +1 -1
  161. package/src/middlewares/internal/mppx.ts +10 -10
  162. package/src/middlewares/nextjs.ts +1 -1
  163. package/src/proxy/Service.ts +2 -2
  164. package/src/server/Methods.ts +2 -2
  165. package/src/server/Mppx.test-d.ts +27 -29
  166. package/src/server/Mppx.test.ts +23 -19
  167. package/src/server/Mppx.ts +43 -43
  168. package/src/server/Transport.test.ts +8 -8
  169. package/src/stripe/{Intents.test.ts → Methods.test.ts} +12 -12
  170. package/src/stripe/Methods.ts +45 -0
  171. package/src/stripe/client/Charge.test.ts +189 -0
  172. package/src/stripe/client/Charge.ts +29 -16
  173. package/src/stripe/client/{MethodIntents.ts → Methods.ts} +2 -2
  174. package/src/stripe/client/index.ts +1 -1
  175. package/src/stripe/index.ts +1 -1
  176. package/src/stripe/internal/types.ts +22 -0
  177. package/src/stripe/server/Charge.test.ts +241 -0
  178. package/src/stripe/server/Charge.ts +124 -38
  179. package/src/stripe/server/{MethodIntents.ts → Methods.ts} +2 -2
  180. package/src/stripe/server/index.ts +1 -1
  181. package/src/tempo/{Intents.test.ts → Methods.test.ts} +15 -15
  182. package/src/tempo/{Intents.ts → Methods.ts} +77 -22
  183. package/src/tempo/client/ChannelOps.ts +1 -1
  184. package/src/tempo/client/Charge.ts +3 -3
  185. package/src/tempo/client/{MethodIntents.ts → Methods.ts} +2 -2
  186. package/src/tempo/client/Session.ts +4 -4
  187. package/src/tempo/client/SessionManager.ts +1 -1
  188. package/src/tempo/client/index.ts +1 -1
  189. package/src/tempo/index.ts +1 -1
  190. package/src/tempo/server/Charge.ts +4 -7
  191. package/src/tempo/server/{MethodIntents.ts → Methods.ts} +3 -3
  192. package/src/tempo/server/Session.test.ts +4 -7
  193. package/src/tempo/server/Session.ts +6 -6
  194. package/src/tempo/server/index.ts +1 -1
  195. package/dist/Intent.d.ts +0 -101
  196. package/dist/Intent.d.ts.map +0 -1
  197. package/dist/Intent.js +0 -83
  198. package/dist/Intent.js.map +0 -1
  199. package/dist/MethodIntent.d.ts +0 -225
  200. package/dist/MethodIntent.d.ts.map +0 -1
  201. package/dist/MethodIntent.js +0 -156
  202. package/dist/MethodIntent.js.map +0 -1
  203. package/dist/stripe/Intents.d.ts.map +0 -1
  204. package/dist/stripe/Intents.js +0 -27
  205. package/dist/stripe/Intents.js.map +0 -1
  206. package/dist/stripe/client/MethodIntents.d.ts.map +0 -1
  207. package/dist/stripe/client/MethodIntents.js.map +0 -1
  208. package/dist/stripe/server/MethodIntents.d.ts.map +0 -1
  209. package/dist/stripe/server/MethodIntents.js.map +0 -1
  210. package/dist/tempo/Intents.d.ts.map +0 -1
  211. package/dist/tempo/Intents.js +0 -81
  212. package/dist/tempo/Intents.js.map +0 -1
  213. package/dist/tempo/client/MethodIntents.d.ts.map +0 -1
  214. package/dist/tempo/client/MethodIntents.js.map +0 -1
  215. package/dist/tempo/server/MethodIntents.d.ts.map +0 -1
  216. package/dist/tempo/server/MethodIntents.js.map +0 -1
  217. package/src/Intent.test.ts +0 -180
  218. package/src/Intent.ts +0 -109
  219. package/src/MethodIntent.test.ts +0 -303
  220. package/src/MethodIntent.ts +0 -388
  221. package/src/stripe/Intents.ts +0 -27
@@ -1,6 +1,7 @@
1
1
  import type { Account } from 'viem'
2
- import * as Intent from '../Intent.js'
3
- import * as MethodIntent from '../MethodIntent.js'
2
+ import { parseUnits } from 'viem'
3
+ import * as Expires from '../Expires.js'
4
+ import * as Method from '../Method.js'
4
5
  import * as z from '../zod.js'
5
6
 
6
7
  /**
@@ -8,8 +9,9 @@ import * as z from '../zod.js'
8
9
  *
9
10
  * @see https://github.com/tempoxyz/payment-auth-spec/blob/main/specs/methods/tempo/draft-tempo-charge-00.md
10
11
  */
11
- export const charge = MethodIntent.fromIntent(Intent.charge, {
12
- method: 'tempo',
12
+ export const charge = Method.from({
13
+ name: 'tempo',
14
+ intent: 'charge',
13
15
  schema: {
14
16
  credential: {
15
17
  payload: z.discriminatedUnion('type', [
@@ -17,9 +19,15 @@ export const charge = MethodIntent.fromIntent(Intent.charge, {
17
19
  z.object({ signature: z.signature(), type: z.literal('transaction') }),
18
20
  ]),
19
21
  },
20
- request: {
21
- methodDetails: z.object({
22
+ request: z.pipe(
23
+ z.object({
24
+ amount: z.amount(),
22
25
  chainId: z.optional(z.number()),
26
+ currency: z.string(),
27
+ decimals: z.number(),
28
+ description: z.optional(z.string()),
29
+ expires: z._default(z.datetime(), () => Expires.minutes(5)),
30
+ externalId: z.optional(z.string()),
23
31
  feePayer: z.optional(
24
32
  z.pipe(
25
33
  z.union([z.boolean(), z.custom<Account>()]),
@@ -27,9 +35,22 @@ export const charge = MethodIntent.fromIntent(Intent.charge, {
27
35
  ),
28
36
  ),
29
37
  memo: z.optional(z.hash()),
38
+ recipient: z.optional(z.string()),
30
39
  }),
31
- requires: ['decimals', 'recipient'],
32
- },
40
+ z.transform(({ amount, chainId, decimals, feePayer, memo, ...rest }) => ({
41
+ ...rest,
42
+ amount: parseUnits(amount, decimals).toString(),
43
+ ...(chainId !== undefined || feePayer !== undefined || memo !== undefined
44
+ ? {
45
+ methodDetails: {
46
+ ...(chainId !== undefined && { chainId }),
47
+ ...(feePayer !== undefined && { feePayer }),
48
+ ...(memo !== undefined && { memo }),
49
+ },
50
+ }
51
+ : {}),
52
+ })),
53
+ ),
33
54
  },
34
55
  })
35
56
 
@@ -39,26 +60,27 @@ export const charge = MethodIntent.fromIntent(Intent.charge, {
39
60
  * Uses cumulative vouchers over a payment channel. Credential payloads
40
61
  * are a discriminated union on `action`: open, topUp, voucher, close.
41
62
  */
42
- export const session = MethodIntent.fromIntent(Intent.session, {
43
- method: 'tempo',
63
+ export const session = Method.from({
64
+ name: 'tempo',
65
+ intent: 'session',
44
66
  schema: {
45
67
  credential: {
46
68
  payload: z.discriminatedUnion('action', [
47
69
  z.object({
48
70
  action: z.literal('open'),
49
- type: z.literal('transaction'),
50
- channelId: z.hash(),
51
- transaction: z.signature(),
52
71
  authorizedSigner: z.optional(z.string()),
72
+ channelId: z.hash(),
53
73
  cumulativeAmount: z.amount(),
54
74
  signature: z.signature(),
75
+ transaction: z.signature(),
76
+ type: z.literal('transaction'),
55
77
  }),
56
78
  z.object({
57
79
  action: z.literal('topUp'),
58
- type: z.literal('transaction'),
80
+ additionalDeposit: z.amount(),
59
81
  channelId: z.hash(),
60
82
  transaction: z.signature(),
61
- additionalDeposit: z.amount(),
83
+ type: z.literal('transaction'),
62
84
  }),
63
85
  z.object({
64
86
  action: z.literal('voucher'),
@@ -74,20 +96,53 @@ export const session = MethodIntent.fromIntent(Intent.session, {
74
96
  }),
75
97
  ]),
76
98
  },
77
- request: {
78
- methodDetails: z.object({
79
- escrowContract: z.string(),
80
- channelId: z.optional(z.hash()),
81
- minVoucherDelta: z.optional(z.amount()),
99
+ request: z.pipe(
100
+ z.object({
101
+ amount: z.amount(),
82
102
  chainId: z.optional(z.number()),
103
+ channelId: z.optional(z.hash()),
104
+ currency: z.string(),
105
+ decimals: z.number(),
106
+ escrowContract: z.optional(z.string()),
83
107
  feePayer: z.optional(
84
108
  z.pipe(
85
109
  z.union([z.boolean(), z.custom<Account>()]),
86
110
  z.transform((v): boolean => (typeof v === 'object' ? true : v)),
87
111
  ),
88
112
  ),
113
+ minVoucherDelta: z.optional(z.amount()),
114
+ recipient: z.optional(z.string()),
115
+ suggestedDeposit: z.optional(z.amount()),
116
+ unitType: z.string(),
89
117
  }),
90
- requires: ['decimals', 'recipient', 'currency'],
91
- },
118
+ z.transform(
119
+ ({
120
+ amount,
121
+ chainId,
122
+ channelId,
123
+ decimals,
124
+ escrowContract,
125
+ feePayer,
126
+ minVoucherDelta,
127
+ suggestedDeposit,
128
+ ...rest
129
+ }) => ({
130
+ ...rest,
131
+ amount: parseUnits(amount, decimals).toString(),
132
+ ...(suggestedDeposit
133
+ ? {
134
+ suggestedDeposit: parseUnits(suggestedDeposit, decimals).toString(),
135
+ }
136
+ : {}),
137
+ methodDetails: {
138
+ escrowContract,
139
+ ...(channelId !== undefined && { channelId }),
140
+ ...(minVoucherDelta !== undefined && { minVoucherDelta }),
141
+ ...(chainId !== undefined && { chainId }),
142
+ ...(feePayer !== undefined && { feePayer }),
143
+ },
144
+ }),
145
+ ),
146
+ ),
92
147
  },
93
148
  })
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Shared client-side channel operations.
3
3
  *
4
- * Provides the low-level helpers that both `session()` (MethodIntent plugin)
4
+ * Provides the low-level helpers that both `session()`
5
5
  * and `sessionManager()` (orchestrator) rely on: escrow resolution, channel
6
6
  * ID computation, on-chain open/voucher/close payload construction, channel
7
7
  * recovery from on-chain state, and credential serialization.
@@ -3,13 +3,13 @@ import { prepareTransactionRequest, signTransaction } from 'viem/actions'
3
3
  import { tempo as tempo_chain } from 'viem/chains'
4
4
  import { Actions } from 'viem/tempo'
5
5
  import * as Credential from '../../Credential.js'
6
- import * as MethodIntent from '../../MethodIntent.js'
6
+ import * as Method from '../../Method.js'
7
7
  import * as Account from '../../viem/Account.js'
8
8
  import * as Client from '../../viem/Client.js'
9
9
  import * as z from '../../zod.js'
10
10
  import * as Attribution from '../Attribution.js'
11
- import * as Intents from '../Intents.js'
12
11
  import * as defaults from '../internal/defaults.js'
12
+ import * as Methods from '../Methods.js'
13
13
 
14
14
  /**
15
15
  * Creates a Tempo charge method intent for usage on the client.
@@ -33,7 +33,7 @@ export function charge(parameters: charge.Parameters = {}) {
33
33
  })
34
34
  const getAccount = Account.getResolver({ account: parameters.account })
35
35
 
36
- return MethodIntent.toClient(Intents.charge, {
36
+ return Method.toClient(Methods.charge, {
37
37
  context: z.object({
38
38
  account: z.optional(z.custom<Account.getResolver.Parameters['account']>()),
39
39
  }),
@@ -3,7 +3,7 @@ import { session as sessionIntent_ } from './Session.js'
3
3
  import { sessionManager as session_ } from './SessionManager.js'
4
4
 
5
5
  /**
6
- * Creates both Tempo `charge` and `session` client method intents from shared parameters.
6
+ * Creates both Tempo `charge` and `session` client methods from shared parameters.
7
7
  *
8
8
  * @example
9
9
  * ```ts
@@ -21,7 +21,7 @@ export function tempo(parameters: tempo.Parameters = {}) {
21
21
  export namespace tempo {
22
22
  export type Parameters = charge_.Parameters & sessionIntent_.Parameters
23
23
 
24
- /** Creates a Tempo `charge` client method intent for one-time TIP-20 token transfers. */
24
+ /** Creates a Tempo `charge` client method for one-time TIP-20 token transfers. */
25
25
  export const charge = charge_
26
26
  /** Creates a client-side streaming session for managing payment channels. */
27
27
  export const session = session_
@@ -2,12 +2,12 @@ import type { Hex } from 'ox'
2
2
  import { type Address, parseUnits, type Account as viem_Account } from 'viem'
3
3
  import { tempo as tempo_chain } from 'viem/chains'
4
4
  import type * as Challenge from '../../Challenge.js'
5
- import * as MethodIntent from '../../MethodIntent.js'
5
+ import * as Method from '../../Method.js'
6
6
  import * as Account from '../../viem/Account.js'
7
7
  import * as Client from '../../viem/Client.js'
8
8
  import * as z from '../../zod.js'
9
- import * as Intents from '../Intents.js'
10
9
  import * as defaults from '../internal/defaults.js'
10
+ import * as Methods from '../Methods.js'
11
11
  import type { StreamCredentialPayload } from '../stream/Types.js'
12
12
  import { signVoucher } from '../stream/Voucher.js'
13
13
  import {
@@ -35,7 +35,7 @@ export const streamContextSchema = z.object({
35
35
  export type StreamContext = z.infer<typeof streamContextSchema>
36
36
 
37
37
  /**
38
- * Creates a session payment MethodIntent plugin for use with `Mppx.create()`.
38
+ * Creates a session payment method for use with `Mppx.create()`.
39
39
  *
40
40
  * Supports both auto mode (set `deposit` to manage channels automatically)
41
41
  * and manual mode (pass `context.action` to control each step).
@@ -330,7 +330,7 @@ export function session(parameters: session.Parameters = {}) {
330
330
  return serializeCredential(challenge, payload, chainId, account)
331
331
  }
332
332
 
333
- return MethodIntent.toClient(Intents.session, {
333
+ return Method.toClient(Methods.session, {
334
334
  context: streamContextSchema,
335
335
 
336
336
  async createCredential({ challenge, context }) {
@@ -38,7 +38,7 @@ export type PaymentResponse = Response & {
38
38
  * Creates a session manager that handles the full client payment lifecycle:
39
39
  * channel open, incremental vouchers, SSE streaming, and channel close.
40
40
  *
41
- * Internally delegates to the `session()` MethodIntent plugin for all
41
+ * Internally delegates to the `session()` method for all
42
42
  * channel state management and credential creation, and to `Fetch.from`
43
43
  * for the 402 challenge/retry flow.
44
44
  *
@@ -1,5 +1,5 @@
1
1
  export { charge } from './Charge.js'
2
- export { tempo } from './MethodIntents.js'
2
+ export { tempo } from './Methods.js'
3
3
  export { session } from './Session.js'
4
4
  export type { PaymentResponse, SessionManager } from './SessionManager.js'
5
5
  export { sessionManager } from './SessionManager.js'
@@ -1,2 +1,2 @@
1
- export * as MethodIntents from './Intents.js'
1
+ export * as Methods from './Methods.js'
2
2
  export * as Stream from './stream/index.js'
@@ -10,12 +10,12 @@ import { tempo as tempo_chain } from 'viem/chains'
10
10
  import { Abis, Transaction } from 'viem/tempo'
11
11
  import { PaymentExpiredError } from '../../Errors.js'
12
12
  import type { LooseOmit } from '../../internal/types.js'
13
- import * as MethodIntent from '../../MethodIntent.js'
13
+ import * as Method from '../../Method.js'
14
14
  import * as Client from '../../viem/Client.js'
15
- import * as Intents from '../Intents.js'
16
15
  import * as Account from '../internal/account.js'
17
16
  import * as defaults from '../internal/defaults.js'
18
17
  import type * as types from '../internal/types.js'
18
+ import * as Methods from '../Methods.js'
19
19
 
20
20
  const transferSelector = /*#__PURE__*/ toFunctionSelector(
21
21
  'function transfer(address to, uint256 amount)',
@@ -56,7 +56,7 @@ export function charge<const parameters extends charge.Parameters>(
56
56
  })
57
57
 
58
58
  type Defaults = charge.DeriveDefaults<parameters>
59
- return MethodIntent.toServer<typeof Intents.charge, Defaults>(Intents.charge, {
59
+ return Method.toServer<typeof Methods.charge, Defaults>(Methods.charge, {
60
60
  defaults: {
61
61
  amount,
62
62
  currency,
@@ -265,10 +265,7 @@ export function charge<const parameters extends charge.Parameters>(
265
265
  }
266
266
 
267
267
  export declare namespace charge {
268
- type Defaults = LooseOmit<
269
- MethodIntent.RequestDefaults<typeof Intents.charge>,
270
- 'feePayer' | 'recipient'
271
- >
268
+ type Defaults = LooseOmit<Method.RequestDefaults<typeof Methods.charge>, 'feePayer' | 'recipient'>
272
269
 
273
270
  type Parameters = {
274
271
  /** Testnet mode. */
@@ -2,7 +2,7 @@ import { charge as charge_ } from './Charge.js'
2
2
  import { session as session_, settle as settle_ } from './Session.js'
3
3
 
4
4
  /**
5
- * Creates both Tempo `charge` and `session` method intents from shared parameters.
5
+ * Creates both Tempo `charge` and `session` methods from shared parameters.
6
6
  *
7
7
  * @example
8
8
  * ```ts
@@ -20,9 +20,9 @@ export function tempo<const parameters extends tempo.Parameters>(parameters?: pa
20
20
  export namespace tempo {
21
21
  export type Parameters = charge_.Parameters & session_.Parameters
22
22
 
23
- /** Creates a Tempo `charge` method intent for one-time TIP-20 token transfers. */
23
+ /** Creates a Tempo `charge` method for one-time TIP-20 token transfers. */
24
24
  export const charge = charge_
25
- /** Creates a Tempo `session` method intent for session-based TIP-20 token payments. */
25
+ /** Creates a Tempo `session` method for session-based TIP-20 token payments. */
26
26
  export const session = session_
27
27
  /** One-shot settle: reads highest voucher from storage and submits on-chain. */
28
28
  export const settle = settle_
@@ -1,3 +1,4 @@
1
+ import type { Challenge, z } from 'mppx'
1
2
  import { Mppx as Mppx_server, tempo as tempo_server } from 'mppx/server'
2
3
  import { type Address, createClient, type Hex } from 'viem'
3
4
  import { Addresses } from 'viem/tempo'
@@ -16,6 +17,7 @@ import {
16
17
  InvalidSignatureError,
17
18
  } from '../../Errors.js'
18
19
  import * as Store from '../../Store.js'
20
+ import type * as Methods from '../Methods.js'
19
21
  import * as ChannelStore from '../stream/ChannelStore.js'
20
22
  import type { StreamReceipt } from '../stream/Types.js'
21
23
  import { signVoucher } from '../stream/Voucher.js'
@@ -1295,18 +1297,13 @@ function makeChallenge(opts: { id?: string; channelId: Hex }) {
1295
1297
  amount: '1000000',
1296
1298
  unitType: 'token',
1297
1299
  currency: currency as string,
1298
- decimals: 6,
1299
1300
  recipient: recipient as string,
1300
- suggestedDeposit: undefined as string | undefined,
1301
1301
  methodDetails: {
1302
1302
  escrowContract: escrowContract as string,
1303
- channelId: undefined as string | undefined,
1304
- minVoucherDelta: undefined as string | undefined,
1305
- chainId: chain.id as number | undefined,
1306
- feePayer: undefined as boolean | undefined,
1303
+ chainId: chain.id,
1307
1304
  },
1308
1305
  },
1309
- }
1306
+ } as Challenge.Challenge<z.output<typeof Methods.session.schema.request>, 'session', 'tempo'>
1310
1307
  }
1311
1308
 
1312
1309
  function makeRequest() {
@@ -30,13 +30,13 @@ import {
30
30
  } from '../../Errors.js'
31
31
  import type { Challenge, Credential } from '../../index.js'
32
32
  import type { LooseOmit } from '../../internal/types.js'
33
- import * as MethodIntent from '../../MethodIntent.js'
33
+ import * as Method from '../../Method.js'
34
34
  import * as Store from '../../Store.js'
35
35
  import * as Client from '../../viem/Client.js'
36
- import * as Intents from '../Intents.js'
37
36
  import * as Account from '../internal/account.js'
38
37
  import * as defaults from '../internal/defaults.js'
39
38
  import type * as types from '../internal/types.js'
39
+ import * as Methods from '../Methods.js'
40
40
  import {
41
41
  broadcastOpenTransaction,
42
42
  broadcastTopUpTransaction,
@@ -51,7 +51,7 @@ import type { SignedVoucher, StreamCredentialPayload, StreamReceipt } from '../s
51
51
  import { parseVoucherFromPayload, verifyVoucher } from '../stream/Voucher.js'
52
52
  import * as Transport from './internal/transport.js'
53
53
 
54
- /** Challenge methodDetails shape for stream intents. */
54
+ /** Challenge methodDetails shape for stream methods. */
55
55
  type StreamMethodDetails = {
56
56
  escrowContract: Address
57
57
  chainId: number
@@ -61,7 +61,7 @@ type StreamMethodDetails = {
61
61
  }
62
62
 
63
63
  /**
64
- * Creates a stream payment server using the mppx Method.toServer() pattern.
64
+ * Creates a stream payment server using the Method.toServer() pattern.
65
65
  *
66
66
  * @example
67
67
  * ```ts
@@ -110,7 +110,7 @@ export function session<const parameters extends session.Parameters>(p?: paramet
110
110
  : undefined
111
111
 
112
112
  type Defaults = session.DeriveDefaults<parameters>
113
- return MethodIntent.toServer<typeof Intents.session, Defaults, Transport>(Intents.session, {
113
+ return Method.toServer<typeof Methods.session, Defaults, Transport>(Methods.session, {
114
114
  defaults: {
115
115
  amount,
116
116
  currency,
@@ -266,7 +266,7 @@ export function session<const parameters extends session.Parameters>(p?: paramet
266
266
 
267
267
  export declare namespace session {
268
268
  type Defaults = LooseOmit<
269
- MethodIntent.RequestDefaults<typeof Intents.session>,
269
+ Method.RequestDefaults<typeof Methods.session>,
270
270
  'feePayer' | 'recipient'
271
271
  >
272
272
 
@@ -1,5 +1,5 @@
1
1
  export * as ChannelStore from '../stream/ChannelStore.js'
2
2
  export * as Sse from '../stream/Sse.js'
3
3
  export { charge } from './Charge.js'
4
- export { tempo } from './MethodIntents.js'
4
+ export { tempo } from './Methods.js'
5
5
  export { session, settle } from './Session.js'
package/dist/Intent.d.ts DELETED
@@ -1,101 +0,0 @@
1
- import * as z from './zod.js';
2
- /**
3
- * A payment intent.
4
- */
5
- export type Intent = {
6
- name: string;
7
- schema: {
8
- request: z.z.ZodMiniObject | z.z.ZodMiniPipe<z.z.ZodMiniObject>;
9
- };
10
- };
11
- /**
12
- * Creates an intent.
13
- *
14
- * @example
15
- * ```ts
16
- * import { z } from 'mppx'
17
- *
18
- * const charge = Intent.from({
19
- * name: 'charge',
20
- * schema: {
21
- * request: z.object({
22
- * amount: z.string(),
23
- * currency: z.string(),
24
- * recipient: z.optional(z.string()),
25
- * }),
26
- * },
27
- * })
28
- * ```
29
- */
30
- export declare function from<const intent extends Intent>(intent: intent): intent;
31
- /**
32
- * Charge intent for one-time immediate payments.
33
- *
34
- * @see https://github.com/tempoxyz/payment-auth-spec/blob/main/specs/intents/draft-payment-intent-charge-00.md
35
- */
36
- export declare const charge: {
37
- readonly name: "charge";
38
- readonly schema: {
39
- readonly request: z.ZodMiniPipe<z.ZodMiniObject<{
40
- amount: z.ZodMiniString<string>;
41
- currency: z.ZodMiniString<string>;
42
- decimals: z.ZodMiniNumber<number>;
43
- description: z.ZodMiniOptional<z.ZodMiniString<string>>;
44
- expires: z.ZodMiniDefault<z.ZodMiniString<string>>;
45
- externalId: z.ZodMiniOptional<z.ZodMiniString<string>>;
46
- recipient: z.ZodMiniOptional<z.ZodMiniString<string>>;
47
- }, z.core.$strip>, z.ZodMiniTransform<{
48
- amount: string;
49
- currency: string;
50
- expires: string;
51
- description?: string | undefined;
52
- externalId?: string | undefined;
53
- recipient?: string | undefined;
54
- }, {
55
- amount: string;
56
- currency: string;
57
- decimals: number;
58
- expires: string;
59
- description?: string | undefined;
60
- externalId?: string | undefined;
61
- recipient?: string | undefined;
62
- }>>;
63
- };
64
- };
65
- /**
66
- * Session intent for pay-as-you-go streaming payments.
67
- *
68
- * Uses cumulative vouchers over a payment channel for
69
- * incremental micropayments without per-request transactions.
70
- */
71
- export declare const session: {
72
- readonly name: "session";
73
- readonly schema: {
74
- readonly request: z.ZodMiniPipe<z.ZodMiniObject<{
75
- amount: z.ZodMiniString<string>;
76
- unitType: z.ZodMiniString<string>;
77
- currency: z.ZodMiniString<string>;
78
- decimals: z.ZodMiniNumber<number>;
79
- recipient: z.ZodMiniOptional<z.ZodMiniString<string>>;
80
- suggestedDeposit: z.ZodMiniOptional<z.ZodMiniString<string>>;
81
- }, z.core.$strip>, z.ZodMiniTransform<{
82
- suggestedDeposit?: string | undefined;
83
- amount: string;
84
- unitType: string;
85
- currency: string;
86
- recipient?: string | undefined;
87
- }, {
88
- amount: string;
89
- unitType: string;
90
- currency: string;
91
- decimals: number;
92
- recipient?: string | undefined;
93
- suggestedDeposit?: string | undefined;
94
- }>>;
95
- };
96
- };
97
- /** @internal Extracts shape from an intent's request schema, supporting both object and pipe. */
98
- export type ShapeOf<intent extends Intent> = intent['schema']['request'] extends z.z.ZodMiniObject ? intent['schema']['request']['shape'] : intent['schema']['request'] extends z.z.ZodMiniPipe<infer A> ? A extends z.z.ZodMiniObject ? A['shape'] : never : never;
99
- /** @internal Extracts the inner object from a pipe or returns the schema directly. */
100
- export declare function shapeOf(intent: Intent): Record<string, z.z.ZodMiniType>;
101
- //# sourceMappingURL=Intent.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Intent.d.ts","sourceRoot":"","sources":["../src/Intent.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,UAAU,CAAA;AAE7B;;GAEG;AACH,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,EAAE;QACN,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,aAAa,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,CAAA;KAChE,CAAA;CACF,CAAA;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,IAAI,CAAC,KAAK,CAAC,MAAM,SAAS,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAExE;AAED;;;;GAIG;AACH,eAAO,MAAM,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqBjB,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;CAqBlB,CAAA;AAEF,iGAAiG;AACjG,MAAM,MAAM,OAAO,CAAC,MAAM,SAAS,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,aAAa,GAC9F,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,GACpC,MAAM,CAAC,QAAQ,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,GAC1D,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,aAAa,GACzB,CAAC,CAAC,OAAO,CAAC,GACV,KAAK,GACP,KAAK,CAAA;AAEX,sFAAsF;AACtF,wBAAgB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAIvE"}
package/dist/Intent.js DELETED
@@ -1,83 +0,0 @@
1
- import { parseUnits } from 'viem';
2
- import * as Expires from './Expires.js';
3
- import * as z from './zod.js';
4
- /**
5
- * Creates an intent.
6
- *
7
- * @example
8
- * ```ts
9
- * import { z } from 'mppx'
10
- *
11
- * const charge = Intent.from({
12
- * name: 'charge',
13
- * schema: {
14
- * request: z.object({
15
- * amount: z.string(),
16
- * currency: z.string(),
17
- * recipient: z.optional(z.string()),
18
- * }),
19
- * },
20
- * })
21
- * ```
22
- */
23
- export function from(intent) {
24
- return intent;
25
- }
26
- /**
27
- * Charge intent for one-time immediate payments.
28
- *
29
- * @see https://github.com/tempoxyz/payment-auth-spec/blob/main/specs/intents/draft-payment-intent-charge-00.md
30
- */
31
- export const charge = from({
32
- name: 'charge',
33
- schema: {
34
- request: z.pipe(z.object({
35
- amount: z.amount(),
36
- currency: z.string(),
37
- decimals: z.number(),
38
- description: z.optional(z.string()),
39
- expires: z._default(z.datetime(), () => Expires.minutes(5)),
40
- externalId: z.optional(z.string()),
41
- recipient: z.optional(z.string()),
42
- }),
43
- // Note: Since the spec states we must have `amount` as a base unit, we
44
- // will transform the amount to decimal units based on `decimals`.
45
- z.transform(({ amount, decimals, ...rest }) => ({
46
- ...rest,
47
- amount: parseUnits(amount, decimals).toString(),
48
- }))),
49
- },
50
- });
51
- /**
52
- * Session intent for pay-as-you-go streaming payments.
53
- *
54
- * Uses cumulative vouchers over a payment channel for
55
- * incremental micropayments without per-request transactions.
56
- */
57
- export const session = from({
58
- name: 'session',
59
- schema: {
60
- request: z.pipe(z.object({
61
- amount: z.amount(),
62
- unitType: z.string(),
63
- currency: z.string(),
64
- decimals: z.number(),
65
- recipient: z.optional(z.string()),
66
- suggestedDeposit: z.optional(z.amount()),
67
- }), z.transform(({ amount, decimals, suggestedDeposit, ...rest }) => ({
68
- ...rest,
69
- amount: parseUnits(amount, decimals).toString(),
70
- ...(suggestedDeposit
71
- ? { suggestedDeposit: parseUnits(suggestedDeposit, decimals).toString() }
72
- : {}),
73
- }))),
74
- },
75
- });
76
- /** @internal Extracts the inner object from a pipe or returns the schema directly. */
77
- export function shapeOf(intent) {
78
- const { request } = intent.schema;
79
- if ('shape' in request)
80
- return request.shape;
81
- return request._zod.def.in.shape;
82
- }
83
- //# sourceMappingURL=Intent.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Intent.js","sourceRoot":"","sources":["../src/Intent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AACjC,OAAO,KAAK,OAAO,MAAM,cAAc,CAAA;AACvC,OAAO,KAAK,CAAC,MAAM,UAAU,CAAA;AAY7B;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,IAAI,CAA8B,MAAc;IAC9D,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAC;IACzB,IAAI,EAAE,QAAQ;IACd,MAAM,EAAE;QACN,OAAO,EAAE,CAAC,CAAC,IAAI,CACb,CAAC,CAAC,MAAM,CAAC;YACP,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;YAClB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;YACpB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;YACpB,WAAW,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;YACnC,OAAO,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;YAC3D,UAAU,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;YAClC,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;SAClC,CAAC;QACF,uEAAuE;QACvE,kEAAkE;QAClE,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;YAC9C,GAAG,IAAI;YACP,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE;SAChD,CAAC,CAAC,CACJ;KACF;CACF,CAAC,CAAA;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,IAAI,CAAC;IAC1B,IAAI,EAAE,SAAS;IACf,MAAM,EAAE;QACN,OAAO,EAAE,CAAC,CAAC,IAAI,CACb,CAAC,CAAC,MAAM,CAAC;YACP,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE;YAClB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;YACpB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;YACpB,QAAQ,EAAE,CAAC,CAAC,MAAM,EAAE;YACpB,SAAS,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;YACjC,gBAAgB,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;SACzC,CAAC,EACF,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,GAAG,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC;YAChE,GAAG,IAAI;YACP,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE;YAC/C,GAAG,CAAC,gBAAgB;gBAClB,CAAC,CAAC,EAAE,gBAAgB,EAAE,UAAU,CAAC,gBAAgB,EAAE,QAAQ,CAAC,CAAC,QAAQ,EAAE,EAAE;gBACzE,CAAC,CAAC,EAAE,CAAC;SACR,CAAC,CAAC,CACJ;KACF;CACF,CAAC,CAAA;AAWF,sFAAsF;AACtF,MAAM,UAAU,OAAO,CAAC,MAAc;IACpC,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,CAAA;IACjC,IAAI,OAAO,IAAI,OAAO;QAAE,OAAO,OAAO,CAAC,KAAwC,CAAA;IAC/E,OAAQ,OAAe,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAA;AAC3C,CAAC"}