Skip to content

feat(root): enable passing apiKey for recovery on eth likes #6511

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

Merged

Conversation

mohammadalfaiyazbitgo
Copy link
Contributor

@mohammadalfaiyazbitgo mohammadalfaiyazbitgo commented Jul 22, 2025

Ticket: WP-5348

@mohammadalfaiyazbitgo mohammadalfaiyazbitgo requested a review from a team as a code owner July 22, 2025 16:55
Copilot

This comment was marked as outdated.

Copy link
Contributor

@margueriteblair margueriteblair left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove TICKET: [WP-000000](https://bitgoinc.atlassian.net/browse/WP-000000) from PR desc?

pranavjain97
pranavjain97 previously approved these changes Jul 22, 2025
Copilot

This comment was marked as outdated.

pranavjain97
pranavjain97 previously approved these changes Jul 23, 2025
- also added example for how to generate an unsigned tx

Ticket: WP-5348
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables passing a custom API key for recovery operations on Ethereum-like blockchain networks instead of relying solely on environment-configured API keys. The changes provide more flexibility for recovery operations by allowing users to specify their own blockchain explorer API keys.

  • Adds optional apiKey parameter to recoveryBlockchainExplorerQuery methods across all ETH-like coin implementations
  • Updates recovery logic to propagate the custom API key through all blockchain explorer queries
  • Adds comprehensive test coverage to verify custom API key usage during recovery operations

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
modules/abstract-eth/src/abstractEthLikeNewCoins.ts Core implementation adding apiKey parameter to recovery methods and explorer queries
modules/sdk-coin-eth/src/eth.ts ETH coin implementation with apiKey support and updated recovery logic
modules/sdk-coin-eth/src/erc20Token.ts ERC20 token recovery with apiKey propagation
modules/sdk-coin-/src/.ts Individual coin implementations adding apiKey parameter to recoveryBlockchainExplorerQuery
modules/bitgo/test/v2/unit/recovery.ts Comprehensive test coverage for API key usage in recovery
modules/sdk-coin-eth/test/unit/eth.ts Unit tests verifying API key override functionality
Comments suppressed due to low confidence (1)

modules/sdk-coin-eth/test/unit/eth.ts:1076

  • The test mocks the global request.get function which could affect other tests if not properly isolated. Consider using a more targeted mocking approach like sinon.stub to avoid potential test interference.
      request.get = function (url: string) {

query: Record<string, string>,
apiKey?: string
): Promise<Record<string, unknown>> {
const apiToken = apiKey ?? common.Environments[this.bitgo.getEnv()][this.getFamily().toLowerCase() + 'ApiToken'];
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Use consistent operator choice with other implementations. Other files use || operator for the same pattern, but this file uses ??. Consider using || for consistency across the codebase.

Suggested change
const apiToken = apiKey ?? common.Environments[this.bitgo.getEnv()][this.getFamily().toLowerCase() + 'ApiToken'];
const apiToken = apiKey || common.Environments[this.bitgo.getEnv()][this.getFamily().toLowerCase() + 'ApiToken'];

Copilot uses AI. Check for mistakes.

Comment on lines +1088 to +1092
if (params.userKey === undefined) {
throw new Error('missing userKey');
}

if (_.isUndefined(params.backupKey)) {
if (params.backupKey === undefined) {
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from _.isUndefined() to strict equality checks removes the lodash dependency but may have different behavior for null values. Consider using == null to check for both undefined and null, or ensure this change is intentional.

Copilot uses AI. Check for mistakes.

throw new Error('missing backupKey');
}

if (_.isUndefined(params.walletPassphrase) && !params.userKey.startsWith('xpub') && !params.isTss) {
if (
!params.isUnsignedSweep &&
Copy link
Preview

Copilot AI Jul 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The validation logic now includes !params.isUnsignedSweep condition but this parameter is optional and may be undefined. Consider using params.isUnsignedSweep !== true to be more explicit about falsy values.

Suggested change
!params.isUnsignedSweep &&
params.isUnsignedSweep !== true &&

Copilot uses AI. Check for mistakes.

walletContractAddress: 'Address-of-your-multisig-wallet',
recoveryDestination: 'Address-To-Recover-Funds-To',
isUnsignedSweep: true,
apiKey: 'Add Your Etherscan ApiKey here',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may I know why are we adding apikey here instead of doingnew BitGoAPI({ env: environment, etherscanApiToken: apiKey });

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The motivation is to make recoveries have a similar interface across coins. If you look at UTXO recoveries,

they expose an API key param as well. Which to me makes sense as you only need the api key at time of recovery, which may not be when the bitgo object is initiated, so this flow is more flexible when it comes to usage.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is relevant for applications like WRW

@mohammadalfaiyazbitgo mohammadalfaiyazbitgo merged commit 1f7c624 into master Jul 24, 2025
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants