incyclist-devices 3.0.9 → 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.
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -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;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -406,7 +406,7 @@ class BleInterface extends node_events_1.EventEmitter {
406
406
  this.addService(announcement);
407
407
  }
408
408
  checkForWahooEnhancement(announcement) {
409
- if (announcement.name.includes('KICKR')) {
409
+ if (announcement.name.includes('KICKR') || announcement.name.includes('Zwift')) {
410
410
  const supported = announcement.serviceUUIDs.map(s => (0, utils_js_1.beautifyUUID)(s));
411
411
  if (supported.length === 1 && (supported[0] === '1818' || supported[0] === 'FC82')) {
412
412
  return true;
@@ -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
- return node_crypto_1.generateKeyPairSync !== undefined && typeof (node_crypto_1.generateKeyPairSync) === 'function';
489
+ const crypto = this.getCrypto();
490
+ return crypto?.generateKeyPairSync !== undefined && typeof (crypto?.generateKeyPairSync) === 'function';
484
491
  }
485
492
  createKeyPair() {
486
- return (0, node_crypto_1.generateKeyPairSync)('ec', {
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' }
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);
@@ -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 {};
@@ -403,7 +403,7 @@ export class BleInterface extends EventEmitter {
403
403
  this.addService(announcement);
404
404
  }
405
405
  checkForWahooEnhancement(announcement) {
406
- if (announcement.name.includes('KICKR')) {
406
+ if (announcement.name.includes('KICKR') || announcement.name.includes('Zwift')) {
407
407
  const supported = announcement.serviceUUIDs.map(s => beautifyUUID(s));
408
408
  if (supported.length === 1 && (supported[0] === '1818' || supported[0] === 'FC82')) {
409
409
  return true;
@@ -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
- return generateKeyPairSync !== undefined && typeof (generateKeyPairSync) === 'function';
486
+ const crypto = this.getCrypto();
487
+ return crypto?.generateKeyPairSync !== undefined && typeof (crypto?.generateKeyPairSync) === 'function';
481
488
  }
482
489
  createKeyPair() {
483
- return generateKeyPairSync('ec', {
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' }
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 };
@@ -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
+ }
@@ -0,0 +1,4 @@
1
+ import { ICryptoBinding } from "./crypto/types";
2
+ export interface IDeviceBinding {
3
+ crypto: ICryptoBinding;
4
+ }
@@ -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;
@@ -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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "incyclist-devices",
3
- "version": "3.0.9",
3
+ "version": "3.0.10",
4
4
  "scripts": {
5
5
  "lint": "eslint . --ext .ts",
6
6
  "build": "npm run build:esm && npm run build:cjs",