@onekeyfe/hd-core 1.0.33-alpha.5 → 1.0.33-alpha.8

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 (131) hide show
  1. package/dist/api/BaseMethod.d.ts +1 -1
  2. package/dist/api/BaseMethod.d.ts.map +1 -1
  3. package/dist/api/allnetwork/AllNetworkGetAddress.d.ts +3 -1
  4. package/dist/api/allnetwork/AllNetworkGetAddress.d.ts.map +1 -1
  5. package/dist/core/index.d.ts.map +1 -1
  6. package/dist/device/Device.d.ts +6 -2
  7. package/dist/device/Device.d.ts.map +1 -1
  8. package/dist/device/DeviceCommands.d.ts +7 -5
  9. package/dist/device/DeviceCommands.d.ts.map +1 -1
  10. package/dist/events/device.d.ts +3 -0
  11. package/dist/events/device.d.ts.map +1 -1
  12. package/dist/events/ui-request.d.ts +3 -2
  13. package/dist/events/ui-request.d.ts.map +1 -1
  14. package/dist/events/ui-response.d.ts +1 -0
  15. package/dist/events/ui-response.d.ts.map +1 -1
  16. package/dist/index.d.ts +18 -8
  17. package/dist/index.js +344 -304
  18. package/dist/utils/deviceFeaturesUtils.d.ts +2 -1
  19. package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
  20. package/dist/utils/patch.d.ts +1 -1
  21. package/package.json +4 -4
  22. package/src/api/BaseMethod.ts +3 -2
  23. package/src/api/CheckAllFirmwareRelease.ts +1 -1
  24. package/src/api/CheckBLEFirmwareRelease.ts +3 -3
  25. package/src/api/CheckBootloaderRelease.ts +1 -1
  26. package/src/api/CheckBridgeRelease.ts +1 -1
  27. package/src/api/CheckFirmwareRelease.ts +3 -3
  28. package/src/api/CipherKeyValue.ts +1 -1
  29. package/src/api/FirmwareUpdate.ts +1 -1
  30. package/src/api/FirmwareUpdateV2.ts +1 -1
  31. package/src/api/FirmwareUpdateV3.ts +1 -1
  32. package/src/api/GetFeatures.ts +3 -3
  33. package/src/api/GetOnekeyFeatures.ts +3 -3
  34. package/src/api/GetPassphraseState.ts +1 -1
  35. package/src/api/alephium/AlephiumGetAddress.ts +1 -1
  36. package/src/api/alephium/AlephiumSignMessage.ts +1 -1
  37. package/src/api/alephium/AlephiumSignTransaction.ts +1 -1
  38. package/src/api/algo/AlgoGetAddress.ts +1 -1
  39. package/src/api/algo/AlgoSignTransaction.ts +1 -1
  40. package/src/api/allnetwork/AllNetworkGetAddress.ts +19 -21
  41. package/src/api/aptos/AptosGetAddress.ts +1 -1
  42. package/src/api/aptos/AptosGetPublicKey.ts +1 -1
  43. package/src/api/aptos/AptosSignMessage.ts +1 -1
  44. package/src/api/aptos/AptosSignTransaction.ts +1 -1
  45. package/src/api/benfen/BenfenGetAddress.ts +1 -1
  46. package/src/api/benfen/BenfenGetPublicKey.ts +1 -1
  47. package/src/api/benfen/BenfenSignMessage.ts +1 -1
  48. package/src/api/benfen/BenfenSignTransaction.ts +1 -1
  49. package/src/api/btc/BTCGetAddress.ts +1 -1
  50. package/src/api/btc/BTCGetPublicKey.ts +1 -1
  51. package/src/api/btc/BTCSignMessage.ts +1 -1
  52. package/src/api/btc/BTCSignPsbt.ts +1 -1
  53. package/src/api/btc/BTCSignTransaction.ts +1 -1
  54. package/src/api/btc/BTCVerifyMessage.ts +1 -1
  55. package/src/api/cardano/CardanoGetAddress.ts +1 -1
  56. package/src/api/cardano/CardanoGetPublicKey.ts +1 -1
  57. package/src/api/cardano/CardanoSignMessage.ts +1 -1
  58. package/src/api/cardano/CardanoSignTransaction.ts +1 -1
  59. package/src/api/conflux/ConfluxGetAddress.ts +1 -1
  60. package/src/api/conflux/ConfluxSignMessage.ts +1 -1
  61. package/src/api/conflux/ConfluxSignMessageCIP23.ts +1 -1
  62. package/src/api/conflux/ConfluxSignTransaction.ts +1 -1
  63. package/src/api/cosmos/CosmosGetAddress.ts +1 -1
  64. package/src/api/cosmos/CosmosGetPublicKey.ts +1 -1
  65. package/src/api/cosmos/CosmosSignTransaction.ts +1 -1
  66. package/src/api/device/DeviceUpdateBootloader.ts +1 -1
  67. package/src/api/dynex/DnxGetAddress.ts +1 -1
  68. package/src/api/dynex/DnxSignTransaction.ts +1 -1
  69. package/src/api/evm/EVMGetAddress.ts +1 -1
  70. package/src/api/evm/EVMGetPublicKey.ts +1 -1
  71. package/src/api/evm/EVMSignMessage.ts +1 -1
  72. package/src/api/evm/EVMSignMessageEIP712.ts +1 -1
  73. package/src/api/evm/EVMSignTransaction.ts +1 -1
  74. package/src/api/evm/EVMSignTypedData.ts +1 -1
  75. package/src/api/evm/EVMVerifyMessage.ts +1 -1
  76. package/src/api/filecoin/FilecoinGetAddress.ts +1 -1
  77. package/src/api/filecoin/FilecoinSignTransaction.ts +1 -1
  78. package/src/api/kaspa/KaspaGetAddress.ts +1 -1
  79. package/src/api/kaspa/KaspaSignTransaction.ts +1 -1
  80. package/src/api/lightning/LnurlAuth.ts +1 -1
  81. package/src/api/near/NearGetAddress.ts +1 -1
  82. package/src/api/near/NearSignTransaction.ts +1 -1
  83. package/src/api/nem/NEMGetAddress.ts +1 -1
  84. package/src/api/nem/NEMSignTransaction.ts +1 -1
  85. package/src/api/neo/NeoGetAddress.ts +1 -1
  86. package/src/api/neo/NeoSignTransaction.ts +1 -1
  87. package/src/api/nervos/NervosGetAddress.ts +1 -1
  88. package/src/api/nervos/NervosSignTransaction.ts +1 -1
  89. package/src/api/nexa/NexaGetAddress.ts +1 -1
  90. package/src/api/nostr/NostrDecryptMessage.ts +1 -1
  91. package/src/api/nostr/NostrEncryptMessage.ts +1 -1
  92. package/src/api/nostr/NostrGetPublicKey.ts +1 -1
  93. package/src/api/nostr/NostrSignEvent.ts +1 -1
  94. package/src/api/nostr/NostrSignSchnorr.ts +1 -1
  95. package/src/api/polkadot/PolkadotGetAddress.ts +1 -1
  96. package/src/api/polkadot/PolkadotSignTransaction.ts +1 -1
  97. package/src/api/scdo/ScdoGetAddress.ts +1 -1
  98. package/src/api/scdo/ScdoSignMessage.ts +1 -1
  99. package/src/api/scdo/ScdoSignTransaction.ts +1 -1
  100. package/src/api/solana/SolGetAddress.ts +1 -1
  101. package/src/api/solana/SolSignMessage.ts +1 -1
  102. package/src/api/solana/SolSignOffchainMessage.ts +1 -1
  103. package/src/api/solana/SolSignTransaction.ts +1 -1
  104. package/src/api/starcoin/StarcoinGetAddress.ts +1 -1
  105. package/src/api/starcoin/StarcoinGetPublicKey.ts +1 -1
  106. package/src/api/starcoin/StarcoinSignMessage.ts +1 -1
  107. package/src/api/starcoin/StarcoinSignTransaction.ts +1 -1
  108. package/src/api/starcoin/StarcoinVerifyMessage.ts +1 -1
  109. package/src/api/stellar/StellarGetAddress.ts +1 -1
  110. package/src/api/stellar/StellarSignTransaction.ts +1 -1
  111. package/src/api/sui/SuiGetAddress.ts +1 -1
  112. package/src/api/sui/SuiGetPublicKey.ts +1 -1
  113. package/src/api/sui/SuiSignMessage.ts +1 -1
  114. package/src/api/sui/SuiSignTransaction.ts +1 -1
  115. package/src/api/test/TestInitializeDeviceDuration.ts +3 -3
  116. package/src/api/ton/TonGetAddress.ts +1 -1
  117. package/src/api/ton/TonSignMessage.ts +1 -1
  118. package/src/api/ton/TonSignProof.ts +1 -1
  119. package/src/api/tron/TronGetAddress.ts +1 -1
  120. package/src/api/tron/TronSignMessage.ts +1 -1
  121. package/src/api/tron/TronSignTransaction.ts +1 -1
  122. package/src/api/xrp/XrpGetAddress.ts +1 -1
  123. package/src/api/xrp/XrpSignTransaction.ts +1 -1
  124. package/src/core/index.ts +11 -7
  125. package/src/data/messages/messages.json +48 -35
  126. package/src/device/Device.ts +24 -10
  127. package/src/device/DeviceCommands.ts +15 -4
  128. package/src/events/device.ts +4 -0
  129. package/src/events/ui-request.ts +3 -2
  130. package/src/events/ui-response.ts +1 -0
  131. package/src/utils/deviceFeaturesUtils.ts +55 -49
