Skip to content

Commit b364bb1

Browse files
Merge pull request #6069 from BitGo/COIN-3222-bsc-fix
fix(sdk-coin-bsc): override verifytsstxn method for bsc
2 parents af48edd + 3d29436 commit b364bb1

File tree

3 files changed

+66
-3
lines changed

3 files changed

+66
-3
lines changed

modules/abstract-eth/src/abstractEthLikeNewCoins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ interface EthTransactionParams extends TransactionParams {
343343
tokenName?: string;
344344
}
345345

346-
interface VerifyEthTransactionOptions extends VerifyTransactionOptions {
346+
export interface VerifyEthTransactionOptions extends VerifyTransactionOptions {
347347
txPrebuild: TransactionPrebuild;
348348
txParams: EthTransactionParams;
349349
}

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { BaseCoin, BitGoBase, common, MPCAlgorithm, MultisigType, multisigTypes } from '@bitgo/sdk-core';
22
import { BaseCoin as StaticsBaseCoin, coins } from '@bitgo/statics';
3-
import { AbstractEthLikeNewCoins, recoveryBlockchainExplorerQuery } from '@bitgo/abstract-eth';
3+
import {
4+
AbstractEthLikeNewCoins,
5+
recoveryBlockchainExplorerQuery,
6+
VerifyEthTransactionOptions,
7+
} from '@bitgo/abstract-eth';
48
import { TransactionBuilder } from './lib';
59

610
export class Bsc extends AbstractEthLikeNewCoins {
@@ -41,4 +45,34 @@ export class Bsc extends AbstractEthLikeNewCoins {
4145
const explorerUrl = common.Environments[this.bitgo.getEnv()].bscscanBaseUrl;
4246
return await recoveryBlockchainExplorerQuery(query, explorerUrl as string, apiToken);
4347
}
48+
49+
/**
50+
* Verify if a tss transaction is valid
51+
*
52+
* @param {VerifyEthTransactionOptions} params
53+
* @param {TransactionParams} params.txParams - params object passed to send
54+
* @param {TransactionPrebuild} params.txPrebuild - prebuild object returned by server
55+
* @param {Wallet} params.wallet - Wallet object to obtain keys to verify against
56+
* @returns {boolean}
57+
*/
58+
async verifyTssTransaction(params: VerifyEthTransactionOptions): Promise<boolean> {
59+
const { txParams, txPrebuild, wallet } = params;
60+
if (
61+
!txParams?.recipients &&
62+
!(
63+
txParams.prebuildTx?.consolidateId ||
64+
(txParams.type && ['acceleration', 'fillNonce', 'transferToken'].includes(txParams.type))
65+
)
66+
) {
67+
throw new Error(`missing txParams`);
68+
}
69+
if (!wallet || !txPrebuild) {
70+
throw new Error(`missing params`);
71+
}
72+
if (txParams.hop && txParams.recipients && txParams.recipients.length > 1) {
73+
throw new Error(`tx cannot be both a batch and hop transaction`);
74+
}
75+
76+
return true;
77+
}
4478
}

modules/sdk-coin-bsc/src/bscToken.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import { EthLikeTokenConfig, coins } from '@bitgo/statics';
66
import { BitGoBase, CoinConstructor, NamedCoinConstructor, MPCAlgorithm } from '@bitgo/sdk-core';
7-
import { CoinNames, EthLikeToken } from '@bitgo/abstract-eth';
7+
import { CoinNames, EthLikeToken, VerifyEthTransactionOptions } from '@bitgo/abstract-eth';
88
import { TransactionBuilder } from './lib';
99

1010
export { EthLikeTokenConfig };
@@ -43,4 +43,33 @@ export class BscToken extends EthLikeToken {
4343
getFullName(): string {
4444
return 'Bsc Token';
4545
}
46+
/**
47+
* Verify if a tss transaction is valid
48+
*
49+
* @param {VerifyEthTransactionOptions} params
50+
* @param {TransactionParams} params.txParams - params object passed to send
51+
* @param {TransactionPrebuild} params.txPrebuild - prebuild object returned by server
52+
* @param {Wallet} params.wallet - Wallet object to obtain keys to verify against
53+
* @returns {boolean}
54+
*/
55+
async verifyTssTransaction(params: VerifyEthTransactionOptions): Promise<boolean> {
56+
const { txParams, txPrebuild, wallet } = params;
57+
if (
58+
!txParams?.recipients &&
59+
!(
60+
txParams.prebuildTx?.consolidateId ||
61+
(txParams.type && ['acceleration', 'fillNonce', 'transferToken'].includes(txParams.type))
62+
)
63+
) {
64+
throw new Error(`missing txParams`);
65+
}
66+
if (!wallet || !txPrebuild) {
67+
throw new Error(`missing params`);
68+
}
69+
if (txParams.hop && txParams.recipients && txParams.recipients.length > 1) {
70+
throw new Error(`tx cannot be both a batch and hop transaction`);
71+
}
72+
73+
return true;
74+
}
4675
}

0 commit comments

Comments
 (0)