@onekeyfe/hd-core 0.0.7 → 0.0.10

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 (87) hide show
  1. package/dist/api/BaseMethod.d.ts +2 -0
  2. package/dist/api/BaseMethod.d.ts.map +1 -1
  3. package/dist/api/CipherKeyValue.d.ts +9 -0
  4. package/dist/api/CipherKeyValue.d.ts.map +1 -0
  5. package/dist/api/device/DeviceRebootToBootloader.d.ts +8 -0
  6. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
  7. package/dist/api/evm/EVMSignMessageEIP712.d.ts +5 -0
  8. package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
  9. package/dist/api/evm/EVMSignTransaction.d.ts +5 -0
  10. package/dist/api/evm/EVMSignTransaction.d.ts.map +1 -1
  11. package/dist/api/evm/EVMSignTypedData.d.ts +7 -1
  12. package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
  13. package/dist/api/helpers/hexUtils.d.ts.map +1 -1
  14. package/dist/api/index.d.ts +7 -0
  15. package/dist/api/index.d.ts.map +1 -1
  16. package/dist/api/nem/NEMGetAddress.d.ts +9 -0
  17. package/dist/api/nem/NEMGetAddress.d.ts.map +1 -0
  18. package/dist/api/nem/NEMSignTransaction.d.ts +20 -0
  19. package/dist/api/nem/NEMSignTransaction.d.ts.map +1 -0
  20. package/dist/api/solana/SolGetAddress.d.ts +9 -0
  21. package/dist/api/solana/SolGetAddress.d.ts.map +1 -0
  22. package/dist/api/solana/SolSignTransaction.d.ts +17 -0
  23. package/dist/api/solana/SolSignTransaction.d.ts.map +1 -0
  24. package/dist/api/stellar/StellarGetAddress.d.ts +9 -0
  25. package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -0
  26. package/dist/api/stellar/StellarSignTransaction.d.ts +335 -0
  27. package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -0
  28. package/dist/core/index.d.ts.map +1 -1
  29. package/dist/data/version.d.ts +1 -1
  30. package/dist/data/version.d.ts.map +1 -1
  31. package/dist/events/ui-request.d.ts +1 -1
  32. package/dist/events/ui-request.d.ts.map +1 -1
  33. package/dist/index.d.ts +299 -3
  34. package/dist/index.js +729 -20
  35. package/dist/inject.d.ts.map +1 -1
  36. package/dist/types/api/cipherKeyValue.d.ts +19 -0
  37. package/dist/types/api/cipherKeyValue.d.ts.map +1 -0
  38. package/dist/types/api/export.d.ts +7 -0
  39. package/dist/types/api/export.d.ts.map +1 -1
  40. package/dist/types/api/index.d.ts +14 -0
  41. package/dist/types/api/index.d.ts.map +1 -1
  42. package/dist/types/api/nemGetAddress.d.ts +15 -0
  43. package/dist/types/api/nemGetAddress.d.ts.map +1 -0
  44. package/dist/types/api/nemSignTransaction.d.ts +93 -0
  45. package/dist/types/api/nemSignTransaction.d.ts.map +1 -0
  46. package/dist/types/api/solGetAddress.d.ts +14 -0
  47. package/dist/types/api/solGetAddress.d.ts.map +1 -0
  48. package/dist/types/api/solSignTransaction.d.ts +14 -0
  49. package/dist/types/api/solSignTransaction.d.ts.map +1 -0
  50. package/dist/types/api/stellarGetAddress.d.ts +14 -0
  51. package/dist/types/api/stellarGetAddress.d.ts.map +1 -0
  52. package/dist/types/api/stellarSignTransaction.d.ts +130 -0
  53. package/dist/types/api/stellarSignTransaction.d.ts.map +1 -0
  54. package/dist/types/device.d.ts +7 -0
  55. package/dist/types/device.d.ts.map +1 -1
  56. package/dist/utils/deviceFeaturesUtils.d.ts +49 -2
  57. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  58. package/package.json +3 -3
  59. package/src/api/BaseMethod.ts +5 -0
  60. package/src/api/CipherKeyValue.ts +66 -0
  61. package/src/api/device/DeviceRebootToBootloader.ts +11 -0
  62. package/src/api/evm/EVMSignMessageEIP712.ts +8 -0
  63. package/src/api/evm/EVMSignTransaction.ts +15 -0
  64. package/src/api/evm/EVMSignTypedData.ts +55 -15
  65. package/src/api/helpers/hexUtils.ts +0 -1
  66. package/src/api/index.ts +10 -0
  67. package/src/api/nem/NEMGetAddress.ts +61 -0
  68. package/src/api/nem/NEMSignTransaction.ts +246 -0
  69. package/src/api/solana/SolGetAddress.ts +59 -0
  70. package/src/api/solana/SolSignTransaction.ts +69 -0
  71. package/src/api/stellar/StellarGetAddress.ts +59 -0
  72. package/src/api/stellar/StellarSignTransaction.ts +213 -0
  73. package/src/core/index.ts +50 -6
  74. package/src/data/version.ts +1 -1
  75. package/src/events/ui-request.ts +1 -1
  76. package/src/inject.ts +15 -0
  77. package/src/types/api/cipherKeyValue.ts +26 -0
  78. package/src/types/api/export.ts +27 -0
  79. package/src/types/api/index.ts +18 -0
  80. package/src/types/api/nemGetAddress.ts +22 -0
  81. package/src/types/api/nemSignTransaction.ts +117 -0
  82. package/src/types/api/solGetAddress.ts +21 -0
  83. package/src/types/api/solSignTransaction.ts +21 -0
  84. package/src/types/api/stellarGetAddress.ts +21 -0
  85. package/src/types/api/stellarSignTransaction.ts +153 -0
  86. package/src/types/device.ts +8 -0
  87. package/src/utils/deviceFeaturesUtils.ts +16 -2
