@ukeyfe/hardware-shared 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.
- package/README.md +3 -0
- package/dist/HardwareError.d.ts +128 -0
- package/dist/HardwareError.d.ts.map +1 -0
- package/dist/constants.d.ts +35 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/deferred.d.ts +9 -0
- package/dist/deferred.d.ts.map +1 -0
- package/dist/deviceType.d.ts +10 -0
- package/dist/deviceType.d.ts.map +1 -0
- package/dist/firmwareType.d.ts +5 -0
- package/dist/firmwareType.d.ts.map +1 -0
- package/dist/index.d.ts +220 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +509 -0
- package/dist/timerUtils.d.ts +2 -0
- package/dist/timerUtils.d.ts.map +1 -0
- package/package.json +28 -0
- package/src/HardwareError.ts +751 -0
- package/src/constants.ts +78 -0
- package/src/deferred.ts +35 -0
- package/src/deviceType.ts +9 -0
- package/src/firmwareType.ts +4 -0
- package/src/index.ts +7 -0
- package/src/timerUtils.ts +4 -0
- package/tsconfig.json +7 -0
package/src/constants.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
export const UKEY_WEBUSB_FILTER = [
|
|
2
|
+
{ vendorId: 0x1209, productId: 0x53c0 }, // Classic Boot、Classic1s Boot、Mini Boot
|
|
3
|
+
{ vendorId: 0x1209, productId: 0x53c1 }, // Classic Firmware、Classic1s Firmware、Mini Firmware、Pro Firmware、Touch Firmware
|
|
4
|
+
{ vendorId: 0x1209, productId: 0x4f4a }, // Pro Boot、Touch Boot
|
|
5
|
+
{ vendorId: 0x1209, productId: 0x4f4b }, // Pro Firmware、Touch Firmware(Not implemented Trezor)
|
|
6
|
+
// { vendorId: 0x1209, productId: 0x4f4c }, // Pro Board
|
|
7
|
+
// { vendorId: 0x1209, productId: 0x4f50 }, // Touch Board
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
// BLE IPC communication message types
|
|
11
|
+
export enum EUKeyBleMessageKeys {
|
|
12
|
+
// BLE device selection related
|
|
13
|
+
BLE_SELECT = '$ukey-ble-select',
|
|
14
|
+
BLE_SELECT_RESULT = '$ukey-ble-select-result',
|
|
15
|
+
BLE_STOP_SCAN = '$ukey-ble-stop-scan',
|
|
16
|
+
BLE_CANCEL_REQUEST = '$ukey-ble-cancel-request',
|
|
17
|
+
BLE_PRE_SELECT = '$ukey-ble-pre-select',
|
|
18
|
+
BLE_CLEAR_PRE_SELECT = '$ukey-ble-clear-pre-select',
|
|
19
|
+
|
|
20
|
+
// BLE pairing related
|
|
21
|
+
BLE_PAIRING_REQUEST = '$ukey-ble-pairing-request',
|
|
22
|
+
BLE_PAIRING_RESPONSE = '$ukey-ble-pairing-response',
|
|
23
|
+
|
|
24
|
+
// BLE enumeration related
|
|
25
|
+
BLE_ENUMERATE = '$ukey-ble-enumerate',
|
|
26
|
+
BLE_ENUMERATE_RESULT = '$ukey-ble-enumerate-result',
|
|
27
|
+
|
|
28
|
+
// BLE connection status related
|
|
29
|
+
BLE_DEVICE_DISCONNECTED = '$ukey-ble-device-disconnected',
|
|
30
|
+
BLE_AVAILABILITY_CHECK = '$ukey-ble-availability-check',
|
|
31
|
+
|
|
32
|
+
// Noble BLE related (for direct BLE communication)
|
|
33
|
+
NOBLE_BLE_ENUMERATE = '$ukey-noble-ble-enumerate',
|
|
34
|
+
NOBLE_BLE_STOP_SCAN = '$ukey-noble-ble-stop-scan',
|
|
35
|
+
NOBLE_BLE_GET_DEVICE = '$ukey-noble-ble-get-device',
|
|
36
|
+
NOBLE_BLE_CONNECT = '$ukey-noble-ble-connect',
|
|
37
|
+
NOBLE_BLE_DISCONNECT = '$ukey-noble-ble-disconnect',
|
|
38
|
+
NOBLE_BLE_WRITE = '$ukey-noble-ble-write',
|
|
39
|
+
NOBLE_BLE_SUBSCRIBE = '$ukey-noble-ble-subscribe',
|
|
40
|
+
NOBLE_BLE_UNSUBSCRIBE = '$ukey-noble-ble-unsubscribe',
|
|
41
|
+
NOBLE_BLE_NOTIFICATION = '$ukey-noble-ble-notification',
|
|
42
|
+
NOBLE_BLE_CANCEL_PAIRING = '$ukey-noble-ble-cancel-pairing',
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const UKEY_SERVICE_UUID = '00000001-0000-1000-8000-00805f9b34fb';
|
|
46
|
+
export const UKEY_WRITE_CHARACTERISTIC_UUID = '00000002-0000-1000-8000-00805f9b34fb';
|
|
47
|
+
export const UKEY_NOTIFY_CHARACTERISTIC_UUID = '00000003-0000-1000-8000-00805f9b34fb';
|
|
48
|
+
|
|
49
|
+
const MESSAGE_TOP_CHAR = 63;
|
|
50
|
+
const MESSAGE_HEADER_BYTE = 35;
|
|
51
|
+
export const isHeaderChunk = (chunk: Buffer | Uint8Array): boolean => {
|
|
52
|
+
if (chunk.length < 9) return false;
|
|
53
|
+
const [MagicQuestionMark, sharp1, sharp2] = chunk;
|
|
54
|
+
|
|
55
|
+
if (
|
|
56
|
+
String.fromCharCode(MagicQuestionMark) === String.fromCharCode(MESSAGE_TOP_CHAR) &&
|
|
57
|
+
String.fromCharCode(sharp1) === String.fromCharCode(MESSAGE_HEADER_BYTE) &&
|
|
58
|
+
String.fromCharCode(sharp2) === String.fromCharCode(MESSAGE_HEADER_BYTE)
|
|
59
|
+
) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return false;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const isUkeyDevice = (name: string | null, id?: string): boolean => {
|
|
67
|
+
if (id?.startsWith?.('MI')) {
|
|
68
|
+
return true;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// 过滤 BixinKeyxxx 和 Kxxxx 和 Txxxx
|
|
72
|
+
// i 忽略大小写模式
|
|
73
|
+
const re = /(BixinKey\d{10})|(K\d{4})|(T\d{4})|(Touch\s\w{4})|(Pro\s\w{4})/i;
|
|
74
|
+
if (name && re.exec(name)) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
};
|
package/src/deferred.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type Deferred<T, I = any, D = any> = {
|
|
2
|
+
id?: I;
|
|
3
|
+
data?: D;
|
|
4
|
+
promise: Promise<T>;
|
|
5
|
+
resolve: (t: T) => void;
|
|
6
|
+
reject: (e: Error) => void;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function createDeferred<T, I = any, D = any>(arg?: I, data?: D): Deferred<T, I, D> {
|
|
10
|
+
let localResolve: (t: T) => void = (_t: T) => {};
|
|
11
|
+
let localReject: (e?: Error) => void = (_e?: Error) => {};
|
|
12
|
+
let id: I | undefined;
|
|
13
|
+
|
|
14
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
15
|
+
const promise: Promise<T> = new Promise(async (resolve, reject) => {
|
|
16
|
+
localResolve = resolve;
|
|
17
|
+
localReject = reject;
|
|
18
|
+
if (typeof arg === 'function') {
|
|
19
|
+
try {
|
|
20
|
+
await arg();
|
|
21
|
+
} catch (error) {
|
|
22
|
+
reject(error);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
if (typeof arg === 'string') id = arg;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return {
|
|
29
|
+
id,
|
|
30
|
+
data,
|
|
31
|
+
resolve: localResolve,
|
|
32
|
+
reject: localReject,
|
|
33
|
+
promise,
|
|
34
|
+
};
|
|
35
|
+
}
|
package/src/index.ts
ADDED