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

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.
@@ -206,72 +206,19 @@ describe('isolated USB identity probe', () => {
206
206
  expect(transport.release).not.toHaveBeenCalled();
207
207
  });
208
208
 
209
- test('retries its own failed Bridge release before probing again', async () => {
210
- const transport = createTransport();
211
- let held: string | undefined;
212
- transport.enumerate.mockImplementation(() =>
213
- Promise.resolve([{ ...descriptor, commType: 'bridge', session: held }])
214
- );
215
- transport.acquire.mockImplementation(() => {
216
- held = 'probe-transport-handle';
217
- return Promise.resolve(held);
218
- });
219
- transport.release
220
- .mockRejectedValueOnce(new Error('release request lost'))
221
- .mockRejectedValueOnce(new Error('Bridge still unavailable'))
222
- .mockImplementation(() => {
223
- held = undefined;
224
- return Promise.resolve(undefined);
225
- });
226
-
227
- await expect(probeUsbDeviceIdentitiesWithTransport(transport, 'bridge')).resolves.toEqual([]);
228
- await expect(probeUsbDeviceIdentitiesWithTransport(transport, 'bridge')).resolves.toEqual([]);
229
- expect(transport.acquire).toHaveBeenCalledTimes(1);
230
- expect(transport.call).toHaveBeenCalledTimes(1);
231
- await expect(probeUsbDeviceIdentitiesWithTransport(transport, 'bridge')).resolves.toHaveLength(
232
- 1
233
- );
234
- expect(transport.acquire).toHaveBeenCalledTimes(2);
235
- expect(transport.release).toHaveBeenCalledTimes(4);
236
- });
237
-
238
- test.each([undefined, 'foreign-transport-handle'])(
239
- 'does not retry a stale Bridge release when ownership changes to %s',
240
- async replacement => {
209
+ test.each([undefined, 'occupied-transport-handle'])(
210
+ 'does not initialize or acquire a Bridge identity probe (session: %s)',
211
+ async session => {
241
212
  const transport = createTransport();
242
- transport.enumerate.mockResolvedValue([{ ...descriptor, commType: 'bridge' }]);
243
- transport.release.mockRejectedValueOnce(new Error('release response lost'));
244
- await probeUsbDeviceIdentitiesWithTransport(transport, 'bridge');
245
- transport.enumerate.mockResolvedValue([
246
- { ...descriptor, commType: 'bridge', session: replacement },
247
- ]);
248
- transport.release.mockClear();
249
- const result = await probeUsbDeviceIdentitiesWithTransport(transport, 'bridge');
250
- expect(result).toHaveLength(replacement ? 0 : 1);
251
- expect(transport.release).toHaveBeenCalledTimes(replacement ? 0 : 1);
252
- if (replacement) {
253
- transport.enumerate.mockResolvedValue([{ ...descriptor, commType: 'bridge' }]);
254
- await expect(
255
- probeUsbDeviceIdentitiesWithTransport(transport, 'bridge')
256
- ).resolves.toHaveLength(1);
257
- }
213
+ transport.enumerate.mockResolvedValue([{ ...descriptor, commType: 'bridge', session }]);
214
+ await expect(probeUsbDeviceIdentitiesWithTransport(transport, 'bridge')).resolves.toEqual([]);
215
+ expect(transport.init).not.toHaveBeenCalled();
216
+ expect(transport.enumerate).not.toHaveBeenCalled();
217
+ expect(transport.acquire).not.toHaveBeenCalled();
218
+ expect(transport.release).not.toHaveBeenCalled();
258
219
  }
259
220
  );
260
221
 
261
- test('never cleans up a Bridge handle recorded by another transport instance', async () => {
262
- const transport = createTransport();
263
- transport.enumerate.mockResolvedValue([{ ...descriptor, commType: 'bridge' }]);
264
- transport.release.mockRejectedValueOnce(new Error('release request lost'));
265
- await probeUsbDeviceIdentitiesWithTransport(transport, 'bridge');
266
- const other = createTransport();
267
- other.enumerate.mockResolvedValue([
268
- { ...descriptor, commType: 'bridge', session: 'usb-transport-handle' },
269
- ]);
270
- await expect(probeUsbDeviceIdentitiesWithTransport(other, 'bridge')).resolves.toEqual([]);
271
- expect(other.release).not.toHaveBeenCalled();
272
- expect(other.acquire).not.toHaveBeenCalled();
273
- });
274
-
275
222
  test('reuses identity only for the exact active WebUSB handle', () => {
276
223
  const handle = {};
277
224
  const endpoint = { ...descriptor, device: handle };
@@ -1 +1 @@
1
- {"version":3,"file":"SearchDevices.d.ts","sourceRoot":"","sources":["../../src/api/SearchDevices.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;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G,IAAI,CAC1C,SAAS,EACT,SAAS,GAAG,MAAM,GAAG,iBAAiB,GAAG,qBAAqB,CAC/D,GAAG;IACF,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;IAClC,SAAS,EAAE,MAAM,OAAO,CAAC,0BAA0B,EAAE,CAAC,CAAC;IACvD,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAC9D,SAAS,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACzD,CAAC;AAYF,eAAO,MAAM,qCAAqC,cACrC,yBAAyB,YAC1B,iBAAiB,CAAC,UAAU,CAAC,mCACP,0BAA0B,KAAK,iBAAiB,GAAG,SAAS,kBAC3F,QAAQ,iBAAiB,EAAE,CAoG7B,CAAC;AAsBF,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,UAAU;IACnD,SAAS,CAAC,EAAE,eAAe,CAAa;IAExC,IAAI;IAME,GAAG,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;CAuFrC"}
@@ -38,5 +38,5 @@ export declare const switchTransport: ({ env, Transport, plugin, }: {
38
38
  env: ConnectSettings['env'];
39
39
  Transport: any;
40
40
  plugin?: LowlevelTransportSharedPlugin | undefined;
41
- }) => void;
41
+ }) => Promise<void>;
42
42
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,YAAY,MAAM,QAAQ,CAAC;AAClC,OAAO,EAEL,KAAK,6BAA6B,EAElC,KAAK,YAAY,EAIlB,MAAM,wBAAwB,CAAC;AAgChC,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAsB1C,OAAO,eAAe,MAAM,2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AAgB,6BAA6B,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,WAoB/E;AAED,wBAAgB,gCAAgC,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,OAAO,WAQlF;AAED,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,OAAO,WAI3D;AAiKD,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,UAAU,GAAG,YAAY,GAAG,SAAS,CAMtF;AA4MD,eAAO,MAAM,MAAM,YAAa,WAAW,cAAc,MAAM,SA4G9D,CAAC;AA8GF,eAAO,MAAM,qBAAqB,gFAejC,CAAC;AAiLF,MAAM,CAAC,OAAO,OAAO,IAAK,SAAQ,YAAY;IAC5C,OAAO,CAAC,cAAc,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;CAiC/B;AAED,eAAO,MAAM,QAAQ,YAIpB,CAAC;AAEF,eAAO,MAAM,aAAa,uBAYzB,CAAC;AAMF,eAAO,MAAM,IAAI,aACL,eAAe,aACd,GAAG,WACL,6BAA6B,8BAiBvC,CAAC;AAIF,eAAO,MAAM,eAAe;SAKrB,eAAe,CAAC,KAAK,CAAC;eAChB,GAAG;;mBAkBf,CAAC"}
package/dist/index.d.ts CHANGED
@@ -1154,7 +1154,7 @@ declare const switchTransport: ({ env, Transport, plugin, }: {
1154
1154
  env: ConnectSettings['env'];
1155
1155
  Transport: any;
1156
1156
  plugin?: LowlevelTransportSharedPlugin | undefined;
1157
- }) => void;
1157
+ }) => Promise<void>;
1158
1158
 
1159
1159
  type UploadPortfolioParams = {
1160
1160
  packageBase64: string;
package/dist/index.js CHANGED
@@ -47231,22 +47231,15 @@ const identityProbeLogger = {
47231
47231
  warn: () => undefined,
47232
47232
  error: () => undefined,
47233
47233
  };
47234
- const pendingBridgeProbeReleases = new WeakMap();
47235
47234
  const probeUsbDeviceIdentitiesWithTransport = (transport, commType, getOwnedIdentity) => __awaiter(void 0, void 0, void 0, function* () {
47236
47235
  var _a;
47236
+ if (commType !== 'webusb')
47237
+ return [];
47237
47238
  yield transport.init(identityProbeLogger);
47238
47239
  const defaultMessages = JSON.stringify(DataManager.getProtobufMessages());
47239
47240
  yield transport.configure(defaultMessages);
47240
47241
  yield ((_a = transport.configureProtocolV2) === null || _a === void 0 ? void 0 : _a.call(transport, JSON.stringify(DataManager.getProtobufMessages('v2Schema'))));
47241
47242
  const descriptors = yield transport.enumerate();
47242
- let pendingReleases = pendingBridgeProbeReleases.get(transport);
47243
- if (commType === 'bridge' && pendingReleases) {
47244
- for (const [path, session] of pendingReleases) {
47245
- if (!descriptors.some(descriptor => descriptor.path === path && descriptor.session === session)) {
47246
- pendingReleases.delete(path);
47247
- }
47248
- }
47249
- }
47250
47243
  const identities = [];
47251
47244
  const readIdentity = (descriptor) => __awaiter(void 0, void 0, void 0, function* () {
47252
47245
  var _b, _c;
@@ -47255,17 +47248,6 @@ const probeUsbDeviceIdentitiesWithTransport = (transport, commType, getOwnedIden
47255
47248
  return undefined;
47256
47249
  if (descriptors.filter(candidate => candidate.path === path).length !== 1)
47257
47250
  return undefined;
47258
- const pendingSession = commType === 'bridge' ? pendingReleases === null || pendingReleases === void 0 ? void 0 : pendingReleases.get(path) : undefined;
47259
- if (pendingSession && descriptor.session === pendingSession) {
47260
- try {
47261
- yield transport.release(pendingSession, false);
47262
- pendingReleases === null || pendingReleases === void 0 ? void 0 : pendingReleases.delete(path);
47263
- descriptor = Object.assign(Object.assign({}, descriptor), { session: undefined });
47264
- }
47265
- catch (_d) {
47266
- return undefined;
47267
- }
47268
- }
47269
47251
  const owner = getOwnedIdentity === null || getOwnedIdentity === void 0 ? void 0 : getOwnedIdentity(descriptor);
47270
47252
  if (owner) {
47271
47253
  return owner;
@@ -47320,22 +47302,15 @@ const probeUsbDeviceIdentitiesWithTransport = (transport, commType, getOwnedIden
47320
47302
  };
47321
47303
  }
47322
47304
  }
47323
- catch (_e) {
47305
+ catch (_d) {
47324
47306
  }
47325
47307
  finally {
47326
47308
  if (session) {
47327
47309
  try {
47328
47310
  yield transport.release(session, false);
47329
47311
  }
47330
- catch (_f) {
47312
+ catch (_e) {
47331
47313
  identified = undefined;
47332
- if (commType === 'bridge') {
47333
- if (!pendingReleases) {
47334
- pendingReleases = new Map();
47335
- pendingBridgeProbeReleases.set(transport, pendingReleases);
47336
- }
47337
- pendingReleases.set(path, session);
47338
- }
47339
47314
  }
47340
47315
  }
47341
47316
  }
@@ -67654,13 +67629,23 @@ const init = (settings, Transport, plugin) => __awaiter(void 0, void 0, void 0,
67654
67629
  throw error;
67655
67630
  }
67656
67631
  });
67632
+ let pendingTransportSwitch = Promise.resolve();
67657
67633
  const switchTransport = ({ env, Transport, plugin, }) => {
67658
- DataManager.updateEnv(env);
67659
- TransportManager.setTransport(Transport, plugin);
67660
- _deviceList = undefined;
67661
- DevicePool.resetState();
67662
- _connector = undefined;
67663
- initConnector();
67634
+ const switching = pendingTransportSwitch
67635
+ .catch(() => undefined)
67636
+ .then(() => __awaiter(void 0, void 0, void 0, function* () {
67637
+ var _a, _b;
67638
+ _connector === null || _connector === void 0 ? void 0 : _connector.stop();
67639
+ yield ((_b = (_a = TransportManager.getTransport()) === null || _a === void 0 ? void 0 : _a.stop) === null || _b === void 0 ? void 0 : _b.call(_a));
67640
+ DataManager.updateEnv(env);
67641
+ TransportManager.setTransport(Transport, plugin);
67642
+ _deviceList = undefined;
67643
+ DevicePool.resetState();
67644
+ _connector = undefined;
67645
+ initConnector();
67646
+ }));
67647
+ pendingTransportSwitch = switching;
67648
+ return switching;
67664
67649
  };
67665
67650
 
67666
67651
  const HardwareSdk = ({ init, call, dispose, eventEmitter, uiResponse, cancel, updateSettings, switchTransport, }) => inject({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/hd-core",
3
- "version": "1.2.8-alpha.19",
3
+ "version": "1.2.8-alpha.20",
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.19",
29
- "@onekeyfe/hd-transport": "1.2.8-alpha.19",
28
+ "@onekeyfe/hd-shared": "1.2.8-alpha.20",
29
+ "@onekeyfe/hd-transport": "1.2.8-alpha.20",
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": "822e744bceb68a0928ad89d445b985897432edcf"
49
+ "gitHead": "973f059fe93a58fdcf098ddb32ba63f621a2c78e"
50
50
  }
@@ -109,14 +109,13 @@ const identityProbeLogger = {
109
109
  error: () => undefined,
110
110
  };
111
111
 
112
- const pendingBridgeProbeReleases = new WeakMap<UsbIdentityProbeTransport, Map<string, string>>();
113
-
114
112
  /** Runs on a separate transport; never initializes or switches the current Core. */
115
113
  export const probeUsbDeviceIdentitiesWithTransport = async (
116
114
  transport: UsbIdentityProbeTransport,
117
115
  commType: UsbDeviceIdentity['commType'],
118
116
  getOwnedIdentity?: (descriptor: UsbIdentityProbeDescriptor) => UsbDeviceIdentity | undefined
119
117
  ): Promise<UsbDeviceIdentity[]> => {
118
+ if (commType !== 'webusb') return [];
120
119
  await transport.init(identityProbeLogger);
121
120
  const defaultMessages = JSON.stringify(DataManager.getProtobufMessages());
122
121
  await transport.configure(defaultMessages);
@@ -124,16 +123,6 @@ export const probeUsbDeviceIdentitiesWithTransport = async (
124
123
  JSON.stringify(DataManager.getProtobufMessages('v2Schema'))
125
124
  );
126
125
  const descriptors = await transport.enumerate();
127
- let pendingReleases = pendingBridgeProbeReleases.get(transport);
128
- if (commType === 'bridge' && pendingReleases) {
129
- for (const [path, session] of pendingReleases) {
130
- if (
131
- !descriptors.some(descriptor => descriptor.path === path && descriptor.session === session)
132
- ) {
133
- pendingReleases.delete(path);
134
- }
135
- }
136
- }
137
126
  const identities: UsbDeviceIdentity[] = [];
138
127
  const readIdentity = async (
139
128
  descriptor: UsbIdentityProbeDescriptor
@@ -141,16 +130,6 @@ export const probeUsbDeviceIdentitiesWithTransport = async (
141
130
  const { path } = descriptor;
142
131
  if (!path || descriptor.commType !== commType) return undefined;
143
132
  if (descriptors.filter(candidate => candidate.path === path).length !== 1) return undefined;
144
- const pendingSession = commType === 'bridge' ? pendingReleases?.get(path) : undefined;
145
- if (pendingSession && descriptor.session === pendingSession) {
146
- try {
147
- await transport.release(pendingSession, false);
148
- pendingReleases?.delete(path);
149
- descriptor = { ...descriptor, session: undefined };
150
- } catch {
151
- return undefined;
152
- }
153
- }
154
133
  const owner = getOwnedIdentity?.(descriptor);
155
134
  if (owner) {
156
135
  return owner;
@@ -225,15 +204,6 @@ export const probeUsbDeviceIdentitiesWithTransport = async (
225
204
  await transport.release(session, false);
226
205
  } catch {
227
206
  identified = undefined;
228
- // Retain only our own Bridge handle; enumeration must confirm ownership
229
- // before a later probe retries a release whose HTTP request may be lost.
230
- if (commType === 'bridge') {
231
- if (!pendingReleases) {
232
- pendingReleases = new Map();
233
- pendingBridgeProbeReleases.set(transport, pendingReleases);
234
- }
235
- pendingReleases.set(path, session);
236
- }
237
207
  }
238
208
  }
239
209
  }
package/src/core/index.ts CHANGED
@@ -2043,6 +2043,8 @@ export const init = async (
2043
2043
  }
2044
2044
  };
2045
2045
 
2046
+ let pendingTransportSwitch: Promise<void> = Promise.resolve();
2047
+
2046
2048
  export const switchTransport = ({
2047
2049
  env,
2048
2050
  Transport,
@@ -2052,10 +2054,19 @@ export const switchTransport = ({
2052
2054
  Transport: any;
2053
2055
  plugin?: LowlevelTransportSharedPlugin;
2054
2056
  }) => {
2055
- DataManager.updateEnv(env);
2056
- TransportManager.setTransport(Transport, plugin);
2057
- _deviceList = undefined;
2058
- DevicePool.resetState();
2059
- _connector = undefined;
2060
- initConnector();
2057
+ // Preserve request order while native transport cleanup is pending.
2058
+ const switching = pendingTransportSwitch
2059
+ .catch(() => undefined)
2060
+ .then(async () => {
2061
+ _connector?.stop();
2062
+ await TransportManager.getTransport()?.stop?.();
2063
+ DataManager.updateEnv(env);
2064
+ TransportManager.setTransport(Transport, plugin);
2065
+ _deviceList = undefined;
2066
+ DevicePool.resetState();
2067
+ _connector = undefined;
2068
+ initConnector();
2069
+ });
2070
+ pendingTransportSwitch = switching;
2071
+ return switching;
2061
2072
  };