Repository navigation
feat(platform-wallet)!: contact requests carry the sender's per-contact shielded address #5901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
QuantumExplorer
wants to merge
12
commits into
feat/dashpay-shielded-tips
Choose a base branch
from
claude/dashpay-contact-address-send
base: feat/dashpay-shielded-tips
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+828
−10
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
c82d5fc
Merge remote-tracking branch 'origin/v5.1-dev' into claude/dashpay-co…
QuantumExplorer 616faf9
feat(sdk): a contact request can carry the sender's shielded address
QuantumExplorer bce076b
Merge remote-tracking branch 'origin/pr-5288' into claude/dashpay-con…
QuantumExplorer 6f04a84
Merge remote-tracking branch 'origin/v5.1-dev' into claude/dashpay-co…
QuantumExplorer d83cf98
feat(platform-wallet): a contact request carries the sender's per-con…
QuantumExplorer e7965fd
Merge branch 'feat/dashpay-shielded-tips' of github.com:dashpay/platf…
QuantumExplorer 7dab512
Merge branch 'feat/dashpay-shielded-tips' of github.com:dashpay/platf…
QuantumExplorer e76f2c6
fix(sdk): a contact request with a shielded address learns the networ…
QuantumExplorer 2e74ff1
fix(platform-wallet): the per-contact address check counts establishe…
QuantumExplorer b445f18
Merge branch 'feat/dashpay-shielded-tips' of github.com:dashpay/platf…
QuantumExplorer 6e629e6
refactor(sdk): the contact request address gate reads the shared acti…
QuantumExplorer 27f9632
fix(platform-wallet): the per-contact address check counts requests n…
QuantumExplorer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
153 changes: 153 additions & 0 deletions
153
packages/rs-platform-wallet/src/wallet/identity/network/contact_shielded_address.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| //! The shielded payment address a contact request carries. | ||
|
|
||
| use super::identity_handle::IdentityWallet; | ||
| use crate::broadcaster::TransactionBroadcaster; | ||
| use crate::error::PlatformWalletError; | ||
| #[cfg(feature = "shielded")] | ||
| use crate::wallet::shielded::shielded_identity_account_index; | ||
| #[cfg(feature = "shielded")] | ||
| use dash_sdk::platform::Fetch; | ||
| #[cfg(feature = "shielded")] | ||
| use dpp::data_contract::accessors::v0::DataContractV0Getters; | ||
| #[cfg(feature = "shielded")] | ||
| use dpp::data_contract::document_type::accessors::DocumentTypeV0Getters; | ||
| #[cfg(feature = "shielded")] | ||
| use dpp::data_contracts::SystemDataContract; | ||
| #[cfg(feature = "shielded")] | ||
| use dpp::prelude::DataContract; | ||
| use dpp::prelude::Identifier; | ||
|
|
||
| /// The DashPay document type of a contact request. | ||
| #[cfg(feature = "shielded")] | ||
| const CONTACT_REQUEST: &str = "contactRequest"; | ||
|
|
||
| /// The `contactRequest` property that carries the sender's shielded address. | ||
| #[cfg(feature = "shielded")] | ||
| const ENCRYPTED_SHIELDED_ADDRESS: &str = "encryptedShieldedAddress"; | ||
|
|
||
| /// Log why `owner_id`'s contact request goes without a shielded address. The | ||
| /// request is still sent, so this is the only trace of the reason. | ||
| #[cfg(feature = "shielded")] | ||
| fn without_address(owner_id: &Identifier, reason: &str) { | ||
| tracing::debug!( | ||
| identity = %owner_id, | ||
| reason, | ||
| "contact request sent without a shielded address" | ||
| ); | ||
| } | ||
|
|
||
| impl<B: TransactionBroadcaster + ?Sized> IdentityWallet<B> { | ||
| /// The shielded payment address `owner_id` gives `to_user_id` in the contact request | ||
| /// it sends under `account_reference`, or `None` when the request goes without one. | ||
| /// | ||
| /// The address is the one the identity's shielded account derives for this request | ||
| /// alone (`AccountViewingKeys::contact_address`), so every contact gets a different | ||
| /// one and a payment that arrives on it is attributed to that contact. It is `None` | ||
| /// unless all of these hold: | ||
| /// | ||
| /// - the identity's shielded account was prepared in this session, which proves with | ||
| /// the seed that the identity holds the slot the account belongs to, and it is | ||
| /// still the account of the slot the identity holds; | ||
| /// - that account's viewing keys are bound; | ||
| /// - the connected network's contact requests have the property that carries the | ||
| /// address. A bundled schema does not show the network has activated it. | ||
| /// | ||
| /// The send is refused when the address would be one this identity has given | ||
| /// another contact. That takes a collision in 87 bits of a keyed hash. | ||
| /// | ||
| /// The caller holds the identity's placement from this call until the request is | ||
| /// signed, so the account is still the identity's when the request commits to it. | ||
| pub(crate) async fn contact_shielded_address( | ||
| &self, | ||
| owner_id: &Identifier, | ||
| to_user_id: &Identifier, | ||
| account_reference: u32, | ||
| ) -> Result<Option<[u8; 43]>, PlatformWalletError> { | ||
| #[cfg(not(feature = "shielded"))] | ||
| { | ||
| let _ = (owner_id, to_user_id, account_reference); | ||
| Ok(None) | ||
| } | ||
| #[cfg(feature = "shielded")] | ||
| { | ||
| // The account of the slot the identity holds now, and the requests it has | ||
| // sent to its other contacts. | ||
| let (account, others) = { | ||
| let wm = self.wallet_manager.read().await; | ||
| let Some(managed) = wm | ||
| .get_wallet_info(&self.wallet_id) | ||
| .and_then(|info| info.identity_manager.managed_identity(owner_id)) | ||
| .filter(|identity| identity.wallet_id == Some(self.wallet_id)) | ||
| else { | ||
| without_address(owner_id, "the wallet does not hold the identity"); | ||
| return Ok(None); | ||
| }; | ||
| let Some(account) = managed | ||
| .identity_index | ||
| .and_then(|index| shielded_identity_account_index(index).ok()) | ||
| else { | ||
| without_address(owner_id, "the identity has no shielded account"); | ||
| return Ok(None); | ||
| }; | ||
| (account, managed.other_sent_account_references(to_user_id)) | ||
| }; | ||
| let Some(keys) = self | ||
| .contact_shielded_addresses | ||
| .proven_account_keys(owner_id, account) | ||
| .await | ||
| else { | ||
| without_address( | ||
| owner_id, | ||
| "the identity's shielded account is not prepared in this session, or \ | ||
| its viewing keys are not bound", | ||
| ); | ||
| return Ok(None); | ||
| }; | ||
| if !self.contact_requests_carry_shielded_address().await? { | ||
| without_address( | ||
| owner_id, | ||
| "the network's contact requests do not carry a shielded address yet", | ||
| ); | ||
| return Ok(None); | ||
| } | ||
|
|
||
| let owner = owner_id.as_bytes(); | ||
| let reference = u64::from(account_reference); | ||
| let index = keys.contact_index(owner, to_user_id.as_bytes(), reference); | ||
| let taken = others.iter().any(|(other, other_reference)| { | ||
| keys.contact_index(owner, other.as_bytes(), u64::from(*other_reference)) == index | ||
| }); | ||
| if taken { | ||
| return Err(PlatformWalletError::InvalidIdentityData( | ||
| "The shielded address of this contact request is one already given to \ | ||
| another contact; send the request under another account reference" | ||
| .to_string(), | ||
| )); | ||
| } | ||
| Ok(Some( | ||
| keys.contact_address(owner, to_user_id.as_bytes(), reference) | ||
| .to_raw_address_bytes(), | ||
| )) | ||
| } | ||
| } | ||
|
|
||
| /// Whether the connected network's DashPay contract gives contact requests the | ||
| /// property that carries a shielded address, which it does from DashPay v3 at | ||
| /// protocol version 15. Read from the network: the bundled schema is the latest one. | ||
| #[cfg(feature = "shielded")] | ||
| async fn contact_requests_carry_shielded_address(&self) -> Result<bool, PlatformWalletError> { | ||
| let contract = DataContract::fetch(&self.sdk, SystemDataContract::Dashpay.id()) | ||
| .await? | ||
| .ok_or_else(|| { | ||
| PlatformWalletError::InvalidIdentityData( | ||
| "DashPay contract is not available".to_string(), | ||
| ) | ||
| })?; | ||
| let contact_request = contract | ||
| .document_type_for_name(CONTACT_REQUEST) | ||
| .map_err(|e| PlatformWalletError::InvalidIdentityData(e.to_string()))?; | ||
| Ok(contact_request | ||
| .properties() | ||
| .contains_key(ENCRYPTED_SHIELDED_ADDRESS)) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.