gatepay-local-mcp 1.0.3 → 1.0.5
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 +360 -65
- package/dist/src/config/env-config.d.ts +32 -0
- package/dist/src/config/env-config.d.ts.map +1 -0
- package/dist/src/config/env-config.js +98 -0
- package/dist/src/config/env-config.js.map +1 -0
- package/dist/src/gate-pay/auth.d.ts +18 -0
- package/dist/src/gate-pay/auth.d.ts.map +1 -0
- package/dist/src/gate-pay/auth.js +38 -0
- package/dist/src/gate-pay/auth.js.map +1 -0
- package/dist/src/gate-pay/centralized-payment/index.d.ts +6 -0
- package/dist/src/gate-pay/centralized-payment/index.d.ts.map +1 -0
- package/dist/src/gate-pay/centralized-payment/index.js +6 -0
- package/dist/src/gate-pay/centralized-payment/index.js.map +1 -0
- package/dist/src/gate-pay/centralized-payment/parser.d.ts +50 -0
- package/dist/src/gate-pay/centralized-payment/parser.d.ts.map +1 -0
- package/dist/src/gate-pay/centralized-payment/parser.js +59 -0
- package/dist/src/gate-pay/centralized-payment/parser.js.map +1 -0
- package/dist/src/gate-pay/centralized-payment/payment-client.d.ts +28 -0
- package/dist/src/gate-pay/centralized-payment/payment-client.d.ts.map +1 -0
- package/dist/src/gate-pay/centralized-payment/payment-client.js +84 -0
- package/dist/src/gate-pay/centralized-payment/payment-client.js.map +1 -0
- package/dist/src/gate-pay/device-flow.d.ts +25 -0
- package/dist/src/gate-pay/device-flow.d.ts.map +1 -0
- package/dist/src/gate-pay/device-flow.js +49 -0
- package/dist/src/gate-pay/device-flow.js.map +1 -0
- package/dist/src/gate-pay/gate-oauth-class.d.ts +21 -0
- package/dist/src/gate-pay/gate-oauth-class.d.ts.map +1 -0
- package/dist/src/gate-pay/gate-oauth-class.js +229 -0
- package/dist/src/gate-pay/gate-oauth-class.js.map +1 -0
- package/dist/src/gate-pay/gate-oauth-config.d.ts +7 -0
- package/dist/src/gate-pay/gate-oauth-config.d.ts.map +1 -0
- package/dist/src/gate-pay/gate-oauth-config.js +107 -0
- package/dist/src/gate-pay/gate-oauth-config.js.map +1 -0
- package/dist/src/gate-pay/gate-oauth.d.ts +6 -0
- package/dist/src/gate-pay/gate-oauth.d.ts.map +1 -0
- package/dist/src/gate-pay/gate-oauth.js +6 -0
- package/dist/src/gate-pay/gate-oauth.js.map +1 -0
- package/dist/src/gate-pay/local-oauth-base.d.ts +25 -0
- package/dist/src/gate-pay/local-oauth-base.d.ts.map +1 -0
- package/dist/src/gate-pay/local-oauth-base.js +193 -0
- package/dist/src/gate-pay/local-oauth-base.js.map +1 -0
- package/dist/src/gate-pay/oauth-browser.d.ts +2 -0
- package/dist/src/gate-pay/oauth-browser.d.ts.map +1 -0
- package/dist/src/gate-pay/oauth-browser.js +32 -0
- package/dist/src/gate-pay/oauth-browser.js.map +1 -0
- package/dist/src/gate-pay/oauth-html.d.ts +3 -0
- package/dist/src/gate-pay/oauth-html.d.ts.map +1 -0
- package/dist/src/gate-pay/oauth-html.js +43 -0
- package/dist/src/gate-pay/oauth-html.js.map +1 -0
- package/dist/src/gate-pay/oauth-log.d.ts +2 -0
- package/dist/src/gate-pay/oauth-log.d.ts.map +1 -0
- package/dist/src/gate-pay/oauth-log.js +10 -0
- package/dist/src/gate-pay/oauth-log.js.map +1 -0
- package/dist/src/gate-pay/oauth-token-exchange.d.ts +19 -0
- package/dist/src/gate-pay/oauth-token-exchange.d.ts.map +1 -0
- package/dist/src/gate-pay/oauth-token-exchange.js +49 -0
- package/dist/src/gate-pay/oauth-token-exchange.js.map +1 -0
- package/dist/src/gate-pay/oauth-types.d.ts +33 -0
- package/dist/src/gate-pay/oauth-types.d.ts.map +1 -0
- package/dist/src/gate-pay/oauth-types.js +2 -0
- package/dist/src/gate-pay/oauth-types.js.map +1 -0
- package/dist/src/gate-pay/pay-token-store.d.ts +18 -0
- package/dist/src/gate-pay/pay-token-store.d.ts.map +1 -0
- package/dist/src/gate-pay/pay-token-store.js +134 -0
- package/dist/src/gate-pay/pay-token-store.js.map +1 -0
- package/dist/src/index.js +18 -631
- package/dist/src/index.js.map +1 -1
- package/dist/src/modes/build-pay-fetch.d.ts +3 -2
- package/dist/src/modes/build-pay-fetch.d.ts.map +1 -1
- package/dist/src/modes/build-pay-fetch.js +7 -14
- package/dist/src/modes/build-pay-fetch.js.map +1 -1
- package/dist/src/modes/local-private-key.d.ts.map +1 -1
- package/dist/src/modes/local-private-key.js +31 -10
- package/dist/src/modes/local-private-key.js.map +1 -1
- package/dist/src/modes/plugin-wallet.d.ts +12 -0
- package/dist/src/modes/plugin-wallet.d.ts.map +1 -1
- package/dist/src/modes/plugin-wallet.js +222 -20
- package/dist/src/modes/plugin-wallet.js.map +1 -1
- package/dist/src/modes/quick-wallet.d.ts.map +1 -1
- package/dist/src/modes/quick-wallet.js +13 -2
- package/dist/src/modes/quick-wallet.js.map +1 -1
- package/dist/src/modes/registry.d.ts.map +1 -1
- package/dist/src/modes/registry.js +4 -1
- package/dist/src/modes/registry.js.map +1 -1
- package/dist/src/modes/signers/index.d.ts +4 -0
- package/dist/src/modes/signers/index.d.ts.map +1 -0
- package/dist/src/modes/signers/index.js +4 -0
- package/dist/src/modes/signers/index.js.map +1 -0
- package/dist/src/modes/signers/local-private-key.d.ts +12 -0
- package/dist/src/modes/signers/local-private-key.d.ts.map +1 -0
- package/dist/src/modes/signers/local-private-key.js +44 -0
- package/dist/src/modes/signers/local-private-key.js.map +1 -0
- package/dist/src/modes/signers/plugin-wallet.d.ts +12 -0
- package/dist/src/modes/signers/plugin-wallet.d.ts.map +1 -0
- package/dist/src/modes/signers/plugin-wallet.js +114 -0
- package/dist/src/modes/signers/plugin-wallet.js.map +1 -0
- package/dist/src/modes/signers/quick-wallet.d.ts +16 -0
- package/dist/src/modes/signers/quick-wallet.d.ts.map +1 -0
- package/dist/src/modes/signers/quick-wallet.js +130 -0
- package/dist/src/modes/signers/quick-wallet.js.map +1 -0
- package/dist/src/modes/signers/shared-utils.d.ts +27 -0
- package/dist/src/modes/signers/shared-utils.d.ts.map +1 -0
- package/dist/src/modes/signers/shared-utils.js +230 -0
- package/dist/src/modes/signers/shared-utils.js.map +1 -0
- package/dist/src/modes/types.d.ts +16 -1
- package/dist/src/modes/types.d.ts.map +1 -1
- package/dist/src/tools/centralized-payment.d.ts +7 -0
- package/dist/src/tools/centralized-payment.d.ts.map +1 -0
- package/dist/src/tools/centralized-payment.js +76 -0
- package/dist/src/tools/centralized-payment.js.map +1 -0
- package/dist/src/tools/create-signature.d.ts +4 -0
- package/dist/src/tools/create-signature.d.ts.map +1 -0
- package/dist/src/tools/create-signature.js +82 -0
- package/dist/src/tools/create-signature.js.map +1 -0
- package/dist/src/tools/gate-pay-auth.d.ts +3 -0
- package/dist/src/tools/gate-pay-auth.d.ts.map +1 -0
- package/dist/src/tools/gate-pay-auth.js +40 -0
- package/dist/src/tools/gate-pay-auth.js.map +1 -0
- package/dist/src/tools/index.d.ts +10 -0
- package/dist/src/tools/index.d.ts.map +1 -0
- package/dist/src/tools/index.js +10 -0
- package/dist/src/tools/index.js.map +1 -0
- package/dist/src/tools/place-order.d.ts +3 -0
- package/dist/src/tools/place-order.d.ts.map +1 -0
- package/dist/src/tools/place-order.js +36 -0
- package/dist/src/tools/place-order.js.map +1 -0
- package/dist/src/tools/quick-wallet-auth.d.ts +6 -0
- package/dist/src/tools/quick-wallet-auth.d.ts.map +1 -0
- package/dist/src/tools/quick-wallet-auth.js +32 -0
- package/dist/src/tools/quick-wallet-auth.js.map +1 -0
- package/dist/src/tools/schemas.d.ts +225 -0
- package/dist/src/tools/schemas.d.ts.map +1 -0
- package/dist/src/tools/schemas.js +274 -0
- package/dist/src/tools/schemas.js.map +1 -0
- package/dist/src/tools/sign-payment.d.ts +4 -0
- package/dist/src/tools/sign-payment.d.ts.map +1 -0
- package/dist/src/tools/sign-payment.js +94 -0
- package/dist/src/tools/sign-payment.js.map +1 -0
- package/dist/src/tools/submit-payment.d.ts +3 -0
- package/dist/src/tools/submit-payment.d.ts.map +1 -0
- package/dist/src/tools/submit-payment.js +43 -0
- package/dist/src/tools/submit-payment.js.map +1 -0
- package/dist/src/tools/x402-request.d.ts +8 -0
- package/dist/src/tools/x402-request.d.ts.map +1 -0
- package/dist/src/tools/x402-request.js +65 -0
- package/dist/src/tools/x402-request.js.map +1 -0
- package/dist/src/utils/balance-check.d.ts +3 -0
- package/dist/src/utils/balance-check.d.ts.map +1 -0
- package/dist/src/utils/balance-check.js +40 -0
- package/dist/src/utils/balance-check.js.map +1 -0
- package/dist/src/utils/client-registry.d.ts +7 -0
- package/dist/src/utils/client-registry.d.ts.map +1 -0
- package/dist/src/utils/client-registry.js +34 -0
- package/dist/src/utils/client-registry.js.map +1 -0
- package/dist/src/utils/response-helpers.d.ts +8 -0
- package/dist/src/utils/response-helpers.d.ts.map +1 -0
- package/dist/src/utils/response-helpers.js +56 -0
- package/dist/src/utils/response-helpers.js.map +1 -0
- package/dist/src/utils/validation.d.ts +3 -0
- package/dist/src/utils/validation.d.ts.map +1 -0
- package/dist/src/utils/validation.js +34 -0
- package/dist/src/utils/validation.js.map +1 -0
- package/dist/src/wallets/device-flow-login.d.ts.map +1 -1
- package/dist/src/wallets/device-flow-login.js +1 -0
- package/dist/src/wallets/device-flow-login.js.map +1 -1
- package/dist/src/wallets/plugin-wallet-client.d.ts +8 -0
- package/dist/src/wallets/plugin-wallet-client.d.ts.map +1 -1
- package/dist/src/wallets/plugin-wallet-client.js +17 -0
- package/dist/src/wallets/plugin-wallet-client.js.map +1 -1
- package/dist/src/x402/exactSvmScheme.d.ts +20 -0
- package/dist/src/x402/exactSvmScheme.d.ts.map +1 -0
- package/dist/src/x402/exactSvmScheme.js +38 -0
- package/dist/src/x402/exactSvmScheme.js.map +1 -0
- package/dist/src/x402/fetch.d.ts.map +1 -1
- package/dist/src/x402/fetch.js +2 -0
- package/dist/src/x402/fetch.js.map +1 -1
- package/dist/src/x402/types.d.ts +5 -0
- package/dist/src/x402/types.d.ts.map +1 -1
- package/dist/src/x402/types.js +0 -3
- package/dist/src/x402/types.js.map +1 -1
- package/package.json +21 -8
- package/dist/src/modes/signers.d.ts +0 -40
- package/dist/src/modes/signers.d.ts.map +0 -1
- package/dist/src/modes/signers.js +0 -293
- package/dist/src/modes/signers.js.map +0 -1
package/Readme.md
CHANGED
|
@@ -1,32 +1,258 @@
|
|
|
1
1
|
# gatepay-local-mcp
|
|
2
2
|
|
|
3
|
-
`gatepay-local-mcp` is a local `stdio` MCP server for calling **
|
|
3
|
+
`gatepay-local-mcp` is a local `stdio` MCP server for calling **X402 payment-protected** HTTP endpoints. It provides a suite of MCP tools to handle the complete X402 payment workflow, from placing orders to signing payments and submitting them to merchants.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
- Built-in
|
|
9
|
-
- Multiple signing modes
|
|
7
|
+
- **7 MCP Tools** covering order placement, signature flows, quick wallet / Gate Pay auth, and centralized payment retries
|
|
8
|
+
- Built-in X402 payment flow under `src/x402/`
|
|
9
|
+
- **Multiple signing modes**: `local_private_key`, `quick_wallet`, `plugin_wallet`
|
|
10
|
+
- **Multi-chain support**: EVM (Ethereum, Base, Polygon, etc.) and Solana
|
|
10
11
|
- Works with Cursor, Claude Desktop, and other MCP clients
|
|
11
|
-
-
|
|
12
|
+
- Auto-selects the first ready signing mode if not specified
|
|
13
|
+
- Gate Pay centralized payment (`sign_mode: centralized_payment`) and `x402_centralized_payment` helper for merchant-side settlement
|
|
14
|
+
|
|
15
|
+
## Available Tools
|
|
16
|
+
|
|
17
|
+
### 1. `x402_place_order`
|
|
18
|
+
|
|
19
|
+
Send an HTTP request and return complete response information including headers, body, and the original request details.
|
|
20
|
+
|
|
21
|
+
**Use case**: Initial request to a payment-protected endpoint that returns `402 Payment Required`.
|
|
22
|
+
|
|
23
|
+
**Parameters**:
|
|
24
|
+
```typescript
|
|
25
|
+
{
|
|
26
|
+
url: string; // Target URL (required)
|
|
27
|
+
method?: string; // HTTP method: GET, POST, PUT, PATCH (default: POST)
|
|
28
|
+
body?: string; // JSON string request body (optional)
|
|
29
|
+
sign_mode?: string; // Signing mode: local_private_key, quick_wallet, plugin_wallet (auto-select if omitted)
|
|
30
|
+
wallet_login_provider?: string; // OAuth provider: google, gate (default: gate)
|
|
31
|
+
}
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
**Returns**: Complete response with status code, headers (including `PAYMENT-REQUIRED`), body, and original request details.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
### 2. `x402_sign_payment`
|
|
39
|
+
|
|
40
|
+
Parse X402 payment requirements, create a signed payment authorization, and submit the payment to complete a 402-protected request (all-in-one workflow).
|
|
41
|
+
|
|
42
|
+
**Use case**: Single-step payment flow - parse, sign, and submit in one call.
|
|
43
|
+
|
|
44
|
+
**Parameters**:
|
|
45
|
+
```typescript
|
|
46
|
+
{
|
|
47
|
+
url: string; // Target URL (required)
|
|
48
|
+
method?: string; // HTTP method (default: POST)
|
|
49
|
+
body?: string; // JSON request body (optional)
|
|
50
|
+
payment_required_header?: string; // Base64-encoded PAYMENT-REQUIRED header
|
|
51
|
+
response_body?: string; // Response body from 402 response (alternative to header)
|
|
52
|
+
sign_mode?: string; // Signing mode (auto-select if omitted)
|
|
53
|
+
wallet_login_provider?: string; // OAuth provider (default: gate)
|
|
54
|
+
}
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
**Returns**: Final response from the merchant after successful payment.
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
### 3. `x402_create_signature`
|
|
62
|
+
|
|
63
|
+
Parse X402 payment requirements and create a signed payment authorization.
|
|
64
|
+
|
|
65
|
+
**Use case**: Two-step workflow - create signature first, then submit separately.
|
|
66
|
+
|
|
67
|
+
**Parameters**:
|
|
68
|
+
```typescript
|
|
69
|
+
{
|
|
70
|
+
payment_required_header?: string; // Base64-encoded PAYMENT-REQUIRED header
|
|
71
|
+
response_body?: string; // Response body from 402 response (alternative to header)
|
|
72
|
+
sign_mode?: string; // Signing mode (auto-select if omitted)
|
|
73
|
+
wallet_login_provider?: string; // OAuth provider (default: gate)
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
**Returns**: Payment payload and base64-encoded `PAYMENT-SIGNATURE` header value.
|
|
78
|
+
|
|
79
|
+
---
|
|
80
|
+
|
|
81
|
+
### 4. `x402_submit_payment`
|
|
82
|
+
|
|
83
|
+
Submit a signed payment to complete a 402-protected request.
|
|
84
|
+
|
|
85
|
+
**Use case**: Second step of two-step workflow - submit the signature created by `x402_create_signature`.
|
|
86
|
+
|
|
87
|
+
**Parameters**:
|
|
88
|
+
```typescript
|
|
89
|
+
{
|
|
90
|
+
url: string; // Target URL (required)
|
|
91
|
+
method?: string; // HTTP method (default: POST)
|
|
92
|
+
body?: string; // JSON request body (optional)
|
|
93
|
+
payment_signature: string; // Base64-encoded PAYMENT-SIGNATURE from x402_create_signature (required)
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
**Returns**: Final response from the merchant.
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
### 5. `x402_quick_wallet_auth`
|
|
102
|
+
|
|
103
|
+
Pre-authorize with Quick Wallet using device-flow OAuth (Google or Gate account).
|
|
104
|
+
|
|
105
|
+
**Use case**: When using `sign_mode: quick_wallet`, run this first to complete the device-flow login before making payment requests.
|
|
106
|
+
|
|
107
|
+
**Parameters**:
|
|
108
|
+
```typescript
|
|
109
|
+
{
|
|
110
|
+
wallet_login_provider?: string; // OAuth provider: google, gate (default: gate)
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
**Returns**: Authorization status and wallet addresses (EVM and Solana).
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
### 6. `x402_gate_pay_auth`
|
|
119
|
+
|
|
120
|
+
Complete the Gate Pay OAuth device flow (browser authorize URL + localhost callback + remote token exchange) and cache the resulting access token/UID for centralized payments.
|
|
121
|
+
|
|
122
|
+
**Use case**: Required before calling `x402_submit_payment` with `sign_mode: centralized_payment` or when preparing to use `x402_centralized_payment`.
|
|
123
|
+
|
|
124
|
+
**Parameters**: _None_
|
|
125
|
+
|
|
126
|
+
**Returns**: Current authorization status with masked Gate Pay UID and access token indicators.
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
### 7. `x402_centralized_payment`
|
|
131
|
+
|
|
132
|
+
Parse the Base64-encoded `PAYMENT-REQUIRED` header and complete the Gate Pay centralized payment flow without submitting a `PAYMENT-SIGNATURE`.
|
|
133
|
+
|
|
134
|
+
**Use case**: When a merchant expects Gate Pay centralized settlement (e.g., OTA or off-chain marketplace) and you prefer an all-in-one helper instead of crafting `PAYMENT-SIGNATURE`.
|
|
135
|
+
|
|
136
|
+
**Parameters**:
|
|
137
|
+
```typescript
|
|
138
|
+
{
|
|
139
|
+
payment_required_header: string; // Base64-encoded PAYMENT-REQUIRED header (required)
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
**Returns**: Payment confirmation including `prepayId`, `merchantTradeNo`, currency, amount, and the raw API response.
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## Workflow Examples
|
|
148
|
+
|
|
149
|
+
### Single-Step Workflow (Recommended)
|
|
150
|
+
|
|
151
|
+
```
|
|
152
|
+
1. x402_place_order → Get payment requirements
|
|
153
|
+
2. x402_sign_payment → Sign and submit payment (all-in-one)
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
### Two-Step Workflow (Advanced)
|
|
157
|
+
|
|
158
|
+
```
|
|
159
|
+
1. x402_place_order → Get payment requirements
|
|
160
|
+
2. x402_create_signature → Create signed payment
|
|
161
|
+
3. x402_submit_payment → Submit signed payment
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
### Quick Wallet Pre-Auth
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
1. x402_quick_wallet_auth → Authorize with Google/Gate
|
|
168
|
+
2. x402_place_order → Get payment requirements
|
|
169
|
+
3. x402_sign_payment → Sign and submit (using quick_wallet)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Centralized Payment (Gate Pay)
|
|
173
|
+
|
|
174
|
+
```
|
|
175
|
+
1. x402_gate_pay_auth → Browser OAuth + token exchange (repeat when token expires)
|
|
176
|
+
2. x402_place_order → Receive PAYMENT-REQUIRED header that encodes Gate Pay order info
|
|
177
|
+
3. x402_submit_payment → Use payment_signature + sign_mode: "centralized_payment" to call the merchant with Authorization: Bearer
|
|
178
|
+
或
|
|
179
|
+
3. x402_centralized_payment → Pass payment_required_header directly for all-in-one centralized settlement
|
|
180
|
+
```
|
|
12
181
|
|
|
13
182
|
## Signing Modes
|
|
14
183
|
|
|
15
|
-
The server
|
|
184
|
+
The server supports three automatic signing modes plus a dedicated Gate Pay centralized mode:
|
|
16
185
|
|
|
17
|
-
| `sign_mode`
|
|
18
|
-
|
|
|
19
|
-
| `local_private_key`
|
|
20
|
-
| `quick_wallet`
|
|
21
|
-
| `plugin_wallet`
|
|
186
|
+
| `sign_mode` | Status | Networks / Scope | Description |
|
|
187
|
+
| ----------------------- | --------------------------------------------- | ---------------- | ----------------------------------------------------------------------------------------------- |
|
|
188
|
+
| `local_private_key` | Ready when `EVM_PRIVATE_KEY` / `SVM_PRIVATE_KEY` set | EVM, Solana | Signs locally with your private keys (no external dependencies) |
|
|
189
|
+
| `quick_wallet` | Ready after OAuth login | EVM, Solana | Custodial MCP wallet with device-flow login (Google/Gate account) |
|
|
190
|
+
| `plugin_wallet` | Ready when `PLUGIN_WALLET_TOKEN` set | EVM, Solana | Browser extension wallet (e.g., Gate Wallet) via MCP bridge |
|
|
191
|
+
| `centralized_payment` | Ready after `x402_gate_pay_auth` completes | Gate Pay | Adds `Authorization: Bearer <Gate Pay access_token>` when calling `x402_submit_payment` or use `x402_centralized_payment` |
|
|
22
192
|
|
|
23
|
-
|
|
193
|
+
**Priority Order** (auto-selection applies to the first three rows when `sign_mode` is omitted):
|
|
194
|
+
1. `plugin_wallet` (priority: 30) - if token configured
|
|
195
|
+
2. `quick_wallet` (priority: 20) - if MCP endpoint configured
|
|
196
|
+
3. `local_private_key` (priority: 10) - if private keys configured
|
|
197
|
+
|
|
198
|
+
The server automatically selects the highest-priority ready mode.
|
|
199
|
+
|
|
200
|
+
### Network Support
|
|
201
|
+
|
|
202
|
+
- **EVM Networks**: Ethereum, Base, Polygon, Arbitrum One, GateChain, GateLayer
|
|
203
|
+
- **Solana Networks**: Solana Mainnet, Solana Devnet
|
|
24
204
|
|
|
25
205
|
## Quick Start
|
|
26
206
|
|
|
27
|
-
###
|
|
207
|
+
### 1. Local Private Key Mode (EVM + Solana)
|
|
208
|
+
|
|
209
|
+
This is the simplest setup for local signing with your own private keys:
|
|
210
|
+
|
|
211
|
+
```json
|
|
212
|
+
{
|
|
213
|
+
"mcpServers": {
|
|
214
|
+
"gatepay-mcp": {
|
|
215
|
+
"command": "npx",
|
|
216
|
+
"args": ["-y", "gatepay-local-mcp"],
|
|
217
|
+
"env": {
|
|
218
|
+
"EVM_PRIVATE_KEY": "your-evm-private-key-hex-with-or-without-0x-prefix",
|
|
219
|
+
"SVM_PRIVATE_KEY": "your-solana-private-key-base58-optional"
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
- Set `EVM_PRIVATE_KEY` for EVM network payments (Ethereum, Base, Polygon, etc.)
|
|
227
|
+
- Set `SVM_PRIVATE_KEY` for Solana network payments (optional)
|
|
228
|
+
- Put this into your MCP config such as `~/.cursor/mcp.json`, then restart or reload MCP
|
|
229
|
+
|
|
230
|
+
### 2. Quick Wallet Mode (Custodial)
|
|
231
|
+
|
|
232
|
+
Remote wallet signing with device-flow OAuth (Google or Gate account):
|
|
233
|
+
|
|
234
|
+
```json
|
|
235
|
+
{
|
|
236
|
+
"mcpServers": {
|
|
237
|
+
"gatepay-mcp": {
|
|
238
|
+
"command": "npx",
|
|
239
|
+
"args": ["-y", "gatepay-local-mcp"],
|
|
240
|
+
"env": {
|
|
241
|
+
"QUICK_WALLET_MCP_URL": "https://walletmcp.gate.com/mcp",
|
|
242
|
+
"QUICK_WALLET_API_KEY": "your-api-key-optional"
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
- First payment will trigger device-flow login (opens browser)
|
|
250
|
+
- Token is persisted at `~/.gate-pay/auth.json`
|
|
251
|
+
- Use `x402_quick_wallet_auth` tool to pre-authorize
|
|
28
252
|
|
|
29
|
-
|
|
253
|
+
### 3. Plugin Wallet Mode (Browser Extension)
|
|
254
|
+
|
|
255
|
+
Sign with browser extension wallet (e.g., Gate Wallet):
|
|
30
256
|
|
|
31
257
|
```json
|
|
32
258
|
{
|
|
@@ -35,31 +261,44 @@ This is the simplest setup if you want local signing:
|
|
|
35
261
|
"command": "npx",
|
|
36
262
|
"args": ["-y", "gatepay-local-mcp"],
|
|
37
263
|
"env": {
|
|
38
|
-
"
|
|
264
|
+
"PLUGIN_WALLET_TOKEN": "your-plugin-wallet-mcp-token"
|
|
39
265
|
}
|
|
40
266
|
}
|
|
41
267
|
}
|
|
42
268
|
}
|
|
43
269
|
```
|
|
44
270
|
|
|
45
|
-
|
|
271
|
+
- Get the token from your browser extension wallet
|
|
272
|
+
- Requires the wallet extension to be installed and running
|
|
273
|
+
- User confirms transactions in the browser extension
|
|
46
274
|
|
|
47
|
-
###
|
|
275
|
+
### 4. Gate Pay Centralized Payment (Browser OAuth)
|
|
48
276
|
|
|
49
|
-
|
|
277
|
+
Use this when merchants expect Gate Pay centralized settlement instead of user-owned signatures.
|
|
50
278
|
|
|
51
279
|
```json
|
|
52
280
|
{
|
|
53
281
|
"mcpServers": {
|
|
54
282
|
"gatepay-mcp": {
|
|
55
283
|
"command": "npx",
|
|
56
|
-
"args": ["-y", "gatepay-local-mcp"]
|
|
284
|
+
"args": ["-y", "gatepay-local-mcp"],
|
|
285
|
+
"env": {
|
|
286
|
+
"GATE_PAY_OAUTH_CLIENT_ID": "your-gate-pay-client-id",
|
|
287
|
+
"GATE_PAY_OAUTH_CLIENT_SECRET": "your-gate-pay-client-secret",
|
|
288
|
+
"GATE_PAY_OAUTH_BACKEND_ORIGIN": "https://www.gate.com/apiw/v2/mcp/oauth",
|
|
289
|
+
"GATE_PAY_ACCOUNT_AUTHORIZE_ORIGIN": "https://gate.com",
|
|
290
|
+
"GATE_PAY_OAUTH_CALLBACK_PORT": "18473",
|
|
291
|
+
"GATE_PAY_CENTRALIZED_PAYMENT_URL": "https://api.gateio.ws/api/v4/pay/ai/order/pay",
|
|
292
|
+
"GATE_PAY_CLIENT_ID": "your-gate-pay-client-id"
|
|
293
|
+
}
|
|
57
294
|
}
|
|
58
295
|
}
|
|
59
296
|
}
|
|
60
297
|
```
|
|
61
298
|
|
|
62
|
-
|
|
299
|
+
- Run `x402_gate_pay_auth` once per token lifecycle; it opens the Gate consent page and exchanges the code automatically.
|
|
300
|
+
- Use `x402_submit_payment` with `sign_mode: "centralized_payment"` after you create a `PAYMENT-SIGNATURE`, or
|
|
301
|
+
- Call `x402_centralized_payment` directly with the Base64 `PAYMENT-REQUIRED` header when you prefer a single-step helper.
|
|
63
302
|
|
|
64
303
|
### Cursor / Claude Desktop with plugin wallet
|
|
65
304
|
|
|
@@ -90,15 +329,34 @@ Before using plugin wallet mode:
|
|
|
90
329
|
|
|
91
330
|
The server loads `.env` from the repository or package root at startup.
|
|
92
331
|
|
|
93
|
-
###
|
|
94
|
-
|
|
95
|
-
| Variable
|
|
96
|
-
|
|
|
97
|
-
| `EVM_PRIVATE_KEY`
|
|
98
|
-
| `
|
|
99
|
-
| `
|
|
100
|
-
|
|
101
|
-
|
|
332
|
+
### Signing Mode Configuration
|
|
333
|
+
|
|
334
|
+
| Variable | Mode | Description |
|
|
335
|
+
| ------------------------- | ------------------- | --------------------------------------------------------------------------- |
|
|
336
|
+
| `EVM_PRIVATE_KEY` | `local_private_key` | Local EVM private key; hex with or without `0x` prefix |
|
|
337
|
+
| `SVM_PRIVATE_KEY` | `local_private_key` | Local Solana private key; base58 encoded (optional) |
|
|
338
|
+
| `QUICK_WALLET_MCP_URL` | `quick_wallet` | MCP wallet endpoint URL (default: `https://walletmcp.gate.com/mcp`) |
|
|
339
|
+
| `QUICK_WALLET_API_KEY` | `quick_wallet` | API key for MCP wallet service (optional) |
|
|
340
|
+
| `PLUGIN_WALLET_TOKEN` | `plugin_wallet` | MCP token from browser extension wallet |
|
|
341
|
+
|
|
342
|
+
### Gate Pay Centralized Payment
|
|
343
|
+
|
|
344
|
+
| Variable | Description |
|
|
345
|
+
| --------------------------------- | --------------------------------------------------------------------------------------------- |
|
|
346
|
+
| `GATE_PAY_OAUTH_CLIENT_ID` | Gate Pay OAuth client id used for device authorization and token exchange |
|
|
347
|
+
| `GATE_PAY_OAUTH_CLIENT_SECRET` | Client secret required when exchanging the authorization code for an access token |
|
|
348
|
+
| `GATE_PAY_OAUTH_BACKEND_ORIGIN` | Base URL for the OAuth backend that hosts the token/refresh endpoints |
|
|
349
|
+
| `GATE_PAY_ACCOUNT_AUTHORIZE_ORIGIN` | Domain that serves the Gate Pay authorization page (opens in the browser) |
|
|
350
|
+
| `GATE_PAY_OAUTH_CALLBACK_PORT` | Local port used to receive the OAuth redirect (set to `0` for a random port if needed) |
|
|
351
|
+
| `GATE_PAY_OAUTH_SCOPE` | OAuth scope requested during device/login flow |
|
|
352
|
+
| `GATE_PAY_OAUTH_AUTHORIZE_USER_AGENT` | Custom User-Agent for the authorization preflight (defaults to `gateio/web`) |
|
|
353
|
+
| `GATE_PAY_CENTRALIZED_PAYMENT_URL`| HTTPS endpoint for submitting centralized payments via Gate Pay |
|
|
354
|
+
| `GATE_PAY_CLIENT_ID` | Merchant client id embedded in centralized payment payloads |
|
|
355
|
+
| `GATE_PAY_OAUTH_TOKEN_BASE_URL` | Optional: origin used to derive default token and refresh endpoints |
|
|
356
|
+
| `GATE_PAY_OAUTH_TOKEN_URL` | Optional: explicit token endpoint path override |
|
|
357
|
+
| `GATE_PAY_OAUTH_REFRESH_URL` | Optional: explicit refresh endpoint path override |
|
|
358
|
+
|
|
359
|
+
### Test and Script Variables
|
|
102
360
|
|
|
103
361
|
| Variable | Used By | Default | Description |
|
|
104
362
|
| ----------------------------- | ------------------------------- | ----------------------- | ----------------------------------------------- |
|
|
@@ -106,55 +364,101 @@ The server loads `.env` from the repository or package root at startup.
|
|
|
106
364
|
| `ENDPOINT_PATH` | `test/privateKey.ts` | `/flight/order` | Endpoint path appended to `RESOURCE_SERVER_URL` |
|
|
107
365
|
| `GATEPAY_MCP_TEST_TIMEOUT_MS` | `test/mcp-x402-request-tool.ts` | `180000` | Timeout for the MCP tool integration test |
|
|
108
366
|
|
|
109
|
-
##
|
|
367
|
+
## Usage Examples
|
|
110
368
|
|
|
111
|
-
###
|
|
369
|
+
### Example 1: Single-Step Payment (Recommended)
|
|
112
370
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
| `wallet_login_provider` | string | No | Login provider for `quick_wallet`: `google` or `gate`; default is `gate` |
|
|
371
|
+
```json
|
|
372
|
+
// Step 1: Place order to get payment requirements
|
|
373
|
+
{
|
|
374
|
+
"tool": "x402_place_order",
|
|
375
|
+
"arguments": {
|
|
376
|
+
"url": "https://api.example.com/order",
|
|
377
|
+
"method": "POST",
|
|
378
|
+
"body": "{\"flightId\":\"FL001\",\"uid\":\"100\"}"
|
|
379
|
+
}
|
|
380
|
+
}
|
|
124
381
|
|
|
125
|
-
|
|
382
|
+
// Step 2: If 402 response, sign and submit payment
|
|
383
|
+
{
|
|
384
|
+
"tool": "x402_sign_payment",
|
|
385
|
+
"arguments": {
|
|
386
|
+
"url": "https://api.example.com/order",
|
|
387
|
+
"method": "POST",
|
|
388
|
+
"body": "{\"flightId\":\"FL001\",\"uid\":\"100\"}",
|
|
389
|
+
"payment_required_header": "<base64-from-place_order>",
|
|
390
|
+
"sign_mode": "quick_wallet"
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
```
|
|
126
394
|
|
|
127
|
-
|
|
395
|
+
### Example 2: Two-Step Payment (Advanced)
|
|
128
396
|
|
|
129
397
|
```json
|
|
398
|
+
// Create signature first
|
|
130
399
|
{
|
|
131
|
-
"
|
|
400
|
+
"tool": "x402_create_signature",
|
|
401
|
+
"arguments": {
|
|
402
|
+
"payment_required_header": "<base64>",
|
|
403
|
+
"sign_mode": "local_private_key"
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
// Then submit separately
|
|
408
|
+
{
|
|
409
|
+
"tool": "x402_submit_payment",
|
|
410
|
+
"arguments": {
|
|
411
|
+
"url": "https://api.example.com/order",
|
|
412
|
+
"payment_signature": "<base64-from-create_signature>"
|
|
413
|
+
}
|
|
132
414
|
}
|
|
133
415
|
```
|
|
134
416
|
|
|
135
|
-
|
|
417
|
+
### Example 3: Quick Wallet with Pre-Auth
|
|
136
418
|
|
|
137
419
|
```json
|
|
420
|
+
// Pre-authorize (opens browser for OAuth)
|
|
138
421
|
{
|
|
139
|
-
"
|
|
140
|
-
"
|
|
141
|
-
|
|
142
|
-
|
|
422
|
+
"tool": "x402_quick_wallet_auth",
|
|
423
|
+
"arguments": {
|
|
424
|
+
"wallet_login_provider": "gate"
|
|
425
|
+
}
|
|
143
426
|
}
|
|
144
427
|
```
|
|
145
428
|
|
|
146
|
-
|
|
429
|
+
### Example 4: Gate Pay Centralized Payment
|
|
147
430
|
|
|
148
431
|
```json
|
|
432
|
+
// Step 1: Run OAuth (opens Gate authorize page)
|
|
433
|
+
{ "tool": "x402_gate_pay_auth", "arguments": {} }
|
|
434
|
+
|
|
435
|
+
// Step 2a: Use centralized helper
|
|
436
|
+
{
|
|
437
|
+
"tool": "x402_centralized_payment",
|
|
438
|
+
"arguments": {
|
|
439
|
+
"payment_required_header": "<base64-from-place_order>"
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// Step 2b: Or submit with sign_mode: centralized_payment
|
|
149
444
|
{
|
|
150
|
-
"
|
|
151
|
-
"
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
445
|
+
"tool": "x402_submit_payment",
|
|
446
|
+
"arguments": {
|
|
447
|
+
"url": "https://api.example.com/order",
|
|
448
|
+
"method": "POST",
|
|
449
|
+
"payment_signature": "<base64-from-create_signature>",
|
|
450
|
+
"sign_mode": "centralized_payment"
|
|
451
|
+
}
|
|
155
452
|
}
|
|
156
453
|
```
|
|
157
454
|
|
|
455
|
+
## Agent Skill
|
|
456
|
+
|
|
457
|
+
- `skills/SKILL.md` contains the `gatepay-x402` skill manifest and prompts so MCP-aware IDEs (Cursor, Claude Desktop, Codex CLI, etc.) know how to call every tool exposed by this server.
|
|
458
|
+
- `skills/gatepay-x402.md` (mirrored at `docs/gatepay-x402.md`) is a natural-language installation guide. Share that link with your AI host for a “one-click” experience: the host can follow the steps to download `gatepay-local-mcp`, register it in `mcpServers`, and copy the `gatepay-x402` skill into its skills directory automatically.
|
|
459
|
+
|
|
460
|
+
Tool names and arguments always match each tool’s MCP `inputSchema` on the server you connect to; check your client’s tool list if you ship a trimmed build.
|
|
461
|
+
|
|
158
462
|
## Development
|
|
159
463
|
|
|
160
464
|
```bash
|
|
@@ -191,15 +495,6 @@ npm run test:mcp-tool
|
|
|
191
495
|
|
|
192
496
|
If you already logged in before, the saved token in `~/.gate-pay/auth.json` will be reused. Otherwise the quick wallet flow may require interactive device login. You can increase the timeout with `GATEPAY_MCP_TEST_TIMEOUT_MS`.
|
|
193
497
|
|
|
194
|
-
## How It Works
|
|
195
|
-
|
|
196
|
-
1. The MCP client calls `x402_request`.
|
|
197
|
-
2. The server normalizes the input and selects a ready `sign_mode`.
|
|
198
|
-
3. The first request is sent to the target URL.
|
|
199
|
-
4. If the upstream returns `402 Payment Required`, the server parses the payment requirements.
|
|
200
|
-
5. The selected signer signs the payment payload.
|
|
201
|
-
6. The server retries the request with the payment header and returns the final response.
|
|
202
|
-
|
|
203
498
|
## License
|
|
204
499
|
|
|
205
500
|
MIT
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 环境配置管理模块
|
|
3
|
+
* 支持通过 GATE_PAY_ENV 环境变量在 test 和 prd 环境间切换
|
|
4
|
+
*/
|
|
5
|
+
export type Environment = "test" | "prd";
|
|
6
|
+
/**
|
|
7
|
+
* 环境配置接口
|
|
8
|
+
*/
|
|
9
|
+
export interface EnvironmentConfig {
|
|
10
|
+
oauthClientId: string;
|
|
11
|
+
oauthClientSecret: string;
|
|
12
|
+
oauthBackendOrigin: string;
|
|
13
|
+
accountAuthorizeOrigin: string;
|
|
14
|
+
oauthCallbackPort: number;
|
|
15
|
+
centralizedPaymentUrl: string;
|
|
16
|
+
paymentClientId: string;
|
|
17
|
+
quickWalletServerUrl: string;
|
|
18
|
+
pluginWalletServerUrl: string;
|
|
19
|
+
oauthScope: string;
|
|
20
|
+
oauthAuthorizeUserAgent: string;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 获取当前环境(test 或 prd)
|
|
24
|
+
* 默认为 prd
|
|
25
|
+
*/
|
|
26
|
+
export declare function getEnvironment(): Environment;
|
|
27
|
+
/**
|
|
28
|
+
* 获取最终环境配置
|
|
29
|
+
* 优先级:直接设置的环境变量 > GATE_PAY_ENV 预设配置 > 默认值
|
|
30
|
+
*/
|
|
31
|
+
export declare function getEnvConfig(): EnvironmentConfig;
|
|
32
|
+
//# sourceMappingURL=env-config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-config.d.ts","sourceRoot":"","sources":["../../../src/config/env-config.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,MAAM,WAAW,GAAG,MAAM,GAAG,KAAK,CAAC;AAEzC;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAEhC,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,kBAAkB,EAAE,MAAM,CAAC;IAC3B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,iBAAiB,EAAE,MAAM,CAAC;IAG1B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,eAAe,EAAE,MAAM,CAAC;IAGxB,oBAAoB,EAAE,MAAM,CAAC;IAC7B,qBAAqB,EAAE,MAAM,CAAC;IAG9B,UAAU,EAAE,MAAM,CAAC;IACnB,uBAAuB,EAAE,MAAM,CAAC;CACjC;AAkDD;;;GAGG;AACH,wBAAgB,cAAc,IAAI,WAAW,CAG5C;AAUD;;;GAGG;AACH,wBAAgB,YAAY,IAAI,iBAAiB,CAoChD"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 环境配置管理模块
|
|
3
|
+
* 支持通过 GATE_PAY_ENV 环境变量在 test 和 prd 环境间切换
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 测试环境配置
|
|
7
|
+
*/
|
|
8
|
+
const TEST_CONFIG = {
|
|
9
|
+
// OAuth 配置
|
|
10
|
+
oauthClientId: "mZ96D37oKk-HrWJc",
|
|
11
|
+
oauthClientSecret: "QcICEvHYl4zlqd27AD8Grw1s78ni989RK1t3igeRdN0=",
|
|
12
|
+
oauthBackendOrigin: "http://dev.halftrust.xyz/oauth2",
|
|
13
|
+
accountAuthorizeOrigin: "https://14099.gateio.tech",
|
|
14
|
+
oauthCallbackPort: 18473,
|
|
15
|
+
// 中心化支付
|
|
16
|
+
centralizedPaymentUrl: "http://dev.halftrust.xyz/payment-service/payment/gatepay/v2/pay/ai/order/pay",
|
|
17
|
+
paymentClientId: "mZ96D37oKk-HrWJc",
|
|
18
|
+
// 钱包服务
|
|
19
|
+
quickWalletServerUrl: "https://wallet-service-mcp-test.gateweb3.cc/mcp",
|
|
20
|
+
pluginWalletServerUrl: "https://walletmcp-test.gateweb3.cc/mcp",
|
|
21
|
+
// 其他配置
|
|
22
|
+
oauthScope: "read_profile",
|
|
23
|
+
oauthAuthorizeUserAgent: "gateio/web",
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* 生产环境配置
|
|
27
|
+
*/
|
|
28
|
+
const PRD_CONFIG = {
|
|
29
|
+
// OAuth 配置
|
|
30
|
+
oauthClientId: "kIWkpCQBJUPWNuDo",
|
|
31
|
+
oauthClientSecret: "u4tyiLBhryczzT_5XcmHLVYQkWYhCIbPH1ejtXqiuLs=",
|
|
32
|
+
oauthBackendOrigin: "https://www.gate.com/apiw/v2/mcp/oauth",
|
|
33
|
+
accountAuthorizeOrigin: "https://gate.com",
|
|
34
|
+
oauthCallbackPort: 18473,
|
|
35
|
+
// 中心化支付
|
|
36
|
+
centralizedPaymentUrl: "https://api.gateio.ws/api/v4/pay/ai/order/pay",
|
|
37
|
+
paymentClientId: "kIWkpCQBJUPWNuDo",
|
|
38
|
+
// 钱包服务
|
|
39
|
+
quickWalletServerUrl: "https://api.gatemcp.ai/mcp/dex",
|
|
40
|
+
pluginWalletServerUrl: "https://walletmcp.gate.com/mcp",
|
|
41
|
+
// 其他配置
|
|
42
|
+
oauthScope: "read_profile",
|
|
43
|
+
oauthAuthorizeUserAgent: "gateio/web",
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* 获取当前环境(test 或 prd)
|
|
47
|
+
* 默认为 prd
|
|
48
|
+
*/
|
|
49
|
+
export function getEnvironment() {
|
|
50
|
+
const env = process.env.GATE_PAY_ENV?.toLowerCase().trim();
|
|
51
|
+
return env === "test" ? "test" : "prd";
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 获取基础环境配置(根据 GATE_PAY_ENV)
|
|
55
|
+
*/
|
|
56
|
+
function getBaseConfig() {
|
|
57
|
+
const env = getEnvironment();
|
|
58
|
+
return env === "test" ? TEST_CONFIG : PRD_CONFIG;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* 获取最终环境配置
|
|
62
|
+
* 优先级:直接设置的环境变量 > GATE_PAY_ENV 预设配置 > 默认值
|
|
63
|
+
*/
|
|
64
|
+
export function getEnvConfig() {
|
|
65
|
+
const baseConfig = getBaseConfig();
|
|
66
|
+
return {
|
|
67
|
+
// OAuth 配置
|
|
68
|
+
oauthClientId: process.env.GATE_PAY_OAUTH_CLIENT_ID?.trim() || baseConfig.oauthClientId,
|
|
69
|
+
oauthClientSecret: process.env.GATE_PAY_OAUTH_CLIENT_SECRET?.trim() || baseConfig.oauthClientSecret,
|
|
70
|
+
oauthBackendOrigin: process.env.GATE_PAY_OAUTH_BACKEND_ORIGIN?.trim()?.replace(/\/$/, "") ||
|
|
71
|
+
baseConfig.oauthBackendOrigin,
|
|
72
|
+
accountAuthorizeOrigin: process.env.GATE_PAY_ACCOUNT_AUTHORIZE_ORIGIN?.trim()?.replace(/\/$/, "") ||
|
|
73
|
+
baseConfig.accountAuthorizeOrigin,
|
|
74
|
+
oauthCallbackPort: parseCallbackPort() ?? baseConfig.oauthCallbackPort,
|
|
75
|
+
// 中心化支付
|
|
76
|
+
centralizedPaymentUrl: process.env.GATE_PAY_CENTRALIZED_PAYMENT_URL?.trim() ||
|
|
77
|
+
baseConfig.centralizedPaymentUrl,
|
|
78
|
+
paymentClientId: process.env.GATE_PAY_CLIENT_ID?.trim() || baseConfig.paymentClientId,
|
|
79
|
+
// 钱包服务
|
|
80
|
+
quickWalletServerUrl: process.env.QUICK_WALLET_SERVER_URL?.trim() || baseConfig.quickWalletServerUrl,
|
|
81
|
+
pluginWalletServerUrl: process.env.PLUGIN_WALLET_SERVER_URL?.trim() || baseConfig.pluginWalletServerUrl,
|
|
82
|
+
// 其他配置
|
|
83
|
+
oauthScope: process.env.GATE_PAY_OAUTH_SCOPE?.trim() || baseConfig.oauthScope,
|
|
84
|
+
oauthAuthorizeUserAgent: process.env.GATE_PAY_OAUTH_AUTHORIZE_USER_AGENT?.trim() ||
|
|
85
|
+
baseConfig.oauthAuthorizeUserAgent,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 解析回调端口
|
|
90
|
+
*/
|
|
91
|
+
function parseCallbackPort() {
|
|
92
|
+
const portStr = process.env.GATE_PAY_OAUTH_CALLBACK_PORT?.trim();
|
|
93
|
+
if (!portStr)
|
|
94
|
+
return undefined;
|
|
95
|
+
const n = parseInt(portStr, 10);
|
|
96
|
+
return Number.isNaN(n) ? undefined : n;
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=env-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env-config.js","sourceRoot":"","sources":["../../../src/config/env-config.ts"],"names":[],"mappings":"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"}
|