@ampersend_ai/ampersend-sdk 0.0.16 → 0.0.21

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 (128) hide show
  1. package/dist/ampersend/approval.d.ts +8 -8
  2. package/dist/ampersend/approval.d.ts.map +1 -1
  3. package/dist/ampersend/approval.js +10 -15
  4. package/dist/ampersend/approval.js.map +1 -1
  5. package/dist/ampersend/client.d.ts +4 -9
  6. package/dist/ampersend/client.d.ts.map +1 -1
  7. package/dist/ampersend/client.js +25 -21
  8. package/dist/ampersend/client.js.map +1 -1
  9. package/dist/ampersend/treasurer.d.ts +14 -79
  10. package/dist/ampersend/treasurer.d.ts.map +1 -1
  11. package/dist/ampersend/treasurer.js +34 -102
  12. package/dist/ampersend/treasurer.js.map +1 -1
  13. package/dist/ampersend/types.d.ts +356 -338
  14. package/dist/ampersend/types.d.ts.map +1 -1
  15. package/dist/ampersend/types.js +120 -150
  16. package/dist/ampersend/types.js.map +1 -1
  17. package/dist/ampersend/zod-bridge.d.ts +15 -0
  18. package/dist/ampersend/zod-bridge.d.ts.map +1 -0
  19. package/dist/ampersend/zod-bridge.js +29 -0
  20. package/dist/ampersend/zod-bridge.js.map +1 -0
  21. package/dist/cli/commands/fetch.d.ts.map +1 -1
  22. package/dist/cli/commands/fetch.js.map +1 -1
  23. package/dist/cli/commands/setup.d.ts +4 -0
  24. package/dist/cli/commands/setup.d.ts.map +1 -1
  25. package/dist/cli/commands/setup.js +52 -7
  26. package/dist/cli/commands/setup.js.map +1 -1
  27. package/dist/index.d.ts +2 -1
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +1 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/mcp/client/client.d.ts +0 -3
  32. package/dist/mcp/client/client.d.ts.map +1 -1
  33. package/dist/mcp/client/client.js +10 -14
  34. package/dist/mcp/client/client.js.map +1 -1
  35. package/dist/mcp/client/factory.d.ts +0 -2
  36. package/dist/mcp/client/factory.d.ts.map +1 -1
  37. package/dist/mcp/client/factory.js +0 -3
  38. package/dist/mcp/client/factory.js.map +1 -1
  39. package/dist/mcp/client/middleware.d.ts +0 -3
  40. package/dist/mcp/client/middleware.d.ts.map +1 -1
  41. package/dist/mcp/client/middleware.js +9 -12
  42. package/dist/mcp/client/middleware.js.map +1 -1
  43. package/dist/mcp/client/protocol.d.ts +81 -85
  44. package/dist/mcp/client/protocol.d.ts.map +1 -1
  45. package/dist/mcp/client/protocol.js +17 -15
  46. package/dist/mcp/client/protocol.js.map +1 -1
  47. package/dist/mcp/client/types.d.ts +6 -19
  48. package/dist/mcp/client/types.d.ts.map +1 -1
  49. package/dist/mcp/proxy/cli.d.ts.map +1 -1
  50. package/dist/mcp/proxy/cli.js +0 -1
  51. package/dist/mcp/proxy/cli.js.map +1 -1
  52. package/dist/mcp/proxy/env.d.ts +0 -9
  53. package/dist/mcp/proxy/env.d.ts.map +1 -1
  54. package/dist/mcp/proxy/env.js +0 -2
  55. package/dist/mcp/proxy/env.js.map +1 -1
  56. package/dist/mcp/proxy/factory.d.ts +0 -2
  57. package/dist/mcp/proxy/factory.d.ts.map +1 -1
  58. package/dist/mcp/proxy/factory.js +0 -3
  59. package/dist/mcp/proxy/factory.js.map +1 -1
  60. package/dist/mcp/server/fastmcp/middleware.d.ts +9 -29
  61. package/dist/mcp/server/fastmcp/middleware.d.ts.map +1 -1
  62. package/dist/mcp/server/fastmcp/middleware.js +10 -42
  63. package/dist/mcp/server/fastmcp/middleware.js.map +1 -1
  64. package/dist/version.d.ts +1 -1
  65. package/dist/version.js +1 -1
  66. package/dist/x402/envelopes.d.ts +62 -0
  67. package/dist/x402/envelopes.d.ts.map +1 -0
  68. package/dist/x402/envelopes.js +73 -0
  69. package/dist/x402/envelopes.js.map +1 -0
  70. package/dist/x402/http/client.d.ts +37 -0
  71. package/dist/x402/http/client.d.ts.map +1 -0
  72. package/dist/x402/http/client.js +159 -0
  73. package/dist/x402/http/client.js.map +1 -0
  74. package/dist/x402/http/factory.d.ts +11 -25
  75. package/dist/x402/http/factory.d.ts.map +1 -1
  76. package/dist/x402/http/factory.js +11 -22
  77. package/dist/x402/http/factory.js.map +1 -1
  78. package/dist/x402/http/index.d.ts +4 -1
  79. package/dist/x402/http/index.d.ts.map +1 -1
  80. package/dist/x402/http/index.js +2 -1
  81. package/dist/x402/http/index.js.map +1 -1
  82. package/dist/x402/index.d.ts +4 -1
  83. package/dist/x402/index.d.ts.map +1 -1
  84. package/dist/x402/index.js +3 -2
  85. package/dist/x402/index.js.map +1 -1
  86. package/dist/x402/treasurer.d.ts +22 -47
  87. package/dist/x402/treasurer.d.ts.map +1 -1
  88. package/dist/x402/treasurers/naive.d.ts +4 -40
  89. package/dist/x402/treasurers/naive.d.ts.map +1 -1
  90. package/dist/x402/treasurers/naive.js +7 -44
  91. package/dist/x402/treasurers/naive.js.map +1 -1
  92. package/dist/x402/wallet.d.ts +7 -32
  93. package/dist/x402/wallet.d.ts.map +1 -1
  94. package/dist/x402/wallet.js +0 -3
  95. package/dist/x402/wallet.js.map +1 -1
  96. package/dist/x402/wallets/account/wallet.d.ts +9 -30
  97. package/dist/x402/wallets/account/wallet.d.ts.map +1 -1
  98. package/dist/x402/wallets/account/wallet.js +30 -37
  99. package/dist/x402/wallets/account/wallet.js.map +1 -1
  100. package/dist/x402/wallets/index.d.ts +0 -1
  101. package/dist/x402/wallets/index.d.ts.map +1 -1
  102. package/dist/x402/wallets/index.js +0 -1
  103. package/dist/x402/wallets/index.js.map +1 -1
  104. package/dist/x402/wallets/smart-account/chain.d.ts +4 -0
  105. package/dist/x402/wallets/smart-account/chain.d.ts.map +1 -0
  106. package/dist/x402/wallets/smart-account/chain.js +12 -0
  107. package/dist/x402/wallets/smart-account/chain.js.map +1 -0
  108. package/dist/x402/wallets/smart-account/cosigned.d.ts +7 -33
  109. package/dist/x402/wallets/smart-account/cosigned.d.ts.map +1 -1
  110. package/dist/x402/wallets/smart-account/cosigned.js +28 -51
  111. package/dist/x402/wallets/smart-account/cosigned.js.map +1 -1
  112. package/dist/x402/wallets/smart-account/exact.d.ts +6 -20
  113. package/dist/x402/wallets/smart-account/exact.d.ts.map +1 -1
  114. package/dist/x402/wallets/smart-account/exact.js +33 -43
  115. package/dist/x402/wallets/smart-account/exact.js.map +1 -1
  116. package/dist/x402/wallets/smart-account/wallet.d.ts +6 -39
  117. package/dist/x402/wallets/smart-account/wallet.d.ts.map +1 -1
  118. package/dist/x402/wallets/smart-account/wallet.js +9 -36
  119. package/dist/x402/wallets/smart-account/wallet.js.map +1 -1
  120. package/package.json +8 -6
  121. package/dist/x402/http/adapter.d.ts +0 -38
  122. package/dist/x402/http/adapter.d.ts.map +0 -1
  123. package/dist/x402/http/adapter.js +0 -199
  124. package/dist/x402/http/adapter.js.map +0 -1
  125. package/dist/x402/http/v2-adapter.d.ts +0 -56
  126. package/dist/x402/http/v2-adapter.d.ts.map +0 -1
  127. package/dist/x402/http/v2-adapter.js +0 -94
  128. package/dist/x402/http/v2-adapter.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/mcp/proxy/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAIxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAQrD;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,4BAA4B;IAC5B,mBAAmB,EAAE,OAAO,CAAA;IAC5B,0CAA0C;IAC1C,oBAAoB,EAAE,GAAG,CAAA;IACzB,iDAAiD;IACjD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,gDAAgD;IAChD,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,CAAC,CAYxG;AAGD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA"}
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/mcp/proxy/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAIxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAKrD;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,4BAA4B;IAC5B,mBAAmB,EAAE,OAAO,CAAA;IAC5B,0CAA0C;IAC1C,oBAAoB,EAAE,GAAG,CAAA;IACzB,iDAAiD;IACjD,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAsB,oBAAoB,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC;IAAE,MAAM,EAAE,WAAW,CAAA;CAAE,CAAC,CAWxG;AAGD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA"}
@@ -7,8 +7,6 @@ import { createAmpersendTreasurer } from "../../ampersend/treasurer.js";
7
7
  import { initializeProxyServer as initializeProxyServerInternal } from "./server/index.js";
