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

Revert signed message prefix to be EIP191 compliant #372

Merged
merged 1 commit into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 1 addition & 10 deletions src/constants/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,4 @@ export const quaisymbol: string = '\u039e'; // "\uD835\uDF63";
*
* @category Constants
*/
export const MessagePrefix: string = '\x19Quai Signed Message:\n';

/**
* A constant for the [EIP-191](https://eips.ethereum.org/EIPS/eip-191) personal message prefix.
*
* (**i.e.** `"\\x19Ethereum Signed Message:\\n"`)
*
* @category Constants
*/
export const EthMessagePrefix: string = '\x19Ethereum Signed Message:\n';
export const MessagePrefix: string = '\x19Ethereum Signed Message:\n';
2 changes: 1 addition & 1 deletion src/hash/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*/

export { id } from './id.js';
export { hashMessage, verifyMessage, ethHashMessage, ethVerifyMessage } from './message.js';
export { hashMessage, verifyMessage } from './message.js';
export { solidityPacked, solidityPackedKeccak256, solidityPackedSha256 } from './solidity.js';
export { TypedDataEncoder, verifyTypedData } from './typed-data.js';

Expand Down
41 changes: 1 addition & 40 deletions src/hash/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { concat } from '../utils/index.js';
import { toUtf8Bytes } from '../encoding/index.js';

import type { SignatureLike } from '../crypto/index.js';
import { EthMessagePrefix } from '../constants/strings.js';

/**
* Computes the Quai Network equivalent of the [EIP-191](https://eips.ethereum.org/EIPS/eip-191) personal-sign message
* digest to sign.
Expand Down Expand Up @@ -55,42 +55,3 @@ export function verifyMessage(message: Uint8Array | string, sig: SignatureLike):
const digest = hashMessage(message);
return recoverAddress(digest, sig);
}

/**
* Computes the [EIP-191](https://eips.ethereum.org/EIPS/eip-191) personal-sign message digest to sign.
*
* This prefixes the message with {@link EthMessagePrefix | **EthMessagePrefix**} and the decimal length of `message` and
* computes the {@link keccak256 | **keccak256**} digest.
*
* If `message` is a string, it is converted to its UTF-8 bytes first. To compute the digest of a
* [**DataHexString**](../types-aliases/DataHex), it must be converted to [**bytes**](../functions/getBytes).
*
* This is the same as `hashMessage` except it uses `EthMessagePrefix` instead of `MessagePrefix` and is available for
* broader compatibility with EVM signing practices.
*
* @category Hash
* @param message
* @returns
*/
export function ethHashMessage(message: Uint8Array | string): string {
if (typeof message === 'string') {
message = toUtf8Bytes(message);
}
return keccak256(concat([toUtf8Bytes(EthMessagePrefix), toUtf8Bytes(String(message.length)), message]));
}

/**
* Return the address of the private key that produced the signature `sig` during signing for `message`.
*
* This is the same as `verifyMessage` except it uses `EthMessagePrefix` instead of `MessagePrefix` and is available for
* broader compatibility with EVM signing practices.
*
* @category Hash
* @param message - The message that was signed.
* @param sig - The signature to verify.
* @returns {string} The address of the signer.
*/
export function ethVerifyMessage(message: Uint8Array | string, sig: SignatureLike): string {
const digest = ethHashMessage(message);
return recoverAddress(digest, sig);
}
2 changes: 0 additions & 2 deletions src/quais.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,6 @@ export {
id,
hashMessage,
verifyMessage,
ethHashMessage,
ethVerifyMessage,
solidityPacked,
solidityPackedKeccak256,
solidityPackedSha256,
Expand Down
Loading