@@ -5,6 +5,17 @@ import { BaseMethod } from '../BaseMethod';
5
5
  export default class DeviceRebootToBootloader extends BaseMethod<RebootToBootloader> {
6
6
  init() {}
7
7
 
8
+ getVersionRange() {
9
+ return {
10
+ classic: {
11
+ min: '2.1.11',
12
+ },
13
+ mini: {
14
+ min: '2.1.11',
15
+ },
16
+ };
17
+ }
18
+
8
19
  async run() {
9
20
  const res = await this.device.commands.typedCall('RebootToBootloader', 'Success');
10
21
 
@@ -26,6 +26,14 @@ export default class EVMSignMessageEIP712 extends BaseMethod<EthereumSignMessage
26
26
  };
27
27
  }
28
28
 
29
+ getVersionRange() {
30
+ return {
31
+ model_mini: {
32
+ min: '2.1.9',
33
+ },
34
+ };
35
+ }
36
+
29
37
  async run() {
30
38
  const res = await this.device.commands.typedCall(
31
39
  'EthereumSignMessageEIP712',
@@ -178,6 +178,21 @@ export default class EVMSignTransaction extends BaseMethod {
178
178
  return this.processTxRequest(response.message, rest, chainId);
179
179
  };
180
180
 
181
+ getVersionRange() {
182
+ if (this.isEIP1559) {
183
+ return {
184
+ model_mini: {
185
+ min: '2.1.11',
186
+ },
187
+ };
188
+ }
189
+ return {
190
+ model_mini: {
191
+ min: '1.0.0',
192
+ },
193
+ };
194
+ }
195
+
181
196
  async run() {
182
197
  const { addressN, isEIP1559, formattedTx } = this;
183
198
 
@@ -1,4 +1,6 @@
1
+ import semver from 'semver';
1
2
  import {
3
+ EthereumMessageSignature,
2
4
  EthereumTypedDataSignature,
3
5
  EthereumTypedDataStructAck,
4
6
  MessageKey,
@@ -14,6 +16,8 @@ import {
14
16
  EthereumSignTypedDataMessage,
15
17
  EthereumSignTypedDataTypes,
16
18
  } from '../../types/api/evmSignTypedData';
19
+ import { getDeviceFirmwareVersion, getDeviceType } from '../../utils/deviceFeaturesUtils';
20
+ import { TypedResponseMessage } from '../../device/DeviceCommands';
17
21
 
18
22
  export type EVMSignTypedDataParams = {
19
23
  addressN: number[];
@@ -23,14 +27,14 @@ export type EVMSignTypedDataParams = {
23
27
  messageHash?: string;
24
28
  };
25
29
 
26
- export default class EVMSignMessageEIP712 extends BaseMethod<EVMSignTypedDataParams> {
30
+ export default class EVMSignTypedData extends BaseMethod<EVMSignTypedDataParams> {
27
31
  init() {
28
32
  this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
29
33
 
30
34
  validateParams(this.payload, [
31
35
  { name: 'path', required: true },
32
- { name: 'metamaskV4Compat', type: 'boolean', required: true },
33
- { name: 'data', type: 'object', required: true },
36
+ { name: 'metamaskV4Compat', type: 'boolean' },
37
+ { name: 'data', type: 'object' },
34
38
  { name: 'domainHash', type: 'hexString' },
35
39
  { name: 'messageHash', type: 'hexString' },
36
40
  ]);
@@ -49,7 +53,7 @@ export default class EVMSignMessageEIP712 extends BaseMethod<EVMSignTypedDataPar
49
53
  this.params.domainHash = formatAnyHex(domainHash);
50
54
  if (messageHash) {
51
55
  this.params.messageHash = formatAnyHex(messageHash);
52
- } else if (!data.primaryType || data.primaryType !== 'EIP712Domain') {
56
+ } else if (!!data && (!data.primaryType || data.primaryType !== 'EIP712Domain')) {
53
57
  throw ERRORS.TypedError(
54
58
  'Method_InvalidParameter',
55
59
  'message_hash should only be empty when data.primaryType=EIP712Domain'
@@ -173,6 +177,28 @@ export default class EVMSignMessageEIP712 extends BaseMethod<EVMSignTypedDataPar
173
177
  // };
174
178
  // }
175
179
 
180
+ getVersionRange() {
181
+ return {
182
+ model_mini: {
183
+ min: '2.1.9',
184
+ },
185
+ };
186
+ }
187
+
188
+ supportSignTyped() {
189
+ const deviceType = getDeviceType(this.device.features);
190
+ if (deviceType === 'classic' || deviceType === 'mini') {
191
+ const currentVersion = getDeviceFirmwareVersion(this.device.features).join('.');
192
+ const supportSignTypedVersion = '2.2.0';
193
+
194
+ if (semver.lt(currentVersion, supportSignTypedVersion)) {
195
+ return false;
196
+ }
197
+ }
198
+
199
+ return true;
200
+ }
201
+
176
202
  async run() {
177
203
  if (!this.device.features) {
178
204
  throw ERRORS.TypedError(
@@ -184,23 +210,37 @@ export default class EVMSignMessageEIP712 extends BaseMethod<EVMSignTypedDataPar
184
210
  const { addressN } = this.params;
185
211
 
186
212
  // For Classic、Mini device we use EthereumSignTypedData
187
- if (this.device.features.model === '1') {
213
+ const deviceType = getDeviceType(this.device.features);
214
+ if (deviceType === 'classic' || deviceType === 'mini') {
188
215
  validateParams(this.params, [
189
216
  { name: 'domainHash', type: 'hexString', required: true },
190
- { name: 'messageHash', type: 'hexString' },
217
+ { name: 'messageHash', type: 'hexString', required: true },
191
218
  ]);
192
219
 
193
220
  const { domainHash, messageHash } = this.params;
194
221
 
195
- const response = await this.device.commands.typedCall(
196
- 'EthereumSignTypedHash',
197
- 'EthereumTypedDataSignature',
198
- {
199
- address_n: addressN,
200
- domain_separator_hash: domainHash ?? '',
201
- message_hash: messageHash,
202
- }
203
- );
222
+ let response;
223
+ if (this.supportSignTyped()) {
224
+ response = await this.device.commands.typedCall(
225
+ 'EthereumSignTypedHash',
226
+ 'EthereumTypedDataSignature',
227
+ {
228
+ address_n: addressN,
229
+ domain_separator_hash: domainHash ?? '',
230
+ message_hash: messageHash,
231
+ }
232
+ );
233
+ } else {
234
+ response = await this.device.commands.typedCall(
235
+ 'EthereumSignMessageEIP712',
236
+ 'EthereumMessageSignature',
237
+ {
238
+ address_n: addressN,
239
+ domain_hash: domainHash ?? '',
240
+ message_hash: messageHash ?? '',
241
+ }
242
+ );
243
+ }
204
244
 
205
245
  return Promise.resolve(response.message);
206
246
  }
@@ -44,7 +44,6 @@ export const formatAnyHex: (value: any) => any = value => {
44
44
  if (typeof value === 'object') {
45
45
  return modifyValues(value, value => formatAnyHex(value));
46
46
  }
47
- console.log('unexpected value', value);
48
47
 
49
48
  return value;
50
49
  };
package/src/api/index.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export { default as searchDevices } from './SearchDevices';
2
2
  export { default as getFeatures } from './GetFeatures';
3
+ export { default as cipherKeyValue } from './CipherKeyValue';
3
4
  export { default as btcGetAddress } from './btc/BTCGetAddress';
4
5
  export { default as btcGetPublicKey } from './btc/BTCGetPublicKey';
5
6
  export { default as btcSignMessage } from './btc/BTCSignMessage';
@@ -29,3 +30,12 @@ export { default as starcoinGetPublicKey } from './starcoin/StarcoinGetPublicKey
29
30
  export { default as starcoinSignMessage } from './starcoin/StarcoinSignMessage';
30
31
  export { default as starcoinSignTransaction } from './starcoin/StarcoinSignTransaction';
31
32
  export { default as starcoinVerifyMessage } from './starcoin/StarcoinVerifyMessage';
33
+
34
+ export { default as nemGetAddress } from './nem/NEMGetAddress';
35
+ export { default as nemSignTransaction } from './nem/NEMSignTransaction';
36
+
37
+ export { default as solGetAddress } from './solana/SolGetAddress';
38
+ export { default as solSignTransaction } from './solana/SolSignTransaction';
39
+
40
+ export { default as stellarGetAddress } from './stellar/StellarGetAddress';
41
+ export { default as stellarSignTransaction } from './stellar/StellarSignTransaction';
@@ -0,0 +1,61 @@
1
+ import { NEMGetAddress as HardwareNEMGetAddress } 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 { NEMAddress, NEMGetAddressParams } from '../../types';
7
+
8
+ const MAINNET = 0x68; // 104
9
+
10
+ export default class NEMGetAddress extends BaseMethod<HardwareNEMGetAddress[]> {
11
+ hasBundle = false;
12
+
13
+ init() {
14
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
15
+
16
+ this.hasBundle = !!this.payload?.bundle;
17
+ const payload = this.hasBundle ? this.payload : { bundle: [this.payload] };
18
+
19
+ // check payload
20
+ validateParams(payload, [{ name: 'bundle', type: 'array' }]);
21
+
22
+ // init params
23
+ this.params = [];
24
+ payload.bundle.forEach((batch: NEMGetAddressParams) => {
25
+ const addressN = validatePath(batch.path, 3);
26
+
27
+ validateParams(batch, [
28
+ { name: 'path', required: true },
29
+ { name: 'network', type: 'number' },
30
+ { name: 'showOnOneKey', type: 'boolean' },
31
+ ]);
32
+
33
+ const showOnOneKey = batch.showOnOneKey ?? true;
34
+
35
+ this.params.push({
36
+ address_n: addressN,
37
+ network: batch.network || MAINNET,
38
+ show_display: showOnOneKey,
39
+ });
40
+ });
41
+ }
42
+
43
+ async run() {
44
+ const responses: NEMAddress[] = [];
45
+
46
+ for (let i = 0; i < this.params.length; i++) {
47
+ const param = this.params[i];
48
+
49
+ const res = await this.device.commands.typedCall('NEMGetAddress', 'NEMAddress', {
50
+ ...param,
51
+ });
52
+
53
+ responses.push({
54
+ path: serializedPath(param.address_n),
55
+ ...res.message,
56
+ });
57
+ }
58
+
59
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
60
+ }
61
+ }
@@ -0,0 +1,246 @@
1
+ import {
2
+ NEMAggregateModification,
3
+ NEMImportanceTransfer,
4
+ NEMMosaicCreation,
5
+ NEMMosaicDefinition,
6
+ NEMMosaicSupplyChange,
7
+ NEMProvisionNamespace,
8
+ NEMSignTx,
9
+ NEMTransactionCommon,
10
+ NEMTransfer,
11
+ } from '@onekeyfe/hd-transport/src/types/messages';
12
+
13
+ import { UI_REQUEST } from '../../constants/ui-request';
14
+ import { validatePath } from '../helpers/pathUtils';
15
+ import { BaseMethod } from '../BaseMethod';
16
+ import { validateParams } from '../helpers/paramsValidator';
17
+ import {
18
+ NEMAggregateModificationTransaction,
19
+ NEMImportanceTransaction,
20
+ NEMMosaicCreationTransaction,
21
+ NEMProvisionNamespaceTransaction,
22
+ NEMSupplyChangeTransaction,
23
+ NEMTransaction,
24
+ NEMTransferTransaction,
25
+ } from '../../types';
26
+ import { ERRORS } from '../../constants';
27
+
28
+ const NEM_TRANSFER = 0x0101;
29
+ const NEM_COSIGNING = 0x0102;
30
+ const NEM_IMPORTANCE_TRANSFER = 0x0801;
31
+ const NEM_AGGREGATE_MODIFICATION = 0x1001;
32
+ const NEM_MULTISIG_SIGNATURE = 0x1002;
33
+ const NEM_MULTISIG = 0x1004;
34
+ const NEM_PROVISION_NAMESPACE = 0x2001;
35
+ const NEM_MOSAIC_CREATION = 0x4001;
36
+ const NEM_SUPPLY_CHANGE = 0x4002;
37
+
38
+ export default class NEMSignTransaction extends BaseMethod<NEMSignTx> {
39
+ NEM_MOSAIC_LEVY_TYPES: Record<number, string> = {
40
+ 1: 'MosaicLevy_Absolute',
41
+ 2: 'MosaicLevy_Percentile',
42
+ };
43
+
44
+ NEM_SUPPLY_CHANGE_TYPES: Record<number, string> = {
45
+ 1: 'SupplyChange_Increase',
46
+ 2: 'SupplyChange_Decrease',
47
+ };
48
+
49
+ NEM_AGGREGATE_MODIFICATION_TYPES: Record<number, string> = {
50
+ 1: 'CosignatoryModification_Add',
51
+ 2: 'CosignatoryModification_Delete',
52
+ };
53
+
54
+ NEM_IMPORTANCE_TRANSFER_MODES: Record<number, string> = {
55
+ 1: 'ImportanceTransfer_Activate',
56
+ 2: 'ImportanceTransfer_Deactivate',
57
+ };
58
+
59
+ getCommon = (tx: NEMTransaction, address_n?: number[]): NEMTransactionCommon => ({
60
+ address_n,
61
+ // eslint-disable-next-line no-bitwise
62
+ network: (tx.version >> 24) & 0xff,
63
+ timestamp: tx.timeStamp,
64
+ fee: tx.fee,
65
+ deadline: tx.deadline ?? 0,
66
+ signer: address_n ? undefined : tx.signer,
67
+ });
68
+
69
+ transferMessage = (tx: NEMTransferTransaction): NEMTransfer => {
70
+ const mosaics = tx.mosaics
71
+ ? tx.mosaics.map(mosaic => ({
72
+ namespace: mosaic.mosaicId.namespaceId,
73
+ mosaic: mosaic.mosaicId.name,
74
+ quantity: mosaic.quantity,
75
+ }))
76
+ : undefined;
77
+
78
+ return {
79
+ recipient: tx.recipient,
80
+ amount: tx.amount,
81
+ payload: tx.message ? tx.message.payload : undefined,
82
+ public_key: tx.message && tx.message.type === 0x02 ? tx.message.publicKey : undefined,
83
+ mosaics,
84
+ };
85
+ };
86
+
87
+ importanceTransferMessage = (tx: NEMImportanceTransaction): NEMImportanceTransfer => ({
88
+ // @ts-expect-error
89
+ mode: this.NEM_IMPORTANCE_TRANSFER_MODES[tx.importanceTransfer.mode],
90
+ public_key: tx.importanceTransfer.publicKey,
91
+ });
92
+
93
+ aggregateModificationMessage = (
94
+ tx: NEMAggregateModificationTransaction
95
+ ): NEMAggregateModification => {
96
+ const modifications = tx.modifications
97
+ ? tx.modifications.map(modification => ({
98
+ type: this.NEM_AGGREGATE_MODIFICATION_TYPES[modification.modificationType],
99
+ public_key: modification.cosignatoryAccount,
100
+ }))
101
+ : undefined;
102
+
103
+ return {
104
+ // @ts-expect-error
105
+ modifications,
106
+ relative_change: tx.minCosignatories.relativeChange,
107
+ };
108
+ };
109
+
110
+ provisionNamespaceMessage = (tx: NEMProvisionNamespaceTransaction): NEMProvisionNamespace => ({
111
+ namespace: tx.newPart ?? '',
112
+ parent: tx.parent || undefined,
113
+ sink: tx.rentalFeeSink ?? '',
114
+ fee: tx.rentalFee ?? 0,
115
+ });
116
+
117
+ mosaicCreationMessage = (tx: NEMMosaicCreationTransaction): NEMMosaicCreation => {
118
+ const { levy } = tx.mosaicDefinition;
119
+
120
+ const definition: NEMMosaicDefinition = {
121
+ namespace: tx.mosaicDefinition.id.namespaceId,
122
+ mosaic: tx.mosaicDefinition.id.name,
123
+ // @ts-expect-error
124
+ levy: levy && levy.type ? this.NEM_MOSAIC_LEVY_TYPES[levy.type] : undefined,
125
+ fee: levy && levy.fee,
126
+ levy_address: levy && levy.recipient,
127
+ levy_namespace: levy && levy.mosaicId && levy.mosaicId.namespaceId,
128
+ levy_mosaic: levy && levy.mosaicId && levy.mosaicId.name,
129
+ description: tx.mosaicDefinition.description,
130
+ };
131
+
132
+ const { properties } = tx.mosaicDefinition;
133
+ if (Array.isArray(properties)) {
134
+ properties.forEach(property => {
135
+ const { name, value } = property;
136
+ switch (name) {
137
+ case 'divisibility':
138
+ definition.divisibility = parseInt(value);
139
+ break;
140
+
141
+ case 'initialSupply':
142
+ definition.supply = parseInt(value);
143
+ break;
144
+
145
+ case 'supplyMutable':
146
+ definition.mutable_supply = value === 'true';
147
+ break;
148
+
149
+ case 'transferable':
150
+ definition.transferable = value === 'true';
151
+ break;
152
+ default:
153
+ }
154
+ });
155
+ }
156
+
157
+ return {
158
+ definition,
159
+ sink: tx.creationFeeSink ?? '',
160
+ fee: tx.creationFee ?? 0,
161
+ };
162
+ };
163
+
164
+ supplyChangeMessage = (tx: NEMSupplyChangeTransaction): NEMMosaicSupplyChange => ({
165
+ namespace: tx.mosaicId.namespaceId,
166
+ mosaic: tx.mosaicId.name,
167
+ // @ts-expect-error
168
+ type: this.NEM_SUPPLY_CHANGE_TYPES[tx.supplyType],
169
+ delta: tx.delta ?? 0,
170
+ });
171
+
172
+ parseTx = (tx: NEMTransaction, address_n: number[]) => {
173
+ let transaction = tx;
174
+ const message: NEMSignTx = {
175
+ transaction: this.getCommon(tx, address_n),
176
+ transfer: undefined,
177
+ importance_transfer: undefined,
178
+ aggregate_modification: undefined,
179
+ provision_namespace: undefined,
180
+ mosaic_creation: undefined,
181
+ supply_change: undefined,
182
+ };
183
+
184
+ if (
185
+ tx.type === NEM_COSIGNING ||
186
+ tx.type === NEM_MULTISIG ||
187
+ tx.type === NEM_MULTISIG_SIGNATURE
188
+ ) {
189
+ message.cosigning = tx.type === NEM_COSIGNING || tx.type === NEM_MULTISIG_SIGNATURE;
190
+ transaction = tx.otherTrans;
191
+ message.multisig = this.getCommon(transaction);
192
+ }
193
+
194
+ switch (transaction.type) {
195
+ case NEM_TRANSFER:
196
+ message.transfer = this.transferMessage(transaction);
197
+ break;
198
+
199
+ case NEM_IMPORTANCE_TRANSFER:
200
+ message.importance_transfer = this.importanceTransferMessage(transaction);
201
+ break;
202
+
203
+ case NEM_AGGREGATE_MODIFICATION:
204
+ message.aggregate_modification = this.aggregateModificationMessage(transaction);
205
+ break;
206
+
207
+ case NEM_PROVISION_NAMESPACE:
208
+ message.provision_namespace = this.provisionNamespaceMessage(transaction);
209
+ break;
210
+
211
+ case NEM_MOSAIC_CREATION:
212
+ message.mosaic_creation = this.mosaicCreationMessage(transaction);
213
+ break;
214
+
215
+ case NEM_SUPPLY_CHANGE:
216
+ message.supply_change = this.supplyChangeMessage(transaction);
217
+ break;
218
+
219
+ default:
220
+ throw ERRORS.TypedError('Method_InvalidParameter', 'Unknown transaction type');
221
+ }
222
+
223
+ return message;
224
+ };
225
+
226
+ init() {
227
+ this.allowDeviceMode = [...this.allowDeviceMode, UI_REQUEST.INITIALIZE];
228
+
229
+ validateParams(this.payload, [
230
+ { name: 'path', required: true },
231
+ { name: 'transaction', type: 'object', required: true },
232
+ ]);
233
+ const { path, transaction } = this.payload;
234
+ const addressN = validatePath(path, 3);
235
+
236
+ this.params = this.parseTx(transaction, addressN);
237
+ }
238
+
239
+ async run() {
240
+ const res = await this.device.commands.typedCall('NEMSignTx', 'NEMSignedTx', {
241
+ ...this.params,
242
+ });
243
+
244
+ return Promise.resolve(res);
245
+ }
246
+ }
@@ -0,0 +1,59 @@
1
+ import { SolanaGetAddress } from '@onekeyfe/hd-transport/src/types/messages';
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 { SolanaAddress, SolanaGetAddressParams } from '../../types';
7
+
8
+ export default class SolGetAddress extends BaseMethod<SolanaGetAddress[]> {
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: SolanaGetAddressParams) => {
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: SolanaAddress[] = [];
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('SolanaGetAddress', 'SolanaAddress', {
46
+ ...param,
47
+ });
48
+
49
+ const { address } = res.message;
50
+
51
+ responses.push({
52
+ path: serializedPath(param.address_n),
53
+ address,
54
+ });
55
+ }
56
+
57
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
58
+ }
59
+ }
@@ -0,0 +1,69 @@
1
+ import { SolanaSignTx as HardwareSolanaSignTx } from '@onekeyfe/hd-transport/src/types/messages';
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 { SolanaSignedTx, SolanaSignTransactionParams } from '../../types';
7
+ import { formatAnyHex } from '../helpers/hexUtils';
8
+
9
+ export default class SolSignTransaction extends BaseMethod<HardwareSolanaSignTx[]> {
10
+ hasBundle = false;
11
+
12
+ init() {
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: SolanaSignTransactionParams) => {
24
+ const addressN = validatePath(batch.path, 3);
25
+
26
+ validateParams(batch, [
27
+ { name: 'path', required: true },
28
+ { name: 'rawTx', type: 'hexString', required: true },
29
+ ]);
30
+
31
+ this.params.push({
32
+ address_n: addressN,
33
+ raw_tx: formatAnyHex(batch.rawTx),
34
+ });
35
+ });
36
+ }
37
+
38
+ getVersionRange() {
39
+ return {
40
+ classic: {
41
+ min: '2.1.9',
42
+ },
43
+ mini: {
44
+ min: '2.1.9',
45
+ },
46
+ };
47
+ }
48
+
49
+ async run() {
50
+ const responses: SolanaSignedTx[] = [];
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('SolanaSignTx', 'SolanaSignedTx', {
56
+ ...param,
57
+ });
58
+
59
+ const { signature } = res.message;
60
+
61
+ responses.push({
62
+ path: serializedPath(param.address_n),
63
+ signature,
64
+ });
65
+ }
66
+
67
+ return Promise.resolve(this.hasBundle ? responses : responses[0]);
68
+ }
69
+ }