mppx 0.4.1 → 0.4.3

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 (63) hide show
  1. package/CHANGELOG.md +266 -0
  2. package/README.md +30 -6
  3. package/dist/bin.js +2 -2
  4. package/dist/bin.js.map +1 -1
  5. package/dist/cli/account.d.ts +53 -0
  6. package/dist/cli/account.d.ts.map +1 -0
  7. package/dist/cli/account.js +156 -0
  8. package/dist/cli/account.js.map +1 -0
  9. package/dist/{cli.d.ts → cli/cli.d.ts} +4 -3
  10. package/dist/cli/cli.d.ts.map +1 -0
  11. package/dist/cli/cli.js +852 -0
  12. package/dist/cli/cli.js.map +1 -0
  13. package/dist/cli/config.d.ts +39 -0
  14. package/dist/cli/config.d.ts.map +1 -0
  15. package/dist/cli/config.js +30 -0
  16. package/dist/cli/config.js.map +1 -0
  17. package/dist/cli/internal.d.ts +16 -0
  18. package/dist/cli/internal.d.ts.map +1 -0
  19. package/dist/cli/internal.js +58 -0
  20. package/dist/cli/internal.js.map +1 -0
  21. package/dist/cli/plugins/index.d.ts +4 -0
  22. package/dist/cli/plugins/index.d.ts.map +1 -0
  23. package/dist/cli/plugins/index.js +4 -0
  24. package/dist/cli/plugins/index.js.map +1 -0
  25. package/dist/cli/plugins/plugin.d.ts +68 -0
  26. package/dist/cli/plugins/plugin.d.ts.map +1 -0
  27. package/dist/cli/plugins/plugin.js +4 -0
  28. package/dist/cli/plugins/plugin.js.map +1 -0
  29. package/dist/cli/plugins/stripe.d.ts +2 -0
  30. package/dist/cli/plugins/stripe.d.ts.map +1 -0
  31. package/dist/cli/plugins/stripe.js +118 -0
  32. package/dist/cli/plugins/stripe.js.map +1 -0
  33. package/dist/cli/plugins/tempo.d.ts +11 -0
  34. package/dist/cli/plugins/tempo.d.ts.map +1 -0
  35. package/dist/cli/plugins/tempo.js +706 -0
  36. package/dist/cli/plugins/tempo.js.map +1 -0
  37. package/dist/cli/utils.d.ts +93 -0
  38. package/dist/cli/utils.d.ts.map +1 -0
  39. package/dist/cli/utils.js +274 -0
  40. package/dist/cli/utils.js.map +1 -0
  41. package/dist/tempo/client/Methods.d.ts +1 -1
  42. package/dist/tempo/client/Session.d.ts +2 -2
  43. package/dist/tempo/internal/defaults.d.ts +1 -1
  44. package/dist/tempo/internal/defaults.js +1 -1
  45. package/package.json +12 -1
  46. package/src/bin.ts +2 -2
  47. package/src/cli/account.ts +157 -0
  48. package/src/{cli.test.ts → cli/cli.test.ts} +107 -51
  49. package/src/cli/cli.ts +907 -0
  50. package/src/cli/config.test.ts +82 -0
  51. package/src/cli/config.ts +44 -0
  52. package/src/cli/internal.ts +72 -0
  53. package/src/cli/plugins/index.ts +3 -0
  54. package/src/cli/plugins/plugin.ts +73 -0
  55. package/src/cli/plugins/stripe.ts +143 -0
  56. package/src/cli/plugins/tempo.ts +842 -0
  57. package/src/cli/utils.ts +336 -0
  58. package/src/tempo/internal/defaults.test.ts +1 -1
  59. package/src/tempo/internal/defaults.ts +1 -1
  60. package/dist/cli.d.ts.map +0 -1
  61. package/dist/cli.js +0 -1992
  62. package/dist/cli.js.map +0 -1
  63. package/src/cli.ts +0 -2178
