@onekeyfe/hd-core 0.1.3 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/api/FirmwareUpdate.d.ts.map +1 -1
  2. package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
  3. package/dist/api/btc/helpers/btcParamsUtils.d.ts.map +1 -1
  4. package/dist/api/btc/helpers/signtx.d.ts.map +1 -1
  5. package/dist/api/btc/helpers/signtxLegacy.d.ts.map +1 -1
  6. package/dist/api/evm/EVMSignTransaction.d.ts.map +1 -1
  7. package/dist/api/evm/EVMSignTypedData.d.ts +1 -2
  8. package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
  9. package/dist/api/firmware/getBinary.d.ts.map +1 -1
  10. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  11. package/dist/api/helpers/paramsValidator.d.ts.map +1 -1
  12. package/dist/api/helpers/pathUtils.d.ts.map +1 -1
  13. package/dist/api/helpers/typeNameUtils.d.ts.map +1 -1
  14. package/dist/api/nem/NEMSignTransaction.d.ts.map +1 -1
  15. package/dist/api/utils.d.ts.map +1 -1
  16. package/dist/constants/errors.d.ts +1 -26
  17. package/dist/constants/errors.d.ts.map +1 -1
  18. package/dist/constants/index.d.ts +1 -1
  19. package/dist/constants/index.d.ts.map +1 -1
  20. package/dist/core/index.d.ts.map +1 -1
  21. package/dist/data-manager/TransportManager.d.ts.map +1 -1
  22. package/dist/device/Device.d.ts +2 -2
  23. package/dist/device/Device.d.ts.map +1 -1
  24. package/dist/device/DeviceCommands.d.ts.map +1 -1
  25. package/dist/device/DeviceConnector.d.ts +2 -2
  26. package/dist/device/DeviceConnector.d.ts.map +1 -1
  27. package/dist/events/core.d.ts +1 -1
  28. package/dist/events/core.d.ts.map +1 -1
  29. package/dist/events/ui-promise.d.ts +1 -1
  30. package/dist/events/ui-promise.d.ts.map +1 -1
  31. package/dist/index.d.ts +87 -134
  32. package/dist/index.js +125 -165
  33. package/dist/types/params.d.ts +1 -1
  34. package/dist/types/params.d.ts.map +1 -1
  35. package/dist/utils/index.d.ts +0 -1
  36. package/dist/utils/index.d.ts.map +1 -1
  37. package/dist/utils/versionUtils.d.ts +1 -1
  38. package/package.json +4 -3
  39. package/src/api/FirmwareUpdate.ts +10 -4
  40. package/src/api/btc/BTCSignTransaction.ts +3 -3
  41. package/src/api/btc/helpers/btcParamsUtils.ts +10 -4
  42. package/src/api/btc/helpers/signtx.ts +33 -15
  43. package/src/api/btc/helpers/signtxLegacy.ts +33 -12
  44. package/src/api/evm/EVMSignTransaction.ts +5 -2
  45. package/src/api/evm/EVMSignTypedData.ts +2 -2
  46. package/src/api/firmware/getBinary.ts +9 -4
  47. package/src/api/firmware/uploadFirmware.ts +4 -3
  48. package/src/api/helpers/bigNumberUtils.ts +4 -4
  49. package/src/api/helpers/paramsValidator.ts +3 -2
  50. package/src/api/helpers/pathUtils.ts +6 -3
  51. package/src/api/helpers/typeNameUtils.ts +7 -4
  52. package/src/api/nem/NEMSignTransaction.ts +5 -2
  53. package/src/api/utils.ts +6 -3
  54. package/src/constants/errors.ts +6 -46
  55. package/src/constants/index.ts +1 -1
  56. package/src/core/index.ts +17 -23
  57. package/src/data-manager/TransportManager.ts +5 -2
  58. package/src/device/Device.ts +11 -6
  59. package/src/device/DeviceCommands.ts +34 -12
  60. package/src/device/DeviceConnector.ts +4 -4
  61. package/src/events/call.ts +1 -1
  62. package/src/events/core.ts +11 -7
  63. package/src/events/ui-promise.ts +1 -1
  64. package/src/types/params.ts +1 -1
  65. package/src/utils/index.ts +0 -1
  66. package/dist/utils/deferred.d.ts +0 -9
  67. package/dist/utils/deferred.d.ts.map +0 -1
  68. package/src/utils/deferred.ts +0 -35
@@ -8,7 +8,7 @@ export interface Unsuccessful {
8
8
  success: false;
9
9
  payload: {
10
10
  error: string;
11
- code?: string;
11
+ code?: string | number;
12
12
  };
13
13
  }
