From f791c0339ac0e71289f89e2d75d3150d7186d91b Mon Sep 17 00:00:00 2001 From: coreyphillips Date: Fri, 20 Nov 2026 16:01:49 -0500 Subject: [PATCH 1/2] feat: let reverse swaps wake the wallet when they can be claimed --- CHANGELOG.md | 1 + src/lib.rs | 32 ++++ src/modules/pubky_swaps/README.md | 14 ++ src/modules/pubky_swaps/client.rs | 249 +++++++++++++++++++++++++++++- src/modules/pubky_swaps/errors.rs | 33 ++++ src/modules/pubky_swaps/mod.rs | 5 +- src/modules/pubky_swaps/store.rs | 4 + src/modules/pubky_swaps/types.rs | 3 + 8 files changed, 337 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0793371f..e83875f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- Pubky Swaps: a reverse quote asks for the claimable hint from a provider that sends it. `PubkySwapRoutePayment` gains `provider_takes_wake`, and `pubky_swaps_send_wake_capability` hands the provider a `swap.claimable` wake grant, so it wakes the device when the swap can be claimed. - Remove the `pubky` module (breaking). Pubky auth goes through Paykit grant links. Removed exports: the legacy Pubky Ring auth `parse_pubky_auth_url` and `approve_pubky_auth`, plus the unused `resolve_pubky_url`, `fetch_pubky_file`, `fetch_pubky_file_string`, `start_pubky_auth`, `cancel_pubky_auth`, `complete_pubky_auth`, `fetch_pubky_profile`, `fetch_pubky_contacts`, `derive_pubky_secret_key`, `pubky_public_key_from_secret`, `pubky_sign_up`, `pubky_sign_in`, `pubky_session_put`, `pubky_session_delete`, `pubky_session_list` and `pubky_put_with_secret_key`. Removed types: the `PubkyProfile` and `PubkyProfileLink` records, `PubkyAuthDetails`, `PubkyAuthKind` and `PubkyError` (`PubkyException` on Android). Drop the `pubky-app-specs` dependency. Pubky Swaps reads a provider's published signing key records as before. - Decode BIP 321 `bitcoin:` URIs without an address. `bitcoin:?lightning=` (served over NFC by Numo point-of-sale terminals, and planned by Square, which serves `lightning:` today) returns `Scanner::Lightning`, and a segwit address in the `bc`, `tb` or `bcrt` parameter returns `Scanner::OnChain` with that address, keeping other instructions such as `lightning` in `params`. An address in the wrong parameter (`bc=tb1…`) returns `InvalidAddress`. `lno`, `sp` or `pay` alone returns `UnsupportedType`, and no payment instruction returns `InvalidAddress` as before. Any `req-` parameter, `req-pop` included, now returns `InvalidFormat`, because Bitkit handles none of them and BIP 321 forbids paying such a URI (breaking for callers that paid `req-pop` URIs). - Update `lightning` to 0.2.8. diff --git a/src/lib.rs b/src/lib.rs index 6b7187bb..c216c52d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3652,6 +3652,38 @@ pub async fn pubky_swaps_advance( .unwrap_or_else(|e| Err(pubky_swaps_runtime_err(e))) } +/// Hand a committed swap's provider a wake grant, so it wakes this device once the swap can be +/// claimed. Only for a swap whose commit reported `provider_takes_wake`. Create the grant with +/// `wake_create_grant` on `swap.claimable`, expiring after the claim window, and revoke it when +/// the swap ends. Sending the same grant again is accepted; a different one for the same swap is +/// refused. Returns whether the provider already sees the swap as claimable: then no wake comes, +/// so advance it now. That is a hint only: `pubky_swaps_advance` checks the lockup itself. The +/// token never appears in the swap record, logs or errors. +#[uniffi::export] +pub async fn pubky_swaps_send_wake_capability( + swap_id: String, + gateway_url: String, + token: String, + expires_at: u64, + mnemonic: String, + bip39_passphrase: Option, +) -> Result { + let rt = ensure_runtime(); + rt.spawn(async move { + pubky_swaps::send_wake_capability( + swap_id, + gateway_url, + token, + expires_at, + mnemonic, + bip39_passphrase, + ) + .await + }) + .await + .unwrap_or_else(|e| Err(pubky_swaps_runtime_err(e))) +} + /// Rebuild the swaps this wallet started, for a wallet restored from its seed. Each of /// `providers` that supports it lists the swaps it holds for the wallet's swap identity, and the /// wallet derives their keys from the seed and checks them against each contract. A swap gets a diff --git a/src/modules/pubky_swaps/README.md b/src/modules/pubky_swaps/README.md index 33bdb475..dcaae665 100644 --- a/src/modules/pubky_swaps/README.md +++ b/src/modules/pubky_swaps/README.md @@ -102,6 +102,20 @@ broadcast again, and a spend without the preimage in its witness (the provider's lockup that never came before the timeout ends in `Failed`. The claim's fee is fixed when the route is quoted and is never bumped, so swap routes are refused on mainnet. +## Wakes + +The claim needs the wallet running once the lockup has its confirmations. A reverse quote asks for +`claimable-hint-v1` when the provider's offer lists it, and `pubky_swaps_commit_route` reports +`provider_takes_wake` when the offer also lists `swap-wake-v1`. The app then creates a wake grant +for `swap.claimable` (`wake_create_grant`) and hands it over with +`pubky_swaps_send_wake_capability`. The provider wakes the device once, through the gateway, when +the lockup reaches depth. The app revokes the grant when the swap ends. + +The provider answers with the swap's snapshot, and the call returns its `claimable` flag: a swap +already claimable gets no wake, so the app advances it now. The flag is a hint only; +`pubky_swaps_advance` checks the lockup on the wallet's own chain view. The grant token is a bearer +secret, so it stays out of the swap record, logs and errors, including a provider's refusal. + ## What it does not do yet - **Discovery:** candidates come from the caller, usually the user's contacts. Each is asked for diff --git a/src/modules/pubky_swaps/client.rs b/src/modules/pubky_swaps/client.rs index 1ae502d5..9f889083 100644 --- a/src/modules/pubky_swaps/client.rs +++ b/src/modules/pubky_swaps/client.rs @@ -15,8 +15,9 @@ use once_cell::sync::Lazy; use swap_common::htlc::build_htlc_script; use swap_common::messages::{ OfferRequest, Quote, QuoteRequest, Reject, SwapAccept, SwapListRequest, SwapMessage, SwapOffer, - SwapRequest, SwapScript, SwapStatusRequest, SwapStatusSnapshot, PAYKIT_CAP_FEATURE, - PROTOCOL_VERSION, SWAP_LIST_FEATURE, + SwapRequest, SwapScript, SwapStatusRequest, SwapStatusSnapshot, SwapWakeCapability, + WakeCapability, CLAIMABLE_HINT_FEATURE, PAYKIT_CAP_FEATURE, PROTOCOL_VERSION, + SWAP_LIST_FEATURE, SWAP_WAKE_FEATURE, SWAP_WAKE_TOPIC, WAKE_TOKEN_MAX_LEN, }; use swap_common::onchain::{build_claim_tx, estimate_spend_fee, spend_vsize}; use swap_common::paykit_cap::{CapMessage, ContractReply, SignedQuote}; @@ -52,6 +53,8 @@ const PENDING_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(60); const PENDING_POLL: std::time::Duration = std::time::Duration::from_secs(2); /// Most pages read from one provider's swap list on restore. const MAX_LIST_PAGES: usize = 100; +/// The `WakeCapability` version providers take. +const WAKE_CAPABILITY_VERSION: u16 = 1; /// Quotes the router fetched, kept until the wallet commits to one of them. static QUOTES: Lazy>> = Lazy::new(Default::default); @@ -67,6 +70,7 @@ struct CachedQuote { signed: SignedQuote, /// The delegated key the quote was signed by, if not the provider's own. delegated_signer: Option, + takes_wake: bool, } /// A quote whose signature checked out, with what committing to it needs. @@ -75,6 +79,8 @@ struct SignedRoute { request: QuoteRequest, signed: SignedQuote, delegated_signer: Option, + /// Whether the provider takes a wake capability for the swap this quote starts. + takes_wake: bool, } fn now_unix() -> u64 { @@ -166,7 +172,7 @@ async fn quote_edge( direction: SwapDirection::Reverse, amount_sat: lock_sat, protocol_version: PROTOCOL_VERSION, - features: vec![], + features: quote_features(offer), }; let mut session = CapSession::new(client, identity, &offer.provider_pkarr)?; let (reply, signed) = session @@ -184,9 +190,28 @@ async fn quote_edge( request, signed, delegated_signer: session.delegated_signer(), + takes_wake: takes_wake(offer), }) } +fn offers(offer: &SwapOffer, feature: &str) -> bool { + offer.features.iter().any(|f| f == feature) +} + +/// What a reverse quote request asks for: the claimable hint, from a provider that sends it. +fn quote_features(offer: &SwapOffer) -> Vec { + if offers(offer, CLAIMABLE_HINT_FEATURE) { + vec![CLAIMABLE_HINT_FEATURE.to_string()] + } else { + vec![] + } +} + +/// Whether the provider takes a wake capability for a swap quoted with the claimable hint. +fn takes_wake(offer: &SwapOffer) -> bool { + offers(offer, SWAP_WAKE_FEATURE) && offers(offer, CLAIMABLE_HINT_FEATURE) +} + /// Whether an offer takes signed negotiation over `direct/1`. Others are skipped: their quotes /// and contracts would be unsigned. fn negotiates_signed(offer: &SwapOffer) -> bool { @@ -374,6 +399,7 @@ async fn best_swap_route( request: signed.request, signed: signed.signed, delegated_signer: signed.delegated_signer, + takes_wake: signed.takes_wake, }, ); Ok(Some(route)) @@ -484,6 +510,7 @@ pub async fn commit_route( request: quote_request, signed, delegated_signer, + takes_wake, } = cached; if network == bitcoin::Network::Bitcoin { return Err(PubkySwapError::invalid( @@ -583,6 +610,7 @@ pub async fn commit_route( claim_seen: false, claim_listed: false, contract: Some(contract), + takes_wake, created_at_unix: now_unix(), }; store::create(&record)?; @@ -596,9 +624,94 @@ pub async fn commit_route( destination_address: route.endpoint.value, htlc_address, timeout_block_height: accept.timeout_block_height, + provider_takes_wake: takes_wake, }) } +/// The `SwapWakeCapability` for `swap_id`, refused here when the provider would refuse it. Its +/// errors never contain the token. +fn wake_capability( + swap_id: Uuid, + gateway_url: String, + token: String, + expires_at: u64, + now: u64, +) -> Result { + if gateway_url.trim().is_empty() { + return Err(PubkySwapError::invalid("the gateway url is empty")); + } + if !token.starts_with("wkg_") + || token.len() > WAKE_TOKEN_MAX_LEN + || !token + .bytes() + .all(|b| b.is_ascii_alphanumeric() || b == b'_' || b == b'-') + { + return Err(PubkySwapError::invalid("not a wake grant token")); + } + if expires_at <= now { + return Err(PubkySwapError::invalid("the wake grant has expired")); + } + Ok(SwapMessage::SwapWakeCapability(SwapWakeCapability { + request_id: Some(Uuid::new_v4()), + swap_id, + capability: WakeCapability { + v: WAKE_CAPABILITY_VERSION, + gateway: gateway_url, + topics: vec![SWAP_WAKE_TOPIC.to_string()], + token, + expires_at, + }, + })) +} + +/// Hand the provider of one of this wallet's swaps a wake grant, so it wakes the wallet through +/// the gateway when the lockup can be claimed. Returns whether the provider already sees the swap +/// as claimable: then no wake comes. The token is kept out of the record, logs and errors. +pub async fn send_wake_capability( + swap_id: String, + gateway_url: String, + token: String, + expires_at: u64, + mnemonic: String, + bip39_passphrase: Option, +) -> Result { + let record = store::load(&swap_id)?; + // A provider without `swap-wake-v1` cannot parse the message and never answers. + if !record.takes_wake { + return Err(PubkySwapError::invalid( + "this swap's provider does not take a wake capability", + )); + } + let swap_id = record.accept.swap_id; + let sent = async { + let message = wake_capability(swap_id, gateway_url, token.clone(), expires_at, now_unix())?; + let secret = keys::identity_secret(&mnemonic, bip39_passphrase.as_deref())?; + let client = DirectClient::bind(secret).await?; + let reply = client.request(&record.provider_pubky, &message).await; + client.close().await; + snapshot_claimable(reply?, swap_id) + }; + sent.await.map_err(|e| e.redact(&token)) +} + +/// The provider's answer to a wake capability: the swap's snapshot, whose `claimable` is a hint +/// only. `advance` still checks the lockup on the wallet's own chain view. +fn snapshot_claimable(reply: SwapMessage, swap_id: Uuid) -> Result { + match reply { + SwapMessage::SwapStatusSnapshot(snapshot) if snapshot.accept.swap_id == swap_id => { + Ok(snapshot.claimable) + } + SwapMessage::SwapStatusSnapshot(_) => Err(PubkySwapError::validation( + "the provider answered with another swap's status", + )), + SwapMessage::Reject(reject) => Err(refused(reject)), + // Not `unexpected`: a reply's contents could echo the token. + _ => Err(PubkySwapError::transport( + "expected the swap's status for its wake capability", + )), + } +} + fn status_of(record: &SwapRecord, state: PubkySwapRouteState) -> PubkySwapRouteStatus { PubkySwapRouteStatus { swap_id: record.swap_id.clone(), @@ -1147,6 +1260,8 @@ fn restored_record( // nothing, and a claim past the window would hand it the preimage and its refund. claim_listed: snapshot.claim_observed_txid_hex.is_some() && payment.settled, contract: None, + // The listing does not say whether the swap was quoted with the claimable hint. + takes_wake: false, created_at_unix: snapshot.created_at_unix, }) } @@ -1474,6 +1589,134 @@ mod tests { }; assert_eq!(reason, "No swap provider is set up."); } + + fn offer_with(features: &[&str]) -> SwapOffer { + SwapOffer { + request_id: None, + offer_id: Uuid::nil(), + provider_pkarr: "provider".into(), + network: swap_common::NetworkSpec::Regtest, + directions: vec![SwapDirection::Reverse], + min_amount_sat: 10_000, + max_amount_sat: 1_000_000, + base_fee_sat: 100, + fee_ppm: 2_500, + required_confirmations: 1, + htlc_timeout_blocks: 144, + lightning_node_id: None, + valid_until_unix: 0, + fund_within_secs: 60, + onchain_fee_sat: 500, + fee_rate_sat_vb: 2, + protocol_version: PROTOCOL_VERSION, + features: features.iter().map(|f| f.to_string()).collect(), + } + } + + #[test] + fn asks_for_the_claimable_hint_only_from_a_provider_that_sends_it() { + let signed = [PAYKIT_CAP_FEATURE, DIRECT_RPC_FEATURE]; + assert!(quote_features(&offer_with(&signed)).is_empty()); + let hinting = offer_with(&[ + PAYKIT_CAP_FEATURE, + DIRECT_RPC_FEATURE, + CLAIMABLE_HINT_FEATURE, + ]); + assert_eq!(quote_features(&hinting), [CLAIMABLE_HINT_FEATURE]); + } + + #[test] + fn takes_a_wake_only_from_a_provider_that_sends_the_hint_and_wakes() { + assert!(!takes_wake(&offer_with(&[]))); + assert!(!takes_wake(&offer_with(&[CLAIMABLE_HINT_FEATURE]))); + assert!(!takes_wake(&offer_with(&[SWAP_WAKE_FEATURE]))); + assert!(takes_wake(&offer_with(&[ + CLAIMABLE_HINT_FEATURE, + SWAP_WAKE_FEATURE + ]))); + } + + const TOKEN: &str = + "wkg_0123456789abcdef0123456789abcdef_abcdefghijklmnopqrstuvwxyz0123456789-_ABCDEFG"; + const GATEWAY: &str = "https://wake.bitkit.to"; + + #[test] + fn builds_the_wake_capability_providers_take() { + let swap_id = Uuid::new_v4(); + let message = wake_capability(swap_id, GATEWAY.into(), TOKEN.into(), 2_000, 1_000).unwrap(); + let wire = serde_json::to_value(&message).unwrap(); + assert_eq!(wire["type"], "SwapWakeCapability"); + assert_eq!(wire["swap_id"], swap_id.to_string()); + assert_eq!( + wire["capability"], + serde_json::json!({ + "v": 1, + "gateway": GATEWAY, + "topics": ["swap.claimable"], + "token": TOKEN, + "expires_at": 2_000, + }) + ); + assert!(!format!("{message:?}").contains(TOKEN)); + } + + #[test] + fn refuses_a_wake_capability_without_naming_its_token() { + let long = format!("wkg_{}", "a".repeat(WAKE_TOKEN_MAX_LEN)); + let refused = [ + (GATEWAY, "wks_not_a_grant", 2_000), + (GATEWAY, long.as_str(), 2_000), + (GATEWAY, "wkg_has space", 2_000), + (GATEWAY, TOKEN, 1_000), + (" ", TOKEN, 2_000), + ]; + for (gateway, token, expires_at) in refused { + let error = + wake_capability(Uuid::nil(), gateway.into(), token.into(), expires_at, 1_000) + .unwrap_err(); + assert!(matches!(error, PubkySwapError::InvalidInput { .. })); + assert!(!error.to_string().contains(token), "{error}"); + } + } + + #[test] + fn reads_the_providers_answer_without_naming_the_token() { + let snapshot = listed_swap(SEED, None); + let swap_id = snapshot.accept.swap_id; + let mut claimable = snapshot.clone(); + claimable.claimable = true; + let answer = |reply| snapshot_claimable(reply, swap_id).map_err(|e| e.redact(TOKEN)); + + assert!(!answer(SwapMessage::SwapStatusSnapshot(snapshot.clone())).unwrap()); + assert!(answer(SwapMessage::SwapStatusSnapshot(claimable)).unwrap()); + assert!(matches!( + snapshot_claimable(SwapMessage::SwapStatusSnapshot(snapshot), Uuid::nil()), + Err(PubkySwapError::Validation { .. }) + )); + let refusal = Reject { + code: Some("invalid_request".into()), + request_id: None, + swap_id: Some(swap_id), + quote_id: None, + reason: format!("grant {TOKEN} is not on the allowlist"), + }; + let error = answer(SwapMessage::Reject(refusal)).unwrap_err(); + assert!(matches!(error, PubkySwapError::Refused { .. })); + assert!(!error.to_string().contains(TOKEN), "{error}"); + } + + #[test] + fn a_record_saved_before_wakes_takes_none() { + let record = restore(&listed_swap( + SEED, + Some(keys::owner_ref(&keys::new_index())), + )) + .expect("restored"); + let mut saved = serde_json::to_value(&record).unwrap(); + saved.as_object_mut().unwrap().remove("takes_wake"); + let loaded: SwapRecord = serde_json::from_value(saved).unwrap(); + assert!(!loaded.takes_wake); + } } #[cfg(test)] diff --git a/src/modules/pubky_swaps/errors.rs b/src/modules/pubky_swaps/errors.rs index 3657d5f6..fe2b1bc5 100644 --- a/src/modules/pubky_swaps/errors.rs +++ b/src/modules/pubky_swaps/errors.rs @@ -57,6 +57,39 @@ impl PubkySwapError { error_details: details.to_string(), } } + + /// This error with every copy of `secret` replaced, so a bearer token never reaches the app + /// or a log, even when a provider echoes it. + pub(crate) fn redact(self, secret: &str) -> Self { + if secret.is_empty() { + return self; + } + let hide = |text: String| text.replace(secret, ""); + match self { + Self::InvalidInput { error_details } => Self::InvalidInput { + error_details: hide(error_details), + }, + Self::Transport { error_details } => Self::Transport { + error_details: hide(error_details), + }, + Self::Refused { code, reason } => Self::Refused { + code: hide(code), + reason: hide(reason), + }, + Self::Validation { error_details } => Self::Validation { + error_details: hide(error_details), + }, + Self::Chain { error_details } => Self::Chain { + error_details: hide(error_details), + }, + Self::Storage { error_details } => Self::Storage { + error_details: hide(error_details), + }, + Self::NotFound { error_details } => Self::NotFound { + error_details: hide(error_details), + }, + } + } } impl From for PubkySwapError { diff --git a/src/modules/pubky_swaps/mod.rs b/src/modules/pubky_swaps/mod.rs index a5d8ea6e..43c363d6 100644 --- a/src/modules/pubky_swaps/mod.rs +++ b/src/modules/pubky_swaps/mod.rs @@ -14,7 +14,10 @@ mod store; mod transport; mod types; -pub use client::{advance_swap, commit_route, provider_edges, restore_swaps, route_paykit_payment}; +pub use client::{ + advance_swap, commit_route, provider_edges, restore_swaps, route_paykit_payment, + send_wake_capability, +}; pub use errors::PubkySwapError; pub(crate) use store::init; pub use types::*; diff --git a/src/modules/pubky_swaps/store.rs b/src/modules/pubky_swaps/store.rs index 16726d32..818a22b9 100644 --- a/src/modules/pubky_swaps/store.rs +++ b/src/modules/pubky_swaps/store.rs @@ -55,6 +55,10 @@ pub(crate) struct SwapRecord { /// from a provider's listing. #[serde(default)] pub contract: Option, + /// Whether the provider takes a wake capability for this swap: it advertised `swap-wake-v1` + /// and the swap was quoted with the claimable hint. False for a swap rebuilt from a listing. + #[serde(default)] + pub takes_wake: bool, pub created_at_unix: u64, } diff --git a/src/modules/pubky_swaps/types.rs b/src/modules/pubky_swaps/types.rs index 81f78bef..170fd9ef 100644 --- a/src/modules/pubky_swaps/types.rs +++ b/src/modules/pubky_swaps/types.rs @@ -63,6 +63,9 @@ pub struct PubkySwapRoutePayment { pub destination_address: String, pub htlc_address: String, pub timeout_block_height: u32, + /// Whether the provider can wake this device once the swap can be claimed. Only then create a + /// `swap.claimable` grant and hand it over with `pubky_swaps_send_wake_capability`. + pub provider_takes_wake: bool, } #[derive(Debug, Clone, PartialEq, Eq, uniffi::Enum)] From d459380d73951b3caa84d631b01fc9497143f09c Mon Sep 17 00:00:00 2001 From: coreyphillips Date: Fri, 20 Nov 2026 16:29:03 -0500 Subject: [PATCH 2/2] chore: regenerate the iOS bindings --- bindings/ios/bitkitcore.swift | 46 +++++++++++++++++++++++++++++++++-- bindings/ios/bitkitcoreFFI.h | 11 +++++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/bindings/ios/bitkitcore.swift b/bindings/ios/bitkitcore.swift index 5eac138e..4715b683 100644 --- a/bindings/ios/bitkitcore.swift +++ b/bindings/ios/bitkitcore.swift @@ -12145,10 +12145,19 @@ public struct PubkySwapRoutePayment { public var destinationAddress: String public var htlcAddress: String public var timeoutBlockHeight: UInt32 + /** + * Whether the provider can wake this device once the swap can be claimed. Only then create a + * `swap.claimable` grant and hand it over with `pubky_swaps_send_wake_capability`. + */ + public var providerTakesWake: Bool // Default memberwise initializers are never public by default, so we // declare one manually. - public init(swapId: String, invoice: String, debitSat: UInt64, deliveredSat: UInt64, destinationAddress: String, htlcAddress: String, timeoutBlockHeight: UInt32) { + public init(swapId: String, invoice: String, debitSat: UInt64, deliveredSat: UInt64, destinationAddress: String, htlcAddress: String, timeoutBlockHeight: UInt32, + /** + * Whether the provider can wake this device once the swap can be claimed. Only then create a + * `swap.claimable` grant and hand it over with `pubky_swaps_send_wake_capability`. + */providerTakesWake: Bool) { self.swapId = swapId self.invoice = invoice self.debitSat = debitSat @@ -12156,6 +12165,7 @@ public struct PubkySwapRoutePayment { self.destinationAddress = destinationAddress self.htlcAddress = htlcAddress self.timeoutBlockHeight = timeoutBlockHeight + self.providerTakesWake = providerTakesWake } } @@ -12187,6 +12197,9 @@ extension PubkySwapRoutePayment: Equatable, Hashable { if lhs.timeoutBlockHeight != rhs.timeoutBlockHeight { return false } + if lhs.providerTakesWake != rhs.providerTakesWake { + return false + } return true } @@ -12198,6 +12211,7 @@ extension PubkySwapRoutePayment: Equatable, Hashable { hasher.combine(destinationAddress) hasher.combine(htlcAddress) hasher.combine(timeoutBlockHeight) + hasher.combine(providerTakesWake) } } @@ -12218,7 +12232,8 @@ public struct FfiConverterTypePubkySwapRoutePayment: FfiConverterRustBuffer { deliveredSat: FfiConverterUInt64.read(from: &buf), destinationAddress: FfiConverterString.read(from: &buf), htlcAddress: FfiConverterString.read(from: &buf), - timeoutBlockHeight: FfiConverterUInt32.read(from: &buf) + timeoutBlockHeight: FfiConverterUInt32.read(from: &buf), + providerTakesWake: FfiConverterBool.read(from: &buf) ) } @@ -12230,6 +12245,7 @@ public struct FfiConverterTypePubkySwapRoutePayment: FfiConverterRustBuffer { FfiConverterString.write(value.destinationAddress, into: &buf) FfiConverterString.write(value.htlcAddress, into: &buf) FfiConverterUInt32.write(value.timeoutBlockHeight, into: &buf) + FfiConverterBool.write(value.providerTakesWake, into: &buf) } } @@ -33817,6 +33833,29 @@ public func pubkySwapsRoutePaykitPayment(request: PaykitRouteRequest, network: N errorHandler: FfiConverterTypePubkySwapError_lift ) } +/** + * Hand a committed swap's provider a wake grant, so it wakes this device once the swap can be + * claimed. Only for a swap whose commit reported `provider_takes_wake`. Create the grant with + * `wake_create_grant` on `swap.claimable`, expiring after the claim window, and revoke it when + * the swap ends. Sending the same grant again is accepted; a different one for the same swap is + * refused. Returns whether the provider already sees the swap as claimable: then no wake comes, + * so advance it now. That is a hint only: `pubky_swaps_advance` checks the lockup itself. The + * token never appears in the swap record, logs or errors. + */ +public func pubkySwapsSendWakeCapability(swapId: String, gatewayUrl: String, token: String, expiresAt: UInt64, mnemonic: String, bip39Passphrase: String?)async throws -> Bool { + return + try await uniffiRustCallAsync( + rustFutureFunc: { + uniffi_bitkitcore_fn_func_pubky_swaps_send_wake_capability(FfiConverterString.lower(swapId),FfiConverterString.lower(gatewayUrl),FfiConverterString.lower(token),FfiConverterUInt64.lower(expiresAt),FfiConverterString.lower(mnemonic),FfiConverterOptionString.lower(bip39Passphrase) + ) + }, + pollFunc: ffi_bitkitcore_rust_future_poll_i8, + completeFunc: ffi_bitkitcore_rust_future_complete_i8, + freeFunc: ffi_bitkitcore_rust_future_free_i8, + liftFunc: FfiConverterBool.lift, + errorHandler: FfiConverterTypePubkySwapError_lift + ) +} /** * Persist a successful outgoing RBF result, including its replacement fee rate, in one transaction. * Call after the node has returned the replacement txid; this function does not broadcast anything. @@ -35422,6 +35461,9 @@ private let initializationResult: InitializationResult = { if (uniffi_bitkitcore_checksum_func_pubky_swaps_route_paykit_payment() != 45030) { return InitializationResult.apiChecksumMismatch } + if (uniffi_bitkitcore_checksum_func_pubky_swaps_send_wake_capability() != 19534) { + return InitializationResult.apiChecksumMismatch + } if (uniffi_bitkitcore_checksum_func_record_rbf_boost() != 15433) { return InitializationResult.apiChecksumMismatch } diff --git a/bindings/ios/bitkitcoreFFI.h b/bindings/ios/bitkitcoreFFI.h index 960f035d..59073cc6 100644 --- a/bindings/ios/bitkitcoreFFI.h +++ b/bindings/ios/bitkitcoreFFI.h @@ -1519,6 +1519,11 @@ uint64_t uniffi_bitkitcore_fn_func_pubky_swaps_restore(RustBuffer providers, Rus uint64_t uniffi_bitkitcore_fn_func_pubky_swaps_route_paykit_payment(RustBuffer request, RustBuffer network, RustBuffer mnemonic, RustBuffer bip39_passphrase ); #endif +#ifndef UNIFFI_FFIDEF_UNIFFI_BITKITCORE_FN_FUNC_PUBKY_SWAPS_SEND_WAKE_CAPABILITY +#define UNIFFI_FFIDEF_UNIFFI_BITKITCORE_FN_FUNC_PUBKY_SWAPS_SEND_WAKE_CAPABILITY +uint64_t uniffi_bitkitcore_fn_func_pubky_swaps_send_wake_capability(RustBuffer swap_id, RustBuffer gateway_url, RustBuffer token, uint64_t expires_at, RustBuffer mnemonic, RustBuffer bip39_passphrase +); +#endif #ifndef UNIFFI_FFIDEF_UNIFFI_BITKITCORE_FN_FUNC_RECORD_RBF_BOOST #define UNIFFI_FFIDEF_UNIFFI_BITKITCORE_FN_FUNC_RECORD_RBF_BOOST void uniffi_bitkitcore_fn_func_record_rbf_boost(RustBuffer wallet_id, RustBuffer original_activity_id, RustBuffer replacement_tx_id, uint64_t fee_rate, RustCallStatus *_Nonnull out_status @@ -3053,6 +3058,12 @@ uint16_t uniffi_bitkitcore_checksum_func_pubky_swaps_restore(void #define UNIFFI_FFIDEF_UNIFFI_BITKITCORE_CHECKSUM_FUNC_PUBKY_SWAPS_ROUTE_PAYKIT_PAYMENT uint16_t uniffi_bitkitcore_checksum_func_pubky_swaps_route_paykit_payment(void +); +#endif +#ifndef UNIFFI_FFIDEF_UNIFFI_BITKITCORE_CHECKSUM_FUNC_PUBKY_SWAPS_SEND_WAKE_CAPABILITY +#define UNIFFI_FFIDEF_UNIFFI_BITKITCORE_CHECKSUM_FUNC_PUBKY_SWAPS_SEND_WAKE_CAPABILITY +uint16_t uniffi_bitkitcore_checksum_func_pubky_swaps_send_wake_capability(void + ); #endif #ifndef UNIFFI_FFIDEF_UNIFFI_BITKITCORE_CHECKSUM_FUNC_RECORD_RBF_BOOST