@onekeyfe/hd-core 0.1.6 → 0.1.9

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 (241) hide show
  1. package/dist/api/CipherKeyValue.d.ts +1 -1
  2. package/dist/api/CipherKeyValue.d.ts.map +1 -1
  3. package/dist/api/FirmwareUpdate.d.ts +1 -3
  4. package/dist/api/FirmwareUpdate.d.ts.map +1 -1
  5. package/dist/api/GetFeatures.d.ts +1 -47
  6. package/dist/api/GetFeatures.d.ts.map +1 -1
  7. package/dist/api/btc/BTCGetAddress.d.ts +1 -1
  8. package/dist/api/btc/BTCGetAddress.d.ts.map +1 -1
  9. package/dist/api/btc/BTCGetPublicKey.d.ts +1 -1
  10. package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -1
  11. package/dist/api/btc/BTCSignMessage.d.ts +2 -5
  12. package/dist/api/btc/BTCSignMessage.d.ts.map +1 -1
  13. package/dist/api/btc/BTCSignTransaction.d.ts +1 -1
  14. package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -1
  15. package/dist/api/btc/BTCVerifyMessage.d.ts +2 -4
  16. package/dist/api/btc/BTCVerifyMessage.d.ts.map +1 -1
  17. package/dist/api/btc/helpers/signtx.d.ts +1 -1
  18. package/dist/api/btc/helpers/signtx.d.ts.map +1 -1
  19. package/dist/api/btc/helpers/signtxLegacy.d.ts +1 -1
  20. package/dist/api/btc/helpers/signtxLegacy.d.ts.map +1 -1
  21. package/dist/api/device/DeviceBackup.d.ts +2 -4
  22. package/dist/api/device/DeviceBackup.d.ts.map +1 -1
  23. package/dist/api/device/DeviceChangePin.d.ts +2 -4
  24. package/dist/api/device/DeviceChangePin.d.ts.map +1 -1
  25. package/dist/api/device/DeviceFlags.d.ts +2 -4
  26. package/dist/api/device/DeviceFlags.d.ts.map +1 -1
  27. package/dist/api/device/DeviceRebootToBootloader.d.ts +2 -4
  28. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
  29. package/dist/api/device/DeviceRecovery.d.ts +2 -4
  30. package/dist/api/device/DeviceRecovery.d.ts.map +1 -1
  31. package/dist/api/device/DeviceReset.d.ts +2 -4
  32. package/dist/api/device/DeviceReset.d.ts.map +1 -1
  33. package/dist/api/device/DeviceSettings.d.ts +2 -4
  34. package/dist/api/device/DeviceSettings.d.ts.map +1 -1
  35. package/dist/api/device/DeviceUpdateReboot.d.ts +2 -4
  36. package/dist/api/device/DeviceUpdateReboot.d.ts.map +1 -1
  37. package/dist/api/device/DeviceVerify.d.ts +8 -0
  38. package/dist/api/device/DeviceVerify.d.ts.map +1 -0
  39. package/dist/api/device/DeviceWipe.d.ts +2 -4
  40. package/dist/api/device/DeviceWipe.d.ts.map +1 -1
  41. package/dist/api/evm/EVMGetAddress.d.ts +1 -1
  42. package/dist/api/evm/EVMGetAddress.d.ts.map +1 -1
  43. package/dist/api/evm/EVMGetPublicKey.d.ts +1 -1
  44. package/dist/api/evm/EVMGetPublicKey.d.ts.map +1 -1
  45. package/dist/api/evm/EVMSignMessage.d.ts +2 -5
  46. package/dist/api/evm/EVMSignMessage.d.ts.map +1 -1
  47. package/dist/api/evm/EVMSignMessageEIP712.d.ts +2 -5
  48. package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
  49. package/dist/api/evm/EVMSignTransaction.d.ts +1 -1
  50. package/dist/api/evm/EVMSignTransaction.d.ts.map +1 -1
  51. package/dist/api/evm/EVMSignTypedData.d.ts +6 -5
  52. package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
  53. package/dist/api/evm/EVMVerifyMessage.d.ts +2 -4
  54. package/dist/api/evm/EVMVerifyMessage.d.ts.map +1 -1
  55. package/dist/api/firmware/uploadFirmware.d.ts +1 -3
  56. package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
  57. package/dist/api/helpers/pathUtils.d.ts +1 -1
  58. package/dist/api/helpers/pathUtils.d.ts.map +1 -1
  59. package/dist/api/helpers/typeNameUtils.d.ts +1 -1
  60. package/dist/api/helpers/typeNameUtils.d.ts.map +1 -1
  61. package/dist/api/index.d.ts +1 -0
  62. package/dist/api/index.d.ts.map +1 -1
  63. package/dist/api/nem/NEMGetAddress.d.ts +1 -1
  64. package/dist/api/nem/NEMGetAddress.d.ts.map +1 -1
  65. package/dist/api/nem/NEMSignTransaction.d.ts +1 -1
  66. package/dist/api/nem/NEMSignTransaction.d.ts.map +1 -1
  67. package/dist/api/solana/SolGetAddress.d.ts +1 -1
  68. package/dist/api/solana/SolGetAddress.d.ts.map +1 -1
  69. package/dist/api/solana/SolSignTransaction.d.ts +1 -1
  70. package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
  71. package/dist/api/starcoin/StarcoinGetAddress.d.ts +1 -1
  72. package/dist/api/starcoin/StarcoinGetAddress.d.ts.map +1 -1
  73. package/dist/api/starcoin/StarcoinGetPublicKey.d.ts +1 -1
  74. package/dist/api/starcoin/StarcoinGetPublicKey.d.ts.map +1 -1
  75. package/dist/api/starcoin/StarcoinSignMessage.d.ts +2 -5
  76. package/dist/api/starcoin/StarcoinSignMessage.d.ts.map +1 -1
  77. package/dist/api/starcoin/StarcoinSignTransaction.d.ts +2 -5
  78. package/dist/api/starcoin/StarcoinSignTransaction.d.ts.map +1 -1
  79. package/dist/api/starcoin/StarcoinVerifyMessage.d.ts +2 -4
  80. package/dist/api/starcoin/StarcoinVerifyMessage.d.ts.map +1 -1
  81. package/dist/api/stellar/StellarGetAddress.d.ts +1 -1
  82. package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -1
  83. package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
  84. package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
  85. package/dist/core/index.d.ts.map +1 -1
  86. package/dist/device/Device.d.ts +1 -1
  87. package/dist/device/Device.d.ts.map +1 -1
  88. package/dist/events/ui-request.d.ts +1 -0
  89. package/dist/events/ui-request.d.ts.map +1 -1
  90. package/dist/index.d.ts +16 -51
  91. package/dist/index.js +244 -2
  92. package/dist/inject.d.ts.map +1 -1
  93. package/dist/types/api/btcGetAddress.d.ts +1 -1
  94. package/dist/types/api/btcGetAddress.d.ts.map +1 -1
  95. package/dist/types/api/btcGetPublicKey.d.ts +1 -1
  96. package/dist/types/api/btcGetPublicKey.d.ts.map +1 -1
  97. package/dist/types/api/btcSignMessage.d.ts +1 -1
  98. package/dist/types/api/btcSignMessage.d.ts.map +1 -1
  99. package/dist/types/api/btcSignTransaction.d.ts +1 -1
  100. package/dist/types/api/btcSignTransaction.d.ts.map +1 -1
  101. package/dist/types/api/btcVerifyMessage.d.ts +1 -1
  102. package/dist/types/api/btcVerifyMessage.d.ts.map +1 -1
  103. package/dist/types/api/cipherKeyValue.d.ts +1 -1
  104. package/dist/types/api/cipherKeyValue.d.ts.map +1 -1
  105. package/dist/types/api/deviceBackup.d.ts +1 -1
  106. package/dist/types/api/deviceBackup.d.ts.map +1 -1
  107. package/dist/types/api/deviceChangePin.d.ts +1 -1
  108. package/dist/types/api/deviceChangePin.d.ts.map +1 -1
  109. package/dist/types/api/deviceFlags.d.ts +1 -1
  110. package/dist/types/api/deviceFlags.d.ts.map +1 -1
  111. package/dist/types/api/deviceRebootToBootloader.d.ts +1 -1
  112. package/dist/types/api/deviceRebootToBootloader.d.ts.map +1 -1
  113. package/dist/types/api/deviceRecovery.d.ts +1 -1
  114. package/dist/types/api/deviceRecovery.d.ts.map +1 -1
  115. package/dist/types/api/deviceReset.d.ts +1 -1
  116. package/dist/types/api/deviceReset.d.ts.map +1 -1
  117. package/dist/types/api/deviceSettings.d.ts +1 -1
  118. package/dist/types/api/deviceSettings.d.ts.map +1 -1
  119. package/dist/types/api/deviceUpdateReboot.d.ts +1 -1
  120. package/dist/types/api/deviceUpdateReboot.d.ts.map +1 -1
  121. package/dist/types/api/deviceVerify.d.ts +11 -0
  122. package/dist/types/api/deviceVerify.d.ts.map +1 -0
  123. package/dist/types/api/deviceWipe.d.ts +1 -1
  124. package/dist/types/api/deviceWipe.d.ts.map +1 -1
  125. package/dist/types/api/evmGetPublicKey.d.ts +1 -1
  126. package/dist/types/api/evmGetPublicKey.d.ts.map +1 -1
  127. package/dist/types/api/evmSignMessage.d.ts +1 -1
  128. package/dist/types/api/evmSignMessage.d.ts.map +1 -1
  129. package/dist/types/api/evmSignMessageEIP712.d.ts +1 -1
  130. package/dist/types/api/evmSignMessageEIP712.d.ts.map +1 -1
  131. package/dist/types/api/evmSignTypedData.d.ts +1 -1
  132. package/dist/types/api/evmSignTypedData.d.ts.map +1 -1
  133. package/dist/types/api/evmVerifyMessage.d.ts +1 -1
  134. package/dist/types/api/evmVerifyMessage.d.ts.map +1 -1
  135. package/dist/types/api/export.d.ts +1 -0
  136. package/dist/types/api/export.d.ts.map +1 -1
  137. package/dist/types/api/index.d.ts +2 -0
  138. package/dist/types/api/index.d.ts.map +1 -1
  139. package/dist/types/api/nemGetAddress.d.ts +1 -1
  140. package/dist/types/api/nemGetAddress.d.ts.map +1 -1
  141. package/dist/types/api/nemSignTransaction.d.ts +1 -1
  142. package/dist/types/api/nemSignTransaction.d.ts.map +1 -1
  143. package/dist/types/api/solGetAddress.d.ts +1 -1
  144. package/dist/types/api/solGetAddress.d.ts.map +1 -1
  145. package/dist/types/api/solSignTransaction.d.ts +1 -1
  146. package/dist/types/api/solSignTransaction.d.ts.map +1 -1
  147. package/dist/types/api/starcoinGetAddress.d.ts +1 -1
  148. package/dist/types/api/starcoinGetAddress.d.ts.map +1 -1
  149. package/dist/types/api/starcoinGetPublicKey.d.ts +1 -1
  150. package/dist/types/api/starcoinGetPublicKey.d.ts.map +1 -1
  151. package/dist/types/api/starcoinSignMessage.d.ts +1 -1
  152. package/dist/types/api/starcoinSignMessage.d.ts.map +1 -1
  153. package/dist/types/api/starcoinSignTransaction.d.ts +1 -1
  154. package/dist/types/api/starcoinSignTransaction.d.ts.map +1 -1
  155. package/dist/types/api/starcoinVerifyMessage.d.ts +1 -1
  156. package/dist/types/api/starcoinVerifyMessage.d.ts.map +1 -1
  157. package/dist/types/api/stellarGetAddress.d.ts +1 -1
  158. package/dist/types/api/stellarGetAddress.d.ts.map +1 -1
  159. package/dist/types/api/stellarSignTransaction.d.ts +1 -1
  160. package/dist/types/api/stellarSignTransaction.d.ts.map +1 -1
  161. package/dist/utils/deviceFeaturesUtils.d.ts +3 -94
  162. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  163. package/package.json +4 -4
  164. package/src/api/CipherKeyValue.ts +1 -1
  165. package/src/api/btc/BTCGetAddress.ts +1 -1
  166. package/src/api/btc/BTCGetPublicKey.ts +1 -1
  167. package/src/api/btc/BTCSignMessage.ts +1 -1
  168. package/src/api/btc/BTCSignTransaction.ts +1 -1
  169. package/src/api/btc/BTCVerifyMessage.ts +1 -1
  170. package/src/api/btc/helpers/signtx.ts +1 -1
  171. package/src/api/btc/helpers/signtxLegacy.ts +1 -1
  172. package/src/api/device/DeviceBackup.ts +1 -1
  173. package/src/api/device/DeviceChangePin.ts +1 -1
  174. package/src/api/device/DeviceFlags.ts +1 -1
  175. package/src/api/device/DeviceRebootToBootloader.ts +1 -1
  176. package/src/api/device/DeviceRecovery.ts +1 -1
  177. package/src/api/device/DeviceReset.ts +1 -1
  178. package/src/api/device/DeviceSettings.ts +1 -1
  179. package/src/api/device/DeviceUpdateReboot.ts +1 -1
  180. package/src/api/device/DeviceVerify.ts +55 -0
  181. package/src/api/device/DeviceWipe.ts +1 -1
  182. package/src/api/evm/EVMGetAddress.ts +1 -1
  183. package/src/api/evm/EVMGetPublicKey.ts +1 -1
  184. package/src/api/evm/EVMSignMessage.ts +1 -1
  185. package/src/api/evm/EVMSignMessageEIP712.ts +1 -1
  186. package/src/api/evm/EVMSignTransaction.ts +1 -5
  187. package/src/api/evm/EVMSignTypedData.ts +119 -124
  188. package/src/api/evm/EVMVerifyMessage.ts +1 -1
  189. package/src/api/helpers/pathUtils.ts +1 -1
  190. package/src/api/helpers/typeNameUtils.ts +1 -1
  191. package/src/api/index.ts +1 -0
  192. package/src/api/nem/NEMGetAddress.ts +1 -1
  193. package/src/api/nem/NEMSignTransaction.ts +1 -1
  194. package/src/api/solana/SolGetAddress.ts +3 -1
  195. package/src/api/solana/SolSignTransaction.ts +3 -1
  196. package/src/api/starcoin/StarcoinGetAddress.ts +1 -1
  197. package/src/api/starcoin/StarcoinGetPublicKey.ts +1 -1
  198. package/src/api/starcoin/StarcoinSignMessage.ts +1 -1
  199. package/src/api/starcoin/StarcoinSignTransaction.ts +1 -1
  200. package/src/api/starcoin/StarcoinVerifyMessage.ts +1 -1
  201. package/src/api/stellar/StellarGetAddress.ts +1 -1
  202. package/src/api/stellar/StellarSignTransaction.ts +1 -1
  203. package/src/core/index.ts +5 -0
  204. package/src/device/Device.ts +4 -1
  205. package/src/events/ui-request.ts +2 -0
  206. package/src/inject.ts +1 -0
  207. package/src/types/api/btcGetAddress.ts +1 -1
  208. package/src/types/api/btcGetPublicKey.ts +1 -1
  209. package/src/types/api/btcSignMessage.ts +1 -1
  210. package/src/types/api/btcSignTransaction.ts +1 -1
  211. package/src/types/api/btcVerifyMessage.ts +1 -1
  212. package/src/types/api/cipherKeyValue.ts +1 -1
  213. package/src/types/api/deviceBackup.ts +1 -1
  214. package/src/types/api/deviceChangePin.ts +1 -1
  215. package/src/types/api/deviceFlags.ts +1 -1
  216. package/src/types/api/deviceRebootToBootloader.ts +1 -1
  217. package/src/types/api/deviceRecovery.ts +1 -1
  218. package/src/types/api/deviceReset.ts +1 -1
  219. package/src/types/api/deviceSettings.ts +1 -1
  220. package/src/types/api/deviceUpdateReboot.ts +1 -1
  221. package/src/types/api/deviceVerify.ts +15 -0
  222. package/src/types/api/deviceWipe.ts +1 -1
  223. package/src/types/api/evmGetPublicKey.ts +1 -1
  224. package/src/types/api/evmSignMessage.ts +1 -1
  225. package/src/types/api/evmSignMessageEIP712.ts +1 -1
  226. package/src/types/api/evmSignTypedData.ts +1 -1
  227. package/src/types/api/evmVerifyMessage.ts +1 -1
  228. package/src/types/api/export.ts +1 -0
  229. package/src/types/api/index.ts +2 -0
  230. package/src/types/api/nemGetAddress.ts +1 -1
  231. package/src/types/api/nemSignTransaction.ts +1 -1
  232. package/src/types/api/solGetAddress.ts +1 -1
  233. package/src/types/api/solSignTransaction.ts +1 -1
  234. package/src/types/api/starcoinGetAddress.ts +1 -1
  235. package/src/types/api/starcoinGetPublicKey.ts +1 -1
  236. package/src/types/api/starcoinSignMessage.ts +1 -1
  237. package/src/types/api/starcoinSignTransaction.ts +1 -1
  238. package/src/types/api/starcoinVerifyMessage.ts +1 -1
  239. package/src/types/api/stellarGetAddress.ts +1 -1
  240. package/src/types/api/stellarSignTransaction.ts +1 -1
  241. package/src/utils/deviceFeaturesUtils.ts +11 -0
