@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,31 +1,22 @@
1
1
  /**
2
- * Simplified factory for Ampersend HTTP client.
3
- *
4
- * Provides one-liner setup for wrapping x402 HTTP clients with Ampersend payment support.
2
+ * Returns an `x402Client` subclass, so the result drops into
3
+ * `wrapFetchWithPayment` unchanged. For advanced setups, construct
4
+ * `AmpersendX402Client` directly.
5
5
  */
6
- import { x402Client } from "@x402/core/client";
7
6
  import type { Address, Hex } from "viem";
8
- import { type Network } from "x402/types";
9
- /**
10
- * Simplified options for Ampersend HTTP client wrapper.
11
- */
7
+ import { AmpersendX402Client } from "./client.ts";
12
8
  export interface SimpleHttpClientOptions {
13
- /** Smart account address */
9
+ /** Smart account address. */
14
10
  smartAccountAddress: Address;
15
- /** Session key private key for signing */
11
+ /** Session key private key for signing. */
16
12
  sessionKeyPrivateKey: Hex;
17
- /** The x402Client instance to wrap (created automatically if not provided) */
18
- client?: x402Client;
19
- /** Ampersend API URL (defaults to production) */
13
+ /** Ampersend API URL. Defaults to production. */
20
14
  apiUrl?: string;
21
- /** Network to use (defaults to "base"). Chain ID is inferred from this. */
22
- network?: Network;
15
+ /** v1 network name (e.g. `"base"`). v1 and v2 (CAIP-2) are both registered. */
16
+ network?: string;
23
17
  }
24
18
  /**
25
- * Create an x402 HTTP client with Ampersend payment support.
26
- *
27
- * This integrates ampersend-sdk with Coinbase's x402 SDK, allowing you to use
28
- * sophisticated payment authorization logic with the standard x402 HTTP client ecosystem.
19
+ * Create an `AmpersendX402Client` wired to the Ampersend API.
29
20
  *
30
21
  * @example
31
22
  * ```typescript
@@ -36,14 +27,9 @@ export interface SimpleHttpClientOptions {
36
27
  * smartAccountAddress: "0x...",
37
28
  * sessionKeyPrivateKey: "0x...",
38
29
  * })
39
- *
40
30
  * const fetchWithPay = wrapFetchWithPayment(fetch, client)
41
31
  * const response = await fetchWithPay("https://paid-api.com/endpoint")
42
32
  * ```
43
- *
44
- * @param options - Simplified HTTP client configuration
45
- * @returns The configured x402Client instance
46
33
  */
47
- export declare function createAmpersendHttpClient(options: SimpleHttpClientOptions): x402Client;
48
- export { wrapWithAmpersend } from "./adapter.ts";
34
+ export declare function createAmpersendHttpClient(options: SimpleHttpClientOptions): AmpersendX402Client;
49
35
  //# sourceMappingURL=factory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/x402/http/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAC9C,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AACxC,OAAO,EAAuB,KAAK,OAAO,EAAE,MAAM,YAAY,CAAA;AAW9D;;GAEG;AACH,MAAM,WAAW,uBAAuB;IACtC,4BAA4B;IAC5B,mBAAmB,EAAE,OAAO,CAAA;IAC5B,0CAA0C;IAC1C,oBAAoB,EAAE,GAAG,CAAA;IACzB,8EAA8E;IAC9E,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,iDAAiD;IACjD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,2EAA2E;IAC3E,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,uBAAuB,GAAG,UAAU,CAiBtF;AAGD,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA"}
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/x402/http/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAA;AAGxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAKjD,MAAM,WAAW,uBAAuB;IACtC,6BAA6B;IAC7B,mBAAmB,EAAE,OAAO,CAAA;IAC5B,2CAA2C;IAC3C,oBAAoB,EAAE,GAAG,CAAA;IACzB,iDAAiD;IACjD,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,+EAA+E;IAC/E,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,uBAAuB,GAAG,mBAAmB,CAiB/F"}
@@ -1,21 +1,15 @@
1
1
  /**
2
- * Simplified factory for Ampersend HTTP client.
3
- *
4
- * Provides one-liner setup for wrapping x402 HTTP clients with Ampersend payment support.
2
+ * Returns an `x402Client` subclass, so the result drops into
3
+ * `wrapFetchWithPayment` unchanged. For advanced setups, construct
4
+ * `AmpersendX402Client` directly.
5
5
  */
