Interface: SchemeAdapter<TSpec, TRequirements, TPayload>
Defined in: packages/x402-express/src/scheme.ts:116
Everything about a payment scheme the middleware cannot know.
TSpec is the merchant-facing spec, TRequirements and TPayload the concrete wire shapes this scheme accepts. The middleware stays generic over all three and narrows through acceptsRequirements and acceptsPayload, which are the only things that have checked a header someone else sent.
Type Parameters
TSpec
TSpec extends BaseRequirementsSpec
TRequirements
TRequirements extends X402PaymentRequirements<unknown>
TPayload
TPayload extends X402PaymentPayload<unknown>
Properties
extraRules
readonly extraRules: RuleTable;Defined in: packages/x402-express/src/scheme.ts:156
How each field of the scheme's extra is held against the merchant's. Key it off the scheme's own schema so the table cannot drift from the shape it describes.
id
readonly id: string;Defined in: packages/x402-express/src/scheme.ts:122
Scheme id, e.g. exact. Used as the default for spec.scheme.
unreadablePayerReason?
unreadablePayerReason?: string;Defined in: packages/x402-express/src/scheme.ts:150
The error code to refuse with when neither the facilitator nor SchemeAdapter.payerOf can name the payer. The scheme's, because the spec's codes are per-scheme: canton-exact answers invalid_exact_canton_malformed_payload, and another scheme has its own. Defaults to the x402 v2 general invalid_payload.
Methods
acceptsPayload()
acceptsPayload(payload): payload is TPayload;Defined in: packages/x402-express/src/scheme.ts:128
Does this payload conform to the scheme?
Parameters
payload
X402PaymentPayload<unknown>
Returns
payload is TPayload
acceptsRequirements()
acceptsRequirements(requirements): requirements is TRequirements;Defined in: packages/x402-express/src/scheme.ts:124
Does this echoed requirement conform to the scheme?
Parameters
requirements
X402PaymentRequirements<unknown>
Returns
requirements is TRequirements
checkBuilt()?
checkBuilt?(requirements, ctx): Promise<void>;Defined in: packages/x402-express/src/scheme.ts:167
Check a requirement a builder returned, before it is advertised. A builder writes the whole requirement, so it can state values that are the facilitator's to state; throw a TermsError (exported from this package) for one that disagrees with the facilitator, so it is refused before a payer signs against it. Optional: a scheme with nothing the facilitator owns needs none.
Parameters
requirements
TRequirements
ctx
Returns
Promise<void>
distinctKey()?
distinctKey?(spec): string | undefined;Defined in: packages/x402-express/src/scheme.ts:142
What makes this entry a distinct way to pay, for the check that a route offers no two of the same. undefined when the spec cannot say without a request — a resolver-valued field — and the entry is then not checked.
Parameters
spec
TSpec
Returns
string | undefined
payerOf()
payerOf(payload): string | undefined;Defined in: packages/x402-express/src/scheme.ts:136
Who paid, read from the payload itself — for when the facilitator does not say. payer is optional in a verify response, and the x402 v2 payload names no payer, so whoever it is has to be recovered from what the payer signed. Only the scheme knows how: canton-exact decodes the prepared transaction and takes its sender. undefined when it cannot be read.
Parameters
payload
TPayload
Returns
string | undefined
quote()
quote(
req,
spec,
ctx
): Promise<SchemeQuote>;Defined in: packages/x402-express/src/scheme.ts:158
Build the scheme's part of a quote from the merchant's spec.
Parameters
req
Request
spec
TSpec
ctx
Returns
Promise<SchemeQuote>