Repository navigation
feat(core): mainnet plan rules, Horizon reads and a run ledger (nothing calls them yet) - #43
Merged
Merged
Conversation
…orizon The mainnet opt-in needs these rules in place before anything is signed, and they are small enough to read on their own. Nothing calls them yet: stellar:pubnet is still refused first, and the run budget still values no mainnet asset. MAINNET_USDC is Circle's USDC on Stellar mainnet as a Stellar Asset Contract. It was checked three ways on 2026-11-21: the issuer Circle's page lists, the contract the SDK derives from that issuer, and the x402 SDK's own constant. A test asserts all three. A mainnet environment must pin that asset and a payee other than the payer (a transfer to oneself would hide what left the account). An option to pay must be exact on stellar:pubnet, in that asset, valid for 1 to 300 seconds, and the token must report 7 decimals. The RPC's latest ledger must be within 12 ledgers of public Horizon's, so an RPC cannot stretch how long a signature stays valid, and the payer's USDC balance through the RPC must equal Horizon's, so an RPC cannot under-report it past the $10 rule. The Horizon reads accept only a 200 JSON answer from a Horizon that says it serves mainnet, follow no redirect, read at most 1 MiB, and name Horizon by its origin only.
…igns A mainnet run must leave a record a person can compare with the chain, also after a crash: no signature without an entry, and an entry before the signature. This adds that record to core, working on every network, as the x402 payment checks' `ledger` option. No CLI option writes one yet. preparePayment writes the intent of a signature (check, endpoint, amount, payee, asset) right after the run is charged and before the key can be asked to sign; a ledger that cannot take it stops the payment with nothing signed. Then it records what became of it: signed, with the ledger its authorization expires at, decoded from the preimage the key signed; not signed (the run stopped before the key was asked, or the signed-terms gate, the only way to the key, refused); or unknown (a client without a gate failed after it was asked). A signature the ledger cannot record is never sent. A payload discarded unsent is recorded as such. Each paid send records the answer's status, or that no answer came; X402-06 records the settlement after verifying it. An entry with no outcome reads as signed and sent. The file, wasit-ledger-<UTC time>.json, is created new and never overwritten, and every change rewrites it whole through a flushed temporary file and a rename, so it is valid JSON whenever the process stops. It names the payer by its public address and the RPC by its origin; free text is sanitised, 64-hex values in it are masked, and it is cut to one line. Closing it records the payer's balances before and after, and whether its USDC went down by exactly the verified settlements and its XLM did not move.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
Two parts of the mainnet opt-in that hold on their own and can be read before the allow path exists. This version still has no mainnet opt-in:
stellar:pubnetis refused before any of this is reached, and the run budget values no mainnet asset.What
The plan rules of a mainnet run (
guard/mainnet-plan.ts,guard/horizon.ts). Exported, called by nothing.MAINNET_USDC: Circle's USDC on Stellar mainnet as a Stellar Asset Contract,CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75. Checked three ways on 2026-11-21 (Circle's listed issuer, the contract the SDK derives from it,USDC_PUBNET_ADDRESSof@x402/stellar2.28.0); a test asserts all three.stellar:pubnet, in that asset, valid for 1 to 300 seconds; the token reports 7 decimals.The run ledger (
guard/run-ledger.ts, theledgeroption of the x402 payment checks). Works on every network; no CLI option writes one yet.preparePaymentwrites each signature's intent after the run is charged and before the key can be asked to sign. A ledger that cannot take it stops the payment with nothing signed.wasit-ledger-<UTC time>.jsonis created new, never overwritten, and rewritten whole through a flushed temporary file and a rename, so it stays valid JSON. Closing it records balances before and after and whether they moved as the ledger says.Tests
Written before the code and seen failing first.
mainnet-plan.test.ts(26),horizon.test.ts(9, a loopback stand-in),run-ledger.test.ts(23),run-ledger-wiring.test.ts(9, the recording chain and a gated variant on a test network).