@onekeyfe/hd-core 1.2.8-alpha.20 → 1.2.8-alpha.21

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.
@@ -1,4 +1,7 @@
1
- import Core, { initConnector } from '../src/core';
1
+ import { HardwareErrorCode, createDeferred } from '@onekeyfe/hd-shared';
2
+
3
+ import Core, { init, initConnector, initCore, switchTransport } from '../src/core';
4
+ import DataManager from '../src/data-manager/DataManager';
2
5
  import TransportManager from '../src/data-manager/TransportManager';
3
6
  import { DevicePool } from '../src/device/DevicePool';
4
7
 
@@ -31,4 +34,114 @@ describe('Core.dispose', () => {
31
34
  expect(transportStop).toHaveBeenCalledTimes(1);
32
35
  expect(disposeDevicePool).toHaveBeenCalledTimes(1);
33
36
  });
37
+
38
+ test('disposal rejects a queued switch without recreating a transport or connector', async () => {
39
+ const previous = TransportManager.transport;
40
+ const { settings } = DataManager;
41
+ const active = { stop: jest.fn().mockResolvedValue(undefined) };
42
+ const replacement = jest.fn(() => ({ stop: jest.fn().mockResolvedValue(undefined) }));
43
+ TransportManager.transport = active as never;
44
+ const core = initCore();
45
+ initConnector();
46
+ const switching = switchTransport({ env: 'emulator', Transport: replacement });
47
+ const rejected = expect(switching).rejects.toMatchObject({
48
+ errorCode: HardwareErrorCode.NotInitialized,
49
+ });
50
+ try {
51
+ await core.dispose();
52
+ await rejected;
53
+ expect(replacement).not.toHaveBeenCalled();
54
+ expect(TransportManager.transport).toBe(active);
55
+ expect(DataManager.settings).toBe(settings);
56
+ expect(DevicePool.emitter.eventNames()).toHaveLength(0);
57
+ } finally {
58
+ await Promise.allSettled([switching]);
59
+ await core.dispose();
60
+ TransportManager.transport = previous;
61
+ DataManager.settings = settings;
62
+ }
63
+ });
64
+
65
+ test.each(['dispose/reinit', 'init', 'initCore'] as const)(
66
+ '%s invalidates running and queued switches without blocking a new lifecycle',
67
+ async lifecycle => {
68
+ const previous = TransportManager.transport;
69
+ const { settings } = DataManager;
70
+ const entered = createDeferred<void>();
71
+ const closing = createDeferred<void>();
72
+ const loading = createDeferred<void>();
73
+ const active = {
74
+ stop: jest.fn(() => {
75
+ entered.resolve();
76
+ return closing.promise;
77
+ }),
78
+ };
79
+ const intermediate = jest.fn(() => ({ stop: jest.fn().mockResolvedValue(undefined) }));
80
+ const stale = jest.fn(() => ({ stop: jest.fn().mockResolvedValue(undefined) }));
81
+ const fresh = { stop: jest.fn().mockResolvedValue(undefined) };
82
+ const current = { stop: jest.fn().mockResolvedValue(undefined) };
83
+ const Fresh = jest.fn(() => fresh);
84
+ jest.spyOn(DataManager, 'load').mockImplementation(async next => {
85
+ await loading.promise;
86
+ DataManager.settings = next;
87
+ });
88
+ TransportManager.transport = active as never;
89
+ let core = initCore();
90
+ initConnector();
91
+ const first = switchTransport({ env: 'emulator', Transport: intermediate });
92
+ await entered.promise;
93
+ const second = switchTransport({ env: 'webusb', Transport: stale });
94
+ const rejected = Promise.all([
95
+ expect(first).rejects.toMatchObject({ errorCode: HardwareErrorCode.NotInitialized }),
96
+ expect(second).rejects.toMatchObject({ errorCode: HardwareErrorCode.NotInitialized }),
97
+ ]);
98
+ rejected.catch(() => undefined);
99
+ let initializing: ReturnType<typeof init> | undefined;
100
+ try {
101
+ if (lifecycle === 'dispose/reinit') {
102
+ const disposing = core.dispose();
103
+ closing.resolve();
104
+ await disposing;
105
+ }
106
+ if (lifecycle === 'initCore') {
107
+ TransportManager.transport = fresh as never;
108
+ DataManager.settings = { ...settings, env: 'desktop-web-ble' };
109
+ core = initCore();
110
+ initConnector();
111
+ } else {
112
+ initializing = init({ ...settings, env: 'desktop-web-ble' }, Fresh);
113
+ if (lifecycle === 'init') {
114
+ closing.resolve();
115
+ await rejected;
116
+ }
117
+ loading.resolve();
118
+ const initialized = await initializing;
119
+ if (!initialized) throw new Error('Core initialization failed');
120
+ core = initialized;
121
+ }
122
+ await switchTransport({
123
+ env: 'emulator',
124
+ Transport: function Current() {
125
+ return current;
126
+ },
127
+ });
128
+ closing.resolve();
129
+ await rejected;
130
+ expect(intermediate).not.toHaveBeenCalled();
131
+ expect(stale).not.toHaveBeenCalled();
132
+ expect(TransportManager.transport).toBe(current);
133
+ expect(DataManager.getSettings('env')).toBe('emulator');
134
+ expect(fresh.stop).toHaveBeenCalledTimes(1);
135
+ expect(current.stop).not.toHaveBeenCalled();
136
+ } finally {
137
+ closing.resolve();
138
+ loading.resolve();
139
+ await initializing;
140
+ await Promise.allSettled([first, second, rejected]);
141
+ await core.dispose();
142
+ TransportManager.transport = previous;
143
+ DataManager.settings = settings;
144
+ }
145
+ }
146
+ );
34
147
  });
