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

wallet: rm legacy eth_sign #5137

Merged
merged 2 commits into from
Oct 26, 2023
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
46 changes: 1 addition & 45 deletions src/model/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { TransactionRequest } from '@ethersproject/abstract-provider';
import { arrayify, BytesLike, Hexable } from '@ethersproject/bytes';
import { arrayify } from '@ethersproject/bytes';
import { HDNode } from '@ethersproject/hdnode';
import { Provider } from '@ethersproject/providers';
import { Transaction } from '@ethersproject/transactions';
Expand Down Expand Up @@ -41,7 +41,6 @@ import { EthereumAddress } from '@/entities';
import {
authenticateWithPIN,
authenticateWithPINAndCreateIfNeeded,
getExistingPIN,
} from '@/handlers/authentication';
import { saveAccountEmptyState } from '@/handlers/localstorage/accountLocal';
import {
Expand Down Expand Up @@ -404,49 +403,6 @@ export const signTransaction = async ({
}
};

export const signMessage = async (
message: BytesLike | Hexable | number,
existingWallet?: Wallet,
provider?: Provider
): Promise<null | {
result?: string;
error?: any;
}> => {
let isHardwareWallet = false;
try {
logger.info('wallet: signing message', { message });
const wallet =
existingWallet || (await loadWallet(undefined, true, provider));
// have to check inverse or we trigger unwanted BT permissions requests
if (!(wallet instanceof Wallet)) {
isHardwareWallet = true;
}
try {
if (!wallet) return null;
const result = await wallet.signMessage(arrayify(message));
return { result };
} catch (error) {
if (isHardwareWallet) {
setHardwareTXError(true);
} else {
Alert.alert(lang.t('wallet.transaction.alert.failed_sign_message'));
}
logger.error(new RainbowError('Failed to sign message'), { error });
return { error };
}
} catch (error) {
if (isHardwareWallet) {
setHardwareTXError(true);
} else {
Alert.alert(lang.t('wallet.transaction.alert.authentication'));
}
logger.error(new RainbowError('Failed to sign message due to auth'), {
error,
});
return null;
}
};

export const signPersonalMessage = async (
message: string | Uint8Array,
existingWallet?: Wallet,
Expand Down
6 changes: 0 additions & 6 deletions src/parsers/requests.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import {
isSignTypedData,
PERSONAL_SIGN,
SEND_TRANSACTION,
SIGN,
SIGN_TRANSACTION,
} from '@/utils/signingMethods';
import { isAddress } from '@ethersproject/address';
Expand Down Expand Up @@ -54,11 +53,6 @@ export const getRequestDisplayDetails = (
dappNetwork
);
}
if (payload.method === SIGN) {
const message = payload?.params?.find(p => !isAddress(p));
const result = getMessageDisplayDetails(message, timestampInMs);
return result;
}
if (payload.method === PERSONAL_SIGN) {
let message = payload?.params?.find(p => !isAddress(p));
try {
Expand Down
8 changes: 0 additions & 8 deletions src/screens/TransactionConfirmationScreen.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ import {
import { Network } from '@/helpers';
import { getAccountProfileInfo } from '@/helpers/accountInfo';
import { findWalletWithAccount } from '@/helpers/findWalletWithAccount';
import networkTypes from '@/helpers/networkTypes';
import {
useAccountSettings,
useCurrentNonce,
Expand All @@ -76,7 +75,6 @@ import {
import {
loadWallet,
sendTransaction,
signMessage,
signPersonalMessage,
signTransaction,
signTypedDataMessage,
Expand All @@ -102,13 +100,10 @@ import { useNativeAssetForNetwork } from '@/utils/ethereumUtils';
import { methodRegistryLookupAndParse } from '@/utils/methodRegistry';
import {
isMessageDisplayType,
isSignFirstParamType,
isSignSecondParamType,
isSignTypedData,
isTransactionDisplayType,
PERSONAL_SIGN,
SEND_TRANSACTION,
SIGN,
SIGN_TYPED_DATA,
SIGN_TYPED_DATA_V4,
} from '@/utils/signingMethods';
Expand Down Expand Up @@ -886,9 +881,6 @@ export default function TransactionConfirmationScreen() {
provider
);
switch (method) {
case SIGN:
response = await signMessage(message, existingWallet);
break;
case PERSONAL_SIGN:
response = await signPersonalMessage(message, existingWallet);
break;
Expand Down
11 changes: 1 addition & 10 deletions src/utils/signingMethods.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
export const PERSONAL_SIGN = 'personal_sign';
export const SEND_TRANSACTION = 'eth_sendTransaction';
export const SIGN = 'eth_sign';
export const SIGN_TRANSACTION = 'eth_signTransaction';
export const SIGN_TYPED_DATA = 'eth_signTypedData';
export const SIGN_TYPED_DATA_V4 = 'eth_signTypedData_v4';

const displayTypes = {
message: [PERSONAL_SIGN, SIGN, SIGN_TYPED_DATA, SIGN_TYPED_DATA_V4],
message: [PERSONAL_SIGN, SIGN_TYPED_DATA, SIGN_TYPED_DATA_V4],
transaction: [SEND_TRANSACTION, SIGN_TRANSACTION],
};
const firstParamSigning = [PERSONAL_SIGN];
const secondParamSigning = [SIGN, SIGN_TYPED_DATA, SIGN_TYPED_DATA_V4];

const allTypes = displayTypes.message.concat(displayTypes.transaction);

Expand All @@ -22,11 +19,5 @@ export const isMessageDisplayType = (method: string) =>
export const isTransactionDisplayType = (method: string) =>
displayTypes.transaction.includes(method);

export const isSignSecondParamType = (method: string) =>
secondParamSigning.includes(method);

export const isSignFirstParamType = (method: string) =>
firstParamSigning.includes(method);

export const isSignTypedData = (method: string) =>
method.startsWith(SIGN_TYPED_DATA);
2 changes: 0 additions & 2 deletions src/walletConnect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ export function parseRPCParams({
message?: string;
} {
switch (method) {
case RPCMethod.Sign:
case RPCMethod.PersonalSign: {
const [address, message] = params.sort(a => (isAddress(a) ? -1 : 1));
const isHex = isHexString(message);
Expand Down Expand Up @@ -227,7 +226,6 @@ export function getApprovedNamespaces(
}

const SUPPORTED_SIGNING_METHODS = [
RPCMethod.Sign,
RPCMethod.PersonalSign,
RPCMethod.SignTypedData,
RPCMethod.SignTypedDataV1,
Expand Down
3 changes: 1 addition & 2 deletions src/walletConnect/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export enum RPCMethod {
Sign = 'eth_sign',
PersonalSign = 'personal_sign',
SignTypedData = 'eth_signTypedData',
SignTypedDataV1 = 'eth_signTypedData_v1',
Expand All @@ -18,7 +17,7 @@ export enum RPCMethod {

export type RPCPayload =
| {
method: RPCMethod.Sign | RPCMethod.PersonalSign;
method: RPCMethod.PersonalSign;
params: [string, string];
}
| {
Expand Down