@mixrpay/merchant-sdk 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.
@@ -0,0 +1,166 @@
1
+ /**
2
+ * MixrPay Merchant SDK - Type definitions
3
+ */
4
+ interface X402Options {
5
+ /** Price in USD (e.g., 0.05 for 5 cents) */
6
+ price: number;
7
+ /** Your merchant wallet address to receive payments */
8
+ recipient?: string;
9
+ /** Chain ID (default: 8453 for Base) */
10
+ chainId?: number;
11
+ /** Facilitator URL for payment settlement */
12
+ facilitator?: string;
13
+ /** Description of what the payment is for */
14
+ description?: string;
15
+ /** Custom function to determine price dynamically */
16
+ getPrice?: (context: PriceContext) => number | Promise<number>;
17
+ /** Called after successful payment verification */
18
+ onPayment?: (payment: X402PaymentResult) => void | Promise<void>;
19
+ /** Skip payment for certain requests (return true to skip) */
20
+ skip?: (context: SkipContext) => boolean | Promise<boolean>;
21
+ /** Allow test payments (for development) */
22
+ testMode?: boolean;
23
+ /**
24
+ * Receipt mode for payment verification responses.
25
+ * - 'jwt': Set X-Payment-Receipt header with JWT (no webhook)
26
+ * - 'webhook': Send webhook only (default, backwards compatible)
27
+ * - 'both': Set JWT header AND send webhook
28
+ */
29
+ receiptMode?: ReceiptMode;
30
+ /** MixrPay API URL for fetching JWT receipts (default: production) */
31
+ mixrpayApiUrl?: string;
32
+ }
33
+ interface PriceContext {
34
+ /** Request path */
35
+ path: string;
36
+ /** Request method */
37
+ method: string;
38
+ /** Request headers */
39
+ headers: Record<string, string | string[] | undefined>;
40
+ /** Request body (if parsed) */
41
+ body?: unknown;
42
+ }
43
+ type SkipContext = PriceContext;
44
+ interface X402PaymentResult {
45
+ /** Whether the payment is valid */
46
+ valid: boolean;
47
+ /** Error message if invalid */
48
+ error?: string;
49
+ /** Address that paid (if valid) */
50
+ payer?: string;
51
+ /** Amount in USDC (major units, e.g., 0.05) */
52
+ amount?: number;
53
+ /** Amount in USDC minor units (e.g., 50000) */
54
+ amountMinor?: bigint;
55
+ /** Settlement transaction hash */
56
+ txHash?: string;
57
+ /** When the payment was settled */
58
+ settledAt?: Date;
59
+ /** The nonce used for this payment */
60
+ nonce?: string;
61
+ /** JWT payment receipt (when receiptMode is 'jwt' or 'both') */
62
+ receipt?: string;
63
+ }
64
+ interface X402PaymentRequired {
65
+ /** Recipient wallet address */
66
+ recipient: string;
67
+ /** Amount in USDC minor units (6 decimals) as string */
68
+ amount: string;
69
+ /** Currency code */
70
+ currency: string;
71
+ /** Chain ID */
72
+ chainId: number;
73
+ /** Facilitator URL */
74
+ facilitator: string;
75
+ /** Unique nonce for this payment request */
76
+ nonce: string;
77
+ /** Unix timestamp when payment requirements expire */
78
+ expiresAt: number;
79
+ /** Description of the payment */
80
+ description?: string;
81
+ }
82
+ interface X402PaymentPayload {
83
+ x402Version: number;
84
+ scheme: 'exact';
85
+ network: 'base' | 'base-sepolia';
86
+ payload: {
87
+ signature: string;
88
+ authorization: {
89
+ from: string;
90
+ to: string;
91
+ value: string;
92
+ validAfter: string;
93
+ validBefore: string;
94
+ nonce: string;
95
+ };
96
+ };
97
+ }
98
+ interface EIP712Domain {
99
+ name: string;
100
+ version: string;
101
+ chainId: number;
102
+ verifyingContract: `0x${string}`;
103
+ }
104
+ interface TransferWithAuthorizationMessage {
105
+ from: `0x${string}`;
106
+ to: `0x${string}`;
107
+ value: bigint;
108
+ validAfter: bigint;
109
+ validBefore: bigint;
110
+ nonce: `0x${string}`;
111
+ }
112
+ interface VerifyOptions {
113
+ /** Expected amount in USDC minor units */
114
+ expectedAmount: bigint;
115
+ /** Expected recipient address */
116
+ expectedRecipient: string;
117
+ /** Chain ID (default: 8453 for Base) */
118
+ chainId?: number;
119
+ /** Facilitator URL */
120
+ facilitator?: string;
121
+ /** Skip on-chain settlement (for testing) */
122
+ skipSettlement?: boolean;
123
+ }
124
+ /**
125
+ * Verified payment receipt from MixrPay.
126
+ */
127
+ interface PaymentReceipt {
128
+ /** Unique payment ID */
129
+ paymentId: string;
130
+ /** Amount in USDC minor units (6 decimals) as string */
131
+ amount: string;
132
+ /** Amount in USD */
133
+ amountUsd: number;
134
+ /** Payer wallet address */
135
+ payer: string;
136
+ /** Recipient wallet address */
137
+ recipient: string;
138
+ /** Blockchain chain ID */
139
+ chainId: number;
140
+ /** Settlement transaction hash */
141
+ txHash: string;
142
+ /** When the payment was settled (ISO string) */
143
+ settledAt: string;
144
+ /** When the receipt was issued */
145
+ issuedAt?: Date;
146
+ /** When the receipt expires */
147
+ expiresAt?: Date;
148
+ }
149
+ /**
150
+ * Options for verifying a payment receipt.
151
+ */
152
+ interface VerifyReceiptOptions {
153
+ /** Custom JWKS URL (default: MixrPay production JWKS) */
154
+ jwksUrl?: string;
155
+ /** Expected issuer (for additional validation) */
156
+ issuer?: string;
157
+ }
158
+ /**
159
+ * Receipt mode for x402 middleware.
160
+ * - 'jwt': Only generate JWT receipt (no webhook)
161
+ * - 'webhook': Only send webhook (default, backwards compatible)
162
+ * - 'both': Generate JWT receipt AND send webhook
163
+ */
164
+ type ReceiptMode = 'jwt' | 'webhook' | 'both';
165
+
166
+ export type { EIP712Domain as E, PaymentReceipt as P, ReceiptMode as R, SkipContext as S, TransferWithAuthorizationMessage as T, VerifyOptions as V, X402PaymentResult as X, VerifyReceiptOptions as a, X402Options as b, X402PaymentRequired as c, X402PaymentPayload as d, PriceContext as e };
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "@mixrpay/merchant-sdk",
3
+ "version": "0.1.0",
4
+ "description": "Add x402 payments to your API in minutes - middleware for Express, Next.js, and Fastify",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.mjs",
12
+ "require": "./dist/index.js"
13
+ },
14
+ "./express": {
15
+ "types": "./dist/middleware/express.d.ts",
16
+ "import": "./dist/middleware/express.mjs",
17
+ "require": "./dist/middleware/express.js"
18
+ },
19
+ "./nextjs": {
20
+ "types": "./dist/middleware/nextjs.d.ts",
21
+ "import": "./dist/middleware/nextjs.mjs",
22
+ "require": "./dist/middleware/nextjs.js"
23
+ },
24
+ "./fastify": {
25
+ "types": "./dist/middleware/fastify.d.ts",
26
+ "import": "./dist/middleware/fastify.mjs",
27
+ "require": "./dist/middleware/fastify.js"
28
+ }
29
+ },
30
+ "files": [
31
+ "dist",
32
+ "README.md"
33
+ ],
34
+ "scripts": {
35
+ "build": "tsup",
36
+ "dev": "tsup --watch",
37
+ "test": "vitest",
38
+ "lint": "eslint src/",
39
+ "typecheck": "tsc --noEmit"
40
+ },
41
+ "keywords": [
42
+ "x402",
43
+ "payments",
44
+ "ai",
45
+ "agents",
46
+ "micropayments",
47
+ "middleware",
48
+ "express",
49
+ "nextjs",
50
+ "fastify",
51
+ "usdc",
52
+ "crypto"
53
+ ],
54
+ "author": "MixrPay",
55
+ "license": "MIT",
56
+ "repository": {
57
+ "type": "git",
58
+ "url": "https://github.com/mixrpay/merchant-sdk"
59
+ },
60
+ "dependencies": {
61
+ "jose": "^5.2.0",
62
+ "viem": "^2.21.0"
63
+ },
64
+ "devDependencies": {
65
+ "@types/express": "^4.17.21",
66
+ "@types/node": "^20.10.0",
67
+ "express": "^4.18.2",
68
+ "fastify": "^4.26.0",
69
+ "next": "^14.0.0",
70
+ "tsup": "^8.0.0",
71
+ "typescript": "^5.3.0",
72
+ "vitest": "^1.0.0"
73
+ },
74
+ "peerDependencies": {
75
+ "express": ">=4.0.0",
76
+ "fastify": ">=4.0.0",
77
+ "next": ">=13.0.0"
78
+ },
79
+ "peerDependenciesMeta": {
80
+ "express": {
81
+ "optional": true
82
+ },
83
+ "fastify": {
84
+ "optional": true
85
+ },
86
+ "next": {
87
+ "optional": true
88
+ }
89
+ }
90
+ }
91
+