@onekeyfe/hd-core 0.0.6 → 0.0.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 (93) 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/SearchDevices.d.ts +1 -1
  6. package/dist/api/SearchDevices.d.ts.map +1 -1
  7. package/dist/api/device/DeviceRebootToBootloader.d.ts +8 -0
  8. package/dist/api/device/DeviceRebootToBootloader.d.ts.map +1 -1
  9. package/dist/api/evm/EVMSignMessageEIP712.d.ts +5 -0
  10. package/dist/api/evm/EVMSignMessageEIP712.d.ts.map +1 -1
  11. package/dist/api/evm/EVMSignTransaction.d.ts +5 -0
  12. package/dist/api/evm/EVMSignTransaction.d.ts.map +1 -1
  13. package/dist/api/evm/EVMSignTypedData.d.ts +7 -1
  14. package/dist/api/evm/EVMSignTypedData.d.ts.map +1 -1
  15. package/dist/api/helpers/hexUtils.d.ts.map +1 -1
  16. package/dist/api/index.d.ts +7 -0
  17. package/dist/api/index.d.ts.map +1 -1
  18. package/dist/api/nem/NEMGetAddress.d.ts +9 -0
  19. package/dist/api/nem/NEMGetAddress.d.ts.map +1 -0
  20. package/dist/api/nem/NEMSignTransaction.d.ts +20 -0
  21. package/dist/api/nem/NEMSignTransaction.d.ts.map +1 -0
  22. package/dist/api/solana/SolGetAddress.d.ts +9 -0
  23. package/dist/api/solana/SolGetAddress.d.ts.map +1 -0
  24. package/dist/api/solana/SolSignTransaction.d.ts +17 -0
  25. package/dist/api/solana/SolSignTransaction.d.ts.map +1 -0
  26. package/dist/api/stellar/StellarGetAddress.d.ts +9 -0
  27. package/dist/api/stellar/StellarGetAddress.d.ts.map +1 -0
  28. package/dist/api/stellar/StellarSignTransaction.d.ts +335 -0
  29. package/dist/api/stellar/StellarSignTransaction.d.ts.map +1 -0
  30. package/dist/core/index.d.ts.map +1 -1
  31. package/dist/data/version.d.ts +1 -1
  32. package/dist/data/version.d.ts.map +1 -1
  33. package/dist/events/ui-request.d.ts +1 -1
  34. package/dist/events/ui-request.d.ts.map +1 -1
  35. package/dist/index.d.ts +301 -3
  36. package/dist/index.js +755 -21
  37. package/dist/inject.d.ts.map +1 -1
  38. package/dist/types/api/cipherKeyValue.d.ts +19 -0
  39. package/dist/types/api/cipherKeyValue.d.ts.map +1 -0
  40. package/dist/types/api/export.d.ts +7 -0
  41. package/dist/types/api/export.d.ts.map +1 -1
  42. package/dist/types/api/index.d.ts +14 -0
  43. package/dist/types/api/index.d.ts.map +1 -1
  44. package/dist/types/api/nemGetAddress.d.ts +15 -0
  45. package/dist/types/api/nemGetAddress.d.ts.map +1 -0
  46. package/dist/types/api/nemSignTransaction.d.ts +93 -0
  47. package/dist/types/api/nemSignTransaction.d.ts.map +1 -0
  48. package/dist/types/api/solGetAddress.d.ts +14 -0
  49. package/dist/types/api/solGetAddress.d.ts.map +1 -0
  50. package/dist/types/api/solSignTransaction.d.ts +14 -0
  51. package/dist/types/api/solSignTransaction.d.ts.map +1 -0
  52. package/dist/types/api/stellarGetAddress.d.ts +14 -0
  53. package/dist/types/api/stellarGetAddress.d.ts.map +1 -0
  54. package/dist/types/api/stellarSignTransaction.d.ts +130 -0
  55. package/dist/types/api/stellarSignTransaction.d.ts.map +1 -0
  56. package/dist/types/device.d.ts +7 -0
  57. package/dist/types/device.d.ts.map +1 -1
  58. package/dist/utils/deviceFeaturesUtils.d.ts +51 -2
  59. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  60. package/dist/utils/index.d.ts +1 -1
  61. package/dist/utils/index.d.ts.map +1 -1
  62. package/package.json +3 -3
  63. package/src/api/BaseMethod.ts +5 -0
  64. package/src/api/CipherKeyValue.ts +66 -0
  65. package/src/api/SearchDevices.ts +2 -2
  66. package/src/api/device/DeviceRebootToBootloader.ts +11 -0
  67. package/src/api/evm/EVMSignMessageEIP712.ts +8 -0
  68. package/src/api/evm/EVMSignTransaction.ts +15 -0
  69. package/src/api/evm/EVMSignTypedData.ts +55 -15
  70. package/src/api/helpers/hexUtils.ts +0 -1
  71. package/src/api/index.ts +10 -0
  72. package/src/api/nem/NEMGetAddress.ts +61 -0
  73. package/src/api/nem/NEMSignTransaction.ts +246 -0
  74. package/src/api/solana/SolGetAddress.ts +59 -0
  75. package/src/api/solana/SolSignTransaction.ts +69 -0
  76. package/src/api/stellar/StellarGetAddress.ts +59 -0
  77. package/src/api/stellar/StellarSignTransaction.ts +213 -0
  78. package/src/core/index.ts +50 -6
  79. package/src/data/version.ts +1 -1
  80. package/src/events/ui-request.ts +1 -1
  81. package/src/inject.ts +15 -0
  82. package/src/types/api/cipherKeyValue.ts +26 -0
  83. package/src/types/api/export.ts +27 -0
  84. package/src/types/api/index.ts +18 -0
  85. package/src/types/api/nemGetAddress.ts +22 -0
  86. package/src/types/api/nemSignTransaction.ts +117 -0
  87. package/src/types/api/solGetAddress.ts +21 -0
  88. package/src/types/api/solSignTransaction.ts +21 -0
  89. package/src/types/api/stellarGetAddress.ts +21 -0
  90. package/src/types/api/stellarSignTransaction.ts +153 -0
  91. package/src/types/device.ts +8 -0
  92. package/src/utils/deviceFeaturesUtils.ts +34 -2
  93. package/src/utils/index.ts +7 -1