@@ -1,23 +1,20 @@
1
1
  import semver from 'semver';
2
- import {
3
- EthereumMessageSignature,
2
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
3
+ import type {
4
4
  EthereumTypedDataSignature,
5
5
  EthereumTypedDataStructAck,
6
- MessageKey,
7
- } from '@onekeyfe/hd-transport/src/types/messages';
8
- import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
6
+ } from '@onekeyfe/hd-transport';
9
7
  import { UI_REQUEST } from '../../constants/ui-request';
10
8
  import { validatePath } from '../helpers/pathUtils';
11
9
  import { BaseMethod } from '../BaseMethod';
12
10
  import { validateParams } from '../helpers/paramsValidator';
13
11
  import { formatAnyHex } from '../helpers/hexUtils';
14
12
  import { encodeData, getFieldType, parseArrayType } from '../helpers/typeNameUtils';
15
- import {
13
+ import { getDeviceFirmwareVersion, getDeviceType } from '../../utils/deviceFeaturesUtils';
14
+ import type {
16
15
  EthereumSignTypedDataMessage,
17
16
  EthereumSignTypedDataTypes,
18
17
  } from '../../types/api/evmSignTypedData';
19
- import { getDeviceFirmwareVersion, getDeviceType } from '../../utils/deviceFeaturesUtils';
20
- import { TypedResponseMessage } from '../../device/DeviceCommands';
21
18
 
22
19
  export type EVMSignTypedDataParams = {
23
20
  addressN: number[];
@@ -62,120 +59,119 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
62
59
  }
63
60
  }
