@ukeyfe/hardware-transport-electron 1.1.13

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.
@@ -0,0 +1,3 @@
1
+ import type { WebContents } from 'electron';
2
+ export declare function setupNobleBleHandlers(webContents: WebContents): void;
3
+ //# sourceMappingURL=noble-ble-handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noble-ble-handler.d.ts","sourceRoot":"","sources":["../src/noble-ble-handler.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,WAAW,EAAsB,MAAM,UAAU,CAAC;AAq9ChE,wBAAgB,qBAAqB,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI,CAsKpE"}
@@ -0,0 +1,30 @@
1
+ export interface NobleBleAPI {
2
+ enumerate: () => Promise<{
3
+ id: string;
4
+ name: string;
5
+ }[]>;
6
+ getDevice: (uuid: string) => Promise<{
7
+ id: string;
8
+ name: string;
9
+ } | null>;
10
+ connect: (uuid: string) => Promise<void>;
11
+ disconnect: (uuid: string) => Promise<void>;
12
+ subscribe: (uuid: string) => Promise<void>;
13
+ unsubscribe: (uuid: string) => Promise<void>;
14
+ write: (uuid: string, data: string) => Promise<void>;
15
+ onNotification: (callback: (deviceId: string, data: string) => void) => () => void;
16
+ onDeviceDisconnected: (callback: (device: {
17
+ id: string;
18
+ name: string;
19
+ }) => void) => () => void;
20
+ checkAvailability: () => Promise<{
21
+ available: boolean;
22
+ state: string;
23
+ unsupported: boolean;
24
+ initialized: boolean;
25
+ }>;
26
+ }
27
+ export interface DesktopAPI {
28
+ nobleBle?: NobleBleAPI;
29
+ }
30
+ //# sourceMappingURL=desktop-api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"desktop-api.d.ts","sourceRoot":"","sources":["../../src/types/desktop-api.ts"],"names":[],"mappings":"AAMA,MAAM,WAAW,WAAW;IAC1B,SAAS,EAAE,MAAM,OAAO,CAAC;QAAE,EAAE,EAAE,M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from './noble-extended';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,UAAU,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,26 @@
1
+ import type { Peripheral, Characteristic } from '@stoprocent/noble';
2
+ export interface DeviceInfo {
3
+ id: string;
4
+ name: string;
5
+ state: string;
6
+ }
7
+ export interface CharacteristicPair {
8
+ write: Characteristic;
9
+ notify: Characteristic;
10
+ }
11
+ export interface NobleModule {
12
+ state: string;
13
+ startScanning(serviceUUIDs: string[], allowDuplicates: boolean, callback?: (error?: Error) => void): void;
14
+ stopScanning(callback?: () => void): void;
15
+ on(event: 'stateChange', listener: (state: string) => void): void;
16
+ on(event: 'discover', listener: (peripheral: Peripheral) => void): void;
17
+ removeListener(event: 'stateChange', listener: (state: string) => void): void;
18
+ removeListener(event: 'discover', listener: (peripheral: Peripheral) => void): void;
19
+ }
20
+ export interface Logger {
21
+ info(message: string, ...args: any[]): void;
22
+ debug(message: string, ...args: any[]): void;
23
+ error(message: string, ...args: any[]): void;
24
+ }
25
+ export declare function safeLog(logger: Logger | null, level: 'info' | 'debug' | 'error', message: string, ...args: any[]): void;
26
+ //# sourceMappingURL=noble-extended.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"noble-extended.d.ts","sourceRoot":"","sources":["../../src/types/noble-extended.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAGpE,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAGD,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,cAAc,CAAC;IACtB,MAAM,EAAE,cAAc,C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0,0 +1,39 @@
1
+ {
2
+ "name": "@ukeyfe/hardware-transport-electron",
3
+ "version": "1.1.13",
4
+ "author": "UKey",
5
+ "homepage": "https://github.com/UKeyHQ/hardware-js-sdk#readme",
6
+ "license": "MIT",
7
+ "main": "dist/index.js",
8
+ "types": "dist/index.d.ts",
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "git+https://github.com/bestyourwallet/hardware-js-sdk"
15
+ },
16
+ "scripts": {
17
+ "dev": "rimraf dist && rollup -c ../../build/rollup.config.js -w",
18
+ "build": "rimraf dist && rollup -c ../../build/rollup.config.js",
19
+ "lint": "eslint .",
20
+ "lint:fix": "eslint . --fix"
21
+ },
22
+ "sideEffects": false,
23
+ "peerDependencies": {
24
+ "electron": ">=25.0.0",
25
+ "electron-log": ">=4.0.0"
26
+ },
27
+ "dependencies": {
28
+ "@ukeyfe/hardware-core": "1.1.13",
29
+ "@ukeyfe/hardware-shared": "1.1.13",
30
+ "@ukeyfe/hardware-transport": "1.1.13",
31
+ "@stoprocent/noble": "2.3.4",
32
+ "p-retry": "^4.6.2"
33
+ },
34
+ "devDependencies": {
35
+ "@types/web-bluetooth": "^0.0.17",
36
+ "electron": "^25.0.0",
37
+ "typescript": "^5.3.3"
38
+ }
39
+ }
package/src/ble-ops.ts ADDED
@@ -0,0 +1,77 @@
1
+ import type { Characteristic } from '@stoprocent/noble';
2
+ import type { Logger } from './types/noble-extended';
3
+
4
+ export interface SoftRefreshParams {
5
+ deviceId: string;
6
+ notifyCharacteristic: Characteristic | null | undefined;
7
+ subscriptionOperations: Map<string, 'subscribing' | 'unsubscribing' | 'idle'>;
8
+ subscribedDevices: Map<string, boolean>;
9
+ pairedDevices: Set<string>;
10
+ notificationCallbacks: Map<string, (hex: string) => void>;
11
+ processNotificationData: (
12
+ deviceId: string,
13
+ data: Buffer
14
+ ) => {
15
+ isComplete: boolean;
16
+ completePacket?: string;
17
+ error?: string;
18
+ };
19
+ logger: Logger | null;
20
+ }
21
+
22
+ export async function softRefreshSubscription(params: SoftRefreshParams): Promise<void> {
23
+ const {
24
+ deviceId,
25
+ notifyCharacteristic,
26
+ subscriptionOperations,
27
+ subscribedDevices,
28
+ pairedDevices,
29
+ notificationCallbacks,
30
+ processNotificationData,
31
+ logger,
32
+ } = params;
33
+
34
+ if (!notifyCharacteristic) {
35
+ throw new Error(`Notify characteristic not available for device ${deviceId}`);
36
+ }
37
+
38
+ logger?.info('[BLE-OPS] Starting subscription refresh', { deviceId });
39
+
40
+ subscriptionOperations.set(deviceId, 'subscribing');
41
+
42
+ await new Promise<void>(resolve => {
43
+ notifyCharacteristic.unsubscribe(() => resolve());
44
+ });
45
+
46
+ await new Promise<void>((resolve, reject) => {
47
+ notifyCharacteristic.subscribe((error?: Error) => {
48
+ if (error) {
49
+ reject(error);
50
+ return;
51
+ }
52
+ resolve();
53
+ });
54
+ });
55
+
56
+ notifyCharacteristic.removeAllListeners('data');
57
+ notifyCharacteristic.on('data', (data: Buffer) => {
58
+ if (!pairedDevices.has(deviceId)) {
59
+ pairedDevices.add(deviceId);
60
+ logger?.info('[BLE-OPS] Device paired successfully', { deviceId });
61
+ }
62
+
63
+ const result = processNotificationData(deviceId, data);
64
+ if (result.error) {
65
+ logger?.error('[BLE-OPS] Packet processing error:', result.error);
66
+ return;
67
+ }
68
+ if (result.isComplete && result.completePacket) {
69
+ const appCb = notificationCallbacks.get(deviceId);
70
+ if (appCb) appCb(result.completePacket);
71
+ }
72
+ });
73
+
74
+ subscribedDevices.set(deviceId, true);
75
+ subscriptionOperations.set(deviceId, 'idle');
76
+ logger?.info('[BLE-OPS] Subscription refresh completed', { deviceId });
77
+ }
package/src/index.ts ADDED
@@ -0,0 +1,11 @@
1
+ import type { WebContents } from 'electron';
2
+
3
+ export * from './types';
4
+
5
+ // Export Desktop API types for other packages to reuse
6
+ export type { DesktopAPI, NobleBleAPI } from './types/desktop-api';
7
+
8
+ export async function initNobleBleSupport(webContents: WebContents) {
9
+ const { setupNobleBleHandlers } = await import('./noble-ble-handler');
10
+ setupNobleBleHandlers(webContents);
11
+ }