14
14
  export interface Success<T> {
@@ -1 +1 @@
1
- {"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/types/params.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,oBAAY,MAAM,CAAC,CAAC,IAAI,YAAY,GAAG,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAElE,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,KAAK,CAAC;IACf,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3C;AAED,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,OAAO,EAAE,IAAI,CAAC;IACd,OAAO,EAAE,CAAC,CAAC;CACZ;AAED,oBAAY,QAAQ,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC"}
1
+ {"version":3,"file":"params.d.ts","sourceRoot":"","sources":["../../src/types/params.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,YAAY;IAC3B,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,oBAAY,MAAM,CAAC,CAAC,IAAI,YAAY,GAAG,CAAC,GAAG;IAAE,MAAM,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAElE,MAAM,WAAW,YAAY;IAC3B,OAAO,EAAE,KAAK,CAAC;IACf,OAAO,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACpD;AAED,MAAM,WAAW,OAAO,CAAC,CAAC;IACxB,OAAO,EAAE,IAAI,CAAC;IACd,OAAO,EAAE,CAAC,CAAC;CACZ;AAED,oBAAY,QAAQ,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC"}
@@ -1,7 +1,6 @@
1
1
  import { initLog, enableLog } from './logger';
2
2
  export * from './assets';
3
3
  export * from './versionUtils';
4
- export * from './deferred';
5
4
  export { getDeviceType, getDeviceTypeByBleName, getDeviceTypeByDeviceId, getDeviceUUID, getDeviceLabel, } from './deviceFeaturesUtils';
6
5
  export { getHDPath, getScriptType } from '../api/helpers/pathUtils';
7
6
  export { initLog, enableLog };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE9C,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,YAAY,CAAC;AAC3B,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACb,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAE9C,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EACL,aAAa,EACb,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACb,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEpE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC"}
@@ -2,5 +2,5 @@ export declare const isValidVersionString: (version: string) => boolean;
2
2
  export declare const isValidVersionArray: (version: number[]) => boolean;
3
3
  export declare const normalizeVersionArray: (version: number[]) => number[];
4
4
  export declare const versionSplit: (version: string) => number[];
5
- export declare const versionCompare: (a: string | number[], b: string | number[]) => 1 | 0 | -1;
5
+ export declare const versionCompare: (a: string | number[], b: string | number[]) => 0 | 1 | -1;
6
6
  //# sourceMappingURL=versionUtils.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "0.1.3",
3
+ "version": "0.1.6",
4
4
  "description": "> TODO: description",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -25,7 +25,8 @@
25
25
  "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@onekeyfe/hd-transport": "^0.1.3",
28
+ "@onekeyfe/hd-shared": "^0.1.6",
29
+ "@onekeyfe/hd-transport": "^0.1.6",
29
30
  "axios": "^0.27.2",
30
31
  "bignumber.js": "^9.0.2",
31
32
  "parse-uri": "^1.0.7",
@@ -35,5 +36,5 @@
35
36
  "@types/parse-uri": "^1.0.0",
36
37
  "@types/semver": "^7.3.9"
37
38
  },
38
- "gitHead": "64411d3cac440d142574f8aa30c9d60204d47c2c"
39
+ "gitHead": "ebe2789fa24cbfb798c9be445678e71e67e33d71"
39
40
  }
@@ -1,4 +1,4 @@
1
- import { ERRORS } from '../constants';
1
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
2
2
  import { UI_REQUEST } from '../constants/ui-request';
3
3
  import { BaseMethod } from './BaseMethod';
4
4
  import { validateParams } from './helpers/paramsValidator';
@@ -24,7 +24,10 @@ export default class FirmwareUpdate extends BaseMethod<Params> {
24
24
  ]);
25
25
 
26
26
  if (!payload.updateType) {
27
- throw ERRORS.TypedError('Method_InvalidParameter', 'updateType is required');
27
+ throw ERRORS.TypedError(
28
+ HardwareErrorCode.CallMethodInvalidParameter,
29
+ 'updateType is required'
30
+ );
28
31
  }
29
32
 
30
33
  this.params = { updateType: payload.updateType };