@@ -0,0 +1,117 @@
1
+ import { NEMSignedTx } from '@onekeyfe/hd-transport/src/types/messages';
2
+ import type { CommonParams, Response } from '../params';
3
+
4
+ type MosaicID = {
5
+ namespaceId: string;
6
+ name: string;
7
+ };
8
+
9
+ type MosaicDefinition = {
10
+ levy?: {
11
+ type?: number;
12
+ fee?: number;
13
+ recipient?: string;
14
+ mosaicId?: MosaicID;
15
+ };
16
+ id: MosaicID;
17
+ description: string;
18
+ properties?: Array<{
19
+ name: 'divisibility' | 'initialSupply' | 'supplyMutable' | 'transferable';
20
+ value: string;
21
+ }>;
22
+ };
23
+
24
+ export type NEMMosaic = {
25
+ mosaicId: MosaicID;
26
+ quantity: number;
27
+ };
28
+
29
+ type Modification = {
30
+ modificationType: number;
31
+ cosignatoryAccount: string;
32
+ };
33
+
34
+ type Message = {
35
+ payload?: string;
36
+ type?: number;
37
+ publicKey?: string;
38
+ };
39
+
40
+ type TransactionCommon = {
41
+ version: number;
42
+ timeStamp: number;
43
+ fee: number;
44
+ deadline?: number;
45
+ signer?: string;
46
+ };
47
+
48
+ export type NEMTransferTransaction = TransactionCommon & {
49
+ type: 0x0101;
50
+ recipient: string;
51
+ amount: number | string;
52
+ mosaics?: NEMMosaic[];
53
+ message?: Message;
54
+ };
55
+
56
+ export type NEMImportanceTransaction = TransactionCommon & {
57
+ type: 0x0801;
58
+ importanceTransfer: {
59
+ mode: number;
60
+ publicKey: string;
61
+ };
62
+ };
63
+
64
+ export type NEMAggregateModificationTransaction = TransactionCommon & {
65
+ type: 0x1001;
66
+ modifications?: Modification[];
67
+ minCosignatories: {
68
+ relativeChange: number;
69
+ };
70
+ };
71
+
72
+ export type NEMProvisionNamespaceTransaction = TransactionCommon & {
73
+ type: 0x2001;
74
+ newPart?: string;
75
+ parent?: string;
76
+ rentalFeeSink?: string;
77
+ rentalFee?: number;
78
+ };
79
+
80
+ export type NEMMosaicCreationTransaction = TransactionCommon & {
81
+ type: 0x4001;
82
+ mosaicDefinition: MosaicDefinition;
83
+ creationFeeSink?: string;
84
+ creationFee?: number;
85
+ };
86
+
87
+ export type NEMSupplyChangeTransaction = TransactionCommon & {
88
+ type: 0x4002;
89
+ mosaicId: MosaicID;
90
+ supplyType: number;
91
+ delta?: number;
92
+ };
93
+
94
+ type Transaction =
95
+ | NEMTransferTransaction
96
+ | NEMImportanceTransaction
97
+ | NEMAggregateModificationTransaction
98
+ | NEMProvisionNamespaceTransaction
99
+ | NEMMosaicCreationTransaction
100
+ | NEMSupplyChangeTransaction;
101
+
102
+ export type NEMMultisigTransaction = TransactionCommon & {
103
+ type: 0x0102 | 0x1002 | 0x1004;
104
+ otherTrans: Transaction;
105
+ };
106
+
107
+ export type NEMTransaction = Transaction | NEMMultisigTransaction;
108
+
109
+ export type NEMSignTransactionParams = {
110
+ path: string | number[];
111
+ transaction: NEMTransaction;
112
+ };
113
+
114
+ export declare function nemSignTransaction(
115
+ connectId: string,
116
+ params: CommonParams & NEMSignTransactionParams
117
+ ): Response<NEMSignedTx>;
@@ -0,0 +1,21 @@
1
+ import { SolanaAddress as HardwareSolanaAddress } from '@onekeyfe/hd-transport/src/types/messages';
2
+ import type { CommonParams, Response } from '../params';
3
+
4
+ export type SolanaAddress = {
5
+ path: string;
6
+ } & HardwareSolanaAddress;
7
+
8
+ export type SolanaGetAddressParams = {
9
+ path: string | number[];
10
+ showOnOneKey?: boolean;
11
+ };
12
+
13
+ export declare function solGetAddress(
14
+ connectId: string,
15
+ params: CommonParams & SolanaGetAddressParams
16
+ ): Response<SolanaAddress>;
17
+
18
+ export declare function solGetAddress(
19
+ connectId: string,
20
+ params: CommonParams & { bundle?: SolanaGetAddressParams[] }
21
+ ): Response<Array<SolanaAddress>>;
@@ -0,0 +1,21 @@
1
+ import { SolanaSignedTx as HardwareSolanaSignedTx } from '@onekeyfe/hd-transport/src/types/messages';
2
+ import type { CommonParams, Response } from '../params';
3
+
4
+ export type SolanaSignedTx = {
5
+ path: string;
6
+ } & HardwareSolanaSignedTx;
7
+
8
+ export type SolanaSignTransactionParams = {
9
+ path: string | number[];
10
+ rawTx?: string;
11
+ };
12
+
13
+ export declare function solSignTransaction(
14
+ connectId: string,
15
+ params: CommonParams & SolanaSignTransactionParams
16
+ ): Response<SolanaSignedTx>;
17
+
18
+ export declare function solSignTransaction(
19
+ connectId: string,
20
+ params: CommonParams & { bundle?: SolanaSignTransactionParams[] }
21
+ ): Response<Array<SolanaSignedTx>>;
@@ -0,0 +1,21 @@
1
+ import { StellarAddress as HardwareStellarAddress } from '@onekeyfe/hd-transport/src/types/messages';
2
+ import type { CommonParams, Response } from '../params';
3
+
4
+ export type StellarAddress = {
5
+ path: string;
6
+ } & HardwareStellarAddress;
7
+
8
+ export type StellarGetAddressParams = {
9
+ path: string | number[];
10
+ showOnOneKey?: boolean;
11
+ };
12
+
13
+ export declare function stellarGetAddress(
14
+ connectId: string,
15
+ params: CommonParams & StellarGetAddressParams
16
+ ): Response<StellarAddress>;
17
+
18
+ export declare function stellarGetAddress(
19
+ connectId: string,
20
+ params: CommonParams & { bundle?: StellarGetAddressParams[] }
21
+ ): Response<Array<StellarAddress>>;
@@ -0,0 +1,153 @@
1
+ import { StellarSignedTx } from '@onekeyfe/hd-transport/src/types/messages';
2
+ import { CommonParams, Response } from '../params';
3
+
4
+ export type StellarAsset = {
5
+ type: 0 | 1 | 2; // 0: native, 1: credit_alphanum4, 2: credit_alphanum12
6
+ code: string;
7
+ issuer?: string;
8
+ };
9
+
10
+ type StellarCreateAccountOperation = {
11
+ type: 'createAccount';
12
+ source?: string;
13
+ destination: string;
14
+ startingBalance: string;
15
+ };
16
+
17
+ type StellarPaymentOperation = {
18
+ type: 'payment';
19
+ source?: string;
20
+ destination: string;
21
+ asset?: StellarAsset | typeof undefined;
22
+ amount: string;
23
+ };
24
+
25
+ type StellarPathPaymentOperation = {
26
+ type: 'pathPayment';
27
+ source?: string;
28
+ sendAsset: StellarAsset;
29
+ sendMax: string;
30
+ destination: string;
31
+ destAsset: StellarAsset;
32
+ destAmount: string;
33
+ path?: StellarAsset[];
34
+ };
35
+
36
+ type StellarPassiveOfferOperation = {
37
+ type: 'createPassiveOffer';
38
+ source?: string;
39
+ buying: StellarAsset;
40
+ selling: StellarAsset;
41
+ amount: string;
42
+ price: { n: number; d: number };
43
+ };
44
+
45
+ type StellarManageOfferOperation = {
46
+ type: 'manageOffer';
47
+ source?: string;
48
+ buying: StellarAsset;
49
+ selling: StellarAsset;
50
+ amount: string;
51
+ offerId?: string;
52
+ price: { n: number; d: number };
53
+ };
54
+
55
+ type StellarSetOptionsOperation = {
56
+ type: 'setOptions';
57
+ source?: string;
58
+ signer?: {
59
+ type: 0 | 1 | 2;
60
+ key: string | Buffer;
61
+ weight?: number;
62
+ };
63
+ inflationDest?: string;
64
+ clearFlags?: number;
65
+ setFlags?: number;
66
+ masterWeight?: number | string;
67
+ lowThreshold?: number | string;
68
+ medThreshold?: number | string;
69
+ highThreshold?: number | string;
70
+ homeDomain?: string;
71
+ };
72
+
73
+ type StellarChangeTrustOperation = {
74
+ type: 'changeTrust';
75
+ source?: string;
76
+ line: StellarAsset;
77
+ limit?: string;
78
+ };
79
+
80
+ type StellarAllowTrustOperation = {
81
+ type: 'allowTrust';
82
+ source?: string;
83
+ trustor: string;
84
+ assetCode: string;
85
+ assetType: number;
86
+ authorize?: boolean | typeof undefined;
87
+ };
88
+
89
+ type StellarAccountMergeOperation = {
90
+ type: 'accountMerge';
91
+ source?: string;
92
+ destination: string;
93
+ };
94
+
95
+ type StellarManageDataOperation = {
96
+ type: 'manageData';
97
+ source?: string;
98
+ name: string;
99
+ value?: Buffer | string;
100
+ };
101
+
102
+ type StellarBumpSequenceOperation = {
103
+ type: 'bumpSequence';
104
+ source?: string;
105
+ bumpTo: string;
106
+ };
107
+
108
+ type StellarInflationOperation = {
109
+ type: 'inflation';
110
+ source?: string;
111
+ };
112
+
113
+ export type StellarOperation =
114
+ | StellarCreateAccountOperation
115
+ | StellarPaymentOperation
116
+ | StellarPathPaymentOperation
117
+ | StellarPassiveOfferOperation
118
+ | StellarManageOfferOperation
119
+ | StellarSetOptionsOperation
120
+ | StellarChangeTrustOperation
121
+ | StellarAllowTrustOperation
122
+ | StellarAccountMergeOperation
123
+ | StellarInflationOperation
124
+ | StellarManageDataOperation
125
+ | StellarBumpSequenceOperation;
126
+
127
+ export type StellarTransaction = {
128
+ source: string;
129
+ fee: number;
130
+ sequence: string | number;
131
+ timebounds?: {
132
+ minTime: number;
133
+ maxTime: number;
134
+ };
135
+ memo?: {
136
+ type: 0 | 1 | 2 | 3 | 4;
137
+ id?: string;
138
+ text?: string;
139
+ hash?: string | Buffer;
140
+ };
141
+ operations: StellarOperation[];
142
+ };
143
+
144
+ export type StellarSignTransactionParams = {
145
+ path: string | number[];
146
+ networkPassphrase: string;
147
+ transaction: StellarTransaction;
148
+ };
149
+
150
+ export declare function stellarSignTransaction(
151
+ connectId: string,
152
+ params: CommonParams & StellarSignTransactionParams
153
+ ): Response<StellarSignedTx>;
@@ -73,8 +73,16 @@ export type Features = PROTO.Features;
73
73
 
