@agentcash/discovery 1.6.4 → 1.7.0

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/index.d.cts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { ResultAsync } from 'neverthrow';
2
- import { CompatibilityMode } from './flags.cjs';
3
2
  import { z } from 'zod';
4
3
 
5
4
  type TrustTier = 'unverified' | 'origin_hosted' | 'ownership_verified' | 'runtime_verified';
@@ -9,53 +8,34 @@ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTION
9
8
 
10
9
  interface MppPaymentOption {
11
10
  protocol: 'mpp';
12
- /** Payment method identifier, e.g. "tempo" (Tempo protocol). */
13
11
  paymentMethod: string;
14
- /** Payment intent type, e.g. "charge". */
15
12
  intent: string;
16
- /** Server protection realm. */
17
13
  realm: string;
18
- /** CAIP-2 style network identifier, e.g. "tempo:4217". */
19
14
  network: string;
20
- /** Currency / token contract. */
21
15
  asset: string;
22
- /** Raw token-unit amount string. */
23
16
  amount: string;
24
- /** Token decimal places, used for display conversion. */
25
17
  decimals?: number;
26
- /** Recipient address. */
27
18
  payTo?: string;
28
- /** Human-readable description of the resource. */
29
19
  description?: string;
30
20
  }
31
21
 
32
22
  interface X402V1PaymentOption {
33
23
  protocol: 'x402';
34
24
  version: 1;
35
- /** Payment scheme, e.g. "exact". */
36
25
  scheme?: string;
37
- /** CAIP-2 network identifier, e.g. "eip155:8453". */
38
26
  network: string;
39
- /** Token contract address. */
40
27
  asset: string;
41
- /** Upper-bound token-unit amount string (v1 semantics). */
42
28
  maxAmountRequired: string;
43
- /** Recipient wallet address. */
44
29
  payTo?: string;
45
30
  maxTimeoutSeconds?: number;
46
31
  }
47
32
  interface X402V2PaymentOption {
48
33
  protocol: 'x402';
49
34
  version: 2;
50
- /** Payment scheme, e.g. "exact". */
51
35
  scheme?: string;
52
- /** CAIP-2 network identifier, e.g. "eip155:8453". */
53
36
  network: string;
54
- /** Token contract address. */
55
37
  asset: string;
56
- /** Exact token-unit amount string (v2 semantics). */
57
38
  amount: string;
58
- /** Recipient wallet address. */
59
39
  payTo?: string;
60
40
  maxTimeoutSeconds?: number;
61
41
  }
@@ -79,7 +59,6 @@ interface OpenApiSource {
79
59
  guidance?: string;
80
60
  fetchedUrl: string;
81
61
  }