64
61
 
65
- // async signTypedData() {
66
- // const { commands } = this.device;
67
- // const { addressN, data, metamaskV4Compat } = this.params;
68
-
69
- // const {
70
- // types,
71
- // primaryType,
72
- // domain,
73
- // message,
74
- // }: EthereumSignTypedDataMessage<EthereumSignTypedDataTypes> = data;
75
-
76
- // let response = await commands.typedCall(
77
- // 'EthereumSignTypedData',
78
- // // 'EthereumTypedDataStructRequest|EthereumTypedDataValueRequest|EthereumTypedDataSignature',
79
- // [
80
- // 'EthereumTypedDataStructRequest',
81
- // 'EthereumTypedDataValueRequest',
82
- // 'EthereumTypedDataSignature',
83
- // ],
84
- // {
85
- // address_n: addressN,
86
- // primary_type: primaryType as string,
87
- // metamask_v4_compat: metamaskV4Compat,
88
- // }
89
- // );
90
-
91
- // while (response.type === 'EthereumTypedDataStructRequest') {
92
- // const { name: typeDefinitionName } = response.message;
93
- // const typeDefinition = types[typeDefinitionName];
94
- // if (typeDefinition === undefined) {
95
- // throw ERRORS.TypedError(
96
- // 'Runtime',
97
- // `Type ${typeDefinitionName} was not defined in types object`
98
- // );
99
- // }
100
-
101
- // const dataStruckAck: EthereumTypedDataStructAck = {
102
- // members: typeDefinition.map(({ name, type: typeName }) => ({
103
- // name,
104
- // type: getFieldType(typeName, types),
105
- // })),
106
- // };
107
-
108
- // response = await commands.typedCall(
109
- // 'EthereumTypedDataStructAck',
110
- // [
111
- // 'EthereumTypedDataStructRequest',
112
- // 'EthereumTypedDataValueRequest',
113
- // 'EthereumTypedDataSignature',
114
- // ] as MessageKey[],
115
- // dataStruckAck
116
- // );
117
- // }
118
-
119
- // while (response.type === 'EthereumTypedDataValueRequest') {
120
- // const { member_path } = response.message;
121
-
122
- // let memberData;
123
- // let memberTypeName: string;
124
-
125
- // const [rootIndex, ...nestedMemberPath] = member_path;
126
- // switch (rootIndex) {
127
- // case 0:
128
- // memberData = domain;
129
- // memberTypeName = 'EIP712Domain';
130
- // break;
131
- // case 1:
132
- // memberData = message;
133
- // memberTypeName = primaryType as string;
134
- // break;
135
- // default:
136
- // throw ERRORS.TypedError('Runtime', 'Root index can only be 0 or 1');
137
- // }
138
-
139
- // for (const index of nestedMemberPath) {
140
- // if (Array.isArray(memberData)) {
141
- // memberTypeName = parseArrayType(memberTypeName).entryTypeName;
142
- // memberData = memberData[index];
143
- // } else if (typeof memberData === 'object' && memberData !== null) {
144
- // const memberTypeDefinition = types[memberTypeName][index];
145
- // memberTypeName = memberTypeDefinition.type;
146
- // memberData = memberData[memberTypeDefinition.name];
147
- // } else {
148
- // // TODO
149
- // }
150
- // }
151
-
152
- // let encodedData;
153
- // if (Array.isArray(memberData)) {
154
- // // Sending the length as uint16
155
- // encodedData = encodeData('uint16', memberData.length);
156
- // } else {
157
- // encodedData = encodeData(memberTypeName, memberData);
158
- // }
159
-
160
- // response = await commands.typedCall(
161
- // 'EthereumTypedDataValueAck',
162
- // ['EthereumTypedDataValueRequest', 'EthereumTypedDataSignature'] as MessageKey[],
163
- // {
164
- // value: encodedData,
165
- // }
166
- // );
167
- // }
168
-
169
- // if (response.type !== 'EthereumTypedDataSignature') {
170
- // throw ERRORS.TypedError('Runtime', 'Unexpected response type');
171
- // }
172
-
173
- // const { address, signature }: EthereumTypedDataSignature = response.message;
174
- // return {
175
- // address,
176
- // signature,
177
- // };
178
- // }
62
+ async signTypedData() {
63
+ const { commands } = this.device;
64
+ const { addressN, data, metamaskV4Compat } = this.params;
65
+
66
+ const {
67
+ types,
68
+ primaryType,
69
+ domain,
70
+ message,
71
+ }: EthereumSignTypedDataMessage<EthereumSignTypedDataTypes> = data;
72
+
73
+ let response = await commands.typedCall(
74
+ 'EthereumSignTypedData',
75
+ [
76
+ 'EthereumTypedDataStructRequest',
77
+ 'EthereumTypedDataValueRequest',
78
+ 'EthereumTypedDataSignature',
79
+ ],
80
+ {
81
+ address_n: addressN,
82
+ primary_type: primaryType as string,
83
+ metamask_v4_compat: metamaskV4Compat,
84
+ }
85
+ );
86
+
87
+ while (response.type === 'EthereumTypedDataStructRequest') {
88
+ const { name: typeDefinitionName } = response.message;
89
+ const typeDefinition = types[typeDefinitionName];
90
+ if (typeDefinition === undefined) {
91
+ throw ERRORS.TypedError(
92
+ 'Runtime',
93
+ `Type ${typeDefinitionName} was not defined in types object`
94
+ );
95
+ }
96
+
97
+ const dataStruckAck: EthereumTypedDataStructAck = {
98
+ members: typeDefinition.map(({ name, type: typeName }) => ({
99
+ name,
100
+ type: getFieldType(typeName, types),
101
+ })),
102
+ };
103
+
104
+ response = await commands.typedCall(
105
+ 'EthereumTypedDataStructAck',
106
+ [
107
+ 'EthereumTypedDataStructRequest',
108
+ 'EthereumTypedDataValueRequest',
109
+ 'EthereumTypedDataSignature',
110
+ ],
111
+ dataStruckAck
112
+ );
113
+ }
114
+
115
+ while (response.type === 'EthereumTypedDataValueRequest') {
116
+ const { member_path } = response.message;
117
+
118
+ let memberData;
119
+ let memberTypeName: string;
120
+
121
+ const [rootIndex, ...nestedMemberPath] = member_path;
122
+ switch (rootIndex) {
123
+ case 0:
124
+ memberData = domain;
125
+ memberTypeName = 'EIP712Domain';
126
+ break;
127
+ case 1:
128
+ memberData = message;
129
+ memberTypeName = primaryType as string;
130
+ break;
131
+ default:
132
+ throw ERRORS.TypedError('Runtime', 'Root index can only be 0 or 1');
133
+ }
134
+
135
+ for (const index of nestedMemberPath) {
136
+ if (Array.isArray(memberData)) {
137
+ memberTypeName = parseArrayType(memberTypeName).entryTypeName;
138
+ memberData = memberData[index];
139
+ } else if (typeof memberData === 'object' && memberData !== null) {
140
+ const memberTypeDefinition = types[memberTypeName][index];
141
+ memberTypeName = memberTypeDefinition.type;
142
+ memberData = memberData[memberTypeDefinition.name];
143
+ } else {
144
+ // TODO
145
+ }
146
+ }
147
+
148
+ let encodedData;
149
+ if (Array.isArray(memberData)) {
150
+ // Sending the length as uint16
151
+ encodedData = encodeData('uint16', memberData.length);
152
+ } else {
153
+ encodedData = encodeData(memberTypeName, memberData);
154
+ }
155
+
156
+ response = await commands.typedCall(
157
+ 'EthereumTypedDataValueAck',
158
+ ['EthereumTypedDataValueRequest', 'EthereumTypedDataSignature'],
159
+ {
160
+ value: encodedData,
161
+ }
162
+ );
163
+ }
164
+
165
+ if (response.type !== 'EthereumTypedDataSignature') {
166
+ throw ERRORS.TypedError('Runtime', 'Unexpected response type');
167
+ }
168
+
169
+ const { address, signature }: EthereumTypedDataSignature = response.message;
170
+ return {
171
+ address,
172
+ signature,
173
+ };
174
+ }
179
175
 
