@onekeyfe/hd-core 0.0.1 → 0.0.4

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 (195) hide show
  1. package/dist/api/GetFeatures.d.ts +1 -0
  2. package/dist/api/GetFeatures.d.ts.map +1 -1
  3. package/dist/api/SearchDevices.d.ts +1 -0
  4. package/dist/api/SearchDevices.d.ts.map +1 -1
  5. package/dist/api/btc/BTCGetAddress.d.ts +9 -0
  6. package/dist/api/btc/BTCGetAddress.d.ts.map +1 -0
  7. package/dist/api/btc/BTCGetPublicKey.d.ts +9 -0
  8. package/dist/api/btc/BTCGetPublicKey.d.ts.map +1 -0
  9. package/dist/api/{BTCSignMessage.d.ts → btc/BTCSignMessage.d.ts} +1 -1
  10. package/dist/api/btc/BTCSignMessage.d.ts.map +1 -0
  11. package/dist/api/{BTCSignTransaction.d.ts → btc/BTCSignTransaction.d.ts} +3 -3
  12. package/dist/api/btc/BTCSignTransaction.d.ts.map +1 -0
  13. package/dist/api/{BTCVerifyMessage.d.ts → btc/BTCVerifyMessage.d.ts} +1 -1
  14. package/dist/api/btc/BTCVerifyMessage.d.ts.map +1 -0
  15. package/dist/api/{helpers → btc/helpers}/btcParamsUtils.d.ts +0 -0
  16. package/dist/api/btc/helpers/btcParamsUtils.d.ts.map +1 -0
  17. package/dist/api/{helpers/btc → btc/helpers}/signtx.d.ts +0 -0
  18. package/dist/api/{helpers/btc → btc/helpers}/signtx.d.ts.map +1 -1
  19. package/dist/api/{helpers/btc → btc/helpers}/signtxLegacy.d.ts +0 -0
  20. package/dist/api/{helpers/btc → btc/helpers}/signtxLegacy.d.ts.map +1 -1
  21. package/dist/api/{DeviceBackup.d.ts → device/DeviceBackup.d.ts} +1 -1
  22. package/dist/api/device/DeviceBackup.d.ts.map +1 -0
  23. package/dist/api/{DeviceChangePin.d.ts → device/DeviceChangePin.d.ts} +1 -1
  24. package/dist/api/device/DeviceChangePin.d.ts.map +1 -0
  25. package/dist/api/{DeviceFlags.d.ts → device/DeviceFlags.d.ts} +1 -1
  26. package/dist/api/device/DeviceFlags.d.ts.map +1 -0
  27. package/dist/api/{DeviceRebootToBootloader.d.ts → device/DeviceRebootToBootloader.d.ts} +1 -1
  28. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -0
  29. package/dist/api/{DeviceRecovery.d.ts → device/DeviceRecovery.d.ts} +1 -1
  30. package/dist/api/device/DeviceRecovery.d.ts.map +1 -0
  31. package/dist/api/{DeviceReset.d.ts → device/DeviceReset.d.ts} +1 -1
  32. package/dist/api/device/DeviceReset.d.ts.map +1 -0
  33. package/dist/api/{DeviceSettings.d.ts → device/DeviceSettings.d.ts} +1 -1
  34. package/dist/api/device/DeviceSettings.d.ts.map +1 -0
  35. package/dist/api/{DeviceUpdateReboot.d.ts → device/DeviceUpdateReboot.d.ts} +1 -1
  36. package/dist/api/device/DeviceUpdateReboot.d.ts.map +1 -0
  37. package/dist/api/{DeviceWipe.d.ts → device/DeviceWipe.d.ts} +1 -1
  38. package/dist/api/device/DeviceWipe.d.ts.map +1 -0
  39. package/dist/api/evm/EVMGetAddress.d.ts +9 -0
  40. package/dist/api/evm/EVMGetAddress.d.ts.map +1 -0
  41. package/dist/api/evm/EVMGetPublicKey.d.ts +9 -0
  42. package/dist/api/evm/EVMGetPublicKey.d.ts.map +1 -0
  43. package/dist/api/{EVMSignMessage.d.ts → evm/EVMSignMessage.d.ts} +1 -1
  44. package/dist/api/evm/EVMSignMessage.d.ts.map +1 -0
  45. package/dist/api/{EVMSignMessageEIP712.d.ts → evm/EVMSignMessageEIP712.d.ts} +1 -1
  46. package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -0
  47. package/dist/api/{EVMSignTransaction.d.ts → evm/EVMSignTransaction.d.ts} +2 -8
  48. package/dist/api/evm/EVMSignTransaction.d.ts.map +1 -0
  49. package/dist/api/{EVMSignTypedData.d.ts → evm/EVMSignTypedData.d.ts} +3 -3
  50. package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -0
  51. package/dist/api/{EVMVerifyMessage.d.ts → evm/EVMVerifyMessage.d.ts} +1 -1
  52. package/dist/api/evm/EVMVerifyMessage.d.ts.map +1 -0
  53. package/dist/api/helpers/pathUtils.d.ts +1 -0
  54. package/dist/api/helpers/pathUtils.d.ts.map +1 -1
  55. package/dist/api/index.d.ts +26 -21
  56. package/dist/api/index.d.ts.map +1 -1
  57. package/dist/api/starcoin/StarcoinGetAddress.d.ts +9 -0
  58. package/dist/api/starcoin/StarcoinGetAddress.d.ts.map +1 -0
  59. package/dist/api/starcoin/StarcoinGetPublicKey.d.ts +9 -0
  60. package/dist/api/starcoin/StarcoinGetPublicKey.d.ts.map +1 -0
  61. package/dist/api/starcoin/StarcoinSignMessage.d.ts +10 -0
  62. package/dist/api/starcoin/StarcoinSignMessage.d.ts.map +1 -0
  63. package/dist/api/starcoin/StarcoinSignTransaction.d.ts +10 -0
  64. package/dist/api/starcoin/StarcoinSignTransaction.d.ts.map +1 -0
  65. package/dist/api/starcoin/StarcoinVerifyMessage.d.ts +9 -0
  66. package/dist/api/starcoin/StarcoinVerifyMessage.d.ts.map +1 -0
  67. package/dist/core/index.d.ts.map +1 -1
  68. package/dist/device/Device.d.ts.map +1 -1
  69. package/dist/events/core.d.ts +2 -1
  70. package/dist/events/core.d.ts.map +1 -1
  71. package/dist/events/device.d.ts +15 -0
  72. package/dist/events/device.d.ts.map +1 -1
  73. package/dist/events/ui-request.d.ts +13 -1
  74. package/dist/events/ui-request.d.ts.map +1 -1
  75. package/dist/index.d.ts +204 -42
  76. package/dist/index.js +253 -48
  77. package/dist/inject.d.ts.map +1 -1
  78. package/dist/types/api/btcGetAddress.d.ts +5 -2
  79. package/dist/types/api/btcGetAddress.d.ts.map +1 -1
  80. package/dist/types/api/btcGetPublicKey.d.ts +5 -2
  81. package/dist/types/api/btcGetPublicKey.d.ts.map +1 -1
  82. package/dist/types/api/deviceSettings.d.ts +2 -2
  83. package/dist/types/api/deviceSettings.d.ts.map +1 -1
  84. package/dist/types/api/evmGetAddress.d.ts +6 -3
  85. package/dist/types/api/evmGetAddress.d.ts.map +1 -1
  86. package/dist/types/api/evmGetPublicKey.d.ts +5 -2
  87. package/dist/types/api/evmGetPublicKey.d.ts.map +1 -1
  88. package/dist/types/api/evmSignTransaction.d.ts +8 -4
  89. package/dist/types/api/evmSignTransaction.d.ts.map +1 -1
  90. package/dist/types/api/export.d.ts +22 -0
  91. package/dist/types/api/export.d.ts.map +1 -0
  92. package/dist/types/api/index.d.ts +11 -0
  93. package/dist/types/api/index.d.ts.map +1 -1
  94. package/dist/types/api/init.d.ts +1 -1
  95. package/dist/types/api/init.d.ts.map +1 -1
  96. package/dist/types/api/searchDevices.d.ts +2 -2
  97. package/dist/types/api/searchDevices.d.ts.map +1 -1
  98. package/dist/types/api/starcoinGetAddress.d.ts +14 -0
  99. package/dist/types/api/starcoinGetAddress.d.ts.map +1 -0
  100. package/dist/types/api/starcoinGetPublicKey.d.ts +14 -0
  101. package/dist/types/api/starcoinGetPublicKey.d.ts.map +1 -0
  102. package/dist/types/api/starcoinSignMessage.d.ts +8 -0
  103. package/dist/types/api/starcoinSignMessage.d.ts.map +1 -0
  104. package/dist/types/api/starcoinSignTransaction.d.ts +8 -0
  105. package/dist/types/api/starcoinSignTransaction.d.ts.map +1 -0
  106. package/dist/types/api/starcoinVerifyMessage.d.ts +9 -0
  107. package/dist/types/api/starcoinVerifyMessage.d.ts.map +1 -0
  108. package/dist/types/device.d.ts +8 -0
  109. package/dist/types/device.d.ts.map +1 -1
  110. package/dist/utils/deviceFeaturesUtils.d.ts +1 -0
  111. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  112. package/dist/utils/index.d.ts +1 -0
  113. package/dist/utils/index.d.ts.map +1 -1
  114. package/package.json +3 -3
  115. package/src/api/SearchDevices.ts +6 -1
  116. package/src/api/{BTCGetAddress.ts → btc/BTCGetAddress.ts} +11 -8
  117. package/src/api/{BTCGetPublicKey.ts → btc/BTCGetPublicKey.ts} +12 -8
  118. package/src/api/{BTCSignMessage.ts → btc/BTCSignMessage.ts} +5 -5
  119. package/src/api/{BTCSignTransaction.ts → btc/BTCSignTransaction.ts} +8 -8
  120. package/src/api/{BTCVerifyMessage.ts → btc/BTCVerifyMessage.ts} +4 -4
  121. package/src/api/{helpers → btc/helpers}/btcParamsUtils.ts +3 -3
  122. package/src/api/{helpers/btc → btc/helpers}/signtx.ts +0 -0
  123. package/src/api/{helpers/btc → btc/helpers}/signtxLegacy.ts +0 -0
  124. package/src/api/{DeviceBackup.ts → device/DeviceBackup.ts} +1 -1
  125. package/src/api/{DeviceChangePin.ts → device/DeviceChangePin.ts} +2 -2
  126. package/src/api/{DeviceFlags.ts → device/DeviceFlags.ts} +2 -2
  127. package/src/api/{DeviceRebootToBootloader.ts → device/DeviceRebootToBootloader.ts} +1 -1
  128. package/src/api/{DeviceRecovery.ts → device/DeviceRecovery.ts} +2 -2
  129. package/src/api/{DeviceReset.ts → device/DeviceReset.ts} +2 -2
  130. package/src/api/{DeviceSettings.ts → device/DeviceSettings.ts} +2 -2
  131. package/src/api/{DeviceUpdateReboot.ts → device/DeviceUpdateReboot.ts} +1 -1
  132. package/src/api/{DeviceWipe.ts → device/DeviceWipe.ts} +1 -1
  133. package/src/api/{EVMGetAddress.ts → evm/EVMGetAddress.ts} +13 -8
  134. package/src/api/{EVMGetPublicKey.ts → evm/EVMGetPublicKey.ts} +11 -8
  135. package/src/api/{EVMSignMessage.ts → evm/EVMSignMessage.ts} +5 -5
  136. package/src/api/{EVMSignMessageEIP712.ts → evm/EVMSignMessageEIP712.ts} +5 -5
  137. package/src/api/{EVMSignTransaction.ts → evm/EVMSignTransaction.ts} +10 -15
  138. package/src/api/{EVMSignTypedData.ts → evm/EVMSignTypedData.ts} +8 -8
  139. package/src/api/{EVMVerifyMessage.ts → evm/EVMVerifyMessage.ts} +4 -4
  140. package/src/api/helpers/pathUtils.ts +13 -0
  141. package/src/api/index.ts +26 -21
  142. package/src/api/starcoin/StarcoinGetAddress.ts +57 -0
  143. package/src/api/starcoin/StarcoinGetPublicKey.ts +64 -0
  144. package/src/api/starcoin/StarcoinSignMessage.ts +40 -0
  145. package/src/api/starcoin/StarcoinSignTransaction.ts +36 -0
  146. package/src/api/starcoin/StarcoinVerifyMessage.ts +33 -0
  147. package/src/core/index.ts +25 -0
  148. package/src/device/Device.ts +4 -0
  149. package/src/events/core.ts +8 -1
  150. package/src/events/device.ts +27 -0
  151. package/src/events/ui-request.ts +16 -1
  152. package/src/inject.ts +12 -1
  153. package/src/types/api/btcGetAddress.ts +6 -2
  154. package/src/types/api/btcGetPublicKey.ts +6 -2
  155. package/src/types/api/deviceSettings.ts +5 -2
  156. package/src/types/api/evmGetAddress.ts +7 -3
  157. package/src/types/api/evmGetPublicKey.ts +6 -2
  158. package/src/types/api/evmSignTransaction.ts +9 -4
  159. package/src/types/api/export.ts +35 -0
  160. package/src/types/api/index.ts +13 -0
  161. package/src/types/api/init.ts +1 -1
  162. package/src/types/api/searchDevices.ts +3 -2
  163. package/src/types/api/starcoinGetAddress.ts +21 -0
  164. package/src/types/api/starcoinGetPublicKey.ts +21 -0
  165. package/src/types/api/starcoinSignMessage.ts +12 -0
  166. package/src/types/api/starcoinSignTransaction.ts +12 -0
  167. package/src/types/api/starcoinVerifyMessage.ts +13 -0
  168. package/src/types/device.ts +9 -0
  169. package/src/utils/index.ts +1 -0
  170. package/dist/api/BTCGetAddress.d.ts +0 -8
  171. package/dist/api/BTCGetAddress.d.ts.map +0 -1
  172. package/dist/api/BTCGetPublicKey.d.ts +0 -8
  173. package/dist/api/BTCGetPublicKey.d.ts.map +0 -1
  174. package/dist/api/BTCSignMessage.d.ts.map +0 -1
  175. package/dist/api/BTCSignTransaction.d.ts.map +0 -1
  176. package/dist/api/BTCVerifyMessage.d.ts.map +0 -1
  177. package/dist/api/DeviceBackup.d.ts.map +0 -1
  178. package/dist/api/DeviceChangePin.d.ts.map +0 -1
  179. package/dist/api/DeviceFlags.d.ts.map +0 -1
  180. package/dist/api/DeviceRebootToBootloader.d.ts.map +0 -1
  181. package/dist/api/DeviceRecovery.d.ts.map +0 -1
  182. package/dist/api/DeviceReset.d.ts.map +0 -1
  183. package/dist/api/DeviceSettings.d.ts.map +0 -1
  184. package/dist/api/DeviceUpdateReboot.d.ts.map +0 -1
  185. package/dist/api/DeviceWipe.d.ts.map +0 -1
  186. package/dist/api/EVMGetAddress.d.ts +0 -8
  187. package/dist/api/EVMGetAddress.d.ts.map +0 -1
  188. package/dist/api/EVMGetPublicKey.d.ts +0 -8
  189. package/dist/api/EVMGetPublicKey.d.ts.map +0 -1
  190. package/dist/api/EVMSignMessage.d.ts.map +0 -1
  191. package/dist/api/EVMSignMessageEIP712.d.ts.map +0 -1
  192. package/dist/api/EVMSignTransaction.d.ts.map +0 -1
  193. package/dist/api/EVMSignTypedData.d.ts.map +0 -1
  194. package/dist/api/EVMVerifyMessage.d.ts.map +0 -1
  195. package/dist/api/helpers/btcParamsUtils.d.ts.map +0 -1
