@onekeyfe/hd-core 0.1.41 → 0.1.44

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 (103) hide show
  1. package/dist/api/BaseMethod.d.ts.map +1 -1
  2. package/dist/api/aptos/AptosGetAddress.d.ts +9 -0
  3. package/dist/api/aptos/AptosGetAddress.d.ts.map +1 -0
  4. package/dist/api/aptos/AptosSignTransaction.d.ts +12 -0
  5. package/dist/api/aptos/AptosSignTransaction.d.ts.map +1 -0
  6. package/dist/api/conflux/ConfluxGetAddress.d.ts +14 -0
  7. package/dist/api/conflux/ConfluxGetAddress.d.ts.map +1 -0
  8. package/dist/api/conflux/ConfluxSignMessage.d.ts +12 -0
  9. package/dist/api/conflux/ConfluxSignMessage.d.ts.map +1 -0
  10. package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts +12 -0
  11. package/dist/api/conflux/ConfluxSignMessageCIP23.d.ts.map +1 -0
  12. package/dist/api/conflux/ConfluxSignTransaction.d.ts +17 -0
  13. package/dist/api/conflux/ConfluxSignTransaction.d.ts.map +1 -0
  14. package/dist/api/helpers/stringUtils.d.ts +1 -0
  15. package/dist/api/helpers/stringUtils.d.ts.map +1 -1
  16. package/dist/api/index.d.ts +21 -10
  17. package/dist/api/index.d.ts.map +1 -1
  18. package/dist/api/near/NearGetAddress.d.ts +14 -0
  19. package/dist/api/near/NearGetAddress.d.ts.map +1 -0
  20. package/dist/api/near/NearSignTransaction.d.ts +12 -0
  21. package/dist/api/near/NearSignTransaction.d.ts.map +1 -0
  22. package/dist/api/solana/SolGetAddress.d.ts.map +1 -1
  23. package/dist/api/solana/SolSignTransaction.d.ts.map +1 -1
  24. package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -1
  25. package/dist/api/tron/TronGetAddress.d.ts +14 -0
  26. package/dist/api/tron/TronGetAddress.d.ts.map +1 -0
  27. package/dist/api/tron/TronSignMessage.d.ts +12 -0
  28. package/dist/api/tron/TronSignMessage.d.ts.map +1 -0
  29. package/dist/api/tron/TronSignTransaction.d.ts +14 -0
  30. package/dist/api/tron/TronSignTransaction.d.ts.map +1 -0
  31. package/dist/core/index.d.ts.map +1 -1
  32. package/dist/device/DeviceCommands.d.ts +1 -1
  33. package/dist/device/DeviceCommands.d.ts.map +1 -1
  34. package/dist/index.d.ts +347 -199
  35. package/dist/index.js +1579 -594
  36. package/dist/inject.d.ts.map +1 -1
  37. package/dist/types/api/aptosGetAddress.d.ts +14 -0
  38. package/dist/types/api/aptosGetAddress.d.ts.map +1 -0
  39. package/dist/types/api/aptosSignTransaction.d.ts +11 -0
  40. package/dist/types/api/aptosSignTransaction.d.ts.map +1 -0
  41. package/dist/types/api/confluxGetAddress.d.ts +15 -0
  42. package/dist/types/api/confluxGetAddress.d.ts.map +1 -0
  43. package/dist/types/api/confluxSignMessage.d.ts +8 -0
  44. package/dist/types/api/confluxSignMessage.d.ts.map +1 -0
  45. package/dist/types/api/confluxSignMessageCIP23.d.ts +9 -0
  46. package/dist/types/api/confluxSignMessageCIP23.d.ts.map +1 -0
  47. package/dist/types/api/confluxSignTransaction.d.ts +25 -0
  48. package/dist/types/api/confluxSignTransaction.d.ts.map +1 -0
  49. package/dist/types/api/deviceVerify.d.ts +2 -3
  50. package/dist/types/api/deviceVerify.d.ts.map +1 -1
  51. package/dist/types/api/export.d.ts +11 -0
  52. package/dist/types/api/export.d.ts.map +1 -1
  53. package/dist/types/api/index.d.ts +49 -27
  54. package/dist/types/api/index.d.ts.map +1 -1
  55. package/dist/types/api/nearGetAddress.d.ts +14 -0
  56. package/dist/types/api/nearGetAddress.d.ts.map +1 -0
  57. package/dist/types/api/nearSignTransaction.d.ts +8 -0
  58. package/dist/types/api/nearSignTransaction.d.ts.map +1 -0
  59. package/dist/types/api/tronGetAddress.d.ts +14 -0
  60. package/dist/types/api/tronGetAddress.d.ts.map +1 -0
  61. package/dist/types/api/tronSignMessage.d.ts +8 -0
  62. package/dist/types/api/tronSignMessage.d.ts.map +1 -0
  63. package/dist/types/api/tronSignTransaction.d.ts +32 -0
  64. package/dist/types/api/tronSignTransaction.d.ts.map +1 -0
  65. package/dist/utils/patch.d.ts +1 -1
  66. package/dist/utils/patch.d.ts.map +1 -1
  67. package/package.json +4 -4
  68. package/src/api/BaseMethod.ts +5 -2
  69. package/src/api/aptos/AptosGetAddress.ts +60 -0
  70. package/src/api/aptos/AptosSignTransaction.ts +45 -0
  71. package/src/api/conflux/ConfluxGetAddress.ts +67 -0
  72. package/src/api/conflux/ConfluxSignMessage.ts +48 -0
  73. package/src/api/conflux/ConfluxSignMessageCIP23.ts +48 -0
  74. package/src/api/conflux/ConfluxSignTransaction.ts +134 -0
  75. package/src/api/helpers/stringUtils.ts +3 -0
  76. package/src/api/index.ts +26 -10
  77. package/src/api/near/NearGetAddress.ts +68 -0
  78. package/src/api/near/NearSignTransaction.ts +45 -0
  79. package/src/api/solana/SolGetAddress.ts +0 -2
  80. package/src/api/solana/SolSignTransaction.ts +0 -2
  81. package/src/api/stellar/StellarSignTransaction.ts +14 -7
  82. package/src/api/tron/TronGetAddress.ts +68 -0
  83. package/src/api/tron/TronSignMessage.ts +48 -0
  84. package/src/api/tron/TronSignTransaction.ts +87 -0
  85. package/src/core/index.ts +15 -2
  86. package/src/data/messages/messages.json +8887 -8433
  87. package/src/device/DeviceCommands.ts +6 -7
  88. package/src/inject.ts +26 -0
  89. package/src/types/api/aptosGetAddress.ts +23 -0
  90. package/src/types/api/aptosSignTransaction.ts +17 -0
  91. package/src/types/api/confluxGetAddress.ts +24 -0
  92. package/src/types/api/confluxSignMessage.ts +13 -0
  93. package/src/types/api/confluxSignMessageCIP23.ts +14 -0
  94. package/src/types/api/confluxSignTransaction.ts +32 -0
  95. package/src/types/api/deviceVerify.ts +2 -2
  96. package/src/types/api/export.ts +25 -0
  97. package/src/types/api/index.ts +101 -35
  98. package/src/types/api/nearGetAddress.ts +23 -0
  99. package/src/types/api/nearSignTransaction.ts +13 -0
  100. package/src/types/api/tronGetAddress.ts +23 -0
  101. package/src/types/api/tronSignMessage.ts +13 -0
  102. package/src/types/api/tronSignTransaction.ts +41 -0
  103. package/src/utils/deviceFeaturesUtils.ts +2 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "0.1.41",
