|
1 | | -import { CosmosSignTx as HardwareCosmosSignTx } from '@onekeyfe/hd-transport'; |
| 1 | +import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared'; |
| 2 | + |
2 | 3 | import { serializedPath, validatePath } from '../helpers/pathUtils'; |
3 | 4 | import { BaseMethod } from '../BaseMethod'; |
4 | 5 | import { validateParams } from '../helpers/paramsValidator'; |
5 | | -import { CosmosSignTransactionParams } from '../../types'; |
6 | 6 | import { formatAnyHex } from '../helpers/hexUtils'; |
7 | 7 |
|
| 8 | +import type { CosmosSignTx as HardwareCosmosSignTx } from '@onekeyfe/hd-transport'; |
| 9 | +import type { CosmosSignTransactionParams } from '../../types'; |
| 10 | + |
8 | 11 | export default class CosmosSignTransaction extends BaseMethod<HardwareCosmosSignTx> { |
9 | 12 | hasBundle = false; |
10 | 13 |
|
@@ -40,15 +43,26 @@ export default class CosmosSignTransaction extends BaseMethod<HardwareCosmosSign |
40 | 43 | } |
41 | 44 |
|
42 | 45 | async run() { |
43 | | - const res = await this.device.commands.typedCall('CosmosSignTx', 'CosmosSignedTx', { |
44 | | - ...this.params, |
45 | | - }); |
| 46 | + try { |
| 47 | + const res = await this.device.commands.typedCall('CosmosSignTx', 'CosmosSignedTx', { |
| 48 | + ...this.params, |
| 49 | + }); |
46 | 50 |
|
47 | | - const { signature } = res.message; |
| 51 | + const { signature } = res.message; |
48 | 52 |
|
49 | | - return { |
50 | | - path: serializedPath(this.params.address_n), |
51 | | - signature, |
52 | | - }; |
| 53 | + return { |
| 54 | + path: serializedPath(this.params.address_n), |
| 55 | + signature, |
| 56 | + }; |
| 57 | + } catch (error) { |
| 58 | + const { message } = error; |
| 59 | + if ( |
| 60 | + message.includes('Failure_DataError,Json parse failed') || |
| 61 | + message.includes('Failure_DataError,Invalid message') |
| 62 | + ) { |
| 63 | + throw ERRORS.TypedError(HardwareErrorCode.CosmosInvalidJsonMessage, message); |
| 64 | + } |
| 65 | + throw error; |
| 66 | + } |
53 | 67 | } |
54 | 68 | } |
0 commit comments