matterbridge 3.3.3-dev-20251018-66ae7a4 → 3.3.3

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.
Files changed (291) hide show
  1. package/CHANGELOG.md +1 -1
  2. package/dist/broadcastServer.d.ts +105 -0
  3. package/dist/broadcastServer.d.ts.map +1 -0
  4. package/dist/broadcastServer.js +86 -1
  5. package/dist/broadcastServer.js.map +1 -0
  6. package/dist/broadcastServerTypes.d.ts +719 -0
  7. package/dist/broadcastServerTypes.d.ts.map +1 -0
  8. package/dist/broadcastServerTypes.js +24 -0
  9. package/dist/broadcastServerTypes.js.map +1 -0
  10. package/dist/cli.d.ts +26 -0
  11. package/dist/cli.d.ts.map +1 -0
  12. package/dist/cli.js +135 -5
  13. package/dist/cli.js.map +1 -0
  14. package/dist/cliEmitter.d.ts +50 -0
  15. package/dist/cliEmitter.d.ts.map +1 -0
  16. package/dist/cliEmitter.js +37 -0
  17. package/dist/cliEmitter.js.map +1 -0
  18. package/dist/cliHistory.d.ts +74 -0
  19. package/dist/cliHistory.d.ts.map +1 -0
  20. package/dist/cliHistory.js +44 -0
  21. package/dist/cliHistory.js.map +1 -0
  22. package/dist/clusters/export.d.ts +2 -0
  23. package/dist/clusters/export.d.ts.map +1 -0
  24. package/dist/clusters/export.js +2 -0
  25. package/dist/clusters/export.js.map +1 -0
  26. package/dist/defaultConfigSchema.d.ts +28 -0
  27. package/dist/defaultConfigSchema.d.ts.map +1 -0
  28. package/dist/defaultConfigSchema.js +24 -0
  29. package/dist/defaultConfigSchema.js.map +1 -0
  30. package/dist/deviceManager.d.ts +117 -0
  31. package/dist/deviceManager.d.ts.map +1 -0
  32. package/dist/deviceManager.js +124 -1
  33. package/dist/deviceManager.js.map +1 -0
  34. package/dist/devices/airConditioner.d.ts +98 -0
  35. package/dist/devices/airConditioner.d.ts.map +1 -0
  36. package/dist/devices/airConditioner.js +57 -0
  37. package/dist/devices/airConditioner.js.map +1 -0
  38. package/dist/devices/batteryStorage.d.ts +48 -0
  39. package/dist/devices/batteryStorage.d.ts.map +1 -0
  40. package/dist/devices/batteryStorage.js +48 -1
  41. package/dist/devices/batteryStorage.js.map +1 -0
  42. package/dist/devices/cooktop.d.ts +60 -0
  43. package/dist/devices/cooktop.d.ts.map +1 -0
  44. package/dist/devices/cooktop.js +55 -0
  45. package/dist/devices/cooktop.js.map +1 -0
  46. package/dist/devices/dishwasher.d.ts +71 -0
  47. package/dist/devices/dishwasher.d.ts.map +1 -0
  48. package/dist/devices/dishwasher.js +57 -0
  49. package/dist/devices/dishwasher.js.map +1 -0
  50. package/dist/devices/evse.d.ts +75 -0
  51. package/dist/devices/evse.d.ts.map +1 -0
  52. package/dist/devices/evse.js +74 -10
  53. package/dist/devices/evse.js.map +1 -0
  54. package/dist/devices/export.d.ts +17 -0
  55. package/dist/devices/export.d.ts.map +1 -0
  56. package/dist/devices/export.js +5 -0
  57. package/dist/devices/export.js.map +1 -0
  58. package/dist/devices/extractorHood.d.ts +46 -0
  59. package/dist/devices/extractorHood.d.ts.map +1 -0
  60. package/dist/devices/extractorHood.js +42 -0
  61. package/dist/devices/extractorHood.js.map +1 -0
  62. package/dist/devices/heatPump.d.ts +47 -0
  63. package/dist/devices/heatPump.d.ts.map +1 -0
  64. package/dist/devices/heatPump.js +50 -2
  65. package/dist/devices/heatPump.js.map +1 -0
  66. package/dist/devices/laundryDryer.d.ts +67 -0
  67. package/dist/devices/laundryDryer.d.ts.map +1 -0
  68. package/dist/devices/laundryDryer.js +62 -3
  69. package/dist/devices/laundryDryer.js.map +1 -0
  70. package/dist/devices/laundryWasher.d.ts +81 -0
  71. package/dist/devices/laundryWasher.d.ts.map +1 -0
  72. package/dist/devices/laundryWasher.js +70 -4
  73. package/dist/devices/laundryWasher.js.map +1 -0
  74. package/dist/devices/microwaveOven.d.ts +168 -0
  75. package/dist/devices/microwaveOven.d.ts.map +1 -0
  76. package/dist/devices/microwaveOven.js +88 -5
  77. package/dist/devices/microwaveOven.js.map +1 -0
  78. package/dist/devices/oven.d.ts +105 -0
  79. package/dist/devices/oven.d.ts.map +1 -0
  80. package/dist/devices/oven.js +85 -0
  81. package/dist/devices/oven.js.map +1 -0
  82. package/dist/devices/refrigerator.d.ts +118 -0
  83. package/dist/devices/refrigerator.d.ts.map +1 -0
  84. package/dist/devices/refrigerator.js +102 -0
  85. package/dist/devices/refrigerator.js.map +1 -0
  86. package/dist/devices/roboticVacuumCleaner.d.ts +112 -0
  87. package/dist/devices/roboticVacuumCleaner.d.ts.map +1 -0
  88. package/dist/devices/roboticVacuumCleaner.js +100 -9
  89. package/dist/devices/roboticVacuumCleaner.js.map +1 -0
  90. package/dist/devices/solarPower.d.ts +40 -0
  91. package/dist/devices/solarPower.d.ts.map +1 -0
  92. package/dist/devices/solarPower.js +38 -0
  93. package/dist/devices/solarPower.js.map +1 -0
  94. package/dist/devices/speaker.d.ts +87 -0
  95. package/dist/devices/speaker.d.ts.map +1 -0
  96. package/dist/devices/speaker.js +84 -0
  97. package/dist/devices/speaker.js.map +1 -0
  98. package/dist/devices/temperatureControl.d.ts +166 -0
  99. package/dist/devices/temperatureControl.d.ts.map +1 -0
  100. package/dist/devices/temperatureControl.js +25 -3
  101. package/dist/devices/temperatureControl.js.map +1 -0
  102. package/dist/devices/waterHeater.d.ts +111 -0
  103. package/dist/devices/waterHeater.d.ts.map +1 -0
  104. package/dist/devices/waterHeater.js +82 -2
  105. package/dist/devices/waterHeater.js.map +1 -0
  106. package/dist/dgram/coap.d.ts +205 -0
  107. package/dist/dgram/coap.d.ts.map +1 -0
  108. package/dist/dgram/coap.js +126 -13
  109. package/dist/dgram/coap.js.map +1 -0
  110. package/dist/dgram/dgram.d.ts +141 -0
  111. package/dist/dgram/dgram.d.ts.map +1 -0
  112. package/dist/dgram/dgram.js +114 -2
  113. package/dist/dgram/dgram.js.map +1 -0
  114. package/dist/dgram/mb_coap.d.ts +24 -0
  115. package/dist/dgram/mb_coap.d.ts.map +1 -0
  116. package/dist/dgram/mb_coap.js +41 -3
  117. package/dist/dgram/mb_coap.js.map +1 -0
  118. package/dist/dgram/mb_mdns.d.ts +24 -0
  119. package/dist/dgram/mb_mdns.d.ts.map +1 -0
  120. package/dist/dgram/mb_mdns.js +80 -15
  121. package/dist/dgram/mb_mdns.js.map +1 -0
  122. package/dist/dgram/mdns.d.ts +290 -0
  123. package/dist/dgram/mdns.d.ts.map +1 -0
  124. package/dist/dgram/mdns.js +299 -137
  125. package/dist/dgram/mdns.js.map +1 -0
  126. package/dist/dgram/multicast.d.ts +67 -0
  127. package/dist/dgram/multicast.d.ts.map +1 -0
  128. package/dist/dgram/multicast.js +62 -1
  129. package/dist/dgram/multicast.js.map +1 -0
  130. package/dist/dgram/unicast.d.ts +56 -0
  131. package/dist/dgram/unicast.d.ts.map +1 -0
  132. package/dist/dgram/unicast.js +54 -0
  133. package/dist/dgram/unicast.js.map +1 -0
  134. package/dist/frontend.d.ts +235 -0
  135. package/dist/frontend.d.ts.map +1 -0
  136. package/dist/frontend.js +413 -34
  137. package/dist/frontend.js.map +1 -0
  138. package/dist/frontendTypes.d.ts +529 -0
  139. package/dist/frontendTypes.d.ts.map +1 -0
  140. package/dist/frontendTypes.js +45 -0
  141. package/dist/frontendTypes.js.map +1 -0
  142. package/dist/helpers.d.ts +48 -0
  143. package/dist/helpers.d.ts.map +1 -0
  144. package/dist/helpers.js +53 -0
  145. package/dist/helpers.js.map +1 -0
  146. package/dist/index.d.ts +33 -0
  147. package/dist/index.d.ts.map +1 -0
  148. package/dist/index.js +25 -0
  149. package/dist/index.js.map +1 -0
  150. package/dist/logger/export.d.ts +2 -0
  151. package/dist/logger/export.d.ts.map +1 -0
  152. package/dist/logger/export.js +1 -0
  153. package/dist/logger/export.js.map +1 -0
  154. package/dist/matter/behaviors.d.ts +2 -0
  155. package/dist/matter/behaviors.d.ts.map +1 -0
  156. package/dist/matter/behaviors.js +2 -0
  157. package/dist/matter/behaviors.js.map +1 -0
  158. package/dist/matter/clusters.d.ts +2 -0
  159. package/dist/matter/clusters.d.ts.map +1 -0
  160. package/dist/matter/clusters.js +2 -0
  161. package/dist/matter/clusters.js.map +1 -0
  162. package/dist/matter/devices.d.ts +2 -0
  163. package/dist/matter/devices.d.ts.map +1 -0
  164. package/dist/matter/devices.js +2 -0
  165. package/dist/matter/devices.js.map +1 -0
  166. package/dist/matter/endpoints.d.ts +2 -0
  167. package/dist/matter/endpoints.d.ts.map +1 -0
  168. package/dist/matter/endpoints.js +2 -0
  169. package/dist/matter/endpoints.js.map +1 -0
  170. package/dist/matter/export.d.ts +5 -0
  171. package/dist/matter/export.d.ts.map +1 -0
  172. package/dist/matter/export.js +3 -0
  173. package/dist/matter/export.js.map +1 -0
  174. package/dist/matter/types.d.ts +3 -0
  175. package/dist/matter/types.d.ts.map +1 -0
  176. package/dist/matter/types.js +3 -0
  177. package/dist/matter/types.js.map +1 -0
  178. package/dist/matterbridge.d.ts +469 -0
  179. package/dist/matterbridge.d.ts.map +1 -0
  180. package/dist/matterbridge.js +795 -45
  181. package/dist/matterbridge.js.map +1 -0
  182. package/dist/matterbridgeAccessoryPlatform.d.ts +42 -0
  183. package/dist/matterbridgeAccessoryPlatform.d.ts.map +1 -0
  184. package/dist/matterbridgeAccessoryPlatform.js +36 -0
  185. package/dist/matterbridgeAccessoryPlatform.js.map +1 -0
  186. package/dist/matterbridgeBehaviors.d.ts +2399 -0
  187. package/dist/matterbridgeBehaviors.d.ts.map +1 -0
  188. package/dist/matterbridgeBehaviors.js +71 -5
  189. package/dist/matterbridgeBehaviors.js.map +1 -0
  190. package/dist/matterbridgeDeviceTypes.d.ts +761 -0
  191. package/dist/matterbridgeDeviceTypes.d.ts.map +1 -0
  192. package/dist/matterbridgeDeviceTypes.js +630 -17
  193. package/dist/matterbridgeDeviceTypes.js.map +1 -0
  194. package/dist/matterbridgeDynamicPlatform.d.ts +42 -0
  195. package/dist/matterbridgeDynamicPlatform.d.ts.map +1 -0
  196. package/dist/matterbridgeDynamicPlatform.js +36 -0
  197. package/dist/matterbridgeDynamicPlatform.js.map +1 -0
  198. package/dist/matterbridgeEndpoint.d.ts +1545 -0
  199. package/dist/matterbridgeEndpoint.d.ts.map +1 -0
  200. package/dist/matterbridgeEndpoint.js +1412 -58
  201. package/dist/matterbridgeEndpoint.js.map +1 -0
  202. package/dist/matterbridgeEndpointHelpers.d.ts +560 -0
  203. package/dist/matterbridgeEndpointHelpers.d.ts.map +1 -0
  204. package/dist/matterbridgeEndpointHelpers.js +368 -10
  205. package/dist/matterbridgeEndpointHelpers.js.map +1 -0
  206. package/dist/matterbridgePlatform.d.ts +402 -0
  207. package/dist/matterbridgePlatform.d.ts.map +1 -0
  208. package/dist/matterbridgePlatform.js +341 -1
  209. package/dist/matterbridgePlatform.js.map +1 -0
  210. package/dist/matterbridgeTypes.d.ts +209 -0
  211. package/dist/matterbridgeTypes.d.ts.map +1 -0
  212. package/dist/matterbridgeTypes.js +26 -0
  213. package/dist/matterbridgeTypes.js.map +1 -0
  214. package/dist/pluginManager.d.ts +353 -0
  215. package/dist/pluginManager.d.ts.map +1 -0
  216. package/dist/pluginManager.js +325 -3
  217. package/dist/pluginManager.js.map +1 -0
  218. package/dist/shelly.d.ts +174 -0
  219. package/dist/shelly.d.ts.map +1 -0
  220. package/dist/shelly.js +168 -7
  221. package/dist/shelly.js.map +1 -0
  222. package/dist/storage/export.d.ts +2 -0
  223. package/dist/storage/export.d.ts.map +1 -0
  224. package/dist/storage/export.js +1 -0
  225. package/dist/storage/export.js.map +1 -0
  226. package/dist/update.d.ts +75 -0
  227. package/dist/update.d.ts.map +1 -0
  228. package/dist/update.js +69 -0
  229. package/dist/update.js.map +1 -0
  230. package/dist/utils/colorUtils.d.ts +99 -0
  231. package/dist/utils/colorUtils.d.ts.map +1 -0
  232. package/dist/utils/colorUtils.js +97 -2
  233. package/dist/utils/colorUtils.js.map +1 -0
  234. package/dist/utils/commandLine.d.ts +59 -0
  235. package/dist/utils/commandLine.d.ts.map +1 -0
  236. package/dist/utils/commandLine.js +54 -0
  237. package/dist/utils/commandLine.js.map +1 -0
  238. package/dist/utils/copyDirectory.d.ts +33 -0
  239. package/dist/utils/copyDirectory.d.ts.map +1 -0
  240. package/dist/utils/copyDirectory.js +38 -1
  241. package/dist/utils/copyDirectory.js.map +1 -0
  242. package/dist/utils/createDirectory.d.ts +34 -0
  243. package/dist/utils/createDirectory.d.ts.map +1 -0
  244. package/dist/utils/createDirectory.js +33 -0
  245. package/dist/utils/createDirectory.js.map +1 -0
  246. package/dist/utils/createZip.d.ts +39 -0
  247. package/dist/utils/createZip.d.ts.map +1 -0
  248. package/dist/utils/createZip.js +47 -2
  249. package/dist/utils/createZip.js.map +1 -0
  250. package/dist/utils/deepCopy.d.ts +32 -0
  251. package/dist/utils/deepCopy.d.ts.map +1 -0
  252. package/dist/utils/deepCopy.js +39 -0
  253. package/dist/utils/deepCopy.js.map +1 -0
  254. package/dist/utils/deepEqual.d.ts +54 -0
  255. package/dist/utils/deepEqual.d.ts.map +1 -0
  256. package/dist/utils/deepEqual.js +72 -1
  257. package/dist/utils/deepEqual.js.map +1 -0
  258. package/dist/utils/error.d.ts +44 -0
  259. package/dist/utils/error.d.ts.map +1 -0
  260. package/dist/utils/error.js +41 -0
  261. package/dist/utils/error.js.map +1 -0
  262. package/dist/utils/export.d.ts +13 -0
  263. package/dist/utils/export.d.ts.map +1 -0
  264. package/dist/utils/export.js +1 -0
  265. package/dist/utils/export.js.map +1 -0
  266. package/dist/utils/hex.d.ts +89 -0
  267. package/dist/utils/hex.d.ts.map +1 -0
  268. package/dist/utils/hex.js +124 -0
  269. package/dist/utils/hex.js.map +1 -0
  270. package/dist/utils/isvalid.d.ts +103 -0
  271. package/dist/utils/isvalid.d.ts.map +1 -0
  272. package/dist/utils/isvalid.js +101 -0
  273. package/dist/utils/isvalid.js.map +1 -0
  274. package/dist/utils/jestHelpers.d.ts +137 -0
  275. package/dist/utils/jestHelpers.d.ts.map +1 -0
  276. package/dist/utils/jestHelpers.js +153 -3
  277. package/dist/utils/jestHelpers.js.map +1 -0
  278. package/dist/utils/network.d.ts +115 -0
  279. package/dist/utils/network.d.ts.map +1 -0
  280. package/dist/utils/network.js +108 -5
  281. package/dist/utils/network.js.map +1 -0
  282. package/dist/utils/spawn.d.ts +35 -0
  283. package/dist/utils/spawn.d.ts.map +1 -0
  284. package/dist/utils/spawn.js +71 -0
  285. package/dist/utils/spawn.js.map +1 -0
  286. package/dist/utils/wait.d.ts +54 -0
  287. package/dist/utils/wait.d.ts.map +1 -0
  288. package/dist/utils/wait.js +60 -8
  289. package/dist/utils/wait.js.map +1 -0
  290. package/npm-shrinkwrap.json +2 -2
  291. package/package.json +2 -1
@@ -1,23 +1,89 @@
1
+ /* eslint-disable @typescript-eslint/no-unused-vars */
2
+ /**
3
+ * This file contains the deepEqual function.
4
+ *
5
+ * @file deepEqual.ts
6
+ * @author Luca Liguori
7
+ * @created 2025-02-16
8
+ * @version 1.0.0
9
+ * @license Apache-2.0
10
+ *
11
+ * Copyright 2025, 2026, 2027 Luca Liguori.
12
+ *
13
+ * Licensed under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License.
15
+ * You may obtain a copy of the License at
16
+ *
17
+ * http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+ /* eslint-disable @typescript-eslint/no-explicit-any */
26
+ /**
27
+ * Performs a deep comparison between two values to determine if they are equivalent.
28
+ * This comparison includes primitive types, arrays, and objects, allowing for optional
29
+ * exclusion of specific properties from the comparison in objects.
30
+ *
31
+ * @param {any} a The first value to compare.
32
+ * @param {any} b The second value to compare.
33
+ * @param {string[]} [excludeProperties] An array of property names to exclude from the comparison in objects.
34
+ * @returns {boolean} True if the values are deeply equal, excluding any specified properties; otherwise, false.
35
+ *
36
+ * Note: This function utilizes recursion for deep comparison of nested structures and includes a debugging
37
+ * mechanism that can be toggled on or off for detailed comparison logging. It is important to ensure that
38
+ * objects do not contain circular references when enabling debug logging to avoid infinite loops.
39
+ *
40
+ * Example usage:
41
+ * ```
42
+ * const obj1 = { a: 1, b: { c: 2 } };
43
+ * const obj2 = { a: 1, b: { c: 2 } };
44
+ * console.log(deepEqual(obj1, obj2)); // true
45
+ *
46
+ * const arr1 = [1, 2, [3, 4]];
47
+ * const arr2 = [1, 2, [3, 4]];
48
+ * console.log(deepEqual(arr1, arr2)); // true
49
+ *
50
+ * const obj3 = { a: 1, b: { c: 2, d: 3 } };
51
+ * const obj4 = { a: 1, b: { c: 2 } };
52
+ * console.log(deepEqual(obj3, obj4, ['d'])); // true, excluding property 'd' from comparison
53
+ * ```
54
+ */
1
55
  export function deepEqual(a, b, excludeProperties = []) {
56
+ // Toggle debugging on or off easily
57
+ // const debug = false;
58
+ // Helper function for conditional logging
2
59
  const debugLog = (...messages) => {
60
+ // if (debug) {
61
+ // console.log(...messages);
62
+ // }
3
63
  };
64
+ // If both are the same instance, return true (handles primitives and same object references)
4
65
  if (a === b) {
5
66
  return true;
6
67
  }
68
+ // If types are different, return false
7
69
  if (typeof a !== typeof b) {
8
70
  debugLog(`deepEqual false for typeof a: ${typeof a} typeof b: ${typeof b}`);
9
71
  return false;
10
72
  }
73
+ // If one of them is null (and we know they are not equal from the first check), return false
11
74
  if (a == null || b == null) {
12
75
  debugLog('deepEqual false for == null');
13
76
  return false;
14
77
  }
78
+ // Handle Dates compare by timestamp
15
79
  if (a instanceof Date && b instanceof Date) {
16
80
  return a.getTime() === b.getTime();
17
81
  }
82
+ // Handle Regexps compare by their source & flags
18
83
  if (a instanceof RegExp && b instanceof RegExp) {
19
84
  return a.source === b.source && a.flags === b.flags;
20
85
  }
86
+ // Handle Arrays
21
87
  if (Array.isArray(a) && Array.isArray(b)) {
22
88
  if (a.length !== b.length) {
23
89
  debugLog(`deepEqual false for array a.length(${a.length}) !== b.length(${b.length})`);
@@ -33,26 +99,31 @@ export function deepEqual(a, b, excludeProperties = []) {
33
99
  }
34
100
  return true;
35
101
  }
102
+ // Handle Objects (and exclude null, functions, and arrays)
36
103
  if (typeof a === 'object' && typeof b === 'object') {
37
104
  const aProps = Object.getOwnPropertyNames(a).filter((prop) => !excludeProperties.includes(prop));
38
105
  const bProps = Object.getOwnPropertyNames(b).filter((prop) => !excludeProperties.includes(prop));
106
+ // If their property lengths are different, they're different objects
39
107
  if (aProps.length !== bProps.length) {
40
108
  debugLog(`deepEqual false for aProps.length(${aProps.length}) !== bProps.length(${bProps.length})`);
41
109
  debugLog(`- aProps.length(${aProps.length}):`, aProps);
42
110
  debugLog(`- bProps.length(${bProps.length}):`, bProps);
43
111
  return false;
44
112
  }
113
+ // Check each property in 'a' to see if it's in 'b' and if it's equal (deep check)
45
114
  for (const prop of aProps) {
46
115
  if (!Object.prototype.hasOwnProperty.call(b, prop)) {
47
116
  debugLog(`deepEqual false for !b.hasOwnProperty(${prop})`);
48
117
  return false;
49
118
  }
50
119
  if (!deepEqual(a[prop], b[prop], excludeProperties)) {
51
- debugLog(`deepEqual false for !deepEqual(a[${prop}], b[${prop}])`);
120
+ debugLog(`deepEqual false for !deepEqual(a[${prop}], b[${prop}])` /* , a[prop], b[prop]*/);
52
121
  return false;
53
122
  }
54
123
  }
55
124
  return true;
56
125
  }
126
+ // If none of the above, the objects are not equal
57
127
  return false;
58
128
  }
129
+ //# sourceMappingURL=deepEqual.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deepEqual.js","sourceRoot":"","sources":["../../src/utils/deepEqual.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,uDAAuD;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,SAAS,CAAC,CAAM,EAAE,CAAM,EAAE,oBAA8B,EAAE;IACxE,oCAAoC;I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CAAC;YACvD,QAAQ,CAAC,mBAAmB,MAAM,CAAC,MAAM,IAAI,EAAE,MAAM,CAAC,CAAC;YACvD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,kFAAkF;QAClF,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;YAC1B,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC,EAAE,CAAC;gBACnD,QAAQ,CAAC,yCAAyC,IAAI,GAAG,CAAC,CAAC;gBAC3D,OAAO,KAAK,CAAC;YACf,CAAC;YACD,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,iBAAiB,CAAC,EAAE,CAAC;gBACpD,QAAQ,CAAC,oCAAoC,IAAI,QAAQ,IAAI,IAAI,CAAC,uBAAuB,CAAC,CAAC;gBAC3F,OAAO,KAAK,CAAC;YACf,CAAC;QACH,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,kDAAkD;IAClD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * This file contains the error functions.
3
+ *
4
+ * @file error.ts
5
+ * @author Luca Liguori
6
+ * @created 2025-07-17
7
+ * @version 1.0.0
8
+ * @license Apache-2.0
9
+ *
10
+ * Copyright 2025, 2026, 2027 Luca Liguori.
11
+ *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+ import type { AnsiLogger } from 'node-ansi-logger';
25
+ /**
26
+ * Logs an error message using the provided AnsiLogger instance.
27
+ *
28
+ * @param {AnsiLogger} log - The AnsiLogger instance to use for logging.
29
+ * @param {string} message - The error message to log.
30
+ * @param {unknown} error - The error object or value to log. If it's an Error instance,
31
+ * its message and stack trace will be included in the log.
32
+ */
33
+ export declare function logError(log: AnsiLogger, message: string, error: unknown): void;
34
+ /**
35
+ * Logs an error message using the provided AnsiLogger instance with detailed inspection.
36
+ * Uses util.inspect to get a detailed view of the error with a stack depth of 10 levels.
37
+ * If the error is an Error instance, it also includes the error message.
38
+ *
39
+ * @param {AnsiLogger} log - The AnsiLogger instance to use for logging.
40
+ * @param {string} message - The error message to log.
41
+ * @param {unknown} error - The error object or value to log. Will be inspected with depth 10.
42
+ */
43
+ export declare function inspectError(log: AnsiLogger, message: string, error: unknown): void;
44
+ //# sourceMappingURL=error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.d.ts","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAE/E;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI,CAInF"}
@@ -1,9 +1,50 @@
1
+ /**
2
+ * This file contains the error functions.
3
+ *
4
+ * @file error.ts
5
+ * @author Luca Liguori
6
+ * @created 2025-07-17
7
+ * @version 1.0.0
8
+ * @license Apache-2.0
9
+ *
10
+ * Copyright 2025, 2026, 2027 Luca Liguori.
11
+ *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
1
24
  import { inspect } from 'node:util';
25
+ /**
26
+ * Logs an error message using the provided AnsiLogger instance.
27
+ *
28
+ * @param {AnsiLogger} log - The AnsiLogger instance to use for logging.
29
+ * @param {string} message - The error message to log.
30
+ * @param {unknown} error - The error object or value to log. If it's an Error instance,
31
+ * its message and stack trace will be included in the log.
32
+ */
2
33
  export function logError(log, message, error) {
3
34
  log.error(`${message}: ${error instanceof Error ? error.message + '\nStack:\n' + error.stack : error}`);
4
35
  }
36
+ /**
37
+ * Logs an error message using the provided AnsiLogger instance with detailed inspection.
38
+ * Uses util.inspect to get a detailed view of the error with a stack depth of 10 levels.
39
+ * If the error is an Error instance, it also includes the error message.
40
+ *
41
+ * @param {AnsiLogger} log - The AnsiLogger instance to use for logging.
42
+ * @param {string} message - The error message to log.
43
+ * @param {unknown} error - The error object or value to log. Will be inspected with depth 10.
44
+ */
5
45
  export function inspectError(log, message, error) {
6
46
  const errorMessage = error instanceof Error ? `${error.message}\n` : '';
7
47
  const inspectedError = inspect(error, { depth: 10, colors: true, showHidden: false });
8
48
  log.error(`${message}: ${errorMessage}${inspectedError}`);
9
49
  }
50
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/utils/error.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAIpC;;;;;;;GAOG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAe,EAAE,OAAe,EAAE,KAAc;IACvE,GAAG,CAAC,KAAK,CAAC,GAAG,OAAO,KAAK,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,GAAG,YAAY,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;AAC1G,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,YAAY,CAAC,GAAe,EAAE,OAAe,EAAE,KAAc;IAC3E,MAAM,YAAY,GAAG,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IACxE,MAAM,cAAc,GAAG,OAAO,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,CAAC,CAAC;IACtF,GAAG,CAAC,KAAK,CAAC,GAAG,OAAO,KAAK,YAAY,GAAG,cAAc,EAAE,CAAC,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,13 @@
1
+ export * from './network.js';
2
+ export * from './commandLine.js';
3
+ export * from './isvalid.js';
4
+ export * from './colorUtils.js';
5
+ export * from './deepCopy.js';
6
+ export * from './deepEqual.js';
7
+ export * from './copyDirectory.js';
8
+ export * from './createDirectory.js';
9
+ export * from './createZip.js';
10
+ export * from './wait.js';
11
+ export * from './hex.js';
12
+ export * from './error.js';
13
+ //# sourceMappingURL=export.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../src/utils/export.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
@@ -10,3 +10,4 @@ export * from './createZip.js';
10
10
  export * from './wait.js';
11
11
  export * from './hex.js';
12
12
  export * from './error.js';
13
+ //# sourceMappingURL=export.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.js","sourceRoot":"","sources":["../../src/utils/export.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,eAAe,CAAC;AAC9B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,WAAW,CAAC;AAC1B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC"}
@@ -0,0 +1,89 @@
1
+ /**
2
+ * This file contains the hex functions.
3
+ *
4
+ * @file hex.ts
5
+ * @author Luca Liguori
6
+ * @created 2025-05-06
7
+ * @version 1.0.0
8
+ * @license Apache-2.0
9
+ *
10
+ * Copyright 2025, 2026, 2027 Luca Liguori.
11
+ *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+ /**
25
+ * Converts an ArrayBuffer or Uint8Array to a hexadecimal string.
26
+ *
27
+ * Accepts any {ArrayBufferLike} input: a raw ArrayBuffer (binary data storage) or
28
+ * a Uint8Array (TypedArray view over an ArrayBuffer). While an ArrayBuffer holds
29
+ * the raw memory, a Uint8Array is a typed view into that memory, letting you access
30
+ * its bytes directly. This function normalizes both by creating a Uint8Array view
31
+ * before conversion.
32
+ *
33
+ * @param {ArrayBufferLike} buffer - The buffer or typed-array view to convert.
34
+ * @returns {string} A lowercase hex string representation of the buffer's bytes.
35
+ *
36
+ * @throws {TypeError} If the input is not an ArrayBuffer or ArrayBufferView.
37
+ */
38
+ export declare function bufferToHex(buffer: ArrayBufferLike): string;
39
+ /**
40
+ * Converts a hexadecimal string to a Uint8Array.
41
+ *
42
+ * @param {string} hex - The hex string to convert. Can include uppercase or lowercase characters.
43
+ * @returns {Uint8Array} A Uint8Array representing the corresponding binary data.
44
+ *
45
+ * @throws {TypeError} If the input is not a string.
46
+ * @throws {Error} If the input length is odd or contains non-hex characters.
47
+ */
48
+ export declare function hexToBuffer(hex: string): Uint8Array;
49
+ /**
50
+ * Converts a PEM (Privacy-Enhanced Mail) formatted string to a Uint8Array.
51
+ *
52
+ * PEM format is a base64-encoded format commonly used for cryptographic keys and certificates,
53
+ * wrapped with header and footer lines like "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----".
54
+ * This function extracts the base64 content and converts it to binary data using Node.js Buffer API.
55
+ *
56
+ * @param {string} pem - The PEM formatted string to convert.
57
+ * @param {boolean} validate - Whether to validate the PEM content using Node.js crypto module. Default is false.
58
+ * @returns {Uint8Array} A Uint8Array representing the decoded binary data.
59
+ *
60
+ * @throws {TypeError} If the input is not a string.
61
+ * @throws {Error} If the PEM format is invalid, contains invalid base64 characters, or validation fails.
62
+ */
63
+ export declare function pemToBuffer(pem: string, validate?: boolean): Uint8Array;
64
+ /**
65
+ * Extracts the raw 32-byte private key scalar from an EC private key PEM.
66
+ *
67
+ * This function parses an EC private key in PEM format and extracts the raw
68
+ * 32-byte private scalar (the "d" value) used in elliptic curve cryptography.
69
+ * This is the actual secret key material.
70
+ *
71
+ * @param {string} pemPrivateKey - The EC private key in PEM format
72
+ * @returns {Uint8Array} The raw 32-byte private key scalar
73
+ * @throws {Error} If the input is not a valid EC private key PEM
74
+ *
75
+ * @example
76
+ * ```typescript
77
+ * const pemKey = `-----BEGIN EC PRIVATE KEY-----
78
+ * MHcCAQEEIFBxqFkUxMoN2JkUXLFeiZnLNUpftjLi0sKMbZ6uajHXoAoGCCqGSM49
79
+ * AwEHoUQDQgAEcJ3eH/rG3zf9WmqMjh5eBSkeXz3Cb4Fig1rTosfHmgyjx/WnLPEe
80
+ * BF4SHvLo0G2COJEHa/VDE5EiKWO9ZR6AOQ==
81
+ * -----END EC PRIVATE KEY-----`;
82
+ *
83
+ * const rawKey = extractPrivateKeyRaw(pemKey);
84
+ * console.log(rawKey.length); // 32
85
+ * console.log(bufferToHex(rawKey)); // hex representation of the private scalar
86
+ * ```
87
+ */
88
+ export declare function extractPrivateKeyRaw(pemPrivateKey: string): Uint8Array;
89
+ //# sourceMappingURL=hex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hex.d.ts","sourceRoot":"","sources":["../../src/utils/hex.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,eAAe,GAAG,MAAM,CAa3D;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAgCnD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,GAAE,OAAe,GAAG,UAAU,CAoG9E;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,oBAAoB,CAAC,aAAa,EAAE,MAAM,GAAG,UAAU,CAgCtE"}
package/dist/utils/hex.js CHANGED
@@ -1,39 +1,114 @@
1
+ /**
2
+ * This file contains the hex functions.
3
+ *
4
+ * @file hex.ts
5
+ * @author Luca Liguori
6
+ * @created 2025-05-06
7
+ * @version 1.0.0
8
+ * @license Apache-2.0
9
+ *
10
+ * Copyright 2025, 2026, 2027 Luca Liguori.
11
+ *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
1
24
  import { createPublicKey, createPrivateKey, X509Certificate } from 'node:crypto';
25
+ /**
26
+ * Converts an ArrayBuffer or Uint8Array to a hexadecimal string.
27
+ *
28
+ * Accepts any {ArrayBufferLike} input: a raw ArrayBuffer (binary data storage) or
29
+ * a Uint8Array (TypedArray view over an ArrayBuffer). While an ArrayBuffer holds
30
+ * the raw memory, a Uint8Array is a typed view into that memory, letting you access
31
+ * its bytes directly. This function normalizes both by creating a Uint8Array view
32
+ * before conversion.
33
+ *
34
+ * @param {ArrayBufferLike} buffer - The buffer or typed-array view to convert.
35
+ * @returns {string} A lowercase hex string representation of the buffer's bytes.
36
+ *
37
+ * @throws {TypeError} If the input is not an ArrayBuffer or ArrayBufferView.
38
+ */
2
39
  export function bufferToHex(buffer) {
40
+ // Check if the input is an ArrayBuffer or ArrayBufferView
3
41
  if (!(buffer instanceof ArrayBuffer || ArrayBuffer.isView(buffer))) {
4
42
  throw new TypeError('Expected input to be an ArrayBuffer or ArrayBufferView');
5
43
  }
44
+ // Create a Uint8Array view over the buffer
6
45
  const bytes = buffer instanceof Uint8Array ? buffer : new Uint8Array(buffer);
46
+ // Convert each byte to 2-digit hex
7
47
  return Array.from(bytes)
8
48
  .map((byte) => byte.toString(16).padStart(2, '0'))
9
49
  .join('');
10
50
  }
51
+ /**
52
+ * Converts a hexadecimal string to a Uint8Array.
53
+ *
54
+ * @param {string} hex - The hex string to convert. Can include uppercase or lowercase characters.
55
+ * @returns {Uint8Array} A Uint8Array representing the corresponding binary data.
56
+ *
57
+ * @throws {TypeError} If the input is not a string.
58
+ * @throws {Error} If the input length is odd or contains non-hex characters.
59
+ */
11
60
  export function hexToBuffer(hex) {
61
+ // Ensure the input is a string
12
62
  if (typeof hex !== 'string') {
13
63
  throw new TypeError('Expected a string for hex input');
14
64
  }
65
+ // Trim any whitespace from the input string
15
66
  const cleaned = hex.trim();
67
+ // Check if the length of the hex string is even
16
68
  if (cleaned.length % 2 !== 0) {
17
69
  throw new Error('Invalid hex string length, must be even');
18
70
  }
71
+ // Validate that the string contains only valid hex characters
19
72
  if (!/^[0-9a-fA-F]*$/.test(cleaned)) {
20
73
  throw new Error('Invalid hex string, contains non-hex characters');
21
74
  }
75
+ // Calculate the length of the resulting Uint8Array
22
76
  const length = cleaned.length / 2;
77
+ // Create a Uint8Array to hold the binary data
23
78
  const result = new Uint8Array(length);
79
+ // Convert each pair of hex characters into a byte
24
80
  for (let i = 0; i < length; i++) {
25
81
  result[i] = parseInt(cleaned.substr(i * 2, 2), 16);
26
82
  }
83
+ // Return the resulting Uint8Array
27
84
  return result;
28
85
  }
86
+ /**
87
+ * Converts a PEM (Privacy-Enhanced Mail) formatted string to a Uint8Array.
88
+ *
89
+ * PEM format is a base64-encoded format commonly used for cryptographic keys and certificates,
90
+ * wrapped with header and footer lines like "-----BEGIN CERTIFICATE-----" and "-----END CERTIFICATE-----".
91
+ * This function extracts the base64 content and converts it to binary data using Node.js Buffer API.
92
+ *
93
+ * @param {string} pem - The PEM formatted string to convert.
94
+ * @param {boolean} validate - Whether to validate the PEM content using Node.js crypto module. Default is false.
95
+ * @returns {Uint8Array} A Uint8Array representing the decoded binary data.
96
+ *
97
+ * @throws {TypeError} If the input is not a string.
98
+ * @throws {Error} If the PEM format is invalid, contains invalid base64 characters, or validation fails.
99
+ */
29
100
  export function pemToBuffer(pem, validate = false) {
101
+ // Ensure the input is a string
30
102
  if (typeof pem !== 'string') {
31
103
  throw new TypeError('Expected a string for PEM input');
32
104
  }
105
+ // Trim whitespace from the input
33
106
  const cleaned = pem.trim();
107
+ // Check if the string appears to be in PEM format
34
108
  if (!cleaned.includes('-----BEGIN') || !cleaned.includes('-----END')) {
35
109
  throw new Error('Invalid PEM format: missing BEGIN/END markers');
36
110
  }
111
+ // Extract the base64 content between the header and footer
37
112
  const lines = cleaned.split('\n');
38
113
  const base64Lines = [];
39
114
  let inContent = false;
@@ -54,65 +129,114 @@ export function pemToBuffer(pem, validate = false) {
54
129
  if (base64Lines.length === 0) {
55
130
  throw new Error('Invalid PEM format: no content found between BEGIN/END markers');
56
131
  }
132
+ // Join all base64 lines together
57
133
  const base64String = base64Lines.join('');
134
+ // Validate base64 string format
58
135
  if (!/^[A-Za-z0-9+/]*={0,2}$/.test(base64String)) {
59
136
  throw new Error('Invalid PEM format: contains invalid base64 characters');
60
137
  }
61
138
  try {
139
+ // Use Node.js Buffer API instead of legacy atob()
62
140
  const buffer = Buffer.from(base64String, 'base64');
141
+ // Convert Buffer to Uint8Array
63
142
  const result = new Uint8Array(buffer);
143
+ // Validate PEM content using Node.js crypto module if requested
64
144
  if (validate) {
65
145
  try {
146
+ // Determine PEM type from the header and validate accordingly
66
147
  const pemType = cleaned.match(/-----BEGIN\s+([^-]+)-----/)?.[1]?.trim();
67
148
  if (pemType?.includes('CERTIFICATE')) {
149
+ // Use X509Certificate for robust certificate validation
68
150
  const cert = new X509Certificate(pem);
151
+ // Check validity period
69
152
  if (cert.validFrom && cert.validTo) {
70
153
  const now = Date.now();
71
154
  const from = Date.parse(cert.validFrom);
72
155
  const to = Date.parse(cert.validTo);
156
+ // istanbul ignore next if
73
157
  if (now < from || now > to) {
74
158
  throw new Error('Certificate is not currently valid');
75
159
  }
76
160
  }
161
+ // Check subject/issuer fields
162
+ // istanbul ignore next if
77
163
  if (!cert.subject || !cert.issuer) {
78
164
  throw new Error('Certificate missing subject or issuer');
79
165
  }
166
+ // Optionally check signature (not possible without CA chain)
80
167
  }
81
168
  else if (pemType?.includes('PRIVATE KEY')) {
169
+ // For private keys, try to create a private key
82
170
  createPrivateKey({ key: pem, format: 'pem' });
83
171
  }
84
172
  else if (pemType?.includes('PUBLIC KEY')) {
173
+ // For public keys, try to create a public key
85
174
  createPublicKey({ key: pem, format: 'pem' });
86
175
  }
176
+ // If no specific type is detected, skip validation
87
177
  }
88
178
  catch (validationError) {
179
+ // istanbul ignore next
89
180
  throw new Error(`PEM validation failed: ${validationError instanceof Error ? validationError.message : String(validationError)}`);
90
181
  }
91
182
  }
92
183
  return result;
93
184
  }
94
185
  catch (error) {
186
+ // istanbul ignore next
95
187
  throw new Error(`Failed to decode base64 content: ${error instanceof Error ? error.message : String(error)}`);
96
188
  }
97
189
  }
190
+ /**
191
+ * Extracts the raw 32-byte private key scalar from an EC private key PEM.
192
+ *
193
+ * This function parses an EC private key in PEM format and extracts the raw
194
+ * 32-byte private scalar (the "d" value) used in elliptic curve cryptography.
195
+ * This is the actual secret key material.
196
+ *
197
+ * @param {string} pemPrivateKey - The EC private key in PEM format
198
+ * @returns {Uint8Array} The raw 32-byte private key scalar
199
+ * @throws {Error} If the input is not a valid EC private key PEM
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * const pemKey = `-----BEGIN EC PRIVATE KEY-----
204
+ * MHcCAQEEIFBxqFkUxMoN2JkUXLFeiZnLNUpftjLi0sKMbZ6uajHXoAoGCCqGSM49
205
+ * AwEHoUQDQgAEcJ3eH/rG3zf9WmqMjh5eBSkeXz3Cb4Fig1rTosfHmgyjx/WnLPEe
206
+ * BF4SHvLo0G2COJEHa/VDE5EiKWO9ZR6AOQ==
207
+ * -----END EC PRIVATE KEY-----`;
208
+ *
209
+ * const rawKey = extractPrivateKeyRaw(pemKey);
210
+ * console.log(rawKey.length); // 32
211
+ * console.log(bufferToHex(rawKey)); // hex representation of the private scalar
212
+ * ```
213
+ */
98
214
  export function extractPrivateKeyRaw(pemPrivateKey) {
99
215
  if (typeof pemPrivateKey !== 'string') {
100
216
  throw new TypeError('Expected a string for PEM private key input');
101
217
  }
218
+ // Extract the private key block
102
219
  const keyBlock = /-----BEGIN (?:EC )?PRIVATE KEY-----[^-]+-----END (?:EC )?PRIVATE KEY-----/s.exec(pemPrivateKey);
103
220
  if (!keyBlock) {
104
221
  throw new Error('No EC PRIVATE KEY block found in the supplied PEM');
105
222
  }
106
223
  try {
224
+ // Create a private key object
107
225
  const privateKey = createPrivateKey(keyBlock[0]);
226
+ // Export as PKCS#8 DER format
108
227
  const pkcs8Der = privateKey.export({ format: 'der', type: 'pkcs8' });
228
+ // For P-256 curves, the private scalar is the last 32 bytes of the PKCS#8 DER
229
+ // istanbul ignore next
109
230
  if (pkcs8Der.length < 32) {
110
231
  throw new Error('Invalid private key: DER data too short');
111
232
  }
233
+ // Extract the last 32 bytes which contain the raw private scalar
112
234
  const rawPrivateKey = pkcs8Der.subarray(pkcs8Der.length - 32);
113
235
  return new Uint8Array(rawPrivateKey);
114
236
  }
115
237
  catch (error) {
238
+ // istanbul ignore next
116
239
  throw new Error(`Failed to extract private key: ${error instanceof Error ? error.message : String(error)}`);
117
240
  }
118
241
  }
242
+ //# sourceMappingURL=hex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hex.js","sourceRoot":"","sources":["../../src/utils/hex.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAEjF;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,WAAW,CAAC,MAAuB;IACjD,0DAA0D;IAC1D,IAAI,CAAC,CAAC,MAAM,YAAY,WAAW,IAAI,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;QACnE,MAAM,IAAI,SAAS,CAAC,wDAAwD,CAAC,CAAC;IAChF,CAAC;IAED,2CAA2C;IAC3C,MAAM,KAAK,GAAG,MAAM,YAAY,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,UAAU,CAA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