@faremeter/types

中文文档
0.22.0发布于 2026/05/27LGPL-3.0-onlyTypeScriptESM + CJS近 30 天下载 4988

TypeScript type definitions and runtime validation for x402 protocol and Faremeter ecosystem

原始使用文档
文档目录83 节
  1. Installation
  2. Features
  3. Subpath Exports
  4. API Reference
  5. Functions
  6. caseInsensitiveLiteral
  7. isValidationError
  8. throwValidationError
  9. normalizePaymentRequiredResponse
  10. normalizeVerifyResponse
  11. normalizeSettleResponse
  12. generateRequirementsMatcher
  13. adaptRequirementsV1ToV2
  14. adaptRequirementsV2ToV1
  15. extractResourceInfoV1
  16. adaptPayloadV1ToV2
  17. adaptPaymentRequiredResponseV1ToV2
  18. adaptPaymentRequiredResponseV2ToV1
  19. adaptVerifyResponseV2ToV1
  20. adaptVerifyResponseV1ToV2
  21. adaptSettleResponseV2ToV1
  22. adaptSettleResponseV2ToV1Legacy
  23. adaptSettleResponseV1ToV2
  24. adaptSettleResponseLegacyToV2
  25. adaptSettleResponseLenientToV2
  26. adaptSupportedKindV2ToV1
  27. adaptSupportedKindV1ToV2
  28. adaptPaymentHandlerV1ToV2
  29. adaptPaymentHandlerV2ToV1
  30. isAddress
  31. isPrivateKey
  32. matchPricingToCapabilities
  33. capabilitiesMatch
  34. narrowHandlers
  35. resolveX402Requirements
  36. settleX402Payment
  37. verifyX402Payment
  38. isBaseAddress
  39. isSolanaCluster
  40. isSolanaCAIP2NetworkString
  41. isSolanaCAIP2Network
  42. createSolanaNetwork
  43. Constants
  44. X_PAYMENT_HEADER
  45. X_PAYMENT_RESPONSE_HEADER
  46. x402PaymentId
  47. x402PaymentRequirements
  48. x402PaymentRequiredResponse
  49. x402PaymentRequiredResponseLenient
  50. x402PaymentPayload
  51. x402PaymentHeaderToPayload
  52. x402VerifyRequest
  53. x402VerifyResponse
  54. x402VerifyResponseLenient
  55. x402SettleRequest
  56. x402SettleResponseLegacy
  57. x402SettleResponse
  58. x402SettleResponseLenient
  59. x402SupportedKind
  60. x402SupportedResponse
  61. V2_PAYMENT_HEADER
  62. V2_PAYMENT_REQUIRED_HEADER
  63. V2_PAYMENT_RESPONSE_HEADER
  64. x402ResourceInfo
  65. x402PaymentRequirements
  66. x402PaymentRequiredResponse
  67. x402PaymentPayload
  68. x402PaymentHeaderToPayload
  69. x402VerifyRequest
  70. x402VerifyResponse
  71. x402SettleRequest
  72. x402SettleResponse
  73. x402SupportedKind
  74. x402SupportedKindAny
  75. x402SupportedResponse
  76. Address
  77. PrivateKey
  78. Base58Address
  79. SolanaCluster
  80. SolanaCAIP2NetworkString
  81. Interfaces
  82. GetRequirementsArgs
  83. FacilitatorHandler

@faremeter/types

TypeScript type definitions and runtime validation for the x402 protocol and Faremeter ecosystem.

Installation

pnpm install @faremeter/types

Features

  • Complete x402 protocol types
  • Runtime validation with arktype
  • Client and facilitator interfaces
  • Chain-specific types (Solana, EVM)
  • Type-safe across the entire ecosystem

Subpath Exports

  • @faremeter/types - Main exports
  • @faremeter/types/x402 - x402 protocol types
  • @faremeter/types/client - Client-side types
  • @faremeter/types/facilitator - Facilitator types
  • @faremeter/types/solana - Solana-specific types
  • @faremeter/types/evm - EVM-specific types

API Reference

Functions

caseInsensitiveLiteral

Creates an arktype validator for case-insensitive string literals.

