@@ -6,6 +6,7 @@ import BigNumber from 'bignumber.js';
6
6
import * as base58 from 'bs58' ;
7
7
8
8
import {
9
+ AuditDecryptedKeyParams ,
9
10
BaseBroadcastTransactionOptions ,
10
11
BaseBroadcastTransactionResult ,
11
12
BaseCoin ,
@@ -27,9 +28,13 @@ import {
27
28
MPCTx ,
28
29
MPCTxs ,
29
30
MPCUnsignedTx ,
31
+ MultisigType ,
32
+ multisigTypes ,
30
33
OvcInput ,
31
34
OvcOutput ,
32
35
ParsedTransaction ,
36
+ PopulatedIntent ,
37
+ PrebuildTransactionWithIntentOptions ,
33
38
PresignTransactionOptions ,
34
39
PublicKey ,
35
40
RecoveryTxRequest ,
@@ -40,14 +45,10 @@ import {
40
45
TransactionRecipient ,
41
46
VerifyAddressOptions ,
42
47
VerifyTransactionOptions ,
43
- MultisigType ,
44
- multisigTypes ,
45
- AuditDecryptedKeyParams ,
46
- PopulatedIntent ,
47
- PrebuildTransactionWithIntentOptions ,
48
48
} from '@bitgo/sdk-core' ;
49
49
import { auditEddsaPrivateKey , getDerivationPath } from '@bitgo/sdk-lib-mpc' ;
50
50
import { BaseNetwork , CoinFamily , coins , BaseCoin as StaticsBaseCoin } from '@bitgo/statics' ;
51
+ import { TOKEN_2022_PROGRAM_ID , TOKEN_PROGRAM_ID } from '@solana/spl-token' ;
51
52
import * as _ from 'lodash' ;
52
53
import * as request from 'superagent' ;
53
54
import { KeyPair as SolKeyPair , Transaction , TransactionBuilder , TransactionBuilderFactory } from './lib' ;
@@ -60,7 +61,6 @@ import {
60
61
isValidPublicKey ,
61
62
validateRawTransaction ,
62
63
} from './lib/utils' ;
63
- import { TOKEN_2022_PROGRAM_ID , TOKEN_PROGRAM_ID } from '@solana/spl-token' ;
64
64
65
65
export const DEFAULT_SCAN_FACTOR = 20 ; // default number of receive addresses to scan for funds
66
66
@@ -173,6 +173,8 @@ export interface SolConsolidationRecoveryOptions extends MPCConsolidationRecover
173
173
}
174
174
175
175
const HEX_REGEX = / ^ [ 0 - 9 a - f A - F ] + $ / ;
176
+ const BLIND_SIGNING_TX_TYPES_TO_CHECK = { enabletoken : 'AssociatedTokenAccountInitialization' } ;
177
+ const BLIND_SIGNING_TX_TYPES_WITH_EMPTY_OUTPUTS = [ 'enabletoken' ] ;
176
178
177
179
export class Sol extends BaseCoin {
178
180
protected readonly _staticsCoin : Readonly < StaticsBaseCoin > ;
@@ -233,6 +235,32 @@ export class Sol extends BaseCoin {
233
235
return Math . pow ( 10 , this . _staticsCoin . decimalPlaces ) ;
234
236
}
235
237
238
+ verifyTxType ( expectedTypeFromUserParams : string | undefined , actualTypeFromDecoded : string | undefined ) : void {
239
+ // do nothing, let the tx fail way down as always
240
+ if ( expectedTypeFromUserParams === undefined || actualTypeFromDecoded === undefined ) return ;
241
+
242
+ // ex: user param comes with 'enabletoken' included in BLIND SIGNING -> if fails later in the IF check
243
+ // ex: user param comes with 'transfer' non included in BLIND SIGNING-> correctPrebuildTxType goes undefined and IF later goes false so it pass
244
+ // check the unit tests for this.
245
+ const correctPrebuildTxType = BLIND_SIGNING_TX_TYPES_TO_CHECK [ expectedTypeFromUserParams ] ;
246
+
247
+ if ( correctPrebuildTxType && correctPrebuildTxType !== actualTypeFromDecoded ) {
248
+ throw new Error (
249
+ `Tx type "${ actualTypeFromDecoded } " does not match expected txParams type "${ expectedTypeFromUserParams } "`
250
+ ) ;
251
+ }
252
+ }
253
+
254
+ verifyNoOutputs ( expectedTypeFromUserParams : string | undefined , decodedTxHex : TransactionExplanation ) : void {
255
+ if (
256
+ expectedTypeFromUserParams &&
257
+ BLIND_SIGNING_TX_TYPES_WITH_EMPTY_OUTPUTS . includes ( expectedTypeFromUserParams ) &&
258
+ decodedTxHex . outputs ?. length > 0
259
+ ) {
260
+ throw new Error ( `Tx outputs were found when none were expected for sol enablement tokens` ) ;
261
+ }
262
+ }
263
+
236
264
async verifyTransaction ( params : SolVerifyTransactionOptions ) : Promise < boolean > {
237
265
// asset name to transfer amount map
238
266
const totalAmount : Record < string , BigNumber > = { } ;
@@ -261,6 +289,9 @@ export class Sol extends BaseCoin {
261
289
transaction . fromRawTransaction ( rawTxBase64 ) ;
262
290
const explainedTx = transaction . explainTransaction ( ) ;
263
291
292
+ this . verifyNoOutputs ( txParams . type , explainedTx ) ;
293
+ this . verifyTxType ( txParams . type , explainedTx . type ) ;
294
+
264
295
// users do not input recipients for consolidation requests as they are generated by the server
265
296
if ( txParams . recipients !== undefined ) {
266
297
const filteredRecipients = txParams . recipients ?. map ( ( recipient ) =>
0 commit comments