3
+ "version": "0.1.44",
4
4
  "description": "> TODO: description",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -24,8 +24,8 @@
24
24
  "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
25
25
  },
26
26
  "dependencies": {
27
- "@onekeyfe/hd-shared": "^0.1.41",
28
- "@onekeyfe/hd-transport": "^0.1.41",
27
+ "@onekeyfe/hd-shared": "^0.1.44",
28
+ "@onekeyfe/hd-transport": "^0.1.44",
29
29
  "axios": "^0.27.2",
30
30
  "bignumber.js": "^9.0.2",
31
31
  "js-sha256": "^0.9.0",
@@ -36,5 +36,5 @@
36
36
  "@types/parse-uri": "^1.0.0",
37
37
  "@types/semver": "^7.3.9"
38
38
  },
39
- "gitHead": "0c5bf8f29b26ee02a5587aa716db4dfd7b17defd"
39
+ "gitHead": "fb673918587877267cbbeca6e0c6abbc56a0d0fa"
40
40
  }
@@ -133,14 +133,17 @@ export abstract class BaseMethod<Params = undefined> {
133
133
  }
134
134
 
135
135
  /**
136
- * Check the level of safety_check when performing transactions on the test network on touch
136
+ * Automatic check safety_check level for Kovan, Ropsten, Rinkeby, Goerli test networks.
137
137
  * @returns {void}
138
138
  */
