Skip to content

feat: let reverse swaps wake the wallet when they can be claimed #200

Open

Description

@coreyphillips

Motivation

A reverse swap can be claimed only once its lockup has its confirmations, and the wallet has to be running to claim it. coreyphillips/pubky-swap#117 added the provider side: when the lockup reaches depth, the provider wakes the owner's device once, through a wake grant the owner sent for that swap. The peer topic is swap.claimable (synonymdev/wake#1). The owner side is not in bitkit-core, so no swap this wallet starts can use it.

Current behavior (verified on master at cd8af15)

  • quote_edge in src/modules/pubky_swaps/client.rs sends every QuoteRequest with features: vec![]. A provider accepts a capability only for a swap quoted with claimable-hint-v1, so none of this wallet's swaps qualify.
  • Nothing sends SwapMessage::SwapWakeCapability. The pinned swap-common (f45e204) already includes pubky-swap#117: the message, WakeCapability, CLAIMABLE_HINT_FEATURE, SWAP_WAKE_FEATURE and SWAP_WAKE_TOPIC.
  • pubky_swaps_commit_route returns after SwapAccept, which is when the capability has to be sent. Its result does not say whether the provider advertises swap-wake-v1.
  • The wake module can already create and revoke the grant (wake_create_grant, wake_revoke_grant).

Requested change

  • List claimable-hint-v1 in a reverse QuoteRequest.features when the provider's offer advertises it. Leave the request unchanged for providers that do not.
  • Tell the app, in the commit result or the swap record, whether the provider advertises swap-wake-v1, so it creates a grant only when the provider can use it.
  • Add a call that sends SwapWakeCapability for one of the wallet's open reverse swaps, after SwapAccept: { v: 1, gateway, topics: ["swap.claimable"], token, expires_at }, with the token and expiry from the app's grant. The provider answers with the swap's snapshot. It refuses a second, different capability for the same swap and accepts an identical resend.
  • Keep the token out of the swap record, logs and errors, including the error for a provider's Reject. The provider keeps it in memory only.

The grant stays in the app: it calls wake_create_grant for its pk: identity and swap.claimable, with an expiry that covers the claim window, and revokes the grant when the swap ends. Grants are capped at 30 created per hour per device and 200 live per identity. A claimable flag from the provider is a hint only. pubky_swaps_advance still checks the lockup on the wallet's own chain view before it claims.

Out of scope

Acceptance criteria

  • A reverse quote from a provider advertising claimable-hint-v1 lists it in features. A quote from any other provider is unchanged.
  • The app can tell from the commit whether the provider takes a wake capability.
  • Sending a capability for an open swap returns the provider's snapshot. Sending a different one for the same swap returns an error.
  • No error, log line or stored record contains the token.
  • Unit tests cover the feature list and the capability message.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions