@blueid/access-cli 0.3.0

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.
@@ -0,0 +1,46 @@
1
+ // @generated by protoc-gen-es v1.3.3 with parameter "target=js"
2
+ // @generated from file BlueLock.proto (syntax proto2)
3
+ /* eslint-disable */
4
+ // @ts-nocheck
5
+
6
+ import { proto2 } from "@bufbuild/protobuf";
7
+ import { BlueLocalTimeSchedule } from "./BlueCore_pb.js";
8
+
9
+ /**
10
+ * @generated from enum BlueLockState
11
+ */
12
+ export const BlueLockState = proto2.makeEnum(
13
+ "BlueLockState",
14
+ [
15
+ {no: 1, name: "UnknownLockState"},
16
+ {no: 2, name: "Locked"},
17
+ {no: 3, name: "Unlocked"},
18
+ {no: 4, name: "Jammed"},
19
+ ],
20
+ );
21
+
22
+ /**
23
+ * @generated from message BlueLockConfig
24
+ */
25
+ export const BlueLockConfig = proto2.makeMessageType(
26
+ "BlueLockConfig",
27
+ () => [
28
+ { no: 1, name: "openSchedules", kind: "message", T: BlueLocalTimeSchedule, repeated: true },
29
+ { no: 2, name: "openScheduleByUser", kind: "scalar", T: 8 /* ScalarType.BOOL */, default: false },
30
+ { no: 20, name: "closedDays", kind: "scalar", T: 13 /* ScalarType.UINT32 */, repeated: true },
31
+ { no: 21, name: "defaultOpenTimeSec", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 5 },
32
+ { no: 22, name: "extendedOpenTimeSec", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 3600 },
33
+ ],
34
+ );
35
+
36
+ /**
37
+ * @generated from message BlueLockStatus
38
+ */
39
+ export const BlueLockStatus = proto2.makeMessageType(
40
+ "BlueLockStatus",
41
+ () => [
42
+ { no: 1, name: "state", kind: "enum", T: proto2.getEnumType(BlueLockState) },
43
+ { no: 2, name: "openings", kind: "scalar", T: 13 /* ScalarType.UINT32 */ },
44
+ ],
45
+ );
46
+
@@ -0,0 +1,73 @@
1
+ // @generated by protoc-gen-es v1.3.3 with parameter "target=js"
2
+ // @generated from file BlueSDK.proto (syntax proto2)
3
+ /* eslint-disable */
4
+ // @ts-nocheck
5
+
6
+ import { proto2 } from "@bufbuild/protobuf";
7
+ import { BlueBleManufacturerInfo } from "./BlueCore_pb.js";
8
+
9
+ /**
10
+ * @generated from enum BlueDeviceType
11
+ */
12
+ export const BlueDeviceType = proto2.makeEnum(
13
+ "BlueDeviceType",
14
+ [
15
+ {no: 1, name: "BluetoothDevice"},
16
+ {no: 2, name: "UWBDevice"},
17
+ ],
18
+ );
19
+
20
+ /**
21
+ * @generated from message BlueI18n
22
+ */
23
+ export const BlueI18n = proto2.makeMessageType(
24
+ "BlueI18n",
25
+ () => [
26
+ { no: 1, name: "nfcWaitMessage", kind: "scalar", T: 9 /* ScalarType.STRING */, default: "Waiting for transponder" },
27
+ { no: 2, name: "nfcOssSuccessReadConfigurationMessage", kind: "scalar", T: 9 /* ScalarType.STRING */, default: "Configuration read successfully" },
28
+ { no: 3, name: "nfcOssSuccessUpdateConfigurationMessage", kind: "scalar", T: 9 /* ScalarType.STRING */, default: "Configuration successfully updated" },
29
+ { no: 4, name: "nfcOssSuccessClearEventsMessage", kind: "scalar", T: 9 /* ScalarType.STRING */, default: "Events successfully cleared" },
30
+ { no: 5, name: "nfcOssSuccessIsProvisionedMessage", kind: "scalar", T: 9 /* ScalarType.STRING */, default: "Is already provisioned" },
31
+ { no: 6, name: "nfcOssSuccessProvisionMessage", kind: "scalar", T: 9 /* ScalarType.STRING */, default: "Successfully provisioned" },
32
+ { no: 7, name: "nfcOssSuccessUnprovisionMessage", kind: "scalar", T: 9 /* ScalarType.STRING */, default: "Successfully unprovisioned" },
33
+ { no: 8, name: "nfcOssSuccessFormatMessage", kind: "scalar", T: 9 /* ScalarType.STRING */, default: "Transponder was successfully formatted" },
34
+ ],
35
+ );
36
+
37
+ /**
38
+ * @generated from message BlueDeviceDetailsBluetooth
39
+ */
40
+ export const BlueDeviceDetailsBluetooth = proto2.makeMessageType(
41
+ "BlueDeviceDetailsBluetooth",
42
+ () => [
43
+ { no: 1, name: "rssi", kind: "scalar", T: 5 /* ScalarType.INT32 */ },
44
+ { no: 2, name: "txPower", kind: "scalar", T: 5 /* ScalarType.INT32 */ },
45
+ { no: 3, name: "isIBeacon", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
46
+ ],
47
+ );
48
+
49
+ /**
50
+ * @generated from message BlueDeviceDetailsUWB
51
+ */
52
+ export const BlueDeviceDetailsUWB = proto2.makeMessageType(
53
+ "BlueDeviceDetailsUWB",
54
+ () => [
55
+ { no: 1, name: "notUsed", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
56
+ ],
57
+ );
58
+
59
+ /**
60
+ * @generated from message BlueDeviceInfo
61
+ */
62
+ export const BlueDeviceInfo = proto2.makeMessageType(
63
+ "BlueDeviceInfo",
64
+ () => [
65
+ { no: 1, name: "deviceType", kind: "enum", T: proto2.getEnumType(BlueDeviceType) },
66
+ { no: 2, name: "deviceId", kind: "scalar", T: 9 /* ScalarType.STRING */ },
67
+ { no: 3, name: "distanceMeters", kind: "scalar", T: 2 /* ScalarType.FLOAT */ },
68
+ { no: 4, name: "manufacturerInfo", kind: "message", T: BlueBleManufacturerInfo },
69
+ { no: 5, name: "bluetooth", kind: "message", T: BlueDeviceDetailsBluetooth, oneof: "details" },
70
+ { no: 6, name: "uwb", kind: "message", T: BlueDeviceDetailsUWB, oneof: "details" },
71
+ ],
72
+ );
73
+
@@ -0,0 +1,249 @@
1
+ // @generated by protoc-gen-es v1.3.3 with parameter "target=js"
2
+ // @generated from file BlueSystem.proto (syntax proto2)
3
+ /* eslint-disable */
4
+ // @ts-nocheck
5
+
6
+ import { proto2 } from "@bufbuild/protobuf";
7
+ import { BlueBatteryLevel, BlueBlacklistEntry, BlueEvent, BlueHardwareType, BlueLocalTimeSchedule, BlueLocalTimestamp } from "./BlueCore_pb.js";
8
+ import { BlueLockConfig, BlueLockStatus } from "./BlueLock_pb.js";
9
+
10
+ /**
11
+ * @generated from enum BlueOnlineMode
12
+ */
13
+ export const BlueOnlineMode = proto2.makeEnum(
14
+ "BlueOnlineMode",
15
+ [
16
+ {no: 0, name: "OfflineMode"},
17
+ {no: 1, name: "ManualWifi"},
18
+ {no: 2, name: "AlwaysOnWifi"},
19
+ {no: 3, name: "UseLan"},
20
+ ],
21
+ );
22
+
23
+ /**
24
+ * @generated from message BlueTimeOffsetPeriod
25
+ */
26
+ export const BlueTimeOffsetPeriod = proto2.makeMessageType(
27
+ "BlueTimeOffsetPeriod",
28
+ () => [
29
+ { no: 1, name: "epoch", kind: "scalar", T: 13 /* ScalarType.UINT32 */ },
30
+ { no: 2, name: "offset", kind: "scalar", T: 5 /* ScalarType.INT32 */ },
31
+ ],
32
+ );
33
+
34
+ /**
35
+ * @generated from message BlueBaseConfig
36
+ */
37
+ export const BlueBaseConfig = proto2.makeMessageType(
38
+ "BlueBaseConfig",
39
+ () => [
40
+ { no: 1, name: "timeOffsetPeriods", kind: "message", T: BlueTimeOffsetPeriod, repeated: true },
41
+ { no: 2, name: "autoCheckSystemStatus", kind: "scalar", T: 8 /* ScalarType.BOOL */, default: false },
42
+ ],
43
+ );
44
+
45
+ /**
46
+ * @generated from message BlueBleConfig
47
+ */
48
+ export const BlueBleConfig = proto2.makeMessageType(
49
+ "BlueBleConfig",
50
+ () => [
51
+ { no: 1, name: "isAdvertising", kind: "scalar", T: 8 /* ScalarType.BOOL */, default: true },
52
+ { no: 2, name: "advertisingSchedules", kind: "message", T: BlueLocalTimeSchedule, repeated: true },
53
+ { no: 3, name: "maxPowerAdvertisingSchedulesIndices", kind: "scalar", T: 13 /* ScalarType.UINT32 */, repeated: true },
54
+ { no: 4, name: "advertisingIntervalMs", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 500 },
55
+ { no: 5, name: "maxConnectionTimeoutMs", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 3000 },
56
+ { no: 6, name: "txPowerLevel", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 3 },
57
+ { no: 7, name: "advertisedTxPower1Meter", kind: "scalar", T: 5 /* ScalarType.INT32 */, default: -77 },
58
+ { no: 8, name: "isIBeaconAdvertisement", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
59
+ ],
60
+ );
61
+
62
+ /**
63
+ * @generated from message BlueOnlineConfig
64
+ */
65
+ export const BlueOnlineConfig = proto2.makeMessageType(
66
+ "BlueOnlineConfig",
67
+ () => [
68
+ { no: 1, name: "mode", kind: "enum", T: proto2.getEnumType(BlueOnlineMode), default: BlueOnlineMode.OfflineMode },
69
+ { no: 2, name: "connectSchedules", kind: "message", T: BlueLocalTimeSchedule, repeated: true },
70
+ { no: 3, name: "wifiSSID", kind: "scalar", T: 9 /* ScalarType.STRING */ },
71
+ { no: 4, name: "wifiPassword", kind: "scalar", T: 9 /* ScalarType.STRING */ },
72
+ { no: 5, name: "timeoutSec", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 30 },
73
+ ],
74
+ );
75
+
76
+ /**
77
+ * @generated from message BlueAccessConfig
78
+ */
79
+ export const BlueAccessConfig = proto2.makeMessageType(
80
+ "BlueAccessConfig",
81
+ () => [
82
+ { no: 1, name: "id", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 1 },
83
+ { no: 2, name: "siteId", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 1 },
84
+ { no: 3, name: "groupIds", kind: "scalar", T: 13 /* ScalarType.UINT32 */, repeated: true },
85
+ ],
86
+ );
87
+
88
+ /**
89
+ *
90
+ * -- Oss SecureId --
91
+ *
92
+ *
93
+ * @generated from message BlueOssConfig
94
+ */
95
+ export const BlueOssConfig = proto2.makeMessageType(
96
+ "BlueOssConfig",
97
+ () => [
98
+ { no: 1, name: "sidMifareAesKey", kind: "scalar", T: 12 /* ScalarType.BYTES */, default: new Uint8Array([0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x11, 0x00]) },
99
+ { no: 2, name: "sidMifareAid", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 16076801 },
100
+ { no: 3, name: "soUpdater", kind: "scalar", T: 8 /* ScalarType.BOOL */, default: false },
101
+ { no: 4, name: "soPushEvents", kind: "scalar", T: 8 /* ScalarType.BOOL */, default: false },
102
+ { no: 5, name: "soWritePendingEvents", kind: "scalar", T: 8 /* ScalarType.BOOL */, default: true },
103
+ { no: 6, name: "soUpdateFromBlacklist", kind: "scalar", T: 8 /* ScalarType.BOOL */, default: true },
104
+ { no: 7, name: "soMifareAesKey", kind: "scalar", T: 12 /* ScalarType.BYTES */, default: new Uint8Array([0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F]) },
105
+ { no: 8, name: "soMifareAid", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 16076800 },
106
+ ],
107
+ );
108
+
109
+ /**
110
+ * @generated from message BlueSystemConfig
111
+ */
112
+ export const BlueSystemConfig = proto2.makeMessageType(
113
+ "BlueSystemConfig",
114
+ () => [
115
+ { no: 1, name: "base", kind: "message", T: BlueBaseConfig },
116
+ { no: 2, name: "ble", kind: "message", T: BlueBleConfig },
117
+ { no: 3, name: "online", kind: "message", T: BlueOnlineConfig },
118
+ { no: 4, name: "access", kind: "message", T: BlueAccessConfig },
119
+ { no: 5, name: "oss", kind: "message", T: BlueOssConfig },
120
+ { no: 6, name: "lock", kind: "message", T: BlueLockConfig, opt: true },
121
+ ],
122
+ );
123
+
124
+ /**
125
+ * @generated from message BlueSystemSettings
126
+ */
127
+ export const BlueSystemSettings = proto2.makeMessageType(
128
+ "BlueSystemSettings",
129
+ () => [
130
+ { no: 1, name: "blacklistMaxEntriesCount", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 0 },
131
+ { no: 2, name: "blacklistEntriesCount", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 0 },
132
+ { no: 3, name: "eventLogMaxEntriesCount", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 0 },
133
+ { no: 4, name: "eventLogEntriesCount", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 0 },
134
+ { no: 5, name: "eventLogSequenceId", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 0 },
135
+ { no: 6, name: "eventLogIndex", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 0 },
136
+ { no: 7, name: "systemLogMaxEntriesCount", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 0 },
137
+ { no: 8, name: "systemLogEntriesCount", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 0 },
138
+ { no: 9, name: "systemLogSequenceId", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 0 },
139
+ { no: 10, name: "systemLogIndex", kind: "scalar", T: 13 /* ScalarType.UINT32 */, default: 0 },
140
+ { no: 11, name: "timeWasSet", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
141
+ { no: 12, name: "isBatteryLow", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
142
+ ],
143
+ );
144
+
145
+ /**
146
+ * @generated from message BlueSystemProvisioning
147
+ */
148
+ export const BlueSystemProvisioning = proto2.makeMessageType(
149
+ "BlueSystemProvisioning",
150
+ () => [
151
+ { no: 1, name: "hardwareType", kind: "enum", T: proto2.getEnumType(BlueHardwareType), default: BlueHardwareType.TestHardware },
152
+ { no: 2, name: "deviceId", kind: "scalar", T: 9 /* ScalarType.STRING */ },
153
+ { no: 3, name: "serialNumber", kind: "scalar", T: 9 /* ScalarType.STRING */, default: "00000000000000000000" },
154
+ { no: 4, name: "terminalPrivateKey", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
155
+ { no: 5, name: "signaturePublicKey", kind: "scalar", T: 12 /* ScalarType.BYTES */ },
156
+ ],
157
+ );
158
+
159
+ /**
160
+ * @generated from message BlueSystemStatus
161
+ */
162
+ export const BlueSystemStatus = proto2.makeMessageType(
163
+ "BlueSystemStatus",
164
+ () => [
165
+ { no: 1, name: "deviceId", kind: "scalar", T: 9 /* ScalarType.STRING */ },
166
+ { no: 2, name: "serialNumber", kind: "scalar", T: 9 /* ScalarType.STRING */ },
167
+ { no: 3, name: "hardwareType", kind: "enum", T: proto2.getEnumType(BlueHardwareType) },
168
+ { no: 4, name: "batteryLevel", kind: "enum", T: proto2.getEnumType(BlueBatteryLevel) },
169
+ { no: 5, name: "applicationVersion", kind: "scalar", T: 13 /* ScalarType.UINT32 */ },
170
+ { no: 6, name: "localTime", kind: "message", T: BlueLocalTimestamp },
171
+ { no: 7, name: "settings", kind: "message", T: BlueSystemSettings },
172
+ { no: 8, name: "blacklistEntriesCount", kind: "scalar", T: 13 /* ScalarType.UINT32 */ },
173
+ { no: 9, name: "eventLogEntriesCount", kind: "scalar", T: 13 /* ScalarType.UINT32 */ },
174
+ { no: 10, name: "eventLogSequenceId", kind: "scalar", T: 13 /* ScalarType.UINT32 */ },
175
+ { no: 11, name: "systemLogEntriesCount", kind: "scalar", T: 13 /* ScalarType.UINT32 */ },
176
+ { no: 12, name: "systemLogSequenceId", kind: "scalar", T: 13 /* ScalarType.UINT32 */ },
177
+ { no: 13, name: "lock", kind: "message", T: BlueLockStatus, opt: true },
178
+ ],
179
+ );
180
+
181
+ /**
182
+ * @generated from message BlueSystemLogQuery
183
+ */
184
+ export const BlueSystemLogQuery = proto2.makeMessageType(
185
+ "BlueSystemLogQuery",
186
+ () => [
187
+ { no: 1, name: "maxCount", kind: "scalar", T: 13 /* ScalarType.UINT32 */ },
188
+ { no: 2, name: "sequenceId", kind: "scalar", T: 13 /* ScalarType.UINT32 */, oneof: "start" },
189
+ { no: 3, name: "fromHead", kind: "scalar", T: 8 /* ScalarType.BOOL */, oneof: "start" },
190
+ ],
191
+ );
192
+
193
+ /**
194
+ * @generated from message BlueSystemLogEntry
195
+ */
196
+ export const BlueSystemLogEntry = proto2.makeMessageType(
197
+ "BlueSystemLogEntry",
198
+ () => [
199
+ { no: 1, name: "sequenceId", kind: "scalar", T: 13 /* ScalarType.UINT32 */ },
200
+ { no: 2, name: "time", kind: "message", T: BlueLocalTimestamp },
201
+ { no: 3, name: "severity", kind: "scalar", T: 13 /* ScalarType.UINT32 */ },
202
+ { no: 4, name: "line", kind: "scalar", T: 13 /* ScalarType.UINT32 */ },
203
+ { no: 5, name: "file", kind: "scalar", T: 9 /* ScalarType.STRING */ },
204
+ { no: 6, name: "message", kind: "scalar", T: 9 /* ScalarType.STRING */ },
205
+ ],
206
+ );
207
+
208
+ /**
209
+ * @generated from message BlueSystemLogResult
210
+ */
211
+ export const BlueSystemLogResult = proto2.makeMessageType(
212
+ "BlueSystemLogResult",
213
+ () => [
214
+ { no: 1, name: "entries", kind: "message", T: BlueSystemLogEntry, repeated: true },
215
+ ],
216
+ );
217
+
218
+ /**
219
+ * @generated from message BlueEventLogQuery
220
+ */
221
+ export const BlueEventLogQuery = proto2.makeMessageType(
222
+ "BlueEventLogQuery",
223
+ () => [
224
+ { no: 1, name: "maxCount", kind: "scalar", T: 13 /* ScalarType.UINT32 */ },
225
+ { no: 2, name: "sequenceId", kind: "scalar", T: 13 /* ScalarType.UINT32 */, oneof: "start" },
226
+ { no: 3, name: "fromHead", kind: "scalar", T: 8 /* ScalarType.BOOL */, oneof: "start" },
227
+ ],
228
+ );
229
+
230
+ /**
231
+ * @generated from message BlueEventLogResult
232
+ */
233
+ export const BlueEventLogResult = proto2.makeMessageType(
234
+ "BlueEventLogResult",
235
+ () => [
236
+ { no: 1, name: "events", kind: "message", T: BlueEvent, repeated: true },
237
+ ],
238
+ );
239
+
240
+ /**
241
+ * @generated from message BlueBlacklistEntries
242
+ */
243
+ export const BlueBlacklistEntries = proto2.makeMessageType(
244
+ "BlueBlacklistEntries",
245
+ () => [
246
+ { no: 1, name: "entries", kind: "message", T: BlueBlacklistEntry, repeated: true },
247
+ ],
248
+ );
249
+
@@ -0,0 +1,46 @@
1
+ import { createPrivateKey } from 'crypto'
2
+ import { getConfigValue, setConfigValue, deleteConfigValue } from '../shared/config.js'
3
+
4
+ export default async ({ identity, privateKey, remove }) => {
5
+ const configKey = `vendors.${identity}`
6
+ const hasVendor = getConfigValue(configKey, undefined)
7
+
8
+ if (remove) {
9
+ if (!hasVendor) {
10
+ throw new Error(`No vendor with identity ${identity} registered`)
11
+ }
12
+
13
+ deleteConfigValue(configKey)
14
+
15
+ console.log(`Successfully removed vendor with identity ${identity}`)
16
+
17
+ return
18
+ }
19
+
20
+ if (!privateKey) {
21
+ throw new Error('Missing valid private key parameter')
22
+ }
23
+
24
+ if (hasVendor) {
25
+ throw new Error(`There already is a vendor with identity ${identity} registered, remove it first`)
26
+ }
27
+
28
+ const privateKeyBuffer = Buffer.from(privateKey, 'base64')
29
+
30
+ // Try to create the key to validate it
31
+ try {
32
+ createPrivateKey({
33
+ key: privateKeyBuffer,
34
+ format: 'der',
35
+ type: 'pkcs8',
36
+ })
37
+ } catch (e) {
38
+ throw new Error('Invalid private key.')
39
+ }
40
+
41
+ setConfigValue(configKey, {
42
+ privateKey,
43
+ })
44
+
45
+ console.log(`Successfully registered new vendor with identity ${identity}`)
46
+ }
@@ -0,0 +1,18 @@
1
+ import { program, Option } from 'commander'
2
+
3
+ import action from './action.js'
4
+
5
+ program
6
+ .command('registerVendor')
7
+ .description('Register or remove a vendor')
8
+ .addOption(
9
+ new Option('--identity [identity]', 'The vendor identity to be registered or removed').makeOptionMandatory(true)
10
+ )
11
+ .addOption(
12
+ new Option(
13
+ '--privateKey [privateKey]',
14
+ 'The vendor`s private key to be registered in base64-encoded DER-format, only required if not removing'
15
+ )
16
+ )
17
+ .addOption(new Option('--remove', 'If set the vendor will be removed, otherwise it will be added'))
18
+ .action(action)
@@ -0,0 +1,25 @@
1
+ import axios from 'axios'
2
+
3
+ const apiUrl = 'https://api.dev.blue-id.com'
4
+
5
+ async function runAxiosCall(call) {
6
+ try {
7
+ return await call();
8
+ } catch (e) {
9
+ let errorText = ''
10
+ try {
11
+ errorText = JSON.stringify(e.response.data, null, 4)
12
+ } catch {
13
+ errorText = e.response ? e.response.toString() : ''
14
+ }
15
+ throw new Error(`Http Error (${e.code}): ${errorText}`)
16
+ }
17
+ }
18
+
19
+ export async function apiGet(path) {
20
+ return runAxiosCall(() => axios.get(`${apiUrl}${path}`))
21
+ }
22
+
23
+ export async function apiPost(path, body) {
24
+ return runAxiosCall(() => axios.post(`${apiUrl}${path}`, body))
25
+ }
@@ -0,0 +1,35 @@
1
+ import Configstore from 'configstore'
2
+
3
+ import packageInfo from './packageInfo.js'
4
+
5
+ let configInstance = null
6
+
7
+ const getConfig = () => {
8
+ if (!configInstance) {
9
+ configInstance = new Configstore(packageInfo().name)
10
+ }
11
+
12
+ return configInstance
13
+ }
14
+
15
+ export const getConfigValue = (key, defaultValue) => {
16
+ const config = getConfig()
17
+
18
+ if (!config.has(key)) {
19
+ return defaultValue
20
+ }
21
+
22
+ return config.get(key)
23
+ }
24
+
25
+ export const setConfigValue = (key, value) => {
26
+ const config = getConfig()
27
+
28
+ config.set(key, value)
29
+ }
30
+
31
+ export const deleteConfigValue = (key) => {
32
+ const config = getConfig()
33
+
34
+ config.delete(key)
35
+ }
@@ -0,0 +1,14 @@
1
+ import { createSign } from 'crypto'
2
+
3
+ export default function createSignature(message, privateKey, signatureFormat) {
4
+ const signer = createSign('sha256')
5
+ signer.update(message)
6
+
7
+ return signer.sign(
8
+ {
9
+ key: privateKey,
10
+ dsaEncoding: 'der',
11
+ },
12
+ signatureFormat
13
+ )
14
+ }
@@ -0,0 +1,8 @@
1
+ import packageInfo from './packageInfo.js'
2
+
3
+ export default () => {
4
+ const { version } = packageInfo()
5
+
6
+ // The first number is our Blue-Version
7
+ return Number.parseInt(version.split('.')[0], 10)
8
+ }
@@ -0,0 +1,25 @@
1
+ import { createPrivateKey } from 'crypto'
2
+
3
+ export default function loadPrivateKey(privateKeyData) {
4
+ if (typeof privateKeyData === 'string') {
5
+ if (privateKeyData.indexOf('-----BEGIN PRIVATE KEY-----') === 0) {
6
+ return createPrivateKey({
7
+ key: privateKeyData,
8
+ format: 'pem',
9
+ type: 'pkcs8',
10
+ })
11
+ }
12
+
13
+ return createPrivateKey({
14
+ key: Buffer.from(privateKeyData, 'base64'),
15
+ format: 'der',
16
+ type: 'pkcs8',
17
+ })
18
+ }
19
+
20
+ return createPrivateKey({
21
+ key: privateKeyData,
22
+ format: 'der',
23
+ type: 'pkcs8',
24
+ })
25
+ }
@@ -0,0 +1,46 @@
1
+ import path from 'path'
2
+ import fs from 'fs'
3
+
4
+ const bufferToCArray = (buffer) => {
5
+ const hexString = buffer.toString('hex')
6
+ const hexArray = hexString.match(/.{1,2}/g)
7
+ return hexArray.map((hex) => `0x${hex}`).join(', ')
8
+ }
9
+
10
+ const bufferToProtoArray = (buffer) => {
11
+ const hexString = buffer.toString('hex')
12
+ const hexArray = hexString.match(/.{1,2}/g)
13
+ return hexArray.map((hex) => `\\x${hex}`).join('')
14
+ }
15
+
16
+ export const outputFormats = ['hex', 'cpphex', 'protohex', 'base64']
17
+
18
+ export default (buffer, format, filename) => {
19
+ let result = null
20
+
21
+ switch (format) {
22
+ case 'hex':
23
+ result = buffer.toString('hex')
24
+ break
25
+ case 'cpphex':
26
+ result = bufferToCArray(buffer)
27
+ break
28
+ case 'protohex':
29
+ result = bufferToProtoArray(buffer)
30
+ break
31
+ case 'base64':
32
+ result = buffer.toString('base64')
33
+ break
34
+ default:
35
+ {
36
+ const filepath = path.resolve(filename)
37
+ fs.writeFileSync(filepath, buffer)
38
+ result = `Written to file <${filepath}>`
39
+ }
40
+ break
41
+ }
42
+
43
+ console.log(`(${format} with ${buffer.length.toString()} bytes)\n`)
44
+ console.log(result)
45
+ console.log('\n')
46
+ }
@@ -0,0 +1,11 @@
1
+ import fs from 'fs'
2
+
3
+ let packageJSON = null
4
+
5
+ export default () => {
6
+ if (!packageJSON) {
7
+ packageJSON = JSON.parse(fs.readFileSync(new URL('../../package.json', import.meta.url)))
8
+ }
9
+
10
+ return packageJSON
11
+ }
@@ -0,0 +1,25 @@
1
+ import chalk from 'chalk'
2
+ import boxen from 'boxen'
3
+
4
+ import getBlueVersion from './getBlueVersion.js'
5
+
6
+ export default () => {
7
+ const lines = [
8
+ `BlueID Tools`,
9
+ `BLUEVERSION: ${getBlueVersion()}`,
10
+ `Copyright ${new Date().getFullYear()} BlueID GmbH.`,
11
+ ``,
12
+ `Type --help for instructions.`,
13
+ ]
14
+
15
+ console.log(
16
+ boxen(chalk.blue(lines.join('\n')), {
17
+ padding: 2,
18
+ backgroundColor: 'white',
19
+ borderColor: 'blue',
20
+ borderStyle: 'double',
21
+ })
22
+ )
23
+
24
+ console.log('\n')
25
+ }
@@ -0,0 +1,20 @@
1
+ import outputBuffer from '../shared/outputBuffer.js'
2
+
3
+ export default async ({ uuid, format }) => {
4
+ if (!uuid) throw new Error('Missing uuid parameter')
5
+ if (!format) throw new Error('Missing format parameter')
6
+
7
+ const bytes = []
8
+
9
+ uuid.split('-').forEach((number, index) => {
10
+ const bytesInChar = index < 3 ? number.match(/.{1,2}/g) : number.match(/.{1,2}/g)
11
+
12
+ bytesInChar.forEach((byte) => {
13
+ bytes.push(parseInt(byte, 16))
14
+ })
15
+ })
16
+
17
+ const buffer = Buffer.from(bytes)
18
+
19
+ outputBuffer(buffer, format, null)
20
+ }
@@ -0,0 +1,12 @@
1
+ import { program, Option } from 'commander'
2
+
3
+ import { outputFormats } from '../shared/outputBuffer.js'
4
+
5
+ import action from './action.js'
6
+
7
+ program
8
+ .command('uuidToBytes')
9
+ .description('Convert an UUID String into an byte array')
10
+ .addOption(new Option('--uuid [uuid]', 'The UUID to be converted'))
11
+ .addOption(new Option('--format [format]', 'The output format to be used').choices(outputFormats))
12
+ .action(action)