74
74
  export type IDeviceType = 'classic' | 'mini' | 'touch' | 'pro';
75
75
 
76
+ // model_mini: 'classic' | 'mini'
77
+ // model_touch: 'touch' | 'pro'
78
+ export type IDeviceModel = 'model_mini' | 'model_touch';
79
+
76
80
  export type IDeviceFirmwareStatus = 'valid' | 'outdated' | 'required' | 'unknown' | 'none';
77
81
 
78
82
  export type IDeviceBLEFirmwareStatus = 'valid' | 'outdated' | 'required' | 'unknown' | 'none';
79
83
 
80
84
  export type ITransportStatus = 'valid' | 'outdated';
85
+
86
+ export type DeviceFirmwareRange = {
87
+ [deviceType in IDeviceType | IDeviceModel]?: { min: string; max?: string };
88
+ };
@@ -1,4 +1,16 @@
1
- import type { Features, IVersionArray, IDeviceType } from '../types';
1
+ import type { Features, IVersionArray, IDeviceType, IDeviceModel } from '../types';
2
+
3
+ export const getDeviceModel = (features?: Features): IDeviceModel => {
4
+ if (!features || typeof features !== 'object') {
5
+ return 'model_mini';
6
+ }
7
+
8
+ if (features.model === '1') {
9
+ return 'model_mini';
10
+ }
11
+ // model === 'T'
12
+ return 'model_touch';
13
+ };
2
14
 