8
8
  /** Default Ampersend API URL */
9
9
  const DEFAULT_API_URL = "https://api.ampersend.ai";
10
- /** Default chain ID (Base Sepolia) */
11
- const DEFAULT_CHAIN_ID = 84532;
12
10
  /**
13
11
  * Initialize an MCP proxy with minimal configuration.
14
12
  *
@@ -37,7 +35,6 @@ export async function createAmpersendProxy(options) {
37
35
  smartAccountAddress: options.smartAccountAddress,
38
36
  sessionKeyPrivateKey: options.sessionKeyPrivateKey,
39
37
  apiUrl: options.apiUrl ?? DEFAULT_API_URL,
40
- chainId: options.chainId ?? DEFAULT_CHAIN_ID,
41
38
  });
42
39
  return initializeProxyServerInternal({
43
40
  transport: { type: "http", port: options.port },
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/mcp/proxy/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,EAAE,qBAAqB,IAAI,6BAA6B,EAAE,MAAM,mBAAmB,CAAA;AAG1F,gCAAgC;AAChC,MAAM,eAAe,GAAG,0BAA0B,CAAA;AAElD,sCAAsC;AACtC,MAAM,gBAAgB,GAAG,KAAK,CAAA;AAmB9B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,OAA2B;IACpE,MAAM,SAAS,GAAG,wBAAwB,CAAC;QACzC,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;QAChD,oBAAoB,EAAE,OAAO,CAAC,oBAAoB;QAClD,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,eAAe;QACzC,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,gBAAgB;KAC7C,CAAC,CAAA;IAEF,OAAO,6BAA6B,CAAC;QACnC,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE;QAC/C,SAAS;KACV,CAAC,CAAA;AACJ,CAAC;AAED,4CAA4C;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA"}
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/mcp/proxy/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,EAAE,qBAAqB,IAAI,6BAA6B,EAAE,MAAM,mBAAmB,CAAA;AAG1F,gCAAgC;AAChC,MAAM,eAAe,GAAG,0BAA0B,CAAA;AAiBlD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,OAA2B;IACpE,MAAM,SAAS,GAAG,wBAAwB,CAAC;QACzC,mBAAmB,EAAE,OAAO,CAAC,mBAAmB;QAChD,oBAAoB,EAAE,OAAO,CAAC,oBAAoB;QAClD,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,eAAe;KAC1C,CAAC,CAAA;IAEF,OAAO,6BAA6B,CAAC;QACnC,SAAS,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE;QAC/C,SAAS;KACV,CAAC,CAAA;AACJ,CAAC;AAED,4CAA4C;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAA"}
@@ -1,50 +1,30 @@
1
+ import type { PaymentPayloadV1, PaymentRequirementsV1 } from "@x402/core/schemas";
2
+ import type { SettleResponse } from "@x402/core/types";
1
3
  import { type AudioContent, type ContentResult, type ImageContent, type ResourceContent, type ResourceLink, type TextContent } from "fastmcp";
2
- import { type PaymentPayload, type PaymentRequirements, type SettleResponse } from "x402/types";
3
- /**
4
- * Callback to determine if payment is required for tool execution
5
- */
4
+ /** Requirements to advertise, or `null` if payment isn't required. */
6
5
  export type OnExecute = (context: {
7
6
  args: unknown;
8
- }) => Promise<PaymentRequirements | null>;
9
- /**
10
- * Callback when payment provided
11
- */
7
+ }) => Promise<PaymentRequirementsV1 | null>;
8
+ /** Return a {@link SettleResponse} to embed in `_meta`, or `void` to accept without settling. */
12
9
  export type OnPayment = (context: {
13
- payment: PaymentPayload;
14
- requirements: PaymentRequirements;
10
+ payment: PaymentPayloadV1;
11
+ requirements: PaymentRequirementsV1;
15
12
  }) => Promise<SettleResponse | void>;