@@ -45,6 +45,23 @@ describe('Core 错误输出边界', () => {
45
45
  });
46
46
  });
47
47
 
48
+ test.each([
49
+ [HardwareErrorCode.TransportProtocolProbeFailed, { expectedProtocol: 'V1' }],
50
+ [
51
+ HardwareErrorCode.TransportProtocolMismatch,
52
+ { expectedProtocol: 'V2', detectedProtocol: 'V1' },
53
+ ],
54
+ ] as const)(
55
+ 'preserves protocol error %s and structured context across the public boundary',
56
+ (code, params) => {
57
+ const error = ERRORS.TypedError(code, undefined, params);
58
+ expect(JSON.parse(JSON.stringify(createErrorMessage(error)))).toEqual({
59
+ success: false,
60
+ payload: { code, error: error.message, params },
61
+ });
62
+ }
63
+ );
64
+
48
65
  test.each([
49
66
  ['webusb', false],
50
67
  ['desktop-webusb', false],
@@ -129,6 +146,8 @@ describe('Core 错误输出边界', () => {
129
146
  HardwareErrorCode.BleUnsupported,
130
147
  HardwareErrorCode.BridgeNeedsPermission,
131
148
  HardwareErrorCode.WebUsbDeviceAccessError,
149
+ HardwareErrorCode.TransportProtocolProbeFailed,
150
+ HardwareErrorCode.TransportProtocolMismatch,
132
151
  ])(
133
152
  'preserves terminal transport error %s in the public response without polling again',
134
153
  async errorCode => {
@@ -138,6 +157,8 @@ describe('Core 错误输出边界', () => {
138
157
  [
139
158
  HardwareErrorCode.BridgeNeedsPermission,
140
159
  HardwareErrorCode.WebUsbDeviceAccessError,
160
+ HardwareErrorCode.TransportProtocolProbeFailed,
161
+ HardwareErrorCode.TransportProtocolMismatch,
141
162
  ].includes(errorCode)
142
163
  ? ('desktop-webusb' as never)
143
164
  : ('react-native' as never)
@@ -75,8 +75,11 @@ describe('DeviceConnector protocol validation', () => {
75
75
  });
76
76
  const connector = new DeviceConnector();
77
77
 
78
- await expect(connector.acquire('classic-id', undefined, undefined, 'V2')).rejects.toThrow(
79
- 'Device protocol mismatch: expected V2, detected V1'
78
+ await expect(connector.acquire('classic-id', undefined, undefined, 'V2')).rejects.toMatchObject(
79
+ {
80
+ errorCode: HardwareErrorCode.TransportProtocolMismatch,
81
+ params: { expectedProtocol: 'V2', detectedProtocol: 'V1' },
82
+ }
80
83
  );
81
84
  });
82
85
 
@@ -610,7 +610,9 @@ describe('public device lifecycle events', () => {
610
610
  );
611
611
 
612
612
  test.each([
613
- [HardwareErrorCode.RuntimeError, true],
613
+ [HardwareErrorCode.TransportProtocolProbeFailed, true],
614
+ [HardwareErrorCode.TransportProtocolMismatch, false],
615
+ [HardwareErrorCode.RuntimeError, false],
614
616
  [HardwareErrorCode.BleDeviceBondError, false],
615
617
  ] as const)(
616
618
  'retries a Protocol V2 probe mismatch with error code %s: %s',
@@ -618,8 +620,8 @@ describe('public device lifecycle events', () => {
618
620
  const method = { payload: { connectProtocol: 'V2' } } as never;
619
621
  const error = {
620
622
  errorCode,
621
- message:
622
- 'Device protocol mismatch: expected V2, but device did not respond to expected protocol',
623
+ message: 'diagnostic wording is not used for classification',
624
+ params: { expectedProtocol: 'V2' },
623
625
  };
624
626
 
625
627
  expect(isRetryableBleProtocolV2ProbeError(method, error)).toBe(expected);
@@ -629,6 +631,8 @@ describe('public device lifecycle events', () => {
629
631
  test.each([
630
632
  [HardwareErrorCode.BleConnectedError, true],
631
633
  [HardwareErrorCode.BleTimeoutError, true],
634
+ [HardwareErrorCode.TransportProtocolProbeFailed, true],
635
+ [HardwareErrorCode.TransportProtocolMismatch, false],
632
636
  [HardwareErrorCode.PollingTimeout, false],
633
637
  [HardwareErrorCode.BleDeviceBondError, false],
634
638
  ] as const)('retries a BLE connection error with error code %s: %s', (errorCode, expected) => {
@@ -641,6 +645,21 @@ describe('public device lifecycle events', () => {
641
645
  expect(isRetryableBleConnectionError(method, error)).toBe(expected);
642
646
  });
643
647
 
648
+ test('does not retry a failed strict V1 probe as a V2 probe or after user cancellation', () => {
649
+ const error = ERRORS.TypedError(HardwareErrorCode.TransportProtocolProbeFailed, undefined, {
650
+ expectedProtocol: 'V1',
651
+ });
652
+ const method = { payload: { connectProtocol: 'V2' } } as never;
653
+ expect(isRetryableBleProtocolV2ProbeError(method, error)).toBe(false);
654
+ expect(isRetryableBleConnectionError(method, error)).toBe(false);
655
+ expect(
656
+ isRetryableBleConnectionError(
657
+ { payload: {}, device: { wasInterruptedByUser: () => true } } as never,
658
+ ERRORS.TypedError(HardwareErrorCode.TransportProtocolProbeFailed)
659
+ )
660
+ ).toBe(false);
661
+ });
662
+
644
663
  test('does not retry the desktop acquire deadline fallback', () => {
645
664
  const method = { payload: { connectProtocol: 'V2' } } as never;
646
665
  const error = {
@@ -1 +1 @@
1
- {"version":3,"file":"FirmwareUpdateV4.d.ts","sourceRoot":"","sources":["../../src/api/FirmwareUpdateV4.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAkD,MAAM,qBAAqB,CAAC;AA0BlG,OAAO,EAAE,wBAAwB,EAAE,MAAM,qCAAqC,CAAC;AAiC/E,OAAO,KAAK,EAEV,sBAAsB,EAEvB,MAAM,6BAA6B,CAAC;AAuErC,wBAAgB,wCAAwC,CACtD,UAAU,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,EAC5C,MAAM,EAAE,sBAAsB,EAC9B,0BAA0B,UAAQ,QAiCnC;AA6UD,eAAO,MAAM,oCAAoC,WACvC,WAAW,GAAG,UAAU,eACnB,MAAM,GAAG,SAAS,YAKhC,CAAC;AAEF,eAAO,MAAM,iCAAiC,0BACrB,MAAM,uBACR,MAA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c,CAAoB;IAE1C,SAAgB,aAAa,EAAE,MAAM,CAAC;IAEtC,OAAO,CAAC,YAAY,CAAsB;IAE1C,yBAAyB,CAAC,UAAU,EAAE,UAAU,CAAC,OAAO,yBAAyB,CAAC,CAAC,CAAC,CAAC;IAIrF,OAAO,CAAC,cAAc,CAAC,CAAgB;IAGvC,OAAO,CAAC,sBAAsB,CAAoC;IAElE,OAAO,CAAC,iBAAiB,CAAoB;;IAS7C,OAAO,CAAC,cAAc;IAuChB,aAAa,CAAC,OAAO,EAAE,WAAW;IAuExC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAOV,gBAAgB;CAmC/B;AAED,eAAO,MAAM,QAAQ,YAMpB,CAAC;AAEF,eAAO,MAAM,aAAa,uBAYzB,CAAC;AAMF,eAAO,MAAM,IAAI,aACL,eAAe,aACd,GAAG,WACL,6BAA6B,8BAmBvC,CAAC;AAEF,eAAO,MAAM,eAAe;SAKrB,eAAe,CAAC,KAAK,CAAC;eAChB,GAAG;;mBAyBf,CAAC"}
@@ -31,7 +31,7 @@ export declare const cancelDeviceInPrompt: (device: Device, expectResponse?: boo
31
31
  };
32
32
  } | {
33
33
  success: boolean;
34
- error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 830 | 831 | 832 | 900 | 901 | 902 | 903;
34
+ error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 604 | 605 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 830 | 831 | 832 | 900 | 901 | 902 | 903;
35
35
  payload: {
36
36
  message: string;
37
37
  };
@@ -50,7 +50,7 @@ export declare const cancelDeviceWithInitialize: (device: Device) => Promise<{
50
50
  };
51
51
  } | {
52
52
  success: boolean;
53
- error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 830 | 831 | 832 | 900 | 901 | 902 | 903;
53
+ error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 604 | 605 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 830 | 831 | 832 | 900 | 901 | 902 | 903;
54
54
  payload: {
55
55
  message: string;
56
56
  };
@@ -81,7 +81,7 @@ export declare class DeviceCommands {
81
81
  };
82
82
  } | {
83
83
  success: boolean;
84
- error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 830 | 831 | 832 | 900 | 901 | 902 | 903;
84
+ error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 604 | 605 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 830 | 831 | 832 | 900 | 901 | 902 | 903;
85
85
  payload: {
86
86
  message: string;
87
87
  };
@@ -100,7 +100,7 @@ export declare class DeviceCommands {
100
100
  };
101
101
  } | {
102
102
  success: boolean;
103
- error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 830 | 831 | 832 | 900 | 901 | 902 | 903;
103
+ error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 604 | 605 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 830 | 831 | 832 | 900 | 901 | 902 | 903;
104
104
  payload: {
105
105
  message: string;
106
106
  };
package/dist/index.d.ts CHANGED
@@ -145,7 +145,7 @@ declare class DeviceCommands {
145
145
  };
146
146
  } | {
147
147
  success: boolean;
148
- error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 830 | 831 | 832 | 900 | 901 | 902 | 903;
148
+ error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 604 | 605 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 830 | 831 | 832 | 900 | 901 | 902 | 903;
149
149
  payload: {
150
150
  message: string;
151
151
  };
@@ -164,7 +164,7 @@ declare class DeviceCommands {
164
164
  };
165
165
  } | {
166
166
  success: boolean;
167
- error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 830 | 831 | 832 | 900 | 901 | 902 | 903;
167
+ error: 0 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 200 | 300 | 301 | 302 | 303 | 304 | 305 | 400 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 500 | 600 | 601 | 602 | 603 | 604 | 605 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 830 | 831 | 832 | 900 | 901 | 902 | 903;
168
168
  payload: {
169
169
  message: string;
170
170
  };
package/dist/index.js CHANGED
@@ -52757,9 +52757,10 @@ const PROTOCOL_V2_TARGET_STATUS_BY_DECODED_NAME = new Map([
52757
52757
  ['FW_MGMT_UPDATER_TASK_STATUS_FAILED_ENTRY_OUT_OF_BOUNDS', 10],
52758
52758
  ]);
52759
52759
  const isProtocolV2ReconnectProbeError = (error) => {
52760
- const message = getProtocolV2UnknownErrorText(error).toLowerCase();
52761
- return ((message.includes('device protocol mismatch') && message.includes('expected v2')) ||
52762
- message.includes('did not respond to expected protocol'));
52760
+ var _a;
52761
+ return getProtocolV2ErrorCode(error) === hdShared.HardwareErrorCode.TransportProtocolProbeFailed &&
52762
+ ((_a = error === null || error === void 0 ? void 0 : error.params) === null || _a === void 0 ? void 0 : _a.expectedProtocol) ===
52763
+ 'V2';
52763
52764
  };
52764
52765
  const isProtocolV2FirmwareStatusEndpointUnavailable = (error) => {
52765
52766
  const message = getProtocolV2UnknownErrorText(error).toLowerCase();
@@ -65959,7 +65960,10 @@ class DeviceConnector {
65959
65960
  : undefined;
65960
65961
  const detectedProtocol = acquiredProtocol !== null && acquiredProtocol !== void 0 ? acquiredProtocol : transport.getProtocolType(path);
65961
65962
  if (detectedProtocol !== expectedProtocol) {
65962
- throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.RuntimeError, `Device protocol mismatch: expected ${expectedProtocol}, detected ${detectedProtocol}`);
65963
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportProtocolMismatch, undefined, {
65964
+ expectedProtocol,
65965
+ detectedProtocol,
65966
+ });
65963
65967
  }
65964
65968
  }
65965
65969
  return res;
@@ -66290,6 +66294,8 @@ const parseInitOptions = (method) => ({
66290
66294
  protocolV2DeviceInfoTimeoutMs: method === null || method === void 0 ? void 0 : method.payload.protocolV2DeviceInfoTimeoutMs,
66291
66295
  });
66292
66296
  let _core;
66297
+ let transportSwitchGeneration = 0;
66298
+ let pendingTransportSwitch = Promise.resolve();
66293
66299
  let _deviceList;
66294
66300
  let _connector;
66295
66301
  let _uiPromises = [];
@@ -66903,16 +66909,14 @@ function canSkipInitialize(method, device) {
66903
66909
  return true;
66904
66910
  }
66905
66911
  function isRetryableBleProtocolV2ProbeError(method, error) {
66912
+ var _a;
66906
66913
  const typedError = error;
66907
- const message = typeof (typedError === null || typedError === void 0 ? void 0 : typedError.message) === 'string' ? typedError.message : String(error !== null && error !== void 0 ? error : '');
66908
66914
  return (method.payload.connectProtocol === 'V2' &&
66909
- (typedError === null || typedError === void 0 ? void 0 : typedError.errorCode) === hdShared.HardwareErrorCode.RuntimeError &&
66910
- message.includes('Device protocol mismatch') &&
66911
- message.includes('expected V2') &&
66912
- message.includes('did not respond to expected protocol'));
66915
+ (typedError === null || typedError === void 0 ? void 0 : typedError.errorCode) === hdShared.HardwareErrorCode.TransportProtocolProbeFailed &&
66916
+ ((_a = typedError.params) === null || _a === void 0 ? void 0 : _a.expectedProtocol) === 'V2');
66913
66917
  }
66914
66918
  function isRetryableBleConnectionError(method, error) {
66915
- var _a, _b;
66919
+ var _a, _b, _c;
66916
66920
  if ((_a = method.device) === null || _a === void 0 ? void 0 : _a.wasInterruptedByUser()) {
66917
66921
  return false;
66918
66922
  }
@@ -66923,6 +66927,8 @@ function isRetryableBleConnectionError(method, error) {
66923
66927
  }
66924
66928
  return ((typedError === null || typedError === void 0 ? void 0 : typedError.errorCode) === hdShared.HardwareErrorCode.BleTimeoutError ||
66925
66929
  (typedError === null || typedError === void 0 ? void 0 : typedError.errorCode) === hdShared.HardwareErrorCode.BleConnectedError ||
66930
+ ((typedError === null || typedError === void 0 ? void 0 : typedError.errorCode) === hdShared.HardwareErrorCode.TransportProtocolProbeFailed &&
66931
+ !((_c = typedError.params) === null || _c === void 0 ? void 0 : _c.expectedProtocol)) ||
66926
66932
  isRetryableBleProtocolV2ProbeError(method, error) ||
66927
66933
  isMissingDetectedProtocolV2Error(method, error));
66928
66934
  }
@@ -67098,6 +67104,8 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
67098
67104
  hdShared.HardwareErrorCode.BridgeTimeoutError,
67099
67105
  hdShared.HardwareErrorCode.BridgeNeedsPermission,
67100
67106
  hdShared.HardwareErrorCode.WebUsbDeviceAccessError,
67107
+ hdShared.HardwareErrorCode.TransportProtocolProbeFailed,
67108
+ hdShared.HardwareErrorCode.TransportProtocolMismatch,
67101
67109
  ].includes(error.errorCode)) {
67102
67110
  _deviceList = undefined;
67103
67111
  reject(error);
@@ -67173,6 +67181,8 @@ const ensureConnected = (_context, method, connectId, pollingId, abortSignal) =>
67173
67181
  hdShared.HardwareErrorCode.BleCharacteristicNotifyChangeFailure,
67174
67182
  hdShared.HardwareErrorCode.BridgeNeedsPermission,
67175
67183
  hdShared.HardwareErrorCode.WebUsbDeviceAccessError,
67184
+ hdShared.HardwareErrorCode.TransportProtocolProbeFailed,
67185
+ hdShared.HardwareErrorCode.TransportProtocolMismatch,
67176
67186
  hdShared.HardwareErrorCode.DeviceInterruptedFromUser,
67177
67187
  hdShared.HardwareErrorCode.CallQueueActionCancelled,
67178
67188
  ].includes(error.errorCode) ||
@@ -67564,6 +67574,8 @@ class Core extends events.exports {
67564
67574
  var _a, _b;
67565
67575
  return __awaiter(this, void 0, void 0, function* () {
67566
67576
  Log.debug(`[Core] Disposing SDK instance: ${this.sdkInstanceId}`);
67577
+ transportSwitchGeneration += 1;
67578
+ pendingTransportSwitch = Promise.resolve();
67567
67579
  pollingManager.stopAll();
67568
67580
  this.requestQueue.abortAllRequests();
67569
67581
  cleanup();
@@ -67595,6 +67607,8 @@ class Core extends events.exports {
67595
67607
  }
67596
67608
  }
67597
67609
  const initCore = () => {
67610
+ transportSwitchGeneration += 1;
67611
+ pendingTransportSwitch = Promise.resolve();
67598
67612
  const core = new Core();
67599
67613
  _core = core;
67600
67614
  return core;
@@ -67614,6 +67628,8 @@ const initTransport = (Transport, plugin) => {
67614
67628
  };
67615
67629
  const init = (settings, Transport, plugin) => __awaiter(void 0, void 0, void 0, function* () {
67616
67630
  try {
67631
+ transportSwitchGeneration += 1;
67632
+ pendingTransportSwitch = Promise.resolve();
67617
67633
  yield DataManager.load(settings);
67618
67634
  initTransport(Transport, plugin);
67619
67635
  enableLog(DataManager.getSettings('debug'));
@@ -67629,14 +67645,20 @@ const init = (settings, Transport, plugin) => __awaiter(void 0, void 0, void 0,
67629
67645
  throw error;
67630
67646
  }
67631
67647
  });
67632
- let pendingTransportSwitch = Promise.resolve();
67633
67648
  const switchTransport = ({ env, Transport, plugin, }) => {
67649
+ const generation = transportSwitchGeneration;
67634
67650
  const switching = pendingTransportSwitch
67635
67651
  .catch(() => undefined)
67636
67652
  .then(() => __awaiter(void 0, void 0, void 0, function* () {
67637
67653
  var _a, _b;
67654
+ if (generation !== transportSwitchGeneration) {
67655
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.NotInitialized);
67656
+ }
67638
67657
  _connector === null || _connector === void 0 ? void 0 : _connector.stop();
67639
67658
  yield ((_b = (_a = TransportManager.getTransport()) === null || _a === void 0 ? void 0 : _a.stop) === null || _b === void 0 ? void 0 : _b.call(_a));
67659
+ if (generation !== transportSwitchGeneration) {
67660
+ throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.NotInitialized);
67661
+ }
67640
67662
  DataManager.updateEnv(env);
67641
67663
  TransportManager.setTransport(Transport, plugin);
67642
67664
  _deviceList = undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.2.8-alpha.20",
3
+ "version": "1.2.8-alpha.21",
4
4
  "description": "Core processes and APIs for communicating with OneKey hardware devices.",
5
5
  "author": "OneKey",
6
6
  "homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -25,8 +25,8 @@
25
25
  "url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
26
26
  },
27
27
  "dependencies": {
28
- "@onekeyfe/hd-shared": "1.2.8-alpha.20",
29
- "@onekeyfe/hd-transport": "1.2.8-alpha.20",
28
+ "@onekeyfe/hd-shared": "1.2.8-alpha.21",
29
+ "@onekeyfe/hd-transport": "1.2.8-alpha.21",
30
30
  "axios": "1.15.2",
31
31
  "bignumber.js": "^9.0.2",
32
32
  "buffer": "^6.0.3",
@@ -46,5 +46,5 @@
46
46
  "@types/w3c-web-usb": "^1.0.10",
47
47
  "@types/web-bluetooth": "^0.0.21"
48
48
  },
49
- "gitHead": "973f059fe93a58fdcf098ddb32ba63f621a2c78e"
49
+ "gitHead": "acc31b02db0a507a597775fc88306c9104c1b5d1"
50
50
  }
@@ -352,13 +352,10 @@ const PROTOCOL_V2_TARGET_STATUS_BY_DECODED_NAME = new Map<string, number>([
352
352
  ['FW_MGMT_UPDATER_TASK_STATUS_FAILED_ENTRY_OUT_OF_BOUNDS', 10],
353
353
  ]);
354
354
 
355
- const isProtocolV2ReconnectProbeError = (error: unknown) => {
356
- const message = getProtocolV2UnknownErrorText(error).toLowerCase();
357
- return (
358
- (message.includes('device protocol mismatch') && message.includes('expected v2')) ||
359
- message.includes('did not respond to expected protocol')
360
- );
361
- };
355
+ const isProtocolV2ReconnectProbeError = (error: unknown) =>
356
+ getProtocolV2ErrorCode(error) === HardwareErrorCode.TransportProtocolProbeFailed &&
357
+ (error as { params?: { expectedProtocol?: unknown } } | undefined)?.params?.expectedProtocol ===
358
+ 'V2';
362
359
 
363
360
  const isProtocolV2FirmwareStatusEndpointUnavailable = (error: unknown) => {
364
361
  const message = getProtocolV2UnknownErrorText(error).toLowerCase();
package/src/core/index.ts CHANGED
@@ -126,6 +126,8 @@ const parseInitOptions = (method?: BaseMethod): InitOptions => ({
126
126
  });
127
127
 
128
128
  let _core: Core | undefined;
129
+ let transportSwitchGeneration = 0;
130
+ let pendingTransportSwitch: Promise<void> = Promise.resolve();
129
131
  let _deviceList: DeviceList | undefined;
130
132
  let _connector: DeviceConnector | undefined;
131
133
  let _uiPromises: UiPromise<UiPromiseResponse['type']>[] = []; // Waiting for ui response
@@ -991,15 +993,11 @@ function canSkipInitialize(method: BaseMethod, device: Device): boolean {
991
993
  }
992
994
 
993
995
  export function isRetryableBleProtocolV2ProbeError(method: BaseMethod, error: unknown) {
994
- const typedError = error as { errorCode?: unknown; message?: unknown };
995
- const message =
996
- typeof typedError?.message === 'string' ? typedError.message : String(error ?? '');
996
+ const typedError = error as { errorCode?: unknown; params?: { expectedProtocol?: unknown } };
997
997
  return (
998
998
  method.payload.connectProtocol === 'V2' &&
999
- typedError?.errorCode === HardwareErrorCode.RuntimeError &&
1000
- message.includes('Device protocol mismatch') &&
1001
- message.includes('expected V2') &&
1002
- message.includes('did not respond to expected protocol')
999
+ typedError?.errorCode === HardwareErrorCode.TransportProtocolProbeFailed &&
1000
+ typedError.params?.expectedProtocol === 'V2'
1003
1001
  );
1004
1002
  }
1005
1003
 
@@ -1009,7 +1007,7 @@ export function isRetryableBleConnectionError(method: BaseMethod, error: unknown
1009
1007
  }
1010
1008
  const typedError = error as {
1011
1009
  errorCode?: unknown;
1012
- params?: { acquireDeadlineExceeded?: unknown };
1010
+ params?: { acquireDeadlineExceeded?: unknown; expectedProtocol?: unknown };
1013
1011
  };
1014
1012
  if (
1015
1013
  typedError?.errorCode === HardwareErrorCode.BleTimeoutError &&
@@ -1020,6 +1018,8 @@ export function isRetryableBleConnectionError(method: BaseMethod, error: unknown
1020
1018
  return (
1021
1019
  typedError?.errorCode === HardwareErrorCode.BleTimeoutError ||
1022
1020
  typedError?.errorCode === HardwareErrorCode.BleConnectedError ||
1021
+ (typedError?.errorCode === HardwareErrorCode.TransportProtocolProbeFailed &&
1022
+ !typedError.params?.expectedProtocol) ||
1023
1023
  isRetryableBleProtocolV2ProbeError(method, error) ||
1024
1024
  isMissingDetectedProtocolV2Error(method, error)
1025
1025
  );
@@ -1274,6 +1274,8 @@ const ensureConnected = async (
1274
1274
  HardwareErrorCode.BridgeTimeoutError,
1275
1275
  HardwareErrorCode.BridgeNeedsPermission,
1276
1276
  HardwareErrorCode.WebUsbDeviceAccessError,
1277
+ HardwareErrorCode.TransportProtocolProbeFailed,
1278
+ HardwareErrorCode.TransportProtocolMismatch,
1277
1279
  ].includes(error.errorCode)
1278
1280
  ) {
1279
1281
  _deviceList = undefined;
@@ -1361,6 +1363,8 @@ const ensureConnected = async (
1361
1363
  HardwareErrorCode.BleCharacteristicNotifyChangeFailure,
1362
1364
  HardwareErrorCode.BridgeNeedsPermission,
1363
1365
  HardwareErrorCode.WebUsbDeviceAccessError,
1366
+ HardwareErrorCode.TransportProtocolProbeFailed,
1367
+ HardwareErrorCode.TransportProtocolMismatch,
1364
1368
  HardwareErrorCode.DeviceInterruptedFromUser,
1365
1369
  HardwareErrorCode.CallQueueActionCancelled,
1366
1370
  ].includes(error.errorCode) ||
@@ -1964,6 +1968,8 @@ export default class Core extends EventEmitter {
1964
1968
 
1965
1969
  private async disposeResources(): Promise<void> {
1966
1970
  Log.debug(`[Core] Disposing SDK instance: ${this.sdkInstanceId}`);
1971
+ transportSwitchGeneration += 1;
1972
+ pendingTransportSwitch = Promise.resolve();
1967
1973
  pollingManager.stopAll();
1968
1974
  this.requestQueue.abortAllRequests();
1969
1975
  cleanup();
@@ -1998,6 +2004,8 @@ export default class Core extends EventEmitter {
1998
2004
  }
1999
2005
 
2000
2006
  export const initCore = () => {
2007
+ transportSwitchGeneration += 1;
2008
+ pendingTransportSwitch = Promise.resolve();
2001
2009
  const core = new Core();
2002
2010
  _core = core;
2003
2011
  return core;
@@ -2027,6 +2035,8 @@ export const init = async (
2027
2035
  plugin?: LowlevelTransportSharedPlugin
2028
2036
  ) => {
2029
2037
  try {
2038
+ transportSwitchGeneration += 1;
2039
+ pendingTransportSwitch = Promise.resolve();
2030
2040
  await DataManager.load(settings);
2031
2041
  initTransport(Transport, plugin);
2032
2042
  enableLog(DataManager.getSettings('debug'));
@@ -2043,8 +2053,6 @@ export const init = async (
2043
2053
  }
2044
2054
  };
2045
2055
 
2046
- let pendingTransportSwitch: Promise<void> = Promise.resolve();
2047
-
2048
2056
  export const switchTransport = ({
2049
2057
  env,
2050
2058
  Transport,
@@ -2054,12 +2062,19 @@ export const switchTransport = ({
2054
2062
  Transport: any;
2055
2063
  plugin?: LowlevelTransportSharedPlugin;
2056
2064
  }) => {
2065
+ const generation = transportSwitchGeneration;
2057
2066
  // Preserve request order while native transport cleanup is pending.
2058
2067
  const switching = pendingTransportSwitch
2059
2068
  .catch(() => undefined)
2060
2069
  .then(async () => {
2070
+ if (generation !== transportSwitchGeneration) {
2071
+ throw ERRORS.TypedError(HardwareErrorCode.NotInitialized);
2072
+ }
2061
2073
  _connector?.stop();
2062
2074
  await TransportManager.getTransport()?.stop?.();
2075
+ if (generation !== transportSwitchGeneration) {
2076
+ throw ERRORS.TypedError(HardwareErrorCode.NotInitialized);
2077
+ }
2063
2078
  DataManager.updateEnv(env);
2064
2079
  TransportManager.setTransport(Transport, plugin);
2065
2080
  _deviceList = undefined;
@@ -133,10 +133,10 @@ export default class DeviceConnector {
133
133
  : undefined;
134
134
  const detectedProtocol = acquiredProtocol ?? transport.getProtocolType(path);
135
135
  if (detectedProtocol !== expectedProtocol) {
136
- throw ERRORS.TypedError(
137
- HardwareErrorCode.RuntimeError,
138
- `Device protocol mismatch: expected ${expectedProtocol}, detected ${detectedProtocol}`
139
- );
136
+ throw ERRORS.TypedError(HardwareErrorCode.TransportProtocolMismatch, undefined, {
137
+ expectedProtocol,
138
+ detectedProtocol,
139
+ });
140
140
  }
141
141
  }
142
142
  return res;