@onekeyfe/hd-common-connect-sdk 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.
- package/__tests__/device-state-events.test.ts +13 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -4
- package/package.json +9 -9
- package/src/index.ts +5 -7
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
probeUsbDeviceIdentitiesWithTransport,
|
|
9
9
|
} from '@onekeyfe/hd-core';
|
|
10
10
|
import { HardwareErrorCode, createDeferred } from '@onekeyfe/hd-shared';
|
|
11
|
+
import HttpTransport from '@onekeyfe/hd-transport-http';
|
|
11
12
|
|
|
12
13
|
import sdkExport, { messagePromises, probeUsbDeviceIdentities } from '../src';
|
|
13
14
|
|
|
@@ -88,7 +89,7 @@ describe('SDK request cleanup', () => {
|
|
|
88
89
|
expect(Object.keys(messagePromises)).toHaveLength(0);
|
|
89
90
|
});
|
|
90
91
|
|
|
91
|
-
test.each(['webusb'
|
|
92
|
+
test.each(['webusb'] as const)(
|
|
92
93
|
'probes %s without disposing an outstanding BLE request and coalesces concurrent probes',
|
|
93
94
|
async commType => {
|
|
94
95
|
const pending = createDeferred<unknown>();
|
|
@@ -116,6 +117,17 @@ describe('SDK request cleanup', () => {
|
|
|
116
117
|
}
|
|
117
118
|
);
|
|
118
119
|
|
|
120
|
+
test('rejects the withdrawn Bridge probe without creating a transport or affecting BLE', async () => {
|
|
121
|
+
jest.mocked(HttpTransport).mockClear();
|
|
122
|
+
jest.mocked(probeUsbDeviceIdentitiesWithTransport).mockClear();
|
|
123
|
+
await expect(probeUsbDeviceIdentities({ commType: 'bridge' })).rejects.toMatchObject({
|
|
124
|
+
errorCode: HardwareErrorCode.CallMethodInvalidParameter,
|
|
125
|
+
});
|
|
126
|
+
expect(HttpTransport).not.toHaveBeenCalled();
|
|
127
|
+
expect(probeUsbDeviceIdentitiesWithTransport).not.toHaveBeenCalled();
|
|
128
|
+
expect(core.dispose).not.toHaveBeenCalled();
|
|
129
|
+
});
|
|
130
|
+
|
|
119
131
|
test('waits for Core disposal and does not retain old listeners after reinitialization', async () => {
|
|
120
132
|
const cleanup = createDeferred<void>();
|
|
121
133
|
core.dispose.mockImplementationOnce(async () => {
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import * as _onekeyfe_hd_core from '@onekeyfe/hd-core';
|
|
|
2
2
|
import { UsbDeviceIdentity } from '@onekeyfe/hd-core';
|
|
3
3
|
import { Deferred } from '@onekeyfe/hd-shared';
|
|
4
4
|
|
|
5
|
-
/** Identify
|
|
5
|
+
/** Identify WebUSB without disposing the current SDK, changing settings, or opening a wallet. */
|
|
6
6
|
declare const probeUsbDeviceIdentities: ({ commType, }: {
|
|
7
7
|
commType: UsbDeviceIdentity['commType'];
|
|
8
8
|
}) => Promise<UsbDeviceIdentity[]>;
|
package/dist/index.js
CHANGED
|
@@ -609,10 +609,10 @@ var _core;
|
|
|
609
609
|
var _settings = HardwareSdk.parseConnectSettings();
|
|
610
610
|
var usbIdentityProbeTransports = {};
|
|
611
611
|
var usbIdentityProbes = {};
|
|
612
|
-
/** Identify
|
|
612
|
+
/** Identify WebUSB without disposing the current SDK, changing settings, or opening a wallet. */
|
|
613
613
|
var probeUsbDeviceIdentities = function (_a) {
|
|
614
614
|
var commType = _a.commType;
|
|
615
|
-
if (commType !== 'webusb'
|
|
615
|
+
if (commType !== 'webusb') {
|
|
616
616
|
return Promise.reject(hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.CallMethodInvalidParameter));
|
|
617
617
|
}
|
|
618
618
|
var pending = usbIdentityProbes[commType];
|
|
@@ -620,8 +620,7 @@ var probeUsbDeviceIdentities = function (_a) {
|
|
|
620
620
|
return pending;
|
|
621
621
|
var transport = usbIdentityProbeTransports[commType];
|
|
622
622
|
if (!transport) {
|
|
623
|
-
transport =
|
|
624
|
-
commType === 'webusb' ? new hdTransportWebDevice.WebUsbTransport(true) : new HttpTransport__default["default"](undefined, 3000);
|
|
623
|
+
transport = new hdTransportWebDevice.WebUsbTransport(true);
|
|
625
624
|
usbIdentityProbeTransports[commType] = transport;
|
|
626
625
|
}
|
|
627
626
|
var probe = HardwareSdk.probeUsbDeviceIdentitiesWithTransport(transport, commType, function (descriptor) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-common-connect-sdk",
|
|
3
|
-
"version": "1.2.8-alpha.
|
|
3
|
+
"version": "1.2.8-alpha.20",
|
|
4
4
|
"author": "OneKey",
|
|
5
5
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
6
6
|
"license": "ISC",
|
|
@@ -21,13 +21,13 @@
|
|
|
21
21
|
"lint:fix": "eslint . --fix"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@onekeyfe/hd-core": "1.2.8-alpha.
|
|
25
|
-
"@onekeyfe/hd-shared": "1.2.8-alpha.
|
|
26
|
-
"@onekeyfe/hd-transport-emulator": "1.2.8-alpha.
|
|
27
|
-
"@onekeyfe/hd-transport-http": "1.2.8-alpha.
|
|
28
|
-
"@onekeyfe/hd-transport-lowlevel": "1.2.8-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport-usb": "1.2.8-alpha.
|
|
30
|
-
"@onekeyfe/hd-transport-web-device": "1.2.8-alpha.
|
|
24
|
+
"@onekeyfe/hd-core": "1.2.8-alpha.20",
|
|
25
|
+
"@onekeyfe/hd-shared": "1.2.8-alpha.20",
|
|
26
|
+
"@onekeyfe/hd-transport-emulator": "1.2.8-alpha.20",
|
|
27
|
+
"@onekeyfe/hd-transport-http": "1.2.8-alpha.20",
|
|
28
|
+
"@onekeyfe/hd-transport-lowlevel": "1.2.8-alpha.20",
|
|
29
|
+
"@onekeyfe/hd-transport-usb": "1.2.8-alpha.20",
|
|
30
|
+
"@onekeyfe/hd-transport-web-device": "1.2.8-alpha.20"
|
|
31
31
|
},
|
|
32
|
-
"gitHead": "
|
|
32
|
+
"gitHead": "973f059fe93a58fdcf098ddb32ba63f621a2c78e"
|
|
33
33
|
}
|
package/src/index.ts
CHANGED
|
@@ -59,28 +59,26 @@ const getTransport = async (env: ConnectSettings['env']) => {
|
|
|
59
59
|
let _core: Core | undefined;
|
|
60
60
|
let _settings = parseConnectSettings();
|
|
61
61
|
|
|
62
|
-
const usbIdentityProbeTransports: Partial<
|
|
63
|
-
|
|
64
|
-
> = {};
|
|
62
|
+
const usbIdentityProbeTransports: Partial<Record<UsbDeviceIdentity['commType'], WebUsbTransport>> =
|
|
63
|
+
{};
|
|
65
64
|
const usbIdentityProbes: Partial<
|
|
66
65
|
Record<UsbDeviceIdentity['commType'], Promise<UsbDeviceIdentity[]>>
|
|
67
66
|
> = {};
|
|
68
67
|
|
|
69
|
-
/** Identify
|
|
68
|
+
/** Identify WebUSB without disposing the current SDK, changing settings, or opening a wallet. */
|
|
70
69
|
export const probeUsbDeviceIdentities = ({
|
|
71
70
|
commType,
|
|
72
71
|
}: {
|
|
73
72
|
commType: UsbDeviceIdentity['commType'];
|
|
74
73
|
}): Promise<UsbDeviceIdentity[]> => {
|
|
75
|
-
if (commType !== 'webusb'
|
|
74
|
+
if (commType !== 'webusb') {
|
|
76
75
|
return Promise.reject(ERRORS.TypedError(HardwareErrorCode.CallMethodInvalidParameter));
|
|
77
76
|
}
|
|
78
77
|
const pending = usbIdentityProbes[commType];
|
|
79
78
|
if (pending) return pending;
|
|
80
79
|
let transport = usbIdentityProbeTransports[commType];
|
|
81
80
|
if (!transport) {
|
|
82
|
-
transport =
|
|
83
|
-
commType === 'webusb' ? new WebUsbTransport(true) : new HttpTransport(undefined, 3000);
|
|
81
|
+
transport = new WebUsbTransport(true);
|
|
84
82
|
usbIdentityProbeTransports[commType] = transport;
|
|
85
83
|
}
|
|
86
84
|
const probe = probeUsbDeviceIdentitiesWithTransport(transport, commType, descriptor =>
|