16
- /**
17
- * Options for the x402 payment middleware
18
- */
19
13
  export interface WithX402PaymentOptions {
20
14
  onExecute: OnExecute;
21
15
  onPayment: OnPayment;
22
16
  }
23
- /**
24
- * FastMCP context with request metadata
25
- */
26
17
  interface FastMCPContext {
27
18
  requestMetadata?: {
28
- "x402/payment"?: PaymentPayload;
19
+ "x402/payment"?: PaymentPayloadV1;
29
20
  [key: string]: unknown;
30
21
  };
31
22
  [key: string]: unknown;
32
23
  }
33
- /**
34
- * The execute function signature from FastMCP
35
- */
36
24
  type ExecuteFunction<TArgs = any, TResult = any> = (args: TArgs, context: FastMCPContext) => Promise<TResult>;
37
25
  export type ToolExecuteReturn = AudioContent | ContentResult | ImageContent | ResourceContent | ResourceLink | string | TextContent | void;
38
- /**
39
- * Middleware that wraps a FastMCP execute function to handle x402 payments
40
- *
41
- * Extracts payment from requestMetadata["x402/payment"] field and adds settlement
42
- * response to result _meta["x402/payment-response"] according to official MCP x402 spec.
43
- */
26
+ /** Wrap a FastMCP `execute` with x402 payment handling per the MCP x402 spec. */
44
27
  export declare function withX402Payment<TArgs = any, TResult = any>(options: WithX402PaymentOptions): (execute: ExecuteFunction<TArgs, TResult>) => ExecuteFunction<TArgs, TResult>;
45
- /**
46
- * Convenience function that directly wraps an execute function
47
- */
48
28
  export declare function createX402Execute<TArgs = any, TResult = any>(options: WithX402PaymentOptions, execute: ExecuteFunction<TArgs, TResult>): ExecuteFunction<TArgs, TResult>;
49
29
  export {};
50
30
  //# sourceMappingURL=middleware.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../../../src/mcp/server/fastmcp/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,YAAY,EACjB,KAAK,WAAW,EACjB,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,mBAAmB,EAAE,KAAK,cAAc,EAAE,MAAM,YAAY,CAAA;AAE/F;;GAEG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,OAAO,EAAE;IAAE,IAAI,EAAE,OA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AY,GACZ,aAAa,GACb,YAAY,GACZ,eAAe,GACf,YAAY,GACZ,MAAM,GACN,WAAW,GACX,IAAI,CAAA;AAkBR,iFAAiF;AACjF,wBAAgB,eAAe,CAAC,KAAK,GAAG,GAAG,EAAE,OAAO,GAAG,GAAG,EACxD,OAAO,EAAE,sBAAsB,GAC9B,CAAC,OAAO,EAAE,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,CAuC/E;AAED,wBAAgB,iBAAiB,CAAC,KAAK,GAAG,GAAG,EAAE,OAAO,GAAG,GAAG,EAC1D,OAAO,EAAE,sBAAsB,EAC/B,OAAO,EAAE,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,GACvC,eAAe,CAAC,KAAK,EAAE,OAAO,CAAC,CAEjC"}
@@ -1,13 +1,5 @@
1
1
  import { CustomMcpError, } from "fastmcp";
