Skip to content

fix: remove base64 decode on SignMessage - #171

Merged
stanleyyconsensys merged 1 commit into
mainfrom
fix/sign-message
Jul 30, 2026
Merged

fix: remove base64 decode on SignMessage #171
stanleyyconsensys merged 1 commit into
mainfrom
fix/sign-message

Conversation

@stanleyyconsensys

@stanleyyconsensys stanleyyconsensys commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Explanation

This PR updates the Snap’s SEP-43 signMessage flow to treat the incoming message as UTF-8 text only (no base64 auto-detection/decoding), aligning what users see in the confirmation UI with what is signed via SEP-0053.

image

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and have prepared draft pull requests for clients and consumer packages to resolve them

message: '2zZDP1sa1BVBfLP7TeeMk3sUbaxAkUhBhDiNdrksaFo=',
signature:
'VA1+7hefNwv2NKScH6n+Sljj15kLAge+M2wE7fzFOf+L0MMbssA1mwfJZRyyrhBORQRle10X1Dxpx+UOI4EbDQ==',
'w2d2NipRh5bdv5SMfQnGRkj5AvZTjLRklACHObR11M5rNORxv0wmZG2o68gm1+12vVDcWptPZf3FjRTtx1qUBA==',

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.

we treat base64 string as string

@stanleyyconsensys stanleyyconsensys changed the title fix: only accept utf8 string fix: SignMessage only accept utf8 string Jul 30, 2026
@stanleyyconsensys stanleyyconsensys changed the title fix: SignMessage only accept utf8 string fix: remove base64 decode on SignMessage Jul 30, 2026

Copilot AI left a comment

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.

Pull request overview

This PR updates the Snap’s SEP-43 signMessage flow to treat the incoming message as UTF-8 text only (no base64 auto-detection/decoding), aligning what users see in the confirmation UI with what is signed via SEP-0053.

Changes:

  • Removed base64 auto-detection/decoding for message signing and verification; messages are always encoded as UTF-8 text before signing.
  • Tightened the keyring signMessage request validation and handler flow to accept/display the provided UTF-8 string as-is.
  • Updated tests and documentation to reflect the UTF-8-only behavior and adjusted reference vectors/fixtures accordingly.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/snap/src/utils/string.ts Removed base64-validation helper used for message auto-detection.
packages/snap/src/services/wallet/Wallet.ts Updated signMessage/verifyMessage to accept string only and always UTF-8 encode before signing/verifying.
packages/snap/src/services/wallet/Wallet.test.ts Updated SEP-0053 test vectors and removed byte-based message signing cases.
packages/snap/src/handlers/keyring/signMessage.ts Simplified handler to pass the message through unchanged for UI display and signing.
packages/snap/src/handlers/keyring/signMessage.test.ts Updated tests to use plain UTF-8 strings and assert UI renderContext matches the signed message.
packages/snap/src/handlers/keyring/keyring.test.ts Updated integration-style tests to pass UTF-8 string messages instead of base64 payloads.
packages/snap/src/handlers/keyring/api.ts Updated SignMessageRequestStruct to accept only Utf8StringStruct (no base64 union).
packages/snap/src/handlers/keyring/api.test.ts Expanded validation tests for various UTF-8 messages, including base64-looking strings treated as text.
packages/snap/docs/use-cases/keyring/signMessage.md Updated documentation to describe UTF-8-only message handling and confirmation behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/snap/src/services/wallet/Wallet.ts
renderContext: {
account,
message: this.#getUtf8Message(message),
message,

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.

the message is a utf string, so no need convert

@@ -1,13 +0,0 @@
import { string } from '@metamask/superstruct';
import { base64 } from '@metamask/utils';

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.

no longer need

@stanleyyconsensys
stanleyyconsensys merged commit 6b8949c into main Jul 30, 2026
11 checks passed
@stanleyyconsensys
stanleyyconsensys deleted the fix/sign-message branch July 30, 2026 13:43
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