Skip to content

feat(cli): serve the RFC 0006 payment surface from a development purse - #745

Draft
tommyldev wants to merge 1 commit into
mainfrom
feat/cli-dev-payment-purse
Draft

feat(cli): serve the RFC 0006 payment surface from a development purse#745
tommyldev wants to merge 1 commit into
mainfrom
feat/cli-dev-payment-purse

Conversation

@tommyldev

@tommyldev tommyldev commented Sep 12, 2026

Copy link
Copy Markdown

Summary

truapi-host dev now serves the RFC 0006 payment surface from a local development purse: payment.subscribeBalance and payment.topUp work against a JSON-backed balance instead of failing with PermissionDenied / Unknown("Payments are not supported in dot.li"). To get there, truapi-platform gains a PaymentPurse trait that any host can install on the signing-host runtime, and the CLI installs a dev implementation of it.

Before this, a product could only exercise its balance or top-up flow on the iOS/Android hosts.

What changes

  • truapi-platform: new PaymentPurse trait with subscribe_balance(purse) -> BoxStream<Balance> (current value first, then every change) and top_up(purse, amount, source). It is not a Platform supertrait. Like PermissionStatusHost, it is installed set-once on the runtime, so existing platform implementations do not change.
  • truapi-server: RuntimeServices holds the installed purse, set through SigningHostRuntime::set_payment_purse. Payment::balance_subscribe and top_up route to it when present. Without a purse the responses are identical to before; wire_result_shape passes unchanged, so desktop and web behaviour does not move. request and status_subscribe stay unimplemented.
  • truapi-host-cli: dev_purse.rs keeps per-purse balances in <session>/dev-purse.json. A tokio::sync::watch fan-out gives every subscriber the current balance, then deduplicated changes. top_up credits from a ProductAccount source and rejects PrivateKey and Coins with InvalidSource rather than pretending to spend a pasted secret. Balance disclosure needs no prompt because the CLI already auto-approves every confirmation.
  • truapi-codegen: golden host-callbacks.ts gains the additive PaymentPurse interface.

Scope

A top-up credits the purse and moves nothing on chain; the log line says so. The purse is a plain number for exercising product flows on testnets. A wallet-backed host would implement the same trait against real funds.

Verified

  • cargo fmt --check, cargo clippy --all-targets on the three crates: clean.
  • cargo test -p truapi-host-cli dev_purse (2), -p truapi-server --test wire_result_shape (13, unchanged), -p truapi-codegen (goldens), -p truapi-platform: pass.
  • End to end against the Humanity product under truapi-host dev --network previewnet: payment.subscribeBalance pushes 0, payment.topUp(1_250_000, ProductAccount{Index(1)}) returns ok, the subscription pushes 1250000, and dev-purse.json persists it across a restart.

Open questions for review

  • Should the CLI gate the dev purse behind a flag (e.g. --dev-purse) rather than installing it unconditionally in dev?
  • Should PaymentPurse also cover request / status_subscribe now, or wait for a real backend?

The headless host answered every payment.* call with PermissionDenied or
"Payments are not supported", so a product could not exercise its balance
or top-up flow outside the phone hosts. A host can now install a
PaymentPurse on the signing-host runtime; the CLI installs a development
purse persisted in the session directory that discloses balances without
a prompt and credits top-ups from a product account without moving funds.
Hosts without a purse answer exactly as before.
@github-actions

Copy link
Copy Markdown

CI Status: not green, 1 item needs attention.

  • rust: failure
All job results
job result
android-bindings success
changes success
codegen success
e2e skipped
explorer success
ios-bindings success
ios-swift success
licenses success
playground success
rust failure
ts-client success
ts-debugger success
ts-host success
wasm-provider success

Commit 5709b249 · run log

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