Skip to content

feat(WalletBase): add SignMessage(string) convenience overload#274

Open
mstevens843 wants to merge 1 commit into
magicblock-labs:mainfrom
mstevens843:feat/sign-message-string-overload
Open

feat(WalletBase): add SignMessage(string) convenience overload#274
mstevens843 wants to merge 1 commit into
magicblock-labs:mainfrom
mstevens843:feat/sign-message-string-overload

Conversation

@mstevens843
Copy link
Copy Markdown
Contributor

@mstevens843 mstevens843 commented Apr 8, 2026

Status Type ⚠️ Core Change Issue
Ready Feature Yes #273

Problem

SignMessage() only accepts byte[]. Every caller must manually convert strings via Encoding.UTF8.GetBytes() before signing, adding unnecessary boilerplate for the
most common use case — signing human-readable messages.

Discovered while building a Unity MWA example app on Solana Seeker hardware with Seed Vault
(unity-solana-mwa-example). Documented as Point 6 in #273.

Solution

Added SignMessage(string message) overload to IWalletBase and WalletBase that handles UTF-8 encoding internally, delegating to the existing SignMessage(byte[]).

All derived wallet classes (InGameWallet, SolanaMobileWalletAdapter, SolanaWalletAdapterWebGL, PhantomDeepLink, SolanaWalletAdapter) inherit the new overload
automatically — zero changes required in implementations.

Before & After Screenshots

BEFORE:

  var payload = Encoding.UTF8.GetBytes("Hello from Unity");                                                                                                             
  var signature = await Web3.Wallet.SignMessage(payload);

AFTER:

  var signature = await Web3.Wallet.SignMessage("Hello from Unity");                                                                                                  

Other changes (e.g. bug fixes, small refactors)

None. Purely additive — no existing signatures or behavior modified.

Deploy Notes

No new scripts or dependencies. Drop-in enhancement to existing API surface.

Summary by CodeRabbit

  • New Features
    • Sign plain text directly (UTF-8) — users can sign strings without manual conversion.
  • Improvements
    • Null input is validated and yields a clear argument error for ambiguous nulls.
    • Behavior remains backward-compatible with existing binary signing workflows.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 8, 2026

Warning

Rate limit exceeded

@mstevens843 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 41 minutes and 9 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: ebaf7f8f-c3bf-46ff-ade6-2c8629d50b15

📥 Commits

Reviewing files that changed from the base of the PR and between 3f03ca1 and 6b9886f.

📒 Files selected for processing (2)
  • Runtime/codebase/WalletBaseExtensions.cs
  • Runtime/codebase/WalletBaseExtensions.cs.meta

Walkthrough

Added a UTF‑8 string overload for SignMessage: new Task<byte[]> SignMessage(string message) on IWalletBase and a WalletBase implementation that validates null, encodes to UTF‑8, and delegates to the existing SignMessage(byte[] message).

Changes

Cohort / File(s) Summary
SignMessage string overload
Runtime/codebase/IWalletBase.cs, Runtime/codebase/WalletBase.cs
Interface: added Task<byte[]> SignMessage(string message). Base class: added public implementation that throws ArgumentNullException for null, encodes the input as UTF‑8 (adds using System.Text;), and forwards to the existing SignMessage(byte[] message). Documentation added clarifying overload ambiguity for null literals.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely summarizes the main change: adding a SignMessage(string) convenience overload to WalletBase.
Description check ✅ Passed The description follows the template structure with all key sections completed: status/type/issue, clear problem statement, detailed solution, before/after code examples, and deployment notes.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Runtime/codebase/WalletBase.cs`:
- Around line 273-277: The new WalletBase.SignMessage(string) overload can cause
compile-time ambiguity when callers invoke SignMessage(null) because null is
convertible to both string and byte[]; to fix, remove the ambiguous overload or
rename it to a non-conflicting public name (e.g., WalletBase.SignUtf8Message)
and update any internal call sites to use the new name; if you must keep the
overload, add clear XML documentation on WalletBase.SignMessage(string) warning
about the null ambiguity and prefer the byte[] overload, but the preferred fix
is renaming to SignUtf8Message to avoid CS0121 for external consumers.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: e429ab7d-1543-4f2f-845a-5b5e7f289c73

📥 Commits

Reviewing files that changed from the base of the PR and between 2d4d903 and dcbbef1.

📒 Files selected for processing (1)
  • Runtime/codebase/WalletBase.cs

Comment thread Runtime/codebase/WalletBase.cs Outdated
@mstevens843
Copy link
Copy Markdown
Contributor Author

Pushed a doc-only update for the CodeRabbit nitpick. Kept the SignMessage(string) overload since it follows the standard C# overload convention developers expect, and the runtime null guard already throws ArgumentNullException. Added an XML block on the method explaining that a literal SignMessage(null)
is ambiguous (CS0121) and how to disambiguate via cast. No API change, no rename.

Ready for review.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@Runtime/codebase/IWalletBase.cs`:
- Around line 108-113: Remove the newly added string overload from the public
interface IWalletBase and provide it as an extension method (or keep it only on
WalletBase) so external implementers are not forced to implement it;
specifically, delete Task<byte[]> SignMessage(string message) from IWalletBase
and add a public static Task<byte[]> SignMessage(this IWalletBase wallet, string
message) extension that encodes the string to UTF‑8 and delegates to the
existing SignMessage(byte[] ...) method, or alternatively implement the string
overload as an instance method only on the concrete WalletBase class to keep the
interface unchanged.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 68c75a5b-a927-43a4-8c16-1e23aa03ffaf

📥 Commits

Reviewing files that changed from the base of the PR and between dcbbef1 and 3f03ca1.

📒 Files selected for processing (2)
  • Runtime/codebase/IWalletBase.cs
  • Runtime/codebase/WalletBase.cs

Comment thread Runtime/codebase/IWalletBase.cs Outdated
…Base

Adds a UTF-8 string convenience overload via an extension method on
IWalletBase, so callers can sign plain strings without manual UTF-8
encoding. Implemented as an extension to avoid the interface-expansion
breakage CodeRabbit flagged on the prior version (a required member on
IWalletBase would have forced every external implementer to add the
method to their own classes).

Instance methods take priority over extension methods, so
wallet.SignMessage(null) still binds unambiguously to SignMessage(byte[])
and the runtime null guard already handles that path. The string
extension throws ArgumentNullException for null inputs.
@mstevens843 mstevens843 force-pushed the feat/sign-message-string-overload branch from 3f03ca1 to 6b9886f Compare April 28, 2026 02:02
@mstevens843
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 28, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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.

1 participant