180
176
  getVersionRange() {
181
177
  return {
@@ -246,7 +242,6 @@ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams>
246
242
  }
247
243
 
248
244
  // For Touch、Pro we use EthereumSignTypedData
249
- // return this.signTypedData();
250
- return Promise.resolve(ERRORS.TypedError('Runtime', 'Not implemented'));
245
+ return this.signTypedData();
251
246
  }
252
247
  }
@@ -1,4 +1,4 @@
1
- import { EthereumVerifyMessage } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { EthereumVerifyMessage } from '@onekeyfe/hd-transport';
2
2
  import { UI_REQUEST } from '../../constants/ui-request';
3
3
  import { BaseMethod } from '../BaseMethod';
4
4
  import { validateParams } from '../helpers/paramsValidator';
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable no-bitwise */
2
2
 
3
- import { ChangeOutputScriptType, InputScriptType } from '@onekeyfe/hd-transport/src/types/messages';
3
+ import { ChangeOutputScriptType, InputScriptType } from '@onekeyfe/hd-transport';
4
4
  import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
5
5
 
6
6
  const HD_HARDENED = 0x80000000;
@@ -1,6 +1,6 @@
1
1
  /* eslint-disable prefer-regex-literals */
2
2
 
3
- import { EthereumDataType, EthereumFieldType } from '@onekeyfe/hd-transport/src/types/messages';
3
+ import { EthereumDataType, EthereumFieldType } from '@onekeyfe/hd-transport';
4
4
 
