@onekeyfe/hwk-desktop-noble-ble 1.2.11-alpha.4 → 1.2.11-alpha.7
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 +173 -0
- package/dist/{chunk-ILABAQJY.mjs → chunk-O6YS25TV.mjs} +9 -1
- package/dist/chunk-O6YS25TV.mjs.map +1 -0
- package/dist/constants.d.mts +12 -1
- package/dist/constants.d.ts +12 -1
- package/dist/constants.js +12 -2
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +7 -3
- package/dist/index.d.mts +45 -4
- package/dist/index.d.ts +45 -4
- package/dist/index.js +777 -56
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +770 -57
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/dist/chunk-ILABAQJY.mjs.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# Desktop BLE for third-party hardware wallets
|
|
2
|
+
|
|
3
|
+
`@onekeyfe/hwk-desktop-noble-ble` owns Ledger/Trezor BLE discovery, GATT I/O,
|
|
4
|
+
Windows OS pairing, cancellation, and connection cleanup in the Electron main
|
|
5
|
+
process. The host owns the native Windows pairing executable, IPC sender authorization,
|
|
6
|
+
UI, translations, and packaging.
|
|
7
|
+
It does not replace the separate OneKey `hd-transport-electron` transport.
|
|
8
|
+
|
|
9
|
+
## Main-process setup
|
|
10
|
+
|
|
11
|
+
Use `initThirdPartyBleSupport` once per active renderer. Existing integrations
|
|
12
|
+
without `windowsPairing` retain native-only behavior. On macOS/Linux the Windows
|
|
13
|
+
option is ignored; this option does not enable Linux BLE support.
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import path from 'path';
|
|
17
|
+
import { app, dialog, ipcMain } from 'electron';
|
|
18
|
+
import {
|
|
19
|
+
initThirdPartyBleSupport,
|
|
20
|
+
withThirdPartyBleIpcErrors,
|
|
21
|
+
} from '@onekeyfe/hwk-desktop-noble-ble';
|
|
22
|
+
import type { IpcMainLike } from '@onekeyfe/hwk-desktop-noble-ble';
|
|
23
|
+
|
|
24
|
+
// Run after creating your BrowserWindow. Do not expose these handlers to DApps.
|
|
25
|
+
const authorizedIpcMain: IpcMainLike = {
|
|
26
|
+
handle(channel, listener) {
|
|
27
|
+
ipcMain.handle(channel, (event, ...args) => {
|
|
28
|
+
if (window.isDestroyed() || event.sender !== window.webContents) {
|
|
29
|
+
throw new Error('BLE IPC sender is not authorized');
|
|
30
|
+
}
|
|
31
|
+
return listener(event, ...args);
|
|
32
|
+
});
|
|
33
|
+
},
|
|
34
|
+
removeHandler: channel => ipcMain.removeHandler(channel),
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const ble = initThirdPartyBleSupport(window.webContents, {
|
|
38
|
+
ipcMain: withThirdPartyBleIpcErrors(authorizedIpcMain),
|
|
39
|
+
windowsPairing: process.platform === 'win32' ? {
|
|
40
|
+
helperPath: app.isPackaged
|
|
41
|
+
? path.join(process.resourcesPath, 'ble-pair', 'onekey-ble-pair.exe')
|
|
42
|
+
: path.join(
|
|
43
|
+
app.getAppPath(), 'resources', 'ble-pair', `win-${process.arch}`,
|
|
44
|
+
'onekey-ble-pair.exe'
|
|
45
|
+
),
|
|
46
|
+
async onPairingRequest({ pin, signal }) {
|
|
47
|
+
if (signal.aborted || window.isDestroyed()) return 'cancel';
|
|
48
|
+
const { response } = await dialog.showMessageBox(window, {
|
|
49
|
+
message: pin,
|
|
50
|
+
detail: 'Compare this code with your device before confirming.',
|
|
51
|
+
buttons: ['Confirm', 'Cancel'],
|
|
52
|
+
cancelId: 1,
|
|
53
|
+
defaultId: 0,
|
|
54
|
+
noLink: true,
|
|
55
|
+
signal,
|
|
56
|
+
});
|
|
57
|
+
return !signal.aborted && response === 0 ? 'confirm' : 'cancel';
|
|
58
|
+
},
|
|
59
|
+
} : undefined,
|
|
60
|
+
});
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The same `windowsPairing` option works with `new NobleBleHandler(options)` for
|
|
64
|
+
hosts that do not use Electron IPC. Neither integration needs an IPC wrapper,
|
|
65
|
+
vendor timeout switches, a global decision callback, or a copy of the pairing
|
|
66
|
+
state machine. The helper path must be host-controlled, never renderer input.
|
|
67
|
+
Missing/unexecutable helpers fail with a structured `BleConnectFailed` error
|
|
68
|
+
instead of silently skipping a configured Windows pairing flow.
|
|
69
|
+
|
|
70
|
+
`onPairingRequest` is a numeric-comparison UI callback, not a device PIN entry or
|
|
71
|
+
Trezor THP authorization callback. Display the supplied code, require an explicit
|
|
72
|
+
user decision, and never log/persist it. A throwing or rejected callback declines
|
|
73
|
+
the OS request. Observe `signal`: close the UI as soon as it aborts, even if the
|
|
74
|
+
underlying Windows process is still cleaning up. A late answer is ignored and
|
|
75
|
+
cannot confirm a later ceremony. With a custom UI, implement the same lifetime
|
|
76
|
+
contract rather than adding an independent timeout.
|
|
77
|
+
|
|
78
|
+
## Windows packaging
|
|
79
|
+
|
|
80
|
+
The SDK does not include or build a native pairing executable. The host must
|
|
81
|
+
provide a trusted, compatible helper through `windowsPairing.helperPath`, along
|
|
82
|
+
with `onPairingRequest`. The OneKey Rust implementation and its x64/ARM64 binaries
|
|
83
|
+
are maintained in the
|
|
84
|
+
[App monorepo](https://github.com/OneKeyHQ/app-monorepo/tree/3f48ac0c1d22c757c64b27566e8d4cdde69262ba/apps/desktop/native-modules/onekey-ble-pair).
|
|
85
|
+
Use the matching [x64/ARM64 binaries from the same revision](https://github.com/OneKeyHQ/app-monorepo/tree/3f48ac0c1d22c757c64b27566e8d4cdde69262ba/apps/desktop/public/static/bin/ble-pair),
|
|
86
|
+
not assets from a different branch. That repository owns native builds and binary
|
|
87
|
+
updates. This revision emits structured `link` and `pairing-result` events and
|
|
88
|
+
continues reading host cancellation after confirmation.
|
|
89
|
+
|
|
90
|
+
Copy the **target build architecture** outside ASAR. For example, if the host
|
|
91
|
+
stores its executables under `resources/ble-pair/win-{x64,arm64}`, add this to its
|
|
92
|
+
electron-builder Windows configuration:
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
win: {
|
|
96
|
+
extraResources: [{
|
|
97
|
+
from: 'resources/ble-pair/win-${arch}',
|
|
98
|
+
to: 'ble-pair',
|
|
99
|
+
filter: ['onekey-ble-pair.exe'],
|
|
100
|
+
}],
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
Keep this SDK package external when bundling the main process, and install a
|
|
105
|
+
compatible `@stoprocent/noble` Electron native build. Do not put the helper inside
|
|
106
|
+
ASAR or choose its architecture from the machine performing a cross build.
|
|
107
|
+
Store/MSIX builds must include the same resource. Installing this package does
|
|
108
|
+
not download or compile a helper, and does not supply the host's native Noble
|
|
109
|
+
patches or Electron build.
|
|
110
|
+
|
|
111
|
+
The host helper must implement the process protocol used by
|
|
112
|
+
`src/windowsPairingHelper.ts`: accept `pair --address`, emit JSON events on stdout,
|
|
113
|
+
and read `confirm`/`cancel` decisions from stdin. Keep host binary updates
|
|
114
|
+
compatible with that protocol. Without the `windowsPairing` option, the SDK
|
|
115
|
+
retains its existing native-only connection behavior.
|
|
116
|
+
|
|
117
|
+
## Lifecycle and error recovery
|
|
118
|
+
|
|
119
|
+
The SDK validates the vendor/GATT profile before any pairing work. It uses the
|
|
120
|
+
selected vendor's discovered address, pauses scanning while retaining the target,
|
|
121
|
+
and serializes Windows ceremonies across handler instances. It never chooses a
|
|
122
|
+
different device automatically. Native GATT connect timeout starts after OS
|
|
123
|
+
pairing, so user confirmation does not consume the 31-second connect deadline.
|
|
124
|
+
Discovery and scan pause have a separate deadline using `connectTimeoutMs`.
|
|
125
|
+
Cancellation or that deadline settles the caller independently of native scan
|
|
126
|
+
cleanup; a late discovery cannot start a cancelled pairing.
|
|
127
|
+
|
|
128
|
+
- Ledger numeric comparison expires after 30 seconds. A pending prompt closes on
|
|
129
|
+
device disconnection.
|
|
130
|
+
- Trezor permits a one-second recovery window for transient pairing link changes.
|
|
131
|
+
A persistent disconnection closes an unanswered prompt. This observation is a
|
|
132
|
+
pairing failure, not proof that the user explicitly cancelled on the device.
|
|
133
|
+
- An unanswered ceremony is bounded at 60 seconds; completion after host
|
|
134
|
+
confirmation is bounded at 30 seconds. Cancelling declines the WinRT deferral
|
|
135
|
+
before a five-second fallback kills a stuck helper.
|
|
136
|
+
- Only the first GATT connection after a **fresh bond** may retry once. The SDK
|
|
137
|
+
does not retry a timed-out native connect or replay address/signing commands.
|
|
138
|
+
- A bonded Ledger's immediate GATT link drop can report `BleBondInvalid`. The same
|
|
139
|
+
symptom on Trezor is left as a connection error because locking can cause it.
|
|
140
|
+
|
|
141
|
+
Call `cancelPairing({ vendor, id })` to cancel one target, `{ vendor }` for one
|
|
142
|
+
vendor, or omit the argument to cancel all. This also covers queued OS pairing,
|
|
143
|
+
native connect, and the delayed fresh-bond retry. Cancellation never answers
|
|
144
|
+
another device's prompt. `disconnect(id)` releases an established connection.
|
|
145
|
+
|
|
146
|
+
On window retirement, await `ble.dispose()` before registering replacement IPC
|
|
147
|
+
handlers. This cancels pending OS pairing and closes its prompt. For app shutdown,
|
|
148
|
+
use `disposeForAppQuit`; when sharing noble with another transport, dispose both
|
|
149
|
+
first and deduplicate their `releaseNoble` callbacks before stopping the native
|
|
150
|
+
manager, as documented by `ThirdPartyBleSupportHandle`.
|
|
151
|
+
|
|
152
|
+
Errors preserve `code`, `message`, and `params` across
|
|
153
|
+
`withThirdPartyBleIpcErrors`. The preload must check
|
|
154
|
+
`isThirdPartyBleIpcErrorResponse(response)` and throw `response.error` as data.
|
|
155
|
+
The renderer-side connector uses `rehydrateElectronBleErrors` to restore these
|
|
156
|
+
rejections as structured errors; that function does not unwrap successful IPC
|
|
157
|
+
responses. Forward the normal response unchanged.
|
|
158
|
+
Keep renderer sender authorization outside the error envelope as in the example.
|
|
159
|
+
Do not reduce structured errors to message-only strings.
|
|
160
|
+
|
|
161
|
+
Host recovery UI should offer these steps:
|
|
162
|
+
|
|
163
|
+
| Failure | User action |
|
|
164
|
+
| --- | --- |
|
|
165
|
+
| `BlePairingCancelled` | Return to device selection; let the user retry when ready. |
|
|
166
|
+
| Pairing timeout/device disconnect | Unlock/wake the device and reopen pairing, then retry. |
|
|
167
|
+
| Trezor no longer reachable | Open **Pair new device** on the Safe 7, rescan, and select the current numbered entry. BLE address/name are discovery locators, not wallet identity. |
|
|
168
|
+
| `BleBondInvalid` | Forget the device in Windows Bluetooth settings, reset its host pairing if needed, then pair again. |
|
|
169
|
+
| Repeated GATT failure | Offer system Bluetooth pairing repair as troubleshooting; do not claim every unreachable device has an invalid bond. |
|
|
170
|
+
|
|
171
|
+
Use live SDK device identity for wallet matching, not a remembered BLE address or
|
|
172
|
+
Trezor name suffix. Windows OS bonding and Trezor THP authorization are separate
|
|
173
|
+
layers; the vendor adapter still owns THP events and permissions.
|
|
@@ -23,6 +23,12 @@ var THIRD_PARTY_BLE_CHANNELS = {
|
|
|
23
23
|
/** push event: main → renderer when device disconnects unexpectedly */
|
|
24
24
|
disconnected: "$onekey-3p-ble-disconnected"
|
|
25
25
|
};
|
|
26
|
+
var THIRD_PARTY_BLE_IPC_ERROR_TYPE = "ThirdPartyBleIpcError";
|
|
27
|
+
function isThirdPartyBleIpcErrorResponse(response) {
|
|
28
|
+
if (!response || typeof response !== "object") return false;
|
|
29
|
+
const candidate = response;
|
|
30
|
+
return candidate.type === THIRD_PARTY_BLE_IPC_ERROR_TYPE && candidate.success === false && typeof candidate.error?.message === "string";
|
|
31
|
+
}
|
|
26
32
|
var THIRD_PARTY_BLE_SCAN_DURATION_MS = 5e3;
|
|
27
33
|
var THIRD_PARTY_BLE_SCAN_IDLE_STOP_MS = 1e4;
|
|
28
34
|
var THIRD_PARTY_BLE_DEVICE_TTL_MS = 5e3;
|
|
@@ -32,10 +38,12 @@ var THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS = 3e3;
|
|
|
32
38
|
export {
|
|
33
39
|
__require,
|
|
34
40
|
THIRD_PARTY_BLE_CHANNELS,
|
|
41
|
+
THIRD_PARTY_BLE_IPC_ERROR_TYPE,
|
|
42
|
+
isThirdPartyBleIpcErrorResponse,
|
|
35
43
|
THIRD_PARTY_BLE_SCAN_DURATION_MS,
|
|
36
44
|
THIRD_PARTY_BLE_SCAN_IDLE_STOP_MS,
|
|
37
45
|
THIRD_PARTY_BLE_DEVICE_TTL_MS,
|
|
38
46
|
THIRD_PARTY_BLE_POWER_ON_TIMEOUT_MS,
|
|
39
47
|
THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS
|
|
40
48
|
};
|
|
41
|
-
//# sourceMappingURL=chunk-
|
|
49
|
+
//# sourceMappingURL=chunk-O6YS25TV.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts"],"sourcesContent":["import type { ConnectorSerializedError } from '@onekeyfe/hwk-adapter-core';\n\n/**\n * Renderer/main IPC channels shared by every third-party BLE vendor; prefixed to\n * avoid clashing with the OneKey handler (`$onekey-noble-ble-*`) in one app.\n */\nexport const THIRD_PARTY_BLE_CHANNELS = {\n scan: '$onekey-3p-ble-scan',\n stopScan: '$onekey-3p-ble-stop-scan',\n connect: '$onekey-3p-ble-connect',\n disconnect: '$onekey-3p-ble-disconnect',\n write: '$onekey-3p-ble-write',\n subscribe: '$onekey-3p-ble-subscribe',\n unsubscribe: '$onekey-3p-ble-unsubscribe',\n availability: '$onekey-3p-ble-availability',\n getDevice: '$onekey-3p-ble-get-device',\n readRssi: '$onekey-3p-ble-read-rssi',\n cancelPairing: '$onekey-3p-ble-cancel-pairing',\n /** push event: main → renderer with assembled BLE notification payload */\n notification: '$onekey-3p-ble-notification',\n /** push event: main → renderer when device disconnects unexpectedly */\n disconnected: '$onekey-3p-ble-disconnected',\n} as const;\n\nexport type ThirdPartyBleChannel =\n (typeof THIRD_PARTY_BLE_CHANNELS)[keyof typeof THIRD_PARTY_BLE_CHANNELS];\n\nexport const THIRD_PARTY_BLE_IPC_ERROR_TYPE = 'ThirdPartyBleIpcError';\n\n/** What a handler wrapped by `withThirdPartyBleIpcErrors` returns instead of throwing. */\nexport interface ThirdPartyBleIpcErrorResponse {\n type: typeof THIRD_PARTY_BLE_IPC_ERROR_TYPE;\n success: false;\n error: ConnectorSerializedError;\n}\n\n/** For the preload, which imports this entry: rethrow `response.error` when this matches. */\nexport function isThirdPartyBleIpcErrorResponse(\n response: unknown\n): response is ThirdPartyBleIpcErrorResponse {\n if (!response || typeof response !== 'object') return false;\n const candidate = response as Partial<ThirdPartyBleIpcErrorResponse>;\n return (\n candidate.type === THIRD_PARTY_BLE_IPC_ERROR_TYPE &&\n candidate.success === false &&\n typeof candidate.error?.message === 'string'\n );\n}\n\n/** Reconnect scan window for `connect(id)`. */\nexport const THIRD_PARTY_BLE_SCAN_DURATION_MS = 5_000;\n\n/** Continuous scan auto-stops this long after the last poll (reset, not accumulated). */\nexport const THIRD_PARTY_BLE_SCAN_IDLE_STOP_MS = 10_000;\n\n/** Drop a device from the snapshot if it hasn't re-advertised within this window. */\nexport const THIRD_PARTY_BLE_DEVICE_TTL_MS = 5_000;\n\n/** Time we'll wait for noble to reach `poweredOn` before failing init. */\nexport const THIRD_PARTY_BLE_POWER_ON_TIMEOUT_MS = 10_000;\n\n/** Time an availability check waits for a fresh noble to report its first state. */\nexport const THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS = 3_000;\n"],"mappings":";;;;;;;;AAMO,IAAM,2BAA2B;AAAA,EACtC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,WAAW;AAAA,EACX,aAAa;AAAA,EACb,cAAc;AAAA,EACd,WAAW;AAAA,EACX,UAAU;AAAA,EACV,eAAe;AAAA;AAAA,EAEf,cAAc;AAAA;AAAA,EAEd,cAAc;AAChB;AAKO,IAAM,iCAAiC;AAUvC,SAAS,gCACd,UAC2C;AAC3C,MAAI,CAAC,YAAY,OAAO,aAAa,SAAU,QAAO;AACtD,QAAM,YAAY;AAClB,SACE,UAAU,SAAS,kCACnB,UAAU,YAAY,SACtB,OAAO,UAAU,OAAO,YAAY;AAExC;AAGO,IAAM,mCAAmC;AAGzC,IAAM,oCAAoC;AAG1C,IAAM,gCAAgC;AAGtC,IAAM,sCAAsC;AAG5C,IAAM,0CAA0C;","names":[]}
|
package/dist/constants.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ConnectorSerializedError } from '@onekeyfe/hwk-adapter-core';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Renderer/main IPC channels shared by every third-party BLE vendor; prefixed to
|
|
3
5
|
* avoid clashing with the OneKey handler (`$onekey-noble-ble-*`) in one app.
|
|
@@ -20,6 +22,15 @@ declare const THIRD_PARTY_BLE_CHANNELS: {
|
|
|
20
22
|
readonly disconnected: "$onekey-3p-ble-disconnected";
|
|
21
23
|
};
|
|
22
24
|
type ThirdPartyBleChannel = (typeof THIRD_PARTY_BLE_CHANNELS)[keyof typeof THIRD_PARTY_BLE_CHANNELS];
|
|
25
|
+
declare const THIRD_PARTY_BLE_IPC_ERROR_TYPE = "ThirdPartyBleIpcError";
|
|
26
|
+
/** What a handler wrapped by `withThirdPartyBleIpcErrors` returns instead of throwing. */
|
|
27
|
+
interface ThirdPartyBleIpcErrorResponse {
|
|
28
|
+
type: typeof THIRD_PARTY_BLE_IPC_ERROR_TYPE;
|
|
29
|
+
success: false;
|
|
30
|
+
error: ConnectorSerializedError;
|
|
31
|
+
}
|
|
32
|
+
/** For the preload, which imports this entry: rethrow `response.error` when this matches. */
|
|
33
|
+
declare function isThirdPartyBleIpcErrorResponse(response: unknown): response is ThirdPartyBleIpcErrorResponse;
|
|
23
34
|
/** Reconnect scan window for `connect(id)`. */
|
|
24
35
|
declare const THIRD_PARTY_BLE_SCAN_DURATION_MS = 5000;
|
|
25
36
|
/** Continuous scan auto-stops this long after the last poll (reset, not accumulated). */
|
|
@@ -31,4 +42,4 @@ declare const THIRD_PARTY_BLE_POWER_ON_TIMEOUT_MS = 10000;
|
|
|
31
42
|
/** Time an availability check waits for a fresh noble to report its first state. */
|
|
32
43
|
declare const THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS = 3000;
|
|
33
44
|
|
|
34
|
-
export { THIRD_PARTY_BLE_CHANNELS, THIRD_PARTY_BLE_DEVICE_TTL_MS, THIRD_PARTY_BLE_POWER_ON_TIMEOUT_MS, THIRD_PARTY_BLE_SCAN_DURATION_MS, THIRD_PARTY_BLE_SCAN_IDLE_STOP_MS, THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS, type ThirdPartyBleChannel };
|
|
45
|
+
export { THIRD_PARTY_BLE_CHANNELS, THIRD_PARTY_BLE_DEVICE_TTL_MS, THIRD_PARTY_BLE_IPC_ERROR_TYPE, THIRD_PARTY_BLE_POWER_ON_TIMEOUT_MS, THIRD_PARTY_BLE_SCAN_DURATION_MS, THIRD_PARTY_BLE_SCAN_IDLE_STOP_MS, THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS, type ThirdPartyBleChannel, type ThirdPartyBleIpcErrorResponse, isThirdPartyBleIpcErrorResponse };
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { ConnectorSerializedError } from '@onekeyfe/hwk-adapter-core';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* Renderer/main IPC channels shared by every third-party BLE vendor; prefixed to
|
|
3
5
|
* avoid clashing with the OneKey handler (`$onekey-noble-ble-*`) in one app.
|
|
@@ -20,6 +22,15 @@ declare const THIRD_PARTY_BLE_CHANNELS: {
|
|
|
20
22
|
readonly disconnected: "$onekey-3p-ble-disconnected";
|
|
21
23
|
};
|
|
22
24
|
type ThirdPartyBleChannel = (typeof THIRD_PARTY_BLE_CHANNELS)[keyof typeof THIRD_PARTY_BLE_CHANNELS];
|
|
25
|
+
declare const THIRD_PARTY_BLE_IPC_ERROR_TYPE = "ThirdPartyBleIpcError";
|
|
26
|
+
/** What a handler wrapped by `withThirdPartyBleIpcErrors` returns instead of throwing. */
|
|
27
|
+
interface ThirdPartyBleIpcErrorResponse {
|
|
28
|
+
type: typeof THIRD_PARTY_BLE_IPC_ERROR_TYPE;
|
|
29
|
+
success: false;
|
|
30
|
+
error: ConnectorSerializedError;
|
|
31
|
+
}
|
|
32
|
+
/** For the preload, which imports this entry: rethrow `response.error` when this matches. */
|
|
33
|
+
declare function isThirdPartyBleIpcErrorResponse(response: unknown): response is ThirdPartyBleIpcErrorResponse;
|
|
23
34
|
/** Reconnect scan window for `connect(id)`. */
|
|
24
35
|
declare const THIRD_PARTY_BLE_SCAN_DURATION_MS = 5000;
|
|
25
36
|
/** Continuous scan auto-stops this long after the last poll (reset, not accumulated). */
|
|
@@ -31,4 +42,4 @@ declare const THIRD_PARTY_BLE_POWER_ON_TIMEOUT_MS = 10000;
|
|
|
31
42
|
/** Time an availability check waits for a fresh noble to report its first state. */
|
|
32
43
|
declare const THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS = 3000;
|
|
33
44
|
|
|
34
|
-
export { THIRD_PARTY_BLE_CHANNELS, THIRD_PARTY_BLE_DEVICE_TTL_MS, THIRD_PARTY_BLE_POWER_ON_TIMEOUT_MS, THIRD_PARTY_BLE_SCAN_DURATION_MS, THIRD_PARTY_BLE_SCAN_IDLE_STOP_MS, THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS, type ThirdPartyBleChannel };
|
|
45
|
+
export { THIRD_PARTY_BLE_CHANNELS, THIRD_PARTY_BLE_DEVICE_TTL_MS, THIRD_PARTY_BLE_IPC_ERROR_TYPE, THIRD_PARTY_BLE_POWER_ON_TIMEOUT_MS, THIRD_PARTY_BLE_SCAN_DURATION_MS, THIRD_PARTY_BLE_SCAN_IDLE_STOP_MS, THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS, type ThirdPartyBleChannel, type ThirdPartyBleIpcErrorResponse, isThirdPartyBleIpcErrorResponse };
|
package/dist/constants.js
CHANGED
|
@@ -22,10 +22,12 @@ var constants_exports = {};
|
|
|
22
22
|
__export(constants_exports, {
|
|
23
23
|
THIRD_PARTY_BLE_CHANNELS: () => THIRD_PARTY_BLE_CHANNELS,
|
|
24
24
|
THIRD_PARTY_BLE_DEVICE_TTL_MS: () => THIRD_PARTY_BLE_DEVICE_TTL_MS,
|
|
25
|
+
THIRD_PARTY_BLE_IPC_ERROR_TYPE: () => THIRD_PARTY_BLE_IPC_ERROR_TYPE,
|
|
25
26
|
THIRD_PARTY_BLE_POWER_ON_TIMEOUT_MS: () => THIRD_PARTY_BLE_POWER_ON_TIMEOUT_MS,
|
|
26
27
|
THIRD_PARTY_BLE_SCAN_DURATION_MS: () => THIRD_PARTY_BLE_SCAN_DURATION_MS,
|
|
27
28
|
THIRD_PARTY_BLE_SCAN_IDLE_STOP_MS: () => THIRD_PARTY_BLE_SCAN_IDLE_STOP_MS,
|
|
28
|
-
THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS: () => THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS
|
|
29
|
+
THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS: () => THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS,
|
|
30
|
+
isThirdPartyBleIpcErrorResponse: () => isThirdPartyBleIpcErrorResponse
|
|
29
31
|
});
|
|
30
32
|
module.exports = __toCommonJS(constants_exports);
|
|
31
33
|
var THIRD_PARTY_BLE_CHANNELS = {
|
|
@@ -45,6 +47,12 @@ var THIRD_PARTY_BLE_CHANNELS = {
|
|
|
45
47
|
/** push event: main → renderer when device disconnects unexpectedly */
|
|
46
48
|
disconnected: "$onekey-3p-ble-disconnected"
|
|
47
49
|
};
|
|
50
|
+
var THIRD_PARTY_BLE_IPC_ERROR_TYPE = "ThirdPartyBleIpcError";
|
|
51
|
+
function isThirdPartyBleIpcErrorResponse(response) {
|
|
52
|
+
if (!response || typeof response !== "object") return false;
|
|
53
|
+
const candidate = response;
|
|
54
|
+
return candidate.type === THIRD_PARTY_BLE_IPC_ERROR_TYPE && candidate.success === false && typeof candidate.error?.message === "string";
|
|
55
|
+
}
|
|
48
56
|
var THIRD_PARTY_BLE_SCAN_DURATION_MS = 5e3;
|
|
49
57
|
var THIRD_PARTY_BLE_SCAN_IDLE_STOP_MS = 1e4;
|
|
50
58
|
var THIRD_PARTY_BLE_DEVICE_TTL_MS = 5e3;
|
|
@@ -54,9 +62,11 @@ var THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS = 3e3;
|
|
|
54
62
|
0 && (module.exports = {
|
|
55
63
|
THIRD_PARTY_BLE_CHANNELS,
|
|
56
64
|
THIRD_PARTY_BLE_DEVICE_TTL_MS,
|
|
65
|
+
THIRD_PARTY_BLE_IPC_ERROR_TYPE,
|
|
57
66
|
THIRD_PARTY_BLE_POWER_ON_TIMEOUT_MS,
|
|
58
67
|
THIRD_PARTY_BLE_SCAN_DURATION_MS,
|
|
59
68
|
THIRD_PARTY_BLE_SCAN_IDLE_STOP_MS,
|
|
60
|
-
THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS
|
|
69
|
+
THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS,
|
|
70
|
+
isThirdPartyBleIpcErrorResponse
|
|
61
71
|
});
|
|
62
72
|
//# sourceMappingURL=constants.js.map
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts"],"sourcesContent":["/**\n * Renderer/main IPC channels shared by every third-party BLE vendor; prefixed to\n * avoid clashing with the OneKey handler (`$onekey-noble-ble-*`) in one app.\n */\nexport const THIRD_PARTY_BLE_CHANNELS = {\n scan: '$onekey-3p-ble-scan',\n stopScan: '$onekey-3p-ble-stop-scan',\n connect: '$onekey-3p-ble-connect',\n disconnect: '$onekey-3p-ble-disconnect',\n write: '$onekey-3p-ble-write',\n subscribe: '$onekey-3p-ble-subscribe',\n unsubscribe: '$onekey-3p-ble-unsubscribe',\n availability: '$onekey-3p-ble-availability',\n getDevice: '$onekey-3p-ble-get-device',\n readRssi: '$onekey-3p-ble-read-rssi',\n cancelPairing: '$onekey-3p-ble-cancel-pairing',\n /** push event: main → renderer with assembled BLE notification payload */\n notification: '$onekey-3p-ble-notification',\n /** push event: main → renderer when device disconnects unexpectedly */\n disconnected: '$onekey-3p-ble-disconnected',\n} as const;\n\nexport type ThirdPartyBleChannel =\n (typeof THIRD_PARTY_BLE_CHANNELS)[keyof typeof THIRD_PARTY_BLE_CHANNELS];\n\n/** Reconnect scan window for `connect(id)`. */\nexport const THIRD_PARTY_BLE_SCAN_DURATION_MS = 5_000;\n\n/** Continuous scan auto-stops this long after the last poll (reset, not accumulated). */\nexport const THIRD_PARTY_BLE_SCAN_IDLE_STOP_MS = 10_000;\n\n/** Drop a device from the snapshot if it hasn't re-advertised within this window. */\nexport const THIRD_PARTY_BLE_DEVICE_TTL_MS = 5_000;\n\n/** Time we'll wait for noble to reach `poweredOn` before failing init. */\nexport const THIRD_PARTY_BLE_POWER_ON_TIMEOUT_MS = 10_000;\n\n/** Time an availability check waits for a fresh noble to report its first state. */\nexport const THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS = 3_000;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts"],"sourcesContent":["import type { ConnectorSerializedError } from '@onekeyfe/hwk-adapter-core';\n\n/**\n * Renderer/main IPC channels shared by every third-party BLE vendor; prefixed to\n * avoid clashing with the OneKey handler (`$onekey-noble-ble-*`) in one app.\n */\nexport const THIRD_PARTY_BLE_CHANNELS = {\n scan: '$onekey-3p-ble-scan',\n stopScan: '$onekey-3p-ble-stop-scan',\n connect: '$onekey-3p-ble-connect',\n disconnect: '$onekey-3p-ble-disconnect',\n write: '$onekey-3p-ble-write',\n subscribe: '$onekey-3p-ble-subscribe',\n unsubscribe: '$onekey-3p-ble-unsubscribe',\n availability: '$onekey-3p-ble-availability',\n getDevice: '$onekey-3p-ble-get-device',\n readRssi: '$onekey-3p-ble-read-rssi',\n cancelPairing: '$onekey-3p-ble-cancel-pairing',\n /** push event: main → renderer with assembled BLE notification payload */\n notification: '$onekey-3p-ble-notification',\n /** push event: main → renderer when device disconnects unexpectedly */\n disconnected: '$onekey-3p-ble-disconnected',\n} as const;\n\nexport type ThirdPartyBleChannel =\n (typeof THIRD_PARTY_BLE_CHANNELS)[keyof typeof THIRD_PARTY_BLE_CHANNELS];\n\nexport const THIRD_PARTY_BLE_IPC_ERROR_TYPE = 'ThirdPartyBleIpcError';\n\n/** What a handler wrapped by `withThirdPartyBleIpcErrors` returns instead of throwing. */\nexport interface ThirdPartyBleIpcErrorResponse {\n type: typeof THIRD_PARTY_BLE_IPC_ERROR_TYPE;\n success: false;\n error: ConnectorSerializedError;\n}\n\n/** For the preload, which imports this entry: rethrow `response.error` when this matches. */\nexport function isThirdPartyBleIpcErrorResponse(\n response: unknown\n): response is ThirdPartyBleIpcErrorResponse {\n if (!response || typeof response !== 'object') return false;\n const candidate = response as Partial<ThirdPartyBleIpcErrorResponse>;\n return (\n candidate.type === THIRD_PARTY_BLE_IPC_ERROR_TYPE &&\n candidate.success === false &&\n typeof candidate.error?.message === 'string'\n );\n}\n\n/** Reconnect scan window for `connect(id)`. */\nexport const THIRD_PARTY_BLE_SCAN_DURATION_MS = 5_000;\n\n/** Continuous scan auto-stops this long after the last poll (reset, not accumulated). */\nexport const THIRD_PARTY_BLE_SCAN_IDLE_STOP_MS = 10_000;\n\n/** Drop a device from the snapshot if it hasn't re-advertised within this window. */\nexport const THIRD_PARTY_BLE_DEVICE_TTL_MS = 5_000;\n\n/** Time we'll wait for noble to reach `poweredOn` before failing init. */\nexport const THIRD_PARTY_BLE_POWER_ON_TIMEOUT_MS = 10_000;\n\n/** Time an availability check waits for a fresh noble to report its first state. */\nexport const THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS = 3_000;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAMO,IAAM,2BAA2B;AAAA,EACtC,MAAM;AAAA,EACN,UAAU;AAAA,EACV,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,WAAW;AAAA,EACX,aAAa;AAAA,EACb,cAAc;AAAA,EACd,WAAW;AAAA,EACX,UAAU;AAAA,EACV,eAAe;AAAA;AAAA,EAEf,cAAc;AAAA;AAAA,EAEd,cAAc;AAChB;AAKO,IAAM,iCAAiC;AAUvC,SAAS,gCACd,UAC2C;AAC3C,MAAI,CAAC,YAAY,OAAO,aAAa,SAAU,QAAO;AACtD,QAAM,YAAY;AAClB,SACE,UAAU,SAAS,kCACnB,UAAU,YAAY,SACtB,OAAO,UAAU,OAAO,YAAY;AAExC;AAGO,IAAM,mCAAmC;AAGzC,IAAM,oCAAoC;AAG1C,IAAM,gCAAgC;AAGtC,IAAM,sCAAsC;AAG5C,IAAM,0CAA0C;","names":[]}
|
package/dist/constants.mjs
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
import {
|
|
2
2
|
THIRD_PARTY_BLE_CHANNELS,
|
|
3
3
|
THIRD_PARTY_BLE_DEVICE_TTL_MS,
|
|
4
|
+
THIRD_PARTY_BLE_IPC_ERROR_TYPE,
|
|
4
5
|
THIRD_PARTY_BLE_POWER_ON_TIMEOUT_MS,
|
|
5
6
|
THIRD_PARTY_BLE_SCAN_DURATION_MS,
|
|
6
7
|
THIRD_PARTY_BLE_SCAN_IDLE_STOP_MS,
|
|
7
|
-
THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS
|
|
8
|
-
|
|
8
|
+
THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS,
|
|
9
|
+
isThirdPartyBleIpcErrorResponse
|
|
10
|
+
} from "./chunk-O6YS25TV.mjs";
|
|
9
11
|
export {
|
|
10
12
|
THIRD_PARTY_BLE_CHANNELS,
|
|
11
13
|
THIRD_PARTY_BLE_DEVICE_TTL_MS,
|
|
14
|
+
THIRD_PARTY_BLE_IPC_ERROR_TYPE,
|
|
12
15
|
THIRD_PARTY_BLE_POWER_ON_TIMEOUT_MS,
|
|
13
16
|
THIRD_PARTY_BLE_SCAN_DURATION_MS,
|
|
14
17
|
THIRD_PARTY_BLE_SCAN_IDLE_STOP_MS,
|
|
15
|
-
THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS
|
|
18
|
+
THIRD_PARTY_BLE_STATE_SETTLE_TIMEOUT_MS,
|
|
19
|
+
isThirdPartyBleIpcErrorResponse
|
|
16
20
|
};
|
|
17
21
|
//# sourceMappingURL=constants.mjs.map
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ElectronBleConnectOptions, ElectronBleScanOptions } from '@onekeyfe/hwk-adapter-core';
|
|
2
|
-
|
|
2
|
+
import { ThirdPartyBleIpcErrorResponse } from './constants.mjs';
|
|
3
|
+
export { THIRD_PARTY_BLE_CHANNELS, THIRD_PARTY_BLE_DEVICE_TTL_MS, THIRD_PARTY_BLE_IPC_ERROR_TYPE, THIRD_PARTY_BLE_POWER_ON_TIMEOUT_MS, THIRD_PARTY_BLE_SCAN_DURATION_MS, THIRD_PARTY_BLE_SCAN_IDLE_STOP_MS, ThirdPartyBleChannel, isThirdPartyBleIpcErrorResponse } from './constants.mjs';
|
|
3
4
|
|
|
4
5
|
type BleDebugLogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
5
6
|
type BleDebugLogEntry = {
|
|
@@ -12,6 +13,22 @@ type BleDebugLogger = (entry: BleDebugLogEntry) => void;
|
|
|
12
13
|
/** Replace sensitive values at any depth; everything else is forwarded verbatim. */
|
|
13
14
|
declare function redactBleDebugLogData(data?: Record<string, unknown>): Record<string, unknown> | undefined;
|
|
14
15
|
|
|
16
|
+
type WindowsBlePairingDecision = 'confirm' | 'cancel';
|
|
17
|
+
interface WindowsBlePairingRequest {
|
|
18
|
+
id: string;
|
|
19
|
+
vendor: string;
|
|
20
|
+
/** Numeric comparison only. Never persist or log this value. */
|
|
21
|
+
pin: string;
|
|
22
|
+
/** Close the prompt immediately when aborted; ignore any later UI answer. */
|
|
23
|
+
signal: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
interface WindowsBlePairingOptions {
|
|
26
|
+
/** Absolute path to the host-provided helper, copied outside Electron's ASAR. */
|
|
27
|
+
helperPath: string;
|
|
28
|
+
/** Resolve only after the user compares the code and confirms or cancels. */
|
|
29
|
+
onPairingRequest(request: WindowsBlePairingRequest): Promise<WindowsBlePairingDecision>;
|
|
30
|
+
}
|
|
31
|
+
|
|
15
32
|
/**
|
|
16
33
|
* Main-process allowlist entry for one vendor key. The renderer only names the vendor; which
|
|
17
34
|
* peripherals it may see and which GATT profile and framing it may use are decided here, so an
|
|
@@ -34,7 +51,7 @@ declare const DEFAULT_THIRD_PARTY_BLE_VENDORS: Readonly<Record<string, ThirdPart
|
|
|
34
51
|
|
|
35
52
|
/** Device info the main process returns to the renderer over IPC. */
|
|
36
53
|
interface ThirdPartyBleDeviceInfo {
|
|
37
|
-
/**
|
|
54
|
+
/** Discovery locator (noble peripheral.id), used as connectId. May rotate; not wallet identity. */
|
|
38
55
|
id: string;
|
|
39
56
|
name?: string;
|
|
40
57
|
rssi?: number;
|
|
@@ -154,10 +171,14 @@ interface NobleCharacteristicLike {
|
|
|
154
171
|
}
|
|
155
172
|
type NobleFactory = () => NobleLike;
|
|
156
173
|
interface NobleBleHandlerOptions {
|
|
174
|
+
/** Windows OS bonding before GATT connect. Omit to retain native-only behavior. */
|
|
175
|
+
windowsPairing?: WindowsBlePairingOptions;
|
|
157
176
|
/** Override for tests; defaults to `require('@stoprocent/noble')`. */
|
|
158
177
|
nobleFactory?: NobleFactory;
|
|
159
|
-
/** Override
|
|
178
|
+
/** Override GATT connect timeout (tests only; defaults to 31s), excluding OS pairing. */
|
|
160
179
|
connectTimeoutMs?: number;
|
|
180
|
+
/** Override the subscribe timeout (tests only; defaults to 60s). */
|
|
181
|
+
subscribeTimeoutMs?: number;
|
|
161
182
|
logger?: BleDebugLogger;
|
|
162
183
|
/**
|
|
163
184
|
* Vendors served over IPC, keyed by the `vendor` the renderer sends. Replaces the default map
|
|
@@ -169,16 +190,21 @@ interface NobleBleHandlerOptions {
|
|
|
169
190
|
declare class NobleBleHandler {
|
|
170
191
|
private _noble;
|
|
171
192
|
private readonly _factory;
|
|
193
|
+
private readonly _windowsPairing?;
|
|
172
194
|
private readonly _connectTimeoutMs;
|
|
195
|
+
private readonly _subscribeTimeoutMs;
|
|
173
196
|
private readonly _logger?;
|
|
174
197
|
private readonly _vendors;
|
|
175
198
|
private readonly _discovered;
|
|
176
199
|
private readonly _lastSeen;
|
|
200
|
+
private readonly _advertisedUuids;
|
|
201
|
+
private readonly _keptByMemory;
|
|
177
202
|
private readonly _connected;
|
|
178
203
|
private _discoverHandler?;
|
|
179
204
|
private _scanning;
|
|
180
205
|
private readonly _scanOwners;
|
|
181
206
|
private _scanTransition;
|
|
207
|
+
private _pairingScanPauses;
|
|
182
208
|
private _idleStopTimer?;
|
|
183
209
|
private _onNotification?;
|
|
184
210
|
private _onDeviceDisconnected?;
|
|
@@ -203,6 +229,7 @@ declare class NobleBleHandler {
|
|
|
203
229
|
* packet, and a Safe 7 ADV carries only its name (UUID is in the scan response).
|
|
204
230
|
*/
|
|
205
231
|
scan(options?: ElectronBleScanOptions): Promise<ThirdPartyBleDeviceInfo[]>;
|
|
232
|
+
private _rememberServiceUuids;
|
|
206
233
|
/**
|
|
207
234
|
* In-range devices matching the caller, minus TTL-expired ones. `_discovered`
|
|
208
235
|
* is only a cache; a missing device can still be reached by `_directConnect`.
|
|
@@ -220,6 +247,7 @@ declare class NobleBleHandler {
|
|
|
220
247
|
private _setScanning;
|
|
221
248
|
/** Stop scanning but keep the discovered cache (used before connect). */
|
|
222
249
|
private _pauseScan;
|
|
250
|
+
private _pauseScanForPairing;
|
|
223
251
|
/** Stop scanning and forget discovered devices (idle timeout / teardown). */
|
|
224
252
|
private _stopContinuousScan;
|
|
225
253
|
/** A vendor releasing discovery must not stop another vendor's scan. */
|
|
@@ -251,9 +279,11 @@ declare class NobleBleHandler {
|
|
|
251
279
|
id: string;
|
|
252
280
|
name?: string;
|
|
253
281
|
}>;
|
|
282
|
+
private _connectWithTimeout;
|
|
254
283
|
private _connectInner;
|
|
255
284
|
disconnect(id: string): Promise<void>;
|
|
256
285
|
subscribe(id: string): Promise<void>;
|
|
286
|
+
private _withSubscribeTimeout;
|
|
257
287
|
unsubscribe(id: string): Promise<void>;
|
|
258
288
|
write(id: string, hexData: string): Promise<void>;
|
|
259
289
|
/** Retire a renderer's handler without stopping a process-wide native manager. */
|
|
@@ -297,10 +327,21 @@ interface ThirdPartyBleSupportHandle {
|
|
|
297
327
|
stop?(): void;
|
|
298
328
|
}) => void): Promise<void>;
|
|
299
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* Electron IPC keeps only an Error's message; as data, a `createHwkError`'s code and params
|
|
332
|
+
* survive. Only those cross, so the renderer rebuilds exactly what the host threw.
|
|
333
|
+
*/
|
|
334
|
+
declare function createThirdPartyBleIpcErrorResponse(error: unknown): ThirdPartyBleIpcErrorResponse;
|
|
335
|
+
/**
|
|
336
|
+
* Handlers registered through this resolve failures as `ThirdPartyBleIpcErrorResponse`.
|
|
337
|
+
* Wrap the `ipcMain` that registers with Electron so inner wrappers still see throws, and
|
|
338
|
+
* pair it with a preload that rethrows `response.error`.
|
|
339
|
+
*/
|
|
340
|
+
declare function withThirdPartyBleIpcErrors(ipcMain: IpcMainLike): IpcMainLike;
|
|
300
341
|
/**
|
|
301
342
|
* Wire a `NobleBleHandler` to Electron IPC once `BrowserWindow` is ready. Call dispose()
|
|
302
343
|
* when retiring a renderer and disposeForAppQuit() before Node teardown.
|
|
303
344
|
*/
|
|
304
345
|
declare function initThirdPartyBleSupport(webContents: WebContentsLike, options?: InitThirdPartyBleSupportOptions): ThirdPartyBleSupportHandle;
|
|
305
346
|
|
|
306
|
-
export { type BleDebugLogEntry, type BleDebugLogLevel, type BleDebugLogger, DEFAULT_THIRD_PARTY_BLE_VENDORS, type InitThirdPartyBleSupportOptions, type IpcMainLike, NobleBleHandler, type NobleBleHandlerOptions, type ThirdPartyBleApi, type ThirdPartyBleAvailability, type ThirdPartyBleDeviceInfo, type ThirdPartyBleSupportHandle, type ThirdPartyBleVendorProfile, initThirdPartyBleSupport, redactBleDebugLogData };
|
|
347
|
+
export { type BleDebugLogEntry, type BleDebugLogLevel, type BleDebugLogger, DEFAULT_THIRD_PARTY_BLE_VENDORS, type InitThirdPartyBleSupportOptions, type IpcMainLike, NobleBleHandler, type NobleBleHandlerOptions, type ThirdPartyBleApi, type ThirdPartyBleAvailability, type ThirdPartyBleDeviceInfo, ThirdPartyBleIpcErrorResponse, type ThirdPartyBleSupportHandle, type ThirdPartyBleVendorProfile, type WindowsBlePairingDecision, type WindowsBlePairingOptions, type WindowsBlePairingRequest, createThirdPartyBleIpcErrorResponse, initThirdPartyBleSupport, redactBleDebugLogData, withThirdPartyBleIpcErrors };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ElectronBleConnectOptions, ElectronBleScanOptions } from '@onekeyfe/hwk-adapter-core';
|
|
2
|
-
|
|
2
|
+
import { ThirdPartyBleIpcErrorResponse } from './constants.js';
|
|
3
|
+
export { THIRD_PARTY_BLE_CHANNELS, THIRD_PARTY_BLE_DEVICE_TTL_MS, THIRD_PARTY_BLE_IPC_ERROR_TYPE, THIRD_PARTY_BLE_POWER_ON_TIMEOUT_MS, THIRD_PARTY_BLE_SCAN_DURATION_MS, THIRD_PARTY_BLE_SCAN_IDLE_STOP_MS, ThirdPartyBleChannel, isThirdPartyBleIpcErrorResponse } from './constants.js';
|
|
3
4
|
|
|
4
5
|
type BleDebugLogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
5
6
|
type BleDebugLogEntry = {
|
|
@@ -12,6 +13,22 @@ type BleDebugLogger = (entry: BleDebugLogEntry) => void;
|
|
|
12
13
|
/** Replace sensitive values at any depth; everything else is forwarded verbatim. */
|
|
13
14
|
declare function redactBleDebugLogData(data?: Record<string, unknown>): Record<string, unknown> | undefined;
|
|
14
15
|
|
|
16
|
+
type WindowsBlePairingDecision = 'confirm' | 'cancel';
|
|
17
|
+
interface WindowsBlePairingRequest {
|
|
18
|
+
id: string;
|
|
19
|
+
vendor: string;
|
|
20
|
+
/** Numeric comparison only. Never persist or log this value. */
|
|
21
|
+
pin: string;
|
|
22
|
+
/** Close the prompt immediately when aborted; ignore any later UI answer. */
|
|
23
|
+
signal: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
interface WindowsBlePairingOptions {
|
|
26
|
+
/** Absolute path to the host-provided helper, copied outside Electron's ASAR. */
|
|
27
|
+
helperPath: string;
|
|
28
|
+
/** Resolve only after the user compares the code and confirms or cancels. */
|
|
29
|
+
onPairingRequest(request: WindowsBlePairingRequest): Promise<WindowsBlePairingDecision>;
|
|
30
|
+
}
|
|
31
|
+
|
|
15
32
|
/**
|
|
16
33
|
* Main-process allowlist entry for one vendor key. The renderer only names the vendor; which
|
|
17
34
|
* peripherals it may see and which GATT profile and framing it may use are decided here, so an
|
|
@@ -34,7 +51,7 @@ declare const DEFAULT_THIRD_PARTY_BLE_VENDORS: Readonly<Record<string, ThirdPart
|
|
|
34
51
|
|
|
35
52
|
/** Device info the main process returns to the renderer over IPC. */
|
|
36
53
|
interface ThirdPartyBleDeviceInfo {
|
|
37
|
-
/**
|
|
54
|
+
/** Discovery locator (noble peripheral.id), used as connectId. May rotate; not wallet identity. */
|
|
38
55
|
id: string;
|
|
39
56
|
name?: string;
|
|
40
57
|
rssi?: number;
|
|
@@ -154,10 +171,14 @@ interface NobleCharacteristicLike {
|
|
|
154
171
|
}
|
|
155
172
|
type NobleFactory = () => NobleLike;
|
|
156
173
|
interface NobleBleHandlerOptions {
|
|
174
|
+
/** Windows OS bonding before GATT connect. Omit to retain native-only behavior. */
|
|
175
|
+
windowsPairing?: WindowsBlePairingOptions;
|
|
157
176
|
/** Override for tests; defaults to `require('@stoprocent/noble')`. */
|
|
158
177
|
nobleFactory?: NobleFactory;
|
|
159
|
-
/** Override
|
|
178
|
+
/** Override GATT connect timeout (tests only; defaults to 31s), excluding OS pairing. */
|
|
160
179
|
connectTimeoutMs?: number;
|
|
180
|
+
/** Override the subscribe timeout (tests only; defaults to 60s). */
|
|
181
|
+
subscribeTimeoutMs?: number;
|
|
161
182
|
logger?: BleDebugLogger;
|
|
162
183
|
/**
|
|
163
184
|
* Vendors served over IPC, keyed by the `vendor` the renderer sends. Replaces the default map
|
|
@@ -169,16 +190,21 @@ interface NobleBleHandlerOptions {
|
|
|
169
190
|
declare class NobleBleHandler {
|
|
170
191
|
private _noble;
|
|
171
192
|
private readonly _factory;
|
|
193
|
+
private readonly _windowsPairing?;
|
|
172
194
|
private readonly _connectTimeoutMs;
|
|
195
|
+
private readonly _subscribeTimeoutMs;
|
|
173
196
|
private readonly _logger?;
|
|
174
197
|
private readonly _vendors;
|
|
175
198
|
private readonly _discovered;
|
|
176
199
|
private readonly _lastSeen;
|
|
200
|
+
private readonly _advertisedUuids;
|
|
201
|
+
private readonly _keptByMemory;
|
|
177
202
|
private readonly _connected;
|
|
178
203
|
private _discoverHandler?;
|
|
179
204
|
private _scanning;
|
|
180
205
|
private readonly _scanOwners;
|
|
181
206
|
private _scanTransition;
|
|
207
|
+
private _pairingScanPauses;
|
|
182
208
|
private _idleStopTimer?;
|
|
183
209
|
private _onNotification?;
|
|
184
210
|
private _onDeviceDisconnected?;
|
|
@@ -203,6 +229,7 @@ declare class NobleBleHandler {
|
|
|
203
229
|
* packet, and a Safe 7 ADV carries only its name (UUID is in the scan response).
|
|
204
230
|
*/
|
|
205
231
|
scan(options?: ElectronBleScanOptions): Promise<ThirdPartyBleDeviceInfo[]>;
|
|
232
|
+
private _rememberServiceUuids;
|
|
206
233
|
/**
|
|
207
234
|
* In-range devices matching the caller, minus TTL-expired ones. `_discovered`
|
|
208
235
|
* is only a cache; a missing device can still be reached by `_directConnect`.
|
|
@@ -220,6 +247,7 @@ declare class NobleBleHandler {
|
|
|
220
247
|
private _setScanning;
|
|
221
248
|
/** Stop scanning but keep the discovered cache (used before connect). */
|
|
222
249
|
private _pauseScan;
|
|
250
|
+
private _pauseScanForPairing;
|
|
223
251
|
/** Stop scanning and forget discovered devices (idle timeout / teardown). */
|
|
224
252
|
private _stopContinuousScan;
|
|
225
253
|
/** A vendor releasing discovery must not stop another vendor's scan. */
|
|
@@ -251,9 +279,11 @@ declare class NobleBleHandler {
|
|
|
251
279
|
id: string;
|
|
252
280
|
name?: string;
|
|
253
281
|
}>;
|
|
282
|
+
private _connectWithTimeout;
|
|
254
283
|
private _connectInner;
|
|
255
284
|
disconnect(id: string): Promise<void>;
|
|
256
285
|
subscribe(id: string): Promise<void>;
|
|
286
|
+
private _withSubscribeTimeout;
|
|
257
287
|
unsubscribe(id: string): Promise<void>;
|
|
258
288
|
write(id: string, hexData: string): Promise<void>;
|
|
259
289
|
/** Retire a renderer's handler without stopping a process-wide native manager. */
|
|
@@ -297,10 +327,21 @@ interface ThirdPartyBleSupportHandle {
|
|
|
297
327
|
stop?(): void;
|
|
298
328
|
}) => void): Promise<void>;
|
|
299
329
|
}
|
|
330
|
+
/**
|
|
331
|
+
* Electron IPC keeps only an Error's message; as data, a `createHwkError`'s code and params
|
|
332
|
+
* survive. Only those cross, so the renderer rebuilds exactly what the host threw.
|
|
333
|
+
*/
|
|
334
|
+
declare function createThirdPartyBleIpcErrorResponse(error: unknown): ThirdPartyBleIpcErrorResponse;
|
|
335
|
+
/**
|
|
336
|
+
* Handlers registered through this resolve failures as `ThirdPartyBleIpcErrorResponse`.
|
|
337
|
+
* Wrap the `ipcMain` that registers with Electron so inner wrappers still see throws, and
|
|
338
|
+
* pair it with a preload that rethrows `response.error`.
|
|
339
|
+
*/
|
|
340
|
+
declare function withThirdPartyBleIpcErrors(ipcMain: IpcMainLike): IpcMainLike;
|
|
300
341
|
/**
|
|
301
342
|
* Wire a `NobleBleHandler` to Electron IPC once `BrowserWindow` is ready. Call dispose()
|
|
302
343
|
* when retiring a renderer and disposeForAppQuit() before Node teardown.
|
|
303
344
|
*/
|
|
304
345
|
declare function initThirdPartyBleSupport(webContents: WebContentsLike, options?: InitThirdPartyBleSupportOptions): ThirdPartyBleSupportHandle;
|
|
305
346
|
|
|
306
|
-
export { type BleDebugLogEntry, type BleDebugLogLevel, type BleDebugLogger, DEFAULT_THIRD_PARTY_BLE_VENDORS, type InitThirdPartyBleSupportOptions, type IpcMainLike, NobleBleHandler, type NobleBleHandlerOptions, type ThirdPartyBleApi, type ThirdPartyBleAvailability, type ThirdPartyBleDeviceInfo, type ThirdPartyBleSupportHandle, type ThirdPartyBleVendorProfile, initThirdPartyBleSupport, redactBleDebugLogData };
|
|
347
|
+
export { type BleDebugLogEntry, type BleDebugLogLevel, type BleDebugLogger, DEFAULT_THIRD_PARTY_BLE_VENDORS, type InitThirdPartyBleSupportOptions, type IpcMainLike, NobleBleHandler, type NobleBleHandlerOptions, type ThirdPartyBleApi, type ThirdPartyBleAvailability, type ThirdPartyBleDeviceInfo, ThirdPartyBleIpcErrorResponse, type ThirdPartyBleSupportHandle, type ThirdPartyBleVendorProfile, type WindowsBlePairingDecision, type WindowsBlePairingOptions, type WindowsBlePairingRequest, createThirdPartyBleIpcErrorResponse, initThirdPartyBleSupport, redactBleDebugLogData, withThirdPartyBleIpcErrors };
|