Input strings are lowercased before matching against the allowed values.

FunctionType
caseInsensitiveLiteral<T extends string>(...l: T[]) => instantiateType<normalizeMorphDistribution<_inferIntersection<(In: string) => To<string>, Lowercase<T>, true>, _inferIntersection<(In: string) => To<string>, Lowercase<T>, true> extends InferredMorph<...> ? i : never, _inferIntersection<...> extends InferredMorph<...> ? [...] extends...

Parameters:

  • l: - The literal string values to accept (case-insensitive)

Returns:

An arktype validator that accepts any case variant of the literals

isValidationError

Type guard that checks if a value is an arktype validation error.

FunctionType
isValidationError(possibleErrors: unknown) => possibleErrors is ArkErrors

Parameters:

  • possibleErrors: - The value to check

Returns:

True if the value is a validation error

throwValidationError

Throws an error with the validation error messages appended.

FunctionType
throwValidationError(message: string, errors: ArkErrors) => never

Parameters:

  • message: - Context message describing what was being validated
  • errors: - The arktype validation errors

normalizePaymentRequiredResponse

Normalize a lenient payment required response to spec-compliant field values. Defaults error to empty string when missing.

FunctionType
normalizePaymentRequiredResponse(res: { x402Version: number; accepts: { scheme: string; network: string; maxAmountRequired: string; resource: string; description: string; payTo: string; maxTimeoutSeconds: number; asset: string; mimeType?: string or undefined; outputSchema?: object or undefined; extra?: object or undefined; }[]; error?: string or undef...

normalizeVerifyResponse

Normalize a lenient verify response to spec-compliant field values. Defaults payer to empty string and strips null from invalidReason.

FunctionType
normalizeVerifyResponse(res: { isValid: boolean; invalidReason?: string or null or undefined; payer?: string or undefined; }) => { isValid: boolean; payer: string; invalidReason?: string or undefined; }

normalizeSettleResponse

Normalize a lenient settle response to spec-compliant field names. Converts legacy field names (txHash, networkId, error) to spec-compliant names (transaction, network, errorReason).

FunctionType
normalizeSettleResponse(res: { success: boolean; errorReason?: string or null or undefined; error?: string or null or undefined; transaction?: string or null or undefined; txHash?: string or null or undefined; network?: string or ... 1 more ... or undefined; networkId?: string or ... 1 more ... or undefined; payer?: string or undefined; }) => { ...; }

generateRequirementsMatcher

Creates a matcher function for filtering payment requirements.

The matcher performs case-insensitive matching on scheme, network, and asset fields.

FunctionType
generateRequirementsMatcher(scheme: string[], network: string[], asset: string[]) => { matchTuple: Type<{ scheme: (In: string) => To<Lowercase<string>>; network: (In: string) => To<Lowercase<string>>; asset: (In: string) => To<...>; }, {}>; isMatchingRequirement: (req: { ...; }) => boolean; }

Parameters:

  • scheme: - Accepted payment scheme names
  • network: - Accepted network identifiers
  • asset: - Accepted asset addresses

Returns:

Object with the matcher tuple and isMatchingRequirement function

adaptRequirementsV1ToV2

Converts v1 payment requirements to v2 format.

FunctionType
adaptRequirementsV1ToV2(req: { scheme: string; network: string; maxAmountRequired: string; resource: string; description: string; payTo: string; maxTimeoutSeconds: number; asset: string; mimeType?: string or undefined; outputSchema?: object or undefined; extra?: object or undefined; }, translateNetwork: NetworkTranslator) => { ...; }

Parameters:

  • req: - The v1 payment requirements
  • translateNetwork: - Function to translate legacy network IDs to CAIP-2

Returns:

The v2 payment requirements

adaptRequirementsV2ToV1

Converts v2 payment requirements to v1 format.

FunctionType
adaptRequirementsV2ToV1(req: { scheme: string; network: string; amount: string; asset: string; payTo: string; maxTimeoutSeconds: number; extra?: object or undefined; }, resource: { url: string; description?: string or undefined; mimeType?: string or undefined; }, translateNetwork?: NetworkTranslator or undefined) => { ...; } and { ...; }

Parameters:

  • req: - The v2 payment requirements
  • resource: - Resource information to populate v1 fields
  • translateNetwork: - Optional function to translate CAIP-2 to legacy IDs

Returns:

The v1 payment requirements with mimeType guaranteed

extractResourceInfoV1

Extracts resource information from v1 payment requirements.

FunctionType
extractResourceInfoV1(req: { scheme: string; network: string; maxAmountRequired: string; resource: string; description: string; payTo: string; maxTimeoutSeconds: number; asset: string; mimeType?: string or undefined; outputSchema?: object or undefined; extra?: object or undefined; }) => { ...; }

Parameters:

  • req: - The v1 payment requirements containing resource fields

Returns:

The extracted resource information

adaptPayloadV1ToV2

Converts a v1 payment payload to v2 format.

FunctionType
adaptPayloadV1ToV2(payload: { x402Version: number; scheme: string; network: string; payload: object; asset?: string or undefined; }, requirements: { scheme: string; network: string; maxAmountRequired: string; resource: string; ... 6 more ...; extra?: object or undefined; }, translateNetwork: NetworkTranslator) => { ...; }

Parameters:

  • payload: - The v1 payment payload
  • requirements: - The v1 requirements used for resource extraction
  • translateNetwork: - Function to translate legacy network IDs to CAIP-2

Returns:

The v2 payment payload

adaptPaymentRequiredResponseV1ToV2

Converts a v1 payment required response to v2 format.

FunctionType
adaptPaymentRequiredResponseV1ToV2(v1Response: { x402Version: number; accepts: { scheme: string; network: string; maxAmountRequired: string; resource: string; description: string; payTo: string; maxTimeoutSeconds: number; asset: string; mimeType?: string or undefined; outputSchema?: object or undefined; extra?: object or undefined; }[]; error?: string ...

Parameters:

  • v1Response: - The v1 payment required response
  • resourceURL: - The URL of the protected resource
  • translateNetwork: - Function to translate legacy network IDs to CAIP-2

Returns:

The v2 payment required response

adaptPaymentRequiredResponseV2ToV1

Converts a v2 payment required response to v1 format.

FunctionType
adaptPaymentRequiredResponseV2ToV1(v2Response: { x402Version: 2; resource: { url: string; description?: string or undefined; mimeType?: string or undefined; }; accepts: { scheme: string; network: string; amount: string; asset: string; payTo: string; maxTimeoutSeconds: number; extra?: object or undefined; }[]; error?: string or undefined; extensions?: ob...

Parameters:

  • v2Response: - The v2 payment required response
  • translateNetwork: - Optional function to translate CAIP-2 to legacy IDs

Returns:

The v1 payment required response

adaptVerifyResponseV2ToV1

Converts a v2 verify response to v1 format.

FunctionType
adaptVerifyResponseV2ToV1(res: { isValid: boolean; invalidReason?: string or undefined; payer?: string or undefined; }) => { isValid: boolean; payer: string; invalidReason?: string or undefined; }

Parameters:

  • res: - The v2 verify response

Returns:

The v1 verify response

adaptVerifyResponseV1ToV2

Converts a v1 verify response to v2 format.

FunctionType
adaptVerifyResponseV1ToV2(res: { isValid: boolean; invalidReason?: string or null or undefined; payer?: string or undefined; }) => { isValid: boolean; invalidReason?: string or undefined; payer?: string or undefined; }

Parameters:

  • res: - The v1 verify response (lenient)

Returns:

The v2 verify response

adaptSettleResponseV2ToV1

Adapt v2 settle response to spec-compliant v1 format. Since v1 spec uses the same field names as v2 (transaction, network, errorReason), this is primarily a network translation pass.

FunctionType
adaptSettleResponseV2ToV1(res: { success: boolean; transaction: string; network: string; errorReason?: string or undefined; payer?: string or undefined; extensions?: object or undefined; }, translateNetwork?: NetworkTranslator or undefined) => { ...; }

adaptSettleResponseV2ToV1Legacy

Adapt v2 settle response to legacy v1 format with old field names. Use this only for backward compatibility with clients expecting txHash/networkId/error field names.

FunctionType
adaptSettleResponseV2ToV1Legacy(res: { success: boolean; transaction: string; network: string; errorReason?: string or undefined; payer?: string or undefined; extensions?: object or undefined; }, translateNetwork?: NetworkTranslator or undefined) => { ...; }

adaptSettleResponseV1ToV2

Adapt v1 settle response to v2 format. Accepts lenient input that may have optional/nullable fields from older handlers.

FunctionType
adaptSettleResponseV1ToV2(res: { success: boolean; errorReason?: string or null or undefined; error?: string or null or undefined; transaction?: string or null or undefined; txHash?: string or null or undefined; network?: string or ... 1 more ... or undefined; networkId?: string or ... 1 more ... or undefined; payer?: string or undefined; }) => { ...; }

adaptSettleResponseLegacyToV2

Adapt legacy v1 settle response (with txHash/networkId/error) to v2 format. Use this when receiving data from older clients that use legacy field names.

FunctionType
adaptSettleResponseLegacyToV2(res: { success: boolean; txHash: string or null; networkId: string or null; error?: string or null or undefined; payer?: string or undefined; }) => { success: boolean; transaction: string; network: string; errorReason?: string or undefined; payer?: string or undefined; extensions?: object or undefined; }

adaptSettleResponseLenientToV2

Adapt a lenient v1 settle response (accepting either legacy or spec-compliant field names) to v2 format. This is the most flexible adapter for parsing incoming settle responses from unknown sources.

FunctionType
adaptSettleResponseLenientToV2(res: { success: boolean; errorReason?: string or null or undefined; error?: string or null or undefined; transaction?: string or null or undefined; txHash?: string or null or undefined; network?: string or ... 1 more ... or undefined; networkId?: string or ... 1 more ... or undefined; payer?: string or undefined; }) => { ...; }

adaptSupportedKindV2ToV1

Converts a v2 supported kind to v1 format.

FunctionType
adaptSupportedKindV2ToV1(kind: { x402Version: 2; scheme: string; network: string; extra?: object or undefined; }, translateNetwork?: NetworkTranslator or undefined) => { x402Version: 1 or 2; scheme: string; network: string; extra?: object or undefined; }

Parameters:

  • kind: - The v2 supported kind
  • translateNetwork: - Optional function to translate CAIP-2 to legacy IDs

Returns:

The v1 supported kind

adaptSupportedKindV1ToV2

Converts a v1 supported kind to v2 format.

FunctionType
adaptSupportedKindV1ToV2(kind: { x402Version: number; scheme: string; network: string; extra?: object or undefined; }, translateNetwork: NetworkTranslator) => { x402Version: 2; scheme: string; network: string; extra?: object or undefined; }

Parameters:

  • kind: - The v1 supported kind
  • translateNetwork: - Function to translate legacy network IDs to CAIP-2

Returns:

The v2 supported kind

adaptPaymentHandlerV1ToV2

Adapt a v1 PaymentHandlerV1 to the PaymentHandler interface.

This allows existing v1 payment handlers to be used with v2 infrastructure. Requirements are converted from v2 to v1 before being passed to the handler, and the resulting execers are wrapped to convert requirements back to v2.

Accepts both spec-compliant handlers (with optional mimeType) and legacy handlers (with required mimeType) for backwards compatibility.

FunctionType
adaptPaymentHandlerV1ToV2(handler: PaymentHandlerV1 or PaymentHandlerV1Strict, translateNetwork: NetworkTranslator) => PaymentHandler

Parameters:

  • handler: - The v1 payment handler to adapt
  • translateNetwork: - Function to translate legacy network IDs to CAIP-2

adaptPaymentHandlerV2ToV1

Adapt a PaymentHandler to the v1 PaymentHandlerV1 interface.

This allows v2 payment handlers to be used with v1 infrastructure.

FunctionType
adaptPaymentHandlerV2ToV1(handler: PaymentHandler, translateNetwork: NetworkTranslator) => PaymentHandlerV1

Parameters:

  • handler: - The v2 payment handler to adapt
  • translateNetwork: - Function to translate legacy network IDs to CAIP-2

isAddress

Type guard that checks if a value is a valid EVM address.

FunctionType
isAddress(maybe: unknown) => maybe is 0x${string}``

Parameters:

  • maybe: - The value to check

Returns:

True if the value matches the EVM address format

isPrivateKey

Type guard that checks if a value is a valid EVM private key.

FunctionType
isPrivateKey(maybe: unknown) => maybe is 0x${string}``

Parameters:

  • maybe: - The value to check

Returns:

True if the value matches the private key format

matchPricingToCapabilities

Returns pricing entries whose network and asset match the given capabilities. Empty networks or assets arrays act as wildcards.

FunctionType
matchPricingToCapabilities(capabilities: HandlerCapabilities, pricing: ResourcePricing[]) => ResourcePricing[]

capabilitiesMatch

Returns true when the given network and asset match the capabilities. Empty networks or assets arrays act as wildcards.

FunctionType
capabilitiesMatch(capabilities: HandlerCapabilities, criteria: { network: string; asset: string; }) => boolean

narrowHandlers

Returns handlers whose capabilities match the given network and asset. Handlers without capabilities are excluded.

Empty networks or assets arrays act as wildcards (match everything). This supports the HTTP handler backward-compat path where the handler delegates all routing to the remote facilitator.

FunctionType
narrowHandlers(handlers: FacilitatorHandler[], criteria: { network: string; asset: string; }) => FacilitatorHandler[]

resolveX402Requirements

Converts {@link ResourcePricing} entries into enriched {@link x402PaymentRequirements} by routing through handlers.

For each handler with capabilities, matches pricing entries by network and asset, constructs skeletal x402 requirements using the handler's declared schemes, then calls handler.getRequirements() to enrich them with protocol-specific fields (extras, timeouts, etc.).

Handlers without capabilities are skipped. If a handler throws, the exception propagates to the caller.

FunctionType
resolveX402Requirements(handlers: FacilitatorHandler[], pricing: ResourcePricing[], resource: string, opts?: ResolveOpts or undefined) => Promise<{ scheme: string; ... 5 more ...; extra?: object or undefined; }[]>

settleX402Payment

Routes a settlement request to the appropriate handler.

Narrows handlers by capabilities (network + asset), then iterates handleSettle until one returns a non-null result. If a handler throws, the exception propagates immediately.

FunctionType
settleX402Payment(handlers: FacilitatorHandler[], requirements: { scheme: string; network: string; amount: string; asset: string; payTo: string; maxTimeoutSeconds: number; extra?: object or undefined; }, payment: { ...; }) => Promise<...>

verifyX402Payment

Routes a verification request to the appropriate handler.

Same pattern as {@link settleX402Payment} but calls handleVerify. Handlers without handleVerify are skipped.

FunctionType
verifyX402Payment(handlers: FacilitatorHandler[], requirements: { scheme: string; network: string; amount: string; asset: string; payTo: string; maxTimeoutSeconds: number; extra?: object or undefined; }, payment: { ...; }) => Promise<...>

isBaseAddress

Type guard that checks if a value is a valid Solana base58 address.

FunctionType
isBaseAddress(maybe: unknown) => maybe is string

Parameters:

  • maybe: - The value to check

Returns:

True if the value matches the base58 address format

isSolanaCluster

Type guard that checks if a value is a valid Solana cluster name.

FunctionType
isSolanaCluster(maybe: unknown) => maybe is "mainnet-beta" or "devnet" or "testnet"

Parameters:

  • maybe: - The value to check

Returns:

True if the value is a known cluster name

isSolanaCAIP2NetworkString

Type guard that checks if a value is a valid Solana CAIP-2 network string.

FunctionType
isSolanaCAIP2NetworkString(maybe: unknown) => maybe is string

Parameters:

  • maybe: - The value to check

Returns:

True if the value matches the Solana CAIP-2 format

isSolanaCAIP2Network

Type guard that checks if a value is a SolanaCAIP2Network object.

FunctionType
isSolanaCAIP2Network(maybe: unknown) => maybe is SolanaCAIP2Network

Parameters:

  • maybe: - The value to check

Returns:

True if the value is a SolanaCAIP2Network object

createSolanaNetwork

Creates a SolanaCAIP2Network object from a CAIP-2 string.

FunctionType
createSolanaNetwork(caip2: string, name?: string or undefined) => SolanaCAIP2Network

Parameters:

  • caip2: - The CAIP-2 network identifier string (e.g., "solana:5eykt...")
  • name: - Optional display name for the network

Returns:

A SolanaCAIP2Network object

Constants

X_PAYMENT_HEADER

HTTP header name for v1 client payment payloads.

ConstantType
X_PAYMENT_HEADER"X-PAYMENT"

X_PAYMENT_RESPONSE_HEADER

HTTP header name for v1 server payment responses.

ConstantType
X_PAYMENT_RESPONSE_HEADER"X-PAYMENT-RESPONSE"

x402PaymentId

ConstantType
x402PaymentIdType<{ scheme: string; network: string; asset: string; }, {}>

x402PaymentRequirements

ConstantType
x402PaymentRequirementsType<{ scheme: string; network: string; maxAmountRequired: string; resource: string; description: string; payTo: string; maxTimeoutSeconds: number; asset: string; mimeType?: string or undefined; outputSchema?: object or undefined; extra?: object or undefined; }, {}>

x402PaymentRequiredResponse

ConstantType
x402PaymentRequiredResponseType<{ x402Version: number; accepts: { scheme: string; network: string; maxAmountRequired: string; resource: string; description: string; payTo: string; maxTimeoutSeconds: number; asset: string; mimeType?: string or undefined; outputSchema?: object or undefined; extra?: object or undefined; }[]; error: string; }, {}>

x402PaymentRequiredResponseLenient

Lenient payment required response parser that accepts optional error field. Use this when parsing incoming data from older servers that may not include the error field.

ConstantType
x402PaymentRequiredResponseLenientType<{ x402Version: number; accepts: { scheme: string; network: string; maxAmountRequired: string; resource: string; description: string; payTo: string; maxTimeoutSeconds: number; asset: string; mimeType?: string or undefined; outputSchema?: object or undefined; extra?: object or undefined; }[]; error?: string or undefi...

x402PaymentPayload

ConstantType
x402PaymentPayloadType<{ x402Version: number; scheme: string; network: string; payload: object; asset?: string or undefined; }, {}>

x402PaymentHeaderToPayload

ConstantType
x402PaymentHeaderToPayloadType<(In: string) => To<{ x402Version: number; scheme: string; network: string; payload: object; asset?: string or undefined; }>, {}>

x402VerifyRequest

ConstantType
x402VerifyRequestType<{ paymentRequirements: { scheme: string; network: string; maxAmountRequired: string; resource: string; description: string; payTo: string; maxTimeoutSeconds: number; asset: string; mimeType?: string or undefined; outputSchema?: object or undefined; extra?: object or undefined; }; paymentHeader?: string or undefined...

x402VerifyResponse

ConstantType
x402VerifyResponseType<{ isValid: boolean; payer: string; invalidReason?: string or undefined; }, {}>

x402VerifyResponseLenient

Lenient verify response parser that accepts optional payer field. Use this when parsing incoming data from older facilitators that may not include the payer field.

ConstantType
x402VerifyResponseLenientType<{ isValid: boolean; invalidReason?: string or null or undefined; payer?: string or undefined; }, {}>

x402SettleRequest

ConstantType
x402SettleRequestType<{ paymentRequirements: { scheme: string; network: string; maxAmountRequired: string; resource: string; description: string; payTo: string; maxTimeoutSeconds: number; asset: string; mimeType?: string or undefined; outputSchema?: object or undefined; extra?: object or undefined; }; paymentHeader?: string or undefined...

x402SettleResponseLegacy

Legacy settle response type with pre-spec field names (txHash, networkId, error). Use x402SettleResponse for spec-compliant field names (transaction, network, errorReason).

This type exists for backward compatibility when interfacing with older clients that use legacy field names.

ConstantType
x402SettleResponseLegacyType<{ success: boolean; txHash: string or null; networkId: string or null; error?: string or null or undefined; payer?: string or undefined; }, {}>

x402SettleResponse

Spec-compliant settle response per x402-specification-v1.md Section 5.3. Field names: transaction, network, errorReason (not txHash, networkId, error)

ConstantType
x402SettleResponseType<{ success: boolean; transaction: string; network: string; payer: string; errorReason?: string or undefined; }, {}>

x402SettleResponseLenient

Lenient settle response parser that accepts either legacy or spec-compliant field names. Use this when parsing incoming data that may come from older clients using legacy field names.

ConstantType
x402SettleResponseLenientType<{ success: boolean; errorReason?: string or null or undefined; error?: string or null or undefined; transaction?: string or null or undefined; txHash?: string or null or undefined; network?: string or ... 1 more ... or undefined; networkId?: string or ... 1 more ... or undefined; payer?: string or undefined; }, {}>

x402SupportedKind

ConstantType
x402SupportedKindType<{ x402Version: number; scheme: string; network: string; extra?: object or undefined; }, {}>

x402SupportedResponse

ConstantType
x402SupportedResponseType<{ kinds: { x402Version: number; scheme: string; network: string; extra?: object or undefined; }[]; }, {}>

V2_PAYMENT_HEADER

HTTP header name for v2 client payment signatures.

ConstantType
V2_PAYMENT_HEADER"PAYMENT-SIGNATURE"

V2_PAYMENT_REQUIRED_HEADER

HTTP header name for v2 402 payment required responses.

ConstantType
V2_PAYMENT_REQUIRED_HEADER"PAYMENT-REQUIRED"

V2_PAYMENT_RESPONSE_HEADER

HTTP header name for v2 server payment responses.

ConstantType
V2_PAYMENT_RESPONSE_HEADER"PAYMENT-RESPONSE"

x402ResourceInfo

ConstantType
x402ResourceInfoType<{ url: string; description?: string or undefined; mimeType?: string or undefined; }, {}>

x402PaymentRequirements

ConstantType
x402PaymentRequirementsType<{ scheme: string; network: string; amount: string; asset: string; payTo: string; maxTimeoutSeconds: number; extra?: object or undefined; }, {}>

x402PaymentRequiredResponse

ConstantType
x402PaymentRequiredResponseType<{ x402Version: 2; resource: { url: string; description?: string or undefined; mimeType?: string or undefined; }; accepts: { scheme: string; network: string; amount: string; asset: string; payTo: string; maxTimeoutSeconds: number; extra?: object or undefined; }[]; error?: string or undefined; extensions?: object or u...

x402PaymentPayload

ConstantType
x402PaymentPayloadType<{ x402Version: 2; accepted: { scheme: string; network: string; amount: string; asset: string; payTo: string; maxTimeoutSeconds: number; extra?: object or undefined; }; payload: object; resource?: { ...; } or undefined; extensions?: object or undefined; }, {}>

x402PaymentHeaderToPayload

ConstantType
x402PaymentHeaderToPayloadType<(In: string) => To<{ x402Version: 2; accepted: { scheme: string; network: string; amount: string; asset: string; payTo: string; maxTimeoutSeconds: number; extra?: object or undefined; }; payload: object; resource?: { ...; } or undefined; extensions?: object or undefined; }>, {}>

x402VerifyRequest

ConstantType
x402VerifyRequestType<{ paymentPayload: { x402Version: 2; accepted: { scheme: string; network: string; amount: string; asset: string; payTo: string; maxTimeoutSeconds: number; extra?: object or undefined; }; payload: object; resource?: { ...; } or undefined; extensions?: object or undefined; }; paymentRequirements: { ...; }; }, {}>

x402VerifyResponse

ConstantType
x402VerifyResponseType<{ isValid: boolean; invalidReason?: string or undefined; payer?: string or undefined; }, {}>

x402SettleRequest

ConstantType
x402SettleRequestType<{ paymentPayload: { x402Version: 2; accepted: { scheme: string; network: string; amount: string; asset: string; payTo: string; maxTimeoutSeconds: number; extra?: object or undefined; }; payload: object; resource?: { ...; } or undefined; extensions?: object or undefined; }; paymentRequirements: { ...; }; }, {}>

x402SettleResponse

ConstantType
x402SettleResponseType<{ success: boolean; transaction: string; network: string; errorReason?: string or undefined; payer?: string or undefined; extensions?: object or undefined; }, {}>

x402SupportedKind

ConstantType
x402SupportedKindType<{ x402Version: 2; scheme: string; network: string; extra?: object or undefined; }, {}>

x402SupportedKindAny

ConstantType
x402SupportedKindAnyType<{ x402Version: 1 or 2; scheme: string; network: string; extra?: object or undefined; }, {}>

x402SupportedResponse

ConstantType
x402SupportedResponseType<{ kinds: { x402Version: 1 or 2; scheme: string; network: string; extra?: object or undefined; }[]; extensions: string[]; signers: Record<string, string[]>; }, {}>

Address

Validator for EVM hex addresses (40 hex characters, optional 0x prefix).

ConstantType
AddressType<0x${string}, {}>

PrivateKey

Validator for EVM private keys (64 hex characters with 0x prefix).

ConstantType
PrivateKeyType<0x${string}, {}>

Base58Address

Validator for Solana base58-encoded addresses.

ConstantType
Base58AddressType<string, {}>

SolanaCluster

Validator for Solana cluster names.

ConstantType
SolanaClusterType<"mainnet-beta" or "devnet" or "testnet", {}>

SolanaCAIP2NetworkString

Validator for Solana CAIP-2 network identifier strings.

Format: solana: where genesis-hash is base58-encoded.

ConstantType
SolanaCAIP2NetworkStringType<string, {}>

Interfaces

GetRequirementsArgs

Arguments passed to the facilitator's getRequirements method.

PropertyTypeDescription
accepts{ scheme: string; network: string; amount: string; asset: string; payTo: string; maxTimeoutSeconds: number; extra?: object or undefined; }[]Payment requirements the server is willing to accept
resource{ url: string; description?: string or undefined; mimeType?: string or undefined; } or undefinedOptional resource information for the protected content

FacilitatorHandler

Handler interface implemented by payment scheme facilitators.

Each method returns null when the request doesn't match the handler's payment scheme, allowing multiple handlers to be composed.

PropertyTypeDescription
capabilitiesHandlerCapabilities or undefinedDeclares what this handler can settle. Required for in-process usage.
schemesstring[] or undefinedx402 schemes this handler can settle. Required for in-process resolution; handlers without it are skipped by the middleware's dispatch path. Distinct from {@link getSupported}, which exists for the facilitator /supported HTTP route and may fan out to remote backends with per-kind timeouts.
getSupported(() => Promise<{ x402Version: 2; scheme: string; network: string; extra?: object or undefined; }>[]) or undefinedReturns the payment schemes this handler supports
getRequirements`(args: GetRequirementsArgs) => Promise<{ scheme: string; netwo

版本与发布记录

@faremeter/types 共发布 32 个版本,首次发布于 2025/07/16;过去 12 个月发布了 12 个版本。

版本发布日期距今
0.22.0latest2026/05/275 个月前
0.21.02026/04/216 个月前
0.20.12026/04/147 个月前
0.20.02026/04/147 个月前
0.19.02026/03/217 个月前
0.18.02026/03/207 个月前

关于 @faremeter/types 的常见问题

@faremeter/types 是什么?

TypeScript type definitions and runtime validation for x402 protocol and Faremeter ecosystem

如何安装 @faremeter/types?

在项目目录运行 npm install @faremeter/types,或使用 pnpm add / yarn add / bun add。

@faremeter/types 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@faremeter/types 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@faremeter/types 可以商用吗?

@faremeter/types 使用 LGPL-3.0-only 许可。弱 Copyleft:作为库被调用时通常不要求开源你自己的代码,但修改库本身需以 LGPL 开源;前端打包合并后的适用边界存在不同理解。以上为概括,不构成法律意见,请以许可原文为准。

@faremeter/types 的下载量有多少?

根据 npm 官方下载统计,@faremeter/types 在 2026/10/15 – 2026/11/13 这 30 天内被下载 4,988 次,日均约 166 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@faremeter/types 还在维护吗?

最新版本 0.22.0 发布于 2026/05/27(5 个月前);至今共发布 32 个版本,其中过去 12 个月发布了 12 个;首次发布于 2025/07/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。