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

refactor: remove signHelper #2626

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
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
2 changes: 0 additions & 2 deletions src/background/controller/provider/rpcFlow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ const flowContext = flow
flow.requestedApproval = false;
// only unlock notification if current flow is an approval flow
notificationService.unLock();
keyringService.resetResend();
}
return gnosisController.watchMessage({
address: safeMessage.safeAddress,
Expand Down Expand Up @@ -385,7 +384,6 @@ export default (request: ProviderRequest) => {
flow.requestedApproval = false;
// only unlock notification if current flow is an approval flow
notificationService.unLock();
keyringService.resetResend();
}
});
};
9 changes: 0 additions & 9 deletions src/background/controller/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2630,15 +2630,6 @@ export class WalletController extends BaseController {
return null;
};

resendWalletConnect = (account: Account) => {
const keyringType = KEYRING_CLASS.WALLETCONNECT;
const keyring: WalletConnectKeyring = this._getKeyringByType(keyringType);
if (keyring) {
return keyring.resend(account);
}
return null;
};

getWalletConnectSessionStatus = (address: string, brandName: string) => {
const keyringType =
brandName === KEYRING_CLASS.Coinbase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
AccessListEIP2930Transaction,
} from '@ethereumjs/tx';
import { EVENTS } from '@/constant';
import { SignHelper } from '../helper';
import { BitBox02BridgeInterface } from './bitbox02-bridge-interface';

