fix: hold the no-wallet guard at the signing choke point - #19
Merged
Conversation
hasWallet() was introduced in #9 to stop a keyless client reaching the signer, then applied to exactly one of six 402 entry points. doRequestHeaders, handleStreamPaymentAndRetry, image.go, video.go and rpc.go all called the signer directly. On Base that means CreatePaymentPayload dereferences a nil *ecdsa.PrivateKey at x402.go's crypto.PubkeyToAddress and panics the caller's goroutine instead of returning the PaymentError the GET path returns. Removing the new guard reproduces it: panic: runtime error: invalid memory address or nil pointer dereference Latent, not live: the exported constructors always set a key, so the invariant held by accident. Moving it to signPayment — which every payment path funnels through — makes it hold by construction, and one line covers all six entry points. The doGetWithPayment call-site check stays. Bailing there skips parsing the 402 body, so a keyless client gets "no wallet is configured" rather than whatever parse error a malformed 402 produces first. signPayment holds the invariant; the call site holds the message. Closes #15.
VickyXAI
pushed a commit
that referenced
this pull request
Aug 4, 2026
Ships the no-wallet guard hoist from #19 (closes #15). Also on main since 0.19.4, neither shipping library code: #20 corrects the README FAQ that told Solana users the Go SDK was Base-only, and #21 adds the release gate that flagged this very commit as missing. First release caught by that gate rather than by a human noticing the tag had fallen behind.
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.
Closes #15.
What
#9 introduced
hasWallet()to stop a keyless client reaching the signer, then applied it to exactly one of six 402 entry points.doRequestHeaders,handleStreamPaymentAndRetry,image.go,video.goandrpc.goall call the signer directly.On Base that means
CreatePaymentPayloaddereferences a nil*ecdsa.PrivateKeyatcrypto.PubkeyToAddress(privateKey.PublicKey)and panics the caller's goroutine instead of returning thePaymentErrorthe GET path returns.This is not theoretical. Removing the guard added here reproduces it:
Severity
Latent, not live. The exported constructors always set a key —
newBaseClienterrors without one,newSolanaBaseClienterrors without one — so the invariant currently holds by accident. Moving it tosignPayment, which every payment path funnels through, makes it hold by construction. One line covers all six entry points instead of one.Why the call-site check stays
doGetWithPaymentkeeps its own check. Bailing there skips parsing the 402 body, so a keyless client getsno wallet is configuredrather than whatever parse error a malformed 402 produces first. Deliberate, and commented as such:signPaymentholds the invariant, the call site holds the message.Testing
TestSignPaymentRejectsKeylessClient— both chains, asserts a*PaymentErrorwith the right message and an empty payload. A panic fails the test outright, so it pins "returns an error" and "does not panic" together.TestCreatePaymentPayloadRejectsKeylessClient— the exported wrapper inherits the guard.Full suite green with
-race -count=2 -shuffle=on, no network.go vetclean.VERSION/CHANGELOG untouched — left for the release.