@parallel-protocol/mpp-types 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # @parallel-protocol/mpp-types
2
+
3
+ MPP (Machine Payments Protocol, mpp.dev) **charge-intent** wire types for the
4
+ Parallel Protocol — the shared contract between the merchant SDK (which runs the
5
+ `Payment` HTTP auth-scheme dance) and the facilitator (which verifies + settles).
6
+
7
+ Conformant to `tempoxyz/mpp-specs` (draft-httpauth-payment-00 + intents/charge +
8
+ methods/evm). Two methods:
9
+
10
+ - **`evm`** — the standard MPP evm/authorization credential type (an EIP-3009
11
+ `transferWithAuthorization`, i.e. Route A). Maximally interoperable.
12
+ - **`parallel`** — Parallel's custom method: the credential payload IS the full
13
+ `SignedPaymentPayload` (`@parallel-protocol/payment-core`), so every route
14
+ (collateral / sUSDp swaps via the Parallelizer, 0% fee) is reachable.
15
+
16
+ Exports the Zod schemas (Challenge / Credential / Receipt / charge request),
17
+ base64url helpers, and `mppCredentialToX402` — which maps a decoded MPP charge
18
+ credential onto the x402 `{ paymentPayload, paymentRequirements }` verify/settle
19
+ inputs.
package/dist/index.cjs ADDED
@@ -0,0 +1,138 @@
1
+ 'use strict';
2
+
3
+ var chains = require('@parallel-protocol/chains');
4
+ var paymentCore = require('@parallel-protocol/payment-core');
5
+ var zod = require('zod');
6
+
7
+ // src/index.ts
8
+ function decodeBase64Url(value) {
9
+ return JSON.parse(Buffer.from(value, "base64url").toString("utf8"));
10
+ }
11
+ function encodeBase64Url(obj) {
12
+ return Buffer.from(JSON.stringify(obj)).toString("base64url");
13
+ }
14
+ var EvmChargeRequestSchema = zod.z.object({
15
+ amount: zod.z.string(),
16
+ currency: paymentCore.AddressSchema,
17
+ recipient: paymentCore.AddressSchema,
18
+ description: zod.z.string().optional(),
19
+ externalId: zod.z.string().optional(),
20
+ methodDetails: zod.z.object({
21
+ chainId: zod.z.number(),
22
+ permit2Address: paymentCore.AddressSchema.optional(),
23
+ credentialTypes: zod.z.array(zod.z.string()).optional(),
24
+ decimals: zod.z.number().optional()
25
+ })
26
+ });
27
+ var MppChallengeSchema = zod.z.object({
28
+ id: zod.z.string(),
29
+ realm: zod.z.string().optional(),
30
+ method: zod.z.enum(["evm", "parallel"]),
31
+ intent: zod.z.literal("charge"),
32
+ /** base64url(JSON) of the charge request (EvmChargeRequest) */
33
+ request: zod.z.string(),
34
+ digest: zod.z.string().optional(),
35
+ expires: zod.z.string().optional(),
36
+ description: zod.z.string().optional(),
37
+ opaque: zod.z.string().optional()
38
+ });
39
+ var EvmAuthorizationPayloadSchema = zod.z.object({
40
+ type: zod.z.literal("authorization"),
41
+ from: paymentCore.AddressSchema,
42
+ to: paymentCore.AddressSchema,
43
+ value: zod.z.string(),
44
+ validAfter: zod.z.string(),
45
+ validBefore: zod.z.string(),
46
+ nonce: paymentCore.Bytes32Schema,
47
+ signature: paymentCore.SignatureSchema
48
+ });
49
+ var MppChargeCredentialSchema = zod.z.object({
50
+ challenge: MppChallengeSchema,
51
+ /** payer identifier (org.paymentauth credential `source`), DID recommended */
52
+ source: zod.z.string().optional(),
53
+ payload: zod.z.union([EvmAuthorizationPayloadSchema, paymentCore.SignedPaymentPayloadSchema])
54
+ });
55
+ var MppVerifyRequestSchema = zod.z.object({
56
+ credential: MppChargeCredentialSchema
57
+ });
58
+ var MppVerifyResponseSchema = zod.z.object({ valid: zod.z.literal(true) });
59
+ var MppReceiptSchema = zod.z.object({
60
+ status: zod.z.literal("success"),
61
+ method: zod.z.enum(["evm", "parallel"]),
62
+ timestamp: zod.z.string(),
63
+ // RFC 3339
64
+ reference: zod.z.string()
65
+ // txHash
66
+ });
67
+ function chainSlugFromId(chainId) {
68
+ return chains.CHAIN_NAMES.find((c) => chains.CHAINS_STATIC[c].viem.id === chainId);
69
+ }
70
+ function mppCredentialToPayment(credential) {
71
+ let request;
72
+ try {
73
+ request = EvmChargeRequestSchema.parse(
74
+ decodeBase64Url(credential.challenge.request)
75
+ );
76
+ } catch {
77
+ return null;
78
+ }
79
+ if (credential.challenge.method === "parallel") {
80
+ const parsed2 = paymentCore.SignedPaymentPayloadSchema.safeParse(credential.payload);
81
+ if (!parsed2.success) return null;
82
+ const payload2 = parsed2.data;
83
+ return {
84
+ recipient: request.recipient,
85
+ signedRecipient: payload2.swapParams?.recipient ?? payload2.payload.authorization.to,
86
+ paymentPayload: payload2,
87
+ paymentRequirements: {
88
+ maxAmountRequired: request.amount,
89
+ asset: request.currency,
90
+ payTo: request.recipient,
91
+ network: payload2.network
92
+ }
93
+ };
94
+ }
95
+ const parsed = EvmAuthorizationPayloadSchema.safeParse(credential.payload);
96
+ if (!parsed.success) return null;
97
+ const payload = parsed.data;
98
+ const network = chainSlugFromId(request.methodDetails.chainId);
99
+ if (!network) return null;
100
+ return {
101
+ recipient: request.recipient,
102
+ signedRecipient: payload.to,
103
+ paymentPayload: {
104
+ scheme: "exact",
105
+ network,
106
+ method: "transferWithAuthorization",
107
+ tokenIn: request.currency,
108
+ payload: {
109
+ signature: payload.signature,
110
+ authorization: {
111
+ from: payload.from,
112
+ to: payload.to,
113
+ value: payload.value,
114
+ validAfter: payload.validAfter,
115
+ validBefore: payload.validBefore,
116
+ nonce: payload.nonce
117
+ }
118
+ }
119
+ },
120
+ paymentRequirements: {
121
+ maxAmountRequired: request.amount,
122
+ asset: request.currency,
123
+ payTo: request.recipient,
124
+ network
125
+ }
126
+ };
127
+ }
128
+
129
+ exports.EvmAuthorizationPayloadSchema = EvmAuthorizationPayloadSchema;
130
+ exports.EvmChargeRequestSchema = EvmChargeRequestSchema;
131
+ exports.MppChallengeSchema = MppChallengeSchema;
132
+ exports.MppChargeCredentialSchema = MppChargeCredentialSchema;
133
+ exports.MppReceiptSchema = MppReceiptSchema;
134
+ exports.MppVerifyRequestSchema = MppVerifyRequestSchema;
135
+ exports.MppVerifyResponseSchema = MppVerifyResponseSchema;
136
+ exports.decodeBase64Url = decodeBase64Url;
137
+ exports.encodeBase64Url = encodeBase64Url;
138
+ exports.mppCredentialToPayment = mppCredentialToPayment;
@@ -0,0 +1,227 @@
1
+ import { SignedPaymentPayload, PaymentRequirements } from '@parallel-protocol/payment-core';
2
+ import { z } from 'zod';
3
+
4
+ declare function decodeBase64Url<T>(value: string): T;
5
+ declare function encodeBase64Url(obj: unknown): string;
6
+ declare const EvmChargeRequestSchema: z.ZodObject<{
7
+ amount: z.ZodString;
8
+ currency: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
9
+ recipient: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
10
+ description: z.ZodOptional<z.ZodString>;
11
+ externalId: z.ZodOptional<z.ZodString>;
12
+ methodDetails: z.ZodObject<{
13
+ chainId: z.ZodNumber;
14
+ permit2Address: z.ZodOptional<z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>>;
15
+ credentialTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
16
+ decimals: z.ZodOptional<z.ZodNumber>;
17
+ }, z.core.$strip>;
18
+ }, z.core.$strip>;
19
+ type EvmChargeRequest = z.infer<typeof EvmChargeRequestSchema>;
20
+ declare const MppChallengeSchema: z.ZodObject<{
21
+ id: z.ZodString;
22
+ realm: z.ZodOptional<z.ZodString>;
23
+ method: z.ZodEnum<{
24
+ evm: "evm";
25
+ parallel: "parallel";
26
+ }>;
27
+ intent: z.ZodLiteral<"charge">;
28
+ request: z.ZodString;
29
+ digest: z.ZodOptional<z.ZodString>;
30
+ expires: z.ZodOptional<z.ZodString>;
31
+ description: z.ZodOptional<z.ZodString>;
32
+ opaque: z.ZodOptional<z.ZodString>;
33
+ }, z.core.$strip>;
34
+ declare const EvmAuthorizationPayloadSchema: z.ZodObject<{
35
+ type: z.ZodLiteral<"authorization">;
36
+ from: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
37
+ to: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
38
+ value: z.ZodString;
39
+ validAfter: z.ZodString;
40
+ validBefore: z.ZodString;
41
+ nonce: z.ZodString;
42
+ signature: z.ZodString;
43
+ }, z.core.$strip>;
44
+ declare const MppChargeCredentialSchema: z.ZodObject<{
45
+ challenge: z.ZodObject<{
46
+ id: z.ZodString;
47
+ realm: z.ZodOptional<z.ZodString>;
48
+ method: z.ZodEnum<{
49
+ evm: "evm";
50
+ parallel: "parallel";
51
+ }>;
52
+ intent: z.ZodLiteral<"charge">;
53
+ request: z.ZodString;
54
+ digest: z.ZodOptional<z.ZodString>;
55
+ expires: z.ZodOptional<z.ZodString>;
56
+ description: z.ZodOptional<z.ZodString>;
57
+ opaque: z.ZodOptional<z.ZodString>;
58
+ }, z.core.$strip>;
59
+ source: z.ZodOptional<z.ZodString>;
60
+ payload: z.ZodUnion<readonly [z.ZodObject<{
61
+ type: z.ZodLiteral<"authorization">;
62
+ from: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
63
+ to: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
64
+ value: z.ZodString;
65
+ validAfter: z.ZodString;
66
+ validBefore: z.ZodString;
67
+ nonce: z.ZodString;
68
+ signature: z.ZodString;
69
+ }, z.core.$strip>, z.ZodObject<{
70
+ scheme: z.ZodLiteral<"exact">;
71
+ network: z.ZodString;
72
+ method: z.ZodEnum<{
73
+ transferWithAuthorization: "transferWithAuthorization";
74
+ swapExactOutputWithAuthorization: "swapExactOutputWithAuthorization";
75
+ swapExactInputWithAuthorization: "swapExactInputWithAuthorization";
76
+ depositWithAuthorization: "depositWithAuthorization";
77
+ redeemWithAuthorization: "redeemWithAuthorization";
78
+ partialRedeemWithAuthorization: "partialRedeemWithAuthorization";
79
+ }>;
80
+ tokenIn: z.ZodOptional<z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>>;
81
+ payload: z.ZodObject<{
82
+ signature: z.ZodString;
83
+ authorization: z.ZodObject<{
84
+ from: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
85
+ to: z.ZodOptional<z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>>;
86
+ value: z.ZodString;
87
+ validAfter: z.ZodString;
88
+ validBefore: z.ZodString;
89
+ nonce: z.ZodString;
90
+ }, z.core.$strip>;
91
+ redeemAuthorization: z.ZodOptional<z.ZodObject<{
92
+ shares: z.ZodString;
93
+ validAfter: z.ZodString;
94
+ validBefore: z.ZodString;
95
+ nonce: z.ZodString;
96
+ }, z.core.$strip>>;
97
+ redeemSignature: z.ZodOptional<z.ZodString>;
98
+ tokenSignature: z.ZodOptional<z.ZodString>;
99
+ depositAuthorization: z.ZodOptional<z.ZodObject<{
100
+ assets: z.ZodString;
101
+ validAfter: z.ZodString;
102
+ validBefore: z.ZodString;
103
+ nonce: z.ZodString;
104
+ }, z.core.$strip>>;
105
+ depositSignature: z.ZodOptional<z.ZodString>;
106
+ }, z.core.$strip>;
107
+ swapParams: z.ZodOptional<z.ZodObject<{
108
+ tokenOut: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
109
+ amountOut: z.ZodOptional<z.ZodString>;
110
+ maxAmountIn: z.ZodOptional<z.ZodString>;
111
+ amountIn: z.ZodOptional<z.ZodString>;
112
+ amountOutMin: z.ZodOptional<z.ZodString>;
113
+ recipient: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
114
+ }, z.core.$strip>>;
115
+ }, z.core.$strip>]>;
116
+ }, z.core.$strip>;
117
+ type MppChargeCredential = z.infer<typeof MppChargeCredentialSchema>;
118
+ declare const MppVerifyRequestSchema: z.ZodObject<{
119
+ credential: z.ZodObject<{
120
+ challenge: z.ZodObject<{
121
+ id: z.ZodString;
122
+ realm: z.ZodOptional<z.ZodString>;
123
+ method: z.ZodEnum<{
124
+ evm: "evm";
125
+ parallel: "parallel";
126
+ }>;
127
+ intent: z.ZodLiteral<"charge">;
128
+ request: z.ZodString;
129
+ digest: z.ZodOptional<z.ZodString>;
130
+ expires: z.ZodOptional<z.ZodString>;
131
+ description: z.ZodOptional<z.ZodString>;
132
+ opaque: z.ZodOptional<z.ZodString>;
133
+ }, z.core.$strip>;
134
+ source: z.ZodOptional<z.ZodString>;
135
+ payload: z.ZodUnion<readonly [z.ZodObject<{
136
+ type: z.ZodLiteral<"authorization">;
137
+ from: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
138
+ to: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
139
+ value: z.ZodString;
140
+ validAfter: z.ZodString;
141
+ validBefore: z.ZodString;
142
+ nonce: z.ZodString;
143
+ signature: z.ZodString;
144
+ }, z.core.$strip>, z.ZodObject<{
145
+ scheme: z.ZodLiteral<"exact">;
146
+ network: z.ZodString;
147
+ method: z.ZodEnum<{
148
+ transferWithAuthorization: "transferWithAuthorization";
149
+ swapExactOutputWithAuthorization: "swapExactOutputWithAuthorization";
150
+ swapExactInputWithAuthorization: "swapExactInputWithAuthorization";
151
+ depositWithAuthorization: "depositWithAuthorization";
152
+ redeemWithAuthorization: "redeemWithAuthorization";
153
+ partialRedeemWithAuthorization: "partialRedeemWithAuthorization";
154
+ }>;
155
+ tokenIn: z.ZodOptional<z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>>;
156
+ payload: z.ZodObject<{
157
+ signature: z.ZodString;
158
+ authorization: z.ZodObject<{
159
+ from: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
160
+ to: z.ZodOptional<z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>>;
161
+ value: z.ZodString;
162
+ validAfter: z.ZodString;
163
+ validBefore: z.ZodString;
164
+ nonce: z.ZodString;
165
+ }, z.core.$strip>;
166
+ redeemAuthorization: z.ZodOptional<z.ZodObject<{
167
+ shares: z.ZodString;
168
+ validAfter: z.ZodString;
169
+ validBefore: z.ZodString;
170
+ nonce: z.ZodString;
171
+ }, z.core.$strip>>;
172
+ redeemSignature: z.ZodOptional<z.ZodString>;
173
+ tokenSignature: z.ZodOptional<z.ZodString>;
174
+ depositAuthorization: z.ZodOptional<z.ZodObject<{
175
+ assets: z.ZodString;
176
+ validAfter: z.ZodString;
177
+ validBefore: z.ZodString;
178
+ nonce: z.ZodString;
179
+ }, z.core.$strip>>;
180
+ depositSignature: z.ZodOptional<z.ZodString>;
181
+ }, z.core.$strip>;
182
+ swapParams: z.ZodOptional<z.ZodObject<{
183
+ tokenOut: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
184
+ amountOut: z.ZodOptional<z.ZodString>;
185
+ maxAmountIn: z.ZodOptional<z.ZodString>;
186
+ amountIn: z.ZodOptional<z.ZodString>;
187
+ amountOutMin: z.ZodOptional<z.ZodString>;
188
+ recipient: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
189
+ }, z.core.$strip>>;
190
+ }, z.core.$strip>]>;
191
+ }, z.core.$strip>;
192
+ }, z.core.$strip>;
193
+ type MppVerifyRequest = z.infer<typeof MppVerifyRequestSchema>;
194
+ declare const MppVerifyResponseSchema: z.ZodObject<{
195
+ valid: z.ZodLiteral<true>;
196
+ }, z.core.$strip>;
197
+ declare const MppReceiptSchema: z.ZodObject<{
198
+ status: z.ZodLiteral<"success">;
199
+ method: z.ZodEnum<{
200
+ evm: "evm";
201
+ parallel: "parallel";
202
+ }>;
203
+ timestamp: z.ZodString;
204
+ reference: z.ZodString;
205
+ }, z.core.$strip>;
206
+ type MppReceipt = z.infer<typeof MppReceiptSchema>;
207
+ interface MppMapped {
208
+ paymentPayload: SignedPaymentPayload;
209
+ paymentRequirements: PaymentRequirements;
210
+ /** merchant recipient from the challenge.request */
211
+ recipient: string;
212
+ /** recipient actually bound in the payload — callers must match it */
213
+ signedRecipient: string | undefined;
214
+ }
215
+ /**
216
+ * Map an MPP charge credential onto the x402 verify/settle inputs.
217
+ * `paymentRequirements` come from the decoded challenge.request; the method
218
+ * selects the payload shape:
219
+ * - `evm` → an EIP-3009 authorization → transferWithAuthorization (Route A)
220
+ * - `parallel` → the payload IS the full SignedPaymentPayload (any route A–L)
221
+ *
222
+ * Returns `null` if the request is malformed, the chain is unknown, or the
223
+ * payload doesn't match the declared method.
224
+ */
225
+ declare function mppCredentialToPayment(credential: MppChargeCredential): MppMapped | null;
226
+
227
+ export { EvmAuthorizationPayloadSchema, type EvmChargeRequest, EvmChargeRequestSchema, MppChallengeSchema, type MppChargeCredential, MppChargeCredentialSchema, type MppMapped, type MppReceipt, MppReceiptSchema, type MppVerifyRequest, MppVerifyRequestSchema, MppVerifyResponseSchema, decodeBase64Url, encodeBase64Url, mppCredentialToPayment };
@@ -0,0 +1,227 @@
1
+ import { SignedPaymentPayload, PaymentRequirements } from '@parallel-protocol/payment-core';
2
+ import { z } from 'zod';
3
+
4
+ declare function decodeBase64Url<T>(value: string): T;
5
+ declare function encodeBase64Url(obj: unknown): string;
6
+ declare const EvmChargeRequestSchema: z.ZodObject<{
7
+ amount: z.ZodString;
8
+ currency: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
9
+ recipient: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
10
+ description: z.ZodOptional<z.ZodString>;
11
+ externalId: z.ZodOptional<z.ZodString>;
12
+ methodDetails: z.ZodObject<{
13
+ chainId: z.ZodNumber;
14
+ permit2Address: z.ZodOptional<z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>>;
15
+ credentialTypes: z.ZodOptional<z.ZodArray<z.ZodString>>;
16
+ decimals: z.ZodOptional<z.ZodNumber>;
17
+ }, z.core.$strip>;
18
+ }, z.core.$strip>;
19
+ type EvmChargeRequest = z.infer<typeof EvmChargeRequestSchema>;
20
+ declare const MppChallengeSchema: z.ZodObject<{
21
+ id: z.ZodString;
22
+ realm: z.ZodOptional<z.ZodString>;
23
+ method: z.ZodEnum<{
24
+ evm: "evm";
25
+ parallel: "parallel";
26
+ }>;
27
+ intent: z.ZodLiteral<"charge">;
28
+ request: z.ZodString;
29
+ digest: z.ZodOptional<z.ZodString>;
30
+ expires: z.ZodOptional<z.ZodString>;
31
+ description: z.ZodOptional<z.ZodString>;
32
+ opaque: z.ZodOptional<z.ZodString>;
33
+ }, z.core.$strip>;
34
+ declare const EvmAuthorizationPayloadSchema: z.ZodObject<{
35
+ type: z.ZodLiteral<"authorization">;
36
+ from: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
37
+ to: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
38
+ value: z.ZodString;
39
+ validAfter: z.ZodString;
40
+ validBefore: z.ZodString;
41
+ nonce: z.ZodString;
42
+ signature: z.ZodString;
43
+ }, z.core.$strip>;
44
+ declare const MppChargeCredentialSchema: z.ZodObject<{
45
+ challenge: z.ZodObject<{
46
+ id: z.ZodString;
47
+ realm: z.ZodOptional<z.ZodString>;
48
+ method: z.ZodEnum<{
49
+ evm: "evm";
50
+ parallel: "parallel";
51
+ }>;
52
+ intent: z.ZodLiteral<"charge">;
53
+ request: z.ZodString;
54
+ digest: z.ZodOptional<z.ZodString>;
55
+ expires: z.ZodOptional<z.ZodString>;
56
+ description: z.ZodOptional<z.ZodString>;
57
+ opaque: z.ZodOptional<z.ZodString>;
58
+ }, z.core.$strip>;
59
+ source: z.ZodOptional<z.ZodString>;
60
+ payload: z.ZodUnion<readonly [z.ZodObject<{
61
+ type: z.ZodLiteral<"authorization">;
62
+ from: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
63
+ to: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
64
+ value: z.ZodString;
65
+ validAfter: z.ZodString;
66
+ validBefore: z.ZodString;
67
+ nonce: z.ZodString;
68
+ signature: z.ZodString;
69
+ }, z.core.$strip>, z.ZodObject<{
70
+ scheme: z.ZodLiteral<"exact">;
71
+ network: z.ZodString;
72
+ method: z.ZodEnum<{
73
+ transferWithAuthorization: "transferWithAuthorization";
74
+ swapExactOutputWithAuthorization: "swapExactOutputWithAuthorization";
75
+ swapExactInputWithAuthorization: "swapExactInputWithAuthorization";
76
+ depositWithAuthorization: "depositWithAuthorization";
77
+ redeemWithAuthorization: "redeemWithAuthorization";
78
+ partialRedeemWithAuthorization: "partialRedeemWithAuthorization";
79
+ }>;
80
+ tokenIn: z.ZodOptional<z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>>;
81
+ payload: z.ZodObject<{
82
+ signature: z.ZodString;
83
+ authorization: z.ZodObject<{
84
+ from: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
85
+ to: z.ZodOptional<z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>>;
86
+ value: z.ZodString;
87
+ validAfter: z.ZodString;
88
+ validBefore: z.ZodString;
89
+ nonce: z.ZodString;
90
+ }, z.core.$strip>;
91
+ redeemAuthorization: z.ZodOptional<z.ZodObject<{
92
+ shares: z.ZodString;
93
+ validAfter: z.ZodString;
94
+ validBefore: z.ZodString;
95
+ nonce: z.ZodString;
96
+ }, z.core.$strip>>;
97
+ redeemSignature: z.ZodOptional<z.ZodString>;
98
+ tokenSignature: z.ZodOptional<z.ZodString>;
99
+ depositAuthorization: z.ZodOptional<z.ZodObject<{
100
+ assets: z.ZodString;
101
+ validAfter: z.ZodString;
102
+ validBefore: z.ZodString;
103
+ nonce: z.ZodString;
104
+ }, z.core.$strip>>;
105
+ depositSignature: z.ZodOptional<z.ZodString>;
106
+ }, z.core.$strip>;
107
+ swapParams: z.ZodOptional<z.ZodObject<{
108
+ tokenOut: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
109
+ amountOut: z.ZodOptional<z.ZodString>;
110
+ maxAmountIn: z.ZodOptional<z.ZodString>;
111
+ amountIn: z.ZodOptional<z.ZodString>;
112
+ amountOutMin: z.ZodOptional<z.ZodString>;
113
+ recipient: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
114
+ }, z.core.$strip>>;
115
+ }, z.core.$strip>]>;
116
+ }, z.core.$strip>;
117
+ type MppChargeCredential = z.infer<typeof MppChargeCredentialSchema>;
118
+ declare const MppVerifyRequestSchema: z.ZodObject<{
119
+ credential: z.ZodObject<{
120
+ challenge: z.ZodObject<{
121
+ id: z.ZodString;
122
+ realm: z.ZodOptional<z.ZodString>;
123
+ method: z.ZodEnum<{
124
+ evm: "evm";
125
+ parallel: "parallel";
126
+ }>;
127
+ intent: z.ZodLiteral<"charge">;
128
+ request: z.ZodString;
129
+ digest: z.ZodOptional<z.ZodString>;
130
+ expires: z.ZodOptional<z.ZodString>;
131
+ description: z.ZodOptional<z.ZodString>;
132
+ opaque: z.ZodOptional<z.ZodString>;
133
+ }, z.core.$strip>;
134
+ source: z.ZodOptional<z.ZodString>;
135
+ payload: z.ZodUnion<readonly [z.ZodObject<{
136
+ type: z.ZodLiteral<"authorization">;
137
+ from: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
138
+ to: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
139
+ value: z.ZodString;
140
+ validAfter: z.ZodString;
141
+ validBefore: z.ZodString;
142
+ nonce: z.ZodString;
143
+ signature: z.ZodString;
144
+ }, z.core.$strip>, z.ZodObject<{
145
+ scheme: z.ZodLiteral<"exact">;
146
+ network: z.ZodString;
147
+ method: z.ZodEnum<{
148
+ transferWithAuthorization: "transferWithAuthorization";
149
+ swapExactOutputWithAuthorization: "swapExactOutputWithAuthorization";
150
+ swapExactInputWithAuthorization: "swapExactInputWithAuthorization";
151
+ depositWithAuthorization: "depositWithAuthorization";
152
+ redeemWithAuthorization: "redeemWithAuthorization";
153
+ partialRedeemWithAuthorization: "partialRedeemWithAuthorization";
154
+ }>;
155
+ tokenIn: z.ZodOptional<z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>>;
156
+ payload: z.ZodObject<{
157
+ signature: z.ZodString;
158
+ authorization: z.ZodObject<{
159
+ from: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
160
+ to: z.ZodOptional<z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>>;
161
+ value: z.ZodString;
162
+ validAfter: z.ZodString;
163
+ validBefore: z.ZodString;
164
+ nonce: z.ZodString;
165
+ }, z.core.$strip>;
166
+ redeemAuthorization: z.ZodOptional<z.ZodObject<{
167
+ shares: z.ZodString;
168
+ validAfter: z.ZodString;
169
+ validBefore: z.ZodString;
170
+ nonce: z.ZodString;
171
+ }, z.core.$strip>>;
172
+ redeemSignature: z.ZodOptional<z.ZodString>;
173
+ tokenSignature: z.ZodOptional<z.ZodString>;
174
+ depositAuthorization: z.ZodOptional<z.ZodObject<{
175
+ assets: z.ZodString;
176
+ validAfter: z.ZodString;
177
+ validBefore: z.ZodString;
178
+ nonce: z.ZodString;
179
+ }, z.core.$strip>>;
180
+ depositSignature: z.ZodOptional<z.ZodString>;
181
+ }, z.core.$strip>;
182
+ swapParams: z.ZodOptional<z.ZodObject<{
183
+ tokenOut: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
184
+ amountOut: z.ZodOptional<z.ZodString>;
185
+ maxAmountIn: z.ZodOptional<z.ZodString>;
186
+ amountIn: z.ZodOptional<z.ZodString>;
187
+ amountOutMin: z.ZodOptional<z.ZodString>;
188
+ recipient: z.ZodType<`0x${string}`, unknown, z.core.$ZodTypeInternals<`0x${string}`, unknown>>;
189
+ }, z.core.$strip>>;
190
+ }, z.core.$strip>]>;
191
+ }, z.core.$strip>;
192
+ }, z.core.$strip>;
193
+ type MppVerifyRequest = z.infer<typeof MppVerifyRequestSchema>;
194
+ declare const MppVerifyResponseSchema: z.ZodObject<{
195
+ valid: z.ZodLiteral<true>;
196
+ }, z.core.$strip>;
197
+ declare const MppReceiptSchema: z.ZodObject<{
198
+ status: z.ZodLiteral<"success">;
199
+ method: z.ZodEnum<{
200
+ evm: "evm";
201
+ parallel: "parallel";
202
+ }>;
203
+ timestamp: z.ZodString;
204
+ reference: z.ZodString;
205
+ }, z.core.$strip>;
206
+ type MppReceipt = z.infer<typeof MppReceiptSchema>;
207
+ interface MppMapped {
208
+ paymentPayload: SignedPaymentPayload;
209
+ paymentRequirements: PaymentRequirements;
210
+ /** merchant recipient from the challenge.request */
211
+ recipient: string;
212
+ /** recipient actually bound in the payload — callers must match it */
213
+ signedRecipient: string | undefined;
214
+ }
215
+ /**
216
+ * Map an MPP charge credential onto the x402 verify/settle inputs.
217
+ * `paymentRequirements` come from the decoded challenge.request; the method
218
+ * selects the payload shape:
219
+ * - `evm` → an EIP-3009 authorization → transferWithAuthorization (Route A)
220
+ * - `parallel` → the payload IS the full SignedPaymentPayload (any route A–L)
221
+ *
222
+ * Returns `null` if the request is malformed, the chain is unknown, or the
223
+ * payload doesn't match the declared method.
224
+ */
225
+ declare function mppCredentialToPayment(credential: MppChargeCredential): MppMapped | null;
226
+
227
+ export { EvmAuthorizationPayloadSchema, type EvmChargeRequest, EvmChargeRequestSchema, MppChallengeSchema, type MppChargeCredential, MppChargeCredentialSchema, type MppMapped, type MppReceipt, MppReceiptSchema, type MppVerifyRequest, MppVerifyRequestSchema, MppVerifyResponseSchema, decodeBase64Url, encodeBase64Url, mppCredentialToPayment };
package/dist/index.js ADDED
@@ -0,0 +1,127 @@
1
+ import { CHAIN_NAMES, CHAINS_STATIC } from '@parallel-protocol/chains';
2
+ import { AddressSchema, SignatureSchema, Bytes32Schema, SignedPaymentPayloadSchema } from '@parallel-protocol/payment-core';
3
+ import { z } from 'zod';
4
+
5
+ // src/index.ts
6
+ function decodeBase64Url(value) {
7
+ return JSON.parse(Buffer.from(value, "base64url").toString("utf8"));
8
+ }
9
+ function encodeBase64Url(obj) {
10
+ return Buffer.from(JSON.stringify(obj)).toString("base64url");
11
+ }
12
+ var EvmChargeRequestSchema = z.object({
13
+ amount: z.string(),
14
+ currency: AddressSchema,
15
+ recipient: AddressSchema,
16
+ description: z.string().optional(),
17
+ externalId: z.string().optional(),
18
+ methodDetails: z.object({
19
+ chainId: z.number(),
20
+ permit2Address: AddressSchema.optional(),
21
+ credentialTypes: z.array(z.string()).optional(),
22
+ decimals: z.number().optional()
23
+ })
24
+ });
25
+ var MppChallengeSchema = z.object({
26
+ id: z.string(),
27
+ realm: z.string().optional(),
28
+ method: z.enum(["evm", "parallel"]),
29
+ intent: z.literal("charge"),
30
+ /** base64url(JSON) of the charge request (EvmChargeRequest) */
31
+ request: z.string(),
32
+ digest: z.string().optional(),
33
+ expires: z.string().optional(),
34
+ description: z.string().optional(),
35
+ opaque: z.string().optional()
36
+ });
37
+ var EvmAuthorizationPayloadSchema = z.object({
38
+ type: z.literal("authorization"),
39
+ from: AddressSchema,
40
+ to: AddressSchema,
41
+ value: z.string(),
42
+ validAfter: z.string(),
43
+ validBefore: z.string(),
44
+ nonce: Bytes32Schema,
45
+ signature: SignatureSchema
46
+ });
47
+ var MppChargeCredentialSchema = z.object({
48
+ challenge: MppChallengeSchema,
49
+ /** payer identifier (org.paymentauth credential `source`), DID recommended */
50
+ source: z.string().optional(),
51
+ payload: z.union([EvmAuthorizationPayloadSchema, SignedPaymentPayloadSchema])
52
+ });
53
+ var MppVerifyRequestSchema = z.object({
54
+ credential: MppChargeCredentialSchema
55
+ });
56
+ var MppVerifyResponseSchema = z.object({ valid: z.literal(true) });
57
+ var MppReceiptSchema = z.object({
58
+ status: z.literal("success"),
59
+ method: z.enum(["evm", "parallel"]),
60
+ timestamp: z.string(),
61
+ // RFC 3339
62
+ reference: z.string()
63
+ // txHash
64
+ });
65
+ function chainSlugFromId(chainId) {
66
+ return CHAIN_NAMES.find((c) => CHAINS_STATIC[c].viem.id === chainId);
67
+ }
68
+ function mppCredentialToPayment(credential) {
69
+ let request;
70
+ try {
71
+ request = EvmChargeRequestSchema.parse(
72
+ decodeBase64Url(credential.challenge.request)
73
+ );
74
+ } catch {
75
+ return null;
76
+ }
77
+ if (credential.challenge.method === "parallel") {
78
+ const parsed2 = SignedPaymentPayloadSchema.safeParse(credential.payload);
79
+ if (!parsed2.success) return null;
80
+ const payload2 = parsed2.data;
81
+ return {
82
+ recipient: request.recipient,
83
+ signedRecipient: payload2.swapParams?.recipient ?? payload2.payload.authorization.to,
84
+ paymentPayload: payload2,
85
+ paymentRequirements: {
86
+ maxAmountRequired: request.amount,
87
+ asset: request.currency,
88
+ payTo: request.recipient,
89
+ network: payload2.network
90
+ }
91
+ };
92
+ }
93
+ const parsed = EvmAuthorizationPayloadSchema.safeParse(credential.payload);
94
+ if (!parsed.success) return null;
95
+ const payload = parsed.data;
96
+ const network = chainSlugFromId(request.methodDetails.chainId);
97
+ if (!network) return null;
98
+ return {
99
+ recipient: request.recipient,
100
+ signedRecipient: payload.to,
101
+ paymentPayload: {
102
+ scheme: "exact",
103
+ network,
104
+ method: "transferWithAuthorization",
105
+ tokenIn: request.currency,
106
+ payload: {
107
+ signature: payload.signature,
108
+ authorization: {
109
+ from: payload.from,
110
+ to: payload.to,
111
+ value: payload.value,
112
+ validAfter: payload.validAfter,
113
+ validBefore: payload.validBefore,
114
+ nonce: payload.nonce
115
+ }
116
+ }
117
+ },
118
+ paymentRequirements: {
119
+ maxAmountRequired: request.amount,
120
+ asset: request.currency,
121
+ payTo: request.recipient,
122
+ network
123
+ }
124
+ };
125
+ }
126
+
127
+ export { EvmAuthorizationPayloadSchema, EvmChargeRequestSchema, MppChallengeSchema, MppChargeCredentialSchema, MppReceiptSchema, MppVerifyRequestSchema, MppVerifyResponseSchema, decodeBase64Url, encodeBase64Url, mppCredentialToPayment };
package/package.json ADDED
@@ -0,0 +1,61 @@
1
+ {
2
+ "name": "@parallel-protocol/mpp-types",
3
+ "version": "0.1.0",
4
+ "description": "Parallel Protocol MPP (Machine Payments Protocol) charge-intent wire types — Challenge/Credential/Receipt + the evm and parallel methods",
5
+ "author": "Parallel Protocol <contact@parallel.best>",
6
+ "repository": "github:parallel-protocol/sdk-merchant",
7
+ "homepage": "https://github.com/parallel-protocol/sdk-merchant",
8
+ "bugs": {
9
+ "url": "https://github.com/parallel-protocol/sdk-merchant/issues"
10
+ },
11
+ "license": "MIT",
12
+ "sideEffects": false,
13
+ "type": "module",
14
+ "main": "./dist/index.cjs",
15
+ "module": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "import": {
20
+ "types": "./dist/index.d.ts",
21
+ "default": "./dist/index.js"
22
+ },
23
+ "require": {
24
+ "types": "./dist/index.d.cts",
25
+ "default": "./dist/index.cjs"
26
+ }
27
+ },
28
+ "./package.json": "./package.json"
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "README.md"
33
+ ],
34
+ "publishConfig": {
35
+ "registry": "https://registry.npmjs.org",
36
+ "access": "public"
37
+ },
38
+ "scripts": {
39
+ "build": "tsup",
40
+ "dev": "tsup --watch",
41
+ "clean": "rm -rf dist coverage",
42
+ "type-check": "tsc --noEmit",
43
+ "test": "vitest"
44
+ },
45
+ "peerDependencies": {
46
+ "viem": "^2.0.0",
47
+ "zod": "^4.0.0"
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "^22.0.0",
51
+ "tsup": "^8.0.0",
52
+ "typescript": "^5.9.0",
53
+ "viem": "^2.47.0",
54
+ "vitest": "^4.0.14",
55
+ "zod": "^4.4.3"
56
+ },
57
+ "dependencies": {
58
+ "@parallel-protocol/chains": "workspace:*",
59
+ "@parallel-protocol/payment-core": "workspace:*"
60
+ }
61
+ }