Skip to content

Commit aaae8a2

Browse files
committed
fix(mbe): added etherscan api token as recovery params
TICKET: WP-5168
1 parent b254361 commit aaae8a2

File tree

6 files changed

+42
-34
lines changed

6 files changed

+42
-34
lines changed

masterBitgoExpress.json

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,6 @@
462462
"ledgerSequenceDelta": {
463463
"type": "number"
464464
},
465-
"gasPrice": {
466-
"type": "number"
467-
},
468465
"noSplitChange": {
469466
"type": "boolean"
470467
},
@@ -762,6 +759,36 @@
762759
"coinSpecificParams": {
763760
"type": "object",
764761
"properties": {
762+
"ecdsaCosmosLikeRecoverySpecificParams": {
763+
"type": "object",
764+
"properties": {
765+
"rootAddress": {
766+
"type": "string"
767+
}
768+
},
769+
"required": [
770+
"rootAddress"
771+
]
772+
},
773+
"ecdsaEthLikeRecoverySpecificParams": {
774+
"type": "object",
775+
"properties": {
776+
"apiKey": {
777+
"type": "string"
778+
},
779+
"bitgoDestinationAddress": {
780+
"type": "string"
781+
},
782+
"walletContractAddress": {
783+
"type": "string"
784+
}
785+
},
786+
"required": [
787+
"apiKey",
788+
"bitgoDestinationAddress",
789+
"walletContractAddress"
790+
]
791+
},
765792
"evmRecoveryOptions": {
766793
"type": "object",
767794
"properties": {

src/__tests__/api/master/recoveryWalletMpcV2.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ describe('MBE mpcv2 recovery', () => {
5858
it('should recover a HETH (an eth-like) wallet by calling the enclaved express service', async () => {
5959
const etherscanTxlistNock = nock('https://api.etherscan.io')
6060
.get(
61-
`/v2/api?chainid=17000&module=account&action=txlist&address=0x43442e403d64d29c4f64065d0c1a0e8edc03d6c8`,
61+
`/v2/api?chainid=17000&module=account&action=txlist&address=0x43442e403d64d29c4f64065d0c1a0e8edc03d6c8&apikey=etherscan-api-key`,
6262
)
6363
.matchHeader('any', () => true)
6464
.reply(200, {
@@ -71,7 +71,7 @@ describe('MBE mpcv2 recovery', () => {
7171

7272
const etherscanBalanceNock = nock('https://api.etherscan.io')
7373
.get(
74-
`/v2/api?chainid=17000&module=account&action=balance&address=0x43442e403d64d29c4f64065d0c1a0e8edc03d6c8`,
74+
`/v2/api?chainid=17000&module=account&action=balance&address=0x43442e403d64d29c4f64065d0c1a0e8edc03d6c8&apikey=etherscan-api-key`,
7575
)
7676
.matchHeader('any', () => true)
7777
.reply(200, {
@@ -105,6 +105,7 @@ describe('MBE mpcv2 recovery', () => {
105105
ecdsaEthLikeRecoverySpecificParams: {
106106
walletContractAddress: '0x43442e403d64d29c4f64065d0c1a0e8edc03d6c8',
107107
bitgoDestinationAddress: '0x43442e403d64d29c4f64065d0c1a0e8edc03d6c8', //placeholder
108+
apiKey: `etherscan-api-key`,
108109
},
109110
},
110111
});

src/api/master/handlers/recoverEcdsaWallets.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { AbstractEthLikeNewCoins } from '@bitgo-beta/sdk-coin-eth';
21
import { BaseCoin, BitGoBase, Ecdsa } from '@bitgo-beta/sdk-core';
32
import { EnclavedExpressClient } from '../clients/enclavedExpressClient';
43
import { isCosmosLikeCoin, isEthLikeCoin } from '../../../shared/coinUtils';
@@ -124,17 +123,15 @@ export async function recoverEcdsaMPCv2Wallets(
124123
const { AbstractEthLikeNewCoins } = await import('@bitgo-beta/sdk-coin-eth');
125124
const { TransactionFactory } = await import('@ethereumjs/tx');
126125

127-
const ethCoin = baseCoin as AbstractEthLikeNewCoins; // all eth-like coins should implement this interface
128126
const unsignedTxFull = TransactionFactory.fromSerializedData(
129127
Buffer.from(unsignedTx.signableHex, 'hex'),
130128
);
131129

132-
const ethCommmon = AbstractEthLikeNewCoins['getEthLikeCommon'](
133-
params.ethLikeParams?.eip1559,
134-
params.ethLikeParams?.replayProtectionOptions,
135-
);
136-
const signedTx = await ethCoin['getSignedTxFromSignature'](
137-
ethCommmon,
130+
const ethCommon = AbstractEthLikeNewCoins.getCustomChainCommon(params.ethLikeParams?.replayProtectionOptions?.chain as number);
131+
ethCommon.setHardfork(params.ethLikeParams?.replayProtectionOptions?.hardfork as string);
132+
133+
const signedTx = await baseCoin['getSignedTxFromSignature'](
134+
ethCommon,
138135
unsignedTxFull,
139136
signature,
140137
);

src/api/master/handlers/recoveryWallet.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ export async function handleRecoveryWalletOnPrem(
271271
gasLimit,
272272
bitgoDestinationAddress: coinSpecificParams?.ecdsaEthLikeRecoverySpecificParams
273273
?.bitgoDestinationAddress as string,
274+
apiKey: coinSpecificParams?.ecdsaEthLikeRecoverySpecificParams?.apiKey,
274275
};
275276
} else if (isCosmosLikeCoin(sdkCoin)) {
276277
params.cosmosLikeParams = {

src/api/master/routers/masterApiSpec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export const RecoveryParamTypes = {
7979
ecdsaEthLikeRecoverySpecificParams: t.type({
8080
walletContractAddress: t.string,
8181
bitgoDestinationAddress: t.string,
82+
apiKey: t.string,
8283
}),
8384

8485
// ECDSA Cosmos-like recovery specific parameters

src/shared/coinUtils.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
FormattedOfflineVaultTxInfo,
55
} from '@bitgo-beta/abstract-utxo';
66
import { CosmosCoin } from '@bitgo-beta/abstract-cosmos';
7-
import { CoinFamily } from '@bitgo-beta/statics';
7+
import { CoinFamily, CoinFeature } from '@bitgo-beta/statics';
88
import { BaseCoin } from '@bitgo-beta/sdk-core';
99
import { AbstractUtxoCoin } from '@bitgo-beta/abstract-utxo';
1010
import { type Xtz, type Txtz } from '@bitgo-beta/sdk-coin-xtz';
@@ -34,27 +34,8 @@ export function isEthLikeCoin(coin: BaseCoin): coin is AbstractEthLikeNewCoins {
3434
return isEthPure || isEthLike;
3535
}
3636

37-
// TODO: this typeguard should not work
3837
export function isCosmosLikeCoin(coin: BaseCoin): coin is CosmosCoin {
39-
const isCosmosLike =
40-
isFamily(coin, CoinFamily.ASI) ||
41-
isFamily(coin, CoinFamily.ATOM) ||
42-
isFamily(coin, CoinFamily.BABY) ||
43-
isFamily(coin, CoinFamily.BLD) ||
44-
isFamily(coin, CoinFamily.COREUM) ||
45-
isFamily(coin, CoinFamily.CRONOS) ||
46-
isFamily(coin, CoinFamily.HASH) ||
47-
isFamily(coin, CoinFamily.INITIA) ||
48-
isFamily(coin, CoinFamily.INJECTIVE) ||
49-
isFamily(coin, CoinFamily.ISLM) ||
50-
isFamily(coin, CoinFamily.MANTRA) ||
51-
isFamily(coin, CoinFamily.OSMO) ||
52-
// isFamily(coin, CoinFamily.RUNE) ||
53-
isFamily(coin, CoinFamily.SEI) ||
54-
isFamily(coin, CoinFamily.TIA) ||
55-
isFamily(coin, CoinFamily.ZETA);
56-
57-
return isCosmosLike;
38+
return coin.getConfig().features.includes(CoinFeature.COSMOS_LIKE_COINS);
5839
}
5940

6041
export function isUtxoCoin(coin: BaseCoin): coin is AbstractUtxoCoin {

0 commit comments

Comments
 (0)