Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: split QR module into frontend and Node.js code #6774

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/index_safe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/security/QR.test.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
75 changes: 10 additions & 65 deletions packages/core/src/security/QR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<ProvisioningInformation_MaxInclusionRequestInterval>
& Partial<ProvisioningInformation_UUID16>
& Partial<ProvisioningInformation_SupportedProtocols>;

function parseTLVData(type: ProvisioningInformationType, data: string) {
switch (type) {
case ProvisioningInformationType.ProductType: {
Expand Down
67 changes: 67 additions & 0 deletions packages/core/src/security/QR_safe.ts
Original file line number Diff line number Diff line change
@@ -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<ProvisioningInformation_MaxInclusionRequestInterval>
& Partial<ProvisioningInformation_UUID16>
& Partial<ProvisioningInformation_SupportedProtocols>;
Loading