From 13b83dabb33c7d7e284edb12b393351206296fc6 Mon Sep 17 00:00:00 2001 From: Quantum Explorer Date: Fri, 13 Nov 2026 06:27:41 +0700 Subject: [PATCH] feat(platform-wallet)!: a private contact request derives the sender's per-contact shielded address A private DashPay contact request took the shielded address it carries from the host app, so giving each contact a different address depended on every host. The wallet now derives it as it does for a contact request document: `send_reserved_private_contact_request` calls `IdentityWallet::contact_shielded_address` with the request's sender, recipient and account reference, and holds the identity placement lock from the derivation until the request is signed. The `shielded_address` parameter is removed from `send_private_contact_request`, `accept_private_contact_request` and `accept_contact_request_replying_in_kind` in the wallet, from the three `platform_wallet_manager_*` C functions, from the JNI bridge, and from the Swift and Kotlin SDK methods. The address a contact gave us, read from a received request, is unchanged at every layer. The private contact request tests that need a request carrying a known address give it through a test-only hook on `contact_shielded_address`; `shielded/contact_address_tests.rs` covers what that function derives. Co-Authored-By: Claude Fable 5.2 --- .../dashfoundation/dashsdk/FfiSmokeTest.kt | 15 +- .../dashsdk/ffi/DashpayNative.kt | 16 +- .../dashsdk/wallet/PlatformWalletManager.kt | 25 ++-- .../src/private_contact_request.rs | 109 +++++--------- .../network/contact_shielded_address.rs | 36 +++++ .../network/private_contact_requests.rs | 137 ++++-------------- .../src/wallet/platform_wallet.rs | 43 ++---- packages/rs-unified-sdk-jni/src/dashpay.rs | 76 ++-------- .../PrivateContactRequests.swift | 115 ++++++--------- 9 files changed, 201 insertions(+), 371 deletions(-) diff --git a/packages/kotlin-sdk/sdk/src/androidTest/kotlin/org/dashfoundation/dashsdk/FfiSmokeTest.kt b/packages/kotlin-sdk/sdk/src/androidTest/kotlin/org/dashfoundation/dashsdk/FfiSmokeTest.kt index 419de77c636..438d059342f 100644 --- a/packages/kotlin-sdk/sdk/src/androidTest/kotlin/org/dashfoundation/dashsdk/FfiSmokeTest.kt +++ b/packages/kotlin-sdk/sdk/src/androidTest/kotlin/org/dashfoundation/dashsdk/FfiSmokeTest.kt @@ -93,11 +93,10 @@ class FfiSmokeTest { * DashPay private contact requests (protocol version 15): the * `DashpayNative` symbols bind with the descriptors Kotlin declares, and * bad input surfaces as a mapped [DashSDKException] rather than a crash. - * A null resolver is refused before any wallet lookup, and a shielded - * address that is not 43 bytes never reaches the FFI (which reads - * exactly 43). The explicit private send and private-reply accept are - * exported only by a shielded build, so they are probed only there; the - * sync, the reads and the in-kind accept are exported by every build. + * A null resolver is refused before any wallet lookup. The explicit + * private send and private-reply accept are exported only by a shielded + * build, so they are probed only there; the sync, the reads and the + * in-kind accept are exported by every build. * The flows themselves need a protocol version 15 network with shielded * funds; their Rust side is covered by the platform-wallet and * platform-wallet-ffi tests. @@ -112,12 +111,12 @@ class FfiSmokeTest { assertThrows(DashSDKException::class.java) { DashpayNative.sendPrivateContactRequest( 0L, ByteArray(32), 0L, 0, ByteArray(32), ByteArray(32), - null, null, null, 0L, + null, null, 0L, ) } assertThrows(DashSDKException::class.java) { DashpayNative.acceptPrivateContactRequest( - 0L, ByteArray(32), 0L, 0, 0L, ByteArray(42), 0L, + 0L, ByteArray(32), 0L, 0, 0L, 0L, ) } } @@ -127,7 +126,7 @@ class FfiSmokeTest { } assertThrows(DashSDKException::class.java) { DashpayNative.acceptContactRequestReplyingInKind( - 0L, ByteArray(32), 0L, 0, 0L, ByteArray(42), 0L, + 0L, ByteArray(32), 0L, 0, 0L, 0L, ) } // The private contact read is benign on a miss (null, as Swift's diff --git a/packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/ffi/DashpayNative.kt b/packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/ffi/DashpayNative.kt index 3d55a791b26..e0cdc41f8dd 100644 --- a/packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/ffi/DashpayNative.kt +++ b/packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/ffi/DashpayNative.kt @@ -296,9 +296,10 @@ internal object DashpayNative { * Send a DashPay private contact request, paid from [account]'s * shielded notes on [walletId]. [resolverHandle] supplies the Orchard * spend authority and the DashPay keys; [signerHandle] is the identity - * signer [TokensNative.sendContactRequest] takes. [shieldedAddress] - * must be 43 raw Orchard bytes when set. Needs the `shielded` native - * feature. Returns the created `ContactRequest` handle (destroy via + * signer [TokensNative.sendContactRequest] takes. The wallet derives + * the Orchard address the request carries, one for this contact alone. + * Needs the `shielded` native feature. Returns the created + * `ContactRequest` handle (destroy via * [TokensNative.contactRequestDestroy]). * ← Swift `PlatformWalletManager.sendPrivateContactRequest`. */ @@ -312,15 +313,16 @@ internal object DashpayNative { recipientIdentityId: ByteArray, accountLabel: String?, autoAcceptProof: ByteArray?, - shieldedAddress: ByteArray?, signerHandle: Long, ): Long /** * Accept the incoming contact request [requestHandle] with a private * reply, paid from [account]'s shielded notes. Handles as for - * [sendPrivateContactRequest]. Returns the `EstablishedContact` handle - * (destroy via [TokensNative.establishedContactDestroy]). + * [sendPrivateContactRequest], and the wallet derives the Orchard + * address the reply carries the same way. Returns the + * `EstablishedContact` handle (destroy via + * [TokensNative.establishedContactDestroy]). * ← Swift `PlatformWalletManager.acceptPrivateContactRequest`. */ @Suppress("LongParameterList") @@ -330,7 +332,6 @@ internal object DashpayNative { resolverHandle: Long, account: Int, requestHandle: Long, - shieldedAddress: ByteArray?, signerHandle: Long, ): Long @@ -407,7 +408,6 @@ internal object DashpayNative { resolverHandle: Long, account: Int, requestHandle: Long, - shieldedAddress: ByteArray?, signerHandle: Long, ): Long } diff --git a/packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/wallet/PlatformWalletManager.kt b/packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/wallet/PlatformWalletManager.kt index 4119242ce73..99416f98e5a 100644 --- a/packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/wallet/PlatformWalletManager.kt +++ b/packages/kotlin-sdk/sdk/src/main/kotlin/org/dashfoundation/dashsdk/wallet/PlatformWalletManager.kt @@ -2178,9 +2178,10 @@ class PlatformWalletManager( * The request is signed by this manager's identity signer * ([signerHandle], the handle the public `Dashpay.sendContactRequest` * is given) and sealed with DashPay keys derived through this manager's - * resolver, which also supplies the Orchard spend authority. - * [shieldedAddress] is the 43-byte raw Orchard address the contact may - * pay us at privately. Blocks for the Halo 2 proof. + * resolver, which also supplies the Orchard spend authority. The + * request carries an Orchard address the contact may pay us at + * privately, which the wallet derives for this contact alone. Blocks + * for the Halo 2 proof. * * Before anything is paid the wallet reads DashPay's private store for * the sender to its end. Throws @@ -2204,7 +2205,6 @@ class PlatformWalletManager( recipientIdentityId: ByteArray, accountLabel: String? = null, autoAcceptProof: ByteArray? = null, - shieldedAddress: ByteArray? = null, account: Int = 0, ): ContactRequestRef = teardownGate.op { require(account >= 0) { "account must be non-negative, got $account" } @@ -2218,7 +2218,6 @@ class PlatformWalletManager( recipientIdentityId, accountLabel, autoAcceptProof, - shieldedAddress, signerHandle, ) } @@ -2235,16 +2234,15 @@ class PlatformWalletManager( * A host accepts with [acceptContactRequestReplyingInKind], which * picks this reply itself; this explicit accept stays for a host that * wants a private reply. The reply is signed by this manager's identity - * signer ([signerHandle]). - * [shieldedAddress] is the 43-byte raw Orchard address the contact may - * pay us at privately. Blocks for the Halo 2 proof. + * signer ([signerHandle]). It carries an Orchard address the contact + * may pay us at privately, which the wallet derives for this contact + * alone. Blocks for the Halo 2 proof. * * @return the established contact; close it (or `use {}`) when done. */ suspend fun acceptPrivateContactRequest( walletId: ByteArray, request: ContactRequestRef, - shieldedAddress: ByteArray? = null, account: Int = 0, ): EstablishedContactRef = teardownGate.op { require(account >= 0) { "account must be non-negative, got $account" } @@ -2255,7 +2253,6 @@ class PlatformWalletManager( mnemonicResolver.nativeHandle, account, request.value, - shieldedAddress, signerHandle, ) } @@ -2274,9 +2271,9 @@ class PlatformWalletManager( * [request] is the incoming request (`Dashpay.incomingContactRequest`). * The reply is signed by this manager's identity signer ([signerHandle]); * the Orchard spend authority comes from this manager's resolver and is - * derived only for a private reply. [shieldedAddress] is the 43-byte raw - * Orchard address the contact may pay us at privately; a public reply - * ignores it. + * derived only for a private reply. A private reply carries an Orchard + * address the contact may pay us at privately, which the wallet derives + * for this contact alone. * * A public or adopted reply needs neither shielded support nor a * mnemonic read for the payment. Throws @@ -2296,7 +2293,6 @@ class PlatformWalletManager( suspend fun acceptContactRequestReplyingInKind( walletId: ByteArray, request: ContactRequestRef, - shieldedAddress: ByteArray? = null, account: Int = 0, ): EstablishedContactRef = teardownGate.op { require(account >= 0) { "account must be non-negative, got $account" } @@ -2307,7 +2303,6 @@ class PlatformWalletManager( mnemonicResolver.nativeHandle, account, request.value, - shieldedAddress, signerHandle, ) } diff --git a/packages/rs-platform-wallet-ffi/src/private_contact_request.rs b/packages/rs-platform-wallet-ffi/src/private_contact_request.rs index 4df1f3cda35..5c216a8bf6b 100644 --- a/packages/rs-platform-wallet-ffi/src/private_contact_request.rs +++ b/packages/rs-platform-wallet-ffi/src/private_contact_request.rs @@ -457,26 +457,13 @@ pub unsafe extern "C" fn platform_wallet_get_private_payments_restore_failure( PlatformWalletFFIResult::ok() } -/// Copy an optional Orchard address: null means none. -/// -/// # Safety -/// A non-null `ptr` must point to [`SHIELDED_ADDRESS_LEN`] readable bytes. -unsafe fn read_shielded_address(ptr: *const u8) -> Option<[u8; SHIELDED_ADDRESS_LEN]> { - if ptr.is_null() { - return None; - } - let mut address = [0u8; SHIELDED_ADDRESS_LEN]; - std::ptr::copy_nonoverlapping(ptr, address.as_mut_ptr(), SHIELDED_ADDRESS_LEN); - Some(address) -} - /// Send a DashPay private contact request from `sender_identity_id` to /// `recipient_identity_id`, paying for it from `account`'s shielded notes, so /// nothing on chain names either identity. The request carries our receiving /// xpub for the contact, the masked account reference, `account_label`, -/// `auto_accept_proof`, and `shielded_address`, the Orchard address the -/// contact may pay us at privately. It is sealed to the recipient's DashPay -/// key inside the resolver-backed signer. +/// `auto_accept_proof`, and an Orchard address the contact may pay us at +/// privately, which the wallet derives for this contact alone. It is sealed +/// to the recipient's DashPay key inside the resolver-backed signer. /// /// `mnemonic_resolver_handle` supplies both the transient Orchard spend /// authority and the DashPay keys. `signer_handle` is the identity signer @@ -497,8 +484,6 @@ unsafe fn read_shielded_address(ptr: *const u8) -> Option<[u8; SHIELDED_ADDRESS_ /// string. /// - `auto_accept_proof`, when non-null, must point to /// `auto_accept_proof_len` readable bytes; `(null, 0)` omits it. -/// - `shielded_address`, when non-null, must point to 43 readable bytes; -/// null omits it. /// - `signer_handle` must be a valid, non-destroyed `*mut SignerHandle` /// produced by `dash_sdk_signer_create_with_ctx`; the caller retains /// ownership and pins it for the call. @@ -516,7 +501,6 @@ pub unsafe extern "C" fn platform_wallet_manager_send_private_contact_request( account_label: *const c_char, auto_accept_proof: *const u8, auto_accept_proof_len: usize, - shielded_address: *const u8, signer_handle: *mut SignerHandle, out_request_handle: *mut Handle, ) -> PlatformWalletFFIResult { @@ -534,7 +518,6 @@ pub unsafe extern "C" fn platform_wallet_manager_send_private_contact_request( account_label, auto_accept_proof, auto_accept_proof_len, - shielded_address, signer_handle, out_request_handle, ) @@ -558,7 +541,6 @@ unsafe fn send_private_contact_request_inner( account_label: *const c_char, auto_accept_proof: *const u8, auto_accept_proof_len: usize, - shielded_address: *const u8, signer_handle: *mut SignerHandle, out_request_handle: *mut Handle, ) -> PlatformWalletFFIResult { @@ -581,7 +563,6 @@ unsafe fn send_private_contact_request_inner( Ok(proof) => proof, Err(result) => return result, }; - let shielded_address = read_shielded_address(shielded_address); let (wallet, coordinator) = match resolve_wallet_and_coordinator(handle, &wallet_id) { Ok(pair) => pair, @@ -616,7 +597,6 @@ unsafe fn send_private_contact_request_inner( &recipient, label, AutoAcceptProofSource::from_option(proof), - shielded_address, signer, &crypto, &prover, @@ -637,9 +617,9 @@ unsafe fn send_private_contact_request_inner( /// Accept a DashPay contact request that came privately, replying privately /// and paying for the reply from `account`'s shielded notes, as -/// [`platform_wallet_manager_send_private_contact_request`] pays. -/// `shielded_address` is the Orchard address the contact may pay us at -/// privately; null omits it. +/// [`platform_wallet_manager_send_private_contact_request`] pays. The reply +/// carries an Orchard address the contact may pay us at privately, which the +/// wallet derives for this contact alone. /// /// `request_handle` is a live `CONTACT_REQUEST_STORAGE` handle of the /// incoming request. `signer_handle` is the identity signer the public accept @@ -651,7 +631,6 @@ unsafe fn send_private_contact_request_inner( /// - `wallet_id_bytes` must point to 32 readable bytes. /// - `mnemonic_resolver_handle` must be a valid, non-destroyed handle; the /// caller retains ownership and pins it for the call. -/// - `shielded_address`, when non-null, must point to 43 readable bytes. /// - `signer_handle` must be a valid, non-destroyed `*mut SignerHandle` /// produced by `dash_sdk_signer_create_with_ctx`; the caller retains /// ownership and pins it for the call. @@ -665,7 +644,6 @@ pub unsafe extern "C" fn platform_wallet_manager_accept_private_contact_request( mnemonic_resolver_handle: *mut MnemonicResolverHandle, account: u32, request_handle: Handle, - shielded_address: *const u8, signer_handle: *mut SignerHandle, out_established_handle: *mut Handle, ) -> PlatformWalletFFIResult { @@ -677,7 +655,6 @@ pub unsafe extern "C" fn platform_wallet_manager_accept_private_contact_request( mnemonic_resolver_handle, account, request_handle, - shielded_address, signer_handle, out_established_handle, ) @@ -697,7 +674,6 @@ unsafe fn accept_private_contact_request_inner( mnemonic_resolver_handle: *mut MnemonicResolverHandle, account: u32, request_handle: Handle, - shielded_address: *const u8, signer_handle: *mut SignerHandle, out_established_handle: *mut Handle, ) -> PlatformWalletFFIResult { @@ -711,7 +687,6 @@ unsafe fn accept_private_contact_request_inner( std::ptr::copy_nonoverlapping(wallet_id_bytes, wallet_id.as_mut_ptr(), 32); let request = CONTACT_REQUEST_STORAGE.with_item(request_handle, |request| request.clone()); let request = unwrap_option_or_return!(request); - let shielded_address = read_shielded_address(shielded_address); let (wallet, coordinator) = match resolve_wallet_and_coordinator(handle, &wallet_id) { Ok(pair) => pair, @@ -738,7 +713,6 @@ unsafe fn accept_private_contact_request_inner( seed.as_ref(), account, &request, - shielded_address, signer, &crypto, &prover, @@ -762,9 +736,9 @@ unsafe fn accept_private_contact_request_inner( /// `account`'s shielded notes, when it came privately and no reply exists /// yet; otherwise with a `contactRequest` document signed by `signer_handle`, /// or by adopting the reply already sent. Which reply a request takes is the -/// wallet's decision: this is the one accept a host calls. `shielded_address` -/// is the Orchard address the contact may pay us at privately; null omits it, -/// and a public reply ignores it. Exported in every build. +/// wallet's decision: this is the one accept a host calls. A private reply +/// carries an Orchard address the contact may pay us at privately, which the +/// wallet derives for this contact alone. Exported in every build. /// /// Only a private reply needs shielded support and the spend authority: the /// shielded coordinator is looked up, and the mnemonic read through @@ -786,7 +760,6 @@ unsafe fn accept_private_contact_request_inner( /// - `wallet_id_bytes` must point to 32 readable bytes. /// - `mnemonic_resolver_handle` must be a valid, non-destroyed handle; the /// caller retains ownership and pins it for the call. -/// - `shielded_address`, when non-null, must point to 43 readable bytes. /// - `signer_handle` must be a valid, non-destroyed `*mut SignerHandle` /// produced by `dash_sdk_signer_create_with_ctx`; the caller retains /// ownership and pins it for the call. @@ -799,7 +772,6 @@ pub unsafe extern "C" fn platform_wallet_manager_accept_contact_request_replying mnemonic_resolver_handle: *mut MnemonicResolverHandle, account: u32, request_handle: Handle, - shielded_address: *const u8, signer_handle: *mut SignerHandle, out_established_handle: *mut Handle, ) -> PlatformWalletFFIResult { @@ -810,7 +782,6 @@ pub unsafe extern "C" fn platform_wallet_manager_accept_contact_request_replying mnemonic_resolver_handle, account, request_handle, - shielded_address, signer_handle, out_established_handle, ) @@ -913,7 +884,6 @@ unsafe fn accept_contact_request_replying_in_kind_inner( mnemonic_resolver_handle: *mut MnemonicResolverHandle, account: u32, request_handle: Handle, - shielded_address: *const u8, signer_handle: *mut SignerHandle, out_established_handle: *mut Handle, ) -> PlatformWalletFFIResult { @@ -927,7 +897,6 @@ unsafe fn accept_contact_request_replying_in_kind_inner( std::ptr::copy_nonoverlapping(wallet_id_bytes, wallet_id.as_mut_ptr(), 32); let request = CONTACT_REQUEST_STORAGE.with_item(request_handle, |request| request.clone()); let request = unwrap_option_or_return!(request); - let shielded_address = read_shielded_address(shielded_address); let wallet = match resolve_manager_wallet(handle, &wallet_id) { Ok(wallet) => wallet, @@ -956,36 +925,30 @@ unsafe fn accept_contact_request_replying_in_kind_inner( let signer: &VTableSigner = &*(signer_addr as *const VTableSigner); let prover = CachedOrchardProver::new(); let result = wallet - .accept_contact_request_replying_in_kind( - &request, - shielded_address, - signer, - &crypto, - || async { - asked.store(true, Ordering::SeqCst); - let parts = tokio::task::spawn_blocking(move || { - // SAFETY: the caller pins the resolver for the call, - // and this export blocks until the task completes. - unsafe { private_reply_payment_parts(handle, wallet_id, resolver_addr) } - }) - .await - .unwrap_or_else(|_| { - Err(( - PlatformWalletFFIResultCode::ErrorUnknown, - "the private reply's payment lookup panicked".to_string(), - )) - }); - match parts { - Ok((coordinator, seed)) => Ok(PrivateReplyPayment { - coordinator, - seed, - account, - prover: &prover, - }), - Err(failure) => Err(record_payment_failure(&failure_slot, failure)), - } - }, - ) + .accept_contact_request_replying_in_kind(&request, signer, &crypto, || async { + asked.store(true, Ordering::SeqCst); + let parts = tokio::task::spawn_blocking(move || { + // SAFETY: the caller pins the resolver for the call, + // and this export blocks until the task completes. + unsafe { private_reply_payment_parts(handle, wallet_id, resolver_addr) } + }) + .await + .unwrap_or_else(|_| { + Err(( + PlatformWalletFFIResultCode::ErrorUnknown, + "the private reply's payment lookup panicked".to_string(), + )) + }); + match parts { + Ok((coordinator, seed)) => Ok(PrivateReplyPayment { + coordinator, + seed, + account, + prover: &prover, + }), + Err(failure) => Err(record_payment_failure(&failure_slot, failure)), + } + }) .await; poke_sync_on_unconfirmed(&result, handle); result @@ -1004,7 +967,6 @@ unsafe fn accept_contact_request_replying_in_kind_inner( .dashpay() .accept_contact_request_replying_in_kind( &request, - shielded_address, signer, &crypto, // Refused before any payment could reach the network, @@ -1144,7 +1106,6 @@ mod tests { std::ptr::null(), std::ptr::null(), 0, - std::ptr::null(), std::ptr::null_mut(), &mut out, ) @@ -1166,7 +1127,6 @@ mod tests { resolver, 0, 0xDEAD_BEEF, - std::ptr::null(), std::ptr::null_mut(), &mut out, ) @@ -1188,7 +1148,6 @@ mod tests { resolver, 0, 0xDEAD_BEEF, - std::ptr::null(), std::ptr::null_mut(), &mut out, ) @@ -1343,7 +1302,6 @@ mod tests { resolver, 0, request_handle, - std::ptr::null(), signer, &mut established, ) @@ -1734,7 +1692,6 @@ mod tests { resolver, 0, request_handle, - std::ptr::null(), signer, &mut established, ) diff --git a/packages/rs-platform-wallet/src/wallet/identity/network/contact_shielded_address.rs b/packages/rs-platform-wallet/src/wallet/identity/network/contact_shielded_address.rs index eae54676081..594d8f06a37 100644 --- a/packages/rs-platform-wallet/src/wallet/identity/network/contact_shielded_address.rs +++ b/packages/rs-platform-wallet/src/wallet/identity/network/contact_shielded_address.rs @@ -52,6 +52,10 @@ impl IdentityWallet { to_user_id: &Identifier, account_reference: u32, ) -> Result, PlatformWalletError> { + #[cfg(test)] + if let Some(address) = test_hooks::given() { + return Ok(Some(address)); + } #[cfg(not(feature = "shielded"))] { let _ = (owner_id, to_user_id, account_reference); @@ -136,3 +140,35 @@ impl IdentityWallet { .contains_key(ENCRYPTED_SHIELDED_ADDRESS)) } } + +/// A test's own answer to [`IdentityWallet::contact_shielded_address`], for tests of how +/// an address a request carries is read, stored and forgotten. They need a request that +/// carries a known address and not the wallet state the derivation takes it from, which +/// `shielded/contact_address_tests.rs` covers. +#[cfg(test)] +pub(crate) mod test_hooks { + use std::cell::Cell; + + thread_local! { + static GIVEN: Cell> = const { Cell::new(None) }; + } + + /// While it lives, every contact request sent from this thread carries the address. + pub(crate) struct GivenAddress(()); + + /// Have every contact request this thread sends carry `address`. + pub(crate) fn give_every_contact(address: [u8; 43]) -> GivenAddress { + GIVEN.set(Some(address)); + GivenAddress(()) + } + + impl Drop for GivenAddress { + fn drop(&mut self) { + GIVEN.set(None); + } + } + + pub(super) fn given() -> Option<[u8; 43]> { + GIVEN.get() + } +} diff --git a/packages/rs-platform-wallet/src/wallet/identity/network/private_contact_requests.rs b/packages/rs-platform-wallet/src/wallet/identity/network/private_contact_requests.rs index 38d02cd6441..3cccc1f2adf 100644 --- a/packages/rs-platform-wallet/src/wallet/identity/network/private_contact_requests.rs +++ b/packages/rs-platform-wallet/src/wallet/identity/network/private_contact_requests.rs @@ -883,7 +883,9 @@ impl DashPayView<'_, B> { /// Send a private contact request from `sender_identity_id` to /// `recipient_identity_id`: the request a `contactRequest` document would /// carry (our receiving xpub for the pair, the masked account reference, - /// the label and the auto-accept proof) plus our `shielded_address`, + /// the label and the auto-accept proof) plus the shielded address the + /// wallet derives for the recipient + /// (`IdentityWallet::contact_shielded_address`), /// signed by `signer` with one of the sender's signing keys, sealed in the /// crypto provider to the recipient's DashPay key, then appended by `pay`, /// which pays for it from the shielded pool and returns the metadata of @@ -934,7 +936,6 @@ impl DashPayView<'_, B> { recipient_identity_id: &Identifier, account_label: Option, auto_accept_proof: AutoAcceptProofSource, - shielded_address: Option<[u8; 43]>, signer: &S, crypto: &C, pay: F, @@ -950,7 +951,6 @@ impl DashPayView<'_, B> { recipient_identity_id, account_label, auto_accept_proof, - shielded_address, signer, crypto, false, @@ -972,7 +972,6 @@ impl DashPayView<'_, B> { pub(super) async fn send_private_reply( &self, request: &ContactRequest, - shielded_address: Option<[u8; 43]>, signer: &S, crypto: &C, pay: F, @@ -990,7 +989,6 @@ impl DashPayView<'_, B> { &request.sender_id, None, AutoAcceptProofSource::None, - shielded_address, signer, crypto, true, @@ -1015,7 +1013,6 @@ impl DashPayView<'_, B> { recipient_identity_id: &Identifier, account_label: Option, auto_accept_proof: AutoAcceptProofSource, - shielded_address: Option<[u8; 43]>, signer: &S, crypto: &C, adopt_reply: bool, @@ -1108,7 +1105,6 @@ impl DashPayView<'_, B> { recipient_identity_id, account_label, auto_accept_proof, - shielded_address, signer, crypto, &mut reservation, @@ -1619,7 +1615,6 @@ impl DashPayView<'_, B> { recipient_identity_id: &Identifier, account_label: Option, auto_accept_proof: AutoAcceptProofSource, - shielded_address: Option<[u8; 43]>, signer: &S, crypto: &C, reservation: &mut PrivateReplyReservation, @@ -1651,6 +1646,15 @@ impl DashPayView<'_, B> { crypto, ) .await?; + // Our shielded payment address for this contact, derived as a public + // request's is (`IdentityWallet::contact_shielded_address`): the address + // the sender's shielded account gives this request alone, or none. The + // identity's placement is held until the request is signed, so the + // account is still the identity's when the request commits to the address. + let placement = self.identity_placement.read().await; + let shielded_address = self + .contact_shielded_address(sender_identity_id, recipient_identity_id, account_reference) + .await?; let extended_public_key: [u8; COMPACT_XPUB_LEN] = xpub_bytes.as_slice().try_into().map_err(|_| { PlatformWalletError::InvalidIdentityData(format!( @@ -1693,6 +1697,7 @@ impl DashPayView<'_, B> { )?; let signature = private_contact_request_signature(signer, &signing_key, &signing_data).await?; + drop(placement); // Wiped on drop, so a send dropped while the seal is awaited wipes it too. let mut esk_seed = Zeroizing::new([0u8; 32]); @@ -1847,7 +1852,6 @@ impl DashPayView<'_, B> { pub async fn accept_private_contact_request( &self, request: &ContactRequest, - shielded_address: Option<[u8; 43]>, signer: &S, crypto: &C, pay: F, @@ -1870,7 +1874,7 @@ impl DashPayView<'_, B> { Box::pin(self.read_private_store_and_keys(&request.recipient_id, crypto)).await?; Box::pin( self.accept_contact_request_replying_with(request, crypto, || { - self.send_private_reply(request, shielded_address, signer, crypto, pay) + self.send_private_reply(request, signer, crypto, pay) }), ) .await @@ -1893,7 +1897,6 @@ impl DashPayView<'_, B> { pub async fn accept_contact_request_replying_in_kind( &self, request: &ContactRequest, - shielded_address: Option<[u8; 43]>, signer: &S, crypto: &C, pay: F, @@ -1907,14 +1910,7 @@ impl DashPayView<'_, B> { Box::pin(self.read_private_store_before_deciding(&request.recipient_id, crypto)).await?; // Boxed: each accept's future holds a store read and a payment. if self.needs_private_reply(request).await { - Box::pin(self.accept_private_contact_request( - request, - shielded_address, - signer, - crypto, - pay, - )) - .await + Box::pin(self.accept_private_contact_request(request, signer, crypto, pay)).await } else { Box::pin(self.accept_contact_request_with_external_signer(request, signer, crypto)) .await @@ -2718,6 +2714,7 @@ impl DashPayView<'_, B> { #[cfg(test)] mod tests { use super::super::contact_requests::sent_contact_request_query; + use super::super::contact_shielded_address::test_hooks::give_every_contact; use super::*; use crate::changeset::{ ClientStartState, ClientWalletStartState, IdentityManagerStartState, @@ -3368,7 +3365,6 @@ mod tests { .dashpay() .accept_contact_request_replying_in_kind( &incoming, - None, &alice_signer, &alice_crypto, no_payment, @@ -3391,7 +3387,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, no_payment, @@ -4589,7 +4584,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, pay, @@ -4635,7 +4629,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, failing, @@ -4751,7 +4744,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, no_payment, @@ -4797,7 +4789,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, no_payment, @@ -4846,7 +4837,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, unconfirmed, @@ -4939,7 +4929,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, delivered, @@ -5022,7 +5011,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, keep_entry(&kept), @@ -5144,7 +5132,7 @@ mod tests { let paid = before .identity() .dashpay() - .accept_private_contact_request(&incoming, None, &bob_signer, &bob_crypto, pay) + .accept_private_contact_request(&incoming, &bob_signer, &bob_crypto, pay) .await; assert!( matches!( @@ -5219,7 +5207,6 @@ mod tests { &alice.id(), None, AutoAcceptProofSource::None, - None, &bob_signer, &bob_crypto, no_payment, @@ -5390,6 +5377,7 @@ mod tests { let (_alice_manager, alice_wallet) = wallet(ALICE_PHRASE, &alice, &[&alice, &bob], vec![]).await; let kept = Arc::new(Mutex::new(Vec::new())); + let given = give_every_contact(shielded_address); let sent = alice_wallet .identity() .dashpay() @@ -5398,13 +5386,13 @@ mod tests { &bob.id(), Some("Alice".to_string()), AutoAcceptProofSource::None, - Some(shielded_address), &alice_signer, &alice_crypto, append_entry(&alice_wallet, 0, vec![], &kept), ) .await .expect("Alice sends the request, read back from the store"); + drop(given); let entry = kept.lock().expect("kept entries").remove(0); assert_eq!(entry.len(), 589, "the entry takes DashPay's entry size"); assert_eq!(sent.sender_key_index, ENCRYPTION_KEY_ID); @@ -5528,7 +5516,6 @@ mod tests { let established = bob_view .accept_contact_request_replying_in_kind( &received, - None, &bob_signer, &bob_crypto, append_entry(&bob_wallet, 1, vec![], &reply), @@ -5655,7 +5642,6 @@ mod tests { .dashpay() .accept_contact_request_replying_in_kind( &incoming, - None, &bob_signer, &bob_crypto, keep_entry(&paid), @@ -5674,7 +5660,6 @@ mod tests { .dashpay() .accept_contact_request_replying_in_kind( &incoming, - None, &bob_signer, &bob_crypto, keep_entry(&paid), @@ -5698,7 +5683,6 @@ mod tests { .dashpay() .accept_contact_request_replying_in_kind( &unknown, - None, &bob_signer, &bob_crypto, keep_entry(&paid), @@ -5728,7 +5712,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, append_entry(&alice_wallet, 0, vec![], &kept), @@ -5776,7 +5759,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, append_entry(&alice_wallet, 0, vec![], &kept), @@ -5855,7 +5837,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, $pay, @@ -5914,7 +5895,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, |_, started: PaymentStarted| { @@ -6585,7 +6565,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, keep_entry(&paid), @@ -6697,7 +6676,6 @@ mod tests { &bob_id, None, AutoAcceptProofSource::None, - None, &alice_signer, &pausing, keep_entry(&paid), @@ -7079,7 +7057,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &stalled, &alice_crypto, keep_entry(&paid), @@ -7101,7 +7078,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &signer(ALICE_PHRASE, &alice), &alice_crypto, keep_entry(&kept), @@ -7135,7 +7111,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, keep_entry(&kept), @@ -7198,7 +7173,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, keep_entry(&kept), @@ -7257,7 +7231,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, keep_entry(&kept), @@ -7284,7 +7257,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, keep_entry(&paid), @@ -7353,7 +7325,6 @@ mod tests { &bob_id, None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, keep_entry(&kept), @@ -7373,7 +7344,6 @@ mod tests { &bob_id, None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, |entry: BinaryData, started: PaymentStarted| { @@ -7438,7 +7408,6 @@ mod tests { &bob_id, None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, append_entry(&before, 0, vec![], &kept), @@ -7468,7 +7437,6 @@ mod tests { &bob_id, None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, unconfirmed, @@ -7516,7 +7484,6 @@ mod tests { &bob_id, None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, no_payment, @@ -7546,7 +7513,6 @@ mod tests { &bob_id, None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, |entry: BinaryData, started: PaymentStarted| { @@ -7681,7 +7647,6 @@ mod tests { &recipient, None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, append_entry(&alice_wallet, start, vec![], &kept), @@ -7699,7 +7664,6 @@ mod tests { &alice.id(), None, AutoAcceptProofSource::None, - None, &bob_signer, &bob_crypto, append_entry(&bob_wallet, 1, vec![], &kept), @@ -7773,6 +7737,7 @@ mod tests { let (_alice_manager, alice_wallet) = wallet(ALICE_PHRASE, &alice, &[&alice, &bob], vec![]).await; let kept = Arc::new(Mutex::new(Vec::new())); + let given = give_every_contact(shielded_address); alice_wallet .identity() .dashpay() @@ -7781,13 +7746,13 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - Some(shielded_address), &signer(ALICE_PHRASE, &alice), &alice_crypto, append_entry(&alice_wallet, 0, vec![], &kept), ) .await .expect("Alice sends"); + drop(given); let entry = kept.lock().expect("kept").remove(0).to_vec(); let (_bob_manager, bob_wallet) = wallet(BOB_PHRASE, &bob, &[&alice, &bob], vec![entry.clone()]).await; @@ -8088,7 +8053,6 @@ mod tests { &alice.id(), None, AutoAcceptProofSource::None, - None, &bob_signer, &bob_crypto, no_payment, @@ -8390,7 +8354,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, keep_entry(&paid), @@ -8428,7 +8391,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, keep_entry(&kept), @@ -9138,13 +9100,7 @@ mod tests { let replied = other .identity() .dashpay() - .accept_private_contact_request( - &received, - None, - &bob_signer, - &bob_crypto, - keep_entry(&reply), - ) + .accept_private_contact_request(&received, &bob_signer, &bob_crypto, keep_entry(&reply)) .await; assert!( matches!( @@ -9173,7 +9129,7 @@ mod tests { .await; let adopted = view - .accept_private_contact_request(&received, None, &bob_signer, &bob_crypto, no_payment) + .accept_private_contact_request(&received, &bob_signer, &bob_crypto, no_payment) .await .expect("the reply is adopted"); assert_eq!(adopted.contact_identity_id, alice.id()); @@ -9437,7 +9393,6 @@ mod tests { Duration::from_millis(200), bob_wallet.accept_contact_request_replying_in_kind( &received, - None, &bob_signer, &bob_crypto, || { @@ -9455,13 +9410,7 @@ mod tests { let retried = bob_wallet .identity() .dashpay() - .accept_private_contact_request( - &received, - None, - &bob_signer, - &bob_crypto, - keep_entry(&reply), - ) + .accept_private_contact_request(&received, &bob_signer, &bob_crypto, keep_entry(&reply)) .await; assert!( matches!( @@ -9531,7 +9480,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, pay, @@ -9577,7 +9525,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, no_payment, @@ -9656,7 +9603,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, pay, @@ -9718,7 +9664,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, keep_entry(&retry), @@ -9870,7 +9815,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, keep_entry(&kept), @@ -10065,7 +10009,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, pay, @@ -10143,7 +10086,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, pay, @@ -10629,7 +10571,6 @@ mod tests { &bob_id, None, AutoAcceptProofSource::None, - None, &signer, &crypto, |_: BinaryData, _: PaymentStarted| { @@ -10773,7 +10714,6 @@ mod tests { &bob_id, None, AutoAcceptProofSource::None, - None, signer, crypto, keep_entry(&kept), @@ -12244,7 +12184,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, failing, @@ -12354,7 +12293,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, pay, @@ -12420,7 +12358,7 @@ mod tests { let (received, bob_signer, bob_crypto) = (&received, &bob_signer, &bob_crypto); async move { first_done.notified().await; - view.send_private_reply(received, None, bob_signer, bob_crypto, no_payment) + view.send_private_reply(received, bob_signer, bob_crypto, no_payment) .await } }); @@ -12428,7 +12366,6 @@ mod tests { let accepted = view .accept_private_contact_request( &received, - None, &bob_signer, &bob_crypto, append_entry(&bob_wallet, 1, vec![], &reply), @@ -12486,7 +12423,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, append_entry(&alice_wallet, 0, vec![], &kept), @@ -12519,7 +12455,6 @@ mod tests { .dashpay() .accept_contact_request_replying_in_kind( &received, - None, &bob_signer, &bob_crypto, keep_entry(&reply), @@ -12559,7 +12494,6 @@ mod tests { .dashpay() .accept_contact_request_replying_in_kind( &received, - None, &bob_signer, &bob_crypto, no_payment, @@ -12610,13 +12544,7 @@ mod tests { let paid = before .identity() .dashpay() - .accept_private_contact_request( - &incoming, - None, - &bob_signer, - &bob_crypto, - keep_entry(&reply), - ) + .accept_private_contact_request(&incoming, &bob_signer, &bob_crypto, keep_entry(&reply)) .await; assert!( matches!( @@ -12661,7 +12589,6 @@ mod tests { .dashpay() .accept_contact_request_replying_in_kind( &incoming, - None, &bob_signer, &bob_crypto, no_payment, @@ -12711,7 +12638,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, append_entry(&alice_wallet, 0, vec![], &kept), @@ -12731,7 +12657,6 @@ mod tests { .dashpay() .accept_contact_request_replying_in_kind( &public, - None, &bob_signer, &bob_crypto, keep_entry(&reply), @@ -12822,7 +12747,7 @@ mod tests { let paid = before .identity() .dashpay() - .accept_private_contact_request(&incoming, None, &bob_signer, &bob_crypto, pay) + .accept_private_contact_request(&incoming, &bob_signer, &bob_crypto, pay) .await; assert!( matches!( @@ -12857,7 +12782,6 @@ mod tests { .dashpay() .accept_contact_request_replying_in_kind( &incoming, - None, &bob_signer, &bob_crypto, no_payment, @@ -12926,7 +12850,6 @@ mod tests { .dashpay() .accept_contact_request_replying_in_kind( &incoming, - None, &bob_signer, &bob_crypto, no_payment, @@ -13336,7 +13259,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, keep_entry(&kept), @@ -13355,7 +13277,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, $pay, @@ -13437,7 +13358,6 @@ mod tests { &$recipient, None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, keep_entry($kept), @@ -13452,7 +13372,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, |_: BinaryData, started: PaymentStarted| { @@ -13516,7 +13435,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, append_entry(&alice_wallet, 0, vec![], &kept), @@ -13546,7 +13464,6 @@ mod tests { &bob.id(), None, AutoAcceptProofSource::None, - None, &alice_signer, &alice_crypto, |_: BinaryData, _: PaymentStarted| -> std::future::Ready> { diff --git a/packages/rs-platform-wallet/src/wallet/platform_wallet.rs b/packages/rs-platform-wallet/src/wallet/platform_wallet.rs index cada57977c2..354549674d0 100644 --- a/packages/rs-platform-wallet/src/wallet/platform_wallet.rs +++ b/packages/rs-platform-wallet/src/wallet/platform_wallet.rs @@ -1811,8 +1811,8 @@ impl PlatformWallet { /// Send a DashPay private contact request (protocol version 15) from /// `sender_identity_id` to `recipient_identity_id`, paying for it from /// `account`'s shielded notes: nothing on chain names either identity. The - /// request carries `account_label`, `auto_accept_proof` and our - /// `shielded_address` for the contact, is signed by `signer` as the + /// request carries `account_label`, `auto_accept_proof` and the shielded + /// address the wallet derives for the contact, is signed by `signer` as the /// sender's transitions are, and is sealed by `crypto`, which keeps the /// encryption key. `seed` supplies the transient spend authority (see /// [`shielded_transfer_to`](Self::shielded_transfer_to)). See @@ -1828,7 +1828,6 @@ impl PlatformWallet { recipient_identity_id: &Identifier, account_label: Option, auto_accept_proof: AutoAcceptProofSource, - shielded_address: Option<[u8; 43]>, signer: &S, crypto: &C, prover: P, @@ -1846,7 +1845,6 @@ impl PlatformWallet { recipient_identity_id, account_label, auto_accept_proof, - shielded_address, signer, crypto, |entry, started| { @@ -1868,8 +1866,8 @@ impl PlatformWallet { /// Accept a DashPay contact request that came privately, replying /// privately and paying for the reply from `account`'s shielded notes, as /// [`send_private_contact_request`](Self::send_private_contact_request) - /// pays and signing it with `signer`. `shielded_address` is the address - /// the contact may pay us at privately. See + /// pays and signing it with `signer`. The reply carries the shielded + /// address the wallet derives for the contact. See /// [`DashPayView::accept_private_contact_request`](crate::DashPayView::accept_private_contact_request). #[cfg(feature = "shielded")] #[allow(clippy::too_many_arguments)] @@ -1879,7 +1877,6 @@ impl PlatformWallet { seed: &[u8], account: u32, request: &ContactRequest, - shielded_address: Option<[u8; 43]>, signer: &S, crypto: &C, prover: P, @@ -1892,24 +1889,18 @@ impl PlatformWallet { let keyset = self.derive_spend_keyset(seed, account).await?; self.identity .dashpay() - .accept_private_contact_request( - request, - shielded_address, - signer, - crypto, - |entry, started| { - self.pay_private_contact_request( - coordinator, - keyset, - account, - &request.recipient_id, - &request.sender_id, - entry, - started, - prover, - ) - }, - ) + .accept_private_contact_request(request, signer, crypto, |entry, started| { + self.pay_private_contact_request( + coordinator, + keyset, + account, + &request.recipient_id, + &request.sender_id, + entry, + started, + prover, + ) + }) .await } @@ -1925,7 +1916,6 @@ impl PlatformWallet { pub async fn accept_contact_request_replying_in_kind( &self, request: &ContactRequest, - shielded_address: Option<[u8; 43]>, signer: &S, crypto: &C, payment: R, @@ -1943,7 +1933,6 @@ impl PlatformWallet { .dashpay() .accept_contact_request_replying_in_kind( request, - shielded_address, signer, crypto, |entry, started| async move { diff --git a/packages/rs-unified-sdk-jni/src/dashpay.rs b/packages/rs-unified-sdk-jni/src/dashpay.rs index ae5fabe16de..7fa52d4c7cf 100644 --- a/packages/rs-unified-sdk-jni/src/dashpay.rs +++ b/packages/rs-unified-sdk-jni/src/dashpay.rs @@ -1263,11 +1263,6 @@ pub extern "system" fn Java_org_dashfoundation_dashsdk_ffi_DashpayNative_claimIn // accept that replies the way a request came // (`acceptContactRequestReplyingInKind`) is exported in every build. -/// The bytes of an Orchard payment address the FFI reads from a -/// `shielded_address` pointer: an 11-byte diversifier and a 32-byte -/// transmission key. -const SHIELDED_ADDRESS_LEN: usize = 43; - /// The longs [`Java_org_dashfoundation_dashsdk_ffi_DashpayNative_syncPrivateContactRequests`] /// returns, in the order `Dashpay.syncPrivateContactRequests` reads them: /// the requests the pass ingested, the store pages read, the entries @@ -1597,7 +1592,9 @@ fn readiness_flags(readiness: &PrivateContactReadinessFFI) -> [jboolean; 4] { } /// Copy an optional Java `byte[]`; JVM null is `None`. Throws and returns -/// `Err` on a JNI error. `field` names the argument in the message. +/// `Err` on a JNI error. `field` names the argument in the message. Only the +/// private send reads one, so it is built with that export. +#[cfg(feature = "shielded")] fn read_opt_bytes(env: &mut JNIEnv, arr: &JByteArray, field: &str) -> Result>, ()> { if arr.is_null() { return Ok(None); @@ -1612,37 +1609,16 @@ fn read_opt_bytes(env: &mut JNIEnv, arr: &JByteArray, field: &str) -> Result Result>, ()> { - let address = read_opt_bytes(env, arr, "shieldedAddress")?; - if let Some(address) = &address { - if address.len() != SHIELDED_ADDRESS_LEN { - throw_sdk_exception( - env, - 1, - &format!( - "shieldedAddress must be {SHIELDED_ADDRESS_LEN} raw Orchard bytes, got {}", - address.len() - ), - ); - return Err(()); - } - } - Ok(address) -} - /// Send a DashPay private contact request from `senderIdentityId` to /// `recipientIdentityId`, paying for it from `account`'s shielded notes /// (bridges `platform_wallet_manager_send_private_contact_request`). /// `resolverHandle` supplies the Orchard spend authority and the DashPay /// keys; `signerHandle` is the identity signer (`SignerHandle`) the public /// [`crate::tokens`] `sendContactRequest` takes, and signs the request. -/// `accountLabel`, `autoAcceptProof` and `shieldedAddress` (43 bytes) may be -/// null. Blocks for the Halo 2 proof; returns the created `ContactRequest` -/// handle (destroy via `TokensNative.contactRequestDestroy`). +/// `accountLabel` and `autoAcceptProof` may be null. The wallet derives the +/// Orchard address the request carries, one for this contact alone. Blocks +/// for the Halo 2 proof; returns the created `ContactRequest` handle (destroy +/// via `TokensNative.contactRequestDestroy`). #[cfg(feature = "shielded")] #[no_mangle] #[allow(clippy::too_many_arguments)] @@ -1657,7 +1633,6 @@ pub extern "system" fn Java_org_dashfoundation_dashsdk_ffi_DashpayNative_sendPri recipient_identity_id: JByteArray, account_label: JString, auto_accept_proof: JByteArray, - shielded_address: JByteArray, signer_handle: jlong, ) -> jlong { guard(&mut env, 0, |env| { @@ -1680,9 +1655,6 @@ pub extern "system" fn Java_org_dashfoundation_dashsdk_ffi_DashpayNative_sendPri let Ok(proof) = read_opt_bytes(env, &auto_accept_proof, "autoAcceptProof") else { return 0; }; - let Ok(address) = read_opt_shielded_address(env, &shielded_address) else { - return 0; - }; let (proof_ptr, proof_len) = proof .as_ref() .map_or((ptr::null(), 0), |proof| (proof.as_ptr(), proof.len())); @@ -1698,9 +1670,6 @@ pub extern "system" fn Java_org_dashfoundation_dashsdk_ffi_DashpayNative_sendPri label.as_ref().map_or(ptr::null(), |label| label.as_ptr()), proof_ptr, proof_len, - address - .as_ref() - .map_or(ptr::null(), |address| address.as_ptr()), signer_handle as *mut SignerHandle, &mut out_handle, ) @@ -1715,10 +1684,10 @@ pub extern "system" fn Java_org_dashfoundation_dashsdk_ffi_DashpayNative_sendPri /// Accept the incoming contact request `requestHandle` with a private reply, /// paying for the reply from `account`'s shielded notes (bridges /// `platform_wallet_manager_accept_private_contact_request`). The handles -/// are as for [`Java_org_dashfoundation_dashsdk_ffi_DashpayNative_sendPrivateContactRequest`]; -/// `shieldedAddress` (43 bytes) may be null. Blocks for the Halo 2 proof; -/// returns the `EstablishedContact` handle (destroy via -/// `TokensNative.establishedContactDestroy`). +/// are as for [`Java_org_dashfoundation_dashsdk_ffi_DashpayNative_sendPrivateContactRequest`], +/// and the wallet derives the Orchard address the reply carries the same +/// way. Blocks for the Halo 2 proof; returns the `EstablishedContact` handle +/// (destroy via `TokensNative.establishedContactDestroy`). #[cfg(feature = "shielded")] #[no_mangle] #[allow(clippy::too_many_arguments)] @@ -1730,7 +1699,6 @@ pub extern "system" fn Java_org_dashfoundation_dashsdk_ffi_DashpayNative_acceptP resolver_handle: jlong, account: jint, request_handle: jlong, - shielded_address: JByteArray, signer_handle: jlong, ) -> jlong { guard(&mut env, 0, |env| { @@ -1741,9 +1709,6 @@ pub extern "system" fn Java_org_dashfoundation_dashsdk_ffi_DashpayNative_acceptP let Some(wid) = read_id32(env, &wallet_id, "walletId") else { return 0; }; - let Ok(address) = read_opt_shielded_address(env, &shielded_address) else { - return 0; - }; let mut out_handle: Handle = 0; let result = unsafe { platform_wallet_ffi::platform_wallet_manager_accept_private_contact_request( @@ -1752,9 +1717,6 @@ pub extern "system" fn Java_org_dashfoundation_dashsdk_ffi_DashpayNative_acceptP resolver_handle as *mut MnemonicResolverHandle, account as u32, request_handle as Handle, - address - .as_ref() - .map_or(ptr::null(), |address| address.as_ptr()), signer_handle as *mut SignerHandle, &mut out_handle, ) @@ -1772,10 +1734,11 @@ pub extern "system" fn Java_org_dashfoundation_dashsdk_ffi_DashpayNative_acceptP /// privately, paid from `account`'s shielded notes, when it came privately /// and no reply exists yet; otherwise with a `contactRequest` document, or by /// adopting the reply already sent. The wallet decides; this is the accept a -/// host calls. Arguments and result are as for the private accept above. -/// Exported in every build: without the `shielded` feature a request that -/// needs a private reply is refused with `ErrorShieldedBuildRequired`, and a -/// public or adopted reply works as in a shielded build. +/// host calls. Arguments and result are as for the private accept above, and +/// a private reply carries the Orchard address the wallet derives for this +/// contact. Exported in every build: without the `shielded` feature a request +/// that needs a private reply is refused with `ErrorShieldedBuildRequired`, +/// and a public or adopted reply works as in a shielded build. #[no_mangle] #[allow(clippy::too_many_arguments)] pub extern "system" fn Java_org_dashfoundation_dashsdk_ffi_DashpayNative_acceptContactRequestReplyingInKind( @@ -1786,7 +1749,6 @@ pub extern "system" fn Java_org_dashfoundation_dashsdk_ffi_DashpayNative_acceptC resolver_handle: jlong, account: jint, request_handle: jlong, - shielded_address: JByteArray, signer_handle: jlong, ) -> jlong { guard(&mut env, 0, |env| { @@ -1797,9 +1759,6 @@ pub extern "system" fn Java_org_dashfoundation_dashsdk_ffi_DashpayNative_acceptC let Some(wid) = read_id32(env, &wallet_id, "walletId") else { return 0; }; - let Ok(address) = read_opt_shielded_address(env, &shielded_address) else { - return 0; - }; let mut out_handle: Handle = 0; let result = unsafe { platform_wallet_ffi::platform_wallet_manager_accept_contact_request_replying_in_kind( @@ -1808,9 +1767,6 @@ pub extern "system" fn Java_org_dashfoundation_dashsdk_ffi_DashpayNative_acceptC resolver_handle as *mut MnemonicResolverHandle, account as u32, request_handle as Handle, - address - .as_ref() - .map_or(ptr::null(), |address| address.as_ptr()), signer_handle as *mut SignerHandle, &mut out_handle, ) diff --git a/packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PrivateContactRequests.swift b/packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PrivateContactRequests.swift index 3ad72306ab0..37059e7df29 100644 --- a/packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PrivateContactRequests.swift +++ b/packages/swift-sdk/Sources/SwiftDashSDK/PlatformWallet/PrivateContactRequests.swift @@ -280,8 +280,9 @@ extension ManagedPlatformWallet { extension PlatformWalletManager { /// Send a DashPay private contact request from `senderIdentityId` to /// `recipientIdentityId`, paying for it from `account`'s shielded notes, - /// so nothing on chain names either identity. `shieldedAddress` is the - /// 43-byte Orchard address the contact may pay us at privately. + /// so nothing on chain names either identity. The request carries an + /// Orchard address the contact may pay us at privately, which the wallet + /// derives for this contact alone. /// /// `resolver` supplies both the Orchard spend authority and the DashPay /// keys. `signer` is the identity signer `sendContactRequest` takes: it @@ -307,13 +308,11 @@ extension PlatformWalletManager { recipientIdentityId: Identifier, accountLabel: String? = nil, autoAcceptProof: Data? = nil, - shieldedAddress: Data? = nil, signer: KeychainSigner ) async throws -> ContactRequest { let handle = try privateContactRequestManagerHandle( walletId: walletId, - resolver: resolver, - shieldedAddress: shieldedAddress + resolver: resolver ) // Counted as the other native manager operations are, so a teardown // waits for this call to return before it frees the manager. @@ -333,22 +332,19 @@ extension PlatformWalletManager { try recipientIdentityId.withFFIBytes { recipientPtr in try withOptionalCString(accountLabel) { labelPtr in try withOptionalBytes(autoAcceptProof) { proofPtr, proofLen in - try withOptionalBytes(shieldedAddress) { addressPtr, _ in - try platform_wallet_manager_send_private_contact_request( - handle, - widPtr, - resolverHandle, - account, - senderPtr, - recipientPtr, - labelPtr, - proofPtr, - proofLen, - addressPtr, - signerHandle, - &outHandle - ).check() - } + try platform_wallet_manager_send_private_contact_request( + handle, + widPtr, + resolverHandle, + account, + senderPtr, + recipientPtr, + labelPtr, + proofPtr, + proofLen, + signerHandle, + &outHandle + ).check() } } } @@ -362,22 +358,20 @@ extension PlatformWalletManager { /// Accept a DashPay contact request that came privately, replying /// privately and paying for the reply from `account`'s shielded notes. - /// `shieldedAddress` is the 43-byte Orchard address the contact may pay - /// us at privately. `signer` is the identity signer - /// `acceptContactRequest` takes; it signs the reply. It throws as - /// `sendPrivateContactRequest` does. + /// The reply carries an Orchard address the contact may pay us at + /// privately, which the wallet derives for this contact alone. `signer` + /// is the identity signer `acceptContactRequest` takes; it signs the + /// reply. It throws as `sendPrivateContactRequest` does. public func acceptPrivateContactRequest( walletId: Data, resolver: MnemonicResolver, account: UInt32 = 0, request: ContactRequest, - shieldedAddress: Data? = nil, signer: KeychainSigner ) async throws -> EstablishedContact { let handle = try privateContactRequestManagerHandle( walletId: walletId, - resolver: resolver, - shieldedAddress: shieldedAddress + resolver: resolver ) // Counted as the other native manager operations are, so a teardown // waits for this call to return before it frees the manager. @@ -391,18 +385,15 @@ extension PlatformWalletManager { let resolverHandle = resolver.handle try withExtendedLifetime((resolver, signer, request)) { try walletId.withFFIBytes { widPtr in - try withOptionalBytes(shieldedAddress) { addressPtr, _ in - try platform_wallet_manager_accept_private_contact_request( - handle, - widPtr, - resolverHandle, - account, - requestHandle, - addressPtr, - signerHandle, - &outHandle - ).check() - } + try platform_wallet_manager_accept_private_contact_request( + handle, + widPtr, + resolverHandle, + account, + requestHandle, + signerHandle, + &outHandle + ).check() } } return outHandle @@ -415,9 +406,10 @@ extension PlatformWalletManager { /// reply exists yet; otherwise with a `contactRequest` document signed by /// `signer`, or by adopting the reply already sent. Which reply a request /// takes is the wallet's decision, so this is the accept a host calls. - /// `shieldedAddress` is the 43-byte Orchard address the contact may pay - /// us at privately; a public reply ignores it. A public or adopted reply - /// needs neither shielded support nor a mnemonic read for the payment. + /// A private reply carries an Orchard address the contact may pay us at + /// privately, which the wallet derives for this contact alone. A public + /// or adopted reply needs neither shielded support nor a mnemonic read + /// for the payment. /// Throws `PlatformWalletError.shieldedSpendUnconfirmed` (or /// `.transactionBroadcastUnconfirmed`) when a private reply may already be /// on chain, or `.privateContactRequestPending` when @@ -431,13 +423,11 @@ extension PlatformWalletManager { resolver: MnemonicResolver, account: UInt32 = 0, request: ContactRequest, - shieldedAddress: Data? = nil, signer: KeychainSigner ) async throws -> EstablishedContact { let handle = try privateContactRequestManagerHandle( walletId: walletId, - resolver: resolver, - shieldedAddress: shieldedAddress + resolver: resolver ) // Counted as the other native manager operations are, so a teardown // waits for this call to return before it frees the manager. @@ -453,18 +443,15 @@ extension PlatformWalletManager { // FFI call, whose vtable callbacks fire during it. try withExtendedLifetime((resolver, signer, request)) { try walletId.withFFIBytes { widPtr in - try withOptionalBytes(shieldedAddress) { addressPtr, _ in - try platform_wallet_manager_accept_contact_request_replying_in_kind( - handle, - widPtr, - resolverHandle, - account, - requestHandle, - addressPtr, - signerHandle, - &outHandle - ).check() - } + try platform_wallet_manager_accept_contact_request_replying_in_kind( + handle, + widPtr, + resolverHandle, + account, + requestHandle, + signerHandle, + &outHandle + ).check() } } return outHandle @@ -474,12 +461,11 @@ extension PlatformWalletManager { /// The manager handle of a private contact request call, refused before /// any FFI call when the arguments cannot be passed: an unconfigured - /// manager, a wallet id that is not 32 bytes, a shielded address that is - /// not the 43 bytes Rust reads, or a resolver without a handle. + /// manager, a wallet id that is not 32 bytes, or a resolver without a + /// handle. private func privateContactRequestManagerHandle( walletId: Data, - resolver: MnemonicResolver, - shieldedAddress: Data? + resolver: MnemonicResolver ) throws -> Handle { guard isConfigured, handle != NULL_HANDLE else { throw PlatformWalletError.invalidHandle("PlatformWalletManager not configured") @@ -487,11 +473,6 @@ extension PlatformWalletManager { guard walletId.count == 32 else { throw PlatformWalletError.invalidParameter("walletId must be exactly 32 bytes") } - if let shieldedAddress, shieldedAddress.count != 43 { - throw PlatformWalletError.invalidParameter( - "shieldedAddress must be exactly 43 raw Orchard bytes" - ) - } guard resolver.handle != nil else { throw PlatformWalletError.invalidParameter("MnemonicResolver has no handle") }