Skip to content

Pay per call from a browser wallet - #8

Merged
lightchainaidev merged 1 commit into
mainfrom
browser-wallet
Oct 14, 2026
Merged

lightchainaidev merged 1 commit into
mainfrom
browser-wallet

Conversation

@lightchainaidev

Copy link
Copy Markdown
Contributor

Per-call payment used to take only a local account (a raw private key). It now also takes a browser wallet's JSON-RPC account, { address, type: 'json-rpc' }, with the wallet as transport (custom(window.ethereum)). A web page can then pay each call through the SDK, with the visitor's own wallet signing.

  • Signing goes through the client's wallet client. A local account still signs by itself, byte for byte as before. A JSON-RPC account asks its wallet for one eth_signTypedData_v4. No transaction, no gas.
  • Smart accounts stay out. The JobRegistry takes only an ECDSA signature by the payer's own key.
  • A rejected signature comes back as the 402, its error.message starting Not paid by the SDK: User rejected the request., followed by the wallet's own reason.
  • README: a "From a browser wallet" section:
    • how to set it up;
    • put the wallet on the network's chain first;
    • what a rejected signature returns;
    • the authorization's clock;
    • one address per client;
    • no smart accounts.

Tests

npm run typecheck, npm run build and npm test all pass (73 of 73).

  • A stand-in browser wallet signs all 9 vectors the SDK signs, and the payment must match each vector byte for byte. It must arrive as exactly one eth_signTypedData_v4 for the payer, with no transaction.
  • A wallet that rejects (code 4001, MetaMask's wording) gets the 402 back. The message carries both viem's prefix and the wallet's reason, and the request is not sent again.

Not covered: deposit() through a browser wallet, and a real wallet against the live API.

Per-call payment took only a local account, a raw key. It now also takes a
browser wallet's JSON-RPC account, { address, type: 'json-rpc' }, with the
wallet as transport (custom(window.ethereum)). The payment is signed through
the client's wallet client: a local account still signs by itself, byte for
byte as before, and a JSON-RPC account asks its wallet for one
eth_signTypedData_v4. Smart accounts stay out: the JobRegistry takes only an
ECDSA signature by the payer's key.

The per-call tests sign the scheme's vectors through a stand-in wallet too,
and pin what a rejected signature gives back: the 402, with the wallet's
reason. The README shows the browser use, and what the page has to do first:
put the wallet on the network's chain.
@lightchainaidev
lightchainaidev merged commit 7239e22 into main Oct 14, 2026
1 check passed
@lightchainaidev
lightchainaidev deleted the browser-wallet branch October 14, 2026 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant