Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<BOLT11>` (served over NFC by Numo point-of-sale terminals, and planned by Square, which serves `lightning:<BOLT11>` 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.
Expand Down
46 changes: 44 additions & 2 deletions bindings/ios/bitkitcore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12145,17 +12145,27 @@ 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
self.deliveredSat = deliveredSat
self.destinationAddress = destinationAddress
self.htlcAddress = htlcAddress
self.timeoutBlockHeight = timeoutBlockHeight
self.providerTakesWake = providerTakesWake
}
}

Expand Down Expand Up @@ -12187,6 +12197,9 @@ extension PubkySwapRoutePayment: Equatable, Hashable {
if lhs.timeoutBlockHeight != rhs.timeoutBlockHeight {
return false
}
if lhs.providerTakesWake != rhs.providerTakesWake {
return false
}
return true
}

Expand All @@ -12198,6 +12211,7 @@ extension PubkySwapRoutePayment: Equatable, Hashable {
hasher.combine(destinationAddress)
hasher.combine(htlcAddress)
hasher.combine(timeoutBlockHeight)
hasher.combine(providerTakesWake)
}
}

Expand All @@ -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)
)
}

Expand All @@ -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)
}
}

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
}
Expand Down
11 changes: 11 additions & 0 deletions bindings/ios/bitkitcoreFFI.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
) -> Result<bool, PubkySwapError> {
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
Expand Down
14 changes: 14 additions & 0 deletions src/modules/pubky_swaps/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading