diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 2fdb773c3baa..8e564843c636 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -17,6 +17,7 @@ export * from "./security/DSK"; export * from "./security/Manager"; export * from "./security/Manager2"; export * from "./security/QR"; +export * from "./security/QR_safe"; export * from "./security/SecurityClass"; export * from "./security/crypto"; export * from "./security/ctr_drbg"; diff --git a/packages/core/src/index_safe.ts b/packages/core/src/index_safe.ts index 12520357e9e2..c335564e4656 100644 --- a/packages/core/src/index_safe.ts +++ b/packages/core/src/index_safe.ts @@ -14,6 +14,7 @@ export * from "./consts"; export * from "./error/ZWaveError"; export * from "./log/shared_safe"; export * from "./security/DSK"; +export * from "./security/QR_safe"; export * from "./security/SecurityClass"; export * from "./security/shared_safe"; export * from "./util/_Types"; diff --git a/packages/core/src/security/QR.test.ts b/packages/core/src/security/QR.test.ts index 67d961d5b7c8..e6dbc1ceee33 100644 --- a/packages/core/src/security/QR.test.ts +++ b/packages/core/src/security/QR.test.ts @@ -1,6 +1,7 @@ import test from "ava"; import { SecurityClass, ZWaveErrorCodes, assertZWaveError } from ".."; -import { QRCodeVersion, parseQRCodeString } from "./QR"; +import { parseQRCodeString } from "./QR"; +import { QRCodeVersion } from "./QR_safe"; function createDummyQR(firstDigits: string): string { return firstDigits + "0".repeat(52 - firstDigits.length); diff --git a/packages/core/src/security/QR.ts b/packages/core/src/security/QR.ts index 5832b7a381cf..4815f97d16bd 100644 --- a/packages/core/src/security/QR.ts +++ b/packages/core/src/security/QR.ts @@ -3,6 +3,16 @@ import { Protocols } from "../capabilities/Protocols"; import { ZWaveError, ZWaveErrorCodes } from "../error/ZWaveError"; import { parseBitMask } from "../values/Primitive"; import { dskToString } from "./DSK"; +import { + ProvisioningInformationType, + type ProvisioningInformation_MaxInclusionRequestInterval, + type ProvisioningInformation_ProductId, + type ProvisioningInformation_ProductType, + type ProvisioningInformation_SupportedProtocols, + type ProvisioningInformation_UUID16, + QRCodeVersion, + type QRProvisioningInformation, +} from "./QR_safe"; import { SecurityClass } from "./SecurityClass"; function readNumber(qr: string, offset: number, length: number): number { @@ -40,71 +50,6 @@ function readUInt16(qr: string, offset: number): number { const onlyDigitsRegex = /^\d+$/; const minQRCodeLength = 52; // 2 digits Z, 2 digits version, 5 digits checksum, 3 digits keys, 40 digits DSK -export enum QRCodeVersion { - S2 = 0, - SmartStart = 1, -} - -export enum ProvisioningInformationType { - ProductType = 0x00, - ProductId = 0x01, - MaxInclusionRequestInterval = 0x02, - UUID16 = 0x03, - SupportedProtocols = 0x04, - // The ones below are NOT QR code compatible and therefore not implemented here - Name = 0x32, - Location = 0x33, - SmartStartInclusionSetting = 0x34, - AdvancedJoining = 0x35, - BootstrappingMode = 0x36, - NetworkStatus = 0x37, -} - -export interface ProvisioningInformation_ProductType { - genericDeviceClass: number; - specificDeviceClass: number; - installerIconType: number; -} - -export interface ProvisioningInformation_ProductId { - manufacturerId: number; - productType: number; - productId: number; - applicationVersion: string; -} - -export interface ProvisioningInformation_MaxInclusionRequestInterval { - maxInclusionRequestInterval: number; -} - -export interface ProvisioningInformation_UUID16 { - uuid: string; -} - -export interface ProvisioningInformation_SupportedProtocols { - supportedProtocols: Protocols[]; -} - -export type QRProvisioningInformation = - & { - version: QRCodeVersion; - /** - * The security classes that were **requested** by the device. - */ - readonly requestedSecurityClasses: SecurityClass[]; - /** - * The security classes that will be **granted** to this device. - * Until this has been changed by a user, this will be identical to {@link requestedSecurityClasses}. - */ - securityClasses: SecurityClass[]; - dsk: string; - } - & ProvisioningInformation_ProductType - & ProvisioningInformation_ProductId - & Partial - & Partial - & Partial; - function parseTLVData(type: ProvisioningInformationType, data: string) { switch (type) { case ProvisioningInformationType.ProductType: { diff --git a/packages/core/src/security/QR_safe.ts b/packages/core/src/security/QR_safe.ts new file mode 100644 index 000000000000..04bbea4b4c21 --- /dev/null +++ b/packages/core/src/security/QR_safe.ts @@ -0,0 +1,67 @@ +import { type Protocols } from "../capabilities/Protocols"; +import { type SecurityClass } from "./SecurityClass"; + +export enum QRCodeVersion { + S2 = 0, + SmartStart = 1, +} + +export enum ProvisioningInformationType { + ProductType = 0x00, + ProductId = 0x01, + MaxInclusionRequestInterval = 0x02, + UUID16 = 0x03, + SupportedProtocols = 0x04, + // The ones below are NOT QR code compatible and therefore not implemented here + Name = 0x32, + Location = 0x33, + SmartStartInclusionSetting = 0x34, + AdvancedJoining = 0x35, + BootstrappingMode = 0x36, + NetworkStatus = 0x37, +} + +export interface ProvisioningInformation_ProductType { + genericDeviceClass: number; + specificDeviceClass: number; + installerIconType: number; +} + +export interface ProvisioningInformation_ProductId { + manufacturerId: number; + productType: number; + productId: number; + applicationVersion: string; +} + +export interface ProvisioningInformation_MaxInclusionRequestInterval { + maxInclusionRequestInterval: number; +} + +export interface ProvisioningInformation_UUID16 { + uuid: string; +} + +export interface ProvisioningInformation_SupportedProtocols { + supportedProtocols: Protocols[]; +} + +export type QRProvisioningInformation = + & { + version: QRCodeVersion; + /** + * The security classes that were **requested** by the device. + */ + readonly requestedSecurityClasses: SecurityClass[]; + /** + * The security classes that will be **granted** to this device. + * Until this has been changed by a user, this will be identical to {@link requestedSecurityClasses}. + */ + securityClasses: SecurityClass[]; + dsk: string; + } + & ProvisioningInformation_ProductType + & ProvisioningInformation_ProductId + & Partial + & Partial + & Partial;