Skip to content

Conversation

felipemadero
Copy link
Contributor

@felipemadero felipemadero commented Sep 25, 2025

Why this should be merged

This PR introduces a ForceSignHash wallet option that enables hash-based transaction signing instead of full transaction signing. This feature is essential for:

  1. Testing flexibility: Enables testing scenarios where hash-based signing is preferred or required
  2. Network compatibility: CubeSigner API currently lacks network options support beyond mainnet/fuji, making hash signing necessary for other network configurations
  3. Future-proofing: Provides infrastructure for advanced signing scenarios while maintaining backward compatibility

The feature is implemented as an optional wallet parameter, ensuring existing functionality remains unchanged while providing the flexibility needed for specializeduse cases.

How this works

The implementation adds a new common.WithForceSignHash() option that can be passed to any wallet transaction method:

  // Enable force sign hash for a specific transaction
  tx, err := wallet.IssueBaseTx(outputs, common.WithForceSignHash())
  // Apply force sign hash to all operations on a wallet instance
  walletWithOptions := pwallet.WithOptions(wallet, common.WithForceSignHash())

Technical Implementation:

  • Added forceSignHash field to common.Options struct with corresponding getter/setter methods
  • Updated both P-chain and X-chain signers to accept ...common.Option parameters
  • Modified visitor structs to include forceSignHash field and use conditional signing logic
  • Created WithOptions wrapper functions for signers to apply default options
  • Fixed wallet WithOptions implementations to properly propagate options to signers

Signing Logic:

  var sig []byte
  if forceSignHash {
      sig, err = signer.SignHash(unsignedHash)  // Hash-based signing
  } else {
      sig, err = signer.Sign(unsignedBytes)     // Full transaction signing
  }

How this was tested

  • Unit tests
  • Example for testing cubesigner on a local network

Need to be documented in RELEASES.md?

This commit introduces a wallet option to enable force sign hash functionality
across P-chain and X-chain transaction signing.

Changes:
- Add ForceSignHash option to common wallet options
- Update P-chain and X-chain signers to support options parameter
- Implement forceSignHash field in visitor structs
- Create WithOptions wrappers for both P-chain and X-chain signers
- Fix wallet WithOptions implementations to return signers with options applied
- Add force sign hash logic to use SignHash() vs Sign() based on option

The force sign hash option can now be used by passing
common.WithForceSignHash() to any wallet transaction method.
@Copilot Copilot AI review requested due to automatic review settings September 25, 2025 16:45
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a ForceSignHash wallet option that enables hash-based transaction signing instead of full transaction signing for both P-chain and X-chain wallets. This feature provides testing flexibility and network compatibility for scenarios where CubeSigner API lacks network options beyond mainnet/fuji.

  • Adds a new ForceSignHash option to the common options structure
  • Updates both P-chain and X-chain signers to support the new signing mode
  • Implements conditional signing logic that chooses between hash-based and full transaction signing

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
wallet/subnet/primary/common/options.go Adds forceSignHash field and WithForceSignHash option
wallet/chain/x/wallet_with_options.go Updates Signer method to propagate options
wallet/chain/x/wallet.go Passes options to SignUnsigned function
wallet/chain/x/signer/with_options.go Creates new wrapper for signers with default options
wallet/chain/x/signer/visitor.go Implements conditional signing logic for X-chain
wallet/chain/x/signer/signer.go Updates Sign interface to accept options
wallet/chain/p/wallet/with_options.go Updates Signer method to propagate options
wallet/chain/p/signer/with_options.go Creates new wrapper for signers with default options
wallet/chain/p/signer/visitor.go Updates all transaction types to use forceSignHash
wallet/chain/p/signer/signer.go Updates Sign interface to accept options

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

1 participant