Skip to content

Commit 9652802

Browse files
committed
feat(sdk-coin-bsc): added support for mpcv2 in recovery
TICKET: WIN-4618
1 parent c4cd6c8 commit 9652802

File tree

6 files changed

+712
-51
lines changed

6 files changed

+712
-51
lines changed

modules/abstract-eth/src/abstractEthLikeNewCoins.ts

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ export type RecoverOptions = {
253253
intendedChain?: string;
254254
common?: EthLikeCommon.default;
255255
derivationSeed?: string;
256+
apiKey?: string;
256257
} & TSSRecoverOptions;
257258

258259
export type GetBatchExecutionInfoRT = {
@@ -531,12 +532,15 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
531532
* @param {String} address - the ETHLike address
532533
* @returns {BigNumber} address balance
533534
*/
534-
async queryAddressBalance(address: string): Promise<any> {
535-
const result = await this.recoveryBlockchainExplorerQuery({
536-
module: 'account',
537-
action: 'balance',
538-
address: address,
539-
});
535+
async queryAddressBalance(address: string, apiKey?: string): Promise<any> {
536+
const result = await this.recoveryBlockchainExplorerQuery(
537+
{
538+
module: 'account',
539+
action: 'balance',
540+
address: address,
541+
},
542+
apiKey
543+
);
540544
// throw if the result does not exist or the result is not a valid number
541545
if (!result || !result.result || isNaN(result.result)) {
542546
throw new Error(`Could not obtain address balance for ${address} from the explorer, got: ${result.result}`);
@@ -837,15 +841,18 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
837841
* @param {string} address
838842
* @returns {Promise<number>}
839843
*/
840-
async getAddressNonce(address: string): Promise<number> {
844+
async getAddressNonce(address: string, apiKey?: string): Promise<number> {
841845
// Get nonce for backup key (should be 0)
842846
let nonce = 0;
843847

844-
const result = await this.recoveryBlockchainExplorerQuery({
845-
module: 'account',
846-
action: 'txlist',
847-
address,
848-
});
848+
const result = await this.recoveryBlockchainExplorerQuery(
849+
{
850+
module: 'account',
851+
action: 'txlist',
852+
address,
853+
},
854+
apiKey
855+
);
849856
if (!result || !Array.isArray(result.result)) {
850857
throw new Error('Unable to find next nonce from Etherscan, got: ' + JSON.stringify(result));
851858
}
@@ -1932,7 +1939,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
19321939
}
19331940
}
19341941

1935-
private async getGasValues(params: RecoverOptions): Promise<{ gasLimit: number; gasPrice: Buffer }> {
1942+
protected async getGasValues(params: RecoverOptions): Promise<{ gasLimit: number; gasPrice: Buffer }> {
19361943
const gasLimit = new optionalDeps.ethUtil.BN(this.setGasLimit(params.gasLimit));
19371944
const gasPrice = params.eip1559
19381945
? new optionalDeps.ethUtil.BN(params.eip1559.maxFeePerGas)
@@ -2017,7 +2024,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
20172024
} as unknown as ECDSAMethodTypes.Signature;
20182025
const signatureHex = Buffer.from(signature.toString(), 'hex');
20192026
const txBuilder = this.getTransactionBuilder(getCommon(this.getNetwork() as EthLikeNetwork));
2020-
txBuilder.from(transaction.serializedTxHex as string);
2027+
txBuilder.from(addHexPrefix(transaction.serializedTxHex) as string);
20212028

20222029
if (!transaction.coinSpecific?.commonKeyChain) {
20232030
throw new Error(`Missing common keychain for transaction at index ${i}`);
@@ -2152,9 +2159,9 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
21522159
};
21532160
}
21542161

2155-
private async buildTssRecoveryTxn(baseAddress: string, gasPrice: any, gasLimit: any, params: RecoverOptions) {
2156-
const nonce = await this.getAddressNonce(baseAddress);
2157-
const txAmount = await this.validateBalanceAndGetTxAmount(baseAddress, gasPrice, gasLimit);
2162+
protected async buildTssRecoveryTxn(baseAddress: string, gasPrice: any, gasLimit: any, params: RecoverOptions) {
2163+
const nonce = await this.getAddressNonce(baseAddress, params.apiKey);
2164+
const txAmount = await this.validateBalanceAndGetTxAmount(baseAddress, gasPrice, gasLimit, params.apiKey);
21582165
const recipients = [
21592166
{
21602167
address: params.recoveryDestination,
@@ -2183,8 +2190,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
21832190
return { txInfo, tx, nonce };
21842191
}
21852192

2186-
async validateBalanceAndGetTxAmount(baseAddress: string, gasPrice: BN, gasLimit: BN) {
2187-
const baseAddressBalance = await this.queryAddressBalance(baseAddress);
2193+
async validateBalanceAndGetTxAmount(baseAddress: string, gasPrice: BN, gasLimit: BN, apiKey?: string) {
2194+
const baseAddressBalance = await this.queryAddressBalance(baseAddress, apiKey);
21882195
const totalGasNeeded = gasPrice.mul(gasLimit);
21892196
const weiToGwei = new BN(10 ** 9);
21902197
if (baseAddressBalance.lt(totalGasNeeded)) {
@@ -2198,7 +2205,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
21982205
return txAmount;
21992206
}
22002207

2201-
async recoveryBlockchainExplorerQuery(query: Record<string, string>): Promise<any> {
2208+
async recoveryBlockchainExplorerQuery(query: Record<string, string>, apiKey?: string): Promise<any> {
22022209
throw new Error('method not implemented');
22032210
}
22042211

0 commit comments

Comments
 (0)