6
- import { x402Client } from "@x402/core/client";
7
- import { EvmNetworkToChainId } from "x402/types";
6
+ import { EVM_NETWORK_CHAIN_ID_MAP } from "@x402/evm/v1";
8
7
  import { createAmpersendTreasurer } from "../../ampersend/treasurer.js";
9
- import { wrapWithAmpersend } from "./adapter.js";
10
- /** Default Ampersend API URL */
8
+ import { AmpersendX402Client } from "./client.js";
11
9
  const DEFAULT_API_URL = "https://api.ampersend.ai";
12
- /** Default network (Base mainnet for production) */
13
10
  const DEFAULT_NETWORK = "base";
14
11
  /**
15
- * Create an x402 HTTP client with Ampersend payment support.
16
- *
17
- * This integrates ampersend-sdk with Coinbase's x402 SDK, allowing you to use
18
- * sophisticated payment authorization logic with the standard x402 HTTP client ecosystem.
12
+ * Create an `AmpersendX402Client` wired to the Ampersend API.
19
13
  *
20
14
  * @example
21
15
  * ```typescript
@@ -26,17 +20,13 @@ const DEFAULT_NETWORK = "base";
26
20
  * smartAccountAddress: "0x...",
27
21
  * sessionKeyPrivateKey: "0x...",
28
22
  * })
29
- *
30
23
  * const fetchWithPay = wrapFetchWithPayment(fetch, client)
31
24
  * const response = await fetchWithPay("https://paid-api.com/endpoint")
32
25
  * ```
33
- *
34
- * @param options - Simplified HTTP client configuration
35
- * @returns The configured x402Client instance
36
26
  */
37
27
  export function createAmpersendHttpClient(options) {
38
28
  const network = options.network ?? DEFAULT_NETWORK;
39
- const chainId = EvmNetworkToChainId.get(network);
29
+ const chainId = EVM_NETWORK_CHAIN_ID_MAP[network];
40
30
  if (chainId === undefined) {
41
31
  throw new Error(`Unknown network: ${network}`);
42
32
  }
@@ -44,11 +34,10 @@ export function createAmpersendHttpClient(options) {
44
34
  smartAccountAddress: options.smartAccountAddress,
45
35
  sessionKeyPrivateKey: options.sessionKeyPrivateKey,
46
36
  apiUrl: options.apiUrl ?? DEFAULT_API_URL,
47
- chainId,
48
37
  });
49
- const client = options.client ?? new x402Client();
50
- return wrapWithAmpersend(client, treasurer, [network]);
38
+ return new AmpersendX402Client(treasurer).withNetworks({
39
+ v1: [network],
40
+ v2: [`eip155:${chainId}`],
41
+ });
51
42
  }
52
- // Re-export original for advanced use cases
53
- export { wrapWithAmpersend } from "./adapter.js";
54
43
  //# sourceMappingURL=factory.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/x402/http/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,OAAO,EAAE,mBAAmB,EAAgB,MAAM,YAAY,CAAA;AAE9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEhD,gCAAgC;AAChC,MAAM,eAAe,GAAG,0BAA0B,CAAA;AAElD,oDAAoD;AACpD,MAAM,eAAe,GAAY,MAAM,CAAA;AAkBvC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAgC;IACxE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,eAAe,CAAA;IAClD,MAAM,OAAO,GAAG,mBAAmB,CAAC,GAAG,CAAC,OAAO,CAAC,CAAA;IAEhD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAA;IAChD,CAAC;IAED,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;KACR,CAAC,CAAA;IAEF,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,IAAI,UAAU,EAAE,CAAA;IACjD,OAAO,iBAAiB,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;AACxD,CAAC;AAED,4CAA4C;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA"}
