Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: viem signing hex or uint8array #388

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

azf20
Copy link
Contributor

@azf20 azf20 commented Feb 14, 2025

What changed?

Allowed passing of a "hex" or bytes to "signMessage" for Viem & Viem-derived Wallet Providers

Why was this change implemented?

Currently Viem signing only supports strings. Viem itself can support Uint8Array & Hex (code, docs).

As the evmWalletProvider doesn't support the { raw: <input> }, we cast everything to a hex string based on the following logic and pass it into raw:

    const hexMessage =
      typeof message === "string" ? (isHex(message) ? message : toHex(message)) : message;

    return this.#walletClient.signMessage({
      account,
      message: { raw: hexMessage },
    });

This is to enable signing Hex messages as well as bytes (e.g. transaction hashes - this came up while trying to sign Gnosis Safe messages) - which otherwise get "hex'd" again by Viem when passed as string messages.

cc @escottalexander

@azf20 azf20 requested a review from murrlincoln as a code owner February 14, 2025 15:23
@cb-heimdall
Copy link

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

@0xRAG 0xRAG added enhancement New feature or request needs review PR / issue needs review banana typescript labels Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
banana enhancement New feature or request needs review PR / issue needs review typescript
Development

Successfully merging this pull request may close these issues.

3 participants