Skip to content

Commit c694864

Browse files
feat(sdk-core,sdk-coin-sol): token enablements verify option and type check improvements
TICKET: WP-5744
1 parent 2099f83 commit c694864

File tree

4 files changed

+32
-27
lines changed

4 files changed

+32
-27
lines changed

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,11 @@ export class Sol extends BaseCoin {
237237
return Math.pow(10, this._staticsCoin.decimalPlaces);
238238
}
239239

240-
verifyTxType(txParams: TransactionParams, actualTypeFromDecoded: string | undefined): void {
241-
// do nothing, let the tx fail way down as always
242-
const expectedTypeFromUserParams = txParams.type;
243-
if (expectedTypeFromUserParams === undefined || actualTypeFromDecoded === undefined) return;
244-
245-
const correctPrebuildTxType = BLIND_SIGNING_TX_TYPES_TO_CHECK[expectedTypeFromUserParams];
246-
247-
if (correctPrebuildTxType && correctPrebuildTxType !== actualTypeFromDecoded) {
240+
verifyTxType(expectedTypeFromUserParams: string, actualTypeFromDecoded: string | undefined): void {
241+
const matchFromUserToDecodedType = BLIND_SIGNING_TX_TYPES_TO_CHECK[expectedTypeFromUserParams];
242+
if (matchFromUserToDecodedType !== actualTypeFromDecoded) {
248243
throw new Error(
249-
`Tx type "${actualTypeFromDecoded}" does not match expected txParams type "${expectedTypeFromUserParams}"`
244+
`Invalid transaction type on token enablement: expected "${matchFromUserToDecodedType}", got "${actualTypeFromDecoded}".`
250245
);
251246
}
252247
}
@@ -351,8 +346,8 @@ export class Sol extends BaseCoin {
351346
transaction.fromRawTransaction(rawTxBase64);
352347
const explainedTx = transaction.explainTransaction();
353348

354-
this.verifyTxType(txParams, explainedTx.type);
355-
if (txParams.type === 'enabletoken') {
349+
if (txParams.type === 'enabletoken' && verificationOptions?.verifyTokenEnablement) {
350+
this.verifyTxType(txParams.type, explainedTx.type);
356351
const tokenEnablementsPrebuild = this.throwIfMissingTokenEnablementsOrReturn(explainedTx);
357352
const enableTokensConfig = this.throwIfMissingEnableTokenConfigOrReturn(txParams);
358353

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3271,6 +3271,7 @@ describe('SOL:', function () {
32713271
txParams,
32723272
txPrebuild: txPrebuildRaw,
32733273
wallet,
3274+
verification: { verifyTokenEnablement: true },
32743275
} as unknown as SolVerifyTransactionOptions);
32753276

32763277
sameIntentTx.should.equal(true);
@@ -3288,8 +3289,12 @@ describe('SOL:', function () {
32883289
txParams,
32893290
txPrebuild: tamperedTxPrebuild,
32903291
wallet,
3292+
verification: { verifyTokenEnablement: true },
32913293
} as unknown as SolVerifyTransactionOptions),
3292-
{ message: 'Tx type "Send" does not match expected txParams type "enabletoken"' }
3294+
{
3295+
message:
3296+
'Invalid transaction type on token enablement: expected "AssociatedTokenAccountInitialization", got "Send".',
3297+
}
32933298
);
32943299
});
32953300

@@ -3304,6 +3309,7 @@ describe('SOL:', function () {
33043309
txParams,
33053310
txPrebuild: tamperedTxPrebuild,
33063311
wallet,
3312+
verification: { verifyTokenEnablement: true },
33073313
} as unknown as SolVerifyTransactionOptions),
33083314
{ message: 'Invalid token name: expected tsol:ray, got tsol:t22mint on token enablement tx' }
33093315
);
@@ -3320,6 +3326,7 @@ describe('SOL:', function () {
33203326
txParams,
33213327
txPrebuild: tamperedTxPrebuild,
33223328
wallet,
3329+
verification: { verifyTokenEnablement: true },
33233330
} as unknown as SolVerifyTransactionOptions),
33243331
{
33253332
message:

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ export interface VerificationOptions {
185185
addresses?: { [address: string]: AddressVerificationData };
186186
allowPaygoOutput?: boolean;
187187
considerMigratedFromAddressInternal?: boolean;
188+
verifyTokenEnablement?: boolean;
188189
// Verify transaction is consolidating to wallet's base address
189190
consolidationToBaseAddress?: boolean;
190191
}

modules/sdk-core/src/bitgo/wallet/wallet.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
/**
22
* @prettier
33
*/
4-
import * as t from 'io-ts';
4+
import { TxSendBody } from '@bitgo/public-types';
5+
import { CoinFamily } from '@bitgo/statics';
56
import assert from 'assert';
67
import BigNumber from 'bignumber.js';
8+
import * as t from 'io-ts';
79
import * as _ from 'lodash';
10+
import { IRequestTracer } from '../../api';
811
import * as common from '../../common';
12+
import { AddressBook, IAddressBook } from '../address-book';
913
import {
1014
IBaseCoin,
1115
NFTTransferOptions,
@@ -25,11 +29,15 @@ import {
2529
MissingEncryptedKeychainError,
2630
NeedUserSignupError,
2731
} from '../errors';
28-
import * as internal from '../internal/internal';
32+
import { SubmitTransactionResponse } from '../inscriptionBuilder';
2933
import { drawKeycard } from '../internal';
34+
import * as internal from '../internal/internal';
3035
import { decryptKeychainPrivateKey, Keychain, KeychainWithEncryptedPrv } from '../keychain';
36+
import { getLightningAuthKey } from '../lightning/lightningWalletUtil';
3137
import { IPendingApproval, PendingApproval, PendingApprovals } from '../pendingApproval';
38+
import { GoStakingWallet, StakingWallet } from '../staking';
3239
import { TradingAccount } from '../trading';
40+
import { getTxRequest } from '../tss';
3341
import {
3442
EddsaUnsignedTransaction,
3543
inferAddressType,
@@ -41,6 +49,11 @@ import {
4149
TokenType,
4250
TxRequest,
4351
} from '../utils';
52+
import { postWithCodec } from '../utils/postWithCodec';
53+
import { EcdsaMPCv2Utils, EcdsaUtils } from '../utils/tss/ecdsa';
54+
import EddsaUtils from '../utils/tss/eddsa';
55+
import { getTxRequestApiVersion, validateTxRequestApiVersion } from '../utils/txRequest';
56+
import { buildParamKeys, BuildParams } from './BuildParams';
4457
import {
4558
AccelerateTransactionOptions,
4659
AddressesByBalanceOptions,
@@ -110,19 +123,6 @@ import {
110123
WalletSignTypedDataOptions,
111124
WalletType,
112125
} from './iWallet';
113-
import { GoStakingWallet, StakingWallet } from '../staking';
114-
import EddsaUtils from '../utils/tss/eddsa';
115-
import { EcdsaMPCv2Utils, EcdsaUtils } from '../utils/tss/ecdsa';
116-
import { getTxRequest } from '../tss';
117-
import { buildParamKeys, BuildParams } from './BuildParams';
118-
import { postWithCodec } from '../utils/postWithCodec';
119-
import { TxSendBody } from '@bitgo/public-types';
120-
import { AddressBook, IAddressBook } from '../address-book';
121-
import { IRequestTracer } from '../../api';
122-
import { getTxRequestApiVersion, validateTxRequestApiVersion } from '../utils/txRequest';
123-
import { getLightningAuthKey } from '../lightning/lightningWalletUtil';
124-
import { SubmitTransactionResponse } from '../inscriptionBuilder';
125-
import { CoinFamily } from '@bitgo/statics';
126126

127127
const debug = require('debug')('bitgo:v2:wallet');
128128

@@ -3231,6 +3231,8 @@ export class Wallet implements IWallet {
32313231
*/
32323232
public async sendTokenEnablement(params: PrebuildAndSignTransactionOptions = {}): Promise<any> {
32333233
const teConfig = this.baseCoin.getTokenEnablementConfig();
3234+
if (params.verification && params.verification.verifyTokenEnablement === undefined)
3235+
params.verification.verifyTokenEnablement = true;
32343236
if (!teConfig.requiresTokenEnablement) {
32353237
throw new Error(`${this.baseCoin.getFullName()} does not require token enablement transactions`);
32363238
}

0 commit comments

Comments
 (0)