@homebridge/hap-nodejs 2.3.1-beta.2 → 2.3.1-beta.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/dist/hap.d.ts +3 -0
- package/dist/hap.js +3 -0
- package/dist/hap.js.map +1 -1
- package/dist/lib/Accessory.d.ts +4 -0
- package/dist/lib/Accessory.js +16 -2
- package/dist/lib/Accessory.js.map +1 -1
- package/dist/lib/HAPServer.d.ts +5 -0
- package/dist/lib/HAPServer.js +23 -10
- package/dist/lib/HAPServer.js.map +1 -1
- package/dist/lib/controller/DoorbellController.d.ts +59 -0
- package/dist/lib/controller/DoorbellController.js +85 -0
- package/dist/lib/controller/DoorbellController.js.map +1 -1
- package/dist/lib/lock/AccessCodeManagement.d.ts +135 -0
- package/dist/lib/lock/AccessCodeManagement.js +328 -0
- package/dist/lib/lock/AccessCodeManagement.js.map +1 -0
- package/dist/lib/lock/NFCAccessManagement.d.ts +200 -0
- package/dist/lib/lock/NFCAccessManagement.js +443 -0
- package/dist/lib/lock/NFCAccessManagement.js.map +1 -0
- package/dist/lib/util/error-status.d.ts +64 -0
- package/dist/lib/util/error-status.js +100 -0
- package/dist/lib/util/error-status.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,443 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
3
|
+
import { EventEmitter } from 'node:events';
|
|
4
|
+
import { Characteristic } from '../Characteristic.js';
|
|
5
|
+
import { Service } from '../Service.js';
|
|
6
|
+
import * as tlv from '../util/tlv.js';
|
|
7
|
+
var NFCAccessSupportedConfigurationTypes;
|
|
8
|
+
(function (NFCAccessSupportedConfigurationTypes) {
|
|
9
|
+
NFCAccessSupportedConfigurationTypes[NFCAccessSupportedConfigurationTypes["MAXIMUM_ISSUER_KEYS"] = 1] = "MAXIMUM_ISSUER_KEYS";
|
|
10
|
+
NFCAccessSupportedConfigurationTypes[NFCAccessSupportedConfigurationTypes["MAXIMUM_SUSPENDED_DEVICE_CREDENTIAL_KEYS"] = 2] = "MAXIMUM_SUSPENDED_DEVICE_CREDENTIAL_KEYS";
|
|
11
|
+
})(NFCAccessSupportedConfigurationTypes || (NFCAccessSupportedConfigurationTypes = {}));
|
|
12
|
+
var NFCAccessControlTypes;
|
|
13
|
+
(function (NFCAccessControlTypes) {
|
|
14
|
+
NFCAccessControlTypes[NFCAccessControlTypes["OPERATION_TYPE"] = 1] = "OPERATION_TYPE";
|
|
15
|
+
NFCAccessControlTypes[NFCAccessControlTypes["ISSUER_KEY_REQUEST"] = 2] = "ISSUER_KEY_REQUEST";
|
|
16
|
+
NFCAccessControlTypes[NFCAccessControlTypes["ISSUER_KEY_RESPONSE"] = 3] = "ISSUER_KEY_RESPONSE";
|
|
17
|
+
NFCAccessControlTypes[NFCAccessControlTypes["DEVICE_CREDENTIAL_KEY_REQUEST"] = 4] = "DEVICE_CREDENTIAL_KEY_REQUEST";
|
|
18
|
+
NFCAccessControlTypes[NFCAccessControlTypes["DEVICE_CREDENTIAL_KEY_RESPONSE"] = 5] = "DEVICE_CREDENTIAL_KEY_RESPONSE";
|
|
19
|
+
NFCAccessControlTypes[NFCAccessControlTypes["READER_KEY_REQUEST"] = 6] = "READER_KEY_REQUEST";
|
|
20
|
+
NFCAccessControlTypes[NFCAccessControlTypes["READER_KEY_RESPONSE"] = 7] = "READER_KEY_RESPONSE";
|
|
21
|
+
})(NFCAccessControlTypes || (NFCAccessControlTypes = {}));
|
|
22
|
+
var IssuerKeyRequestTypes;
|
|
23
|
+
(function (IssuerKeyRequestTypes) {
|
|
24
|
+
IssuerKeyRequestTypes[IssuerKeyRequestTypes["TYPE"] = 1] = "TYPE";
|
|
25
|
+
IssuerKeyRequestTypes[IssuerKeyRequestTypes["KEY"] = 2] = "KEY";
|
|
26
|
+
IssuerKeyRequestTypes[IssuerKeyRequestTypes["IDENTIFIER"] = 3] = "IDENTIFIER";
|
|
27
|
+
})(IssuerKeyRequestTypes || (IssuerKeyRequestTypes = {}));
|
|
28
|
+
var IssuerKeyResponseTypes;
|
|
29
|
+
(function (IssuerKeyResponseTypes) {
|
|
30
|
+
IssuerKeyResponseTypes[IssuerKeyResponseTypes["IDENTIFIER"] = 1] = "IDENTIFIER";
|
|
31
|
+
IssuerKeyResponseTypes[IssuerKeyResponseTypes["STATUS_CODE"] = 2] = "STATUS_CODE";
|
|
32
|
+
})(IssuerKeyResponseTypes || (IssuerKeyResponseTypes = {}));
|
|
33
|
+
var DeviceCredentialKeyRequestTypes;
|
|
34
|
+
(function (DeviceCredentialKeyRequestTypes) {
|
|
35
|
+
DeviceCredentialKeyRequestTypes[DeviceCredentialKeyRequestTypes["TYPE"] = 1] = "TYPE";
|
|
36
|
+
DeviceCredentialKeyRequestTypes[DeviceCredentialKeyRequestTypes["KEY"] = 2] = "KEY";
|
|
37
|
+
DeviceCredentialKeyRequestTypes[DeviceCredentialKeyRequestTypes["ISSUER_KEY_IDENTIFIER"] = 3] = "ISSUER_KEY_IDENTIFIER";
|
|
38
|
+
DeviceCredentialKeyRequestTypes[DeviceCredentialKeyRequestTypes["STATE"] = 4] = "STATE";
|
|
39
|
+
DeviceCredentialKeyRequestTypes[DeviceCredentialKeyRequestTypes["IDENTIFIER"] = 5] = "IDENTIFIER";
|
|
40
|
+
})(DeviceCredentialKeyRequestTypes || (DeviceCredentialKeyRequestTypes = {}));
|
|
41
|
+
var DeviceCredentialKeyResponseTypes;
|
|
42
|
+
(function (DeviceCredentialKeyResponseTypes) {
|
|
43
|
+
DeviceCredentialKeyResponseTypes[DeviceCredentialKeyResponseTypes["IDENTIFIER"] = 1] = "IDENTIFIER";
|
|
44
|
+
DeviceCredentialKeyResponseTypes[DeviceCredentialKeyResponseTypes["ISSUER_KEY_IDENTIFIER"] = 2] = "ISSUER_KEY_IDENTIFIER";
|
|
45
|
+
DeviceCredentialKeyResponseTypes[DeviceCredentialKeyResponseTypes["STATUS_CODE"] = 3] = "STATUS_CODE";
|
|
46
|
+
})(DeviceCredentialKeyResponseTypes || (DeviceCredentialKeyResponseTypes = {}));
|
|
47
|
+
var ReaderKeyRequestTypes;
|
|
48
|
+
(function (ReaderKeyRequestTypes) {
|
|
49
|
+
ReaderKeyRequestTypes[ReaderKeyRequestTypes["TYPE"] = 1] = "TYPE";
|
|
50
|
+
ReaderKeyRequestTypes[ReaderKeyRequestTypes["KEY"] = 2] = "KEY";
|
|
51
|
+
ReaderKeyRequestTypes[ReaderKeyRequestTypes["READER_IDENTIFIER"] = 3] = "READER_IDENTIFIER";
|
|
52
|
+
ReaderKeyRequestTypes[ReaderKeyRequestTypes["IDENTIFIER"] = 4] = "IDENTIFIER";
|
|
53
|
+
})(ReaderKeyRequestTypes || (ReaderKeyRequestTypes = {}));
|
|
54
|
+
var ReaderKeyResponseTypes;
|
|
55
|
+
(function (ReaderKeyResponseTypes) {
|
|
56
|
+
ReaderKeyResponseTypes[ReaderKeyResponseTypes["IDENTIFIER"] = 1] = "IDENTIFIER";
|
|
57
|
+
ReaderKeyResponseTypes[ReaderKeyResponseTypes["STATUS_CODE"] = 2] = "STATUS_CODE";
|
|
58
|
+
})(ReaderKeyResponseTypes || (ReaderKeyResponseTypes = {}));
|
|
59
|
+
var HardwareFinishTypes;
|
|
60
|
+
(function (HardwareFinishTypes) {
|
|
61
|
+
HardwareFinishTypes[HardwareFinishTypes["RGB_COLOR_VALUE"] = 1] = "RGB_COLOR_VALUE";
|
|
62
|
+
})(HardwareFinishTypes || (HardwareFinishTypes = {}));
|
|
63
|
+
var NFCAccessOperation;
|
|
64
|
+
(function (NFCAccessOperation) {
|
|
65
|
+
NFCAccessOperation[NFCAccessOperation["LIST"] = 1] = "LIST";
|
|
66
|
+
NFCAccessOperation[NFCAccessOperation["ADD"] = 2] = "ADD";
|
|
67
|
+
NFCAccessOperation[NFCAccessOperation["REMOVE"] = 3] = "REMOVE";
|
|
68
|
+
})(NFCAccessOperation || (NFCAccessOperation = {}));
|
|
69
|
+
var NFCAccessKeyType;
|
|
70
|
+
(function (NFCAccessKeyType) {
|
|
71
|
+
NFCAccessKeyType[NFCAccessKeyType["ED25519"] = 1] = "ED25519";
|
|
72
|
+
NFCAccessKeyType[NFCAccessKeyType["NIST256"] = 2] = "NIST256";
|
|
73
|
+
})(NFCAccessKeyType || (NFCAccessKeyType = {}));
|
|
74
|
+
var NFCAccessKeyState;
|
|
75
|
+
(function (NFCAccessKeyState) {
|
|
76
|
+
NFCAccessKeyState[NFCAccessKeyState["SUSPENDED"] = 0] = "SUSPENDED";
|
|
77
|
+
NFCAccessKeyState[NFCAccessKeyState["ACTIVE"] = 1] = "ACTIVE";
|
|
78
|
+
})(NFCAccessKeyState || (NFCAccessKeyState = {}));
|
|
79
|
+
/**
|
|
80
|
+
* The result of one NFC Access operation, as sent back to the Home app.
|
|
81
|
+
*
|
|
82
|
+
* @group Lock
|
|
83
|
+
*/
|
|
84
|
+
export var NFCAccessResponseStatus;
|
|
85
|
+
(function (NFCAccessResponseStatus) {
|
|
86
|
+
NFCAccessResponseStatus[NFCAccessResponseStatus["SUCCESS"] = 0] = "SUCCESS";
|
|
87
|
+
NFCAccessResponseStatus[NFCAccessResponseStatus["OUT_OF_RESOURCES"] = 1] = "OUT_OF_RESOURCES";
|
|
88
|
+
NFCAccessResponseStatus[NFCAccessResponseStatus["DUPLICATE"] = 2] = "DUPLICATE";
|
|
89
|
+
NFCAccessResponseStatus[NFCAccessResponseStatus["DOES_NOT_EXIST"] = 3] = "DOES_NOT_EXIST";
|
|
90
|
+
NFCAccessResponseStatus[NFCAccessResponseStatus["NOT_SUPPORTED"] = 4] = "NOT_SUPPORTED";
|
|
91
|
+
})(NFCAccessResponseStatus || (NFCAccessResponseStatus = {}));
|
|
92
|
+
/**
|
|
93
|
+
* The colour of the home key card in Wallet. These four are the only values the Home app accepts.
|
|
94
|
+
*
|
|
95
|
+
* @group Lock
|
|
96
|
+
*/
|
|
97
|
+
export var HomeKeyFinish;
|
|
98
|
+
(function (HomeKeyFinish) {
|
|
99
|
+
HomeKeyFinish[HomeKeyFinish["BLACK"] = 0] = "BLACK";
|
|
100
|
+
HomeKeyFinish[HomeKeyFinish["TAN"] = 14341582] = "TAN";
|
|
101
|
+
HomeKeyFinish[HomeKeyFinish["SILVER"] = 14935011] = "SILVER";
|
|
102
|
+
HomeKeyFinish[HomeKeyFinish["GOLD"] = 15521450] = "GOLD";
|
|
103
|
+
})(HomeKeyFinish || (HomeKeyFinish = {}));
|
|
104
|
+
/**
|
|
105
|
+
* @group Lock
|
|
106
|
+
*/
|
|
107
|
+
export var NFCAccessManagementEvent;
|
|
108
|
+
(function (NFCAccessManagementEvent) {
|
|
109
|
+
NFCAccessManagementEvent["STATE_UPDATED"] = "update-state";
|
|
110
|
+
})(NFCAccessManagementEvent || (NFCAccessManagementEvent = {}));
|
|
111
|
+
const KEY_IDENTIFIER_PREFIX = Buffer.from('key-identifier', 'ascii');
|
|
112
|
+
/**
|
|
113
|
+
* Builds the value of the Hardware Finish characteristic for a card colour.
|
|
114
|
+
* Set it on the AccessoryInformation service of a lock with home keys.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* ```ts
|
|
118
|
+
* accessory.getService(Service.AccessoryInformation)!
|
|
119
|
+
* .setCharacteristic(Characteristic.HardwareFinish, encodeHardwareFinish(HomeKeyFinish.TAN));
|
|
120
|
+
* ```
|
|
121
|
+
* @param finish - the colour of the home key card in Wallet
|
|
122
|
+
* @group Lock
|
|
123
|
+
*/
|
|
124
|
+
export function encodeHardwareFinish(finish) {
|
|
125
|
+
return tlv.encode(HardwareFinishTypes.RGB_COLOR_VALUE, tlv.writeUInt32(finish)).toString('base64');
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Handles the NFCAccess service of a lock: the part of Apple Home Key which runs over HomeKit.
|
|
129
|
+
* The Home app hands the lock a reader key, and the public key of the home key on each phone and watch.
|
|
130
|
+
*
|
|
131
|
+
* This is only half of Home Key. The other half is the NFC reader at the door, which talks to the phone with
|
|
132
|
+
* those keys. HAP-NodeJS has no part in that: without a reader, the key shows in Wallet and opens nothing.
|
|
133
|
+
*
|
|
134
|
+
* Listen for {@link NFCAccessManagementEvent.STATE_UPDATED} to save the state and to hand it to the reader, and
|
|
135
|
+
* pass the saved state back as {@link NFCAccessManagementOptions.state} on the next start.
|
|
136
|
+
*
|
|
137
|
+
* The state holds a private key. Save it in a file of your own which nobody has a reason to share. A Homebridge
|
|
138
|
+
* plugin must not put it in the context of the accessory: that is written to the `cachedAccessories` file,
|
|
139
|
+
* which people post in bug reports.
|
|
140
|
+
*
|
|
141
|
+
* The lock also needs a LockMechanism service, and the colour of the card comes from the Hardware Finish
|
|
142
|
+
* characteristic of the AccessoryInformation service: see {@link encodeHardwareFinish}.
|
|
143
|
+
*
|
|
144
|
+
* HomeKit does not document this service. The layout comes from Apple's own HomeKit code, and the handling of
|
|
145
|
+
* reader keys and device credential keys matches the plugin homebridge-fake-homekey. The handling of issuer keys
|
|
146
|
+
* and the answers to a list of device credential keys are not confirmed against a Home app.
|
|
147
|
+
*
|
|
148
|
+
* @example
|
|
149
|
+
* ```ts
|
|
150
|
+
* // an accessory restored from the cache already has the service: hand it over, so no second one is added
|
|
151
|
+
* const cachedService = accessory.getService(Service.NFCAccess);
|
|
152
|
+
* const nfcAccess = new NFCAccessManagement({ state: savedState, service: cachedService });
|
|
153
|
+
* if (!cachedService) {
|
|
154
|
+
* accessory.addService(nfcAccess.getService());
|
|
155
|
+
* }
|
|
156
|
+
* accessory.getService(Service.AccessoryInformation)!
|
|
157
|
+
* .setCharacteristic(Characteristic.HardwareFinish, encodeHardwareFinish(HomeKeyFinish.TAN));
|
|
158
|
+
*
|
|
159
|
+
* nfcAccess.on(NFCAccessManagementEvent.STATE_UPDATED, (state) => {
|
|
160
|
+
* // save the state in a file of your own (not in the accessory context), and hand it to the NFC reader
|
|
161
|
+
* });
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* @group Lock
|
|
165
|
+
*/
|
|
166
|
+
export class NFCAccessManagement extends EventEmitter {
|
|
167
|
+
nfcAccessService;
|
|
168
|
+
maximumIssuerKeys;
|
|
169
|
+
maximumSuspendedDeviceCredentialKeys;
|
|
170
|
+
maximumDeviceCredentialKeys;
|
|
171
|
+
state;
|
|
172
|
+
/**
|
|
173
|
+
* Instantiates a new NFCAccessManagement.
|
|
174
|
+
*
|
|
175
|
+
* @param {NFCAccessManagementOptions} options - the limits of the lock, its saved state and your own NFCAccess service
|
|
176
|
+
*/
|
|
177
|
+
constructor(options = {}) {
|
|
178
|
+
super();
|
|
179
|
+
this.maximumIssuerKeys = options.maximumIssuerKeys ?? 16;
|
|
180
|
+
this.maximumSuspendedDeviceCredentialKeys = options.maximumSuspendedDeviceCredentialKeys ?? 16;
|
|
181
|
+
this.maximumDeviceCredentialKeys = options.maximumDeviceCredentialKeys ?? 16;
|
|
182
|
+
this.state = {
|
|
183
|
+
readerKey: options.state?.readerKey && { ...options.state.readerKey },
|
|
184
|
+
issuerKeys: (options.state?.issuerKeys ?? []).map(key => ({ ...key })),
|
|
185
|
+
deviceCredentialKeys: (options.state?.deviceCredentialKeys ?? []).map(key => ({ ...key })),
|
|
186
|
+
};
|
|
187
|
+
this.nfcAccessService = options.service || new Service.NFCAccess();
|
|
188
|
+
this.setupServiceHandlers();
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* The identifier of a reader key or an issuer key: the first 8 bytes of SHA-256("key-identifier" + key).
|
|
192
|
+
*
|
|
193
|
+
* @param key - the private key of a reader key, or the public key of an issuer key
|
|
194
|
+
*/
|
|
195
|
+
static keyIdentifier(key) {
|
|
196
|
+
return createHash('sha256').update(Buffer.concat([KEY_IDENTIFIER_PREFIX, key])).digest().subarray(0, 8);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* @returns the NFCAccess service
|
|
200
|
+
*/
|
|
201
|
+
getService() {
|
|
202
|
+
return this.nfcAccessService;
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* @returns a copy of everything the Home app has stored on the lock. It holds a private key.
|
|
206
|
+
*/
|
|
207
|
+
getState() {
|
|
208
|
+
return {
|
|
209
|
+
readerKey: this.state.readerKey && { ...this.state.readerKey },
|
|
210
|
+
issuerKeys: this.state.issuerKeys.map(key => ({ ...key })),
|
|
211
|
+
deviceCredentialKeys: this.state.deviceCredentialKeys.map(key => ({ ...key })),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* This destroys the NFCAccessManagement.
|
|
216
|
+
* It unregisters the SET handler it has associated with the given NFCAccess service.
|
|
217
|
+
* It removes all event handlers which were registered to this object.
|
|
218
|
+
*/
|
|
219
|
+
destroy() {
|
|
220
|
+
this.removeAllListeners();
|
|
221
|
+
this.nfcAccessService.getCharacteristic(Characteristic.NFCAccessControlPoint).removeOnSet();
|
|
222
|
+
}
|
|
223
|
+
handleControlPointWrite(value) {
|
|
224
|
+
let response = Buffer.alloc(0);
|
|
225
|
+
const before = JSON.stringify(this.state);
|
|
226
|
+
try {
|
|
227
|
+
const objects = tlv.decodeWithLists(Buffer.from(value, 'base64'));
|
|
228
|
+
const operationData = objects[NFCAccessControlTypes.OPERATION_TYPE];
|
|
229
|
+
const operation = operationData
|
|
230
|
+
? tlv.readVariableUIntLE(operationData)
|
|
231
|
+
: undefined;
|
|
232
|
+
// one write can hold several requests of one kind, as a list: each gets its own answer, in the same order
|
|
233
|
+
const answer = (requestType, responseType, handle) => {
|
|
234
|
+
const requests = objects[requestType];
|
|
235
|
+
if (requests === undefined) {
|
|
236
|
+
return undefined;
|
|
237
|
+
}
|
|
238
|
+
const answers = (Array.isArray(requests)
|
|
239
|
+
? requests
|
|
240
|
+
: [requests]).flatMap(data => handle(tlv.decode(data)));
|
|
241
|
+
// an empty list is no entry at all, not an entry of zero length
|
|
242
|
+
return answers.length > 0
|
|
243
|
+
? tlv.encode(responseType, answers)
|
|
244
|
+
: Buffer.alloc(0);
|
|
245
|
+
};
|
|
246
|
+
response = answer(NFCAccessControlTypes.READER_KEY_REQUEST, NFCAccessControlTypes.READER_KEY_RESPONSE, fields => this.handleReaderKey(operation, fields))
|
|
247
|
+
?? answer(NFCAccessControlTypes.DEVICE_CREDENTIAL_KEY_REQUEST, NFCAccessControlTypes.DEVICE_CREDENTIAL_KEY_RESPONSE, fields => this.handleDeviceCredentialKey(operation, fields))
|
|
248
|
+
?? answer(NFCAccessControlTypes.ISSUER_KEY_REQUEST, NFCAccessControlTypes.ISSUER_KEY_RESPONSE, fields => this.handleIssuerKey(operation, fields))
|
|
249
|
+
?? Buffer.alloc(0);
|
|
250
|
+
}
|
|
251
|
+
catch {
|
|
252
|
+
// a value which cannot be read is answered with nothing, as an unknown request is
|
|
253
|
+
}
|
|
254
|
+
if (JSON.stringify(this.state) !== before) {
|
|
255
|
+
const state = this.getState();
|
|
256
|
+
setTimeout(() => {
|
|
257
|
+
// the state of this write, not the state at the time the timer fires: another write may have followed by then
|
|
258
|
+
this.emit(NFCAccessManagementEvent.STATE_UPDATED, state);
|
|
259
|
+
}, 0).unref();
|
|
260
|
+
}
|
|
261
|
+
return response.toString('base64');
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* @returns the answers to one reader key request, without the type of the response around them
|
|
265
|
+
*/
|
|
266
|
+
handleReaderKey(operation, fields) {
|
|
267
|
+
const readerKey = this.state.readerKey;
|
|
268
|
+
const answer = (status) => [
|
|
269
|
+
tlv.encode(ReaderKeyResponseTypes.STATUS_CODE, status),
|
|
270
|
+
];
|
|
271
|
+
switch (operation) {
|
|
272
|
+
case NFCAccessOperation.LIST:
|
|
273
|
+
// a lock without a reader key answers with nothing
|
|
274
|
+
return readerKey
|
|
275
|
+
? [
|
|
276
|
+
tlv.encode(ReaderKeyResponseTypes.IDENTIFIER, Buffer.from(readerKey.identifier, 'hex')),
|
|
277
|
+
]
|
|
278
|
+
: [];
|
|
279
|
+
case NFCAccessOperation.ADD: {
|
|
280
|
+
const type = fields[ReaderKeyRequestTypes.TYPE];
|
|
281
|
+
const privateKey = fields[ReaderKeyRequestTypes.KEY];
|
|
282
|
+
if (!type || tlv.readVariableUIntLE(type) !== NFCAccessKeyType.NIST256 || privateKey?.length !== 32) {
|
|
283
|
+
return answer(NFCAccessResponseStatus.NOT_SUPPORTED);
|
|
284
|
+
}
|
|
285
|
+
const identifier = NFCAccessManagement.keyIdentifier(privateKey).toString('hex');
|
|
286
|
+
if (readerKey?.identifier === identifier) {
|
|
287
|
+
return answer(NFCAccessResponseStatus.DUPLICATE);
|
|
288
|
+
}
|
|
289
|
+
this.state.readerKey = {
|
|
290
|
+
identifier,
|
|
291
|
+
privateKey: privateKey.toString('hex'),
|
|
292
|
+
readerIdentifier: (fields[ReaderKeyRequestTypes.READER_IDENTIFIER] ?? Buffer.alloc(0)).toString('hex'),
|
|
293
|
+
};
|
|
294
|
+
return answer(NFCAccessResponseStatus.SUCCESS);
|
|
295
|
+
}
|
|
296
|
+
case NFCAccessOperation.REMOVE: {
|
|
297
|
+
const wanted = fields[ReaderKeyRequestTypes.IDENTIFIER]?.toString('hex');
|
|
298
|
+
if (!readerKey || (wanted !== undefined && wanted !== readerKey.identifier)) {
|
|
299
|
+
return answer(NFCAccessResponseStatus.DOES_NOT_EXIST);
|
|
300
|
+
}
|
|
301
|
+
// without the reader key the device credential keys open nothing, so they go with it
|
|
302
|
+
this.state.readerKey = undefined;
|
|
303
|
+
this.state.deviceCredentialKeys = [];
|
|
304
|
+
return answer(NFCAccessResponseStatus.SUCCESS);
|
|
305
|
+
}
|
|
306
|
+
default:
|
|
307
|
+
return [];
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* @returns the answers to one device credential key request, without the type of the response around them
|
|
312
|
+
*/
|
|
313
|
+
handleDeviceCredentialKey(operation, fields) {
|
|
314
|
+
const issuerKeyIdentifier = fields[DeviceCredentialKeyRequestTypes.ISSUER_KEY_IDENTIFIER];
|
|
315
|
+
const answer = (status) => [
|
|
316
|
+
Buffer.concat([
|
|
317
|
+
...(issuerKeyIdentifier
|
|
318
|
+
? [
|
|
319
|
+
tlv.encode(DeviceCredentialKeyResponseTypes.ISSUER_KEY_IDENTIFIER, issuerKeyIdentifier),
|
|
320
|
+
]
|
|
321
|
+
: []),
|
|
322
|
+
tlv.encode(DeviceCredentialKeyResponseTypes.STATUS_CODE, status),
|
|
323
|
+
]),
|
|
324
|
+
];
|
|
325
|
+
switch (operation) {
|
|
326
|
+
case NFCAccessOperation.LIST:
|
|
327
|
+
return this.state.deviceCredentialKeys.map(key => Buffer.concat([
|
|
328
|
+
tlv.encode(DeviceCredentialKeyResponseTypes.IDENTIFIER, Buffer.from(key.identifier, 'hex')),
|
|
329
|
+
tlv.encode(DeviceCredentialKeyResponseTypes.ISSUER_KEY_IDENTIFIER, Buffer.from(key.issuerKeyIdentifier, 'hex')),
|
|
330
|
+
tlv.encode(DeviceCredentialKeyResponseTypes.STATUS_CODE, NFCAccessResponseStatus.SUCCESS),
|
|
331
|
+
]));
|
|
332
|
+
case NFCAccessOperation.ADD: {
|
|
333
|
+
const type = fields[DeviceCredentialKeyRequestTypes.TYPE];
|
|
334
|
+
const publicKey = fields[DeviceCredentialKeyRequestTypes.KEY];
|
|
335
|
+
if (!type || tlv.readVariableUIntLE(type) !== NFCAccessKeyType.NIST256 || publicKey?.length !== 64 || !issuerKeyIdentifier) {
|
|
336
|
+
return answer(NFCAccessResponseStatus.NOT_SUPPORTED);
|
|
337
|
+
}
|
|
338
|
+
const identifier = createHash('sha1').update(Buffer.concat([
|
|
339
|
+
Buffer.from([0x04]),
|
|
340
|
+
publicKey,
|
|
341
|
+
])).digest().subarray(0, 6).toString('hex');
|
|
342
|
+
if (this.state.deviceCredentialKeys.some(key => key.identifier === identifier)) {
|
|
343
|
+
return answer(NFCAccessResponseStatus.DUPLICATE);
|
|
344
|
+
}
|
|
345
|
+
const state = fields[DeviceCredentialKeyRequestTypes.STATE];
|
|
346
|
+
const active = !state || tlv.readVariableUIntLE(state) === NFCAccessKeyState.ACTIVE;
|
|
347
|
+
const suspended = this.state.deviceCredentialKeys.filter(key => !key.active).length;
|
|
348
|
+
if (this.state.deviceCredentialKeys.length >= this.maximumDeviceCredentialKeys
|
|
349
|
+
|| (!active && suspended >= this.maximumSuspendedDeviceCredentialKeys)) {
|
|
350
|
+
return answer(NFCAccessResponseStatus.OUT_OF_RESOURCES);
|
|
351
|
+
}
|
|
352
|
+
this.state.deviceCredentialKeys.push({
|
|
353
|
+
identifier,
|
|
354
|
+
publicKey: publicKey.toString('hex'),
|
|
355
|
+
issuerKeyIdentifier: issuerKeyIdentifier.toString('hex'),
|
|
356
|
+
active,
|
|
357
|
+
});
|
|
358
|
+
return answer(NFCAccessResponseStatus.SUCCESS);
|
|
359
|
+
}
|
|
360
|
+
case NFCAccessOperation.REMOVE: {
|
|
361
|
+
// which identifier the Home app sends is not confirmed, so the full public key is accepted too
|
|
362
|
+
const wanted = fields[DeviceCredentialKeyRequestTypes.IDENTIFIER]?.toString('hex');
|
|
363
|
+
const index = wanted === undefined
|
|
364
|
+
? -1
|
|
365
|
+
: this.state.deviceCredentialKeys.findIndex(key => key.identifier === wanted || key.publicKey === wanted);
|
|
366
|
+
if (index < 0) {
|
|
367
|
+
return answer(NFCAccessResponseStatus.DOES_NOT_EXIST);
|
|
368
|
+
}
|
|
369
|
+
this.state.deviceCredentialKeys.splice(index, 1);
|
|
370
|
+
return answer(NFCAccessResponseStatus.SUCCESS);
|
|
371
|
+
}
|
|
372
|
+
default:
|
|
373
|
+
return [];
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* @returns the answers to one issuer key request, without the type of the response around them
|
|
378
|
+
*/
|
|
379
|
+
handleIssuerKey(operation, fields) {
|
|
380
|
+
const answer = (status, identifier) => [
|
|
381
|
+
Buffer.concat([
|
|
382
|
+
...(identifier
|
|
383
|
+
? [
|
|
384
|
+
tlv.encode(IssuerKeyResponseTypes.IDENTIFIER, Buffer.from(identifier, 'hex')),
|
|
385
|
+
]
|
|
386
|
+
: []),
|
|
387
|
+
tlv.encode(IssuerKeyResponseTypes.STATUS_CODE, status),
|
|
388
|
+
]),
|
|
389
|
+
];
|
|
390
|
+
switch (operation) {
|
|
391
|
+
case NFCAccessOperation.LIST:
|
|
392
|
+
return this.state.issuerKeys.map(key => Buffer.concat([
|
|
393
|
+
tlv.encode(IssuerKeyResponseTypes.IDENTIFIER, Buffer.from(key.identifier, 'hex')),
|
|
394
|
+
tlv.encode(IssuerKeyResponseTypes.STATUS_CODE, NFCAccessResponseStatus.SUCCESS),
|
|
395
|
+
]));
|
|
396
|
+
case NFCAccessOperation.ADD: {
|
|
397
|
+
const type = fields[IssuerKeyRequestTypes.TYPE];
|
|
398
|
+
const publicKey = fields[IssuerKeyRequestTypes.KEY];
|
|
399
|
+
if (!type || tlv.readVariableUIntLE(type) !== NFCAccessKeyType.ED25519 || publicKey?.length !== 32) {
|
|
400
|
+
return answer(NFCAccessResponseStatus.NOT_SUPPORTED);
|
|
401
|
+
}
|
|
402
|
+
const identifier = NFCAccessManagement.keyIdentifier(publicKey).toString('hex');
|
|
403
|
+
if (this.state.issuerKeys.some(key => key.identifier === identifier)) {
|
|
404
|
+
return answer(NFCAccessResponseStatus.DUPLICATE, identifier);
|
|
405
|
+
}
|
|
406
|
+
if (this.state.issuerKeys.length >= this.maximumIssuerKeys) {
|
|
407
|
+
return answer(NFCAccessResponseStatus.OUT_OF_RESOURCES, identifier);
|
|
408
|
+
}
|
|
409
|
+
this.state.issuerKeys.push({
|
|
410
|
+
identifier,
|
|
411
|
+
publicKey: publicKey.toString('hex'),
|
|
412
|
+
});
|
|
413
|
+
return answer(NFCAccessResponseStatus.SUCCESS, identifier);
|
|
414
|
+
}
|
|
415
|
+
case NFCAccessOperation.REMOVE: {
|
|
416
|
+
const wanted = fields[IssuerKeyRequestTypes.IDENTIFIER]?.toString('hex');
|
|
417
|
+
const index = this.state.issuerKeys.findIndex(key => key.identifier === wanted);
|
|
418
|
+
if (index < 0) {
|
|
419
|
+
return answer(NFCAccessResponseStatus.DOES_NOT_EXIST, wanted);
|
|
420
|
+
}
|
|
421
|
+
this.state.issuerKeys.splice(index, 1);
|
|
422
|
+
return answer(NFCAccessResponseStatus.SUCCESS, wanted);
|
|
423
|
+
}
|
|
424
|
+
default:
|
|
425
|
+
return [];
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
setupServiceHandlers() {
|
|
429
|
+
this.nfcAccessService.getCharacteristic(Characteristic.NFCAccessSupportedConfiguration)
|
|
430
|
+
.updateValue(Buffer.concat([
|
|
431
|
+
tlv.encode(NFCAccessSupportedConfigurationTypes.MAXIMUM_ISSUER_KEYS, this.maximumIssuerKeys),
|
|
432
|
+
tlv.encode(NFCAccessSupportedConfigurationTypes.MAXIMUM_SUSPENDED_DEVICE_CREDENTIAL_KEYS, this.maximumSuspendedDeviceCredentialKeys),
|
|
433
|
+
]).toString('base64'));
|
|
434
|
+
// Kept at 0, as the plugin homebridge-fake-homekey does, which works with the Home app.
|
|
435
|
+
// AccessCodeManagement counts up instead. Which of the two the Home app needs is not confirmed.
|
|
436
|
+
this.nfcAccessService.getCharacteristic(Characteristic.ConfigurationState)
|
|
437
|
+
.updateValue(0);
|
|
438
|
+
this.nfcAccessService.getCharacteristic(Characteristic.NFCAccessControlPoint)
|
|
439
|
+
.onSet(value => this.handleControlPointWrite(value))
|
|
440
|
+
.updateValue('');
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
//# sourceMappingURL=NFCAccessManagement.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NFCAccessManagement.js","sourceRoot":"","sources":["../../../src/lib/lock/NFCAccessManagement.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AACpC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAE1C,OAAO,EAAE,cAAc,EAA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ACd,OAAO,MAAM,CAAC,uBAAuB,CAAC,cAAc,EAAE,MAAM,CAAC,CAAA;gBAC/D,CAAC;gBACD,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;gBACtC,OAAO,MAAM,CAAC,uBAAuB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;YACxD,CAAC;YACD;gBACE,OAAO,EAAE,CAAA;QACb,CAAC;IACH,CAAC;IAEO,oBAAoB;QAC1B,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,cAAc,CAAC,+BAA+B,CAAC;aACpF,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC;YACzB,GAAG,CAAC,MAAM,CAAC,oCAAoC,CAAC,mBAAmB,EAAE,IAAI,CAAC,iBAAiB,CAAC;YAC5F,GAAG,CAAC,MAAM,CAAC,oCAAoC,CAAC,wCAAwC,EAAE,IAAI,CAAC,oCAAoC,CAAC;SACrI,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAA;QAExB,wFAAwF;QACxF,gGAAgG;QAChG,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,cAAc,CAAC,kBAAkB,CAAC;aACvE,WAAW,CAAC,CAAC,CAAC,CAAA;QAEjB,IAAI,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,cAAc,CAAC,qBAAqB,CAAC;aAC1E,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,uBAAuB,CAAC,KAAe,CAAC,CAAC;aAC7D,WAAW,CAAC,EAAE,CAAC,CAAA;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The faults an accessory can report with the Error Status characteristic.
|
|
3
|
+
* The Home app turns a fault which was not there before into a notification, like "Front Door Jammed".
|
|
4
|
+
*
|
|
5
|
+
* @group Utils
|
|
6
|
+
*/
|
|
7
|
+
export declare enum ErrorStatusCode {
|
|
8
|
+
SENSOR_FAILURE = 0,
|
|
9
|
+
AUDIO_FAILURE = 1,
|
|
10
|
+
BULB_FAILURE = 2,
|
|
11
|
+
POWER_INSTABILITY = 3,
|
|
12
|
+
EXCESSIVE_BATTERY_DRAIN = 4,
|
|
13
|
+
CONNECTIVITY_FAILURE = 5,
|
|
14
|
+
COOLING_FAILURE = 6,
|
|
15
|
+
HEATING_FAILURE = 7,
|
|
16
|
+
JAMMED = 8,
|
|
17
|
+
DEVICE_OVERHEATING = 9,
|
|
18
|
+
SAFETY_TEMPERATURE_EXCEEDED = 10,
|
|
19
|
+
SUDDEN_TEMPERATURE_CHANGE = 11,
|
|
20
|
+
FREEZE_RISK = 12,
|
|
21
|
+
CALIBRATION_ERROR = 13,
|
|
22
|
+
DEVICE_DAMAGED = 14
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* One fault of an accessory.
|
|
26
|
+
*
|
|
27
|
+
* @group Utils
|
|
28
|
+
*/
|
|
29
|
+
export interface ErrorStatusEntry {
|
|
30
|
+
code: ErrorStatusCode;
|
|
31
|
+
/** Text of the manufacturer about the fault, like its own error number. Keep it short. */
|
|
32
|
+
manufacturerErrorInfo?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Builds the value of the Error Status characteristic from the faults an accessory has right now.
|
|
36
|
+
* No faults is an empty value.
|
|
37
|
+
*
|
|
38
|
+
* No service lists the characteristic, so add it to the service the fault belongs to, and update it when a
|
|
39
|
+
* fault starts or ends.
|
|
40
|
+
*
|
|
41
|
+
* HomeKit does not document this characteristic, which is new in iOS 27. The layout comes from Apple's own
|
|
42
|
+
* HomeKit code.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const errorStatus = lockService.addCharacteristic(Characteristic.ErrorStatus);
|
|
47
|
+
*
|
|
48
|
+
* // when the lock jams
|
|
49
|
+
* errorStatus.updateValue(encodeErrorStatus([{ code: ErrorStatusCode.JAMMED }]));
|
|
50
|
+
*
|
|
51
|
+
* // when the fault ends
|
|
52
|
+
* errorStatus.updateValue(encodeErrorStatus([]));
|
|
53
|
+
* ```
|
|
54
|
+
* @param entries - the faults the accessory has right now
|
|
55
|
+
* @group Utils
|
|
56
|
+
*/
|
|
57
|
+
export declare function encodeErrorStatus(entries: ErrorStatusEntry[]): string;
|
|
58
|
+
/**
|
|
59
|
+
* Reads the value of the Error Status characteristic back into its faults.
|
|
60
|
+
*
|
|
61
|
+
* @param value - the value of the characteristic, as base64
|
|
62
|
+
* @group Utils
|
|
63
|
+
*/
|
|
64
|
+
export declare function decodeErrorStatus(value: string): ErrorStatusEntry[];
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { Buffer } from 'node:buffer';
|
|
2
|
+
import * as tlv from './tlv.js';
|
|
3
|
+
var ErrorStatusTypes;
|
|
4
|
+
(function (ErrorStatusTypes) {
|
|
5
|
+
ErrorStatusTypes[ErrorStatusTypes["ERROR_ENTRY"] = 1] = "ERROR_ENTRY";
|
|
6
|
+
})(ErrorStatusTypes || (ErrorStatusTypes = {}));
|
|
7
|
+
var ErrorEntryTypes;
|
|
8
|
+
(function (ErrorEntryTypes) {
|
|
9
|
+
ErrorEntryTypes[ErrorEntryTypes["ERROR_CODE"] = 1] = "ERROR_CODE";
|
|
10
|
+
ErrorEntryTypes[ErrorEntryTypes["MANUFACTURER_ERROR_INFO"] = 2] = "MANUFACTURER_ERROR_INFO";
|
|
11
|
+
})(ErrorEntryTypes || (ErrorEntryTypes = {}));
|
|
12
|
+
/**
|
|
13
|
+
* The faults an accessory can report with the Error Status characteristic.
|
|
14
|
+
* The Home app turns a fault which was not there before into a notification, like "Front Door Jammed".
|
|
15
|
+
*
|
|
16
|
+
* @group Utils
|
|
17
|
+
*/
|
|
18
|
+
export var ErrorStatusCode;
|
|
19
|
+
(function (ErrorStatusCode) {
|
|
20
|
+
ErrorStatusCode[ErrorStatusCode["SENSOR_FAILURE"] = 0] = "SENSOR_FAILURE";
|
|
21
|
+
ErrorStatusCode[ErrorStatusCode["AUDIO_FAILURE"] = 1] = "AUDIO_FAILURE";
|
|
22
|
+
ErrorStatusCode[ErrorStatusCode["BULB_FAILURE"] = 2] = "BULB_FAILURE";
|
|
23
|
+
ErrorStatusCode[ErrorStatusCode["POWER_INSTABILITY"] = 3] = "POWER_INSTABILITY";
|
|
24
|
+
ErrorStatusCode[ErrorStatusCode["EXCESSIVE_BATTERY_DRAIN"] = 4] = "EXCESSIVE_BATTERY_DRAIN";
|
|
25
|
+
ErrorStatusCode[ErrorStatusCode["CONNECTIVITY_FAILURE"] = 5] = "CONNECTIVITY_FAILURE";
|
|
26
|
+
ErrorStatusCode[ErrorStatusCode["COOLING_FAILURE"] = 6] = "COOLING_FAILURE";
|
|
27
|
+
ErrorStatusCode[ErrorStatusCode["HEATING_FAILURE"] = 7] = "HEATING_FAILURE";
|
|
28
|
+
ErrorStatusCode[ErrorStatusCode["JAMMED"] = 8] = "JAMMED";
|
|
29
|
+
ErrorStatusCode[ErrorStatusCode["DEVICE_OVERHEATING"] = 9] = "DEVICE_OVERHEATING";
|
|
30
|
+
ErrorStatusCode[ErrorStatusCode["SAFETY_TEMPERATURE_EXCEEDED"] = 10] = "SAFETY_TEMPERATURE_EXCEEDED";
|
|
31
|
+
ErrorStatusCode[ErrorStatusCode["SUDDEN_TEMPERATURE_CHANGE"] = 11] = "SUDDEN_TEMPERATURE_CHANGE";
|
|
32
|
+
ErrorStatusCode[ErrorStatusCode["FREEZE_RISK"] = 12] = "FREEZE_RISK";
|
|
33
|
+
ErrorStatusCode[ErrorStatusCode["CALIBRATION_ERROR"] = 13] = "CALIBRATION_ERROR";
|
|
34
|
+
ErrorStatusCode[ErrorStatusCode["DEVICE_DAMAGED"] = 14] = "DEVICE_DAMAGED";
|
|
35
|
+
})(ErrorStatusCode || (ErrorStatusCode = {}));
|
|
36
|
+
/**
|
|
37
|
+
* Builds the value of the Error Status characteristic from the faults an accessory has right now.
|
|
38
|
+
* No faults is an empty value.
|
|
39
|
+
*
|
|
40
|
+
* No service lists the characteristic, so add it to the service the fault belongs to, and update it when a
|
|
41
|
+
* fault starts or ends.
|
|
42
|
+
*
|
|
43
|
+
* HomeKit does not document this characteristic, which is new in iOS 27. The layout comes from Apple's own
|
|
44
|
+
* HomeKit code.
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* const errorStatus = lockService.addCharacteristic(Characteristic.ErrorStatus);
|
|
49
|
+
*
|
|
50
|
+
* // when the lock jams
|
|
51
|
+
* errorStatus.updateValue(encodeErrorStatus([{ code: ErrorStatusCode.JAMMED }]));
|
|
52
|
+
*
|
|
53
|
+
* // when the fault ends
|
|
54
|
+
* errorStatus.updateValue(encodeErrorStatus([]));
|
|
55
|
+
* ```
|
|
56
|
+
* @param entries - the faults the accessory has right now
|
|
57
|
+
* @group Utils
|
|
58
|
+
*/
|
|
59
|
+
export function encodeErrorStatus(entries) {
|
|
60
|
+
if (entries.length === 0) {
|
|
61
|
+
return '';
|
|
62
|
+
}
|
|
63
|
+
return tlv.encode(ErrorStatusTypes.ERROR_ENTRY, entries.map(entry => Buffer.concat([
|
|
64
|
+
tlv.encode(ErrorEntryTypes.ERROR_CODE, tlv.writeVariableUIntLE(entry.code)),
|
|
65
|
+
...(entry.manufacturerErrorInfo
|
|
66
|
+
? [
|
|
67
|
+
tlv.encode(ErrorEntryTypes.MANUFACTURER_ERROR_INFO, entry.manufacturerErrorInfo),
|
|
68
|
+
]
|
|
69
|
+
: []),
|
|
70
|
+
]))).toString('base64');
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Reads the value of the Error Status characteristic back into its faults.
|
|
74
|
+
*
|
|
75
|
+
* @param value - the value of the characteristic, as base64
|
|
76
|
+
* @group Utils
|
|
77
|
+
*/
|
|
78
|
+
export function decodeErrorStatus(value) {
|
|
79
|
+
const entries = tlv.decodeWithLists(Buffer.from(value, 'base64'))[ErrorStatusTypes.ERROR_ENTRY];
|
|
80
|
+
if (entries === undefined) {
|
|
81
|
+
return [];
|
|
82
|
+
}
|
|
83
|
+
return (Array.isArray(entries)
|
|
84
|
+
? entries
|
|
85
|
+
: [entries]).map((data) => {
|
|
86
|
+
const fields = tlv.decode(data);
|
|
87
|
+
const code = fields[ErrorEntryTypes.ERROR_CODE];
|
|
88
|
+
if (!code) {
|
|
89
|
+
throw new Error('Error Status entry without an error code');
|
|
90
|
+
}
|
|
91
|
+
const info = fields[ErrorEntryTypes.MANUFACTURER_ERROR_INFO];
|
|
92
|
+
return {
|
|
93
|
+
code: tlv.readVariableUIntLE(code),
|
|
94
|
+
...(info && {
|
|
95
|
+
manufacturerErrorInfo: info.toString('utf8'),
|
|
96
|
+
}),
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=error-status.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-status.js","sourceRoot":"","sources":["../../../src/lib/util/error-status.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAEpC,OAAO,KAAK,GAAG,MAAM,UAAU,CAAA;AAE/B,IAAK,gBAEJ;AAFD,WAAK,gBAAgB;IACnB,qEAAkB,CAAA;AACpB,CAAC,EAFI,gBAAgB,KAAhB,gBAAgB,QAEpB;AAED,IAAK,eAGJ;AAHD,WAAK,eAAe;IAClB,iEAAiB,CAAA;IACjB,2FAA8B,CAAA;AAChC,CAAC,EAHI,eAAe,KAAf,eAAe,QAGnB;AAED;;;;;GAKG;AACH,MAAM,CAAN,IAAY,eAgBX;AAhBD,WAAY,eAAe;IACzB,yEAAkB,CAAA;IAClB,uEAAiB,CAAA;IACjB,qEAAgB,CAAA;IAChB,+EAAqB,CAAA;IACrB,2FAA2B,CAAA;IAC3B,qFAAwB,CAAA;IACxB,2EAAmB,CAAA;IACnB,2EAAmB,CAAA;IACnB,yDAAU,CAAA;IACV,iFAAsB,CAAA;IACtB,oG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