139
139
  async checkSafetyLevelOnTestNet() {
140
140
  const deviceType = getDeviceType(this.device.features);
141
141
  if (deviceType !== 'touch') return;
142
142
  let checkFlag = false;
143
- if (this.name === 'evmSignTransaction' && Number(this.payload?.transaction?.chainId) !== 1) {
143
+ if (
144
+ this.name === 'evmSignTransaction' &&
145
+ [3, 4, 5, 42].includes(Number(this.payload?.transaction?.chainId))
146
+ ) {
144
147
  checkFlag = true;
145
148
  }
146
149
  if (checkFlag && this.device.features?.safety_checks === 'Strict') {
@@ -0,0 +1,60 @@
1
+ import { AptosGetAddress as HardwareAptosGetAddress } from '@onekeyfe/hd-transport';
2
+ import { UI_REQUEST } from '../../constants/ui-request';
3
+ import { serializedPath, validatePath } from '../helpers/pathUtils';
4
+ import { BaseMethod } from '../BaseMethod';
5
+ import { validateParams } from '../helpers/paramsValidator';
6
+ import { AptosAddress, AptosGetAddressParams } from '../../types';
7
+
8
+ export default class AptosGetAddress extends BaseMethod<HardwareAptosGetAddress[]> {
9
+ hasBundle = false;
10
+
11
+ init() {
12
+ this.checkDeviceId = true;
13
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
14
+
15
+ this.hasBundle = !!this.payload?.bundle;
16
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
17
+
18
+ // check payload
19
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
20
+
21
+ // init params
22
+ this.params = [];
23
+ payload.bundle.forEach((batch: AptosGetAddressParams) => {
24
+ const addressN = validatePath(batch.path, 3);
25
+
26
+ validateParams(batch, [
27
+ { name: 'path', required: true },
28
+ { name: 'showOnOneKey', type: 'boolean' },
29
+ ]);
30
+
31
+ const showOnOneKey = batch.showOnOneKey ?? true;
32
+
33
+ this.params.push({
34
+ address_n: addressN,
35
+ show_display: showOnOneKey,
36
+ });
37
+ });
38
+ }
39
+
40
+ async run() {
41
+ const responses: AptosAddress[] = [];
42
+
43
+ for (let i = 0; i < this.params.length; i++) {
44
+ const param = this.params[i];
45
+
46
+ const res = await this.device.commands.typedCall('AptosGetAddress', 'AptosAddress', {
47
+ ...param,
48
+ });
49
+
50
+ const { address } = res.message;
51
+
52
+ responses.push({
53
+ path: serializedPath(param.address_n),
54
+ address,
55
+ });
56
+ }
57
+
58
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
59
+ }
60
+ }
@@ -0,0 +1,45 @@
1
+ import { AptosSignTx as HardwareAptosSignTx } from '@onekeyfe/hd-transport';
2
+ import { UI_REQUEST } from '../../constants/ui-request';
3
+ import { serializedPath, 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 AptosSignTransaction extends BaseMethod<HardwareAptosSignTx> {
9
+ init() {
10
+ this.checkDeviceId = true;
11
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
12
+
13
+ // check payload
14
+ validateParams(this.payload, [
15
+ { name: 'path', required: true },
16
+ { name: 'rawTx', type: 'hexString', required: true },
17
+ ]);
18
+
19
+ const { path, rawTx } = this.payload;
20
+
21
+ const addressN = validatePath(path, 3);
22
+
23
+ // init params
24
+ this.params = {
25
+ address_n: addressN,
26
+ raw_tx: formatAnyHex(rawTx),
27
+ };
28
+ }
29
+
30
+ getVersionRange() {
31
+ return {
32
+ model_mini: {
33
+ min: '2.4.0',
34
+ },
35
+ };
36
+ }
37
+
38
+ async run() {
39
+ const res = await this.device.commands.typedCall('AptosSignTx', 'AptosSignedTx', {
40
+ ...this.params,
41
+ });
42
+
43
+ return Promise.resolve(res.message);
44
+ }
45
+ }
@@ -0,0 +1,67 @@
1
+ import { ConfluxGetAddress as HardwareConfluxGetAddress } from '@onekeyfe/hd-transport';
2
+ import { UI_REQUEST } from '../../constants/ui-request';
3
+ import { serializedPath, validatePath } from '../helpers/pathUtils';
4
+ import { BaseMethod } from '../BaseMethod';
5
+ import { validateParams } from '../helpers/paramsValidator';
6
+ import { ConfluxAddress, ConfluxGetAddressParams } from '../../types/api/confluxGetAddress';
7
+
8
+ export default class ConfluxGetAddress extends BaseMethod<HardwareConfluxGetAddress[]> {
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: ConfluxGetAddressParams) => {
23
+ const addressN = validatePath(batch.path, 3);
24
+
25
+ validateParams(batch, [
26
+ { name: 'path', required: true },
27
+ { name: 'chainId', type: 'number' },
28
+ { name: 'showOnOneKey', type: 'boolean' },
29
+ ]);
30
+
31
+ const showOnOneKey = batch.showOnOneKey ?? true;
32
+
33
+ this.params.push({
34
+ address_n: addressN,
35
+ chain_id: batch.chainId,
36
+ show_display: showOnOneKey,
37
+ });
38
+ });
39
+ }
40
+
41
+ getVersionRange() {
42
+ return {
43
+ model_mini: {
44
+ min: '2.4.0',
45
+ },
46
+ };
47
+ }
48
+
49
+ async run() {
50
+ const responses: ConfluxAddress[] = [];
51
+
52
+ for (let i = 0; i < this.params.length; i++) {
53
+ const param = this.params[i];
54
+
55
+ const res = await this.device.commands.typedCall('ConfluxGetAddress', 'ConfluxAddress', {
56
+ ...param,
57
+ });
58
+
59
+ responses.push({
60
+ path: serializedPath(param.address_n),
61
+ ...res.message,
62
+ });
63
+ }
64
+
65
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
66
+ }
67
+ }
@@ -0,0 +1,48 @@
1
+ import { ConfluxSignMessage as HardwareConfluxSignMessage } from '@onekeyfe/hd-transport';
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 ConfluxSignMessage extends BaseMethod<HardwareConfluxSignMessage> {
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
+ getVersionRange() {
30
+ return {
31
+ model_mini: {
32
+ min: '2.4.0',
33
+ },
34
+ };
35
+ }
36
+
37
+ async run() {
38
+ const res = await this.device.commands.typedCall(
39
+ 'ConfluxSignMessage',
40
+ 'ConfluxMessageSignature',
41
+ {
42
+ ...this.params,
43
+ },
44
+ );
45
+
46
+ return Promise.resolve(res.message);
47
+ }
48
+ }
@@ -0,0 +1,48 @@
1
+ import { ConfluxSignMessageCIP23 as HardwareConfluxSignMessageCIP23 } from '@onekeyfe/hd-transport';
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 ConfluxSignMessageCIP23 extends BaseMethod<HardwareConfluxSignMessageCIP23> {
9
+ init() {
10
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
11
+
12
+ validateParams(this.payload, [
13
+ { name: 'path', required: true },
14
+ { name: 'domainHash', type: 'hexString', required: true },
15
+ { name: 'messageHash', type: 'hexString', required: true },
16
+ ]);
17
+
18
+ const { path, domainHash, messageHash } = this.payload;
19
+
20
+ const addressN = validatePath(path, 3);
21
+
22
+ this.params = {
23
+ address_n: addressN,
24
+ domain_hash: formatAnyHex(domainHash),
25
+ message_hash: formatAnyHex(messageHash),
26
+ };
27
+ }
28
+
29
+ getVersionRange() {
30
+ return {
31
+ model_mini: {
32
+ min: '2.4.0',
33
+ },
34
+ };
35
+ }
36
+
37
+ async run() {
38
+ const res = await this.device.commands.typedCall(
39
+ 'ConfluxSignMessageCIP23',
40
+ 'ConfluxMessageSignature',
41
+ {
42
+ ...this.params,
43
+ },
44
+ );
45
+
46
+ return Promise.resolve(res.message);
47
+ }
48
+ }
@@ -0,0 +1,134 @@
1
+ import { ConfluxSignTx, ConfluxTxRequest } from '@onekeyfe/hd-transport';
2
+ import { ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
3
+ import {
4
+ ConfluxSignedTx,
5
+ ConfluxSignTransactionParams,
6
+ ConfluxTransaction,
7
+ } from '../../types/api/confluxSignTransaction';
8
+
9
+ import { UI_REQUEST } from '../../constants/ui-request';
10
+ import { validatePath } from '../helpers/pathUtils';
11
+ import { BaseMethod } from '../BaseMethod';
12
+ import { SchemaParam, validateParams } from '../helpers/paramsValidator';
13
+
14
+ import { cutString } from '../helpers/stringUtils';
15
+ import { formatAnyHex, stripHexStartZeroes } from '../helpers/hexUtils';
16
+
17
+ export default class ConfluxSignTransaction extends BaseMethod {
18
+ addressN: number[] = [];
19
+
20
+ formattedTx: ConfluxTransaction | undefined;
21
+
22
+ init() {
23
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
24
+
25
+ validateParams(this.payload, [
26
+ { name: 'path', required: true },
27
+ { name: 'transaction', type: 'object', required: true },
28
+ ]);
29
+ const { path, transaction } = this.payload;
30
+ this.addressN = validatePath(path, 3);
31
+
32
+ const tx: ConfluxSignTransactionParams['transaction'] = transaction;
33
+
34
+ // check if transaction is valid
35
+ const schema: SchemaParam[] = [
36
+ { name: 'to', type: 'hexString', required: true },
37
+ { name: 'value', type: 'hexString', required: true },
38
+ { name: 'gasLimit', type: 'hexString', required: true },
39
+ { name: 'gasPrice', type: 'hexString', required: true },
40
+ { name: 'nonce', type: 'hexString', required: true },
41
+ { name: 'epochHeight', type: 'hexString', required: true },
42
+ { name: 'storageLimit', type: 'hexString', required: true },
43
+ { name: 'chainId', type: 'number', required: true },
44
+ { name: 'data', type: 'hexString' },
45
+ ];
46
+
47
+ validateParams(tx, schema);
48
+
49
+ this.formattedTx = formatAnyHex(tx);
50
+ }
51
+
52
+ processTxRequest = async (request: ConfluxTxRequest, data: string): Promise<ConfluxSignedTx> => {
53
+ if (!request.data_length) {
54
+ const v = request.signature_v;
55
+ const r = request.signature_r;
56
+ const s = request.signature_s;
57
+
58
+ if (v == null || r == null || s == null) {
59
+ throw ERRORS.TypedError(HardwareErrorCode.CallMethodError, 'sign transaction failed');
60
+ }
61
+
62
+ return Promise.resolve({
63
+ v: `0x${v.toString(16)}`,
64
+ r: `0x${r}`,
65
+ s: `0x${s}`,
66
+ });
67
+ }
68
+
69
+ const [first, rest] = cutString(data, request.data_length * 2);
70
+ const response = await this.device.commands.typedCall('ConfluxTxAck', 'ConfluxTxRequest', {
71
+ data_chunk: first,
72
+ });
73
+
74
+ return this.processTxRequest(response.message, rest);
75
+ };
76
+
77
+ evmSignTx = async (addressN: number[], tx: ConfluxTransaction) => {
78
+ const { to, value, gasPrice, gasLimit, nonce, data, chainId, epochHeight, storageLimit } = tx;
79
+
80
+ const length = data == null ? 0 : data.length / 2;
81
+
82
+ const [first, rest] = cutString(data, 1024 * 2);
83
+
84
+ let message: ConfluxSignTx = {
85
+ address_n: addressN,
86
+ nonce: stripHexStartZeroes(nonce),
87
+ gas_price: stripHexStartZeroes(gasPrice),
88
+ gas_limit: stripHexStartZeroes(gasLimit),
89
+ to,
90
+ value: stripHexStartZeroes(value),
91
+ epoch_height: stripHexStartZeroes(epochHeight),
92
+ storage_limit: stripHexStartZeroes(storageLimit),
93
+ chain_id: chainId,
94
+ };
95
+
96
+ if (length !== 0) {
97
+ message = {
98
+ ...message,
99
+ data_length: length,
100
+ data_initial_chunk: first,
101
+ };
102
+ }
103
+
104
+ const response = await this.device.commands.typedCall(
105
+ 'ConfluxSignTx',
106
+ 'ConfluxTxRequest',
107
+ message,
108
+ );
109
+
110
+ return this.processTxRequest(response.message, rest);
111
+ };
112
+
113
+ getVersionRange() {
114
+ return {
115
+ model_mini: {
116
+ min: '2.4.0',
117
+ },
118
+ };
119
+ }
120
+
121
+ async run() {
122
+ const { addressN, formattedTx } = this;
123
+ if (formattedTx == null) {
124
+ throw ERRORS.TypedError(
125
+ HardwareErrorCode.CallMethodInvalidParameter,
126
+ 'ConfluxSignTransaction: format tx error',
127
+ );
128
+ }
129
+
130
+ const signedTx = await this.evmSignTx(addressN, formattedTx);
131
+
132
+ return Promise.resolve(signedTx);
133
+ }
134
+ }
@@ -6,3 +6,6 @@ export const cutString = (str: string | undefined, cutLen: number): [string, str
6
6
  const second = str.slice(cutLen);
7
7
  return [first, second];
8
8
  };
9
+
10
+ export const toSnakeCase = (val: string): string =>
11
+ val.replace(/([A-Z])/g, el => '_' + el.toLowerCase());
package/src/api/index.ts CHANGED
@@ -1,11 +1,7 @@
1
1
  export { default as searchDevices } from './SearchDevices';
2
2
  export { default as getFeatures } from './GetFeatures';
3
- export { default as cipherKeyValue } from './CipherKeyValue';
4
- export { default as btcGetAddress } from './btc/BTCGetAddress';
5
- export { default as btcGetPublicKey } from './btc/BTCGetPublicKey';
6
- export { default as btcSignMessage } from './btc/BTCSignMessage';
7
- export { default as btcSignTransaction } from './btc/BTCSignTransaction';
8
- export { default as btcVerifyMessage } from './btc/BTCVerifyMessage';
3
+ export { default as getPassphraseState } from './GetPassphraseState';
4
+ export { default as getLogs } from './GetLogs';
9
5
  export { default as checkFirmwareRelease } from './CheckFirmwareRelease';
10
6
  export { default as checkBLEFirmwareRelease } from './CheckBLEFirmwareRelease';
11
7
  export { default as checkTransportRelease } from './CheckTransportRelease';
@@ -21,6 +17,22 @@ export { default as deviceUpdateReboot } from './device/DeviceUpdateReboot';
21
17
  export { default as deviceSupportFeatures } from './device/DeviceSupportFeatures';
22
18
  export { default as deviceVerify } from './device/DeviceVerify';
23
19
  export { default as deviceWipe } from './device/DeviceWipe';
20
+ export { default as firmwareUpdate } from './FirmwareUpdate';
21
+ export { default as requestWebUsbDevice } from './RequestWebUsbDevice';
22
+
23
+ export { default as cipherKeyValue } from './CipherKeyValue';
24
+
25
+ export { default as btcGetAddress } from './btc/BTCGetAddress';
26
+ export { default as btcGetPublicKey } from './btc/BTCGetPublicKey';
27
+ export { default as btcSignMessage } from './btc/BTCSignMessage';
28
+ export { default as btcSignTransaction } from './btc/BTCSignTransaction';
29
+ export { default as btcVerifyMessage } from './btc/BTCVerifyMessage';
30
+
31
+ export { default as confluxGetAddress } from './conflux/ConfluxGetAddress';
32
+ export { default as confluxSignMessage } from './conflux/ConfluxSignMessage';
33
+ export { default as confluxSignMessageCIP23 } from './conflux/ConfluxSignMessageCIP23';
34
+ export { default as confluxSignTransaction } from './conflux/ConfluxSignTransaction';
35
+
24
36
  export { default as evmGetAddress } from './evm/EVMGetAddress';
25
37
  export { default as evmGetPublicKey } from './evm/EVMGetPublicKey';
26
38
  export { default as evmSignMessage } from './evm/EVMSignMessage';
@@ -28,6 +40,7 @@ export { default as evmSignMessageEIP712 } from './evm/EVMSignMessageEIP712';
28
40
  export { default as evmSignTransaction } from './evm/EVMSignTransaction';
29
41
  export { default as evmSignTypedData } from './evm/EVMSignTypedData';
30
42
  export { default as evmVerifyMessage } from './evm/EVMVerifyMessage';
43
+
31
44
  export { default as starcoinGetAddress } from './starcoin/StarcoinGetAddress';
32
45
  export { default as starcoinGetPublicKey } from './starcoin/StarcoinGetPublicKey';
33
46
  export { default as starcoinSignMessage } from './starcoin/StarcoinSignMessage';
@@ -43,9 +56,12 @@ export { default as solSignTransaction } from './solana/SolSignTransaction';
43
56
  export { default as stellarGetAddress } from './stellar/StellarGetAddress';
44
57
  export { default as stellarSignTransaction } from './stellar/StellarSignTransaction';
45
58
 
46
- export { default as firmwareUpdate } from './FirmwareUpdate';
59
+ export { default as tronGetAddress } from './tron/TronGetAddress';
60
+ export { default as tronSignMessage } from './tron/TronSignMessage';
61
+ export { default as tronSignTransaction } from './tron/TronSignTransaction';
47
62
 
48
- export { default as requestWebUsbDevice } from './RequestWebUsbDevice';
63
+ export { default as nearGetAddress } from './near/NearGetAddress';
64
+ export { default as nearSignTransaction } from './near/NearSignTransaction';
49
65
 
50
- export { default as getPassphraseState } from './GetPassphraseState';
51
- export { default as getLogs } from './GetLogs';
66
+ export { default as aptosGetAddress } from './aptos/AptosGetAddress';
67
+ export { default as aptosSignTransaction } from './aptos/AptosSignTransaction';
@@ -0,0 +1,68 @@
1
+ import { NearGetAddress as HardwareNearGetAddress } from '@onekeyfe/hd-transport';
2
+ import { UI_REQUEST } from '../../constants/ui-request';
3
+ import { serializedPath, validatePath } from '../helpers/pathUtils';
4
+ import { BaseMethod } from '../BaseMethod';
5
+ import { validateParams } from '../helpers/paramsValidator';
6
+ import { NearGetAddressParams, NearAddress } from '../../types';
7
+
8
+ export default class NearGetAddress extends BaseMethod<HardwareNearGetAddress[]> {
9
+ hasBundle = false;
10
+
11
+ init() {
12
+ this.checkDeviceId = true;
13
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
14
+
15
+ this.hasBundle = !!this.payload?.bundle;
16
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
17
+
18
+ // check payload
19
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
20
+
21
+ // init params
22
+ this.params = [];
23
+ payload.bundle.forEach((batch: NearGetAddressParams) => {
24
+ const addressN = validatePath(batch.path, 3);
25
+
26
+ validateParams(batch, [
27
+ { name: 'path', required: true },
28
+ { name: 'showOnOneKey', type: 'boolean' },
29
+ ]);
30
+
31
+ const showOnOneKey = batch.showOnOneKey ?? true;
32
+
33
+ this.params.push({
34
+ address_n: addressN,
35
+ show_display: showOnOneKey,
36
+ });
37
+ });
38
+ }
39
+
40
+ getVersionRange() {
41
+ return {
42
+ model_mini: {
43
+ min: '2.4.0',
44
+ },
45
+ };
46
+ }
47
+
48
+ async run() {
49
+ const responses: NearAddress[] = [];
50
+
51
+ for (let i = 0; i < this.params.length; i++) {
52
+ const param = this.params[i];
53
+
54
+ const res = await this.device.commands.typedCall('NearGetAddress', 'NearAddress', {
55
+ ...param,
56
+ });
57
+
58
+ const { address } = res.message;
59
+
60
+ responses.push({
61
+ path: serializedPath(param.address_n),
62
+ address,
63
+ });
64
+ }
65
+
66
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
67
+ }
68
+ }
@@ -0,0 +1,45 @@
1
+ import { NearSignTx as HardwareNearSignTx } from '@onekeyfe/hd-transport';
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 NearSignTransaction extends BaseMethod<HardwareNearSignTx> {
9
+ init() {
10
+ this.checkDeviceId = true;
11
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
12
+
13
+ // check payload
14
+ validateParams(this.payload, [
15
+ { name: 'path', required: true },
16
+ { name: 'rawTx', type: 'hexString', required: true },
17
+ ]);
18
+
19
+ const { path, rawTx } = this.payload;
20
+
21
+ const addressN = validatePath(path, 3);
22
+
23
+ // init params
24
+ this.params = {
25
+ address_n: addressN,
26
+ raw_tx: formatAnyHex(rawTx),
27
+ };
28
+ }
29
+
30
+ getVersionRange() {
31
+ return {
32
+ model_mini: {
33
+ min: '2.4.0',
34
+ },
35
+ };
36
+ }
37
+
38
+ async run() {
39
+ const res = await this.device.commands.typedCall('NearSignTx', 'NearSignedTx', {
40
+ ...this.params,
41
+ });
42
+
43
+ return Promise.resolve(res.message);
44
+ }
45
+ }
@@ -43,12 +43,10 @@ export default class SolGetAddress extends BaseMethod<SolanaGetAddress[]> {
43
43
  for (let i = 0; i < this.params.length; i++) {
44
44
  const param = this.params[i];
45
45
 
46
- // @ts-expect-error
47
46
  const res = await this.device.commands.typedCall('SolanaGetAddress', 'SolanaAddress', {
48
47
  ...param,
49
48
  });
50
49
 
51
- // @ts-expect-error
52
50
  const { address } = res.message;
53
51
 
54
52
  responses.push({
@@ -53,12 +53,10 @@ export default class SolSignTransaction extends BaseMethod<HardwareSolanaSignTx[
53
53
  for (let i = 0; i < this.params.length; i++) {
54
54
  const param = this.params[i];
55
55
 
56
- // @ts-expect-error
57
56
  const res = await this.device.commands.typedCall('SolanaSignTx', 'SolanaSignedTx', {
58
57
  ...param,
59
58
  });
60
59
 
61
- // @ts-expect-error
62
60
  const { signature } = res.message;
63
61
 
64
62
  responses.push({