package/CHANGELOG.md ADDED
@@ -0,0 +1,266 @@
1
+ # mppx
2
+
3
+ ## 0.4.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 7f8d103: chore: update mainnet escrow contract address
8
+
9
+ ## 0.4.2
10
+
11
+ ### Patch Changes
12
+
13
+ - c089da5: Added CLI config via `mppx.config.(js|mjs|ts)`. Allows for extending `mppx` CLI to support non-built-in methods.
14
+
15
+ ## 0.4.1
16
+
17
+ ### Patch Changes
18
+
19
+ - f2bc051: Support keychain V2 (`0x04`) signatures via ox 0.14 upgrade
20
+
21
+ ## 0.4.0
22
+
23
+ ### Minor Changes
24
+
25
+ - 143ebc9: Support handler function refs in `compose()`.
26
+
27
+ - **`[mppx.tempo.charge, { amount: '1' }]` syntax** — `compose()` now accepts handler function references (e.g. `mppx.tempo.charge`) as the first element of entry tuples, in addition to `Method.AnyServer` objects and `"name/intent"` string keys.
28
+ - **`_method` metadata on nested handlers** — nested handler functions are tagged with their source `Method.AnyServer`, enabling `compose()` to resolve the correct handler.
29
+
30
+ ### Patch Changes
31
+
32
+ - db2033c: Set `feeToken` during server co-sign and simulation for fee-payer transactions.
33
+
34
+ When the client sends a fee-payer (0x78) envelope, `feeToken` is intentionally omitted. The server must set it at co-sign time, but previously never did — causing "Fee token spending limit exceeded" errors. Now resolves `feeToken` from the deserialized transaction or falls back to the chain's default currency.
35
+
36
+ ## 0.3.16
37
+
38
+ ### Patch Changes
39
+
40
+ - 79bbfc6: Added multi-challenge `mppx.challenge()` combinator for presenting multiple payment methods in a single 402 response, nested accessors (`mppx.tempo.charge(...)`), `Mppx.challenge()` static, `Challenge.fromResponseList()`, and automatic client preference-based challenge selection.
41
+ - b4f3c92: Migrated to use `call` instead of manual `eth_estimateGas`.
42
+
43
+ ## 0.3.15
44
+
45
+ ### Patch Changes
46
+
47
+ - cd42c28: Added `rawFetch` property to the client `Mppx` instance, exposing the original unwrapped fetch function for requests that should bypass 402 payment interception.
48
+ - 230ef16: Moved CLI payment logs (Payment Required, Payment Receipt, channel open/close) behind `-v` flag. Added `-vv` for full HTTP headers.
49
+
50
+ ## 0.3.14
51
+
52
+ ### Patch Changes
53
+
54
+ - 345425f: Removed `expires` from charge request schemas (tempo, stripe). Expiry is now conveyed exclusively via the `expires` auth-param on the Challenge, not duplicated in the request body. Server handlers default to `Expires.minutes(5)` when `expires` is not explicitly provided.
55
+ - eb19f32: Added `mode` parameter to `tempo.charge()` client — `'push'` (client broadcasts tx, sends hash) and `'pull'` (client signs tx, server broadcasts). Defaults to `'push'` for JSON-RPC accounts, `'pull'` otherwise.
56
+
57
+ ## 0.3.13
58
+
59
+ ### Patch Changes
60
+
61
+ - 82206f5: Made `constantTimeEqual` isomorphic by replacing `node:crypto` with `ox` sha256 and a custom constant-time comparison.
62
+
63
+ ## 0.3.12
64
+
65
+ ### Patch Changes
66
+
67
+ - c28944e: Added `autoSwap` flag to `tempo` method. When enabled, the client automatically swaps from supported currencies via the DEX if the payer lacks the target token.
68
+ - 9c23cb7: Fixed fetch polyfill to pass `init` through unmodified for non-402 responses. Previously, every request eagerly destructured `init` to strip the `context` property, creating a new object that could break libraries relying on object identity (e.g. WebSocket upgrade handshakes).
69
+
70
+ ## 0.3.11
71
+
72
+ ### Patch Changes
73
+
74
+ - fd466c3: Added `waitForConfirmation` option to `session()` and `charge()` payment methods. When `false`, transactions are simulated via `eth_estimateGas` and broadcast without waiting for on-chain confirmation, reducing latency.
75
+ - ddb7057: Fixed `Handlers` type to omit shorthand intent keys when multiple methods share the same intent, matching runtime behavior and preventing `TypeError` on collision.
76
+
77
+ ## 0.3.10
78
+
79
+ ### Patch Changes
80
+
81
+ - 558279e: Added `closeRequestedAt` check in session voucher handler with configurable `channelStateTtl` (default: 60s). Prevented payers from using a channel after initiating a forced close.
82
+ - 558279e: Added expiration check on credentials in the core handler. Expired credentials are now rejected with `PaymentExpiredError` instead of being processed.
83
+ - 558279e: Added token address validation in `broadcastTopUpTransaction` fee-payer logic. Prevented approve calls to arbitrary contracts in fee-sponsored topUp transactions.
84
+ - 558279e: Bound credential verification to the route's configured request. Prevented cross-route scope confusion where a credential issued for one route could be presented at another.
85
+ - 558279e: Removed insecure hardcoded `'tmp'` fallback for `secretKey`. `Mppx.create()` now throws a clear error if neither `MPP_SECRET_KEY` env var nor explicit `secretKey` is provided.
86
+ - 5d4bb93: Removed `realm` from `PaymentRequiredError` detail message to avoid leaking deployment URLs and hostnames in error responses.
87
+
88
+ ## 0.3.9
89
+
90
+ ### Patch Changes
91
+
92
+ - a016e1f: Added fee payer support to `settleOnChain` and `closeOnChain` for server-originated transactions on chains where the server EOA has no native tokens. Transactions are built using `prepareTransactionRequest` → dual-sign → `sendRawTransactionSync` with an explicitly resolved fee token.
93
+
94
+ ## 0.3.8
95
+
96
+ ### Patch Changes
97
+
98
+ - 7cb0d5f: Fixed CLI failing with "No account found" when `MPPX_PRIVATE_KEY` is set to an empty string.
99
+
100
+ ## 0.3.7
101
+
102
+ ### Patch Changes
103
+
104
+ - e4f0138: Added `nonceKey: 'expiring'` to tempo charge transactions to avoid nonce collisions on parallel requests.
105
+
106
+ ## 0.3.6
107
+
108
+ ### Patch Changes
109
+
110
+ - d2fb5e3: Fixed issue where mainnet would not default to USDC unless `testnet: false` was explicitly passed.
111
+
112
+ ## 0.3.5
113
+
114
+ ### Patch Changes
115
+
116
+ - 6e2be11: Replaced `--channel <id>` and `--deposit <amount>` CLI flags with `-M`/`--method-opt` for passing method-specific options.
117
+
118
+ ```diff
119
+ # Before
120
+ - mppx example.com/content --channel 0x123 --deposit 1000000
121
+
122
+ # After
123
+ + mppx example.com/content -M channel=0x123 -M deposit=1000000
124
+ ```
125
+
126
+ - 6e2be11: Added Stripe payment method support to the CLI.
127
+
128
+ ```bash
129
+ # Set your Stripe test-mode secret key
130
+ export MPPX_STRIPE_SECRET_KEY=sk_test_...
131
+
132
+ # Make a request to a Stripe-enabled endpoint
133
+ mppx https://example.com/content
134
+ ```
135
+
136
+ - 955deb2: Renamed USDC.e to USDC in account view token list.
137
+
138
+ ## 0.3.4
139
+
140
+ ### Patch Changes
141
+
142
+ - 9cf4943: Added USDC.e to account view mainnet token list and use `MPPX_RPC_URL` for default mainnet balance fetching.
143
+ - 11c0422: Renamed internal `stream` terminology to `session` to align with the MPP spec. This includes renaming the `src/tempo/stream/` directory to `src/tempo/session/`, updating all problem type URIs from `…/problems/stream/…` to `…/problems/session/…`, and renaming associated types (e.g., `StreamCredentialPayload` → `SessionCredentialPayload`). No public API changes.
144
+
145
+ ## 0.3.3
146
+
147
+ ### Patch Changes
148
+
149
+ - 04b04c9: Added auto-detection of `realm` and `secretKey` from environment variables in `Mppx.create()`.
150
+
151
+ - **Realm**: checks `MPP_REALM`, `FLY_APP_NAME`, `HEROKU_APP_NAME`, `HOST`, `HOSTNAME`, `RAILWAY_PUBLIC_DOMAIN`, `RENDER_EXTERNAL_HOSTNAME`, `VERCEL_URL`, `WEBSITE_HOSTNAME`
152
+ - **Secret key**: checks `MPP_SECRET_KEY`
153
+
154
+ ## 0.3.2
155
+
156
+ ### Patch Changes
157
+
158
+ - b927c06: - `mppx/proxy`: Modified routes to show service in path for completeness (e.g. `POST /openai/v1/chat/completions` instead of `POST /v1/chat/completions`).
159
+
160
+ ## 0.3.1
161
+
162
+ ### Patch Changes
163
+
164
+ - e6c9f85: Fixed `/discover.md` route returning 404.
165
+
166
+ ## 0.3.0
167
+
168
+ ### Minor Changes
169
+
170
+ - d60f623: - **`mpp/proxy` (Breaking):** Renamed `/services*` discovery routes to `/discover*`.
171
+ - `mpp/proxy`: Simplified `llms.txt` to a brief service overview, linking each service to `/discover/<id>`.
172
+ - `mpp/proxy`: Added `/discover` and `/discover/<id>` endpoints with content negotiation (JSON by default, markdown for `Accept: text/markdown`/`text/plain` or bot/CLI user agents).
173
+ - `mpp/proxy`: Added `.md` extension variants (`/discover.md`, `/discover/<id>.md`) for explicit markdown.
174
+ - `mpp/proxy`: Added `/discover/all` for full markdown listing with route details.
175
+
176
+ ## 0.2.6
177
+
178
+ ### Patch Changes
179
+
180
+ - 83c3bab: - Added `title` and `description` options to `Proxy.create` config, used to populate the `llms.txt` heading and description.
181
+
182
+ ```ts
183
+ const proxy = Proxy.create({
184
+ title: 'My AI Gateway',
185
+ description: 'A paid proxy for LLM and AI services.',
186
+ services: [...]
187
+ })
188
+ ```
189
+
190
+ - Added `title`, `description`, and `docsLlmsUrl` properties to `Service` type and `Service.from` config.
191
+
192
+ ```ts
193
+ Service.from('my-api', {
194
+ baseUrl: 'https://api.example.com',
195
+ title: 'My API',
196
+ description: 'A custom API service.',
197
+ docsLlmsUrl: 'https://example.com/llms.txt',
198
+ routes: { ... },
199
+ })
200
+
201
+ // or with per-endpoint docs
202
+ Service.from('my-api', {
203
+ baseUrl: 'https://api.example.com',
204
+ docsLlmsUrl: (endpoint) =>
205
+ endpoint
206
+ ? `https://example.com/api/${encodeURIComponent(endpoint)}.md`
207
+ : 'https://example.com/llms.txt',
208
+ routes: { ... },
209
+ })
210
+ ```
211
+
212
+ ## 0.2.5
213
+
214
+ ### Patch Changes
215
+
216
+ - 01fa8ba: Added fallback `authorizedSigner` to `account.accessKeyAddress` when not explicitly provided.
217
+
218
+ ## 0.2.4
219
+
220
+ ### Patch Changes
221
+
222
+ - 83d0175: Bumped `viem` peer dependency to `>=2.46.2`.
223
+
224
+ ## 0.2.3
225
+
226
+ ### Patch Changes
227
+
228
+ - c0aa6ad: Fixed Stripe `createWithClient` to use `shared_payment_granted_token` instead of `payment_method` when creating a PaymentIntent with an SPT. This aligns the SDK client path with the raw fetch path and fixes 402 errors on credential retry.
229
+ - e7f5985: Rejected keychain and non-secp256k1 signatures in `verifyVoucher`.
230
+
231
+ ## 0.2.2
232
+
233
+ ### Patch Changes
234
+
235
+ - 360fc03: Added `Json.canonicalize` from `ox`
236
+
237
+ ## 0.2.1
238
+
239
+ ### Patch Changes
240
+
241
+ - eb72c76: **Breaking:**
242
+ - Renamed `Challenge.fromIntent` to `Challenge.fromMethod`.
243
+ - Renamed `PaymentRequest.fromIntent` to `PaymentRequest.fromMethod`.
244
+
245
+ ## 0.2.0
246
+
247
+ ### Minor Changes
248
+
249
+ - 627f5ec: **Breaking:**
250
+
251
+ - Renamed `Intent` and `MethodIntent` modules to `Method`.
252
+ - Removed `Intent` export from `mppx`. Use `Method` instead.
253
+ - Removed `MethodIntent` export from `mppx`. Use `Method` instead.
254
+ - Renamed `MethodIntents` export to `Methods` in `mppx/tempo` and `mppx/stripe`.
255
+
256
+ ## 0.1.1
257
+
258
+ ### Patch Changes
259
+
260
+ - 910102d: Fixed SSE streaming reliability: pass `signal` through `SessionManager.sse()` so HTTP connections close on abort, snapshot challenge at SSE open time to prevent concurrent requests from corrupting voucher credentials, and forward `request.signal` to `Sse.serve()` so `chargeOrWait` breaks on disconnect.
261
+
262
+ ## 0.1.0
263
+
264
+ ### Minor Changes
265
+
266
+ - badab1a: Initial release.
package/README.md CHANGED
@@ -1,9 +1,33 @@
1
- # mppx
2
-
3
- TypeScript SDK for the [**Machine Payments Protocol**](https://mpp.dev)
4
-
5
- [![npm](https://img.shields.io/npm/v/mppx.svg)](https://www.npmjs.com/package/mppx)
6
- [![License](https://img.shields.io/npm/l/mppx.svg)](LICENSE)
1
+ <picture>
2
+ <source media="(prefers-color-scheme: dark)" srcset=".github/logo-dark.svg">
3
+ <source media="(prefers-color-scheme: light)" srcset=".github/logo-light.svg">
4
+ <img alt="mppx" src=".github/logo-light.svg" width="100%" height="100px">
5
+ </picture>
6
+
7
+ <p></p>
8
+
9
+ <p align="center"><b>TypeScript SDK for the <a href="https://mpp.dev">Machine Payments Protocol</a></b></p>
10
+
11
+ <p align="center">
12
+ <a href="https://mpp.dev/sdk/typescript">Documentation</a> · <a href="#install">Install</a> · <a href="#quick-start">Quick Start</a> · <a href="#examples">Examples</a> · <a href="#cli">CLI</a> · <a href="#payments-proxy">Payments Proxy</a> · <a href="https://github.com/tempoxyz/mpp-specs">Protocol</a>
13
+ </p>
14
+
15
+ <p align="center">
16
+ <a href="https://www.npmjs.com/package/mppx">
17
+ <picture>
18
+ <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/v/mppx?colorA=21262d&colorB=21262d&style=flat">
19
+ <img src="https://img.shields.io/npm/v/mppx?colorA=f6f8fa&colorB=f6f8fa&style=flat" alt="Version">
20
+ </picture>
21
+ </a>
22
+ <a href="https://github.com/wevm/mppx/blob/main/LICENSE">
23
+ <picture>
24
+ <source media="(prefers-color-scheme: dark)" srcset="https://img.shields.io/npm/l/mppx?colorA=21262d&colorB=21262d&style=flat">
25
+ <img src="https://img.shields.io/npm/l/mppx?colorA=f6f8fa&colorB=f6f8fa&style=flat" alt="MIT License">
26
+ </picture>
27
+ </a>
28
+ </p>
29
+
30
+ ---
7
31
 
8
32
  ## Documentation
9
33
 
package/dist/bin.js CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import cli from './cli.js';
3
- cli.serve();
2
+ import cli from './cli/cli.js';
3
+ cli.serve().then(() => process.exit(0));
4
4
  //# sourceMappingURL=bin.js.map
package/dist/bin.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA,OAAO,GAAG,MAAM,UAAU,CAAA;AAE1B,GAAG,CAAC,KAAK,EAAE,CAAA"}
1
+ {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";AACA,OAAO,GAAG,MAAM,cAAc,CAAA;AAE9B,GAAG,CAAC,KAAK,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA"}
@@ -0,0 +1,53 @@
1
+ export declare function execCommand(command: string, args: string[]): Promise<{
2
+ stdout: string;
3
+ stderr: string;
4
+ error: Error | null;
5
+ }>;
6
+ export declare function createDefaultStore(): {
7
+ get(): string;
8
+ set(value: string): void;
9
+ clear(): void;
10
+ };
11
+ export declare function resolveAccountName(explicit?: string): string;
12
+ export declare function createKeychain(account?: string): {
13
+ list(): Promise<string[]>;
14
+ get(): Promise<string | undefined>;
15
+ set(value: string): Promise<void>;
16
+ delete(): Promise<void>;
17
+ };
18
+ /**
19
+ * Resolve a CLI account to a viem `LocalAccount`.
20
+ *
21
+ * Resolution order:
22
+ * 1. `MPPX_PRIVATE_KEY` environment variable
23
+ * 2. OS keychain lookup for the named account
24
+ *
25
+ * @example
26
+ * ```ts
27
+ * import { resolveAccount } from 'mppx/cli'
28
+ * import { tempo } from 'mppx/client'
29
+ *
30
+ * export default defineConfig({
31
+ * methods: [tempo({ account: await resolveAccount() })],
32
+ * })
33
+ * ```
34
+ */
35
+ export declare function resolveAccount(name?: string): Promise<{
36
+ address: import("viem/accounts").Address;
37
+ nonceManager?: import("viem/accounts").NonceManager | undefined;
38
+ sign: (parameters: {
39
+ hash: import("viem").Hash;
40
+ }) => Promise<import("viem").Hex>;
41
+ signAuthorization: (parameters: import("viem").AuthorizationRequest) => Promise<import("viem/accounts").SignAuthorizationReturnType>;
42
+ signMessage: ({ message }: {
43
+ message: import("viem").SignableMessage;
44
+ }) => Promise<import("viem").Hex>;
45
+ signTransaction: <serializer extends import("viem").SerializeTransactionFn<import("viem").TransactionSerializable> = import("viem").SerializeTransactionFn<import("viem").TransactionSerializable>, transaction extends Parameters<serializer>[0] = Parameters<serializer>[0]>(transaction: transaction, options?: {
46
+ serializer?: serializer | undefined;
47
+ } | undefined) => Promise<import("viem").Hex>;
48
+ signTypedData: <const typedData extends import("viem").TypedData | Record<string, unknown>, primaryType extends keyof typedData | "EIP712Domain" = keyof typedData>(parameters: import("viem").TypedDataDefinition<typedData, primaryType>) => Promise<import("viem").Hex>;
49
+ publicKey: import("viem").Hex;
50
+ source: "privateKey";
51
+ type: "local";
52
+ }>;
53
+ //# sourceMappingURL=account.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../src/cli/account.ts"],"names":[],"mappings":"AAOA,wBAAgB,WAAW,CACzB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EAAE,GACb,OAAO,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;CAAE,CAAC,CAMlE;AAED,wBAAgB,kBAAkB;WAOvB,MAAM;eAOF,MAAM,GAAG,IAAI;aAIf,IAAI;EAMhB;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAI5D;AAGD,wBAAgB,cAAc,CAAC,OAAO,SAAS;YAG7B,OAAO,CAAC,MAAM,EAAE,CAAC;WAyBlB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;eAYvB,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;cAsBvB,OAAO,CAAC,IAAI,CAAC;EAahC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,cAAc,CAAC,IAAI,CAAC,EAAE,MAAM;;;;;;;;;;oTAxFhB,CAAC;kBAAsB,CAAC;;;;;;GAmGzD"}
@@ -0,0 +1,156 @@
1
+ import * as child from 'node:child_process';
2
+ import * as fs from 'node:fs';
3
+ import * as os from 'node:os';
4
+ import * as path from 'node:path';
5
+ const SERVICE_NAME = 'mppx';
6
+ export function execCommand(command, args) {
7
+ return new Promise((resolve) => {
8
+ child.execFile(command, args, (error, stdout, stderr) => {
9
+ resolve({ stdout: stdout.trim(), stderr: stderr.trim(), error });
10
+ });
11
+ });
12
+ }
13
+ export function createDefaultStore() {
14
+ const configPath = path.join(process.env.XDG_CONFIG_HOME || path.join(os.homedir(), '.config'), 'mppx', 'default');
15
+ return {
16
+ get() {
17
+ try {
18
+ return fs.readFileSync(configPath, 'utf-8').trim() || 'main';
19
+ }
20
+ catch {
21
+ return 'main';
22
+ }
23
+ },
24
+ set(value) {
25
+ fs.mkdirSync(path.dirname(configPath), { recursive: true });
26
+ fs.writeFileSync(configPath, value, 'utf-8');
27
+ },
28
+ clear() {
29
+ try {
30
+ fs.unlinkSync(configPath);
31
+ }
32
+ catch { }
33
+ },
34
+ };
35
+ }
36
+ export function resolveAccountName(explicit) {
37
+ if (explicit)
38
+ return explicit;
39
+ if (process.env.MPPX_ACCOUNT?.trim())
40
+ return process.env.MPPX_ACCOUNT;
41
+ return createDefaultStore().get();
42
+ }
43
+ // biome-ignore format: compact shell commands
44
+ export function createKeychain(account = 'main') {
45
+ const service = SERVICE_NAME;
46
+ return {
47
+ async list() {
48
+ const platform = os.platform();
49
+ if (platform === 'darwin') {
50
+ const { stdout, error } = await execCommand('security', ['dump-keychain']);
51
+ if (error)
52
+ return [];
53
+ const accounts = [];
54
+ const blocks = stdout.split('keychain:');
55
+ for (const block of blocks) {
56
+ const serviceMatch = block.match(/"svce"<blob>="([^"]*)"/);
57
+ const accountMatch = block.match(/"acct"<blob>="([^"]*)"/);
58
+ if (serviceMatch?.[1] === service && accountMatch?.[1])
59
+ accounts.push(accountMatch[1]);
60
+ }
61
+ return accounts;
62
+ }
63
+ if (platform === 'linux') {
64
+ const { stdout, stderr, error } = await execCommand('secret-tool', ['search', '--all', '--unlock', 'service', service]);
65
+ if (error)
66
+ return [];
67
+ const combined = `${stdout}\n${stderr}`;
68
+ const accounts = [];
69
+ const matches = combined.matchAll(/\baccount = (.+)/g);
70
+ for (const match of matches)
71
+ if (match[1])
72
+ accounts.push(match[1]);
73
+ return accounts;
74
+ }
75
+ throw new Error(`Unsupported platform: ${platform}`);
76
+ },
77
+ async get() {
78
+ const platform = os.platform();
79
+ if (platform === 'darwin') {
80
+ const { stdout, error } = await execCommand('security', ['find-generic-password', '-s', service, '-a', account, '-w']);
81
+ return error ? undefined : stdout;
82
+ }
83
+ if (platform === 'linux') {
84
+ const { stdout, error } = await execCommand('secret-tool', ['lookup', 'service', service, 'account', account]);
85
+ return error ? undefined : stdout || undefined;
86
+ }
87
+ throw new Error(`Unsupported platform: ${platform}`);
88
+ },
89
+ async set(value) {
90
+ const platform = os.platform();
91
+ if (platform === 'darwin') {
92
+ await execCommand('security', ['delete-generic-password', '-s', service, '-a', account]);
93
+ const { error } = await execCommand('security', ['add-generic-password', '-s', service, '-a', account, '-w', value]);
94
+ if (error)
95
+ throw error;
96
+ return;
97
+ }
98
+ if (platform === 'linux') {
99
+ const proc = child.execFile('secret-tool', ['store', '--label', `${service} ${account}`, 'service', service, 'account', account]);
100
+ proc.stdin?.write(value);
101
+ proc.stdin?.end();
102
+ return new Promise((resolve, reject) => {
103
+ proc.on('close', (code) => {
104
+ if (code === 0)
105
+ resolve();
106
+ else
107
+ reject(new Error(`secret-tool exited with code ${code}`));
108
+ });
109
+ proc.on('error', reject);
110
+ });
111
+ }
112
+ throw new Error(`Unsupported platform: ${platform}`);
113
+ },
114
+ async delete() {
115
+ const platform = os.platform();
116
+ if (platform === 'darwin') {
117
+ await execCommand('security', ['delete-generic-password', '-s', service, '-a', account]);
118
+ return;
119
+ }
120
+ if (platform === 'linux') {
121
+ await execCommand('secret-tool', ['clear', 'service', service, 'account', account]);
122
+ return;
123
+ }
124
+ throw new Error(`Unsupported platform: ${platform}`);
125
+ },
126
+ };
127
+ }
128
+ /**
129
+ * Resolve a CLI account to a viem `LocalAccount`.
130
+ *
131
+ * Resolution order:
132
+ * 1. `MPPX_PRIVATE_KEY` environment variable
133
+ * 2. OS keychain lookup for the named account
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * import { resolveAccount } from 'mppx/cli'
138
+ * import { tempo } from 'mppx/client'
139
+ *
140
+ * export default defineConfig({
141
+ * methods: [tempo({ account: await resolveAccount() })],
142
+ * })
143
+ * ```
144
+ */
145
+ export async function resolveAccount(name) {
146
+ const { privateKeyToAccount } = await import('viem/accounts');
147
+ const envKey = process.env.MPPX_PRIVATE_KEY?.trim();
148
+ if (envKey)
149
+ return privateKeyToAccount(envKey);
150
+ const accountName = resolveAccountName(name);
151
+ const key = await createKeychain(accountName).get();
152
+ if (key)
153
+ return privateKeyToAccount(key);
154
+ throw new Error(`Account "${accountName}" not found.`);
155
+ }
156
+ //# sourceMappingURL=account.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../../src/cli/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,oBAAoB,CAAA;AAC3C,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,EAAE,MAAM,SAAS,CAAA;AAC7B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAA;AAEjC,MAAM,YAAY,GAAG,MAAM,CAAA;AAE3B,MAAM,UAAU,WAAW,CACzB,OAAe,EACf,IAAc;IAEd,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,KAAK,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,K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Agent: string;
8
11
  verbose: number;
9
12
  account?: string | undefined;
10
- confirm?: boolean | undefined;
13
+ config?: string | undefined;
11
14
  data?: string | undefined;
12
15
  fail?: boolean | undefined;
13
16
  header?: string[] | undefined;
@@ -18,8 +21,6 @@ declare const cli: Cli.Cli<{
18
21
  method?: string | undefined;
19
22
  methodOpt?: string[] | undefined;
20
23
  rpcUrl?: string | undefined;
21
- silent?: boolean | undefined;
22
- userAgent?: string | undefined;
23
24
  };
24
25
  };
25
26
  }, undefined, undefined>;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli/cli.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,GAAG,EAAa,MAAM,OAAO,CAAA;AAkCtC,QAAA,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;wBAuaP,CAAA;AA8bF,eAAe,GAAG,CAAA"}