const hdPathString = "m/44'/60'/0'/0";
Expand All @@ -28,9 +27,6 @@ class BitBox02Keyring extends EventEmitter {
unlockedAccount = 0;
paths = {};
hdPath = '';
signHelper = new SignHelper({
errorEventName: EVENTS.COMMON_HARDWARE.REJECTED,
});

bridge!: BitBox02BridgeInterface;

Expand Down Expand Up @@ -66,10 +62,6 @@ class BitBox02Keyring extends EventEmitter {
return Promise.resolve();
}

resend() {
this.signHelper.resend();
}

async init() {
await this.bridge.init(this.hdPath);
}
Expand Down Expand Up @@ -178,77 +170,73 @@ class BitBox02Keyring extends EventEmitter {

// tx is an instance of the ethereumjs-transaction class.
async signTransaction(address, tx: TypedTransaction) {
return this.signHelper.invoke(async () => {
await this.init();

let result;
const txData: JsonTx = {
to: tx.to!.toString(),
value: `0x${tx.value.toString('hex')}`,
data: this._normalize(tx.data),
nonce: `0x${tx.nonce.toString('hex')}`,
gasLimit: `0x${tx.gasLimit.toString('hex')}`,
};
await this.init();

if (tx instanceof FeeMarketEIP1559Transaction) {
result = await this.bridge.ethSign1559Transaction(
this._pathFromAddress(address),
tx.toJSON()
);
txData.type = '0x02';
txData.maxPriorityFeePerGas = `0x${tx.maxPriorityFeePerGas.toString(
'hex'
)}`;
txData.maxFeePerGas = `0x${tx.maxFeePerGas.toString('hex')}`;
} else if (
tx instanceof Transaction ||
tx instanceof AccessListEIP2930Transaction
) {
result = await this.bridge.ethSignTransaction(
tx.common.chainIdBN().toNumber(),
this._pathFromAddress(address),
tx.toJSON()
);
txData.gasPrice = `0x${tx.gasPrice.toString('hex')}`;
}
txData.chainId = `0x${tx.common.chainIdBN().toString('hex')}`;
txData.r = result.r;
txData.s = result.s;
txData.v = result.v;
const signedTx = TransactionFactory.fromTxData(txData);
const addressSignedWith = ethUtil.toChecksumAddress(
signedTx.getSenderAddress().toString()
let result;
const txData: JsonTx = {
to: tx.to!.toString(),
value: `0x${tx.value.toString('hex')}`,
data: this._normalize(tx.data),
nonce: `0x${tx.nonce.toString('hex')}`,
gasLimit: `0x${tx.gasLimit.toString('hex')}`,
};

if (tx instanceof FeeMarketEIP1559Transaction) {
result = await this.bridge.ethSign1559Transaction(
this._pathFromAddress(address),
tx.toJSON()
);
const correctAddress = ethUtil.toChecksumAddress(address);
if (addressSignedWith !== correctAddress) {
throw new Error('signature doesnt match the right address');
}
return signedTx;
});
txData.type = '0x02';
txData.maxPriorityFeePerGas = `0x${tx.maxPriorityFeePerGas.toString(
'hex'
)}`;
txData.maxFeePerGas = `0x${tx.maxFeePerGas.toString('hex')}`;
} else if (
tx instanceof Transaction ||
tx instanceof AccessListEIP2930Transaction
) {
result = await this.bridge.ethSignTransaction(
tx.common.chainIdBN().toNumber(),
this._pathFromAddress(address),
tx.toJSON()
);
txData.gasPrice = `0x${tx.gasPrice.toString('hex')}`;
}
txData.chainId = `0x${tx.common.chainIdBN().toString('hex')}`;
txData.r = result.r;
txData.s = result.s;
txData.v = result.v;
const signedTx = TransactionFactory.fromTxData(txData);
const addressSignedWith = ethUtil.toChecksumAddress(
signedTx.getSenderAddress().toString()
);
const correctAddress = ethUtil.toChecksumAddress(address);
if (addressSignedWith !== correctAddress) {
throw new Error('signature doesnt match the right address');
}
return signedTx;
}

signMessage(withAccount: string, data: string): Promise<any> {
return this.signPersonalMessage(withAccount, data);
}

async signPersonalMessage(withAccount, message) {
return this.signHelper.invoke(async () => {
await this.init();
await this.init();

const result = await this.bridge.ethSignMessage(
1,
this._pathFromAddress(withAccount),
message
);
const sig = Buffer.concat([
Buffer.from(result.r),
Buffer.from(result.s),
Buffer.from(result.v),
]);

const sigHex = `0x${sig.toString('hex')}`;
return sigHex;
});
const result = await this.bridge.ethSignMessage(
1,
this._pathFromAddress(withAccount),
message
);
const sig = Buffer.concat([
Buffer.from(result.r),
Buffer.from(result.s),
Buffer.from(result.v),
]);

const sigHex = `0x${sig.toString('hex')}`;
return sigHex;
}

async signTypedData(withAccount, data, options: any = {}) {
Expand All @@ -257,32 +245,30 @@ class BitBox02Keyring extends EventEmitter {
`Only version 4 of typed data signing is supported. Provided version: ${options.version}`
);
}
return this.signHelper.invoke(async () => {
await this.init();
const result = await this.bridge.ethSignTypedMessage(
data.domain.chainId || 1,
this._pathFromAddress(withAccount),
data
);
const sig = Buffer.concat([
Buffer.from(result.r),
Buffer.from(result.s),
Buffer.from(result.v),
]);
const sigHex = `0x${sig.toString('hex')}`;
const addressSignedWith = sigUtil.recoverTypedSignature({
data,
signature: sigHex,
version: options.version,
});
if (
ethUtil.toChecksumAddress(addressSignedWith) !==
ethUtil.toChecksumAddress(withAccount)
) {
throw new Error('The signature doesnt match the right address');
}
return sigHex;
await this.init();
const result = await this.bridge.ethSignTypedMessage(
data.domain.chainId || 1,
this._pathFromAddress(withAccount),
data
);
const sig = Buffer.concat([
Buffer.from(result.r),
Buffer.from(result.s),
Buffer.from(result.v),
]);
const sigHex = `0x${sig.toString('hex')}`;
const addressSignedWith = sigUtil.recoverTypedSignature({
data,
signature: sigHex,
version: options.version,
});
if (
ethUtil.toChecksumAddress(addressSignedWith) !==
ethUtil.toChecksumAddress(withAccount)
) {
throw new Error('The signature doesnt match the right address');
}
return sigHex;
}

exportAccount(): Promise<any> {
Expand Down
Loading
Loading