82
- /** Returned when the spec was fetched successfully but failed schema validation. */
83
62
  interface OpenApiParseFailure {
84
63
  parseFailure: true;
85
64
  fetchedUrl: string;
@@ -96,40 +75,25 @@ interface OpenApiRoute {
96
75
  protocols?: string[];
97
76
  pricing?: PricingHint;
98
77
  }
99
- interface WellKnownSource {
100
- raw: Record<string, unknown>;
101
- routes: WellKnownRoute[];
102
- title?: string;
103
- description?: string;
104
- instructions?: string;
105
- fetchedUrl: string;
106
- /** Which well-known document(s) this source was built from. */
107
- protocol: 'x402' | 'mpp' | 'x402+mpp';
108
- }
109
- interface WellKnownRoute {
110
- path: string;
111
- method: HttpMethod;
112
- /** Raw price hint from the well-known document (e.g. MPP `payment.amount`). */
113
- price?: string;
114
- }
115
78
  interface ProbeResult {
116
79
  path: string;
117
80
  method: HttpMethod;
118
81
  authHint: AuthMode;
119
82
  protocols?: string[];
120
- /** Raw 402 response body, present when the endpoint returned a payment challenge. */
121
83
  paymentRequiredBody?: unknown;
122
- /** Raw WWW-Authenticate header value from the 402 response. */
123
84
  wwwAuthenticate?: string;
124
85
  }
125
86
  interface L2Result {
87
+ origin?: string;
126
88
  title?: string;
127
89
  description?: string;
128
90
  version?: string;
129
91
  routes: L2Route[];
130
- source: 'openapi' | 'well-known/x402' | 'well-known/mpp' | 'well-known/x402+mpp' | null;
92
+ source: 'openapi' | null;
93
+ trustTier?: TrustTier;
131
94
  }
132
95
  interface L2Route {
96
+ resourceKey?: string;
133
97
  path: string;
134
98
  method: HttpMethod;
135
99
  summary: string;
@@ -148,30 +112,18 @@ interface L3Result {
148
112
  protocols?: string[];
149
113
  inputSchema?: Record<string, unknown>;
150
114
  outputSchema?: Record<string, unknown>;
151
- /** Live payment options parsed from the 402 response. Only present on probe results. */
152
115
  paymentOptions?: PaymentOption[];
153
- /**
154
- * Raw 402 response body captured during probing. Present when the endpoint was probed
155
- * and returned a 402. Used by getWarningsForL3 to run full payment-required validation.
156
- */
157
116
  paymentRequiredBody?: unknown;
158
- /**
159
- * Raw WWW-Authenticate header value from the 402 response. Present when the endpoint
160
- * was probed and returned a 402 with an MPP challenge. Used by getWarningsForMppHeader.
161
- */
162
117
  wwwAuthenticate?: string;
163
118
  }
164
119
  interface L4Result {
165
120
  guidance: string;
166
- source: 'openapi' | 'well-known/x402' | 'well-known/mpp' | 'well-known/x402+mpp';
121
+ source: 'openapi';
167
122
  }
168
123
 
169
124
  declare enum GuidanceMode {
170
- /** Include guidance only when under the auto-include threshold (default). */
171
125
  Auto = "auto",
172
- /** Always include guidance, even if large. */
173
126
  Always = "always",
174
- /** Never include guidance; return discovery data only. */
175
127
  Never = "never"
176
128
  }
177
129
  interface DiscoverOriginSchemaOptions {
@@ -184,23 +136,17 @@ interface DiscoverOriginSchemaOptions {
184
136
  interface DiscoverOriginSchemaSuccess {
185
137
  found: true;
186
138
  origin: string;
187
- /** Which discovery context source produced the endpoint list (e.g. `"openapi"`). */
188
139
  source: string;
189
- /** Metadata from the OpenAPI `info` block, when available. */
140
+ trustTier: TrustTier;
190
141
  info?: {
191
142
  title: string;
192
143
  description?: string;
193
144
  version?: string;
194
145
  };
195
- /** Discovered endpoints with advisory pricing and auth metadata. */
196
146
  endpoints: L2Route[];
197
- /** True when guidance text exists for this API. */
198
147
  guidanceAvailable: boolean;
199
- /** Estimated token count of the guidance text. Present when guidanceAvailable is true. */
200
148
  guidanceTokens?: number;
201
- /** Guidance text. Included when short enough (auto mode) or guidance='always'. */
202
149
  guidance?: string;
203
- /** Ownership proof strings collected from the discovery document, if any. */
204
150
  ownershipProofs?: string[];
205
151
  }
206
152
  interface DiscoverOriginSchemaNotFound {
@@ -211,25 +157,10 @@ interface DiscoverOriginSchemaNotFound {
211
157
  }
212
158
  type DiscoverOriginSchemaResult = DiscoverOriginSchemaSuccess | DiscoverOriginSchemaNotFound;
213
159
  interface CheckEndpointOptions {
214
- /** Full endpoint URL (e.g. `"https://api.example.com/pay"`). */
215
160
  url: string;
216
161
  headers?: Record<string, string>;
217
162
  signal?: AbortSignal;
218
- /** Sample input body for the endpoint.
219
- *
220
- * Providing this will cause the endpoint to always be probed, and will return the exact
221
- * PaymentOptions that would be returned by the live 402 response.
222
- *
223
- * The agent will use this to get an exact price quote for the body they are planning on sending
224
- * with fetch.
225
- *
226
- */
227
163
  sampleInputBody?: Record<string, unknown>;
228
- /**
229
- * When true, skips OpenAPI lookup and probes the live endpoint directly.
230
- * Use this to retrieve actual PaymentOptions (realm, payTo, network, asset, amount)
231
- * from the 402 response rather than static OpenAPI metadata.
232
- */
233
164
  probe?: boolean;
234
165
  }
235
166
  interface EndpointMethodAdvisory extends L3Result {
@@ -261,39 +192,18 @@ interface FetchError {
261
192
 
262
193
  declare function getOpenAPI(origin: string, headers?: Record<string, string>, signal?: AbortSignal, specificationOverrideUrl?: string): ResultAsync<OpenApiSource | OpenApiParseFailure | null, FetchError>;
263
194
 
264
- /**
265
- * Fetches both `/.well-known/x402` and `/.well-known/mpp` in parallel and merges results.
266
- *
267
- * In practice these are mutually exclusive, but if both exist their routes are combined
268
- * (deduplicated by method+path). x402 wins on instruction/fetchedUrl conflicts.
269
- *
270
- * Individual leg failures are treated as "not found" for that leg so valid data from
271
- * the other is never suppressed. Returns Err(FetchError) only when both legs hard-fail.
272
- */
273
- declare function getWellKnown(origin: string, headers?: Record<string, string>, signal?: AbortSignal): ResultAsync<WellKnownSource | null, FetchError>;
274
-
275
- declare function getX402WellKnown(origin: string, headers?: Record<string, string>, signal?: AbortSignal): ResultAsync<WellKnownSource | null, FetchError>;
276
-
277
- declare function getMppWellKnown(origin: string, headers?: Record<string, string>, signal?: AbortSignal): ResultAsync<WellKnownSource | null, FetchError>;
278
-
279
195
  declare function getProbe(url: string, headers?: Record<string, string>, signal?: AbortSignal, inputBody?: Record<string, unknown>): ResultAsync<ProbeResult[], FetchError>;
280
196
 
281
197
  declare function checkL2ForOpenAPI(openApi: OpenApiSource): L2Result;
282
- declare function checkL2ForWellknown(wellKnown: WellKnownSource): L2Result;
283
198
 
284
199
  declare function getL3ForOpenAPI(openApi: OpenApiSource, path: string, method: HttpMethod): L3Result | null;
285
200
  declare function getL3ForProbe(probe: ProbeResult[], path: string, method: HttpMethod, openApi?: OpenApiSource | null): L3Result | null;
286
- /**
287
- * Probes `url` and populates `paymentRequiredBody` on each advisory so that
288
- * getWarningsForL3 can run full 402-body validation. Mutates in place; no-ops on network error.
289
- */
290
201
  declare function attachProbePayload(url: string, advisories: Array<L3Result & {
291
202
  method: HttpMethod;
292
203
  }>): Promise<void>;
293
204
  declare function getL3(openApi: OpenApiSource | null, probe: ProbeResult[], path: string, method: HttpMethod): L3Result | null;
294
205
 
295
206
  declare function checkL4ForOpenAPI(openApi: OpenApiSource): L4Result | null;
296
- declare function checkL4ForWellknown(wellKnown: WellKnownSource): L4Result | null;
297
207
 
298
208
  declare const VALIDATION_CODES: {
299
209
  readonly COINBASE_SCHEMA_INVALID: "COINBASE_SCHEMA_INVALID";
@@ -319,7 +229,7 @@ declare const VALIDATION_CODES: {
319
229
  };
320
230
 
321
231
  type ValidationSeverity = 'error' | 'warn' | 'info';
322
- type ValidationStage = 'payment_required' | 'openapi' | 'metadata' | 'compat' | 'runtime_probe';
232
+ type ValidationStage = 'payment_required' | 'openapi' | 'metadata' | 'runtime_probe';
323
233
  interface ValidationIssue {
324
234
  code: string;
325
235
  severity: ValidationSeverity;
@@ -356,7 +266,6 @@ interface NormalizedPaymentRequired {
356
266
  hasOutputSchema: boolean;
357
267
  }
358
268
  interface ValidatePaymentRequiredOptions {
359
- compatMode?: CompatibilityMode;
360
269
  requireInputSchema?: boolean;
361
270
  requireOutputSchema?: boolean;
362
271
  metadata?: MetadataPreview;
@@ -378,10 +287,6 @@ interface ValidatePaymentRequiredDetailedResult {
378
287
 
379
288
  declare function evaluateMetadataCompleteness(metadata: MetadataPreview): ValidationIssue[];
380
289
 
381
- /**
382
- * Validates a 402 response body. Delegates to getWarningsFor402Body (the canonical
383
- * audit function) and reconstructs the full typed result shape for backwards compatibility.
384
- */
385
290
  declare function validatePaymentRequiredDetailed(payload: unknown, options?: ValidatePaymentRequiredOptions): ValidatePaymentRequiredDetailedResult;
386
291
 
387
292
  declare const FixedPriceSchema: z.ZodObject<{
@@ -439,7 +344,6 @@ type PaymentInfo = z.infer<typeof PaymentInfoSchema>;
439
344
 
440
345
  declare const AUDIT_CODES: {
441
346
  readonly OPENAPI_NOT_FOUND: "OPENAPI_NOT_FOUND";
442
- readonly WELLKNOWN_NOT_FOUND: "WELLKNOWN_NOT_FOUND";
443
347
  readonly OPENAPI_PARSE_ERROR: "OPENAPI_PARSE_ERROR";
444
348
  readonly OPENAPI_NO_ROUTES: "OPENAPI_NO_ROUTES";
445
349
  readonly L2_NO_ROUTES: "L2_NO_ROUTES";
@@ -454,6 +358,7 @@ declare const AUDIT_CODES: {
454
358
  readonly L2_PROTOCOLS_MISSING_ON_PAID: "L2_PROTOCOLS_MISSING_ON_PAID";
455
359
  readonly L2_X402_MALFORMED: "L2_X402_MALFORMED";
456
360
  readonly L2_MPP_MALFORMED: "L2_MPP_MALFORMED";
361
+ readonly LEGACY_WELL_KNOWN_FOUND: "LEGACY_WELL_KNOWN_FOUND";
457
362
  readonly L3_NOT_FOUND: "L3_NOT_FOUND";
458
363
  readonly L3_INPUT_SCHEMA_MISSING: "L3_INPUT_SCHEMA_MISSING";
459
364
  readonly L3_AUTH_MODE_MISSING: "L3_AUTH_MODE_MISSING";
@@ -483,43 +388,29 @@ interface AuditWarning {
483
388
  severity: AuditSeverity;
484
389
  message: string;
485
390
  hint?: string;
486
- /** Dotted path to the field this warning refers to, when applicable. */
487
391
  path?: string;
488
392
  }
489
393
 
490
- /** Type guard: true when the value is a parse-failure sentinel (spec fetched but invalid). */
491
394
  declare function isOpenApiParseFailure(value: OpenApiSource | OpenApiParseFailure | null): value is OpenApiParseFailure;
492
395
  declare function getWarningsForOpenAPI(openApi: OpenApiSource | OpenApiParseFailure | null): AuditWarning[];
493
- declare function getWarningsForWellKnown(wellKnown: WellKnownSource | null): AuditWarning[];
494
396
 
495
397
  declare function getWarningsForL2(l2: L2Result): AuditWarning[];
496
398
 
497
- /**
498
- * Validates a raw 402 response body and returns issues as AuditWarnings.
499
- * Uses the v1/v2 protocol validators directly — the canonical source of truth
500
- * for 402 body quality checks. x402scan should call this instead of
501
- * validatePaymentRequiredDetailed.
502
- */
503
- declare function getWarningsFor402Body(body: unknown): AuditWarning[];
399
+ declare function getWarningsFor402Body(body: unknown): ValidationIssue[];
504
400
  declare function getWarningsForL3(l3: L3Result | null): AuditWarning[];
505
401
 
506
402
  declare function getWarningsForL4(l4: L4Result | null): AuditWarning[];
507
403
 
508
- /**
509
- * Validates a raw WWW-Authenticate header value from an MPP 402 response and
510
- * returns issues as AuditWarnings.
511
- *
512
- * Checks for:
513
- * - Header presence
514
- * - At least one Payment challenge
515
- * - Required challenge parameters: id, method, intent, realm, expires, request
516
- * - Valid base64url-encoded JSON in the request field
517
- * - Required request fields: currency (asset), amount
518
- * - Recommended request field: recipient (payTo)
519
- */
520
404
  declare function getWarningsForMppHeader(wwwAuthenticate: string | null | undefined): AuditWarning[];
521
405
 
522
406
  declare function checkFavicon(origin: string): ResultAsync<boolean, never>;
523
407
  declare function getWarningsForFavicon(origin: string): ResultAsync<AuditWarning[], never>;
524
408
 
525
- export { AUDIT_CODES, type AuditCode, type AuditSeverity, type AuditWarning, type AuthMode, type CheckEndpointNotFound, type CheckEndpointOptions, type CheckEndpointResult, type CheckEndpointSuccess, type DiscoverOriginSchemaNotFound, type DiscoverOriginSchemaOptions, type DiscoverOriginSchemaResult, type DiscoverOriginSchemaSuccess, type DynamicPrice, type EndpointMethodAdvisory, type FixedPrice, GuidanceMode, type HttpMethod, type L2Result, type L2Route, type L3Result, type L4Result, type MetadataPreview, type MppPaymentOption, type MppProtocol, type NormalizedAccept, type NormalizedPaymentRequired, type OpenApiParseFailure, type OpenApiRoute, type OpenApiSource, type PaymentInfo, PaymentInfoSchema, type PaymentOption, type PaymentProtocol, PaymentProtocolSchema, type Price, PriceSchema, type PricingMode, type ProbeResult, type TrustTier, VALIDATION_CODES, type ValidatePaymentRequiredDetailedResult, type ValidatePaymentRequiredOptions, type ValidationIssue, type ValidationSeverity, type ValidationStage, type ValidationSummary, type WellKnownRoute, type WellKnownSource, type X402PaymentOption, type X402Protocol, type X402V1PaymentOption, type X402V2PaymentOption, attachProbePayload, checkEndpointSchema, checkFavicon, checkL2ForOpenAPI, checkL2ForWellknown, checkL4ForOpenAPI, checkL4ForWellknown, discoverOriginSchema, evaluateMetadataCompleteness, getL3, getL3ForOpenAPI, getL3ForProbe, getMppWellKnown, getOpenAPI, getProbe, getWarningsFor402Body, getWarningsForFavicon, getWarningsForL2, getWarningsForL3, getWarningsForL4, getWarningsForMppHeader, getWarningsForOpenAPI, getWarningsForWellKnown, getWellKnown, getX402WellKnown, isOpenApiParseFailure, validatePaymentRequiredDetailed };
409
+ interface LegacyWellKnownProbe {
410
+ x402: boolean;
411
+ mpp: boolean;
412
+ }
413
+ declare function probeLegacyWellKnown(origin: string, headers?: Record<string, string>, signal?: AbortSignal): ResultAsync<LegacyWellKnownProbe, FetchError>;
414
+ declare function getWarningsForLegacyWellKnown(probe: LegacyWellKnownProbe): AuditWarning[];
415
+
416
+ export { AUDIT_CODES, type AuditCode, type AuditSeverity, type AuditWarning, type AuthMode, type CheckEndpointNotFound, type CheckEndpointOptions, type CheckEndpointResult, type CheckEndpointSuccess, type DiscoverOriginSchemaNotFound, type DiscoverOriginSchemaOptions, type DiscoverOriginSchemaResult, type DiscoverOriginSchemaSuccess, type DynamicPrice, type EndpointMethodAdvisory, type FixedPrice, GuidanceMode, type HttpMethod, type L2Result, type L2Route, type L3Result, type L4Result, type LegacyWellKnownProbe, type MetadataPreview, type MppPaymentOption, type MppProtocol, MppProtocolSchema, type NormalizedAccept, type NormalizedPaymentRequired, type OpenApiParseFailure, type OpenApiRoute, type OpenApiSource, type PaymentInfo, PaymentInfoSchema, type PaymentOption, type PaymentProtocol, PaymentProtocolSchema, type Price, PriceSchema, type PricingMode, type ProbeResult, type TrustTier, VALIDATION_CODES, type ValidatePaymentRequiredDetailedResult, type ValidatePaymentRequiredOptions, type ValidationIssue, type ValidationSeverity, type ValidationStage, type ValidationSummary, type X402PaymentOption, type X402Protocol, X402ProtocolSchema, type X402V1PaymentOption, type X402V2PaymentOption, attachProbePayload, checkEndpointSchema, checkFavicon, checkL2ForOpenAPI, checkL4ForOpenAPI, discoverOriginSchema, evaluateMetadataCompleteness, getL3, getL3ForOpenAPI, getL3ForProbe, getOpenAPI, getProbe, getWarningsFor402Body, getWarningsForFavicon, getWarningsForL2, getWarningsForL3, getWarningsForL4, getWarningsForLegacyWellKnown, getWarningsForMppHeader, getWarningsForOpenAPI, isOpenApiParseFailure, probeLegacyWellKnown, validatePaymentRequiredDetailed };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,4 @@
1
1
  import { ResultAsync } from 'neverthrow';
2
- import { CompatibilityMode } from './flags.js';
3
2
  import { z } from 'zod';
4
3
 
5
4
  type TrustTier = 'unverified' | 'origin_hosted' | 'ownership_verified' | 'runtime_verified';
@@ -9,53 +8,34 @@ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTION
9
8
 
10
9
  interface MppPaymentOption {
11
10
  protocol: 'mpp';
12
- /** Payment method identifier, e.g. "tempo" (Tempo protocol). */
13
11
  paymentMethod: string;
14
- /** Payment intent type, e.g. "charge". */
15
12
  intent: string;
16
- /** Server protection realm. */
17
13
  realm: string;
18
- /** CAIP-2 style network identifier, e.g. "tempo:4217". */
19
14
  network: string;
20
- /** Currency / token contract. */
21
15
  asset: string;
22
- /** Raw token-unit amount string. */
23
16
  amount: string;
24
- /** Token decimal places, used for display conversion. */
25
17
  decimals?: number;
26
- /** Recipient address. */
27
18
  payTo?: string;
28
- /** Human-readable description of the resource. */
29
19
  description?: string;
30
20
  }
31
21
 
32
22
  interface X402V1PaymentOption {
33
23
  protocol: 'x402';
34
24
  version: 1;
35
- /** Payment scheme, e.g. "exact". */
36
25
  scheme?: string;
37
- /** CAIP-2 network identifier, e.g. "eip155:8453". */
38
26
  network: string;
39
- /** Token contract address. */
40
27
  asset: string;
41
- /** Upper-bound token-unit amount string (v1 semantics). */
42
28
  maxAmountRequired: string;
43
- /** Recipient wallet address. */
44
29
  payTo?: string;
45
30
  maxTimeoutSeconds?: number;
46
31
  }
47
32
  interface X402V2PaymentOption {
48
33
  protocol: 'x402';
49
34
  version: 2;
50
- /** Payment scheme, e.g. "exact". */
51
35
  scheme?: string;
52
- /** CAIP-2 network identifier, e.g. "eip155:8453". */
53
36
  network: string;
54
- /** Token contract address. */
55
37
  asset: string;
56
- /** Exact token-unit amount string (v2 semantics). */
57
38
  amount: string;
58
- /** Recipient wallet address. */
59
39
  payTo?: string;
60
40
  maxTimeoutSeconds?: number;
61
41
  }
@@ -79,7 +59,6 @@ interface OpenApiSource {
79
59
  guidance?: string;
80
60
  fetchedUrl: string;
81
61
  }
82
- /** Returned when the spec was fetched successfully but failed schema validation. */
83
62
  interface OpenApiParseFailure {
84
63
  parseFailure: true;
85
64
  fetchedUrl: string;
@@ -96,40 +75,25 @@ interface OpenApiRoute {
96
75
  protocols?: string[];
97
76
  pricing?: PricingHint;
98
77
  }
99
- interface WellKnownSource {
100
- raw: Record<string, unknown>;
101
- routes: WellKnownRoute[];
102
- title?: string;
103
- description?: string;
104
- instructions?: string;
105
- fetchedUrl: string;
106
- /** Which well-known document(s) this source was built from. */
107
- protocol: 'x402' | 'mpp' | 'x402+mpp';
108
- }
109
- interface WellKnownRoute {
110
- path: string;
111
- method: HttpMethod;
112
- /** Raw price hint from the well-known document (e.g. MPP `payment.amount`). */
113
- price?: string;
114
- }
115
78
  interface ProbeResult {
116
79
  path: string;
117
80
  method: HttpMethod;
118
81
  authHint: AuthMode;
119
82
  protocols?: string[];
120
- /** Raw 402 response body, present when the endpoint returned a payment challenge. */
121
83
  paymentRequiredBody?: unknown;
122
- /** Raw WWW-Authenticate header value from the 402 response. */
123
84
  wwwAuthenticate?: string;
124
85
  }
125
86
  interface L2Result {
87
+ origin?: string;
126
88
  title?: string;
127
89
  description?: string;
128
90
  version?: string;
129
91
  routes: L2Route[];
130
- source: 'openapi' | 'well-known/x402' | 'well-known/mpp' | 'well-known/x402+mpp' | null;
92
+ source: 'openapi' | null;
93
+ trustTier?: TrustTier;
131
94
  }
132
95
  interface L2Route {
96
+ resourceKey?: string;
133
97
  path: string;
134
98
  method: HttpMethod;
135
99
  summary: string;
@@ -148,30 +112,18 @@ interface L3Result {
148
112
  protocols?: string[];
149
113
  inputSchema?: Record<string, unknown>;
150
114
  outputSchema?: Record<string, unknown>;
151
- /** Live payment options parsed from the 402 response. Only present on probe results. */
152
115
  paymentOptions?: PaymentOption[];
153
- /**
154
- * Raw 402 response body captured during probing. Present when the endpoint was probed
155
- * and returned a 402. Used by getWarningsForL3 to run full payment-required validation.
156
- */
157
116
  paymentRequiredBody?: unknown;
158
- /**
159
- * Raw WWW-Authenticate header value from the 402 response. Present when the endpoint
160
- * was probed and returned a 402 with an MPP challenge. Used by getWarningsForMppHeader.
161
- */
162
117
  wwwAuthenticate?: string;
163
118
  }
164
119
  interface L4Result {
165
120
  guidance: string;
166
- source: 'openapi' | 'well-known/x402' | 'well-known/mpp' | 'well-known/x402+mpp';
121
+ source: 'openapi';
167
122
  }
168
123
 
169
124
  declare enum GuidanceMode {
170
- /** Include guidance only when under the auto-include threshold (default). */
171
125
  Auto = "auto",
172
- /** Always include guidance, even if large. */
173
126
  Always = "always",
174
- /** Never include guidance; return discovery data only. */
175
127
  Never = "never"
176
128
  }
177
129
  interface DiscoverOriginSchemaOptions {
@@ -184,23 +136,17 @@ interface DiscoverOriginSchemaOptions {
184
136
  interface DiscoverOriginSchemaSuccess {
185
137
  found: true;
186
138
  origin: string;
187
- /** Which discovery context source produced the endpoint list (e.g. `"openapi"`). */
188
139
  source: string;
189
- /** Metadata from the OpenAPI `info` block, when available. */
140
+ trustTier: TrustTier;
190
141
  info?: {
191
142
  title: string;
192
143
  description?: string;
193
144
  version?: string;
194
145
  };
195
- /** Discovered endpoints with advisory pricing and auth metadata. */
196
146
  endpoints: L2Route[];
197
- /** True when guidance text exists for this API. */
198
147
  guidanceAvailable: boolean;
199
- /** Estimated token count of the guidance text. Present when guidanceAvailable is true. */
200
148
  guidanceTokens?: number;
201
- /** Guidance text. Included when short enough (auto mode) or guidance='always'. */
202
149
  guidance?: string;
203
- /** Ownership proof strings collected from the discovery document, if any. */
204
150
  ownershipProofs?: string[];
205
151
  }
206
152
  interface DiscoverOriginSchemaNotFound {
@@ -211,25 +157,10 @@ interface DiscoverOriginSchemaNotFound {
211
157
  }
212
158
  type DiscoverOriginSchemaResult = DiscoverOriginSchemaSuccess | DiscoverOriginSchemaNotFound;
213
159
  interface CheckEndpointOptions {
214
- /** Full endpoint URL (e.g. `"https://api.example.com/pay"`). */
215
160
  url: string;
216
161
  headers?: Record<string, string>;
217
162
  signal?: AbortSignal;
218
- /** Sample input body for the endpoint.
219
- *
220
- * Providing this will cause the endpoint to always be probed, and will return the exact
221
- * PaymentOptions that would be returned by the live 402 response.
222
- *
223
- * The agent will use this to get an exact price quote for the body they are planning on sending
224
- * with fetch.
225
- *
226
- */
227
163
  sampleInputBody?: Record<string, unknown>;
228
- /**
229
- * When true, skips OpenAPI lookup and probes the live endpoint directly.
230
- * Use this to retrieve actual PaymentOptions (realm, payTo, network, asset, amount)
231
- * from the 402 response rather than static OpenAPI metadata.
232
- */
233
164
  probe?: boolean;
234
165
  }
235
166
  interface EndpointMethodAdvisory extends L3Result {
@@ -261,39 +192,18 @@ interface FetchError {
261
192
 
262
193
  declare function getOpenAPI(origin: string, headers?: Record<string, string>, signal?: AbortSignal, specificationOverrideUrl?: string): ResultAsync<OpenApiSource | OpenApiParseFailure | null, FetchError>;
263
194
 
264
- /**
265
- * Fetches both `/.well-known/x402` and `/.well-known/mpp` in parallel and merges results.
266
- *
267
- * In practice these are mutually exclusive, but if both exist their routes are combined
268
- * (deduplicated by method+path). x402 wins on instruction/fetchedUrl conflicts.
269
- *
270
- * Individual leg failures are treated as "not found" for that leg so valid data from
271
- * the other is never suppressed. Returns Err(FetchError) only when both legs hard-fail.
272
- */
273
- declare function getWellKnown(origin: string, headers?: Record<string, string>, signal?: AbortSignal): ResultAsync<WellKnownSource | null, FetchError>;
274
-
275
- declare function getX402WellKnown(origin: string, headers?: Record<string, string>, signal?: AbortSignal): ResultAsync<WellKnownSource | null, FetchError>;
276
-
277
- declare function getMppWellKnown(origin: string, headers?: Record<string, string>, signal?: AbortSignal): ResultAsync<WellKnownSource | null, FetchError>;
278
-
279
195
  declare function getProbe(url: string, headers?: Record<string, string>, signal?: AbortSignal, inputBody?: Record<string, unknown>): ResultAsync<ProbeResult[], FetchError>;
280
196
 
281
197
  declare function checkL2ForOpenAPI(openApi: OpenApiSource): L2Result;
282
- declare function checkL2ForWellknown(wellKnown: WellKnownSource): L2Result;
283
198
 
284
199
  declare function getL3ForOpenAPI(openApi: OpenApiSource, path: string, method: HttpMethod): L3Result | null;
285
200
  declare function getL3ForProbe(probe: ProbeResult[], path: string, method: HttpMethod, openApi?: OpenApiSource | null): L3Result | null;
286
- /**
287
- * Probes `url` and populates `paymentRequiredBody` on each advisory so that
288
- * getWarningsForL3 can run full 402-body validation. Mutates in place; no-ops on network error.
289
- */
290
201
  declare function attachProbePayload(url: string, advisories: Array<L3Result & {
291
202
  method: HttpMethod;
292
203
  }>): Promise<void>;
293
204
  declare function getL3(openApi: OpenApiSource | null, probe: ProbeResult[], path: string, method: HttpMethod): L3Result | null;
294
205
 
295
206
  declare function checkL4ForOpenAPI(openApi: OpenApiSource): L4Result | null;
296
- declare function checkL4ForWellknown(wellKnown: WellKnownSource): L4Result | null;
297
207
 
298
208
  declare const VALIDATION_CODES: {
299
209
  readonly COINBASE_SCHEMA_INVALID: "COINBASE_SCHEMA_INVALID";
@@ -319,7 +229,7 @@ declare const VALIDATION_CODES: {
319
229
  };
320
230
 
321
231
  type ValidationSeverity = 'error' | 'warn' | 'info';
322
- type ValidationStage = 'payment_required' | 'openapi' | 'metadata' | 'compat' | 'runtime_probe';
232
+ type ValidationStage = 'payment_required' | 'openapi' | 'metadata' | 'runtime_probe';
323
233
  interface ValidationIssue {
324
234
  code: string;
325
235
  severity: ValidationSeverity;
@@ -356,7 +266,6 @@ interface NormalizedPaymentRequired {
356
266
  hasOutputSchema: boolean;
357
267
  }
358
268
  interface ValidatePaymentRequiredOptions {
359
- compatMode?: CompatibilityMode;
360
269
  requireInputSchema?: boolean;
361
270
  requireOutputSchema?: boolean;
362
271
  metadata?: MetadataPreview;
@@ -378,10 +287,6 @@ interface ValidatePaymentRequiredDetailedResult {
378
287
 
379
288
  declare function evaluateMetadataCompleteness(metadata: MetadataPreview): ValidationIssue[];
380
289
 
381
- /**
382
- * Validates a 402 response body. Delegates to getWarningsFor402Body (the canonical
383
- * audit function) and reconstructs the full typed result shape for backwards compatibility.
384
- */
385
290
  declare function validatePaymentRequiredDetailed(payload: unknown, options?: ValidatePaymentRequiredOptions): ValidatePaymentRequiredDetailedResult;
386
291
 
387
292
  declare const FixedPriceSchema: z.ZodObject<{
@@ -439,7 +344,6 @@ type PaymentInfo = z.infer<typeof PaymentInfoSchema>;
439
344
 
440
345
  declare const AUDIT_CODES: {
441
346
  readonly OPENAPI_NOT_FOUND: "OPENAPI_NOT_FOUND";
442
- readonly WELLKNOWN_NOT_FOUND: "WELLKNOWN_NOT_FOUND";
443
347
  readonly OPENAPI_PARSE_ERROR: "OPENAPI_PARSE_ERROR";
444
348
  readonly OPENAPI_NO_ROUTES: "OPENAPI_NO_ROUTES";
445
349
  readonly L2_NO_ROUTES: "L2_NO_ROUTES";
@@ -454,6 +358,7 @@ declare const AUDIT_CODES: {
454
358
  readonly L2_PROTOCOLS_MISSING_ON_PAID: "L2_PROTOCOLS_MISSING_ON_PAID";
455
359
  readonly L2_X402_MALFORMED: "L2_X402_MALFORMED";
456
360
  readonly L2_MPP_MALFORMED: "L2_MPP_MALFORMED";
361
+ readonly LEGACY_WELL_KNOWN_FOUND: "LEGACY_WELL_KNOWN_FOUND";
457
362
  readonly L3_NOT_FOUND: "L3_NOT_FOUND";
458
363
  readonly L3_INPUT_SCHEMA_MISSING: "L3_INPUT_SCHEMA_MISSING";
459
364
  readonly L3_AUTH_MODE_MISSING: "L3_AUTH_MODE_MISSING";
@@ -483,43 +388,29 @@ interface AuditWarning {
483
388
  severity: AuditSeverity;
484
389
  message: string;
485
390
  hint?: string;
486
- /** Dotted path to the field this warning refers to, when applicable. */
487
391
  path?: string;
488
392
  }
489
393
 
490
- /** Type guard: true when the value is a parse-failure sentinel (spec fetched but invalid). */
491
394
  declare function isOpenApiParseFailure(value: OpenApiSource | OpenApiParseFailure | null): value is OpenApiParseFailure;
492
395
  declare function getWarningsForOpenAPI(openApi: OpenApiSource | OpenApiParseFailure | null): AuditWarning[];
493
- declare function getWarningsForWellKnown(wellKnown: WellKnownSource | null): AuditWarning[];
494
396
 
495
397
  declare function getWarningsForL2(l2: L2Result): AuditWarning[];
496
398
 
497
- /**
498
- * Validates a raw 402 response body and returns issues as AuditWarnings.
499
- * Uses the v1/v2 protocol validators directly — the canonical source of truth
500
- * for 402 body quality checks. x402scan should call this instead of
501
- * validatePaymentRequiredDetailed.
502
- */
503
- declare function getWarningsFor402Body(body: unknown): AuditWarning[];
399
+ declare function getWarningsFor402Body(body: unknown): ValidationIssue[];
504
400
  declare function getWarningsForL3(l3: L3Result | null): AuditWarning[];
505
401
 
506
402
  declare function getWarningsForL4(l4: L4Result | null): AuditWarning[];
507
403
 
508
- /**
509
- * Validates a raw WWW-Authenticate header value from an MPP 402 response and
510
- * returns issues as AuditWarnings.
511
- *
512
- * Checks for:
513
- * - Header presence
514
- * - At least one Payment challenge
515
- * - Required challenge parameters: id, method, intent, realm, expires, request
516
- * - Valid base64url-encoded JSON in the request field
517
- * - Required request fields: currency (asset), amount
518
- * - Recommended request field: recipient (payTo)
519
- */
520
404
  declare function getWarningsForMppHeader(wwwAuthenticate: string | null | undefined): AuditWarning[];
521
405
 
522
406
  declare function checkFavicon(origin: string): ResultAsync<boolean, never>;
523
407
  declare function getWarningsForFavicon(origin: string): ResultAsync<AuditWarning[], never>;
524
408
 
525
- export { AUDIT_CODES, type AuditCode, type AuditSeverity, type AuditWarning, type AuthMode, type CheckEndpointNotFound, type CheckEndpointOptions, type CheckEndpointResult, type CheckEndpointSuccess, type DiscoverOriginSchemaNotFound, type DiscoverOriginSchemaOptions, type DiscoverOriginSchemaResult, type DiscoverOriginSchemaSuccess, type DynamicPrice, type EndpointMethodAdvisory, type FixedPrice, GuidanceMode, type HttpMethod, type L2Result, type L2Route, type L3Result, type L4Result, type MetadataPreview, type MppPaymentOption, type MppProtocol, type NormalizedAccept, type NormalizedPaymentRequired, type OpenApiParseFailure, type OpenApiRoute, type OpenApiSource, type PaymentInfo, PaymentInfoSchema, type PaymentOption, type PaymentProtocol, PaymentProtocolSchema, type Price, PriceSchema, type PricingMode, type ProbeResult, type TrustTier, VALIDATION_CODES, type ValidatePaymentRequiredDetailedResult, type ValidatePaymentRequiredOptions, type ValidationIssue, type ValidationSeverity, type ValidationStage, type ValidationSummary, type WellKnownRoute, type WellKnownSource, type X402PaymentOption, type X402Protocol, type X402V1PaymentOption, type X402V2PaymentOption, attachProbePayload, checkEndpointSchema, checkFavicon, checkL2ForOpenAPI, checkL2ForWellknown, checkL4ForOpenAPI, checkL4ForWellknown, discoverOriginSchema, evaluateMetadataCompleteness, getL3, getL3ForOpenAPI, getL3ForProbe, getMppWellKnown, getOpenAPI, getProbe, getWarningsFor402Body, getWarningsForFavicon, getWarningsForL2, getWarningsForL3, getWarningsForL4, getWarningsForMppHeader, getWarningsForOpenAPI, getWarningsForWellKnown, getWellKnown, getX402WellKnown, isOpenApiParseFailure, validatePaymentRequiredDetailed };
409
+ interface LegacyWellKnownProbe {
410
+ x402: boolean;
411
+ mpp: boolean;
412
+ }
413
+ declare function probeLegacyWellKnown(origin: string, headers?: Record<string, string>, signal?: AbortSignal): ResultAsync<LegacyWellKnownProbe, FetchError>;
414
+ declare function getWarningsForLegacyWellKnown(probe: LegacyWellKnownProbe): AuditWarning[];
415
+
416
+ export { AUDIT_CODES, type AuditCode, type AuditSeverity, type AuditWarning, type AuthMode, type CheckEndpointNotFound, type CheckEndpointOptions, type CheckEndpointResult, type CheckEndpointSuccess, type DiscoverOriginSchemaNotFound, type DiscoverOriginSchemaOptions, type DiscoverOriginSchemaResult, type DiscoverOriginSchemaSuccess, type DynamicPrice, type EndpointMethodAdvisory, type FixedPrice, GuidanceMode, type HttpMethod, type L2Result, type L2Route, type L3Result, type L4Result, type LegacyWellKnownProbe, type MetadataPreview, type MppPaymentOption, type MppProtocol, MppProtocolSchema, type NormalizedAccept, type NormalizedPaymentRequired, type OpenApiParseFailure, type OpenApiRoute, type OpenApiSource, type PaymentInfo, PaymentInfoSchema, type PaymentOption, type PaymentProtocol, PaymentProtocolSchema, type Price, PriceSchema, type PricingMode, type ProbeResult, type TrustTier, VALIDATION_CODES, type ValidatePaymentRequiredDetailedResult, type ValidatePaymentRequiredOptions, type ValidationIssue, type ValidationSeverity, type ValidationStage, type ValidationSummary, type X402PaymentOption, type X402Protocol, X402ProtocolSchema, type X402V1PaymentOption, type X402V2PaymentOption, attachProbePayload, checkEndpointSchema, checkFavicon, checkL2ForOpenAPI, checkL4ForOpenAPI, discoverOriginSchema, evaluateMetadataCompleteness, getL3, getL3ForOpenAPI, getL3ForProbe, getOpenAPI, getProbe, getWarningsFor402Body, getWarningsForFavicon, getWarningsForL2, getWarningsForL3, getWarningsForL4, getWarningsForLegacyWellKnown, getWarningsForMppHeader, getWarningsForOpenAPI, isOpenApiParseFailure, probeLegacyWellKnown, validatePaymentRequiredDetailed };