@@ -54,7 +57,10 @@ export default class FirmwareUpdate extends BaseMethod<Params> {
54
57
  binary = this.params.binary;
55
58
  } else {
56
59
  if (!device.features) {
57
- throw ERRORS.TypedError('Runtime', 'no features found for this device');
60
+ throw ERRORS.TypedError(
61
+ HardwareErrorCode.RuntimeError,
62
+ 'no features found for this device'
63
+ );
58
64
  }
59
65
  const firmware = await getBinary({
60
66
  features: device.features,
@@ -64,7 +70,7 @@ export default class FirmwareUpdate extends BaseMethod<Params> {
64
70
  binary = firmware.binary;
65
71
  }
66
72
  } catch (err) {
67
- throw ERRORS.TypedError('Method_FirmwareUpdate_DownloadFailed', err);
73
+ throw ERRORS.TypedError(HardwareErrorCode.FirmwareUpdateDownloadFailed, err);
68
74
  }
69
75
 
70
76
  return uploadFirmware(
@@ -1,5 +1,6 @@
1
1
  import { TxInputType, TxOutputType } from '@onekeyfe/hd-transport/src/types/messages';
2
2
 
3
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
3
4
  import { UI_REQUEST } from '../../constants/ui-request';
4
5
  import { getOutputScriptType, isSegwitPath, validatePath } from '../helpers/pathUtils';
5
6
  import { BaseMethod } from '../BaseMethod';
@@ -10,7 +11,6 @@ import {
10
11
  RefTransaction,
11
12
  TransactionOptions,
12
13
  } from '../../types/api/btcSignTransaction';
13
- import { ERRORS } from '../../constants';
14
14
  import signtx from './helpers/signtx';
15
15
  import signtxLegacy from './helpers/signtxLegacy';
16
16
  import { getCoinInfo } from './helpers/btcParamsUtils';
@@ -82,7 +82,7 @@ export default class BTCSignTransaction extends BaseMethod<Params> {
82
82
  Object.prototype.hasOwnProperty.call(output, 'address')
83
83
  ) {
84
84
  throw ERRORS.TypedError(
85
- 'Method_InvalidParameter',
85
+ HardwareErrorCode.CallMethodInvalidParameter,
86
86
  'Cannot use address and address_n in one output'
87
87
  );
88
88
  }
@@ -91,7 +91,7 @@ export default class BTCSignTransaction extends BaseMethod<Params> {
91
91
  const scriptType = getOutputScriptType(output.address_n);
92
92
  if (output.script_type !== scriptType)
93
93
  throw ERRORS.TypedError(
94
- 'Method_InvalidParameter',
94
+ HardwareErrorCode.CallMethodInvalidParameter,
95
95
  `Output change script_type should be set to ${scriptType}`
96
96
  );
97
97
  }
@@ -1,4 +1,4 @@
1
- import { ERRORS } from '../../../constants';
1
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
2
2
  import { getScriptType, isMultisigPath, fromHardened } from '../../helpers/pathUtils';
3
3
  import bitcoin from '../../../data/coins/bitcoin.json';
4
4
 
@@ -22,11 +22,17 @@ export const getCoinInfo = (path: number[] | undefined, coin: string | undefined
22
22
 
23
23
  if (!coinInfo) {
24
24
  if (coin) {
25
- throw ERRORS.TypedError('Method_InvalidParameter', `Invalid coin name: ${coin}`);
25
+ throw ERRORS.TypedError(
26
+ HardwareErrorCode.CallMethodInvalidParameter,
27
+ `Invalid coin name: ${coin}`
28
+ );
26
29
  } else if (path) {
27
- throw ERRORS.TypedError('Method_InvalidParameter', `Invalid path: ${path[0]}`);
30
+ throw ERRORS.TypedError(
31
+ HardwareErrorCode.CallMethodInvalidParameter,
32
+ `Invalid path: ${path[0]}`
33
+ );
28
34
  } else {
29
- throw ERRORS.TypedError('Method_InvalidParameter');
35
+ throw ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter);
30
36
  }
31
37
  }
32
38
 
@@ -10,7 +10,7 @@ import {
10
10
  SignedTransaction,
11
11
  TransactionOptions,
12
12
  } from '@onekeyfe/hd-core/src/types/api/btcSignTransaction';
13
- import { ERRORS } from '../../../constants';
13
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
14
14
 
15
15
  type RefTxs = { [hash: string]: RefTransaction };
16
16
  type Props = {
@@ -26,17 +26,23 @@ type Props = {
26
26
  const requestPrevTxInfo = ({ typedCall, txRequest: { request_type, details }, refTxs }: Props) => {
27
27
  const { tx_hash } = details;
28
28
  if (!tx_hash) {
29
- throw ERRORS.TypedError('Runtime', 'requestPrevTxInfo: unknown details.tx_hash');
29
+ throw ERRORS.TypedError(
30
+ HardwareErrorCode.RuntimeError,
31
+ 'requestPrevTxInfo: unknown details.tx_hash'
32
+ );
30
33
  }
31
34
  const tx = refTxs[tx_hash.toLowerCase()];
32
35
  if (!tx) {
33
- throw ERRORS.TypedError('Runtime', `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
36
+ throw ERRORS.TypedError(
37
+ HardwareErrorCode.RuntimeError,
38
+ `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`
39
+ );
34
40
  }
35
41
  if (request_type === 'TXINPUT') {
36
42
  // bin_outputs not present in tx = invalid RefTransaction object
37
43
  if (!tx.bin_outputs)
38
44
  throw ERRORS.TypedError(
39
- 'Runtime',
45
+ HardwareErrorCode.RuntimeError,
40
46
  `requestPrevTxInfo: Requested unknown TXINPUT: ${tx_hash}`
41
47
  );
42
48
  return typedCall('TxAckPrevInput', 'TxRequest', {
@@ -47,7 +53,7 @@ const requestPrevTxInfo = ({ typedCall, txRequest: { request_type, details }, re
47
53
  // bin_outputs not present in tx = invalid RefTransaction object
48
54
  if (!tx.bin_outputs)
49
55
  throw ERRORS.TypedError(
50
- 'Runtime',
56
+ HardwareErrorCode.RuntimeError,
51
57
  `requestPrevTxInfo: Requested unknown TXOUTPUT: ${tx_hash}`
52
58
  );
53
59
  return typedCall('TxAckPrevOutput', 'TxRequest', {
@@ -58,7 +64,7 @@ const requestPrevTxInfo = ({ typedCall, txRequest: { request_type, details }, re
58
64
  // outputs not present in tx = invalid RefTransaction object
59
65
  if (!tx.outputs)
60
66
  throw ERRORS.TypedError(
61
- 'Runtime',
67
+ HardwareErrorCode.RuntimeError,
62
68
  `requestPrevTxInfo: Requested unknown TXORIGINPUT: ${tx_hash}`
63
69
  );
64
70
  return typedCall('TxAckInput', 'TxRequest', {
@@ -69,7 +75,7 @@ const requestPrevTxInfo = ({ typedCall, txRequest: { request_type, details }, re
69
75
  // outputs not present in tx = invalid RefTransaction object
70
76
  if (!tx.outputs)
71
77
  throw ERRORS.TypedError(
72
- 'Runtime',
78
+ HardwareErrorCode.RuntimeError,
73
79
  `requestPrevTxInfo: Requested unknown TXORIGOUTPUT: ${tx_hash}`
74
80
  );
75
81
  return typedCall('TxAckOutput', 'TxRequest', {
@@ -78,14 +84,20 @@ const requestPrevTxInfo = ({ typedCall, txRequest: { request_type, details }, re
78
84
  }
79
85
  if (request_type === 'TXEXTRADATA') {
80
86
  if (typeof details.extra_data_len !== 'number') {
81
- throw ERRORS.TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_len');
87
+ throw ERRORS.TypedError(
88
+ HardwareErrorCode.RuntimeError,
89
+ 'requestPrevTxInfo: Missing extra_data_len'
90
+ );
82
91
  }
83
92
  if (typeof details.extra_data_offset !== 'number') {
84
- throw ERRORS.TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_offset');
93
+ throw ERRORS.TypedError(
94
+ HardwareErrorCode.RuntimeError,
95
+ 'requestPrevTxInfo: Missing extra_data_offset'
96
+ );
85
97
  }
86
98
  if (typeof tx.extra_data !== 'string') {
87
99
  throw ERRORS.TypedError(
88
- 'Runtime',
100
+ HardwareErrorCode.RuntimeError,
89
101
  `requestPrevTxInfo: No extra data for transaction ${tx.hash}`
90
102
  );
91
103
  }
@@ -110,7 +122,10 @@ const requestPrevTxInfo = ({ typedCall, txRequest: { request_type, details }, re
110
122
  };
111
123
  return typedCall('TxAckPrevMeta', 'TxRequest', { tx: meta });
112
124
  }
113
- throw ERRORS.TypedError('Runtime', `requestPrevTxInfo: Unknown request type: ${request_type}`);
125
+ throw ERRORS.TypedError(
126
+ HardwareErrorCode.RuntimeError,
127
+ `requestPrevTxInfo: Unknown request type: ${request_type}`
128
+ );
114
129
  };
115
130
 
116
131
  const requestSignedTxInfo = ({
@@ -129,17 +144,20 @@ const requestSignedTxInfo = ({
129
144
  }
130
145
  if (request_type === 'TXMETA') {
131
146
  throw ERRORS.TypedError(
132
- 'Runtime',
147
+ HardwareErrorCode.RuntimeError,
133
148
  'requestSignedTxInfo: Cannot read TXMETA from signed transaction'
134
149
  );
135
150
  }
136
151
  if (request_type === 'TXEXTRADATA') {
137
152
  throw ERRORS.TypedError(
138
- 'Runtime',
153
+ HardwareErrorCode.RuntimeError,
139
154
  'requestSignedTxInfo: Cannot read TXEXTRADATA from signed transaction'
140
155
  );
141
156
  }
142
- throw ERRORS.TypedError('Runtime', `requestSignedTxInfo: Unknown request type: ${request_type}`);
157
+ throw ERRORS.TypedError(
158
+ HardwareErrorCode.RuntimeError,
159
+ `requestSignedTxInfo: Unknown request type: ${request_type}`
160
+ );
143
161
  };
144
162
 
145
163
  // requests information about a transaction
@@ -165,7 +183,7 @@ const saveTxSignatures = (
165
183
  if (typeof signature_index === 'number') {
166
184
  if (!signature) {
167
185
  throw ERRORS.TypedError(
168
- 'Runtime',
186
+ HardwareErrorCode.RuntimeError,
169
187
  'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.'
170
188
  );
171
189
  }
@@ -6,7 +6,7 @@ import {
6
6
  TxRequestSerializedType,
7
7
  TypedCall,
8
8
  } from '@onekeyfe/hd-transport/src/types/messages';
9
- import { ERRORS } from '../../../constants';
9
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
10
10
  import {
11
11
  RefTransaction,
12
12
  SignedTransaction,
@@ -30,14 +30,23 @@ const requestPrevTxInfo = ({
30
30
  }: Props): TxAckResponse => {
31
31
  const { tx_hash } = details;
32
32
  if (!tx_hash) {
33
- throw ERRORS.TypedError('Runtime', 'requestPrevTxInfo: unknown details.tx_hash');
33
+ throw ERRORS.TypedError(
34
+ HardwareErrorCode.RuntimeError,
35
+ 'requestPrevTxInfo: unknown details.tx_hash'
36
+ );
34
37
  }
35
38
  const tx = refTxs[tx_hash.toLowerCase()];
36
39
  if (!tx) {
37
- throw ERRORS.TypedError('Runtime', `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`);
40
+ throw ERRORS.TypedError(
41
+ HardwareErrorCode.RuntimeError,
42
+ `requestPrevTxInfo: Requested unknown tx: ${tx_hash}`
43
+ );
38
44
  }
39
45
  if (!tx.bin_outputs) {
40
- throw ERRORS.TypedError('Runtime', `requestPrevTxInfo: bin_outputs not set tx: ${tx_hash}`);
46
+ throw ERRORS.TypedError(
47
+ HardwareErrorCode.RuntimeError,
48
+ `requestPrevTxInfo: bin_outputs not set tx: ${tx_hash}`
49
+ );
41
50
  }
42
51
  if (request_type === 'TXINPUT') {
43
52
  return { inputs: [tx.inputs[details.request_index]] };
@@ -47,14 +56,20 @@ const requestPrevTxInfo = ({
47
56
  }
48
57
  if (request_type === 'TXEXTRADATA') {
49
58
  if (typeof details.extra_data_len !== 'number') {
50
- throw ERRORS.TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_len');
59
+ throw ERRORS.TypedError(
60
+ HardwareErrorCode.RuntimeError,
61
+ 'requestPrevTxInfo: Missing extra_data_len'
62
+ );
51
63
  }
52
64
  if (typeof details.extra_data_offset !== 'number') {
53
- throw ERRORS.TypedError('Runtime', 'requestPrevTxInfo: Missing extra_data_offset');
65
+ throw ERRORS.TypedError(
66
+ HardwareErrorCode.RuntimeError,
67
+ 'requestPrevTxInfo: Missing extra_data_offset'
68
+ );
54
69
  }
55
70
  if (typeof tx.extra_data !== 'string') {
56
71
  throw ERRORS.TypedError(
57
- 'Runtime',
72
+ HardwareErrorCode.RuntimeError,
58
73
  `requestPrevTxInfo: No extra data for transaction ${tx.hash}`
59
74
  );
60
75
  }
@@ -85,7 +100,10 @@ const requestPrevTxInfo = ({
85
100
  }
86
101
  return meta;
87
102
  }
88
- throw ERRORS.TypedError('Runtime', `requestPrevTxInfo: Unknown request type: ${request_type}`);
103
+ throw ERRORS.TypedError(
104
+ HardwareErrorCode.RuntimeError,
105
+ `requestPrevTxInfo: Unknown request type: ${request_type}`
106
+ );
89
107
  };
90
108
 
91
109
  const requestSignedTxInfo = ({
@@ -101,17 +119,20 @@ const requestSignedTxInfo = ({
101
119
  }
102
120
  if (request_type === 'TXMETA') {
103
121
  throw ERRORS.TypedError(
104
- 'Runtime',
122
+ HardwareErrorCode.RuntimeError,
105
123
  'requestSignedTxInfo: Cannot read TXMETA from signed transaction'
106
124
  );
107
125
  }
108
126
  if (request_type === 'TXEXTRADATA') {
109
127
  throw ERRORS.TypedError(
110
- 'Runtime',
128
+ HardwareErrorCode.RuntimeError,
111
129
  'requestSignedTxInfo: Cannot read TXEXTRADATA from signed transaction'
112
130
  );
113
131
  }
114
- throw ERRORS.TypedError('Runtime', `requestSignedTxInfo: Unknown request type: ${request_type}`);
132
+ throw ERRORS.TypedError(
133
+ HardwareErrorCode.RuntimeError,
134
+ `requestSignedTxInfo: Unknown request type: ${request_type}`
135
+ );
115
136
  };
116
137
 
117
138
  // requests information about a transaction
@@ -137,7 +158,7 @@ const saveTxSignatures = (
137
158
  if (typeof signature_index === 'number') {
138
159
  if (!signature) {
139
160
  throw ERRORS.TypedError(
140
- 'Runtime',
161
+ HardwareErrorCode.RuntimeError,
141
162
  'saveTxSignatures: Unexpected null in trezor:TxRequestSerialized signature.'
142
163
  );
143
164
  }
@@ -4,6 +4,7 @@ import {
4
4
  EthereumTxRequest,
5
5
  } from '@onekeyfe/hd-transport/src/types/messages';
6
6
 
7
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
7
8
  import { UI_REQUEST } from '../../constants/ui-request';
8
9
  import { validatePath } from '../helpers/pathUtils';
9
10
  import { BaseMethod } from '../BaseMethod';
@@ -16,7 +17,6 @@ import {
16
17
  } from '../../types/api/evmSignTransaction';
17
18
  import { cutString } from '../helpers/stringUtils';
18
19
  import { formatAnyHex, stripHexStartZeroes } from '../helpers/hexUtils';
19
- import { ERRORS } from '../../constants';
20
20
 
21
21
  export default class EVMSignTransaction extends BaseMethod {
22
22
  addressN: number[] = [];
@@ -71,7 +71,10 @@ export default class EVMSignTransaction extends BaseMethod {
71
71
  const s = request.signature_s;
72
72
 
73
73
  if (v == null || r == null || s == null) {
74
- throw ERRORS.TypedError('Runtime', 'processTxRequest: Unexpected request');
74
+ throw ERRORS.TypedError(
75
+ HardwareErrorCode.RuntimeError,
76
+ 'processTxRequest: Unexpected request'
77
+ );
75
78
  }
76
79
 
77
80
  // if v is not 27 or 28, it is a legacy transaction
@@ -5,12 +5,12 @@ import {
5
5
  EthereumTypedDataStructAck,
6
6
  MessageKey,
7
7
  } from '@onekeyfe/hd-transport/src/types/messages';
8
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
8
9
  import { UI_REQUEST } from '../../constants/ui-request';
9
10
  import { validatePath } from '../helpers/pathUtils';
10
11
  import { BaseMethod } from '../BaseMethod';
11
12
  import { validateParams } from '../helpers/paramsValidator';
12
13
  import { formatAnyHex } from '../helpers/hexUtils';
13
- import { ERRORS } from '../../constants';
14
14
  import { encodeData, getFieldType, parseArrayType } from '../helpers/typeNameUtils';
15
15
  import {
16
16
  EthereumSignTypedDataMessage,
@@ -55,7 +55,7 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
55
55
  this.params.messageHash = formatAnyHex(messageHash);
56
56
  } else if (!!data && (!data.primaryType || data.primaryType !== 'EIP712Domain')) {
57
57
  throw ERRORS.TypedError(
58
- 'Method_InvalidParameter',
58
+ HardwareErrorCode.CallMethodInvalidParameter,
59
59
  'message_hash should only be empty when data.primaryType=EIP712Domain'
60
60
  );
61
61
  }
@@ -1,8 +1,8 @@
1
1
  import semver from 'semver';
2
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
2
3
  import { Features } from '../../types';
3
4
  import { getDeviceType, httpRequest } from '../../utils';
4
5
  import { DataManager } from '../../data-manager';
5
- import { ERRORS } from '../../constants';
6
6
 
7
7
  export interface GetInfoProps {
8
8
  features: Features;
@@ -17,19 +17,24 @@ export const getBinary = async ({ features, updateType, version }: GetBinaryProp
17
17
  const releaseInfo = getInfo({ features, updateType });
18
18
 
19
19
  if (!releaseInfo) {
20
- throw ERRORS.TypedError('Runtime', 'no firmware found for this device');
20
+ throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'no firmware found for this device');
21
21
  }
22
22
 
23
23
  if (
24
24
  version &&
25
25
  !semver.eq(releaseInfo.version as unknown as semver.SemVer, version as unknown as semver.SemVer)
26
26
  ) {
27
- throw ERRORS.TypedError('Runtime', 'firmware version mismatch');
27
+ throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'firmware version mismatch');
28
28
  }
29
29
 
30
30
  // @ts-expect-error
31
31
  const url = updateType === 'ble' ? releaseInfo.webUpdate : releaseInfo.url;
32
- const fw = await httpRequest(url, 'binary');
32
+ let fw;
33
+ try {
34
+ fw = await httpRequest(url, 'binary');
35
+ } catch {
36
+ throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Method_FirmwareUpdate_DownloadFailed');
37
+ }
33
38
 
34
39
  return {
35
40
  ...releaseInfo,
@@ -1,5 +1,6 @@
1
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
1
2
  import { DEVICE, CoreMessage, createUiMessage, UI_REQUEST } from '../../events';
2
- import { ERRORS, PROTO } from '../../constants';
3
+ import { PROTO } from '../../constants';
3
4
  import type { Device } from '../../device/Device';
4
5
  import type { TypedCall } from '../../device/DeviceCommands';
5
6
  import { KnownDevice } from '../../types';
@@ -39,7 +40,7 @@ export const uploadFirmware = async (
39
40
  const { message } = await typedCall('FirmwareUpload', 'Success', {
40
41
  payload,
41
42
  });
42
-
43
+ postProgressMessage(device, 100, postMessage);
43
44
  return message;
44
45
  }
45
46
 
@@ -68,5 +69,5 @@ export const uploadFirmware = async (
68
69
  return response.message;
69
70
  }
70
71
 
71
- throw ERRORS.TypedError('Runtime', 'uploadFirmware: unknown major_version');
72
+ throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'uploadFirmware: unknown major_version');
72
73
  };
@@ -1,5 +1,5 @@
1
1
  import BigNumber from 'bignumber.js';
2
- import { ERRORS } from '../../constants';
2
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
3
3
 
4
4
  /**
5
5
  * Converts a number to a two's complement representation.
@@ -20,7 +20,7 @@ export const twosComplement = (number: BigNumber, bytes: number): BigNumber => {
20
20
 
21
21
  if (bigNumber.isGreaterThan(maxValue) || bigNumber.isLessThan(minValue)) {
22
22
  throw ERRORS.TypedError(
23
- 'Runtime',
23
+ HardwareErrorCode.RuntimeError,
24
24
  `Overflow when trying to convert number ${number.toString()} into ${bytes} bytes`
25
25
  );
26
26
  }
@@ -42,7 +42,7 @@ export const intToHex = (
42
42
  }
43
43
  if (bigNumber.isNegative()) {
44
44
  throw ERRORS.TypedError(
45
- 'Runtime',
45
+ HardwareErrorCode.RuntimeError,
46
46
  `Cannot convert negative number to unsigned interger: ${number.toString()}`
47
47
  );
48
48
  }
@@ -50,7 +50,7 @@ export const intToHex = (
50
50
  const hexChars = bytes * 2;
51
51
  if (hex.length > hexChars) {
52
52
  throw ERRORS.TypedError(
53
- 'Runtime',
53
+ HardwareErrorCode.RuntimeError,
54
54
  `Overflow when trying to convert number ${number.toString()} into ${bytes} bytes`
55
55
  );
56
56
  }
@@ -1,6 +1,6 @@
1
1
  import BigNumber from 'bignumber.js';
2
2
 
3
- import { ERRORS } from '../../constants';
3
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
4
4
  import { addHexPrefix, isHexString } from './hexUtils';
5
5
 
6
6
  export type SchemaParam = {
@@ -18,7 +18,8 @@ export type SchemaParam = {
18
18
  allowEmpty?: boolean;
19
19
  };
20
20
 
21
- const invalidParameter = (message: string) => ERRORS.TypedError('Method_InvalidParameter', message);
21
+ const invalidParameter = (message: string) =>
22
+ ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter, message);
22
23
 
23
24
  export const validateParams = (values: any, fields: Array<SchemaParam>): void => {
24
25
  fields.forEach(field => {
@@ -1,15 +1,18 @@
1
1
  /* eslint-disable no-bitwise */
2
2
 
3
3
  import { ChangeOutputScriptType, InputScriptType } from '@onekeyfe/hd-transport/src/types/messages';
4
- import { ERRORS } from '../../constants';
4
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
5
5
 
6
6
  const HD_HARDENED = 0x80000000;
7
7
  export const toHardened = (n: number): number => (n | HD_HARDENED) >>> 0;
8
8
  export const fromHardened = (n: number): number => (n & ~HD_HARDENED) >>> 0;
9
9
 
10
- const PATH_NOT_VALID = ERRORS.TypedError('Method_InvalidParameter', 'Not a valid path');
10
+ const PATH_NOT_VALID = ERRORS.TypedError(
11
+ HardwareErrorCode.CallMethodInvalidParameter,
12
+ 'Not a valid path'
13
+ );
11
14
  const PATH_NEGATIVE_VALUES = ERRORS.TypedError(
12
- 'Method_InvalidParameter',
15
+ HardwareErrorCode.CallMethodInvalidParameter,
13
16
  'Path cannot contain negative values'
14
17
  );
15
18
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { EthereumDataType, EthereumFieldType } from '@onekeyfe/hd-transport/src/types/messages';
4
4
 
5
- import { ERRORS } from '../../constants';
5
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
6
6
  import { EthereumSignTypedDataTypes } from '../../types/api/evmSignTypedData';
7
7
  import { intToHex } from './bigNumberUtils';
8
8
  import { formatAnyHex } from './hexUtils';
@@ -25,7 +25,7 @@ export const parseArrayType = (
25
25
  const arrayMatch = paramTypeArray.exec(arrayTypeName);
26
26
  if (arrayMatch === null) {
27
27
  throw ERRORS.TypedError(
28
- 'Runtime',
28
+ HardwareErrorCode.RuntimeError,
29
29
  `typename ${arrayTypeName} could not be parsed as an EIP-712 array`
30
30
  );
31
31
  }
@@ -62,7 +62,7 @@ export const encodeData = (typeName: string, data: any): string => {
62
62
 
63
63
  // We should be receiving only atomic, non-array types
64
64
  throw ERRORS.TypedError(
65
- 'Runtime',
65
+ HardwareErrorCode.RuntimeError,
66
66
  `Unsupported data type for direct field encoding: ${typeName}`
67
67
  );
68
68
  };
@@ -128,5 +128,8 @@ export const getFieldType = (
128
128
  };
129
129
  }
130
130
 
131
- throw ERRORS.TypedError('Runtime', `No type definition specified: ${typeName}`);
131
+ throw ERRORS.TypedError(
132
+ HardwareErrorCode.RuntimeError,
133
+ `No type definition specified: ${typeName}`
134
+ );
132
135
  };
@@ -10,6 +10,7 @@ import {
10
10
  NEMTransfer,
11
11
  } from '@onekeyfe/hd-transport/src/types/messages';
12
12
 
13
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
13
14
  import { UI_REQUEST } from '../../constants/ui-request';
14
15
  import { validatePath } from '../helpers/pathUtils';
15
16
  import { BaseMethod } from '../BaseMethod';
@@ -23,7 +24,6 @@ import {
23
24
  NEMTransaction,
24
25
  NEMTransferTransaction,
25
26
  } from '../../types';
26
- import { ERRORS } from '../../constants';
27
27
 
28
28
  const NEM_TRANSFER = 0x0101;
29
29
  const NEM_COSIGNING = 0x0102;
@@ -217,7 +217,10 @@ export default class NEMSignTransaction extends BaseMethod<NEMSignTx> {
217
217
  break;
218
218
 
219
219
  default:
220
- throw ERRORS.TypedError('Method_InvalidParameter', 'Unknown transaction type');
220
+ throw ERRORS.TypedError(
221
+ HardwareErrorCode.CallMethodInvalidParameter,
222
+ 'Unknown transaction type'
223
+ );
221
224
  }
222
225
 
223
226
  return message;