2
- import {} from "x402/types";
3
- /**
4
- * Creates a payment error with x402 requirements
5
- *
6
- * Workaround: Embeds x402 data as JSON in the error message for when FastMCP
7
- * doesn't properly propagate the data field. This allows the client to fall back
8
- * to parsing the data from the message.
9
- */
10
- function createPaymentError(requirements, errorReason = null, paymentResponse = null) {
2
+ function createPaymentError(requirements, errorReason = null, settlement = null) {
11
3
  const data = {
12
4
  message: "Payment required for tool execution",
13
5
  code: 402,
@@ -17,8 +9,8 @@ function createPaymentError(requirements, errorReason = null, paymentResponse =
17
9
  if (errorReason) {
18
10
  data.error = errorReason;
19
11
  }
20
- if (paymentResponse) {
21
- data["x402/payment-response"] = paymentResponse;
12
+ if (settlement) {
13
+ data["x402/payment-response"] = settlement;
22
14
  }
23
15
  return new CustomMcpError(402, data.message, data);
24
16
  }
@@ -29,71 +21,47 @@ function normalizeToolResult(result) {
29
21
  if (typeof result === "string") {
30
22
  return { content: [{ text: result, type: "text" }] };
31
23
  }
32
- // Check if it's an individual content type (has 'type' property)
33
24
  if ("type" in result) {
34
25
  return { content: [result] };
35
26
  }
36
- // Already a ContentResult
37
27
  return result;
38
28
  }
39
- /**
40
- * Middleware that wraps a FastMCP execute function to handle x402 payments
41
- *
42
- * Extracts payment from requestMetadata["x402/payment"] field and adds settlement
43
- * response to result _meta["x402/payment-response"] according to official MCP x402 spec.
44
- */
29
+ /** Wrap a FastMCP `execute` with x402 payment handling per the MCP x402 spec. */
45
30
  export function withX402Payment(options) {
46
31
  return (execute) => {
47
32
  return async (args, context) => {
48
- // Extract payment from MCP request metadata (via FastMCP context)
49
33
  const payment = context.requestMetadata?.["x402/payment"];
50
- // Check if payment is required
51
34
  const requirements = await options.onExecute({ args });
52
- // No payment required - execute normally
53
35
  if (!requirements) {
54
36
  return execute(args, context);
55
37
  }
56
- // Payment is required
57
38
  if (!payment) {
58
- // No payment provided - return error with requirements
59
39
  throw createPaymentError(requirements);
60
40
  }
61
- // Payment provided
62
- let onPaymentResp;
41
+ let settlement;
63
42
  try {
64
- onPaymentResp = await options.onPayment({
65
- payment,
66
- requirements,
67
- });
43
+ settlement = await options.onPayment({ payment, requirements });
68
44
  }
69
45
  catch (error) {
70
- // Payment invalid - extract reason from error
71
46
  const reason = error instanceof Error ? error.message : String(error);
72
47
  throw createPaymentError(requirements, reason);
73
48
  }
74
- if (onPaymentResp && !onPaymentResp.success) {
75
- // Payment rejected - return error with reason
76
- throw createPaymentError(requirements, onPaymentResp.errorReason, onPaymentResp);
49
+ if (settlement && !settlement.success) {
50
+ throw createPaymentError(requirements, settlement.errorReason ?? null, settlement);
77
51
  }
78
- // Payment valid - proceed with execution
79
52
  const result = await execute(args, context);
80
- // Did not settle
81
- if (!onPaymentResp) {
53
+ if (!settlement) {
82
54
  return result;
83
55
  }
84
56
  const normalizedResult = normalizeToolResult(result);
85
- // Add settlement response to result _meta (official spec)
86
57
  normalizedResult._meta = {
87
58
  ...normalizedResult._meta,
88
- "x402/payment-response": onPaymentResp,
59
+ "x402/payment-response": settlement,
89
60
  };
90
61
  return normalizedResult;
91
62
  };
92
63
  };
93
64
  }
94
- /**
95
- * Convenience function that directly wraps an execute function
96
- */
97
65
  export function createX402Execute(options, execute) {
98
66
  return withX402Payment(options)(execute);
99
67
  }
@@ -1 +1 @@
1
- {"version":3,"file":"middleware.js","sourceRoot":"","sources":["../../../../src/mcp/server/fastmcp/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,GAOf,MAAM,SAAS,CAAA;AAChB,OAAO,EAAsE,MAAM,YAAY,CAAA;AAmD/F;;;;;;GAMG;AACH,SAAS,kBAAkB,CACzB,YAAiC,EACjC,cAA6B,IAAI,EACjC,kBAAyC,IAAI;IAE7C,MAAM,IAAI,GAAqB;QAC7B,OAAO,EAAE,qCAAqC;QAC9C,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,CAAC;QACd,OAAO,EAAE,CAAC,YAAY,CAAC;KACxB,CAAA;IACD,IAAI,WAAW,EAAE,CAAC;QAChB,IAAI,CAAC,KAAK,GAAG,WAAW,CAAA;IAC1B,CAAC;IACD,IAAI,eAAe,EAAE,CAAC;QACpB,IAAI,CAAC,uBAAuB,CAAC,GAAG,eAAe,CAAA;IACjD,CAAC;IAED,OAAO,IAAI,cAAc,CAAC,GAAG,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;AACpD,CAAC;AAYD,SAAS,mBAAmB,CAAC,MAAyB;IACpD,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAC5C,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,CAAA;IACxB,CAAC;IAED,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC,EAAE,CAAA;IACtD,CAAC;IAED,iEAAiE;IACjE,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;QACrB,OAAO,EAAE,OAAO,EAAE,CAAC,MAAM,CAAC,EAAE,CAA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AM,kBAAkB,CAAC,YAAY,EAAE,MAAM,CAAC,CAAA;YAChD,CAAC;YACD,IAAI,UAAU,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;gBACtC,MAAM,kBAAkB,CAAC,YAAY,EAAE,UAAU,CAAC,WAAW,IAAI,IAAI,EAAE,UAAU,CAAC,CAAA;YACpF,CAAC;YAED,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;YAE3C,IAAI,CAAC,UAAU,EAAE,CAAC;gBAChB,OAAO,MAAM,CAAA;YACf,CAAC;YAED,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,MAA2B,CAAC,CAAA;YACzE,gBAAgB,CAAC,KAAK,GAAG;gBACvB,GAAG,gBAAgB,CAAC,KAAK;gBACzB,uBAAuB,EAAE,UAAU;aACpC,CAAA;YACD,OAAO,gBAA2B,CAAA;QACpC,CAAC,CAAA;IACH,CAAC,CAAA;AACH,CAAC;AAED,MAAM,UAAU,iBAAiB,CAC/B,OAA+B,EAC/B,OAAwC;IAExC,OAAO,eAAe,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAA;AAC1C,CAAC"}
package/dist/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  /** SDK version - keep in sync with package.json */
2
- export declare const VERSION = "0.0.16";
2
+ export declare const VERSION = "0.0.21";
3
3
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -1,3 +1,3 @@
1
1
  /** SDK version - keep in sync with package.json */
2
- export const VERSION = "0.0.16";
2
+ export const VERSION = "0.0.21";
3
3
  //# sourceMappingURL=version.js.map
@@ -0,0 +1,62 @@
1
+ /**
2
+ * Ampersend protocol envelopes: `{ protocol, data }` wrappers where `data` is
3
+ * the byte-exact upstream payload (no re-serialization).
4
+ *
5
+ * PaymentRequest (seller's 402)
6
+ * ↓ treasurer picks accepts[i]
7
+ * PaymentInstruction (request + index; wallet input)
8
+ * ↓ wallet signs
9
+ * PaymentAuthorization (signed, ready to submit)
10
+ * ↓ facilitator settles
11
+ * SettlementResult
12
+ *
13
+ * `PaymentInstruction` keeps the full request by reference so v2's
14
+ * `deepEqual(accepts[i], …)` check (spec §5.1.3) can't drift.
15
+ */
16
+ import type { PaymentPayloadV1, PaymentPayloadV2, PaymentRequiredV1, PaymentRequiredV2, PaymentRequirementsV1, PaymentRequirementsV2 } from "@x402/core/schemas";
17
+ import type { SettleResponse } from "@x402/core/types";
18
+ export type Protocol = "x402-v1" | "x402-v2";
19
+ /** The seller's full 402 body. Treasurers pick one `data.accepts[i]` (or none). */
20
+ export type PaymentRequest = {
21
+ readonly protocol: "x402-v1";
22
+ readonly data: PaymentRequiredV1;
23
+ } | {
24
+ readonly protocol: "x402-v2";
25
+ readonly data: PaymentRequiredV2;
26
+ };
27
+ /** Request + `acceptsIndex`. Full request rides along so v2 echo is byte-exact. */
28
+ export type PaymentInstruction = {
29
+ readonly protocol: "x402-v1";
30
+ readonly request: PaymentRequiredV1;
31
+ readonly acceptsIndex: number;
32
+ } | {
33
+ readonly protocol: "x402-v2";
34
+ readonly request: PaymentRequiredV2;
35
+ readonly acceptsIndex: number;
36
+ };
37
+ export type PaymentAuthorization = {
38
+ readonly protocol: "x402-v1";
39
+ readonly data: PaymentPayloadV1;
40
+ } | {
41
+ readonly protocol: "x402-v2";
42
+ readonly data: PaymentPayloadV2;
43
+ };
44
+ /** Upstream ships one `SettleResponse` for both versions. */
45
+ export type SettlementResult = {
46
+ readonly protocol: "x402-v1";
47
+ readonly data: SettleResponse;
48
+ } | {
49
+ readonly protocol: "x402-v2";
50
+ readonly data: SettleResponse;
51
+ };
52
+ export declare function acceptedOf(instruction: PaymentInstruction): PaymentRequirementsV1 | PaymentRequirementsV2;
53
+ /** Payment amount in atomic units (stringified bigint). */
54
+ export declare function amountOf(instruction: PaymentInstruction): string;
55
+ export declare function resourceUrlOf(instruction: PaymentInstruction): string;
56
+ /** Wrap a request at `acceptsIndex: 0`. Upstream `accepts.min(1)` guarantees non-empty. */
57
+ export declare function firstInstructionOf(request: PaymentRequest): PaymentInstruction;
58
+ /** Scheme-specific signed body. exact-EVM: `{ signature, authorization }`. */
59
+ export type SchemeSpecificPayload = Record<string, unknown>;
60
+ /** Wrap a signed payload into a `PaymentAuthorization`. v2 echoes `resource`, `accepted`, `extensions` verbatim. */
61
+ export declare function buildAuthorization(instruction: PaymentInstruction, signedPayload: SchemeSpecificPayload): PaymentAuthorization;
62
+ //# sourceMappingURL=envelopes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelopes.d.ts","sourceRoot":"","sources":["../../src/x402/envelopes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAEtD,MAAM,MAAM,QAAQ,GAAG,SAAS,GAAG,SAAS,CAAA;AAE5C,mFAAmF;AACnF,MAAM,MAAM,cAAc,GACtB;IAAE,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAA;CAAE,GAClE;IAAE,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,iBAAiB,CAAA;CAAE,CAAA;AAEtE,mFAAmF;AACnF,MAAM,MAAM,kBAAkB,GAC1B;IACE,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAA;IAC5B,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAA;IACnC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAC9B,GACD;IACE,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAA;IAC5B,QAAQ,CAAC,OAAO,EAAE,iBAAiB,CAAA;IACnC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAC9B,CAAA;AAEL,MAAM,MAAM,oBAAoB,GAC5B;IAAE,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAA;CAAE,GACjE;IAAE,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAA;CAAE,CAAA;AAErE,6DAA6D;AAC7D,MAAM,MAAM,gBAAgB,GACxB;IAAE,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;CAAE,GAC/D;IAAE,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,cAAc,CAAA;CAAE,CAAA;AAEnE,wBAAgB,UAAU,CAAC,WAAW,EAAE,kBAAkB,GAAG,qBAAqB,GAAG,qBAAqB,CAQzG;AAED,2DAA2D;AAC3D,wBAAgB,QAAQ,CAAC,WAAW,EAAE,kBAAkB,GAAG,MAAM,CAIhE;AAED,wBAAgB,aAAa,CAAC,WAAW,EAAE,kBAAkB,GAAG,MAAM,CAIrE;AAED,2FAA2F;AAC3F,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,cAAc,GAAG,kBAAkB,CAI9E;AAED,8EAA8E;AAC9E,MAAM,MAAM,qBAAqB,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAE3D,oHAAoH;AACpH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,kBAAkB,EAC/B,aAAa,EAAE,qBAAqB,GACnC,oBAAoB,CA+BtB"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Ampersend protocol envelopes: `{ protocol, data }` wrappers where `data` is
3
+ * the byte-exact upstream payload (no re-serialization).
4
+ *
5
+ * PaymentRequest (seller's 402)
6
+ * ↓ treasurer picks accepts[i]
7
+ * PaymentInstruction (request + index; wallet input)
8
+ * ↓ wallet signs
9
+ * PaymentAuthorization (signed, ready to submit)
10
+ * ↓ facilitator settles
11
+ * SettlementResult
12
+ *
13
+ * `PaymentInstruction` keeps the full request by reference so v2's
14
+ * `deepEqual(accepts[i], …)` check (spec §5.1.3) can't drift.
15
+ */
16
+ export function acceptedOf(instruction) {
17
+ const accepted = instruction.request.accepts[instruction.acceptsIndex];
18
+ if (!accepted) {
19
+ throw new Error(`PaymentInstruction.acceptsIndex ${instruction.acceptsIndex} out of bounds (accepts.length=${instruction.request.accepts.length})`);
20
+ }
21
+ return accepted;
22
+ }
23
+ /** Payment amount in atomic units (stringified bigint). */
24
+ export function amountOf(instruction) {
25
+ return instruction.protocol === "x402-v1"
26
+ ? instruction.request.accepts[instruction.acceptsIndex].maxAmountRequired
27
+ : instruction.request.accepts[instruction.acceptsIndex].amount;
28
+ }
29
+ export function resourceUrlOf(instruction) {
30
+ return instruction.protocol === "x402-v1"
31
+ ? instruction.request.accepts[instruction.acceptsIndex].resource
32
+ : instruction.request.resource.url;
33
+ }
34
+ /** Wrap a request at `acceptsIndex: 0`. Upstream `accepts.min(1)` guarantees non-empty. */
35
+ export function firstInstructionOf(request) {
36
+ return request.protocol === "x402-v1"
37
+ ? { protocol: "x402-v1", request: request.data, acceptsIndex: 0 }
38
+ : { protocol: "x402-v2", request: request.data, acceptsIndex: 0 };
39
+ }
40
+ /** Wrap a signed payload into a `PaymentAuthorization`. v2 echoes `resource`, `accepted`, `extensions` verbatim. */
41
+ export function buildAuthorization(instruction, signedPayload) {
42
+ if (instruction.protocol === "x402-v1") {
43
+ const accepted = instruction.request.accepts[instruction.acceptsIndex];
44
+ if (!accepted) {
45
+ throw new Error(`PaymentInstruction.acceptsIndex ${instruction.acceptsIndex} out of bounds`);
46
+ }
47
+ return {
48
+ protocol: "x402-v1",
49
+ data: {
50
+ x402Version: 1,
51
+ scheme: accepted.scheme,
52
+ network: accepted.network,
53
+ payload: signedPayload,
54
+ },
55
+ };
56
+ }
57
+ const accepted = instruction.request.accepts[instruction.acceptsIndex];
58
+ if (!accepted) {
59
+ throw new Error(`PaymentInstruction.acceptsIndex ${instruction.acceptsIndex} out of bounds`);
60
+ }
61
+ return {
62
+ protocol: "x402-v2",
63
+ data: {
64
+ x402Version: 2,
65
+ resource: instruction.request.resource,
66
+ accepted,
67
+ payload: signedPayload,
68
+ ...(instruction.request.extensions !== undefined &&
69
+ instruction.request.extensions !== null && { extensions: instruction.request.extensions }),
70
+ },
71
+ };
72
+ }
73
+ //# sourceMappingURL=envelopes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"envelopes.js","sourceRoot":"","sources":["../../src/x402/envelopes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAyCH,MAAM,UAAU,UAAU,CAAC,WAA+B;IACxD,MAAM,QAAQ,GAAG,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,YAAY,CAAC,CAAA;IACtE,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CACb,mCAAmC,WAAW,CAAC,YAAY,kCAAkC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,GAAG,CACnI,CAAA;IACH,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,QAAQ,CAAC,WAA+B;IACtD,OAAO,WAAW,CAAC,QAAQ,KAAK,SAAS;QACvC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,YAAY,CAAE,CAAC,iBAAiB;QAC1E,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW,CAAC,YAAY,CAAE,CAAC,MAAM,CAAA;AACnE,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,WAA+B;IAC3D,OAAO,WAAW,CAAC,QAAQ,KAAK,SAAS;QACvC,CAAC,CAAC,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,WAAW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Q,EAAE,SAAS;QACnB,IAAI,EAAE;YACJ,WAAW,EAAE,CAAC;YACd,QAAQ,EAAE,WAAW,CAAC,OAAO,CAAC,QAAQ;YACtC,QAAQ;YACR,OAAO,EAAE,aAAa;YACtB,GAAG,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS;gBAC9C,WAAW,CAAC,OAAO,CAAC,UAAU,KAAK,IAAI,IAAI,EAAE,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;SAC7F;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { x402Client } from "@x402/core/client";
2
+ import type { PaymentPayload as V2PaymentPayload, PaymentRequired as V2PaymentRequired } from "@x402/core/types";
3
+ import type { X402Treasurer } from "../treasurer.ts";
4
+ /**
5
+ * v1 uses network names (`"base"`), v2 uses CAIP-2 (`"eip155:8453"`) or
6
+ * wildcards (`"eip155:*"`). Register whichever protocols you want to accept.
7
+ */
8
+ export interface AmpersendNetworks {
9
+ v1?: ReadonlyArray<string>;
10
+ v2?: ReadonlyArray<string>;
11
+ }
12
+ export declare class PaymentDeclinedError extends Error {
13
+ constructor();
14
+ }
15
+ export declare class UnsupportedProtocolError extends Error {
16
+ readonly x402Version: number;
17
+ constructor(x402Version: number);
18
+ }
19
+ /**
20
+ * `x402Client` whose `accepts[i]` selection is driven by an async treasurer.
21
+ *
22
+ * Upstream's selector is sync, so we override `createPaymentPayload` to run
23
+ * the treasurer first, stash `{ accepted → authorization }` in a WeakMap,
24
+ * and delegate to `super`. The installed selector returns the stashed entry
25
+ * by reference equality; our scheme client hands back the pre-signed payload.
26
+ * Hooks, policies, extensions, and failure recovery stay upstream's.
27
+ *
28
+ * Reference equality on `Authorization.accepted` is load-bearing — the
29
+ * treasurer must return the original `accepts[i]`, not a clone.
30
+ */
31
+ export declare class AmpersendX402Client extends x402Client {
32
+ #private;
33
+ constructor(treasurer: X402Treasurer);
34
+ withNetworks(networks: AmpersendNetworks): this;
35
+ createPaymentPayload(paymentRequired: V2PaymentRequired): Promise<V2PaymentPayload>;
36
+ }
37
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/x402/http/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAQ9C,OAAO,KAAK,EAGV,cAAc,IAAI,gBAAgB,EAClC,eAAe,IAAI,iBAAiB,EAErC,MAAM,kBAAkB,CAAA;AAGzB,OAAO,KAAK,EAAiB,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEnE;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,EAAE,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;IAC1B,EAAE,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;CAC3B;AAED,qBAAa,oBAAqB,SAAQ,KAAK;;CAK9C;AAED,qBAAa,wBAAyB,SAAQ,KAAK;aACrB,WAAW,EAAE,MAAM;gBAAnB,WAAW,EAAE,MAAM;CAOhD;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,mBAAoB,SAAQ,UAAU;;gBAKrC,SAAS,EAAE,aAAa;IAmBpC,YAAY,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;IAehC,oBAAoB,CAAC,eAAe,EAAE,iBAAiB,GAAG,OAAO,CAAC,gBAAgB,CAAC;CAwCnG"}
@@ -0,0 +1,159 @@
1
+ import { x402Client } from "@x402/core/client";
2
+ import { PaymentRequiredV1Schema, PaymentRequiredV2Schema, } from "@x402/core/schemas";
3
+ export class PaymentDeclinedError extends Error {
4
+ constructor() {
5
+ super("Payment declined by treasurer");
6
+ this.name = "PaymentDeclinedError";
7
+ }
8
+ }
9
+ export class UnsupportedProtocolError extends Error {
10
+ x402Version;
11
+ constructor(x402Version) {
12
+ super(`No scheme registered for x402 version ${x402Version}. ` +
13
+ `Register at least one network for this version via \`.withNetworks({ v${x402Version}: [...] })\`.`);
14
+ this.x402Version = x402Version;
15
+ this.name = "UnsupportedProtocolError";
16
+ }
17
+ }
18
+ /**
19
+ * `x402Client` whose `accepts[i]` selection is driven by an async treasurer.
20
+ *
21
+ * Upstream's selector is sync, so we override `createPaymentPayload` to run
22
+ * the treasurer first, stash `{ accepted → authorization }` in a WeakMap,
23
+ * and delegate to `super`. The installed selector returns the stashed entry
24
+ * by reference equality; our scheme client hands back the pre-signed payload.
25
+ * Hooks, policies, extensions, and failure recovery stay upstream's.
26
+ *
27
+ * Reference equality on `Authorization.accepted` is load-bearing — the
28
+ * treasurer must return the original `accepts[i]`, not a clone.
29
+ */
30
+ export class AmpersendX402Client extends x402Client {
31
+ #treasurer;
32
+ #authByAccepted;
33
+ #supportedVersions = new Set();
34
+ constructor(treasurer) {
35
+ const authByAccepted = new WeakMap();
36
+ super((_x402Version, accepts) => {
37
+ for (const accept of accepts) {
38
+ if (authByAccepted.has(accept))
39
+ return accept;
40
+ }
41
+ throw new Error("AmpersendX402Client: the treasurer's pick is not present in the filtered " +
42
+ "accepts[]. It was either filtered out by a registered policy or the scheme/" +
43
+ "network is not registered. Register the network with `.withNetworks()` or " +
44
+ "relax the policy so the treasurer's pick survives.");
45
+ });
46
+ this.#treasurer = treasurer;
47
+ this.#authByAccepted = authByAccepted;
48
+ }
49
+ withNetworks(networks) {
50
+ const schemeClient = new TreasurerSchemeClient(this.#authByAccepted);
51
+ if (networks.v1?.length)
52
+ this.#supportedVersions.add(1);
53
+ if (networks.v2?.length)
54
+ this.#supportedVersions.add(2);
55
+ for (const network of networks.v1 ?? []) {
56
+ this.registerV1(network, schemeClient);
57
+ }
58
+ for (const network of networks.v2 ?? []) {
59
+ // Upstream pattern-matches networks (including wildcards), but types
60
+ // them as CAIP-2 template literals.
61
+ this.register(network, schemeClient);
62
+ }
63
+ return this;
64
+ }
65
+ async createPaymentPayload(paymentRequired) {
66
+ // Fail before calling the treasurer — avoids wasting an API round-trip on an unsignable request.
67
+ if (!this.#supportedVersions.has(paymentRequired.x402Version)) {
68
+ throw new UnsupportedProtocolError(paymentRequired.x402Version);
69
+ }
70
+ const request = toPaymentRequest(paymentRequired);
71
+ let authorization;
72
+ try {
73
+ authorization = await this.#treasurer.onPaymentRequired(request, { method: "http" });
74
+ }
75
+ catch (error) {
76
+ throw new Error(`Treasurer failed: ${error instanceof Error ? error.message : String(error)}`);
77
+ }
78
+ if (!authorization)
79
+ throw new PaymentDeclinedError();
80
+ const accepted = authorization.accepted;
81
+ if (!paymentRequired.accepts.includes(authorization.accepted)) {
82
+ throw new Error("AmpersendX402Client: Authorization.accepted is not an element of " +
83
+ "paymentRequired.accepts (reference equality required). The treasurer must " +
84
+ "return the original accepts[i] reference, not a clone.");
85
+ }
86
+ this.#authByAccepted.set(accepted, authorization);
87
+ try {
88
+ const payload = await super.createPaymentPayload(paymentRequired);
89
+ await this.#treasurer.onStatus("sending", authorization, { method: "http" });
90
+ return payload;
91
+ }
92
+ catch (error) {
93
+ await this.#treasurer.onStatus("error", authorization, {
94
+ method: "http",
95
+ params: { error: error instanceof Error ? error.message : String(error) },
96
+ });
97
+ throw error;
98
+ }
99
+ finally {
100
+ this.#authByAccepted.delete(accepted);
101
+ }
102
+ }
103
+ }
104
+ /** Does not sign — returns the treasurer's pre-signed payload, looked up by `accepts[i]` reference. */
105
+ class TreasurerSchemeClient {
106
+ store;
107
+ scheme = "exact";
108
+ constructor(store) {
109
+ this.store = store;
110
+ }
111
+ async createPaymentPayload(x402Version, requirements) {
112
+ const authorization = this.store.get(requirements);
113
+ if (!authorization) {
114
+ throw new Error("TreasurerSchemeClient invoked without a stashed authorization. This " +
115
+ "indicates a call path that bypassed AmpersendX402Client.createPaymentPayload.");
116
+ }
117
+ const payment = authorization.payment;
118
+ if (x402Version === 1) {
119
+ if (payment.protocol !== "x402-v1") {
120
+ throw new Error(`Expected v1 authorization; got ${payment.protocol}`);
121
+ }
122
+ return payment.data;
123
+ }
124
+ if (payment.protocol !== "x402-v2") {
125
+ throw new Error(`Expected v2 authorization; got ${payment.protocol}`);
126
+ }
127
+ // Upstream reconstructs `resource` and `accepted` from paymentRequired,
128
+ // so we only return x402Version + payload + optional extensions.
129
+ const result = {
130
+ x402Version: payment.data.x402Version,
131
+ payload: payment.data.payload,
132
+ };
133
+ if (payment.data.extensions != null) {
134
+ result.extensions = payment.data.extensions;
135
+ }
136
+ return result;
137
+ }
138
+ }
139
+ // `data` keeps the original reference (not `r.data`) — reference-equality on
140
+ // `accepts[i]` is load-bearing for the WeakMap dispatch above.
141
+ function toPaymentRequest(paymentRequired) {
142
+ switch (paymentRequired.x402Version) {
143
+ case 1: {
144
+ const r = PaymentRequiredV1Schema.safeParse(paymentRequired);
145
+ if (!r.success)
146
+ throw new Error(`Invalid x402 v1 PaymentRequired: ${r.error.message}`);
147
+ return { protocol: "x402-v1", data: paymentRequired };
148
+ }
149
+ case 2: {
150
+ const r = PaymentRequiredV2Schema.safeParse(paymentRequired);
151
+ if (!r.success)
152
+ throw new Error(`Invalid x402 v2 PaymentRequired: ${r.error.message}`);
153
+ return { protocol: "x402-v2", data: paymentRequired };
154
+ }
155
+ default:
156
+ throw new Error(`Unsupported x402 version: ${paymentRequired.x402Version}`);
157
+ }
158
+ }
159
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/x402/http/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,EACL,uBAAuB,EACvB,uBAAuB,GAIxB,MAAM,oBAAoB,CAAA;AAqB3B,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C;QACE,KAAK,CAAC,+BAA+B,CAAC,CAAA;QACtC,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAA;IACpC,CAAC;CACF;AAED,MAAM,OAAO,wBAAyB,SAAQ,KAAK;IACrB;IAA5B,YAA4B,WAAmB;QAC7C,KAAK,CACH,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