@@ -44,6 +44,10 @@ export interface DeviceButtonRequestPayload extends Omit<PROTO.ButtonRequest, 'c
44
44
  code?: PROTO.ButtonRequest['code'] | 'ButtonRequest_FirmwareUpdate';
45
45
  }
46
46
 
47
+ export type PassphraseRequestPayload = {
48
+ existsAttachPinUser?: boolean;
49
+ };
50
+
47
51
  export interface DeviceButtonRequest {
48
52
  type: typeof DEVICE.BUTTON;
49
53
  payload: DeviceButtonRequestPayload & { device: Device | null };
@@ -34,7 +34,7 @@ export const UI_REQUEST = {
34
34
  BOOTLOADER: 'ui-device_bootloader_mode',
35
35
  NOT_IN_BOOTLOADER: 'ui-device_not_in_bootloader_mode',
36
36
  REQUIRE_MODE: 'ui-device_require_mode',
37
- INITIALIZE: 'ui-device_not_initialized',
37
+ NOT_INITIALIZE: 'ui-device_not_initialized',
38
38
  SEEDLESS: 'ui-device_seedless',
39
39
  FIRMWARE_OLD: 'ui-device_firmware_old',
40
40
  FIRMWARE_NOT_SUPPORTED: 'ui-device_firmware_unsupported',
@@ -66,7 +66,7 @@ export type UiRequestDeviceAction = {
66
66
  type: typeof UI_REQUEST.REQUEST_PIN;
67
67
  payload: {
68
68
  device: Device;
69
- type?: PROTO.PinMatrixRequestType | 'ButtonRequest_PinEntry';
69
+ type?: PROTO.PinMatrixRequestType | 'ButtonRequest_PinEntry' | 'ButtonRequest_AttachPin';
70
70
  };
71
71
  };
72
72
 
@@ -80,6 +80,7 @@ export interface UiRequestPassphrase {
80
80
  payload: {
81
81
  device: Device;
82
82
  passphraseState?: string;
83
+ existsAttachPinUser?: boolean;
83
84
  };
84
85
  }
85
86
 
@@ -18,6 +18,7 @@ export interface UiResponsePassphrase {
18
18
  payload: {
19
19
  value: string;
20
20
  passphraseOnDevice?: boolean;
21
+ attachPinOnDevice?: boolean;
21
22
  save?: boolean;
22
23
  };
23
24
  }
@@ -1,7 +1,7 @@
1
1
  import semver from 'semver';
2
2
  import { isNaN } from 'lodash';
3
3
  import { EDeviceType, ERRORS, HardwareErrorCode } from '@onekeyfe/hd-shared';
4
- // import { toHardened } from '../api/helpers/pathUtils';
4
+ import { toHardened } from '../api/helpers/pathUtils';
5
5
  import { DeviceCommands } from '../device/DeviceCommands';
6
6
  import type { Features, SupportFeatureType } from '../types';
7
7
  import { DeviceModelToTypes, DeviceTypeToModels } from '../types';
@@ -83,11 +83,13 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
83
83
  const { features, commands } = device;
84
84
  const locked = features?.unlocked === false;
85
85
 
86
- const sessionId = device.getInternalState();
87
- const { passphraseState, newSession } = await getPassphraseState(features, commands, {
88
- sessionId,
89
- ...options,
90
- });
86
+ const { passphraseState, newSession, unlockedAttachPin } = await getPassphraseState(
87
+ features,
88
+ commands,
89
+ {
90
+ ...options,
91
+ }
92
+ );
91
93
 
92
94
  // Attach to pin try to fix internal state
93
95
  if (newSession && passphraseState && features?.device_id) {
@@ -110,7 +112,7 @@ export const getPassphraseStateWithRefreshDeviceInfo = async (
110
112
  await device.getFeatures();
111
113
  }
112
114
 
113
- return { passphraseState, newSession };
115
+ return { passphraseState, newSession, unlockedAttachPin };
114
116
  };
115
117
 
116
118
  export const getPassphraseState = async (
@@ -118,30 +120,53 @@ export const getPassphraseState = async (
118
120
  commands: DeviceCommands,
119
121
  options?: {
120
122
  expectPassphraseState?: string;
121
- sessionId?: string;
122
123
  onlyMainPin?: boolean;
124
+ // createAttachPinWallet?: boolean;
123
125
  }
124
- ): Promise<{ passphraseState: string | undefined; newSession: string | undefined }> => {
125
- if (!features) return { passphraseState: undefined, newSession: undefined };
126
- // const firmwareVersion = getDeviceFirmwareVersion(features);
127
- // const deviceType = getDeviceType(features);
128
-
129
- // if (deviceType === EDeviceType.Pro && semver.gte(firmwareVersion.join('.'), '4.13.2')) {
130
- console.log(
131
- '=====>>>>>> getPassphraseState begin: ',
132
- options?.onlyMainPin,
133
- options?.expectPassphraseState,
134
- options?.sessionId
135
- );
126
+ ): Promise<{
127
+ passphraseState: string | undefined;
128
+ newSession: string | undefined;
129
+ unlockedAttachPin: boolean | undefined;
130
+ }> => {
131
+ if (!features)
132
+ return { passphraseState: undefined, newSession: undefined, unlockedAttachPin: undefined };
136
133
 
137
- // @ts-expect-error
138
- const { message, type } = await commands.typedCall('GetPassphraseState', 'PassphraseState', {
139
- session_id: options?.sessionId,
140
- btc_test: options?.onlyMainPin ? undefined : options?.expectPassphraseState,
141
- onlyMainPin: options?.onlyMainPin,
142
- });
134
+ const firmwareVersion = getDeviceFirmwareVersion(features);
135
+ const deviceType = getDeviceType(features);
136
+
137
+ if (deviceType === EDeviceType.Pro && semver.gte(firmwareVersion.join('.'), '4.13.2')) {
138
+ console.log(
139
+ '=====>>>>>> getPassphraseState begin: ',
140
+ options?.onlyMainPin,
141
+ options?.expectPassphraseState
142
+ );
143
143
 
144
- console.log('=====>>>>>> getPassphraseState end: result ', message);
144
+ const { message, type } = await commands.typedCall('GetPassphraseState', 'PassphraseState', {
145
+ passphrase_state: options?.onlyMainPin ? undefined : options?.expectPassphraseState,
146
+ // allow_create_attach_pin: options?.createAttachPinWallet,
147
+ // _only_main_pin: options?.onlyMainPin,
148
+ });
149
+
150
+ console.log('=====>>>>>> getPassphraseState end: result ', message);
151
+
152
+ // @ts-expect-error
153
+ if (type === 'CallMethodError') {
154
+ throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
155
+ }
156
+
157
+ return {
158
+ passphraseState: message.passphrase_state,
159
+ newSession: message.session_id,
160
+ unlockedAttachPin: message.unlocked_attach_pin,
161
+ };
162
+ }
163
+
164
+ const { message, type } = await commands.typedCall('GetAddress', 'Address', {
165
+ address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
166
+ coin_name: 'Testnet',
167
+ script_type: 'SPENDADDRESS',
168
+ show_display: false,
169
+ });
145
170
 
146
171
  // @ts-expect-error
147
172
  if (type === 'CallMethodError') {
@@ -149,29 +174,10 @@ export const getPassphraseState = async (
149
174
  }
150
175
 
151
176
  return {
152
- // @ts-expect-error
153
- passphraseState: message.btc_test,
154
- // @ts-expect-error
155
- newSession: message.session_id,
177
+ passphraseState: message.address,
178
+ newSession: undefined,
179
+ unlockedAttachPin: undefined,
156
180
  };
157
- // }
158
-
159
- // const { message, type } = await commands.typedCall('GetAddress', 'Address', {
160
- // address_n: [toHardened(44), toHardened(1), toHardened(0), 0, 0],
161
- // coin_name: 'Testnet',
162
- // script_type: 'SPENDADDRESS',
163
- // show_display: false,
164
- // });
165
-
166
- // // @ts-expect-error
167
- // if (type === 'CallMethodError') {
168
- // throw ERRORS.TypedError(HardwareErrorCode.RuntimeError, 'Get the passphrase state error');
169
- // }
170
-
171
- // return {
172
- // passphraseState: message.address,
173
- // newSession: undefined,
174
- // };
175
181
  };
176
182
 
177
183
  export const supportBatchPublicKey = (