Skip to content

Commit 8299032

Browse files
Merge pull request #7670 from BitGo/WIN-8054
fix(sdk-coin-iota): update verify transaction check in iota
2 parents 94b79dc + aec76a6 commit 8299032

File tree

2 files changed

+55
-3
lines changed

2 files changed

+55
-3
lines changed

modules/sdk-coin-iota/src/iota.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
MPCType,
1515
PopulatedIntent,
1616
PrebuildTransactionWithIntentOptions,
17+
TransactionRecipient,
1718
verifyEddsaTssWalletAddress,
1819
} from '@bitgo/sdk-core';
1920
import { BaseCoin as StaticsBaseCoin, CoinFamily, coins } from '@bitgo/statics';
@@ -121,7 +122,21 @@ export class Iota extends BaseCoin {
121122
throw new Error('Tx not a transfer transaction');
122123
}
123124
const txData = transaction.toJson() as TransferTxData;
124-
if (!txData.recipients || !_.isEqual(txParams.recipients, txData.recipients)) {
125+
126+
if (!txData.recipients) {
127+
throw new Error('Tx recipients does not match with expected txParams recipients');
128+
}
129+
130+
const normalizeRecipient = (recipient: TransactionRecipient) =>
131+
_.pick(recipient, ['address', 'amount', 'tokenName']);
132+
const txDataRecipients = txData.recipients.map(normalizeRecipient);
133+
const txParamsRecipients = txParams.recipients.map(normalizeRecipient);
134+
135+
const allRecipientsMatch = txParamsRecipients.every((expectedRecipient) =>
136+
txDataRecipients.some((actualRecipient) => _.isEqual(expectedRecipient, actualRecipient))
137+
);
138+
139+
if (!allRecipientsMatch) {
125140
throw new Error('Tx recipients does not match with expected txParams recipients');
126141
}
127142
}

modules/sdk-coin-iota/test/unit/iota.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,34 @@ describe('IOTA:', function () {
201201
);
202202
});
203203

204+
it('should verify transaction with recipients containing extra fields', async function () {
205+
// The verification should only compare address, amount, and tokenName
206+
// Extra fields should be ignored
207+
const txBuilder = factory.getTransferBuilder();
208+
txBuilder.sender(testData.sender.address);
209+
txBuilder.recipients(testData.recipients);
210+
txBuilder.paymentObjects(testData.paymentObjects);
211+
txBuilder.gasData(testData.gasData);
212+
213+
const tx = (await txBuilder.build()) as TransferTransaction;
214+
const txHex = Buffer.from(await tx.toBroadcastFormat(), 'base64').toString('hex');
215+
216+
// Add extra fields to recipients that should be ignored during comparison
217+
const recipientsWithExtraFields = testData.recipients.map((r) => ({
218+
...r,
219+
extraField: 'should be ignored',
220+
anotherField: 123,
221+
}));
222+
223+
should.equal(
224+
await basecoin.verifyTransaction({
225+
txPrebuild: { txHex: txHex },
226+
txParams: { recipients: recipientsWithExtraFields },
227+
}),
228+
true
229+
);
230+
});
231+
204232
it('should detect mismatched recipients', async function () {
205233
const txBuilder = factory.getTransferBuilder();
206234
txBuilder.sender(testData.sender.address);
@@ -210,11 +238,20 @@ describe('IOTA:', function () {
210238

211239
const tx = (await txBuilder.build()) as TransferTransaction;
212240
const txHex = Buffer.from(await tx.toBroadcastFormat(), 'base64').toString('hex');
213-
assert.rejects(
241+
242+
// Create mismatched recipients with different addresses/amounts
243+
const mismatchedRecipients = [
244+
{
245+
address: testData.addresses.validAddresses[2], // Different address
246+
amount: '9999', // Different amount
247+
},
248+
];
249+
250+
await assert.rejects(
214251
async () =>
215252
await basecoin.verifyTransaction({
216253
txPrebuild: { txHex: txHex },
217-
txParams: { recipients: testData.recipients },
254+
txParams: { recipients: mismatchedRecipients },
218255
}),
219256
/Tx recipients does not match with expected txParams recipients/
220257
);

0 commit comments

Comments
 (0)