3
15
  export const getDeviceType = (features?: Features): IDeviceType => {
4
16
  if (!features || typeof features !== 'object' || !features.serial_no) {
@@ -8,6 +20,24 @@ export const getDeviceType = (features?: Features): IDeviceType => {
8
20
  const serialNo = features.serial_no;
9
21
  const miniFlag = serialNo.slice(0, 2);
10
22
  if (miniFlag.toLowerCase() === 'mi') return 'mini';
23
+ if (miniFlag.toLowerCase() === 'tc') return 'touch';
24
+ return 'classic';
25
+ };
26
+
27
+ export const getDeviceTypeByBleName = (name?: string): IDeviceType | null => {
28
+ if (!name) return 'classic';
29
+ if (name.startsWith('MI')) return 'mini';
30
+ if (name.startsWith('T')) return 'touch';
31
+ return 'classic';
32
+ };
33
+
34
+ export const getDeviceTypeByDeviceId = (deviceId?: string): IDeviceType => {
35
+ if (!deviceId) {
36
+ return 'classic';
37
+ }
38
+
39
+ const miniFlag = deviceId.slice(0, 2);
40
+ if (miniFlag.toLowerCase() === 'mi') return 'mini';
11
41
  return 'classic';
12
42
  };
13
43
 
@@ -31,7 +61,9 @@ export const getDeviceLabel = (features: Features) => {
31
61
  /**
32
62
  * Get Connected Device version by features
33
63
  */
34
- export const getDeviceFirmwareVersion = (features: Features): IVersionArray => {
64
+ export const getDeviceFirmwareVersion = (features: Features | undefined): IVersionArray => {
65
+ if (!features) return [0, 0, 0];
66
+
35
67
  if (features.onekey_version) {
36
68
  return features.onekey_version.split('.') as unknown as IVersionArray;
37
69
  }
@@ -3,7 +3,13 @@ import { initLog, enableLog } from './logger';
3
3
  export * from './assets';
4
4
  export * from './versionUtils';
5
5
  export * from './deferred';
6
- export { getDeviceType, getDeviceUUID, getDeviceLabel } from './deviceFeaturesUtils';
6
+ export {
7
+ getDeviceType,
8
+ getDeviceTypeByBleName,
9
+ getDeviceTypeByDeviceId,
10
+ getDeviceUUID,
11
+ getDeviceLabel,
12
+ } from './deviceFeaturesUtils';
7
13
  export { getHDPath, getScriptType } from '../api/helpers/pathUtils';
8
14
 
9
15
  export { initLog, enableLog };