@onekeyfe/hd-common-connect-sdk 1.2.11-alpha.5 → 1.2.11-alpha.6
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/README.md +5 -1
- package/dist/index.js +4 -0
- package/package.json +16 -10
- package/scripts/check-bundle.mjs +35 -0
- package/src/index.ts +7 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# `@onekeyfe/hd-common-connect-sdk`
|
|
2
2
|
|
|
3
|
-
`@onekeyfe/hd-common-connect-sdk` is a
|
|
3
|
+
`@onekeyfe/hd-common-connect-sdk` is a unified in-process Hardware SDK entry point that runs Core and the selected transport directly in Node.js, Electron, browser/extension, and native bridge (`lowlevel`) runtimes.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -42,6 +42,10 @@ await HardwareSDKLowLevel.init({ env: 'webusb' });
|
|
|
42
42
|
await HardwareSDKLowLevel.dispose();
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
The package's `browser` mapping excludes the native USB dependency from browser
|
|
46
|
+
bundles. The browser host still needs a `Buffer` polyfill for Core and its
|
|
47
|
+
dependencies. Use `env: 'node-usb'` from a Node.js build.
|
|
48
|
+
|
|
45
49
|
The host still obtains WebUSB permission through a user gesture and handles device
|
|
46
50
|
confirmation, PIN and passphrase events. An extension service worker should proxy
|
|
47
51
|
to its offscreen host. Use one active SDK host per runtime and dispose it before
|
package/dist/index.js
CHANGED
|
@@ -597,6 +597,10 @@ var getTransport = function (env) { return __awaiter(void 0, void 0, void 0, fun
|
|
|
597
597
|
return [4 /*yield*/, Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@onekeyfe/hd-transport-usb')); })];
|
|
598
598
|
case 1:
|
|
599
599
|
NodeUsbTransport = (_a.sent()).default;
|
|
600
|
+
// Browser bundlers replace this Node-only package with an empty module.
|
|
601
|
+
if (typeof NodeUsbTransport !== 'function') {
|
|
602
|
+
throw hdShared.ERRORS.TypedError(hdShared.HardwareErrorCode.TransportNotConfigured, 'Node USB requires Node.js');
|
|
603
|
+
}
|
|
600
604
|
return [2 /*return*/, NodeUsbTransport];
|
|
601
605
|
case 2:
|
|
602
606
|
if (env === 'emulator')
|
package/package.json
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/hd-common-connect-sdk",
|
|
3
|
-
"version": "1.2.11-alpha.
|
|
3
|
+
"version": "1.2.11-alpha.6",
|
|
4
4
|
"author": "OneKey",
|
|
5
5
|
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
|
|
6
6
|
"license": "ISC",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
|
+
"browser": {
|
|
9
|
+
"@onekeyfe/hd-transport-usb": false
|
|
10
|
+
},
|
|
8
11
|
"types": "dist/index.d.ts",
|
|
9
12
|
"repository": {
|
|
10
13
|
"type": "git",
|
|
@@ -15,19 +18,22 @@
|
|
|
15
18
|
},
|
|
16
19
|
"scripts": {
|
|
17
20
|
"dev": "rimraf dist && rollup -c ../../build/rollup.config.js -w",
|
|
18
|
-
"build": "rimraf dist && rollup -c ../../build/rollup.config.js",
|
|
21
|
+
"build": "rimraf dist && rollup -c ../../build/rollup.config.js && node scripts/check-bundle.mjs",
|
|
19
22
|
"test": "jest",
|
|
20
23
|
"lint": "eslint .",
|
|
21
24
|
"lint:fix": "eslint . --fix"
|
|
22
25
|
},
|
|
26
|
+
"devDependencies": {
|
|
27
|
+
"esbuild": "^0.27.0"
|
|
28
|
+
},
|
|
23
29
|
"dependencies": {
|
|
24
|
-
"@onekeyfe/hd-core": "1.2.11-alpha.
|
|
25
|
-
"@onekeyfe/hd-shared": "1.2.11-alpha.
|
|
26
|
-
"@onekeyfe/hd-transport-emulator": "1.2.11-alpha.
|
|
27
|
-
"@onekeyfe/hd-transport-http": "1.2.11-alpha.
|
|
28
|
-
"@onekeyfe/hd-transport-lowlevel": "1.2.11-alpha.
|
|
29
|
-
"@onekeyfe/hd-transport-usb": "1.2.11-alpha.
|
|
30
|
-
"@onekeyfe/hd-transport-web-device": "1.2.11-alpha.
|
|
30
|
+
"@onekeyfe/hd-core": "1.2.11-alpha.6",
|
|
31
|
+
"@onekeyfe/hd-shared": "1.2.11-alpha.6",
|
|
32
|
+
"@onekeyfe/hd-transport-emulator": "1.2.11-alpha.6",
|
|
33
|
+
"@onekeyfe/hd-transport-http": "1.2.11-alpha.6",
|
|
34
|
+
"@onekeyfe/hd-transport-lowlevel": "1.2.11-alpha.6",
|
|
35
|
+
"@onekeyfe/hd-transport-usb": "1.2.11-alpha.6",
|
|
36
|
+
"@onekeyfe/hd-transport-web-device": "1.2.11-alpha.6"
|
|
31
37
|
},
|
|
32
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "fe0e726cdb7de7d9889e26af1db227d9bed32369"
|
|
33
39
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
|
|
4
|
+
import { buildSync } from 'esbuild';
|
|
5
|
+
|
|
6
|
+
const packageDirectory = fileURLToPath(new URL('..', import.meta.url));
|
|
7
|
+
const options = {
|
|
8
|
+
absWorkingDir: packageDirectory,
|
|
9
|
+
stdin: {
|
|
10
|
+
contents: `export { HardwareSDKLowLevel } from '@onekeyfe/hd-common-connect-sdk';`,
|
|
11
|
+
resolveDir: packageDirectory,
|
|
12
|
+
},
|
|
13
|
+
bundle: true,
|
|
14
|
+
format: 'cjs',
|
|
15
|
+
logLevel: 'error',
|
|
16
|
+
metafile: true,
|
|
17
|
+
write: false,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const nativeUsbModule = /(?:^|\/)(?:hd-transport-usb|usb|node-gyp-build)\//u;
|
|
21
|
+
const hasNativeUsb = ({ metafile }) =>
|
|
22
|
+
Object.keys(metafile.inputs).some(
|
|
23
|
+
input => !input.startsWith('(disabled):') && nativeUsbModule.test(input)
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
assert.equal(
|
|
27
|
+
hasNativeUsb(buildSync({ ...options, platform: 'browser' })),
|
|
28
|
+
false,
|
|
29
|
+
'Browser bundles must exclude the native USB transport'
|
|
30
|
+
);
|
|
31
|
+
assert.equal(
|
|
32
|
+
hasNativeUsb(buildSync({ ...options, platform: 'node' })),
|
|
33
|
+
true,
|
|
34
|
+
'Node bundles must retain the native USB transport'
|
|
35
|
+
);
|
package/src/index.ts
CHANGED
|
@@ -49,9 +49,14 @@ const getTransport = async (env: ConnectSettings['env']) => {
|
|
|
49
49
|
if (env === 'webusb' || env === 'desktop-webusb') return WebUsbTransport;
|
|
50
50
|
if (env === 'lowlevel') return LowlevelTransport;
|
|
51
51
|
if (env === 'node-usb') {
|
|
52
|
-
// Dynamic import — usb is a native Node.js module (libusb C++ bindings)
|
|
53
|
-
// that cannot be resolved by browser/React Native bundlers
|
|
54
52
|
const { default: NodeUsbTransport } = await import('@onekeyfe/hd-transport-usb');
|
|
53
|
+
// Browser bundlers replace this Node-only package with an empty module.
|
|
54
|
+
if (typeof NodeUsbTransport !== 'function') {
|
|
55
|
+
throw ERRORS.TypedError(
|
|
56
|
+
HardwareErrorCode.TransportNotConfigured,
|
|
57
|
+
'Node USB requires Node.js'
|
|
58
|
+
);
|
|
59
|
+
}
|
|
55
60
|
return NodeUsbTransport;
|
|
56
61
|
}
|
|
57
62
|
if (env === 'emulator') return EmulatorTransport;
|