feat(client): add spending policy for x402 payments#40
Open
Bortlesboat wants to merge 1 commit intomicrochipgnu:mainfrom
Open
feat(client): add spending policy for x402 payments#40Bortlesboat wants to merge 1 commit intomicrochipgnu:mainfrom
Bortlesboat wants to merge 1 commit intomicrochipgnu:mainfrom
Conversation
Adds a SpendingTracker that evaluates configurable spending rules before signing any x402 payment. Supports rolling hourly/daily budgets, per-transaction and per-tool caps, rate limiting, and recipient allow/block lists. Fully opt-in — no policy configured means existing behavior is unchanged. Also exposes --max-per-hour, --max-per-day, --max-tx-per-hour CLI flags for the connect command. Closes microchipgnu#31
|
@Bortlesboat is attempting to deploy a commit to the Inventions Hub Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds client-side spending controls that sit between x402 402-negotiation and payment signing. Addresses #31.
What it does
SpendingTrackerevaluates configurable rules before any payment is signed:maxPerHour/maxPerDay(atomic units, in-memory window)maxTransactionsPerHourmaxPerTransaction(works alongside existingmaxPaymentValue)toolLimitsmap for different spending ceilings per tool nameallowedRecipients/blockedRecipientsaddress listsThe tracker records successful payments and prunes entries older than 24h.
SDK usage
CLI usage
Also reads
X402_MAX_PER_HOUR,X402_MAX_PER_DAY,X402_MAX_TX_PER_HOURenv vars.Design decisions
policyconfig means zero behavioral change.isError: truewith a descriptive message, same pattern as the existingmaxPaymentValuecheck.Type-checks clean against the existing codebase.