@@ -1,9 +1,9 @@
1
1
  import { EthereumSignMessageEIP712 } from '@onekeyfe/hd-transport/src/types/messages';
2
- import { UI_REQUEST } from '../constants/ui-request';
3
- import { validatePath } from './helpers/pathUtils';
4
- import { BaseMethod } from './BaseMethod';
5
- import { validateParams } from './helpers/paramsValidator';
6
- import { formatAnyHex } from './helpers/hexUtils';
2
+ import { UI_REQUEST } from '../../constants/ui-request';
3
+ import { validatePath } from '../helpers/pathUtils';
4
+ import { BaseMethod } from '../BaseMethod';
5
+ import { validateParams } from '../helpers/paramsValidator';
6
+ import { formatAnyHex } from '../helpers/hexUtils';
7
7
 
8
8
  export default class EVMSignMessageEIP712 extends BaseMethod<EthereumSignMessageEIP712> {
9
9
  init() {
@@ -4,24 +4,19 @@ import {
4
4
  EthereumTxRequest,
5
5
  } from '@onekeyfe/hd-transport/src/types/messages';
6
6
 
7
- import { UI_REQUEST } from '../constants/ui-request';
8
- import { validatePath } from './helpers/pathUtils';
9
- import { BaseMethod } from './BaseMethod';
10
- import { SchemaParam, validateParams } from './helpers/paramsValidator';
7
+ import { UI_REQUEST } from '../../constants/ui-request';
8
+ import { validatePath } from '../helpers/pathUtils';
9
+ import { BaseMethod } from '../BaseMethod';
10
+ import { SchemaParam, validateParams } from '../helpers/paramsValidator';
11
11
  import {
12
+ EVMSignedTx,
12
13
  EVMSignTransactionParams,
13
14
  EVMTransaction,
14
15
  EVMTransactionEIP1559,
15
- } from '../types/api/evmSignTransaction';
16
- import { cutString } from './helpers/stringUtils';
17
- import { formatAnyHex, stripHexStartZeroes } from './helpers/hexUtils';
18
- import { ERRORS } from '../constants';
19
-
20
- type EVMSignedTx = {
21
- v: string;
22
- r: string;
23
- s: string;
24
- };
16
+ } from '../../types/api/evmSignTransaction';
17
+ import { cutString } from '../helpers/stringUtils';
18
+ import { formatAnyHex, stripHexStartZeroes } from '../helpers/hexUtils';
19
+ import { ERRORS } from '../../constants';
25
20
 
26
21
  export default class EVMSignTransaction extends BaseMethod {
27
22
  addressN: number[] = [];
@@ -75,7 +70,7 @@ export default class EVMSignTransaction extends BaseMethod {
75
70
  const r = request.signature_r;
76
71
  const s = request.signature_s;
77
72
 
78
- if (!v || !r || !s) {
73
+ if (v == null || r == null || s == null) {
79
74
  throw ERRORS.TypedError('Runtime', 'processTxRequest: Unexpected request');
80
75
  }
81
76
 
@@ -3,17 +3,17 @@ import {
3
3
  EthereumTypedDataStructAck,
4
4
  MessageKey,
5
5
  } from '@onekeyfe/hd-transport/src/types/messages';
6
- import { UI_REQUEST } from '../constants/ui-request';
7
- import { validatePath } from './helpers/pathUtils';
8
- import { BaseMethod } from './BaseMethod';
9
- import { validateParams } from './helpers/paramsValidator';
10
- import { formatAnyHex } from './helpers/hexUtils';
11
- import { ERRORS } from '../constants';
12
- import { encodeData, getFieldType, parseArrayType } from './helpers/typeNameUtils';
6
+ import { UI_REQUEST } from '../../constants/ui-request';
7
+ import { validatePath } from '../helpers/pathUtils';
8
+ import { BaseMethod } from '../BaseMethod';
9
+ import { validateParams } from '../helpers/paramsValidator';
10
+ import { formatAnyHex } from '../helpers/hexUtils';
11
+ import { ERRORS } from '../../constants';
12
+ import { encodeData, getFieldType, parseArrayType } from '../helpers/typeNameUtils';
13
13
  import {
14
14
  EthereumSignTypedDataMessage,
15
15
  EthereumSignTypedDataTypes,
16
- } from '../types/api/evmSignTypedData';
16
+ } from '../../types/api/evmSignTypedData';
17
17
 
18
18
  export type EVMSignTypedDataParams = {
19
19
  addressN: number[];
@@ -1,8 +1,8 @@
1
1
  import { EthereumVerifyMessage } from '@onekeyfe/hd-transport/src/types/messages';
2
- import { UI_REQUEST } from '../constants/ui-request';
3
- import { BaseMethod } from './BaseMethod';
4
- import { validateParams } from './helpers/paramsValidator';
5
- import { formatAnyHex } from './helpers/hexUtils';
2
+ import { UI_REQUEST } from '../../constants/ui-request';
3
+ import { BaseMethod } from '../BaseMethod';
4
+ import { validateParams } from '../helpers/paramsValidator';
5
+ import { formatAnyHex } from '../helpers/hexUtils';
6
6
 
7
7
  export default class EVMSignMessage extends BaseMethod<EthereumVerifyMessage> {
8
8
  init() {
@@ -84,6 +84,19 @@ export const getOutputScriptType = (path?: number[]): ChangeOutputScriptType =>
84
84
  }
85
85
  };
86
86
 
87
+ export const serializedPath = (path: Array<number>): string => {
88
+ const pathStr = path
89
+ .map((p: number) => {
90
+ if (p & HD_HARDENED) {
91
+ return `${p & ~HD_HARDENED}'`;
92
+ }
93
+ return p;
94
+ })
95
+ .join('/');
96
+
97
+ return `m/${pathStr}`;
98
+ };
99
+
87
100
  export const validatePath = (
88
101
  path: string | Array<number>,
89
102
  length = 0,
package/src/api/index.ts CHANGED
@@ -1,26 +1,31 @@
1
1
  export { default as searchDevices } from './SearchDevices';
2
2
  export { default as getFeatures } from './GetFeatures';
3
- export { default as btcGetAddress } from './BTCGetAddress';
4
- export { default as btcGetPublicKey } from './BTCGetPublicKey';
5
- export { default as btcSignMessage } from './BTCSignMessage';
6
- export { default as btcSignTransaction } from './BTCSignTransaction';
7
- export { default as btcVerifyMessage } from './BTCVerifyMessage';
3
+ export { default as btcGetAddress } from './btc/BTCGetAddress';
4
+ export { default as btcGetPublicKey } from './btc/BTCGetPublicKey';
5
+ export { default as btcSignMessage } from './btc/BTCSignMessage';
6
+ export { default as btcSignTransaction } from './btc/BTCSignTransaction';
7
+ export { default as btcVerifyMessage } from './btc/BTCVerifyMessage';
8
8
  export { default as checkFirmwareRelease } from './CheckFirmwareRelease';
9
9
  export { default as checkBLEFirmwareRelease } from './CheckBLEFirmwareRelease';
10
10
  export { default as checkTransportRelease } from './CheckTransportRelease';
11
- export { default as deviceBackup } from './DeviceBackup';
12
- export { default as deviceChangePin } from './DeviceChangePin';
13
- export { default as deviceFlags } from './DeviceFlags';
14
- export { default as deviceRebootToBootloader } from './DeviceRebootToBootloader';
15
- export { default as deviceRecovery } from './DeviceRecovery';
16
- export { default as deviceReset } from './DeviceReset';
17
- export { default as deviceSettings } from './DeviceSettings';
18
- export { default as deviceUpdateReboot } from './DeviceUpdateReboot';
19
- export { default as deviceWipe } from './DeviceWipe';
20
- export { default as evmGetAddress } from './EVMGetAddress';
21
- export { default as evmGetPublicKey } from './EVMGetPublicKey';
22
- export { default as evmSignMessage } from './EVMSignMessage';
23
- export { default as evmSignMessageEIP712 } from './EVMSignMessageEIP712';
24
- export { default as evmSignTransaction } from './EVMSignTransaction';
25
- export { default as evmSignTypedData } from './EVMSignTypedData';
26
- export { default as evmVerifyMessage } from './EVMVerifyMessage';
11
+ export { default as deviceBackup } from './device/DeviceBackup';
12
+ export { default as deviceChangePin } from './device/DeviceChangePin';
13
+ export { default as deviceFlags } from './device/DeviceFlags';
14
+ export { default as deviceRebootToBootloader } from './device/DeviceRebootToBootloader';
15
+ export { default as deviceRecovery } from './device/DeviceRecovery';
16
+ export { default as deviceReset } from './device/DeviceReset';
17
+ export { default as deviceSettings } from './device/DeviceSettings';
18
+ export { default as deviceUpdateReboot } from './device/DeviceUpdateReboot';
19
+ export { default as deviceWipe } from './device/DeviceWipe';
20
+ export { default as evmGetAddress } from './evm/EVMGetAddress';
21
+ export { default as evmGetPublicKey } from './evm/EVMGetPublicKey';
22
+ export { default as evmSignMessage } from './evm/EVMSignMessage';
23
+ export { default as evmSignMessageEIP712 } from './evm/EVMSignMessageEIP712';
24
+ export { default as evmSignTransaction } from './evm/EVMSignTransaction';
25
+ export { default as evmSignTypedData } from './evm/EVMSignTypedData';
26
+ export { default as evmVerifyMessage } from './evm/EVMVerifyMessage';
27
+ export { default as starcoinGetAddress } from './starcoin/StarcoinGetAddress';
28
+ export { default as starcoinGetPublicKey } from './starcoin/StarcoinGetPublicKey';
29
+ export { default as starcoinSignMessage } from './starcoin/StarcoinSignMessage';
30
+ export { default as starcoinSignTransaction } from './starcoin/StarcoinSignTransaction';
31
+ export { default as starcoinVerifyMessage } from './starcoin/StarcoinVerifyMessage';
@@ -0,0 +1,57 @@
1
+ import { StarcoinGetAddress as HardwareStarcoinGetAddress } from '@onekeyfe/hd-transport/src/types/messages';
2
+ import { UI_REQUEST } from '../../constants/ui-request';
3
+ import { validatePath, serializedPath } from '../helpers/pathUtils';
4
+ import { BaseMethod } from '../BaseMethod';
5
+ import { validateParams } from '../helpers/paramsValidator';
6
+ import { StarcoinAddress, StarcoinGetAddressParams } from '../../types/api/starcoinGetAddress';
7
+
8
+ export default class StarcoinGetAddress extends BaseMethod<HardwareStarcoinGetAddress[]> {
9
+ hasBundle = false;
10
+
11
+ init() {
12
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
13
+
14
+ this.hasBundle = !!this.payload?.bundle;
15
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
16
+
17
+ // check payload
18
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
19
+
20
+ // init params
21
+ this.params = [];
22
+ payload.bundle.forEach((batch: StarcoinGetAddressParams) => {
23
+ const addressN = validatePath(batch.path, 3);
24
+
25
+ validateParams(batch, [
26
+ { name: 'path', required: true },
27
+ { name: 'showOnOneKey', type: 'boolean' },
28
+ ]);
29
+
30
+ const showOnOneKey = batch.showOnOneKey ?? true;
31
+
32
+ this.params.push({
33
+ address_n: addressN,
34
+ show_display: showOnOneKey,
35
+ });
36
+ });
37
+ }
38
+
39
+ async run() {
40
+ const responses: StarcoinAddress[] = [];
41
+
42
+ for (let i = 0; i < this.params.length; i++) {
43
+ const param = this.params[i];
44
+
45
+ const res = await this.device.commands.typedCall('StarcoinGetAddress', 'StarcoinAddress', {
46
+ ...param,
47
+ });
48
+
49
+ responses.push({
50
+ path: serializedPath(param.address_n),
51
+ ...res.message,
52
+ });
53
+ }
54
+
55
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
56
+ }
57
+ }
@@ -0,0 +1,64 @@
1
+ import { StarcoinGetPublicKey as HardwareStarcoinGetPublicKey } from '@onekeyfe/hd-transport/src/types/messages';
2
+ import { UI_REQUEST } from '../../constants/ui-request';
3
+ import { validatePath, serializedPath } from '../helpers/pathUtils';
4
+ import { BaseMethod } from '../BaseMethod';
5
+ import { validateParams } from '../helpers/paramsValidator';
6
+ import {
7
+ StarcoinPublicKey,
8
+ StarcoinGetPublicKeyParams,
9
+ } from '../../types/api/starcoinGetPublicKey';
10
+
11
+ export default class StarcoinGetPublicKey extends BaseMethod<HardwareStarcoinGetPublicKey[]> {
12
+ hasBundle = false;
13
+
14
+ init() {
15
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
16
+
17
+ this.hasBundle = !!this.payload?.bundle;
18
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
19
+
20
+ // check payload
21
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
22
+
23
+ // init params
24
+ this.params = [];
25
+ payload.bundle.forEach((batch: StarcoinGetPublicKeyParams) => {
26
+ const addressN = validatePath(batch.path, 3);
27
+
28
+ validateParams(batch, [
29
+ { name: 'path', required: true },
30
+ { name: 'showOnOneKey', type: 'boolean' },
31
+ ]);
32
+
33
+ const showOnOneKey = batch.showOnOneKey ?? true;
34
+
35
+ this.params.push({
36
+ address_n: addressN,
37
+ show_display: showOnOneKey,
38
+ });
39
+ });
40
+ }
41
+
42
+ async run() {
43
+ const responses: StarcoinPublicKey[] = [];
44
+
45
+ for (let i = 0; i < this.params.length; i++) {
46
+ const param = this.params[i];
47
+
48
+ const res = await this.device.commands.typedCall(
49
+ 'StarcoinGetPublicKey',
50
+ 'StarcoinPublicKey',
51
+ {
52
+ ...param,
53
+ }
54
+ );
55
+
56
+ responses.push({
57
+ path: serializedPath(param.address_n),
58
+ ...res.message,
59
+ });
60
+ }
61
+
62
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
63
+ }
64
+ }
@@ -0,0 +1,40 @@
1
+ import { StarcoinSignMessage as HardwareStarcoinSignMessage } from '@onekeyfe/hd-transport/src/types/messages';
2
+ import { UI_REQUEST } from '../../constants/ui-request';
3
+ import { validatePath } from '../helpers/pathUtils';
4
+ import { BaseMethod } from '../BaseMethod';
5
+ import { validateParams } from '../helpers/paramsValidator';
6
+ import { formatAnyHex } from '../helpers/hexUtils';
7
+
8
+ export default class StarcoinSignMessage extends BaseMethod<HardwareStarcoinSignMessage> {
9
+ init() {
10
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
11
+
12
+ // check payload
13
+ validateParams(this.payload, [
14
+ { name: 'path', required: true },
15
+ { name: 'messageHex', type: 'hexString', required: true },
16
+ ]);
17
+
18
+ const { path, messageHex } = this.payload;
19
+
20
+ const addressN = validatePath(path, 3);
21
+
22
+ // init params
23
+ this.params = {
24
+ address_n: addressN,
25
+ message: formatAnyHex(messageHex),
26
+ };
27
+ }
28
+
29
+ async run() {
30
+ const res = await this.device.commands.typedCall(
31
+ 'StarcoinSignMessage',
32
+ 'StarcoinMessageSignature',
33
+ {
34
+ ...this.params,
35
+ }
36
+ );
37
+
38
+ return Promise.resolve(res.message);
39
+ }
40
+ }
@@ -0,0 +1,36 @@
1
+ import { StarcoinSignTx } from '@onekeyfe/hd-transport/src/types/messages';
2
+ import { UI_REQUEST } from '../../constants/ui-request';
3
+ import { validatePath } from '../helpers/pathUtils';
4
+ import { BaseMethod } from '../BaseMethod';
5
+ import { validateParams } from '../helpers/paramsValidator';
6
+ import { formatAnyHex } from '../helpers/hexUtils';
7
+
8
+ export default class StarcoinSignTransaction extends BaseMethod<StarcoinSignTx> {
9
+ init() {
10
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
11
+
12
+ // check payload
13
+ validateParams(this.payload, [
14
+ { name: 'path', required: true },
15
+ { name: 'rawTx', type: 'hexString', required: true },
16
+ ]);
17
+
18
+ const { path, rawTx } = this.payload;
19
+
20
+ const addressN = validatePath(path, 3);
21
+
22
+ // init params
23
+ this.params = {
24
+ address_n: addressN,
25
+ raw_tx: formatAnyHex(rawTx),
26
+ };
27
+ }
28
+
29
+ async run() {
30
+ const res = await this.device.commands.typedCall('StarcoinSignTx', 'StarcoinSignedTx', {
31
+ ...this.params,
32
+ });
33
+
34
+ return Promise.resolve(res.message);
35
+ }
36
+ }
@@ -0,0 +1,33 @@
1
+ import { StarcoinVerifyMessage as HardwareStarcoinVerifyMessage } from '@onekeyfe/hd-transport/src/types/messages';
2
+ import { UI_REQUEST } from '../../constants/ui-request';
3
+ import { BaseMethod } from '../BaseMethod';
4
+ import { validateParams } from '../helpers/paramsValidator';
5
+ import { formatAnyHex } from '../helpers/hexUtils';
6
+
7
+ export default class EVMSignMessage extends BaseMethod<HardwareStarcoinVerifyMessage> {
8
+ init() {
9
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
10
+
11
+ validateParams(this.payload, [
12
+ { name: 'publicKey', type: 'string', required: true },
13
+ { name: 'messageHex', type: 'hexString', required: true },
14
+ { name: 'signature', type: 'hexString', required: true },
15
+ ]);
16
+
17
+ const { publicKey, messageHex, signature } = formatAnyHex(this.payload);
18
+
19
+ this.params = {
20
+ public_key: publicKey,
21
+ message: messageHex,
22
+ signature,
23
+ };
24
+ }
25
+
26
+ async run() {
27
+ const res = await this.device.commands.typedCall('StarcoinVerifyMessage', 'Success', {
28
+ ...this.params,
29
+ });
30
+
31
+ return Promise.resolve(res.message);
32
+ }
33
+ }
package/src/core/index.ts CHANGED
@@ -19,6 +19,7 @@ import {
19
19
  UiPromise,
20
20
  UiPromiseResponse,
21
21
  createUiMessage,
22
+ createDeviceMessage,
22
23
  } from '../events';
23
24
  import type { BaseMethod } from '../api/BaseMethod';
24
25
  import type { ConnectSettings, KnownDevice } from '../types';
@@ -90,6 +91,9 @@ export const callAPI = async (message: CoreMessage) => {
90
91
  method.setDevice?.(device);
91
92
 
92
93
  device.on(DEVICE.PIN, onDevicePinHandler);
94
+ device.on(DEVICE.BUTTON, (d, code) => {
95
+ onDeviceButtonHandler(d, code);
96
+ });
93
97
 
94
98
  try {
95
99
  const inner = async (): Promise<void> => {
@@ -144,6 +148,10 @@ export const callAPI = async (message: CoreMessage) => {
144
148
  method.dispose();
145
149
  }
146
150
  }
151
+
152
+ closePopup();
153
+
154
+ cleanup();
147
155
  // TODO: 方法执行后,检查队列内是否有等待调用的 API,依次调用
148
156
  }
149
157
  };
@@ -203,6 +211,18 @@ function initDeviceForBle(method: BaseMethod) {
203
211
  return device;
204
212
  }
205
213
 
214
+ const cleanup = () => {
215
+ _uiPromises = [];
216
+ Log.debug('Cleanup...');
217
+ };
218
+
219
+ /**
220
+ * Force close popup
221
+ */
222
+ const closePopup = () => {
223
+ postMessage(createUiMessage(UI_REQUEST.CLOSE_UI_WINDOW));
224
+ };
225
+
206
226
  const onDevicePinHandler = async (...[device, type, callback]: DeviceEvents['pin']) => {
207
227
  console.log('onDevicePinHandler');
208
228
  // create ui promise
@@ -220,6 +240,11 @@ const onDevicePinHandler = async (...[device, type, callback]: DeviceEvents['pin
220
240
  callback(null, uiResp.payload);
221
241
  };
222
242
 
243
+ const onDeviceButtonHandler = (...[device, request]: [...DeviceEvents['button']]) => {
244
+ postMessage(createDeviceMessage(DEVICE.BUTTON, { ...request, device: device.toMessageObject() }));
245
+ postMessage(createUiMessage(UI_REQUEST.REQUEST_BUTTON, { device: device.toMessageObject() }));
246
+ };
247
+
223
248
  /**
224
249
  * Emit message to listener (parent).
225
250
  * Clear method reference from _callMethods
@@ -119,6 +119,10 @@ export class Device extends EventEmitter {
119
119
  /** ID for current seeds, will clear after replace a new seed at device */
120
120
  deviceId: this.features.device_id || null,
121
121
  path: this.originalDescriptor.path,
122
+ name:
123
+ this.features.ble_name ||
124
+ this.features.label ||
125
+ `OneKey ${getDeviceType(this.features).toUpperCase()}`,
122
126
  label: getDeviceLabel(this.features),
123
127
  mode: this.getMode(),
124
128
  features: this.features,
@@ -1,5 +1,6 @@
1
1
  import { Unsuccessful } from '../types/params';
2
2
  import { IFrameCallMessage } from './call';
3
+ import { DeviceEventMessage } from './device';
3
4
  import { IFrameEventMessage } from './iframe';
4
5
  import { UiEventMessage } from './ui-request';
5
6
  import { UiResponseMessage } from './ui-response';
@@ -9,7 +10,13 @@ export const CORE_EVENT = 'CORE_EVENT';
9
10
  export type CoreMessage = {
10
11
  id?: string;
11
12
  success?: true | false;
12
- } & (IFrameEventMessage | IFrameCallMessage | UiResponseMessage | UiEventMessage);
13
+ } & (
14
+ | IFrameEventMessage
15
+ | IFrameCallMessage
16
+ | UiResponseMessage
17
+ | UiEventMessage
18
+ | DeviceEventMessage
19
+ );
13
20
 
14
21
  export type PostMessageEvent = MessageEvent<any>;
15
22
 
@@ -1,5 +1,8 @@
1
1
  import type { PROTO } from '../constants';
2
+ import type { KnownDevice as Device } from '../types/device';
3
+ import { MessageFactoryFn } from './utils';
2
4
 
5
+ export const DEVICE_EVENT = 'DEVICE_EVENT';
3
6
  export const DEVICE = {
4
7
  // device list events
5
8
  CONNECT: 'device-connect',
@@ -26,3 +29,27 @@ export const DEVICE = {
26
29
  export interface DeviceButtonRequestPayload extends Omit<PROTO.ButtonRequest, 'code'> {
27
30
  code?: PROTO.ButtonRequest['code'] | 'ButtonRequest_FirmwareUpdate';
28
31
  }
32
+
33
+ export interface DeviceButtonRequest {
34
+ type: typeof DEVICE.BUTTON;
35
+ payload: DeviceButtonRequestPayload & { device: Device | null };
36
+ }
37
+
38
+ export type DeviceEvent = DeviceButtonRequest;
39
+
40
+ export type DeviceEventMessage = DeviceEvent & { event: typeof DEVICE_EVENT };
41
+
42
+ export type DeviceEventListenerFn = (
43
+ type: typeof DEVICE_EVENT,
44
+ cb: (event: DeviceEventMessage) => void
45
+ ) => void;
46
+
47
+ export const createDeviceMessage: MessageFactoryFn<typeof DEVICE_EVENT, DeviceEvent> = (
48
+ type,
49
+ payload
50
+ ) =>
51
+ ({
52
+ event: DEVICE_EVENT,
53
+ type,
54
+ payload,
55
+ } as any);
@@ -1,13 +1,23 @@
1
1
  import type { PROTO } from '../constants';
2
2
  import type { Device } from '../types';
3
+ import type { DeviceButtonRequest } from './device';
3
4
  import type { MessageFactoryFn } from './utils';
4
5
 
5
6
  export const UI_EVENT = 'UI_EVENT';
6
7
 
7
8
  export const UI_REQUEST = {
8
9
  REQUEST_PIN: 'ui-request_pin',
10
+ INVALID_PIN: 'ui-invalid_pin',
11
+ REQUEST_BUTTON: 'ui-button',
12
+
13
+ CLOSE_UI_WINDOW: 'ui-close_window',
9
14
  } as const;
10
15
 
16
+ export interface UiRequestWithoutPayload {
17
+ type: typeof UI_REQUEST.CLOSE_UI_WINDOW;
18
+ payload?: typeof undefined;
19
+ }
20
+
11
21
  export type UiRequestDeviceAction = {
12
22
  type: typeof UI_REQUEST.REQUEST_PIN;
13
23
  payload: {
@@ -16,7 +26,12 @@ export type UiRequestDeviceAction = {
16
26
  };
17
27
  };
18
28
 
19
- export type UiEvent = UiRequestDeviceAction;
29
+ export interface UiRequestButton {
30
+ type: typeof UI_REQUEST.REQUEST_BUTTON;
31
+ payload: DeviceButtonRequest['payload'];
32
+ }
33
+
34
+ export type UiEvent = UiRequestWithoutPayload | UiRequestDeviceAction | UiRequestButton;
20
35
 
21
36
  export type UiEventMessage = UiEvent & { event: typeof UI_EVENT };
22
37
 
package/src/inject.ts CHANGED
@@ -73,7 +73,7 @@ export const inject = ({
73
73
  deviceRebootToBootloader: connectId => call({ connectId, method: 'deviceRebootToBootloader' }),
74
74
  deviceRecovery: (connectId, params) => call({ ...params, connectId, method: 'deviceRecovery' }),
75
75
  deviceReset: (connectId, params) => call({ ...params, connectId, method: 'deviceReset' }),
76
- deviceSettings: connectId => call({ connectId, method: 'deviceSettings' }),
76
+ deviceSettings: (connectId, params) => call({ ...params, connectId, method: 'deviceSettings' }),
77
77
  deviceUpdateReboot: connectId => call({ connectId, method: 'deviceUpdateReboot' }),
78
78
  deviceWipe: connectId => call({ connectId, method: 'deviceWipe' }),
79
79
 
@@ -98,6 +98,17 @@ export const inject = ({
98
98
  call({ ...params, connectId, method: 'btcSignTransaction' }),
99
99
  btcVerifyMessage: (connectId, params) =>
100
100
  call({ ...params, connectId, method: 'btcVerifyMessage' }),
101
+
102
+ starcoinGetAddress: (connectId, params) =>
103
+ call({ ...params, connectId, method: 'starcoinGetAddress' }),
104
+ starcoinGetPublicKey: (connectId, params) =>
105
+ call({ ...params, connectId, method: 'starcoinGetPublicKey' }),
106
+ starcoinSignMessage: (connectId, params) =>
107
+ call({ ...params, connectId, method: 'starcoinSignMessage' }),
108
+ starcoinSignTransaction: (connectId, params) =>
109
+ call({ ...params, connectId, method: 'starcoinSignTransaction' }),
110
+ starcoinVerifyMessage: (connectId, params) =>
111
+ call({ ...params, connectId, method: 'starcoinVerifyMessage' }),
101
112
  };
102
113
  return api;
103
114
  };
@@ -5,6 +5,10 @@ import {
5
5
  } from '@onekeyfe/hd-transport/src/types/messages';
6
6
  import type { CommonParams, Response } from '../params';
7
7
 
8
+ export type BTCAddress = {
9
+ path: string;
10
+ } & Address;
11
+
8
12
  export type BTCGetAddressParams = {
9
13
  path: string | number[];
10
14
  coin?: string;
@@ -16,9 +20,9 @@ export type BTCGetAddressParams = {
16
20
  export declare function btcGetAddress(
17
21
  connectId: string,
18
22
  params: CommonParams & BTCGetAddressParams
19
- ): Response<Address>;
23
+ ): Response<BTCAddress>;
20
24
 
21
25
  export declare function btcGetAddress(
22
26
  connectId: string,
23
27
  params: CommonParams & { bundle?: BTCGetAddressParams[] }
24
- ): Response<Array<Address>>;
28
+ ): Response<Array<BTCAddress>>;
@@ -1,6 +1,10 @@
1
1
  import { InputScriptType, PublicKey } from '@onekeyfe/hd-transport/src/types/messages';
2
2
  import type { CommonParams, Response } from '../params';
3
3
 
4
+ export type BTCPublicKey = {
5
+ path: string;
6
+ } & PublicKey;
7
+
4
8
  export type BTCGetPublicKeyParams = {
5
9
  path: string | number[];
6
10
  coin?: string;
@@ -11,9 +15,9 @@ export type BTCGetPublicKeyParams = {
11
15
  export declare function btcGetPublicKey(
12
16
  connectId: string,
13
17
  params: CommonParams & BTCGetPublicKeyParams
14
- ): Response<PublicKey>;
18
+ ): Response<BTCPublicKey>;
15
19
 
16
20
  export declare function btcGetPublicKey(
17
21
  connectId: string,
18
22
  params: CommonParams & { bundle?: BTCGetPublicKeyParams[] }
19
- ): Response<Array<PublicKey>>;
23
+ ): Response<Array<BTCPublicKey>>;