Skip to content

Commit b967950

Browse files
authored
Merge pull request #7481 from BitGo/derek/SC-3865-update-erc-20-check-for-walletconnect
feat(sdk-core): update erc20 token transfer check for walletconnect
2 parents 6a46ea4 + e14641b commit b967950

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

modules/abstract-eth/src/abstractEthLikeNewCoins.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2858,7 +2858,23 @@ export abstract class AbstractEthLikeNewCoins extends AbstractEthLikeCoin {
28582858
{ address: addHexPrefix(recipientAddress.toString()), amount: amount.toString() },
28592859
]);
28602860
}
2861-
if (expectedDestination.toLowerCase() !== addHexPrefix(recipientAddress.toString()).toLowerCase()) {
2861+
2862+
// Check if recipients[0].data exists (WalletConnect flow)
2863+
let expectedRecipientAddress: string;
2864+
const recipientData = (recipients[0] as any).data;
2865+
if (recipientData && recipientData.startsWith('0xa9059cbb')) {
2866+
// WalletConnect: decode expected recipient from recipients[0].data
2867+
const [expectedRecipient] = getRawDecoded(
2868+
['address', 'uint256'],
2869+
getBufferedByteCode('0xa9059cbb', recipientData)
2870+
);
2871+
expectedRecipientAddress = addHexPrefix(expectedRecipient.toString()).toLowerCase();
2872+
} else {
2873+
// Normal flow: use recipients[0].address
2874+
expectedRecipientAddress = expectedDestination.toLowerCase();
2875+
}
2876+
2877+
if (expectedRecipientAddress !== addHexPrefix(recipientAddress.toString()).toLowerCase()) {
28622878
throwRecipientMismatch('destination address does not match with the recipient address', [
28632879
{ address: addHexPrefix(recipientAddress.toString()), amount: amount.toString() },
28642880
]);

modules/bitgo/test/v2/unit/internal/tssUtils/ecdsa.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,6 +856,39 @@ describe('TSS Ecdsa Utils:', async function () {
856856
.should.be.rejectedWith('the transaction amount in txPrebuild does not match the value given by client');
857857
});
858858

859+
it('signTxRequest should succeed for WalletConnect ERC20 transfer with data field', async function () {
860+
nock.cleanAll();
861+
// WalletConnect ERC20 transfer: recipients[0].address is token contract, recipients[0].data contains the actual recipient
862+
const signableHex =
863+
'02f86f83088bb00283e1d7dd84768ea6898301e04b94d9327fd36c3312466efed23ff0493453ee32f55180b844a9059cbb0000000000000000000000007d7e63af583ba73ba5c927dbd028153963566bef00000000000000000000000000000000000000000000000000470de4df820000c0';
864+
const serializedTxHex =
865+
'02f87283088bb00283e1d7dd84768ea6898301e04b94d9327fd36c3312466efed23ff0493453ee32f55180b844a9059cbb0000000000000000000000007d7e63af583ba73ba5c927dbd028153963566bef00000000000000000000000000000000000000000000000000470de4df820000c0808080';
866+
await setupSignTxRequestNocks(true, userSignShare, aShare, dShare, enterpriseData, {
867+
signableHex,
868+
serializedTxHex,
869+
apiVersion: 'full',
870+
});
871+
await tssUtils.signTxRequest({
872+
txRequest: txRequestId,
873+
prv: JSON.stringify({
874+
pShare: userKeyShare.pShare,
875+
bitgoNShare: bitgoKeyShare.nShares[1],
876+
backupNShare: backupKeyShare.nShares[1],
877+
}),
878+
reqId,
879+
txParams: {
880+
recipients: [
881+
{
882+
address: '0xd9327fd36c3312466efed23ff0493453ee32f551', // Token contract address
883+
amount: '20000000000000000',
884+
data: '0xa9059cbb0000000000000000000000007d7e63af583ba73ba5c927dbd028153963566bef00000000000000000000000000000000000000000000000000470de4df820000', // ERC20 transfer calldata with actual recipient
885+
},
886+
],
887+
type: 'transfer',
888+
},
889+
});
890+
});
891+
859892
it('getOfflineSignerPaillierModulus should succeed', async function () {
860893
const paillierModulus = tssUtils.getOfflineSignerPaillierModulus({
861894
prv: JSON.stringify({

modules/sdk-core/src/bitgo/baseCoin/iBaseCoin.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export interface ITransactionRecipient {
8181
amount: string | number;
8282
tokenName?: string;
8383
memo?: string;
84+
data?: string;
8485
}
8586

8687
/**

0 commit comments

Comments
 (0)