@cmdoss/suipay-mcp 0.2.2-dev.6 → 0.2.2-dev.7
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/dist/bin/suipay.js +2 -2
- package/dist/{chunk-UTKVBAEZ.js → chunk-6ZSOXII5.js} +1504 -231
- package/dist/{chunk-AEV6Q6JC.js → chunk-KR6WRUDY.js} +1 -1
- package/dist/{http-DBP9qgVw.d.ts → http-DggnqM91.d.ts} +234 -4
- package/dist/http.d.ts +4 -1
- package/dist/http.js +1 -1
- package/dist/index.d.ts +10 -210
- package/dist/index.js +2 -2
- package/package.json +3 -2
|
@@ -3,8 +3,11 @@ import { McpAccessContext } from '@cmdoss/suipay-sdk/mcp/access-context';
|
|
|
3
3
|
import { SettlementDTO } from '@cmdoss/suipay-sdk/buyer/settlement-dto';
|
|
4
4
|
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
5
5
|
import { GetObjectJson } from '@cmdoss/suipay-sdk/agent-sdk/reads';
|
|
6
|
-
import { DelegatedKeySigner, DelegatedPayerDeps } from '@cmdoss/suipay-sdk/delegated-signer/payer';
|
|
6
|
+
import { DelegatedKeySigner, DelegatedPayerDeps, GuardedSettleFields } from '@cmdoss/suipay-sdk/delegated-signer/payer';
|
|
7
7
|
import { TraceRunResolver, TraceSink } from '@cmdoss/suipay-core/trace/types';
|
|
8
|
+
import { PaidHttpRequest } from '@cmdoss/suipay-sdk/protocol/paid-http-request';
|
|
9
|
+
import { Dialect } from '@cmdoss/suipay-sdk/protocol/types';
|
|
10
|
+
import { PayOperationDeps } from '@cmdoss/suipay-sdk/pay-operation';
|
|
8
11
|
|
|
9
12
|
/**
|
|
10
13
|
* Authenticated MCP request context (remote Streamable HTTP).
|
|
@@ -16,7 +19,7 @@ import { TraceRunResolver, TraceSink } from '@cmdoss/suipay-core/trace/types';
|
|
|
16
19
|
*
|
|
17
20
|
* Non-custodial: the gateway holds NO key that can spend. There is deliberately
|
|
18
21
|
* no `decryptDelegateSeed` and no forwarded `sponsorAuthorization` here — the
|
|
19
|
-
* `pay` tool only PREPARES an unsigned `spend_account::
|
|
22
|
+
* `pay` tool only PREPARES an unsigned `spend_account::settle_policy` / `settle_any_recipient` transaction from the
|
|
20
23
|
* immutable grant snapshot (`prepareSpendAccountPayment`), and the client that
|
|
21
24
|
* holds the delegate key signs locally and submits. Only signatures ever reach
|
|
22
25
|
* the gateway. See docs/design/mcp-non-custodial-signing.md and ADR-0013 §3.
|
|
@@ -40,7 +43,7 @@ interface McpAuthContext {
|
|
|
40
43
|
/** Public, descriptive policy context. Never used as payment authority. */
|
|
41
44
|
access?: McpAccessContext;
|
|
42
45
|
/**
|
|
43
|
-
* When present, `pay` prepares unsigned spend_account::
|
|
46
|
+
* When present, `pay` prepares unsigned spend_account::settle_policy / settle_any_recipient bytes for the
|
|
44
47
|
* client-held delegate key to sign locally — no server-side decrypt or
|
|
45
48
|
* signing. Stdio local V1 profile path remains when absent.
|
|
46
49
|
*/
|
|
@@ -79,6 +82,14 @@ interface McpConfig {
|
|
|
79
82
|
minFunded: bigint;
|
|
80
83
|
minMaxPerPayment: bigint;
|
|
81
84
|
label: string;
|
|
85
|
+
/**
|
|
86
|
+
* The canonical `ExclusionDirectory` object id (the same
|
|
87
|
+
* `SUIPAY_EXCLUSION_DIRECTORY_OBJECT_ID` the gateway reads). Present enables the
|
|
88
|
+
* non-custodial pay path to resolve the per-recipient `RecipientRegistry` and
|
|
89
|
+
* build a GUARDED delegate settle for a guarded offer. `null` when
|
|
90
|
+
* unset — a guarded offer then FAILS CLOSED (no unguarded settle).
|
|
91
|
+
*/
|
|
92
|
+
exclusionDirectoryObjectId: string | null;
|
|
82
93
|
}
|
|
83
94
|
/**
|
|
84
95
|
* CLI flags: `--local` / `-local`, `--dev` / `-dev`. Unknown args are ignored
|
|
@@ -249,6 +260,223 @@ interface TraceMcpHttpRequestInput {
|
|
|
249
260
|
*/
|
|
250
261
|
declare function traceMcpHttpRequest(input: TraceMcpHttpRequestInput): Promise<Response>;
|
|
251
262
|
|
|
263
|
+
/**
|
|
264
|
+
* Shared pay-request helpers.
|
|
265
|
+
*
|
|
266
|
+
* The V1 allowance sponsored payer (ADR-0010) is retired; only the
|
|
267
|
+
* rail-neutral request surface the SpendAccount payer depends on survives here:
|
|
268
|
+
* the `PayResult` shape every payer returns. `paidRequestInit` is the SDK helper
|
|
269
|
+
* that builds the one RequestInit replayed byte for byte on both calls.
|
|
270
|
+
*/
|
|
271
|
+
|
|
272
|
+
type PayResult = {
|
|
273
|
+
status: 'ok' | 'failed' | 'ambiguous';
|
|
274
|
+
/**
|
|
275
|
+
* `true` — settlement confirmed. `false` — money did not leave the
|
|
276
|
+
* account. `'unknown'` — execute/finality did not resolve; a retry can
|
|
277
|
+
* pay twice.
|
|
278
|
+
*/
|
|
279
|
+
paid: boolean | 'unknown';
|
|
280
|
+
body?: unknown;
|
|
281
|
+
receipt?: unknown;
|
|
282
|
+
code?: string;
|
|
283
|
+
detail?: string;
|
|
284
|
+
txDigest?: string;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* SpendAccount PREPARE-only client (non-custodial MCP).
|
|
289
|
+
*
|
|
290
|
+
* The remote MCP `pay` tool runs inside the gateway, which holds NO key that can
|
|
291
|
+
* spend. So this module does not sign or submit: it PREPARES a payment and hands
|
|
292
|
+
* back an unsigned `spend_account::settle_policy` / `settle_any_recipient` transaction plus everything the client
|
|
293
|
+
* needs. The client — which holds the delegate key — sponsors, signs locally,
|
|
294
|
+
* and submits through the same personal-message challenge → local-sign → submit flow the
|
|
295
|
+
* REST/SDK delegate path uses. Only signatures ever reach the gateway; the
|
|
296
|
+
* private key is never placed in an HTTP body, a bearer, or any header.
|
|
297
|
+
*
|
|
298
|
+
* Flow: 402 Offer → request-binding → package/network SSOT →
|
|
299
|
+
* resolveGrantTarget(snapshot, offer.targetHash) (pause/revoke gate) → cap/coin
|
|
300
|
+
* checks → assertLive (fresh authority) → build unsigned kind bytes → return the
|
|
301
|
+
* signing request. There is deliberately no sponsor call, no decrypt, no
|
|
302
|
+
* signature, and no forwarded bearer here.
|
|
303
|
+
*
|
|
304
|
+
* See docs/design/mcp-non-custodial-signing.md and ADR-0013 §3.
|
|
305
|
+
*/
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Read/prepare-only session for the non-custodial MCP pay tool. It carries the
|
|
309
|
+
* immutable grant snapshot and an optional prepare-time live gate — and no key,
|
|
310
|
+
* by construction. There is no `decryptDelegateSeed` and no `sponsorAuthorization`.
|
|
311
|
+
*/
|
|
312
|
+
interface SpendAccountPrepareSession {
|
|
313
|
+
snapshot: GrantSnapshot;
|
|
314
|
+
/** SpendAccount package id (V2). */
|
|
315
|
+
packageId: string;
|
|
316
|
+
/**
|
|
317
|
+
* Re-assert the grant is still live (not paused/revoked/expired) against fresh
|
|
318
|
+
* canonical state, invoked immediately before a signing request is handed back.
|
|
319
|
+
* Throw to abort. Optional; when absent, only the request-time snapshot gates
|
|
320
|
+
* the prepare (on-chain `spend_account::settle_policy` remains the final backstop for any
|
|
321
|
+
* spend the client later submits).
|
|
322
|
+
*/
|
|
323
|
+
assertLive?: () => Promise<void>;
|
|
324
|
+
}
|
|
325
|
+
interface SpendAccountPayDeps {
|
|
326
|
+
fetchImpl?: typeof fetch;
|
|
327
|
+
/**
|
|
328
|
+
* Build only-transaction-kind bytes for the canonical guarded debit
|
|
329
|
+
* (`spend_account::settle_policy` / `settle_any_recipient`).
|
|
330
|
+
*
|
|
331
|
+
* The guarded-settle fields ({@link GuardedSettleFields}) are required on the
|
|
332
|
+
* fresh lineage: every delegate settle consumes the shared exclusion marker.
|
|
333
|
+
* Dropping them fails closed rather than building an unguarded call that no
|
|
334
|
+
* longer exists on chain.
|
|
335
|
+
*/
|
|
336
|
+
buildPayKind?: (input: {
|
|
337
|
+
delegate: string;
|
|
338
|
+
coinType: string;
|
|
339
|
+
poolObjectId: string;
|
|
340
|
+
grantObjectId: string;
|
|
341
|
+
policyId: number | string;
|
|
342
|
+
targetHash: string;
|
|
343
|
+
amount: string;
|
|
344
|
+
paymentIdHash: Uint8Array;
|
|
345
|
+
termsHash: Uint8Array;
|
|
346
|
+
recipient?: string;
|
|
347
|
+
accessMode?: 'scoped' | 'open';
|
|
348
|
+
} & GuardedSettleFields) => Promise<{
|
|
349
|
+
kindBytes: string;
|
|
350
|
+
}>;
|
|
351
|
+
/**
|
|
352
|
+
* Resolve the per-recipient `RecipientRegistry` bound in the offer's exclusion
|
|
353
|
+
* directory (guarded offers only). Injected seam for tests; production
|
|
354
|
+
* leaves it unset and the prepare wires a live gRPC-backed resolver from the
|
|
355
|
+
* configured `ExclusionDirectory` id when present, else fails closed.
|
|
356
|
+
*/
|
|
357
|
+
resolveExclusionRegistry?: PayOperationDeps['resolveExclusionRegistry'];
|
|
358
|
+
/**
|
|
359
|
+
* Live trace for this prepare. Purely observational: emission records what the
|
|
360
|
+
* canonical read decisions already returned — an event is written after a check
|
|
361
|
+
* passes and can never be the thing that lets the next step run.
|
|
362
|
+
*/
|
|
363
|
+
trace?: SpendAccountPayTrace;
|
|
364
|
+
}
|
|
365
|
+
interface SpendAccountPayTrace {
|
|
366
|
+
sink: TraceSink;
|
|
367
|
+
traceId: string;
|
|
368
|
+
requestId: string | null;
|
|
369
|
+
buyerAccountId: string;
|
|
370
|
+
connectionId: string;
|
|
371
|
+
/** HMAC secret for signed cross-request context. Absent disables signing. */
|
|
372
|
+
secret?: string | null;
|
|
373
|
+
/** Injected clock, for tests. */
|
|
374
|
+
now?: () => number;
|
|
375
|
+
}
|
|
376
|
+
/** The unsigned payment the client signs locally and submits. */
|
|
377
|
+
interface SpendAccountSigningRequest {
|
|
378
|
+
/**
|
|
379
|
+
* Unsigned `spend_account::settle_policy` / `settle_any_recipient` transaction-kind bytes (base64), sender set to
|
|
380
|
+
* `delegateAddress`. The client sponsors these for gas, signs with the delegate
|
|
381
|
+
* key, and submits — the gateway never receives the key.
|
|
382
|
+
*/
|
|
383
|
+
unsignedKindBytes: string;
|
|
384
|
+
delegateAddress: string;
|
|
385
|
+
packageId: string;
|
|
386
|
+
poolObjectId: string;
|
|
387
|
+
grantObjectId: string;
|
|
388
|
+
/** On-chain policy id the pay is bound to. */
|
|
389
|
+
policyId: number | string;
|
|
390
|
+
coinType: string;
|
|
391
|
+
targetHash: string;
|
|
392
|
+
amount: string;
|
|
393
|
+
/** Hex (no 0x) of the payment-id hash bound into the transaction. */
|
|
394
|
+
paymentIdHashHex: string;
|
|
395
|
+
/** Hex (no 0x) of the terms hash bound into the transaction. */
|
|
396
|
+
termsHashHex: string;
|
|
397
|
+
challengeId: string;
|
|
398
|
+
/** The exact paid request to replay after the client submits. */
|
|
399
|
+
resource: {
|
|
400
|
+
url: string;
|
|
401
|
+
method: string;
|
|
402
|
+
};
|
|
403
|
+
dialect: Dialect;
|
|
404
|
+
/** Recipient the agent requested (offer.payTo). */
|
|
405
|
+
recipient: string;
|
|
406
|
+
/** Where the client (holding the key) sponsors and submits. */
|
|
407
|
+
submit: {
|
|
408
|
+
sponsorUrl: string;
|
|
409
|
+
executeUrl: string;
|
|
410
|
+
moveCallTarget: string;
|
|
411
|
+
};
|
|
412
|
+
/**
|
|
413
|
+
* ISO-8601 timestamp when this prepared operation expires. After this time the
|
|
414
|
+
* unsigned bytes are no longer valid and the client must re-call pay() for a
|
|
415
|
+
* fresh prepare. Derived from the offer TTL.
|
|
416
|
+
*/
|
|
417
|
+
expiresAt: string;
|
|
418
|
+
/** Restated hard rule for the agent host. */
|
|
419
|
+
note: string;
|
|
420
|
+
}
|
|
421
|
+
interface PreparedPayment {
|
|
422
|
+
status: 'prepared';
|
|
423
|
+
paid: false;
|
|
424
|
+
signingRequest: SpendAccountSigningRequest;
|
|
425
|
+
}
|
|
426
|
+
/** Prepared signing request, or a canonical failure (never a spend). */
|
|
427
|
+
type SpendAccountPrepareResult = PreparedPayment | PayResult;
|
|
428
|
+
/** Default kind builder (no chain client — pure PTB). */
|
|
429
|
+
declare function buildSpendAccountPayKind(input: {
|
|
430
|
+
packageId: string;
|
|
431
|
+
delegate: string;
|
|
432
|
+
coinType: string;
|
|
433
|
+
poolObjectId: string;
|
|
434
|
+
grantObjectId: string;
|
|
435
|
+
policyId: number | string;
|
|
436
|
+
targetHash: string;
|
|
437
|
+
amount: string;
|
|
438
|
+
paymentIdHash: Uint8Array;
|
|
439
|
+
termsHash: Uint8Array;
|
|
440
|
+
} & GuardedSettleFields): Promise<{
|
|
441
|
+
kindBytes: string;
|
|
442
|
+
}>;
|
|
443
|
+
/**
|
|
444
|
+
* Refuse blind signing: a client validating a sponsored transaction must be able
|
|
445
|
+
* to prove the sponsored bytes reconstruct the intended spend_account::settle_policy. Kept
|
|
446
|
+
* here (and exported) so both the client signer and its tests share one check.
|
|
447
|
+
*/
|
|
448
|
+
declare function verifySpendAccountPayReconstructs(bytes: string, expected: {
|
|
449
|
+
kindBytes: string;
|
|
450
|
+
packageId: string;
|
|
451
|
+
delegate: string;
|
|
452
|
+
poolObjectId: string;
|
|
453
|
+
grantObjectId: string;
|
|
454
|
+
amount: string;
|
|
455
|
+
}): void;
|
|
456
|
+
/**
|
|
457
|
+
* Prepare a delegate payment WITHOUT signing. Reads the 402 offer, binds it,
|
|
458
|
+
* gates on the immutable grant snapshot + a fresh authority check, builds the
|
|
459
|
+
* unsigned transaction, and returns a signing request. The client holding the
|
|
460
|
+
* delegate key signs locally and submits. This function never decrypts, signs,
|
|
461
|
+
* sponsors, or submits.
|
|
462
|
+
*
|
|
463
|
+
* Uses `resolvePayment` from the SDK pay-operation module for the
|
|
464
|
+
* shared offer-acquisition + authority-resolution pipeline (steps 1–5 + assertLive
|
|
465
|
+
* + hash derivation + buildPayKind). This module wraps that with MCP-specific
|
|
466
|
+
* concerns: trace events, dialect-mode ceiling check, and signing-request
|
|
467
|
+
* construction.
|
|
468
|
+
*/
|
|
469
|
+
declare function prepareSpendAccountPayment(args: {
|
|
470
|
+
url: string;
|
|
471
|
+
/** The one normalized paid request, replayed byte for byte after signing. */
|
|
472
|
+
request?: PaidHttpRequest;
|
|
473
|
+
session: SpendAccountPrepareSession;
|
|
474
|
+
cfg: McpConfig;
|
|
475
|
+
deps?: SpendAccountPayDeps;
|
|
476
|
+
/** Preferred dialect when the 402 advertises both (default mpp). */
|
|
477
|
+
preferredDialect?: Dialect;
|
|
478
|
+
}): Promise<SpendAccountPrepareResult>;
|
|
479
|
+
|
|
252
480
|
/**
|
|
253
481
|
* Transport-neutral SuiPay MCP server + tool registry.
|
|
254
482
|
* Used by stdio (index.ts) and Streamable HTTP (http.ts).
|
|
@@ -378,6 +606,8 @@ interface McpServerOptions {
|
|
|
378
606
|
* does not already authorize.
|
|
379
607
|
*/
|
|
380
608
|
resolveAgentHeld?: AgentHeldResolver;
|
|
609
|
+
/** Override the exclusion-registry resolver (tests / offline). */
|
|
610
|
+
resolveExclusionRegistry?: SpendAccountPayDeps['resolveExclusionRegistry'];
|
|
381
611
|
/**
|
|
382
612
|
* Wire that created this server. Hosted HTTP never forwards `file` into `pay`.
|
|
383
613
|
* Stdio is the default so existing tests stay local.
|
|
@@ -402,4 +632,4 @@ declare function createServer(cfg: McpConfig, auth?: McpAuthContext, trace?: Mcp
|
|
|
402
632
|
*/
|
|
403
633
|
declare function handleSuipayMcpHttpRequest(req: Request, cfg: McpConfig, auth?: McpAuthContext, trace?: McpTraceRuntime | null, options?: McpServerOptions): Promise<Response>;
|
|
404
634
|
|
|
405
|
-
export { type AgentHeldResolver as A, type McpConfig as M, PACKAGE_NAME as P, TOOLS as T, type McpAuthContext as a, type McpTraceHooks as b, type
|
|
635
|
+
export { type AgentHeldResolver as A, traceMcpHttpRequest as B, verifySpendAccountPayReconstructs as C, type McpConfig as M, PACKAGE_NAME as P, type SpendAccountSigningRequest as S, TOOLS as T, type McpAuthContext as a, type McpTraceHooks as b, type SpendAccountPayDeps as c, type AgentHeldSettlement as d, MCP_TARGET_PRESETS as e, type McpEnvelope as f, type McpEnvelopeEntry as g, type McpServerOptions as h, type McpTarget as i, type McpTraceContext as j, type McpTraceRuntime as k, type PreparedPayment as l, type SpendAccountPrepareResult as m, type SpendAccountPrepareSession as n, buildSpendAccountPayKind as o, canonicalMcpRequestId as p, createServer as q, handleSuipayMcpHttpRequest as r, inspectMcpEnvelope as s, loadMcpConfig as t, parseMcpTargetFlag as u, prepareSpendAccountPayment as v, resetAgentHeldProcessLedger as w, resolveAgentHeldSettlement as x, resolveMcpTarget as y, sameMcpGateway as z };
|
package/dist/http.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { r as handleSuipayMcpHttpRequest } from './http-DggnqM91.js';
|
|
2
2
|
import '@cmdoss/suipay-core/policy/grant-target';
|
|
3
3
|
import '@cmdoss/suipay-sdk/mcp/access-context';
|
|
4
4
|
import '@cmdoss/suipay-sdk/buyer/settlement-dto';
|
|
@@ -6,3 +6,6 @@ import '@modelcontextprotocol/sdk/server/index.js';
|
|
|
6
6
|
import '@cmdoss/suipay-sdk/agent-sdk/reads';
|
|
7
7
|
import '@cmdoss/suipay-sdk/delegated-signer/payer';
|
|
8
8
|
import '@cmdoss/suipay-core/trace/types';
|
|
9
|
+
import '@cmdoss/suipay-sdk/protocol/paid-http-request';
|
|
10
|
+
import '@cmdoss/suipay-sdk/protocol/types';
|
|
11
|
+
import '@cmdoss/suipay-sdk/pay-operation';
|
package/dist/http.js
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Wallet } from '@cmdoss/suipay-core/chain/types';
|
|
2
|
-
import { M as McpConfig, a as McpAuthContext, b as McpTraceHooks } from './http-
|
|
3
|
-
export { A as AgentHeldResolver,
|
|
4
|
-
import { GrantSnapshot } from '@cmdoss/suipay-core/policy/grant-target';
|
|
5
|
-
export { resolveGrantTarget } from '@cmdoss/suipay-core/policy/grant-target';
|
|
6
|
-
import { PaidHttpRequest } from '@cmdoss/suipay-sdk/protocol/paid-http-request';
|
|
7
|
-
import { TraceSink } from '@cmdoss/suipay-core/trace/types';
|
|
8
|
-
import { Dialect } from '@cmdoss/suipay-sdk/protocol/types';
|
|
2
|
+
import { S as SpendAccountSigningRequest, M as McpConfig, a as McpAuthContext, b as McpTraceHooks, c as SpendAccountPayDeps } from './http-DggnqM91.js';
|
|
3
|
+
export { A as AgentHeldResolver, d as AgentHeldSettlement, e as MCP_TARGET_PRESETS, f as McpEnvelope, g as McpEnvelopeEntry, h as McpServerOptions, i as McpTarget, j as McpTraceContext, k as McpTraceRuntime, P as PACKAGE_NAME, l as PreparedPayment, m as SpendAccountPrepareResult, n as SpendAccountPrepareSession, T as TOOLS, o as buildSpendAccountPayKind, p as canonicalMcpRequestId, q as createServer, r as handleSuipayMcpHttpRequest, s as inspectMcpEnvelope, t as loadMcpConfig, u as parseMcpTargetFlag, v as prepareSpendAccountPayment, w as resetAgentHeldProcessLedger, x as resolveAgentHeldSettlement, y as resolveMcpTarget, z as sameMcpGateway, B as traceMcpHttpRequest, C as verifySpendAccountPayReconstructs } from './http-DggnqM91.js';
|
|
9
4
|
import { GetObjectJson, createReader } from '@cmdoss/suipay-sdk/agent-sdk/reads';
|
|
10
5
|
import { DelegatedKeySigner, DelegatedPayerSession, DelegatedPayerConfig, DelegatedPayerDeps, SpendIntent, DelegatedPayResult } from '@cmdoss/suipay-sdk/delegated-signer/payer';
|
|
6
|
+
import { PaidHttpRequest } from '@cmdoss/suipay-sdk/protocol/paid-http-request';
|
|
11
7
|
import { createPayer } from '@cmdoss/suipay-sdk/agent-sdk/delegate-agent';
|
|
12
8
|
import { CallToolResult } from '@modelcontextprotocol/sdk/types.js';
|
|
9
|
+
export { resolveGrantTarget } from '@cmdoss/suipay-core/policy/grant-target';
|
|
13
10
|
import '@cmdoss/suipay-sdk/mcp/access-context';
|
|
14
11
|
import '@cmdoss/suipay-sdk/buyer/settlement-dto';
|
|
15
12
|
import '@modelcontextprotocol/sdk/server/index.js';
|
|
13
|
+
import '@cmdoss/suipay-core/trace/types';
|
|
14
|
+
import '@cmdoss/suipay-sdk/protocol/types';
|
|
15
|
+
import '@cmdoss/suipay-sdk/pay-operation';
|
|
16
16
|
|
|
17
17
|
interface SuiPayCredentials {
|
|
18
18
|
/** 64-hex Ed25519 seed. NEVER logged. */
|
|
@@ -68,208 +68,6 @@ declare function loadLocalSigner(): {
|
|
|
68
68
|
signPersonalMessage: (message: Uint8Array) => Promise<string>;
|
|
69
69
|
} | null;
|
|
70
70
|
|
|
71
|
-
/**
|
|
72
|
-
* Shared pay-request helpers.
|
|
73
|
-
*
|
|
74
|
-
* The V1 allowance sponsored payer (ADR-0010) is retired; only the
|
|
75
|
-
* rail-neutral request surface the SpendAccount payer depends on survives here:
|
|
76
|
-
* the `PayResult` shape every payer returns. `paidRequestInit` is the SDK helper
|
|
77
|
-
* that builds the one RequestInit replayed byte for byte on both calls.
|
|
78
|
-
*/
|
|
79
|
-
|
|
80
|
-
type PayResult = {
|
|
81
|
-
status: 'ok' | 'failed' | 'ambiguous';
|
|
82
|
-
/**
|
|
83
|
-
* `true` — settlement confirmed. `false` — money did not leave the
|
|
84
|
-
* account. `'unknown'` — execute/finality did not resolve; a retry can
|
|
85
|
-
* pay twice.
|
|
86
|
-
*/
|
|
87
|
-
paid: boolean | 'unknown';
|
|
88
|
-
body?: unknown;
|
|
89
|
-
receipt?: unknown;
|
|
90
|
-
code?: string;
|
|
91
|
-
detail?: string;
|
|
92
|
-
txDigest?: string;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* SpendAccount PREPARE-only client (non-custodial MCP).
|
|
97
|
-
*
|
|
98
|
-
* The remote MCP `pay` tool runs inside the gateway, which holds NO key that can
|
|
99
|
-
* spend. So this module does not sign or submit: it PREPARES a payment and hands
|
|
100
|
-
* back an unsigned `spend_account::settle_policy_payment` transaction plus everything the client
|
|
101
|
-
* needs. The client — which holds the delegate key — sponsors, signs locally,
|
|
102
|
-
* and submits through the same personal-message challenge → local-sign → submit flow the
|
|
103
|
-
* REST/SDK delegate path uses. Only signatures ever reach the gateway; the
|
|
104
|
-
* private key is never placed in an HTTP body, a bearer, or any header.
|
|
105
|
-
*
|
|
106
|
-
* Flow: 402 Offer → request-binding → package/network SSOT →
|
|
107
|
-
* resolveGrantTarget(snapshot, offer.targetHash) (pause/revoke gate) → cap/coin
|
|
108
|
-
* checks → assertLive (fresh authority) → build unsigned kind bytes → return the
|
|
109
|
-
* signing request. There is deliberately no sponsor call, no decrypt, no
|
|
110
|
-
* signature, and no forwarded bearer here.
|
|
111
|
-
*
|
|
112
|
-
* See docs/design/mcp-non-custodial-signing.md and ADR-0013 §3.
|
|
113
|
-
*/
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Read/prepare-only session for the non-custodial MCP pay tool. It carries the
|
|
117
|
-
* immutable grant snapshot and an optional prepare-time live gate — and no key,
|
|
118
|
-
* by construction. There is no `decryptDelegateSeed` and no `sponsorAuthorization`.
|
|
119
|
-
*/
|
|
120
|
-
interface SpendAccountPrepareSession {
|
|
121
|
-
snapshot: GrantSnapshot;
|
|
122
|
-
/** SpendAccount package id (V2). */
|
|
123
|
-
packageId: string;
|
|
124
|
-
/**
|
|
125
|
-
* Re-assert the grant is still live (not paused/revoked/expired) against fresh
|
|
126
|
-
* canonical state, invoked immediately before a signing request is handed back.
|
|
127
|
-
* Throw to abort. Optional; when absent, only the request-time snapshot gates
|
|
128
|
-
* the prepare (on-chain `spend_account::settle_policy_payment` remains the final backstop for any
|
|
129
|
-
* spend the client later submits).
|
|
130
|
-
*/
|
|
131
|
-
assertLive?: () => Promise<void>;
|
|
132
|
-
}
|
|
133
|
-
interface SpendAccountPayDeps {
|
|
134
|
-
fetchImpl?: typeof fetch;
|
|
135
|
-
/** Build only-transaction-kind bytes for spend_account::settle_policy_payment. */
|
|
136
|
-
buildPayKind?: (input: {
|
|
137
|
-
delegate: string;
|
|
138
|
-
coinType: string;
|
|
139
|
-
poolObjectId: string;
|
|
140
|
-
grantObjectId: string;
|
|
141
|
-
policyId: number | string;
|
|
142
|
-
targetHash: string;
|
|
143
|
-
amount: string;
|
|
144
|
-
paymentIdHash: Uint8Array;
|
|
145
|
-
termsHash: Uint8Array;
|
|
146
|
-
recipient?: string;
|
|
147
|
-
accessMode?: 'scoped' | 'open';
|
|
148
|
-
}) => Promise<{
|
|
149
|
-
kindBytes: string;
|
|
150
|
-
}>;
|
|
151
|
-
/**
|
|
152
|
-
* Live trace for this prepare. Purely observational: emission records what the
|
|
153
|
-
* canonical read decisions already returned — an event is written after a check
|
|
154
|
-
* passes and can never be the thing that lets the next step run.
|
|
155
|
-
*/
|
|
156
|
-
trace?: SpendAccountPayTrace;
|
|
157
|
-
}
|
|
158
|
-
interface SpendAccountPayTrace {
|
|
159
|
-
sink: TraceSink;
|
|
160
|
-
traceId: string;
|
|
161
|
-
requestId: string | null;
|
|
162
|
-
buyerAccountId: string;
|
|
163
|
-
connectionId: string;
|
|
164
|
-
/** HMAC secret for signed cross-request context. Absent disables signing. */
|
|
165
|
-
secret?: string | null;
|
|
166
|
-
/** Injected clock, for tests. */
|
|
167
|
-
now?: () => number;
|
|
168
|
-
}
|
|
169
|
-
/** The unsigned payment the client signs locally and submits. */
|
|
170
|
-
interface SpendAccountSigningRequest {
|
|
171
|
-
/**
|
|
172
|
-
* Unsigned `spend_account::settle_policy_payment` transaction-kind bytes (base64), sender set to
|
|
173
|
-
* `delegateAddress`. The client sponsors these for gas, signs with the delegate
|
|
174
|
-
* key, and submits — the gateway never receives the key.
|
|
175
|
-
*/
|
|
176
|
-
unsignedKindBytes: string;
|
|
177
|
-
delegateAddress: string;
|
|
178
|
-
packageId: string;
|
|
179
|
-
poolObjectId: string;
|
|
180
|
-
grantObjectId: string;
|
|
181
|
-
/** On-chain policy id the pay is bound to. */
|
|
182
|
-
policyId: number | string;
|
|
183
|
-
coinType: string;
|
|
184
|
-
targetHash: string;
|
|
185
|
-
amount: string;
|
|
186
|
-
/** Hex (no 0x) of the payment-id hash bound into the transaction. */
|
|
187
|
-
paymentIdHashHex: string;
|
|
188
|
-
/** Hex (no 0x) of the terms hash bound into the transaction. */
|
|
189
|
-
termsHashHex: string;
|
|
190
|
-
challengeId: string;
|
|
191
|
-
/** The exact paid request to replay after the client submits. */
|
|
192
|
-
resource: {
|
|
193
|
-
url: string;
|
|
194
|
-
method: string;
|
|
195
|
-
};
|
|
196
|
-
dialect: Dialect;
|
|
197
|
-
/** Recipient the agent requested (offer.payTo). */
|
|
198
|
-
recipient: string;
|
|
199
|
-
/** Where the client (holding the key) sponsors and submits. */
|
|
200
|
-
submit: {
|
|
201
|
-
sponsorUrl: string;
|
|
202
|
-
executeUrl: string;
|
|
203
|
-
moveCallTarget: string;
|
|
204
|
-
};
|
|
205
|
-
/**
|
|
206
|
-
* ISO-8601 timestamp when this prepared operation expires. After this time the
|
|
207
|
-
* unsigned bytes are no longer valid and the client must re-call pay() for a
|
|
208
|
-
* fresh prepare. Derived from the offer TTL.
|
|
209
|
-
*/
|
|
210
|
-
expiresAt: string;
|
|
211
|
-
/** Restated hard rule for the agent host. */
|
|
212
|
-
note: string;
|
|
213
|
-
}
|
|
214
|
-
interface PreparedPayment {
|
|
215
|
-
status: 'prepared';
|
|
216
|
-
paid: false;
|
|
217
|
-
signingRequest: SpendAccountSigningRequest;
|
|
218
|
-
}
|
|
219
|
-
/** Prepared signing request, or a canonical failure (never a spend). */
|
|
220
|
-
type SpendAccountPrepareResult = PreparedPayment | PayResult;
|
|
221
|
-
/** Default kind builder (no chain client — pure PTB). */
|
|
222
|
-
declare function buildSpendAccountPayKind(input: {
|
|
223
|
-
packageId: string;
|
|
224
|
-
delegate: string;
|
|
225
|
-
coinType: string;
|
|
226
|
-
poolObjectId: string;
|
|
227
|
-
grantObjectId: string;
|
|
228
|
-
policyId: number | string;
|
|
229
|
-
targetHash: string;
|
|
230
|
-
amount: string;
|
|
231
|
-
paymentIdHash: Uint8Array;
|
|
232
|
-
termsHash: Uint8Array;
|
|
233
|
-
}): Promise<{
|
|
234
|
-
kindBytes: string;
|
|
235
|
-
}>;
|
|
236
|
-
/**
|
|
237
|
-
* Refuse blind signing: a client validating a sponsored transaction must be able
|
|
238
|
-
* to prove the sponsored bytes reconstruct the intended spend_account::settle_policy_payment. Kept
|
|
239
|
-
* here (and exported) so both the client signer and its tests share one check.
|
|
240
|
-
*/
|
|
241
|
-
declare function verifySpendAccountPayReconstructs(bytes: string, expected: {
|
|
242
|
-
kindBytes: string;
|
|
243
|
-
packageId: string;
|
|
244
|
-
delegate: string;
|
|
245
|
-
poolObjectId: string;
|
|
246
|
-
grantObjectId: string;
|
|
247
|
-
amount: string;
|
|
248
|
-
}): void;
|
|
249
|
-
/**
|
|
250
|
-
* Prepare a delegate payment WITHOUT signing. Reads the 402 offer, binds it,
|
|
251
|
-
* gates on the immutable grant snapshot + a fresh authority check, builds the
|
|
252
|
-
* unsigned transaction, and returns a signing request. The client holding the
|
|
253
|
-
* delegate key signs locally and submits. This function never decrypts, signs,
|
|
254
|
-
* sponsors, or submits.
|
|
255
|
-
*
|
|
256
|
-
* Uses `resolvePayment` from the SDK pay-operation module (SAIP-170) for the
|
|
257
|
-
* shared offer-acquisition + authority-resolution pipeline (steps 1–5 + assertLive
|
|
258
|
-
* + hash derivation + buildPayKind). This module wraps that with MCP-specific
|
|
259
|
-
* concerns: trace events, dialect-mode ceiling check, and signing-request
|
|
260
|
-
* construction.
|
|
261
|
-
*/
|
|
262
|
-
declare function prepareSpendAccountPayment(args: {
|
|
263
|
-
url: string;
|
|
264
|
-
/** The one normalized paid request, replayed byte for byte after signing. */
|
|
265
|
-
request?: PaidHttpRequest;
|
|
266
|
-
session: SpendAccountPrepareSession;
|
|
267
|
-
cfg: McpConfig;
|
|
268
|
-
deps?: SpendAccountPayDeps;
|
|
269
|
-
/** Preferred dialect when the 402 advertises both (default mpp). */
|
|
270
|
-
preferredDialect?: Dialect;
|
|
271
|
-
}): Promise<SpendAccountPrepareResult>;
|
|
272
|
-
|
|
273
71
|
/**
|
|
274
72
|
* Client-side completion of an MCP prepared payment.
|
|
275
73
|
*
|
|
@@ -366,6 +164,8 @@ interface ToolDeps {
|
|
|
366
164
|
};
|
|
367
165
|
/** Override the prepare-time kind builder (tests / offline). */
|
|
368
166
|
buildPayKind?: SpendAccountPayDeps['buildPayKind'];
|
|
167
|
+
/** Override the exclusion-registry resolver (tests / offline). */
|
|
168
|
+
resolveExclusionRegistry?: SpendAccountPayDeps['resolveExclusionRegistry'];
|
|
369
169
|
/**
|
|
370
170
|
* Stdio login surfaces the console URL (MCP progress notification). The URL
|
|
371
171
|
* carries the delegate address only — never the seed.
|
|
@@ -394,4 +194,4 @@ declare function loadBootProfile(load?: typeof loadPaymentProfile): {
|
|
|
394
194
|
};
|
|
395
195
|
declare function main(): Promise<void>;
|
|
396
196
|
|
|
397
|
-
export { McpAuthContext, McpConfig, McpTraceHooks,
|
|
197
|
+
export { McpAuthContext, McpConfig, McpTraceHooks, SpendAccountSigningRequest, ensureLocalSigningKey, loadBootProfile, loadLocalSigner, main, pay, receipts, settlePreparedMcpPayment };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
loadBootProfile,
|
|
3
3
|
main
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-KR6WRUDY.js";
|
|
5
5
|
import {
|
|
6
6
|
MCP_TARGET_PRESETS,
|
|
7
7
|
PACKAGE_NAME,
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
settlePreparedMcpPayment,
|
|
27
27
|
traceMcpHttpRequest,
|
|
28
28
|
verifySpendAccountPayReconstructs
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-6ZSOXII5.js";
|
|
30
30
|
export {
|
|
31
31
|
MCP_TARGET_PRESETS,
|
|
32
32
|
PACKAGE_NAME,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmdoss/suipay-mcp",
|
|
3
|
-
"version": "0.2.2-dev.
|
|
3
|
+
"version": "0.2.2-dev.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "SuiPay MCP \u2014 pay MPP-gated APIs from a spend-account grant with an agent-held delegate key.",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
"README.md"
|
|
20
20
|
],
|
|
21
21
|
"publishConfig": {
|
|
22
|
-
"access": "public"
|
|
22
|
+
"access": "public",
|
|
23
|
+
"provenance": true
|
|
23
24
|
},
|
|
24
25
|
"engines": {
|
|
25
26
|
"node": ">=20"
|