@@ -253,6 +253,7 @@ export type RecoverOptions = {
253
253
intendedChain ?: string ;
254
254
common ?: EthLikeCommon . default ;
255
255
derivationSeed ?: string ;
256
+ apiKey ?: string ;
256
257
} & TSSRecoverOptions ;
257
258
258
259
export type GetBatchExecutionInfoRT = {
@@ -531,12 +532,15 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
531
532
* @param {String } address - the ETHLike address
532
533
* @returns {BigNumber } address balance
533
534
*/
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
+ ) ;
540
544
// throw if the result does not exist or the result is not a valid number
541
545
if ( ! result || ! result . result || isNaN ( result . result ) ) {
542
546
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 {
837
841
* @param {string } address
838
842
* @returns {Promise<number> }
839
843
*/
840
- async getAddressNonce ( address : string ) : Promise < number > {
844
+ async getAddressNonce ( address : string , apiKey ?: string ) : Promise < number > {
841
845
// Get nonce for backup key (should be 0)
842
846
let nonce = 0 ;
843
847
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
+ ) ;
849
856
if ( ! result || ! Array . isArray ( result . result ) ) {
850
857
throw new Error ( 'Unable to find next nonce from Etherscan, got: ' + JSON . stringify ( result ) ) ;
851
858
}
@@ -1932,7 +1939,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
1932
1939
}
1933
1940
}
1934
1941
1935
- private async getGasValues ( params : RecoverOptions ) : Promise < { gasLimit : number ; gasPrice : Buffer } > {
1942
+ protected async getGasValues ( params : RecoverOptions ) : Promise < { gasLimit : number ; gasPrice : Buffer } > {
1936
1943
const gasLimit = new optionalDeps . ethUtil . BN ( this . setGasLimit ( params . gasLimit ) ) ;
1937
1944
const gasPrice = params . eip1559
1938
1945
? new optionalDeps . ethUtil . BN ( params . eip1559 . maxFeePerGas )
@@ -2017,7 +2024,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
2017
2024
} as unknown as ECDSAMethodTypes . Signature ;
2018
2025
const signatureHex = Buffer . from ( signature . toString ( ) , 'hex' ) ;
2019
2026
const txBuilder = this . getTransactionBuilder ( getCommon ( this . getNetwork ( ) as EthLikeNetwork ) ) ;
2020
- txBuilder . from ( transaction . serializedTxHex as string ) ;
2027
+ txBuilder . from ( addHexPrefix ( transaction . serializedTxHex ) as string ) ;
2021
2028
2022
2029
if ( ! transaction . coinSpecific ?. commonKeyChain ) {
2023
2030
throw new Error ( `Missing common keychain for transaction at index ${ i } ` ) ;
@@ -2152,9 +2159,9 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
2152
2159
} ;
2153
2160
}
2154
2161
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 ) ;
2158
2165
const recipients = [
2159
2166
{
2160
2167
address : params . recoveryDestination ,
@@ -2183,8 +2190,8 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
2183
2190
return { txInfo, tx, nonce } ;
2184
2191
}
2185
2192
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 ) ;
2188
2195
const totalGasNeeded = gasPrice . mul ( gasLimit ) ;
2189
2196
const weiToGwei = new BN ( 10 ** 9 ) ;
2190
2197
if ( baseAddressBalance . lt ( totalGasNeeded ) ) {
@@ -2198,7 +2205,7 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
2198
2205
return txAmount ;
2199
2206
}
2200
2207
2201
- async recoveryBlockchainExplorerQuery ( query : Record < string , string > ) : Promise < any > {
2208
+ async recoveryBlockchainExplorerQuery ( query : Record < string , string > , apiKey ?: string ) : Promise < any > {
2202
2209
throw new Error ( 'method not implemented' ) ;
2203
2210
}
2204
2211
0 commit comments