@agentcash/discovery 1.1.2 → 1.2.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.cjs CHANGED
@@ -50,6 +50,7 @@ __export(index_exports, {
50
50
  getWarningsForL2: () => getWarningsForL2,
51
51
  getWarningsForL3: () => getWarningsForL3,
52
52
  getWarningsForL4: () => getWarningsForL4,
53
+ getWarningsForMppHeader: () => getWarningsForMppHeader,
53
54
  getWarningsForOpenAPI: () => getWarningsForOpenAPI,
54
55
  getWarningsForWellKnown: () => getWarningsForWellKnown,
55
56
  getWellKnown: () => getWellKnown,
@@ -13887,7 +13888,6 @@ var WellKnownDocSchema = external_exports.object({
13887
13888
  version: external_exports.number().optional(),
13888
13889
  resources: external_exports.array(external_exports.string()).default([]),
13889
13890
  mppResources: external_exports.array(external_exports.string()).optional(),
13890
- // isMmmEnabled
13891
13891
  description: external_exports.string().optional(),
13892
13892
  ownershipProofs: external_exports.array(external_exports.string()).optional(),
13893
13893
  instructions: external_exports.string().optional()
@@ -13997,9 +13997,6 @@ function fetchSafe(url2, init) {
13997
13997
  return import_neverthrow.ResultAsync.fromPromise(fetch(url2, init), toFetchError);
13998
13998
  }
13999
13999
 
14000
- // src/mmm-enabled.ts
14001
- var isMmmEnabled = () => "1.1.2".includes("-mmm");
14002
-
14003
14000
  // src/core/source/openapi/index.ts
14004
14001
  var OpenApiParsedSchema = OpenApiDocSchema.transform((doc) => {
14005
14002
  const routes = [];
@@ -14009,9 +14006,7 @@ var OpenApiParsedSchema = OpenApiDocSchema.transform((doc) => {
14009
14006
  if (!operation) continue;
14010
14007
  const authMode = inferAuthMode(operation, doc.security, doc.components?.securitySchemes) ?? void 0;
14011
14008
  const p = operation["x-payment-info"];
14012
- const protocols = (p?.protocols ?? []).filter(
14013
- (proto) => proto !== "mpp" || isMmmEnabled()
14014
- );
14009
+ const protocols = (p?.protocols ?? []).filter((proto) => proto.length > 0);
14015
14010
  const pricing = (authMode === "paid" || authMode === "apiKey+paid") && p ? {
14016
14011
  pricingMode: p.pricingMode,
14017
14012
  ...p.price ? { price: p.price } : {},
@@ -14125,6 +14120,7 @@ function checkL2ForOpenAPI(openApi) {
14125
14120
  return {
14126
14121
  ...openApi.info.title ? { title: openApi.info.title } : {},
14127
14122
  ...openApi.info.description ? { description: openApi.info.description } : {},
14123
+ ...openApi.info.version ? { version: openApi.info.version } : {},
14128
14124
  routes,
14129
14125
  source: "openapi"
14130
14126
  };
@@ -14195,7 +14191,13 @@ async function discoverOriginSchema(options) {
14195
14191
  found: true,
14196
14192
  origin,
14197
14193
  source: "openapi",
14198
- ...l22.title ? { info: { title: l22.title, ...l22.description ? { description: l22.description } : {} } } : {},
14194
+ ...l22.title ? {
14195
+ info: {
14196
+ title: l22.title,
14197
+ ...l22.description ? { description: l22.description } : {},
14198
+ ...l22.version ? { version: l22.version } : {}
14199
+ }
14200
+ } : {},
14199
14201
  endpoints: l22.routes
14200
14202
  };
14201
14203
  return withGuidance(base2, l42, guidanceMode);
@@ -14649,7 +14651,7 @@ function detectProtocols(response) {
14649
14651
  }
14650
14652
  const authHeader = response.headers.get("www-authenticate")?.toLowerCase() ?? "";
14651
14653
  if (authHeader.includes("x402")) protocols.add("x402");
14652
- if (isMmmEnabled() && authHeader.includes("mpp")) protocols.add("mpp");
14654
+ if (authHeader.includes("mpp")) protocols.add("mpp");
14653
14655
  return [...protocols];
14654
14656
  }
14655
14657
  function buildProbeUrl(url2, method, inputBody) {
@@ -14729,7 +14731,7 @@ function parseAuthParams(segment) {
14729
14731
  return params;
14730
14732
  }
14731
14733
  function extractPaymentOptions4(wwwAuthenticate) {
14732
- if (!isMmmEnabled() || !wwwAuthenticate) return [];
14734
+ if (!wwwAuthenticate) return [];
14733
14735
  const options = [];
14734
14736
  for (const segment of wwwAuthenticate.split(/,\s*(?=Payment\s)/i)) {
14735
14737
  const stripped = segment.replace(/^Payment\s+/i, "").trim();
@@ -14758,12 +14760,10 @@ function extractPaymentOptions4(wwwAuthenticate) {
14758
14760
  if (!asset || !amount) continue;
14759
14761
  options.push({
14760
14762
  protocol: "mpp",
14761
- // isMmmEnabled
14762
14763
  paymentMethod,
14763
14764
  intent,
14764
14765
  realm,
14765
14766
  network: `tempo:${String(chainId)}`,
14766
- // isMmmEnabled
14767
14767
  asset,
14768
14768
  amount,
14769
14769
  ...decimals != null ? { decimals } : {},
@@ -14891,7 +14891,7 @@ function parseOperationProtocols(operation) {
14891
14891
  const paymentInfo = operation["x-payment-info"];
14892
14892
  if (!isRecord(paymentInfo) || !Array.isArray(paymentInfo.protocols)) return void 0;
14893
14893
  const protocols = paymentInfo.protocols.filter(
14894
- (protocol) => typeof protocol === "string" && protocol.length > 0 && (protocol !== "mpp" || isMmmEnabled())
14894
+ (protocol) => typeof protocol === "string" && protocol.length > 0
14895
14895
  );
14896
14896
  return protocols.length > 0 ? protocols : void 0;
14897
14897
  }
@@ -14922,8 +14922,7 @@ function getL3ForProbe(probe, path, method) {
14922
14922
  const outputSchema = probeResult.paymentRequiredBody ? parseOutputSchema(probeResult.paymentRequiredBody) : void 0;
14923
14923
  const paymentOptions = [
14924
14924
  ...probeResult.paymentRequiredBody ? extractPaymentOptions3(probeResult.paymentRequiredBody) : [],
14925
- ...isMmmEnabled() ? extractPaymentOptions4(probeResult.wwwAuthenticate) : []
14926
- // isMmmEnabled
14925
+ ...extractPaymentOptions4(probeResult.wwwAuthenticate)
14927
14926
  ];
14928
14927
  return {
14929
14928
  source: "probe",
@@ -14932,7 +14931,8 @@ function getL3ForProbe(probe, path, method) {
14932
14931
  ...inputSchema ? { inputSchema } : {},
14933
14932
  ...outputSchema ? { outputSchema } : {},
14934
14933
  ...paymentOptions.length ? { paymentOptions } : {},
14935
- ...probeResult.paymentRequiredBody !== void 0 ? { paymentRequiredBody: probeResult.paymentRequiredBody } : {}
14934
+ ...probeResult.paymentRequiredBody !== void 0 ? { paymentRequiredBody: probeResult.paymentRequiredBody } : {},
14935
+ ...probeResult.wwwAuthenticate ? { wwwAuthenticate: probeResult.wwwAuthenticate } : {}
14936
14936
  };
14937
14937
  }
14938
14938
  async function attachProbePayload(url2, advisories) {
@@ -14967,7 +14967,7 @@ async function checkEndpointSchema(options) {
14967
14967
  const endpoint = new URL(ensureProtocol(options.url));
14968
14968
  const origin = normalizeOrigin(endpoint.origin);
14969
14969
  const path = normalizePath(endpoint.pathname || "/");
14970
- if (options.sampleInputBody !== void 0) {
14970
+ if (options.probe || options.sampleInputBody !== void 0) {
14971
14971
  const probeResult2 = await getProbe(
14972
14972
  endpoint.href,
14973
14973
  options.headers,
@@ -15113,9 +15113,23 @@ var AUDIT_CODES = {
15113
15113
  L3_INPUT_SCHEMA_MISSING: "L3_INPUT_SCHEMA_MISSING",
15114
15114
  L3_AUTH_MODE_MISSING: "L3_AUTH_MODE_MISSING",
15115
15115
  L3_PROTOCOLS_MISSING_ON_PAID: "L3_PROTOCOLS_MISSING_ON_PAID",
15116
+ L3_PAYMENT_OPTIONS_MISSING_ON_PAID: "L3_PAYMENT_OPTIONS_MISSING_ON_PAID",
15116
15117
  // ─── L4 guidance checks ──────────────────────────────────────────────────────
15117
15118
  L4_GUIDANCE_MISSING: "L4_GUIDANCE_MISSING",
15118
- L4_GUIDANCE_TOO_LONG: "L4_GUIDANCE_TOO_LONG"
15119
+ L4_GUIDANCE_TOO_LONG: "L4_GUIDANCE_TOO_LONG",
15120
+ // ─── MPP WWW-Authenticate header checks ──────────────────────────────────────
15121
+ MPP_HEADER_MISSING: "MPP_HEADER_MISSING",
15122
+ MPP_NO_PAYMENT_CHALLENGES: "MPP_NO_PAYMENT_CHALLENGES",
15123
+ MPP_CHALLENGE_ID_MISSING: "MPP_CHALLENGE_ID_MISSING",
15124
+ MPP_CHALLENGE_METHOD_MISSING: "MPP_CHALLENGE_METHOD_MISSING",
15125
+ MPP_CHALLENGE_INTENT_MISSING: "MPP_CHALLENGE_INTENT_MISSING",
15126
+ MPP_CHALLENGE_REALM_MISSING: "MPP_CHALLENGE_REALM_MISSING",
15127
+ MPP_CHALLENGE_EXPIRES_MISSING: "MPP_CHALLENGE_EXPIRES_MISSING",
15128
+ MPP_CHALLENGE_REQUEST_MISSING: "MPP_CHALLENGE_REQUEST_MISSING",
15129
+ MPP_CHALLENGE_REQUEST_INVALID: "MPP_CHALLENGE_REQUEST_INVALID",
15130
+ MPP_CHALLENGE_ASSET_MISSING: "MPP_CHALLENGE_ASSET_MISSING",
15131
+ MPP_CHALLENGE_AMOUNT_MISSING: "MPP_CHALLENGE_AMOUNT_MISSING",
15132
+ MPP_CHALLENGE_RECIPIENT_MISSING: "MPP_CHALLENGE_RECIPIENT_MISSING"
15119
15133
  };
15120
15134
 
15121
15135
  // src/core/protocols/x402/v1/coinbase-schema.ts
@@ -15204,6 +15218,157 @@ function validateWithCoinbaseSchema2(body) {
15204
15218
  });
15205
15219
  }
15206
15220
 
15221
+ // src/audit/warnings/mpp.ts
15222
+ function parseAuthParams2(segment) {
15223
+ const params = {};
15224
+ const re = /(\w+)=(?:"([^"]*)"|'([^']*)')/g;
15225
+ let match;
15226
+ while ((match = re.exec(segment)) !== null) {
15227
+ params[match[1]] = match[2] ?? match[3] ?? "";
15228
+ }
15229
+ return params;
15230
+ }
15231
+ function getWarningsForMppHeader(wwwAuthenticate) {
15232
+ if (!wwwAuthenticate?.trim()) {
15233
+ return [
15234
+ {
15235
+ code: AUDIT_CODES.MPP_HEADER_MISSING,
15236
+ severity: "error",
15237
+ message: "WWW-Authenticate header is absent.",
15238
+ hint: "MPP endpoints must respond to unauthenticated requests with a 402 and a WWW-Authenticate: Payment ... header."
15239
+ }
15240
+ ];
15241
+ }
15242
+ const segments = wwwAuthenticate.split(/,\s*(?=Payment\s)/i).filter((s) => /^Payment\s/i.test(s.trim()));
15243
+ if (segments.length === 0) {
15244
+ return [
15245
+ {
15246
+ code: AUDIT_CODES.MPP_NO_PAYMENT_CHALLENGES,
15247
+ severity: "error",
15248
+ message: "WWW-Authenticate header contains no Payment challenges.",
15249
+ hint: `Add at least one Payment challenge: WWW-Authenticate: Payment method="tempo" intent="charge" realm="..." request='...'`
15250
+ }
15251
+ ];
15252
+ }
15253
+ const warnings = [];
15254
+ for (let i = 0; i < segments.length; i++) {
15255
+ const stripped = segments[i].replace(/^Payment\s+/i, "").trim();
15256
+ const params = parseAuthParams2(stripped);
15257
+ const idx = `WWW-Authenticate[${i}]`;
15258
+ if (!params["id"]) {
15259
+ warnings.push({
15260
+ code: AUDIT_CODES.MPP_CHALLENGE_ID_MISSING,
15261
+ severity: "error",
15262
+ message: `Payment challenge ${i} is missing the id parameter.`,
15263
+ hint: "Set id to a unique challenge identifier so clients can correlate credentials to challenges.",
15264
+ path: `${idx}.id`
15265
+ });
15266
+ }
15267
+ if (!params["method"]) {
15268
+ warnings.push({
15269
+ code: AUDIT_CODES.MPP_CHALLENGE_METHOD_MISSING,
15270
+ severity: "error",
15271
+ message: `Payment challenge ${i} is missing the method parameter.`,
15272
+ hint: 'Set method="tempo" (or your payment method identifier) on the Payment challenge.',
15273
+ path: `${idx}.method`
15274
+ });
15275
+ }
15276
+ if (!params["intent"]) {
15277
+ warnings.push({
15278
+ code: AUDIT_CODES.MPP_CHALLENGE_INTENT_MISSING,
15279
+ severity: "error",
15280
+ message: `Payment challenge ${i} is missing the intent parameter.`,
15281
+ hint: 'Set intent="charge" on the Payment challenge.',
15282
+ path: `${idx}.intent`
15283
+ });
15284
+ }
15285
+ if (!params["realm"]) {
15286
+ warnings.push({
15287
+ code: AUDIT_CODES.MPP_CHALLENGE_REALM_MISSING,
15288
+ severity: "error",
15289
+ message: `Payment challenge ${i} is missing the realm parameter.`,
15290
+ hint: "Set realm to a stable server identifier so clients can associate payment credentials.",
15291
+ path: `${idx}.realm`
15292
+ });
15293
+ }
15294
+ if (!params["expires"]) {
15295
+ warnings.push({
15296
+ code: AUDIT_CODES.MPP_CHALLENGE_EXPIRES_MISSING,
15297
+ severity: "error",
15298
+ message: `Payment challenge ${i} is missing the expires parameter.`,
15299
+ hint: "Set expires to an RFC 3339 timestamp so clients know when the challenge lapses.",
15300
+ path: `${idx}.expires`
15301
+ });
15302
+ }
15303
+ const requestStr = params["request"];
15304
+ if (!requestStr) {
15305
+ warnings.push({
15306
+ code: AUDIT_CODES.MPP_CHALLENGE_REQUEST_MISSING,
15307
+ severity: "error",
15308
+ message: `Payment challenge ${i} is missing the request field.`,
15309
+ hint: `Include a base64url-encoded JSON request field: request=base64url('{"currency":"...","amount":"...","recipient":"..."}')`,
15310
+ path: `${idx}.request`
15311
+ });
15312
+ continue;
15313
+ }
15314
+ let request;
15315
+ try {
15316
+ const decoded = Buffer.from(requestStr, "base64url").toString("utf-8");
15317
+ const parsed = JSON.parse(decoded);
15318
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
15319
+ throw new Error("not an object");
15320
+ }
15321
+ request = parsed;
15322
+ } catch {
15323
+ warnings.push({
15324
+ code: AUDIT_CODES.MPP_CHALLENGE_REQUEST_INVALID,
15325
+ severity: "error",
15326
+ message: `Payment challenge ${i} request field is not valid base64url-encoded JSON.`,
15327
+ hint: "The request value must be a base64url-encoded JCS JSON object.",
15328
+ path: `${idx}.request`
15329
+ });
15330
+ continue;
15331
+ }
15332
+ if (!request["currency"]) {
15333
+ warnings.push({
15334
+ code: AUDIT_CODES.MPP_CHALLENGE_ASSET_MISSING,
15335
+ severity: "error",
15336
+ message: `Payment challenge ${i} is missing currency in the request object.`,
15337
+ hint: "Set currency to a TIP-20 token address (e.g. a USDC contract).",
15338
+ path: `${idx}.request.currency`
15339
+ });
15340
+ }
15341
+ const amount = request["amount"];
15342
+ if (amount === void 0 || amount === null) {
15343
+ warnings.push({
15344
+ code: AUDIT_CODES.MPP_CHALLENGE_AMOUNT_MISSING,
15345
+ severity: "error",
15346
+ message: `Payment challenge ${i} is missing amount in the request object.`,
15347
+ hint: 'Set amount to a raw token-unit string (e.g. "1000000" for 1 USDC with 6 decimals).',
15348
+ path: `${idx}.request.amount`
15349
+ });
15350
+ } else if (typeof amount !== "string" && typeof amount !== "number") {
15351
+ warnings.push({
15352
+ code: AUDIT_CODES.MPP_CHALLENGE_AMOUNT_MISSING,
15353
+ severity: "error",
15354
+ message: `Payment challenge ${i} has an invalid amount type (got ${typeof amount}, expected string or number).`,
15355
+ hint: "Set amount to a raw token-unit string.",
15356
+ path: `${idx}.request.amount`
15357
+ });
15358
+ }
15359
+ if (!request["recipient"]) {
15360
+ warnings.push({
15361
+ code: AUDIT_CODES.MPP_CHALLENGE_RECIPIENT_MISSING,
15362
+ severity: "error",
15363
+ message: `Payment challenge ${i} is missing recipient in the request object.`,
15364
+ hint: "Set recipient to the wallet address that should receive payment.",
15365
+ path: `${idx}.request.recipient`
15366
+ });
15367
+ }
15368
+ }
15369
+ return warnings;
15370
+ }
15371
+
15207
15372
  // src/audit/warnings/l3.ts
15208
15373
  function getWarningsFor402Body(body) {
15209
15374
  if (!isRecord(body)) {
@@ -15333,17 +15498,28 @@ function getWarningsForL3(l3) {
15333
15498
  hint: "Add a requestBody or parameters schema so agents can construct valid payloads."
15334
15499
  });
15335
15500
  }
15336
- if (l3.authMode === "paid" && !l3.protocols?.length) {
15501
+ if (l3.authMode === "paid" && l3.source === "openapi" && !l3.protocols?.length) {
15337
15502
  warnings.push({
15338
15503
  code: AUDIT_CODES.L3_PROTOCOLS_MISSING_ON_PAID,
15339
15504
  severity: "info",
15340
15505
  message: "Paid endpoint does not declare supported payment protocols.",
15341
- hint: "Add x-payment-info.protocols (e.g. ['x402']) to the operation."
15506
+ hint: "Add x-payment-info.protocols (e.g. ['x402', 'mpp']) to the operation."
15507
+ });
15508
+ }
15509
+ if (l3.authMode === "paid" && l3.source === "probe" && !l3.paymentOptions?.length) {
15510
+ warnings.push({
15511
+ code: AUDIT_CODES.L3_PAYMENT_OPTIONS_MISSING_ON_PAID,
15512
+ severity: "warn",
15513
+ message: "Paid endpoint did not return payment options in the 402 response.",
15514
+ hint: "Ensure the 402 response returns a valid payment challenge so clients know how to pay."
15342
15515
  });
15343
15516
  }
15344
15517
  if (l3.paymentRequiredBody !== void 0) {
15345
15518
  warnings.push(...getWarningsFor402Body(l3.paymentRequiredBody));
15346
15519
  }
15520
+ if (l3.wwwAuthenticate !== void 0) {
15521
+ warnings.push(...getWarningsForMppHeader(l3.wwwAuthenticate));
15522
+ }
15347
15523
  return warnings;
15348
15524
  }
15349
15525
 
@@ -15568,6 +15744,7 @@ function getWarningsForL4(l4) {
15568
15744
  getWarningsForL2,
15569
15745
  getWarningsForL3,
15570
15746
  getWarningsForL4,
15747
+ getWarningsForMppHeader,
15571
15748
  getWarningsForOpenAPI,
15572
15749
  getWarningsForWellKnown,
15573
15750
  getWellKnown,
package/dist/index.d.cts CHANGED
@@ -8,12 +8,14 @@ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTION
8
8
 
9
9
  interface MppPaymentOption {
10
10
  protocol: 'mpp';
11
- /** Payment method identifier, e.g. "tempo" (Tempo protocol). */ paymentMethod: string;
11
+ /** Payment method identifier, e.g. "tempo" (Tempo protocol). */
12
+ paymentMethod: string;
12
13
  /** Payment intent type, e.g. "charge". */
13
14
  intent: string;
14
15
  /** Server protection realm. */
15
16
  realm: string;
16
- /** CAIP-2 style network identifier, e.g. "tempo:4217". */ network: string;
17
+ /** CAIP-2 style network identifier, e.g. "tempo:4217". */
18
+ network: string;
17
19
  /** Currency / token contract. */
18
20
  asset: string;
19
21
  /** Raw token-unit amount string. */
@@ -107,6 +109,7 @@ interface ProbeResult {
107
109
  interface L2Result {
108
110
  title?: string;
109
111
  description?: string;
112
+ version?: string;
110
113
  routes: L2Route[];
111
114
  source: 'openapi' | 'well-known/x402' | null;
112
115
  }
@@ -134,6 +137,11 @@ interface L3Result {
134
137
  * and returned a 402. Used by getWarningsForL3 to run full payment-required validation.
135
138
  */
136
139
  paymentRequiredBody?: unknown;
140
+ /**
141
+ * Raw WWW-Authenticate header value from the 402 response. Present when the endpoint
142
+ * was probed and returned a 402 with an MPP challenge. Used by getWarningsForMppHeader.
143
+ */
144
+ wwwAuthenticate?: string;
137
145
  }
138
146
  interface L4Result {
139
147
  guidance: string;
@@ -164,6 +172,7 @@ interface DiscoverOriginSchemaSuccess {
164
172
  info?: {
165
173
  title: string;
166
174
  description?: string;
175
+ version?: string;
167
176
  };
168
177
  /** Discovered endpoints with advisory pricing and auth metadata. */
169
178
  endpoints: L2Route[];
@@ -196,6 +205,12 @@ interface CheckEndpointOptions {
196
205
  *
197
206
  */
198
207
  sampleInputBody?: Record<string, unknown>;
208
+ /**
209
+ * When true, skips OpenAPI lookup and probes the live endpoint directly.
210
+ * Use this to retrieve actual PaymentOptions (realm, payTo, network, asset, amount)
211
+ * from the 402 response rather than static OpenAPI metadata.
212
+ */
213
+ probe?: boolean;
199
214
  }
200
215
  interface EndpointMethodAdvisory extends L3Result {
201
216
  method: HttpMethod;
@@ -351,8 +366,21 @@ declare const AUDIT_CODES: {
351
366
  readonly L3_INPUT_SCHEMA_MISSING: "L3_INPUT_SCHEMA_MISSING";
352
367
  readonly L3_AUTH_MODE_MISSING: "L3_AUTH_MODE_MISSING";
353
368
  readonly L3_PROTOCOLS_MISSING_ON_PAID: "L3_PROTOCOLS_MISSING_ON_PAID";
369
+ readonly L3_PAYMENT_OPTIONS_MISSING_ON_PAID: "L3_PAYMENT_OPTIONS_MISSING_ON_PAID";
354
370
  readonly L4_GUIDANCE_MISSING: "L4_GUIDANCE_MISSING";
355
371
  readonly L4_GUIDANCE_TOO_LONG: "L4_GUIDANCE_TOO_LONG";
372
+ readonly MPP_HEADER_MISSING: "MPP_HEADER_MISSING";
373
+ readonly MPP_NO_PAYMENT_CHALLENGES: "MPP_NO_PAYMENT_CHALLENGES";
374
+ readonly MPP_CHALLENGE_ID_MISSING: "MPP_CHALLENGE_ID_MISSING";
375
+ readonly MPP_CHALLENGE_METHOD_MISSING: "MPP_CHALLENGE_METHOD_MISSING";
376
+ readonly MPP_CHALLENGE_INTENT_MISSING: "MPP_CHALLENGE_INTENT_MISSING";
377
+ readonly MPP_CHALLENGE_REALM_MISSING: "MPP_CHALLENGE_REALM_MISSING";
378
+ readonly MPP_CHALLENGE_EXPIRES_MISSING: "MPP_CHALLENGE_EXPIRES_MISSING";
379
+ readonly MPP_CHALLENGE_REQUEST_MISSING: "MPP_CHALLENGE_REQUEST_MISSING";
380
+ readonly MPP_CHALLENGE_REQUEST_INVALID: "MPP_CHALLENGE_REQUEST_INVALID";
381
+ readonly MPP_CHALLENGE_ASSET_MISSING: "MPP_CHALLENGE_ASSET_MISSING";
382
+ readonly MPP_CHALLENGE_AMOUNT_MISSING: "MPP_CHALLENGE_AMOUNT_MISSING";
383
+ readonly MPP_CHALLENGE_RECIPIENT_MISSING: "MPP_CHALLENGE_RECIPIENT_MISSING";
356
384
  };
357
385
  type AuditCode = (typeof AUDIT_CODES)[keyof typeof AUDIT_CODES];
358
386
 
@@ -382,4 +410,18 @@ declare function getWarningsForL3(l3: L3Result | null): AuditWarning[];
382
410
 
383
411
  declare function getWarningsForL4(l4: L4Result | null): AuditWarning[];
384
412
 
385
- 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 EndpointMethodAdvisory, GuidanceMode, type HttpMethod, type L2Result, type L2Route, type L3Result, type L4Result, type MetadataPreview, type MppPaymentOption, type NormalizedAccept, type NormalizedPaymentRequired, type OpenApiRoute, type OpenApiSource, type PaymentOption, 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 X402V1PaymentOption, type X402V2PaymentOption, attachProbePayload, checkEndpointSchema, checkL2ForOpenAPI, checkL2ForWellknown, checkL4ForOpenAPI, checkL4ForWellknown, discoverOriginSchema, evaluateMetadataCompleteness, getL3, getL3ForOpenAPI, getL3ForProbe, getOpenAPI, getProbe, getWarningsFor402Body, getWarningsForL2, getWarningsForL3, getWarningsForL4, getWarningsForOpenAPI, getWarningsForWellKnown, getWellKnown, validatePaymentRequiredDetailed };
413
+ /**
414
+ * Validates a raw WWW-Authenticate header value from an MPP 402 response and
415
+ * returns issues as AuditWarnings.
416
+ *
417
+ * Checks for:
418
+ * - Header presence
419
+ * - At least one Payment challenge
420
+ * - Required challenge parameters: id, method, intent, realm, expires, request
421
+ * - Valid base64url-encoded JSON in the request field
422
+ * - Required request fields: currency (asset), amount
423
+ * - Recommended request field: recipient (payTo)
424
+ */
425
+ declare function getWarningsForMppHeader(wwwAuthenticate: string | null | undefined): AuditWarning[];
426
+
427
+ 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 EndpointMethodAdvisory, GuidanceMode, type HttpMethod, type L2Result, type L2Route, type L3Result, type L4Result, type MetadataPreview, type MppPaymentOption, type NormalizedAccept, type NormalizedPaymentRequired, type OpenApiRoute, type OpenApiSource, type PaymentOption, 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 X402V1PaymentOption, type X402V2PaymentOption, attachProbePayload, checkEndpointSchema, checkL2ForOpenAPI, checkL2ForWellknown, checkL4ForOpenAPI, checkL4ForWellknown, discoverOriginSchema, evaluateMetadataCompleteness, getL3, getL3ForOpenAPI, getL3ForProbe, getOpenAPI, getProbe, getWarningsFor402Body, getWarningsForL2, getWarningsForL3, getWarningsForL4, getWarningsForMppHeader, getWarningsForOpenAPI, getWarningsForWellKnown, getWellKnown, validatePaymentRequiredDetailed };
package/dist/index.d.ts CHANGED
@@ -8,12 +8,14 @@ type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTION
8
8
 
9
9
  interface MppPaymentOption {
10
10
  protocol: 'mpp';
11
- /** Payment method identifier, e.g. "tempo" (Tempo protocol). */ paymentMethod: string;
11
+ /** Payment method identifier, e.g. "tempo" (Tempo protocol). */
12
+ paymentMethod: string;
12
13
  /** Payment intent type, e.g. "charge". */
13
14
  intent: string;
14
15
  /** Server protection realm. */
15
16
  realm: string;
16
- /** CAIP-2 style network identifier, e.g. "tempo:4217". */ network: string;
17
+ /** CAIP-2 style network identifier, e.g. "tempo:4217". */
18
+ network: string;
17
19
  /** Currency / token contract. */
18
20
  asset: string;
19
21
  /** Raw token-unit amount string. */
@@ -107,6 +109,7 @@ interface ProbeResult {
107
109
  interface L2Result {
108
110
  title?: string;
109
111
  description?: string;
112
+ version?: string;
110
113
  routes: L2Route[];
111
114
  source: 'openapi' | 'well-known/x402' | null;
112
115
  }
@@ -134,6 +137,11 @@ interface L3Result {
134
137
  * and returned a 402. Used by getWarningsForL3 to run full payment-required validation.
135
138
  */
136
139
  paymentRequiredBody?: unknown;
140
+ /**
141
+ * Raw WWW-Authenticate header value from the 402 response. Present when the endpoint
142
+ * was probed and returned a 402 with an MPP challenge. Used by getWarningsForMppHeader.
143
+ */
144
+ wwwAuthenticate?: string;
137
145
  }
138
146
  interface L4Result {
139
147
  guidance: string;
@@ -164,6 +172,7 @@ interface DiscoverOriginSchemaSuccess {
164
172
  info?: {
165
173
  title: string;
166
174
  description?: string;
175
+ version?: string;
167
176
  };
168
177
  /** Discovered endpoints with advisory pricing and auth metadata. */
169
178
  endpoints: L2Route[];
@@ -196,6 +205,12 @@ interface CheckEndpointOptions {
196
205
  *
197
206
  */
198
207
  sampleInputBody?: Record<string, unknown>;
208
+ /**
209
+ * When true, skips OpenAPI lookup and probes the live endpoint directly.
210
+ * Use this to retrieve actual PaymentOptions (realm, payTo, network, asset, amount)
211
+ * from the 402 response rather than static OpenAPI metadata.
212
+ */
213
+ probe?: boolean;
199
214
  }
200
215
  interface EndpointMethodAdvisory extends L3Result {
201
216
  method: HttpMethod;
@@ -351,8 +366,21 @@ declare const AUDIT_CODES: {
351
366
  readonly L3_INPUT_SCHEMA_MISSING: "L3_INPUT_SCHEMA_MISSING";
352
367
  readonly L3_AUTH_MODE_MISSING: "L3_AUTH_MODE_MISSING";
353
368
  readonly L3_PROTOCOLS_MISSING_ON_PAID: "L3_PROTOCOLS_MISSING_ON_PAID";
369
+ readonly L3_PAYMENT_OPTIONS_MISSING_ON_PAID: "L3_PAYMENT_OPTIONS_MISSING_ON_PAID";
354
370
  readonly L4_GUIDANCE_MISSING: "L4_GUIDANCE_MISSING";
355
371
  readonly L4_GUIDANCE_TOO_LONG: "L4_GUIDANCE_TOO_LONG";
372
+ readonly MPP_HEADER_MISSING: "MPP_HEADER_MISSING";
373
+ readonly MPP_NO_PAYMENT_CHALLENGES: "MPP_NO_PAYMENT_CHALLENGES";
374
+ readonly MPP_CHALLENGE_ID_MISSING: "MPP_CHALLENGE_ID_MISSING";
375
+ readonly MPP_CHALLENGE_METHOD_MISSING: "MPP_CHALLENGE_METHOD_MISSING";
376
+ readonly MPP_CHALLENGE_INTENT_MISSING: "MPP_CHALLENGE_INTENT_MISSING";
377
+ readonly MPP_CHALLENGE_REALM_MISSING: "MPP_CHALLENGE_REALM_MISSING";
378
+ readonly MPP_CHALLENGE_EXPIRES_MISSING: "MPP_CHALLENGE_EXPIRES_MISSING";
379
+ readonly MPP_CHALLENGE_REQUEST_MISSING: "MPP_CHALLENGE_REQUEST_MISSING";
380
+ readonly MPP_CHALLENGE_REQUEST_INVALID: "MPP_CHALLENGE_REQUEST_INVALID";
381
+ readonly MPP_CHALLENGE_ASSET_MISSING: "MPP_CHALLENGE_ASSET_MISSING";
382
+ readonly MPP_CHALLENGE_AMOUNT_MISSING: "MPP_CHALLENGE_AMOUNT_MISSING";
383
+ readonly MPP_CHALLENGE_RECIPIENT_MISSING: "MPP_CHALLENGE_RECIPIENT_MISSING";
356
384
  };
357
385
  type AuditCode = (typeof AUDIT_CODES)[keyof typeof AUDIT_CODES];
358
386
 
@@ -382,4 +410,18 @@ declare function getWarningsForL3(l3: L3Result | null): AuditWarning[];
382
410
 
383
411
  declare function getWarningsForL4(l4: L4Result | null): AuditWarning[];
384
412
 
385
- 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 EndpointMethodAdvisory, GuidanceMode, type HttpMethod, type L2Result, type L2Route, type L3Result, type L4Result, type MetadataPreview, type MppPaymentOption, type NormalizedAccept, type NormalizedPaymentRequired, type OpenApiRoute, type OpenApiSource, type PaymentOption, 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 X402V1PaymentOption, type X402V2PaymentOption, attachProbePayload, checkEndpointSchema, checkL2ForOpenAPI, checkL2ForWellknown, checkL4ForOpenAPI, checkL4ForWellknown, discoverOriginSchema, evaluateMetadataCompleteness, getL3, getL3ForOpenAPI, getL3ForProbe, getOpenAPI, getProbe, getWarningsFor402Body, getWarningsForL2, getWarningsForL3, getWarningsForL4, getWarningsForOpenAPI, getWarningsForWellKnown, getWellKnown, validatePaymentRequiredDetailed };
413
+ /**
414
+ * Validates a raw WWW-Authenticate header value from an MPP 402 response and
415
+ * returns issues as AuditWarnings.
416
+ *
417
+ * Checks for:
418
+ * - Header presence
419
+ * - At least one Payment challenge
420
+ * - Required challenge parameters: id, method, intent, realm, expires, request
421
+ * - Valid base64url-encoded JSON in the request field
422
+ * - Required request fields: currency (asset), amount
423
+ * - Recommended request field: recipient (payTo)
424
+ */
425
+ declare function getWarningsForMppHeader(wwwAuthenticate: string | null | undefined): AuditWarning[];
426
+
427
+ 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 EndpointMethodAdvisory, GuidanceMode, type HttpMethod, type L2Result, type L2Route, type L3Result, type L4Result, type MetadataPreview, type MppPaymentOption, type NormalizedAccept, type NormalizedPaymentRequired, type OpenApiRoute, type OpenApiSource, type PaymentOption, 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 X402V1PaymentOption, type X402V2PaymentOption, attachProbePayload, checkEndpointSchema, checkL2ForOpenAPI, checkL2ForWellknown, checkL4ForOpenAPI, checkL4ForWellknown, discoverOriginSchema, evaluateMetadataCompleteness, getL3, getL3ForOpenAPI, getL3ForProbe, getOpenAPI, getProbe, getWarningsFor402Body, getWarningsForL2, getWarningsForL3, getWarningsForL4, getWarningsForMppHeader, getWarningsForOpenAPI, getWarningsForWellKnown, getWellKnown, validatePaymentRequiredDetailed };