5
5
  import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
6
6
  import { EthereumSignTypedDataTypes } from '../../types/api/evmSignTypedData';
package/src/api/index.ts CHANGED
@@ -17,6 +17,7 @@ export { default as deviceRecovery } from './device/DeviceRecovery';
17
17
  export { default as deviceReset } from './device/DeviceReset';
18
18
  export { default as deviceSettings } from './device/DeviceSettings';
19
19
  export { default as deviceUpdateReboot } from './device/DeviceUpdateReboot';
20
+ export { default as deviceVerify } from './device/DeviceVerify';
20
21
  export { default as deviceWipe } from './device/DeviceWipe';
21
22
  export { default as evmGetAddress } from './evm/EVMGetAddress';
22
23
  export { default as evmGetPublicKey } from './evm/EVMGetPublicKey';
@@ -1,4 +1,4 @@
1
- import { NEMGetAddress as HardwareNEMGetAddress } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { NEMGetAddress as HardwareNEMGetAddress } from '@onekeyfe/hd-transport';
2
2
  import { UI_REQUEST } from '../../constants/ui-request';
3
3
  import { validatePath, serializedPath } from '../helpers/pathUtils';
4
4
  import { BaseMethod } from '../BaseMethod';
@@ -8,7 +8,7 @@ import {
8
8
  NEMSignTx,
9
9
  NEMTransactionCommon,
10
10
  NEMTransfer,
11
- } from '@onekeyfe/hd-transport/src/types/messages';
11
+ } from '@onekeyfe/hd-transport';
12
12
 
