Skip to content

feat(message-signing): Add AddressPath type and refactor to use Asset/PubkeyInfo#231

Merged
CharlVS merged 3 commits intodevfrom
feat/message-signing-address-path
Oct 5, 2025
Merged

feat(message-signing): Add AddressPath type and refactor to use Asset/PubkeyInfo#231
CharlVS merged 3 commits intodevfrom
feat/message-signing-address-path

Conversation

@CharlVS
Copy link
Copy Markdown
Collaborator

@CharlVS CharlVS commented Oct 2, 2025

Summary

This PR introduces the AddressPath type and refactors the message signing functionality to use high-level types (Asset and PubkeyInfo) instead of low-level string parameters.

Changes

1. New AddressPath Class

  • Location: packages/komodo_defi_rpc_methods/lib/src/common_structures/hd_wallet/address_path.dart
  • Represents HD wallet address paths per API documentation
  • Supports both derivation path format (m/44'/141'/0'/0/0) and component format (accountId/chain/addressId)
  • Immutable with @immutable annotation
  • Includes fromJson(), toJson(), proper equality, and hashCode

2. Refactored SignMessageRequest

Before:

SignMessageRequest(
  coin: coin,
  message: message,
  derivationPath: derivationPath,
  accountId: accountId,
  chain: chain,
  addressId: addressId,
)

After:

SignMessageRequest(
  coin: coin,
  message: message,
  addressPath: AddressPath.derivationPath(path),
)

3. Updated MessageSigningManager (SDK Layer)

Before:

await signMessage(
  coin: 'BTC',
  message: 'Hello',
  address: 'addr123',
  derivationPath: "m/44'/0'/0'/0/0",
);

After:

final pubkeys = await sdk.pubkeys.getPubkeys(asset);
await signMessage(
  asset: asset,
  addressInfo: pubkeys.keys.first,
  message: 'Hello',
);

4. Updated Components

  • MessageSigningMethodsNamespace: Simplified to use AddressPath
  • RpcMethodsLibrary: Updated to use new signature
  • SDK example widget: Updated to use new API
  • Removed deprecated individual HD parameters (no backward compatibility needed)

Benefits

Type Safety: Using Asset and PubkeyInfo prevents runtime errors
Cleaner API: Fewer parameters, more intuitive usage
Better Abstraction: SDK layer properly abstracts RPC complexity
Consistency: Matches patterns used by other SDK managers
Automatic HD Handling: Derivation paths extracted from PubkeyInfo
API Compliant: Fully compliant with KDF API documentation

Testing

  • ✅ No linter errors
  • ✅ No compilation errors
  • ✅ All files properly formatted
  • ✅ API documentation complete
  • ✅ Example code updated and working

Related

Part of the message signing feature implementation for the Komodo Wallet.


Note

Adds AddressPath type and refactors message signing to use AddressPath plus Asset/PubkeyInfo, removing legacy HD params and updating SDK and example.

  • Message Signing API:
    • Refactor SignMessageRequest to accept AddressPath (address) instead of separate derivationPath/accountId/chain/addressId.
    • Update MessageSigningMethodsNamespace and rpc_methods_library to use addressPath.
  • Common Structures:
    • Add hd_wallet/AddressPath union type with fromJson/toJson and export via common_structures.dart.
  • SDK:
    • Update MessageSigningManager to accept Asset and PubkeyInfo, auto-deriving AddressPath from PubkeyInfo.
    • Example AssetHeaderWidget updated to new API (uses asset and pubkeys without manual address/derivation fields).
  • Cleanup:
    • Remove custom_token_storage_interface.dart.
    • Minor export order adjustment in _coins_config_index.dart.

Written by Cursor Bugbot for commit 69b99d4. This will update automatically on new commits. Configure here.

…/PubkeyInfo

- Add AddressPath class for HD wallet address path handling
  - Supports both derivation path and component-based formats
  - Immutable with proper equality and JSON serialization
  - Documented with API reference links

- Refactor SignMessageRequest to use AddressPath
  - Simplified from 4 optional parameters to single AddressPath
  - Better type safety and API compliance
  - Maintains full HD and non-HD wallet support

- Update MessageSigningManager to use high-level types
  - Replace String coin parameter with Asset type
  - Replace individual derivation params with PubkeyInfo
  - Automatic conversion from PubkeyInfo to AddressPath
  - Use asset.id.id for correct coin identifier

- Update example and namespace implementations
  - Remove deprecated individual HD parameters
  - Add comprehensive documentation and examples
  - Ensure consistent API across RPC and SDK layers

This provides a cleaner, more type-safe API that better abstracts
the underlying RPC complexity while maintaining full compatibility
with the Komodo DeFi Framework message signing endpoints.
Copilot AI review requested due to automatic review settings October 2, 2025 12:16
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 2, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

✨ Finishing touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/message-signing-address-path

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

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 the AddressPath type and refactors message signing functionality to use high-level types (Asset and PubkeyInfo) instead of low-level string parameters, providing better type safety and a cleaner API.

  • Introduces AddressPath class to handle HD wallet derivation paths with both full path and component formats
  • Refactors MessageSigningManager to use Asset and PubkeyInfo parameters instead of string-based coin/address parameters
  • Updates RPC layer to use the new AddressPath type, simplifying parameter handling

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/komodo_defi_sdk/lib/src/message_signing/message_signing_manager.dart Refactored to use Asset/PubkeyInfo parameters and AddressPath conversion
packages/komodo_defi_sdk/example/lib/widgets/asset/asset_header_widget.dart Updated to use new SDK API with Asset and PubkeyInfo
packages/komodo_defi_rpc_methods/lib/src/rpc_methods_library.dart Simplified to use AddressPath parameter
packages/komodo_defi_rpc_methods/lib/src/rpc_methods/utility/message_signing_rpc_namespace.dart Updated to use AddressPath with comprehensive documentation
packages/komodo_defi_rpc_methods/lib/src/rpc_methods/utility/message_signing.dart Refactored to use AddressPath instead of individual HD parameters
packages/komodo_defi_rpc_methods/lib/src/common_structures/hd_wallet/address_path.dart New AddressPath class supporting both derivation path and component formats
packages/komodo_defi_rpc_methods/lib/src/common_structures/common_structures.dart Added export for new AddressPath class

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

@CharlVS CharlVS self-assigned this Oct 2, 2025
- Remove custom_token_storage_interface.dart (unused)
- Alphabetically sort exports in _coins_config_index.dart
@CharlVS CharlVS requested a review from takenagain October 2, 2025 12:21
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

- Replace manual immutability implementation with freezed
- Use union types for derivationPath and components constructors
- Leverage freezed's when/maybeWhen for type-safe pattern matching
- Maintain custom fromJson/toJson for API compatibility
- Reduce boilerplate: ~40 lines vs ~135 lines manually
- Keep all existing APIs and behavior unchanged

Benefits:
- Automatic copyWith, equality, hashCode, toString generation
- Type-safe exhaustive pattern matching with when/maybeWhen
- Better maintainability and less error-prone
- Consistent with freezed usage across the codebase
params['address'] = address;
// Add HD address path if provided
if (addressPath != null) {
params['address'] = addressPath!.toJson();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: Empty Derivation Path Included in Request

The SignMessageRequest now includes empty derivation paths ({"derivation_path": ""}) in its JSON payload when addressInfo.derivationPath is an empty string. This differs from the previous implementation, which used an isNotEmpty check to omit such paths, and may lead to API errors.

Additional Locations (1)

Fix in Cursor Fix in Web

Copy link
Copy Markdown
Contributor

@takenagain takenagain left a comment

Choose a reason for hiding this comment

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

LGTM, WOMM. The removed file is confirmed to be unreferenced, and absent from the index that could make it visible.

/// ```
Future<String> signMessage({
required String coin,
required Asset asset,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion: AssetId seems more appropriate here, seeing as asset.id.id is the only referenced field.

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.

Good point, thanks!

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.

@codex please implement

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Summary

Testing

  • ⚠️ dart format packages/komodo_defi_sdk/lib/src/message_signing/message_signing_manager.dart packages/komodo_defi_sdk/example/lib/widgets/asset/asset_header_widget.dart (emitted analysis include warnings because the shared analysis options reference unavailable packages, but formatting completed successfully)

View task →

@CharlVS CharlVS merged commit f8c83ba into dev Oct 5, 2025
5 of 9 checks passed
@CharlVS CharlVS deleted the feat/message-signing-address-path branch October 5, 2025 13:50
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