1
+ {"version":3,"file":"factory.js","sourceRoot":"","sources":["../../../src/x402/http/factory.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAA;AAGvD,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAA;AACvE,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEjD,MAAM,eAAe,GAAG,0BAA0B,CAAA;AAClD,MAAM,eAAe,GAAG,MAAM,CAAA;AAa9B;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,yBAAyB,CAAC,OAAgC;IACxE,MAAM,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,eAAe,CAAA;IAClD,MAAM,OAAO,GAAI,wBAA6D,CAAC,OAAO,CAAC,CAAA;IACvF,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAA;IAChD,CAAC;IAED,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,IAAI,mBAAmB,CAAC,SAAS,CAAC,CAAC,YAAY,CAAC;QACrD,EAAE,EAAE,CAAC,OAAO,CAAC;QACb,EAAE,EAAE,CAAC,UAAU,OAAO,EAAE,CAAC;KAC1B,CAAC,CAAA;AACJ,CAAC"}
@@ -1,2 +1,5 @@
1
- export { wrapWithAmpersend } from "./adapter.ts";
1
+ export { AmpersendX402Client, PaymentDeclinedError, UnsupportedProtocolError } from "./client.ts";
2
+ export type { AmpersendNetworks } from "./client.ts";
3
+ export { createAmpersendHttpClient } from "./factory.ts";
4
+ export type { SimpleHttpClientOptions } from "./factory.ts";
2
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/x402/http/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/x402/http/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AACjG,YAAY,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA;AACxD,YAAY,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA"}
@@ -1,2 +1,3 @@
1
- export { wrapWithAmpersend } from "./adapter.js";
1
+ export { AmpersendX402Client, PaymentDeclinedError, UnsupportedProtocolError } from "./client.js";
2
+ export { createAmpersendHttpClient } from "./factory.js";
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/x402/http/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/x402/http/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAA;AAEjG,OAAO,EAAE,yBAAyB,EAAE,MAAM,cAAc,CAAA"}
@@ -1,8 +1,11 @@
1
+ export type { PaymentAuthorization, PaymentInstruction, PaymentRequest, Protocol, SchemeSpecificPayload, SettlementResult, } from "./envelopes.ts";
2
+ export { acceptedOf, amountOf, buildAuthorization, firstInstructionOf, resourceUrlOf } from "./envelopes.ts";
1
3
  export type { Authorization, PaymentContext, PaymentStatus, X402Treasurer } from "./treasurer.ts";
2
4
  export type { ERC3009AuthorizationData, ServerAuthorizationData } from "./types.ts";
3
5
  export { WalletError } from "./wallet.ts";
4
6
  export type { X402Wallet } from "./wallet.ts";
5
7
  export { AccountWallet, SmartAccountWallet, createWalletFromConfig } from "./wallets/index.ts";
6
8
  export type { SmartAccountConfig, WalletConfig, EOAWalletConfig, SmartAccountWalletConfig } from "./wallets/index.ts";
7
- export { wrapWithAmpersend } from "./http/index.ts";
9
+ export { AmpersendX402Client, PaymentDeclinedError, UnsupportedProtocolError, createAmpersendHttpClient, } from "./http/index.ts";
10
+ export type { AmpersendNetworks, SimpleHttpClientOptions } from "./http/index.ts";
8
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/x402/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACjG,YAAY,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAG7C,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAC9F,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAGrH,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/x402/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,oBAAoB,EACpB,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACR,qBAAqB,EACrB,gBAAgB,GACjB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAG5G,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AACjG,YAAY,EAAE,wBAAwB,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AACnF,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AACzC,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAG7C,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAC9F,YAAY,EAAE,kBAAkB,EAAE,YAAY,EAAE,eAAe,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAGrH,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,iBAAiB,CAAA;AACxB,YAAY,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAA"}
@@ -1,6 +1,7 @@
1
+ export { acceptedOf, amountOf, buildAuthorization, firstInstructionOf, resourceUrlOf } from "./envelopes.js";
1
2
  export { WalletError } from "./wallet.js";
2
3
  // Wallet implementations
3
4
  export { AccountWallet, SmartAccountWallet, createWalletFromConfig } from "./wallets/index.js";
4
- // HTTP adapter
5
- export { wrapWithAmpersend } from "./http/index.js";
5
+ // HTTP integration
6
+ export { AmpersendX402Client, PaymentDeclinedError, UnsupportedProtocolError, createAmpersendHttpClient, } from "./http/index.js";
6
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/x402/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGzC,yBAAyB;AACzB,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAG9F,eAAe;AACf,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/x402/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAK5G,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAGzC,yBAAyB;AACzB,OAAO,EAAE,aAAa,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAA;AAG9F,mBAAmB;AACnB,OAAO,EACL,mBAAmB,EACnB,oBAAoB,EACpB,wBAAwB,EACxB,yBAAyB,GAC1B,MAAM,iBAAiB,CAAA"}
@@ -1,64 +1,39 @@
1
- import type { PaymentPayload, PaymentRequirements } from "x402/types";
1
+ import type { PaymentRequirementsV1, PaymentRequirementsV2 } from "@x402/core/schemas";
2
+ import type { PaymentAuthorization, PaymentRequest } from "./envelopes.ts";
2
3
  /**
3
- * Context information for payment decisions
4
+ * Loose caller context which protocol triggered the flow and any debugging
5
+ * metadata. NOT payment details; those live on the {@link PaymentRequest}.
4
6
  */
5
7
  export interface PaymentContext {
6
8
  method: string;
7
- params: any;
9
+ params?: any;
8
10
  metadata?: Record<string, unknown>;
9
11
  }
10
- /**
11
- * Authorization linking a payment with a tracking ID
12
- */
13
12
  export interface Authorization {
14
- payment: PaymentPayload;
13
+ payment: PaymentAuthorization;
15
14
  authorizationId: string;
15
+ /**
16
+ * The `accepts[i]` the wallet signed against. Must be `===` to an element
17
+ * of the original `PaymentRequest.data.accepts` — reference equality is
18
+ * load-bearing for downstream integrations (e.g. the `x402Client` subclass).
19
+ */
20
+ accepted: PaymentRequirementsV1 | PaymentRequirementsV2;
16
21
  }
17
- /**
18
- * Payment status types for tracking payment lifecycle
19
- */
20
22
  export type PaymentStatus = "sending" | "accepted" | "rejected" | "declined" | "error";
21
23
  /**
22
- * X402Treasurer interface - Separates payment decision logic from payment creation
23
- *
24
- * An X402Treasurer decides whether to approve or reject payment requests,
25
- * tracks payment status, and delegates actual payment creation to an X402Wallet.
24
+ * Separates payment *decisions* from payment *creation*. Receives the seller's
25
+ * full 402 body, returns a signed {@link Authorization} or `null` to decline.
26
+ * Internally picks an index into `request.data.accepts[]` and hands the
27
+ * resulting `PaymentInstruction` to a wallet; use {@link firstInstructionOf}
28
+ * for the trivial "take the first option" case.
26
29
  *
27
- * @example
28
- * ```typescript
29
- * class BudgetTreasurer implements X402Treasurer {
30
- * constructor(private wallet: X402Wallet, private dailyLimit: number) {}
31
- *
32
- * async onPaymentRequired(requirements, context) {
33
- * if (this.wouldExceedBudget(requirements[0])) {
34
- * return null // Decline
35
- * }
36
- * const payment = await this.wallet.createPayment(requirements[0])
37
- * return { payment, authorizationId: crypto.randomUUID() }
38
- * }
39
- *
40
- * async onStatus(status, authorization, context) {
41
- * console.log(`Payment ${authorization.authorizationId}: ${status}`)
42
- * }
43
- * }
44
- * ```
30
+ * Return `null` only for domain-level declines (budget exhausted, user
31
+ * rejected, policy said no). Infrastructure failures — network errors, auth
32
+ * failures, wallet signing errors — must **throw**, so callers can distinguish
33
+ * "you can't have this payment" from "something is broken."
45
34
  */
46
35
  export interface X402Treasurer {
47
- /**
48
- * Called when payment is required.
49
- *
50
- * @param requirements - Array of payment requirements from seller (typically use first)
51
- * @param context - Optional context about the request requiring payment
52
- * @returns Authorization to proceed with payment, or null to decline
53
- */
54
- onPaymentRequired(requirements: ReadonlyArray<PaymentRequirements>, context?: PaymentContext): Promise<Authorization | null>;
55
- /**
56
- * Called with payment status updates throughout the payment lifecycle.
57
- *
58
- * @param status - Current payment status
59
- * @param authorization - The authorization returned from onPaymentRequired
60
- * @param context - Optional context about the status update
61
- */
36
+ onPaymentRequired(request: PaymentRequest, context?: PaymentContext): Promise<Authorization | null>;
62
37
  onStatus(status: PaymentStatus, authorization: Authorization, context?: PaymentContext): Promise<void>;
63
38
  }
64
39
  //# sourceMappingURL=treasurer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"treasurer.d.ts","sourceRoot":"","sources":["../../src/x402/treasurer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAEr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;OAIG;IACH,QAAQ,EAAE,qBAAqB,GAAG,qBAAqB,CAAA;CACxD;AAED,MAAM,MAAM,aAAa,GACrB,SAAS,GACT,UAAU,GACV,UAAU,GACV,UAAU,GACV,OAAO,CAAA;AAEX;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,aAAa;IAC5B,iBAAiB,CAAC,OAAO,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAA;IACnG,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;CACvG"}
@@ -1,52 +1,16 @@
1
- import type { PaymentRequirements } from "x402/types";
1
+ import { type PaymentRequest } from "../envelopes.ts";
2
2
  import type { Authorization, PaymentContext, PaymentStatus, X402Treasurer } from "../treasurer.ts";
3
3
  import type { X402Wallet } from "../wallet.ts";
4
4
  import { type WalletConfig } from "../wallets/index.ts";
5
5
  /**
6
- * NaiveTreasurer - Auto-approves all payment requests
7
- *
8
- * This treasurer automatically approves all payment requests without
9
- * any budget checks or user confirmation. Useful for:
10
- * - Testing and development
11
- * - Trusted sellers where all requests should be paid
12
- * - Simple use cases without budget limits
13
- *
14
- * @example
15
- * ```typescript
16
- * const wallet = new AccountWallet(account)
17
- * const treasurer = new NaiveTreasurer(wallet)
18
- *
19
- * // Auto-approves all payments
20
- * const client = new X402Client({ treasurer })
21
- * ```
6
+ * Auto-approves any request by signing its first `accepts[]` entry. No budget
7
+ * or policy checks; for testing and development only.
22
8
  */
23
9
  export declare class NaiveTreasurer implements X402Treasurer {
24
10
  private wallet;
25
11
  constructor(wallet: X402Wallet);
26
- /**
27
- * Always approves payment by creating payment with the wallet.
28
- * Uses the first requirement from the array.
29
- */
30
- onPaymentRequired(requirements: Array<PaymentRequirements>, _context?: PaymentContext): Promise<Authorization | null>;
31
- /**
32
- * Logs payment status to console for debugging.
33
- */
12
+ onPaymentRequired(request: PaymentRequest, _context?: PaymentContext): Promise<Authorization | null>;
34
13
  onStatus(status: PaymentStatus, authorization: Authorization, _context?: PaymentContext): Promise<void>;
35
14
  }
36
- /**
37
- * Creates a naive treasurer that automatically approves all payment requests.
38
- * This treasurer selects the first payment requirement and creates a payment immediately.
39
- *
40
- * @param walletConfig - Configuration for the wallet to use
41
- * @returns An X402Treasurer implementation
42
- *
43
- * @example
44
- * ```typescript
45
- * const treasurer = createNaiveTreasurer({
46
- * type: 'eoa',
47
- * privateKey: '0x...'
48
- * })
49
- * ```
50
- */
51
15
  export declare function createNaiveTreasurer(walletConfig: WalletConfig): X402Treasurer;
52
16
  //# sourceMappingURL=naive.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"naive.d.ts","sourceRoot":"","sources":["../../../src/x402/treasurers/naive.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErD,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAClG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAA0B,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAE/E;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,cAAe,YAAW,aAAa;IACtC,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEtC;;;OAGG;IACG,iBAAiB,CACrB,YAAY,EAAE,KAAK,CAAC,mBAAmB,CAAC,EACxC,QAAQ,CAAC,EAAE,cAAc,GACxB,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAchC;;OAEG;IACG,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAG9G;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,YAAY,GAAG,aAAa,CAG9E"}
1
+ {"version":3,"file":"naive.d.ts","sourceRoot":"","sources":["../../../src/x402/treasurers/naive.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,KAAK,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrF,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAClG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,EAA0B,KAAK,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAE/E;;;GAGG;AACH,qBAAa,cAAe,YAAW,aAAa;IACtC,OAAO,CAAC,MAAM;gBAAN,MAAM,EAAE,UAAU;IAEhC,iBAAiB,CAAC,OAAO,EAAE,cAAc,EAAE,QAAQ,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC;IAUpG,QAAQ,CAAC,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,aAAa,EAAE,QAAQ,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC;CAG9G;AAED,wBAAgB,oBAAoB,CAAC,YAAY,EAAE,YAAY,GAAG,aAAa,CAG9E"}
@@ -1,64 +1,27 @@
1
+ import { acceptedOf, firstInstructionOf } from "../envelopes.js";
1
2
  import { createWalletFromConfig } from "../wallets/index.js";
2
3
  /**
3
- * NaiveTreasurer - Auto-approves all payment requests
4
- *
5
- * This treasurer automatically approves all payment requests without
6
- * any budget checks or user confirmation. Useful for:
7
- * - Testing and development
8
- * - Trusted sellers where all requests should be paid
9
- * - Simple use cases without budget limits
10
- *
11
- * @example
12
- * ```typescript
13
- * const wallet = new AccountWallet(account)
14
- * const treasurer = new NaiveTreasurer(wallet)
15
- *
16
- * // Auto-approves all payments
17
- * const client = new X402Client({ treasurer })
18
- * ```
4
+ * Auto-approves any request by signing its first `accepts[]` entry. No budget
5
+ * or policy checks; for testing and development only.
19
6
  */
20
7
  export class NaiveTreasurer {
21
8
  wallet;
22
9
  constructor(wallet) {
23
10
  this.wallet = wallet;
24
11
  }
25
- /**
26
- * Always approves payment by creating payment with the wallet.
27
- * Uses the first requirement from the array.
28
- */
29
- async onPaymentRequired(requirements, _context) {
30
- if (requirements.length === 0) {
31
- return null;
32
- }
33
- // Create payment using the wallet
34
- const payment = await this.wallet.createPayment(requirements[0]);
12
+ async onPaymentRequired(request, _context) {
13
+ const instruction = firstInstructionOf(request);
14
+ const payment = await this.wallet.createPayment(instruction);
35
15
  return {
36
16
  payment,
37
17
  authorizationId: crypto.randomUUID(),
18
+ accepted: acceptedOf(instruction),
38
19
  };
39
20
  }
40
- /**
41
- * Logs payment status to console for debugging.
42
- */
43
21
  async onStatus(status, authorization, _context) {
44
22
  console.log(`[NaiveTreasurer] Payment ${authorization.authorizationId}: ${status}`);
45
23
  }
46
24
  }
47
- /**
48
- * Creates a naive treasurer that automatically approves all payment requests.
49
- * This treasurer selects the first payment requirement and creates a payment immediately.
50
- *
51
- * @param walletConfig - Configuration for the wallet to use
52
- * @returns An X402Treasurer implementation
53
- *
54
- * @example
55
- * ```typescript
56
- * const treasurer = createNaiveTreasurer({
57
- * type: 'eoa',
58
- * privateKey: '0x...'
59
- * })
60
- * ```
61
- */
62
25
  export function createNaiveTreasurer(walletConfig) {
63
26
  const wallet = createWalletFromConfig(walletConfig);
64
27
  return new NaiveTreasurer(wallet);
@@ -1 +1 @@
1
- {"version":3,"file":"naive.js","sourceRoot":"","sources":["../../../src/x402/treasurers/naive.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,sBAAsB,EAAqB,MAAM,qBAAqB,CAAA;AAE/E;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,OAAO,cAAc;IACL;IAApB,YAAoB,MAAkB;QAAlB,WAAM,GAAN,MAAM,CAAY;IAAG,CAAC;IAE1C;;;OAGG;IACH,KAAK,CA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e,EAAE,MAAM,CAAC,UAAU,EAAE;YACpC,QAAQ,EAAE,UAAU,CAAC,WAAW,CAAC;SAClC,CAAA;IACH,CAAC;IAED,KAAK,CAAC,QAAQ,CAAC,MAAqB,EAAE,aAA4B,EAAE,QAAyB;QAC3F,OAAO,CAAC,GAAG,CAAC,4BAA4B,aAAa,CAAC,eAAe,KAAK,MAAM,EAAE,CAAC,CAAA;IACrF,CAAC;CACF;AAED,MAAM,UAAU,oBAAoB,CAAC,YAA0B;IAC7D,MAAM,MAAM,GAAG,sBAAsB,CAAC,YAAY,CAAC,CAAA;IACnD,OAAO,IAAI,cAAc,CAAC,MAAM,CAAC,CAAA;AACnC,CAAC"}
@@ -1,43 +1,18 @@
1
- import type { PaymentPayload, PaymentRequirements } from "x402/types";
1
+ import type { PaymentAuthorization, PaymentInstruction } from "./envelopes.ts";
2
2
  import type { ServerAuthorizationData } from "./types.ts";
3
- /**
4
- * Error thrown when wallet cannot create a payment
5
- */
6
3
  export declare class WalletError extends Error {
7
4
  cause?: Error | undefined;
8
5
  constructor(message: string, cause?: Error | undefined);
9
6
  }
10
7
  /**
11
- * X402Wallet interface - Creates payment payloads from requirements
12
- *
13
- * An X402Wallet is responsible for creating cryptographically signed payment payloads
14
- * that can be submitted to sellers. Different wallet implementations support
15
- * different account types (EOA, smart accounts, etc.).
16
- *
17
- * @example
18
- * ```typescript
19
- * class AccountWallet implements X402Wallet {
20
- * constructor(private account: Account) {}
8
+ * Signs a {@link PaymentInstruction} into a {@link PaymentAuthorization}.
21
9
  *
22
- * async createPayment(requirements: PaymentRequirements): Promise<PaymentPayload> {
23
- * if (requirements.scheme !== "exact") {
24
- * throw new WalletError(`Unsupported scheme: ${requirements.scheme}`)
25
- * }
26
- * // Create and sign payment
27
- * return signedPayment
28
- * }
29
- * }
30
- * ```
10
+ * Implementations read fields via {@link acceptedOf} / {@link amountOf} and
11
+ * return via {@link buildAuthorization}, which handles the v1/v2 envelope
12
+ * packaging (including v2's `resource`/`accepted`/`extensions` echo).
31
13
  */
32
14
  export interface X402Wallet {
33
- /**
34
- * Creates a payment payload from requirements.
35
- *
36
- * @param requirements - Payment requirements from seller
37
- * @param serverAuthorization - Optional server co-signature data (for co-signed smart account keys)
38
- * @returns Signed payment payload ready for submission
39
- * @throws {WalletError} If unable to create payment (unsupported scheme, insufficient funds, etc.)
40
- */
41
- createPayment(requirements: PaymentRequirements, serverAuthorization?: ServerAuthorizationData): Promise<PaymentPayload>;
15
+ /** @throws {WalletError} for unsupported schemes, insufficient funds, etc. */
16
+ createPayment(instruction: PaymentInstruction, serverAuthorization?: ServerAuthorizationData): Promise<PaymentAuthorization>;
42
17
  }
43
18
  //# sourceMappingURL=wallet.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/x402/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAEzD;;GAEG;AACH,qBAAa,WAAY,SAAQ,KAAK;IAG3B,KAAK,CAAC,EAAE,KAAK;gBADpB,OAAO,EAAE,MAAM,EACR,KAAK,CAAC,EAAE,KAAK,YAAA;CAKvB;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,UAAU;IACzB;;;;;;;OAOG;IACH,aAAa,CACX,YAAY,EAAE,mBAAmB,EACjC,mBAAmB,CAAC,EAAE,uBAAuB,GAC5C,OAAO,CAAC,cAAc,CAAC,CAAA;CAC3B"}
1
+ {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/x402/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AAC9E,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAEzD,qBAAa,WAAY,SAAQ,KAAK;IAG3B,KAAK,CAAC,EAAE,KAAK;gBADpB,OAAO,EAAE,MAAM,EACR,KAAK,CAAC,EAAE,KAAK,YAAA;CAKvB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,UAAU;IACzB,8EAA8E;IAC9E,aAAa,CACX,WAAW,EAAE,kBAAkB,EAC/B,mBAAmB,CAAC,EAAE,uBAAuB,GAC5C,OAAO,CAAC,oBAAoB,CAAC,CAAA;CACjC"}
@@ -1,6 +1,3 @@
1
- /**
2
- * Error thrown when wallet cannot create a payment
3
- */
4
1
  export class WalletError extends Error {
5
2
  cause;
6
3
  constructor(message, cause) {
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/x402/wallet.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAG3B;IAFT,YACE,OAAe,EACR,KAAa;QAEpB,KAAK,CAAC,OAAO,CAAC,CAAA;QAFP,UAAK,GAAL,KAAK,CAAQ;QAGpB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;IAC3B,CAAC;CACF"}
1
+ {"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/x402/wallet.ts"],"names":[],"mappings":"AAGA,MAAM,OAAO,WAAY,SAAQ,KAAK;IAG3B;IAFT,YACE,OAAe,EACR,KAAa;QAEpB,KAAK,CAAC,OAAO,CAAC,CAAA;QAFP,UAAK,GAAL,KAAK,CAAQ;QAGpB,IAAI,CAAC,IAAI,GAAG,aAAa,CAAA;IAC3B,CAAC;CACF"}
@@ -1,41 +1,20 @@
1
1
  import type { Hex, LocalAccount } from "viem";
2
- import type { PaymentPayload, PaymentRequirements } from "x402/types";
3
- import type { ServerAuthorizationData } from "../../../ampersend/types.ts";
2
+ import { type PaymentAuthorization, type PaymentInstruction } from "../../envelopes.ts";
3
+ import type { ServerAuthorizationData } from "../../types.ts";
4
4
  import { type X402Wallet } from "../../wallet.ts";
5
5
  /**
6
- * AccountWallet - EOA (Externally Owned Account) wallet implementation
7
- *
8
- * Creates payment payloads signed by an EOA private key.
9
- * Supports the "exact" payment scheme.
10
- *
11
- * @example
12
- * ```typescript
13
- * import { privateKeyToAccount } from "viem/accounts"
14
- *
15
- * // From viem Account
16
- * const account = privateKeyToAccount("0x...")
17
- * const wallet = new AccountWallet(account)
18
- *
19
- * // From private key directly
20
- * const wallet = AccountWallet.fromPrivateKey("0x...")
21
- * ```
6
+ * EOA wallet for x402 `exact` on EVM. A `LocalAccount` is sufficient for
7
+ * EIP-3009 and base Permit2; EIP-2612 permit enrichment is skipped because it
8
+ * needs `readContract`, which `LocalAccount` lacks.
22
9
  */
23
10
  export declare class AccountWallet implements X402Wallet {
24
11
  private account;
12
+ private signer;
13
+ private schemeV1;
14
+ private schemeV2;
25
15
  constructor(account: LocalAccount);
26
- /**
27
- * Creates an AccountWallet from a private key
28
- */
29
16
  static fromPrivateKey(privateKey: Hex): AccountWallet;
30
- /**
31
- * Creates a payment payload from requirements.
32
- * Only supports "exact" payment scheme.
33
- * Note: serverAuthorization parameter is ignored for EOA wallets (only used by SmartAccountWallet)
34
- */
35
- createPayment(requirements: PaymentRequirements, _serverAuthorization?: ServerAuthorizationData): Promise<PaymentPayload>;
36
- /**
37
- * Returns the account address
38
- */
17
+ createPayment(instruction: PaymentInstruction, serverAuthorization?: ServerAuthorizationData): Promise<PaymentAuthorization>;
39
18
  get address(): Hex;
40
19
  }
41
20
  //# sourceMappingURL=wallet.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../../../src/x402/wallets/account/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,MAAM,CAAA;AAG7C,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AAErE,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAA;AAC1E,OAAO,EAAe,KAAK,UAAU,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