13
13
  import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
14
14
  import { UI_REQUEST } from '../../constants/ui-request';
@@ -1,4 +1,4 @@
1
- import { SolanaGetAddress } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { SolanaGetAddress } from '@onekeyfe/hd-transport';
2
2
  import { UI_REQUEST } from '../../constants/ui-request';
3
3
  import { serializedPath, validatePath } from '../helpers/pathUtils';
4
4
  import { BaseMethod } from '../BaseMethod';
@@ -42,10 +42,12 @@ export default class SolGetAddress extends BaseMethod<SolanaGetAddress[]> {
42
42
  for (let i = 0; i < this.params.length; i++) {
43
43
  const param = this.params[i];
44
44
 
45
+ // @ts-expect-error
45
46
  const res = await this.device.commands.typedCall('SolanaGetAddress', 'SolanaAddress', {
46
47
  ...param,
47
48
  });
48
49
 
50
+ // @ts-expect-error
49
51
  const { address } = res.message;
50
52
 
51
53
  responses.push({
@@ -1,4 +1,4 @@
1
- import { SolanaSignTx as HardwareSolanaSignTx } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { SolanaSignTx as HardwareSolanaSignTx } from '@onekeyfe/hd-transport';
2
2
  import { UI_REQUEST } from '../../constants/ui-request';
3
3
  import { serializedPath, validatePath } from '../helpers/pathUtils';
4
4
  import { BaseMethod } from '../BaseMethod';
@@ -52,10 +52,12 @@ export default class SolSignTransaction extends BaseMethod<HardwareSolanaSignTx[
52
52
  for (let i = 0; i < this.params.length; i++) {
53
53
  const param = this.params[i];
54
54
 
55
+ // @ts-expect-error
55
56
  const res = await this.device.commands.typedCall('SolanaSignTx', 'SolanaSignedTx', {
56
57
  ...param,
57
58
  });
58
59
 
60
+ // @ts-expect-error
59
61
  const { signature } = res.message;
60
62
 
61
63
  responses.push({
@@ -1,4 +1,4 @@
1
- import { StarcoinGetAddress as HardwareStarcoinGetAddress } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { StarcoinGetAddress as HardwareStarcoinGetAddress } from '@onekeyfe/hd-transport';
2
2
  import { UI_REQUEST } from '../../constants/ui-request';
3
3
  import { validatePath, serializedPath } from '../helpers/pathUtils';
4
4
  import { BaseMethod } from '../BaseMethod';
@@ -1,4 +1,4 @@
1
- import { StarcoinGetPublicKey as HardwareStarcoinGetPublicKey } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { StarcoinGetPublicKey as HardwareStarcoinGetPublicKey } from '@onekeyfe/hd-transport';
2
2
  import { UI_REQUEST } from '../../constants/ui-request';
3
3
  import { validatePath, serializedPath } from '../helpers/pathUtils';
4
4
  import { BaseMethod } from '../BaseMethod';
@@ -1,4 +1,4 @@
1
- import { StarcoinSignMessage as HardwareStarcoinSignMessage } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { StarcoinSignMessage as HardwareStarcoinSignMessage } from '@onekeyfe/hd-transport';
2
2
  import { UI_REQUEST } from '../../constants/ui-request';
3
3
  import { validatePath } from '../helpers/pathUtils';
4
4
  import { BaseMethod } from '../BaseMethod';
@@ -1,4 +1,4 @@
1
- import { StarcoinSignTx } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { StarcoinSignTx } from '@onekeyfe/hd-transport';
2
2
  import { UI_REQUEST } from '../../constants/ui-request';
3
3
  import { validatePath } from '../helpers/pathUtils';
4
4
  import { BaseMethod } from '../BaseMethod';
@@ -1,4 +1,4 @@
1
- import { StarcoinVerifyMessage as HardwareStarcoinVerifyMessage } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { StarcoinVerifyMessage as HardwareStarcoinVerifyMessage } from '@onekeyfe/hd-transport';
2
2
  import { UI_REQUEST } from '../../constants/ui-request';
3
3
  import { BaseMethod } from '../BaseMethod';
4
4
  import { validateParams } from '../helpers/paramsValidator';
@@ -1,4 +1,4 @@
1
- import { StellarGetAddress as HardwareStellarGetAddress } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { StellarGetAddress as HardwareStellarGetAddress } from '@onekeyfe/hd-transport';
2
2
  import { UI_REQUEST } from '../../constants/ui-request';
3
3
  import { serializedPath, validatePath } from '../helpers/pathUtils';
4
4
  import { BaseMethod } from '../BaseMethod';
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  StellarSignedTx,
3
3
  StellarSignTx as HardwareStellarSignTx,
4
- } from '@onekeyfe/hd-transport/src/types/messages';
4
+ } from '@onekeyfe/hd-transport';
5
5
  import { UI_REQUEST } from '../../constants/ui-request';
6
6
  import { validatePath } from '../helpers/pathUtils';
7
7
  import { BaseMethod } from '../BaseMethod';
package/src/core/index.ts CHANGED
@@ -140,6 +140,11 @@ export const callAPI = async (message: CoreMessage) => {
140
140
  method.requireDeviceMode
141
141
  );
142
142
  if (unexpectedMode) {
143
+ if (unexpectedMode === UI_REQUEST.NOT_IN_BOOTLOADER) {
144
+ return Promise.reject(
145
+ ERRORS.TypedError(HardwareErrorCode.DeviceUnexpectedBootloaderMode)
146
+ );
147
+ }
143
148
  return Promise.reject(
144
149
  ERRORS.TypedError(HardwareErrorCode.DeviceUnexpectedMode, unexpectedMode)
145
150
  );
@@ -12,6 +12,7 @@ import {
12
12
  getDeviceType,
13
13
  getDeviceUUID,
14
14
  getDeviceBLEFirmwareVersion,
15
+ getDeviceTypeOnBootloader,
15
16
  } from '../utils/deviceFeaturesUtils';
16
17
  import type { Features, Device as DeviceTyped, UnavailableCapabilities } from '../types';
17
18
  import { DEVICE, DeviceButtonRequestPayload } from '../events';
@@ -114,7 +115,9 @@ export class Device extends EventEmitter {
114
115
  connectId: env === 'react-native' ? this.mainId || null : getDeviceUUID(this.features),
115
116
  /** Hardware ID, will not change at any time */
116
117
  uuid: getDeviceUUID(this.features),
117
- deviceType: getDeviceType(this.features),
118
+ deviceType: this.features.bootloader_mode
119
+ ? getDeviceTypeOnBootloader(this.features)
120
+ : getDeviceType(this.features),
118
121
  /** ID for current seeds, will clear after replace a new seed at device */
119
122
  deviceId: this.features.device_id || null,
120
123
  path: this.originalDescriptor.path,
@@ -16,6 +16,8 @@ export const UI_REQUEST = {
16
16
  LOCATION_PERMISSION: 'ui-location_permission',
17
17
 
18
18
  FIRMWARE_PROGRESS: 'ui-firmware-progress',
19
+
20
+ NOT_IN_BOOTLOADER: 'ui-device_not_in_bootloader_mode',
19
21
  } as const;
20
22
 
21
23
  export interface UiRequestWithoutPayload {
package/src/inject.ts CHANGED
@@ -77,6 +77,7 @@ export const inject = ({
77
77
  deviceReset: (connectId, params) => call({ ...params, connectId, method: 'deviceReset' }),
78
78
  deviceSettings: (connectId, params) => call({ ...params, connectId, method: 'deviceSettings' }),
79
79
  deviceUpdateReboot: connectId => call({ connectId, method: 'deviceUpdateReboot' }),
80
+ deviceVerify: (connectId, params) => call({ ...params, connectId, method: 'deviceVerify' }),
80
81
  deviceWipe: connectId => call({ connectId, method: 'deviceWipe' }),
81
82
 
82
83
  evmGetAddress: (connectId, params) => call({ ...params, connectId, method: 'evmGetAddress' }),
@@ -2,7 +2,7 @@ import {
2
2
  Address,
3
3
  InputScriptType,
4
4
  MultisigRedeemScriptType,
5
- } from '@onekeyfe/hd-transport/src/types/messages';
5
+ } from '@onekeyfe/hd-transport';
6
6
  import type { CommonParams, Response } from '../params';
7
7
 
8
8
  export type BTCAddress = {
@@ -1,4 +1,4 @@
1
- import { InputScriptType, PublicKey } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { InputScriptType, PublicKey } from '@onekeyfe/hd-transport';
2
2
  import type { CommonParams, Response } from '../params';
3
3
 
4
4
  export type BTCPublicKey = {
@@ -1,4 +1,4 @@
1
- import { MessageSignature } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { MessageSignature } from '@onekeyfe/hd-transport';
2
2
  import type { CommonParams, Response } from '../params';
3
3
 
4
4
  export type BTCSignMessageParams = {
@@ -4,7 +4,7 @@ import {
4
4
  TxOutputBinType,
5
5
  TxOutputType,
6
6
  TxInputType,
7
- } from '@onekeyfe/hd-transport/src/types/messages';
7
+ } from '@onekeyfe/hd-transport';
8
8
  import type { CommonParams, Response } from '../params';
9
9
 
10
10
  export type SignedTransaction = {
@@ -1,4 +1,4 @@
1
- import { Success } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { Success } from '@onekeyfe/hd-transport';
2
2
  import type { CommonParams, Response } from '../params';
3
3
 
4
4
  export type BTCVerifyMessageParams = {
@@ -1,4 +1,4 @@
1
- import { CipheredKeyValue as HardwareCipheredKeyValue } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { CipheredKeyValue as HardwareCipheredKeyValue } from '@onekeyfe/hd-transport';
2
2
  import type { CommonParams, Response } from '../params';
3
3
 
4
4
  export type CipheredKeyValue = {
@@ -1,4 +1,4 @@
1
- import { Success } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { Success } from '@onekeyfe/hd-transport';
2
2
  import type { Response } from '../params';
3
3
 
4
4
  export declare function deviceBackup(connectId: string): Response<Success>;
@@ -1,4 +1,4 @@
1
- import { Success } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { Success } from '@onekeyfe/hd-transport';
2
2
  import type { CommonParams, Response } from '../params';
3
3
 
4
4
  export type DeviceChangePinParams = {
@@ -1,4 +1,4 @@
1
- import { Success } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { Success } from '@onekeyfe/hd-transport';
2
2
  import type { CommonParams, Response } from '../params';
3
3
 
4
4
  export type DeviceFlagsParams = {
@@ -1,4 +1,4 @@
1
- import { Success } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { Success } from '@onekeyfe/hd-transport';
2
2
  import type { Response } from '../params';
3
3
 
4
4
  export declare function deviceRebootToBootloader(connectId: string): Response<Success>;
@@ -1,4 +1,4 @@
1
- import { RecoveryDeviceType, Success } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { RecoveryDeviceType, Success } from '@onekeyfe/hd-transport';
2
2
  import type { CommonParams, Response } from '../params';
3
3
 
4
4
  export type DeviceRecoveryParams = {
@@ -1,4 +1,4 @@
1
- import { Success } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { Success } from '@onekeyfe/hd-transport';
2
2
  import type { CommonParams, Response } from '../params';
3
3
 
4
4
  export type DeviceResetParams = {
@@ -1,4 +1,4 @@
1
- import { SafetyCheckLevel, Success } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { SafetyCheckLevel, Success } from '@onekeyfe/hd-transport';
2
2
  import type { CommonParams, Response } from '../params';
3
3
 
4
4
  export type DeviceSettingsParams = {
@@ -1,4 +1,4 @@
1
- import { Success } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { Success } from '@onekeyfe/hd-transport';
2
2
  import type { Response } from '../params';
3
3
 
4
4
  export declare function deviceUpdateReboot(connectId: string): Response<Success>;
@@ -0,0 +1,15 @@
1
+ import type { CommonParams, Response } from '../params';
2
+
3
+ export type DeviceVerifyParams = {
4
+ dataHex: string;
5
+ };
6
+
7
+ export type DeviceVerifySignature = {
8
+ cert: Buffer;
9
+ signature: Buffer;
10
+ };
11
+
12
+ export declare function deviceVerify(
13
+ connectId: string,
14
+ params: CommonParams & DeviceVerifyParams
15
+ ): Response<DeviceVerifySignature>;
@@ -1,4 +1,4 @@
1
- import { Success } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { Success } from '@onekeyfe/hd-transport';
2
2
  import type { Response } from '../params';
3
3
 
4
4
  export declare function deviceWipe(connectId: string): Response<Success>;
@@ -1,4 +1,4 @@
1
- import { EthereumPublicKey } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { EthereumPublicKey } from '@onekeyfe/hd-transport';
2
2
  import type { CommonParams, Response } from '../params';
3
3
 
4
4
  export type EVMPublicKey = {
@@ -1,4 +1,4 @@
1
- import { EthereumMessageSignature } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { EthereumMessageSignature } from '@onekeyfe/hd-transport';
2
2
  import type { CommonParams, Response } from '../params';
3
3
 
4
4
  export type EVMSignMessageParams = {
@@ -1,4 +1,4 @@
1
- import { EthereumMessageSignature } from '@onekeyfe/hd-transport/src/types/messages';
1
+ import { EthereumMessageSignature } from '@onekeyfe/hd-transport';
2
2
  import type { CommonParams, Response } from '../params';
3
3
 
4
4
  export type EVMSignMessageEIP712Params = {