Skip to content

Refactor wallet for public account changes#452

Draft
jonesmarvin8 wants to merge 25 commits intomainfrom
marvin/refactor-wallet-pub-acc
Draft

Refactor wallet for public account changes#452
jonesmarvin8 wants to merge 25 commits intomainfrom
marvin/refactor-wallet-pub-acc

Conversation

@jonesmarvin8
Copy link
Copy Markdown
Collaborator

@jonesmarvin8 jonesmarvin8 commented Apr 20, 2026

🎯 Purpose

Minor refactoring Wallet's handling of public accounts in preparation of Keycard integration.

⚙️ Approach

  • KeyTreePublic to optional storage
  • Reorganization for WitnessSet generation (specific for native token transactions).

🧪 How to Test

All pre-existing tests should be unaffected.

🔗 Dependencies

Uses PR 457 as a base to have a single base for PR 451 to build off of.

🔜 Future Work

N/A

📋 PR Completion Checklist

  • Complete PR description
  • Implement the core functionality
  • Add/update tests
  • Add/update documentation and inline comments

@jonesmarvin8 jonesmarvin8 marked this pull request as ready for review April 21, 2026 22:38
@jonesmarvin8 jonesmarvin8 changed the base branch from main to marvin/signature-bip340-fixes April 24, 2026 16:00
Comment thread wallet/src/lib.rs
Comment thread wallet/src/chain_storage.rs Outdated
Comment thread wallet/src/program_facades/native_token_transfer/public.rs Outdated
Comment thread wallet/src/lib.rs Outdated
Comment thread nssa/src/privacy_preserving_transaction/witness_set.rs Outdated
Comment thread wallet/src/config.rs
Copy link
Copy Markdown
Collaborator

@moudyellaz moudyellaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks for addressing my comments. Left 2 minor comments.

@jonesmarvin8 jonesmarvin8 requested a review from moudyellaz April 29, 2026 11:40
Copy link
Copy Markdown
Collaborator

@schouhy schouhy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I'm finding hard to review as this looks like some minor adjustments for a bigger PR and I'd like to understand the bigger scope to see if I agree with the design choices.

Comment on lines +11 to +24
#[must_use]
pub fn from_list(signatures: &[Signature], pub_keys: &[PublicKey]) -> Self {
assert_eq!(signatures.len(), pub_keys.len());

let signatures_and_public_keys = signatures
.iter()
.zip(pub_keys.iter())
.map(|(sig, key)| (sig.clone(), key.clone()))
.collect();

Self {
signatures_and_public_keys,
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unused. Let's remove it. Also, I think it's not a good idea to provide constructors that don't enforce valid object creation. I mean, this method would allow to create a WitnessSet instance with invalid signatures for the given public keys. In case such a method is needed for the rest I'd have it return a Result and return Err in case signatures are not valid for the give public keys, or there's a mismatch in the number of elements (instead of panicking)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is necessary for Keycard. Keycard produces a signature within its logic. Though, it makes sense to add checks for:

  • Check signature with corresponding public key.
  • Enforce length.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added tests for this constructor as well. Let me know what you think.


// Assumes this now silently skips accounts without signing keys
let witness_set = WalletCore::sign_public_message(self.0, &message, &sign_ids)
.expect("`WalletCore::sign_public_message() failed to produce a signature for a NativeTokenTransfer.");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.expect("`WalletCore::sign_public_message() failed to produce a signature for a NativeTokenTransfer.");
.expect("`WalletCore::sign_public_message()` failed to produce a signature for a NativeTokenTransfer.");

Comment thread wallet/src/lib.rs Outdated
#[must_use]
pub fn sign_privacy_message(
message: &nssa::privacy_preserving_transaction::Message,
proof: &Proof,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's have proof: Proof as parameter so there's no hidden cloning inside this function

Comment thread wallet/src/lib.rs
}

#[must_use]
pub fn sign_privacy_message(
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this indireciton here. Why do we need this wrapper of the witnesset constructor?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I separated the logic in sign_privacy_message to send_privacy_preserving_tx_with_pre_check since Keycard support will introduce more complex logic for signatures.

@jonesmarvin8 jonesmarvin8 changed the base branch from marvin/signature-bip340-fixes to main April 30, 2026 18:22
@jonesmarvin8 jonesmarvin8 marked this pull request as draft May 1, 2026 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants