zigbee-herdsman 6.0.2 → 6.0.4
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/CHANGELOG.md +14 -0
- package/package.json +9 -3
- package/.github/ISSUE_TEMPLATE/config.yml +0 -5
- package/.github/dependabot.yml +0 -22
- package/.github/workflows/ci.yml +0 -69
- package/.github/workflows/release-please.yml +0 -18
- package/.github/workflows/stale.yml +0 -20
- package/.github/workflows/typedoc.yaml +0 -47
- package/.release-please-manifest.json +0 -3
- package/.vscode/extensions.json +0 -3
- package/.vscode/settings.json +0 -11
- package/biome.json +0 -98
- package/examples/join-and-log.js +0 -24
- package/release-please-config.json +0 -9
- package/src/adapter/adapter.ts +0 -189
- package/src/adapter/adapterDiscovery.ts +0 -666
- package/src/adapter/const.ts +0 -12
- package/src/adapter/deconz/adapter/deconzAdapter.ts +0 -877
- package/src/adapter/deconz/driver/constants.ts +0 -246
- package/src/adapter/deconz/driver/driver.ts +0 -1540
- package/src/adapter/deconz/driver/frame.ts +0 -11
- package/src/adapter/deconz/driver/frameParser.ts +0 -753
- package/src/adapter/deconz/driver/parser.ts +0 -45
- package/src/adapter/deconz/driver/writer.ts +0 -22
- package/src/adapter/deconz/types.d.ts +0 -13
- package/src/adapter/ember/adapter/emberAdapter.ts +0 -2265
- package/src/adapter/ember/adapter/endpoints.ts +0 -86
- package/src/adapter/ember/adapter/oneWaitress.ts +0 -324
- package/src/adapter/ember/adapter/tokensManager.ts +0 -782
- package/src/adapter/ember/consts.ts +0 -178
- package/src/adapter/ember/enums.ts +0 -1746
- package/src/adapter/ember/ezsp/buffalo.ts +0 -1392
- package/src/adapter/ember/ezsp/consts.ts +0 -148
- package/src/adapter/ember/ezsp/enums.ts +0 -1114
- package/src/adapter/ember/ezsp/ezsp.ts +0 -9061
- package/src/adapter/ember/ezspError.ts +0 -10
- package/src/adapter/ember/types.ts +0 -866
- package/src/adapter/ember/uart/ash.ts +0 -1960
- package/src/adapter/ember/uart/consts.ts +0 -109
- package/src/adapter/ember/uart/enums.ts +0 -192
- package/src/adapter/ember/uart/parser.ts +0 -48
- package/src/adapter/ember/uart/queues.ts +0 -247
- package/src/adapter/ember/uart/writer.ts +0 -53
- package/src/adapter/ember/utils/initters.ts +0 -58
- package/src/adapter/ember/utils/math.ts +0 -73
- package/src/adapter/events.ts +0 -21
- package/src/adapter/ezsp/adapter/backup.ts +0 -109
- package/src/adapter/ezsp/adapter/ezspAdapter.ts +0 -614
- package/src/adapter/ezsp/driver/commands.ts +0 -2497
- package/src/adapter/ezsp/driver/consts.ts +0 -11
- package/src/adapter/ezsp/driver/driver.ts +0 -1002
- package/src/adapter/ezsp/driver/ezsp.ts +0 -802
- package/src/adapter/ezsp/driver/frame.ts +0 -101
- package/src/adapter/ezsp/driver/index.ts +0 -4
- package/src/adapter/ezsp/driver/multicast.ts +0 -78
- package/src/adapter/ezsp/driver/parser.ts +0 -81
- package/src/adapter/ezsp/driver/types/basic.ts +0 -201
- package/src/adapter/ezsp/driver/types/index.ts +0 -239
- package/src/adapter/ezsp/driver/types/named.ts +0 -2330
- package/src/adapter/ezsp/driver/types/struct.ts +0 -844
- package/src/adapter/ezsp/driver/uart.ts +0 -460
- package/src/adapter/ezsp/driver/utils/crc16ccitt.ts +0 -44
- package/src/adapter/ezsp/driver/utils/index.ts +0 -32
- package/src/adapter/ezsp/driver/writer.ts +0 -64
- package/src/adapter/index.ts +0 -3
- package/src/adapter/serialPort.ts +0 -58
- package/src/adapter/socketPortUtils.ts +0 -16
- package/src/adapter/tstype.ts +0 -78
- package/src/adapter/z-stack/adapter/adapter-backup.ts +0 -519
- package/src/adapter/z-stack/adapter/adapter-nv-memory.ts +0 -457
- package/src/adapter/z-stack/adapter/endpoints.ts +0 -57
- package/src/adapter/z-stack/adapter/manager.ts +0 -543
- package/src/adapter/z-stack/adapter/tstype.ts +0 -6
- package/src/adapter/z-stack/adapter/zStackAdapter.ts +0 -1190
- package/src/adapter/z-stack/constants/af.ts +0 -27
- package/src/adapter/z-stack/constants/common.ts +0 -285
- package/src/adapter/z-stack/constants/dbg.ts +0 -23
- package/src/adapter/z-stack/constants/index.ts +0 -11
- package/src/adapter/z-stack/constants/mac.ts +0 -128
- package/src/adapter/z-stack/constants/sapi.ts +0 -25
- package/src/adapter/z-stack/constants/sys.ts +0 -72
- package/src/adapter/z-stack/constants/util.ts +0 -82
- package/src/adapter/z-stack/constants/utils.ts +0 -14
- package/src/adapter/z-stack/constants/zdo.ts +0 -103
- package/src/adapter/z-stack/models/startup-options.ts +0 -13
- package/src/adapter/z-stack/structs/entries/address-manager-entry.ts +0 -44
- package/src/adapter/z-stack/structs/entries/address-manager-table.ts +0 -19
- package/src/adapter/z-stack/structs/entries/aps-link-key-data-entry.ts +0 -12
- package/src/adapter/z-stack/structs/entries/aps-link-key-data-table.ts +0 -21
- package/src/adapter/z-stack/structs/entries/aps-tc-link-key-entry.ts +0 -19
- package/src/adapter/z-stack/structs/entries/aps-tc-link-key-table.ts +0 -21
- package/src/adapter/z-stack/structs/entries/channel-list.ts +0 -8
- package/src/adapter/z-stack/structs/entries/has-configured.ts +0 -16
- package/src/adapter/z-stack/structs/entries/index.ts +0 -16
- package/src/adapter/z-stack/structs/entries/nib.ts +0 -66
- package/src/adapter/z-stack/structs/entries/nwk-key-descriptor.ts +0 -15
- package/src/adapter/z-stack/structs/entries/nwk-key.ts +0 -13
- package/src/adapter/z-stack/structs/entries/nwk-pan-id.ts +0 -8
- package/src/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-entry.ts +0 -20
- package/src/adapter/z-stack/structs/entries/nwk-sec-material-descriptor-table.ts +0 -19
- package/src/adapter/z-stack/structs/entries/security-manager-entry.ts +0 -33
- package/src/adapter/z-stack/structs/entries/security-manager-table.ts +0 -22
- package/src/adapter/z-stack/structs/index.ts +0 -4
- package/src/adapter/z-stack/structs/serializable-memory-object.ts +0 -14
- package/src/adapter/z-stack/structs/struct.ts +0 -367
- package/src/adapter/z-stack/structs/table.ts +0 -198
- package/src/adapter/z-stack/unpi/constants.ts +0 -33
- package/src/adapter/z-stack/unpi/frame.ts +0 -62
- package/src/adapter/z-stack/unpi/index.ts +0 -4
- package/src/adapter/z-stack/unpi/parser.ts +0 -56
- package/src/adapter/z-stack/unpi/writer.ts +0 -21
- package/src/adapter/z-stack/utils/channel-list.ts +0 -40
- package/src/adapter/z-stack/utils/index.ts +0 -2
- package/src/adapter/z-stack/utils/network-options.ts +0 -26
- package/src/adapter/z-stack/znp/buffaloZnp.ts +0 -175
- package/src/adapter/z-stack/znp/definition.ts +0 -2713
- package/src/adapter/z-stack/znp/index.ts +0 -2
- package/src/adapter/z-stack/znp/parameterType.ts +0 -22
- package/src/adapter/z-stack/znp/tstype.ts +0 -44
- package/src/adapter/z-stack/znp/utils.ts +0 -10
- package/src/adapter/z-stack/znp/znp.ts +0 -342
- package/src/adapter/z-stack/znp/zpiObject.ts +0 -148
- package/src/adapter/zboss/adapter/zbossAdapter.ts +0 -526
- package/src/adapter/zboss/commands.ts +0 -1184
- package/src/adapter/zboss/consts.ts +0 -9
- package/src/adapter/zboss/driver.ts +0 -422
- package/src/adapter/zboss/enums.ts +0 -360
- package/src/adapter/zboss/frame.ts +0 -227
- package/src/adapter/zboss/reader.ts +0 -65
- package/src/adapter/zboss/types.ts +0 -0
- package/src/adapter/zboss/uart.ts +0 -428
- package/src/adapter/zboss/utils.ts +0 -58
- package/src/adapter/zboss/writer.ts +0 -49
- package/src/adapter/zigate/adapter/patchZdoBuffaloBE.ts +0 -27
- package/src/adapter/zigate/adapter/zigateAdapter.ts +0 -618
- package/src/adapter/zigate/driver/LICENSE +0 -17
- package/src/adapter/zigate/driver/buffaloZiGate.ts +0 -212
- package/src/adapter/zigate/driver/commandType.ts +0 -418
- package/src/adapter/zigate/driver/constants.ts +0 -150
- package/src/adapter/zigate/driver/frame.ts +0 -197
- package/src/adapter/zigate/driver/messageType.ts +0 -287
- package/src/adapter/zigate/driver/parameterType.ts +0 -32
- package/src/adapter/zigate/driver/ziGateObject.ts +0 -146
- package/src/adapter/zigate/driver/zigate.ts +0 -423
- package/src/adapter/zoh/adapter/utils.ts +0 -27
- package/src/adapter/zoh/adapter/zohAdapter.ts +0 -838
- package/src/buffalo/buffalo.ts +0 -342
- package/src/buffalo/index.ts +0 -1
- package/src/controller/controller.ts +0 -1022
- package/src/controller/database.ts +0 -124
- package/src/controller/events.ts +0 -52
- package/src/controller/greenPower.ts +0 -603
- package/src/controller/helpers/index.ts +0 -1
- package/src/controller/helpers/installCodes.ts +0 -107
- package/src/controller/helpers/request.ts +0 -96
- package/src/controller/helpers/requestQueue.ts +0 -125
- package/src/controller/helpers/zclFrameConverter.ts +0 -47
- package/src/controller/helpers/zclTransactionSequenceNumber.ts +0 -19
- package/src/controller/index.ts +0 -6
- package/src/controller/model/device.ts +0 -1249
- package/src/controller/model/endpoint.ts +0 -1105
- package/src/controller/model/entity.ts +0 -23
- package/src/controller/model/group.ts +0 -424
- package/src/controller/model/index.ts +0 -5
- package/src/controller/model/zigbeeEntity.ts +0 -30
- package/src/controller/touchlink.ts +0 -189
- package/src/controller/tstype.ts +0 -274
- package/src/index.ts +0 -12
- package/src/models/backup-storage-legacy.ts +0 -48
- package/src/models/backup-storage-unified.ts +0 -47
- package/src/models/backup.ts +0 -37
- package/src/models/index.ts +0 -5
- package/src/models/network-options.ts +0 -11
- package/src/utils/backup.ts +0 -152
- package/src/utils/index.ts +0 -5
- package/src/utils/logger.ts +0 -20
- package/src/utils/patchBigIntSerialization.ts +0 -8
- package/src/utils/queue.ts +0 -76
- package/src/utils/types.d.ts +0 -3
- package/src/utils/utils.ts +0 -19
- package/src/utils/wait.ts +0 -5
- package/src/utils/waitress.ts +0 -96
- package/src/zspec/consts.ts +0 -84
- package/src/zspec/enums.ts +0 -22
- package/src/zspec/index.ts +0 -3
- package/src/zspec/tstypes.ts +0 -18
- package/src/zspec/utils.ts +0 -247
- package/src/zspec/zcl/buffaloZcl.ts +0 -1220
- package/src/zspec/zcl/definition/cluster.ts +0 -5915
- package/src/zspec/zcl/definition/clusters-typegen.ts +0 -588
- package/src/zspec/zcl/definition/clusters-types.ts +0 -7331
- package/src/zspec/zcl/definition/consts.ts +0 -24
- package/src/zspec/zcl/definition/enums.ts +0 -203
- package/src/zspec/zcl/definition/foundation.ts +0 -329
- package/src/zspec/zcl/definition/manufacturerCode.ts +0 -729
- package/src/zspec/zcl/definition/status.ts +0 -69
- package/src/zspec/zcl/definition/tstype.ts +0 -377
- package/src/zspec/zcl/index.ts +0 -11
- package/src/zspec/zcl/utils.ts +0 -321
- package/src/zspec/zcl/zclFrame.ts +0 -356
- package/src/zspec/zcl/zclHeader.ts +0 -102
- package/src/zspec/zcl/zclStatusError.ts +0 -10
- package/src/zspec/zdo/buffaloZdo.ts +0 -2336
- package/src/zspec/zdo/definition/clusters.ts +0 -722
- package/src/zspec/zdo/definition/consts.ts +0 -16
- package/src/zspec/zdo/definition/enums.ts +0 -99
- package/src/zspec/zdo/definition/status.ts +0 -105
- package/src/zspec/zdo/definition/tstypes.ts +0 -1062
- package/src/zspec/zdo/index.ts +0 -7
- package/src/zspec/zdo/utils.ts +0 -76
- package/src/zspec/zdo/zdoStatusError.ts +0 -10
- package/test/adapter/adapter.test.ts +0 -1062
- package/test/adapter/ember/ash.test.ts +0 -337
- package/test/adapter/ember/consts.ts +0 -131
- package/test/adapter/ember/emberAdapter.test.ts +0 -3449
- package/test/adapter/ember/ezsp.test.ts +0 -385
- package/test/adapter/ember/ezspBuffalo.test.ts +0 -93
- package/test/adapter/ember/ezspError.test.ts +0 -12
- package/test/adapter/ember/math.test.ts +0 -206
- package/test/adapter/ezsp/frame.test.ts +0 -30
- package/test/adapter/ezsp/uart.test.ts +0 -181
- package/test/adapter/z-stack/adapter.test.ts +0 -3984
- package/test/adapter/z-stack/constants.test.ts +0 -33
- package/test/adapter/z-stack/structs.test.ts +0 -115
- package/test/adapter/z-stack/unpi.test.ts +0 -213
- package/test/adapter/z-stack/znp.test.ts +0 -1284
- package/test/adapter/zboss/fixZdoResponse.test.ts +0 -179
- package/test/adapter/zigate/patchZdoBuffaloBE.test.ts +0 -81
- package/test/adapter/zigate/zdo.test.ts +0 -187
- package/test/adapter/zoh/utils.test.ts +0 -36
- package/test/adapter/zoh/zohAdapter.test.ts +0 -1307
- package/test/benchOptions.ts +0 -14
- package/test/buffalo.test.ts +0 -431
- package/test/controller.bench.ts +0 -214
- package/test/controller.test.ts +0 -8702
- package/test/greenpower.test.ts +0 -1408
- package/test/mockAdapters.ts +0 -65
- package/test/mockDevices.ts +0 -598
- package/test/requests.bench.ts +0 -229
- package/test/testUtils.ts +0 -20
- package/test/tsconfig.json +0 -9
- package/test/utils/math.ts +0 -19
- package/test/utils.test.ts +0 -279
- package/test/vitest.config.mts +0 -26
- package/test/zcl.test.ts +0 -2831
- package/test/zspec/utils.test.ts +0 -68
- package/test/zspec/zcl/buffalo.test.ts +0 -1374
- package/test/zspec/zcl/frame.test.ts +0 -960
- package/test/zspec/zcl/utils.test.ts +0 -273
- package/test/zspec/zdo/buffalo.test.ts +0 -1850
- package/test/zspec/zdo/utils.test.ts +0 -241
- package/tsconfig.json +0 -24
package/src/utils/queue.ts
DELETED
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
interface Job {
|
|
2
|
-
key?: string | number;
|
|
3
|
-
running: boolean;
|
|
4
|
-
start?: () => void;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export class Queue {
|
|
8
|
-
private jobs: Job[];
|
|
9
|
-
private readonly concurrent: number;
|
|
10
|
-
|
|
11
|
-
constructor(concurrent = 1) {
|
|
12
|
-
this.jobs = [];
|
|
13
|
-
this.concurrent = concurrent;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
public async execute<T>(func: () => Promise<T>, key?: string | number): Promise<T> {
|
|
17
|
-
const job: Job = {key, running: false};
|
|
18
|
-
this.jobs.push(job);
|
|
19
|
-
|
|
20
|
-
// Minor optimization/workaround: various tests like the idea that a job that is immediately runnable is run without an event loop spin.
|
|
21
|
-
// This also helps with stack traces in some cases, so avoid an `await` if we can help it.
|
|
22
|
-
if (this.getNext() !== job) {
|
|
23
|
-
await new Promise<void>((resolve): void => {
|
|
24
|
-
job.start = (): void => {
|
|
25
|
-
job.running = true;
|
|
26
|
-
resolve();
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
this.executeNext();
|
|
30
|
-
});
|
|
31
|
-
} else {
|
|
32
|
-
job.running = true;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
try {
|
|
36
|
-
return await func();
|
|
37
|
-
} finally {
|
|
38
|
-
this.jobs.splice(this.jobs.indexOf(job), 1);
|
|
39
|
-
this.executeNext();
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
private executeNext(): void {
|
|
44
|
-
const job = this.getNext();
|
|
45
|
-
|
|
46
|
-
if (job) {
|
|
47
|
-
// if we get here, start is always defined for job
|
|
48
|
-
// biome-ignore lint/style/noNonNullAssertion: ignored using `--suppress`
|
|
49
|
-
job.start!();
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
private getNext(): Job | undefined {
|
|
54
|
-
if (this.jobs.filter((j) => j.running).length > this.concurrent - 1) {
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
for (let i = 0; i < this.jobs.length; i++) {
|
|
59
|
-
const job = this.jobs[i];
|
|
60
|
-
|
|
61
|
-
if (!job.running && (!job.key || !this.jobs.find((j) => j.key === job.key && j.running))) {
|
|
62
|
-
return job;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
public clear(): void {
|
|
70
|
-
this.jobs = [];
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
public count(): number {
|
|
74
|
-
return this.jobs.length;
|
|
75
|
-
}
|
|
76
|
-
}
|
package/src/utils/types.d.ts
DELETED
package/src/utils/utils.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
export function isNumberArray(value: unknown): value is number[] {
|
|
2
|
-
return Array.isArray(value) && value.every((item) => typeof item === "number");
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
export function isNumberArrayOfLength(value: unknown, length: number): boolean {
|
|
6
|
-
return isNumberArray(value) && value.length === length;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function assertString(input: unknown): asserts input is string {
|
|
10
|
-
if (typeof input !== "string") {
|
|
11
|
-
throw new Error("Input must be a string!");
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function isObjectEmpty(object: object): boolean {
|
|
16
|
-
// much faster than checking `Object.keys(object).length`
|
|
17
|
-
for (const _k in object) return false;
|
|
18
|
-
return true;
|
|
19
|
-
}
|
package/src/utils/wait.ts
DELETED
package/src/utils/waitress.ts
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
interface Waiter<TPayload, TMatcher> {
|
|
2
|
-
ID: number;
|
|
3
|
-
resolve: (payload: TPayload) => void;
|
|
4
|
-
reject: (error: Error) => void;
|
|
5
|
-
timer?: NodeJS.Timeout;
|
|
6
|
-
resolved: boolean;
|
|
7
|
-
timedout: boolean;
|
|
8
|
-
matcher: TMatcher;
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
type Validator<TPayload, TMatcher> = (payload: TPayload, matcher: TMatcher) => boolean;
|
|
12
|
-
type TimeoutFormatter<TMatcher> = (matcher: TMatcher, timeout: number) => string;
|
|
13
|
-
|
|
14
|
-
export class Waitress<TPayload, TMatcher> {
|
|
15
|
-
private waiters: Map<number, Waiter<TPayload, TMatcher>>;
|
|
16
|
-
private readonly validator: Validator<TPayload, TMatcher>;
|
|
17
|
-
private readonly timeoutFormatter: TimeoutFormatter<TMatcher>;
|
|
18
|
-
private currentID: number;
|
|
19
|
-
|
|
20
|
-
public constructor(validator: Validator<TPayload, TMatcher>, timeoutFormatter: TimeoutFormatter<TMatcher>) {
|
|
21
|
-
this.waiters = new Map();
|
|
22
|
-
this.timeoutFormatter = timeoutFormatter;
|
|
23
|
-
this.validator = validator;
|
|
24
|
-
this.currentID = 0;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public clear(): void {
|
|
28
|
-
for (const [, waiter] of this.waiters) {
|
|
29
|
-
clearTimeout(waiter.timer);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
this.waiters.clear();
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
public resolve(payload: TPayload): boolean {
|
|
36
|
-
return this.forEachMatching(payload, (waiter) => waiter.resolve(payload));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
public reject(payload: TPayload, message: string): boolean {
|
|
40
|
-
return this.forEachMatching(payload, (waiter) => waiter.reject(new Error(message)));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
public remove(id: number): void {
|
|
44
|
-
const waiter = this.waiters.get(id);
|
|
45
|
-
if (waiter) {
|
|
46
|
-
if (!waiter.timedout && waiter.timer) {
|
|
47
|
-
clearTimeout(waiter.timer);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
this.waiters.delete(id);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public waitFor(matcher: TMatcher, timeout: number): {ID: number; start: () => {promise: Promise<TPayload>; ID: number}} {
|
|
55
|
-
this.currentID += 1;
|
|
56
|
-
const ID = this.currentID;
|
|
57
|
-
|
|
58
|
-
const promise: Promise<TPayload> = new Promise((resolve, reject): void => {
|
|
59
|
-
const object: Waiter<TPayload, TMatcher> = {matcher, resolve, reject, timedout: false, resolved: false, ID};
|
|
60
|
-
this.waiters.set(ID, object);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const start = (): {promise: Promise<TPayload>; ID: number} => {
|
|
64
|
-
const waiter = this.waiters.get(ID);
|
|
65
|
-
if (waiter && !waiter.resolved && !waiter.timer) {
|
|
66
|
-
// Capture the stack trace from the caller of start()
|
|
67
|
-
const error = new Error(this.timeoutFormatter(matcher, timeout));
|
|
68
|
-
Error.captureStackTrace(error);
|
|
69
|
-
waiter.timer = setTimeout((): void => {
|
|
70
|
-
waiter.timedout = true;
|
|
71
|
-
waiter.reject(error);
|
|
72
|
-
}, timeout);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return {promise, ID};
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
return {ID, start};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
private forEachMatching(payload: TPayload, action: (waiter: Waiter<TPayload, TMatcher>) => void): boolean {
|
|
82
|
-
let foundMatching = false;
|
|
83
|
-
for (const [index, waiter] of this.waiters.entries()) {
|
|
84
|
-
if (waiter.timedout) {
|
|
85
|
-
this.waiters.delete(index);
|
|
86
|
-
} else if (this.validator(payload, waiter.matcher)) {
|
|
87
|
-
clearTimeout(waiter.timer);
|
|
88
|
-
waiter.resolved = true;
|
|
89
|
-
this.waiters.delete(index);
|
|
90
|
-
action(waiter);
|
|
91
|
-
foundMatching = true;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
return foundMatching;
|
|
95
|
-
}
|
|
96
|
-
}
|
package/src/zspec/consts.ts
DELETED
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import type {ExtendedPanId} from "./tstypes";
|
|
2
|
-
|
|
3
|
-
/** Current supported Zigbee revision: https://csa-iot.org/wp-content/uploads/2023/04/05-3474-23-csg-zigbee-specification-compressed.pdf */
|
|
4
|
-
export const ZIGBEE_REVISION = 23;
|
|
5
|
-
|
|
6
|
-
/** The network ID of the coordinator in a ZigBee network is 0x0000. */
|
|
7
|
-
export const COORDINATOR_ADDRESS = 0x0000;
|
|
8
|
-
|
|
9
|
-
/** Endpoint profile ID for Zigbee 3.0. "Home Automation" */
|
|
10
|
-
export const HA_PROFILE_ID = 0x0104;
|
|
11
|
-
/** Endpoint profile ID for Smart Energy */
|
|
12
|
-
export const SE_PROFILE_ID = 0x0109;
|
|
13
|
-
/** Endpoint profile ID for Green Power */
|
|
14
|
-
export const GP_PROFILE_ID = 0xa1e0;
|
|
15
|
-
/** The touchlink (ZigBee Light Link/ZLL) Profile ID. */
|
|
16
|
-
export const TOUCHLINK_PROFILE_ID = 0xc05e;
|
|
17
|
-
/** The profile ID used to address all the public profiles. */
|
|
18
|
-
export const WILDCARD_PROFILE_ID = 0xffff;
|
|
19
|
-
|
|
20
|
-
/** The default HA endpoint. */
|
|
21
|
-
export const HA_ENDPOINT = 0x01;
|
|
22
|
-
/** The GP endpoint, as defined in the ZigBee spec. */
|
|
23
|
-
export const GP_ENDPOINT = 0xf2;
|
|
24
|
-
|
|
25
|
-
export const GP_GROUP_ID = 0x0b84;
|
|
26
|
-
|
|
27
|
-
/** The maximum 802.15.4 channel number is 26. */
|
|
28
|
-
export const MAX_802_15_4_CHANNEL_NUMBER = 26;
|
|
29
|
-
/** The minimum 2.4GHz 802.15.4 channel number is 11. */
|
|
30
|
-
export const MIN_802_15_4_CHANNEL_NUMBER = 11;
|
|
31
|
-
/** There are sixteen 802.15.4 channels. */
|
|
32
|
-
export const NUM_802_15_4_CHANNELS = MAX_802_15_4_CHANNEL_NUMBER - MIN_802_15_4_CHANNEL_NUMBER + 1;
|
|
33
|
-
/** A bitmask to scan all 2.4 GHz 802.15.4 channels. */
|
|
34
|
-
export const ALL_802_15_4_CHANNELS_MASK = 0x07fff800;
|
|
35
|
-
/** A bitmask of the preferred 2.4 GHz 802.15.4 channels to scan. */
|
|
36
|
-
export const PREFERRED_802_15_4_CHANNELS_MASK = 0x0318c800;
|
|
37
|
-
/** List of all Zigbee channels */
|
|
38
|
-
export const ALL_802_15_4_CHANNELS = [11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26];
|
|
39
|
-
/** List of preferred Zigbee channels */
|
|
40
|
-
export const PREFERRED_802_15_4_CHANNELS = [11, 14, 15, 19, 20, 24, 25];
|
|
41
|
-
|
|
42
|
-
/** A blank (also used as "wildcard") EUI64 hex string prefixed with 0x */
|
|
43
|
-
export const BLANK_EUI64 = "0xFFFFFFFFFFFFFFFF";
|
|
44
|
-
/** A blank extended PAN ID. (null/not present) */
|
|
45
|
-
export const BLANK_EXTENDED_PAN_ID: Readonly<ExtendedPanId> = [0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00];
|
|
46
|
-
|
|
47
|
-
/** An invalid profile ID. This is a reserved profileId. */
|
|
48
|
-
export const INVALID_PROFILE_ID = 0xffff;
|
|
49
|
-
/** An invalid cluster ID. */
|
|
50
|
-
export const INVALID_CLUSTER_ID = 0xffff;
|
|
51
|
-
/** An invalid PAN ID. */
|
|
52
|
-
export const INVALID_PAN_ID = 0xffff;
|
|
53
|
-
|
|
54
|
-
/** A distinguished network ID that will never be assigned to any node. It is used to indicate the absence of a node ID. */
|
|
55
|
-
export const NULL_NODE_ID = 0xffff;
|
|
56
|
-
/** A distinguished binding index used to indicate the absence of a binding. */
|
|
57
|
-
export const NULL_BINDING = 0xff;
|
|
58
|
-
|
|
59
|
-
/** This key is "ZigBeeAlliance09" */
|
|
60
|
-
export const INTEROPERABILITY_LINK_KEY: readonly number[] = [
|
|
61
|
-
0x5a, 0x69, 0x67, 0x42, 0x65, 0x65, 0x41, 0x6c, 0x6c, 0x69, 0x61, 0x6e, 0x63, 0x65, 0x30, 0x39,
|
|
62
|
-
];
|
|
63
|
-
|
|
64
|
-
export const PERMIT_JOIN_FOREVER = 0xff;
|
|
65
|
-
export const PERMIT_JOIN_MAX_TIMEOUT = 0xfe;
|
|
66
|
-
|
|
67
|
-
/** Size of EUI64 (an IEEE address) in bytes. */
|
|
68
|
-
export const EUI64_SIZE = 8;
|
|
69
|
-
/** Size of an PAN identifier in bytes. */
|
|
70
|
-
export const PAN_ID_SIZE = 2;
|
|
71
|
-
/** Size of an extended PAN identifier in bytes. */
|
|
72
|
-
export const EXTENDED_PAN_ID_SIZE = 8;
|
|
73
|
-
/** Size of an encryption key in bytes. */
|
|
74
|
-
export const DEFAULT_ENCRYPTION_KEY_SIZE = 16;
|
|
75
|
-
/** Size of a AES-128-MMO (Matyas-Meyer-Oseas) block in bytes. */
|
|
76
|
-
export const AES_MMO_128_BLOCK_SIZE = 16;
|
|
77
|
-
/**
|
|
78
|
-
* Valid install code sizes, including `INSTALL_CODE_CRC_SIZE`.
|
|
79
|
-
*
|
|
80
|
-
* NOTE: 18 is now standard, first for iterations, order after is important (8 before 10)!
|
|
81
|
-
*/
|
|
82
|
-
export const INSTALL_CODE_SIZES: ReadonlyArray<number> = [18, 8, 10, 14];
|
|
83
|
-
/** Size of the CRC appended to install codes. */
|
|
84
|
-
export const INSTALL_CODE_CRC_SIZE = 2;
|
package/src/zspec/enums.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ZigBee Broadcast Addresses
|
|
3
|
-
*
|
|
4
|
-
* ZigBee specifies three different broadcast addresses that reach different collections of nodes.
|
|
5
|
-
* Broadcasts are normally sent only to routers.
|
|
6
|
-
* Broadcasts can also be forwarded to end devices, either all of them or only those that do not sleep.
|
|
7
|
-
* Broadcasting to end devices is both significantly more resource-intensive and significantly less reliable than broadcasting to routers.
|
|
8
|
-
*/
|
|
9
|
-
export enum BroadcastAddress {
|
|
10
|
-
// Reserved = 0xfff8,
|
|
11
|
-
// Reserved = 0xfff9,
|
|
12
|
-
// Reserved = 0xfffa,
|
|
13
|
-
/** Low power routers only */
|
|
14
|
-
LOW_POWER_ROUTERS = 0xfffb,
|
|
15
|
-
/** All routers and coordinator */
|
|
16
|
-
DEFAULT = 0xfffc,
|
|
17
|
-
/** macRxOnWhenIdle = TRUE (all non-sleepy devices) */
|
|
18
|
-
RX_ON_WHEN_IDLE = 0xfffd,
|
|
19
|
-
// Reserved = 0xFFFE,
|
|
20
|
-
/** All devices in PAN (including sleepy end devices) */
|
|
21
|
-
SLEEPY = 0xffff,
|
|
22
|
-
}
|
package/src/zspec/index.ts
DELETED
package/src/zspec/tstypes.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* EUI 64-bit ID (IEEE 802.15.4 long address). uint8[EUI64_SIZE]
|
|
3
|
-
*
|
|
4
|
-
* NOTE: Expected to contain `0x` prefix
|
|
5
|
-
*/
|
|
6
|
-
export type Eui64 = `0x${string}`;
|
|
7
|
-
/** IEEE 802.15.4 node ID. Also known as short address. uint16 */
|
|
8
|
-
export type NodeId = number;
|
|
9
|
-
/** IEEE 802.15.4 PAN ID. uint16 */
|
|
10
|
-
export type PanId = number;
|
|
11
|
-
/** PAN 64-bit ID (IEEE 802.15.4 long address). uint8[EXTENDED_PAN_ID_SIZE] */
|
|
12
|
-
export type ExtendedPanId = number[];
|
|
13
|
-
/** 16-bit ZigBee multicast group identifier. uint16 */
|
|
14
|
-
export type MulticastId = number;
|
|
15
|
-
/** Refer to the Zigbee application profile ID. uint16 */
|
|
16
|
-
export type ProfileId = number;
|
|
17
|
-
/** Refer to the ZCL cluster ID. uint16 */
|
|
18
|
-
export type ClusterId = number;
|
package/src/zspec/utils.ts
DELETED
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
import {createCipheriv} from "node:crypto";
|
|
2
|
-
import {AES_MMO_128_BLOCK_SIZE, ALL_802_15_4_CHANNELS} from "./consts";
|
|
3
|
-
import {BroadcastAddress} from "./enums";
|
|
4
|
-
import type {Eui64} from "./tstypes";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Convert a channels array to a uint32 channel mask.
|
|
8
|
-
* @param channels
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
11
|
-
export const channelsToUInt32Mask = (channels: number[]): number => {
|
|
12
|
-
return channels.reduce((a, c) => a + (1 << c), 0);
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Convert a uint32 channel mask to a channels array.
|
|
17
|
-
* @param mask
|
|
18
|
-
* @returns
|
|
19
|
-
*/
|
|
20
|
-
export const uint32MaskToChannels = (mask: number): number[] => {
|
|
21
|
-
const channels: number[] = [];
|
|
22
|
-
|
|
23
|
-
for (const channel of ALL_802_15_4_CHANNELS) {
|
|
24
|
-
if ((2 ** channel) & mask) {
|
|
25
|
-
channels.push(channel);
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return channels;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
export const isBroadcastAddress = (address: number): boolean => {
|
|
33
|
-
return (
|
|
34
|
-
address === BroadcastAddress.DEFAULT ||
|
|
35
|
-
address === BroadcastAddress.RX_ON_WHEN_IDLE ||
|
|
36
|
-
address === BroadcastAddress.SLEEPY ||
|
|
37
|
-
address === BroadcastAddress.LOW_POWER_ROUTERS
|
|
38
|
-
);
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Represent a little endian buffer in `0x...` form
|
|
43
|
-
*
|
|
44
|
-
* NOTE: the buffer is always copied to avoid reversal in reference
|
|
45
|
-
*/
|
|
46
|
-
export const eui64LEBufferToHex = (eui64LEBuf: Buffer): Eui64 => `0x${Buffer.from(eui64LEBuf).reverse().toString("hex")}`;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Represent a big endian buffer in `0x...` form
|
|
50
|
-
*/
|
|
51
|
-
export const eui64BEBufferToHex = (eui64BEBuf: Buffer): Eui64 => `0x${eui64BEBuf.toString("hex")}`;
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Calculate the CRC 8, 16 or 32 for the given data.
|
|
55
|
-
*
|
|
56
|
-
* @see https://www.crccalc.com/
|
|
57
|
-
*
|
|
58
|
-
* @param data
|
|
59
|
-
* @param length CRC Length
|
|
60
|
-
* @param poly Polynomial
|
|
61
|
-
* @param crc Initialization value
|
|
62
|
-
* @param xorOut Final XOR value
|
|
63
|
-
* @param refIn Reflected In
|
|
64
|
-
* @param refOut Reflected Out
|
|
65
|
-
* @returns The calculated CRC
|
|
66
|
-
*
|
|
67
|
-
* NOTE: This is not exported for test coverage reasons (large number of combinations possible, many unused).
|
|
68
|
-
* Specific, needed, algorithms should be defined as exported wrappers below, and coverage added for them.
|
|
69
|
-
*/
|
|
70
|
-
function calcCRC(
|
|
71
|
-
data: number[] | Uint8Array | Buffer,
|
|
72
|
-
length: 8 | 16 | 32,
|
|
73
|
-
poly: number,
|
|
74
|
-
crc = 0,
|
|
75
|
-
xorOut = 0,
|
|
76
|
-
refIn = false,
|
|
77
|
-
refOut = false,
|
|
78
|
-
): number {
|
|
79
|
-
// https://web.archive.org/web/20150226083354/http://leetcode.com/2011/08/reverse-bits.html
|
|
80
|
-
const reflect = (x: number, size: 8 | 16 | 32): number => {
|
|
81
|
-
if (size === 8) {
|
|
82
|
-
x = ((x & 0x55) << 1) | ((x & 0xaa) >> 1);
|
|
83
|
-
x = ((x & 0x33) << 2) | ((x & 0xcc) >> 2);
|
|
84
|
-
x = ((x & 0x0f) << 4) | ((x & 0xf0) >> 4);
|
|
85
|
-
} else if (size === 16) {
|
|
86
|
-
x = ((x & 0x5555) << 1) | ((x & 0xaaaa) >> 1);
|
|
87
|
-
x = ((x & 0x3333) << 2) | ((x & 0xcccc) >> 2);
|
|
88
|
-
x = ((x & 0x0f0f) << 4) | ((x & 0xf0f0) >> 4);
|
|
89
|
-
x = ((x & 0x00ff) << 8) | ((x & 0xff00) >> 8);
|
|
90
|
-
/* v8 ignore start */
|
|
91
|
-
} /* if (size === 32) */ else {
|
|
92
|
-
x = ((x & 0x55555555) << 1) | ((x & 0xaaaaaaaa) >> 1);
|
|
93
|
-
x = ((x & 0x33333333) << 2) | ((x & 0xcccccccc) >> 2);
|
|
94
|
-
x = ((x & 0x0f0f0f0f) << 4) | ((x & 0xf0f0f0f0) >> 4);
|
|
95
|
-
x = ((x & 0x00ff00ff) << 8) | ((x & 0xff00ff00) >> 8);
|
|
96
|
-
x = ((x & 0x0000ffff) << 16) | ((x & 0xffff0000) >> 16);
|
|
97
|
-
}
|
|
98
|
-
/* v8 ignore stop */
|
|
99
|
-
|
|
100
|
-
return x;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
poly = (1 << length) | poly;
|
|
104
|
-
|
|
105
|
-
for (let byte of data) {
|
|
106
|
-
if (refIn) {
|
|
107
|
-
byte = reflect(byte, 8);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
crc ^= byte << (length - 8);
|
|
111
|
-
|
|
112
|
-
for (let i = 0; i < 8; i++) {
|
|
113
|
-
crc <<= 1;
|
|
114
|
-
|
|
115
|
-
if (crc & (1 << length)) {
|
|
116
|
-
crc ^= poly;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (refOut) {
|
|
122
|
-
crc = reflect(crc, length);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return crc ^ xorOut;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* CRC-16/X-25
|
|
130
|
-
* aka CRC-16/IBM-SDLC
|
|
131
|
-
* aka CRC-16/ISO-HDLC
|
|
132
|
-
* aka CRC-16/ISO-IEC-14443-3-B
|
|
133
|
-
* aka CRC-B
|
|
134
|
-
* aka X-25
|
|
135
|
-
*
|
|
136
|
-
* Shortcut for `calcCRC(data, 16, 0x1021, 0xFFFF, 0xFFFF, true, true)`
|
|
137
|
-
*
|
|
138
|
-
* Used for Install Codes - see Document 13-0402-13 - 10.1
|
|
139
|
-
*/
|
|
140
|
-
export function crc16X25(data: number[] | Uint8Array | Buffer): number {
|
|
141
|
-
return calcCRC(data, 16, 0x1021, 0xffff, 0xffff, true, true);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* CRC-16/XMODEM
|
|
146
|
-
* aka CRC-16/ACORN
|
|
147
|
-
* aka CRC-16/LTE
|
|
148
|
-
* aka CRC-16/V-41-MSB
|
|
149
|
-
* aka XMODEM
|
|
150
|
-
* aka ZMODEM
|
|
151
|
-
*
|
|
152
|
-
* Shortcut for `calcCRC(data, 16, 0x1021)`
|
|
153
|
-
*
|
|
154
|
-
* Used for XMODEM transfers, often involved in ZigBee environments
|
|
155
|
-
*/
|
|
156
|
-
export function crc16XMODEM(data: number[] | Uint8Array | Buffer): number {
|
|
157
|
-
return calcCRC(data, 16, 0x1021);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
/**
|
|
161
|
-
* CRC-16/CCITT
|
|
162
|
-
* aka CRC-16/KERMIT
|
|
163
|
-
* aka CRC-16/BLUETOOTH
|
|
164
|
-
* aka CRC-16/CCITT-TRUE
|
|
165
|
-
* aka CRC-16/V-41-LSB
|
|
166
|
-
* aka CRC-CCITT
|
|
167
|
-
* aka KERMIT
|
|
168
|
-
*
|
|
169
|
-
* Shortcut for `calcCRC(data, 16, 0x1021, 0x0000, 0x0000, true, true)`
|
|
170
|
-
*/
|
|
171
|
-
export function crc16CCITT(data: number[] | Uint8Array | Buffer): number {
|
|
172
|
-
return calcCRC(data, 16, 0x1021, 0x0000, 0x0000, true, true);
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* CRC-16/CCITT-FALSE
|
|
177
|
-
* aka CRC-16/IBM-3740
|
|
178
|
-
* aka CRC-16/AUTOSAR
|
|
179
|
-
*
|
|
180
|
-
* Shortcut for `calcCRC(data, 16, 0x1021, 0xffff)`
|
|
181
|
-
*/
|
|
182
|
-
export function crc16CCITTFALSE(data: number[] | Uint8Array | Buffer): number {
|
|
183
|
-
return calcCRC(data, 16, 0x1021, 0xffff);
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
function aes128MmoHashUpdate(result: Buffer, data: Buffer, dataSize: number): void {
|
|
187
|
-
while (dataSize >= AES_MMO_128_BLOCK_SIZE) {
|
|
188
|
-
const cipher = createCipheriv("aes-128-ecb", result, null);
|
|
189
|
-
const block = data.subarray(0, AES_MMO_128_BLOCK_SIZE);
|
|
190
|
-
const encryptedBlock = Buffer.concat([cipher.update(block), cipher.final()]);
|
|
191
|
-
|
|
192
|
-
// XOR encrypted and plaintext
|
|
193
|
-
for (let i = 0; i < AES_MMO_128_BLOCK_SIZE; i++) {
|
|
194
|
-
result[i] = encryptedBlock[i] ^ block[i];
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
data = data.subarray(AES_MMO_128_BLOCK_SIZE);
|
|
198
|
-
dataSize -= AES_MMO_128_BLOCK_SIZE;
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
/**
|
|
203
|
-
* AES-128-MMO (Matyas-Meyer-Oseas) hashing (using node 'crypto' built-in with 'aes-128-ecb')
|
|
204
|
-
*
|
|
205
|
-
* Used for Install Codes - see Document 13-0402-13 - 10.1
|
|
206
|
-
*/
|
|
207
|
-
export function aes128MmoHash(data: Buffer): Buffer {
|
|
208
|
-
const hashResult = Buffer.alloc(AES_MMO_128_BLOCK_SIZE);
|
|
209
|
-
const temp = Buffer.alloc(AES_MMO_128_BLOCK_SIZE);
|
|
210
|
-
let remainingLength = data.length;
|
|
211
|
-
let position = 0;
|
|
212
|
-
|
|
213
|
-
for (position; remainingLength >= AES_MMO_128_BLOCK_SIZE; ) {
|
|
214
|
-
const chunk = data.subarray(position, position + AES_MMO_128_BLOCK_SIZE);
|
|
215
|
-
|
|
216
|
-
aes128MmoHashUpdate(hashResult, chunk, chunk.length);
|
|
217
|
-
|
|
218
|
-
position += AES_MMO_128_BLOCK_SIZE;
|
|
219
|
-
remainingLength -= AES_MMO_128_BLOCK_SIZE;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
for (let i = 0; i < remainingLength; i++) {
|
|
223
|
-
temp[i] = data[position + i];
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
// per the spec, concatenate a 1 bit followed by all zero bits
|
|
227
|
-
temp[remainingLength] = 0x80;
|
|
228
|
-
|
|
229
|
-
// if appending the bit string will push us beyond the 16-byte boundary, hash that block and append another 16-byte block
|
|
230
|
-
if (AES_MMO_128_BLOCK_SIZE - remainingLength < 3) {
|
|
231
|
-
aes128MmoHashUpdate(hashResult, temp, AES_MMO_128_BLOCK_SIZE);
|
|
232
|
-
temp.fill(0);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
temp[AES_MMO_128_BLOCK_SIZE - 2] = (data.length >> 5) & 0xff;
|
|
236
|
-
temp[AES_MMO_128_BLOCK_SIZE - 1] = (data.length << 3) & 0xff;
|
|
237
|
-
|
|
238
|
-
aes128MmoHashUpdate(hashResult, temp, AES_MMO_128_BLOCK_SIZE);
|
|
239
|
-
|
|
240
|
-
const result = Buffer.alloc(AES_MMO_128_BLOCK_SIZE);
|
|
241
|
-
|
|
242
|
-
for (let i = 0; i < AES_MMO_128_BLOCK_SIZE; i++) {
|
|
243
|
-
result[i] = hashResult[i];
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
return result;
|
|
247
|
-
}
|