wire-mesh-core 1.0.3 → 1.1.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.
|
@@ -14,14 +14,20 @@ function bytesToHex(bytes) {
|
|
|
14
14
|
function deviceIdToHex(device) {
|
|
15
15
|
return bytesToHex(device);
|
|
16
16
|
}
|
|
17
|
+
/** The arbitrary-length reverse of bytesToHex -- decodes a lowercase, byte-exact hex string back into the bytes it encodes. Throws on an odd-length string, a non-hex character, or a non-lowercase one, rather than silently truncating or normalising a malformed input, matching deviceIdFromHex's own fail-closed convention for the fixed-length case. */
|
|
18
|
+
function bytesFromHex(hex) {
|
|
19
|
+
if (!/^([0-9a-f]{2})*$/.test(hex)) throw new Error(`expected an even-length, lowercase hex string, got ${JSON.stringify(hex)}`);
|
|
20
|
+
const bytes = new Uint8Array(hex.length / HEX_BYTE_WIDTH);
|
|
21
|
+
for (let i = 0; i < bytes.length; i++) bytes[i] = Number.parseInt(hex.slice(i * HEX_BYTE_WIDTH, (i + 1) * HEX_BYTE_WIDTH), HEX_RADIX);
|
|
22
|
+
return bytes;
|
|
23
|
+
}
|
|
17
24
|
/** Parses a lowercase, 64-character device-id-hex string back into the 32-byte DeviceId it encodes. Throws on anything that isn't exactly that shape, rather than silently truncating or zero-padding a malformed input. */
|
|
18
25
|
function deviceIdFromHex(hex) {
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
for (let i = 0; i < bytes.length; i++) bytes[i] = Number.parseInt(hex.slice(i * HEX_BYTE_WIDTH, (i + 1) * HEX_BYTE_WIDTH), HEX_RADIX);
|
|
22
|
-
return require_generated_protocol.deviceIdSchema.parse(bytes);
|
|
26
|
+
if (hex.length !== DEVICE_ID_HEX_LENGTH) throw new Error(`expected a 64-character lowercase hex string, got ${JSON.stringify(hex)}`);
|
|
27
|
+
return require_generated_protocol.deviceIdSchema.parse(bytesFromHex(hex));
|
|
23
28
|
}
|
|
24
29
|
//#endregion
|
|
30
|
+
exports.bytesFromHex = bytesFromHex;
|
|
25
31
|
exports.bytesToHex = bytesToHex;
|
|
26
32
|
exports.deviceIdFromHex = deviceIdFromHex;
|
|
27
33
|
exports.deviceIdToHex = deviceIdToHex;
|
|
@@ -4,6 +4,8 @@ import { v as DeviceId } from "../protocol-B26-5VX7.cjs";
|
|
|
4
4
|
export declare function bytesToHex(bytes: Uint8Array): string;
|
|
5
5
|
/** Lowercase, byte-exact hex -- the same encoding room.cddl's device-id-hex regex and the conformance vectors' synthetic device-ids already use. */
|
|
6
6
|
export declare function deviceIdToHex(device: DeviceId): string;
|
|
7
|
+
/** The arbitrary-length reverse of bytesToHex -- decodes a lowercase, byte-exact hex string back into the bytes it encodes. Throws on an odd-length string, a non-hex character, or a non-lowercase one, rather than silently truncating or normalising a malformed input, matching deviceIdFromHex's own fail-closed convention for the fixed-length case. */
|
|
8
|
+
export declare function bytesFromHex(hex: string): Uint8Array;
|
|
7
9
|
/** Parses a lowercase, 64-character device-id-hex string back into the 32-byte DeviceId it encodes. Throws on anything that isn't exactly that shape, rather than silently truncating or zero-padding a malformed input. */
|
|
8
10
|
export declare function deviceIdFromHex(hex: string): DeviceId;
|
|
9
11
|
//#endregion
|
|
@@ -4,6 +4,8 @@ import { v as DeviceId } from "../protocol-B26-5VX7.mjs";
|
|
|
4
4
|
export declare function bytesToHex(bytes: Uint8Array): string;
|
|
5
5
|
/** Lowercase, byte-exact hex -- the same encoding room.cddl's device-id-hex regex and the conformance vectors' synthetic device-ids already use. */
|
|
6
6
|
export declare function deviceIdToHex(device: DeviceId): string;
|
|
7
|
+
/** The arbitrary-length reverse of bytesToHex -- decodes a lowercase, byte-exact hex string back into the bytes it encodes. Throws on an odd-length string, a non-hex character, or a non-lowercase one, rather than silently truncating or normalising a malformed input, matching deviceIdFromHex's own fail-closed convention for the fixed-length case. */
|
|
8
|
+
export declare function bytesFromHex(hex: string): Uint8Array;
|
|
7
9
|
/** Parses a lowercase, 64-character device-id-hex string back into the 32-byte DeviceId it encodes. Throws on anything that isn't exactly that shape, rather than silently truncating or zero-padding a malformed input. */
|
|
8
10
|
export declare function deviceIdFromHex(hex: string): DeviceId;
|
|
9
11
|
//#endregion
|
|
@@ -13,12 +13,17 @@ function bytesToHex(bytes) {
|
|
|
13
13
|
function deviceIdToHex(device) {
|
|
14
14
|
return bytesToHex(device);
|
|
15
15
|
}
|
|
16
|
+
/** The arbitrary-length reverse of bytesToHex -- decodes a lowercase, byte-exact hex string back into the bytes it encodes. Throws on an odd-length string, a non-hex character, or a non-lowercase one, rather than silently truncating or normalising a malformed input, matching deviceIdFromHex's own fail-closed convention for the fixed-length case. */
|
|
17
|
+
function bytesFromHex(hex) {
|
|
18
|
+
if (!/^([0-9a-f]{2})*$/.test(hex)) throw new Error(`expected an even-length, lowercase hex string, got ${JSON.stringify(hex)}`);
|
|
19
|
+
const bytes = new Uint8Array(hex.length / HEX_BYTE_WIDTH);
|
|
20
|
+
for (let i = 0; i < bytes.length; i++) bytes[i] = Number.parseInt(hex.slice(i * HEX_BYTE_WIDTH, (i + 1) * HEX_BYTE_WIDTH), HEX_RADIX);
|
|
21
|
+
return bytes;
|
|
22
|
+
}
|
|
16
23
|
/** Parses a lowercase, 64-character device-id-hex string back into the 32-byte DeviceId it encodes. Throws on anything that isn't exactly that shape, rather than silently truncating or zero-padding a malformed input. */
|
|
17
24
|
function deviceIdFromHex(hex) {
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
for (let i = 0; i < bytes.length; i++) bytes[i] = Number.parseInt(hex.slice(i * HEX_BYTE_WIDTH, (i + 1) * HEX_BYTE_WIDTH), HEX_RADIX);
|
|
21
|
-
return deviceIdSchema.parse(bytes);
|
|
25
|
+
if (hex.length !== DEVICE_ID_HEX_LENGTH) throw new Error(`expected a 64-character lowercase hex string, got ${JSON.stringify(hex)}`);
|
|
26
|
+
return deviceIdSchema.parse(bytesFromHex(hex));
|
|
22
27
|
}
|
|
23
28
|
//#endregion
|
|
24
|
-
export { bytesToHex, deviceIdFromHex, deviceIdToHex };
|
|
29
|
+
export { bytesFromHex, bytesToHex, deviceIdFromHex, deviceIdToHex };
|