-
Notifications
You must be signed in to change notification settings - Fork 304
fix(sdk-core): enforce recipient verification in ECDSA TSS signing #8924
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
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import { TransactionParams } from '../../baseCoin'; | ||
| import { InvalidTransactionError } from '../../errors'; | ||
| import { PopulatedIntent, TxRequest } from './baseTypes'; | ||
|
|
||
| /** | ||
| * Transaction types that legitimately carry no explicit recipients. | ||
| * These are the intentType strings as stored in TxRequest.intent.intentType by WP. | ||
| * verifyTransaction handles no-recipient validation for these internally. | ||
| * Mirrors the bypass list in abstractEthLikeNewCoins.ts verifyTssTransaction. | ||
| * | ||
| * ECDSA types: acceleration, fillNonce, transferToken, tokenApproval, consolidate, | ||
| * bridgeFunds, enableToken, customTx, contractCall | ||
| * BSC/BNB delegation-based staking: delegate, undelegate, switchValidator | ||
| * CELO/ETH lock-based staking: stake, unstake, stakeWithCallData, unstakeWithCallData, | ||
| * transferStake, increaseStake, goUnstake | ||
| * Claim rewards (BSC, CELO — TRX/SOL use EdDSA and are unaffected): claim, stakeClaimRewards | ||
| */ | ||
| export const NO_RECIPIENT_TX_TYPES = new Set([ | ||
| // ECDSA types | ||
| 'acceleration', | ||
| 'fillNonce', | ||
| 'transferToken', | ||
| 'tokenApproval', | ||
| 'consolidate', | ||
| 'bridgeFunds', | ||
| 'enableToken', | ||
| 'enabletoken', | ||
| 'disabletoken', | ||
| 'customTx', | ||
| // DeFi vault operations — recipients/calldata built server-side from defiParams | ||
| 'defiApprove', | ||
| 'defiDeposit', | ||
| // Smart contract invocations with no explicit SDK-level recipients | ||
| 'contractCall', | ||
|
|
||
| // BSC/BNB delegation-based staking — intentType strings from TxRequest.intent.intentType | ||
| 'delegate', | ||
| 'undelegate', | ||
| 'switchValidator', | ||
|
|
||
| // CELO/ETH lock-based staking | ||
| 'stake', | ||
| 'unstake', | ||
| 'stakeWithCallData', | ||
| 'unstakeWithCallData', | ||
| 'transferStake', | ||
| 'increaseStake', | ||
| 'goUnstake', | ||
|
|
||
| // Claim rewards — BSC and CELO (TRX/SOL/Cosmos use EdDSA, not affected by this guard) | ||
| 'claim', | ||
| 'stakeClaimRewards', | ||
|
|
||
| 'createAccount', | ||
| 'transferAccept', | ||
| 'transferReject', | ||
| 'transferOfferWithdrawn', | ||
| 'cantonCommand', | ||
| 'pledge', | ||
|
mrdanish26 marked this conversation as resolved.
|
||
| ]); | ||
|
|
||
| /** | ||
| * Resolves the effective txParams for TSS signing recipient verification. | ||
| * | ||
| * For smart contract interactions, recipients live in txRequest.intent.recipients | ||
| * (native amount = 0, so buildParams is empty). Falls back to intent recipients | ||
| * mapped to ITransactionRecipient shape when txParams.recipients is absent. | ||
| * | ||
| * Staking intents (BSC delegate/undelegate, CELO stake/unstake, etc.) are | ||
| * identified generically by the presence of `stakingRequestId` on the intent — | ||
| * a required field on BaseStakeIntent in @bitgo/public-types. These intents | ||
| * have no txParams recipients by design; validation is done at the coin layer. | ||
| * | ||
| * Throws InvalidTransactionError if no recipients can be resolved and the | ||
| * transaction is not a known no-recipient type. | ||
| */ | ||
| export function resolveEffectiveTxParams( | ||
| txRequest: TxRequest, | ||
| txParams: TransactionParams | undefined | ||
| ): TransactionParams { | ||
| const intentRecipients = (txRequest.intent as PopulatedIntent)?.recipients?.map((intentRecipient) => ({ | ||
| address: intentRecipient.address.address, | ||
| amount: intentRecipient.amount.value, | ||
| data: intentRecipient.data, | ||
| })); | ||
|
|
||
| const effectiveTxParams: TransactionParams = { | ||
| ...txParams, | ||
| recipients: txParams?.recipients?.length ? txParams.recipients : intentRecipients, | ||
| }; | ||
|
|
||
| // Fall back to intent.intentType when txParams.type is not explicitly set. | ||
| // Staking wallets call signTransaction without txParams, so the type lives only in the intent. | ||
| const txType = effectiveTxParams.type ?? (txRequest.intent as PopulatedIntent)?.intentType ?? ''; | ||
|
|
||
| // Propagate the resolved type so downstream callers | ||
| if (!effectiveTxParams.type && txType) { | ||
| effectiveTxParams.type = txType; | ||
| } | ||
|
|
||
| // Propagate stakingRequestId from intent into effectiveTxParams so verifyTssTransaction | ||
| // overrides can bypass the no-recipient guard without needing access to txRequest directly. | ||
| const intentStakingRequestId = (txRequest.intent as PopulatedIntent)?.stakingRequestId; | ||
| if (intentStakingRequestId && !effectiveTxParams.stakingRequestId) { | ||
| effectiveTxParams.stakingRequestId = intentStakingRequestId; | ||
| } | ||
|
|
||
| // All staking intents (BSC delegate/undelegate, CELO stake/unstake, etc.) carry | ||
| // stakingRequestId as a required field on BaseStakeIntent (@bitgo/public-types). | ||
| // Use its presence as a generic staking signal — no need to enumerate every intentType. | ||
| const isStakingIntent = !!(txRequest.intent as PopulatedIntent)?.stakingRequestId; | ||
|
|
||
| if (!effectiveTxParams.recipients?.length && !isStakingIntent && !NO_RECIPIENT_TX_TYPES.has(txType)) { | ||
| throw new InvalidTransactionError( | ||
| 'Recipient details are required to verify this transaction before signing. Pass txParams with at least one recipient.' | ||
| ); | ||
| } | ||
|
|
||
| return effectiveTxParams; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.