@onekeyfe/hd-core 1.2.0-alpha.50 → 1.2.0-alpha.52
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.
- package/__tests__/AllNetworkGetAddressBase.tracing.test.ts +0 -78
- package/__tests__/DeviceEventRegistration.test.ts +0 -6
- package/__tests__/check-all-firmware-release-protocol-v2.test.ts +3 -111
- package/__tests__/connectSettings.test.ts +47 -5
- package/__tests__/device-initialize-timeout.test.ts +56 -0
- package/__tests__/device-lifecycle-events.test.ts +3 -105
- package/__tests__/firmware-update/check-all-firmware-release.test.ts +175 -0
- package/__tests__/firmware-update/firmware-artifact-source.test.ts +119 -0
- package/__tests__/firmware-update/firmware-host-binding.test.ts +70 -0
- package/__tests__/firmware-update/firmware-preparation-error.test.ts +27 -0
- package/__tests__/firmware-update/firmware-update-bootloader-poll.test.ts +200 -0
- package/__tests__/firmware-update/firmware-update-capabilities.test.ts +13 -0
- package/__tests__/firmware-update/firmware-update-plan-bootloader-identity.test.ts +294 -0
- package/__tests__/firmware-update/firmware-update-plan.test.ts +593 -0
- package/__tests__/firmware-update/firmware-update-prepared-plan.test.ts +213 -0
- package/__tests__/firmware-update/firmware-update-v2-download-before-boot.test.ts +59 -31
- package/__tests__/firmware-update/firmware-update-v3-reconnect.test.ts +58 -0
- package/__tests__/firmware-update/firmware-upload-source.test.ts +70 -0
- package/__tests__/get-device-state.test.ts +12 -132
- package/__tests__/homescreen.test.ts +1 -41
- package/__tests__/logBlockEvent.test.ts +1 -1
- package/__tests__/method-protocol-support.test.ts +0 -19
- package/__tests__/open-wallet-session.test.ts +33 -446
- package/__tests__/protocol-v2-unlock-policy.test.ts +35 -196
- package/__tests__/protocol-v2.test.ts +1032 -1056
- package/__tests__/protocolV2UiInteraction.test.ts +0 -63
- package/__tests__/public-pro2-api-boundary.test.ts +0 -1
- package/__tests__/search-devices.test.ts +3 -12
- package/dist/api/BaseMethod.d.ts +1 -3
- package/dist/api/BaseMethod.d.ts.map +1 -1
- package/dist/api/CheckAllFirmwareRelease.d.ts.map +1 -1
- package/dist/api/FirmwareUpdate.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV2.d.ts +11 -0
- package/dist/api/FirmwareUpdateV2.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV3.d.ts +7 -3
- package/dist/api/FirmwareUpdateV3.d.ts.map +1 -1
- package/dist/api/FirmwareUpdateV4.d.ts +25 -9
- package/dist/api/FirmwareUpdateV4.d.ts.map +1 -1
- package/dist/api/GetPassphraseState.d.ts.map +1 -1
- package/dist/api/OpenWalletSession.d.ts.map +1 -1
- package/dist/api/SearchDevices.d.ts.map +1 -1
- package/dist/api/allnetwork/AllNetworkGetAddressBase.d.ts.map +1 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts +5 -1
- package/dist/api/device/DeviceUpdateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareArtifactSource.d.ts +25 -0
- package/dist/api/firmware/FirmwareArtifactSource.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareHostBinding.d.ts +6 -0
- package/dist/api/firmware/FirmwareHostBinding.d.ts.map +1 -0
- package/dist/api/firmware/FirmwarePreparationError.d.ts +3 -0
- package/dist/api/firmware/FirmwarePreparationError.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts +9 -0
- package/dist/api/firmware/FirmwareUpdateBaseMethod.d.ts.map +1 -1
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts +3 -0
- package/dist/api/firmware/FirmwareUpdateCapabilities.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts +25 -0
- package/dist/api/firmware/FirmwareUpdatePlan.d.ts.map +1 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts +32 -0
- package/dist/api/firmware/FirmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/api/firmware/getBinary.d.ts +7 -0
- package/dist/api/firmware/getBinary.d.ts.map +1 -1
- package/dist/api/firmware/progressThrottle.d.ts +3 -0
- package/dist/api/firmware/progressThrottle.d.ts.map +1 -0
- package/dist/api/firmware/updateBootloader.d.ts +2 -0
- package/dist/api/firmware/updateBootloader.d.ts.map +1 -1
- package/dist/api/firmware/uploadFirmware.d.ts +9 -1
- package/dist/api/firmware/uploadFirmware.d.ts.map +1 -1
- package/dist/api/helpers/protocolV2FileWrite.d.ts +0 -2
- package/dist/api/helpers/protocolV2FileWrite.d.ts.map +1 -1
- package/dist/api/index.d.ts +0 -2
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/protocol-v2/ProtocolInfoRequest.d.ts.map +1 -1
- package/dist/api/stellar/StellarSignTransaction.d.ts +1 -1
- package/dist/core/deviceEventRegistration.d.ts +0 -2
- package/dist/core/deviceEventRegistration.d.ts.map +1 -1
- package/dist/core/index.d.ts.map +1 -1
- package/dist/data-manager/DataManager.d.ts +2 -4
- package/dist/data-manager/DataManager.d.ts.map +1 -1
- package/dist/data-manager/connectSettings.d.ts.map +1 -1
- package/dist/device/Device.d.ts +6 -29
- package/dist/device/Device.d.ts.map +1 -1
- package/dist/device/DeviceCommands.d.ts +4 -4
- package/dist/device/DevicePool.d.ts.map +1 -1
- package/dist/events/device.d.ts +0 -4
- package/dist/events/device.d.ts.map +1 -1
- package/dist/events/logBlockEvent.d.ts.map +1 -1
- package/dist/events/ui-promise.d.ts +2 -4
- package/dist/events/ui-promise.d.ts.map +1 -1
- package/dist/events/ui-request.d.ts +2 -31
- package/dist/events/ui-request.d.ts.map +1 -1
- package/dist/events/ui-response.d.ts +2 -10
- package/dist/events/ui-response.d.ts.map +1 -1
- package/dist/index.d.ts +230 -203
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3469 -2419
- package/dist/inject.d.ts +1 -6
- package/dist/inject.d.ts.map +1 -1
- package/dist/lowLevelInject.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/features.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/lockedError.d.ts +2 -0
- package/dist/protocols/protocol-v2/lockedError.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/uiInteraction.d.ts +4 -7
- package/dist/protocols/protocol-v2/uiInteraction.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts +3 -1
- package/dist/protocols/protocol-v2/unlockPolicy.d.ts.map +1 -1
- package/dist/protocols/protocol-v2/unlockRetry.d.ts +10 -0
- package/dist/protocols/protocol-v2/unlockRetry.d.ts.map +1 -0
- package/dist/protocols/protocol-v2/walletSession.d.ts +1 -4
- package/dist/protocols/protocol-v2/walletSession.d.ts.map +1 -1
- package/dist/topLevelInject.d.ts.map +1 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts +4 -1
- package/dist/types/api/checkAllFirmwareRelease.d.ts.map +1 -1
- package/dist/types/api/deviceUpdateBootloader.d.ts +6 -0
- package/dist/types/api/deviceUpdateBootloader.d.ts.map +1 -1
- package/dist/types/api/export.d.ts +4 -1
- package/dist/types/api/export.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdate.d.ts +70 -2
- package/dist/types/api/firmwareUpdate.d.ts.map +1 -1
- package/dist/types/api/firmwareUpdateCapabilities.d.ts +9 -0
- package/dist/types/api/firmwareUpdateCapabilities.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts +28 -0
- package/dist/types/api/firmwareUpdatePlan.d.ts.map +1 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts +42 -0
- package/dist/types/api/firmwareUpdatePreparedPlan.d.ts.map +1 -0
- package/dist/types/api/index.d.ts +10 -7
- package/dist/types/api/index.d.ts.map +1 -1
- package/dist/types/api/protocolV2.d.ts +0 -3
- package/dist/types/api/protocolV2.d.ts.map +1 -1
- package/dist/types/params.d.ts +0 -1
- package/dist/types/params.d.ts.map +1 -1
- package/dist/types/settings.d.ts +13 -22
- package/dist/types/settings.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesCompat.d.ts +1 -0
- package/dist/utils/deviceFeaturesCompat.d.ts.map +1 -1
- package/dist/utils/deviceFeaturesUtils.d.ts +0 -2
- package/dist/utils/deviceFeaturesUtils.d.ts.map +1 -1
- package/dist/utils/homescreen.d.ts +0 -4
- package/dist/utils/homescreen.d.ts.map +1 -1
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/patch.d.ts +1 -1
- package/dist/utils/patch.d.ts.map +1 -1
- package/dist/utils/pro2Wallpaper.d.ts +0 -10
- package/dist/utils/pro2Wallpaper.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/api/BaseMethod.ts +10 -8
- package/src/api/CheckAllFirmwareRelease.ts +53 -41
- package/src/api/FirmwareUpdate.ts +15 -7
- package/src/api/FirmwareUpdateV2.ts +316 -126
- package/src/api/FirmwareUpdateV3.ts +265 -63
- package/src/api/FirmwareUpdateV4.ts +937 -430
- package/src/api/GetPassphraseState.ts +1 -7
- package/src/api/OpenWalletSession.ts +17 -54
- package/src/api/SearchDevices.ts +1 -3
- package/src/api/allnetwork/AllNetworkGetAddressBase.ts +11 -32
- package/src/api/device/DeviceUnlock.ts +1 -1
- package/src/api/device/DeviceUpdateBootloader.ts +122 -6
- package/src/api/firmware/FirmwareArtifactSource.ts +278 -0
- package/src/api/firmware/FirmwareHostBinding.ts +100 -0
- package/src/api/firmware/FirmwarePreparationError.ts +12 -0
- package/src/api/firmware/FirmwareUpdateBaseMethod.ts +83 -16
- package/src/api/firmware/FirmwareUpdateCapabilities.ts +9 -0
- package/src/api/firmware/FirmwareUpdatePlan.ts +772 -0
- package/src/api/firmware/FirmwareUpdatePreparedPlan.ts +415 -0
- package/src/api/firmware/progressThrottle.ts +44 -0
- package/src/api/firmware/updateBootloader.ts +19 -4
- package/src/api/firmware/uploadFirmware.ts +144 -39
- package/src/api/helpers/protocolV2FileWrite.ts +4 -11
- package/src/api/index.ts +0 -2
- package/src/api/protocol-v2/ProtocolInfoRequest.ts +1 -3
- package/src/core/deviceEventRegistration.ts +0 -4
- package/src/core/index.ts +83 -167
- package/src/data/messages/messages-protocol-v2.json +0 -25
- package/src/data-manager/DataManager.ts +38 -67
- package/src/data-manager/connectSettings.ts +11 -0
- package/src/device/Device.ts +42 -257
- package/src/device/DevicePool.ts +2 -7
- package/src/events/device.ts +0 -4
- package/src/events/logBlockEvent.ts +0 -1
- package/src/events/ui-promise.ts +2 -4
- package/src/events/ui-request.ts +2 -36
- package/src/events/ui-response.ts +2 -12
- package/src/index.ts +5 -0
- package/src/inject.ts +24 -60
- package/src/lowLevelInject.ts +8 -7
- package/src/protocols/protocol-v2/features.ts +2 -9
- package/src/protocols/protocol-v2/lockedError.ts +10 -0
- package/src/protocols/protocol-v2/uiInteraction.ts +6 -46
- package/src/protocols/protocol-v2/unlockPolicy.ts +105 -1
- package/src/protocols/protocol-v2/unlockRetry.ts +109 -0
- package/src/protocols/protocol-v2/walletSession.ts +30 -169
- package/src/topLevelInject.ts +8 -7
- package/src/types/api/checkAllFirmwareRelease.ts +4 -1
- package/src/types/api/deviceUpdateBootloader.ts +6 -0
- package/src/types/api/export.ts +18 -0
- package/src/types/api/firmwareUpdate.ts +76 -3
- package/src/types/api/firmwareUpdateCapabilities.ts +9 -0
- package/src/types/api/firmwareUpdatePlan.ts +38 -0
- package/src/types/api/firmwareUpdatePreparedPlan.ts +53 -0
- package/src/types/api/index.ts +14 -13
- package/src/types/api/protocolV2.ts +0 -13
- package/src/types/params.ts +1 -7
- package/src/types/settings.ts +13 -42
- package/src/utils/deviceFeaturesCompat.ts +6 -0
- package/src/utils/deviceFeaturesUtils.ts +0 -4
- package/src/utils/homescreen.ts +6 -32
- package/src/utils/index.ts +1 -6
- package/src/utils/pro2Wallpaper.ts +8 -35
- package/__tests__/deviceUploadNft.test.ts +0 -293
- package/__tests__/pro2Nft.test.ts +0 -108
- package/__tests__/protocol-binding.test.ts +0 -89
- package/__tests__/protocol-v2-resources.test.ts +0 -284
- package/__tests__/protocol-v2-ui-lifecycle.test.ts +0 -91
- package/__tests__/uiProgressThrottle.test.ts +0 -74
- package/__tests__/uiPromiseRegistry.test.ts +0 -86
- package/dist/api/DetectDeviceConnectProtocol.d.ts +0 -7
- package/dist/api/DetectDeviceConnectProtocol.d.ts.map +0 -1
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts +0 -31
- package/dist/api/protocol-v2/DeviceUploadNft.d.ts.map +0 -1
- package/dist/core/uiPromiseRegistry.d.ts +0 -4
- package/dist/core/uiPromiseRegistry.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/resources.d.ts +0 -30
- package/dist/protocols/protocol-v2/resources.d.ts.map +0 -1
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts +0 -22
- package/dist/protocols/protocol-v2/unlockPolicyRunner.d.ts.map +0 -1
- package/dist/types/api/detectDeviceConnectProtocol.d.ts +0 -4
- package/dist/types/api/detectDeviceConnectProtocol.d.ts.map +0 -1
- package/dist/utils/pro2Nft.d.ts +0 -31
- package/dist/utils/pro2Nft.d.ts.map +0 -1
- package/dist/utils/uiProgressThrottle.d.ts +0 -3
- package/dist/utils/uiProgressThrottle.d.ts.map +0 -1
- package/src/api/DetectDeviceConnectProtocol.ts +0 -18
- package/src/api/protocol-v2/DeviceUploadNft.ts +0 -189
- package/src/core/uiPromiseRegistry.ts +0 -41
- package/src/protocols/protocol-v2/resources.ts +0 -359
- package/src/protocols/protocol-v2/unlockPolicyRunner.ts +0 -124
- package/src/types/api/detectDeviceConnectProtocol.ts +0 -7
- package/src/utils/pro2Nft.ts +0 -142
- package/src/utils/uiProgressThrottle.ts +0 -63
package/src/device/Device.ts
CHANGED
|
@@ -74,9 +74,7 @@ import type { DeviceStateReadOptions } from '../types/api/getDeviceState';
|
|
|
74
74
|
import type {
|
|
75
75
|
DeviceButtonRequestPayload,
|
|
76
76
|
DeviceFeaturesPayload,
|
|
77
|
-
HardwareUiInteractionMeta,
|
|
78
77
|
PassphraseRequestPayload,
|
|
79
|
-
ProtocolV2UiEventMetadata,
|
|
80
78
|
} from '../events';
|
|
81
79
|
import type { PassphrasePromptResponse } from './DeviceCommands';
|
|
82
80
|
import type { Deferred, HardwareConnectProtocol } from '@onekeyfe/hd-shared';
|
|
@@ -95,10 +93,14 @@ export type InitOptions = {
|
|
|
95
93
|
passphraseState?: string;
|
|
96
94
|
deriveCardano?: boolean;
|
|
97
95
|
connectProtocol?: HardwareConnectProtocol;
|
|
98
|
-
forceProtocolDetection?: boolean;
|
|
99
96
|
protocolV2DeviceInfoTimeoutMs?: number;
|
|
100
97
|
/** Refresh Protocol V2 runtime state before returning discovery results. */
|
|
101
98
|
refreshRuntimeState?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Protocol V1 Initialize response timeout override. Reboot-wait polling passes a
|
|
101
|
+
* short value so an unanswered probe settles before the next poll tick.
|
|
102
|
+
*/
|
|
103
|
+
timeoutMs?: number;
|
|
102
104
|
};
|
|
103
105
|
|
|
104
106
|
export type RunOptions = {
|
|
@@ -135,8 +137,6 @@ const isProtocolV2DeviceStatusUnsupportedError = (error: unknown) => {
|
|
|
135
137
|
|
|
136
138
|
export interface DeviceEvents {
|
|
137
139
|
[DEVICE.PIN]: [Device, PROTO.PinMatrixRequestType | undefined, (err: any, pin: string) => void];
|
|
138
|
-
[DEVICE.PIN_ON_DEVICE]: [Device, DeviceSessionPinType, ProtocolV2UiEventMetadata?];
|
|
139
|
-
[DEVICE.PIN_ON_DEVICE_COMPLETE]: [Device, HardwareUiInteractionMeta];
|
|
140
140
|
[DEVICE.PASSPHRASE_ON_DEVICE]: [Device, PassphraseRequestPayload?];
|
|
141
141
|
[DEVICE.ATTACH_PIN_ON_DEVICE]: [Device, PassphraseRequestPayload?];
|
|
142
142
|
[DEVICE.BUTTON]: [Device, DeviceButtonRequestPayload];
|
|
@@ -235,24 +235,6 @@ export class Device extends EventEmitter {
|
|
|
235
235
|
/** Force the next initialization to reload DeviceInfo after reconnect or reboot. */
|
|
236
236
|
private protocolV2StateNeedsReload = false;
|
|
237
237
|
|
|
238
|
-
/** Runtime context negotiated once per active Protocol V2 link. */
|
|
239
|
-
private protocolV2RuntimeContext?: ProtocolInfo;
|
|
240
|
-
|
|
241
|
-
/** Coalesces concurrent first-use runtime negotiation on the same active link. */
|
|
242
|
-
private protocolV2RuntimeContextPromise?: Promise<ProtocolInfo>;
|
|
243
|
-
|
|
244
|
-
/** Invalidates an in-flight runtime-context response without adding a transport epoch. */
|
|
245
|
-
private protocolV2RuntimeContextRequestToken?: object;
|
|
246
|
-
|
|
247
|
-
private protocolV2UiInteraction?: {
|
|
248
|
-
interactionId: string;
|
|
249
|
-
phaseCounter: number;
|
|
250
|
-
sequence: number;
|
|
251
|
-
opened: boolean;
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
private protocolV2UiInteractionCounter = 0;
|
|
255
|
-
|
|
256
238
|
get state() {
|
|
257
239
|
return this.stateStore.getState();
|
|
258
240
|
}
|
|
@@ -378,10 +360,7 @@ export class Device extends EventEmitter {
|
|
|
378
360
|
* Device connect
|
|
379
361
|
* @returns {Promise<boolean>}
|
|
380
362
|
*/
|
|
381
|
-
connect(
|
|
382
|
-
connectProtocol?: HardwareConnectProtocol,
|
|
383
|
-
options?: { forceProtocolDetection?: boolean }
|
|
384
|
-
) {
|
|
363
|
+
connect(connectProtocol?: HardwareConnectProtocol) {
|
|
385
364
|
const env = DataManager.getSettings('env');
|
|
386
365
|
// eslint-disable-next-line no-async-promise-executor
|
|
387
366
|
return new Promise<boolean>(async (resolve, reject) => {
|
|
@@ -391,7 +370,7 @@ export class Device extends EventEmitter {
|
|
|
391
370
|
return;
|
|
392
371
|
}
|
|
393
372
|
try {
|
|
394
|
-
await this.acquire(connectProtocol
|
|
373
|
+
await this.acquire(connectProtocol);
|
|
395
374
|
resolve(true);
|
|
396
375
|
} catch (error) {
|
|
397
376
|
reject(error);
|
|
@@ -401,7 +380,7 @@ export class Device extends EventEmitter {
|
|
|
401
380
|
// 不存在 Session ID 或存在 Session ID 但设备在别处使用,都需要 acquire 获取最新 sessionID
|
|
402
381
|
if (!this.mainId || (!this.isUsedHere() && this.originalDescriptor)) {
|
|
403
382
|
try {
|
|
404
|
-
await this.acquire(connectProtocol
|
|
383
|
+
await this.acquire(connectProtocol);
|
|
405
384
|
resolve(true);
|
|
406
385
|
} catch (error) {
|
|
407
386
|
reject(error);
|
|
@@ -418,16 +397,11 @@ export class Device extends EventEmitter {
|
|
|
418
397
|
|
|
419
398
|
async acquire(
|
|
420
399
|
expectedProtocol?: HardwareConnectProtocol,
|
|
421
|
-
options?: { throwOnRunPromiseError?: boolean
|
|
400
|
+
options?: { throwOnRunPromiseError?: boolean }
|
|
422
401
|
) {
|
|
423
402
|
const env = DataManager.getSettings('env');
|
|
424
403
|
const mainIdKey = DataManager.isBleConnect(env) ? 'id' : 'session';
|
|
425
|
-
const
|
|
426
|
-
// A protocol stored after a successful probe is authoritative. Only the explicit
|
|
427
|
-
// first-connection/recovery path may bypass it and probe both protocols again.
|
|
428
|
-
const strictProtocol = options?.forceProtocolDetection
|
|
429
|
-
? undefined
|
|
430
|
-
: expectedProtocol ?? this.originalDescriptor.protocolType;
|
|
404
|
+
const protocolHint = expectedProtocol ? undefined : this.originalDescriptor.protocolType;
|
|
431
405
|
try {
|
|
432
406
|
let acquireResult: unknown;
|
|
433
407
|
if (DataManager.isBleConnect(env)) {
|
|
@@ -439,8 +413,8 @@ export class Device extends EventEmitter {
|
|
|
439
413
|
this.originalDescriptor.id,
|
|
440
414
|
undefined,
|
|
441
415
|
true,
|
|
442
|
-
|
|
443
|
-
|
|
416
|
+
expectedProtocol,
|
|
417
|
+
protocolHint
|
|
444
418
|
);
|
|
445
419
|
this.mainId = (acquireResult as any)?.uuid ?? '';
|
|
446
420
|
Log.debug('Expected uuid:', this.mainId);
|
|
@@ -449,31 +423,24 @@ export class Device extends EventEmitter {
|
|
|
449
423
|
this.originalDescriptor.path,
|
|
450
424
|
this.originalDescriptor.session,
|
|
451
425
|
undefined,
|
|
452
|
-
|
|
453
|
-
|
|
426
|
+
expectedProtocol,
|
|
427
|
+
protocolHint
|
|
454
428
|
);
|
|
455
429
|
this.mainId = acquireResult as string | undefined;
|
|
456
430
|
Log.debug('Expected session id:', this.mainId);
|
|
457
431
|
}
|
|
432
|
+
this.deviceAcquired = true;
|
|
433
|
+
this.updateDescriptor({ [mainIdKey]: this.mainId } as unknown as DeviceDescriptor);
|
|
434
|
+
|
|
458
435
|
// Propagate protocol version detected during acquire.
|
|
459
436
|
const detectedProtocol =
|
|
460
437
|
(acquireResult as { protocolType?: HardwareConnectProtocol } | undefined)?.protocolType ??
|
|
461
438
|
TransportManager.transport?.getProtocolType?.(
|
|
462
439
|
DataManager.isBleConnect(env) ? this.originalDescriptor.id : this.originalDescriptor.path
|
|
463
440
|
);
|
|
464
|
-
if (options?.forceProtocolDetection && !detectedProtocol) {
|
|
465
|
-
throw ERRORS.TypedError(
|
|
466
|
-
HardwareErrorCode.RuntimeError,
|
|
467
|
-
`Active protocol detection returned no protocol for ${
|
|
468
|
-
this.originalDescriptor.path || this.originalDescriptor.id
|
|
469
|
-
}`
|
|
470
|
-
);
|
|
471
|
-
}
|
|
472
441
|
if (detectedProtocol) {
|
|
473
442
|
this.originalDescriptor.protocolType = detectedProtocol;
|
|
474
443
|
}
|
|
475
|
-
this.deviceAcquired = true;
|
|
476
|
-
this.updateDescriptor({ [mainIdKey]: this.mainId } as unknown as DeviceDescriptor);
|
|
477
444
|
|
|
478
445
|
if (this.commands) {
|
|
479
446
|
await this.commands.dispose(false);
|
|
@@ -481,22 +448,6 @@ export class Device extends EventEmitter {
|
|
|
481
448
|
|
|
482
449
|
this.commands = new DeviceCommands(this, this.mainId ?? '');
|
|
483
450
|
} catch (error) {
|
|
484
|
-
if (options?.forceProtocolDetection) {
|
|
485
|
-
this.originalDescriptor.protocolType = previousProtocol;
|
|
486
|
-
const failedSession = this.mainId;
|
|
487
|
-
this.deviceAcquired = false;
|
|
488
|
-
if (failedSession) {
|
|
489
|
-
try {
|
|
490
|
-
await this.deviceConnector?.release?.(failedSession, false);
|
|
491
|
-
} catch (releaseError) {
|
|
492
|
-
Log.debug('Failed to release an unsuccessful protocol probe', releaseError);
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
if (!DataManager.isBleConnect(env)) {
|
|
496
|
-
this.mainId = null;
|
|
497
|
-
this.updateDescriptor({ session: null } as DeviceDescriptor);
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
451
|
if (options?.throwOnRunPromiseError) {
|
|
501
452
|
throw error;
|
|
502
453
|
}
|
|
@@ -905,7 +856,7 @@ export class Device extends EventEmitter {
|
|
|
905
856
|
const initStartAt = Date.now();
|
|
906
857
|
const { message } = await this.commands.typedCall('Initialize', 'Features', payload, {
|
|
907
858
|
// iOS BLE bound devices can need close to 20 seconds.
|
|
908
|
-
timeoutMs: 25 * 1000,
|
|
859
|
+
timeoutMs: options?.timeoutMs ?? 25 * 1000,
|
|
909
860
|
});
|
|
910
861
|
this.setLastInitializeDuration(Date.now() - initStartAt);
|
|
911
862
|
this._updateFeatures(message, initSession);
|
|
@@ -1018,10 +969,7 @@ export class Device extends EventEmitter {
|
|
|
1018
969
|
await this.getFeatures();
|
|
1019
970
|
}
|
|
1020
971
|
|
|
1021
|
-
|
|
1022
|
-
this.getCurrentDeviceType() === EDeviceType.Touch ||
|
|
1023
|
-
this.getCurrentDeviceType() === EDeviceType.Pro;
|
|
1024
|
-
if (!this.isProtocolV2() && refresh.has('verification') && supportsProtocolV1OnekeyFeatures) {
|
|
972
|
+
if (!this.isProtocolV2() && refresh.has('verification')) {
|
|
1025
973
|
const { message } = await this.commands.typedCall('OnekeyGetFeatures', 'OnekeyFeatures');
|
|
1026
974
|
this.updateState(mapProtocolV1OnekeyFeaturesToState(message), 'device-info');
|
|
1027
975
|
}
|
|
@@ -1044,7 +992,13 @@ export class Device extends EventEmitter {
|
|
|
1044
992
|
}
|
|
1045
993
|
|
|
1046
994
|
if (refresh.has('status') && !initializedWithDeviceInfo) {
|
|
1047
|
-
|
|
995
|
+
const deviceInfo =
|
|
996
|
+
refreshedDeviceInfo ??
|
|
997
|
+
(await requestProtocolV2DeviceInfo({
|
|
998
|
+
commands: this.commands,
|
|
999
|
+
request: getProtocolV2DeviceInfoRequest(),
|
|
1000
|
+
}));
|
|
1001
|
+
await this.probeProtocolV2RuntimeState(deviceInfo);
|
|
1048
1002
|
}
|
|
1049
1003
|
|
|
1050
1004
|
if (refresh.has('settings') && this.state?.status.mode === 'normal') {
|
|
@@ -1115,58 +1069,15 @@ export class Device extends EventEmitter {
|
|
|
1115
1069
|
return this.features;
|
|
1116
1070
|
}
|
|
1117
1071
|
|
|
1118
|
-
async
|
|
1119
|
-
const
|
|
1120
|
-
this.
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
: undefined);
|
|
1124
|
-
if (cachedProtocolInfo) {
|
|
1125
|
-
this.protocolV2RuntimeContext = cachedProtocolInfo;
|
|
1126
|
-
return cachedProtocolInfo;
|
|
1127
|
-
}
|
|
1128
|
-
|
|
1129
|
-
if (this.protocolV2RuntimeContextPromise) {
|
|
1130
|
-
return this.protocolV2RuntimeContextPromise;
|
|
1131
|
-
}
|
|
1132
|
-
|
|
1133
|
-
const requestToken = {};
|
|
1134
|
-
const pendingRequest = (async () => {
|
|
1135
|
-
const protocolInfo = await requestProtocolV2ProtocolInfo({
|
|
1136
|
-
commands: this.commands,
|
|
1137
|
-
timeoutMs,
|
|
1138
|
-
});
|
|
1139
|
-
if (this.protocolV2RuntimeContextRequestToken !== requestToken) {
|
|
1140
|
-
throw ERRORS.TypedError(
|
|
1141
|
-
HardwareErrorCode.DeviceInitializeFailed,
|
|
1142
|
-
'Protocol V2 runtime context was invalidated while loading.'
|
|
1143
|
-
);
|
|
1144
|
-
}
|
|
1145
|
-
this.protocolV2RuntimeContext = protocolInfo;
|
|
1146
|
-
return protocolInfo;
|
|
1147
|
-
})();
|
|
1148
|
-
this.protocolV2RuntimeContextRequestToken = requestToken;
|
|
1149
|
-
this.protocolV2RuntimeContextPromise = pendingRequest;
|
|
1150
|
-
|
|
1151
|
-
try {
|
|
1152
|
-
return await pendingRequest;
|
|
1153
|
-
} finally {
|
|
1154
|
-
if (this.protocolV2RuntimeContextPromise === pendingRequest) {
|
|
1155
|
-
this.protocolV2RuntimeContextPromise = undefined;
|
|
1156
|
-
}
|
|
1157
|
-
if (this.protocolV2RuntimeContextRequestToken === requestToken) {
|
|
1158
|
-
this.protocolV2RuntimeContextRequestToken = undefined;
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
}
|
|
1162
|
-
|
|
1163
|
-
async probeProtocolV2RuntimeState(deviceInfo?: ProtocolV2DeviceInfo, timeoutMs?: number) {
|
|
1164
|
-
const protocolInfo = await this.ensureProtocolV2RuntimeContext(timeoutMs);
|
|
1072
|
+
async probeProtocolV2RuntimeState(deviceInfo: ProtocolV2DeviceInfo, timeoutMs?: number) {
|
|
1073
|
+
const protocolInfo = await requestProtocolV2ProtocolInfo({
|
|
1074
|
+
commands: this.commands,
|
|
1075
|
+
timeoutMs,
|
|
1076
|
+
});
|
|
1165
1077
|
const runtimeMode = getProtocolV2RuntimeMode(protocolInfo);
|
|
1166
|
-
const
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
: this.getCurrentDeviceType();
|
|
1078
|
+
const protocolV2DeviceType = resolveProtocolV2DeviceIdentity(
|
|
1079
|
+
deviceInfo.hw?.Device_type
|
|
1080
|
+
).deviceType;
|
|
1170
1081
|
if (runtimeMode === 'romloader' && protocolV2DeviceType !== EDeviceType.Pro2) {
|
|
1171
1082
|
throw ERRORS.TypedError(
|
|
1172
1083
|
HardwareErrorCode.DeviceInitializeFailed,
|
|
@@ -1241,9 +1152,6 @@ export class Device extends EventEmitter {
|
|
|
1241
1152
|
this.deviceAcquired = false;
|
|
1242
1153
|
if (!this.isProtocolV2()) return;
|
|
1243
1154
|
this.protocolV2StateNeedsReload = true;
|
|
1244
|
-
this.protocolV2RuntimeContext = undefined;
|
|
1245
|
-
this.protocolV2RuntimeContextPromise = undefined;
|
|
1246
|
-
this.protocolV2RuntimeContextRequestToken = undefined;
|
|
1247
1155
|
this.clearPreInitialized();
|
|
1248
1156
|
}
|
|
1249
1157
|
|
|
@@ -1252,14 +1160,9 @@ export class Device extends EventEmitter {
|
|
|
1252
1160
|
if (deviceId) {
|
|
1253
1161
|
deviceWalletSessionStore.deleteDevice(deviceId);
|
|
1254
1162
|
}
|
|
1255
|
-
if (this.isProtocolV2()) {
|
|
1256
|
-
|
|
1257
|
-
deviceWalletSessionStore.deleteDevice(this.originalDescriptor.path);
|
|
1258
|
-
}
|
|
1163
|
+
if (this.isProtocolV2() && this.originalDescriptor.path !== deviceId) {
|
|
1164
|
+
deviceWalletSessionStore.deleteDevice(this.originalDescriptor.path);
|
|
1259
1165
|
this.protocolV2StateNeedsReload = true;
|
|
1260
|
-
this.protocolV2RuntimeContext = undefined;
|
|
1261
|
-
this.protocolV2RuntimeContextPromise = undefined;
|
|
1262
|
-
this.protocolV2RuntimeContextRequestToken = undefined;
|
|
1263
1166
|
}
|
|
1264
1167
|
|
|
1265
1168
|
this.passphraseState = undefined;
|
|
@@ -1272,9 +1175,6 @@ export class Device extends EventEmitter {
|
|
|
1272
1175
|
if (!this.isProtocolV2()) return;
|
|
1273
1176
|
|
|
1274
1177
|
this.protocolV2StateNeedsReload = true;
|
|
1275
|
-
this.protocolV2RuntimeContext = undefined;
|
|
1276
|
-
this.protocolV2RuntimeContextPromise = undefined;
|
|
1277
|
-
this.protocolV2RuntimeContextRequestToken = undefined;
|
|
1278
1178
|
this.clearPreInitialized();
|
|
1279
1179
|
let loaderMode: 'bootloader' | 'romloader' | undefined;
|
|
1280
1180
|
if (rebootType === DeviceRebootType.Bootloader) {
|
|
@@ -1381,17 +1281,11 @@ export class Device extends EventEmitter {
|
|
|
1381
1281
|
}
|
|
1382
1282
|
};
|
|
1383
1283
|
|
|
1384
|
-
|
|
1385
|
-
|
|
1386
|
-
await this.release();
|
|
1387
|
-
}
|
|
1388
|
-
|
|
1389
|
-
if (options.forceProtocolDetection || !this.isUsedHere() || this.commands.disposed) {
|
|
1284
|
+
if (!this.isUsedHere() || this.commands.disposed) {
|
|
1285
|
+
const env = DataManager.getSettings('env');
|
|
1390
1286
|
if (env !== 'react-native') {
|
|
1391
1287
|
try {
|
|
1392
|
-
await this.acquire(options.connectProtocol
|
|
1393
|
-
forceProtocolDetection: options.forceProtocolDetection,
|
|
1394
|
-
});
|
|
1288
|
+
await this.acquire(options.connectProtocol);
|
|
1395
1289
|
} catch (error) {
|
|
1396
1290
|
clearRunPromise();
|
|
1397
1291
|
runPromise.reject(error);
|
|
@@ -1633,85 +1527,6 @@ export class Device extends EventEmitter {
|
|
|
1633
1527
|
return res.message;
|
|
1634
1528
|
}
|
|
1635
1529
|
|
|
1636
|
-
beginProtocolV2UiInteraction() {
|
|
1637
|
-
if (!this.isProtocolV2()) return;
|
|
1638
|
-
this.protocolV2UiInteraction = {
|
|
1639
|
-
interactionId: `${this.instanceId}:${Date.now()}:${++this.protocolV2UiInteractionCounter}`,
|
|
1640
|
-
phaseCounter: 0,
|
|
1641
|
-
sequence: 0,
|
|
1642
|
-
opened: false,
|
|
1643
|
-
};
|
|
1644
|
-
}
|
|
1645
|
-
|
|
1646
|
-
createProtocolV2UiPhaseMetadata(
|
|
1647
|
-
phase: HardwareUiInteractionMeta['phase'],
|
|
1648
|
-
transition: HardwareUiInteractionMeta['transition'],
|
|
1649
|
-
options?: {
|
|
1650
|
-
phaseId?: string;
|
|
1651
|
-
outcome?: HardwareUiInteractionMeta['outcome'];
|
|
1652
|
-
}
|
|
1653
|
-
): HardwareUiInteractionMeta | undefined {
|
|
1654
|
-
if (!this.isProtocolV2()) return undefined;
|
|
1655
|
-
if (!this.protocolV2UiInteraction) this.beginProtocolV2UiInteraction();
|
|
1656
|
-
|
|
1657
|
-
const interaction = this.protocolV2UiInteraction;
|
|
1658
|
-
if (!interaction) return undefined;
|
|
1659
|
-
const phaseId =
|
|
1660
|
-
options?.phaseId ?? `${interaction.interactionId}:phase-${++interaction.phaseCounter}`;
|
|
1661
|
-
interaction.opened = true;
|
|
1662
|
-
interaction.sequence += 1;
|
|
1663
|
-
|
|
1664
|
-
return {
|
|
1665
|
-
interactionId: interaction.interactionId,
|
|
1666
|
-
phaseId,
|
|
1667
|
-
sequence: interaction.sequence,
|
|
1668
|
-
phase,
|
|
1669
|
-
transition,
|
|
1670
|
-
...(options?.outcome ? { outcome: options.outcome } : {}),
|
|
1671
|
-
protocol: 'V2',
|
|
1672
|
-
};
|
|
1673
|
-
}
|
|
1674
|
-
|
|
1675
|
-
completeProtocolV2UiPhase(
|
|
1676
|
-
phase: HardwareUiInteractionMeta,
|
|
1677
|
-
outcome: HardwareUiInteractionMeta['outcome'] = 'succeeded'
|
|
1678
|
-
) {
|
|
1679
|
-
return this.createProtocolV2UiPhaseMetadata(phase.phase, 'complete', {
|
|
1680
|
-
phaseId: phase.phaseId,
|
|
1681
|
-
outcome,
|
|
1682
|
-
});
|
|
1683
|
-
}
|
|
1684
|
-
|
|
1685
|
-
finishProtocolV2UiInteraction(
|
|
1686
|
-
outcome?: HardwareUiInteractionMeta['outcome'],
|
|
1687
|
-
options?: { ensureMetadata?: boolean }
|
|
1688
|
-
) {
|
|
1689
|
-
const interaction = this.protocolV2UiInteraction;
|
|
1690
|
-
if (!interaction || (!interaction.opened && !options?.ensureMetadata)) {
|
|
1691
|
-
this.protocolV2UiInteraction = undefined;
|
|
1692
|
-
return undefined;
|
|
1693
|
-
}
|
|
1694
|
-
|
|
1695
|
-
const phaseId = `${interaction.interactionId}:phase-${Math.max(interaction.phaseCounter, 1)}`;
|
|
1696
|
-
interaction.opened = true;
|
|
1697
|
-
interaction.sequence += 1;
|
|
1698
|
-
const metadata: HardwareUiInteractionMeta = {
|
|
1699
|
-
interactionId: interaction.interactionId,
|
|
1700
|
-
phaseId,
|
|
1701
|
-
sequence: interaction.sequence,
|
|
1702
|
-
phase: 'processing',
|
|
1703
|
-
transition: 'finish',
|
|
1704
|
-
outcome: outcome ?? 'succeeded',
|
|
1705
|
-
protocol: 'V2',
|
|
1706
|
-
};
|
|
1707
|
-
this.protocolV2UiInteraction = undefined;
|
|
1708
|
-
return metadata;
|
|
1709
|
-
}
|
|
1710
|
-
|
|
1711
|
-
hasOpenProtocolV2UiInteraction() {
|
|
1712
|
-
return this.protocolV2UiInteraction?.opened === true;
|
|
1713
|
-
}
|
|
1714
|
-
|
|
1715
1530
|
supportUnlockVersionRange(): DeviceFirmwareRange {
|
|
1716
1531
|
// This range applies to Protocol V1 Pro devices; Pro2 has a dedicated unlock flow.
|
|
1717
1532
|
return {
|
|
@@ -1721,33 +1536,10 @@ export class Device extends EventEmitter {
|
|
|
1721
1536
|
};
|
|
1722
1537
|
}
|
|
1723
1538
|
|
|
1724
|
-
async unlockDevice(
|
|
1725
|
-
pinType?: DeviceSessionPinType,
|
|
1726
|
-
options?: ProtocolV2UiEventMetadata & { emitUiEvent?: boolean }
|
|
1727
|
-
) {
|
|
1539
|
+
async unlockDevice(pinType: DeviceSessionPinType = DeviceSessionPinType.Main) {
|
|
1728
1540
|
if (this.isProtocolV2()) {
|
|
1729
|
-
const requestedPinType = pinType ?? DeviceSessionPinType.Main;
|
|
1730
|
-
const interaction =
|
|
1731
|
-
options?.interaction ??
|
|
1732
|
-
(options?.emitUiEvent === false
|
|
1733
|
-
? undefined
|
|
1734
|
-
: this.createProtocolV2UiPhaseMetadata('pin', 'start'));
|
|
1735
|
-
if (options?.emitUiEvent !== false) {
|
|
1736
|
-
this.emit(DEVICE.PIN_ON_DEVICE, this, requestedPinType, {
|
|
1737
|
-
source: options?.source ?? 'unlock-coordinator',
|
|
1738
|
-
reason: options?.reason ?? 'device-unlock',
|
|
1739
|
-
deviceOnly: options?.deviceOnly ?? true,
|
|
1740
|
-
completion: options?.completion,
|
|
1741
|
-
method: options?.method,
|
|
1742
|
-
page: options?.page,
|
|
1743
|
-
operation: options?.operation,
|
|
1744
|
-
interaction: options?.interaction ?? interaction,
|
|
1745
|
-
});
|
|
1746
|
-
}
|
|
1747
1541
|
try {
|
|
1748
|
-
await this.commands.typedCall('DeviceSessionAskPin', 'Success', {
|
|
1749
|
-
type: requestedPinType,
|
|
1750
|
-
});
|
|
1542
|
+
await this.commands.typedCall('DeviceSessionAskPin', 'Success', { type: pinType });
|
|
1751
1543
|
} catch (error) {
|
|
1752
1544
|
const errorText =
|
|
1753
1545
|
error instanceof Error
|
|
@@ -1759,11 +1551,6 @@ export class Device extends EventEmitter {
|
|
|
1759
1551
|
throw error;
|
|
1760
1552
|
}
|
|
1761
1553
|
|
|
1762
|
-
const completion = interaction ? this.completeProtocolV2UiPhase(interaction) : undefined;
|
|
1763
|
-
if (completion) {
|
|
1764
|
-
this.emit(DEVICE.PIN_ON_DEVICE_COMPLETE, this, completion);
|
|
1765
|
-
}
|
|
1766
|
-
|
|
1767
1554
|
const status = await requestProtocolV2DeviceStatus({ commands: this.commands });
|
|
1768
1555
|
return this.updateProtocolV2Status(status);
|
|
1769
1556
|
}
|
|
@@ -1825,8 +1612,7 @@ export class Device extends EventEmitter {
|
|
|
1825
1612
|
async checkPassphraseStateSafety(
|
|
1826
1613
|
passphraseState?: string,
|
|
1827
1614
|
useEmptyPassphrase?: boolean,
|
|
1828
|
-
skipPassphraseCheck?: boolean
|
|
1829
|
-
deriveCardano?: boolean
|
|
1615
|
+
skipPassphraseCheck?: boolean
|
|
1830
1616
|
) {
|
|
1831
1617
|
if (this.isUnacquired()) return false;
|
|
1832
1618
|
|
|
@@ -1835,7 +1621,6 @@ export class Device extends EventEmitter {
|
|
|
1835
1621
|
await getPassphraseStateWithRefreshDeviceInfo(this, {
|
|
1836
1622
|
expectPassphraseState: expectedPassphraseState,
|
|
1837
1623
|
onlyMainPin: useEmptyPassphrase,
|
|
1838
|
-
deriveCardano,
|
|
1839
1624
|
});
|
|
1840
1625
|
|
|
1841
1626
|
// Main wallet and unlock Attach Pin, throw safe error
|
package/src/device/DevicePool.ts
CHANGED
|
@@ -156,9 +156,7 @@ export class DevicePool extends EventEmitter {
|
|
|
156
156
|
if (!device) {
|
|
157
157
|
device = Device.fromDescriptor(descriptor);
|
|
158
158
|
device.deviceConnector = this.connector;
|
|
159
|
-
await device.connect(initOptions?.connectProtocol
|
|
160
|
-
forceProtocolDetection: initOptions?.forceProtocolDetection,
|
|
161
|
-
});
|
|
159
|
+
await device.connect(initOptions?.connectProtocol);
|
|
162
160
|
try {
|
|
163
161
|
await device.initialize(initOptions);
|
|
164
162
|
if (initOptions?.refreshRuntimeState && device.isProtocolV2()) {
|
|
@@ -183,10 +181,7 @@ export class DevicePool extends EventEmitter {
|
|
|
183
181
|
refreshError = error;
|
|
184
182
|
}
|
|
185
183
|
},
|
|
186
|
-
{
|
|
187
|
-
connectProtocol: initOptions.connectProtocol,
|
|
188
|
-
forceProtocolDetection: initOptions.forceProtocolDetection,
|
|
189
|
-
}
|
|
184
|
+
{ connectProtocol: initOptions.connectProtocol }
|
|
190
185
|
);
|
|
191
186
|
if (refreshError instanceof Error) throw refreshError;
|
|
192
187
|
if (refreshError) throw new Error(String(refreshError));
|
package/src/events/device.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { MessageFactoryFn } from './utils';
|
|
2
|
-
import type { HardwareUiInteractionMeta } from './ui-request';
|
|
3
2
|
import type { PROTO } from '../constants';
|
|
4
3
|
import type {
|
|
5
4
|
KnownDevice as Device,
|
|
@@ -27,8 +26,6 @@ export const DEVICE = {
|
|
|
27
26
|
// onekey-transport events in protobuf format
|
|
28
27
|
BUTTON: 'button',
|
|
29
28
|
PIN: 'pin',
|
|
30
|
-
PIN_ON_DEVICE: 'pin_on_device',
|
|
31
|
-
PIN_ON_DEVICE_COMPLETE: 'pin_on_device_complete',
|
|
32
29
|
PASSPHRASE: 'passphrase',
|
|
33
30
|
PASSPHRASE_ON_DEVICE: 'passphrase_on_device',
|
|
34
31
|
ATTACH_PIN_ON_DEVICE: 'attach_pin_on_device',
|
|
@@ -61,7 +58,6 @@ export type PassphraseRequestPayload = {
|
|
|
61
58
|
source?: 'wallet-session-coordinator';
|
|
62
59
|
reason?: 'open-wallet' | 'session-recovery';
|
|
63
60
|
expectedPassphraseState?: string;
|
|
64
|
-
interaction?: HardwareUiInteractionMeta;
|
|
65
61
|
};
|
|
66
62
|
|
|
67
63
|
export interface DeviceButtonRequest {
|
package/src/events/ui-promise.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Deferred } from '@onekeyfe/hd-shared';
|
|
2
2
|
import type { DEVICE } from './device';
|
|
3
3
|
import type { Device } from '../device/Device';
|
|
4
|
-
import type {
|
|
4
|
+
import type { UiResponseEvent } from './ui-response';
|
|
5
5
|
|
|
6
6
|
export type UiPromiseResponse =
|
|
7
7
|
| UiResponseEvent
|
|
@@ -11,6 +11,4 @@ export type UiPromise<T extends UiPromiseResponse['type']> = Deferred<
|
|
|
11
11
|
Extract<UiPromiseResponse, { type: T }>,
|
|
12
12
|
T,
|
|
13
13
|
Device
|
|
14
|
-
|
|
15
|
-
responseCorrelation?: UiResponseCorrelation;
|
|
16
|
-
};
|
|
14
|
+
>;
|
package/src/events/ui-request.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { PROTO } from '../constants';
|
|
2
2
|
import type { Device } from '../types';
|
|
3
3
|
import type { DeviceButtonRequest } from './device';
|
|
4
|
-
import type { UiResponseCorrelation } from './ui-response';
|
|
5
4
|
import type { MessageFactoryFn } from './utils';
|
|
6
5
|
|
|
7
6
|
export const UI_EVENT = 'UI_EVENT';
|
|
@@ -57,17 +56,6 @@ export type ProtocolV2UiEventSource =
|
|
|
57
56
|
|
|
58
57
|
export type ProtocolV2UiCompletion = 'page-accepted' | 'operation-completed';
|
|
59
58
|
|
|
60
|
-
export type HardwareUiInteractionMeta = {
|
|
61
|
-
interactionId: string;
|
|
62
|
-
phaseId: string;
|
|
63
|
-
sequence: number;
|
|
64
|
-
phase: 'pin' | 'passphrase' | 'passphrase-on-device' | 'button' | 'processing';
|
|
65
|
-
transition: 'start' | 'complete' | 'finish';
|
|
66
|
-
outcome?: 'submitted' | 'succeeded' | 'failed' | 'cancelled' | 'disconnected';
|
|
67
|
-
protocol: 'V2';
|
|
68
|
-
device?: Device;
|
|
69
|
-
};
|
|
70
|
-
|
|
71
59
|
export type ProtocolV2UiEventMetadata = {
|
|
72
60
|
source?: ProtocolV2UiEventSource;
|
|
73
61
|
reason?: string;
|
|
@@ -76,29 +64,12 @@ export type ProtocolV2UiEventMetadata = {
|
|
|
76
64
|
method?: string;
|
|
77
65
|
page?: string | number;
|
|
78
66
|
operation?: string;
|
|
79
|
-
interaction?: HardwareUiInteractionMeta;
|
|
80
67
|
};
|
|
81
68
|
|
|
82
|
-
export type UiRequestWindowClose =
|
|
83
|
-
| {
|
|
84
|
-
type: typeof UI_REQUEST.CLOSE_UI_WINDOW;
|
|
85
|
-
payload: HardwareUiInteractionMeta;
|
|
86
|
-
}
|
|
87
|
-
| {
|
|
88
|
-
type: typeof UI_REQUEST.CLOSE_UI_PIN_WINDOW;
|
|
89
|
-
payload: HardwareUiInteractionMeta;
|
|
90
|
-
}
|
|
91
|
-
| {
|
|
92
|
-
type: typeof UI_REQUEST.CLOSE_UI_WINDOW;
|
|
93
|
-
payload?: undefined;
|
|
94
|
-
}
|
|
95
|
-
| {
|
|
96
|
-
type: typeof UI_REQUEST.CLOSE_UI_PIN_WINDOW;
|
|
97
|
-
payload?: undefined;
|
|
98
|
-
};
|
|
99
|
-
|
|
100
69
|
export interface UiRequestWithoutPayload {
|
|
101
70
|
type:
|
|
71
|
+
| typeof UI_REQUEST.CLOSE_UI_WINDOW
|
|
72
|
+
| typeof UI_REQUEST.CLOSE_UI_PIN_WINDOW
|
|
102
73
|
| typeof UI_REQUEST.BLUETOOTH_PERMISSION
|
|
103
74
|
| typeof UI_REQUEST.BLUETOOTH_UNSUPPORTED
|
|
104
75
|
| typeof UI_REQUEST.BLUETOOTH_POWERED_OFF
|
|
@@ -122,7 +93,6 @@ export type UiRequestDeviceAction = {
|
|
|
122
93
|
payload: ProtocolV2UiEventMetadata & {
|
|
123
94
|
device: Device;
|
|
124
95
|
type?: PROTO.PinMatrixRequestType | 'ButtonRequest_PinEntry' | 'ButtonRequest_AttachPin';
|
|
125
|
-
responseCorrelation?: UiResponseCorrelation;
|
|
126
96
|
};
|
|
127
97
|
};
|
|
128
98
|
|
|
@@ -141,8 +111,6 @@ export interface UiRequestPassphrase {
|
|
|
141
111
|
source?: 'wallet-session-coordinator';
|
|
142
112
|
reason?: 'open-wallet' | 'session-recovery';
|
|
143
113
|
expectedPassphraseState?: string;
|
|
144
|
-
interaction?: HardwareUiInteractionMeta;
|
|
145
|
-
responseCorrelation?: UiResponseCorrelation;
|
|
146
114
|
};
|
|
147
115
|
}
|
|
148
116
|
|
|
@@ -153,7 +121,6 @@ export interface UiRequestPassphraseOnDevice {
|
|
|
153
121
|
passphraseState?: string;
|
|
154
122
|
source?: 'wallet-session-coordinator';
|
|
155
123
|
reason?: 'open-wallet' | 'session-recovery';
|
|
156
|
-
interaction?: HardwareUiInteractionMeta;
|
|
157
124
|
};
|
|
158
125
|
}
|
|
159
126
|
|
|
@@ -224,7 +191,6 @@ export interface PreviousAddressResult {
|
|
|
224
191
|
|
|
225
192
|
export type UiEvent =
|
|
226
193
|
| UiRequestWithoutPayload
|
|
227
|
-
| UiRequestWindowClose
|
|
228
194
|
| UiRequestDeviceAction
|
|
229
195
|
| UiRequestButton
|
|
230
196
|
| UiRequestPassphraseOnDevice
|
|
@@ -11,22 +11,12 @@ export const UI_RESPONSE = {
|
|
|
11
11
|
'ui-receive_select-device-for-switch-firmware-web-device',
|
|
12
12
|
} as const;
|
|
13
13
|
|
|
14
|
-
export interface
|
|
15
|
-
interactionId: string;
|
|
16
|
-
deviceId: string;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface UiResponseCorrelationFields {
|
|
20
|
-
interactionId?: string;
|
|
21
|
-
deviceId?: string;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export interface UiResponsePin extends UiResponseCorrelationFields {
|
|
14
|
+
export interface UiResponsePin {
|
|
25
15
|
type: typeof UI_RESPONSE.RECEIVE_PIN;
|
|
26
16
|
payload: string;
|
|
27
17
|
}
|
|
28
18
|
|
|
29
|
-
export interface UiResponsePassphrase
|
|
19
|
+
export interface UiResponsePassphrase {
|
|
30
20
|
type: typeof UI_RESPONSE.RECEIVE_PASSPHRASE;
|
|
31
21
|
payload: {
|
|
32
22
|
value: string;
|
package/src/index.ts
CHANGED
|
@@ -19,6 +19,11 @@ export * from './types';
|
|
|
19
19
|
export { whitelist, whitelistExtension } from './data/config';
|
|
20
20
|
export { executeCallback, cleanupCallback };
|
|
21
21
|
export { preloadSessionCache } from './device/Device';
|
|
22
|
+
export {
|
|
23
|
+
getFirmwareUpdateHostBindingGeneration,
|
|
24
|
+
registerFirmwareUpdateHostBinding,
|
|
25
|
+
unregisterFirmwareUpdateHostBinding,
|
|
26
|
+
} from './api/firmware/FirmwareHostBinding';
|
|
22
27
|
|
|
23
28
|
const HardwareSdk = ({
|
|
24
29
|
init,
|