incyclist-devices 3.0.8 → 3.0.10
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/lib/cjs/antv2/base/interface.js +3 -0
- package/lib/cjs/bindings/crypto/types.js +2 -0
- package/lib/cjs/bindings/index.js +18 -0
- package/lib/cjs/bindings/types.js +2 -0
- package/lib/cjs/ble/base/interface.js +7 -2
- package/lib/cjs/ble/zwift/play/sensor.js +11 -3
- package/lib/cjs/direct-connect/base/interface.js +6 -3
- package/lib/cjs/index.js +1 -0
- package/lib/cjs/serial/base/serial-interface.js +3 -0
- package/lib/esm/antv2/base/interface.js +3 -0
- package/lib/esm/bindings/crypto/index.js +14 -0
- package/lib/esm/bindings/crypto/types.js +1 -0
- package/lib/esm/bindings/index.js +14 -0
- package/lib/esm/bindings/types.js +1 -0
- package/lib/esm/ble/base/interface.js +7 -2
- package/lib/esm/ble/bindings/crypto/types.js +1 -0
- package/lib/esm/ble/zwift/play/sensor.js +11 -3
- package/lib/esm/direct-connect/base/interface.js +6 -3
- package/lib/esm/index.js +1 -0
- package/lib/esm/serial/base/serial-interface.js +3 -0
- package/lib/types/antv2/base/interface.d.ts +1 -0
- package/lib/types/bindings/crypto/index.d.ts +8 -0
- package/lib/types/bindings/crypto/types.d.ts +45 -0
- package/lib/types/bindings/index.d.ts +8 -0
- package/lib/types/bindings/types.d.ts +4 -0
- package/lib/types/ble/base/interface.d.ts +2 -1
- package/lib/types/ble/bindings/crypto/types.d.ts +45 -0
- package/lib/types/ble/zwift/play/sensor.d.ts +2 -0
- package/lib/types/direct-connect/base/interface.d.ts +2 -1
- package/lib/types/index.d.ts +1 -0
- package/lib/types/serial/base/serial-interface.d.ts +1 -0
- package/lib/types/types/interface.d.ts +1 -0
- package/package.json +1 -1
|
@@ -144,6 +144,9 @@ class AntInterface extends node_events_1.EventEmitter {
|
|
|
144
144
|
this.connected = false;
|
|
145
145
|
return closed;
|
|
146
146
|
}
|
|
147
|
+
async terminate() {
|
|
148
|
+
await this.disconnect();
|
|
149
|
+
}
|
|
147
150
|
onError(profile, error) {
|
|
148
151
|
this.logEvent({ message: 'ANT+ERROR:', profile, error });
|
|
149
152
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BindingsFactory = void 0;
|
|
4
|
+
class BindingsFactory {
|
|
5
|
+
static instance;
|
|
6
|
+
binding;
|
|
7
|
+
static getInstance() {
|
|
8
|
+
this.instance = this.instance ?? new BindingsFactory();
|
|
9
|
+
return this.instance;
|
|
10
|
+
}
|
|
11
|
+
getBinding() {
|
|
12
|
+
return this.binding;
|
|
13
|
+
}
|
|
14
|
+
setBinding(binding) {
|
|
15
|
+
this.binding = binding;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.BindingsFactory = BindingsFactory;
|
|
@@ -115,7 +115,6 @@ class BleInterface extends node_events_1.EventEmitter {
|
|
|
115
115
|
return false;
|
|
116
116
|
}
|
|
117
117
|
if (this.isConnecting()) {
|
|
118
|
-
this.logEvent({ message: 'BLE connect - already connecting' });
|
|
119
118
|
return this.connectTask.getPromise();
|
|
120
119
|
}
|
|
121
120
|
this.logEvent({ message: 'BLE connect request' });
|
|
@@ -184,6 +183,9 @@ class BleInterface extends node_events_1.EventEmitter {
|
|
|
184
183
|
const success = await this.disconnectTask.run().catch(() => false);
|
|
185
184
|
return success;
|
|
186
185
|
}
|
|
186
|
+
async terminate() {
|
|
187
|
+
await this.disconnect();
|
|
188
|
+
}
|
|
187
189
|
isConnected() {
|
|
188
190
|
return this.confirmedBleState === 'poweredOn';
|
|
189
191
|
}
|
|
@@ -404,7 +406,7 @@ class BleInterface extends node_events_1.EventEmitter {
|
|
|
404
406
|
this.addService(announcement);
|
|
405
407
|
}
|
|
406
408
|
checkForWahooEnhancement(announcement) {
|
|
407
|
-
if (announcement.name.includes('KICKR')) {
|
|
409
|
+
if (announcement.name.includes('KICKR') || announcement.name.includes('Zwift')) {
|
|
408
410
|
const supported = announcement.serviceUUIDs.map(s => (0, utils_js_1.beautifyUUID)(s));
|
|
409
411
|
if (supported.length === 1 && (supported[0] === '1818' || supported[0] === 'FC82')) {
|
|
410
412
|
return true;
|
|
@@ -629,6 +631,9 @@ class BleInterface extends node_events_1.EventEmitter {
|
|
|
629
631
|
});
|
|
630
632
|
}
|
|
631
633
|
onError(err) {
|
|
634
|
+
if (typeof err === 'string') {
|
|
635
|
+
this.logError(new Error(err), 'BLE connect');
|
|
636
|
+
}
|
|
632
637
|
this.logError(err, 'BLE connect');
|
|
633
638
|
}
|
|
634
639
|
async onConnected() {
|
|
@@ -4,8 +4,8 @@ exports.BleZwiftPlaySensor = void 0;
|
|
|
4
4
|
const zwift_hub_js_1 = require("../../../proto/zwift_hub.js");
|
|
5
5
|
const sensor_js_1 = require("../../base/sensor.js");
|
|
6
6
|
const utils_js_1 = require("../../utils.js");
|
|
7
|
-
const node_crypto_1 = require("node:crypto");
|
|
8
7
|
const node_events_1 = require("node:events");
|
|
8
|
+
const index_js_1 = require("../../../bindings/index.js");
|
|
9
9
|
class BleZwiftPlaySensor extends sensor_js_1.TBleSensor {
|
|
10
10
|
static profile = 'Controller';
|
|
11
11
|
static protocol = 'zwift-play';
|
|
@@ -479,11 +479,19 @@ class BleZwiftPlaySensor extends sensor_js_1.TBleSensor {
|
|
|
479
479
|
}
|
|
480
480
|
reset() {
|
|
481
481
|
}
|
|
482
|
+
getCrypto() {
|
|
483
|
+
let crypto = index_js_1.BindingsFactory.getInstance()?.getBinding()?.crypto;
|
|
484
|
+
if (!crypto)
|
|
485
|
+
crypto = require('node:crypto');
|
|
486
|
+
return crypto;
|
|
487
|
+
}
|
|
482
488
|
encryptedSupported() {
|
|
483
|
-
|
|
489
|
+
const crypto = this.getCrypto();
|
|
490
|
+
return crypto?.generateKeyPairSync !== undefined && typeof (crypto?.generateKeyPairSync) === 'function';
|
|
484
491
|
}
|
|
485
492
|
createKeyPair() {
|
|
486
|
-
|
|
493
|
+
const crypto = this.getCrypto();
|
|
494
|
+
return crypto.generateKeyPairSync('ec', {
|
|
487
495
|
namedCurve: 'prime256v1',
|
|
488
496
|
publicKeyEncoding: { type: 'spki', format: 'der' },
|
|
489
497
|
privateKeyEncoding: { type: 'pkcs8', format: 'der' }
|
|
@@ -144,13 +144,16 @@ class DirectConnectInterface extends node_events_1.EventEmitter {
|
|
|
144
144
|
return true;
|
|
145
145
|
this.logEvent({ message: 'Disconnecting from Direct Connect' });
|
|
146
146
|
await this.stopScan();
|
|
147
|
+
return true;
|
|
148
|
+
}
|
|
149
|
+
async terminate() {
|
|
150
|
+
await this.disconnect();
|
|
147
151
|
this.getBinding()?.mdns?.disconnect();
|
|
148
152
|
this.internalEvents.removeAllListeners();
|
|
149
153
|
this.connected = false;
|
|
150
154
|
const disconnected = !this.isConnected();
|
|
151
155
|
if (disconnected)
|
|
152
156
|
this.emit('disconnect');
|
|
153
|
-
return disconnected;
|
|
154
157
|
}
|
|
155
158
|
isConnected() {
|
|
156
159
|
return this.connected && this.getBinding()?.mdns !== undefined && this.binding.mdns !== null;
|
|
@@ -159,7 +162,7 @@ class DirectConnectInterface extends node_events_1.EventEmitter {
|
|
|
159
162
|
this.logDisabled = false;
|
|
160
163
|
if (this.isScanning()) {
|
|
161
164
|
this.logEvent({ message: 'starting scan - already scanning' });
|
|
162
|
-
await this.scanTask
|
|
165
|
+
await this.scanTask?.getPromise();
|
|
163
166
|
}
|
|
164
167
|
this.logEvent({ message: 'starting scan ..' });
|
|
165
168
|
await this.reconnect();
|
|
@@ -177,7 +180,7 @@ class DirectConnectInterface extends node_events_1.EventEmitter {
|
|
|
177
180
|
if (!this.isScanning())
|
|
178
181
|
return true;
|
|
179
182
|
this.logEvent({ message: 'stopping scan ...', interface: 'wifi' });
|
|
180
|
-
const res = await this.scanTask
|
|
183
|
+
const res = await this.scanTask?.stop();
|
|
181
184
|
delete this.scanTask;
|
|
182
185
|
return (res === true);
|
|
183
186
|
}
|
package/lib/cjs/index.js
CHANGED
|
@@ -49,3 +49,4 @@ __exportStar(require("./antv2/index.js"), exports);
|
|
|
49
49
|
__exportStar(require("./direct-connect/index.js"), exports);
|
|
50
50
|
__exportStar(require("./features/index.js"), exports);
|
|
51
51
|
__exportStar(require("./proto/zwift_hub.js"), exports);
|
|
52
|
+
__exportStar(require("./bindings/index.js"), exports);
|
|
@@ -118,6 +118,9 @@ class SerialInterface extends node_events_1.EventEmitter {
|
|
|
118
118
|
this.connected = false;
|
|
119
119
|
return true;
|
|
120
120
|
}
|
|
121
|
+
async terminate() {
|
|
122
|
+
await this.disconnect();
|
|
123
|
+
}
|
|
121
124
|
async openPort(path) {
|
|
122
125
|
this.logEvent({ message: 'opening port', port: path });
|
|
123
126
|
const existing = this.ports.findIndex(p => p.path === path);
|
|
@@ -139,6 +139,9 @@ export default class AntInterface extends EventEmitter {
|
|
|
139
139
|
this.connected = false;
|
|
140
140
|
return closed;
|
|
141
141
|
}
|
|
142
|
+
async terminate() {
|
|
143
|
+
await this.disconnect();
|
|
144
|
+
}
|
|
142
145
|
onError(profile, error) {
|
|
143
146
|
this.logEvent({ message: 'ANT+ERROR:', profile, error });
|
|
144
147
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class BindingsFactory {
|
|
2
|
+
static instance;
|
|
3
|
+
binding;
|
|
4
|
+
static getInstance() {
|
|
5
|
+
this.instance = this.instance ?? new BindingsFactory();
|
|
6
|
+
return this.instance;
|
|
7
|
+
}
|
|
8
|
+
getBinding() {
|
|
9
|
+
return this.binding;
|
|
10
|
+
}
|
|
11
|
+
setBinding(binding) {
|
|
12
|
+
this.binding = binding;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export class BindingsFactory {
|
|
2
|
+
static instance;
|
|
3
|
+
binding;
|
|
4
|
+
static getInstance() {
|
|
5
|
+
this.instance = this.instance ?? new BindingsFactory();
|
|
6
|
+
return this.instance;
|
|
7
|
+
}
|
|
8
|
+
getBinding() {
|
|
9
|
+
return this.binding;
|
|
10
|
+
}
|
|
11
|
+
setBinding(binding) {
|
|
12
|
+
this.binding = binding;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -112,7 +112,6 @@ export class BleInterface extends EventEmitter {
|
|
|
112
112
|
return false;
|
|
113
113
|
}
|
|
114
114
|
if (this.isConnecting()) {
|
|
115
|
-
this.logEvent({ message: 'BLE connect - already connecting' });
|
|
116
115
|
return this.connectTask.getPromise();
|
|
117
116
|
}
|
|
118
117
|
this.logEvent({ message: 'BLE connect request' });
|
|
@@ -181,6 +180,9 @@ export class BleInterface extends EventEmitter {
|
|
|
181
180
|
const success = await this.disconnectTask.run().catch(() => false);
|
|
182
181
|
return success;
|
|
183
182
|
}
|
|
183
|
+
async terminate() {
|
|
184
|
+
await this.disconnect();
|
|
185
|
+
}
|
|
184
186
|
isConnected() {
|
|
185
187
|
return this.confirmedBleState === 'poweredOn';
|
|
186
188
|
}
|
|
@@ -401,7 +403,7 @@ export class BleInterface extends EventEmitter {
|
|
|
401
403
|
this.addService(announcement);
|
|
402
404
|
}
|
|
403
405
|
checkForWahooEnhancement(announcement) {
|
|
404
|
-
if (announcement.name.includes('KICKR')) {
|
|
406
|
+
if (announcement.name.includes('KICKR') || announcement.name.includes('Zwift')) {
|
|
405
407
|
const supported = announcement.serviceUUIDs.map(s => beautifyUUID(s));
|
|
406
408
|
if (supported.length === 1 && (supported[0] === '1818' || supported[0] === 'FC82')) {
|
|
407
409
|
return true;
|
|
@@ -626,6 +628,9 @@ export class BleInterface extends EventEmitter {
|
|
|
626
628
|
});
|
|
627
629
|
}
|
|
628
630
|
onError(err) {
|
|
631
|
+
if (typeof err === 'string') {
|
|
632
|
+
this.logError(new Error(err), 'BLE connect');
|
|
633
|
+
}
|
|
629
634
|
this.logError(err, 'BLE connect');
|
|
630
635
|
}
|
|
631
636
|
async onConnected() {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ClickKeyPadStatus, DeviceDataEnvelope, DeviceInformationContent, DeviceSettings, HubCommand, HubRequest, HubRidingData, Idle, PlayButtonStatus, TrainerResponse } from "../../../proto/zwift_hub.js";
|
|
2
2
|
import { TBleSensor } from "../../base/sensor.js";
|
|
3
3
|
import { beautifyUUID, fullUUID } from "../../utils.js";
|
|
4
|
-
import { generateKeyPairSync } from 'node:crypto';
|
|
5
4
|
import { EventEmitter } from "node:events";
|
|
5
|
+
import { BindingsFactory } from "../../../bindings/index.js";
|
|
6
6
|
export class BleZwiftPlaySensor extends TBleSensor {
|
|
7
7
|
static profile = 'Controller';
|
|
8
8
|
static protocol = 'zwift-play';
|
|
@@ -476,11 +476,19 @@ export class BleZwiftPlaySensor extends TBleSensor {
|
|
|
476
476
|
}
|
|
477
477
|
reset() {
|
|
478
478
|
}
|
|
479
|
+
getCrypto() {
|
|
480
|
+
let crypto = BindingsFactory.getInstance()?.getBinding()?.crypto;
|
|
481
|
+
if (!crypto)
|
|
482
|
+
crypto = require('node:crypto');
|
|
483
|
+
return crypto;
|
|
484
|
+
}
|
|
479
485
|
encryptedSupported() {
|
|
480
|
-
|
|
486
|
+
const crypto = this.getCrypto();
|
|
487
|
+
return crypto?.generateKeyPairSync !== undefined && typeof (crypto?.generateKeyPairSync) === 'function';
|
|
481
488
|
}
|
|
482
489
|
createKeyPair() {
|
|
483
|
-
|
|
490
|
+
const crypto = this.getCrypto();
|
|
491
|
+
return crypto.generateKeyPairSync('ec', {
|
|
484
492
|
namedCurve: 'prime256v1',
|
|
485
493
|
publicKeyEncoding: { type: 'spki', format: 'der' },
|
|
486
494
|
privateKeyEncoding: { type: 'pkcs8', format: 'der' }
|
|
@@ -141,13 +141,16 @@ export default class DirectConnectInterface extends EventEmitter {
|
|
|
141
141
|
return true;
|
|
142
142
|
this.logEvent({ message: 'Disconnecting from Direct Connect' });
|
|
143
143
|
await this.stopScan();
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
async terminate() {
|
|
147
|
+
await this.disconnect();
|
|
144
148
|
this.getBinding()?.mdns?.disconnect();
|
|
145
149
|
this.internalEvents.removeAllListeners();
|
|
146
150
|
this.connected = false;
|
|
147
151
|
const disconnected = !this.isConnected();
|
|
148
152
|
if (disconnected)
|
|
149
153
|
this.emit('disconnect');
|
|
150
|
-
return disconnected;
|
|
151
154
|
}
|
|
152
155
|
isConnected() {
|
|
153
156
|
return this.connected && this.getBinding()?.mdns !== undefined && this.binding.mdns !== null;
|
|
@@ -156,7 +159,7 @@ export default class DirectConnectInterface extends EventEmitter {
|
|
|
156
159
|
this.logDisabled = false;
|
|
157
160
|
if (this.isScanning()) {
|
|
158
161
|
this.logEvent({ message: 'starting scan - already scanning' });
|
|
159
|
-
await this.scanTask
|
|
162
|
+
await this.scanTask?.getPromise();
|
|
160
163
|
}
|
|
161
164
|
this.logEvent({ message: 'starting scan ..' });
|
|
162
165
|
await this.reconnect();
|
|
@@ -174,7 +177,7 @@ export default class DirectConnectInterface extends EventEmitter {
|
|
|
174
177
|
if (!this.isScanning())
|
|
175
178
|
return true;
|
|
176
179
|
this.logEvent({ message: 'stopping scan ...', interface: 'wifi' });
|
|
177
|
-
const res = await this.scanTask
|
|
180
|
+
const res = await this.scanTask?.stop();
|
|
178
181
|
delete this.scanTask;
|
|
179
182
|
return (res === true);
|
|
180
183
|
}
|
package/lib/esm/index.js
CHANGED
|
@@ -15,4 +15,5 @@ export * from './antv2/index.js';
|
|
|
15
15
|
export * from './direct-connect/index.js';
|
|
16
16
|
export * from './features/index.js';
|
|
17
17
|
export * from './proto/zwift_hub.js';
|
|
18
|
+
export * from './bindings/index.js';
|
|
18
19
|
export { IncyclistDevice, AdapterFactory, InterfaceFactory, INTERFACE, IncyclistCapability, calc, MockBinding, BleHrMock, DaumClassicMock, DaumClassicSimulator, DaumClassicMockImpl, DaumPremiumMock, DaumPremiumMockImpl, DaumPremiumMockSimulator };
|
|
@@ -113,6 +113,9 @@ export default class SerialInterface extends EventEmitter {
|
|
|
113
113
|
this.connected = false;
|
|
114
114
|
return true;
|
|
115
115
|
}
|
|
116
|
+
async terminate() {
|
|
117
|
+
await this.disconnect();
|
|
118
|
+
}
|
|
116
119
|
async openPort(path) {
|
|
117
120
|
this.logEvent({ message: 'opening port', port: path });
|
|
118
121
|
const existing = this.ports.findIndex(p => p.path === path);
|
|
@@ -39,6 +39,7 @@ export default class AntInterface extends EventEmitter implements IncyclistInter
|
|
|
39
39
|
isConnected(): boolean;
|
|
40
40
|
connect(): Promise<boolean>;
|
|
41
41
|
disconnect(): Promise<boolean>;
|
|
42
|
+
terminate(): Promise<void>;
|
|
42
43
|
onError(profile: any, error: any): void;
|
|
43
44
|
onData(profile: any, id: any, data: any, tag: any): void;
|
|
44
45
|
getReconnectPause(): number;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IDeviceBinding } from "../types";
|
|
2
|
+
export declare class BindingsFactory {
|
|
3
|
+
protected static instance: BindingsFactory;
|
|
4
|
+
protected binding: IDeviceBinding | undefined;
|
|
5
|
+
protected static getInstance(): BindingsFactory;
|
|
6
|
+
getBinding(): IDeviceBinding | undefined;
|
|
7
|
+
setBinding(binding: IDeviceBinding): void;
|
|
8
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type KeyFormat = 'pem' | 'der';
|
|
2
|
+
export type KeyType = 'rsa' | 'rsa-pss' | 'dsa' | 'ec' | 'ed25519' | 'ed448' | 'x25519' | 'x448';
|
|
3
|
+
export interface KeyEncodingOptions {
|
|
4
|
+
type: 'pkcs1' | 'pkcs8' | 'spki' | 'sec1';
|
|
5
|
+
format: KeyFormat;
|
|
6
|
+
}
|
|
7
|
+
export interface GenerateKeyPairOptions {
|
|
8
|
+
modulusLength?: number;
|
|
9
|
+
publicExponent?: number;
|
|
10
|
+
namedCurve?: string;
|
|
11
|
+
publicKeyEncoding: KeyEncodingOptions;
|
|
12
|
+
privateKeyEncoding: KeyEncodingOptions;
|
|
13
|
+
}
|
|
14
|
+
export interface KeyPair {
|
|
15
|
+
publicKey: string | Buffer<ArrayBufferLike>;
|
|
16
|
+
privateKey: string | Buffer<ArrayBufferLike>;
|
|
17
|
+
}
|
|
18
|
+
export interface IHash {
|
|
19
|
+
update(data: string | Buffer<ArrayBufferLike>): IHash;
|
|
20
|
+
digest(encoding: 'hex' | 'base64'): string;
|
|
21
|
+
digest(): Buffer<ArrayBufferLike>;
|
|
22
|
+
}
|
|
23
|
+
export interface IHmac {
|
|
24
|
+
update(data: string | Buffer<ArrayBufferLike>): IHmac;
|
|
25
|
+
digest(encoding: 'hex' | 'base64'): string;
|
|
26
|
+
digest(): Buffer<ArrayBufferLike>;
|
|
27
|
+
}
|
|
28
|
+
export interface ICipher {
|
|
29
|
+
update(data: Buffer<ArrayBufferLike>): Buffer<ArrayBufferLike>;
|
|
30
|
+
final(): Buffer<ArrayBufferLike>;
|
|
31
|
+
setAutoPadding(autoPadding?: boolean): ICipher;
|
|
32
|
+
}
|
|
33
|
+
export interface IDecipher {
|
|
34
|
+
update(data: Buffer<ArrayBufferLike>): Buffer<ArrayBufferLike>;
|
|
35
|
+
final(): Buffer<ArrayBufferLike>;
|
|
36
|
+
setAutoPadding(autoPadding?: boolean): IDecipher;
|
|
37
|
+
}
|
|
38
|
+
export interface ICryptoBinding {
|
|
39
|
+
randomBytes(size: number): Buffer<ArrayBufferLike>;
|
|
40
|
+
createHash(algorithm: string): IHash;
|
|
41
|
+
createHmac(algorithm: string, key: string | Buffer<ArrayBufferLike>): IHmac;
|
|
42
|
+
createCipheriv(algorithm: string, key: Buffer<ArrayBufferLike>, iv: Buffer<ArrayBufferLike>): ICipher;
|
|
43
|
+
createDecipheriv(algorithm: string, key: Buffer<ArrayBufferLike>, iv: Buffer<ArrayBufferLike>): IDecipher;
|
|
44
|
+
generateKeyPairSync(type: KeyType, options: GenerateKeyPairOptions): KeyPair;
|
|
45
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { IDeviceBinding } from "./types";
|
|
2
|
+
export declare class BindingsFactory {
|
|
3
|
+
protected static instance: BindingsFactory;
|
|
4
|
+
protected binding: IDeviceBinding | undefined;
|
|
5
|
+
static getInstance(): BindingsFactory;
|
|
6
|
+
getBinding(): IDeviceBinding | undefined;
|
|
7
|
+
setBinding(binding: IDeviceBinding): void;
|
|
8
|
+
}
|
|
@@ -54,6 +54,7 @@ export declare class BleInterface extends EventEmitter implements IBleInterface<
|
|
|
54
54
|
connect(reconnect?: boolean): Promise<boolean>;
|
|
55
55
|
connectInternal(reconnect?: boolean): Promise<boolean>;
|
|
56
56
|
disconnect(connectionLost?: boolean): Promise<boolean>;
|
|
57
|
+
terminate(): Promise<void>;
|
|
57
58
|
isConnected(): boolean;
|
|
58
59
|
registerConnected(peripheral: IBlePeripheral, id: string): void;
|
|
59
60
|
unregisterConnected(id: string): void;
|
|
@@ -101,7 +102,7 @@ export declare class BleInterface extends EventEmitter implements IBleInterface<
|
|
|
101
102
|
addKnownDevice(_settings: BleDeviceSettings): void;
|
|
102
103
|
protected connectBle(): Promise<boolean>;
|
|
103
104
|
protected waitForBleConnected(): Promise<boolean>;
|
|
104
|
-
protected onError(err: Error): void;
|
|
105
|
+
protected onError(err: Error | string): void;
|
|
105
106
|
protected onConnected(): Promise<void>;
|
|
106
107
|
protected onDisconnected(): Promise<void>;
|
|
107
108
|
protected onBleStateChange(state: BleInterfaceState): Promise<void>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type KeyFormat = 'pem' | 'der';
|
|
2
|
+
export type KeyType = 'rsa' | 'rsa-pss' | 'dsa' | 'ec' | 'ed25519' | 'ed448' | 'x25519' | 'x448';
|
|
3
|
+
export interface KeyEncodingOptions {
|
|
4
|
+
type: 'pkcs1' | 'pkcs8' | 'spki' | 'sec1';
|
|
5
|
+
format: KeyFormat;
|
|
6
|
+
}
|
|
7
|
+
export interface GenerateKeyPairOptions {
|
|
8
|
+
modulusLength?: number;
|
|
9
|
+
publicExponent?: number;
|
|
10
|
+
namedCurve?: string;
|
|
11
|
+
publicKeyEncoding: KeyEncodingOptions;
|
|
12
|
+
privateKeyEncoding: KeyEncodingOptions;
|
|
13
|
+
}
|
|
14
|
+
export interface KeyPair {
|
|
15
|
+
publicKey: string | Buffer<ArrayBufferLike>;
|
|
16
|
+
privateKey: string | Buffer<ArrayBufferLike>;
|
|
17
|
+
}
|
|
18
|
+
export interface IHash {
|
|
19
|
+
update(data: string | Buffer<ArrayBufferLike>): IHash;
|
|
20
|
+
digest(encoding: 'hex' | 'base64'): string;
|
|
21
|
+
digest(): Buffer<ArrayBufferLike>;
|
|
22
|
+
}
|
|
23
|
+
export interface IHmac {
|
|
24
|
+
update(data: string | Buffer<ArrayBufferLike>): IHmac;
|
|
25
|
+
digest(encoding: 'hex' | 'base64'): string;
|
|
26
|
+
digest(): Buffer<ArrayBufferLike>;
|
|
27
|
+
}
|
|
28
|
+
export interface ICipher {
|
|
29
|
+
update(data: Buffer<ArrayBufferLike>): Buffer<ArrayBufferLike>;
|
|
30
|
+
final(): Buffer<ArrayBufferLike>;
|
|
31
|
+
setAutoPadding(autoPadding?: boolean): ICipher;
|
|
32
|
+
}
|
|
33
|
+
export interface IDecipher {
|
|
34
|
+
update(data: Buffer<ArrayBufferLike>): Buffer<ArrayBufferLike>;
|
|
35
|
+
final(): Buffer<ArrayBufferLike>;
|
|
36
|
+
setAutoPadding(autoPadding?: boolean): IDecipher;
|
|
37
|
+
}
|
|
38
|
+
export interface ICryptoBinding {
|
|
39
|
+
randomBytes(size: number): Buffer<ArrayBufferLike>;
|
|
40
|
+
createHash(algorithm: string): IHash;
|
|
41
|
+
createHmac(algorithm: string, key: string | Buffer<ArrayBufferLike>): IHmac;
|
|
42
|
+
createCipheriv(algorithm: string, key: Buffer<ArrayBufferLike>, iv: Buffer<ArrayBufferLike>): ICipher;
|
|
43
|
+
createDecipheriv(algorithm: string, key: Buffer<ArrayBufferLike>, iv: Buffer<ArrayBufferLike>): IDecipher;
|
|
44
|
+
generateKeyPairSync(type: KeyType, options: GenerateKeyPairOptions): KeyPair;
|
|
45
|
+
}
|
|
@@ -4,6 +4,7 @@ import { DeviceSettingsSubContent, HubCommand, HubRequest, SimulationParam } fro
|
|
|
4
4
|
import { TBleSensor } from "../../base/sensor.js";
|
|
5
5
|
import { BleProtocol, IBlePeripheral } from "../../types.js";
|
|
6
6
|
import { EventEmitter } from "node:events";
|
|
7
|
+
import { ICryptoBinding } from "../../../bindings/crypto/types.js";
|
|
7
8
|
type ButtonState = {
|
|
8
9
|
pressed: boolean;
|
|
9
10
|
timestamp: number;
|
|
@@ -62,6 +63,7 @@ export declare class BleZwiftPlaySensor extends TBleSensor {
|
|
|
62
63
|
read(characteristic: string, ignoreErrors?: boolean): Promise<Buffer | null>;
|
|
63
64
|
pair(): Promise<boolean>;
|
|
64
65
|
reset(): void;
|
|
66
|
+
protected getCrypto(): ICryptoBinding;
|
|
65
67
|
protected encryptedSupported(): boolean;
|
|
66
68
|
protected createKeyPair(): any;
|
|
67
69
|
protected setInitialState(): void;
|
|
@@ -24,7 +24,7 @@ export default class DirectConnectInterface extends EventEmitter implements IBle
|
|
|
24
24
|
protected logDisabled: boolean;
|
|
25
25
|
protected internalEvents: EventEmitter;
|
|
26
26
|
protected services: Announcement[];
|
|
27
|
-
protected scanTask: InteruptableTask<TaskState, DeviceSettings[]
|
|
27
|
+
protected scanTask: InteruptableTask<TaskState, DeviceSettings[]> | undefined;
|
|
28
28
|
protected matching?: Array<string>;
|
|
29
29
|
protected instance: number;
|
|
30
30
|
protected connected: boolean;
|
|
@@ -43,6 +43,7 @@ export default class DirectConnectInterface extends EventEmitter implements IBle
|
|
|
43
43
|
autoConnect(): void;
|
|
44
44
|
connect(reconnect?: boolean): Promise<boolean>;
|
|
45
45
|
disconnect(): Promise<boolean>;
|
|
46
|
+
terminate(): Promise<void>;
|
|
46
47
|
isConnected(): boolean;
|
|
47
48
|
scan(props: DirectConnectScanProps): Promise<DeviceSettings[]>;
|
|
48
49
|
stopScan(): Promise<boolean>;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -19,4 +19,5 @@ export * from './antv2/index.js';
|
|
|
19
19
|
export * from './direct-connect/index.js';
|
|
20
20
|
export * from './features/index.js';
|
|
21
21
|
export * from './proto/zwift_hub.js';
|
|
22
|
+
export * from './bindings/index.js';
|
|
22
23
|
export { IAdapter, IncyclistDevice, IncyclistDeviceAdapter, DeviceSettings, DeviceProperties, AdapterFactory, InterfaceFactory, IncyclistInterface, INTERFACE, InterfaceProps, ICyclingMode, IncyclistAdapterData as DeviceData, IncyclistCapability, calc, MockBinding, BleHrMock, DaumClassicMock, DaumClassicSimulator, DaumClassicMockImpl, DaumPremiumMock, DaumPremiumMockImpl, DaumPremiumMockSimulator };
|
|
@@ -26,6 +26,7 @@ export default class SerialInterface extends EventEmitter implements IncyclistIn
|
|
|
26
26
|
releaseInUse(path: string): void;
|
|
27
27
|
connect(): Promise<boolean>;
|
|
28
28
|
disconnect(): Promise<boolean>;
|
|
29
|
+
terminate(): Promise<void>;
|
|
29
30
|
openPort(path: string): Promise<SerialPortStream | null>;
|
|
30
31
|
closePort(path: string): Promise<boolean>;
|
|
31
32
|
scan(props: SerialScannerProps): Promise<SerialDeviceSettings[]>;
|
|
@@ -12,6 +12,7 @@ export interface IncyclistInterface extends EventEmitter {
|
|
|
12
12
|
setBinding(binding: any): void;
|
|
13
13
|
connect(): Promise<boolean>;
|
|
14
14
|
disconnect(): Promise<boolean>;
|
|
15
|
+
terminate(): Promise<void>;
|
|
15
16
|
isConnected(): boolean;
|
|
16
17
|
scan(props: IncyclistScanProps): Promise<DeviceSettings[]>;
|
|
17
18
|
stopScan(): Promise<boolean>;
|