From b3a80307bf260205aead2da03fcd3a2bb2be4ff7 Mon Sep 17 00:00:00 2001 From: Gancho Radkov <43912948+ganchoradkov@users.noreply.github.com> Date: Tue, 14 May 2024 10:38:55 +0300 Subject: [PATCH] fix: encodes all `personal_sign` messages to hex (#2237) Co-authored-by: Gancho Radkov --- packages/ethers/src/client.ts | 9 ++++++--- packages/ethers5/src/client.ts | 6 ++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/packages/ethers/src/client.ts b/packages/ethers/src/client.ts index a579056f12..abeadc01fe 100644 --- a/packages/ethers/src/client.ts +++ b/packages/ethers/src/client.ts @@ -33,7 +33,10 @@ import { formatUnits, JsonRpcSigner, BrowserProvider, - Contract + Contract, + hexlify, + toUtf8Bytes, + isHexString } from 'ethers' import { EthersConstantsUtil, @@ -306,10 +309,10 @@ export class Web3Modal extends Web3ModalScaffold { if (!provider) { throw new Error('connectionControllerClient:signMessage - provider is undefined') } - + const hexMessage = isHexString(message) ? message : hexlify(toUtf8Bytes(message)) const signature = await provider.request({ method: 'personal_sign', - params: [message, this.getAddress()] + params: [hexMessage, this.getAddress()] }) return signature as `0x${string}` diff --git a/packages/ethers5/src/client.ts b/packages/ethers5/src/client.ts index adbd3fc359..caa5ab6d91 100644 --- a/packages/ethers5/src/client.ts +++ b/packages/ethers5/src/client.ts @@ -278,10 +278,12 @@ export class Web3Modal extends Web3ModalScaffold { if (!provider) { throw new Error('connectionControllerClient:signMessage - provider is undefined') } - + const hexMessage = utils.isHexString(message) + ? message + : utils.hexlify(utils.toUtf8Bytes(message)) const signature = await provider.request({ method: 'personal_sign', - params: [message, this.getAddress()] + params: [hexMessage, this.getAddress()] }) return signature as `0x${string}`