1
1
// Descriptive error types for common issues which may arise
2
2
// during the operation of BitGoJS or BitGoExpress
3
3
import { BitGoJsError } from '../bitgojsError' ;
4
+ import { IRequestTracer } from '../api/types' ;
5
+ import { TransactionParams } from './baseCoin' ;
6
+ import { TokenTransferRecipientParams } from './utils/tss/baseTypes' ;
4
7
5
8
// re-export for backwards compat
6
9
export { BitGoJsError } ;
@@ -175,7 +178,7 @@ export class NeedUserSignupError extends BitGoJsError {
175
178
}
176
179
}
177
180
178
- export class ApiResponseError < ResponseBodyType = any > extends BitGoJsError {
181
+ export class ApiResponseError < ResponseBodyType = unknown > extends BitGoJsError {
179
182
message : string ;
180
183
status : number ;
181
184
result ?: ResponseBodyType ;
@@ -197,3 +200,188 @@ export class ApiResponseError<ResponseBodyType = any> extends BitGoJsError {
197
200
this . needsOTP = needsOTP ;
198
201
}
199
202
}
203
+
204
+ /**
205
+ * Interface for token approval information used in suspicious transaction detection
206
+ *
207
+ * @interface TokenApproval
208
+ * @property {string } [tokenName] - Optional human-readable name of the token
209
+ * @property {string } tokenAddress - The contract address of the token being approved
210
+ * @property {number | 'unlimited' } authorizingAmount - The amount being authorized for spending, or 'unlimited' for infinite approval
211
+ * @property {string } authorizingAddress - The address being authorized to spend the tokens
212
+ */
213
+ export interface TokenApproval {
214
+ tokenName ?: string ;
215
+ tokenAddress : string ;
216
+ authorizingAmount : number | 'unlimited' ;
217
+ authorizingAddress : string ;
218
+ }
219
+
220
+ /**
221
+ * Interface for mismatched recipient information detected during transaction verification
222
+ *
223
+ * @interface MismatchedRecipient
224
+ * @property {string } address - The recipient address that was found in the transaction
225
+ * @property {string } amount - The amount being sent to this recipient
226
+ * @property {string | TokenTransferRecipientParams } [data] - Optional transaction data or token transfer parameters
227
+ * @property {string } [tokenName] - Optional name of the token being transferred
228
+ * @property {TokenTransferRecipientParams } [tokenData] - Optional structured token transfer data
229
+ */
230
+ export interface MismatchedRecipient {
231
+ address : string ;
232
+ amount : string ;
233
+ data ?: string | TokenTransferRecipientParams ;
234
+ tokenName ?: string ;
235
+ tokenData ?: TokenTransferRecipientParams ;
236
+ }
237
+
238
+ /**
239
+ * Interface for contract interaction data payload used in suspicious transaction detection
240
+ *
241
+ * @interface ContractDataPayload
242
+ * @property {string } address - The contract address being interacted with
243
+ * @property {string } rawContractPayload - The raw contract payload in serialized form specific to the blockchain
244
+ * @property {unknown } decodedContractPayload - The decoded contract payload, structure varies by coin/chain implementation
245
+ */
246
+ export interface ContractDataPayload {
247
+ address : string ;
248
+ // The raw contract payload in serialized form of the chain
249
+ rawContractPayload : string ;
250
+ // To be defined on a per-coin basis
251
+ decodedContractPayload : unknown ;
252
+ }
253
+
254
+ /**
255
+ * Base error class for suspicious transaction detection
256
+ *
257
+ * This error is thrown when a transaction is detected to have suspicious characteristics
258
+ * that don't match the expected parameters or behavior.
259
+ *
260
+ * @class SuspiciousTransactionError
261
+ * @extends {BitGoJsError }
262
+ * @property {string | IRequestTracer } id - Transaction ID or request tracer for tracking
263
+ * @property {TransactionParams[] } txParams - Array of transaction parameters that were analyzed
264
+ * @property {string } txHex - The raw transaction in hexadecimal format
265
+ */
266
+ export class SuspiciousTransactionError extends BitGoJsError {
267
+ public readonly id : string | IRequestTracer ;
268
+ public readonly txParams : TransactionParams [ ] ;
269
+ public readonly txHex : string ;
270
+
271
+ /**
272
+ * Creates an instance of SuspiciousTransactionError
273
+ *
274
+ * @param {string } message - Error message describing the suspicious activity
275
+ * @param {string | IRequestTracer } id - Transaction ID or request tracer
276
+ * @param {TransactionParams[] } txParams - Transaction parameters that were analyzed
277
+ * @param {string } txHex - Raw transaction hex string
278
+ */
279
+ public constructor ( message : string , id : string | IRequestTracer , txParams : TransactionParams [ ] , txHex : string ) {
280
+ super ( message ) ;
281
+ this . id = id ;
282
+ this . txParams = txParams ;
283
+ this . txHex = txHex ;
284
+ }
285
+ }
286
+
287
+ /**
288
+ * Error thrown when transaction parameters don't match the expected recipients
289
+ *
290
+ * This error occurs when the transaction contains recipients or amounts that differ
291
+ * from what was expected based on the original transaction parameters.
292
+ *
293
+ * @class SuspiciousTransactionParameterMismatchError
294
+ * @extends {SuspiciousTransactionError }
295
+ * @property {MismatchedRecipient[] } mismatchedRecipients - Array of recipients that don't match expectations
296
+ */
297
+ export class SuspiciousTransactionParameterMismatchError extends SuspiciousTransactionError {
298
+ public readonly mismatchedRecipients : MismatchedRecipient [ ] ;
299
+
300
+ /**
301
+ * Creates an instance of SuspiciousTransactionParameterMismatchError
302
+ *
303
+ * @param {string } message - Error message describing the parameter mismatch
304
+ * @param {string | IRequestTracer } id - Transaction ID or request tracer
305
+ * @param {TransactionParams[] } txParams - Transaction parameters that were analyzed
306
+ * @param {string } txHex - Raw transaction hex string
307
+ * @param {MismatchedRecipient[] } mismatchedRecipients - Array of mismatched recipient information
308
+ */
309
+ public constructor (
310
+ message : string ,
311
+ id : string | IRequestTracer ,
312
+ txParams : TransactionParams [ ] ,
313
+ txHex : string ,
314
+ mismatchedRecipients : MismatchedRecipient [ ]
315
+ ) {
316
+ super ( message , id , txParams , txHex ) ;
317
+ this . mismatchedRecipients = mismatchedRecipients ;
318
+ }
319
+ }
320
+
321
+ /**
322
+ * Error thrown when contract interaction data doesn't match expected payload
323
+ *
324
+ * This error occurs when a transaction interacts with a smart contract but the
325
+ * contract call data or method doesn't match what was expected.
326
+ *
327
+ * @class SuspiciousContractInteractionError
328
+ * @extends {SuspiciousTransactionError }
329
+ * @property {ContractDataPayload } mismatchedDataPayload - The contract interaction data that was unexpected
330
+ */
331
+ export class SuspiciousContractInteractionError extends SuspiciousTransactionError {
332
+ public readonly mismatchedDataPayload : ContractDataPayload ;
333
+
334
+ /**
335
+ * Creates an instance of SuspiciousContractInteractionError
336
+ *
337
+ * @param {string } message - Error message describing the contract interaction issue
338
+ * @param {string | IRequestTracer } id - Transaction ID or request tracer
339
+ * @param {TransactionParams[] } txParams - Transaction parameters that were analyzed
340
+ * @param {string } txHex - Raw transaction hex string
341
+ * @param {ContractDataPayload } mismatchedDataPayload - The unexpected contract interaction data
342
+ */
343
+ public constructor (
344
+ message : string ,
345
+ id : string | IRequestTracer ,
346
+ txParams : TransactionParams [ ] ,
347
+ txHex : string ,
348
+ mismatchedDataPayload : ContractDataPayload
349
+ ) {
350
+ super ( message , id , txParams , txHex ) ;
351
+ this . mismatchedDataPayload = mismatchedDataPayload ;
352
+ }
353
+ }
354
+
355
+ /**
356
+ * Error thrown when unauthorized token approval is detected
357
+ *
358
+ * This error occurs when a transaction contains a token approval that wasn't
359
+ * expected or authorized by the user, potentially indicating malicious activity.
360
+ *
361
+ * @class SuspiciousUnauthorizedTokenApproval
362
+ * @extends {SuspiciousTransactionError }
363
+ * @property {TokenApproval } tokenApproval - Details of the unauthorized token approval
364
+ */
365
+ export class SuspiciousUnauthorizedTokenApproval extends SuspiciousTransactionError {
366
+ public readonly tokenApproval : TokenApproval ;
367
+
368
+ /**
369
+ * Creates an instance of SuspiciousUnauthorizedTokenApproval
370
+ *
371
+ * @param {string } message - Error message describing the unauthorized approval
372
+ * @param {string | IRequestTracer } id - Transaction ID or request tracer
373
+ * @param {TransactionParams[] } txParams - Transaction parameters that were analyzed
374
+ * @param {string } txHex - Raw transaction hex string
375
+ * @param {TokenApproval } tokenApproval - Details of the unauthorized token approval
376
+ */
377
+ public constructor (
378
+ message : string ,
379
+ id : string | IRequestTracer ,
380
+ txParams : TransactionParams [ ] ,
381
+ txHex : string ,
382
+ tokenApproval : TokenApproval
383
+ ) {
384
+ super ( message , id , txParams , txHex ) ;
385
+ this . tokenApproval = tokenApproval ;
386
+ }
387
+ }
0 commit comments