-
Notifications
You must be signed in to change notification settings - Fork 299
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
feat(root): enable passing apiKey for recovery on eth likes #6511
Conversation
margueriteblair
left a comment
There was a problem hiding this 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?
b4b8112
a575e29 to
b4b8112
Compare
- also added example for how to generate an unsigned tx Ticket: WP-5348
dc8d3c2
b4b8112 to
dc8d3c2
Compare
There was a problem hiding this 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
apiKeyparameter torecoveryBlockchainExplorerQuerymethods 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.getfunction 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']; |
Copilot
AI
Jul 24, 2025
There was a problem hiding this comment.
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.
| const apiToken = apiKey ?? common.Environments[this.bitgo.getEnv()][this.getFamily().toLowerCase() + 'ApiToken']; | |
| const apiToken = apiKey || common.Environments[this.bitgo.getEnv()][this.getFamily().toLowerCase() + 'ApiToken']; |
| if (params.userKey === undefined) { | ||
| throw new Error('missing userKey'); | ||
| } | ||
|
|
||
| if (_.isUndefined(params.backupKey)) { | ||
| if (params.backupKey === undefined) { |
Copilot
AI
Jul 24, 2025
There was a problem hiding this comment.
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.
|
|
||
| if (_.isUndefined(params.walletPassphrase) && !params.userKey.startsWith('xpub') && !params.isTss) { | ||
| if ( | ||
| !params.isUnsignedSweep && |
Copilot
AI
Jul 24, 2025
There was a problem hiding this comment.
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.
| !params.isUnsignedSweep && | |
| params.isUnsignedSweep !== true && |
| walletContractAddress: 'Address-of-your-multisig-wallet', | ||
| recoveryDestination: 'Address-To-Recover-Funds-To', | ||
| isUnsignedSweep: true, | ||
| apiKey: 'Add Your Etherscan ApiKey here', |
There was a problem hiding this comment.
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 });
There was a problem hiding this comment.
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,
| type RecoverParams = { |
There was a problem hiding this comment.
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
Ticket: WP-5348