web-examples
web-examples copied to clipboard
Message signature function has some error.
in HelperUtils.ts, getSignParamsMessage function returns original message,
but this function returns an error if the message is exactly 20 bytes.
/**
* Gets message from various signing request methods by filtering out
* a value that is not an address (thus is a message).
* If it is a hex string, it gets converted to utf8 string
*/
export function getSignParamsMessage(params: string[]) {
const message = params.filter(p => !utils.isAddress(p))[0]
return convertHexToUtf8(message)
}
Because the address in params is filtered, the 20 Bytes message is treated as an address and the message is not returned.
As an example, suppose we sign the message Is this 20 bytes ???,
which is converted to 0x49732074686973203230206279746573203f3f3f,
and the isAddress function cannot distinguish whether this is a message or an address.
switch (request.method) {
case EIP155_SIGNING_METHODS.PERSONAL_SIGN:
case EIP155_SIGNING_METHODS.ETH_SIGN:
const message = getSignParamsMessage(request.params)
const signedMessage = await wallet.signMessage(message)
return formatJsonRpcResult(id, signedMessage)
I know the function is like this because the parameter order of PERSONAL_SIGN and ETH_SIGN are different,
but I think this part should be modified.
thx!