@shroud-fi/x402 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/types.ts ADDED
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Shared types used by both server and client.
3
+ */
4
+
5
+ import type { Address, Hex } from 'viem';
6
+ import type {
7
+ X402FacilitatorConfig,
8
+ X402PaymentRequirements,
9
+ } from './protocol.js';
10
+
11
+ /**
12
+ * Hint object returned alongside a freshly generated challenge.
13
+ *
14
+ * The server uses these values to emit an ERC-5564 Announcement event AFTER
15
+ * the payment settles (out-of-scope for this milestone — operator wires the
16
+ * on-chain emit). Carrying it on the challenge object lets the server
17
+ * correlate "this challenge → this announcement" without re-derivation.
18
+ *
19
+ * Privacy: contains only the ephemeral public key + view tag + the freshly
20
+ * derived stealth address. None of these leak the recipient's main wallet.
21
+ */
22
+ export interface X402StealthAnnouncementHint {
23
+ readonly ephemeralPubKey: Hex;
24
+ readonly viewTag: number;
25
+ readonly stealthAddress: Address;
26
+ }
27
+
28
+ /**
29
+ * The full server-side challenge object. Comes out of `x402.challenge(...)`.
30
+ *
31
+ * `status` + `headers` + `body` are wire-shaped — operator's HTTP framework
32
+ * adapter simply spreads them onto its response. `announcement` is internal
33
+ * metadata for the operator's scanner integration.
34
+ */
35
+ export interface X402Challenge {
36
+ readonly status: 402;
37
+ readonly headers: Readonly<Record<string, string>>;
38
+ readonly body: {
39
+ readonly x402Version: 2;
40
+ readonly error: string;
41
+ readonly accepts: readonly X402PaymentRequirements[];
42
+ };
43
+ readonly announcement: X402StealthAnnouncementHint;
44
+ }
45
+
46
+ /**
47
+ * Result of `x402.verify(...)`.
48
+ *
49
+ * Privacy: no amount, no signature, no nonce. `error` is a short tag string
50
+ * only ('signature_invalid', 'amount_mismatch', 'expired', etc) — never the
51
+ * full underlying error or any bytes.
52
+ */
53
+ export interface X402PaymentVerification {
54
+ readonly valid: boolean;
55
+ readonly settledTxHash?: Hex;
56
+ readonly error?: string;
57
+ }
58
+
59
+ /**
60
+ * `createX402Server` config.
61
+ *
62
+ * Privacy: the `recipientMetaAddress` is the server agent's PUBLIC meta-address
63
+ * (`st:base:0x...`). No private keys ever appear in this config.
64
+ */
65
+ export interface X402ServerConfig {
66
+ /** Transport for reads + chain id lookups. */
67
+ readonly transport: import('@shroud-fi/transport').ShroudFiTransport;
68
+ /** ERC-6538 meta-address string (`st:base:0x...`) for the receiving agent. */
69
+ readonly recipientMetaAddress: string;
70
+ /** ERC-20 asset address (must be the canonical USDC for the chain). */
71
+ readonly asset: Address;
72
+ /** EVM chain id (must match the asset's deployment). */
73
+ readonly chainId: number;
74
+ /** Default price in token base units (uint256). */
75
+ readonly defaultPriceAtomic: bigint;
76
+ /** Optional facilitator override; defaults to PayAI free-tier. */
77
+ readonly facilitator?: X402FacilitatorConfig;
78
+ }
79
+
80
+ /**
81
+ * `createX402Client` config.
82
+ *
83
+ * Privacy: the client uses the transport's `walletClient.account` for
84
+ * signing. The private key never appears here directly — it lives inside
85
+ * the viem account, scoped to the transport's lifetime.
86
+ */
87
+ export interface X402ClientConfig {
88
+ /** Transport with a configured `walletClient` (account required). */
89
+ readonly transport: import('@shroud-fi/transport').ShroudFiTransport;
90
+ /** Optional facilitator override; defaults to PayAI free-tier. */
91
+ readonly facilitator?: X402FacilitatorConfig;
92
+ }
93
+
94
+ /**
95
+ * What a client `.fetch(...)` call surfaces beyond the standard Response.
96
+ * Non-standard `x402Settlement` property is attached when the server returned
97
+ * `X-PAYMENT-RESPONSE`. Optional — present only on successful auto-pay.
98
+ */
99
+ export interface X402PaymentResult {
100
+ readonly txHash: Hex;
101
+ readonly settledAt: number;
102
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "../../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist/esm",
5
+ "rootDir": "./src"
6
+ },
7
+ "include": ["src/**/*.ts"],
8
+ "exclude": ["dist", "test", "node_modules"]
9
+ }