Skip to content

Commit

Permalink
Allow S2 keys in OZW format for migration from networkKey (#399)
Browse files Browse the repository at this point in the history
  • Loading branch information
kpine authored Sep 30, 2021
1 parent 0c6a1e2 commit a0e014e
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/bin/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ import { ZwavejsServer } from "../lib/server";
import { createMockDriver } from "../mock";
import { parseArgs } from "../util/parse-args";

const normalizeKey = (
key: Buffer | string,
keyName: string,
supportOZWFormat: boolean = false
): Buffer => {
const normalizeKey = (key: Buffer | string, keyName: string): Buffer => {
if (Buffer.isBuffer(key)) return key;
if (key.length === 32) return Buffer.from(key, "hex");
if (supportOZWFormat && key.includes("0x"))
// Convert from OpenZWave format
if (key.includes("0x"))
return Buffer.from(key.replace(/0x/g, "").replace(/, /g, ""), "hex");
throw new Error(`Invalid key format for ${keyName} option`);
};
Expand Down Expand Up @@ -86,8 +83,7 @@ interface Args {
if (!options.securityKeys) options.securityKeys = {};
options.securityKeys.S0_Legacy = normalizeKey(
options.networkKey,
"networkKey",
true
"networkKey"
);
console.warn(
"The `networkKey` option is deprecated in favor of `securityKeys` option. To eliminate " +
Expand Down

0 comments on commit a0e014e

Please sign in to comment.