1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 function arraysAreEqual(arr1
, arr2
) {
12 if (arr1
.length
!== arr2
.length
) {
15 for (let i
= 0; i
< arr1
.length
; i
++) {
16 if (arr1
[i
] !== arr2
[i
]) {
24 // Serialization / Derserialization helpers
26 function stringToByteArray(str
) {
27 return new TextEncoder().encode(str
);
30 function byteArrayToString(byteArray
) {
31 return new TextDecoder().decode(new Uint8Array(byteArray
).buffer
);
34 function stringToArrayBuffer(str
) {
35 return new Uint8Array(new TextEncoder().encode(str
)).buffer
;
38 function byteArrayToHexString(buffer
) {
39 const byteArray
= new Uint8Array(buffer
);
41 for (let i
= 0; i
< byteArray
.length
; i
++) {
42 const hex
= byteArray
[i
].toString(16);
43 const paddedHex
= ("00" + hex
).slice(-2);
44 hexParts
.push(paddedHex
);
46 return hexParts
.join("");