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

Fix eth_sign #2626

Merged
merged 5 commits into from
Dec 6, 2021
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
21 changes: 21 additions & 0 deletions e2e/hardhatTransactionFlow.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { exec } from 'child_process';
import { JsonRpcProvider } from '@ethersproject/providers';
import { Wallet } from '@ethersproject/wallet';
import WalletConnect from '@walletconnect/client';
import { convertUtf8ToHex } from '@walletconnect/utils';
import { ethers } from 'ethers';
import * as Helpers from './helpers';

Expand Down Expand Up @@ -288,6 +289,26 @@ describe('Hardhat Transaction Flow', () => {
}
});

it('Should be able to sign eth_sign messages via WC', async () => {
const message = `My email is [email protected]`;
const hexMsg = convertUtf8ToHex(message);
const msgParams = [account, hexMsg];
const result = connector.signMessage(msgParams);
await Helpers.checkIfVisible('wc-request-sheet');
await Helpers.waitAndTap('wc-confirm-action-button');
await Helpers.delay(1000);

if (!result) throw new Error('WC Connection failed');
const signature = await result;
// verify signature
if (
signature !==
'0x141d62e1aaa2202ededb07f1684ef6d3d9958d334713010ea91df3831e3a3c99303a83f334d1e5e935c4edd7146a2f3f4301c5d509ccfeffd55f5db4e971958b1c'
) {
throw new Error('WC eth_sign failed');
}
});

it('Should be able to sign typed data messages via WC', async () => {
const msg = {
types: {
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
"@ethersproject/providers": "5.4.0",
"@ethersproject/random": "5.4.0",
"@ethersproject/shims": "5.4.0",
"@ethersproject/signing-key": "5.4.0",
"@ethersproject/solidity": "5.4.0",
"@ethersproject/transactions": "5.4.0",
"@ethersproject/units": "5.4.0",
Expand Down
13 changes: 3 additions & 10 deletions src/model/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import { TransactionRequest } from '@ethersproject/abstract-provider';
import {
arrayify,
BytesLike,
Hexable,
joinSignature,
} from '@ethersproject/bytes';
import { arrayify, BytesLike, Hexable } from '@ethersproject/bytes';
import { HDNode } from '@ethersproject/hdnode';
import { Provider } from '@ethersproject/providers';
import { SigningKey } from '@ethersproject/signing-key';
import { Transaction } from '@ethersproject/transactions';
import { Wallet } from '@ethersproject/wallet';
import {
Expand Down Expand Up @@ -329,9 +323,8 @@ export const signMessage = async (
existingWallet || (await loadWallet(undefined, true, provider));
try {
if (!wallet) return null;
const signingKey = new SigningKey(wallet.privateKey);
const sigParams = await signingKey.signDigest(arrayify(message));
return { result: joinSignature(sigParams) };
const result = await wallet.signMessage(arrayify(message));
return { result };
} catch (error) {
Alert.alert(lang.t('wallet.transaction.alert.failed_sign_message'));
logger.sentry('Error', error);
Expand Down
12 changes: 0 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1926,18 +1926,6 @@
resolved "https://registry.yarnpkg.com/@ethersproject/shims/-/shims-5.4.0.tgz#7c243cea96a8ffdbc04bb031cd55e7897431276b"
integrity sha512-J/M1oudCBPw4T8pBoE8wO65dIJruGBSZ1HyKVSygO3rF95Sq1LasQFEfKNzJl2nJP20ni4eXTNlEdKFKoVxnpw==

"@ethersproject/[email protected]":
version "5.4.0"
resolved "https://registry.yarnpkg.com/@ethersproject/signing-key/-/signing-key-5.4.0.tgz#2f05120984e81cf89a3d5f6dec5c68ee0894fbec"
integrity sha512-q8POUeywx6AKg2/jX9qBYZIAmKSB4ubGXdQ88l40hmATj29JnG5pp331nAWwwxPn2Qao4JpWHNZsQN+bPiSW9A==
dependencies:
"@ethersproject/bytes" "^5.4.0"
"@ethersproject/logger" "^5.4.0"
"@ethersproject/properties" "^5.4.0"
bn.js "^4.11.9"
elliptic "6.5.4"
hash.js "1.1.7"

"@ethersproject/[email protected]", "@ethersproject/signing-key@^5.4.0", "@ethersproject/signing-key@^5.5.0":
version "5.5.0"
resolved "https://registry.yarnpkg.com/@ethersproject/signing-key/-/signing-key-5.5.0.tgz#2aa37169ce7e01e3e80f2c14325f624c29cedbe0"
Expand Down