Skip to content

Commit

Permalink
fix: encodes all personal_sign messages to hex (#2237)
Browse files Browse the repository at this point in the history
Co-authored-by: Gancho Radkov <ganchoradkov@gmail.com>
  • Loading branch information
ganchoradkov and Gancho Radkov committed May 14, 2024
1 parent 29998c9 commit b3a8030
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 6 additions & 3 deletions packages/ethers/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ import {
formatUnits,
JsonRpcSigner,
BrowserProvider,
Contract
Contract,
hexlify,
toUtf8Bytes,
isHexString
} from 'ethers'
import {
EthersConstantsUtil,
Expand Down Expand Up @@ -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}`
Expand Down
6 changes: 4 additions & 2 deletions packages/ethers5/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
Expand Down

0 comments on commit b3a8030

Please sign in to comment.