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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions typescript/agentkit/src/wallet-providers/viemWalletProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
ReadContractParameters,
ReadContractReturnType,
parseEther,
isHex,
toHex,
} from "viem";
import { EvmWalletProvider } from "./evmWalletProvider";
import { Network } from "../network";
Expand Down Expand Up @@ -64,13 +66,19 @@ export class ViemWalletProvider extends EvmWalletProvider {
* @param message - The message to sign.
* @returns The signed message.
*/
async signMessage(message: string): Promise<`0x${string}`> {
async signMessage(message: string | Uint8Array): Promise<`0x${string}`> {
const account = this.#walletClient.account;
if (!account) {
throw new Error("Account not found");
}

return this.#walletClient.signMessage({ account, message });
const _message =
typeof message === "string" ? (isHex(message) ? message : toHex(message)) : message;

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

/**
Expand Down
Loading